初始
This commit is contained in:
@ -0,0 +1,138 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-09-20 14:55:24
|
||||
// 生成路径: internal/app/system/logic/bus_camera_chinese_standard.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.RegisterBusCameraChineseStandard(New())
|
||||
}
|
||||
|
||||
func New() *sBusCameraChineseStandard {
|
||||
return &sBusCameraChineseStandard{}
|
||||
}
|
||||
|
||||
type sBusCameraChineseStandard struct{}
|
||||
|
||||
func (s *sBusCameraChineseStandard) List(ctx context.Context, req *system.BusCameraChineseStandardSearchReq) (listRes *system.BusCameraChineseStandardSearchRes, err error) {
|
||||
listRes = new(system.BusCameraChineseStandardSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusCameraChineseStandard.Ctx(ctx).WithAll()
|
||||
m = m.Where(dao.BusCameraChineseStandard.Columns().ProjectId+" = ?", req.ProjectId)
|
||||
if req.CountryState != "" {
|
||||
m = m.Where(dao.BusCameraChineseStandard.Columns().CountryState+" = ?", req.CountryState)
|
||||
}
|
||||
if req.CountryNumber != "" {
|
||||
m = m.Where(dao.BusCameraChineseStandard.Columns().CountryNumber+" like ?", "%"+req.CountryNumber+"%")
|
||||
}
|
||||
if req.CountryName != "" {
|
||||
m = m.Where(dao.BusCameraChineseStandard.Columns().CountryName+" like ?", "%"+req.CountryName+"%")
|
||||
}
|
||||
//创建时间模糊查询
|
||||
if req.CreatedAt != "" {
|
||||
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
|
||||
m = m.Where(dao.BusCameraChineseStandard.Columns().CreatedAt+" like ?", "%"+date+"%")
|
||||
}
|
||||
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.BusCameraChineseStandard.Columns().CreatedAt+" >=? AND "+dao.BusCameraChineseStandard.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.BusCameraChineseStandardInfoRes
|
||||
err = m.Fields(system.BusCameraChineseStandardSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusCameraChineseStandardListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.BusCameraChineseStandardListRes{
|
||||
Id: v.Id,
|
||||
CountryNumber: v.CountryNumber,
|
||||
CountryName: v.CountryName,
|
||||
CountryState: v.CountryState,
|
||||
ProjectId: v.ProjectId,
|
||||
CreatedAt: v.CreatedAt,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusCameraChineseStandard) GetById(ctx context.Context, id int64) (res *model.BusCameraChineseStandardInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.BusCameraChineseStandard.Ctx(ctx).WithAll().Where(dao.BusCameraChineseStandard.Columns().Id, id).Scan(&res)
|
||||
//获取创建人 更新人
|
||||
by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
|
||||
infoRes := by.(model.BusCameraChineseStandardInfoRes)
|
||||
res = &infoRes
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusCameraChineseStandard) Add(ctx context.Context, req *system.BusCameraChineseStandardAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusCameraChineseStandard.Ctx(ctx).Insert(do.BusCameraChineseStandard{
|
||||
CountryNumber: req.CountryNumber,
|
||||
CountryName: req.CountryName,
|
||||
ProjectId: req.ProjectId,
|
||||
CreateBy: ct.New().GetLoginUser(ctx).Id,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusCameraChineseStandard) Edit(ctx context.Context, req *system.BusCameraChineseStandardEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusCameraChineseStandard.Ctx(ctx).WherePri(req.Id).Update(do.BusCameraChineseStandard{
|
||||
CountryNumber: req.CountryNumber,
|
||||
CountryName: req.CountryName,
|
||||
CountryState: req.CountryState,
|
||||
ProjectId: req.ProjectId,
|
||||
UpdateBy: ct.New().GetLoginUser(ctx).Id,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusCameraChineseStandard) Delete(ctx context.Context, ids []int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusCameraChannel.Ctx(ctx).Delete(dao.BusCameraChannel.Columns().CountryId+" in(?)", ids)
|
||||
_, err = dao.BusCameraChineseStandard.Ctx(ctx).Delete(dao.BusCameraChineseStandard.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user