Files

596 lines
18 KiB
Go
Raw Normal View History

2021-11-02 16:22:07 +08:00
package work
import (
2021-11-05 15:27:04 +08:00
model2 "ArmedPolice/app/common/model"
2021-11-02 16:22:07 +08:00
"ArmedPolice/app/controller/basic"
2021-11-08 17:42:23 +08:00
"ArmedPolice/app/handle"
2021-11-05 15:27:04 +08:00
"ArmedPolice/app/model"
2021-11-02 16:22:07 +08:00
"ArmedPolice/app/service"
2021-11-11 17:10:43 +08:00
"ArmedPolice/lib"
2021-11-08 17:42:23 +08:00
"ArmedPolice/serve/orm"
"ArmedPolice/utils"
"errors"
"gorm.io/gorm"
"time"
2021-11-02 16:22:07 +08:00
)
type Instance struct{ *service.Session }
type InstanceHandle func(session *service.Session) *Instance
2021-11-05 15:27:04 +08:00
type (
// InstanceInfo 基本信息
InstanceInfo struct {
basic.CommonIDString
*model.WorkInstanceInfo
}
2021-11-09 14:08:02 +08:00
// InstanceDetailInfo 详细信息
InstanceDetailInfo struct {
basic.CommonIDString
*model.WorkInstanceInfo
2021-11-19 15:34:22 +08:00
EquipmentID string `json:"equipment_id"`
ScheduleID string `json:"schedule_id"`
Outside struct {
2021-11-18 09:51:39 +08:00
SupplierName string `json:"supplier_name"`
2021-11-19 11:53:20 +08:00
} `json:"outside"`
2021-11-18 09:51:39 +08:00
Within struct {
Material []*model.WorkMaterialInfo `json:"material"`
2021-11-19 09:24:15 +08:00
Purchase []*model.WorkPurchaseInfo `json:"purchase"`
2021-11-18 09:51:39 +08:00
} `json:"within"`
2021-11-11 14:05:52 +08:00
Distribution *model2.WorkInstanceDistribution `json:"distribution"`
2021-11-18 09:51:39 +08:00
History []*model.WorkProgressInfo `json:"history"`
2021-11-09 14:08:02 +08:00
}
2021-11-08 17:42:23 +08:00
// InstanceLaunchParams 发起参数信息
InstanceLaunchParams struct {
ID uint64
Kind int // 类型
Title string
EquipmentID uint64 // 装备ID
Breakdowns []uint64 // 故障类型
PlateNumber string // 车牌号
Priority, IsAssist int // 优先级,是否需要上级审批
Remark string // 备注信息
2021-11-18 09:51:39 +08:00
Supplier *InstanceLaunchParamsForSupplier
2021-11-08 17:42:23 +08:00
Material []*InstanceLaunchParamsForMaterial
2021-11-18 18:28:34 +08:00
Purchase []*InstanceLaunchParamsForPurchase
2021-11-08 17:42:23 +08:00
Distribution *InstanceLaunchParamsForDistribution
}
2021-11-18 09:51:39 +08:00
// InstanceLaunchParamsForSupplier 供应商信息
InstanceLaunchParamsForSupplier struct {
SupplierID uint64 `json:"supplier_id"`
}
2021-11-08 17:42:23 +08:00
// InstanceLaunchParamsForMaterial 配件信息
InstanceLaunchParamsForMaterial struct {
2021-11-11 14:05:52 +08:00
ID uint64 // 器材ID
SupplierID uint64 // 供应商ID
Number float64 // 需要数量
2021-11-08 17:42:23 +08:00
}
2021-11-18 18:28:34 +08:00
// InstanceLaunchParamsForPurchase 采购信息
InstanceLaunchParamsForPurchase struct {
ID uint64 // 器材ID
SupplierID uint64 // 供应商ID
Price float64 // 采购单价
Number float64 // 采购数量
}
2021-11-08 17:42:23 +08:00
// InstanceLaunchParamsForDistribution 配送信息
InstanceLaunchParamsForDistribution struct {
Name, Mobile, Address string
}
2021-11-18 18:28:34 +08:00
// InstanceExamineParams 审核参数信息
InstanceExamineParams struct {
Material []*InstanceLaunchParamsForMaterial
Purchase []*InstanceLaunchParamsForPurchase
}
2021-11-05 15:27:04 +08:00
)
2021-11-18 09:51:39 +08:00
func (c *Instance) publish(kind int, reviewer []string) {
msg := &service.HubEmit{
Msg: handle.NewWorkNotice("你有一条待办事项", &struct {
Kind int `json:"kind"`
}{
Kind: kind,
}),
}
2021-11-08 17:42:23 +08:00
utils.TryCatch(func() {
for _, v := range reviewer {
2021-11-18 09:51:39 +08:00
msg.ID = v
service.HubMessage.EmitHandle(msg)
2021-11-08 17:42:23 +08:00
}
})
}
2021-11-18 18:28:34 +08:00
func (c *Instance) material(tx *gorm.DB, material []*InstanceLaunchParamsForMaterial, workID uint64) error {
// 工单器材信息
workMaterials := make([]*model2.WorkMaterial, 0)
for _, v := range material {
if v.ID <= 0 || v.SupplierID <= 0 || v.Number <= 0 {
return errors.New("操作错误,器材参数不完全")
}
workMaterials = append(workMaterials, &model2.WorkMaterial{
MaterialID: v.ID, MaterialSupplierID: v.SupplierID, MaterialNumber: v.Number,
})
}
// 处理库存信息
if len(workMaterials) > 0 {
mManageMaterialSupplier := model.NewManageMaterialSupplier()
now := time.Now()
for _, v := range workMaterials {
v.WorkID = workID
if err := model2.UpdatesWhere(mManageMaterialSupplier.ManageMaterialSupplier, map[string]interface{}{
"frozen_stock": gorm.Expr("frozen_stock + ?", v.MaterialNumber), "updated_at": now,
}, []*model2.ModelWhere{
model2.NewWhere("material_id", v.MaterialID),
model2.NewWhere("supplier_id", v.MaterialSupplierID),
}, tx); err != nil {
return err
}
}
mWorkMaterial := model.NewWorkMaterial()
if err := model2.Creates(mWorkMaterial.WorkMaterial, &workMaterials, tx); err != nil {
return err
}
}
return nil
}
/// purchase 采购操作
2021-11-19 09:24:15 +08:00
func (c *Instance) purchase(tx *gorm.DB, purchase []*InstanceLaunchParamsForPurchase, workID uint64) error {
//mManageMaterialPurchase := model.NewManageMaterialPurchase()
2021-11-18 18:28:34 +08:00
2021-11-19 09:24:15 +08:00
//_purchase := make([]*model2.ManageMaterialPurchase, 0)
2021-11-18 18:28:34 +08:00
for _, v := range purchase {
2021-11-19 09:24:15 +08:00
mManageMaterialPurchase := model.NewManageMaterialPurchase()
mManageMaterialPurchase.UID = c.UID
mManageMaterialPurchase.OrderNo = lib.OrderNo()
mManageMaterialPurchase.MaterialID = v.ID
mManageMaterialPurchase.SupplierID = v.SupplierID
mManageMaterialPurchase.Price = v.Price
mManageMaterialPurchase.Number = v.Number
mManageMaterialPurchase.Remark = "工单采购"
err := model2.Create(mManageMaterialPurchase.ManageMaterialPurchase, tx)
if err != nil {
2021-11-18 18:28:34 +08:00
return err
}
2021-11-19 09:24:15 +08:00
mWorkPurchase := model.NewWorkPurchase()
mWorkPurchase.WorkID = workID
mWorkPurchase.MaterialPurchaseID = mManageMaterialPurchase.ID
if err = model2.Create(mWorkPurchase.WorkPurchase, tx); err != nil {
return err
}
//_purchase = append(_purchase, &model2.ManageMaterialPurchase{
// UID: c.UID,
// OrderNo: lib.OrderNo(),
// MaterialID: v.ID,
// SupplierID: v.SupplierID,
// Price: v.Price,
// Number: v.Number,
// Remark: "工单采购",
//})
}
//if len(_purchase) > 0 {
// if err := model2.Creates(mManageMaterialPurchase.ManageMaterialPurchase, _purchase, tx); err != nil {
// return err
// }
//}
2021-11-18 18:28:34 +08:00
return nil
}
2021-11-05 15:27:04 +08:00
// List 列表信息
2021-11-19 09:24:15 +08:00
func (c *Instance) List(equipmentCode, equipmentTitle string, kind, page, pageSize int) (*basic.PageDataResponse, error) {
2021-11-05 15:27:04 +08:00
mWorkInstance := model.NewWorkInstance()
where := make([]*model2.ModelWhere, 0)
2021-11-19 09:24:15 +08:00
if equipmentCode != "" {
where = append(where, model2.NewWhereLike("e.code", equipmentCode))
}
if equipmentTitle != "" {
where = append(where, model2.NewWhereLike("e.title", equipmentTitle))
2021-11-05 15:27:04 +08:00
}
if kind > 0 {
where = append(where, model2.NewWhere("w.kind", kind))
}
var count int64
out, err := mWorkInstance.Instances(page, pageSize, &count, where...)
if err != nil {
return nil, err
}
list := make([]*InstanceInfo, 0)
mSysBreakdown := model.NewSysBreakdown()
2021-11-05 15:27:04 +08:00
for _, v := range out {
mWorkInstance.ID = v.ID
v.BreakdownTitle = mSysBreakdown.BreakdownTitle(v.Breakdown)
2021-11-05 15:27:04 +08:00
list = append(list, &InstanceInfo{
CommonIDString: basic.CommonIDString{ID: mWorkInstance.GetEncodeID()}, WorkInstanceInfo: v,
})
}
return &basic.PageDataResponse{Data: list, Count: count}, nil
}
2021-11-09 14:08:02 +08:00
// Person 个人提交的审核信息
2021-11-19 11:53:20 +08:00
func (c *Instance) Person(equipmentCode, equipmentTitle string, kind, page, pageSize int) (*basic.PageDataResponse, error) {
2021-11-09 14:08:02 +08:00
mWorkInstance := model.NewWorkInstance()
where := make([]*model2.ModelWhere, 0)
2021-11-19 11:53:20 +08:00
if equipmentCode != "" {
where = append(where, model2.NewWhereLike("e.code", equipmentCode))
}
if equipmentTitle != "" {
where = append(where, model2.NewWhereLike("e.title", equipmentTitle))
2021-11-09 14:08:02 +08:00
}
if kind > 0 {
where = append(where, model2.NewWhere("w.kind", kind))
}
var count int64
2021-11-15 17:32:23 +08:00
out, err := mWorkInstance.Persons(c.UID, page, pageSize, &count, where...)
2021-11-09 14:08:02 +08:00
if err != nil {
return nil, err
}
list := make([]*InstanceInfo, 0)
mSysBreakdown := model.NewSysBreakdown()
2021-11-09 14:08:02 +08:00
for _, v := range out {
mWorkInstance.ID = v.ID
v.BreakdownTitle = mSysBreakdown.BreakdownTitle(v.Breakdown)
2021-11-05 15:27:04 +08:00
2021-11-09 14:08:02 +08:00
list = append(list, &InstanceInfo{
CommonIDString: basic.CommonIDString{ID: mWorkInstance.GetEncodeID()}, WorkInstanceInfo: v,
})
}
return &basic.PageDataResponse{Data: list, Count: count}, nil
}
// Workbench 工作台
2021-11-19 11:53:20 +08:00
func (c *Instance) Workbench(equipmentCode, equipmentTitle string, kind, page, pageSize int) (*basic.PageDataResponse, error) {
2021-11-09 18:38:57 +08:00
// 查询用户角色信息
mSysUserRole := model.NewSysUserRole()
roleIDs := make([]string, 0)
2021-11-09 14:08:02 +08:00
2021-11-10 11:26:40 +08:00
err := model2.Pluck(mSysUserRole.SysUserRole, "role_id", &roleIDs, model2.NewWhere("uid", c.UID))
2021-11-09 18:38:57 +08:00
if err != nil {
return nil, err
}
2021-11-10 11:26:40 +08:00
mWorkInstance := model.NewWorkInstance()
where := make([]*model2.ModelWhere, 0)
2021-11-19 11:53:20 +08:00
if equipmentCode != "" {
where = append(where, model2.NewWhereLike("e.code", equipmentCode))
}
if equipmentTitle != "" {
where = append(where, model2.NewWhereLike("e.title", equipmentTitle))
2021-11-10 11:26:40 +08:00
}
if kind > 0 {
where = append(where, model2.NewWhere("w.kind", kind))
}
// 筛选用户可操作的流程信息
condition := &model.WorkbenchCondition{
UID: c.UIDToString(), RoleIDs: roleIDs,
}
if condition.WorkSchedule, err = model.NewWorkSchedule().WorkSchedules(model2.WorkScheduleKindForRepair, condition); err != nil {
return nil, err
}
2021-11-10 11:26:40 +08:00
var count int64
out := make([]*model.WorkInstanceInfo, 0)
if out, err = mWorkInstance.Workbenchs(condition, page, pageSize, &count, where...); err != nil {
2021-11-10 11:26:40 +08:00
return nil, err
}
2021-11-16 16:39:21 +08:00
list := make([]*InstanceInfo, 0)
mSysBreakdown := model.NewSysBreakdown()
2021-11-16 16:39:21 +08:00
for _, v := range out {
mWorkInstance.ID = v.ID
v.BreakdownTitle = mSysBreakdown.BreakdownTitle(v.Breakdown)
2021-11-16 16:39:21 +08:00
list = append(list, &InstanceInfo{
CommonIDString: basic.CommonIDString{ID: mWorkInstance.GetEncodeID()}, WorkInstanceInfo: v,
})
}
return &basic.PageDataResponse{Data: list, Count: count}, nil
2021-11-09 14:08:02 +08:00
}
2021-11-11 14:05:52 +08:00
// Detail 详细信息
func (c *Instance) Detail(id uint64) (*InstanceDetailInfo, error) {
out := new(InstanceDetailInfo)
var err error
2021-11-09 14:08:02 +08:00
mWorkInstance := model.NewWorkInstance()
2021-11-11 14:05:52 +08:00
// 基本信息
if out.WorkInstanceInfo, err = mWorkInstance.Detail(id); err != nil {
return nil, err
}
2021-11-18 09:51:39 +08:00
mWorkInstance.SetID(out.WorkInstanceInfo.ID)
out.CommonIDString = basic.CommonIDString{
2021-11-19 11:53:20 +08:00
ID: mWorkInstance.GetEncodeID(),
2021-11-18 09:51:39 +08:00
}
out.WorkInstanceInfo.BreakdownTitle = model.NewSysBreakdown().BreakdownTitle(out.WorkInstanceInfo.Breakdown)
2021-11-19 15:34:22 +08:00
out.EquipmentID = (&model2.Model{ID: out.WorkInstanceInfo.EquipmentID}).GetEncodeID()
out.ScheduleID = (&model2.Model{ID: out.WorkInstanceInfo.ScheduleID}).GetEncodeID()
2021-11-11 14:05:52 +08:00
// 位置信息
mWorkInstance.Distribution = out.WorkInstanceInfo.Distribution
2021-11-18 09:51:39 +08:00
2021-11-11 14:05:52 +08:00
out.Distribution = mWorkInstance.GetDistributionAttribute()
// 内修才有数据
if out.WorkInstanceInfo.Kind == model2.WorkInstanceKindForWithin {
2021-11-19 09:24:15 +08:00
// 器材信息
2021-11-18 09:51:39 +08:00
materials := make([]*model.WorkMaterialInfo, 0)
if materials, err = model.NewWorkMaterial().Materials(id); err != nil {
2021-11-11 14:05:52 +08:00
return nil, err
}
2021-11-19 09:24:15 +08:00
// 采购信息
purchases := make([]*model.WorkPurchaseInfo, 0)
if purchases, err = model.NewWorkPurchase().Purchases(id); err != nil {
return nil, err
}
2021-11-18 09:51:39 +08:00
out.Within = struct {
Material []*model.WorkMaterialInfo `json:"material"`
2021-11-19 09:24:15 +08:00
Purchase []*model.WorkPurchaseInfo `json:"purchase"`
}{Material: materials, Purchase: purchases}
2021-11-18 09:51:39 +08:00
} else if out.WorkInstanceInfo.Kind == model2.WorkInstanceKindForOutside {
out.Outside = struct {
SupplierName string `json:"supplier_name"`
}{SupplierName: out.WorkInstanceInfo.SupplierName}
}
2021-11-19 11:53:20 +08:00
// 工单历史信息
2021-11-18 09:51:39 +08:00
if out.History, err = model.NewWorkProgress().Progress(id); err != nil {
return nil, err
2021-11-11 14:05:52 +08:00
}
return out, nil
2021-11-02 16:22:07 +08:00
}
2021-11-08 15:52:46 +08:00
// Launch 发起工单申请
2021-11-08 17:42:23 +08:00
func (c *Instance) Launch(params *InstanceLaunchParams) error {
// 查询产品信息是否存在
mManageEquipment := model.NewManageEquipment()
var count int64
err := model2.Count(mManageEquipment.ManageEquipment, &count, model2.NewWhere("id", params.EquipmentID))
if err != nil {
return err
} else if count <= 0 {
return errors.New("操作错误,该装备信息不存在或已被删除")
}
// 工单信息
mWorkInstance := model.NewWorkInstance()
2021-11-15 17:32:23 +08:00
mWorkInstance.UID = c.UID
2021-11-18 09:51:39 +08:00
mWorkInstance.OrderNo = lib.OrderNo()
2021-11-08 17:42:23 +08:00
mWorkInstance.Kind = model2.WorkInstanceKind(params.Kind)
mWorkInstance.Title = params.Title
mWorkInstance.EquipmentID = params.EquipmentID
mWorkInstance.PlateNumber = params.PlateNumber
mWorkInstance.Priority = model2.WorkInstancePriority(params.Priority)
mWorkInstance.IsAssist = model2.WorkInstanceAssist(params.IsAssist)
mWorkInstance.SetBreakdownAttribute(params.Breakdowns)
mWorkInstance.SetDistributionAttribute(&model2.WorkInstanceDistribution{
Name: params.Distribution.Name, Mobile: params.Distribution.Mobile, Address: params.Distribution.Address,
})
mWorkInstance.Remark = params.Remark
2021-11-11 14:05:52 +08:00
2021-11-18 09:51:39 +08:00
if mWorkInstance.Kind == model2.WorkInstanceKindForOutside {
if params.Supplier.SupplierID <= 0 {
return errors.New("操作错误,承修单位不存在")
}
mWorkInstance.SupplierID = params.Supplier.SupplierID
2021-11-11 14:05:52 +08:00
}
2021-11-08 17:42:23 +08:00
// 查询工单进度流程
// TODO工单流程
// 第一阶段:创建工单,默认创建时,直接完成
mWorkSchedule := model.NewWorkSchedule()
isExist := false
2021-11-09 14:08:02 +08:00
if isExist, err = mWorkSchedule.FirstSchedule(model2.WorkScheduleKindForRepair); err != nil {
2021-11-08 17:42:23 +08:00
return err
} else if !isExist {
return errors.New("操作错误,无工单流程信息,请先核实数据")
}
mWorkInstance.Schedule = mWorkSchedule.ID
2021-11-10 11:26:40 +08:00
mWorkInstance.Status = model2.WorkInstanceStatusForComplete
2021-11-19 11:53:20 +08:00
// 工单流程信息
mWorkProgress := model.NewWorkProgress()
mWorkProgress.ScheduleID = mWorkInstance.Schedule
2021-11-08 17:42:23 +08:00
// 下一流程
nextWorkSchedule := new(model.WorkScheduleInfo)
if nextWorkSchedule, err = mWorkSchedule.NextSchedule(mWorkInstance.IsAssist == model2.WorkInstanceAssistForYes); err != nil {
return err
}
2021-11-10 11:26:40 +08:00
if nextWorkSchedule != nil {
mWorkInstance.Status = model2.WorkInstanceStatusForOngoing
mWorkInstance.Schedule = nextWorkSchedule.ID
2021-11-08 17:42:23 +08:00
}
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
2021-11-19 11:53:20 +08:00
// 工单信息
2021-11-08 17:42:23 +08:00
if err = model2.Create(mWorkInstance.WorkInstance, tx); err != nil {
return err
}
2021-11-19 11:53:20 +08:00
// 工单历史
2021-11-08 17:42:23 +08:00
mWorkProgress.UID = c.UID
mWorkProgress.WorkID = mWorkInstance.ID
2021-11-19 11:53:20 +08:00
mWorkProgress.Status = model2.WorkProgressStatusForCreate
mWorkProgress.Remark = ""
2021-11-08 17:42:23 +08:00
if err = model2.Create(mWorkProgress.WorkProgress, tx); err != nil {
return err
}
2021-11-18 18:28:34 +08:00
// 内修模块信息
if mWorkInstance.Kind == model2.WorkInstanceKindForWithin && params.IsAssist <= 0 {
// 物料信息
if err = c.material(tx, params.Material, mWorkInstance.ID); err != nil {
return err
2021-11-11 14:05:52 +08:00
}
2021-11-18 18:28:34 +08:00
// 采购信息
2021-11-19 09:24:15 +08:00
if err = c.purchase(tx, params.Purchase, mWorkInstance.ID); err != nil {
2021-11-11 14:05:52 +08:00
return err
}
}
2021-11-09 14:08:02 +08:00
if nextWorkSchedule != nil {
// 推送通知
2021-11-18 09:51:39 +08:00
go c.publish(params.Kind, nextWorkSchedule.Reviewer)
2021-11-08 17:42:23 +08:00
}
return nil
})
}
// Examine 审核操作
2021-11-18 18:28:34 +08:00
func (c *Instance) Examine(id uint64, status int, remark string, isAssist int, params *InstanceExamineParams) error {
2021-11-08 17:42:23 +08:00
_status := model2.WorkProgressStatus(status)
if _status != model2.WorkProgressStatusForAgree && _status != model2.WorkProgressStatusForRefuse {
return errors.New("操作错误,审核状态异常")
}
mWorkInstance := model.NewWorkInstance()
mWorkInstance.ID = id
2021-11-19 18:21:12 +08:00
isExist, err := model2.FirstField(mWorkInstance.WorkInstance, []string{"id", "kind", "schedule", "is_assist", "status"})
2021-11-08 17:42:23 +08:00
if err != nil {
return err
} else if !isExist {
return errors.New("操作错误,工单信息不存在")
} else if mWorkInstance.Status == model2.WorkInstanceStatusForComplete {
return errors.New("操作错误,当前工单信息已结束")
}
// 查询当前工单所在流程的信息
mWorkSchedule := model.NewWorkSchedule()
mWorkSchedule.ID = mWorkInstance.Schedule
2021-11-10 11:26:40 +08:00
if isExist, err = model2.First(mWorkSchedule.WorkSchedule); err != nil {
2021-11-08 17:42:23 +08:00
return err
} else if !isExist {
return errors.New("操作错误,未知的工单流程")
}
// 验证审核权限
isAuth := false
if isAuth, err = mWorkSchedule.ValidateAuth(c.UID); err != nil {
return err
} else if !isAuth {
return errors.New("操作错误,无权限审批")
}
2021-11-18 18:28:34 +08:00
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
2021-11-08 17:42:23 +08:00
// 工单流程记录
mWorkProgress := model.NewWorkProgress()
mWorkProgress.UID = c.UID
mWorkProgress.WorkID = id
mWorkProgress.ScheduleID = mWorkSchedule.ID
mWorkProgress.Status = _status
mWorkProgress.Remark = remark
2021-11-19 18:21:12 +08:00
if mWorkProgress.Remark == "" {
mWorkProgress.Remark = "审批通过"
}
2021-11-08 17:42:23 +08:00
if err = model2.Create(mWorkProgress.WorkProgress, tx); err != nil {
return err
}
workUpdates := map[string]interface{}{
"status": model2.WorkInstanceStatusForComplete, "updated_at": time.Now(),
}
2021-11-19 18:21:12 +08:00
// 上一流程
// TODO获取上一流程代码写的不好后期优化考虑
lastWorkSchedule := new(model.WorkScheduleInfo)
2021-11-08 17:42:23 +08:00
// 下一流程
2021-11-09 14:08:02 +08:00
nextScheduleInfo := new(model.WorkScheduleInfo)
2021-11-08 17:42:23 +08:00
// 拒绝审批,工单直接结束
if _status == model2.WorkProgressStatusForRefuse {
goto FINISH
}
2021-11-19 18:21:12 +08:00
// 上一流程信息
if lastWorkSchedule, err = mWorkSchedule.LastSchedule(); err != nil {
return err
}
//
2021-11-08 17:42:23 +08:00
// 下一流程信息
2021-11-19 18:21:12 +08:00
if nextScheduleInfo, err = mWorkSchedule.NextSchedule(mWorkInstance.IsAssist == model2.WorkInstanceAssistForYes); err != nil {
2021-11-08 17:42:23 +08:00
return err
}
// 无下一流程,工单直接完成
2021-11-09 14:08:02 +08:00
if nextScheduleInfo == nil || nextScheduleInfo.ID <= 0 {
2021-11-08 17:42:23 +08:00
goto FINISH
}
workUpdates["status"] = model2.WorkInstanceStatusForOngoing
2021-11-09 14:08:02 +08:00
workUpdates["schedule"] = nextScheduleInfo.ID
2021-11-08 17:42:23 +08:00
2021-11-19 18:21:12 +08:00
// 当前阶段无上一流程才会更新
if lastWorkSchedule == nil {
2021-11-08 17:42:23 +08:00
workUpdates["is_assist"] = isAssist
}
FINISH:
if err = model2.Updates(mWorkInstance.WorkInstance, workUpdates, tx); err != nil {
return err
}
2021-11-09 14:08:02 +08:00
// 完成,创建维修工单
if workUpdates["status"] == model2.WorkInstanceStatusForComplete {
// 创建维修工单
mWorkRepair := model.NewWorkRepair()
2021-11-11 17:10:43 +08:00
mWorkRepair.OrderNo = lib.OrderNo()
2021-11-09 14:08:02 +08:00
mWorkRepair.WorkID = mWorkInstance.ID
2021-11-11 17:10:43 +08:00
// 默认进行中
mWorkRepair.Status = model2.WorkRepairStatusForOngoing
2021-11-09 14:08:02 +08:00
if err = model2.Create(mWorkRepair.WorkRepair, tx); err != nil {
return err
}
}
2021-11-18 18:28:34 +08:00
// 处理器材信息
if mWorkInstance.Kind == model2.WorkInstanceKindForWithin && isAssist <= 0 {
// 物料信息
if err = c.material(tx, params.Material, id); err != nil {
return err
}
// 采购信息
2021-11-19 09:24:15 +08:00
if err = c.purchase(tx, params.Purchase, id); err != nil {
2021-11-18 18:28:34 +08:00
return err
}
}
2021-11-09 14:08:02 +08:00
// 推送通知
2021-11-18 09:51:39 +08:00
if nextScheduleInfo != nil {
go c.publish(int(mWorkInstance.Kind), nextScheduleInfo.Reviewer)
}
2021-11-08 17:42:23 +08:00
return nil
2021-11-18 18:28:34 +08:00
})
2021-11-02 16:22:07 +08:00
}
2021-11-09 14:08:02 +08:00
// Delete 删除操作
func (c *Instance) Delete(id uint64) error {
mWorkInstance := model.NewWorkInstance()
mWorkInstance.ID = id
return model2.Delete(mWorkInstance.WorkInstance)
2021-11-02 16:22:07 +08:00
}
func NewInstance() InstanceHandle {
return func(session *service.Session) *Instance {
return &Instance{session}
}
}