初始
This commit is contained in:
@ -0,0 +1,910 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2024-03-21 15:23:59
|
||||
// 生成路径: internal/app/system/logic/bus_inspection_ticket.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/net/ghttp"
|
||||
"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"
|
||||
"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"
|
||||
"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"
|
||||
systemService "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"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterBusInspectionTicket(New())
|
||||
}
|
||||
|
||||
type FileEntity struct {
|
||||
TicketId int64 `p:"ticket_id" dc:"质量工单主键ID(级联删除)"`
|
||||
Type string `p:"type" dc:"类型(1巡检 2整改)"`
|
||||
Name string `p:"name" dc:"文件名称"`
|
||||
Path string `p:"path" dc:"文件路径"`
|
||||
FileType string `p:"file_type" dc:"文件类型(后缀)"`
|
||||
}
|
||||
|
||||
func New() *sBusInspectionTicket {
|
||||
return &sBusInspectionTicket{}
|
||||
}
|
||||
|
||||
type sBusInspectionTicket struct{}
|
||||
|
||||
func (s *sBusInspectionTicket) UpdataCorrector(ctx context.Context, req *system.UpdataCorrectorReq) (err error) {
|
||||
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
//1、先查看当前状态是否通知状态
|
||||
columns := dao.BusInspectionTicket.Columns()
|
||||
var aData *model.BusInspectionTicketInfoRes
|
||||
err = dao.BusInspectionTicket.Ctx(ctx).WherePri(req.Id).Scan(&aData)
|
||||
liberr.ErrIsNil(ctx, err, "获取工单失败!")
|
||||
if aData != nil && aData.Status != "1" {
|
||||
liberr.ErrIsNil(ctx, errors.New("当前工单状态不是通知状态,无法更改整改人"))
|
||||
return
|
||||
}
|
||||
//2、变更当前工单的整改人
|
||||
_, err = dao.BusInspectionTicket.Ctx(ctx).Data(columns.Corrector, req.Corrector).WherePri(req.Id).Update()
|
||||
liberr.ErrIsNil(ctx, err, "变更整改人失败")
|
||||
//3、删除当前工单的提醒失败
|
||||
err2 := reminders.UserIDOrderIDDel(aData.Corrector, aData.Id)
|
||||
liberr.ErrIsNil(ctx, err2, "删除当前工单的提醒失败")
|
||||
//3、发送通知
|
||||
value, _ := g.DB().Model("sys_dict_data").Ctx(ctx).Where("dict_type", "inspection_type").Where("dict_value", aData.InspectionType).Fields("dict_label").Value()
|
||||
message := reminders.Reminder{
|
||||
Type: reminders.Quality,
|
||||
Status: reminders.Reform,
|
||||
Title: value.String(),
|
||||
Content: aData.InspectionResult,
|
||||
ProjectID: int(aData.ProjectId),
|
||||
ReceiverID: aData.CreatedBy,
|
||||
TargetID: int(req.Id),
|
||||
}
|
||||
err = reminders.PublishReminder(message, false)
|
||||
if err != nil {
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
}
|
||||
})
|
||||
return err
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *sBusInspectionTicket) LargeScreenDetails(ctx context.Context, req *system.LargeScreenDetailsReq) (res *system.LargeScreenDetailsRes, err error) {
|
||||
res = new(system.LargeScreenDetailsRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusInspectionTicket.Ctx(ctx).As("a").
|
||||
LeftJoin(dao.SysProject.Table(), "b", "b.id = a.project_id").
|
||||
LeftJoin("sys_dict_data", "c", "c.dict_type = 'inspection_type' and c.dict_value = a.inspection_type")
|
||||
//1、获取主体数据
|
||||
var zd = "a.id," + //主键ID
|
||||
"b.project_name as projectName," + //项目名称
|
||||
"a.created_by as fill," + //检查人
|
||||
"a.check_time as checkTime," + //检查时间
|
||||
"a.rectification_time as rectificationTime," + //整改时间
|
||||
"a.review_time as reviewTime," + //验证时间
|
||||
"a.feedback as feedback," + //整改反馈
|
||||
"a.reply_date," + //回复时间
|
||||
"a.is_reply," + //是否回复
|
||||
"a.inspection_headline," + //巡检主题
|
||||
"a.inspection_result," + //巡检结果
|
||||
"c.dict_label as inspection_type," + //巡检类型
|
||||
"a.created_at," + //巡检记录时间
|
||||
"a.status,a.verification_type"
|
||||
if req.Type == "2" {
|
||||
m = m.LeftJoin(dao.BusConstructionUser.Table(), "d", "d.openid = a.corrector")
|
||||
zd = zd + ",d.user_name as abarbeitung" //整改人
|
||||
}
|
||||
m = m.Fields(zd) //巡检到整改为2表示回复、整改到验证1通过2拒绝
|
||||
err = m.Where("a.id", req.Id).Scan(&res)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
//2、获取附件
|
||||
var pathEntity []*model.BusInspectionTicketPath
|
||||
err = g.DB().Model("bus_inspection_ticket_path").Ctx(ctx).Where("ticket_id", req.Id).Scan(&pathEntity)
|
||||
liberr.ErrIsNil(ctx, err, "查询失败")
|
||||
//3、分类附件
|
||||
var one []*model.BusInspectionTicketPath
|
||||
var two []*model.BusInspectionTicketPath
|
||||
for i := range pathEntity {
|
||||
if pathEntity[i].Type == "1" {
|
||||
one = append(one, pathEntity[i])
|
||||
} else {
|
||||
two = append(two, pathEntity[i])
|
||||
}
|
||||
}
|
||||
res.Inspectionccessories = one
|
||||
res.CorrectiveAttachment = two
|
||||
//3、获取
|
||||
res.Fill = coryCommon.SelectByString(ctx, coryCommon.IsNumeric(res.Fill), res.Fill)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusInspectionTicket) GisQualityManagementListFunc(ctx context.Context, req *system.GisQualityManagementListReq) (listRes *system.GisQualityManagementListRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
listRes = new(system.GisQualityManagementListRes)
|
||||
m := dao.BusInspectionTicket.Ctx(ctx).As("a").
|
||||
Fields("a.id,b.dict_label,a.inspection_headline,a.status,a.verification_type,a.created_at").
|
||||
LeftJoin("sys_dict_data", "b", "b.dict_type = 'inspection_type' and b.dict_value = a.inspection_type").
|
||||
Where("a.is_reply", req.Type).Where("a.project_id", req.ProjectId)
|
||||
values, err := m.Array()
|
||||
liberr.ErrIsNil(ctx, err, "获取总行数失败")
|
||||
listRes.Total = len(values)
|
||||
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
|
||||
}
|
||||
var entity []*system.GisQualityManagementListEntityRes
|
||||
err = m.Page(req.PageNum, req.PageSize).Order(order).Scan(&entity)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = entity
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusInspectionTicket) GisQualityManagementResFunc(ctx context.Context, req *system.GisQualityManagementReq) (res *system.GisQualityManagementRes, err error) {
|
||||
res = new(system.GisQualityManagementRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
//1、获取巡检记录(质量工单不需要回复的所有数据)
|
||||
safe := dao.BusInspectionTicket.Ctx(ctx).
|
||||
Where("project_id", req.ProjectId).Safe()
|
||||
count, err := safe.Where("is_reply", "2").Count()
|
||||
liberr.ErrIsNil(ctx, err, "巡检记录统计失败")
|
||||
res.InspectionRecord = count
|
||||
//2、整改情况统计(百分比)
|
||||
countTwo, err := safe.Where("is_reply", "1").Count()
|
||||
liberr.ErrIsNil(ctx, err, "情况统计情况统计失败")
|
||||
countThree, err := safe.Where("is_reply", "1").
|
||||
Where("status", "3").
|
||||
Where("verification_type", "1").
|
||||
Count()
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
if float64(countThree) == 0 {
|
||||
res.ReorganizeTheSituation = 0
|
||||
} else {
|
||||
consequence, err := coryCommon.PercentageFunc(100, float64(countTwo), float64(countThree))
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
res.ReorganizeTheSituation = consequence
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusInspectionTicket) InspectionTicketAppletDetailsFunc(ctx context.Context, req *wxApplet.InspectionTicketAppletDetailsReq) (res *wxApplet.InspectionTicketAppletDetailsRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
//1、获取主体数据
|
||||
m := dao.BusInspectionTicket.Ctx(ctx).As("a").
|
||||
LeftJoin(dao.SysProject.Table(), "b", "b.id = a.project_id").
|
||||
LeftJoin("sys_dict_data", "c", "dict_type = 'inspection_type' and dict_value = a.Inspection_type").
|
||||
LeftJoin(dao.BusConstructionUser.Table(), "d", "d.openid = a.corrector").
|
||||
Fields(
|
||||
"a.id,b.project_name as projectName," + //主键ID、项目名称
|
||||
"c.dict_label," + //巡检类型
|
||||
"a.inspection_headline," + //巡检主题
|
||||
"a.inspection_result," + //巡检结果
|
||||
"d.user_name as abarbeitung," + //整改人
|
||||
"a.is_reply,a.reply_date," + //是否回复、回复时间
|
||||
"a.created_by as fill,a.created_at," + //填报人、填报时间
|
||||
"a.feedback," + //整改反馈
|
||||
"a.verification_result," + //验证结果
|
||||
"a.status,a.verification_type," + //工单状态、验证状态
|
||||
"a.updated_at as updatedAt," + //更新时间
|
||||
"a.rectification_time as rectificationTime") //整改时间
|
||||
err = m.Where("a.id", req.Id).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "查询失败")
|
||||
//2、获取附件
|
||||
var pathEntity []*model.BusInspectionTicketPath
|
||||
err = g.DB().Model("bus_inspection_ticket_path").Ctx(ctx).Where("ticket_id", req.Id).Scan(&pathEntity)
|
||||
liberr.ErrIsNil(ctx, err, "查询失败")
|
||||
//3、分类附件
|
||||
var one []*model.BusInspectionTicketPath
|
||||
var two []*model.BusInspectionTicketPath
|
||||
for i := range pathEntity {
|
||||
if pathEntity[i].Type == "1" {
|
||||
one = append(one, pathEntity[i])
|
||||
} else {
|
||||
two = append(two, pathEntity[i])
|
||||
}
|
||||
}
|
||||
res.Inspectionccessories = one
|
||||
res.CorrectiveAttachment = two
|
||||
//3、获取
|
||||
res.Fill = coryCommon.SelectByString(ctx, coryCommon.IsNumeric(res.Fill), res.Fill)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusInspectionTicket) AcquisitionOfCorrectivePersonnelFunc(ctx context.Context, req *wxApplet.AcquisitionOfCorrectivePersonnelReq) (res *wxApplet.AcquisitionOfCorrectivePersonnelRes, err error) {
|
||||
res = new(wxApplet.AcquisitionOfCorrectivePersonnelRes)
|
||||
var listEntity []*model.AcquisitionOfCorrectivePersonnelEntityRes
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusConstructionUser.Ctx(ctx).As("a").
|
||||
LeftJoin("sys_project_team_member", "b", "b.openid = a.openid").
|
||||
Fields("a.openid,a.user_name").
|
||||
Where("a.project_id", req.ProjectId).
|
||||
Where("b.post_id = 10").
|
||||
Where("a.team_id > 0").
|
||||
Where("a.team_id is not null")
|
||||
if req.UserName != "" {
|
||||
m = m.Where("a.user_name", "%"+req.UserName+"%")
|
||||
}
|
||||
m.Scan(&listEntity)
|
||||
liberr.ErrIsNil(ctx, err, "查询失败")
|
||||
})
|
||||
res.List = listEntity
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusInspectionTicket) InspectionTicketAppletListFunc(ctx context.Context, req *wxApplet.InspectionTicketAppletListReq) (listRes *wxApplet.InspectionTicketAppletListRes, err error) {
|
||||
listRes = new(wxApplet.InspectionTicketAppletListRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
//1、根据名字模糊搜索到项目id
|
||||
var projectIds []string
|
||||
if req.ProjectName != "" {
|
||||
value, err := dao.SysProject.Ctx(ctx).
|
||||
Where("(project_name like ? or short_name like ?)", "%"+req.ProjectName+"%", "%"+req.ProjectName+"%").
|
||||
Fields("GROUP_CONCAT(id)").Value()
|
||||
liberr.ErrIsNil(ctx, err, "模糊查询失败")
|
||||
split := strings.Split(value.String(), ",")
|
||||
for i := range split {
|
||||
projectIds = append(projectIds, split[i])
|
||||
}
|
||||
}
|
||||
//2、根据项目id+openid获取到数据
|
||||
var appletList []*model.AppletListRes
|
||||
m := dao.BusInspectionTicket.Ctx(ctx).As("a").
|
||||
LeftJoin(dao.SysProject.Table(), "b", "b.id = a.project_id").
|
||||
LeftJoin("sys_dict_data", "c", "dict_type = 'inspection_type' and dict_value = a.Inspection_type").
|
||||
LeftJoin(dao.BusConstructionUser.Table(), "d", "d.openid = a.corrector").
|
||||
//LeftJoin(dao.BusConstructionUser.Table(), "e", "e.openid = a.created_by").
|
||||
Fields(
|
||||
"a.id,b.project_name as projectName," + //主键ID、项目名称
|
||||
"c.dict_label as dictLabel," + //巡检类型
|
||||
"d.user_name as userName," + //整改人
|
||||
"a.inspection_headline as inspectionHeadline," + //巡检主题
|
||||
"a.inspection_result as inspectionResult," + //巡检结果
|
||||
"a.status,a.verification_type as verificationType," + //工单状态
|
||||
//"e.user_name as createBy," +
|
||||
"a.created_by as createdBy," +
|
||||
"a.is_reply as isReply," +
|
||||
"a.created_at as createdAt") //创建人、创建时间
|
||||
if req.StudyType != "" {
|
||||
m = m.Where("a.inspection_type", req.StudyType)
|
||||
}
|
||||
if req.Status != "" && req.Status != "0" {
|
||||
m = m.Where("a.status", req.Status)
|
||||
} else {
|
||||
m = m.Where("a.pid", "0")
|
||||
}
|
||||
if req.ProjectId != 0 {
|
||||
m = m.Where("a.project_id = ?", req.ProjectId)
|
||||
}
|
||||
if req.CreatedAt != "" {
|
||||
m = m.Where("DATE_FORMAT(a.created_at,'%Y-%m-%d') = ?", req.CreatedAt)
|
||||
}
|
||||
if req.Type == "1" {
|
||||
m = m.Where("a.created_by", req.OpenId)
|
||||
}
|
||||
if req.Type == "2" {
|
||||
m = m.Where("a.corrector", req.OpenId).Where("a.is_reply <> 2")
|
||||
}
|
||||
if req.Type == "3" {
|
||||
m = m.Where("a.created_by = ? or a.corrector = ?", req.OpenId, req.OpenId)
|
||||
}
|
||||
if len(projectIds) > 0 {
|
||||
m = m.Where("b.id in (?)", projectIds)
|
||||
}
|
||||
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,a.created_at desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
m.Page(req.PageNum, req.PageSize).Order(order).Scan(&appletList)
|
||||
//3、获取
|
||||
for i := range appletList {
|
||||
//当前工单如若被拒绝,那么就查询当前工单下最新的数据信息,然后把当前数据给替换掉(主要替换id、状态)
|
||||
if appletList[i].VerificationType == "2" {
|
||||
type zdmp struct {
|
||||
gmeta.Meta `orm:"table:bus_inspection_ticket"`
|
||||
Id int64 `orm:"id" json:"id"`
|
||||
VerificationType string `orm:"verification_type" json:"verificationType"`
|
||||
}
|
||||
var zdmpData []zdmp
|
||||
mysql := dao.BusInspectionTicket.Ctx(ctx).As("a").
|
||||
Where("a.pid", appletList[i].Id).Safe()
|
||||
if err := mysql.Fields("a.id,a.verification_type").Scan(&zdmpData); err != nil {
|
||||
liberr.ErrIsNil(ctx, err, "无法获取安全工单拒绝数据")
|
||||
return
|
||||
} else {
|
||||
for i2 := range zdmpData {
|
||||
if zdmpData[i2].VerificationType == "" || zdmpData[i2].VerificationType == "1" {
|
||||
zdmpData[i2].VerificationType = "true"
|
||||
} else {
|
||||
zdmpData[i2].VerificationType = "false"
|
||||
}
|
||||
}
|
||||
zdmpData = append(zdmpData, zdmp{
|
||||
Id: appletList[i].Id,
|
||||
VerificationType: "false",
|
||||
})
|
||||
sort.Slice(zdmpData, func(i, j int) bool {
|
||||
return zdmpData[i].Id > zdmpData[j].Id
|
||||
})
|
||||
appletList[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"`
|
||||
VerificationType string `orm:"verification_type" json:"verificationType"`
|
||||
}
|
||||
zdData := new(zd)
|
||||
err := mysql.
|
||||
Where("(a.verification_type != '2') OR (a.verification_type IS NULL)").
|
||||
Fields("a.id,a.status,a.verification_type").
|
||||
Scan(&zdData)
|
||||
if err == nil {
|
||||
appletList[i].Id = zdData.Id
|
||||
appletList[i].Status = zdData.Status
|
||||
appletList[i].VerificationType = zdData.VerificationType
|
||||
} else {
|
||||
liberr.ErrIsNil(ctx, err, "无法获取安全工单转换数据")
|
||||
return
|
||||
}
|
||||
}
|
||||
appletList[i].CreatedById = appletList[i].CreatedBy
|
||||
appletList[i].CreatedBy = coryCommon.SelectByString(ctx, coryCommon.IsNumeric(appletList[i].CreatedBy), appletList[i].CreatedBy)
|
||||
}
|
||||
listRes.List = appletList
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusInspectionTicket) InspectionTicketAppletVerifyFunc(ctx context.Context, req *wxApplet.InspectionTicketAppletVerifyReq) (err error) {
|
||||
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
//1、更新数据
|
||||
_, err = dao.BusInspectionTicket.Ctx(ctx).WherePri(req.Id).OmitEmpty().Update(do.BusInspectionTicket{
|
||||
VerificationResult: req.VerificationResult,
|
||||
VerificationType: req.VerificationType,
|
||||
Status: "3", //整改
|
||||
ReviewTime: gtime.New(time.Now()),
|
||||
UpdatedBy: req.Openid,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "验证提交失败")
|
||||
//2、查询数据
|
||||
var aData model.BusInspectionTicketInfoRes
|
||||
err = dao.BusInspectionTicket.Ctx(ctx).WherePri(req.Id).Scan(&aData)
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
//3、消息提醒
|
||||
value, _ := g.DB().Model("sys_dict_data").Ctx(ctx).Where("dict_type", "inspection_type").Where("dict_value", aData.InspectionType).Fields("dict_label").Value()
|
||||
message := reminders.Reminder{
|
||||
Type: reminders.Quality,
|
||||
Status: reminders.Recheck,
|
||||
Title: value.String(),
|
||||
Content: aData.InspectionResult,
|
||||
ProjectID: int(aData.ProjectId),
|
||||
ReceiverID: aData.Corrector,
|
||||
TargetID: int(req.Id),
|
||||
}
|
||||
err = reminders.PublishReminder(message, false)
|
||||
if err != nil {
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
}
|
||||
})
|
||||
return err
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusInspectionTicket) InspectionTicketAppletAbarbeitungFunc(ctx context.Context, req *wxApplet.InspectionTicketAppletAbarbeitungReq) (err error) {
|
||||
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
//1、更新数据
|
||||
_, err = dao.BusInspectionTicket.Ctx(ctx).WherePri(req.Id).OmitEmpty().Update(do.BusInspectionTicket{
|
||||
Feedback: req.Feedback,
|
||||
Status: "2", //整改
|
||||
RectificationTime: gtime.New(time.Now()),
|
||||
UpdatedBy: req.Openid,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "整改提交失败")
|
||||
//2、存储文件
|
||||
if len(req.File) > 0 {
|
||||
err = SaveFunc(ctx, req.File, req.Id, "2") //整改
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
}
|
||||
//2、查询数据
|
||||
var aData model.BusInspectionTicketInfoRes
|
||||
err = dao.BusInspectionTicket.Ctx(ctx).WherePri(req.Id).Scan(&aData)
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
//3、消息提醒
|
||||
value, _ := g.DB().Model("sys_dict_data").Ctx(ctx).Where("dict_type", "inspection_type").Where("dict_value", aData.InspectionType).Fields("dict_label").Value()
|
||||
message := reminders.Reminder{
|
||||
Type: reminders.Quality,
|
||||
Status: reminders.Reform,
|
||||
Title: value.String(),
|
||||
Content: aData.InspectionResult,
|
||||
ProjectID: int(aData.ProjectId),
|
||||
ReceiverID: aData.CreatedBy,
|
||||
TargetID: int(req.Id),
|
||||
}
|
||||
err = reminders.PublishReminder(message, false)
|
||||
if err != nil {
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
}
|
||||
})
|
||||
return err
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusInspectionTicket) InspectionTicketAppletAddFunc(ctx context.Context, req *wxApplet.InspectionTicketAppletAddReq) (err error) {
|
||||
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
isStatus := "1" //默认为通知
|
||||
if req.IsReply == "2" {
|
||||
isStatus = "3"
|
||||
}
|
||||
ticket := do.BusInspectionTicket{
|
||||
ProjectId: req.ProjectId,
|
||||
InspectionType: req.InspectionType,
|
||||
InspectionHeadline: req.InspectionHeadline,
|
||||
InspectionResult: req.InspectionResult,
|
||||
Corrector: req.Corrector,
|
||||
IsReply: req.IsReply,
|
||||
ReplyDate: req.ReplyDate,
|
||||
Status: isStatus,
|
||||
CreatedBy: req.Openid,
|
||||
CheckTime: gtime.New(time.Now()),
|
||||
}
|
||||
//如果回复为否,那么工单状态为验证且通过
|
||||
if isStatus == "3" {
|
||||
ticket.VerificationType = "1"
|
||||
}
|
||||
//1、上传文件基本信息
|
||||
info, err := dao.BusInspectionTicket.Ctx(ctx).OmitEmpty().Insert(ticket)
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
id, _ := info.LastInsertId()
|
||||
//2、上传并存储文件
|
||||
if len(req.File) > 0 {
|
||||
err = SaveFunc(ctx, req.File, id, "1") //巡检
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
}
|
||||
//3、消息提醒
|
||||
value, _ := g.DB().Model("sys_dict_data").Ctx(ctx).Where("dict_type", "inspection_type").Where("dict_value", req.InspectionType).Fields("dict_label").Value()
|
||||
message := reminders.Reminder{
|
||||
Type: reminders.Quality,
|
||||
Status: reminders.Remind,
|
||||
|
||||
Title: value.String(),
|
||||
Content: req.InspectionResult,
|
||||
|
||||
ProjectID: int(req.ProjectId),
|
||||
ReceiverID: req.Corrector,
|
||||
TargetID: int(id),
|
||||
}
|
||||
err = reminders.PublishReminder(message, false)
|
||||
if err != nil {
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
}
|
||||
})
|
||||
return err
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusInspectionTicket) List(ctx context.Context, req *system.BusInspectionTicketSearchReq) (listRes *system.BusInspectionTicketSearchRes, err error) {
|
||||
listRes = new(system.BusInspectionTicketSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusInspectionTicket.Ctx(ctx).As("a").
|
||||
LeftJoin(dao.SysProject.Table(), "b", "b.id = a.project_id").
|
||||
LeftJoin(dao.BusConstructionUser.Table(), "d", "d.openid = a.corrector").
|
||||
Fields(`
|
||||
a.id,
|
||||
a.feedback,
|
||||
a.status,
|
||||
b.project_name,
|
||||
a.inspection_type,
|
||||
a.inspection_headline,
|
||||
a.inspection_result,
|
||||
d.user_name as two,
|
||||
a.created_at,
|
||||
a.updated_at,
|
||||
a.verification_type,
|
||||
a.created_by,
|
||||
a.is_reply,
|
||||
a.rectification_time
|
||||
`)
|
||||
m = m.Where("a.pid", "0")
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where("a."+dao.BusInspectionTicket.Columns().ProjectId+" = ?", gconv.Int64(req.ProjectId))
|
||||
}
|
||||
if req.InspectionType != "" {
|
||||
m = m.Where("a."+dao.BusInspectionTicket.Columns().InspectionType+" = ?", req.InspectionType)
|
||||
}
|
||||
if req.Status != "" {
|
||||
m = m.Where("a."+dao.BusInspectionTicket.Columns().Status+" = ?", req.Status)
|
||||
}
|
||||
//创建时间模糊查询
|
||||
if req.CreatedAt != "" {
|
||||
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
|
||||
m = m.Where("a."+dao.BusInspectionTicket.Columns().CreatedAt+" like ?", "%"+date+"%")
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where("a."+dao.BusInspectionTicket.Columns().CreatedAt+" >=? AND "+"a."+dao.BusInspectionTicket.Columns().CreatedAt+" <=?", req.DateRange[0], req.DateRange[1])
|
||||
}
|
||||
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.id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.PcListRes
|
||||
err = m.Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
for i := range res {
|
||||
//当前工单如若被拒绝,那么就查询当前工单下最新的数据信息,然后把当前数据给替换掉(主要替换id、状态)
|
||||
if res[i].VerificationType == "2" {
|
||||
type zdmp struct {
|
||||
gmeta.Meta `orm:"table:bus_inspection_ticket"`
|
||||
Id int64 `orm:"id" json:"id"`
|
||||
VerificationType string `orm:"verification_type" json:"verificationType"`
|
||||
}
|
||||
var zdmpData []zdmp
|
||||
mysql := dao.BusInspectionTicket.Ctx(ctx).As("a").
|
||||
Where("a.pid", res[i].Id).Safe()
|
||||
if err := mysql.Fields("a.id,a.verification_type").Scan(&zdmpData); err != nil {
|
||||
liberr.ErrIsNil(ctx, err, "无法获取安全工单拒绝数据")
|
||||
return
|
||||
} else {
|
||||
for i2 := range zdmpData {
|
||||
if zdmpData[i2].VerificationType == "" || zdmpData[i2].VerificationType == "1" {
|
||||
zdmpData[i2].VerificationType = "true"
|
||||
} else {
|
||||
zdmpData[i2].VerificationType = "false"
|
||||
}
|
||||
}
|
||||
zdmpData = append(zdmpData, zdmp{
|
||||
Id: res[i].Id,
|
||||
VerificationType: "false",
|
||||
})
|
||||
sort.Slice(zdmpData, func(i, j int) bool {
|
||||
return zdmpData[i].Id > zdmpData[j].Id
|
||||
})
|
||||
res[i].RefuseList = zdmpData
|
||||
}
|
||||
type zd struct {
|
||||
gmeta.Meta `orm:"table:bus_inspection_ticket"`
|
||||
Id int64 `orm:"id" json:"id"`
|
||||
Status string `orm:"status" json:"status"`
|
||||
VerificationType string `orm:"verification_type" json:"verificationType"`
|
||||
}
|
||||
zdData := new(zd)
|
||||
err := mysql.
|
||||
Where("(a.verification_type != '2') OR (a.verification_type IS NULL)").
|
||||
Fields("a.id,a.status,a.verification_type").
|
||||
Scan(&zdData)
|
||||
if err == nil {
|
||||
res[i].Id = zdData.Id
|
||||
res[i].Status = zdData.Status
|
||||
res[i].VerificationType = zdData.VerificationType
|
||||
} else {
|
||||
liberr.ErrIsNil(ctx, err, "无法获取安全工单转换数据")
|
||||
return
|
||||
}
|
||||
}
|
||||
res[i].One = coryCommon.SelectByString(ctx, coryCommon.IsNumeric(res[i].CreatedBy), res[i].CreatedBy)
|
||||
}
|
||||
listRes.List = res
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusInspectionTicket) GetById(ctx context.Context, id int64) (res *model.AppletDetailsRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
//1、获取主体数据
|
||||
m := dao.BusInspectionTicket.Ctx(ctx).As("a").
|
||||
LeftJoin(dao.SysProject.Table(), "b", "b.id = a.project_id").
|
||||
LeftJoin("sys_dict_data", "c", "dict_type = 'inspection_type' and dict_value = a.Inspection_type").
|
||||
LeftJoin(dao.BusConstructionUser.Table(), "d", "d.openid = a.corrector").
|
||||
Fields(
|
||||
"a.id,b.project_name as projectName," + //主键ID、项目名称
|
||||
"c.dict_label," + //巡检类型
|
||||
"a.inspection_headline," + //巡检主题
|
||||
"a.inspection_result," + //巡检结果
|
||||
"d.user_name as abarbeitung," + //整改人
|
||||
"a.is_reply,a.reply_date," + //是否回复、回复时间
|
||||
"a.created_by as fill,a.created_at," + //填报人、填报时间
|
||||
"a.feedback," + //整改反馈
|
||||
"a.verification_result," + //验证结果
|
||||
"a.status,a.verification_type," + //工单状态、验证状态
|
||||
"a.updated_at as updatedAt," + //更新时间
|
||||
"a.rectification_time as rectificationTime") //整改时间
|
||||
err = m.Where("a.id", id).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "查询失败")
|
||||
//2、获取附件
|
||||
var pathEntity []*model.BusInspectionTicketPath
|
||||
err = g.DB().Model("bus_inspection_ticket_path").Ctx(ctx).Where("ticket_id", id).Scan(&pathEntity)
|
||||
liberr.ErrIsNil(ctx, err, "查询失败")
|
||||
//3、分类附件
|
||||
var one []*model.BusInspectionTicketPath
|
||||
var two []*model.BusInspectionTicketPath
|
||||
for i := range pathEntity {
|
||||
if pathEntity[i].Type == "1" {
|
||||
one = append(one, pathEntity[i])
|
||||
} else {
|
||||
two = append(two, pathEntity[i])
|
||||
}
|
||||
}
|
||||
res.Inspectionccessories = one
|
||||
res.CorrectiveAttachment = two
|
||||
//3、获取
|
||||
res.Fill = coryCommon.SelectByString(ctx, coryCommon.IsNumeric(res.Fill), res.Fill)
|
||||
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusInspectionTicket) Add(ctx context.Context, req *system.BusInspectionTicketAddReq) (err error) {
|
||||
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
//1、存储基本信息
|
||||
//date := tool.New().GetFormattedDate(time.Now())
|
||||
info, err := dao.BusInspectionTicket.Ctx(ctx).Insert(do.BusInspectionTicket{
|
||||
ProjectId: req.ProjectId,
|
||||
InspectionType: req.InspectionType,
|
||||
InspectionHeadline: req.InspectionHeadline,
|
||||
InspectionResult: req.InspectionResult,
|
||||
Corrector: req.Corrector,
|
||||
Status: "1",
|
||||
IsReply: req.IsReply,
|
||||
ReplyDate: req.ReplyDate,
|
||||
CheckTime: gtime.New(time.Now()),
|
||||
CreatedBy: systemService.Context().GetUserId(ctx),
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
id, _ := info.LastInsertId()
|
||||
//2、上传并存储文件
|
||||
if req.HseManagementAdd == 1 {
|
||||
err = SaveFunc(ctx, req.FileTwo, id, "1") //巡检
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
} else {
|
||||
err = UploadAndSaveFunc(ctx, req.File, id, "1") //巡检
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
}
|
||||
//3、消息提醒
|
||||
value, _ := g.DB().Model("sys_dict_data").Ctx(ctx).Where("dict_type", "inspection_type").Where("dict_value", req.InspectionType).Fields("dict_label").Value()
|
||||
message := reminders.Reminder{
|
||||
Type: reminders.Quality,
|
||||
Status: reminders.Remind,
|
||||
Title: value.String(),
|
||||
Content: req.InspectionHeadline,
|
||||
ProjectID: int(req.ProjectId),
|
||||
ReceiverID: req.Corrector,
|
||||
TargetID: int(id),
|
||||
}
|
||||
err = reminders.PublishReminder(message, false)
|
||||
if err != nil {
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
}
|
||||
})
|
||||
return err
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusInspectionTicket) Edit(ctx context.Context, req *system.BusInspectionTicketAbarbeitungReq) (err error) {
|
||||
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
//1、插入数据
|
||||
_, err = dao.BusInspectionTicket.Ctx(ctx).WherePri(req.Id).Update(do.BusInspectionTicket{
|
||||
Status: "2",
|
||||
RectificationTime: gtime.New(time.Now()),
|
||||
UpdatedBy: systemService.Context().GetUserId(ctx),
|
||||
})
|
||||
err = UploadAndSaveFunc(ctx, req.File, req.Id, "1") //巡检
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
//2、查询数据
|
||||
var aData model.BusInspectionTicketInfoRes
|
||||
err = dao.BusInspectionTicket.Ctx(ctx).WherePri(req.Id).Scan(&aData)
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
//3、消息提醒
|
||||
value, _ := g.DB().Model("sys_dict_data").Ctx(ctx).Where("dict_type", "inspection_type").Where("dict_value", aData.InspectionType).Fields("dict_label").Value()
|
||||
message := reminders.Reminder{
|
||||
Type: reminders.Quality,
|
||||
Status: reminders.Reform,
|
||||
Title: value.String(),
|
||||
Content: aData.InspectionResult,
|
||||
ProjectID: int(aData.ProjectId),
|
||||
ReceiverID: aData.CreatedBy,
|
||||
TargetID: int(req.Id),
|
||||
}
|
||||
err = reminders.PublishReminder(message, false)
|
||||
if err != nil {
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
}
|
||||
})
|
||||
return err
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusInspectionTicket) EditVerification(ctx context.Context, req *system.BusInspectionTicketVerificationReq) (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.BusInspectionTicket.Ctx(ctx).WherePri(req.Id).Update(do.BusInspectionTicket{
|
||||
VerificationType: req.VerificationType,
|
||||
VerificationResult: req.VerificationResult,
|
||||
Status: "3",
|
||||
ReviewTime: gtime.New(time.Now()),
|
||||
UpdatedBy: systemService.Context().GetUserId(ctx),
|
||||
})
|
||||
//2-1、查询数据
|
||||
var aData model.BusInspectionTicketInfoRes
|
||||
err = dao.BusInspectionTicket.Ctx(ctx).WherePri(req.Id).Scan(&aData)
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
//2-2、如果拒绝那么就重新写入当前数据到整改人
|
||||
if req.VerificationType == "2" {
|
||||
bData := new(model.ReviewRejectionRes)
|
||||
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"
|
||||
bData.CreatedBy = strconv.FormatUint(systemService.Context().GetUserId(ctx), 10)
|
||||
_, resultErr := dao.BusInspectionTicket.Ctx(ctx).OmitEmpty().Insert(bData)
|
||||
if resultErr != nil {
|
||||
liberr.ErrIsNil(ctx, resultErr)
|
||||
return
|
||||
}
|
||||
}
|
||||
//3、消息提醒
|
||||
value, _ := g.DB().Model("sys_dict_data").Ctx(ctx).Where("dict_type", "inspection_type").Where("dict_value", aData.InspectionType).Fields("dict_label").Value()
|
||||
message := reminders.Reminder{
|
||||
Type: reminders.Quality,
|
||||
Status: reminders.Recheck,
|
||||
Title: value.String(),
|
||||
Content: aData.InspectionResult,
|
||||
ProjectID: int(aData.ProjectId),
|
||||
ReceiverID: aData.Corrector,
|
||||
TargetID: int(req.Id),
|
||||
}
|
||||
err = reminders.PublishReminder(message, false)
|
||||
if err != nil {
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
}
|
||||
})
|
||||
return err
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusInspectionTicket) Delete(ctx context.Context, ids []int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
//1、删除数据
|
||||
_, err = dao.BusInspectionTicket.Ctx(ctx).Delete(dao.BusInspectionTicket.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
//2、删除文件
|
||||
var files []*model.BusInspectionTicketPath
|
||||
err := g.DB().Model("bus_inspection_ticket_path").Ctx(ctx).Where("ticket_id in (?)", ids).Scan(&files)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
if files != nil {
|
||||
var paths []string
|
||||
for i := range files {
|
||||
paths = append(paths, files[i].Path)
|
||||
}
|
||||
coryCommon.BatchFile(paths)
|
||||
}
|
||||
})
|
||||
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 []*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,
|
||||
Type: typeStr,
|
||||
Name: File[i].Filename,
|
||||
Path: rpath,
|
||||
FileType: ext,
|
||||
}
|
||||
fileEntitys = append(fileEntitys, &entity)
|
||||
}
|
||||
//3、上传文件的附件信息
|
||||
_, err = g.DB().Model("bus_inspection_ticket_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) {
|
||||
if len(fileInfo) > 0 {
|
||||
//2、获取文件数据,然后对文件进行上传
|
||||
var fileEntitys []*FileEntity
|
||||
for i := range fileInfo {
|
||||
rpath := coryCommon.FileToFunc(filepath.ToSlash(fileInfo[i].Url), 3)
|
||||
entity := FileEntity{
|
||||
TicketId: id,
|
||||
Type: typeStr,
|
||||
Name: fileInfo[i].Name,
|
||||
Path: rpath,
|
||||
FileType: fileInfo[i].FileType,
|
||||
}
|
||||
fileEntitys = append(fileEntitys, &entity)
|
||||
}
|
||||
//3、上传文件的附件信息
|
||||
_, err = g.DB().Model("bus_inspection_ticket_path").Ctx(ctx).Insert(fileEntitys)
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
}
|
||||
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user