data_approve.go 12 KB

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