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,621 @@
// ==========================================================================
// GFast自动生成logic操作代码。
// 生成日期2023-07-29 11:14:16
// 生成路径: internal/app/system/logic/bus_equipment_materials.go
// 生成人gfast
// desc:材料/设备名称
// company:云南奇讯科技有限公司
// ==========================================================================
package logic
import (
"context"
"errors"
"fmt"
"github.com/gogf/gf/v2/frame/g"
"github.com/tiger1103/gfast/v3/api/v1/system"
comModel "github.com/tiger1103/gfast/v3/internal/app/common/model"
"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"
sysUserLogic "github.com/tiger1103/gfast/v3/internal/app/system/logic/sysUser"
"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"
"strings"
)
func init() {
service.RegisterBusEquipmentMaterials(New())
}
func New() *sBusEquipmentMaterials {
return &sBusEquipmentMaterials{}
}
type sBusEquipmentMaterials struct{}
func (s *sBusEquipmentMaterials) ConditionFunc(ctx context.Context, req *system.ConditionReq) (res *system.ConditionRes, err error) {
res = new(system.ConditionRes)
//1、获取材料列表
var dateEntity []*model.BusEquipmentMaterialsInfoRes
sql := dao.BusEquipmentMaterials.Ctx(ctx).
As("a").
LeftJoin("bus_equipment_materials_inventory", "b", "b.equipment_materials_id = a.equipment_materials_id AND out_put = 1").
Where("a.project_id", req.ProjectId).
Fields("a.equipment_materials_id,a.equipment_materials_name,SUM(b.number) AS total_number").
Group("a.equipment_materials_id,a.equipment_materials_name")
if req.IsPaging == "YES" || req.IsPaging == "yes" {
arr, err := sql.Array()
liberr.ErrIsNil(ctx, err, "获取总行数失败")
res.Total = len(arr)
if req.PageNum == 0 {
req.PageNum = 1
}
res.CurrentPage = req.PageNum
if req.PageSize == 0 {
req.PageSize = consts.PageSize
}
order := "a.equipment_materials_name desc,equipment_materials_id desc"
if req.OrderBy != "" {
order = req.OrderBy
}
sql = sql.Page(req.PageNum, req.PageSize).Order(order)
}
err = sql.Scan(&dateEntity)
if dateEntity != nil {
var cl []*system.ConditionListRes
for _, de := range dateEntity {
var clTwo = new(system.ConditionListRes)
clTwo.Id = de.EquipmentMaterialsId
clTwo.Name = de.EquipmentMaterialsName
clTwo.Number = de.TotalNumber
cl = append(cl, clTwo)
}
res.List = cl
}
return
}
//func (s *sBusEquipmentMaterials) ConditionFunc(ctx context.Context, req *system.ConditionReq) (res *system.ConditionRes, err error) {
// res = new(system.ConditionRes)
// var drOne []*system.DateListRes
// startDate, err := time.Parse("2006-01-02", req.DateRange[0])
// if err != nil {
// fmt.Println("无法解析开始日期:", err)
// return
// }
// endDate, err := time.Parse("2006-01-02", req.DateRange[1])
// if err != nil {
// fmt.Println("无法解析结束日期:", err)
// return
// }
// currentDate := startDate
// for currentDate.Before(endDate) || currentDate.Equal(endDate) {
// dateTime := currentDate.Format("2006-01-02")
// currentDate = currentDate.AddDate(0, 0, 1)
// var drTwo = new(system.DateListRes)
// drTwo.DateStr = dateTime
// //2、材料列表材料列表分页
// var dateEntity []*model.BusEquipmentMaterialsInfoRes
// sql := dao.BusEquipmentMaterials.Ctx(ctx).
// Where("project_id", req.ProjectId)
// if req.IsPaging == "YES" || req.IsPaging == "yes" {
// arr, err := sql.Array()
// liberr.ErrIsNil(ctx, err, "获取总行数失败")
// res.Total = len(arr)
// if req.PageNum == 0 {
// req.PageNum = 1
// }
// res.CurrentPage = req.PageNum
// if req.PageSize == 0 {
// req.PageSize = consts.PageSize
// }
// order := "equipment_materials_id desc"
// if req.OrderBy != "" {
// order = req.OrderBy
// }
// sql = sql.Page(req.PageNum, req.PageSize).Order(order)
// }
// err = sql.Scan(&dateEntity)
// //3、根据材料获取到对应的出库数量 (最近7天的出库数量)
// if len(dateEntity) > 0 {
// var cl []*system.ConditionListRes
// for _, de := range dateEntity {
// //2、统计当前项目下
// var clTwo = new(system.ConditionListRes)
// value, _ := dao.BusEquipmentMaterialsInventory.Ctx(ctx).
// Where("equipment_materials_id", de.EquipmentMaterialsId).
// Where("date_format(created_at,'%y%m%d') >= date_format(?,'%y%m%d')", dateTime).
// Where("out_put", "1").
// Fields("sum(number)").
// Value()
// clTwo.Id = de.EquipmentMaterialsId
// clTwo.Name = de.EquipmentMaterialsName
// clTwo.Number = value.Int()
// cl = append(cl, clTwo)
// }
// drTwo.List = cl
// }
// drOne = append(drOne, drTwo)
// }
// res.List = drOne
// return
//}
func (s *sBusEquipmentMaterials) MaterialsFunc(ctx context.Context, req *system.MaterialsReq) (res *system.MaterialsRes, err error) {
res = new(system.MaterialsRes)
err = g.Try(ctx, func(ctx context.Context) {
var pneOne []*system.MaterialsNumberEntity
//1、获取当前用户的项目信息 (需要判断是否分页)
ids := sysUserLogic.ProjectAll(ctx)
var projectListEntity []*model.SysProjectListRes
sql := dao.SysProject.Ctx(ctx).Where("id in (" + ids + ")")
if req.IsPaging == "YES" || req.IsPaging == "yes" {
arr, err := sql.Array()
liberr.ErrIsNil(ctx, err, "获取总行数失败")
res.Total = len(arr)
if req.PageNum == 0 {
req.PageNum = 1
}
res.CurrentPage = req.PageNum
if req.PageSize == 0 {
req.PageSize = consts.PageSize
}
order := "id desc"
if req.OrderBy != "" {
order = req.OrderBy
}
sql = sql.Fields(system.SysProjectSearchRes{}).Page(req.PageNum, req.PageSize).Order(order)
}
err = sql.Scan(&projectListEntity)
//2、获取当前项目下材料的数量的统计
for _, dataTwo := range projectListEntity {
var towOne []*system.Materials
var bm []*model.BusEquipmentMaterialsListRes
err = dao.BusEquipmentMaterials.Ctx(ctx).As("a").
Fields("a.*,"+
"(select sum(number) from bus_equipment_materials_inventory where equipment_materials_id = a.equipment_materials_id and out_put = '1') AS nr,"+
"(select sum(number) from bus_equipment_materials_inventory where equipment_materials_id = a.equipment_materials_id and out_put = '2') AS rk").
Where("a.project_id", dataTwo.Id).
Group("a.equipment_materials_id").
Scan(&bm)
for _, dataOne := range bm {
var towTwo = new(system.Materials)
towTwo.StatusName = dataOne.EquipmentMaterialsName
towTwo.Predict = dataOne.Rk
towTwo.Practical = dataOne.Nr
towOne = append(towOne, towTwo)
}
var pneTwo = new(system.MaterialsNumberEntity)
pneTwo.ProjectId = dataTwo.Id
if dataTwo.ShortName != "" {
pneTwo.ProjectName = dataTwo.ShortName
} else {
pneTwo.ProjectName = dataTwo.ProjectName
}
pneTwo.MaterialsList = towOne
pneOne = append(pneOne, pneTwo)
}
res.List = pneOne
liberr.ErrIsNil(ctx, err, "代码错误,请联系管理员!")
})
return
}
func (s *sBusEquipmentMaterials) List(ctx context.Context, req *system.BusEquipmentMaterialsSearchReq) (listRes *system.BusEquipmentMaterialsSearchRes, err error) {
listRes = new(system.BusEquipmentMaterialsSearchRes)
err = g.Try(ctx, func(ctx context.Context) {
m := dao.BusEquipmentMaterials.Ctx(ctx).As("a").WithAll().Fields("a.*,(SELECT max(updated_at) from bus_equipment_materials_inventory where deleted_at IS NULL And equipment_materials_id = a.equipment_materials_id) AS timeOfEntryAndExit ")
if req.ProjectId != "" {
m = m.Where("a."+dao.BusEquipmentMaterials.Columns().ProjectId+" = ?", req.ProjectId)
}
if req.EquipmentMaterialsName != "" {
m = m.Where("a."+dao.BusEquipmentMaterials.Columns().EquipmentMaterialsName+" like ?", "%"+req.EquipmentMaterialsName+"%")
}
if req.CompanyId != "" {
m = m.Where("a."+dao.BusEquipmentMaterials.Columns().CompanyId+" like ?", "%"+req.CompanyId+"%")
}
array, _ := m.Array()
listRes.Total = len(array)
liberr.ErrIsNil(ctx, err, "获取总行数失败")
if req.PageNum == 0 {
req.PageNum = 1
}
listRes.CurrentPage = req.PageNum
if req.PageSize == 0 {
req.PageSize = consts.PageSize
}
order := "equipment_materials_id desc"
if req.OrderBy != "" {
order = req.OrderBy
}
var res []*model.BusEquipmentMaterialsInfoRes
err = m.Fields(system.BusEquipmentMaterialsSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
liberr.ErrIsNil(ctx, err, "获取数据失败")
listRes.List = make([]*model.BusEquipmentMaterialsListRes, len(res))
for k, v := range res {
listRes.List[k] = &model.BusEquipmentMaterialsListRes{
EquipmentMaterialsId: v.EquipmentMaterialsId,
EquipmentMaterialsName: v.EquipmentMaterialsName,
CompanyId: v.CompanyId,
ProjectId: v.ProjectId,
TypeSpecificationName: v.TypeSpecificationName,
TypeSpecificationUrl: v.TypeSpecificationUrl,
CertificateConformityName: v.CertificateConformityName,
CertificateConformityUrl: v.CertificateConformityUrl,
QualityName: v.QualityName,
QualityUrl: v.QualityUrl,
InspectionReportName: v.InspectionReportName,
InspectionReportUrl: v.InspectionReportUrl,
ReexamineReportName: v.ReexamineReportName,
ReexamineReportUrl: v.ReexamineReportUrl,
UsePart: v.UsePart,
WeightId: v.WeightId,
Remark: v.Remark,
QuantityCount: v.QuantityCount,
Status: v.Status,
CreateBy: v.CreateBy,
UpdateBy: v.UpdateBy,
CreatedAt: v.CreatedAt,
TimeOfEntryAndExit: v.TimeOfEntryAndExit,
}
}
})
return
}
func (s *sBusEquipmentMaterials) GetByEquipmentMaterialsId(ctx context.Context, equipmentMaterialsId int64) (res *model.BusEquipmentMaterialsInfoRes, err error) {
err = g.Try(ctx, func(ctx context.Context) {
err = dao.BusEquipmentMaterials.Ctx(ctx).WithAll().Where(dao.BusEquipmentMaterials.Columns().EquipmentMaterialsId, equipmentMaterialsId).Scan(&res)
////获取创建人 更新人
//by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
//infoRes := by.(model.BusEquipmentMaterialsInfoRes)
//res = &infoRes
//liberr.ErrIsNil(ctx, err, "获取信息失败")
})
return
}
func (s *sBusEquipmentMaterials) Add(ctx context.Context, req *system.BusEquipmentMaterialsAddReq) (err error) {
defer func() {
if err := recover(); err != nil {
fmt.Println("发生错误:", err)
return
}
}()
//判断设备材料名称是否重复
if req.EquipmentMaterialsName != "" {
emvalue, _ := dao.BusEquipmentMaterials.Ctx(ctx).
Where(dao.BusEquipmentMaterials.Columns().EquipmentMaterialsName, req.EquipmentMaterialsName).
Where(dao.BusEquipmentMaterials.Columns().CompanyId, req.CompanyId).
Where(dao.BusEquipmentMaterials.Columns().ProjectId, req.ProjectId).
Where(dao.BusEquipmentMaterials.Columns().TypeSpecificationName, req.TypeSpecificationName).
Where(dao.BusEquipmentMaterials.Columns().WeightId, req.WeightId).Count()
if emvalue != 0 {
err = errors.New("设备材料名称不能重复")
return err
}
}
materials := do.BusEquipmentMaterials{
EquipmentMaterialsName: req.EquipmentMaterialsName,
CompanyId: req.CompanyId,
ProjectId: req.ProjectId,
TypeSpecificationName: req.TypeSpecificationName,
UsePart: req.UsePart,
WeightId: req.WeightId,
Remark: req.Remark,
QuantityCount: req.QuantityCount,
//Status: req.Status,
CreateBy: ct.New().GetLoginUser(ctx).Id,
}
if len(req.CertificateConformityUrl) > 0 {
materials.CertificateConformityName = strings.Split(req.CertificateConformityUrl[0].Name, ".")[0]
materials.CertificateConformityUrl = req.CertificateConformityUrl[0].Url
}
if len(req.QualityUrl) > 0 {
materials.QualityName = strings.Split(req.QualityUrl[0].Name, ".")[0]
materials.QualityUrl = req.QualityUrl[0].Url
}
if len(req.InspectionReportUrl) > 0 {
materials.InspectionReportName = strings.Split(req.InspectionReportUrl[0].Name, ".")[0]
materials.InspectionReportUrl = req.InspectionReportUrl[0].Url
}
if len(req.ReexamineReportUrl) > 0 {
materials.ReexamineReportName = strings.Split(req.ReexamineReportUrl[0].Name, ".")[0]
materials.ReexamineReportUrl = req.ReexamineReportUrl[0].Url
}
_, err = dao.BusEquipmentMaterials.Ctx(ctx).Insert(materials)
if err != nil {
panic("添加失败")
}
return
}
func (s *sBusEquipmentMaterials) Edit(ctx context.Context, req *system.BusEquipmentMaterialsEditReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
//判断设备材料名称是否重复
emCount, _ := dao.BusEquipmentMaterials.Ctx(ctx).
Where(dao.BusEquipmentMaterials.Columns().EquipmentMaterialsName, req.EquipmentMaterialsName).
Where(dao.BusEquipmentMaterials.Columns().CompanyId, req.CompanyId).
Where(dao.BusEquipmentMaterials.Columns().ProjectId, req.ProjectId).
Where(dao.BusEquipmentMaterials.Columns().TypeSpecificationName, req.TypeSpecificationName).
Where(dao.BusEquipmentMaterials.Columns().WeightId, req.WeightId).
Where(dao.BusEquipmentMaterials.Columns().EquipmentMaterialsId+"!= ?", req.EquipmentMaterialsId). //排除当前记录
Count()
if emCount > 0 {
err = errors.New("设备材料名称不能重复")
liberr.ErrIsNil(ctx, err)
return
}
materials := do.BusEquipmentMaterials{
EquipmentMaterialsName: req.EquipmentMaterialsName,
CompanyId: req.CompanyId,
ProjectId: req.ProjectId,
TypeSpecificationName: req.TypeSpecificationName,
//TypeSpecificationName: strings.Split(req.TypeSpecificationUrl[0].Name, ".")[0],
//TypeSpecificationUrl: req.TypeSpecificationUrl[0].Url,
UsePart: req.UsePart,
WeightId: req.WeightId,
Remark: req.Remark,
QuantityCount: req.QuantityCount,
Status: req.Status,
UpdateBy: ct.New().GetLoginUser(ctx).Id,
}
if len(req.CertificateConformityUrl) > 0 {
materials.CertificateConformityName = strings.Split(req.CertificateConformityUrl[0].Name, ".")[0]
materials.CertificateConformityUrl = req.CertificateConformityUrl[0].Url
}
if len(req.QualityUrl) > 0 {
materials.QualityName = strings.Split(req.QualityUrl[0].Name, ".")[0]
materials.QualityUrl = req.QualityUrl[0].Url
}
if len(req.InspectionReportUrl) > 0 {
materials.InspectionReportName = strings.Split(req.InspectionReportUrl[0].Name, ".")[0]
materials.InspectionReportUrl = req.InspectionReportUrl[0].Url
}
if len(req.ReexamineReportUrl) > 0 {
materials.ReexamineReportName = strings.Split(req.ReexamineReportUrl[0].Name, ".")[0]
materials.ReexamineReportUrl = req.ReexamineReportUrl[0].Url
}
_, err = dao.BusEquipmentMaterials.Ctx(ctx).WherePri(req.EquipmentMaterialsId).Update(materials)
liberr.ErrIsNil(ctx, err, "修改失败")
})
return
}
func (s *sBusEquipmentMaterials) Delete(ctx context.Context, equipmentMaterialsIds []int64) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.BusEquipmentMaterials.Ctx(ctx).Delete(dao.BusEquipmentMaterials.Columns().EquipmentMaterialsId+" in (?)", equipmentMaterialsIds)
liberr.ErrIsNil(ctx, err, "删除失败")
})
return
}
// APP
func (s *sBusEquipmentMaterials) AppAdd(ctx context.Context, req *system.BusEquipmentMaterialsAppAddReq) (err error) {
defer func() {
if err := recover(); err != nil {
return
}
}()
//判断设备材料名称是否重复
if req.EquipmentMaterialsName != "" {
emvalue, _ := dao.BusEquipmentMaterials.Ctx(ctx).
Where(dao.BusEquipmentMaterials.Columns().EquipmentMaterialsName, req.EquipmentMaterialsName).
Where(dao.BusEquipmentMaterials.Columns().CompanyId, req.CompanyId).
Where(dao.BusEquipmentMaterials.Columns().ProjectId, req.ProjectId).
Where(dao.BusEquipmentMaterials.Columns().TypeSpecificationName, req.TypeSpecificationName).
Where(dao.BusEquipmentMaterials.Columns().WeightId, req.WeightId).Count()
if emvalue != 0 {
err = errors.New("设备材料名称不能重复")
return err
}
}
materials := do.BusEquipmentMaterials{
EquipmentMaterialsName: req.EquipmentMaterialsName,
CompanyId: req.CompanyId,
ProjectId: req.ProjectId,
TypeSpecificationName: req.TypeSpecificationName,
UsePart: req.UsePart,
WeightId: req.WeightId,
Remark: req.Remark,
QuantityCount: req.QuantityCount,
//Status: req.Status,
CreateBy: ct.New().GetLoginUser(ctx).Id,
}
if len(req.CertificateConformityUrl) > 0 {
materials.CertificateConformityName = strings.Split(req.CertificateConformityUrl[0].Name, ".")[0]
materials.CertificateConformityUrl = req.CertificateConformityUrl[0].Url
}
if len(req.QualityUrl) > 0 {
materials.QualityName = strings.Split(req.QualityUrl[0].Name, ".")[0]
materials.QualityUrl = req.QualityUrl[0].Url
}
if len(req.InspectionReportUrl) > 0 {
materials.InspectionReportName = strings.Split(req.InspectionReportUrl[0].Name, ".")[0]
materials.InspectionReportUrl = req.InspectionReportUrl[0].Url
}
if len(req.ReexamineReportUrl) > 0 {
materials.ReexamineReportName = strings.Split(req.ReexamineReportUrl[0].Name, ".")[0]
materials.ReexamineReportUrl = req.ReexamineReportUrl[0].Url
}
_, err = dao.BusEquipmentMaterials.Ctx(ctx).Insert(materials)
if err != nil {
panic("添加失败")
}
return
}
func (s *sBusEquipmentMaterials) AppEdit(ctx context.Context, req *system.BusEquipmentMaterialsAppEditReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
//判断设备材料名称是否重复
emCount, _ := dao.BusEquipmentMaterials.Ctx(ctx).
Where(dao.BusEquipmentMaterials.Columns().EquipmentMaterialsName, req.EquipmentMaterialsName).
Where(dao.BusEquipmentMaterials.Columns().CompanyId, req.CompanyId).
Where(dao.BusEquipmentMaterials.Columns().ProjectId, req.ProjectId).
Where(dao.BusEquipmentMaterials.Columns().TypeSpecificationName, req.TypeSpecificationName).
Where(dao.BusEquipmentMaterials.Columns().WeightId, req.WeightId).
Where(dao.BusEquipmentMaterials.Columns().EquipmentMaterialsId+"!= ?", req.EquipmentMaterialsId). //排除当前记录
Count()
if emCount > 0 {
err = errors.New("设备材料名称不能重复")
liberr.ErrIsNil(ctx, err)
return
}
//初始化[]*comModel.UpFile 检查len是否为空数组
fourFile := []*comModel.UpFile{
new(comModel.UpFile),
}
if req.CertificateConformityUrl == nil || len(req.CertificateConformityUrl) == 0 {
req.CertificateConformityUrl = fourFile
}
if req.QualityUrl == nil || len(req.QualityUrl) == 0 {
req.QualityUrl = fourFile
}
if req.InspectionReportUrl == nil || len(req.InspectionReportUrl) == 0 {
req.InspectionReportUrl = fourFile
}
if req.ReexamineReportUrl == nil || len(req.ReexamineReportUrl) == 0 {
req.ReexamineReportUrl = fourFile
}
_, err = dao.BusEquipmentMaterials.Ctx(ctx).WherePri(req.EquipmentMaterialsId).Update(do.BusEquipmentMaterials{
EquipmentMaterialsName: req.EquipmentMaterialsName,
CompanyId: req.CompanyId,
ProjectId: req.ProjectId,
TypeSpecificationName: req.TypeSpecificationName,
CertificateConformityName: strings.Split(req.CertificateConformityUrl[0].Name, ".")[0],
CertificateConformityUrl: req.CertificateConformityUrl[0].Url,
QualityName: strings.Split(req.QualityUrl[0].Name, ".")[0],
QualityUrl: req.QualityUrl[0].Url,
InspectionReportName: strings.Split(req.InspectionReportUrl[0].Name, ".")[0],
InspectionReportUrl: req.InspectionReportUrl[0].Url,
ReexamineReportName: strings.Split(req.ReexamineReportUrl[0].Name, ".")[0],
ReexamineReportUrl: req.ReexamineReportUrl[0].Url,
UsePart: req.UsePart,
WeightId: req.WeightId,
Remark: req.Remark,
QuantityCount: req.QuantityCount,
Status: req.Status,
UpdateBy: ct.New().GetLoginUser(ctx).Id,
})
liberr.ErrIsNil(ctx, err, "修改失败")
})
return
}
func (s *sBusEquipmentMaterials) AppList(ctx context.Context, req *system.BusEquipmentMaterialsAppSearchReq) (listRes *system.BusEquipmentMaterialsAppSearchRes, err error) {
listRes = new(system.BusEquipmentMaterialsAppSearchRes)
err = g.Try(ctx, func(ctx context.Context) {
m := dao.BusEquipmentMaterials.Ctx(ctx).As("bem").WithAll().
FieldsPrefix("bem", model.BusEquipmentMaterialsAppNameRes{}).
FieldSum("CASE WHEN bei.out_put = 2 THEN bei.number ELSE 0 END", "allInventoryNumber").
FieldSum("CASE WHEN bei.out_put = 1 THEN bei.number ELSE 0 END", "allOutboundNumber").
LeftJoin("bus_equipment_materials_inventory bei ON bem.equipment_materials_id = bei.equipment_materials_id")
//Fields("bem.equipment_materials_id AS 'equipmentMaterialsId',")
//Fields("a.*,(SELECT max(updated_at) from bus_equipment_materials_inventory where deleted_at IS NULL And equipment_materials_id = a.equipment_materials_id) AS timeOfEntryAndExit ")
if req.ProjectId != "" {
m = m.Where("bem."+dao.BusEquipmentMaterials.Columns().ProjectId+" = ?", req.ProjectId)
}
if req.EquipmentMaterialsName != "" {
m = m.Where("bem."+dao.BusEquipmentMaterials.Columns().EquipmentMaterialsName+" like ?", "%"+req.EquipmentMaterialsName+"%")
}
if req.CompanyId != "" {
m = m.Where("bem."+dao.BusEquipmentMaterials.Columns().CompanyId+" like ?", "%"+req.CompanyId+"%")
}
Sces := "bem.equipment_materials_id, bem.equipment_materials_name, bem.company_id, bem.project_id, bem.weight_id, bem.type_specification_name"
array, _ := m.Group(Sces).Array()
listRes.Total = len(array)
liberr.ErrIsNil(ctx, err, "获取总行数失败")
if req.PageNum == 0 {
req.PageNum = 1
}
listRes.CurrentPage = req.PageNum
if req.PageSize == 0 {
req.PageSize = consts.PageSize
}
order := "equipment_materials_id desc"
if req.OrderBy != "" {
order = req.OrderBy
}
var res []*model.BusEquipmentMaterialsAppListRes
err = m.Page(req.PageNum, req.PageSize).Group(Sces).Order(order).Scan(&res)
liberr.ErrIsNil(ctx, err, "获取数据失败")
listRes.List = make([]*model.BusEquipmentMaterialsAppListRes, len(res))
for k, v := range res {
listRes.List[k] = &model.BusEquipmentMaterialsAppListRes{
EquipmentMaterialsId: v.EquipmentMaterialsId,
EquipmentMaterialsName: v.EquipmentMaterialsName,
CompanyId: v.CompanyId,
ProjectId: v.ProjectId,
TypeSpecificationName: v.TypeSpecificationName,
WeightId: v.WeightId,
QuantityCount: v.QuantityCount,
AllInventoryNumber: v.AllInventoryNumber,
AllOutboundNumber: v.AllOutboundNumber,
}
}
})
return
}
func (s *sBusEquipmentMaterials) AppGetById(ctx context.Context, equipmentMaterialsId int64) (res *model.BusEquipmentMaterialsAppFileInfoRes, err error) {
err = g.Try(ctx, func(ctx context.Context) {
var reslist *model.BusEquipmentMaterialsAppInfoRes
err = dao.BusEquipmentMaterials.Ctx(ctx).As("bem").Fields("bem.*,bc.company_name").LeftJoin("bus_company bc ON bc.company_id =bem.company_id").
Where("bem.equipment_materials_id =?", equipmentMaterialsId).Scan(&reslist)
liberr.ErrIsNil(ctx, err, "获取信息失败")
// 使用封装的函数减少代码重复
files := map[string][]model.FourFile{
"CertificateConformityFile": {model.FourFile{Name: reslist.CertificateConformityName, Path: reslist.CertificateConformityUrl}},
"QualityFile": {model.FourFile{Name: reslist.QualityName, Path: reslist.QualityUrl}},
"InspectionReportFile": {model.FourFile{Name: reslist.InspectionReportName, Path: reslist.InspectionReportUrl}},
"ReexamineReportFile": {model.FourFile{Name: reslist.ReexamineReportName, Path: reslist.ReexamineReportUrl}},
}
//返回自己处理过后的数据
res = &model.BusEquipmentMaterialsAppFileInfoRes{
EquipmentMaterialsId: reslist.EquipmentMaterialsId,
EquipmentMaterialsName: reslist.EquipmentMaterialsName,
CompanyId: reslist.CompanyId,
CompanyName: reslist.CompanyName,
ProjectId: reslist.ProjectId,
TypeSpecificationName: reslist.TypeSpecificationName,
TypeSpecificationUrl: reslist.TypeSpecificationUrl,
// 使用循环和map简化文件数据的赋值
CertificateConformityFile: fillFiles(files["CertificateConformityFile"]),
QualityFile: fillFiles(files["QualityFile"]),
InspectionReportFile: fillFiles(files["InspectionReportFile"]),
ReexamineReportFile: fillFiles(files["ReexamineReportFile"]),
UsePart: reslist.UsePart,
WeightId: reslist.WeightId,
Remark: reslist.Remark,
QuantityCount: reslist.QuantityCount,
Status: reslist.Status,
CreateBy: reslist.CreateBy,
UpdateBy: reslist.UpdateBy,
CreatedAt: reslist.CreatedAt,
UpdatedAt: reslist.UpdatedAt,
}
////获取创建人 更新人
//by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
//infoRes := by.(model.BusEquipmentMaterialsInfoRes)
//res = &infoRes
//liberr.ErrIsNil(ctx, err, "获取信息失败")
})
return
}
// fillFiles 检查路径是否为空如果非空则将FourFile切片填充为非空切片
func fillFiles(files []model.FourFile) []model.FourFile {
if len(files) > 0 && files[0].Path != "" {
return files
}
return nil
}