knowledge_approve.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. package knowledge_approve
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/controllers"
  5. "eta_gn/eta_api/models"
  6. "eta_gn/eta_api/models/knowledge"
  7. "eta_gn/eta_api/models/knowledge_approve/request"
  8. "eta_gn/eta_api/models/knowledge_approve/response"
  9. "eta_gn/eta_api/services/knowledge_approve"
  10. "eta_gn/eta_api/utils"
  11. "fmt"
  12. "github.com/rdlucklib/rdluck_tools/paging"
  13. )
  14. type KnowledgeApproveController struct {
  15. controllers.BaseAuthController
  16. }
  17. // List
  18. // @Title 审批列表
  19. // @Description 审批列表
  20. // @Param PageSize query int true "每页数据条数"
  21. // @Param CurrentIndex query int true "当前页页码"
  22. // @Param ListType query int true "列表类型:1-待处理;2-已处理;3-我发起的"
  23. // @Param ClassifyId query int false "分类ID"
  24. // @Param Keyword query string false "搜索关键词"
  25. // @Param ApproveState query int false "审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"
  26. // @Param TimeType query int false "时间类型:1-提交时间;2-处理时间;3-审批时间"
  27. // @Param StartTime query string false "开始时间"
  28. // @Param EndTime query string false "结束时间"
  29. // @Param SortField query int false "排序字段:1-提交时间;2-处理时间;3-审批时间"
  30. // @Param SortRule query int false "排序方式: 1-正序; 2-倒序(默认)"
  31. // @Success 200 {object} report_approve.KnowledgeResourceApproveListResp
  32. // @router /list [get]
  33. func (this *KnowledgeApproveController) List() {
  34. br := new(models.BaseResponse).Init()
  35. defer func() {
  36. if br.ErrMsg == "" {
  37. br.IsSendEmail = false
  38. }
  39. this.Data["json"] = br
  40. this.ServeJSON()
  41. }()
  42. sysUser := this.SysUser
  43. pageSize, _ := this.GetInt("PageSize")
  44. currentIndex, _ := this.GetInt("CurrentIndex")
  45. listType, _ := this.GetInt("ListType")
  46. approveState, _ := this.GetInt("ApproveState")
  47. timeType, _ := this.GetInt("TimeType")
  48. startTime := this.GetString("StartTime")
  49. endTime := this.GetString("EndTime")
  50. sortField, _ := this.GetInt("SortField")
  51. sortRule, _ := this.GetInt("SortRule")
  52. classifyId, _ := this.GetInt("ClassifyId")
  53. keyword := this.GetString("Keyword")
  54. if pageSize <= 0 {
  55. pageSize = utils.PageSize10
  56. }
  57. if currentIndex <= 0 {
  58. currentIndex = 1
  59. }
  60. startSize := paging.StartIndex(currentIndex, pageSize)
  61. var list []*response.KnowledgeResourceApproveItemOrmResp
  62. var total int
  63. var msg string
  64. var err error
  65. classifyList, msg, err := knowledge_approve.GetKnowledgeClassifyAll()
  66. if err != nil {
  67. if msg != "" {
  68. br.Msg = msg
  69. } else {
  70. br.Msg = "获取审批列表成功"
  71. }
  72. br.ErrMsg = "获取分类列表失败, Err: " + err.Error()
  73. return
  74. }
  75. classifyMap := make(map[int]string)
  76. for _, v := range classifyList {
  77. classifyMap[v.ClassifyId] = v.ClassifyName
  78. }
  79. switch listType {
  80. case 1:
  81. list, total, msg, err = knowledge_approve.ProcessingKnowledgeResourceApprove(sysUser.AdminId, classifyId, timeType, sortField, sortRule, startSize, pageSize, sysUser.RealName, startTime, endTime, keyword)
  82. case 2:
  83. list, total, msg, err = knowledge_approve.SolvedKnowledgeResourceApprove(sysUser.AdminId, classifyId, timeType, sortField, sortRule, approveState, startSize, pageSize, sysUser.RealName, startTime, endTime, keyword)
  84. case 3:
  85. list, total, msg, err = knowledge_approve.MyApplyKnowledgeResourceApproves(sysUser.AdminId, classifyId, timeType, sortField, sortRule, approveState, startSize, pageSize, sysUser.RealName, startTime, endTime, keyword)
  86. default:
  87. br.Msg = "列表类型错误"
  88. return
  89. }
  90. if err != nil {
  91. if msg != "" {
  92. br.Msg = msg
  93. } else {
  94. br.Msg = "获取审批列表失败"
  95. }
  96. br.ErrMsg = "获取审批列表失败, Err: " + err.Error()
  97. return
  98. }
  99. for _, v := range list {
  100. v.ClassifyName = classifyMap[v.ClassifyId]
  101. }
  102. resp := new(response.KnowledgeResourceApproveListResp)
  103. page := paging.GetPaging(currentIndex, pageSize, total)
  104. resp.List = list
  105. resp.Paging = page
  106. br.Msg = "获取审批列表成功"
  107. br.Data = resp
  108. br.Ret = 200
  109. br.Success = true
  110. }
  111. // list
  112. // @Title 公共知识资源分类列表
  113. // @Description 公共知识资源分类列表
  114. // @Success 200 {object} []*knowledge.KnowledgeClassifyItem
  115. // @router /classify/list [get]
  116. func (this *KnowledgeApproveController) ClassifyList() {
  117. br := new(models.BaseResponse).Init()
  118. defer func() {
  119. if br.ErrMsg == "" {
  120. br.IsSendEmail = false
  121. }
  122. this.Data["json"] = br
  123. this.ServeJSON()
  124. }()
  125. res, msg, err := knowledge_approve.GetPulicKnowledgeClassifyList(knowledge.KnowledgeResourceTypeOpinion)
  126. if err != nil {
  127. if msg == "" {
  128. br.Msg = "获取分类列表失败"
  129. } else {
  130. br.Msg = msg
  131. }
  132. br.ErrMsg = err.Error()
  133. return
  134. }
  135. br.Data = res
  136. br.Msg = "获取分类列表成功"
  137. br.Ret = 200
  138. br.Success = true
  139. }
  140. // Approve
  141. // @Title 通过审批
  142. // @Description 通过审批
  143. // @Param request body request.KnowledgeResourceApprovePassReq true "type json string"
  144. // @Success 200 string "操作成功"
  145. // @router /approve [post]
  146. func (this *KnowledgeApproveController) Approve() {
  147. br := new(models.BaseResponse).Init()
  148. defer func() {
  149. if br.ErrMsg == "" {
  150. br.IsSendEmail = false
  151. }
  152. this.Data["json"] = br
  153. this.ServeJSON()
  154. }()
  155. sysUser := this.SysUser
  156. if sysUser == nil {
  157. br.Msg = "请登录"
  158. br.ErrMsg = "请登录,SysUser Is Empty"
  159. br.Ret = 408
  160. return
  161. }
  162. var req request.KnowledgeResourceApprovePassReq
  163. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  164. br.Msg = "参数有误"
  165. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  166. return
  167. }
  168. if req.KnowledgeResourceApproveId <= 0 {
  169. br.Msg = "参数有误"
  170. br.ErrMsg = fmt.Sprintf("参数有误, KnowledgeResourceApproveId: %d", req.KnowledgeResourceApproveId)
  171. return
  172. }
  173. // 通过审批
  174. msg, err := knowledge_approve.PassKnowledgeResourceApprove(req.KnowledgeResourceApproveId, sysUser.AdminId)
  175. if err != nil {
  176. if msg != "" {
  177. br.Msg = msg
  178. } else {
  179. br.Msg = "操作失败"
  180. }
  181. br.ErrMsg = "通过审批失败, Err: " + err.Error()
  182. return
  183. }
  184. br.Ret = 200
  185. br.Success = true
  186. br.Msg = "操作成功"
  187. }
  188. // Detail
  189. // @Title 审批详情
  190. // @Description 审批详情
  191. // @Param KnowledgeResourceApproveId query int true "审批ID"
  192. // @Success 200 {object} report_approve.KnowledgeResourceApproveDetail
  193. // @router /detail [get]
  194. func (this *KnowledgeApproveController) Detail() {
  195. br := new(models.BaseResponse).Init()
  196. defer func() {
  197. if br.ErrMsg == "" {
  198. br.IsSendEmail = false
  199. }
  200. this.Data["json"] = br
  201. this.ServeJSON()
  202. }()
  203. sysUser := this.SysUser
  204. if sysUser == nil {
  205. br.Msg = "请登录"
  206. br.ErrMsg = "请登录,SysUser Is Empty"
  207. br.Ret = 408
  208. return
  209. }
  210. approveId, _ := this.GetInt("KnowledgeResourceApproveId")
  211. if approveId <= 0 {
  212. br.Msg = "参数有误"
  213. br.ErrMsg = fmt.Sprintf("参数有误, KnowledgeResourceApproveId: %d", approveId)
  214. return
  215. }
  216. resp, msg, err := knowledge_approve.GetApproveDetail(approveId)
  217. if err != nil {
  218. if msg != "" {
  219. br.Msg = msg
  220. } else {
  221. br.Msg = "获取审批详情失败"
  222. }
  223. br.ErrMsg = "获取审批详情失败, Err: " + err.Error()
  224. return
  225. }
  226. br.Data = resp
  227. br.Ret = 200
  228. br.Success = true
  229. br.Msg = "获取成功"
  230. }
  231. // Refuse
  232. // @Title 驳回审批
  233. // @Description 驳回审批
  234. // @Param request body request.KnowledgeResourceApproveRefuseReq true "type json string"
  235. // @Success 200 string "操作成功"
  236. // @router /refuse [post]
  237. func (this *KnowledgeApproveController) Refuse() {
  238. br := new(models.BaseResponse).Init()
  239. defer func() {
  240. if br.ErrMsg == "" {
  241. br.IsSendEmail = false
  242. }
  243. this.Data["json"] = br
  244. this.ServeJSON()
  245. }()
  246. sysUser := this.SysUser
  247. if sysUser == nil {
  248. br.Msg = "请登录"
  249. br.ErrMsg = "请登录,SysUser Is Empty"
  250. br.Ret = 408
  251. return
  252. }
  253. var req request.KnowledgeResourceApproveRefuseReq
  254. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  255. br.Msg = "参数有误"
  256. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  257. return
  258. }
  259. if req.KnowledgeResourceApproveId <= 0 {
  260. br.Msg = "参数有误"
  261. br.ErrMsg = fmt.Sprintf("参数有误, KnowledgeResourceApproveId: %d", req.KnowledgeResourceApproveId)
  262. return
  263. }
  264. maxStrLen := 500
  265. approvelen := len([]rune(req.ApproveRemark))
  266. if approvelen > maxStrLen {
  267. br.Msg = fmt.Sprintf("审批驳回原因不能超过%d字", maxStrLen)
  268. return
  269. }
  270. msg, err := knowledge_approve.KnowledgeResourceApproveRefuse(req.KnowledgeResourceApproveId, sysUser.AdminId, req.ApproveRemark)
  271. if err != nil {
  272. if msg != "" {
  273. br.Msg = msg
  274. } else {
  275. br.Msg = "操作失败"
  276. }
  277. br.ErrMsg = "驳回审批失败, Err: " + err.Error()
  278. return
  279. }
  280. br.Ret = 200
  281. br.Success = true
  282. br.Msg = "操作成功"
  283. }
  284. // Cancel
  285. // @Title 撤销审批
  286. // @Description 撤销审批
  287. // @Param request body report_approve.KnowledgeResourceApproveCancelReq true "type json string"
  288. // @Success 200 string "操作成功"
  289. // @router /cancel [post]
  290. func (this *KnowledgeApproveController) Cancel() {
  291. br := new(models.BaseResponse).Init()
  292. defer func() {
  293. if br.ErrMsg == "" {
  294. br.IsSendEmail = false
  295. }
  296. this.Data["json"] = br
  297. this.ServeJSON()
  298. }()
  299. sysUser := this.SysUser
  300. if sysUser == nil {
  301. br.Msg = "请登录"
  302. br.ErrMsg = "请登录,SysUser Is Empty"
  303. br.Ret = 408
  304. return
  305. }
  306. var req request.KnowledgeResourceApproveCancelReq
  307. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  308. br.Msg = "参数有误"
  309. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  310. return
  311. }
  312. if req.KnowledgeResourceApproveId <= 0 {
  313. br.Msg = "参数有误"
  314. br.ErrMsg = fmt.Sprintf("参数有误, KnowledgeResourceApproveId: %d", req.KnowledgeResourceApproveId)
  315. return
  316. }
  317. // 撤销审批
  318. msg, e := knowledge_approve.KnowledgeResourceApproveCancel(req.KnowledgeResourceApproveId, sysUser.AdminId, sysUser.RealName)
  319. if e != nil {
  320. if msg != "" {
  321. br.Msg = msg
  322. } else {
  323. br.Msg = "操作失败"
  324. }
  325. br.ErrMsg = "撤销审批失败, Err: " + e.Error()
  326. return
  327. }
  328. br.Ret = 200
  329. br.Success = true
  330. br.Msg = "操作成功"
  331. }
  332. // MessageList
  333. // @Title 审批消息列表
  334. // @Description 审批消息列表
  335. // @Param PageSize query int true "每页数据条数"
  336. // @Param CurrentIndex query int true "当前页页码"
  337. // @Success 200 {object} report_approve.KnowledgeResourceApproveMessageListResp
  338. // @router /message/list [get]
  339. func (this *KnowledgeApproveController) MessageList() {
  340. br := new(models.BaseResponse).Init()
  341. defer func() {
  342. if br.ErrMsg == "" {
  343. br.IsSendEmail = false
  344. }
  345. this.Data["json"] = br
  346. this.ServeJSON()
  347. }()
  348. sysUser := this.SysUser
  349. if sysUser == nil {
  350. br.Msg = "请登录"
  351. br.ErrMsg = "请登录,SysUser Is Empty"
  352. br.Ret = 408
  353. return
  354. }
  355. currentIndex, _ := this.GetInt("CurrentIndex")
  356. pageSize, _ := this.GetInt("PageSize")
  357. // 分页
  358. var startSize int
  359. if pageSize <= 0 {
  360. pageSize = utils.PageSize20
  361. }
  362. if currentIndex <= 0 {
  363. currentIndex = 1
  364. }
  365. startSize = utils.StartIndex(currentIndex, pageSize)
  366. resp := new(response.KnowledgeResourceApproveMessageListResp)
  367. list, total, unRead, msg, err := knowledge_approve.GetKnowledgeResourceApproveMessage(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.KnowledgeResourceApproveMessageReadReq true "type json string"
  390. // @Success 200 string "操作成功"
  391. // @router /message/read [post]
  392. func (this *KnowledgeApproveController) 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.KnowledgeResourceApproveMessageReadReq
  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 := knowledge_approve.ReadKnowledgeMessage(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.KnowledgeResourceApproveCheckApproveOpenReq true "type json string"
  437. // @Success 200 string "操作成功"
  438. // @router /classify/check_open [post]
  439. func (this *KnowledgeApproveController) 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.KnowledgeResourceApproveCheckApproveOpenReq
  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 := knowledge_approve.CheckKnowledgeOpenApprove(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. }