bi_approve_flow.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. package biapprove
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/controllers"
  5. "eta_gn/eta_api/models"
  6. "eta_gn/eta_api/models/bi_approve/request"
  7. "eta_gn/eta_api/models/bi_approve/response"
  8. biapprove "eta_gn/eta_api/services/bi_approve"
  9. "eta_gn/eta_api/utils"
  10. "strings"
  11. "github.com/rdlucklib/rdluck_tools/paging"
  12. )
  13. type BiApproveFlowController struct {
  14. controllers.BaseAuthController
  15. }
  16. // List
  17. // @Title 审批流列表
  18. // @Description 审批流列表
  19. // @Param PageSize query int true "每页数据条数"
  20. // @Param CurrentIndex query int true "当前页页码"
  21. // @Param ClassifyId query int false "分类ID"
  22. // @Param Keyword query string false "搜索关键词"
  23. // @Param SortRule query int false "排序方式: 1-正序; 2-倒序(默认)"
  24. // @Success 200 {object} report_approve.ReportApproveListResp
  25. // @router /flow/list [get]
  26. func (c *BiApproveFlowController) List() {
  27. br := new(models.BaseResponse).Init()
  28. defer func() {
  29. if br.ErrMsg == "" {
  30. br.IsSendEmail = false
  31. }
  32. c.Data["json"] = br
  33. c.ServeJSON()
  34. }()
  35. pageSize, _ := c.GetInt("PageSize")
  36. currentIndex, _ := c.GetInt("CurrentIndex")
  37. keyword := c.GetString("Keyword")
  38. classifyId, _ := c.GetInt("ClassifyId", 0)
  39. sortRule, _ := c.GetInt("SortRule", 2)
  40. if pageSize <= 0 {
  41. pageSize = utils.PageSize10
  42. }
  43. if currentIndex <= 0 {
  44. currentIndex = 1
  45. }
  46. var condition string
  47. var pars []interface{}
  48. if keyword != "" {
  49. condition = ` AND flow_name LIKE ?`
  50. pars = utils.GetLikeKeywordPars(pars, keyword, 1)
  51. }
  52. if classifyId > 0 {
  53. condition += ` AND classify_id = ?`
  54. pars = append(pars, classifyId)
  55. }
  56. startSize := paging.StartIndex(currentIndex, pageSize)
  57. orderMap := map[int]string{1: "ASC", 2: "DESC"}
  58. condition += " ORDER BY create_time " + orderMap[sortRule]
  59. res, total, msg, err := biapprove.GetBiApproveFlowList(condition, pars, startSize, pageSize)
  60. if err != nil {
  61. if msg != "" {
  62. br.Msg = msg
  63. } else {
  64. br.Msg = "获取审批流列表失败"
  65. }
  66. br.ErrMsg = "获取审批流列表失败, err:" + err.Error()
  67. return
  68. }
  69. page := paging.GetPaging(currentIndex, pageSize, total)
  70. resp := new(response.BiApproveFlowListResp)
  71. resp.List = res
  72. resp.Paging = page
  73. br.Data = resp
  74. br.Msg = "获取审批流列表成功"
  75. br.Success = true
  76. br.Ret = 200
  77. }
  78. // Add
  79. // @Title 新增审批流
  80. // @Description 新增审批流
  81. // @Param request body request.BiApproveFlowSaveReq true "type json string"
  82. // @Success 200
  83. // @router /flow/add [post]
  84. func (c *BiApproveFlowController) Add() {
  85. br := new(models.BaseResponse).Init()
  86. defer func() {
  87. if br.ErrMsg == "" {
  88. br.IsSendEmail = false
  89. }
  90. c.Data["json"] = br
  91. c.ServeJSON()
  92. }()
  93. var req *request.BiApproveFlowSaveReq
  94. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  95. br.Msg = "参数解析失败"
  96. br.ErrMsg = "参数解析失败, err:" + err.Error()
  97. return
  98. }
  99. req.FlowName = strings.TrimSpace(req.FlowName)
  100. if req.FlowName == "" {
  101. br.Msg = "审批流名称不能为空"
  102. return
  103. }
  104. if len([]rune(req.FlowName)) > 20 {
  105. br.Msg = "审批流名称最多输入20个字符"
  106. return
  107. }
  108. if req.ClassifyId <= 0 {
  109. br.Msg = "请选择审批分类"
  110. return
  111. }
  112. if len(req.Nodes) == 0 {
  113. br.Msg = "请添加审批流程"
  114. return
  115. }
  116. if req.BiApproveFlowId > 0 {
  117. br.Msg = "审批流已存在"
  118. return
  119. }
  120. _, msg, err := biapprove.SaveBiApproveFlow(req)
  121. if err != nil {
  122. if msg != "" {
  123. br.Msg = msg
  124. } else {
  125. br.Msg = "新增审批流失败"
  126. }
  127. br.ErrMsg = "新增审批流失败, err:" + err.Error()
  128. return
  129. }
  130. br.Msg = "新增审批流成功"
  131. br.Success = true
  132. br.Ret = 200
  133. }
  134. // edit
  135. // @Title 新增审批流
  136. // @Description 新增审批流
  137. // @Param request body request.BiApproveFlowSaveReq true "type json string"
  138. // @Success 200 {object} report_approve.ReportApproveFlowDetailItem
  139. // @router /flow/edit [post]
  140. func (c *BiApproveFlowController) Edit() {
  141. br := new(models.BaseResponse).Init()
  142. defer func() {
  143. if br.ErrMsg == "" {
  144. br.IsSendEmail = false
  145. }
  146. c.Data["json"] = br
  147. c.ServeJSON()
  148. }()
  149. var req *request.BiApproveFlowSaveReq
  150. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  151. br.Msg = "参数解析失败"
  152. br.ErrMsg = "参数解析失败, err:" + err.Error()
  153. return
  154. }
  155. req.FlowName = strings.TrimSpace(req.FlowName)
  156. if req.FlowName == "" {
  157. br.Msg = "审批流名称不能为空"
  158. return
  159. }
  160. if len([]rune(req.FlowName)) > 20 {
  161. br.Msg = "审批流名称最多输入20个字符"
  162. return
  163. }
  164. if req.ClassifyId <= 0 {
  165. br.Msg = "请选择审批分类"
  166. return
  167. }
  168. if len(req.Nodes) == 0 {
  169. br.Msg = "请添加审批流程"
  170. return
  171. }
  172. if req.BiApproveFlowId == 0 {
  173. br.Msg = "审批流不存在, 请刷新重试"
  174. return
  175. }
  176. ok, msg, err := biapprove.SaveBiApproveFlow(req)
  177. if err != nil {
  178. if msg != "" {
  179. br.Msg = msg
  180. } else {
  181. br.Msg = "编辑审批流失败"
  182. }
  183. br.ErrMsg = "编辑审批流失败, err:" + err.Error()
  184. return
  185. }
  186. if !ok {
  187. br.Msg = msg
  188. return
  189. }
  190. br.Msg = "编辑审批流成功"
  191. br.Success = true
  192. br.Ret = 200
  193. }
  194. // delete
  195. // @Title 新增审批流
  196. // @Description 新增审批流
  197. // @Param request body request.BiApproveFlowRemoveResp true "type json string"
  198. // @Success 200 {object} report_approve.ReportApproveFlowDetailItem
  199. // @router /flow/remove [post]
  200. func (c *BiApproveFlowController) Remove() {
  201. br := new(models.BaseResponse).Init()
  202. defer func() {
  203. if br.ErrMsg == "" {
  204. br.IsSendEmail = false
  205. }
  206. c.Data["json"] = br
  207. c.ServeJSON()
  208. }()
  209. var req *request.BiApproveFlowRemoveResp
  210. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  211. br.Msg = "参数解析失败"
  212. br.ErrMsg = "参数解析失败, err:" + err.Error()
  213. return
  214. }
  215. if req.BiApproveFlowId <= 0 {
  216. br.Msg = "审批流不存在, 请刷新重试"
  217. return
  218. }
  219. ok, msg, err := biapprove.DeleteBiApproveFlow(req.BiApproveFlowId)
  220. if err != nil {
  221. if msg != "" {
  222. br.Msg = msg
  223. } else {
  224. br.Msg = "删除审批流失败"
  225. }
  226. br.ErrMsg = "删除审批流失败, err:" + err.Error()
  227. return
  228. }
  229. if !ok {
  230. br.Msg = msg
  231. return
  232. }
  233. br.Msg = "删除审批流成功"
  234. br.Success = true
  235. br.Ret = 200
  236. }
  237. // Detail
  238. // @Title 审批流详情
  239. // @Description 审批流详情
  240. // @Param request body request.BiApproveFlowRemoveResp true "type json string"
  241. // @Success 200 {object} report_approve.ReportApproveFlowDetailItem
  242. // @router /flow/detail [get]
  243. func (c *BiApproveFlowController) Detail() {
  244. br := new(models.BaseResponse).Init()
  245. defer func() {
  246. if br.ErrMsg == "" {
  247. br.IsSendEmail = false
  248. }
  249. c.Data["json"] = br
  250. c.ServeJSON()
  251. }()
  252. sysUser := c.SysUser
  253. if sysUser == nil {
  254. br.Msg = "请登录"
  255. br.ErrMsg = "请登录,SysUser Is Empty"
  256. br.Ret = 408
  257. return
  258. }
  259. flowId, _ := c.GetInt("BiApproveFlowId")
  260. if flowId <= 0 {
  261. br.Msg = "审批流不存在"
  262. return
  263. }
  264. detail, msg, err := biapprove.GetBiApproveFlowDetail(flowId)
  265. if err != nil {
  266. if msg != "" {
  267. br.Msg = msg
  268. } else {
  269. br.Msg = "获取审批流详情失败"
  270. }
  271. br.ErrMsg = "获取审批流详情失败, err:" + err.Error()
  272. return
  273. }
  274. if detail == nil {
  275. br.Msg = "审批流不存在"
  276. return
  277. }
  278. br.Data = detail
  279. br.Ret = 200
  280. br.Success = true
  281. br.Msg = "获取审批流详情成功"
  282. }