初始
This commit is contained in:
198
internal/app/system/logic/busTour/bus_tour.go
Normal file
198
internal/app/system/logic/busTour/bus_tour.go
Normal file
@ -0,0 +1,198 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-10-10 12:11:05
|
||||
// 生成路径: internal/app/system/logic/bus_tour.go
|
||||
// 生成人:gfast
|
||||
// desc:煤科巡视-故障记录
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"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"
|
||||
busFolderFile "github.com/tiger1103/gfast/v3/internal/app/system/logic/busFolderFile"
|
||||
"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.RegisterBusTour(New())
|
||||
}
|
||||
|
||||
func New() *sBusTour {
|
||||
return &sBusTour{}
|
||||
}
|
||||
|
||||
type sBusTour struct{}
|
||||
|
||||
func (s *sBusTour) ListAll(ctx context.Context, req *system.BusTourSearchAllReq) (listRes *system.BusTourSearchAllRes, err error) {
|
||||
listRes = new(system.BusTourSearchAllRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusTour.Ctx(ctx).WithAll()
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where(dao.BusTour.Columns().ProjectId, req.ProjectId)
|
||||
}
|
||||
order := "created_at desc"
|
||||
var res []*model.BusTourInfoRes
|
||||
err = m.Order(order).Limit(18).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusTourListRes, len(res))
|
||||
for k, v := range res {
|
||||
// 获取当前数据的违章图片
|
||||
// value, _ := g.DB().Model(v.TableName).Ctx(ctx).WherePri("id", v.TableId).Fields("camera_name as nickname").Value()
|
||||
listRes.List[k] = &model.BusTourListRes{
|
||||
Id: v.Id,
|
||||
ProjectId: v.ProjectId,
|
||||
TourCategory: v.TourCategory,
|
||||
TourType: v.TourType,
|
||||
Picture: v.Picture,
|
||||
Describe: v.Describe,
|
||||
Num: v.Num,
|
||||
// Nickname: value.String(),
|
||||
CreatedAt: v.CreatedAt,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusTour) List(ctx context.Context, req *system.BusTourSearchReq) (listRes *system.BusTourSearchRes, err error) {
|
||||
listRes = new(system.BusTourSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusTour.Ctx(ctx).WithAll()
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where(dao.BusTour.Columns().ProjectId, req.ProjectId)
|
||||
}
|
||||
if req.TourCategory != "" {
|
||||
m = m.Where(dao.BusTour.Columns().TourCategory+" = ?", req.TourCategory)
|
||||
}
|
||||
if req.TourType != "" {
|
||||
m = m.Where(dao.BusTour.Columns().TourType+" = ?", req.TourType)
|
||||
}
|
||||
if req.Describe != "" {
|
||||
m = m.Where(dao.BusTour.Columns().Describe+" = ?", req.Describe)
|
||||
}
|
||||
// 创建时间模糊查询
|
||||
if req.CreatedAt != "" {
|
||||
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
|
||||
m = m.Where(dao.BusTour.Columns().CreatedAt+" like ?", "%"+date+"%")
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.BusTour.Columns().CreatedAt+" >=? AND "+dao.BusTour.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 := "created_at desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.BusTourInfoRes
|
||||
err = m.Fields(system.BusTourSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusTourListRes, len(res))
|
||||
for k, v := range res {
|
||||
// value, _ := g.DB().Model(v.TableName).Ctx(ctx).WherePri("id", v.TableId).Fields("camera_name as nickname").Value()
|
||||
listRes.List[k] = &model.BusTourListRes{
|
||||
Id: v.Id,
|
||||
ProjectId: v.ProjectId,
|
||||
TourCategory: v.TourCategory,
|
||||
TourType: v.TourType,
|
||||
Picture: v.Picture,
|
||||
Describe: v.Describe,
|
||||
Num: v.Num,
|
||||
// Nickname: value.String(),
|
||||
CreatedAt: v.CreatedAt,
|
||||
SxtName: v.SxtName,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusTour) GetById(ctx context.Context, id int64) (res *model.BusTourInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.BusTour.Ctx(ctx).WithAll().Where(dao.BusTour.Columns().Id, id).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusTour) Add(ctx context.Context, req *system.BusTourAddReq) (err error) {
|
||||
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
// 1、新增数据
|
||||
idInfo, err := dao.BusTour.Ctx(ctx).Insert(do.BusTour{
|
||||
ProjectId: req.ProjectId,
|
||||
TourCategory: req.TourCategory,
|
||||
TourType: req.TourType,
|
||||
Picture: req.Picture,
|
||||
Describe: req.Describe,
|
||||
Num: req.Num,
|
||||
TableName: req.TableName,
|
||||
TableId: req.TableId,
|
||||
SxtName: req.SxtName,
|
||||
})
|
||||
id, err := idInfo.LastInsertId()
|
||||
// 2、将数据给到图库
|
||||
err = busFolderFile.New().AllPicture(
|
||||
ctx,
|
||||
strings.Split(req.Picture, ","),
|
||||
4,
|
||||
dao.BusTour.Table(),
|
||||
id,
|
||||
"1",
|
||||
"1",
|
||||
"",
|
||||
req.ProjectId,
|
||||
)
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return err
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusTour) Edit(ctx context.Context, req *system.BusTourEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusTour.Ctx(ctx).WherePri(req.Id).Update(do.BusTour{})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusTour) Delete(ctx context.Context, ids []int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
// 1、删除资源文件
|
||||
var res []*model.BusTourInfoRes
|
||||
dao.BusTour.Ctx(ctx).Where("id in (?)", ids).Fields("picture").Scan(&res)
|
||||
if len(res) > 0 {
|
||||
for _, data := range res {
|
||||
coryCommon.BatchFile(strings.Split(data.Picture, ","))
|
||||
}
|
||||
}
|
||||
// 2、删除数据
|
||||
_, err = dao.BusTour.Ctx(ctx).Delete(dao.BusTour.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user