feat:完善项目
This commit is contained in:
183
app/api/work.go
183
app/api/work.go
@ -17,8 +17,8 @@ type (
|
||||
workLaunchForm struct {
|
||||
Kind int `json:"kind" form:"kind" binding:"required"` // 类型
|
||||
Title string `json:"title" form:"title"`
|
||||
EquipmentID uint64 `json:"equipment_id" form:"equipment_id" binding:"required"` // 装备ID
|
||||
Breakdowns []uint64 `json:"breakdowns" form:"breakdowns"` // 故障类型
|
||||
EquipmentID string `json:"equipment_id" form:"equipment_id" binding:"required"` // 装备ID
|
||||
Breakdowns []string `json:"breakdowns" form:"breakdowns"` // 故障类型
|
||||
PlateNumber string `json:"plate_number" form:"plate_number"` // 车牌号
|
||||
Priority int `json:"priority" form:"priority" binding:"required"` // 优先级
|
||||
IsAssist int `json:"is_assist" form:"is_assist"` // 是否需要上级审批
|
||||
@ -26,12 +26,15 @@ type (
|
||||
}
|
||||
// workLaunchMaterialForm 工单发起配件信息
|
||||
workLaunchMaterialForm struct {
|
||||
ID string `json:"id" form:"id"`
|
||||
SupplierID string `json:"supplier_id" form:"supplier_id"`
|
||||
Number float64 `json:"number" form:"number"`
|
||||
}
|
||||
// workLaunchDistributionForm 工单发起地址信息
|
||||
workLaunchDistributionForm struct {
|
||||
Name string `json:"name" form:"name" binding:"required"` // 联系人
|
||||
Mobile string `json:"mobile" form:"mobile" binding:"required"` // 联系方式
|
||||
Address string `json:"address" form:"address" binding:"required"` // 联系地址
|
||||
Name string `json:"name" form:"name"` // 联系人
|
||||
Mobile string `json:"mobile" form:"mobile"` // 联系方式
|
||||
Address string `json:"address" form:"address"` // 联系地址
|
||||
}
|
||||
// scheduleForm 流程信息
|
||||
scheduleForm struct {
|
||||
@ -60,6 +63,7 @@ type (
|
||||
*
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
* @apiSuccess (200) {String} data.id ID
|
||||
* @apiSuccess (200) {Number} data.kind 类型(1:外修,2:内修)
|
||||
* @apiSuccess (200) {String} data.title 标题名称
|
||||
* @apiSuccess (200) {String} data.material_code 装备编码
|
||||
* @apiSuccess (200) {String} data.material_title 装备名称
|
||||
@ -68,7 +72,7 @@ type (
|
||||
* @apiSuccess (200) {Number} data.priority 紧急状态(1:普通,2:紧急,3:非常紧急)
|
||||
* @apiSuccess (200) {Number} data.status 状态(0:进行中,1:已完成)
|
||||
* @apiSuccess (200) {Time} data.created_at 创建时间
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
@ -79,6 +83,7 @@ type (
|
||||
* "data": [
|
||||
* {
|
||||
* "id": "m9Qa2ZaOvE",
|
||||
* "kind": 2,
|
||||
* "title": "刹车盘",
|
||||
* "material_code": "装备编码",
|
||||
* "material_title": "装备名称",
|
||||
@ -121,6 +126,7 @@ func (*Work) Instance(c *gin.Context) {
|
||||
*
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
* @apiSuccess (200) {String} data.id ID
|
||||
* @apiSuccess (200) {Number} data.kind 类型(1:外修,2:内修)
|
||||
* @apiSuccess (200) {String} data.title 标题名称
|
||||
* @apiSuccess (200) {String} data.material_code 装备编码
|
||||
* @apiSuccess (200) {String} data.material_title 装备名称
|
||||
@ -140,6 +146,7 @@ func (*Work) Instance(c *gin.Context) {
|
||||
* "data": [
|
||||
* {
|
||||
* "id": "m9Qa2ZaOvE",
|
||||
* "kind": 2,
|
||||
* "title": "刹车盘",
|
||||
* "material_code": "装备编码",
|
||||
* "material_title": "装备名称",
|
||||
@ -182,6 +189,7 @@ func (*Work) Person(c *gin.Context) {
|
||||
*
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
* @apiSuccess (200) {String} data.id ID
|
||||
* @apiSuccess (200) {Number} data.kind 类型(1:外修,2:内修)
|
||||
* @apiSuccess (200) {String} data.title 标题名称
|
||||
* @apiSuccess (200) {String} data.material_code 装备编码
|
||||
* @apiSuccess (200) {String} data.material_title 装备名称
|
||||
@ -201,6 +209,7 @@ func (*Work) Person(c *gin.Context) {
|
||||
* "data": [
|
||||
* {
|
||||
* "id": "m9Qa2ZaOvE",
|
||||
* "kind": 2,
|
||||
* "title": "刹车盘",
|
||||
* "material_code": "装备编码",
|
||||
* "material_title": "装备名称",
|
||||
@ -227,6 +236,74 @@ func (*Work) Workbench(c *gin.Context) {
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/v1/work/detail 工单详情信息
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName WorkDetail
|
||||
* @apiGroup Work
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
* @apiHeader {string} Content-Type=application/json 传输方式
|
||||
*
|
||||
* @apiParam {String} id 工单ID
|
||||
*
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
* @apiSuccess (200) {String} data.id ID
|
||||
* @apiSuccess (200) {Number} data.kind 类型(1:外修,2:内修)
|
||||
* @apiSuccess (200) {String} data.title 标题名称
|
||||
* @apiSuccess (200) {String} data.material_code 装备编码
|
||||
* @apiSuccess (200) {String} data.material_title 装备名称
|
||||
* @apiSuccess (200) {String} data.breakdown_title 故障信息
|
||||
* @apiSuccess (200) {String} data.schedule_title 流程名称
|
||||
* @apiSuccess (200) {Number} data.priority 紧急状态(1:普通,2:紧急,3:非常紧急)
|
||||
* @apiSuccess (200) {Number} data.status 状态(0:进行中,1:已完成)
|
||||
* @apiSuccess (200) {Time} data.created_at 创建时间
|
||||
* @apiSuccess (200) {Object} data.distribution 配送信息
|
||||
* @apiSuccess (200) {String} data.distribution.name 联系人
|
||||
* @apiSuccess (200) {String} data.distribution.mobile 联系方式
|
||||
* @apiSuccess (200) {String} data.distribution.address 联系地址
|
||||
* @apiSuccess (200) {Object} data.materials 配件信息
|
||||
* @apiSuccess (200) {Float} data.materials.material_number 所需数量
|
||||
* @apiSuccess (200) {String} data.materials.material_code 配件编码
|
||||
* @apiSuccess (200) {String} data.materials.material_title 配件名称
|
||||
* @apiSuccess (200) {Float} data.materials.material_price 配件价格
|
||||
* @apiSuccess (200) {String} data.materials.supplier_name 供应商名称
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": {
|
||||
* "id": "m9Qa2ZaOvE",
|
||||
* "kind": 2,
|
||||
* "title": "刹车盘",
|
||||
* "material_code": "装备编码",
|
||||
* "material_title": "装备名称",
|
||||
* "breakdown_title": "发动机,刹车盘",
|
||||
* "schedule_title": "分管领导审批",
|
||||
* "priority": 1,
|
||||
* "status": 0,
|
||||
* "created_at": "2021-11-05T14:24:07+08:00",
|
||||
* "distribution": [
|
||||
* "name": "",
|
||||
* "mobile": "",
|
||||
* "address": "",
|
||||
* ],
|
||||
* "materials": [
|
||||
* {
|
||||
* "material_number": 0,
|
||||
* "material_code": "2222",
|
||||
* "material_title": "qewqe",
|
||||
* "material_price": 0,
|
||||
* "supplier_name": "测试的"
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
func (*Work) Detail(c *gin.Context) {
|
||||
form := new(IDStringForm)
|
||||
|
||||
@ -238,23 +315,113 @@ func (*Work) Detail(c *gin.Context) {
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/v1/work/launch 工单发起
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName WorkLaunch
|
||||
* @apiGroup Work
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
* @apiHeader {string} Content-Type=application/json 传输方式
|
||||
*
|
||||
* @apiParam {Object[]} material 配件信息,内修才需要上传
|
||||
* @apiParam {String} material.id 配件ID
|
||||
* @apiParam {String} material.supplier_id 供应商ID
|
||||
* @apiParam {String} material.number 配件数量
|
||||
* @apiParam {Number} kind 工单类型
|
||||
* @apiParam {String} [title="''"] 工单名称
|
||||
* @apiParam {Number} equipment_id 装备名称
|
||||
* @apiParam {String[]} breakdowns 故障类型
|
||||
* @apiParam {String} plate_number 车牌号
|
||||
* @apiParam {Number} priority 紧急状态(1:普通,2:紧急,3:非常紧急)
|
||||
* @apiParam {Number} [is_assist=0] 是否需要上级协助(1:是)
|
||||
* @apiParam {String} [remark="''"] 备注信息
|
||||
* @apiParam {Object} distribution 配送信息
|
||||
* @apiParam {String} distribution.name 联系人
|
||||
* @apiParam {String} distribution.mobile 联系方式
|
||||
* @apiParam {String} distribution.address 联系地址
|
||||
*
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (*Work) Launch(c *gin.Context) {
|
||||
form := &struct {
|
||||
workLaunchForm
|
||||
Material []*workLaunchMaterialForm `json:"material" form:"material"`
|
||||
Address workLaunchDistributionForm `json:"distribution" form:"distribution"`
|
||||
Distribution workLaunchDistributionForm `json:"distribution" form:"distribution"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
materials := make([]*work.InstanceLaunchParamsForMaterial, 0)
|
||||
|
||||
obj := new(IDStringForm)
|
||||
obj.ID = form.EquipmentID
|
||||
equipmentID := obj.Convert()
|
||||
|
||||
breakdowns := make([]uint64, 0)
|
||||
for _, v := range form.Breakdowns {
|
||||
obj.ID = v
|
||||
breakdowns = append(breakdowns, obj.Convert())
|
||||
}
|
||||
for _, v := range form.Material {
|
||||
// 器材ID
|
||||
obj.ID = v.ID
|
||||
id := obj.Convert()
|
||||
// 供应商ID
|
||||
obj.ID = v.SupplierID
|
||||
supplierID := obj.Convert()
|
||||
materials = append(materials, &work.InstanceLaunchParamsForMaterial{
|
||||
ID: id, SupplierID: supplierID, Number: v.Number,
|
||||
})
|
||||
}
|
||||
err := work.NewInstance()(getSession()(c).(*service.Session)).Launch(&work.InstanceLaunchParams{
|
||||
Kind: form.Kind, Title: form.Title, EquipmentID: form.EquipmentID, Breakdowns: form.Breakdowns,
|
||||
Kind: form.Kind, Title: form.Title, EquipmentID: equipmentID, Breakdowns: breakdowns,
|
||||
PlateNumber: form.PlateNumber, Priority: form.Priority, IsAssist: form.IsAssist, Remark: form.Remark,
|
||||
Material: materials,
|
||||
Distribution: &work.InstanceLaunchParamsForDistribution{
|
||||
Name: form.Distribution.Name, Mobile: form.Distribution.Mobile, Address: form.Distribution.Address,
|
||||
},
|
||||
})
|
||||
APIResponse(err)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/v1/work/examine 工单审核
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName WorkExamine
|
||||
* @apiGroup Work
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
* @apiHeader {string} Content-Type=application/json 传输方式
|
||||
*
|
||||
* @apiParam {String} id 工单ID
|
||||
* @apiParam {String} status 审核状态
|
||||
* @apiParam {String} remark 备注信息
|
||||
* @apiParam {Number} [is_assist=0] 是否需要上级协助(0:不需要,1:需要)
|
||||
*
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (*Work) Examine(c *gin.Context) {
|
||||
form := &struct {
|
||||
IDStringForm
|
||||
|
@ -52,7 +52,7 @@ func initModel() {
|
||||
&synchronized{iModel: model.NewManageEquipment()}, &synchronized{iModel: model.NewManageEquipmentMaterial()},
|
||||
&synchronized{iModel: model.NewManageMaterial()}, &synchronized{iModel: model.NewManageMaterialSupplier()},
|
||||
&synchronized{iModel: model.NewManageMaterialPurchase()}, &synchronized{iModel: model.NewManageMaterialWarehouse()},
|
||||
&synchronized{iModel: model.NewWorkInstance()}, &synchronized{iModel: model.NewWorkProgress()},
|
||||
&synchronized{iModel: model.NewWorkInstance()}, &synchronized{iModel: model.NewWorkMaterial()}, &synchronized{iModel: model.NewWorkProgress()},
|
||||
&synchronized{iModel: model.NewWorkSchedule()}, &synchronized{iModel: model.NewWorkRepair()},
|
||||
)
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
package model
|
||||
|
||||
// WorkDetail 工单详细信息
|
||||
type WorkDetail struct {
|
||||
Model
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
func (m *WorkDetail) TableName() string {
|
||||
return "work_detail"
|
||||
}
|
||||
|
||||
func NewWorkDetail() *WorkDetail {
|
||||
return &WorkDetail{}
|
||||
}
|
@ -18,9 +18,9 @@ type WorkInstance struct {
|
||||
Priority WorkInstancePriority `gorm:"column:priority;type:tinyint(1);default:1;comment:工单优先级" json:"priority"`
|
||||
Schedule uint64 `gorm:"column:schedule;type:int(11);default:1;comment:工单进度" json:"schedule"`
|
||||
IsAssist WorkInstanceAssist `gorm:"column:is_assist;type:tinyint(1);default:0;comment:协助状态" json:"is_assist"` // 当前阶段协助状态,确认是否需要下一阶段协助
|
||||
Status WorkInstanceStatus `gorm:"column:status;type:tinyint(1);default:0;comment:工单状态" json:"status"`
|
||||
Remark string `gorm:"column:remark;type:varchar(255);default:null;comment:备注信息" json:"remark"`
|
||||
Distribution string `gorm:"column:distribution;type:varchar(255);default:null;comment:配送信息" json:"-"`
|
||||
Status WorkInstanceStatus `gorm:"column:status;type:tinyint(1);default:0;comment:工单状态" json:"status"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
20
app/common/model/work_material.go
Normal file
20
app/common/model/work_material.go
Normal file
@ -0,0 +1,20 @@
|
||||
package model
|
||||
|
||||
// WorkMaterial 工单器材数据模型
|
||||
type WorkMaterial struct {
|
||||
Model
|
||||
WorkID uint64 `gorm:"column:work_id;type:int(11);default:0;comment:工单ID" json:"-"`
|
||||
MaterialID uint64 `gorm:"column:material_id;type:int(11);default:0;comment:器材ID" json:"-"`
|
||||
MaterialSupplierID uint64 `gorm:"column:material_supplier_id;type:int(11);default:0;comment:器材供应商ID" json:"-"`
|
||||
MaterialNumber float64 `gorm:"column:material_number;type:decimal(10,2);default:0;comment:所需器材数量" json:"material_number"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
func (m *WorkMaterial) TableName() string {
|
||||
return "work_material"
|
||||
}
|
||||
|
||||
func NewWorkMaterial() *WorkMaterial {
|
||||
return &WorkMaterial{}
|
||||
}
|
@ -25,7 +25,7 @@ func (c *MaterialSuppler) List() (*basic.PageDataResponse, error) {
|
||||
|
||||
// Select 筛选信息
|
||||
func (c *MaterialSuppler) Select(materialID uint64) ([]*MaterialSupplerBasic, error) {
|
||||
mManageMaterSupplier := model.NewManageMaterSupplier()
|
||||
mManageMaterSupplier := model.NewManageMaterialSupplier()
|
||||
out, err := mManageMaterSupplier.Basic(model2.NewWhere("m_s.material_id", materialID))
|
||||
|
||||
if err != nil {
|
||||
@ -46,7 +46,7 @@ func (c *MaterialSuppler) Select(materialID uint64) ([]*MaterialSupplerBasic, er
|
||||
|
||||
// Form 数据操作
|
||||
func (c *MaterialSuppler) Form(materialID, supplierID uint64, stock float64) error {
|
||||
mManageMaterSupplier := model.NewManageMaterSupplier()
|
||||
mManageMaterSupplier := model.NewManageMaterialSupplier()
|
||||
|
||||
var count int64
|
||||
|
||||
@ -62,7 +62,7 @@ func (c *MaterialSuppler) Form(materialID, supplierID uint64, stock float64) err
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *MaterialSuppler) Delete(id uint64) error {
|
||||
mManageMaterSupplier := model.NewManageMaterSupplier()
|
||||
mManageMaterSupplier := model.NewManageMaterialSupplier()
|
||||
mManageMaterSupplier.SetID(id)
|
||||
return model2.Delete(mManageMaterSupplier.ManageMaterialSupplier)
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -35,6 +35,6 @@ func (m *ManageMaterialSupplier) Basic(where ...*model.ModelWhere) ([]*ManageMat
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewManageMaterSupplier() *ManageMaterialSupplier {
|
||||
func NewManageMaterialSupplier() *ManageMaterialSupplier {
|
||||
return &ManageMaterialSupplier{}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package model
|
||||
import (
|
||||
"ArmedPolice/app/common/model"
|
||||
"ArmedPolice/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type SysTenant struct {
|
||||
@ -26,15 +27,15 @@ type (
|
||||
// Parent 父集元素,包含自己
|
||||
func (m *SysTenant) Parent(tenantID uint64) ([]*SysTenantBasic, error) {
|
||||
sql := `SELECT T2.id, T2.name FROM
|
||||
(SELECT @r AS _id, (SELECT @r := parent_id FROM ? WHERE id = _id) AS parent_id,
|
||||
(SELECT @r AS _id, (SELECT @r := parent_id FROM %s WHERE id = _id) AS parent_id,
|
||||
@l := @l + 1 AS lvl
|
||||
FROM (SELECT @r := ?, @l := 0 ) vars, ? h WHERE @r <> 0) T1
|
||||
JOIN ? T2 ON T1._id = T2.id
|
||||
FROM (SELECT @r := %d, @l := 0 ) vars, %s h WHERE @r <> 0) T1
|
||||
JOIN %s T2 ON T1._id = T2.id
|
||||
ORDER BY T1.lvl DESC`
|
||||
|
||||
out := make([]*SysTenantBasic, 0)
|
||||
|
||||
err := orm.GetDB().Raw(sql, m.TableName(), tenantID, m.TableName(), m.TableName()).Scan(&out).Error
|
||||
err := orm.GetDB().Raw(fmt.Sprintf(sql, m.TableName(), tenantID, m.TableName(), m.TableName())).Scan(&out).Error
|
||||
|
||||
return out, err
|
||||
}
|
||||
|
@ -16,11 +16,13 @@ type WorkInstance struct {
|
||||
type WorkInstanceInfo struct {
|
||||
ID uint64 `json:"-"`
|
||||
Title string `json:"title"`
|
||||
Kind model.WorkInstanceKind `json:"kind"`
|
||||
EquipmentCode string `json:"equipment_code"`
|
||||
EquipmentTitle string `json:"equipment_title"`
|
||||
BreakdownTitle string `json:"breakdown_title"`
|
||||
ScheduleTitle string `json:"schedule_title"`
|
||||
Priority int `json:"priority"`
|
||||
Distribution string `json:"distribution"`
|
||||
Status int `json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
@ -31,6 +33,24 @@ type WorkbenchCondition struct {
|
||||
RoleIDs []string
|
||||
}
|
||||
|
||||
// Detail 详细信息
|
||||
func (m *WorkInstance) Detail(id uint64) (*WorkInstanceInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS w").
|
||||
Select("w.id", "w.kind", "w.title", "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",
|
||||
"s.title AS schedule_title", "w.distribution", "w.status", "w.created_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS e ON w.equipment_id = e.id", model.NewManageEquipment().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS s ON w.schedule = s.id", model.NewWorkSchedule().TableName())).
|
||||
Where("w.id = ?", id)
|
||||
|
||||
out := new(WorkInstanceInfo)
|
||||
|
||||
if err := db.Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Instances 基本信息
|
||||
func (m *WorkInstance) Instances(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*WorkInstanceInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS w").
|
||||
|
42
app/model/work_material.go
Normal file
42
app/model/work_material.go
Normal file
@ -0,0 +1,42 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"ArmedPolice/app/common/model"
|
||||
"ArmedPolice/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type WorkMaterial struct {
|
||||
*model.WorkMaterial
|
||||
}
|
||||
|
||||
// WorkMaterialInfo 器材信息
|
||||
type WorkMaterialInfo struct {
|
||||
ID uint64 `json:"-"`
|
||||
MaterialNumber float64 `json:"material_number"`
|
||||
MaterialCode string `json:"material_code"`
|
||||
MaterialTitle string `json:"material_title"`
|
||||
MaterialPrice float64 `json:"material_price"`
|
||||
SupplierName string `json:"supplier_name"`
|
||||
}
|
||||
|
||||
// Materials 器材信息
|
||||
func (m *WorkMaterial) Materials(workID uint64) ([]*WorkMaterialInfo, error) {
|
||||
out := make([]*WorkMaterialInfo, 0)
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" w").
|
||||
Select("w.id", "w.material_number", "m.code AS material_code", "m.title AS material_title",
|
||||
"m.price AS material_price", "s.name AS supplier_name").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS m ON w.material_id = m.id", model.NewManageMaterial().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS s ON w.material_supplier_id = s.id", model.NewManageSupplier().TableName())).
|
||||
Where("w.work_id = ?", workID)
|
||||
|
||||
if err := db.Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewWorkMaterial() *WorkMaterial {
|
||||
return &WorkMaterial{model.NewWorkMaterial()}
|
||||
}
|
@ -164,6 +164,7 @@ func (this *Router) registerAPI() {
|
||||
workV1.POST("/list", _api.Instance)
|
||||
workV1.POST("/person", _api.Person)
|
||||
workV1.POST("/workbench", _api.Workbench)
|
||||
workV1.POST("/detail", _api.Detail)
|
||||
workV1.POST("/launch", _api.Launch)
|
||||
workV1.POST("/examine", _api.Examine)
|
||||
workV1.POST("/delete", _api.Delete)
|
||||
|
Reference in New Issue
Block a user