初始
This commit is contained in:
322
internal/app/system/logic/busComplaintBox/bus_complaint_box.go
Normal file
322
internal/app/system/logic/busComplaintBox/bus_complaint_box.go
Normal file
@ -0,0 +1,322 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-12-04 18:09:50
|
||||
// 生成路径: internal/app/system/logic/bus_complaint_box.go
|
||||
// 生成人:gfast
|
||||
// desc:意见箱
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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/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"
|
||||
"github.com/tiger1103/gfast/v3/library/liberr"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterBusComplaintBox(New())
|
||||
}
|
||||
|
||||
func New() *sBusComplaintBox {
|
||||
return &sBusComplaintBox{}
|
||||
}
|
||||
|
||||
type sBusComplaintBox struct{}
|
||||
|
||||
func (s *sBusComplaintBox) AppletAdd(ctx context.Context, req *wxApplet.AppletComplaintBoxAddReq) (err error) {
|
||||
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
info, err := dao.BusComplaintBox.Ctx(ctx).Insert(do.BusComplaintBox{
|
||||
ProjectId: req.ProjectId,
|
||||
Openid: req.Openid,
|
||||
Opinion: req.Opinion,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
// 2、存储文件
|
||||
if len(req.File) > 0 {
|
||||
id, _ := info.LastInsertId()
|
||||
err = UploadAndSaveFunc(ctx, req.File, id) // 巡检
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
}
|
||||
})
|
||||
return err
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusComplaintBox) AppletList(ctx context.Context, req *wxApplet.AppletComplaintBoxSearchReq) (listRes *wxApplet.AppletComplaintBoxSearchRes, err error) {
|
||||
listRes = new(wxApplet.AppletComplaintBoxSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusComplaintBox.Ctx(ctx).As("a").
|
||||
LeftJoin("sys_project", "b", "a.openid = b.id").
|
||||
Fields("a.*,b.project_name,b.short_name").
|
||||
Where("a."+dao.BusComplaintBox.Columns().Openid+" = ?", req.Openid)
|
||||
if req.Status != "" {
|
||||
m = m.Where("a."+dao.BusComplaintBox.Columns().Status+" = ?", req.Status)
|
||||
}
|
||||
if req.Dispose != "" {
|
||||
m = m.Where("a."+dao.BusComplaintBox.Columns().Dispose+" = ?", gconv.Time(req.Dispose))
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where("a."+dao.BusComplaintBox.Columns().CreatedAt+" >=? AND "+"a."+dao.BusComplaintBox.Columns().CreatedAt+" <=?", req.DateRange[0], req.DateRange[1])
|
||||
}
|
||||
array, err2 := m.Array()
|
||||
listRes.Total = array
|
||||
liberr.ErrIsNil(ctx, err2, "获取总行数失败")
|
||||
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.BusComplaintBoxInfoRes
|
||||
err = m.Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusComplaintBoxListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.BusComplaintBoxListRes{
|
||||
Id: v.Id,
|
||||
ProjectId: v.ProjectId,
|
||||
Opinion: v.Opinion,
|
||||
Status: v.Status,
|
||||
Dispose: v.Dispose,
|
||||
CreatedAt: v.CreatedAt,
|
||||
ProjectName: v.ProjectName,
|
||||
ShortName: v.ShortName,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusComplaintBox) List(ctx context.Context, req *system.BusComplaintBoxSearchReq) (listRes *system.BusComplaintBoxSearchRes, err error) {
|
||||
listRes = new(system.BusComplaintBoxSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusComplaintBox.Ctx(ctx).WithAll().As("a").
|
||||
LeftJoin(dao.BusConstructionUser.Table(), "b", "a.openid = b.openid").
|
||||
Fields("a.*,b.phone")
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where("a."+dao.BusComplaintBox.Columns().ProjectId+" = ?", gconv.Int64(req.ProjectId))
|
||||
}
|
||||
if req.Openid != "" {
|
||||
m = m.Where("a."+dao.BusComplaintBox.Columns().Openid+" = ?", req.Openid)
|
||||
}
|
||||
if req.Status != "" {
|
||||
// m = m.Where("a."+dao.BusComplaintBox.Columns().Status+" = ?", req.Status)
|
||||
|
||||
// 如果 status 为 0 未读,那么 dispose 为 null
|
||||
if req.Status == "0" {
|
||||
m = m.Where("a." + dao.BusComplaintBox.Columns().Dispose + " is null")
|
||||
}
|
||||
|
||||
if req.Status == "1" {
|
||||
m = m.Where("a." + dao.BusComplaintBox.Columns().Dispose + " is not null")
|
||||
}
|
||||
}
|
||||
// if req.Dispose != "" {
|
||||
// m = m.Where("a."+dao.BusComplaintBox.Columns().Dispose+" = ?", gconv.Time(req.Dispose))
|
||||
// }
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where("a."+dao.BusComplaintBox.Columns().CreatedAt+" >=? AND "+dao.BusComplaintBox.Columns().CreatedAt+" <=?", req.DateRange[0], req.DateRange[1])
|
||||
}
|
||||
|
||||
if req.Phone != "" {
|
||||
m = m.Where("b.phone", req.Phone)
|
||||
}
|
||||
|
||||
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 := "id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.BusComplaintBoxInfoRes
|
||||
err = m.Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusComplaintBoxListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.BusComplaintBoxListRes{
|
||||
Id: v.Id,
|
||||
ProjectId: v.ProjectId,
|
||||
Openid: v.Openid,
|
||||
Opinion: v.Opinion,
|
||||
Status: v.Status,
|
||||
Dispose: v.Dispose,
|
||||
Remark: v.Remark,
|
||||
CreatedAt: v.CreatedAt,
|
||||
Phone: v.Phone,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusComplaintBox) GetById(ctx context.Context, id int64) (res *model.BusComplaintBoxInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
// 1、获取数据
|
||||
err = dao.BusComplaintBox.Ctx(ctx).WithAll().Where(dao.BusComplaintBox.Columns().Id, id).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
// 2、获取附件下的附件信息
|
||||
var fjEntity []*model.FileEntityRes
|
||||
err = g.DB().Model("bus_complaint_box_path").Ctx(ctx).Where("ticket_id", id).Scan(&fjEntity)
|
||||
liberr.ErrIsNil(ctx, err, "获取附近信息失败")
|
||||
res.FileEntityList = fjEntity
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
//func (s *sBusComplaintBox) Add(ctx context.Context, req *system.BusComplaintBoxAddReq) (err error) {
|
||||
// err = g.Try(ctx, func(ctx context.Context) {
|
||||
// _, err = dao.BusComplaintBox.Ctx(ctx).Insert(do.BusComplaintBox{
|
||||
// ProjectId: req.ProjectId,
|
||||
// Openid: req.Openid,
|
||||
// Opinion: req.Opinion,
|
||||
// })
|
||||
// liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
// })
|
||||
// return
|
||||
//}
|
||||
|
||||
func (s *sBusComplaintBox) Edit(ctx context.Context, req *system.BusComplaintBoxEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusComplaintBox.Ctx(ctx).WherePri(req.Id).Update(do.BusComplaintBox{
|
||||
ProjectId: req.ProjectId,
|
||||
Openid: req.Openid,
|
||||
Opinion: req.Opinion,
|
||||
Status: req.Status,
|
||||
Dispose: req.Dispose,
|
||||
Remark: req.Remark,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusComplaintBox) Delete(ctx context.Context, ids []int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
// 1、获取当前需要删除数据的附件
|
||||
array, _ := g.DB().Model("bus_complaint_box_path").Ctx(ctx).Where("ticket_id in (?)", ids).Fields("path").Array()
|
||||
if len(array) > 0 {
|
||||
var filePath []string
|
||||
for i := range array {
|
||||
filePath = append(filePath, array[i].String())
|
||||
}
|
||||
coryCommon.BatchFile(filePath)
|
||||
}
|
||||
// 3、删除数据
|
||||
_, err = dao.BusComplaintBox.Ctx(ctx).Delete(dao.BusComplaintBox.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
type FileEntity struct {
|
||||
TicketId int64 `p:"ticket_id" dc:"主键ID"`
|
||||
Name string `p:"name" dc:"文件名称"`
|
||||
Path string `p:"path" dc:"文件路径"`
|
||||
FileType string `p:"file_type" dc:"文件类型(后缀)"`
|
||||
}
|
||||
|
||||
// UploadAndSaveFunc 上传并存储文件
|
||||
func UploadAndSaveFunc(ctx context.Context, File []*wxApplet.Files, id int64) (err error) {
|
||||
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
// 2、获取文件数据,然后对文件进行上传
|
||||
var fileEntitys []*FileEntity
|
||||
for i := range File {
|
||||
rpath := coryCommon.FileToFunc(File[i].Path, 2)
|
||||
_, ext, _ := coryCommon.FileInfo(rpath)
|
||||
entity := FileEntity{
|
||||
TicketId: id,
|
||||
Name: File[i].Name,
|
||||
Path: File[i].Path,
|
||||
FileType: ext,
|
||||
}
|
||||
fileEntitys = append(fileEntitys, &entity)
|
||||
}
|
||||
// 3、上传文件的附件信息
|
||||
_, err = g.DB().Model("bus_complaint_box_path").Ctx(ctx).Insert(fileEntitys)
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return err
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
//// UploadAndSaveFunc 上传并存储文件
|
||||
//func UploadAndSaveFunc(ctx context.Context, File []*ghttp.UploadFile, id int64) (err error) {
|
||||
// err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
// err = g.Try(ctx, func(ctx context.Context) {
|
||||
// //2、获取文件数据,然后对文件进行上传
|
||||
// var fileEntitys []*FileEntity
|
||||
// for i := range File {
|
||||
// str, err := coryCommon.UploadFileTwo(ctx, File[i], coryCommon.Helmet)
|
||||
// liberr.ErrIsNil(ctx, err, "上传附件失败!")
|
||||
// str = filepath.ToSlash(str)
|
||||
// rpath := coryCommon.ResourcePublicToFunc("/"+str, 0)
|
||||
// _, ext, _ := coryCommon.FileInfo(rpath)
|
||||
// entity := FileEntity{
|
||||
// TicketId: id,
|
||||
// Name: File[i].Filename,
|
||||
// Path: rpath,
|
||||
// FileType: ext,
|
||||
// }
|
||||
// fileEntitys = append(fileEntitys, &entity)
|
||||
// }
|
||||
// //3、上传文件的附件信息
|
||||
// _, err = g.DB().Model("bus_complaint_box_path").Ctx(ctx).Insert(fileEntitys)
|
||||
// liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
// })
|
||||
// return err
|
||||
// })
|
||||
// return err
|
||||
//}
|
||||
|
||||
//// ComplaintBoxPath 附件新增
|
||||
//func ComplaintBoxPath(ctx context.Context, fileInfo []*comModel.UpFile, id int64) (err error) {
|
||||
// err = g.Try(ctx, func(ctx context.Context) {
|
||||
// //2、获取文件数据,然后对文件进行上传
|
||||
// var fileEntitys []*FileEntity
|
||||
// for i := range fileInfo {
|
||||
// rpath := coryCommon.FileToFunc(filepath.ToSlash(fileInfo[i].Url), 3)
|
||||
// entity := FileEntity{
|
||||
// TicketId: id,
|
||||
// Name: fileInfo[i].Name,
|
||||
// Path: rpath,
|
||||
// FileType: fileInfo[i].FileType,
|
||||
// }
|
||||
// fileEntitys = append(fileEntitys, &entity)
|
||||
// }
|
||||
// //3、上传文件的附件信息
|
||||
// _, err = g.DB().Model("bus_complaint_box_path").Ctx(ctx).Insert(fileEntitys)
|
||||
// liberr.ErrIsNil(ctx, err, "意见反馈附件上传失败")
|
||||
// })
|
||||
// return
|
||||
//}
|
||||
Reference in New Issue
Block a user