初始
This commit is contained in:
@ -0,0 +1,139 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-08-02 15:28:49
|
||||
// 生成路径: internal/app/system/logic/bus_scheduled_weekly.go
|
||||
// 生成人:gfast
|
||||
// desc:周报
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package logic
|
||||
|
||||
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/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.RegisterBusScheduledWeekly(New())
|
||||
}
|
||||
|
||||
func New() *sBusScheduledWeekly {
|
||||
return &sBusScheduledWeekly{}
|
||||
}
|
||||
|
||||
type sBusScheduledWeekly struct{}
|
||||
|
||||
func (s *sBusScheduledWeekly) List(ctx context.Context, req *system.BusScheduledWeeklySearchReq) (listRes *system.BusScheduledWeeklySearchRes, err error) {
|
||||
listRes = new(system.BusScheduledWeeklySearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusScheduledWeekly.Ctx(ctx).WithAll()
|
||||
if req.Status != "" {
|
||||
m = m.Where(dao.BusScheduledWeekly.Columns().Status+" = ?", req.Status)
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.BusScheduledWeekly.Columns().CreatedAt+" >=? AND "+dao.BusScheduledWeekly.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 := "plan_weekly_id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.BusScheduledWeeklyInfoRes
|
||||
err = m.Fields(system.BusScheduledWeeklySearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusScheduledWeeklyListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.BusScheduledWeeklyListRes{
|
||||
PlanWeeklyId: v.PlanWeeklyId,
|
||||
PlanPeriodId: v.PlanPeriodId,
|
||||
WeeklyPlanName: v.WeeklyPlanName,
|
||||
WeeklyStartTime: v.WeeklyStartTime,
|
||||
WeeklyEndTime: v.WeeklyEndTime,
|
||||
WeeklyPlanFinish: v.WeeklyPlanFinish,
|
||||
WeeklyRealityFinish: v.WeeklyRealityFinish,
|
||||
WeekyAccumulativeFinish: v.WeekyAccumulativeFinish,
|
||||
WeekyAccumulativeTotal: v.WeekyAccumulativeTotal,
|
||||
CompletionRate: v.CompletionRate,
|
||||
Leader: v.Leader,
|
||||
Status: v.Status,
|
||||
WeeklyDocumentUrl: v.WeeklyDocumentUrl,
|
||||
CreatedAt: v.CreatedAt,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusScheduledWeekly) GetByPlanWeeklyId(ctx context.Context, planWeeklyId int64) (res *model.BusScheduledWeeklyInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.BusScheduledWeekly.Ctx(ctx).WithAll().Where(dao.BusScheduledWeekly.Columns().PlanWeeklyId, planWeeklyId).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusScheduledWeekly) Add(ctx context.Context, req *system.BusScheduledWeeklyAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusScheduledWeekly.Ctx(ctx).Insert(do.BusScheduledWeekly{
|
||||
PlanPeriodId: req.PlanPeriodId,
|
||||
WeeklyPlanName: req.WeeklyPlanName,
|
||||
WeeklyStartTime: req.WeeklyStartTime,
|
||||
WeeklyEndTime: req.WeeklyEndTime,
|
||||
WeeklyPlanFinish: req.WeeklyPlanFinish,
|
||||
WeeklyRealityFinish: req.WeeklyRealityFinish,
|
||||
WeekyAccumulativeFinish: req.WeekyAccumulativeFinish,
|
||||
WeekyAccumulativeTotal: req.WeekyAccumulativeTotal,
|
||||
CompletionRate: req.CompletionRate,
|
||||
Leader: req.Leader,
|
||||
Status: req.Status,
|
||||
WeeklyDocumentUrl: req.WeeklyDocumentUrl,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusScheduledWeekly) Edit(ctx context.Context, req *system.BusScheduledWeeklyEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusScheduledWeekly.Ctx(ctx).WherePri(req.PlanWeeklyId).Update(do.BusScheduledWeekly{
|
||||
PlanPeriodId: req.PlanPeriodId,
|
||||
WeeklyPlanName: req.WeeklyPlanName,
|
||||
WeeklyStartTime: req.WeeklyStartTime,
|
||||
WeeklyEndTime: req.WeeklyEndTime,
|
||||
WeeklyPlanFinish: req.WeeklyPlanFinish,
|
||||
WeeklyRealityFinish: req.WeeklyRealityFinish,
|
||||
WeekyAccumulativeFinish: req.WeekyAccumulativeFinish,
|
||||
WeekyAccumulativeTotal: req.WeekyAccumulativeTotal,
|
||||
CompletionRate: req.CompletionRate,
|
||||
Leader: req.Leader,
|
||||
Status: req.Status,
|
||||
WeeklyDocumentUrl: req.WeeklyDocumentUrl,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusScheduledWeekly) Delete(ctx context.Context, planWeeklyIds []int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusScheduledWeekly.Ctx(ctx).Delete(dao.BusScheduledWeekly.Columns().PlanWeeklyId+" in (?)", planWeeklyIds)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user