feat:完善项目
This commit is contained in:
@ -787,3 +787,14 @@ func (*Work) RepairEvaluate(c *gin.Context) {
|
||||
err := work.NewRepair()(getSession()(c).(*service.Session)).Evaluate(form.Convert(), form.Score)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Work) RepairDelete(c *gin.Context) {
|
||||
form := new(IDStringForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := work.NewRepair()(getSession()(c).(*service.Session)).Delete(form.Convert())
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
@ -5,8 +5,6 @@ import (
|
||||
"ArmedPolice/config"
|
||||
"ArmedPolice/lib"
|
||||
"ArmedPolice/serve/orm"
|
||||
"ArmedPolice/utils"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type synchronized struct {
|
||||
@ -21,6 +19,40 @@ type caches struct {
|
||||
toCache func(values interface{})
|
||||
}
|
||||
|
||||
type (
|
||||
// structForSysConfig 系统配置
|
||||
structForSysConfig struct {
|
||||
ID uint64 `json:"id"`
|
||||
Kind int `json:"kind"`
|
||||
Name string `json:"name"`
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
IsDeleted int `json:"is_deleted"`
|
||||
}
|
||||
// structForSysRole 角色配置
|
||||
structForSysRole struct {
|
||||
ID uint64 `json:"id"`
|
||||
TenantID uint64 `json:"tenant_id"`
|
||||
ParentID uint64 `json:"parent_id"`
|
||||
Name string `json:"name"`
|
||||
Remark string `json:"remark"`
|
||||
Sort int `json:"sort"`
|
||||
IsDeleted int `json:"is_deleted"`
|
||||
}
|
||||
// structForWorkSchedule 工单流程配置
|
||||
structForWorkSchedule struct {
|
||||
ID uint64 `json:"id"`
|
||||
Kind int `json:"kind"`
|
||||
Title string `json:"title"`
|
||||
Stage int `json:"stage"`
|
||||
Step int `json:"step"`
|
||||
Target int `json:"target"`
|
||||
TargetValue string `json:"target_value"`
|
||||
IsCountersign int `json:"is_countersign"`
|
||||
IsDeleted int `json:"is_deleted"`
|
||||
}
|
||||
)
|
||||
|
||||
func initModel() {
|
||||
db := orm.GetDB()
|
||||
|
||||
@ -40,10 +72,23 @@ func initModel() {
|
||||
function(
|
||||
&synchronized{iModel: model.NewSysTenant()},
|
||||
&synchronized{iModel: model.NewSysConfig(), iValues: func() interface{} {
|
||||
values := make([]*model.SysConfig, 0)
|
||||
lib.LoadConfig("./json/sys_config.json", &values)
|
||||
fmt.Println(utils.AnyToJSON(values))
|
||||
return values
|
||||
values := make([]*structForSysConfig, 0)
|
||||
|
||||
out := make([]*model.SysConfig, 0)
|
||||
|
||||
lib.LoadConfig("./json/sys_config.json", &values, func(i interface{}) {
|
||||
for _, v := range values {
|
||||
out = append(out, &model.SysConfig{
|
||||
Model: model.Model{ID: v.ID},
|
||||
Kind: model.SysConfigKind(v.Kind),
|
||||
Name: v.Name,
|
||||
Key: v.Key,
|
||||
Value: v.Value,
|
||||
ModelDeleted: model.ModelDeleted{IsDeleted: model.DeleteStatus(v.IsDeleted)},
|
||||
})
|
||||
}
|
||||
})
|
||||
return out
|
||||
}},
|
||||
&synchronized{iModel: model.NewSysMenu()}, &synchronized{iModel: model.NewSysAuth()},
|
||||
&synchronized{iModel: model.NewSysUser(), iValues: func() interface{} {
|
||||
@ -51,9 +96,23 @@ func initModel() {
|
||||
IsAdmin: model.SysUserAdministratorForAdmin, Remark: "超级管理员"}
|
||||
}},
|
||||
&synchronized{iModel: model.NewSysRole(), iValues: func() interface{} {
|
||||
values := make([]*model.SysRole, 0)
|
||||
lib.LoadConfig("./json/sys_role.json", &values)
|
||||
return values
|
||||
out := make([]*model.SysRole, 0)
|
||||
values := make([]*structForSysRole, 0)
|
||||
|
||||
lib.LoadConfig("./json/sys_role.json", &values, func(i interface{}) {
|
||||
for _, v := range values {
|
||||
out = append(out, &model.SysRole{
|
||||
Model: model.Model{ID: v.ID},
|
||||
ModelTenant: model.ModelTenant{TenantID: v.TenantID},
|
||||
ParentID: v.ParentID,
|
||||
Name: v.Name,
|
||||
Remark: v.Remark,
|
||||
Sort: v.Sort,
|
||||
ModelDeleted: model.ModelDeleted{IsDeleted: model.DeleteStatus(v.IsDeleted)},
|
||||
})
|
||||
}
|
||||
})
|
||||
return out
|
||||
}}, &synchronized{iModel: model.NewSysRoleMenu()}, &synchronized{iModel: model.NewSysRoleAuth()},
|
||||
&synchronized{iModel: model.NewSysUserRole()},
|
||||
// 日志管理
|
||||
@ -68,10 +127,28 @@ func initModel() {
|
||||
&synchronized{iModel: model.NewManageMaterialPurchase()}, &synchronized{iModel: model.NewManageMaterialWarehouse()},
|
||||
&synchronized{iModel: model.NewWorkInstance()}, &synchronized{iModel: model.NewWorkMaterial()}, &synchronized{iModel: model.NewWorkProgress()},
|
||||
&synchronized{iModel: model.NewWorkSchedule(), iValues: func() interface{} {
|
||||
values := make([]*model.WorkSchedule, 0)
|
||||
lib.LoadConfig("./json/work_schedule.json", &values)
|
||||
return values
|
||||
}}, &synchronized{iModel: model.NewWorkPurchase()},
|
||||
out := make([]*model.WorkSchedule, 0)
|
||||
|
||||
values := make([]*structForWorkSchedule, 0)
|
||||
|
||||
lib.LoadConfig("./json/work_schedule.json", &values, func(i interface{}) {
|
||||
for _, v := range values {
|
||||
out = append(out, &model.WorkSchedule{
|
||||
Model: model.Model{ID: v.ID},
|
||||
Kind: model.WorkScheduleKind(v.Kind),
|
||||
Title: v.Title,
|
||||
Stage: v.Stage,
|
||||
Step: v.Step,
|
||||
Target: model.WorkScheduleTarget(v.Target),
|
||||
TargetValue: v.TargetValue,
|
||||
IsCountersign: model.WorkScheduleCountersign(v.IsCountersign),
|
||||
ModelDeleted: model.ModelDeleted{IsDeleted: model.DeleteStatus(v.IsDeleted)},
|
||||
})
|
||||
}
|
||||
})
|
||||
return out
|
||||
},
|
||||
}, &synchronized{iModel: model.NewWorkPurchase()},
|
||||
&synchronized{iModel: model.NewWorkRepair()}, &synchronized{iModel: model.NewWorkRepairDetail()},
|
||||
)
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ type WorkRepair struct {
|
||||
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"`
|
||||
EvaluateScore float64 `gorm:"column:evaluate_score;type:decimal(10,2);default:0;comment:评价分数" json:"evaluate_score"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
@ -455,7 +455,7 @@ func (c *Instance) Examine(id uint64, status int, remark string, isAssist int, p
|
||||
mWorkInstance := model.NewWorkInstance()
|
||||
mWorkInstance.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mWorkInstance.WorkInstance, []string{"id", "kind", "schedule", "status"})
|
||||
isExist, err := model2.FirstField(mWorkInstance.WorkInstance, []string{"id", "kind", "schedule", "is_assist", "status"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@ -490,12 +490,18 @@ func (c *Instance) Examine(id uint64, status int, remark string, isAssist int, p
|
||||
mWorkProgress.Status = _status
|
||||
mWorkProgress.Remark = remark
|
||||
|
||||
if mWorkProgress.Remark == "" {
|
||||
mWorkProgress.Remark = "审批通过"
|
||||
}
|
||||
if err = model2.Create(mWorkProgress.WorkProgress, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
workUpdates := map[string]interface{}{
|
||||
"status": model2.WorkInstanceStatusForComplete, "updated_at": time.Now(),
|
||||
}
|
||||
// 上一流程
|
||||
// TODO:获取上一流程,代码写的不好,后期优化考虑
|
||||
lastWorkSchedule := new(model.WorkScheduleInfo)
|
||||
// 下一流程
|
||||
nextScheduleInfo := new(model.WorkScheduleInfo)
|
||||
|
||||
@ -503,8 +509,13 @@ func (c *Instance) Examine(id uint64, status int, remark string, isAssist int, p
|
||||
if _status == model2.WorkProgressStatusForRefuse {
|
||||
goto FINISH
|
||||
}
|
||||
// 上一流程信息
|
||||
if lastWorkSchedule, err = mWorkSchedule.LastSchedule(); err != nil {
|
||||
return err
|
||||
}
|
||||
//
|
||||
// 下一流程信息
|
||||
if nextScheduleInfo, err = mWorkSchedule.NextSchedule(model2.WorkInstanceAssist(isAssist) == model2.WorkInstanceAssistForYes); err != nil {
|
||||
if nextScheduleInfo, err = mWorkSchedule.NextSchedule(mWorkInstance.IsAssist == model2.WorkInstanceAssistForYes); err != nil {
|
||||
return err
|
||||
}
|
||||
// 无下一流程,工单直接完成
|
||||
@ -514,7 +525,8 @@ func (c *Instance) Examine(id uint64, status int, remark string, isAssist int, p
|
||||
workUpdates["status"] = model2.WorkInstanceStatusForOngoing
|
||||
workUpdates["schedule"] = nextScheduleInfo.ID
|
||||
|
||||
if nextScheduleInfo.IsNextStage {
|
||||
// 当前阶段无上一流程才会更新
|
||||
if lastWorkSchedule == nil {
|
||||
workUpdates["is_assist"] = isAssist
|
||||
}
|
||||
FINISH:
|
||||
|
@ -39,10 +39,10 @@ func (c *Repair) List(orderNo, equipmentCode, equipmentTitle string, page, pageS
|
||||
where = append(where, model2.NewWhereLike("r.order_no", orderNo))
|
||||
}
|
||||
if equipmentCode != "" {
|
||||
where = append(where, model2.NewWhereLike("w.code", equipmentCode))
|
||||
where = append(where, model2.NewWhereLike("e.code", equipmentCode))
|
||||
}
|
||||
if equipmentTitle != "" {
|
||||
where = append(where, model2.NewWhereLike("w.title", equipmentTitle))
|
||||
where = append(where, model2.NewWhereLike("e.title", equipmentTitle))
|
||||
}
|
||||
var count int64
|
||||
|
||||
@ -55,11 +55,11 @@ func (c *Repair) List(orderNo, equipmentCode, equipmentTitle string, page, pageS
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &RepairInfo{
|
||||
CommonIDString: basic.CommonIDString{v.GetEncodeID()},
|
||||
CommonIDString: basic.CommonIDString{ID: v.GetEncodeID()},
|
||||
WorkRepairInfo: v,
|
||||
})
|
||||
}
|
||||
return &basic.PageDataResponse{Data: nil, Count: 0}, nil
|
||||
return &basic.PageDataResponse{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
// Detail 详细信息
|
||||
@ -80,7 +80,7 @@ func (c *Repair) Detail(id uint64) (*RepairDetailInfo, error) {
|
||||
}
|
||||
return &RepairDetailInfo{
|
||||
RepairInfo: &RepairInfo{
|
||||
CommonIDString: basic.CommonIDString{repair.GetEncodeID()},
|
||||
CommonIDString: basic.CommonIDString{ID: repair.GetEncodeID()},
|
||||
WorkRepairInfo: repair,
|
||||
},
|
||||
Details: details,
|
||||
@ -211,7 +211,7 @@ func (c *Repair) Evaluate(id uint64, score float64) error {
|
||||
if isExist, err = model2.FirstField(mManageSupplierEvaluate.ManageSupplierEvaluate, []string{"id"},
|
||||
model2.NewWhere("id", v)); err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
} else if isExist {
|
||||
if err = model2.Updates(mManageSupplierEvaluate.ManageSupplierEvaluate, updates, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -222,7 +222,7 @@ func (c *Repair) Evaluate(id uint64, score float64) error {
|
||||
if score == 1 {
|
||||
data.Praise = 1
|
||||
} else if score == 2 {
|
||||
data.Middle = 2
|
||||
data.Middle = 1
|
||||
} else {
|
||||
data.Negative = 1
|
||||
}
|
||||
@ -237,6 +237,13 @@ func (c *Repair) Evaluate(id uint64, score float64) error {
|
||||
})
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Repair) Delete(id uint64) error {
|
||||
mWorkRepair := model.NewWorkRepair()
|
||||
mWorkRepair.ID = id
|
||||
return model2.Delete(mWorkRepair.WorkRepair)
|
||||
}
|
||||
|
||||
func NewRepair() RepairHandle {
|
||||
return func(session *service.Session) *Repair {
|
||||
return &Repair{session}
|
||||
|
@ -18,6 +18,7 @@ type WorkRepairInfo struct {
|
||||
EquipmentTitle string `json:"equipment_title"`
|
||||
Priority int `json:"priority"`
|
||||
BreakdownTitle string `json:"breakdown_title"`
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type WorkRepairEvaluateInfo struct {
|
||||
@ -29,9 +30,11 @@ func (m *WorkRepair) Repairs(page, pageSize int, count *int64, where ...*model.M
|
||||
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").
|
||||
"r.is_evaluate", "r.evaluate_score", "r.status", "u.name AS username", "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()))
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS e ON w.equipment_id = e.id", model.NewManageEquipment().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON w.uid = u.uuid", model.NewSysUser().TableName())).
|
||||
Where("r.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
|
@ -18,9 +18,8 @@ type WorkSchedules struct {
|
||||
|
||||
// WorkScheduleInfo 工单流程信息
|
||||
type WorkScheduleInfo struct {
|
||||
ID uint64 `json:"id"`
|
||||
IsNextStage bool `json:"is_next_stage"` // 下一步骤
|
||||
Reviewer []string `json:"reviewer"`
|
||||
ID uint64 `json:"id"`
|
||||
Reviewer []string `json:"reviewer"`
|
||||
}
|
||||
|
||||
// ValidateAuth 验证权限
|
||||
@ -70,6 +69,22 @@ func (m *WorkSchedule) FirstSchedule(kind model.WorkScheduleKind) (bool, error)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// LastSchedule 上一流程信息
|
||||
func (m *WorkSchedule) LastSchedule() (*WorkScheduleInfo, error) {
|
||||
mLastWorkSchedule := model.NewWorkSchedule()
|
||||
|
||||
isExist, err := model.FirstField(mLastWorkSchedule, []string{"id", "stage", "step"},
|
||||
model.NewWhere("kind", m.Kind),
|
||||
model.NewWhere("stage", m.Stage), model.NewWhereCondition("step", "<", m.Step))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !isExist { // 直接抛出当前阶段下一流程信息
|
||||
return nil, nil
|
||||
}
|
||||
return &WorkScheduleInfo{ID: mLastWorkSchedule.ID, Reviewer: mLastWorkSchedule.GetTargetValueAttribute()}, err
|
||||
}
|
||||
|
||||
// NextSchedule 下一流程
|
||||
func (m *WorkSchedule) NextSchedule(isAssets bool) (*WorkScheduleInfo, error) {
|
||||
nextWorkSchedule := model.NewWorkSchedule()
|
||||
@ -80,7 +95,7 @@ func (m *WorkSchedule) NextSchedule(isAssets bool) (*WorkScheduleInfo, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if isExist { // 直接抛出当前阶段下一流程信息
|
||||
return &WorkScheduleInfo{ID: nextWorkSchedule.ID, Reviewer: nextWorkSchedule.GetTargetValueAttribute()}, err
|
||||
goto RETURN
|
||||
}
|
||||
// 进入下一阶段
|
||||
// 是否需要下一阶段协助
|
||||
@ -99,7 +114,17 @@ func (m *WorkSchedule) NextSchedule(isAssets bool) (*WorkScheduleInfo, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return &WorkScheduleInfo{ID: nextWorkSchedule.ID, IsNextStage: true, Reviewer: nextWorkSchedule.GetTargetValueAttribute()}, err
|
||||
RETURN:
|
||||
//var count int64
|
||||
//// 判断是否当前阶段第一个元素
|
||||
//if err = orm.GetDB().Table(nextWorkSchedule.TableName()).
|
||||
// Where("kind = ? AND is_deleted = ?", nextWorkSchedule.Kind, model.DeleteStatusForNot).
|
||||
// Where("stage = ?", nextWorkSchedule.Stage).
|
||||
// Where("step < ?", nextWorkSchedule.Step).
|
||||
// Count(&count).Error; err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
return &WorkScheduleInfo{ID: nextWorkSchedule.ID, Reviewer: nextWorkSchedule.GetTargetValueAttribute()}, err
|
||||
}
|
||||
|
||||
// Schedules 流程信息
|
||||
|
23
lib/config_test.go
Normal file
23
lib/config_test.go
Normal file
@ -0,0 +1,23 @@
|
||||
package lib
|
||||
|
||||
import (
|
||||
"ArmedPolice/utils"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type (
|
||||
structForSysConfig struct {
|
||||
ID uint64 `json:"id"`
|
||||
Kind int `json:"kind"`
|
||||
Name string `json:"name"`
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
IsDeleted int `json:"is_deleted"`
|
||||
}
|
||||
)
|
||||
|
||||
func TestLoadConfig(t *testing.T) {
|
||||
values := make([]*structForSysConfig, 0)
|
||||
LoadConfig("../json/sys_config.json", &values)
|
||||
t.Log(utils.AnyToJSON(values))
|
||||
}
|
@ -205,6 +205,7 @@ func (this *Router) registerAPI() {
|
||||
workV1.POST("/repair/begin", _api.RepairBegin)
|
||||
workV1.POST("/repair/finish", _api.RepairFinish)
|
||||
workV1.POST("/repair/evaluate", _api.RepairEvaluate)
|
||||
workV1.POST("/repair/delete", _api.RepairDelete)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,6 @@ import "testing"
|
||||
|
||||
func TestSha256String(t *testing.T) {
|
||||
//t.Log(Md5String("9f735e0df9a1ddc702bf0a1a7b83033f9f7153a00c29de82cedadc9957289b05"))
|
||||
t.Log(HASHIDEncode(35))
|
||||
t.Log(HASHIDEncode(65))
|
||||
t.Log(HASHIDDecode("EgmJ4Ga7LQ"))
|
||||
}
|
||||
|
Reference in New Issue
Block a user