feat:完善项目
This commit is contained in:
@ -598,3 +598,70 @@ func (*Work) ScheduleDelete(c *gin.Context) {
|
||||
err := work.NewSchedule()(getSession()(c).(*service.Session)).Delete(form.Convert())
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Work) Repair(c *gin.Context) {
|
||||
form := &struct {
|
||||
OrderNo string `json:"order_no" form:"order_no"`
|
||||
EquipmentCode string `json:"equipment_code" form:"equipment_code"`
|
||||
EquipmentTitle string `json:"equipment_title" form:"equipment_title"`
|
||||
PageForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := work.NewRepair()(getSession()(c).(*service.Session)).List(form.OrderNo, form.EquipmentCode, form.EquipmentTitle,
|
||||
form.Page, form.PageSize)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Work) RepairDetail(c *gin.Context) {
|
||||
form := new(IDStringForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := work.NewRepair()(getSession()(c).(*service.Session)).Detail(form.Convert())
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Work) RepairBegin(c *gin.Context) {
|
||||
form := &struct {
|
||||
IDStringForm
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := work.NewRepair()(getSession()(c).(*service.Session)).Begin(form.Convert(), form.Remark)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Work) RepairFinish(c *gin.Context) {
|
||||
form := &struct {
|
||||
IDStringForm
|
||||
ImageForm
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := work.NewRepair()(getSession()(c).(*service.Session)).Finish(form.Convert(), form.Image, form.Remark)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Work) RepairEvaluate(c *gin.Context) {
|
||||
form := &struct {
|
||||
IDStringForm
|
||||
Score float64 `json:"score" form:"score" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := work.NewRepair()(getSession()(c).(*service.Session)).Evaluate(form.Convert(), form.Score)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
@ -3,12 +3,36 @@ package model
|
||||
// WorkRepair 工单维修数据模型
|
||||
type WorkRepair struct {
|
||||
Model
|
||||
WorkID uint64 `gorm:"column:work_id;type:int(11);default:0;comment:工单ID" json:"-"`
|
||||
Status int `json:"status"`
|
||||
OrderNo string `gorm:"column:order_no;type:varchar(30);default:null;comment:维修单号" json:"order_no"`
|
||||
WorkID uint64 `gorm:"column:work_id;type:int(11);default:0;comment:工单ID" json:"-"`
|
||||
Status WorkRepairStatus `gorm:"column:status;type:tinyint(1);default:0;comment:维修工单状态" json:"status"`
|
||||
IsEvaluate WorkRepairStatusEvaluate `gorm:"column:is_evaluate;type:tinyint(1);default:0;comment:评价状态" json:"is_evaluate"`
|
||||
EvaluateScore int `gorm:"column:evaluate_score;type:decimal(10,2);default:0;comment:评价分数" json:"evaluate_score"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
// WorkRepairStatus 工单状态
|
||||
type WorkRepairStatus int
|
||||
|
||||
const (
|
||||
// WorkRepairStatusForNotBegin 未开始
|
||||
WorkRepairStatusForNotBegin WorkRepairStatus = iota
|
||||
// WorkRepairStatusForOngoing 进行中
|
||||
WorkRepairStatusForOngoing
|
||||
// WorkRepairStatusForFinished 已结束
|
||||
WorkRepairStatusForFinished
|
||||
)
|
||||
|
||||
type WorkRepairStatusEvaluate int
|
||||
|
||||
const (
|
||||
// WorkRepairStatusEvaluateForNot 未评价
|
||||
WorkRepairStatusEvaluateForNot WorkRepairStatusEvaluate = iota
|
||||
// WorkRepairStatusEvaluateForYes 已评价
|
||||
WorkRepairStatusEvaluateForYes
|
||||
)
|
||||
|
||||
func (m *WorkRepair) TableName() string {
|
||||
return "work_repair"
|
||||
}
|
||||
|
34
app/common/model/work_repair_detail.go
Normal file
34
app/common/model/work_repair_detail.go
Normal file
@ -0,0 +1,34 @@
|
||||
package model
|
||||
|
||||
// WorkRepairDetail 维修工单详细数据模型
|
||||
type WorkRepairDetail struct {
|
||||
Model
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
RepairID uint64 `gorm:"column:repair_id;type:int(11);default:0;comment:维修工单ID" json:"-"`
|
||||
Tage WorkRepairDetailTags `gorm:"column:tage;type:varchar(255);default:null;comment:标签" json:"tage"`
|
||||
Remark string `gorm:"column:remark;type:varchar(255);default:null;comment:备注信息" json:"remark"`
|
||||
Other string `gorm:"column:other;type:varchar(255);default:null;comment:其他信息" json:"other"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
type (
|
||||
WorkRepairDetailForFinish struct {
|
||||
Image string `json:"image"`
|
||||
}
|
||||
)
|
||||
|
||||
type WorkRepairDetailTags string
|
||||
|
||||
const (
|
||||
WorkRepairDetailTagsForBegin WorkRepairDetailTags = "开始维修"
|
||||
WorkRepairDetailTagsForFinish WorkRepairDetailTags = "完成维修"
|
||||
)
|
||||
|
||||
func (m *WorkRepairDetail) TableName() string {
|
||||
return "work_repair_detail"
|
||||
}
|
||||
|
||||
func NewWorkRepairDetail() *WorkRepairDetail {
|
||||
return &WorkRepairDetail{}
|
||||
}
|
@ -6,6 +6,7 @@ import (
|
||||
"ArmedPolice/app/handle"
|
||||
"ArmedPolice/app/model"
|
||||
"ArmedPolice/app/service"
|
||||
"ArmedPolice/lib"
|
||||
"ArmedPolice/serve/orm"
|
||||
"ArmedPolice/utils"
|
||||
"errors"
|
||||
@ -376,7 +377,10 @@ func (c *Instance) Examine(id uint64, status int, remark string, isAssist int) e
|
||||
if workUpdates["status"] == model2.WorkInstanceStatusForComplete {
|
||||
// 创建维修工单
|
||||
mWorkRepair := model.NewWorkRepair()
|
||||
mWorkRepair.OrderNo = lib.OrderNo()
|
||||
mWorkRepair.WorkID = mWorkInstance.ID
|
||||
// 默认进行中
|
||||
mWorkRepair.Status = model2.WorkRepairStatusForOngoing
|
||||
|
||||
if err = model2.Create(mWorkRepair.WorkRepair, tx); err != nil {
|
||||
return err
|
||||
|
191
app/controller/work/repair.go
Normal file
191
app/controller/work/repair.go
Normal file
@ -0,0 +1,191 @@
|
||||
package work
|
||||
|
||||
import (
|
||||
model2 "ArmedPolice/app/common/model"
|
||||
"ArmedPolice/app/controller/basic"
|
||||
"ArmedPolice/app/model"
|
||||
"ArmedPolice/app/service"
|
||||
"ArmedPolice/serve/orm"
|
||||
"ArmedPolice/utils"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Repair struct{ *service.Session }
|
||||
|
||||
type RepairHandle func(session *service.Session) *Repair
|
||||
|
||||
type (
|
||||
// RepairInfo 基本信息
|
||||
RepairInfo struct {
|
||||
basic.CommonIDString
|
||||
*model.WorkRepairInfo
|
||||
}
|
||||
// RepairDetailInfo 详细信息
|
||||
RepairDetailInfo struct {
|
||||
*RepairInfo
|
||||
Details []*model2.WorkRepairDetail `json:"details"`
|
||||
}
|
||||
)
|
||||
|
||||
// List 列表信息
|
||||
func (c *Repair) List(orderNo, equipmentCode, equipmentTitle string, page, pageSize int) (*basic.PageDataResponse, error) {
|
||||
mWorkRepair := model.NewWorkRepair()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if orderNo != "" {
|
||||
where = append(where, model2.NewWhereLike("r.order_no", orderNo))
|
||||
}
|
||||
if equipmentCode != "" {
|
||||
where = append(where, model2.NewWhereLike("w.code", equipmentCode))
|
||||
}
|
||||
if equipmentTitle != "" {
|
||||
where = append(where, model2.NewWhereLike("w.title", equipmentTitle))
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mWorkRepair.Repairs(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*RepairInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &RepairInfo{
|
||||
CommonIDString: basic.CommonIDString{v.GetEncodeID()},
|
||||
WorkRepairInfo: v,
|
||||
})
|
||||
}
|
||||
return &basic.PageDataResponse{Data: nil, Count: 0}, nil
|
||||
}
|
||||
|
||||
// Detail 详细信息
|
||||
func (c *Repair) Detail(id uint64) (*RepairDetailInfo, error) {
|
||||
|
||||
repair, err := model.NewWorkRepair().Detail(id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
details := make([]*model2.WorkRepairDetail, 0)
|
||||
|
||||
if err = model2.Find(model.NewWorkRepairDetail().WorkRepairDetail, &details, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("repair_id", id),
|
||||
Order: model2.NewOrder("id", model2.OrderModeToAsc),
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &RepairDetailInfo{
|
||||
RepairInfo: &RepairInfo{
|
||||
CommonIDString: basic.CommonIDString{repair.GetEncodeID()},
|
||||
WorkRepairInfo: repair,
|
||||
},
|
||||
Details: details,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Begin 开始维修操作
|
||||
func (c *Repair) Begin(id uint64, remark string) error {
|
||||
mWorkRepair := model.NewWorkRepair()
|
||||
mWorkRepair.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mWorkRepair.WorkRepair, []string{"id", "status"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,维修工单信息不存在或已被删除")
|
||||
}
|
||||
if mWorkRepair.Status != model2.WorkRepairStatusForNotBegin {
|
||||
return errors.New("操作错误,维修工单状态异常,不可操作")
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Updates(mWorkRepair.WorkRepair, map[string]interface{}{
|
||||
"status": model2.WorkRepairStatusForOngoing, "updated_at": time.Now(),
|
||||
}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
// 维修工单详情
|
||||
mWorkRepairDetail := model.NewWorkRepairDetail()
|
||||
mWorkRepairDetail.UID = c.UID
|
||||
mWorkRepairDetail.RepairID = id
|
||||
mWorkRepairDetail.Tage = model2.WorkRepairDetailTagsForBegin
|
||||
mWorkRepairDetail.Remark = remark
|
||||
|
||||
if err = model2.Create(mWorkRepairDetail.WorkRepairDetail, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Finish 完成维修操作
|
||||
func (c *Repair) Finish(id uint64, image, remark string) error {
|
||||
mWorkRepair := model.NewWorkRepair()
|
||||
mWorkRepair.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mWorkRepair.WorkRepair, []string{"id", "status"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,维修工单信息不存在或已被删除")
|
||||
}
|
||||
if mWorkRepair.Status != model2.WorkRepairStatusForOngoing {
|
||||
return errors.New("操作错误,维修工单状态异常,不可操作")
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Updates(mWorkRepair.WorkRepair, map[string]interface{}{
|
||||
"status": model2.WorkRepairStatusForFinished, "updated_at": time.Now(),
|
||||
}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
// 维修工单详情
|
||||
mWorkRepairDetail := model.NewWorkRepairDetail()
|
||||
mWorkRepairDetail.UID = c.UID
|
||||
mWorkRepairDetail.RepairID = id
|
||||
mWorkRepairDetail.Tage = model2.WorkRepairDetailTagsForFinish
|
||||
mWorkRepairDetail.Remark = remark
|
||||
mWorkRepairDetail.Other = utils.AnyToJSON(&model2.WorkRepairDetailForFinish{Image: image})
|
||||
|
||||
if err = model2.Create(mWorkRepairDetail.WorkRepairDetail, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Evaluate 评价
|
||||
func (c *Repair) Evaluate(id uint64, score float64) error {
|
||||
mWorkRepair := model.NewWorkRepair()
|
||||
mWorkRepair.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mWorkRepair.WorkRepair, []string{"id", "status", "is_evaluate"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,维修工单信息不存在或已被删除")
|
||||
}
|
||||
if mWorkRepair.Status != model2.WorkRepairStatusForFinished {
|
||||
return errors.New("操作错误,维修工单状态异常,不可操作")
|
||||
}
|
||||
if mWorkRepair.IsEvaluate != model2.WorkRepairStatusEvaluateForNot {
|
||||
return errors.New("操作错误,当前工单已评价,不可重复评价")
|
||||
}
|
||||
if err = model2.Updates(mWorkRepair.WorkRepair, map[string]interface{}{
|
||||
"is_evaluate": model2.WorkRepairStatusEvaluateForYes, "evaluate_score": score, "updated_at": time.Now(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewRepair() RepairHandle {
|
||||
return func(session *service.Session) *Repair {
|
||||
return &Repair{session}
|
||||
}
|
||||
}
|
@ -1,11 +1,68 @@
|
||||
package model
|
||||
|
||||
import "ArmedPolice/app/common/model"
|
||||
import (
|
||||
"ArmedPolice/app/common/model"
|
||||
"ArmedPolice/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type WorkRepair struct {
|
||||
*model.WorkRepair
|
||||
}
|
||||
|
||||
// WorkRepairInfo 维修工单信息
|
||||
type WorkRepairInfo struct {
|
||||
*model.WorkRepair
|
||||
Title string `json:"title"`
|
||||
EquipmentCode string `json:"equipment_code"`
|
||||
EquipmentTitle string `json:"equipment_title"`
|
||||
Priority int `json:"priority"`
|
||||
BreakdownTitle string `json:"breakdown_title"`
|
||||
}
|
||||
|
||||
// Repairs 维修工单信息
|
||||
func (m *WorkRepair) Repairs(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*WorkRepairInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" r").
|
||||
Select("r.id", "r.order_no", "e.code AS equipment_code", "e.title AS equipment_title", "w.priority",
|
||||
"(SELECT GROUP_CONCAT(s_b.title) FROM (SELECT id, title FROM sys_breakdown) AS s_b WHERE FIND_IN_SET(s_b.id, w.breakdown)) AS breakdown_title",
|
||||
"r.created_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS w ON r.work_id = w.id", model.NewWorkInstance().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS e ON w.equipment_id = e.id", model.NewManageEquipment().TableName()))
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*WorkRepairInfo, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("r.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Detail 维修工单信息
|
||||
func (m *WorkRepair) Detail(id uint64) (*WorkRepairInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" r").
|
||||
Select("r.id", "r.order_no", "e.code AS equipment_code", "e.title AS equipment_title", "w.priority",
|
||||
"(SELECT GROUP_CONCAT(s_b.title) FROM (SELECT id, title FROM sys_breakdown) AS s_b WHERE FIND_IN_SET(s_b.id, w.breakdown)) AS breakdown_title",
|
||||
"r.created_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS w ON r.work_id = w.id", model.NewWorkInstance().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS e ON w.equipment_id = e.id", model.NewManageEquipment().TableName())).
|
||||
Where("r.id = ?", id)
|
||||
|
||||
out := new(WorkRepairInfo)
|
||||
|
||||
if err := db.Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewWorkRepair() *WorkRepair {
|
||||
return &WorkRepair{model.NewWorkRepair()}
|
||||
}
|
||||
|
11
app/model/work_repair_detail.go
Normal file
11
app/model/work_repair_detail.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "ArmedPolice/app/common/model"
|
||||
|
||||
type WorkRepairDetail struct {
|
||||
*model.WorkRepairDetail
|
||||
}
|
||||
|
||||
func NewWorkRepairDetail() *WorkRepairDetail {
|
||||
return &WorkRepairDetail{model.NewWorkRepairDetail()}
|
||||
}
|
Reference in New Issue
Block a user