192 lines
6.5 KiB
Go
192 lines
6.5 KiB
Go
// ==========================================================================
|
||
// GFast自动生成logic操作代码。
|
||
// 生成日期:2025-08-11 16:38:01
|
||
// 生成路径: internal/app/businesses/logic/biology_ecology.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.RegisterBiologyEcology(NewIBiologyEcology())
|
||
}
|
||
|
||
func NewIBiologyEcology() service.IBiologyEcology {
|
||
return &sBiologyEcology{}
|
||
}
|
||
|
||
type sBiologyEcology struct{}
|
||
|
||
func (s *sBiologyEcology) List(ctx context.Context, req *model.BiologyEcologySearchReq) (listRes *model.BiologyEcologySearchRes, err error) {
|
||
listRes = new(model.BiologyEcologySearchRes)
|
||
err = g.Try(ctx, func(ctx context.Context) {
|
||
m := dao.BiologyEcology.Ctx(ctx).WithAll()
|
||
if req.Id != "" {
|
||
m = m.Where(dao.BiologyEcology.Columns().Id+" = ?", req.Id)
|
||
}
|
||
if req.SpeciesCode != "" {
|
||
m = m.Where(dao.BiologyEcology.Columns().SpeciesCode+" like ?", "%"+req.SpeciesCode+"%")
|
||
}
|
||
if req.LifeHistory != "" {
|
||
m = m.Where(dao.BiologyEcology.Columns().LifeHistory+" like ?", "%"+req.LifeHistory+"%")
|
||
}
|
||
if req.HabitatType != "" {
|
||
m = m.Where(dao.BiologyEcology.Columns().HabitatType+" like ?", "%"+req.HabitatType+"%")
|
||
}
|
||
if req.SpecimenGather != "" {
|
||
m = m.Where(dao.BiologyEcology.Columns().SpecimenGather+" like ?", "%"+req.SpecimenGather+"%")
|
||
}
|
||
if req.SpecimenSave != "" {
|
||
m = m.Where(dao.BiologyEcology.Columns().SpecimenSave+" like ?", "%"+req.SpecimenSave+"%")
|
||
}
|
||
if req.IntroduceDesc != "" {
|
||
m = m.Where(dao.BiologyEcology.Columns().IntroduceDesc+" like ?", "%"+req.IntroduceDesc+"%")
|
||
}
|
||
if req.Diffuse != "" {
|
||
m = m.Where(dao.BiologyEcology.Columns().Diffuse+" like ?", "%"+req.Diffuse+"%")
|
||
}
|
||
if req.RiskAssessment != "" {
|
||
m = m.Where(dao.BiologyEcology.Columns().RiskAssessment+" like ?", "%"+req.RiskAssessment+"%")
|
||
}
|
||
if req.SourcesData != "" {
|
||
m = m.Where(dao.BiologyEcology.Columns().SourcesData+" like ?", "%"+req.SourcesData+"%")
|
||
}
|
||
if req.CreateUser != "" {
|
||
m = m.Where(dao.BiologyEcology.Columns().CreateUser+" = ?", gconv.Int(req.CreateUser))
|
||
}
|
||
if req.AuditStatus != "" {
|
||
m = m.Where(dao.BiologyEcology.Columns().AuditStatus+" = ?", gconv.Int(req.AuditStatus))
|
||
}
|
||
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.BiologyEcologyListRes
|
||
err = m.Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||
listRes.List = make([]*model.BiologyEcologyListRes, len(res))
|
||
for k, v := range res {
|
||
listRes.List[k] = &model.BiologyEcologyListRes{
|
||
Id: v.Id,
|
||
SpeciesCode: v.SpeciesCode,
|
||
LifeHistory: v.LifeHistory,
|
||
Character: v.Character,
|
||
HabitatType: v.HabitatType,
|
||
ZoologyDescribe: v.ZoologyDescribe,
|
||
SpecimenGather: v.SpecimenGather,
|
||
SpecimenSave: v.SpecimenSave,
|
||
IntroduceDesc: v.IntroduceDesc,
|
||
Diffuse: v.Diffuse,
|
||
RiskAssessment: v.RiskAssessment,
|
||
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 *sBiologyEcology) GetById(ctx context.Context, id int) (res *model.BiologyEcologyInfoRes, err error) {
|
||
err = g.Try(ctx, func(ctx context.Context) {
|
||
err = dao.BiologyEcology.Ctx(ctx).WithAll().Where(dao.BiologyEcology.Columns().Id, id).Scan(&res)
|
||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||
})
|
||
return
|
||
}
|
||
|
||
func (s *sBiologyEcology) Add(ctx context.Context, req *model.BiologyEcologyAddReq) (err error) {
|
||
err = g.Try(ctx, func(ctx context.Context) {
|
||
_, err = dao.BiologyEcology.Ctx(ctx).Insert(do.BiologyEcology{
|
||
SpeciesCode: req.SpeciesCode,
|
||
LifeHistory: req.LifeHistory,
|
||
Character: req.Character,
|
||
HabitatType: req.HabitatType,
|
||
ZoologyDescribe: req.ZoologyDescribe,
|
||
SpecimenGather: req.SpecimenGather,
|
||
SpecimenSave: req.SpecimenSave,
|
||
IntroduceDesc: req.IntroduceDesc,
|
||
Diffuse: req.Diffuse,
|
||
RiskAssessment: req.RiskAssessment,
|
||
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 *sBiologyEcology) Edit(ctx context.Context, req *model.BiologyEcologyEditReq) (err error) {
|
||
err = g.Try(ctx, func(ctx context.Context) {
|
||
_, err = dao.BiologyEcology.Ctx(ctx).WherePri(req.Id).Update(do.BiologyEcology{
|
||
SpeciesCode: req.SpeciesCode,
|
||
LifeHistory: req.LifeHistory,
|
||
Character: req.Character,
|
||
HabitatType: req.HabitatType,
|
||
ZoologyDescribe: req.ZoologyDescribe,
|
||
SpecimenGather: req.SpecimenGather,
|
||
SpecimenSave: req.SpecimenSave,
|
||
IntroduceDesc: req.IntroduceDesc,
|
||
Diffuse: req.Diffuse,
|
||
RiskAssessment: req.RiskAssessment,
|
||
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 *sBiologyEcology) Delete(ctx context.Context, ids []int) (err error) {
|
||
err = g.Try(ctx, func(ctx context.Context) {
|
||
_, err = dao.BiologyEcology.Ctx(ctx).Delete(dao.BiologyEcology.Columns().Id+" in (?)", ids)
|
||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||
})
|
||
return
|
||
}
|