初始
This commit is contained in:
@ -0,0 +1,164 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2024-04-11 17:28:54
|
||||
// 生成路径: internal/app/system/logic/bus_design_period_range.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"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterBusDesignPeriodRange(New())
|
||||
}
|
||||
|
||||
func New() *sBusDesignPeriodRange {
|
||||
return &sBusDesignPeriodRange{}
|
||||
}
|
||||
|
||||
type sBusDesignPeriodRange struct{}
|
||||
|
||||
func (s *sBusDesignPeriodRange) List(ctx context.Context, req *system.BusDesignPeriodRangeSearchReq) (listRes *system.BusDesignPeriodRangeSearchRes, err error) {
|
||||
listRes = new(system.BusDesignPeriodRangeSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusDesignPeriodRange.Ctx(ctx).WithAll()
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where(dao.BusDesignPeriodRange.Columns().ProjectId+" = ?", gconv.Int64(req.ProjectId))
|
||||
}
|
||||
if req.TableType != "" {
|
||||
m = m.Where(dao.BusDesignPeriodRange.Columns().TableType+" = ?", req.TableType)
|
||||
}
|
||||
if req.FileName != "" {
|
||||
m = m.Where(dao.BusDesignPeriodRange.Columns().FileName+" like ?", "%"+req.FileName+"%")
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.BusDesignPeriodRange.Columns().CreatedAt+" >=? AND "+dao.BusDesignPeriodRange.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 := "id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.BusDesignPeriodRangeInfoRes
|
||||
err = m.Fields(system.BusDesignPeriodRangeSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusDesignPeriodRangeListRes, len(res))
|
||||
for k, v := range res {
|
||||
//1、根据项目ID判断某表下是否有一个叫【/**/**.docx】的文件或文件夹
|
||||
tableName := ""
|
||||
if v.TableType == "1" {
|
||||
tableName = dao.DocumentCompletion.Table()
|
||||
} else if v.TableType == "2" {
|
||||
tableName = dao.DocumentProductionDrawing.Table()
|
||||
} else {
|
||||
tableName = dao.DocumentReport.Table()
|
||||
}
|
||||
value, err := g.DB().Model(tableName).Ctx(ctx).
|
||||
Where("project_id", v.ProjectId).
|
||||
Where("filen_path like ?", "%"+strconv.FormatInt(v.ProjectId, 10)+v.FilePath).Fields("create_by").Value()
|
||||
var cBy = value.String()
|
||||
if err != nil {
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
return
|
||||
}
|
||||
//2、如果有这个文件夹就获取创建人并变更状态,反之不动
|
||||
var isNum = "1"
|
||||
if cBy != "" {
|
||||
isNum = "2"
|
||||
}
|
||||
if isNum != v.IsEntering {
|
||||
dao.BusDesignPeriodRange.Ctx(ctx).WherePri(v.Id).Update(g.Map{"create_by": cBy, "is_entering": isNum})
|
||||
}
|
||||
//3、返回的数据信息
|
||||
listRes.List[k] = &model.BusDesignPeriodRangeListRes{
|
||||
Id: v.Id,
|
||||
ProjectId: v.ProjectId,
|
||||
TableType: v.TableType,
|
||||
FileName: v.FileName,
|
||||
FilePath: v.FilePath,
|
||||
IsEntering: isNum,
|
||||
StartTime: v.StartTime,
|
||||
EndTime: v.EndTime,
|
||||
CreateBy: coryCommon.SelectByString(ctx, coryCommon.IsNumeric(v.CreateBy), v.CreateBy),
|
||||
UpdateBy: coryCommon.SelectByString(ctx, coryCommon.IsNumeric(v.UpdateBy), v.UpdateBy),
|
||||
CreatedAt: v.CreatedAt,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusDesignPeriodRange) GetById(ctx context.Context, id int64) (res *model.BusDesignPeriodRangeInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.BusDesignPeriodRange.Ctx(ctx).WithAll().Where(dao.BusDesignPeriodRange.Columns().Id, id).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusDesignPeriodRange) Add(ctx context.Context, req *system.BusDesignPeriodRangeAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusDesignPeriodRange.Ctx(ctx).Insert(do.BusDesignPeriodRange{
|
||||
ProjectId: req.ProjectId,
|
||||
TableType: req.TableType,
|
||||
FileName: req.FileName,
|
||||
FilePath: req.FilePath,
|
||||
StartTime: req.StartTime,
|
||||
EndTime: req.EndTime,
|
||||
CreateBy: ct.New().GetLoginUser(ctx).Id,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusDesignPeriodRange) Edit(ctx context.Context, req *system.BusDesignPeriodRangeEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusDesignPeriodRange.Ctx(ctx).WherePri(req.Id).Update(do.BusDesignPeriodRange{
|
||||
ProjectId: req.ProjectId,
|
||||
TableType: req.TableType,
|
||||
FileName: req.FileName,
|
||||
FilePath: req.FilePath,
|
||||
IsEntering: req.IsEntering,
|
||||
StartTime: req.StartTime,
|
||||
EndTime: req.EndTime,
|
||||
CreateBy: req.CreateBy,
|
||||
UpdateBy: ct.New().GetLoginUser(ctx).Id,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusDesignPeriodRange) Delete(ctx context.Context, ids []int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusDesignPeriodRange.Ctx(ctx).Delete(dao.BusDesignPeriodRange.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user