初始
This commit is contained in:
135
internal/app/system/logic/projectSchedule/project_schedule.go
Normal file
135
internal/app/system/logic/projectSchedule/project_schedule.go
Normal file
@ -0,0 +1,135 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2024-03-13 18:17:32
|
||||
// 生成路径: internal/app/system/logic/project_schedule.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"
|
||||
"github.com/tiger1103/gfast/v3/library/liberr"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterProjectSchedule(New())
|
||||
}
|
||||
|
||||
func New() *sProjectSchedule {
|
||||
return &sProjectSchedule{}
|
||||
}
|
||||
|
||||
type sProjectSchedule struct{}
|
||||
|
||||
func (s *sProjectSchedule) List(ctx context.Context, req *system.ProjectScheduleSearchReq) (listRes *system.ProjectScheduleSearchRes, err error) {
|
||||
listRes = new(system.ProjectScheduleSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.ProjectSchedule.Ctx(ctx).WithAll()
|
||||
if req.Id != "" {
|
||||
m = m.Where(dao.ProjectSchedule.Columns().Id+" = ?", req.Id)
|
||||
}
|
||||
if req.ParentId != "" {
|
||||
m = m.Where(dao.ProjectSchedule.Columns().ParentId+" = ?", gconv.Int(req.ParentId))
|
||||
}
|
||||
if req.StartDate != "" {
|
||||
m = m.Where(dao.ProjectSchedule.Columns().StartDate+" = ?", req.StartDate)
|
||||
}
|
||||
if req.EndDate != "" {
|
||||
m = m.Where(dao.ProjectSchedule.Columns().EndDate+" = ?", req.EndDate)
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.ProjectSchedule.Columns().CreatedAt+" >=? AND "+dao.ProjectSchedule.Columns().CreatedAt+" <=?", req.DateRange[0], req.DateRange[1])
|
||||
}
|
||||
if req.Name != "" {
|
||||
m = m.Where(dao.ProjectSchedule.Columns().Name+" like ?", "%"+req.Name+"%")
|
||||
}
|
||||
if req.PlaneNum != "" {
|
||||
m = m.Where(dao.ProjectSchedule.Columns().PlaneNum+" = ?", req.PlaneNum)
|
||||
}
|
||||
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.ProjectScheduleInfoRes
|
||||
err = m.Fields(system.ProjectScheduleSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.ProjectScheduleListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.ProjectScheduleListRes{
|
||||
Id: v.Id,
|
||||
ParentId: v.ParentId,
|
||||
StartDate: v.StartDate,
|
||||
EndDate: v.EndDate,
|
||||
CreatedAt: v.CreatedAt,
|
||||
Name: v.Name,
|
||||
PlaneNum: v.PlaneNum,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sProjectSchedule) GetById(ctx context.Context, id uint) (res *model.ProjectScheduleInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.ProjectSchedule.Ctx(ctx).WithAll().Where(dao.ProjectSchedule.Columns().Id, id).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sProjectSchedule) Add(ctx context.Context, req *system.ProjectScheduleAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.ProjectSchedule.Ctx(ctx).Insert(do.ProjectSchedule{
|
||||
ParentId: req.ParentId,
|
||||
StartDate: req.StartDate,
|
||||
EndDate: req.EndDate,
|
||||
Name: req.Name,
|
||||
PlaneNum: req.PlaneNum,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sProjectSchedule) Edit(ctx context.Context, req *system.ProjectScheduleEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.ProjectSchedule.Ctx(ctx).WherePri(req.Id).Update(do.ProjectSchedule{
|
||||
ParentId: req.ParentId,
|
||||
StartDate: req.StartDate,
|
||||
EndDate: req.EndDate,
|
||||
Name: req.Name,
|
||||
PlaneNum: req.PlaneNum,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sProjectSchedule) Delete(ctx context.Context, ids []uint) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.ProjectSchedule.Ctx(ctx).Delete(dao.ProjectSchedule.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user