初始
This commit is contained in:
@ -0,0 +1,146 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-07-29 11:14:45
|
||||
// 生成路径: internal/app/system/logic/bus_equipment_equipment_unpacking.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"
|
||||
ct "github.com/tiger1103/gfast/v3/internal/app/system/logic/context"
|
||||
tool "github.com/tiger1103/gfast/v3/utility/coryUtils"
|
||||
|
||||
"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.RegisterBusEquipmentEquipmentUnpacking(New())
|
||||
}
|
||||
|
||||
func New() *sBusEquipmentEquipmentUnpacking {
|
||||
return &sBusEquipmentEquipmentUnpacking{}
|
||||
}
|
||||
|
||||
type sBusEquipmentEquipmentUnpacking struct{}
|
||||
|
||||
func (s *sBusEquipmentEquipmentUnpacking) List(ctx context.Context, req *system.BusEquipmentEquipmentUnpackingSearchReq) (listRes *system.BusEquipmentEquipmentUnpackingSearchRes, err error) {
|
||||
listRes = new(system.BusEquipmentEquipmentUnpackingSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusEquipmentEquipmentUnpacking.Ctx(ctx).WithAll()
|
||||
if req.UnpackingName != "" {
|
||||
m = m.Where(dao.BusEquipmentEquipmentUnpacking.Columns().UnpackingName+" like ?", "%"+req.UnpackingName+"%")
|
||||
}
|
||||
if req.Status != "" {
|
||||
m = m.Where(dao.BusEquipmentEquipmentUnpacking.Columns().Status+" = ?", req.Status)
|
||||
}
|
||||
if req.CreatedAt != "" {
|
||||
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
|
||||
m = m.Where(dao.BusEquipmentEquipmentUnpacking.Columns().CreatedAt+" like ?", "%"+date+"%")
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.BusEquipmentEquipmentUnpacking.Columns().CreatedAt+" >=? AND "+dao.BusEquipmentEquipmentUnpacking.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 := "unpacking_id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.BusEquipmentEquipmentUnpackingInfoRes
|
||||
err = m.Fields(system.BusEquipmentEquipmentUnpackingSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusEquipmentEquipmentUnpackingListRes, len(res))
|
||||
for k, v := range res {
|
||||
//unpackingUrl := ([]*comModel.UpFile)(nil)
|
||||
//err = gjson.DecodeTo(v.UnpackingUrl, &unpackingUrl)
|
||||
//liberr.ErrIsNil(ctx, err)
|
||||
listRes.List[k] = &model.BusEquipmentEquipmentUnpackingListRes{
|
||||
UnpackingId: v.UnpackingId,
|
||||
EquipmentMaterialsId: v.EquipmentMaterialsId,
|
||||
UnpackingName: v.UnpackingName,
|
||||
UnpackingUrl: v.UnpackingUrl,
|
||||
ProjectId: v.ProjectId,
|
||||
Status: v.Status,
|
||||
CreatedAt: v.CreatedAt,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusEquipmentEquipmentUnpacking) GetByUnpackingId(ctx context.Context, unpackingId int64) (res *model.BusEquipmentEquipmentUnpackingInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.BusEquipmentEquipmentUnpacking.Ctx(ctx).WithAll().Where(dao.BusEquipmentEquipmentUnpacking.Columns().UnpackingId, unpackingId).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
//获取创建人 更新人
|
||||
by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
|
||||
infoRes := by.(model.BusEquipmentEquipmentUnpackingInfoRes)
|
||||
res = &infoRes
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusEquipmentEquipmentUnpacking) Add(ctx context.Context, req *system.BusEquipmentEquipmentUnpackingAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
//for _, obj := range req.UnpackingUrl {
|
||||
// obj.Url, err = libUtils.GetFilesPath(ctx, obj.Url)
|
||||
// liberr.ErrIsNil(ctx, err)
|
||||
//}
|
||||
_, err = dao.BusEquipmentEquipmentUnpacking.Ctx(ctx).Insert(do.BusEquipmentEquipmentUnpacking{
|
||||
EquipmentMaterialsId: req.EquipmentMaterialsId,
|
||||
UnpackingName: req.UnpackingName,
|
||||
UnpackingUrl: req.UnpackingUrl[0].Url,
|
||||
ProjectId: req.ProjectId,
|
||||
Status: req.Status,
|
||||
CreateBy: ct.New().GetLoginUser(ctx).Id,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusEquipmentEquipmentUnpacking) Edit(ctx context.Context, req *system.BusEquipmentEquipmentUnpackingEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
//for _, obj := range req.UnpackingUrl {
|
||||
// obj.Url, err = libUtils.GetFilesPath(ctx, obj.Url)
|
||||
// liberr.ErrIsNil(ctx, err)
|
||||
//}
|
||||
_, err = dao.BusEquipmentEquipmentUnpacking.Ctx(ctx).WherePri(req.UnpackingId).Update(do.BusEquipmentEquipmentUnpacking{
|
||||
EquipmentMaterialsId: req.EquipmentMaterialsId,
|
||||
UnpackingName: req.UnpackingName,
|
||||
UnpackingUrl: req.UnpackingUrl[0].Url,
|
||||
Status: req.Status,
|
||||
UpdateBy: ct.New().GetLoginUser(ctx).Id,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusEquipmentEquipmentUnpacking) Delete(ctx context.Context, unpackingIds []int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusEquipmentEquipmentUnpacking.Ctx(ctx).Delete(dao.BusEquipmentEquipmentUnpacking.Columns().UnpackingId+" in (?)", unpackingIds)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user