feat:完善项目
This commit is contained in:
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}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user