wk_process.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. package v1
  2. import (
  3. "fmt"
  4. "gin-vue-admin/global"
  5. "gin-vue-admin/model"
  6. "gin-vue-admin/model/request"
  7. "gin-vue-admin/model/response"
  8. "gin-vue-admin/service"
  9. "github.com/gin-gonic/gin"
  10. )
  11. // @Tags WorkflowProcess
  12. // @Summary 创建WorkflowProcess
  13. // @Security ApiKeyAuth
  14. // @accept application/json
  15. // @Produce application/json
  16. // @Param data body model.WorkflowProcess true "创建WorkflowProcess"
  17. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  18. // @Router /workflowProcess/createWorkflowProcess [post]
  19. func CreateWorkflowProcess(c *gin.Context) {
  20. var workflowProcess model.WorkflowProcess
  21. _ = c.ShouldBindJSON(&workflowProcess)
  22. err := service.CreateWorkflowProcess(workflowProcess)
  23. if err != nil {
  24. response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
  25. } else {
  26. response.OkWithMessage("创建成功", c)
  27. }
  28. }
  29. // @Tags WorkflowProcess
  30. // @Summary 删除WorkflowProcess
  31. // @Security ApiKeyAuth
  32. // @accept application/json
  33. // @Produce application/json
  34. // @Param data body model.WorkflowProcess true "删除WorkflowProcess"
  35. // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
  36. // @Router /workflowProcess/deleteWorkflowProcess [delete]
  37. func DeleteWorkflowProcess(c *gin.Context) {
  38. var workflowProcess model.WorkflowProcess
  39. _ = c.ShouldBindJSON(&workflowProcess)
  40. err := service.DeleteWorkflowProcess(workflowProcess)
  41. if err != nil {
  42. response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
  43. } else {
  44. response.OkWithMessage("删除成功", c)
  45. }
  46. }
  47. // @Tags WorkflowProcess
  48. // @Summary 批量删除WorkflowProcess
  49. // @Security ApiKeyAuth
  50. // @accept application/json
  51. // @Produce application/json
  52. // @Param data body request.IdsReq true "批量删除WorkflowProcess"
  53. // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
  54. // @Router /workflowProcess/deleteWorkflowProcessByIds [delete]
  55. func DeleteWorkflowProcessByIds(c *gin.Context) {
  56. var IDS request.IdsReq
  57. _ = c.ShouldBindJSON(&IDS)
  58. err := service.DeleteWorkflowProcessByIds(IDS)
  59. if err != nil {
  60. response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
  61. } else {
  62. response.OkWithMessage("删除成功", c)
  63. }
  64. }
  65. // @Tags WorkflowProcess
  66. // @Summary 更新WorkflowProcess
  67. // @Security ApiKeyAuth
  68. // @accept application/json
  69. // @Produce application/json
  70. // @Param data body model.WorkflowProcess true "更新WorkflowProcess"
  71. // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
  72. // @Router /workflowProcess/updateWorkflowProcess [put]
  73. func UpdateWorkflowProcess(c *gin.Context) {
  74. var workflowProcess model.WorkflowProcess
  75. _ = c.ShouldBindJSON(&workflowProcess)
  76. err := service.UpdateWorkflowProcess(&workflowProcess)
  77. if err != nil {
  78. response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
  79. } else {
  80. response.OkWithMessage("更新成功", c)
  81. }
  82. }
  83. // @Tags WorkflowProcess
  84. // @Summary 用id查询WorkflowProcess
  85. // @Security ApiKeyAuth
  86. // @accept application/json
  87. // @Produce application/json
  88. // @Param data body model.WorkflowProcess true "用id查询WorkflowProcess"
  89. // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
  90. // @Router /workflowProcess/findWorkflowProcess [get]
  91. func FindWorkflowProcess(c *gin.Context) {
  92. var workflowProcess model.WorkflowProcess
  93. _ = c.ShouldBindQuery(&workflowProcess)
  94. err, reworkflowProcess := service.GetWorkflowProcess(workflowProcess.ID)
  95. if err != nil {
  96. response.FailWithMessage(fmt.Sprintf("查询失败,%v", err), c)
  97. } else {
  98. response.OkWithData(gin.H{"reworkflowProcess": reworkflowProcess}, c)
  99. }
  100. }
  101. // @Tags WorkflowProcess
  102. // @Summary 用id查询工作流步骤
  103. // @Security ApiKeyAuth
  104. // @accept application/json
  105. // @Produce application/json
  106. // @Param data body model.WorkflowProcess true "用id查询WorkflowProcess"
  107. // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
  108. // @Router /workflowProcess/findWorkflowStep [get]
  109. func FindWorkflowStep(c *gin.Context) {
  110. var workflowProcess model.WorkflowProcess
  111. _ = c.ShouldBindQuery(&workflowProcess)
  112. err, workflow := service.FindWorkflowStep(workflowProcess.ID)
  113. if err != nil {
  114. response.FailWithMessage(fmt.Sprintf("查询失败,%v", err), c)
  115. } else {
  116. response.OkWithData(gin.H{"workflow": workflow}, c)
  117. }
  118. }
  119. // @Tags WorkflowProcess
  120. // @Summary 分页获取WorkflowProcess列表
  121. // @Security ApiKeyAuth
  122. // @accept application/json
  123. // @Produce application/json
  124. // @Param data body request.WorkflowProcessSearch true "分页获取WorkflowProcess列表"
  125. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  126. // @Router /workflowProcess/getWorkflowProcessList [get]
  127. func GetWorkflowProcessList(c *gin.Context) {
  128. var pageInfo request.WorkflowProcessSearch
  129. _ = c.ShouldBindQuery(&pageInfo)
  130. err, list, total := service.GetWorkflowProcessInfoList(pageInfo)
  131. if err != nil {
  132. response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
  133. } else {
  134. response.OkWithData(response.PageResult{
  135. List: list,
  136. Total: total,
  137. Page: pageInfo.Page,
  138. PageSize: pageInfo.PageSize,
  139. }, c)
  140. }
  141. }
  142. // @Tags WorkflowProcess
  143. // @Summary 开启工作流
  144. // @Security ApiKeyAuth
  145. // @accept application/json
  146. // @Produce application/json
  147. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  148. // @Router /workflowProcess/startWorkflow [post]
  149. func StartWorkflow(c *gin.Context) {
  150. business := c.Query("businessType")
  151. wfInfo := model.WorkflowBusinessStruct[business]()
  152. c.ShouldBindJSON(wfInfo)
  153. err := service.StartWorkflow(wfInfo)
  154. if err != nil {
  155. response.FailWithMessage(err.Error(), c)
  156. return
  157. }
  158. response.OkWithMessage("启动成功", c)
  159. }
  160. // @Tags WorkflowProcess
  161. // @Summary 我发起的工作流
  162. // @Security ApiKeyAuth
  163. // @accept application/json
  164. // @Produce application/json
  165. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  166. // @Router /workflowProcess/getMyStated [get]
  167. func GetMyStated(c *gin.Context) {
  168. if claims, exists := c.Get("claims"); !exists {
  169. errStr := "从Gin的Context中获取从jwt解析出来的用户ID失败, 请检查路由是否使用jwt中间件"
  170. global.GVA_LOG.Error(errStr)
  171. response.FailWithMessage(errStr, c)
  172. } else {
  173. waitUse := claims.(*request.CustomClaims)
  174. err, wfms := service.GetMyStated(waitUse.ID)
  175. if err != nil {
  176. errStr := err.Error()
  177. global.GVA_LOG.Error(errStr)
  178. response.FailWithMessage(errStr, c)
  179. return
  180. }
  181. response.OkWithData(gin.H{"wfms": wfms}, c)
  182. }
  183. }
  184. // @Tags WorkflowProcess
  185. // @Summary 我的待办
  186. // @Security ApiKeyAuth
  187. // @accept application/json
  188. // @Produce application/json
  189. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  190. // @Router /workflowProcess/getMyNeed [get]
  191. func GetMyNeed(c *gin.Context) {
  192. if claims, exists := c.Get("claims"); !exists {
  193. errStr := "从Gin的Context中获取从jwt解析出来的用户ID失败, 请检查路由是否使用jwt中间件"
  194. global.GVA_LOG.Error(errStr)
  195. response.FailWithMessage(errStr, c)
  196. } else {
  197. waitUse := claims.(*request.CustomClaims)
  198. err, wfms := service.GetMyNeed(waitUse.ID, waitUse.AuthorityId)
  199. if err != nil {
  200. errStr := err.Error()
  201. global.GVA_LOG.Error(errStr)
  202. response.FailWithMessage(errStr, c)
  203. return
  204. }
  205. response.OkWithData(gin.H{"wfms": wfms}, c)
  206. }
  207. }
  208. // @Tags WorkflowProcess
  209. // @Summary 根据id获取当前节点详情和历史
  210. // @Security ApiKeyAuth
  211. // @accept application/json
  212. // @Produce application/json
  213. // @Param data body request.GetById true "根据id获取当前节点详情和过往"
  214. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  215. // @Router /workflowProcess/getWorkflowMoveByID [get]
  216. func GetWorkflowMoveByID(c *gin.Context) {
  217. var req request.GetById
  218. _ = c.ShouldBindQuery(&req)
  219. err, move, moves, business := service.GetWorkflowMoveByID(req.Id)
  220. if err != nil {
  221. errStr := err.Error()
  222. global.GVA_LOG.Error(errStr)
  223. response.FailWithMessage(errStr, c)
  224. return
  225. }
  226. response.OkWithData(gin.H{"move": move, "moves": moves, "business": business}, c)
  227. }