feat:完善项目
This commit is contained in:
@ -27,6 +27,8 @@ type (
|
||||
InstanceDetailInfo struct {
|
||||
basic.CommonIDString
|
||||
*model.WorkInstanceInfo
|
||||
Distribution *model2.WorkInstanceDistribution `json:"distribution"`
|
||||
Materials []*model.WorkMaterialInfo `json:"materials"`
|
||||
}
|
||||
// InstanceLaunchParams 发起参数信息
|
||||
InstanceLaunchParams struct {
|
||||
@ -43,6 +45,9 @@ type (
|
||||
}
|
||||
// InstanceLaunchParamsForMaterial 配件信息
|
||||
InstanceLaunchParamsForMaterial struct {
|
||||
ID uint64 // 器材ID
|
||||
SupplierID uint64 // 供应商ID
|
||||
Number float64 // 需要数量
|
||||
}
|
||||
// InstanceLaunchParamsForDistribution 配送信息
|
||||
InstanceLaunchParamsForDistribution struct {
|
||||
@ -157,10 +162,27 @@ func (c *Instance) Workbench(materialID uint64, kind, page, pageSize int) (*basi
|
||||
return &basic.PageDataResponse{Data: out, Count: count}, nil
|
||||
}
|
||||
|
||||
func (c *Instance) Detail(id uint64) (interface{}, error) {
|
||||
// Detail 详细信息
|
||||
func (c *Instance) Detail(id uint64) (*InstanceDetailInfo, error) {
|
||||
out := new(InstanceDetailInfo)
|
||||
|
||||
var err error
|
||||
|
||||
mWorkInstance := model.NewWorkInstance()
|
||||
mWorkInstance.ID = id
|
||||
return nil, nil
|
||||
// 基本信息
|
||||
if out.WorkInstanceInfo, err = mWorkInstance.Detail(id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 位置信息
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Launch 发起工单申请
|
||||
@ -190,9 +212,23 @@ func (c *Instance) Launch(params *InstanceLaunchParams) error {
|
||||
Name: params.Distribution.Name, Mobile: params.Distribution.Mobile, Address: params.Distribution.Address,
|
||||
})
|
||||
mWorkInstance.Remark = params.Remark
|
||||
|
||||
// 工单流程信息
|
||||
mWorkProgress := model.NewWorkProgress()
|
||||
// 工单器材信息
|
||||
workMaterials := make([]*model2.WorkMaterial, 0)
|
||||
|
||||
// 内修模块,同步器材库存信息
|
||||
if mWorkInstance.Kind == model2.WorkInstanceKindForWithin {
|
||||
for _, v := range params.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,
|
||||
})
|
||||
}
|
||||
}
|
||||
// 查询工单进度流程
|
||||
// TODO:工单流程
|
||||
// 第一阶段:创建工单,默认创建时,直接完成
|
||||
@ -217,6 +253,8 @@ func (c *Instance) Launch(params *InstanceLaunchParams) error {
|
||||
mWorkInstance.Status = model2.WorkInstanceStatusForOngoing
|
||||
mWorkInstance.Schedule = nextWorkSchedule.ID
|
||||
}
|
||||
now := time.Now()
|
||||
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Create(mWorkInstance.WorkInstance, tx); err != nil {
|
||||
return err
|
||||
@ -230,6 +268,25 @@ 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 {
|
||||
mManageMaterialSupplier := model.NewManageMaterialSupplier()
|
||||
|
||||
for _, v := range workMaterials {
|
||||
v.WorkID = mWorkInstance.ID
|
||||
|
||||
if err = model2.UpdatesWhere(mManageMaterialSupplier.ManageMaterialSupplier, map[string]interface{}{
|
||||
"frozen_stock": gorm.Expr("frozen_stock + ?", v.MaterialNumber), "updated_at": now,
|
||||
}, nil, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
mWorkMaterial := model.NewWorkMaterial()
|
||||
|
||||
if err = model2.Creates(mWorkMaterial.WorkMaterial, &workMaterials, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if nextWorkSchedule != nil {
|
||||
// 推送通知
|
||||
go c.publish(nextWorkSchedule.Reviewer)
|
||||
|
Reference in New Issue
Block a user