初始
This commit is contained in:
@ -0,0 +1,150 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2024-03-13 17:36:45
|
||||
// 生成路径: internal/app/system/logic/construction_project.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/api/v1/system"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model/do"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/service"
|
||||
systemService "github.com/tiger1103/gfast/v3/internal/app/system/service"
|
||||
"github.com/tiger1103/gfast/v3/library/liberr"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterConstructionProject(New())
|
||||
}
|
||||
|
||||
func New() *sConstructionProject {
|
||||
return &sConstructionProject{}
|
||||
}
|
||||
|
||||
type sConstructionProject struct{}
|
||||
|
||||
func (s *sConstructionProject) List(ctx context.Context, req *system.ConstructionProjectSearchReq) (listRes *system.ConstructionProjectSearchRes, err error) {
|
||||
listRes = new(system.ConstructionProjectSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.ConstructionProject.Ctx(ctx).WithAll()
|
||||
if req.ConstructionId != "" {
|
||||
m = m.Where(dao.ConstructionProject.Columns().ConstructionId+" = ?", req.ConstructionId)
|
||||
}
|
||||
if req.CreatedBy != "" {
|
||||
m = m.Where(dao.ConstructionProject.Columns().CreatedBy+" = ?", gconv.Uint64(req.CreatedBy))
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.ConstructionProject.Columns().CreatedAt+" >=? AND "+dao.ConstructionProject.Columns().CreatedAt+" <=?", req.DateRange[0], req.DateRange[1])
|
||||
}
|
||||
if req.FangzhenId != "" {
|
||||
m = m.Where(dao.ConstructionProject.Columns().FangzhenId+" = ?", gconv.Int(req.FangzhenId))
|
||||
}
|
||||
if req.ConstructionName != "" {
|
||||
m = m.Where(dao.ConstructionProject.Columns().ConstructionName+" like ?", "%"+req.ConstructionName+"%")
|
||||
}
|
||||
if req.Total != "" {
|
||||
m = m.Where(dao.ConstructionProject.Columns().Total+" = ?", gconv.Int(req.Total))
|
||||
}
|
||||
if req.IsPercentage != "" {
|
||||
m = m.Where(dao.ConstructionProject.Columns().IsPercentage+" = ?", gconv.Int(req.IsPercentage))
|
||||
}
|
||||
if req.EndTime != "" {
|
||||
m = m.Where(dao.ConstructionProject.Columns().EndTime+" = ?", gconv.Time(req.EndTime))
|
||||
}
|
||||
if req.StartTime != "" {
|
||||
m = m.Where(dao.ConstructionProject.Columns().StartTime+" = ?", gconv.Time(req.StartTime))
|
||||
}
|
||||
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 := "construction_id asc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.ConstructionProjectInfoRes
|
||||
err = m.Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.ConstructionProjectListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.ConstructionProjectListRes{
|
||||
ConstructionId: v.ConstructionId,
|
||||
CreatedBy: v.CreatedBy,
|
||||
CreatedAt: v.CreatedAt,
|
||||
FangzhenId: v.FangzhenId,
|
||||
ConstructionName: v.ConstructionName,
|
||||
Total: v.Total,
|
||||
Remark: v.Remark,
|
||||
IsPercentage: v.IsPercentage,
|
||||
EndTime: v.EndTime,
|
||||
StartTime: v.StartTime,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sConstructionProject) GetByConstructionId(ctx context.Context, constructionId uint64) (res *model.ConstructionProjectInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.ConstructionProject.Ctx(ctx).WithAll().Where(dao.ConstructionProject.Columns().ConstructionId, constructionId).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sConstructionProject) Add(ctx context.Context, req *system.ConstructionProjectAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.ConstructionProject.Ctx(ctx).Insert(do.ConstructionProject{
|
||||
FangzhenId: req.FangzhenId,
|
||||
ConstructionName: req.ConstructionName,
|
||||
Total: req.Total,
|
||||
Remark: req.Remark,
|
||||
IsPercentage: req.IsPercentage,
|
||||
EndTime: req.EndTime,
|
||||
StartTime: req.StartTime,
|
||||
CreatedBy: systemService.Context().GetUserId(ctx),
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sConstructionProject) Edit(ctx context.Context, req *system.ConstructionProjectEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.ConstructionProject.Ctx(ctx).WherePri(req.ConstructionId).Update(do.ConstructionProject{
|
||||
FangzhenId: req.FangzhenId,
|
||||
ConstructionName: req.ConstructionName,
|
||||
Total: req.Total,
|
||||
Remark: req.Remark,
|
||||
IsPercentage: req.IsPercentage,
|
||||
EndTime: req.EndTime,
|
||||
StartTime: req.StartTime,
|
||||
UpdatedBy: systemService.Context().GetUserId(ctx),
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sConstructionProject) Delete(ctx context.Context, constructionIds []uint64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.ConstructionProject.Ctx(ctx).Delete(dao.ConstructionProject.Columns().ConstructionId+" in (?)", constructionIds)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user