This commit is contained in:
2025-07-07 20:11:59 +08:00
parent ab0fdbc447
commit 06e3aa2eb3
2009 changed files with 193082 additions and 0 deletions

View File

@ -0,0 +1,144 @@
// ==========================================================================
// GFast自动生成logic操作代码。
// 生成日期2023-07-29 11:36:04
// 生成路径: internal/app/system/logic/bus_standing_book.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.RegisterBusStandingBook(New())
}
func New() *sBusStandingBook {
return &sBusStandingBook{}
}
type sBusStandingBook struct{}
func (s *sBusStandingBook) List(ctx context.Context, req *system.BusStandingBookSearchReq) (listRes *system.BusStandingBookSearchRes, err error) {
listRes = new(system.BusStandingBookSearchRes)
err = g.Try(ctx, func(ctx context.Context) {
m := dao.BusStandingBook.Ctx(ctx).WithAll()
if req.EquipmentMaterialsId != "" {
m = m.Where(dao.BusStandingBook.Columns().EquipmentMaterialsId+" like ?", "%"+req.EquipmentMaterialsId+"%")
}
if req.StandingBookType != "" {
m = m.Where(dao.BusStandingBook.Columns().StandingBookType+" = ?", req.StandingBookType)
}
//创建时间模糊查询
if req.CreatedAt != "" {
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
m = m.Where(dao.BusStandingBook.Columns().CreatedAt+" like ?", "%"+date+"%")
}
if len(req.DateRange) != 0 {
m = m.Where(dao.BusStandingBook.Columns().CreatedAt+" >=? AND "+dao.BusStandingBook.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 := "standing_book_id desc"
if req.OrderBy != "" {
order = req.OrderBy
}
var res []*model.BusStandingBookInfoRes
err = m.Fields(system.BusStandingBookSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
liberr.ErrIsNil(ctx, err, "获取数据失败")
listRes.List = make([]*model.BusStandingBookListRes, len(res))
for k, v := range res {
fromString, _ := tool.New().FormatTimeString(v.ApproachTime, "2")
listRes.List[k] = &model.BusStandingBookListRes{
StandingBookId: v.StandingBookId,
EquipmentMaterialsId: v.EquipmentMaterialsId,
StandingBookType: v.StandingBookType,
ApproachTime: fromString,
Quantity: v.Quantity,
Gross: v.Gross,
Status: v.Status,
SignerRecipient: v.SignerRecipient,
CreatedAt: v.CreatedAt,
}
}
})
return
}
func (s *sBusStandingBook) GetByStandingBookId(ctx context.Context, standingBookId int64) (res *model.BusStandingBookInfoRes, err error) {
err = g.Try(ctx, func(ctx context.Context) {
err = dao.BusStandingBook.Ctx(ctx).WithAll().Where(dao.BusStandingBook.Columns().StandingBookId, standingBookId).Scan(&res)
liberr.ErrIsNil(ctx, err, "获取信息失败")
})
//获取创建人 更新人
by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
infoRes := by.(model.BusStandingBookInfoRes)
res = &infoRes
return
}
func (s *sBusStandingBook) Add(ctx context.Context, req *system.BusStandingBookAddReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
name := ct.New().GetLoginUser(ctx).Id
_, err = dao.BusStandingBook.Ctx(ctx).Insert(do.BusStandingBook{
EquipmentMaterialsId: req.EquipmentMaterialsId,
ProjectId: req.ProjectId,
StandingBookType: req.StandingBookType,
ApproachTime: req.ApproachTime,
Quantity: req.Quantity,
Gross: req.Quantity,
SignerRecipient: req.SignerRecipient,
CreateBy: name,
})
liberr.ErrIsNil(ctx, err, "添加失败")
})
return
}
func (s *sBusStandingBook) Edit(ctx context.Context, req *system.BusStandingBookEditReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
name := ct.New().GetLoginUser(ctx).Id
_, err = dao.BusStandingBook.Ctx(ctx).WherePri(req.StandingBookId).Update(do.BusStandingBook{
EquipmentMaterialsId: req.EquipmentMaterialsId,
StandingBookType: req.StandingBookType,
ApproachTime: req.ApproachTime,
Quantity: req.Quantity,
SignerRecipient: req.SignerRecipient,
UpdateBy: name,
Status: req.Status,
})
liberr.ErrIsNil(ctx, err, "修改失败")
})
return
}
func (s *sBusStandingBook) Delete(ctx context.Context, standingBookIds []int64) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.BusStandingBook.Ctx(ctx).Delete(dao.BusStandingBook.Columns().StandingBookId+" in (?)", standingBookIds)
liberr.ErrIsNil(ctx, err, "删除失败")
})
return
}