This commit is contained in:
2025-07-07 20:11:59 +08:00
parent ab0fdbc447
commit 06e3aa2eb3
2009 changed files with 193082 additions and 0 deletions

View File

@ -0,0 +1,966 @@
// ==========================================================================
// GFast自动生成logic操作代码。
// 生成日期2023-11-20 11:18:37
// 生成路径: internal/app/system/logic/bus_violation_record.go
// 生成人gfast
// desc:违章记录
// company:云南奇讯科技有限公司
// ==========================================================================
package logic
import (
"context"
"errors"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/util/gmeta"
"github.com/jinzhu/copier"
"github.com/tiger1103/gfast/v3/api/v1/common/coryCommon"
"github.com/tiger1103/gfast/v3/api/v1/system"
wxSystem "github.com/tiger1103/gfast/v3/api/wxApplet/wxApplet"
comModel "github.com/tiger1103/gfast/v3/internal/app/common/model"
"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"
"github.com/tiger1103/gfast/v3/third/reminders"
tool "github.com/tiger1103/gfast/v3/utility/coryUtils"
"sort"
"strconv"
"strings"
"time"
)
func init() {
service.RegisterBusViolationRecord(New())
}
func New() *sBusViolationRecord {
return &sBusViolationRecord{}
}
type sBusViolationRecord struct{}
func (s *sBusViolationRecord) AppSafetyHazardTodayFunc(ctx context.Context, req *wxSystem.AppSafetyHazardTodayReq) (listRes *wxSystem.AppSafetyHazardTodayRes, err error) {
listRes = new(wxSystem.AppSafetyHazardTodayRes)
err = g.Try(ctx, func(ctx context.Context) {
//2、查询违章记录
var listEnity []*model.AppWorkOrderPcListLogicRes
m := dao.BusViolationRecord.Ctx(ctx).As("a").
LeftJoin("sys_dict_data", "b", "b.dict_type = 'tour_type' and b.dict_value = a.tour_type").
LeftJoin("sys_dict_data", "c", "c.dict_type = 'violation_record_data_source' and c.dict_value = a.data_source").
LeftJoin("sys_project", "d", "d.id = a.project_id").
Fields("a.id,a.created_at,b.dict_label as tt,c.dict_label as ds,d.project_name as projectName")
if req.FuzzyQuery != "" { //模糊查询
array, _ := g.DB().Model("sys_dict_data").Ctx(ctx).
Where("dict_type", "tour_type").
Where("dict_label like ?", "%"+req.FuzzyQuery+"%").Fields("dict_value").Array()
m = m.Where("a.tour_type in (?)", array)
}
if req.DateQuery != "" {
m = m.Where("DATE_FORMAT( a.created_at, '%Y-%m-%d' ) = ?", req.DateQuery)
}
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 := "a.created_at desc"
if req.OrderBy != "" {
order = req.OrderBy
}
err = m.Page(req.PageNum, req.PageSize).Order(order).Scan(&listEnity)
liberr.ErrIsNil(ctx, err)
// 获取附件信息(通知)
for i := range listEnity {
var entity []*model.BusViolationRecordPathLogicRes
g.DB().Model("bus_violation_record_path").Ctx(ctx).
Where("ticket_id", listEnity[i].Id).
Where("type", 1).
Fields("path").Scan(&entity)
listEnity[i].CheckAttachment = entity
}
listRes.List = listEnity
})
return
}
func (s *sBusViolationRecord) AppWorkOrderAppListFunc(ctx context.Context, req *wxSystem.AppWorkOrderAppListReq) (listRes *wxSystem.AppWorkOrderPcListRes, err error) {
listRes = new(wxSystem.AppWorkOrderPcListRes)
err = g.Try(ctx, func(ctx context.Context) {
//2、查询违章记录
var listEnity []*model.AppWorkOrderPcListLogicRes
m := dao.BusViolationRecord.Ctx(ctx).As("a").
LeftJoin("sys_dict_data", "b", "b.dict_type = 'tour_type' and b.dict_value = a.tour_type").
LeftJoin("sys_dict_data", "c", "c.dict_type = 'violation_record_data_source' and c.dict_value = a.data_source").
LeftJoin("sys_project", "d", "d.id = a.project_id").
Fields("a.*,b.dict_label as tt,c.dict_label as ds,d.project_name as projectName").
Where("a.openid", req.Openid).
Where("a.project_id", req.ProjectId).
Where("a.pid", 0)
if req.FuzzyQuery != "" { //模糊查询
array, _ := g.DB().Model("sys_dict_data").Ctx(ctx).
Where("dict_type", "tour_type").
Where("dict_label like ?", "%"+req.FuzzyQuery+"%").Fields("dict_value").Array()
m = m.Where("a.tour_type in (?)", array)
}
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 := "a.status asc"
if req.OrderBy != "" {
order = req.OrderBy
}
err = m.Page(req.PageNum, req.PageSize).Order(order).Scan(&listEnity)
liberr.ErrIsNil(ctx, err)
//3、获取
for i := range listEnity {
//当前工单如若被拒绝那么就查询当前工单下最新的数据信息然后把当前数据给替换掉主要替换id、状态
if listEnity[i].ReviewType == "2" {
type zdmp struct {
gmeta.Meta `orm:"table:bus_violation_record"`
Id int64 `orm:"id" json:"id"`
ReviewType string `orm:"review_type" json:"reviewType"`
}
var zdmpData []zdmp
mysql := dao.BusViolationRecord.Ctx(ctx).As("a").
Where("a.pid", listEnity[i].Id).Safe()
if err := mysql.Fields("a.id,a.review_type").Scan(&zdmpData); err != nil {
liberr.ErrIsNil(ctx, err, "无法获取安全工单拒绝数据")
return
} else {
for i2 := range zdmpData {
if zdmpData[i2].ReviewType == "" || zdmpData[i2].ReviewType == "1" {
zdmpData[i2].ReviewType = "true"
} else {
zdmpData[i2].ReviewType = "false"
}
}
zdmpData = append(zdmpData, zdmp{
Id: listEnity[i].Id,
ReviewType: "false",
})
sort.Slice(zdmpData, func(i, j int) bool {
return zdmpData[i].Id > zdmpData[j].Id
})
listEnity[i].RefuseList = zdmpData
}
type zd struct {
gmeta.Meta `orm:"table:bus_hse_management"`
Id int64 `orm:"id" json:"id"`
Status string `orm:"status" json:"status"`
}
zdData := new(zd)
err := mysql.
Where("(a.review_type != '2') OR (a.review_type IS NULL)").
Fields("a.id,a.status").
Scan(&zdData)
if err == nil {
listEnity[i].Id = zdData.Id
listEnity[i].Status = zdData.Status
listEnity[i].ReviewType = ""
} else {
liberr.ErrIsNil(ctx, err, "无法获取安全工单转换数据")
return
}
}
if listEnity[i].Openid != "" { //获取处理人名称
value, _ := dao.BusConstructionUser.Ctx(ctx).Where("openid", listEnity[i].Openid).Fields("user_name").Value()
listEnity[i].OpenidName = value.String()
}
if listEnity[i].Status == "3" { //复查人名称
value, _ := dao.SysUser.Ctx(ctx).Where("id", listEnity[i].SelectPeople).Fields("user_nickname").Value()
listEnity[i].ReviewName = value.String()
}
i2, _ := g.DB().Model("bus_violation_record_correlation").Ctx(ctx).
Where("a.record_id", listEnity[i].Id).As("a").
LeftJoin(dao.SysUser.Table(), "b", "b.id = a.user_id").
Fields("b.user_nickname").Array()
for i3 := range i2 { //哪些人可以复查(只需有一个复查就行了)
listEnity[i].SuperintendName = append(listEnity[i].SuperintendName, i2[i3].String())
}
}
listRes.List = listEnity
})
return
}
func (s *sBusViolationRecord) AppReviewFuncFunc(ctx context.Context, req *wxSystem.AppReviewReq) (err error) {
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.BusViolationRecord.Ctx(ctx).WherePri(req.Id).Update(do.BusViolationRecord{
ReviewType: req.ReviewType,
Status: "3",
ReviewTime: gtime.New(time.Now()),
Review: req.Review,
UpdateBy: req.Operator,
})
liberr.ErrIsNil(ctx, err, "复查失败")
//如果拒绝那么就重新写入当前数据到整改人
var aData model.BusViolationRecordInfoRes
err = dao.BusViolationRecord.Ctx(ctx).WherePri(req.Id).Scan(&aData)
if req.ReviewType == "2" {
bData := new(model.RefuseToAddRes)
if err := copier.Copy(bData, aData); err != nil {
liberr.ErrIsNil(ctx, err)
return
}
if aData.Pid == 0 {
bData.Pid = aData.Id
} else {
bData.Pid = aData.Pid
}
bData.Status = "1"
_, resultErr := dao.BusViolationRecord.Ctx(ctx).OmitEmpty().Insert(bData)
if resultErr != nil {
liberr.ErrIsNil(ctx, resultErr)
return
}
}
err = AiNotificationFunc(ctx, req.Id, reminders.Recheck)
if err != nil {
liberr.ErrIsNil(ctx, err)
}
})
return err
})
return
}
func (s *sBusViolationRecord) AppRectificationReplyFunc(ctx context.Context, req *wxSystem.AppRectificationReplyReq) (err error) {
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.BusViolationRecord.Ctx(ctx).WherePri(req.Id).Update(do.BusViolationRecord{
Status: "2",
RectificationTime: gtime.New(time.Now()),
UpdateBy: ct.New().GetLoginUser(ctx).OpenId,
})
liberr.ErrIsNil(ctx, err, "整改回复失败")
if len(req.File) > 0 {
err = SaveFunc(ctx, req.File, req.Id, "2")
liberr.ErrIsNil(ctx, err, "整改附件存储失败")
}
err = AiNotificationFunc(ctx, req.Id, reminders.Reform)
if err != nil {
liberr.ErrIsNil(ctx, err)
}
})
return err
})
return
}
func (s *sBusViolationRecord) AppWorkOrderParticularsFunc(ctx context.Context, req *wxSystem.AppWorkOrderParticularsReq) (enity *wxSystem.AppWorkOrderParticularsRes, err error) {
err = g.Try(ctx, func(ctx context.Context) {
//1、获取主体信息
err = dao.BusViolationRecord.Ctx(ctx).As("a").
LeftJoin("sys_dict_data", "b", "b.dict_type = 'tour_type' and b.dict_value = a.tour_type").
LeftJoin("sys_dict_data", "c", "c.dict_type = 'violation_record_data_source' and c.dict_value = a.data_source").
LeftJoin("sys_project", "d", "d.id = a.project_id").
Fields("a.*,b.dict_label as tt,c.dict_label as ds,d.project_name as projectName").
Where("a.id", req.Id).Scan(&enity)
liberr.ErrIsNil(ctx, err, "获取当前AI数据失败")
if enity.Openid != "" { //获取处理人名称
value, _ := dao.BusConstructionUser.Ctx(ctx).Where("openid", enity.Openid).Fields("user_name").Value()
enity.OpenidName = value.String()
}
if enity.Status == "3" { //复查人名称
value, _ := dao.SysUser.Ctx(ctx).Where("id", enity.SelectPeople).Fields("user_nickname").Value()
enity.ReviewName = value.String()
}
i2, _ := g.DB().Model("bus_violation_record_correlation").Ctx(ctx).
Where("a.record_id", enity.Id).As("a").
LeftJoin(dao.SysUser.Table(), "b", "b.id = a.user_id").
Fields("b.user_nickname").Array()
for i3 := range i2 { //哪些人可以复查(只需有一个复查就行了)
enity.SuperintendName = append(enity.SuperintendName, i2[i3].String())
}
//2、获取附件
var pathEntity []*model.BusViolationRecordPathLogicRes
err = g.DB().Model("bus_violation_record_path").Ctx(ctx).Where("ticket_id", req.Id).Scan(&pathEntity)
liberr.ErrIsNil(ctx, err, "查询失败")
//3、分类附件
var one []*model.BusViolationRecordPathLogicRes
var two []*model.BusViolationRecordPathLogicRes
for i := range pathEntity {
if pathEntity[i].Type == "1" {
one = append(one, pathEntity[i])
} else {
two = append(two, pathEntity[i])
}
}
enity.CheckAttachment = one
enity.AbarbeitungAttachment = two
})
return
}
func (s *sBusViolationRecord) AppWorkOrderPcListFunc(ctx context.Context, req *wxSystem.AppWorkOrderPcListReq) (listRes *wxSystem.AppWorkOrderPcListRes, err error) {
var uid = int64(ct.New().GetLoginUser(ctx).Id)
listRes = new(wxSystem.AppWorkOrderPcListRes)
err = g.Try(ctx, func(ctx context.Context) {
//1、查看当前pc用户需要督察哪些违章记录
var ids []int64
values, err := g.DB().Model("bus_violation_record_correlation").Ctx(ctx).Where("user_id", req.PcUserId).Fields("record_id").Array()
liberr.ErrIsNil(ctx, err, "获取当前AI数据失败")
if len(values) == 0 {
return
} else {
for i := range values {
ids = append(ids, values[i].Int64())
}
}
//2、查询违章记录
var listEnity []*model.AppWorkOrderPcListLogicRes
m := dao.BusViolationRecord.Ctx(ctx).As("a").
LeftJoin("sys_dict_data", "b", "b.dict_type = 'tour_type' and b.dict_value = a.tour_type").
LeftJoin("sys_dict_data", "c", "c.dict_type = 'violation_record_data_source' and c.dict_value = a.data_source").
LeftJoin("sys_project", "d", "d.id = a.project_id").
Fields("a.*,b.dict_label as tt,c.dict_label as ds,d.project_name as projectName").
Where("a.project_id", req.ProjectId).
Where("a.id in (?)", ids)
if req.FuzzyQuery != "" { //模糊查询
array, _ := g.DB().Model("sys_dict_data").Ctx(ctx).
Where("dict_type", "tour_type").
Where("dict_label like ?", "%"+req.FuzzyQuery+"%").Fields("dict_value").Array()
m = m.Where("a.tour_type in (?)", array)
}
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 := "a.status asc"
if req.OrderBy != "" {
order = req.OrderBy
}
err = m.Page(req.PageNum, req.PageSize).Order(order).Scan(&listEnity)
liberr.ErrIsNil(ctx, err)
//3、获取
for i := range listEnity {
//当前工单如若被拒绝那么就查询当前工单下最新的数据信息然后把当前数据给替换掉主要替换id、状态
if listEnity[i].ReviewType == "2" {
type zdmp struct {
gmeta.Meta `orm:"table:bus_violation_record"`
Id int64 `orm:"id" json:"id"`
ReviewType string `orm:"review_type" json:"reviewType"`
}
var zdmpData []zdmp
mysql := dao.BusViolationRecord.Ctx(ctx).As("a").
Where("a.pid", listEnity[i].Id).Safe()
if err := mysql.Fields("a.id,a.review_type").Scan(&zdmpData); err != nil {
liberr.ErrIsNil(ctx, err, "无法获取安全工单拒绝数据")
return
} else {
for i2 := range zdmpData {
if zdmpData[i2].ReviewType == "" || zdmpData[i2].ReviewType == "1" {
zdmpData[i2].ReviewType = "true"
} else {
zdmpData[i2].ReviewType = "false"
}
}
zdmpData = append(zdmpData, zdmp{
Id: listEnity[i].Id,
ReviewType: "false",
})
sort.Slice(zdmpData, func(i, j int) bool {
return zdmpData[i].Id > zdmpData[j].Id
})
listEnity[i].RefuseList = zdmpData
}
type zd struct {
gmeta.Meta `orm:"table:bus_hse_management"`
Id int64 `orm:"id" json:"id"`
Status string `orm:"status" json:"status"`
}
zdData := new(zd)
err := mysql.
Where("(a.review_type != '2') OR (a.review_type IS NULL)").
Fields("a.id,a.status").
Scan(&zdData)
if err == nil {
listEnity[i].Id = zdData.Id
listEnity[i].Status = zdData.Status
listEnity[i].ReviewType = ""
} else {
liberr.ErrIsNil(ctx, err, "无法获取安全工单转换数据")
return
}
}
if listEnity[i].Openid != "" { //获取处理人名称
value, _ := dao.BusConstructionUser.Ctx(ctx).Where("openid", listEnity[i].Openid).Fields("user_name").Value()
listEnity[i].OpenidName = value.String()
}
if listEnity[i].Status == "3" { //复查人名称
value, _ := dao.SysUser.Ctx(ctx).Where("id", listEnity[i].SelectPeople).Fields("user_nickname").Value()
listEnity[i].ReviewName = value.String()
}
i2, _ := g.DB().Model("bus_violation_record_correlation").Ctx(ctx).
Where("a.record_id", listEnity[i].Id).As("a").
LeftJoin(dao.SysUser.Table(), "b", "b.id = a.user_id").
Fields("b.user_nickname").Array()
for i3 := range i2 { //哪些人可以复查(只需有一个复查就行了)
listEnity[i].SuperintendName = append(listEnity[i].SuperintendName, i2[i3].String())
}
// 判断当前人是否可以进行复查
if listEnity[i].SelectPeople == uid {
listEnity[i].IsReview = true
} else {
listEnity[i].IsReview = false
}
}
listRes.List = listEnity
})
return
}
func (s *sBusViolationRecord) AppGetsAllThePeopleUnderTheCurrentPersonsProjectFunc(ctx context.Context, req *wxSystem.AppGetsAllThePeopleUnderTheCurrentPersonsProjectReq) (listRes *wxSystem.AppGetsAllThePeopleUnderTheCurrentPersonsProjectRes, err error) {
listRes = new(wxSystem.AppGetsAllThePeopleUnderTheCurrentPersonsProjectRes)
err = g.Try(ctx, func(ctx context.Context) {
//1、获取当前人的项目ID
value, _ := dao.BusConstructionUser.Ctx(ctx).Where("openid", req.Openid).Fields("projectId").Value()
liberr.ErrIsNil(ctx, err)
//2、获取当前项目下的所有人头像、名称、电话
m := dao.BusConstructionUser.Ctx(ctx).Where("project_id", value.String()).Fields("openid,pace_photo,user_name,phone")
if req.Name != "" {
m = m.Where(dao.BusConstructionUser.Columns().UserName+" like ?", "%"+req.Name+"%")
}
//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 := "user_name asc"
//if req.OrderBy != "" {
// order = req.OrderBy
//}
var personnelList []*wxSystem.AppPersonnelListRes
//err = m.Page(req.PageNum, req.PageSize).Order(order).Scan(&personnelList)
err = m.Scan(&personnelList)
liberr.ErrIsNil(ctx, err)
listRes.List = personnelList
})
return
}
func (s *sBusViolationRecord) AppAiInformFunc(ctx context.Context, req *wxSystem.AppAiInformReq) (err error) {
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.BusViolationRecord.Ctx(ctx).WherePri(req.Id).OmitEmpty().Update(do.BusViolationRecord{
ProcessingPeriod: req.ProcessingPeriod,
Openid: req.Openid,
Remark: req.Remark,
SelectPeople: ct.New().GetLoginUser(ctx).Id,
UpdateBy: ct.New().GetLoginUser(ctx).OpenId,
})
liberr.ErrIsNil(ctx, err, "选择处理人失败!")
err = AiNotificationFunc(ctx, req.Id, reminders.Remind)
if err != nil {
liberr.ErrIsNil(ctx, err)
}
})
return err
})
return
}
func (s *sBusViolationRecord) WxDetails(ctx context.Context, req *wxSystem.WxBusViolationRecordDetailsReq) (res *wxSystem.WxBusViolationRecordDetailsRes, err error) {
err = dao.BusViolationRecord.Ctx(ctx).As("a").
LeftJoin("bus_construction_user", "b", "a.openid = b.openid").
Fields("a.*,b.nick_name,b.user_name").Where("a.id", req.Id).Scan(&res)
return
}
func (s *sBusViolationRecord) SelectTheViolatorFunc(ctx context.Context, req *system.BSelectTheViolatorReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
i := ct.New().GetLoginUser(ctx).Id
_, err = dao.BusViolationRecord.Ctx(ctx).WherePri(req.Id).Update(do.BusViolationRecord{
ProcessingPeriod: req.ProcessingPeriod,
Openid: req.Openid,
Remark: req.Remark,
UpdateBy: i,
SelectPeople: i,
})
liberr.ErrIsNil(ctx, err, "修改失败")
id, _ := strconv.ParseInt(req.Id, 10, 64)
err = AiNotificationFunc(ctx, id, reminders.Remind)
if err != nil {
liberr.ErrIsNil(ctx, err)
}
})
return
}
func (s *sBusViolationRecord) WxEdit(ctx context.Context, req *wxSystem.BusViolationRecordEditReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.BusViolationRecord.Ctx(ctx).WherePri(req.Id).Update(do.BusViolationRecord{
//IsDispose: req.IsDispose,
//WxOrPc: req.WxOrPc,
UpdateBy: req.Openid,
})
liberr.ErrIsNil(ctx, err, "修改失败")
})
return
}
func (s *sBusViolationRecord) WxListTwo(ctx context.Context, req *wxSystem.BusViolationRecordSearchTwoReq) (listRes *wxSystem.BusViolationRecordSearchTwoRes, err error) {
listRes = new(wxSystem.BusViolationRecordSearchTwoRes)
err = g.Try(ctx, func(ctx context.Context) {
m := dao.BusViolationRecord.Ctx(ctx).As("a").
LeftJoin("bus_construction_user", "b", "a.openid = b.openid").
Fields("a.*,b.nick_name,b.user_name").Where("a.wx_or_pc = 2").Where("a.create_by", req.Openid)
if req.TourType != "" {
m = m.Where("a."+dao.BusViolationRecord.Columns().TourType+" = ?", req.TourType)
}
if req.IsDispose != "" {
m = m.Where("a."+dao.BusViolationRecord.Columns().IsDispose+" = ?", req.IsDispose)
}
//创建时间模糊查询
if req.CreatedAt != "" {
//date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
m = m.Where("a."+dao.BusViolationRecord.Columns().CreatedAt+" like ?", "%"+req.CreatedAt+"%")
}
if len(req.DateRange) != 0 {
m = m.Where("a."+dao.BusViolationRecord.Columns().CreatedAt+" >=? AND "+"a."+dao.BusViolationRecord.Columns().CreatedAt+" <=?", req.DateRange[0], req.DateRange[1])
}
array, _ := m.Array()
listRes.Total = len(array)
liberr.ErrIsNil(ctx, err, "获取总行数失败")
if req.PageNum == 0 {
req.PageNum = 1
}
listRes.CurrentPage = req.PageNum
if req.PageSize == 0 {
req.PageSize = consts.PageSize
}
order := "a.is_dispose asc,a.id desc"
if req.OrderBy != "" {
order = req.OrderBy
}
var res []*model.BusViolationRecordInfoRes
err = m.Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
liberr.ErrIsNil(ctx, err, "获取数据失败")
listRes.List = make([]*model.BusViolationRecordListRes, len(res))
for k, v := range res {
//if v.Picture == "" {
// v.Picture = v.PictureTwo
//}
listRes.List[k] = &model.BusViolationRecordListRes{
Id: v.Id,
ProjectId: v.ProjectId,
Openid: v.Openid,
TourType: v.TourType,
//IsDispose: v.IsDispose,
CreatedAt: v.CreatedAt,
//LaborDate: v.LaborDate,
NickName: v.NickName,
UserName: v.UserName,
//Picture: v.Picture,
UpdatedAt: v.UpdatedAt,
Remark: v.Remark,
}
}
})
return
}
func (s *sBusViolationRecord) WxList(ctx context.Context, req *wxSystem.BusViolationRecordSearchReq) (listRes *wxSystem.BusViolationRecordSearchRes, err error) {
listRes = new(wxSystem.BusViolationRecordSearchRes)
err = g.Try(ctx, func(ctx context.Context) {
m := dao.BusViolationRecord.Ctx(ctx).As("a").
LeftJoin("bus_construction_user", "b", "a.openid = b.openid").
LeftJoin("bus_tour", "c", "a.tour_id = c.id").
Fields("a.*,b.nick_name,c.picture as pictureTwo")
if req.TourType != "" {
m = m.Where("a."+dao.BusViolationRecord.Columns().TourType+" = ?", req.TourType)
}
if req.IsDispose != "" {
m = m.Where("a."+dao.BusViolationRecord.Columns().IsDispose+" = ?", req.IsDispose)
}
if req.Openid != "" {
m = m.Where("a."+dao.BusViolationRecord.Columns().Openid+" = ?", req.Openid)
}
//创建时间模糊查询
if req.CreatedAt != "" {
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
m = m.Where("a."+dao.BusViolationRecord.Columns().CreatedAt+" like ?", "%"+date+"%")
}
if len(req.DateRange) != 0 {
m = m.Where("a."+dao.BusViolationRecord.Columns().CreatedAt+" >=? AND "+"a."+dao.BusViolationRecord.Columns().CreatedAt+" <=?", req.DateRange[0], req.DateRange[1])
}
array, _ := m.Array()
listRes.Total = len(array)
liberr.ErrIsNil(ctx, err, "获取总行数失败")
if req.PageNum == 0 {
req.PageNum = 1
}
listRes.CurrentPage = req.PageNum
if req.PageSize == 0 {
req.PageSize = consts.PageSize
}
order := "a.is_dispose asc,a.id desc"
if req.OrderBy != "" {
order = req.OrderBy
}
var res []*model.BusViolationRecordInfoRes
err = m.Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
liberr.ErrIsNil(ctx, err, "获取数据失败")
listRes.List = make([]*model.BusViolationRecordListRes, len(res))
for k, v := range res {
//if v.Picture == "" {
// v.Picture = v.PictureTwo
//}
listRes.List[k] = &model.BusViolationRecordListRes{
Id: v.Id,
ProjectId: v.ProjectId,
Openid: v.Openid,
TourType: v.TourType,
//IsDispose: v.IsDispose,
CreatedAt: v.CreatedAt,
//LaborDate: v.LaborDate,
NickName: v.NickName,
//Picture: v.Picture,
}
}
})
return
}
func (s *sBusViolationRecord) List(ctx context.Context, req *system.BusViolationRecordSearchReq) (listRes *system.BusViolationRecordSearchRes, err error) {
var uid = int64(ct.New().GetLoginUser(ctx).Id)
listRes = new(system.BusViolationRecordSearchRes)
err = g.Try(ctx, func(ctx context.Context) {
m := dao.BusViolationRecord.Ctx(ctx).As("a").
LeftJoin("bus_construction_user", "b", "a.openid = b.openid").
LeftJoin("bus_tour", "c", "a.tour_id = c.id").
Fields("a.*,b.nick_name,b.user_name,c.picture as pictureTwo").
Where("a.project_id", req.ProjectId).
Where("a.pid", 0)
if req.Id > 0 {
m = m.Where("a."+dao.BusViolationRecord.Columns().Id, req.Id)
}
if req.TourType != "" {
m = m.Where("a."+dao.BusViolationRecord.Columns().TourType+" = ?", req.TourType)
}
if req.IsDispose != "" {
m = m.Where("a."+dao.BusViolationRecord.Columns().IsDispose+" = ?", req.IsDispose)
}
//创建时间模糊查询
if req.CreatedAt != "" {
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
m = m.Where("a."+dao.BusViolationRecord.Columns().CreatedAt+" like ?", "%"+date+"%")
}
if len(req.DateRange) != 0 {
m = m.Where("a."+dao.BusViolationRecord.Columns().CreatedAt+" >=? AND "+"a."+dao.BusViolationRecord.Columns().CreatedAt+" <=?", req.DateRange[0], req.DateRange[1])
}
array, _ := m.Array()
listRes.Total = len(array)
liberr.ErrIsNil(ctx, err, "获取总行数失败")
if req.PageNum == 0 {
req.PageNum = 1
}
listRes.CurrentPage = req.PageNum
if req.PageSize == 0 {
req.PageSize = consts.PageSize
}
order := "a.is_dispose asc,a.id desc"
if req.OrderBy != "" {
order = req.OrderBy
}
var res []*model.BusViolationRecordInfoRes
err = m.Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
liberr.ErrIsNil(ctx, err, "获取数据失败")
listRes.List = make([]*model.BusViolationRecordListRes, len(res))
for k, v := range res {
//当前工单如若被拒绝那么就查询当前工单下最新的数据信息然后把当前数据给替换掉主要替换id、状态
if res[k].ReviewType == "2" {
type zdmp struct {
gmeta.Meta `orm:"table:bus_violation_record"`
Id int64 `orm:"id" json:"id"`
ReviewType string `orm:"review_type" json:"reviewType"`
}
var zdmpData []zdmp
mysql := dao.BusViolationRecord.Ctx(ctx).As("a").
Where("a.pid", res[k].Id).Safe()
if err := mysql.Fields("a.id,a.review_type").Scan(&zdmpData); err != nil {
liberr.ErrIsNil(ctx, err, "无法获取安全工单拒绝数据")
return
} else {
for i2 := range zdmpData {
if zdmpData[i2].ReviewType == "" || zdmpData[i2].ReviewType == "1" {
zdmpData[i2].ReviewType = "true"
} else {
zdmpData[i2].ReviewType = "false"
}
}
zdmpData = append(zdmpData, zdmp{
Id: res[k].Id,
ReviewType: "false",
})
sort.Slice(zdmpData, func(i, j int) bool {
return zdmpData[i].Id > zdmpData[j].Id
})
res[k].RefuseList = zdmpData
}
type zd struct {
gmeta.Meta `orm:"table:bus_hse_management"`
Id int64 `orm:"id" json:"id"`
Status string `orm:"status" json:"status"`
}
zdData := new(zd)
err := mysql.
Where("(a.review_type != '2') OR (a.review_type IS NULL)").
Fields("a.id,a.status").
Scan(&zdData)
if err == nil {
res[k].Id = zdData.Id
res[k].Status = zdData.Status
res[k].ReviewType = ""
} else {
liberr.ErrIsNil(ctx, err, "无法获取安全工单转换数据")
return
}
}
listRes.List[k] = &model.BusViolationRecordListRes{
Id: v.Id,
ProjectId: v.ProjectId,
DataSource: v.DataSource,
Level: v.Level,
TourType: v.TourType,
Openid: v.Openid,
NickName: v.NickName,
UserName: v.UserName,
//IsDispose: v.IsDispose,
//Picture: v.Picture,
Remark: v.Remark,
CreatedAt: v.CreatedAt,
Status: v.Status,
ReviewType: v.ReviewType,
SxtName: v.SxtName,
RefuseList: v.RefuseList,
//LaborDate: v.LaborDate,
}
//状态为3 查询出复查人
if v.Status == "3" {
ve := coryCommon.SelectByString(ctx, coryCommon.IsNumeric(v.UpdateBy), v.UpdateBy)
listRes.List[k].ReviewName = ve
}
// 判断当前人是否可以进行复查
if v.SelectPeople == uid {
v.IsReview = true
} else {
v.IsReview = false
}
}
})
return
}
func (s *sBusViolationRecord) GetById(ctx context.Context, id int64) (res *model.BusViolationRecordInfoRes, err error) {
err = g.Try(ctx, func(ctx context.Context) {
err = dao.BusViolationRecord.Ctx(ctx).Where(dao.BusViolationRecord.Columns().Id, id).Scan(&res)
//获取创建人 更新人名称
by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
infoRes := by.(model.BusViolationRecordInfoRes)
res = &infoRes
liberr.ErrIsNil(ctx, err, "获取信息失败")
//通知了谁?
var violationRecordCorrelationEntity []*model.ViolationRecordCorrelation
err = g.DB().Model("bus_violation_record_correlation").Ctx(ctx).As("a").
LeftJoin(dao.SysUser.Table(), "b", "b.id = a.user_id").
LeftJoin(dao.SysPost.Table(), "c", "c.post_id = a.post_id").
Fields("a.*,b.user_nickname as user_name,c.post_name as post_name").
Where("a.record_id", id).Scan(&violationRecordCorrelationEntity)
liberr.ErrIsNil(ctx, err, "获取通知人失败")
if len(violationRecordCorrelationEntity) > 0 {
res.ViolationRecordCorrelationList = violationRecordCorrelationEntity
}
//谁选择了处理人?
value, _ := dao.SysUser.Ctx(ctx).Where("id", res.SelectPeople).Fields("user_nickname").Value()
res.SelectPeople = value.Int64()
//谁处理了?处理时间?处理结果?内容(备注)
value2, _ := dao.BusConstructionUser.Ctx(ctx).Where("openid", res.Openid).Fields("user_name").Value()
res.Openid = value2.String()
})
return
}
func (s *sBusViolationRecord) Add(ctx context.Context, req *system.BusViolationRecordAddReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
//1、根据类型推断出违章/工单等级
var levelEntity *model.BusViolationLevelInfoRes
err := dao.BusViolationLevel.Ctx(ctx).WhereLike("tour_type", "%"+req.TourType+"%").Scan(&levelEntity)
if err != nil {
liberr.ErrIsNil(ctx, err)
return
}
if levelEntity == nil {
errors.New("请联系后台管理员,给该类型添加权重(等级)!")
liberr.ErrIsNil(ctx, err)
return
}
_, err = dao.BusViolationRecord.Ctx(ctx).Insert(do.BusViolationRecord{
ProjectId: req.ProjectId,
Openid: req.Conductor,
LevelId: levelEntity.Id,
Level: levelEntity.Grade,
TourType: req.TourType,
DataSource: req.DataSource,
//Picture: req.Picture,
Remark: req.Remark,
//WxOrPc: "1",
//LaborDate: req.LaborDate,
CreateBy: ct.New().GetLoginUser(ctx).Id,
})
liberr.ErrIsNil(ctx, err, "添加失败")
})
return
}
func (s *sBusViolationRecord) WxAdd(ctx context.Context, req *wxSystem.WxBusViolationRecordAddReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
//1、根据类型推断出违章/工单等级
var levelEntity *model.BusViolationLevelInfoRes
err := dao.BusViolationLevel.Ctx(ctx).WhereLike("tour_type", "%"+req.TourType+"%").Scan(&levelEntity)
if err != nil {
liberr.ErrIsNil(ctx, err)
return
}
if levelEntity == nil {
errors.New("请联系后台管理员,给该类型添加权重(等级)!")
liberr.ErrIsNil(ctx, err)
return
}
req.Picture = strings.Replace(req.Picture, "/file/", "/wxfile/", 1)
_, err = dao.BusViolationRecord.Ctx(ctx).Insert(do.BusViolationRecord{
ProjectId: req.ProjectId,
LevelId: levelEntity.Id,
Level: levelEntity.Grade,
TourType: req.TourType,
DataSource: "artificial",
//Picture: req.Picture,
Remark: req.Remark,
//WxOrPc: "2",
//LaborDate: req.LaborDate,
CreateBy: req.ByOpenid,
})
liberr.ErrIsNil(ctx, err, "添加失败")
})
return
}
func (s *sBusViolationRecord) Delete(ctx context.Context, ids []int64) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.BusViolationRecord.Ctx(ctx).Delete(dao.BusViolationRecord.Columns().Id+" in (?)", ids)
liberr.ErrIsNil(ctx, err, "删除失败")
})
return
}
//// UploadAndSaveFunc 上传并存储文件
//func UploadAndSaveFunc(ctx context.Context, File []*ghttp.UploadFile, id int64, typeStr string) (err error) {
// err = g.Try(ctx, func(ctx context.Context) {
// //2、获取文件数据然后对文件进行上传
// var fileEntitys []*model.BusViolationRecordPathLogicRes
// 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 := model.BusViolationRecordPathLogicRes{
// TicketId: id,
// Type: typeStr,
// Name: File[i].Filename,
// Path: rpath,
// FileType: ext,
// }
// fileEntitys = append(fileEntitys, &entity)
// }
// //3、上传文件的附件信息
// _, err = g.DB().Model("bus_violation_record_path").Ctx(ctx).Insert(fileEntitys)
// liberr.ErrIsNil(ctx, err, "添加失败")
// })
// return
//}
// SaveFunc 存储文件
func SaveFunc(ctx context.Context, fileInfo []*comModel.UpFile, id int64, typeStr string) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
//2、获取文件数据然后对文件进行上传
var fileEntitys []*model.BusViolationRecordPathLogicRes
for i := range fileInfo {
entity := model.BusViolationRecordPathLogicRes{
TicketId: id,
Type: typeStr,
Name: fileInfo[i].Name,
Path: fileInfo[i].Url,
FileType: fileInfo[i].FileType,
}
fileEntitys = append(fileEntitys, &entity)
}
//3、上传文件的附件信息
_, err = g.DB().Model("bus_violation_record_path").Ctx(ctx).Insert(fileEntitys)
liberr.ErrIsNil(ctx, err, "添加失败")
})
return
}
func AiNotificationFunc(ctx context.Context, id int64, status int) (err error) {
//2、获取对应数据
var aData model.BusViolationRecordInfoRes
err = dao.BusViolationRecord.Ctx(ctx).WherePri(id).Scan(&aData)
//3、消息提醒
value, _ := g.DB().Model("sys_dict_data").Ctx(ctx).Where("dict_type", "tour_type").Where("dict_value", aData.TourType).Fields("dict_label").Value()
message := reminders.Reminder{
Type: reminders.AI,
Status: status,
Title: value.String(), //违章类型
Content: aData.Level, //违章等级
ProjectID: int(aData.ProjectId),
ReceiverID: aData.Openid,
TargetID: int(id),
}
if status == reminders.Remind || status == reminders.Recheck {
message.ReceiverID = aData.Openid
} else {
message.ReceiverID = strconv.FormatInt(aData.SelectPeople, 10)
}
err = reminders.PublishReminder(message, false)
return err
}