From 3471eb1a8fe7955cccf7258459b81aa85a6b5f04 Mon Sep 17 00:00:00 2001 From: xiangheng <11675084@qq.com> Date: Thu, 21 Dec 2023 23:20:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=97=E5=85=B8=E5=8A=A0=E5=85=A5=E9=A2=9C?= =?UTF-8?q?=E8=89=B2=E6=96=B9=E4=BE=BF=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/src/components/dict-value/index.vue | 2 +- .../flow_apply/components/apply_submit.vue | 12 +- admin/src/views/flow_apply/index.vue | 34 ++-- .../flow_history/components/todo/approve.vue | 165 ------------------ admin/src/views/flow_history/todo.vue | 125 ++++++++----- admin/src/views/setting/dict/data/edit.vue | 8 + admin/src/views/setting/dict/data/index.vue | 53 ++++-- server/admin/flow_history/flow_history_ctl.go | 8 +- .../admin/flow_history/flow_history_schema.go | 20 ++- .../flow_history/flow_history_service.go | 147 +++++++++------- server/admin/setting/dict_data/schema.go | 7 +- server/main.go | 2 +- server/model/setting_model/dict_data.go | 1 + 13 files changed, 271 insertions(+), 313 deletions(-) delete mode 100644 admin/src/views/flow_history/components/todo/approve.vue diff --git a/admin/src/components/dict-value/index.vue b/admin/src/components/dict-value/index.vue index 2935e5d..7b742a9 100644 --- a/admin/src/components/dict-value/index.vue +++ b/admin/src/components/dict-value/index.vue @@ -1,7 +1,7 @@ diff --git a/admin/src/views/flow_apply/components/apply_submit.vue b/admin/src/views/flow_apply/components/apply_submit.vue index 86046e6..03792ed 100644 --- a/admin/src/views/flow_apply/components/apply_submit.vue +++ b/admin/src/views/flow_apply/components/apply_submit.vue @@ -91,15 +91,14 @@ const formRules = { } ] } -function open(row) { +function open(applyId) { console.log('open') Object.assign(formData, new formDataState()) - formData.id = row.id + formData.id = applyId dialogVisible.value = true flow_history_next_node({ - applyId: row.id, - currentNodeId: '' + applyId: applyId }).then((res) => { console.log('res', res) next_nodes.value = res @@ -122,14 +121,13 @@ function BeforeClose() { function getData() { console.log('getData', next_nodes) - if (!formData.applyUserId) { + if (userTask.value && !formData.applyUserId) { feedback.msgWarning('请选择审批人') return } flow_history_pass({ applyId: formData.id, - currentNodeId: '', - nextNodeAdminId: formData.applyUserId, + nextNodeAdminId: formData.applyUserId || 0, passRemark: formData.passRemark }).then(() => { BeforeClose() diff --git a/admin/src/views/flow_apply/index.vue b/admin/src/views/flow_apply/index.vue index be13a67..f1a69f5 100644 --- a/admin/src/views/flow_apply/index.vue +++ b/admin/src/views/flow_apply/index.vue @@ -2,9 +2,9 @@
- + @@ -115,7 +115,12 @@
- - diff --git a/admin/src/views/flow_history/todo.vue b/admin/src/views/flow_history/todo.vue index 661f3f9..09bb7be 100644 --- a/admin/src/views/flow_history/todo.vue +++ b/admin/src/views/flow_history/todo.vue @@ -7,13 +7,6 @@ - - - - - - - 查询 重置 @@ -21,25 +14,12 @@ -
- - - 新增 - -
+ - - - - - + + + + diff --git a/admin/src/views/setting/dict/data/edit.vue b/admin/src/views/setting/dict/data/edit.vue index 8620e7e..e5d5a4e 100644 --- a/admin/src/views/setting/dict/data/edit.vue +++ b/admin/src/views/setting/dict/data/edit.vue @@ -29,6 +29,13 @@ + + +
@@ -73,6 +80,7 @@ const formData = reactive({ typeValue: '', name: '', value: '', + color: '', sort: 0, status: 1, remark: '', diff --git a/admin/src/views/setting/dict/data/index.vue b/admin/src/views/setting/dict/data/index.vue index bf20d7c..a348e84 100644 --- a/admin/src/views/setting/dict/data/index.vue +++ b/admin/src/views/setting/dict/data/index.vue @@ -5,12 +5,21 @@ - + - + @@ -33,8 +42,12 @@ 添加数据 - + @@ -43,27 +56,45 @@
- + + - + diff --git a/server/admin/flow_history/flow_history_ctl.go b/server/admin/flow_history/flow_history_ctl.go index 72f0321..5a64245 100644 --- a/server/admin/flow_history/flow_history_ctl.go +++ b/server/admin/flow_history/flow_history_ctl.go @@ -141,11 +141,11 @@ func (hd FlowHistoryHandler) Del(c *gin.Context) { // // @Router /api/flow_apply/SubmitApply [post] func (hd FlowHistoryHandler) Pass(c *gin.Context) { - var nextNode NextNodeReq - if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &nextNode)) { + var pass PassReq + if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &pass)) { return } - err := Service.Pass(nextNode) + err := Service.Pass(pass) response.CheckAndResp(c, err) // 申请流程id, @@ -174,7 +174,7 @@ func (hd FlowHistoryHandler) NextNode(c *gin.Context) { } // response.CheckAndResp(c, Service.GetNextNode(nextNode)) - res, _, err := Service.GetNextNode(nextNode) + res, _, _, err := Service.GetNextNode(nextNode.ApplyId) response.CheckAndRespWithData(c, res, err) } diff --git a/server/admin/flow_history/flow_history_schema.go b/server/admin/flow_history/flow_history_schema.go index 527a690..38e1746 100644 --- a/server/admin/flow_history/flow_history_schema.go +++ b/server/admin/flow_history/flow_history_schema.go @@ -72,12 +72,6 @@ type FlowHistoryResp struct { CreateTime core.TsTime `json:"createTime" structs:"createTime"` // 创建时间 } -type NextNodeReq struct { - ApplyId int `form:"applyId"` // 申请id - CurrentNodeId string `form:"currentNodeId"` // 流程里的节点id - FormValue string `form:"formValue"` - NextNodeAdminId int `form:"nextNodeAdminId"` // 下一个节点的审批用户id -} type FlowTree struct { Id string `json:"id"` Pid string `json:"pid"` @@ -92,3 +86,17 @@ type FlowTree struct { Children *[]FlowTree `json:"children"` } +type NextNodeReq struct { + ApplyId int `form:"applyId"` // 申请id + // CurrentNodeId string `form:"currentNodeId"` // 流程里的节点id + // FormValue string `form:"formValue"` + // NextNodeAdminId int `form:"nextNodeAdminId"` // 下一个节点的审批用户id +} +type PassReq struct { + ApplyId int `form:"applyId"` // 申请id + + // CurrentNodeId string `form:"currentNodeId"` // 流程里的节点id + // FormValue string `form:"formValue"` + NextNodeAdminId int `form:"nextNodeAdminId"` // 下一个节点的审批用户id + PassRemark string `form:"passRemark"` // 通过备注 +} diff --git a/server/admin/flow_history/flow_history_service.go b/server/admin/flow_history/flow_history_service.go index c6e2733..8df109c 100644 --- a/server/admin/flow_history/flow_history_service.go +++ b/server/admin/flow_history/flow_history_service.go @@ -215,84 +215,111 @@ func (Service flowHistoryService) GetApprover(node FlowTree) (res []admin.System return adminResp, nil } -func (Service flowHistoryService) Pass(nextNode NextNodeReq) (e error) { - nextNodes, applyDetail, err := Service.GetNextNode(nextNode) +func (Service flowHistoryService) Pass(pass PassReq) (e error) { + nextNodes, applyDetail, LastHistory, err := Service.GetNextNode(pass.ApplyId) - isEnd := false - if err == nil { - for _, v := range nextNodes { - // if v.Type == "bpmn:exclusiveGateway" { - // 这里网关不用处理,顶多加一条历史记录 - // } - if v.Type == "bpmn:serviceTask" { - // 发邮件之类的,待完善 - } else if v.Type == "bpmn:userTask" { - var addReq = FlowHistoryAddReq{} - addReq.ApplyId = applyDetail.Id - addReq.FormValue = applyDetail.FormValue - addReq.NodeId = v.Id - addReq.ApproverId = nextNode.NextNodeAdminId - - // addReq.ApproverNickname = applyDetail.ApproverNickname - - addReq.TemplateId = applyDetail.TemplateId - addReq.ApplyUserId = applyDetail.ApplyUserId - addReq.ApplyUserNickname = applyDetail.ApplyUserNickname - addReq.PassStatus = 1 - err = Service.Add(addReq) - } else if v.Type == "bpmn:endEvent" { - isEnd = true - var addReq = FlowHistoryAddReq{} - addReq.ApplyId = applyDetail.Id - addReq.FormValue = applyDetail.FormValue - addReq.NodeId = v.Id - addReq.ApproverId = 0 - - // addReq.ApproverNickname = applyDetail.ApproverNickname - - addReq.TemplateId = applyDetail.TemplateId - addReq.ApplyUserId = applyDetail.ApplyUserId - addReq.ApplyUserNickname = applyDetail.ApplyUserNickname - addReq.PassStatus = 2 - err = Service.Add(addReq) - } - } + if err != nil { + return err } - // 待提交或者有结束节点,修改申请状态 - if applyDetail.Status == 1 || isEnd { - status := 2 //审批中 - if isEnd { - status = 3 //审批通过 + isEnd := false // 是否是最后一个节点 + + FormValue := applyDetail.FormValue + if LastHistory.Id != 0 { + FormValue = LastHistory.FormValue + } + var flows = []model.FlowHistory{} + + for _, v := range nextNodes { + // if v.Type == "bpmn:exclusiveGateway" { + // 这里网关不用处理,顶多加一条历史记录 + // } + var flow = model.FlowHistory{ + ApplyId: applyDetail.Id, + NodeId: v.Id, + FormValue: FormValue, + PassStatus: 1, + ApplyUserId: applyDetail.ApplyUserId, + TemplateId: applyDetail.TemplateId, + ApplyUserNickname: applyDetail.ApplyUserNickname, + ApproverId: 0, } - // 更改状态 - err = flow_apply.Service.Edit(flow_apply.FlowApplyEditReq{ - Id: nextNode.ApplyId, - Status: status, - }) - if err != nil { + if v.Type == "bpmn:serviceTask" { + // 发邮件之类的,待完善 + } else if v.Type == "bpmn:userTask" { + flow.ApproverId = pass.NextNodeAdminId + flow.PassStatus = 1 //1待处理 + } else if v.Type == "bpmn:endEvent" { + isEnd = true + flow.ApproverId = 0 + flow.PassStatus = 2 //2通过 + } + flows = append(flows, flow) + } + + err = Service.db.Transaction(func(tx *gorm.DB) error { + // 在事务中执行一些 db 操作(从这里开始,您应该使用 'tx' 而不是 'db') + if err := tx.Create(&flows).Error; err != nil { + // 返回任何错误都会回滚事务 return err } - } + // LastHistory + tx.Model(&LastHistory).Update("pass_status", 2) + if LastHistory.Id > 0 { + LastHistory.PassStatus = 2 + LastHistory.PassRemark = pass.PassRemark + tx.Save(&LastHistory) + } + + // 待提交或者有结束节点,修改申请状态 + if applyDetail.Status == 1 || isEnd { + status := 2 //审批中 + if isEnd { + status = 3 //审批通过 + } + tx.Model(&model.FlowApply{}).Where(model.FlowApply{ + Id: pass.ApplyId, + }).Update("status", status) + + if err != nil { + return err + } + } + return nil + }) + return err } /** * 获取下一批流程,直到审批或结束节点 */ -func (Service flowHistoryService) GetNextNode(nextNode NextNodeReq) (res []FlowTree, apply flow_apply.FlowApplyResp, e error) { - var applyDetail, err = flow_apply.Service.Detail(nextNode.ApplyId) +func (Service flowHistoryService) GetNextNode(ApplyId int) (res []FlowTree, apply flow_apply.FlowApplyResp, LastHistory model.FlowHistory, e error) { + var applyDetail, err = flow_apply.Service.Detail(ApplyId) + if e = response.CheckErr(err, "获取审批申请失败"); e != nil { return } + // 获取最后一条历史记录 + // var LastHistory model.FlowHistory + result := Service.db.Where(model.FlowHistory{ + ApplyId: ApplyId, + }).Limit(1).Last(&LastHistory) + // start var flowTree []FlowTree json.Unmarshal([]byte(applyDetail.FlowProcessDataList), &flowTree) var formValue map[string]interface{} - json.Unmarshal([]byte(nextNode.FormValue), &formValue) + + if result.RowsAffected == 1 { //有最新审批记录 + json.Unmarshal([]byte(LastHistory.FormValue), &formValue) + + } else { + json.Unmarshal([]byte(applyDetail.FormValue), &formValue) + } var next []FlowTree - - if nextNode.CurrentNodeId == "" { + if result.RowsAffected == 0 { + // if nextNode.CurrentNodeId == "" { for _, v := range flowTree { if v.Type == "bpmn:startEvent" { next = *v.Children @@ -301,7 +328,7 @@ func (Service flowHistoryService) GetNextNode(nextNode NextNodeReq) (res []FlowT } } else { for _, v := range flowTree { - if v.Id == nextNode.CurrentNodeId { + if v.Id == LastHistory.NodeId { next = *v.Children break } @@ -309,7 +336,7 @@ func (Service flowHistoryService) GetNextNode(nextNode NextNodeReq) (res []FlowT } var nextNodes []FlowTree res = DeepNextNode(nextNodes, &next, formValue) - return res, applyDetail, e + return res, applyDetail, LastHistory, e } // 返回节点数组,最后一个节点为用户或结束节点 diff --git a/server/admin/setting/dict_data/schema.go b/server/admin/setting/dict_data/schema.go index 154000f..d723845 100644 --- a/server/admin/setting/dict_data/schema.go +++ b/server/admin/setting/dict_data/schema.go @@ -8,6 +8,7 @@ type SettingDictDataResp struct { TypeId uint `json:"typeId" structs:"typeId"` // 类型 Name string `json:"name" structs:"name"` // 键 Value string `json:"value" structs:"value"` // 值 + Color string `json:"color" structs:"color"` // 颜色 Remark string `json:"remark" structs:"remark"` // 备注 Sort uint16 `json:"sort" structs:"sort"` // 排序 Status uint8 `json:"status" structs:"status"` // 状态: [0=停用, 1=禁用] @@ -33,7 +34,8 @@ type SettingDictDataAddReq struct { TypeId uint `form:"typeId" binding:"required,gt=0"` // 类型 Name string `form:"name" binding:"required,max=100"` // 键 Value string `form:"value" binding:"required,max=200"` // 值 - remark string `form:"remark" binding:"max=200"` // 备注 + Color string `form:"color"` // 颜色 + Remark string `form:"remark" binding:"max=200"` // 备注 Sort int `form:"sort" binding:"gte=0"` // 排序 Status int8 `form:"status,default=-1" binding:"oneof=-1 0 1"` // 状态: 0=停用,1=启用 } @@ -44,7 +46,8 @@ type SettingDictDataEditReq struct { TypeId uint `form:"typeId" binding:"required,gte=0"` // 类型 Name string `form:"name" binding:"required,max=100"` // 键 Value string `form:"value" binding:"required,max=200"` // 值 - remark string `form:"remark" binding:"max=200"` // 备注 + Color string `form:"color"` // 颜色 + Remark string `form:"remark" binding:"max=200"` // 备注 Sort int `form:"sort" binding:"gte=0"` // 排序 Status int8 `form:"status,default=-1" binding:"oneof=-1 0 1"` // 状态: 0=停用,1=启用 } diff --git a/server/main.go b/server/main.go index 269cf56..752f2f3 100644 --- a/server/main.go +++ b/server/main.go @@ -103,7 +103,7 @@ func main() { fmt.Println("格式化文档注释:", "swag fmt") fmt.Println("生成文档:", "swag init") - fmt.Println("文档:", "http://localhost:8001/swagger/index.html") + fmt.Printf("文档: http://localhost:%v/swagger/index.html", config.Config.ServerPort) // 初始化server s := initServer(router) // 运行服务 diff --git a/server/model/setting_model/dict_data.go b/server/model/setting_model/dict_data.go index 454f92e..2d5b5ec 100644 --- a/server/model/setting_model/dict_data.go +++ b/server/model/setting_model/dict_data.go @@ -6,6 +6,7 @@ type DictData struct { TypeId uint `gorm:"not null;default:0;comment:'类型'"` Name string `gorm:"not null;default:'';comment:'键名''"` Value string `gorm:"not null;default:'';comment:'数值'"` + Color string `gorm:"default:'';comment:'颜色'"` Remark string `gorm:"not null;default:'';comment:'备注'"` Sort uint16 `gorm:"not null;default:0;comment:'排序'"` Status uint8 `gorm:"not null;default:1;comment:'字典状态: 0=停用, 1=正常'"`