249 lines
8.2 KiB
Go
249 lines
8.2 KiB
Go
// ==========================================================================
|
||
// GFast自动生成logic操作代码。
|
||
// 生成日期:2025-08-11 17:00:45
|
||
// 生成路径: internal/app/businesses/logic/species_survey.go
|
||
// 生成人:gfast
|
||
// desc:物种调查
|
||
// company:云南奇讯科技有限公司
|
||
// ==========================================================================
|
||
|
||
package logic
|
||
|
||
import (
|
||
"context"
|
||
|
||
"github.com/gogf/gf/v2/frame/g"
|
||
"github.com/gogf/gf/v2/util/gconv"
|
||
"github.com/tiger1103/gfast/v3/internal/app/businesses/dao"
|
||
"github.com/tiger1103/gfast/v3/internal/app/businesses/model"
|
||
"github.com/tiger1103/gfast/v3/internal/app/businesses/model/do"
|
||
"github.com/tiger1103/gfast/v3/internal/app/businesses/service"
|
||
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
|
||
"github.com/tiger1103/gfast/v3/library/liberr"
|
||
)
|
||
|
||
func init() {
|
||
service.RegisterSpeciesSurvey(NewISpeciesSurvey())
|
||
}
|
||
|
||
func NewISpeciesSurvey() service.ISpeciesSurvey {
|
||
return &sSpeciesSurvey{}
|
||
}
|
||
|
||
type sSpeciesSurvey struct{}
|
||
|
||
func (s *sSpeciesSurvey) List(ctx context.Context, req *model.SpeciesSurveySearchReq) (listRes *model.SpeciesSurveySearchRes, err error) {
|
||
listRes = new(model.SpeciesSurveySearchRes)
|
||
err = g.Try(ctx, func(ctx context.Context) {
|
||
m := dao.SpeciesSurvey.Ctx(ctx).WithAll()
|
||
if req.Id != "" {
|
||
m = m.Where(dao.SpeciesSurvey.Columns().Id+" = ?", req.Id)
|
||
}
|
||
if req.SpeciesCode != "" {
|
||
m = m.Where(dao.SpeciesSurvey.Columns().SpeciesCode+" like ?", "%"+req.SpeciesCode+"%")
|
||
}
|
||
if req.Province != "" {
|
||
m = m.Where(dao.SpeciesSurvey.Columns().Province+" like ?", "%"+req.Province+"%")
|
||
}
|
||
if req.City != "" {
|
||
m = m.Where(dao.SpeciesSurvey.Columns().City+" like ?", "%"+req.City+"%")
|
||
}
|
||
if req.County != "" {
|
||
m = m.Where(dao.SpeciesSurvey.Columns().County+" like ?", "%"+req.County+"%")
|
||
}
|
||
if req.Code != "" {
|
||
m = m.Where(dao.SpeciesSurvey.Columns().Code+" like ?", "%"+req.Code+"%")
|
||
}
|
||
if req.CourseName != "" {
|
||
m = m.Where(dao.SpeciesSurvey.Columns().CourseName+" like ?", "%"+req.CourseName+"%")
|
||
}
|
||
if req.MarkName != "" {
|
||
m = m.Where(dao.SpeciesSurvey.Columns().MarkName+" like ?", "%"+req.MarkName+"%")
|
||
}
|
||
if req.HabitatType != "" {
|
||
m = m.Where(dao.SpeciesSurvey.Columns().HabitatType+" like ?", "%"+req.HabitatType+"%")
|
||
}
|
||
if req.SoilType != "" {
|
||
m = m.Where(dao.SpeciesSurvey.Columns().SoilType+" like ?", "%"+req.SoilType+"%")
|
||
}
|
||
if req.SpeciesName != "" {
|
||
m = m.Where(dao.SpeciesSurvey.Columns().SpeciesName+" like ?", "%"+req.SpeciesName+"%")
|
||
}
|
||
if req.HarmObject != "" {
|
||
m = m.Where(dao.SpeciesSurvey.Columns().HarmObject+" like ?", "%"+req.HarmObject+"%")
|
||
}
|
||
if req.StandardCode != "" {
|
||
m = m.Where(dao.SpeciesSurvey.Columns().StandardCode+" like ?", "%"+req.StandardCode+"%")
|
||
}
|
||
if req.SpecimenCode != "" {
|
||
m = m.Where(dao.SpeciesSurvey.Columns().SpecimenCode+" like ?", "%"+req.SpecimenCode+"%")
|
||
}
|
||
if req.SourcesData != "" {
|
||
m = m.Where(dao.SpeciesSurvey.Columns().SourcesData+" like ?", "%"+req.SourcesData+"%")
|
||
}
|
||
if req.CreateUser != "" {
|
||
m = m.Where(dao.SpeciesSurvey.Columns().CreateUser+" = ?", gconv.Int(req.CreateUser))
|
||
}
|
||
listRes.Total, err = m.Count()
|
||
liberr.ErrIsNil(ctx, err, "获取总行数失败")
|
||
if req.PageNum == 0 {
|
||
req.PageNum = 1
|
||
}
|
||
listRes.CurrentPage = req.PageNum
|
||
if req.PageSize == 0 {
|
||
req.PageSize = consts.PageSize
|
||
}
|
||
order := "id asc"
|
||
if req.OrderBy != "" {
|
||
order = req.OrderBy
|
||
}
|
||
var res []*model.SpeciesSurveyListRes
|
||
err = m.Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||
listRes.List = make([]*model.SpeciesSurveyListRes, len(res))
|
||
for k, v := range res {
|
||
listRes.List[k] = &model.SpeciesSurveyListRes{
|
||
Id: v.Id,
|
||
SpeciesCode: v.SpeciesCode,
|
||
Province: v.Province,
|
||
City: v.City,
|
||
County: v.County,
|
||
Code: v.Code,
|
||
CourseName: v.CourseName,
|
||
MarkArea: v.MarkArea,
|
||
MarkName: v.MarkName,
|
||
Longitude: v.Longitude,
|
||
Dimensionality: v.Dimensionality,
|
||
Elevation: v.Elevation,
|
||
Temperature: v.Temperature,
|
||
Precipitation: v.Precipitation,
|
||
MarkAreaM: v.MarkAreaM,
|
||
HabitatType: v.HabitatType,
|
||
SoilType: v.SoilType,
|
||
SpeciesName: v.SpeciesName,
|
||
HarmObject: v.HarmObject,
|
||
HappenArea: v.HappenArea,
|
||
Treatment: v.Treatment,
|
||
IsStandard: v.IsStandard,
|
||
StandardCode: v.StandardCode,
|
||
IsSpecimen: v.IsSpecimen,
|
||
SpecimenCode: v.SpecimenCode,
|
||
Img: v.Img,
|
||
SourcesData: v.SourcesData,
|
||
CreateUser: v.CreateUser,
|
||
CreateDate: v.CreateDate,
|
||
AuditUser: v.AuditUser,
|
||
AuditDate: v.AuditDate,
|
||
AuditStatus: v.AuditStatus,
|
||
AuditView: v.AuditView,
|
||
Remark: v.Remark,
|
||
Version: v.Version,
|
||
CreatedAt: v.CreatedAt,
|
||
}
|
||
}
|
||
})
|
||
return
|
||
}
|
||
|
||
func (s *sSpeciesSurvey) GetById(ctx context.Context, id int) (res *model.SpeciesSurveyInfoRes, err error) {
|
||
err = g.Try(ctx, func(ctx context.Context) {
|
||
err = dao.SpeciesSurvey.Ctx(ctx).WithAll().Where(dao.SpeciesSurvey.Columns().Id, id).Scan(&res)
|
||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||
})
|
||
return
|
||
}
|
||
|
||
func (s *sSpeciesSurvey) Add(ctx context.Context, req *model.SpeciesSurveyAddReq) (err error) {
|
||
err = g.Try(ctx, func(ctx context.Context) {
|
||
_, err = dao.SpeciesSurvey.Ctx(ctx).Insert(do.SpeciesSurvey{
|
||
SpeciesCode: req.SpeciesCode,
|
||
Province: req.Province,
|
||
City: req.City,
|
||
County: req.County,
|
||
Code: req.Code,
|
||
CourseName: req.CourseName,
|
||
MarkArea: req.MarkArea,
|
||
MarkName: req.MarkName,
|
||
Longitude: req.Longitude,
|
||
Dimensionality: req.Dimensionality,
|
||
Elevation: req.Elevation,
|
||
Temperature: req.Temperature,
|
||
Precipitation: req.Precipitation,
|
||
MarkAreaM: req.MarkAreaM,
|
||
HabitatType: req.HabitatType,
|
||
SoilType: req.SoilType,
|
||
SpeciesName: req.SpeciesName,
|
||
HarmObject: req.HarmObject,
|
||
HappenArea: req.HappenArea,
|
||
Treatment: req.Treatment,
|
||
IsStandard: req.IsStandard,
|
||
StandardCode: req.StandardCode,
|
||
IsSpecimen: req.IsSpecimen,
|
||
SpecimenCode: req.SpecimenCode,
|
||
Img: req.Img,
|
||
SourcesData: req.SourcesData,
|
||
CreateUser: req.CreateUser,
|
||
CreateDate: req.CreateDate,
|
||
//AuditUser: req.AuditUser,
|
||
//AuditDate: req.AuditDate,
|
||
AuditStatus: req.AuditStatus,
|
||
//AuditView: req.AuditView,
|
||
Remark: req.Remark,
|
||
//Version: req.Version,
|
||
})
|
||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||
})
|
||
return
|
||
}
|
||
|
||
func (s *sSpeciesSurvey) Edit(ctx context.Context, req *model.SpeciesSurveyEditReq) (err error) {
|
||
err = g.Try(ctx, func(ctx context.Context) {
|
||
_, err = dao.SpeciesSurvey.Ctx(ctx).WherePri(req.Id).Update(do.SpeciesSurvey{
|
||
SpeciesCode: req.SpeciesCode,
|
||
Province: req.Province,
|
||
City: req.City,
|
||
County: req.County,
|
||
Code: req.Code,
|
||
CourseName: req.CourseName,
|
||
MarkArea: req.MarkArea,
|
||
MarkName: req.MarkName,
|
||
Longitude: req.Longitude,
|
||
Dimensionality: req.Dimensionality,
|
||
Elevation: req.Elevation,
|
||
Temperature: req.Temperature,
|
||
Precipitation: req.Precipitation,
|
||
MarkAreaM: req.MarkAreaM,
|
||
HabitatType: req.HabitatType,
|
||
SoilType: req.SoilType,
|
||
SpeciesName: req.SpeciesName,
|
||
HarmObject: req.HarmObject,
|
||
HappenArea: req.HappenArea,
|
||
Treatment: req.Treatment,
|
||
IsStandard: req.IsStandard,
|
||
StandardCode: req.StandardCode,
|
||
IsSpecimen: req.IsSpecimen,
|
||
SpecimenCode: req.SpecimenCode,
|
||
Img: req.Img,
|
||
SourcesData: req.SourcesData,
|
||
CreateUser: req.CreateUser,
|
||
CreateDate: req.CreateDate,
|
||
//AuditUser: req.AuditUser,
|
||
//AuditDate: req.AuditDate,
|
||
AuditStatus: req.AuditStatus,
|
||
//AuditView: req.AuditView,
|
||
Remark: req.Remark,
|
||
Version: req.Version,
|
||
})
|
||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||
})
|
||
return
|
||
}
|
||
|
||
func (s *sSpeciesSurvey) Delete(ctx context.Context, ids []int) (err error) {
|
||
err = g.Try(ctx, func(ctx context.Context) {
|
||
_, err = dao.SpeciesSurvey.Ctx(ctx).Delete(dao.SpeciesSurvey.Columns().Id+" in (?)", ids)
|
||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||
})
|
||
return
|
||
}
|