初始
This commit is contained in:
@ -0,0 +1,218 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-08-14 11:24:31
|
||||
// 生成路径: internal/app/wxApplet/logic/bus_labourservice.go
|
||||
// 生成人:gfast
|
||||
// desc:劳务公司
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"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/wxApplet/wxApplet"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
|
||||
ct "github.com/tiger1103/gfast/v3/internal/app/system/logic/context"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/wxApplet/dao"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/wxApplet/model"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/wxApplet/model/do"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/wxApplet/service"
|
||||
"github.com/tiger1103/gfast/v3/library/liberr"
|
||||
tool "github.com/tiger1103/gfast/v3/utility/coryUtils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterBusLabourservice(New())
|
||||
}
|
||||
|
||||
func New() *sBusLabourservice {
|
||||
return &sBusLabourservice{}
|
||||
}
|
||||
|
||||
type sBusLabourservice struct{}
|
||||
|
||||
func (s *sBusLabourservice) PcAdd(ctx context.Context, req *wxApplet.BusPcAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, InsertErr := g.DB().Model("bus_labourservice_file").Data(&model.BusLabourserviceFileRes{
|
||||
Pid: req.Pid,
|
||||
Type: req.Type,
|
||||
Name: req.Name,
|
||||
Path: req.Path,
|
||||
}).Insert()
|
||||
liberr.ErrIsNil(ctx, InsertErr, "资料添加错误!")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusLabourservice) PcDel(ctx context.Context, req *wxApplet.BusPcDelReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := g.DB().Model("bus_labourservice_file").Where("id", req.Id).Safe()
|
||||
//1、查询数据
|
||||
path, err := m.Fields("path").Value()
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
//2、删除数据
|
||||
_, err = m.Delete()
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
//3、删除文件
|
||||
coryCommon.BatchFile(strings.Split(path.String(), ","))
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusLabourservice) PcFind(ctx context.Context, req *wxApplet.BusPcFindReq) (res *wxApplet.BusPcFindRes, err error) {
|
||||
res = new(wxApplet.BusPcFindRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
var fileRes []*model.BusLabourserviceFileRes
|
||||
err = g.DB().Model("bus_labourservice_file").Where("pid", req.Pid).Scan(&fileRes)
|
||||
res.List = fileRes
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusLabourservice) AppListOfParticipatingUnitsFunc(ctx context.Context, req *wxApplet.AppListOfParticipatingUnitsReq) (listRes *wxApplet.AppListOfParticipatingUnitsRes, err error) {
|
||||
listRes = new(wxApplet.AppListOfParticipatingUnitsRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusLabourservice.Ctx(ctx).WithAll()
|
||||
if req.FuzzyQuery != "" {
|
||||
m = m.Where(dao.BusLabourservice.Columns().Name+" like ?", "%"+req.FuzzyQuery+"%")
|
||||
}
|
||||
order := "name asc"
|
||||
var res []*model.BusLabourserviceInfoRes
|
||||
err = m.Fields(wxApplet.BusLabourserviceSearchRes{}).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusLabourserviceListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.BusLabourserviceListRes{
|
||||
Id: v.Id,
|
||||
Name: v.Name,
|
||||
Principal: v.Principal,
|
||||
Phone: v.Phone,
|
||||
Custodian: v.Custodian,
|
||||
CustodianPhone: v.CustodianPhone,
|
||||
CreatedAt: v.CreatedAt,
|
||||
Remark: v.Remark,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusLabourservice) List(ctx context.Context, req *wxApplet.BusLabourserviceSearchReq) (listRes *wxApplet.BusLabourserviceSearchRes, err error) {
|
||||
listRes = new(wxApplet.BusLabourserviceSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusLabourservice.Ctx(ctx).WithAll()
|
||||
if req.Name != "" {
|
||||
m = m.Where(dao.BusLabourservice.Columns().Name+" like ?", "%"+req.Name+"%")
|
||||
}
|
||||
//创建时间模糊查询
|
||||
if req.CreatedAt != "" {
|
||||
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
|
||||
m = m.Where(dao.BusLabourservice.Columns().CreatedAt+" like ?", "%"+date+"%")
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.BusLabourservice.Columns().CreatedAt+" >=? AND "+dao.BusLabourservice.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.BusLabourserviceInfoRes
|
||||
err = m.Fields(wxApplet.BusLabourserviceSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusLabourserviceListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.BusLabourserviceListRes{
|
||||
Id: v.Id,
|
||||
Name: v.Name,
|
||||
Principal: v.Principal,
|
||||
Phone: v.Phone,
|
||||
Custodian: v.Custodian,
|
||||
CustodianPhone: v.CustodianPhone,
|
||||
CreatedAt: v.CreatedAt,
|
||||
Remark: v.Remark,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusLabourservice) GetById(ctx context.Context, id int64) (res *model.BusLabourserviceInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.BusLabourservice.Ctx(ctx).WithAll().Where(dao.BusLabourservice.Columns().Id, id).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
//获取创建人 更新人
|
||||
by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
|
||||
infoRes := by.(model.BusLabourserviceInfoRes)
|
||||
res = &infoRes
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusLabourservice) Add(ctx context.Context, req *wxApplet.BusLabourserviceAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
columns := dao.BusLabourservice.Columns()
|
||||
//1、判断劳务公司是否重复
|
||||
count, countErr := dao.BusLabourservice.Ctx(ctx).Where(columns.Name, req.Name).Count()
|
||||
liberr.ErrIsNil(ctx, countErr, "获取劳务信息失败!")
|
||||
if count > 0 {
|
||||
liberr.ErrIsNil(ctx, errors.New("该劳务公司已存在!"))
|
||||
return
|
||||
}
|
||||
//2、添加劳务公司
|
||||
name := ct.New().GetLoginUser(ctx).Id
|
||||
_, errInsertInfo := dao.BusLabourservice.Ctx(ctx).Insert(do.BusLabourservice{
|
||||
Name: req.Name,
|
||||
Principal: req.Principal,
|
||||
Phone: req.Phone,
|
||||
Custodian: req.Custodian,
|
||||
CustodianPhone: req.CustodianPhone,
|
||||
Remark: req.Remark,
|
||||
CreateBy: name,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, errInsertInfo, "添加失败")
|
||||
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *sBusLabourservice) Edit(ctx context.Context, req *wxApplet.BusLabourserviceEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
//1、修改资料
|
||||
name := ct.New().GetLoginUser(ctx).Id
|
||||
_, err = dao.BusLabourservice.Ctx(ctx).WherePri(req.Id).Update(do.BusLabourservice{
|
||||
Name: req.Name,
|
||||
Principal: req.Principal,
|
||||
Phone: req.Phone,
|
||||
Custodian: req.Custodian,
|
||||
CustodianPhone: req.CustodianPhone,
|
||||
Remark: req.Remark,
|
||||
UpdateBy: name,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *sBusLabourservice) Delete(ctx context.Context, ids []int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusLabourservice.Ctx(ctx).Delete(dao.BusLabourservice.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user