Merge pull request #140 from lanyulei/dev

feat: 添加工单重开功能,fixes #133, #5
This commit is contained in:
lanyulei 2021-03-03 00:29:42 +08:00 committed by GitHub
commit bd9277c88f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 109 additions and 0 deletions

View File

@ -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, "")
}

View File

@ -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;

View File

@ -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)
}
}