diff --git a/app/api/manage.go b/app/api/manage.go index 0542faf..6afdd95 100644 --- a/app/api/manage.go +++ b/app/api/manage.go @@ -33,20 +33,109 @@ type ( * @apiDefine Manage 数据管理 */ +/** +* @api {post} /api/v1/manage/equipment 装备信息 +* @apiVersion 1.0.0 +* @apiName ManageEquipment +* @apiGroup Manage +* +* @apiHeader {string} x-token token +* +* @apiParam {String} [parent_id="''"] 父集ID +* @apiParam {String} [title="''"] 名称 +* +* @apiSuccess (200) {Number} code 成功响应状态码! +* @apiSuccess (200) {String} msg 成功提示 +* @apiSuccess (200) {Object} data 数据信息 +* @apiSuccess (200) {String} data.id ID +* @apiSuccess (200) {String} data.code 装备编码 +* @apiSuccess (200) {String} data.title 装备名称 +* @apiSuccess (200) {String} data.image 装备图片 +* @apiSuccess (200) {String} data.created_at 创建时间 +* @apiSuccess (200) {Object} data.childrens 子集 +* +* @apiSuccessExample {json} Success response: +* HTTPS 200 OK +* { +* "code": 200 +* "msg": "ok" +* "data": [ +* { +* "id": "EgmJ4Ga7LQ", +* "code": "S110", +* "title": "装甲车-11", +* "image": "http://192.168.31.195:8030/", +* "created_at": "2021-11-09T13:39:19+08:00", +* "children": [] +* } +* ] +* } + */ func (*Manage) Equipment(c *gin.Context) { form := &struct { ParentID uint64 `json:"parent_id" form:"parent_id"` Title string `json:"title" form:"title"` - PageForm }{} if err := bind(form)(c); err != nil { APIFailure(err.(error))(c) return } - data, err := manage.NewEquipment()(getSession()(c).(*service.Session)).List(form.ParentID, form.Title, form.Page, form.PageSize) + data, err := manage.NewEquipment()(getSession()(c).(*service.Session)).List(form.ParentID, form.Title) APIResponse(err, data)(c) } +/** +* @api {post} /api/v1/manage/equipment/detail 装备详细信息 +* @apiVersion 1.0.0 +* @apiName ManageEquipmentDetail +* @apiGroup Manage +* +* @apiHeader {string} x-token token +* +* @apiParam {String} [id="''"] 区域标识 +* +* @apiSuccess (200) {Number} code 成功响应状态码! +* @apiSuccess (200) {String} msg 成功提示 +* @apiSuccess (200) {Object} data 数据信息 +* @apiSuccess (200) {String} data.id ID +* @apiSuccess (200) {String} data.code 装备编码 +* @apiSuccess (200) {String} data.title 装备名称 +* @apiSuccess (200) {String} data.image 装备图片 +* @apiSuccess (200) {String} data.created_at 创建时间 +* @apiSuccess (200) {Object} data.materials 器材信息 +* @apiSuccess (200) {String} data.materials.id 器材ID +* @apiSuccess (200) {String} data.materials.code 器材编码 +* @apiSuccess (200) {String} data.materials.title 器材名称 +* @apiSuccess (200) {Number} data.materials.unit 器材单位 +* @apiSuccess (200) {String} data.materials.manufacturer_name 器材制造商 +* +* @apiSuccessExample {json} Success response: +* HTTPS 200 OK +* { +* "code": 200 +* "msg": "ok" +* "data": [ +* { +* "id": "EgmJ4Ga7LQ", +* "code": "S110", +* "title": "装甲车-11", +* "image": "http://192.168.31.195:8030/", +* "config": "", +* "remark": "", +* "created_at": "2021-11-09T13:39:19+08:00", +* "materials": [ +* { +* "id": "EgmJ4Ga7LQ", +* "code": "S110", +* "title": "装甲车-11", +* "unit": 1, +* "manufacturer_name": "测试的" +* } +* ] +* } +* ] +* } + */ func (*Manage) EquipmentDetail(c *gin.Context) { form := new(IDStringForm) diff --git a/app/api/menu.go b/app/api/menu.go index b2babb0..6ee811a 100644 --- a/app/api/menu.go +++ b/app/api/menu.go @@ -12,7 +12,7 @@ type Menu struct{} type ( // menuForm 菜单信息 menuForm struct { - ParentID uint64 `json:"parent_id" form:"parent_id"` + ParentID string `json:"parent_id" form:"parent_id"` Name string `json:"name" form:"name" binding:"required"` Kind int `json:"kind" form:"kind" binding:"required"` Link string `json:"link" form:"link"` @@ -115,8 +115,10 @@ func (a *Menu) Add(c *gin.Context) { APIFailure(err.(error))(c) return } + obj := new(IDStringForm) + obj.ID = form.ParentID err := menu.NewInstance()(getSession()(c).(*service.Session)).Form(&menu.InstanceParams{ - ParentID: form.ParentID, Name: form.Name, Kind: form.Kind, Link: form.Link, Component: form.Component, + ParentID: obj.Convert(), Name: form.Name, Kind: form.Kind, Link: form.Link, Component: form.Component, Icon: form.Icon, Auth: form.Auth, Sort: form.Sort, Status: form.Status, Remark: form.Remark, }) APIResponse(err)(c) @@ -161,8 +163,10 @@ func (a *Menu) Edit(c *gin.Context) { APIFailure(err.(error))(c) return } + obj := new(IDStringForm) + obj.ID = form.ParentID err := menu.NewInstance()(getSession()(c).(*service.Session)).Form(&menu.InstanceParams{ - ID: form.Convert(), ParentID: form.ParentID, Name: form.Name, Kind: form.Kind, Link: form.Link, Component: form.Component, + ID: form.Convert(), ParentID: obj.Convert(), Name: form.Name, Kind: form.Kind, Link: form.Link, Component: form.Component, Icon: form.Icon, Auth: form.Auth, Sort: form.Sort, Status: form.Status, Remark: form.Remark, }) APIResponse(err)(c) diff --git a/app/api/work.go b/app/api/work.go index feb6d33..5888fc4 100644 --- a/app/api/work.go +++ b/app/api/work.go @@ -94,10 +94,35 @@ func (*Work) Instance(c *gin.Context) { APIResponse(err, data)(c) } +func (*Work) Person(c *gin.Context) { + form := &struct { + MaterialID uint64 `json:"material_id" form:"material_id"` + Kind int `json:"kind" form:"kind"` + PageForm + }{} + if err := bind(form)(c); err != nil { + APIFailure(err.(error))(c) + return + } + data, err := work.NewInstance()(getSession()(c).(*service.Session)).Person(form.MaterialID, form.Kind, form.Page, form.PageSize) + APIResponse(err, data)(c) +} + func (*Work) ToDo(c *gin.Context) { } +func (*Work) Detail(c *gin.Context) { + form := new(IDStringForm) + + if err := bind(form)(c); err != nil { + APIFailure(err.(error))(c) + return + } + data, err := work.NewInstance()(getSession()(c).(*service.Session)).Detail(form.Convert()) + APIResponse(err, data)(c) +} + func (*Work) Launch(c *gin.Context) { form := &struct { workLaunchForm @@ -129,3 +154,19 @@ func (*Work) Examine(c *gin.Context) { err := work.NewInstance()(getSession()(c).(*service.Session)).Examine(form.Convert(), form.Status, form.Remark, form.IsAssist) APIResponse(err) } + +func (*Work) Delete(c *gin.Context) { + form := new(IDStringForm) + + if err := bind(form)(c); err != nil { + APIFailure(err.(error))(c) + return + } + err := work.NewInstance()(getSession()(c).(*service.Session)).Delete(form.Convert()) + APIResponse(err)(c) +} + +func (*Work) Schedule(c *gin.Context) { + data, err := work.NewSchedule()(getSession()(c).(*service.Session)).List() + APIResponse(err, data)(c) +} diff --git a/app/common/init.go b/app/common/init.go index 05bbafe..038af40 100644 --- a/app/common/init.go +++ b/app/common/init.go @@ -49,9 +49,11 @@ func initModel() { &synchronized{iModel: model.NewSysBreakdown()}, // 功能信息 &synchronized{iModel: model.NewManageSupplier()}, + &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.NewWorkInstance()}, &synchronized{iModel: model.NewWorkProgress()}, + &synchronized{iModel: model.NewWorkSchedule()}, &synchronized{iModel: model.NewWorkRepair()}, ) } func initCacheMode() { diff --git a/app/common/model/work_instance.go b/app/common/model/work_instance.go index de8a888..02f4c9f 100644 --- a/app/common/model/work_instance.go +++ b/app/common/model/work_instance.go @@ -17,7 +17,7 @@ type WorkInstance struct { Breakdown string `gorm:"column:breakdown;type:varchar(150);default:null;comment:故障" json:"breakdown"` 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 `orm:"column:is_assist;type:tinyint(1);default:0;comment:协助状态" json:"is_assist"` // 当前阶段协助状态,确认是否需要下一阶段协助 + 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:"-"` diff --git a/app/common/model/work_schedule.go b/app/common/model/work_schedule.go index 359fde2..5db1b71 100644 --- a/app/common/model/work_schedule.go +++ b/app/common/model/work_schedule.go @@ -5,16 +5,25 @@ import "strings" // WorkSchedule 工单流程数据模型 type WorkSchedule struct { Model + Kind WorkScheduleKind `gorm:"column:kind;type:tinyint(1);default:1;comment:工单类型" json:"-"` Title string `gorm:"column:title;type:varchar(30);default:null;comment:标题" json:"title"` - Stage int `orm:"column:stage;type:tinyint(1);default:1;comment:阶段" json:"stage"` - Step int `orm:"column:step;type:tinyint(1);default:1;comment:步骤(1:阶段-1:步骤)" json:"step"` - Target WorkScheduleTarget `orm:"column:target;type:tinyint(1);default:1;comment:对象类型" json:"target"` - TargetValue string `orm:"column:target_value;type:tinyint(1);default:1;comment:对象信息" json:"target_value"` - IsCountersign WorkScheduleCountersign `orm:"column:is_countersign;type:tinyint(1);default:0;comment:是否会签" json:"is_countersign"` + Stage int `gorm:"column:stage;type:tinyint(1);default:1;comment:阶段" json:"stage"` + Step int `gorm:"column:step;type:tinyint(1);default:1;comment:步骤(1:阶段-1:步骤)" json:"step"` + Target WorkScheduleTarget `gorm:"column:target;type:tinyint(1);default:1;comment:对象类型" json:"target"` + TargetValue string `gorm:"column:target_value;type:tinyint(1);default:1;comment:对象信息" json:"target_value"` + IsCountersign WorkScheduleCountersign `gorm:"column:is_countersign;type:tinyint(1);default:0;comment:是否会签" json:"is_countersign"` ModelDeleted ModelAt } +// WorkScheduleKind 工单流程类型 +type WorkScheduleKind int + +const ( + // WorkScheduleKindForRepair 维修工单 + WorkScheduleKindForRepair WorkScheduleKind = iota + 1 +) + // WorkScheduleTarget 工单对象类型 type WorkScheduleTarget int @@ -51,6 +60,13 @@ func (m *WorkSchedule) SetTargetValueAttribute(value []string) { m.TargetValue = strings.Join(value, ",") } +func (m *WorkSchedule) KindTitle() string { + if m.Kind == WorkScheduleKindForRepair { + return "维修工单" + } + return "" +} + func NewWorkSchedule() *WorkSchedule { return &WorkSchedule{} } diff --git a/app/controller/manage/equipment.go b/app/controller/manage/equipment.go index b030349..84acb82 100644 --- a/app/controller/manage/equipment.go +++ b/app/controller/manage/equipment.go @@ -52,18 +52,24 @@ func (c *EquipmentParams) isExist(iModel model2.IModel, tenantID uint64) (bool, return count > 0, nil } -func (c *Equipment) tree(src []*model2.ManageEquipment, parentID uint64) []*EquipmentInfo { +func (c *Equipment) tree(iModel model2.IModel, src []*model2.ManageEquipment, parentID uint64) []*EquipmentInfo { out := make([]*EquipmentInfo, 0) for _, v := range src { if v.ParentID == parentID { + //parentID := "0" + // + //if v.ParentID > 0 { + // iModel.SetID(v.ParentID) + // parentID = iModel.GetEncodeID() + //} out = append(out, &EquipmentInfo{ CommonIDString: basic.CommonIDString{ID: v.GetEncodeID()}, Code: v.Code, Title: v.Title, Image: v.Analysis(config.SettingInfo.Domain), CreatedAt: v.CreatedAt, - Children: c.tree(src, v.ID), + Children: c.tree(iModel, src, v.ID), }) } } @@ -71,21 +77,17 @@ func (c *Equipment) tree(src []*model2.ManageEquipment, parentID uint64) []*Equi } // List 列表信息 -func (c *Equipment) List(parentID uint64, title string, page, pageSize int) ([]*EquipmentInfo, error) { +func (c *Equipment) List(parentID uint64, title string) ([]*EquipmentInfo, error) { mManageEquipment := model.NewManageEquipment() out := make([]*model2.ManageEquipment, 0) where := []*model2.ModelWhereOrder{ &model2.ModelWhereOrder{ + Where: model2.NewWhere("parentID", parentID), Order: model2.NewOrder("id", model2.OrderModeToDesc), }, } - if parentID > 0 { - where = append(where, &model2.ModelWhereOrder{ - Where: model2.NewWhere("parentID", parentID), - }) - } if title != "" { where = append(where, &model2.ModelWhereOrder{ Where: model2.NewWhereLike("title", title), @@ -95,8 +97,7 @@ func (c *Equipment) List(parentID uint64, title string, page, pageSize int) ([]* where...); err != nil { return nil, err } - - return c.tree(out, 0), nil + return c.tree(mManageEquipment.ManageEquipment, out, 0), nil } // Detail 详细信息 diff --git a/app/controller/menu/instance.go b/app/controller/menu/instance.go index 61bd3d6..bc81ce4 100644 --- a/app/controller/menu/instance.go +++ b/app/controller/menu/instance.go @@ -17,6 +17,7 @@ type ( InstanceInfo struct { ID string `json:"id"` *model2.SysMenu + ParentID string `json:"parent_id"` Children []*InstanceInfo `json:"children"` } // InstanceIdentityInfo 多个身份菜单信息 @@ -37,15 +38,22 @@ type ( ) // tree 树状筛选 -func (c *Instance) tree(src []*model2.SysMenu, parentID uint64) []*InstanceInfo { +func (c *Instance) tree(iModel model2.IModel, src []*model2.SysMenu, parentID uint64) []*InstanceInfo { out := make([]*InstanceInfo, 0) for _, v := range src { if v.ParentID == parentID { + parentID := "0" + + if v.ParentID > 0 { + iModel.SetID(v.ParentID) + parentID = iModel.GetEncodeID() + } out = append(out, &InstanceInfo{ ID: v.GetEncodeID(), + ParentID: parentID, SysMenu: v, - Children: c.tree(src, v.ID), + Children: c.tree(iModel, src, v.ID), }) } } @@ -79,7 +87,7 @@ func (c *Instance) List() ([]*InstanceInfo, error) { if err != nil { return nil, err } - return c.tree(out, 0), nil + return c.tree(mSysMenu.SysMenu, out, 0), nil } // Form 数据操作 @@ -96,7 +104,7 @@ func (c *Instance) Form(params *InstanceParams) error { }, Auth: model2.SysMenuAuth(params.Auth), Sort: params.Sort, - Status: model2.SysMenuStatusForNormal, + Status: model2.SysMenuStatus(params.Status), Remark: params.Remark, }) } @@ -121,7 +129,7 @@ func (c *Instance) Form(params *InstanceParams) error { out.Status = model2.SysMenuStatus(params.Status) out.Remark = params.Remark - if err = model2.Save(out); err != nil { + if err = model2.Save(out.SysMenu); err != nil { return err } return nil diff --git a/app/controller/work/instance.go b/app/controller/work/instance.go index 91dea57..8960f58 100644 --- a/app/controller/work/instance.go +++ b/app/controller/work/instance.go @@ -23,6 +23,11 @@ type ( basic.CommonIDString *model.WorkInstanceInfo } + // InstanceDetailInfo 详细信息 + InstanceDetailInfo struct { + basic.CommonIDString + *model.WorkInstanceInfo + } // InstanceLaunchParams 发起参数信息 InstanceLaunchParams struct { ID uint64 @@ -88,8 +93,46 @@ func (c *Instance) List(materialID uint64, kind, page, pageSize int) (*basic.Pag return &basic.PageDataResponse{Data: list, Count: count}, nil } -func (c *Instance) ToDo() { +// Person 个人提交的审核信息 +func (c *Instance) Person(materialID uint64, kind, page, pageSize int) (*basic.PageDataResponse, error) { + mWorkInstance := model.NewWorkInstance() + where := make([]*model2.ModelWhere, 0) + + if materialID > 0 { + where = append(where, model2.NewWhere("w.material_id", materialID)) + } + if kind > 0 { + where = append(where, model2.NewWhere("w.kind", kind)) + } + var count int64 + + out, err := mWorkInstance.Persons(c.UID, model2.WorkScheduleKindForRepair, page, pageSize, &count, where...) + + if err != nil { + return nil, err + } + list := make([]*InstanceInfo, 0) + + for _, v := range out { + mWorkInstance.ID = v.ID + + list = append(list, &InstanceInfo{ + CommonIDString: basic.CommonIDString{ID: mWorkInstance.GetEncodeID()}, WorkInstanceInfo: v, + }) + } + return &basic.PageDataResponse{Data: list, Count: count}, nil +} + +// Workbench 工作台 +func (c *Instance) Workbench() { + +} + +func (c *Instance) Detail(id uint64) (interface{}, error) { + mWorkInstance := model.NewWorkInstance() + mWorkInstance.ID = id + return nil, nil } // Launch 发起工单申请 @@ -129,7 +172,7 @@ func (c *Instance) Launch(params *InstanceLaunchParams) error { isExist := false - if isExist, err = mWorkSchedule.FirstSchedule(); err != nil { + if isExist, err = mWorkSchedule.FirstSchedule(model2.WorkScheduleKindForRepair); err != nil { return err } else if !isExist { return errors.New("操作错误,无工单流程信息,请先核实数据") @@ -157,12 +200,9 @@ func (c *Instance) Launch(params *InstanceLaunchParams) error { if err = model2.Create(mWorkProgress.WorkProgress, tx); err != nil { return err } - // 创建维修工单 - mWorkRepair := model.NewWorkRepair() - mWorkRepair.WorkID = mWorkInstance.ID - - if err = model2.Create(mWorkRepair.WorkRepair, tx); err != nil { - return err + if nextWorkSchedule != nil { + // 推送通知 + go c.publish(nextWorkSchedule.Reviewer) } return nil }) @@ -204,6 +244,7 @@ func (c *Instance) Examine(id uint64, status int, remark string, isAssist int) e } else if !isAuth { return errors.New("操作错误,无权限审批") } + if err = orm.GetDB().Transaction(func(tx *gorm.DB) error { // 工单流程记录 mWorkProgress := model.NewWorkProgress() @@ -220,33 +261,42 @@ func (c *Instance) Examine(id uint64, status int, remark string, isAssist int) e "status": model2.WorkInstanceStatusForComplete, "updated_at": time.Now(), } // 下一流程 - newNextScheduleInfo := new(model.WorkScheduleInfo) + nextScheduleInfo := new(model.WorkScheduleInfo) // 拒绝审批,工单直接结束 if _status == model2.WorkProgressStatusForRefuse { goto FINISH } // 下一流程信息 - if newNextScheduleInfo, err = mWorkSchedule.NextSchedule(model2.WorkInstanceAssist(isAssist) == model2.WorkInstanceAssistForYes); err != nil { + if nextScheduleInfo, err = mWorkSchedule.NextSchedule(model2.WorkInstanceAssist(isAssist) == model2.WorkInstanceAssistForYes); err != nil { return err } // 无下一流程,工单直接完成 - if newNextScheduleInfo == nil || newNextScheduleInfo.ID <= 0 { + if nextScheduleInfo == nil || nextScheduleInfo.ID <= 0 { goto FINISH } workUpdates["status"] = model2.WorkInstanceStatusForOngoing - workUpdates["schedule"] = newNextScheduleInfo.ID + workUpdates["schedule"] = nextScheduleInfo.ID - if newNextScheduleInfo.IsNext { + if nextScheduleInfo.IsNextStage { workUpdates["is_assist"] = isAssist } - // 推送通知 - go c.publish(newNextScheduleInfo.Reviewer) - FINISH: if err = model2.Updates(mWorkInstance.WorkInstance, workUpdates, tx); err != nil { return err } + // 完成,创建维修工单 + if workUpdates["status"] == model2.WorkInstanceStatusForComplete { + // 创建维修工单 + mWorkRepair := model.NewWorkRepair() + mWorkRepair.WorkID = mWorkInstance.ID + + if err = model2.Create(mWorkRepair.WorkRepair, tx); err != nil { + return err + } + } + // 推送通知 + go c.publish(nextScheduleInfo.Reviewer) return nil }); err != nil { return err @@ -254,8 +304,11 @@ func (c *Instance) Examine(id uint64, status int, remark string, isAssist int) e return nil } -func (c *Instance) Delete() error { - return nil +// Delete 删除操作 +func (c *Instance) Delete(id uint64) error { + mWorkInstance := model.NewWorkInstance() + mWorkInstance.ID = id + return model2.Delete(mWorkInstance.WorkInstance) } func NewInstance() InstanceHandle { diff --git a/app/model/manage_equipment_material.go b/app/model/manage_equipment_material.go index a0672e3..b212968 100644 --- a/app/model/manage_equipment_material.go +++ b/app/model/manage_equipment_material.go @@ -19,7 +19,7 @@ func (m *ManageEquipmentMaterial) Materials(equipmentID uint64) ([]*ManageEquipm db := orm.GetDB().Table(m.TableName()+" AS e"). Select("e.id", "m.code", "m.title", "m.unit", "s.name AS manufacturer_name"). Joins(fmt.Sprintf("LEFT JOIN %s AS m ON e.material_id = m.id", model.NewManageMaterial().TableName())). - Joins(fmt.Sprintf("LEFT JOIN %s AS s ON m.supplier_id = s.id", model.NewManageSupplier().TableName())). + Joins(fmt.Sprintf("LEFT JOIN %s AS s ON m.manufacturer_id = s.id", model.NewManageSupplier().TableName())). Where("e.equipment_id = ? AND e.is_deleted = ?", equipmentID, model.DeleteStatusForNot) out := make([]*ManageEquipmentMaterialInfo, 0) diff --git a/app/model/sys_menu.go b/app/model/sys_menu.go index 6480cc2..607a1d1 100644 --- a/app/model/sys_menu.go +++ b/app/model/sys_menu.go @@ -20,8 +20,7 @@ type SysMenuScene struct { func (m *SysMenu) Menus() ([]*model.SysMenu, error) { out := make([]*model.SysMenu, 0) - db := orm.GetDB().Table(m.TableName()). - Where("status = ? AND is_deleted = ?", model.SysMenuStatusForNormal, model.DeleteStatusForNot) + db := orm.GetDB().Table(m.TableName()).Where("is_deleted = ?", model.DeleteStatusForNot) if err := db.Order("parent_id " + model.OrderModeToAsc).Order("sort " + model.OrderModeToDesc).Scan(&out).Error; err != nil { return nil, err diff --git a/app/model/work_instance.go b/app/model/work_instance.go index 57302df..47054db 100644 --- a/app/model/work_instance.go +++ b/app/model/work_instance.go @@ -49,6 +49,41 @@ func (m *WorkInstance) Instances(page, pageSize int, count *int64, where ...*mod return out, nil } +// Persons 个人信息 +func (m *WorkInstance) Persons(uid uint64, kind model.WorkScheduleKind, page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*WorkInstanceInfo, error) { + mWorkProgress := model.NewWorkProgress() + + mWorkSchedule := model.NewWorkSchedule() + + db := orm.GetDB().Table(model.NewWorkProgress().TableName()+" AS p"). + Select("w.id", "w.title", "e.code AS equipment_code", "e.title AS equipment_title", "w.priority", + "GROUP_CONCAT(b.title) AS breakdown_title", "w.status", "w.created_at"). + Joins(fmt.Sprintf("LEFT JOIN %s AS w ON p.work_id = w.id", m.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 b ON FIND_IN_SET(b.id, w.breakdown)", model.NewSysBreakdown().TableName())). + Joins(fmt.Sprintf("LEFT JOIN (SELECT id FROM %s WHERE kind = %d ORDER BY stage ASC, step ASC limit 1) AS s ON p.schedule_id = s.id", + mWorkSchedule.TableName(), kind)). + Where("p.is_deleted = ? AND w.is_deleted = ?", model.DeleteStatusForNot, model.DeleteStatusForNot). + Where("p.uid = ?", uid). + Where("s.id > ?", 0). + Group("w.id") + + if len(where) > 0 { + for _, wo := range where { + db = db.Where(wo.Condition, wo.Value) + } + } + out := make([]*WorkInstanceInfo, 0) + + if err := orm.GetDB().Table(mWorkProgress.TableName()).Where("is_deleted = ?", model.DeleteStatusForNot).Count(count).Error; err != nil { + return nil, err + } + if err := db.Order("w.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil { + return nil, err + } + return out, nil +} + func NewWorkInstance() *WorkInstance { return &WorkInstance{model.NewWorkInstance()} } diff --git a/app/model/work_schedule.go b/app/model/work_schedule.go index 9109b62..31ad598 100644 --- a/app/model/work_schedule.go +++ b/app/model/work_schedule.go @@ -13,9 +13,9 @@ type WorkSchedule struct { // WorkScheduleInfo 工单流程信息 type WorkScheduleInfo struct { - ID uint64 `json:"id"` - IsNext bool `json:"is_next"` - Reviewer []string `json:"reviewer"` + ID uint64 `json:"id"` + IsNextStage bool `json:"is_next_stage"` // 下一步骤 + Reviewer []string `json:"reviewer"` } // ValidateAuth 验证权限 @@ -50,8 +50,9 @@ func (m *WorkSchedule) ValidateAuth(uid uint64) (bool, error) { } // FirstSchedule 第一个流程 -func (m *WorkSchedule) FirstSchedule() (bool, error) { +func (m *WorkSchedule) FirstSchedule(kind model.WorkScheduleKind) (bool, error) { db := orm.GetDB().Table(m.TableName()).Select("id", "title", "stage", "step"). + Where("kind = ?", kind). Where("is_deleted = ?", model.DeleteStatusForNot). Order("stage " + model.OrderModeToAsc).Order("step " + model.OrderModeToAsc) @@ -66,15 +67,15 @@ func (m *WorkSchedule) FirstSchedule() (bool, error) { // NextSchedule 下一流程 func (m *WorkSchedule) NextSchedule(isAssets bool) (*WorkScheduleInfo, error) { - next := NewWorkSchedule() + nextWorkSchedule := model.NewWorkSchedule() - isExist, err := model.FirstWhere(next.WorkSchedule, model.NewWhere("stage", m.Stage), - model.NewWhere("step", m.Stage+1)) + isExist, err := model.FirstWhere(nextWorkSchedule, 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 &WorkScheduleInfo{ID: next.ID, Reviewer: next.GetTargetValueAttribute()}, err + return &WorkScheduleInfo{ID: nextWorkSchedule.ID, Reviewer: nextWorkSchedule.GetTargetValueAttribute()}, err } // 进入下一阶段 // 是否需要下一阶段协助 @@ -83,13 +84,36 @@ func (m *WorkSchedule) NextSchedule(isAssets bool) (*WorkScheduleInfo, error) { return nil, nil } // 下一阶段第一流程信息 - if isExist, err = model.FirstWhere(next.WorkSchedule, model.NewWhere("stage", m.Stage+1), - model.NewWhere("step", 1)); err != nil { + if err = orm.GetDB().Table(nextWorkSchedule.TableName()). + Where("kind = ? AND is_deleted = ?", m.Kind, model.DeleteStatusForNot). + Where("stage > ?", m.Stage). + Order("stage " + model.OrderModeToAsc).Order("step " + model.OrderModeToAsc). + First(nextWorkSchedule).Error; err != nil { + if err == gorm.ErrRecordNotFound { + return nil, nil + } return nil, err - } else if !isExist { - return nil, nil } - return &WorkScheduleInfo{ID: next.ID, IsNext: true, Reviewer: next.GetTargetValueAttribute()}, err + return &WorkScheduleInfo{ID: nextWorkSchedule.ID, IsNextStage: true, Reviewer: nextWorkSchedule.GetTargetValueAttribute()}, err +} + +// Schedules 流程信息 +func (m *WorkSchedule) Schedules() ([]*model.WorkSchedule, error) { + sql := `SELECT s.id, s.kind, s.title, s.stage, s.step, s.target, +CASE s.target +WHEN 1 THEN +(SELECT GROUP_CONCAT(u_d.name) FROM ( SELECT u.uuid, u.name FROM %s AS u WHERE u.is_deleted = %d) AS u_d WHERE FIND_IN_SET( u_d.uuid, s.target_value )) +WHEN 2 THEN +(SELECT GROUP_CONCAT(r_d.name) FROM (SELECT r.id, r.name FROM %s AS r WHERE r.is_deleted = %d) AS r_d WHERE FIND_IN_SET( r_d.id, s.target_value )) +ELSE "" +END AS target_value, s.is_countersign, s.created_at +FROM %s AS s WHERE s.is_deleted = %d ORDER BY s.kind ASC, s.stage ASC, s.step ASC` + out := make([]*model.WorkSchedule, 0) + + err := orm.GetDB().Raw(fmt.Sprintf(sql, model.NewSysUser().TableName(), model.DeleteStatusForNot, + model.NewSysRole().TableName(), model.DeleteStatusForNot, m.TableName(), model.DeleteStatusForNot)).Scan(&out).Error + + return out, err } func NewWorkSchedule() *WorkSchedule { diff --git a/router/router.go b/router/router.go index 7cce9b5..44888a9 100644 --- a/router/router.go +++ b/router/router.go @@ -129,6 +129,11 @@ func (this *Router) registerAPI() { { _api := new(api.Work) workV1.POST("/list", _api.Instance) + workV1.POST("/person", _api.Person) + workV1.POST("/launch", _api.Launch) + workV1.POST("/examine", _api.Examine) + workV1.POST("/delete", _api.Delete) + workV1.GET("/schedule", _api.Schedule) } }