bi_approve.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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. "fmt"
  11. "github.com/rdlucklib/rdluck_tools/paging"
  12. )
  13. type BiApproveController 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 ListType query int true "列表类型:1-待处理;2-已处理;3-我发起的"
  22. // @Param ClassifyId query int false "分类ID"
  23. // @Param Keyword query string false "搜索关键词"
  24. // @Param ApproveState query int false "审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"
  25. // @Param TimeType query int false "时间类型:1-提交时间;2-处理时间;3-审批时间"
  26. // @Param StartTime query string false "开始时间"
  27. // @Param EndTime query string false "结束时间"
  28. // @Param SortField query int false "排序字段:1-提交时间;2-处理时间;3-审批时间"
  29. // @Param SortRule query int false "排序方式: 1-正序; 2-倒序(默认)"
  30. // @Success 200 {object} report_approve.BiApproveListResp
  31. // @router /list [get]
  32. func (this *BiApproveController) List() {
  33. br := new(models.BaseResponse).Init()
  34. defer func() {
  35. if br.ErrMsg == "" {
  36. br.IsSendEmail = false
  37. }
  38. this.Data["json"] = br
  39. this.ServeJSON()
  40. }()
  41. sysUser := this.SysUser
  42. pageSize, _ := this.GetInt("PageSize")
  43. currentIndex, _ := this.GetInt("CurrentIndex")
  44. listType, _ := this.GetInt("ListType")
  45. approveState, _ := this.GetInt("ApproveState")
  46. timeType, _ := this.GetInt("TimeType")
  47. startTime := this.GetString("StartTime")
  48. endTime := this.GetString("EndTime")
  49. sortField, _ := this.GetInt("SortField")
  50. sortRule, _ := this.GetInt("SortRule")
  51. classifyId, _ := this.GetInt("ClassifyId")
  52. keyword := this.GetString("Keyword")
  53. if pageSize <= 0 {
  54. pageSize = utils.PageSize10
  55. }
  56. if currentIndex <= 0 {
  57. currentIndex = 1
  58. }
  59. startSize := paging.StartIndex(currentIndex, pageSize)
  60. var list []*response.BiApproveItemOrmResp
  61. var total int
  62. var msg string
  63. var err error
  64. classifyList, msg, err := biapprove.GetBiClassifyAll()
  65. if err != nil {
  66. if msg != "" {
  67. br.Msg = msg
  68. } else {
  69. br.Msg = "获取审批列表成功"
  70. }
  71. br.ErrMsg = "获取分类列表失败, Err: " + err.Error()
  72. return
  73. }
  74. classifyMap := make(map[int]string)
  75. for _, v := range classifyList {
  76. classifyMap[v.BiDashboardClassifyId] = v.BiDashboardClassifyName
  77. }
  78. switch listType {
  79. case 1:
  80. list, total, msg, err = biapprove.ProcessingBiApprove(sysUser.AdminId, classifyId, timeType, sortField, sortRule, startSize, pageSize, sysUser.RealName, startTime, endTime, keyword)
  81. case 2:
  82. list, total, msg, err = biapprove.SolvedBiApprove(sysUser.AdminId, classifyId, timeType, sortField, sortRule, approveState, startSize, pageSize, sysUser.RealName, startTime, endTime, keyword)
  83. case 3:
  84. list, total, msg, err = biapprove.MyApplyBiApproves(sysUser.AdminId, classifyId, timeType, sortField, sortRule, approveState, startSize, pageSize, sysUser.RealName, startTime, endTime, keyword)
  85. default:
  86. br.Msg = "列表类型错误"
  87. return
  88. }
  89. if err != nil {
  90. if msg != "" {
  91. br.Msg = msg
  92. } else {
  93. br.Msg = "获取审批列表失败"
  94. }
  95. br.ErrMsg = "获取审批列表失败, Err: " + err.Error()
  96. return
  97. }
  98. for _, v := range list {
  99. v.ClassifyName = classifyMap[v.ClassifyId]
  100. }
  101. resp := new(response.BiApproveListResp)
  102. page := paging.GetPaging(currentIndex, pageSize, total)
  103. resp.List = list
  104. resp.Paging = page
  105. br.Msg = "获取审批列表成功"
  106. br.Data = resp
  107. br.Ret = 200
  108. br.Success = true
  109. }
  110. // list
  111. // @Title 公共看板分类列表
  112. // @Description 公共看板分类列表
  113. // @Success 200 {object} report_approve.BiApproveFlowDetailItem
  114. // @router /classify/list [get]
  115. func (this *BiApproveController) ClassifyList() {
  116. br := new(models.BaseResponse).Init()
  117. defer func() {
  118. if br.ErrMsg == "" {
  119. br.IsSendEmail = false
  120. }
  121. this.Data["json"] = br
  122. this.ServeJSON()
  123. }()
  124. res, msg, err := biapprove.GetPulicBiClassifyList()
  125. if err != nil {
  126. if msg == "" {
  127. br.Msg = "获取分类列表失败"
  128. } else {
  129. br.Msg = msg
  130. }
  131. br.ErrMsg = err.Error()
  132. return
  133. }
  134. br.Data = res
  135. br.Msg = "获取分类列表成功"
  136. br.Ret = 200
  137. br.Success = true
  138. }
  139. // Approve
  140. // @Title 通过审批
  141. // @Description 通过审批
  142. // @Param request body report_approve.BiApprovePassReq true "type json string"
  143. // @Success 200 string "操作成功"
  144. // @router /approve [post]
  145. func (this *BiApproveController) Approve() {
  146. br := new(models.BaseResponse).Init()
  147. defer func() {
  148. if br.ErrMsg == "" {
  149. br.IsSendEmail = false
  150. }
  151. this.Data["json"] = br
  152. this.ServeJSON()
  153. }()
  154. sysUser := this.SysUser
  155. if sysUser == nil {
  156. br.Msg = "请登录"
  157. br.ErrMsg = "请登录,SysUser Is Empty"
  158. br.Ret = 408
  159. return
  160. }
  161. var req request.BiApprovePassReq
  162. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  163. br.Msg = "参数有误"
  164. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  165. return
  166. }
  167. if req.BiApproveId <= 0 {
  168. br.Msg = "参数有误"
  169. br.ErrMsg = fmt.Sprintf("参数有误, BiApproveId: %d", req.BiApproveId)
  170. return
  171. }
  172. // 通过审批
  173. msg, err := biapprove.PassBiApprove(req.BiApproveId, sysUser.AdminId)
  174. if err != nil {
  175. if msg != "" {
  176. br.Msg = msg
  177. } else {
  178. br.Msg = "操作失败"
  179. }
  180. br.ErrMsg = "通过审批失败, Err: " + err.Error()
  181. return
  182. }
  183. br.Ret = 200
  184. br.Success = true
  185. br.Msg = "操作成功"
  186. }
  187. // Detail
  188. // @Title 审批详情
  189. // @Description 审批详情
  190. // @Param BiApproveId query int true "审批ID"
  191. // @Success 200 {object} report_approve.BiApproveDetail
  192. // @router /detail [get]
  193. func (this *BiApproveController) Detail() {
  194. br := new(models.BaseResponse).Init()
  195. defer func() {
  196. if br.ErrMsg == "" {
  197. br.IsSendEmail = false
  198. }
  199. this.Data["json"] = br
  200. this.ServeJSON()
  201. }()
  202. sysUser := this.SysUser
  203. if sysUser == nil {
  204. br.Msg = "请登录"
  205. br.ErrMsg = "请登录,SysUser Is Empty"
  206. br.Ret = 408
  207. return
  208. }
  209. approveId, _ := this.GetInt("BiApproveId")
  210. if approveId <= 0 {
  211. br.Msg = "参数有误"
  212. br.ErrMsg = fmt.Sprintf("参数有误, BiApproveId: %d", approveId)
  213. return
  214. }
  215. resp, msg, err := biapprove.GetApproveDetail(approveId)
  216. if err != nil {
  217. if msg != "" {
  218. br.Msg = msg
  219. } else {
  220. br.Msg = "获取审批详情失败"
  221. }
  222. br.ErrMsg = "获取审批详情失败, Err: " + err.Error()
  223. return
  224. }
  225. br.Data = resp
  226. br.Ret = 200
  227. br.Success = true
  228. br.Msg = "获取成功"
  229. }
  230. // Refuse
  231. // @Title 驳回审批
  232. // @Description 驳回审批
  233. // @Param request body request.BiApproveRefuseReq true "type json string"
  234. // @Success 200 string "操作成功"
  235. // @router /refuse [post]
  236. func (this *BiApproveController) Refuse() {
  237. br := new(models.BaseResponse).Init()
  238. defer func() {
  239. if br.ErrMsg == "" {
  240. br.IsSendEmail = false
  241. }
  242. this.Data["json"] = br
  243. this.ServeJSON()
  244. }()
  245. sysUser := this.SysUser
  246. if sysUser == nil {
  247. br.Msg = "请登录"
  248. br.ErrMsg = "请登录,SysUser Is Empty"
  249. br.Ret = 408
  250. return
  251. }
  252. var req request.BiApproveRefuseReq
  253. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  254. br.Msg = "参数有误"
  255. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  256. return
  257. }
  258. if req.BiApproveId <= 0 {
  259. br.Msg = "参数有误"
  260. br.ErrMsg = fmt.Sprintf("参数有误, BiApproveId: %d", req.BiApproveId)
  261. return
  262. }
  263. maxStrLen := 500
  264. approvelen := len([]rune(req.ApproveRemark))
  265. if approvelen > maxStrLen {
  266. br.Msg = fmt.Sprintf("审批驳回原因不能超过%d字", maxStrLen)
  267. return
  268. }
  269. msg, err := biapprove.BiApproveRefuse(req.BiApproveId, sysUser.AdminId, req.ApproveRemark)
  270. if err != nil {
  271. if msg != "" {
  272. br.Msg = msg
  273. } else {
  274. br.Msg = "操作失败"
  275. }
  276. br.ErrMsg = "驳回审批失败, Err: " + err.Error()
  277. return
  278. }
  279. br.Ret = 200
  280. br.Success = true
  281. br.Msg = "操作成功"
  282. }
  283. // Cancel
  284. // @Title 撤销审批
  285. // @Description 撤销审批
  286. // @Param request body report_approve.BiApproveCancelReq true "type json string"
  287. // @Success 200 string "操作成功"
  288. // @router /cancel [post]
  289. func (this *BiApproveController) Cancel() {
  290. br := new(models.BaseResponse).Init()
  291. defer func() {
  292. if br.ErrMsg == "" {
  293. br.IsSendEmail = false
  294. }
  295. this.Data["json"] = br
  296. this.ServeJSON()
  297. }()
  298. sysUser := this.SysUser
  299. if sysUser == nil {
  300. br.Msg = "请登录"
  301. br.ErrMsg = "请登录,SysUser Is Empty"
  302. br.Ret = 408
  303. return
  304. }
  305. var req request.BiApproveCancelReq
  306. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  307. br.Msg = "参数有误"
  308. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  309. return
  310. }
  311. if req.BiApproveId <= 0 {
  312. br.Msg = "参数有误"
  313. br.ErrMsg = fmt.Sprintf("参数有误, BiApproveId: %d", req.BiApproveId)
  314. return
  315. }
  316. // 撤销审批
  317. msg, e := biapprove.BiApproveCancel(req.BiApproveId, sysUser.AdminId, sysUser.RealName)
  318. if e != nil {
  319. if msg != "" {
  320. br.Msg = msg
  321. } else {
  322. br.Msg = "操作失败"
  323. }
  324. br.ErrMsg = "撤销审批失败, Err: " + e.Error()
  325. return
  326. }
  327. br.Ret = 200
  328. br.Success = true
  329. br.Msg = "操作成功"
  330. }
  331. // MessageList
  332. // @Title 审批消息列表
  333. // @Description 审批消息列表
  334. // @Param PageSize query int true "每页数据条数"
  335. // @Param CurrentIndex query int true "当前页页码"
  336. // @Success 200 {object} report_approve.BiApproveMessageListResp
  337. // @router /message/list [get]
  338. func (this *BiApproveController) MessageList() {
  339. br := new(models.BaseResponse).Init()
  340. defer func() {
  341. if br.ErrMsg == "" {
  342. br.IsSendEmail = false
  343. }
  344. this.Data["json"] = br
  345. this.ServeJSON()
  346. }()
  347. sysUser := this.SysUser
  348. if sysUser == nil {
  349. br.Msg = "请登录"
  350. br.ErrMsg = "请登录,SysUser Is Empty"
  351. br.Ret = 408
  352. return
  353. }
  354. currentIndex, _ := this.GetInt("currentIndex")
  355. pageSize, _ := this.GetInt("pageSize")
  356. // 分页
  357. var startSize int
  358. if pageSize <= 0 {
  359. pageSize = utils.PageSize20
  360. }
  361. if currentIndex <= 0 {
  362. currentIndex = 1
  363. }
  364. startSize = utils.StartIndex(currentIndex, pageSize)
  365. resp := new(response.BiApproveMessageListResp)
  366. resp.List = make([]*response.BiApproveMessageItem, 0)
  367. list, total, unRead, msg, err := biapprove.GetBiApproveMessage(sysUser.AdminId, startSize, pageSize)
  368. if err != nil {
  369. if msg != "" {
  370. br.Msg = msg
  371. } else {
  372. br.Msg = "获取审批消息失败"
  373. }
  374. br.ErrMsg = "获取审批消息失败, Err: " + err.Error()
  375. return
  376. }
  377. resp.List = list
  378. resp.UnreadTotal = unRead
  379. page := paging.GetPaging(currentIndex, pageSize, total)
  380. resp.Paging = page
  381. br.Data = resp
  382. br.Ret = 200
  383. br.Success = true
  384. br.Msg = "获取成功"
  385. }
  386. // MessageRead
  387. // @Title 消息已读
  388. // @Description 消息已读
  389. // @Param request body report_approve.BiApproveMessageReadReq true "type json string"
  390. // @Success 200 string "操作成功"
  391. // @router /message/read [post]
  392. func (this *BiApproveController) MessageRead() {
  393. br := new(models.BaseResponse).Init()
  394. defer func() {
  395. if br.ErrMsg == "" {
  396. br.IsSendEmail = false
  397. }
  398. this.Data["json"] = br
  399. this.ServeJSON()
  400. }()
  401. sysUser := this.SysUser
  402. if sysUser == nil {
  403. br.Msg = "请登录"
  404. br.ErrMsg = "请登录,SysUser Is Empty"
  405. br.Ret = 408
  406. return
  407. }
  408. var req request.BiApproveMessageReadReq
  409. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  410. br.Msg = "参数有误"
  411. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  412. return
  413. }
  414. if req.MessageId <= 0 {
  415. br.Msg = "参数有误"
  416. br.ErrMsg = fmt.Sprintf("参数有误, MessageId: %d", req.MessageId)
  417. return
  418. }
  419. msg, err := biapprove.ReadBiMessage(req.MessageId, sysUser.AdminId)
  420. if err != nil {
  421. if msg != "" {
  422. br.Msg = msg
  423. } else {
  424. br.Msg = "操作失败"
  425. }
  426. br.ErrMsg = "消息已读失败, Err: " + err.Error()
  427. return
  428. }
  429. br.Ret = 200
  430. br.Success = true
  431. br.Msg = "操作成功"
  432. }
  433. // CheckApproveOpen
  434. // @Title 校验分类是否开启审批
  435. // @Description 校验分类是否开启审批
  436. // @Param request body report_approve.BiApproveCheckApproveOpenReq true "type json string"
  437. // @Success 200 string "操作成功"
  438. // @router /classify/check_open [post]
  439. func (this *BiApproveController) CheckApproveOpen() {
  440. br := new(models.BaseResponse).Init()
  441. defer func() {
  442. if br.ErrMsg == "" {
  443. br.IsSendEmail = false
  444. }
  445. this.Data["json"] = br
  446. this.ServeJSON()
  447. }()
  448. sysUser := this.SysUser
  449. if sysUser == nil {
  450. br.Msg = "请登录"
  451. br.ErrMsg = "请登录,SysUser Is Empty"
  452. br.Ret = 408
  453. return
  454. }
  455. var req request.BiApproveCheckApproveOpenReq
  456. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  457. br.Msg = "参数有误"
  458. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  459. return
  460. }
  461. // 校验是否开启了审批流
  462. opening, e := biapprove.CheckBiOpenApprove(req.ClassifyId)
  463. if e != nil {
  464. br.Msg = "操作失败"
  465. br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
  466. return
  467. }
  468. br.Data = opening
  469. br.Ret = 200
  470. br.Success = true
  471. br.Msg = "操作成功"
  472. }