From 29c250e5c8d05c13fffbaea9d1cc8e618b347f8d Mon Sep 17 00:00:00 2001 From: "Mr. Lan" Date: Wed, 3 Mar 2021 00:29:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=B7=A5=E5=8D=95?= =?UTF-8?q?=E9=87=8D=E5=BC=80=E5=8A=9F=E8=83=BD=EF=BC=8Cfixes=20#133,=20#5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apis/process/workOrder.go | 100 ++++++++++++++++++++++++++++++++++++ config/db.sql | 8 +++ router/process/workOrder.go | 1 + 3 files changed, 109 insertions(+) diff --git a/apis/process/workOrder.go b/apis/process/workOrder.go index 22a615d..f705dad 100644 --- a/apis/process/workOrder.go +++ b/apis/process/workOrder.go @@ -450,3 +450,103 @@ func DeleteWorkOrder(c *gin.Context) { app.OK(c, "", "工单已删除") } + +// 重开工单 +func ReopenWorkOrder(c *gin.Context) { + var ( + err error + id string + workOrder process.WorkOrderInfo + processInfo process.Info + structure map[string]interface{} + startId string + label string + jsonState []byte + relatedPerson []byte + newWorkOrder process.WorkOrderInfo + workOrderData []*process.TplData + ) + + id = c.Param("id") + + // 查询当前ID的工单信息 + err = orm.Eloquent.Find(&workOrder, id).Error + if err != nil { + app.Error(c, -1, err, fmt.Sprintf("查询工单信息失败, %s", err.Error())) + return + } + + // 创建新的工单 + err = orm.Eloquent.Find(&processInfo, workOrder.Process).Error + if err != nil { + app.Error(c, -1, err, fmt.Sprintf("查询流程信息失败, %s", err.Error())) + return + } + err = json.Unmarshal(processInfo.Structure, &structure) + if err != nil { + app.Error(c, -1, err, fmt.Sprintf("Json序列化失败, %s", err.Error())) + return + } + for _, node := range structure["nodes"].([]interface{}) { + if node.(map[string]interface{})["clazz"] == "start" { + startId = node.(map[string]interface{})["id"].(string) + label = node.(map[string]interface{})["label"].(string) + } + } + + state := []map[string]interface{}{ + {"id": startId, "label": label, "processor": []int{tools.GetUserId(c)}, "process_method": "person"}, + } + jsonState, err = json.Marshal(state) + if err != nil { + app.Error(c, -1, err, fmt.Sprintf("Json序列化失败, %s", err.Error())) + return + } + + relatedPerson, err = json.Marshal([]int{tools.GetUserId(c)}) + if err != nil { + app.Error(c, -1, err, fmt.Sprintf("Json序列化失败, %s", err.Error())) + return + } + + tx := orm.Eloquent.Begin() + + newWorkOrder = process.WorkOrderInfo{ + Title: workOrder.Title + "-copy", + Priority: workOrder.Priority, + Process: workOrder.Process, + Classify: workOrder.Classify, + State: jsonState, + RelatedPerson: relatedPerson, + Creator: tools.GetUserId(c), + } + err = tx.Create(&newWorkOrder).Error + if err != nil { + tx.Rollback() + app.Error(c, -1, err, fmt.Sprintf("新建工单失败, %s", err.Error())) + return + } + + // 查询工单数据 + err = orm.Eloquent.Model(&process.TplData{}).Where("work_order = ?", id).Find(&workOrderData).Error + if err != nil { + tx.Rollback() + app.Error(c, -1, err, fmt.Sprintf("查询工单数据失败, %s", err.Error())) + return + } + + for _, d := range workOrderData { + d.WorkOrder = newWorkOrder.Id + d.Id = 0 + err = tx.Create(d).Error + if err != nil { + tx.Rollback() + app.Error(c, -1, err, fmt.Sprintf("创建工单数据失败, %s", err.Error())) + return + } + } + + tx.Commit() + + app.OK(c, nil, "") +} diff --git a/config/db.sql b/config/db.sql index 782954d..a29f95c 100644 --- a/config/db.sql +++ b/config/db.sql @@ -78,6 +78,12 @@ INSERT INTO `casbin_rule`(`p_type`, `v0`, `v1`, `v2`, `v3`, `v4`, `v5`) VALUES ( INSERT INTO `casbin_rule`(`p_type`, `v0`, `v1`, `v2`, `v3`, `v4`, `v5`) VALUES ('p', 'admin', '/api/v1/settings', 'POST', NULL, NULL, NULL); INSERT INTO `casbin_rule`(`p_type`, `v0`, `v1`, `v2`, `v3`, `v4`, `v5`) VALUES ('p', 'admin', '/api/v1/settings', 'GET', NULL, NULL, NULL); INSERT INTO `casbin_rule`(`p_type`, `v0`, `v1`, `v2`, `v3`, `v4`, `v5`) VALUES ('p', 'admin', '/api/v1/loginlog', 'DELETE', NULL, NULL, NULL); +INSERT INTO `casbin_rule`(p_type, v0, v1, v2, v3, v4, v5) VALUES ('p', 'admin', '/api/v1/work-order/active-order/:id', 'PUT', null, null, null); +INSERT INTO `casbin_rule`(p_type, v0, v1, v2, v3, v4, v5) VALUES ('p', 'admin', '/api/v1/work-order/delete/:id', 'DELETE', null, null, null); +INSERT INTO `casbin_rule`(p_type, v0, v1, v2, v3, v4, v5) VALUES ('p', 'admin', '/api/v1/ordinaryDeptList', 'GET', null, null, null); +INSERT INTO `casbin_rule`(p_type, v0, v1, v2, v3, v4, v5) VALUES ('p', 'admin', '/api/v1/tpl/clone/:id', 'POST', null, null, null); +INSERT INTO `casbin_rule`(p_type, v0, v1, v2, v3, v4, v5) VALUES ('p', 'admin', '/api/v1/process/clone/:id', 'POST', null, null, null); +INSERT INTO `casbin_rule`(p_type, v0, v1, v2, v3, v4, v5) VALUES ('p', 'admin', '/api/v1/work-order/reopen/:id', 'POST', null, null, null); INSERT INTO `casbin_rule`(`p_type`, `v0`, `v1`, `v2`, `v3`, `v4`, `v5`) VALUES ('p', 'common', '/api/v1/user/profile', 'GET', NULL, NULL, NULL); INSERT INTO `casbin_rule`(`p_type`, `v0`, `v1`, `v2`, `v3`, `v4`, `v5`) VALUES ('p', 'common', '/api/v1/menurole', 'GET', NULL, NULL, NULL); INSERT INTO `casbin_rule`(`p_type`, `v0`, `v1`, `v2`, `v3`, `v4`, `v5`) VALUES ('p', 'common', '/api/v1/menuTreeselect', 'GET', NULL, NULL, NULL); @@ -277,6 +283,8 @@ INSERT INTO sys_menu (menu_id, menu_name, title, icon, path, paths, menu_type, ` INSERT INTO sys_menu (menu_id, menu_name, title, icon, path, paths, menu_type, `action`, permission, parent_id, no_cache, breadcrumb, component, sort, visible, create_by, update_by, is_frame, create_time, update_time, delete_time) VALUES (367, '', '克隆模版', 'bug', '/api/v1/tpl/clone/:id', '/0/63/281/282/294/367', 'A', 'POST', '', 294, '0', '', '', 0, '1', '1', '', 1, '2021-02-19 23:00:31', '2021-02-19 23:00:31', null); INSERT INTO sys_menu (menu_id, menu_name, title, icon, path, paths, menu_type, `action`, permission, parent_id, no_cache, breadcrumb, component, sort, visible, create_by, update_by, is_frame, create_time, update_time, delete_time) VALUES (368, '', '克隆流程', '', '', '/0/268/274/277/368', 'F', '', 'process:admin:manager:clone', 277, '0', '', '', 0, '0', '1', '1', 1, '2021-02-19 23:17:46', '2021-02-19 23:36:46', null); INSERT INTO sys_menu (menu_id, menu_name, title, icon, path, paths, menu_type, `action`, permission, parent_id, no_cache, breadcrumb, component, sort, visible, create_by, update_by, is_frame, create_time, update_time, delete_time) VALUES (369, '', '克隆流程', 'bug', '/api/v1/process/clone/:id', '/0/63/281/282/309/369', 'A', 'POST', '', 309, '0', '', '', 0, '1', '1', '', 1, '2021-02-19 23:25:18', '2021-02-19 23:25:18', null); +INSERT INTO sys_menu (menu_id, menu_name, title, icon, path, paths, menu_type, action, permission, parent_id, no_cache, breadcrumb, component, sort, visible, create_by, update_by, is_frame, create_time, update_time, delete_time) VALUES (370, '', '重开工单', 'guide', '', '/0/268/271/370', 'F', '', 'process:list:myCreate:reopen', 271, '0', '', '', 0, '0', '1', '', 1, '2021-03-02 22:45:17', '2021-03-02 22:45:17', null); +INSERT INTO sys_menu (menu_id, menu_name, title, icon, path, paths, menu_type, action, permission, parent_id, no_cache, breadcrumb, component, sort, visible, create_by, update_by, is_frame, create_time, update_time, delete_time) VALUES (371, '', '重开工单', 'bug', '/api/v1/work-order/reopen/:id', '/0/63/281/333/371', 'A', 'POST', '', 333, '0', '', '', 0, '1', '1', '', 1, '2021-03-02 22:46:46', '2021-03-02 22:46:46', null); COMMIT; BEGIN; diff --git a/router/process/workOrder.go b/router/process/workOrder.go index 086bdfc..4413da2 100644 --- a/router/process/workOrder.go +++ b/router/process/workOrder.go @@ -24,5 +24,6 @@ func RegisterWorkOrderRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMidd workOrderRouter.GET("/urge", process.UrgeWorkOrder) workOrderRouter.PUT("/active-order/:id", process.ActiveOrder) workOrderRouter.DELETE("/delete/:id", process.DeleteWorkOrder) + workOrderRouter.POST("/reopen/:id", process.ReopenWorkOrder) } }