初始
This commit is contained in:
@ -0,0 +1,127 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-07-28 15:27:53
|
||||
// 生成路径: internal/app/system/logic/bus_equipment_materials_weight.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.RegisterBusEquipmentMaterialsWeight(New())
|
||||
}
|
||||
|
||||
func New() *sBusEquipmentMaterialsWeight {
|
||||
return &sBusEquipmentMaterialsWeight{}
|
||||
}
|
||||
|
||||
type sBusEquipmentMaterialsWeight struct{}
|
||||
|
||||
func (s *sBusEquipmentMaterialsWeight) List(ctx context.Context, req *system.BusEquipmentMaterialsWeightSearchReq) (listRes *system.BusEquipmentMaterialsWeightSearchRes, err error) {
|
||||
listRes = new(system.BusEquipmentMaterialsWeightSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusEquipmentMaterialsWeight.Ctx(ctx).WithAll()
|
||||
if req.Weight != "" {
|
||||
m = m.Where(dao.BusEquipmentMaterialsWeight.Columns().Weight+" like ?", "%"+req.Weight+"%")
|
||||
}
|
||||
if req.Status != "" {
|
||||
m = m.Where(dao.BusEquipmentMaterialsWeight.Columns().Status+" = ?", req.Status)
|
||||
}
|
||||
if req.CreatedAt != "" {
|
||||
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
|
||||
m = m.Where(dao.BusEquipmentMaterialsWeight.Columns().CreatedAt+" like ?", "%"+date+"%")
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.BusEquipmentMaterialsWeight.Columns().CreatedAt+" >=? AND "+dao.BusEquipmentMaterialsWeight.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 := "weight_id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.BusEquipmentMaterialsWeightInfoRes
|
||||
err = m.Fields(system.BusEquipmentMaterialsWeightSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusEquipmentMaterialsWeightListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.BusEquipmentMaterialsWeightListRes{
|
||||
WeightId: v.WeightId,
|
||||
Weight: v.Weight,
|
||||
Status: v.Status,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusEquipmentMaterialsWeight) GetByWeightId(ctx context.Context, weightId int64) (res *model.BusEquipmentMaterialsWeightInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.BusEquipmentMaterialsWeight.Ctx(ctx).WithAll().Where(dao.BusEquipmentMaterialsWeight.Columns().WeightId, weightId).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
//获取创建人 更新人
|
||||
by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
|
||||
infoRes := by.(model.BusEquipmentMaterialsWeightInfoRes)
|
||||
res = &infoRes
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusEquipmentMaterialsWeight) Add(ctx context.Context, req *system.BusEquipmentMaterialsWeightAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
name := ct.New().GetLoginUser(ctx).Id
|
||||
_, err = dao.BusEquipmentMaterialsWeight.Ctx(ctx).Insert(do.BusEquipmentMaterialsWeight{
|
||||
Weight: req.Weight,
|
||||
Status: req.Status,
|
||||
CreateBy: name,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusEquipmentMaterialsWeight) Edit(ctx context.Context, req *system.BusEquipmentMaterialsWeightEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
name := ct.New().GetLoginUser(ctx).Id
|
||||
_, err = dao.BusEquipmentMaterialsWeight.Ctx(ctx).WherePri(req.WeightId).Update(do.BusEquipmentMaterialsWeight{
|
||||
Weight: req.Weight,
|
||||
Status: req.Status,
|
||||
UpdateBy: name,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusEquipmentMaterialsWeight) Delete(ctx context.Context, weightIds []int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusEquipmentMaterialsWeight.Ctx(ctx).Delete(dao.BusEquipmentMaterialsWeight.Columns().WeightId+" in (?)", weightIds)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user