feat:完善项目
This commit is contained in:
@ -28,8 +28,14 @@ type (
|
||||
InstanceDetailInfo struct {
|
||||
basic.CommonIDString
|
||||
*model.WorkInstanceInfo
|
||||
Outside struct {
|
||||
SupplierName string `json:"supplier_name"`
|
||||
} `json:"outside" form:"outside"`
|
||||
Within struct {
|
||||
Material []*model.WorkMaterialInfo `json:"material"`
|
||||
} `json:"within"`
|
||||
Distribution *model2.WorkInstanceDistribution `json:"distribution"`
|
||||
Materials []*model.WorkMaterialInfo `json:"materials"`
|
||||
History []*model.WorkProgressInfo `json:"history"`
|
||||
}
|
||||
// InstanceLaunchParams 发起参数信息
|
||||
InstanceLaunchParams struct {
|
||||
@ -41,9 +47,14 @@ type (
|
||||
PlateNumber string // 车牌号
|
||||
Priority, IsAssist int // 优先级,是否需要上级审批
|
||||
Remark string // 备注信息
|
||||
Supplier *InstanceLaunchParamsForSupplier
|
||||
Material []*InstanceLaunchParamsForMaterial
|
||||
Distribution *InstanceLaunchParamsForDistribution
|
||||
}
|
||||
// InstanceLaunchParamsForSupplier 供应商信息
|
||||
InstanceLaunchParamsForSupplier struct {
|
||||
SupplierID uint64 `json:"supplier_id"`
|
||||
}
|
||||
// InstanceLaunchParamsForMaterial 配件信息
|
||||
InstanceLaunchParamsForMaterial struct {
|
||||
ID uint64 // 器材ID
|
||||
@ -56,14 +67,18 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (c *Instance) publish(reviewer []string) {
|
||||
func (c *Instance) publish(kind int, reviewer []string) {
|
||||
msg := &service.HubEmit{
|
||||
Msg: handle.NewWorkNotice("你有一条待办事项", &struct {
|
||||
Kind int `json:"kind"`
|
||||
}{
|
||||
Kind: kind,
|
||||
}),
|
||||
}
|
||||
utils.TryCatch(func() {
|
||||
for _, v := range reviewer {
|
||||
// Socket通知
|
||||
service.HubMessage.EmitHandle(&service.HubEmit{
|
||||
ID: v,
|
||||
Msg: handle.NewWorkNotice("你有一条待办事项"),
|
||||
})
|
||||
msg.ID = v
|
||||
service.HubMessage.EmitHandle(msg)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -183,14 +198,31 @@ func (c *Instance) Detail(id uint64) (*InstanceDetailInfo, error) {
|
||||
if out.WorkInstanceInfo, err = mWorkInstance.Detail(id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mWorkInstance.SetID(out.WorkInstanceInfo.ID)
|
||||
out.CommonIDString = basic.CommonIDString{
|
||||
ID: mWorkInstance.GetEncodeTenantID(),
|
||||
}
|
||||
// 位置信息
|
||||
mWorkInstance.Distribution = out.WorkInstanceInfo.Distribution
|
||||
|
||||
out.Distribution = mWorkInstance.GetDistributionAttribute()
|
||||
// 内修才有数据
|
||||
if out.WorkInstanceInfo.Kind == model2.WorkInstanceKindForWithin {
|
||||
if out.Materials, err = model.NewWorkMaterial().Materials(id); err != nil {
|
||||
materials := make([]*model.WorkMaterialInfo, 0)
|
||||
|
||||
if materials, err = model.NewWorkMaterial().Materials(id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out.Within = struct {
|
||||
Material []*model.WorkMaterialInfo `json:"material"`
|
||||
}{Material: materials}
|
||||
} else if out.WorkInstanceInfo.Kind == model2.WorkInstanceKindForOutside {
|
||||
out.Outside = struct {
|
||||
SupplierName string `json:"supplier_name"`
|
||||
}{SupplierName: out.WorkInstanceInfo.SupplierName}
|
||||
}
|
||||
if out.History, err = model.NewWorkProgress().Progress(id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
@ -212,6 +244,7 @@ func (c *Instance) Launch(params *InstanceLaunchParams) error {
|
||||
// 工单信息
|
||||
mWorkInstance := model.NewWorkInstance()
|
||||
mWorkInstance.UID = c.UID
|
||||
mWorkInstance.OrderNo = lib.OrderNo()
|
||||
mWorkInstance.Kind = model2.WorkInstanceKind(params.Kind)
|
||||
mWorkInstance.Title = params.Title
|
||||
mWorkInstance.EquipmentID = params.EquipmentID
|
||||
@ -229,8 +262,13 @@ func (c *Instance) Launch(params *InstanceLaunchParams) error {
|
||||
// 工单器材信息
|
||||
workMaterials := make([]*model2.WorkMaterial, 0)
|
||||
|
||||
// 内修模块,同步器材库存信息
|
||||
if mWorkInstance.Kind == model2.WorkInstanceKindForWithin {
|
||||
if mWorkInstance.Kind == model2.WorkInstanceKindForOutside {
|
||||
if params.Supplier.SupplierID <= 0 {
|
||||
return errors.New("操作错误,承修单位不存在")
|
||||
}
|
||||
mWorkInstance.SupplierID = params.Supplier.SupplierID
|
||||
// 内修模块,同步器材库存信息
|
||||
} else if mWorkInstance.Kind == model2.WorkInstanceKindForWithin && params.IsAssist <= 0 {
|
||||
for _, v := range params.Material {
|
||||
if v.ID <= 0 || v.SupplierID <= 0 || v.Number <= 0 {
|
||||
return errors.New("操作错误,器材参数不完全")
|
||||
@ -279,8 +317,9 @@ func (c *Instance) Launch(params *InstanceLaunchParams) error {
|
||||
if err = model2.Create(mWorkProgress.WorkProgress, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
// 内修模块,同步器材库存信息
|
||||
if mWorkInstance.Kind == model2.WorkInstanceKindForWithin && len(workMaterials) > 0 {
|
||||
|
||||
// 处理库存信息
|
||||
if len(workMaterials) > 0 {
|
||||
mManageMaterialSupplier := model.NewManageMaterialSupplier()
|
||||
|
||||
for _, v := range workMaterials {
|
||||
@ -288,7 +327,10 @@ func (c *Instance) Launch(params *InstanceLaunchParams) error {
|
||||
|
||||
if err = model2.UpdatesWhere(mManageMaterialSupplier.ManageMaterialSupplier, map[string]interface{}{
|
||||
"frozen_stock": gorm.Expr("frozen_stock + ?", v.MaterialNumber), "updated_at": now,
|
||||
}, nil, tx); err != nil {
|
||||
}, []*model2.ModelWhere{
|
||||
model2.NewWhere("material_id", v.MaterialID),
|
||||
model2.NewWhere("supplier_id", v.MaterialSupplierID),
|
||||
}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -300,7 +342,7 @@ func (c *Instance) Launch(params *InstanceLaunchParams) error {
|
||||
}
|
||||
if nextWorkSchedule != nil {
|
||||
// 推送通知
|
||||
go c.publish(nextWorkSchedule.Reviewer)
|
||||
go c.publish(params.Kind, nextWorkSchedule.Reviewer)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
@ -316,7 +358,7 @@ func (c *Instance) Examine(id uint64, status int, remark string, isAssist int) e
|
||||
mWorkInstance := model.NewWorkInstance()
|
||||
mWorkInstance.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mWorkInstance.WorkInstance, []string{"id", "schedule", "status"})
|
||||
isExist, err := model2.FirstField(mWorkInstance.WorkInstance, []string{"id", "kind", "schedule", "status"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@ -397,7 +439,9 @@ func (c *Instance) Examine(id uint64, status int, remark string, isAssist int) e
|
||||
}
|
||||
}
|
||||
// 推送通知
|
||||
go c.publish(nextScheduleInfo.Reviewer)
|
||||
if nextScheduleInfo != nil {
|
||||
go c.publish(int(mWorkInstance.Kind), nextScheduleInfo.Reviewer)
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user