bi_approve_flow.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. if sortRule == 0 {
  59. sortRule = 2
  60. }
  61. condition += " ORDER BY create_time " + orderMap[sortRule]
  62. res, total, msg, err := biapprove.GetBiApproveFlowList(condition, pars, startSize, pageSize)
  63. if err != nil {
  64. if msg != "" {
  65. br.Msg = msg
  66. } else {
  67. br.Msg = "获取审批流列表失败"
  68. }
  69. br.ErrMsg = "获取审批流列表失败, err:" + err.Error()
  70. return
  71. }
  72. page := paging.GetPaging(currentIndex, pageSize, total)
  73. resp := new(response.BiApproveFlowListResp)
  74. resp.List = res
  75. resp.Paging = page
  76. br.Data = resp
  77. br.Msg = "获取审批流列表成功"
  78. br.Success = true
  79. br.Ret = 200
  80. }
  81. // Add
  82. // @Title 新增审批流
  83. // @Description 新增审批流
  84. // @Param request body request.BiApproveFlowSaveReq true "type json string"
  85. // @Success 200
  86. // @router /flow/add [post]
  87. func (c *BiApproveFlowController) Add() {
  88. br := new(models.BaseResponse).Init()
  89. defer func() {
  90. if br.ErrMsg == "" {
  91. br.IsSendEmail = false
  92. }
  93. c.Data["json"] = br
  94. c.ServeJSON()
  95. }()
  96. var req *request.BiApproveFlowSaveReq
  97. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  98. br.Msg = "参数解析失败"
  99. br.ErrMsg = "参数解析失败, err:" + err.Error()
  100. return
  101. }
  102. req.FlowName = strings.TrimSpace(req.FlowName)
  103. if req.FlowName == "" {
  104. br.Msg = "审批流名称不能为空"
  105. return
  106. }
  107. if len([]rune(req.FlowName)) > 20 {
  108. br.Msg = "审批流名称最多输入20个字符"
  109. return
  110. }
  111. if req.ClassifyId <= 0 {
  112. br.Msg = "请选择审批分类"
  113. return
  114. }
  115. if len(req.Nodes) == 0 {
  116. br.Msg = "请添加审批流程"
  117. return
  118. }
  119. if req.BiApproveFlowId > 0 {
  120. br.Msg = "审批流已存在"
  121. return
  122. }
  123. _, msg, err := biapprove.SaveBiApproveFlow(req)
  124. if err != nil {
  125. if msg != "" {
  126. br.Msg = msg
  127. } else {
  128. br.Msg = "新增审批流失败"
  129. }
  130. br.ErrMsg = "新增审批流失败, err:" + err.Error()
  131. return
  132. }
  133. br.Msg = "新增审批流成功"
  134. br.Success = true
  135. br.Ret = 200
  136. }
  137. // edit
  138. // @Title 新增审批流
  139. // @Description 新增审批流
  140. // @Param request body request.BiApproveFlowSaveReq true "type json string"
  141. // @Success 200 {object} report_approve.ReportApproveFlowDetailItem
  142. // @router /flow/edit [post]
  143. func (c *BiApproveFlowController) Edit() {
  144. br := new(models.BaseResponse).Init()
  145. defer func() {
  146. if br.ErrMsg == "" {
  147. br.IsSendEmail = false
  148. }
  149. c.Data["json"] = br
  150. c.ServeJSON()
  151. }()
  152. var req *request.BiApproveFlowSaveReq
  153. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  154. br.Msg = "参数解析失败"
  155. br.ErrMsg = "参数解析失败, err:" + err.Error()
  156. return
  157. }
  158. req.FlowName = strings.TrimSpace(req.FlowName)
  159. if req.FlowName == "" {
  160. br.Msg = "审批流名称不能为空"
  161. return
  162. }
  163. if len([]rune(req.FlowName)) > 20 {
  164. br.Msg = "审批流名称最多输入20个字符"
  165. return
  166. }
  167. if req.ClassifyId <= 0 {
  168. br.Msg = "请选择审批分类"
  169. return
  170. }
  171. if len(req.Nodes) == 0 {
  172. br.Msg = "请添加审批流程"
  173. return
  174. }
  175. if req.BiApproveFlowId == 0 {
  176. br.Msg = "审批流不存在, 请刷新重试"
  177. return
  178. }
  179. ok, msg, err := biapprove.SaveBiApproveFlow(req)
  180. if err != nil {
  181. if msg != "" {
  182. br.Msg = msg
  183. } else {
  184. br.Msg = "编辑审批流失败"
  185. }
  186. br.ErrMsg = "编辑审批流失败, err:" + err.Error()
  187. return
  188. }
  189. if !ok {
  190. br.Msg = msg
  191. return
  192. }
  193. br.Msg = "编辑审批流成功"
  194. br.Success = true
  195. br.Ret = 200
  196. }
  197. // delete
  198. // @Title 新增审批流
  199. // @Description 新增审批流
  200. // @Param request body request.BiApproveFlowRemoveResp true "type json string"
  201. // @Success 200 {object} report_approve.ReportApproveFlowDetailItem
  202. // @router /flow/remove [post]
  203. func (c *BiApproveFlowController) Remove() {
  204. br := new(models.BaseResponse).Init()
  205. defer func() {
  206. if br.ErrMsg == "" {
  207. br.IsSendEmail = false
  208. }
  209. c.Data["json"] = br
  210. c.ServeJSON()
  211. }()
  212. var req *request.BiApproveFlowRemoveResp
  213. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  214. br.Msg = "参数解析失败"
  215. br.ErrMsg = "参数解析失败, err:" + err.Error()
  216. return
  217. }
  218. if req.BiApproveFlowId <= 0 {
  219. br.Msg = "审批流不存在, 请刷新重试"
  220. return
  221. }
  222. ok, msg, err := biapprove.DeleteBiApproveFlow(req.BiApproveFlowId)
  223. if err != nil {
  224. if msg != "" {
  225. br.Msg = msg
  226. } else {
  227. br.Msg = "删除审批流失败"
  228. }
  229. br.ErrMsg = "删除审批流失败, err:" + err.Error()
  230. return
  231. }
  232. if !ok {
  233. br.Msg = msg
  234. return
  235. }
  236. br.Msg = "删除审批流成功"
  237. br.Success = true
  238. br.Ret = 200
  239. }
  240. // Detail
  241. // @Title 审批流详情
  242. // @Description 审批流详情
  243. // @Param request body request.BiApproveFlowRemoveResp true "type json string"
  244. // @Success 200 {object} report_approve.ReportApproveFlowDetailItem
  245. // @router /flow/detail [get]
  246. func (c *BiApproveFlowController) Detail() {
  247. br := new(models.BaseResponse).Init()
  248. defer func() {
  249. if br.ErrMsg == "" {
  250. br.IsSendEmail = false
  251. }
  252. c.Data["json"] = br
  253. c.ServeJSON()
  254. }()
  255. sysUser := c.SysUser
  256. if sysUser == nil {
  257. br.Msg = "请登录"
  258. br.ErrMsg = "请登录,SysUser Is Empty"
  259. br.Ret = 408
  260. return
  261. }
  262. flowId, _ := c.GetInt("BiApproveFlowId")
  263. if flowId <= 0 {
  264. br.Msg = "审批流不存在"
  265. return
  266. }
  267. detail, msg, err := biapprove.GetBiApproveFlowDetail(flowId)
  268. if err != nil {
  269. if msg != "" {
  270. br.Msg = msg
  271. } else {
  272. br.Msg = "获取审批流详情失败"
  273. }
  274. br.ErrMsg = "获取审批流详情失败, err:" + err.Error()
  275. return
  276. }
  277. if detail == nil {
  278. br.Msg = "审批流不存在"
  279. return
  280. }
  281. br.Data = detail
  282. br.Ret = 200
  283. br.Success = true
  284. br.Msg = "获取审批流详情成功"
  285. }