-
+
+
正常
停用
-
+
-
+
编辑
-
+
删除
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=正常'"`