初始
This commit is contained in:
@ -0,0 +1,258 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2024-03-22 16:27:43
|
||||
// 生成路径: internal/app/system/logic/bus_construction_log.go
|
||||
// 生成人:gfast
|
||||
// desc:施工日志
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/common/coryCommon"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/system"
|
||||
"github.com/tiger1103/gfast/v3/api/wxApplet/wxApplet"
|
||||
"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"
|
||||
systemService "github.com/tiger1103/gfast/v3/internal/app/system/service"
|
||||
"github.com/tiger1103/gfast/v3/library/liberr"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterBusConstructionLog(New())
|
||||
}
|
||||
|
||||
func New() *sBusConstructionLog {
|
||||
return &sBusConstructionLog{}
|
||||
}
|
||||
|
||||
type sBusConstructionLog struct{}
|
||||
|
||||
func (s *sBusConstructionLog) ConstructionLogList(ctx context.Context, req *wxApplet.ConstructionLogListReq) (listRes *wxApplet.ConstructionLogListRes, err error) {
|
||||
listRes = new(wxApplet.ConstructionLogListRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
//1、根据名字模糊搜索到项目id
|
||||
var projectIds []string
|
||||
if req.ProjectName != "" {
|
||||
value, err := dao.SysProject.Ctx(ctx).
|
||||
Where("(project_name like ? or short_name like ?)", "%"+req.ProjectName+"%", "%"+req.ProjectName+"%").
|
||||
Fields("GROUP_CONCAT(id)").Value()
|
||||
liberr.ErrIsNil(ctx, err, "模糊查询失败")
|
||||
split := strings.Split(value.String(), ",")
|
||||
for i := range split {
|
||||
projectIds = append(projectIds, split[i])
|
||||
}
|
||||
}
|
||||
//2、查询数据
|
||||
m := dao.BusConstructionLog.Ctx(ctx).As("a").
|
||||
LeftJoin(dao.SysProject.Table(), "b", "b.id = a.project_id").
|
||||
Where("a.created_by", req.OpenId).
|
||||
Fields("a.*,b.project_name")
|
||||
if req.CreatedAt != "" {
|
||||
//m = m.Where("DATE_FORMAT(a.created_at,'%Y-%m-%d') = ?", req.CreatedAt)
|
||||
m = m.Where("a.date_of_occurrence = ?", req.CreatedAt)
|
||||
}
|
||||
if len(projectIds) > 0 {
|
||||
m = m.Where("b.id in (?)", projectIds)
|
||||
}
|
||||
if len(req.ProjectId) > 0 {
|
||||
m = m.Where("b.id", req.ProjectId)
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where("a."+dao.BusConstructionLog.Columns().CreatedAt+" >=? AND "+"a."+dao.BusConstructionLog.Columns().CreatedAt+" <=?", req.DateRange[0], req.DateRange[1])
|
||||
}
|
||||
array, err := m.Array()
|
||||
liberr.ErrIsNil(ctx, err, "获取总行数失败")
|
||||
listRes.Total = len(array)
|
||||
if req.PageNum == 0 {
|
||||
req.PageNum = 1
|
||||
}
|
||||
listRes.CurrentPage = req.PageNum
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = consts.PageSize
|
||||
}
|
||||
order := "date_of_occurrence desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.AppletList
|
||||
err = m.Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
//3、获取当前数据的新增人(创建人)
|
||||
for i := range res {
|
||||
ve := coryCommon.SelectByString(ctx, coryCommon.IsNumeric(res[i].CreatedBy), res[i].CreatedBy)
|
||||
res[i].CreatedBy = ve
|
||||
}
|
||||
listRes.List = res
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusConstructionLog) ConstructionLogDetails(ctx context.Context, req *wxApplet.ConstructionLogDetailsReq) (listRes *wxApplet.ConstructionLogDetailsRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.BusConstructionLog.Ctx(ctx).As("a").
|
||||
LeftJoin(dao.SysProject.Table(), "b", "b.id = a.project_id").
|
||||
Fields("a.*,b.project_name").Where("a.id", req.Id).Scan(&listRes)
|
||||
liberr.ErrIsNil(ctx, err, "查询失败")
|
||||
//3、获取创建人
|
||||
ve := coryCommon.SelectByString(ctx, coryCommon.IsNumeric(listRes.CreatedBy), listRes.CreatedBy)
|
||||
listRes.CreatedBy = ve
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusConstructionLog) ConstructionLogAdd(ctx context.Context, req *wxApplet.ConstructionLogAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
var str string
|
||||
if len(req.File) > 0 {
|
||||
for i := range req.File {
|
||||
replace := strings.Replace(req.File[i].Url, "/file/", "/wxfile/", 1)
|
||||
str = str + replace + ","
|
||||
}
|
||||
}
|
||||
if len(str) > 0 {
|
||||
str = str[:len(str)-1]
|
||||
}
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
_, err = dao.BusConstructionLog.Ctx(ctx).Insert(do.BusConstructionLog{
|
||||
ProjectId: req.ProjectId,
|
||||
DateOfOccurrence: req.DateOfOccurrence,
|
||||
Condition: req.Condition,
|
||||
TechnologyQuality: req.TechnologyQuality,
|
||||
Remark: req.Remark,
|
||||
Path: str,
|
||||
CreatedBy: req.OpenId,
|
||||
})
|
||||
//如果错误,删除图片
|
||||
if err != nil {
|
||||
if len(str) > 0 {
|
||||
var sg []string
|
||||
split := strings.Split(str, ",")
|
||||
for i := range split {
|
||||
sg = append(sg, split[i])
|
||||
}
|
||||
coryCommon.BatchFile(sg)
|
||||
}
|
||||
}
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusConstructionLog) List(ctx context.Context, req *system.BusConstructionLogSearchReq) (listRes *system.BusConstructionLogSearchRes, err error) {
|
||||
|
||||
listRes = new(system.BusConstructionLogSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
////1、根据名字模糊搜索到项目id
|
||||
//var projectIds []string
|
||||
//if req.ProjectName != "" {
|
||||
// value, err := dao.SysProject.Ctx(ctx).
|
||||
// Where("(project_name like ? or short_name like ?)", "%"+req.ProjectName+"%", "%"+req.ProjectName+"%").
|
||||
// Fields("GROUP_CONCAT(id)").Value()
|
||||
// liberr.ErrIsNil(ctx, err, "模糊查询失败")
|
||||
// split := strings.Split(value.String(), ",")
|
||||
// for i := range split {
|
||||
// projectIds = append(projectIds, split[i])
|
||||
// }
|
||||
//}
|
||||
//2、请求分页数据
|
||||
m := dao.BusConstructionLog.Ctx(ctx).As("a").
|
||||
LeftJoin(dao.SysProject.Table(), "b", "b.id = a.project_id").
|
||||
Fields("a.*,b.project_name as projectName")
|
||||
if req.ProjectId > 0 {
|
||||
m = m.Where("a."+dao.BusConstructionLog.Columns().ProjectId+" = ?", req.ProjectId)
|
||||
}
|
||||
if req.DateOfOccurrence != "" {
|
||||
m = m.Where("a."+dao.BusConstructionLog.Columns().DateOfOccurrence, req.DateOfOccurrence)
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where("a."+dao.BusConstructionLog.Columns().CreatedAt+" >=? AND a."+dao.BusConstructionLog.Columns().CreatedAt+" <=?", req.DateRange[0], req.DateRange[1])
|
||||
}
|
||||
array, err := m.Array()
|
||||
liberr.ErrIsNil(ctx, err, "获取总行数失败")
|
||||
listRes.Total = len(array)
|
||||
if req.PageNum == 0 {
|
||||
req.PageNum = 1
|
||||
}
|
||||
listRes.CurrentPage = req.PageNum
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = consts.PageSize
|
||||
}
|
||||
order := "date_of_occurrence desc,a.id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.AppletDetails
|
||||
err = m.Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
if res != nil {
|
||||
listRes.List = res
|
||||
}
|
||||
for i := range res {
|
||||
res[i].CreatedBy = coryCommon.SelectByString(ctx, coryCommon.IsNumeric(res[i].CreatedBy), res[i].CreatedBy)
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusConstructionLog) GetById(ctx context.Context, id int64) (res *model.AppletDetails, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.BusConstructionLog.Ctx(ctx).As("a").
|
||||
LeftJoin(dao.SysProject.Table(), "b", "b.id = a.project_id").
|
||||
Fields("a.*,b.project_name as projectName").
|
||||
Where("a."+dao.BusConstructionLog.Columns().Id, id).Scan(&res)
|
||||
if res != nil {
|
||||
//获取创建人 更新人名称
|
||||
by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
|
||||
infoRes := by.(model.AppletDetails)
|
||||
res = &infoRes
|
||||
}
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusConstructionLog) Add(ctx context.Context, req *system.BusConstructionLogAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusConstructionLog.Ctx(ctx).Insert(do.BusConstructionLog{
|
||||
ProjectId: req.ProjectId,
|
||||
DateOfOccurrence: req.DateOfOccurrence,
|
||||
Condition: req.Condition,
|
||||
TechnologyQuality: req.TechnologyQuality,
|
||||
Remark: req.Remark,
|
||||
Path: req.Path,
|
||||
CreatedBy: systemService.Context().GetUserId(ctx),
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusConstructionLog) Edit(ctx context.Context, req *system.BusConstructionLogEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusConstructionLog.Ctx(ctx).WherePri(req.Id).Update(do.BusConstructionLog{
|
||||
DateOfOccurrence: req.DateOfOccurrence,
|
||||
Condition: req.Condition,
|
||||
TechnologyQuality: req.TechnologyQuality,
|
||||
Remark: req.Remark,
|
||||
UpdatedBy: systemService.Context().GetUserId(ctx),
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusConstructionLog) Delete(ctx context.Context, ids []int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusConstructionLog.Ctx(ctx).Delete(dao.BusConstructionLog.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user