You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

258 lines
8.5 KiB

  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/completeWorkflowMove [post]
  167. func CompleteWorkflowMove(c *gin.Context) {
  168. business := c.Query("businessType")
  169. wfInfo := model.WorkflowBusinessStruct[business]()
  170. c.ShouldBindJSON(wfInfo)
  171. err := service.CompleteWorkflowMove(wfInfo)
  172. if err != nil {
  173. response.FailWithMessage(err.Error(), c)
  174. return
  175. }
  176. response.OkWithMessage("启动成功", c)
  177. }
  178. // @Tags WorkflowProcess
  179. // @Summary 我发起的工作流
  180. // @Security ApiKeyAuth
  181. // @accept application/json
  182. // @Produce application/json
  183. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  184. // @Router /workflowProcess/getMyStated [get]
  185. func GetMyStated(c *gin.Context) {
  186. if claims, exists := c.Get("claims"); !exists {
  187. errStr := "从Gin的Context中获取从jwt解析出来的用户ID失败, 请检查路由是否使用jwt中间件"
  188. global.GVA_LOG.Error(errStr)
  189. response.FailWithMessage(errStr, c)
  190. } else {
  191. waitUse := claims.(*request.CustomClaims)
  192. err, wfms := service.GetMyStated(waitUse.ID)
  193. if err != nil {
  194. errStr := err.Error()
  195. global.GVA_LOG.Error(errStr)
  196. response.FailWithMessage(errStr, c)
  197. return
  198. }
  199. response.OkWithData(gin.H{"wfms": wfms}, c)
  200. }
  201. }
  202. // @Tags WorkflowProcess
  203. // @Summary 我的待办
  204. // @Security ApiKeyAuth
  205. // @accept application/json
  206. // @Produce application/json
  207. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  208. // @Router /workflowProcess/getMyNeed [get]
  209. func GetMyNeed(c *gin.Context) {
  210. if claims, exists := c.Get("claims"); !exists {
  211. errStr := "从Gin的Context中获取从jwt解析出来的用户ID失败, 请检查路由是否使用jwt中间件"
  212. global.GVA_LOG.Error(errStr)
  213. response.FailWithMessage(errStr, c)
  214. } else {
  215. waitUse := claims.(*request.CustomClaims)
  216. err, wfms := service.GetMyNeed(waitUse.ID, waitUse.AuthorityId)
  217. if err != nil {
  218. errStr := err.Error()
  219. global.GVA_LOG.Error(errStr)
  220. response.FailWithMessage(errStr, c)
  221. return
  222. }
  223. response.OkWithData(gin.H{"wfms": wfms}, c)
  224. }
  225. }
  226. // @Tags WorkflowProcess
  227. // @Summary 根据id获取当前节点详情和历史
  228. // @Security ApiKeyAuth
  229. // @accept application/json
  230. // @Produce application/json
  231. // @Param data body request.GetById true "根据id获取当前节点详情和过往"
  232. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  233. // @Router /workflowProcess/getWorkflowMoveByID [get]
  234. func GetWorkflowMoveByID(c *gin.Context) {
  235. var req request.GetById
  236. _ = c.ShouldBindQuery(&req)
  237. err, move, moves, business := service.GetWorkflowMoveByID(req.Id)
  238. if err != nil {
  239. errStr := err.Error()
  240. global.GVA_LOG.Error(errStr)
  241. response.FailWithMessage(errStr, c)
  242. return
  243. }
  244. response.OkWithData(gin.H{"move": move, "moves": moves, "business": business}, c)
  245. }