初始
This commit is contained in:
121
internal/app/system/controller/project_schedule.go
Normal file
121
internal/app/system/controller/project_schedule.go
Normal file
@ -0,0 +1,121 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成controller操作代码。
|
||||
// 生成日期:2024-03-13 18:17:32
|
||||
// 生成路径: internal/app/system/controller/project_schedule.go
|
||||
// 生成人:gfast
|
||||
// desc:项目排期
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/system"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
|
||||
"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"
|
||||
)
|
||||
|
||||
type projectScheduleController struct {
|
||||
BaseController
|
||||
}
|
||||
|
||||
var ProjectSchedule = new(projectScheduleController)
|
||||
|
||||
// List 列表
|
||||
func (c *projectScheduleController) List(ctx context.Context, req *system.ProjectScheduleSearchReq) (res *system.ProjectScheduleSearchRes, err error) {
|
||||
res, err = service.ProjectSchedule().List(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// Get 获取项目排期
|
||||
func (c *projectScheduleController) Get(ctx context.Context, req *system.ProjectScheduleGetReq) (res *system.ProjectScheduleGetRes, err error) {
|
||||
res = new(system.ProjectScheduleGetRes)
|
||||
res.ProjectScheduleInfoRes, err = service.ProjectSchedule().GetById(ctx, req.Id)
|
||||
return
|
||||
}
|
||||
|
||||
// Add 添加项目排期
|
||||
func (c *projectScheduleController) Add(ctx context.Context, req *system.ProjectScheduleAddReq) (res *system.ProjectScheduleAddRes, err error) {
|
||||
err = service.ProjectSchedule().Add(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// Edit 修改项目排期
|
||||
func (c *projectScheduleController) Edit(ctx context.Context, req *system.ProjectScheduleEditReq) (res *system.ProjectScheduleEditRes, err error) {
|
||||
err = service.ProjectSchedule().Edit(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// Delete 删除项目排期
|
||||
func (c *projectScheduleController) Delete(ctx context.Context, req *system.ProjectScheduleDeleteReq) (res *system.ProjectScheduleDeleteRes, err error) {
|
||||
err = service.ProjectSchedule().Delete(ctx, req.Ids)
|
||||
return
|
||||
}
|
||||
|
||||
// 添加一个计划
|
||||
func (s *projectScheduleController) AddSchedule(ctx context.Context, req *system.ProjectScheduleAddPlanReq) (res *system.ProjectScheduleAddPlanRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
if req.Types == 1 {
|
||||
// 如果添加计划时,发现父级的 type ==0 的数据不存在,则将其父项目的开始时间修改为,第一个子任务的开始时间
|
||||
// 查询父级的 type == 0 的数据
|
||||
parentData, err := dao.ProjectSchedule.Ctx(ctx).Where(dao.ProjectSchedule.Columns().ParentId, req.ConstructionId).Where(dao.ProjectSchedule.Columns().Types, 0).One()
|
||||
liberr.ErrIsNil(ctx, err, "查询失败")
|
||||
if parentData == nil {
|
||||
// 如果父级的 type == 0 的数据不存在,则添加一条 parent_id = req.ConstructionId, types = 0 的数据
|
||||
_, err = dao.ProjectSchedule.Ctx(ctx).Insert(do.ProjectSchedule{
|
||||
ParentId: req.ConstructionId,
|
||||
StartDate: req.StartDate,
|
||||
EndDate: req.EndDate,
|
||||
Name: req.Name,
|
||||
PlaneNum: req.PlaneNum,
|
||||
Types: 0,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "更新失败")
|
||||
}
|
||||
|
||||
// 插入一条 type = 1 的数据
|
||||
_, err = dao.ProjectSchedule.Ctx(ctx).Insert(do.ProjectSchedule{
|
||||
ParentId: req.ConstructionId,
|
||||
StartDate: req.StartDate,
|
||||
EndDate: req.EndDate,
|
||||
Name: req.Name,
|
||||
PlaneNum: req.PlaneNum,
|
||||
Types: 1,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "更新失败")
|
||||
return
|
||||
}
|
||||
// 如果数据不存在,则添加
|
||||
count, err := dao.ProjectSchedule.Ctx(ctx).Where(dao.ProjectSchedule.Columns().ParentId, req.ConstructionId).Count()
|
||||
liberr.ErrIsNil(ctx, err, "查询失败")
|
||||
if count == 0 {
|
||||
_, err = dao.ProjectSchedule.Ctx(ctx).Insert(do.ProjectSchedule{
|
||||
ParentId: req.ConstructionId,
|
||||
StartDate: req.StartDate,
|
||||
EndDate: req.EndDate,
|
||||
Name: req.Name,
|
||||
PlaneNum: req.PlaneNum,
|
||||
Types: req.Types,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
} else {
|
||||
// 如果数据存在,则更新
|
||||
_, err = dao.ProjectSchedule.Ctx(ctx).Where(dao.ProjectSchedule.Columns().ParentId, req.ConstructionId).Update(do.ProjectSchedule{
|
||||
ParentId: req.ConstructionId,
|
||||
StartDate: req.StartDate,
|
||||
EndDate: req.EndDate,
|
||||
Name: req.Name,
|
||||
PlaneNum: req.PlaneNum,
|
||||
Types: req.Types,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "更新失败")
|
||||
}
|
||||
})
|
||||
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user