初始
This commit is contained in:
290
internal/app/system/logic/planWeekReality/plan_week_reality.go
Normal file
290
internal/app/system/logic/planWeekReality/plan_week_reality.go
Normal file
@ -0,0 +1,290 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-08-17 17:23:07
|
||||
// 生成路径: internal/app/system/logic/plan_week_reality.go
|
||||
// 生成人:xyb
|
||||
// desc:实际完成的周计划
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/system"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
|
||||
ct "github.com/tiger1103/gfast/v3/internal/app/system/logic/context"
|
||||
"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"
|
||||
"sort"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterPlanWeekReality(New())
|
||||
}
|
||||
|
||||
func New() *sPlanWeekReality {
|
||||
return &sPlanWeekReality{}
|
||||
}
|
||||
|
||||
type sPlanWeekReality struct{}
|
||||
|
||||
func (s *sPlanWeekReality) PlanWeekRealityCompare(ctx context.Context, req *system.PlanWeekRealityCompareReq) (res *system.PlanWeekRealityCompareRes, err error) {
|
||||
|
||||
res = &system.PlanWeekRealityCompareRes{}
|
||||
res.RealityList = []model.Task{}
|
||||
res.PlanList = []model.Task{}
|
||||
err = dao.PlanWeekReality.Ctx(ctx).WithAll().Where(dao.PlanWeekReality.Columns().PlanId, req.PlanID).Scan(&res.RealityList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = dao.PlanWeek.Ctx(ctx).WithAll().Where(dao.PlanWeek.Columns().PlanId, req.PlanID).Scan(&res.PlanList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sPlanWeekReality) List(ctx context.Context, req *system.PlanWeekRealitySearchReq) (listRes *system.PlanWeekRealitySearchRes, err error) {
|
||||
listRes = new(system.PlanWeekRealitySearchRes)
|
||||
/* err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.PlanWeekReality.Ctx(ctx).WithAll()
|
||||
if req.Id != "" {
|
||||
m = m.Where(dao.PlanWeekReality.Columns().Id+" = ?", req.Id)
|
||||
}
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where(dao.PlanWeekReality.Columns().ProjectId+" = ?", req.ProjectId)
|
||||
}
|
||||
if req.SourceId != "" {
|
||||
m = m.Where(dao.PlanWeekReality.Columns().SourceId+" = ?", req.SourceId)
|
||||
}
|
||||
if req.Name != "" {
|
||||
m = m.Where(dao.PlanWeekReality.Columns().Name+" like ?", "%"+req.Name+"%")
|
||||
}
|
||||
if req.Start != "" {
|
||||
m = m.Where(dao.PlanWeekReality.Columns().Start+" = ?", req.Start)
|
||||
}
|
||||
if req.End != "" {
|
||||
m = m.Where(dao.PlanWeekReality.Columns().End+" = ?", req.End)
|
||||
}
|
||||
if req.PlanName != "" {
|
||||
m = m.Where(dao.PlanWeekReality.Columns().PlanName+" like ?", "%"+req.PlanName+"%")
|
||||
}
|
||||
if req.PlanId != "" {
|
||||
m = m.Where(dao.PlanWeekReality.Columns().PlanId+" = ?", req.PlanId)
|
||||
}
|
||||
if req.CreateBy != "" {
|
||||
m = m.Where(dao.PlanWeekReality.Columns().CreateBy+" = ?", req.CreateBy)
|
||||
}
|
||||
if req.UpdateBy != "" {
|
||||
m = m.Where(dao.PlanWeekReality.Columns().UpdateBy+" = ?", req.UpdateBy)
|
||||
}
|
||||
if req.CreateAt != "" {
|
||||
m = m.Where(dao.PlanWeekReality.Columns().CreateAt+" = ?", gconv.Time(req.CreateAt))
|
||||
}
|
||||
if req.UpdateAt != "" {
|
||||
m = m.Where(dao.PlanWeekReality.Columns().UpdateAt+" = ?", gconv.Time(req.UpdateAt))
|
||||
}
|
||||
if req.Table != "" {
|
||||
m = m.Where(dao.PlanWeekReality.Columns().Table+" = ?", req.Table)
|
||||
}
|
||||
if req.Status != "" {
|
||||
m = m.Where(dao.PlanWeekReality.Columns().Status+" = ?", gconv.Int(req.Status))
|
||||
}
|
||||
if req.SourceType != "" {
|
||||
m = m.Where(dao.PlanWeekReality.Columns().SourceType+" = ?", req.SourceType)
|
||||
}
|
||||
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 desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.PlanWeekRealityInfoRes
|
||||
err = m.Fields(system.PlanWeekRealitySearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.PlanWeekRealityListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.PlanWeekRealityListRes{
|
||||
Id: v.Id,
|
||||
ProjectId: v.ProjectId,
|
||||
SourceId: v.SourceId,
|
||||
Name: v.Name,
|
||||
Start: v.Start,
|
||||
End: v.End,
|
||||
PlanName: v.PlanName,
|
||||
PlanId: v.PlanId,
|
||||
CreateBy: v.CreateBy,
|
||||
UpdateBy: v.UpdateBy,
|
||||
CreateAt: v.CreateAt,
|
||||
UpdateAt: v.UpdateAt,
|
||||
Table: v.Table,
|
||||
Status: v.Status,
|
||||
SourceType: v.SourceType,
|
||||
}
|
||||
}
|
||||
})*/
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.PlanWeekReality.Ctx(ctx).WithAll()
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where(dao.PlanWeekReality.Columns().ProjectId+" = ?", req.ProjectId)
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where("date_format(start,'%Y-%m-%d') >= ? AND date_format(end,'%Y-%m-%d')<=?", req.DateRange[0], req.DateRange[1])
|
||||
}
|
||||
var res []*model.PlanWeekRealityInfoRes
|
||||
err = m.Fields(system.PlanWeekRealitySearchRes{}).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
|
||||
listRes.List = []*model.PlanWeekRealityListRes{}
|
||||
var plans_map = make(map[string]*model.PlanWeekRealityListRes)
|
||||
for _, v := range res {
|
||||
pl := plans_map[v.PlanId]
|
||||
if pl == nil {
|
||||
pl = &model.PlanWeekRealityListRes{}
|
||||
pl.PlanID = v.PlanId
|
||||
pl.PlanName = v.PlanName
|
||||
pl.Start = v.Start
|
||||
pl.End = v.End
|
||||
pl.ProjectId = v.ProjectId
|
||||
pl.Tasks = []model.Task{}
|
||||
plans_map[v.PlanId] = pl
|
||||
}
|
||||
tsk := model.Task{}
|
||||
tsk.SourceId = v.SourceId
|
||||
tsk.Name = v.Name
|
||||
tsk.Table = v.Table
|
||||
tsk.Status = v.Status
|
||||
tsk.SourceType = v.SourceType
|
||||
tsk.Cnt = v.Cnt
|
||||
pl.Tasks = append(pl.Tasks, tsk)
|
||||
/*listRes.List[k] = &model.PlanWeekListRes{
|
||||
Id: v.Id,
|
||||
ProjectId: v.ProjectId,
|
||||
SourceId: v.SourceId,
|
||||
Name: v.Name,
|
||||
Start: v.Start,
|
||||
End: v.End,
|
||||
PlanName: v.PlanName,
|
||||
PlanId: v.PlanId,
|
||||
CreateBy: v.CreateBy,
|
||||
UpdateBy: v.UpdateBy,
|
||||
CreateAt: v.CreateAt,
|
||||
UpdateAt: v.UpdateAt,
|
||||
Table: v.Table,
|
||||
Status: v.Status,
|
||||
}*/
|
||||
}
|
||||
for _, plan := range plans_map {
|
||||
listRes.List = append(listRes.List, plan)
|
||||
}
|
||||
sort.Slice(listRes.List, func(i, j int) bool {
|
||||
return listRes.List[i].Start < listRes.List[j].Start
|
||||
})
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sPlanWeekReality) GetById(ctx context.Context, id int) (res *model.PlanWeekRealityInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.PlanWeekReality.Ctx(ctx).WithAll().Where(dao.PlanWeekReality.Columns().Id, id).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sPlanWeekReality) Add(ctx context.Context, req *system.PlanWeekRealityAddReq) (err error) {
|
||||
/* err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.PlanWeekReality.Ctx(ctx).Insert(do.PlanWeekReality{
|
||||
ProjectId: req.ProjectId,
|
||||
SourceId: req.SourceId,
|
||||
Name: req.Name,
|
||||
Start: req.Start,
|
||||
End: req.End,
|
||||
PlanName: req.PlanName,
|
||||
PlanId: req.PlanId,
|
||||
CreateBy: req.CreateBy,
|
||||
UpdateBy: req.UpdateBy,
|
||||
CreateAt: req.CreateAt,
|
||||
UpdateAt: req.UpdateAt,
|
||||
Table: req.Table,
|
||||
Status: req.Status,
|
||||
SourceType: req.SourceType,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})*/
|
||||
if len(req.Tasks) == 0 {
|
||||
err = errors.New("工作记录为空")
|
||||
return
|
||||
}
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
dao.PlanWeekReality.Ctx(ctx).Unscoped().Delete(dao.PlanWeekReality.Columns().PlanId, req.PlanID)
|
||||
var tasks []do.PlanWeekReality
|
||||
CreateBy := ct.New().GetLoginUser(ctx).Id
|
||||
for _, task := range req.Tasks {
|
||||
t := do.PlanWeekReality{}
|
||||
t.ProjectId = req.ProjectId
|
||||
t.PlanName = req.PlanName
|
||||
t.PlanId = req.PlanID
|
||||
t.SourceId = task.SourceId
|
||||
t.Name = task.Name
|
||||
//t.Table = task.Table
|
||||
t.Status = 2
|
||||
t.CreateBy = CreateBy
|
||||
t.UpdateBy = CreateBy
|
||||
t.Start = req.Start
|
||||
t.End = req.End
|
||||
t.SourceType = task.SourceType
|
||||
t.Cnt = task.Cnt
|
||||
tasks = append(tasks, t)
|
||||
}
|
||||
_, err = dao.PlanWeekReality.Ctx(ctx).Insert(&tasks)
|
||||
fmt.Println(err)
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sPlanWeekReality) Edit(ctx context.Context, req *system.PlanWeekRealityEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.PlanWeekReality.Ctx(ctx).WherePri(req.Id).Update(do.PlanWeekReality{
|
||||
ProjectId: req.ProjectId,
|
||||
SourceId: req.SourceId,
|
||||
Name: req.Name,
|
||||
Start: req.Start,
|
||||
End: req.End,
|
||||
PlanName: req.PlanName,
|
||||
PlanId: req.PlanId,
|
||||
CreateBy: req.CreateBy,
|
||||
UpdateBy: req.UpdateBy,
|
||||
CreateAt: req.CreateAt,
|
||||
UpdateAt: req.UpdateAt,
|
||||
Table: req.Table,
|
||||
Status: req.Status,
|
||||
SourceType: req.SourceType,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sPlanWeekReality) Delete(ctx context.Context, ids []int) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.PlanWeekReality.Ctx(ctx).Delete(dao.PlanWeekReality.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user