初始
This commit is contained in:
@ -0,0 +1,127 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-08-02 15:21:55
|
||||
// 生成路径: internal/app/system/logic/bus_scheduled_weekly_photovoltaic.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.RegisterBusScheduledWeeklyPhotovoltaic(New())
|
||||
}
|
||||
|
||||
func New() *sBusScheduledWeeklyPhotovoltaic {
|
||||
return &sBusScheduledWeeklyPhotovoltaic{}
|
||||
}
|
||||
|
||||
type sBusScheduledWeeklyPhotovoltaic struct{}
|
||||
|
||||
func (s *sBusScheduledWeeklyPhotovoltaic) List(ctx context.Context, req *system.BusScheduledWeeklyPhotovoltaicSearchReq) (listRes *system.BusScheduledWeeklyPhotovoltaicSearchRes, err error) {
|
||||
listRes = new(system.BusScheduledWeeklyPhotovoltaicSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusScheduledWeeklyPhotovoltaic.Ctx(ctx).WithAll()
|
||||
if req.PhotovoltaicNumber != "" {
|
||||
m = m.Where(dao.BusScheduledWeeklyPhotovoltaic.Columns().PhotovoltaicNumber+" = ?", req.PhotovoltaicNumber)
|
||||
}
|
||||
if req.InstallNot != "" {
|
||||
m = m.Where(dao.BusScheduledWeeklyPhotovoltaic.Columns().InstallNot+" = ?", req.InstallNot)
|
||||
}
|
||||
if req.Status != "" {
|
||||
m = m.Where(dao.BusScheduledWeeklyPhotovoltaic.Columns().Status+" = ?", req.Status)
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.BusScheduledWeeklyPhotovoltaic.Columns().CreatedAt+" >=? AND "+dao.BusScheduledWeeklyPhotovoltaic.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 := "photovoltaic_id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.BusScheduledWeeklyPhotovoltaicInfoRes
|
||||
err = m.Fields(system.BusScheduledWeeklyPhotovoltaicSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusScheduledWeeklyPhotovoltaicListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.BusScheduledWeeklyPhotovoltaicListRes{
|
||||
PhotovoltaicId: v.PhotovoltaicId,
|
||||
PlanWeeklyId: v.PlanWeeklyId,
|
||||
PhotovoltaicNumber: v.PhotovoltaicNumber,
|
||||
PhotovoltaicNumberGis: v.PhotovoltaicNumberGis,
|
||||
InstallNot: v.InstallNot,
|
||||
InstallCreateTime: v.InstallCreateTime,
|
||||
Status: v.Status,
|
||||
ProjectId: v.ProjectId,
|
||||
CreatedAt: v.CreatedAt,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusScheduledWeeklyPhotovoltaic) GetByPhotovoltaicId(ctx context.Context, photovoltaicId int64) (res *model.BusScheduledWeeklyPhotovoltaicInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.BusScheduledWeeklyPhotovoltaic.Ctx(ctx).WithAll().Where(dao.BusScheduledWeeklyPhotovoltaic.Columns().PhotovoltaicId, photovoltaicId).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusScheduledWeeklyPhotovoltaic) Add(ctx context.Context, req *system.BusScheduledWeeklyPhotovoltaicAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusScheduledWeeklyPhotovoltaic.Ctx(ctx).Insert(do.BusScheduledWeeklyPhotovoltaic{
|
||||
PlanWeeklyId: req.PlanWeeklyId,
|
||||
PhotovoltaicNumber: req.PhotovoltaicNumber,
|
||||
PhotovoltaicNumberGis: req.PhotovoltaicNumberGis,
|
||||
ProjectId: req.ProjectId,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusScheduledWeeklyPhotovoltaic) Edit(ctx context.Context, req *system.BusScheduledWeeklyPhotovoltaicEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusScheduledWeeklyPhotovoltaic.Ctx(ctx).WherePri(req.PhotovoltaicId).Update(do.BusScheduledWeeklyPhotovoltaic{
|
||||
PlanWeeklyId: req.PlanWeeklyId,
|
||||
PhotovoltaicNumber: req.PhotovoltaicNumber,
|
||||
PhotovoltaicNumberGis: req.PhotovoltaicNumberGis,
|
||||
InstallNot: req.InstallNot,
|
||||
InstallCreateTime: req.InstallCreateTime,
|
||||
Status: req.Status,
|
||||
ProjectId: req.ProjectId,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusScheduledWeeklyPhotovoltaic) Delete(ctx context.Context, photovoltaicIds []int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusScheduledWeeklyPhotovoltaic.Ctx(ctx).Delete(dao.BusScheduledWeeklyPhotovoltaic.Columns().PhotovoltaicId+" in (?)", photovoltaicIds)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user