初始
This commit is contained in:
145
internal/app/system/logic/planDaily/plan_daily.go
Normal file
145
internal/app/system/logic/planDaily/plan_daily.go
Normal file
@ -0,0 +1,145 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-09-26 14:31:07
|
||||
// 生成路径: internal/app/system/logic/plan_daily.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/common/coryCommon"
|
||||
"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"
|
||||
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"
|
||||
tool "github.com/tiger1103/gfast/v3/utility/coryUtils"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterPlanDaily(New())
|
||||
}
|
||||
|
||||
func New() *sPlanDaily {
|
||||
return &sPlanDaily{}
|
||||
}
|
||||
|
||||
type sPlanDaily struct{}
|
||||
|
||||
func (s *sPlanDaily) List(ctx context.Context, req *system.PlanDailySearchReq) (listRes *system.PlanDailySearchRes, err error) {
|
||||
listRes = new(system.PlanDailySearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.PlanDaily.Ctx(ctx).WithAll()
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where(dao.PlanDaily.Columns().ProjectId+" = ?", req.ProjectId)
|
||||
}
|
||||
if req.SourceId != "" {
|
||||
m = m.Where(dao.PlanDaily.Columns().SourceId+" = ?", req.SourceId)
|
||||
}
|
||||
if req.Name != "" {
|
||||
m = m.Where(dao.PlanDaily.Columns().Name+" like ?", "%"+req.Name+"%")
|
||||
}
|
||||
//创建时间模糊查询
|
||||
if req.CreatedAt != "" {
|
||||
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
|
||||
m = m.Where(dao.PlanDaily.Columns().CreatedAt+" like ?", "%"+date+"%")
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.PlanDaily.Columns().CreatedAt+" >=? AND "+dao.PlanDaily.Columns().CreatedAt+" <=?", req.DateRange[0], req.DateRange[1])
|
||||
}
|
||||
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.PlanDailyInfoRes
|
||||
err = m.Fields(system.PlanDailySearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.PlanDailyListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.PlanDailyListRes{
|
||||
Id: v.Id,
|
||||
ProjectId: v.ProjectId,
|
||||
SourceId: v.SourceId,
|
||||
Name: v.Name,
|
||||
SourceType: v.SourceType,
|
||||
Cnt: v.Cnt,
|
||||
DataTime: v.DataTime,
|
||||
Status: v.Status,
|
||||
CreatedAt: v.CreatedAt,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sPlanDaily) GetById(ctx context.Context, id int64) (res *model.PlanDailyInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.PlanDaily.Ctx(ctx).WithAll().Where(dao.PlanDaily.Columns().Id, id).Scan(&res)
|
||||
//获取创建人 更新人
|
||||
by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
|
||||
infoRes := by.(model.PlanDailyInfoRes)
|
||||
res = &infoRes
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sPlanDaily) Add(ctx context.Context, req *system.PlanDailyAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.PlanDaily.Ctx(ctx).Insert(do.PlanDaily{
|
||||
ProjectId: req.ProjectId,
|
||||
SourceId: req.SourceId,
|
||||
Name: req.Name,
|
||||
SourceType: req.SourceType,
|
||||
Cnt: req.Cnt,
|
||||
DataTime: req.DataTime,
|
||||
Status: req.Status,
|
||||
CreateBy: ct.New().GetLoginUser(ctx).Id,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sPlanDaily) Edit(ctx context.Context, req *system.PlanDailyEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.PlanDaily.Ctx(ctx).WherePri(req.Id).Update(do.PlanDaily{
|
||||
ProjectId: req.ProjectId,
|
||||
SourceId: req.SourceId,
|
||||
Name: req.Name,
|
||||
SourceType: req.SourceType,
|
||||
Cnt: req.Cnt,
|
||||
DataTime: req.DataTime,
|
||||
Status: req.Status,
|
||||
UpdateBy: ct.New().GetLoginUser(ctx).Id,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sPlanDaily) Delete(ctx context.Context, ids []int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.PlanDaily.Ctx(ctx).Delete(dao.PlanDaily.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user