初始
This commit is contained in:
156
internal/app/system/logic/busCompany/bus_company.go
Normal file
156
internal/app/system/logic/busCompany/bus_company.go
Normal file
@ -0,0 +1,156 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-07-28 14:08:14
|
||||
// 生成路径: internal/app/system/logic/bus_company.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.RegisterBusCompany(New())
|
||||
}
|
||||
|
||||
func New() *sBusCompany {
|
||||
return &sBusCompany{}
|
||||
}
|
||||
|
||||
type sBusCompany struct{}
|
||||
|
||||
func (s *sBusCompany) List(ctx context.Context, req *system.BusCompanySearchReq) (listRes *system.BusCompanySearchRes, err error) {
|
||||
listRes = new(system.BusCompanySearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusCompany.Ctx(ctx).WithAll()
|
||||
if req.CompanyId != "" {
|
||||
m = m.Where(dao.BusCompany.Columns().CompanyId+" = ?", req.CompanyId)
|
||||
}
|
||||
if req.CompanyName != "" {
|
||||
m = m.Where(dao.BusCompany.Columns().CompanyName+" like ?", "%"+req.CompanyName+"%")
|
||||
}
|
||||
if req.Status != "" {
|
||||
m = m.Where(dao.BusCompany.Columns().Status+" = ?", req.Status)
|
||||
}
|
||||
if req.CreatedAt != "" {
|
||||
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
|
||||
m = m.Where(dao.BusCompany.Columns().CreatedAt+" like ?", "%"+date+"%")
|
||||
}
|
||||
//if len(req.DateRange) != 0 {
|
||||
// m = m.Where(dao.BusCompany.Columns().CreatedAt+" >=? AND "+dao.BusCompany.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 := "company_id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.BusCompanyInfoRes
|
||||
err = m.Fields(system.BusCompanySearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusCompanyListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.BusCompanyListRes{
|
||||
CompanyId: v.CompanyId,
|
||||
CompanyName: v.CompanyName,
|
||||
Status: v.Status,
|
||||
CreateBy: v.CreateBy,
|
||||
UpdateBy: v.UpdateBy,
|
||||
CreatedAt: v.CreatedAt,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusCompany) GetByCompanyId(ctx context.Context, companyId int64) (res *model.BusCompanyInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.BusCompany.Ctx(ctx).WithAll().Where(dao.BusCompany.Columns().CompanyId, companyId).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
//获取创建人 更新人
|
||||
by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
|
||||
infoRes := by.(model.BusCompanyInfoRes)
|
||||
res = &infoRes
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusCompany) Add(ctx context.Context, req *system.BusCompanyAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
name := ct.New().GetLoginUser(ctx).Id
|
||||
_, err = dao.BusCompany.Ctx(ctx).Insert(do.BusCompany{
|
||||
CompanyName: req.CompanyName,
|
||||
Status: req.Status,
|
||||
CreateBy: name,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusCompany) Edit(ctx context.Context, req *system.BusCompanyEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
name := ct.New().GetLoginUser(ctx).Id
|
||||
_, err = dao.BusCompany.Ctx(ctx).WherePri(req.CompanyId).Update(do.BusCompany{
|
||||
CompanyName: req.CompanyName,
|
||||
Status: req.Status,
|
||||
UpdateBy: name,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusCompany) Delete(ctx context.Context, companyIds []int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusCompany.Ctx(ctx).Delete(dao.BusCompany.Columns().CompanyId+" in (?)", companyIds)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
//app
|
||||
|
||||
func (s *sBusCompany) AppList(ctx context.Context, req *system.BusCompanyAppSearchReq) (listRes *system.BusCompanyAppSearchRes, err error) {
|
||||
listRes = new(system.BusCompanyAppSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusCompany.Ctx(ctx).WithAll().Where(dao.BusCompany.Columns().Status+" != ?", 1) //1停用 0正常使用
|
||||
listRes.Total, err = m.Count()
|
||||
liberr.ErrIsNil(ctx, err, "获取总行数失败")
|
||||
order := "company_id desc"
|
||||
var res []*model.BusCompanyAppListRes
|
||||
err = m.Fields(system.BusCompanyAppSearchRes{}).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusCompanyAppListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.BusCompanyAppListRes{
|
||||
CompanyId: v.CompanyId,
|
||||
CompanyName: v.CompanyName,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user