report_approve.go 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  1. package report_approve
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/report_approve"
  7. "eta/eta_api/services"
  8. "eta/eta_api/utils"
  9. "fmt"
  10. "sort"
  11. "strconv"
  12. "strings"
  13. "time"
  14. "github.com/rdlucklib/rdluck_tools/paging"
  15. )
  16. // ReportApproveController 报告审批
  17. type ReportApproveController struct {
  18. controllers.BaseAuthController
  19. }
  20. // List
  21. // @Title 审批列表
  22. // @Description 审批列表
  23. // @Param PageSize query int true "每页数据条数"
  24. // @Param CurrentIndex query int true "当前页页码"
  25. // @Param ListType query int true "列表类型:1-待处理;2-已处理;3-我发起的"
  26. // @Param ReportType query int false "报告类型:1-中文研报;2-英文研报;3-智能研报"
  27. // @Param ClassifyIdFirst query int false "一级分类ID"
  28. // @Param ClassifyIdSecond query int false "二级分类ID"
  29. // @Param ClassifyIdThird query int false "三级级分类ID"
  30. // @Param Keyword query string false "搜索关键词"
  31. // @Param ApproveState query int false "审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"
  32. // @Param TimeType query int false "时间类型:1-提交时间;2-处理时间;3-审批时间"
  33. // @Param StartTime query string false "开始时间"
  34. // @Param EndTime query string false "结束时间"
  35. // @Param SortField query int false "排序字段:1-提交时间;2-处理时间;3-审批时间"
  36. // @Param SortRule query int false "排序方式: 1-正序; 2-倒序(默认)"
  37. // @Success 200 {object} report_approve.ReportApproveListResp
  38. // @router /list [get]
  39. func (this *ReportApproveController) List() {
  40. br := new(models.BaseResponse).Init()
  41. defer func() {
  42. if br.ErrMsg == "" {
  43. br.IsSendEmail = false
  44. }
  45. this.Data["json"] = br
  46. this.ServeJSON()
  47. }()
  48. sysUser := this.SysUser
  49. if sysUser == nil {
  50. br.Msg = "请登录"
  51. br.ErrMsg = "请登录,SysUser Is Empty"
  52. br.Ret = 408
  53. return
  54. }
  55. params := new(report_approve.ReportApproveListReq)
  56. if e := this.ParseForm(params); e != nil {
  57. br.Msg = "获取失败"
  58. br.ErrMsg = "入参解析失败, Err: " + e.Error()
  59. return
  60. }
  61. if params.ListType != 1 && params.ListType != 2 && params.ListType != 3 {
  62. br.Msg = "列表类型有误"
  63. return
  64. }
  65. // 报告分类
  66. cnClassifyIdName, enClassifyIdName := make(map[int]string), make(map[int]string)
  67. cnClassify, e := models.GetAllClassify()
  68. if e != nil {
  69. br.Msg = "获取失败"
  70. br.ErrMsg = "获取中文分类失败, Err: " + e.Error()
  71. return
  72. }
  73. for _, v := range cnClassify {
  74. cnClassifyIdName[v.Id] = v.ClassifyName
  75. }
  76. enClassify, e := models.GetEnglishClassifies()
  77. if e != nil {
  78. br.Msg = "获取失败"
  79. br.ErrMsg = "获取英文分类失败, Err: " + e.Error()
  80. return
  81. }
  82. enRootIdMap := make(map[int]int) // 英文分类的一级分类ID
  83. for _, v := range enClassify {
  84. enClassifyIdName[v.Id] = v.ClassifyName
  85. enRootIdMap[v.Id] = v.RootId
  86. }
  87. // 分页
  88. var startSize int
  89. if params.PageSize <= 0 {
  90. params.PageSize = utils.PageSize20
  91. }
  92. if params.CurrentIndex <= 0 {
  93. params.CurrentIndex = 1
  94. }
  95. startSize = utils.StartIndex(params.CurrentIndex, params.PageSize)
  96. resp := new(report_approve.ReportApproveListResp)
  97. respTotal := 0
  98. respList := make([]*report_approve.ReportApproveItem, 0)
  99. timeField := map[int]string{1: fmt.Sprintf("a.%s", report_approve.ReportApproveCols.CreateTime), 2: fmt.Sprintf("a.%s", report_approve.ReportApproveRecordCols.ApproveTime), 3: fmt.Sprintf("b.%s", report_approve.ReportApproveCols.ApproveTime)}
  100. mineTimeField := map[int]string{1: fmt.Sprintf("%s", report_approve.ReportApproveCols.CreateTime), 3: fmt.Sprintf("%s", report_approve.ReportApproveCols.ApproveTime)}
  101. orderRules := map[int]string{1: "ASC", 2: "DESC"}
  102. ormList := make([]*report_approve.ReportApproveItemOrm, 0)
  103. // 待处理
  104. if params.ListType == 1 {
  105. cond := fmt.Sprintf(` AND a.%s = ? AND b.%s = ? AND a.%s = ?`, report_approve.ReportApproveRecordCols.State, report_approve.ReportApproveCols.State, report_approve.ReportApproveRecordCols.ApproveUserId)
  106. pars := make([]interface{}, 0)
  107. pars = append(pars, report_approve.ReportApproveStateApproving, report_approve.ReportApproveStateApproving, sysUser.AdminId)
  108. order := ""
  109. // 筛选条件
  110. if params.ReportType > 0 {
  111. cond += fmt.Sprintf(` AND b.%s = ?`, report_approve.ReportApproveCols.ReportType)
  112. pars = append(pars, params.ReportType)
  113. }
  114. if params.ClassifyFirstId > 0 {
  115. cond += fmt.Sprintf(` AND b.%s = ?`, report_approve.ReportApproveCols.ClassifyFirstId)
  116. pars = append(pars, params.ClassifyFirstId)
  117. }
  118. if params.ClassifySecondId > 0 {
  119. cond += fmt.Sprintf(` AND b.%s = ?`, report_approve.ReportApproveCols.ClassifySecondId)
  120. pars = append(pars, params.ClassifySecondId)
  121. }
  122. if params.ClassifyThirdId > 0 {
  123. cond += fmt.Sprintf(` AND b.%s = ?`, report_approve.ReportApproveCols.ClassifyThirdId)
  124. pars = append(pars, params.ClassifyThirdId)
  125. }
  126. if params.TimeType <= 0 {
  127. params.TimeType = 1
  128. }
  129. if params.TimeType == 1 && params.StartTime != "" && params.EndTime != "" {
  130. _, e := time.Parse(utils.FormatDate, params.StartTime)
  131. if e != nil {
  132. br.Msg = "开始时间格式有误"
  133. return
  134. }
  135. _, e = time.Parse(utils.FormatDate, params.EndTime)
  136. if e != nil {
  137. br.Msg = "结束时间格式有误"
  138. return
  139. }
  140. st := fmt.Sprintf("%s %s", params.StartTime, "00:00:00")
  141. ed := fmt.Sprintf("%s %s", params.EndTime, "23:59:59")
  142. cond += fmt.Sprintf(` AND (b.%s BETWEEN ? AND ?)`, report_approve.ReportApproveCols.CreateTime)
  143. pars = append(pars, st, ed)
  144. }
  145. params.Keyword = strings.TrimSpace(params.Keyword)
  146. if params.Keyword != "" {
  147. kw := fmt.Sprint("%", params.Keyword, "%")
  148. cond += fmt.Sprintf(` AND b.%s LIKE ?`, report_approve.ReportApproveCols.ReportTitle)
  149. pars = append(pars, kw)
  150. }
  151. if params.SortField > 0 && params.SortRule > 0 {
  152. orderField := timeField[params.SortField]
  153. if orderField == "" {
  154. br.Msg = "时间排序字段有误"
  155. return
  156. }
  157. orderRule := orderRules[params.SortRule]
  158. if orderRule == "" {
  159. br.Msg = "时间排序方式有误"
  160. return
  161. }
  162. order = fmt.Sprintf("%s %s", orderField, orderRule)
  163. }
  164. total, e := report_approve.GetApprovingReportApproveCount(cond, pars)
  165. if e != nil {
  166. br.Msg = "获取失败"
  167. br.ErrMsg = "GetApprovingReportApproveCount err: " + e.Error()
  168. return
  169. }
  170. respTotal = total
  171. list, e := report_approve.GetApprovingReportApprovePageList(cond, pars, order, startSize, params.PageSize)
  172. if e != nil {
  173. br.Msg = "获取失败"
  174. br.ErrMsg = "GetApprovingReportApprovePageList err: " + e.Error()
  175. return
  176. }
  177. ormList = list
  178. }
  179. // 已处理
  180. if params.ListType == 2 {
  181. cond := fmt.Sprintf(` AND a.%s = ? AND a.%s IN (%s)`, report_approve.ReportApproveRecordCols.ApproveUserId, report_approve.ReportApproveRecordCols.NodeState, utils.GetOrmInReplace(2))
  182. pars := make([]interface{}, 0)
  183. pars = append(pars, sysUser.AdminId, []int{report_approve.ReportApproveStatePass, report_approve.ReportApproveStateRefuse})
  184. order := ""
  185. // 筛选条件
  186. if params.ReportType > 0 {
  187. cond += fmt.Sprintf(` AND b.%s = ?`, report_approve.ReportApproveCols.ReportType)
  188. pars = append(pars, params.ReportType)
  189. }
  190. if params.ClassifyFirstId > 0 {
  191. cond += fmt.Sprintf(` AND b.%s = ?`, report_approve.ReportApproveCols.ClassifyFirstId)
  192. pars = append(pars, params.ClassifyFirstId)
  193. }
  194. if params.ClassifySecondId > 0 {
  195. cond += fmt.Sprintf(` AND b.%s = ?`, report_approve.ReportApproveCols.ClassifySecondId)
  196. pars = append(pars, params.ClassifySecondId)
  197. }
  198. if params.ClassifyThirdId > 0 {
  199. cond += fmt.Sprintf(` AND b.%s = ?`, report_approve.ReportApproveCols.ClassifyThirdId)
  200. pars = append(pars, params.ClassifyThirdId)
  201. }
  202. if params.TimeType > 0 && params.StartTime != "" && params.EndTime != "" {
  203. _, e := time.Parse(utils.FormatDate, params.StartTime)
  204. if e != nil {
  205. br.Msg = "开始时间格式有误"
  206. return
  207. }
  208. _, e = time.Parse(utils.FormatDate, params.EndTime)
  209. if e != nil {
  210. br.Msg = "结束时间格式有误"
  211. return
  212. }
  213. st := fmt.Sprintf("%s %s", params.StartTime, "00:00:00")
  214. ed := fmt.Sprintf("%s %s", params.EndTime, "23:59:59")
  215. cond += fmt.Sprintf(` AND (%s BETWEEN ? AND ?)`, timeField[params.TimeType])
  216. pars = append(pars, st, ed)
  217. }
  218. params.Keyword = strings.TrimSpace(params.Keyword)
  219. if params.Keyword != "" {
  220. kw := fmt.Sprint("%", params.Keyword, "%")
  221. cond += fmt.Sprintf(` AND b.%s LIKE ?`, report_approve.ReportApproveCols.ReportTitle)
  222. pars = append(pars, kw)
  223. }
  224. if params.SortField > 0 && params.SortRule > 0 {
  225. orderField := timeField[params.SortField]
  226. if orderField == "" {
  227. br.Msg = "时间排序字段有误"
  228. return
  229. }
  230. orderRule := orderRules[params.SortRule]
  231. if orderRule == "" {
  232. br.Msg = "时间排序方式有误"
  233. return
  234. }
  235. order = fmt.Sprintf("%s %s", orderField, orderRule)
  236. }
  237. if params.ApproveState > 0 {
  238. cond += fmt.Sprintf(` AND a.%s = ?`, report_approve.ReportApproveRecordCols.State)
  239. pars = append(pars, params.ApproveState)
  240. }
  241. total, e := report_approve.GetApprovedReportApproveCount(cond, pars)
  242. if e != nil {
  243. br.Msg = "获取失败"
  244. br.ErrMsg = "GetApprovedReportApproveCount err: " + e.Error()
  245. return
  246. }
  247. respTotal = total
  248. list, e := report_approve.GetApprovedReportApprovePageList(cond, pars, order, startSize, params.PageSize)
  249. if e != nil {
  250. br.Msg = "获取失败"
  251. br.ErrMsg = "GetApprovedReportApprovePageList err: " + e.Error()
  252. return
  253. }
  254. for _, v := range list {
  255. // 这个时候的状态,用审批状态
  256. v.RecordState = v.NodeState
  257. v.ApproveTime = v.NodeApproveTime
  258. }
  259. ormList = list
  260. }
  261. // 我发起的
  262. if params.ListType == 3 {
  263. cond := fmt.Sprintf(` AND a.%s = ?`, report_approve.ReportApproveCols.ApplyUserId)
  264. pars := make([]interface{}, 0)
  265. pars = append(pars, sysUser.AdminId)
  266. order := ""
  267. // 筛选条件
  268. if params.ReportType > 0 {
  269. cond += fmt.Sprintf(` AND a.%s = ?`, report_approve.ReportApproveCols.ReportType)
  270. pars = append(pars, params.ReportType)
  271. }
  272. if params.ClassifyFirstId > 0 {
  273. cond += fmt.Sprintf(` AND a.%s = ?`, report_approve.ReportApproveCols.ClassifyFirstId)
  274. pars = append(pars, params.ClassifyFirstId)
  275. }
  276. if params.ClassifySecondId > 0 {
  277. cond += fmt.Sprintf(` AND a.%s = ?`, report_approve.ReportApproveCols.ClassifySecondId)
  278. pars = append(pars, params.ClassifySecondId)
  279. }
  280. if params.ClassifyThirdId > 0 {
  281. cond += fmt.Sprintf(` AND a.%s = ?`, report_approve.ReportApproveCols.ClassifyThirdId)
  282. pars = append(pars, params.ClassifyThirdId)
  283. }
  284. if params.TimeType > 0 && params.StartTime != "" && params.EndTime != "" {
  285. _, e := time.Parse(utils.FormatDate, params.StartTime)
  286. if e != nil {
  287. br.Msg = "开始时间格式有误"
  288. return
  289. }
  290. _, e = time.Parse(utils.FormatDate, params.EndTime)
  291. if e != nil {
  292. br.Msg = "结束时间格式有误"
  293. return
  294. }
  295. st := fmt.Sprintf("%s %s", params.StartTime, "00:00:00")
  296. ed := fmt.Sprintf("%s %s", params.EndTime, "23:59:59")
  297. field := mineTimeField[params.TimeType]
  298. if field == "" {
  299. br.Msg = "筛选时间有误"
  300. return
  301. }
  302. cond += fmt.Sprintf(` AND (%s BETWEEN ? AND ?)`, field)
  303. pars = append(pars, st, ed)
  304. }
  305. params.Keyword = strings.TrimSpace(params.Keyword)
  306. if params.Keyword != "" {
  307. kw := fmt.Sprint("%", params.Keyword, "%")
  308. cond += fmt.Sprintf(` AND a.%s LIKE ?`, report_approve.ReportApproveCols.ReportTitle)
  309. pars = append(pars, kw)
  310. }
  311. if params.SortField > 0 && params.SortRule > 0 {
  312. orderField := mineTimeField[params.SortField]
  313. if orderField == "" {
  314. br.Msg = "时间排序字段有误"
  315. return
  316. }
  317. orderRule := orderRules[params.SortRule]
  318. if orderRule == "" {
  319. br.Msg = "时间排序方式有误"
  320. return
  321. }
  322. order = fmt.Sprintf("%s %s", orderField, orderRule)
  323. }
  324. if params.ApproveState > 0 {
  325. cond += fmt.Sprintf(` AND a.%s = ?`, report_approve.ReportApproveRecordCols.State)
  326. pars = append(pars, params.ApproveState)
  327. }
  328. total, e := report_approve.GetApplyReportApproveCount(cond, pars)
  329. if e != nil {
  330. br.Msg = "获取失败"
  331. br.ErrMsg = "GetApplyReportApproveCount err: " + e.Error()
  332. return
  333. }
  334. respTotal = total
  335. list, e := report_approve.GetApplyReportApprovePageList(cond, pars, order, startSize, params.PageSize)
  336. if e != nil {
  337. br.Msg = "获取失败"
  338. br.ErrMsg = "GetApplyReportApprovePageList err: " + e.Error()
  339. return
  340. }
  341. ormList = list
  342. }
  343. // 审批通过的报告显示下载按钮
  344. reportImg := make(map[string]string)
  345. reportPdf := make(map[string]string)
  346. reportImgMobile := make(map[string]string)
  347. reportPdfMobile := make(map[string]string)
  348. {
  349. var reportIds, enReportIds []int
  350. for _, v := range ormList {
  351. if v.State != report_approve.ReportApproveStatePass {
  352. continue
  353. }
  354. if v.ReportType == report_approve.FlowReportTypeChinese {
  355. reportIds = append(reportIds, v.ReportId)
  356. }
  357. if v.ReportType == report_approve.FlowReportTypeEnglish {
  358. enReportIds = append(enReportIds, v.ReportId)
  359. }
  360. }
  361. if len(reportIds) > 0 {
  362. reports, e := models.GetReportFieldsByIds(reportIds, []string{"id", "detail_img_url", "detail_pdf_url", "detail_img_url_mobile", "detail_pdf_url_mobile"})
  363. if e != nil {
  364. br.Msg = "获取失败"
  365. br.ErrMsg = fmt.Sprintf("GetReportFieldsByIds, %v", e)
  366. return
  367. }
  368. for _, r := range reports {
  369. k := fmt.Sprintf("%d-%d", report_approve.FlowReportTypeChinese, r.Id)
  370. reportImg[k] = r.DetailImgUrl
  371. reportPdf[k] = r.DetailPdfUrl
  372. reportImgMobile[k] = r.DetailImgUrlMobile
  373. reportPdfMobile[k] = r.DetailPdfUrlMobile
  374. }
  375. }
  376. if len(enReportIds) > 0 {
  377. enReports, e := models.GetEnglishReportFieldsByIds(enReportIds, []string{"id", "detail_img_url", "detail_pdf_url", "detail_img_url_mobile", "detail_pdf_url_mobile"})
  378. if e != nil {
  379. br.Msg = "获取失败"
  380. br.ErrMsg = fmt.Sprintf("GetEnglishReportFieldsByIds, %v", e)
  381. return
  382. }
  383. for _, r := range enReports {
  384. k := fmt.Sprintf("%d-%d", report_approve.FlowReportTypeEnglish, r.Id)
  385. reportImg[k] = r.DetailImgUrl
  386. reportPdf[k] = r.DetailPdfUrl
  387. reportImgMobile[k] = r.DetailImgUrlMobile
  388. reportPdfMobile[k] = r.DetailPdfUrlMobile
  389. }
  390. }
  391. }
  392. // 格式化列表
  393. for _, v := range ormList {
  394. t := report_approve.FormatReportApproveOrm2Item(v)
  395. if v.ReportType == report_approve.FlowReportTypeEnglish {
  396. var classifyPath []string
  397. if v.ReportType > 0 {
  398. classifyPath = append(classifyPath, report_approve.FlowReportTypeMap[v.ReportType])
  399. }
  400. if v.ClassifyFirstId > 0 {
  401. classifyPath = append(classifyPath, enClassifyIdName[v.ClassifyFirstId])
  402. }
  403. if v.ClassifySecondId > 0 {
  404. classifyPath = append(classifyPath, enClassifyIdName[v.ClassifySecondId])
  405. }
  406. if v.ClassifyThirdId > 0 {
  407. classifyPath = append(classifyPath, enClassifyIdName[v.ClassifyThirdId])
  408. }
  409. t.ReportClassify = strings.Join(classifyPath, "/")
  410. } else {
  411. //t.ReportClassify = fmt.Sprintf("%s/%s/%s", report_approve.FlowReportTypeMap[v.ReportType], cnClassifyIdName[v.ClassifyFirstId], cnClassifyIdName[v.ClassifySecondId])
  412. var classifyPath []string
  413. if v.ReportType > 0 {
  414. classifyPath = append(classifyPath, report_approve.FlowReportTypeMap[v.ReportType])
  415. }
  416. if v.ClassifyFirstId > 0 {
  417. classifyPath = append(classifyPath, cnClassifyIdName[v.ClassifyFirstId])
  418. }
  419. if v.ClassifySecondId > 0 {
  420. classifyPath = append(classifyPath, cnClassifyIdName[v.ClassifySecondId])
  421. }
  422. if v.ClassifyThirdId > 0 {
  423. classifyPath = append(classifyPath, cnClassifyIdName[v.ClassifyThirdId])
  424. }
  425. t.ReportClassify = strings.Join(classifyPath, "/")
  426. }
  427. k := fmt.Sprintf("%d-%d", t.ReportType, t.ReportId)
  428. t.DetailImgUrl = reportImg[k]
  429. t.DetailPdfUrl = reportPdf[k]
  430. t.DetailImgUrlMobile = reportImgMobile[k]
  431. t.DetailPdfUrlMobile = reportPdfMobile[k]
  432. respList = append(respList, t)
  433. }
  434. page := paging.GetPaging(params.CurrentIndex, params.PageSize, respTotal)
  435. resp.Paging = page
  436. resp.List = respList
  437. br.Data = resp
  438. br.Ret = 200
  439. br.Success = true
  440. br.Msg = "获取成功"
  441. }
  442. // Detail
  443. // @Title 审批详情
  444. // @Description 审批详情
  445. // @Param ReportApproveId query int true "审批ID"
  446. // @Success 200 {object} report_approve.ReportApproveDetail
  447. // @router /detail [get]
  448. func (this *ReportApproveController) Detail() {
  449. br := new(models.BaseResponse).Init()
  450. defer func() {
  451. if br.ErrMsg == "" {
  452. br.IsSendEmail = false
  453. }
  454. this.Data["json"] = br
  455. this.ServeJSON()
  456. }()
  457. sysUser := this.SysUser
  458. if sysUser == nil {
  459. br.Msg = "请登录"
  460. br.ErrMsg = "请登录,SysUser Is Empty"
  461. br.Ret = 408
  462. return
  463. }
  464. approveId, _ := this.GetInt("ReportApproveId")
  465. if approveId <= 0 {
  466. br.Msg = "参数有误"
  467. br.ErrMsg = fmt.Sprintf("参数有误, ReportApproveId: %d", approveId)
  468. return
  469. }
  470. approveOb := new(report_approve.ReportApprove)
  471. approveItem, e := approveOb.GetItemById(approveId)
  472. if e != nil && !utils.IsErrNoRow(e) {
  473. br.Msg = "获取失败"
  474. br.ErrMsg = "获取审批失败, Err: " + e.Error()
  475. return
  476. }
  477. if approveItem != nil && approveItem.ReportApproveId <= 0 {
  478. br.Msg = "审批已被删除, 请刷新页面"
  479. return
  480. }
  481. // 审批信息
  482. detail := new(report_approve.ReportApproveDetail)
  483. detail.Approve = new(report_approve.ReportApproveDetailItem)
  484. detail.Approve.ReportApproveId = approveItem.ReportApproveId
  485. detail.Approve.State = approveItem.State
  486. detail.Approve.FlowId = approveItem.FlowId
  487. detail.Approve.FlowVersion = approveItem.FlowVersion
  488. detail.Approve.StartNodeId = approveItem.StartNodeId
  489. detail.Approve.CurrNodeId = approveItem.CurrNodeId
  490. detail.Approve.ApplyUserId = approveItem.ApplyUserId
  491. detail.Approve.ApplyUserName = approveItem.ApplyUserName
  492. detail.Approve.ApproveTime = utils.TimeTransferString(utils.FormatDateTime, approveItem.ApproveTime)
  493. detail.Approve.CreateTime = utils.TimeTransferString(utils.FormatDateTime, approveItem.CreateTime)
  494. detail.Approve.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, approveItem.ModifyTime)
  495. // 审批流
  496. //flowOb := new(report_approve.ReportApproveFlow)
  497. //flowItem, e := flowOb.GetItemById(approveItem.FlowId)
  498. //if e != nil {
  499. // if e.Error() == utils.ErrNoRow() {
  500. // br.Msg = "审批流已被删除, 请刷新页面"
  501. // return
  502. // }
  503. // br.Msg = "获取失败"
  504. // br.ErrMsg = "获取审批流失败, Err: " + e.Error()
  505. // return
  506. //}
  507. //detail.ApproveFlow = report_approve.FormatReportApproveFlow2Item(flowItem)
  508. // 审批节点
  509. nodeOb := new(report_approve.ReportApproveNode)
  510. nodeCond := fmt.Sprintf(` AND %s = ? AND %s = ?`, report_approve.ReportApproveNodeCols.ReportApproveFlowId, report_approve.ReportApproveNodeCols.CurrVersion)
  511. nodePars := make([]interface{}, 0)
  512. nodePars = append(nodePars, approveItem.FlowId, approveItem.FlowVersion)
  513. nodeItems, e := nodeOb.GetItemsByCondition(nodeCond, nodePars, []string{}, "")
  514. if e != nil {
  515. br.Msg = "获取失败"
  516. br.ErrMsg = "获取审批节点失败, Err: " + e.Error()
  517. return
  518. }
  519. // 审批记录
  520. recordOb := new(report_approve.ReportApproveRecord)
  521. recordCond := fmt.Sprintf(` AND %s = ?`, report_approve.ReportApproveRecordCols.ReportApproveId)
  522. recordPars := make([]interface{}, 0)
  523. recordPars = append(recordPars, approveItem.ReportApproveId)
  524. recordItems, e := recordOb.GetItemsByCondition(recordCond, recordPars, []string{}, fmt.Sprintf("%s DESC", report_approve.ReportApproveRecordCols.ApproveTime))
  525. if e != nil {
  526. br.Msg = "获取失败"
  527. br.ErrMsg = "获取审批记录失败, Err: " + e.Error()
  528. return
  529. }
  530. recordMap := make(map[string]*report_approve.ReportApproveRecord)
  531. for _, v := range recordItems {
  532. k := fmt.Sprintf("%d-%d", v.NodeId, v.ApproveUserId)
  533. recordMap[k] = v
  534. }
  535. // 审批流节点详情
  536. detail.ApproveFlowNodes = make([]*report_approve.ReportApproveDetailNodes, 0)
  537. for _, v := range nodeItems {
  538. t := new(report_approve.ReportApproveDetailNodes)
  539. t.ReportApproveNodeId = v.ReportApproveNodeId
  540. t.ReportApproveFlowId = v.ReportApproveFlowId
  541. t.PrevNodeId = v.PrevNodeId
  542. t.NextNodeId = v.NextNodeId
  543. t.NodeType = v.NodeType
  544. t.ApproveType = v.ApproveType
  545. t.Users = make([]*report_approve.ReportApproveDetailNodeUser, 0)
  546. us := make([]*report_approve.ReportApproveNodeUserReq, 0)
  547. if v.Users != "" {
  548. e = json.Unmarshal([]byte(v.Users), &us)
  549. if e != nil {
  550. br.Msg = "获取失败"
  551. br.ErrMsg = "节点用户解析失败, Err: " + e.Error()
  552. return
  553. }
  554. }
  555. for _, vu := range us {
  556. u := new(report_approve.ReportApproveDetailNodeUser)
  557. u.UserType = vu.UserType
  558. u.UserId = vu.UserId
  559. u.UserName = vu.UserName
  560. u.Sort = vu.Sort
  561. // 审批记录
  562. k := fmt.Sprintf("%d-%d", v.ReportApproveNodeId, vu.UserId)
  563. r := recordMap[k]
  564. if r != nil {
  565. u.ApproveRecord = new(report_approve.ReportApproveDetailNodeUserRecord)
  566. u.ApproveRecord.ReportApproveRecordId = r.ReportApproveRecordId
  567. u.ApproveRecord.State = r.State
  568. u.ApproveRecord.ApproveUserId = r.ApproveUserId
  569. u.ApproveRecord.ApproveUserName = r.ApproveUserName
  570. u.ApproveRecord.ApproveRemark = r.ApproveRemark
  571. u.ApproveRecord.ApproveTime = utils.TimeTransferString(utils.FormatDateTime, r.ApproveTime)
  572. }
  573. t.Users = append(t.Users, u)
  574. }
  575. sort.Slice(t.Users, func(k, j int) bool {
  576. return t.Users[k].Sort < t.Users[j].Sort
  577. })
  578. detail.ApproveFlowNodes = append(detail.ApproveFlowNodes, t)
  579. }
  580. // 报告信息
  581. cnClassifyIdName, enClassifyIdName := make(map[int]string), make(map[int]string)
  582. cnClassify, e := models.GetAllClassify()
  583. if e != nil {
  584. br.Msg = "获取失败"
  585. br.ErrMsg = "获取中文分类失败, Err: " + e.Error()
  586. return
  587. }
  588. for _, v := range cnClassify {
  589. cnClassifyIdName[v.Id] = v.ClassifyName
  590. }
  591. enClassify, e := models.GetEnglishClassifies()
  592. if e != nil {
  593. br.Msg = "获取失败"
  594. br.ErrMsg = "获取英文分类失败, Err: " + e.Error()
  595. return
  596. }
  597. enRootIdMap := make(map[int]int) // 英文分类的一级分类ID
  598. for _, v := range enClassify {
  599. enClassifyIdName[v.Id] = v.ClassifyName
  600. enRootIdMap[v.Id] = v.RootId
  601. }
  602. detail.Report = new(report_approve.ReportApproveDetailReport)
  603. detail.Report.ReportType = approveItem.ReportType
  604. detail.Report.ReportId = approveItem.ReportId
  605. detail.Report.ReportTitle = approveItem.ReportTitle
  606. detail.Report.ReportLayout = 1
  607. // 报告分类路由
  608. {
  609. if approveItem.ReportType == report_approve.FlowReportTypeChinese {
  610. reportInfo, e := models.GetReportLayoutByReportId(approveItem.ReportId)
  611. if e != nil {
  612. br.Msg = "获取失败"
  613. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  614. return
  615. }
  616. detail.Report.ReportLayout = reportInfo.ReportLayout
  617. detail.Report.ReportCode = utils.MD5(strconv.Itoa(approveItem.ReportId))
  618. }
  619. if approveItem.ReportType == report_approve.FlowReportTypeEnglish {
  620. detail.Report.ReportCode = utils.MD5(strconv.Itoa(approveItem.ReportId))
  621. }
  622. if approveItem.ReportType == report_approve.FlowReportTypeSmart {
  623. detail.Report.ReportLayout = 2
  624. detail.Report.ReportCode = utils.MD5(fmt.Sprint("smart_", approveItem.ReportId))
  625. }
  626. var classifyPath []string
  627. if approveItem.ReportType > 0 {
  628. classifyPath = append(classifyPath, report_approve.FlowReportTypeMap[approveItem.ReportType])
  629. }
  630. if approveItem.ReportType == report_approve.FlowReportTypeEnglish {
  631. if approveItem.ClassifyFirstId > 0 {
  632. classifyPath = append(classifyPath, enClassifyIdName[approveItem.ClassifyFirstId])
  633. }
  634. if approveItem.ClassifySecondId > 0 {
  635. classifyPath = append(classifyPath, enClassifyIdName[approveItem.ClassifySecondId])
  636. }
  637. if approveItem.ClassifyThirdId > 0 {
  638. classifyPath = append(classifyPath, enClassifyIdName[approveItem.ClassifyThirdId])
  639. }
  640. detail.Report.ReportClassify = strings.Join(classifyPath, "/")
  641. } else {
  642. if approveItem.ClassifyFirstId > 0 {
  643. classifyPath = append(classifyPath, cnClassifyIdName[approveItem.ClassifyFirstId])
  644. }
  645. if approveItem.ClassifySecondId > 0 {
  646. classifyPath = append(classifyPath, cnClassifyIdName[approveItem.ClassifySecondId])
  647. }
  648. if approveItem.ClassifyThirdId > 0 {
  649. classifyPath = append(classifyPath, cnClassifyIdName[approveItem.ClassifyThirdId])
  650. }
  651. detail.Report.ReportClassify = strings.Join(classifyPath, "/")
  652. }
  653. }
  654. br.Data = detail
  655. br.Ret = 200
  656. br.Success = true
  657. br.Msg = "获取成功"
  658. }
  659. // Approve
  660. // @Title 通过审批
  661. // @Description 通过审批
  662. // @Param request body report_approve.ReportApprovePassReq true "type json string"
  663. // @Success 200 string "操作成功"
  664. // @router /approve [post]
  665. func (this *ReportApproveController) Approve() {
  666. br := new(models.BaseResponse).Init()
  667. defer func() {
  668. if br.ErrMsg == "" {
  669. br.IsSendEmail = false
  670. }
  671. this.Data["json"] = br
  672. this.ServeJSON()
  673. }()
  674. sysUser := this.SysUser
  675. if sysUser == nil {
  676. br.Msg = "请登录"
  677. br.ErrMsg = "请登录,SysUser Is Empty"
  678. br.Ret = 408
  679. return
  680. }
  681. var req report_approve.ReportApprovePassReq
  682. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  683. br.Msg = "参数有误"
  684. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  685. return
  686. }
  687. if req.ReportApproveId <= 0 {
  688. br.Msg = "参数有误"
  689. br.ErrMsg = fmt.Sprintf("参数有误, ReportApproveId: %d", req.ReportApproveId)
  690. return
  691. }
  692. approveOb := new(report_approve.ReportApprove)
  693. approveItem, e := approveOb.GetItemById(req.ReportApproveId)
  694. if e != nil && !utils.IsErrNoRow(e) {
  695. br.Msg = "操作失败"
  696. br.ErrMsg = "获取审批信息失败, Err: " + e.Error()
  697. return
  698. }
  699. if approveItem != nil && approveItem.ReportApproveId <= 0 {
  700. br.Msg = "审批不存在, 请刷新页面"
  701. return
  702. }
  703. if approveItem.State != report_approve.ReportApproveStateApproving {
  704. br.Msg = "审批状态有误, 请刷新页面"
  705. br.ErrMsg = fmt.Sprintf("审批状态有误, State: %d", approveItem.State)
  706. return
  707. }
  708. // 校验审批记录和审批
  709. recordOb := new(report_approve.ReportApproveRecord)
  710. recordCond := fmt.Sprintf(` AND %s = ? AND %s = ? AND %s = ?`, report_approve.ReportApproveRecordCols.ReportApproveId, report_approve.ReportApproveRecordCols.ApproveUserId, report_approve.ReportApproveRecordCols.State)
  711. recordPars := make([]interface{}, 0)
  712. recordPars = append(recordPars, approveItem.ReportApproveId, sysUser.AdminId, report_approve.ReportApproveStateApproving)
  713. recordItem, e := recordOb.GetItemByCondition(recordCond, recordPars, "")
  714. if e != nil && !utils.IsErrNoRow(e) {
  715. br.Msg = "操作失败"
  716. br.ErrMsg = "获取审批记录失败, Err: " + e.Error()
  717. return
  718. }
  719. if recordItem != nil && recordItem.ReportApproveRecordId <= 0 {
  720. br.Msg = "审批记录有误"
  721. return
  722. }
  723. // 通过审批
  724. tips, e := services.PassReportApprove(approveItem, recordItem, sysUser.AdminId, req.ReportUrl)
  725. if e != nil {
  726. br.Msg = "操作失败"
  727. br.ErrMsg = "通过审批失败, Err: " + e.Error()
  728. return
  729. }
  730. if tips != "" {
  731. br.Msg = tips
  732. return
  733. }
  734. br.Ret = 200
  735. br.Success = true
  736. br.Msg = "操作成功"
  737. }
  738. // Refuse
  739. // @Title 驳回审批
  740. // @Description 驳回审批
  741. // @Param request body report_approve.ReportApproveRefuseReq true "type json string"
  742. // @Success 200 string "操作成功"
  743. // @router /refuse [post]
  744. func (this *ReportApproveController) Refuse() {
  745. br := new(models.BaseResponse).Init()
  746. defer func() {
  747. if br.ErrMsg == "" {
  748. br.IsSendEmail = false
  749. }
  750. this.Data["json"] = br
  751. this.ServeJSON()
  752. }()
  753. sysUser := this.SysUser
  754. if sysUser == nil {
  755. br.Msg = "请登录"
  756. br.ErrMsg = "请登录,SysUser Is Empty"
  757. br.Ret = 408
  758. return
  759. }
  760. var req report_approve.ReportApproveRefuseReq
  761. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  762. br.Msg = "参数有误"
  763. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  764. return
  765. }
  766. if req.ReportApproveId <= 0 {
  767. br.Msg = "参数有误"
  768. br.ErrMsg = fmt.Sprintf("参数有误, ReportApproveId: %d", req.ReportApproveId)
  769. return
  770. }
  771. approveOb := new(report_approve.ReportApprove)
  772. approveItem, e := approveOb.GetItemById(req.ReportApproveId)
  773. if e != nil && !utils.IsErrNoRow(e) {
  774. br.Msg = "操作失败"
  775. br.ErrMsg = "获取审批信息失败, Err: " + e.Error()
  776. return
  777. }
  778. if approveItem != nil && approveItem.ReportApproveId <= 0 {
  779. br.Msg = "审批不存在, 请刷新页面"
  780. return
  781. }
  782. if approveItem.State != report_approve.ReportApproveStateApproving {
  783. br.Msg = "审批状态有误, 请刷新页面"
  784. br.ErrMsg = fmt.Sprintf("审批状态有误, State: %d", approveItem.State)
  785. return
  786. }
  787. // 校验审批记录和审批
  788. recordOb := new(report_approve.ReportApproveRecord)
  789. recordCond := fmt.Sprintf(` AND %s = ? AND %s = ? AND %s = ?`, report_approve.ReportApproveRecordCols.ReportApproveId, report_approve.ReportApproveRecordCols.ApproveUserId, report_approve.ReportApproveRecordCols.State)
  790. recordPars := make([]interface{}, 0)
  791. recordPars = append(recordPars, approveItem.ReportApproveId, sysUser.AdminId, report_approve.ReportApproveStateApproving)
  792. recordItem, e := recordOb.GetItemByCondition(recordCond, recordPars, "")
  793. if e != nil && !utils.IsErrNoRow(e) {
  794. br.Msg = "操作失败"
  795. br.ErrMsg = "获取审批记录失败, Err: " + e.Error()
  796. return
  797. }
  798. if recordItem != nil && recordItem.ReportApproveRecordId <= 0 {
  799. br.Msg = "审批记录有误"
  800. return
  801. }
  802. // 驳回审批
  803. if e = services.RefuseReportApprove(approveItem, recordItem, req.ApproveRemark, sysUser.AdminId); e != nil {
  804. br.Msg = "操作失败"
  805. br.ErrMsg = "驳回审批失败, Err: " + e.Error()
  806. return
  807. }
  808. br.Ret = 200
  809. br.Success = true
  810. br.Msg = "操作成功"
  811. }
  812. // Cancel
  813. // @Title 撤销审批
  814. // @Description 撤销审批
  815. // @Param request body report_approve.ReportApproveCancelReq true "type json string"
  816. // @Success 200 string "操作成功"
  817. // @router /cancel [post]
  818. func (this *ReportApproveController) Cancel() {
  819. br := new(models.BaseResponse).Init()
  820. defer func() {
  821. if br.ErrMsg == "" {
  822. br.IsSendEmail = false
  823. }
  824. this.Data["json"] = br
  825. this.ServeJSON()
  826. }()
  827. sysUser := this.SysUser
  828. if sysUser == nil {
  829. br.Msg = "请登录"
  830. br.ErrMsg = "请登录,SysUser Is Empty"
  831. br.Ret = 408
  832. return
  833. }
  834. var req report_approve.ReportApproveCancelReq
  835. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  836. br.Msg = "参数有误"
  837. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  838. return
  839. }
  840. if req.ReportApproveId <= 0 {
  841. br.Msg = "参数有误"
  842. br.ErrMsg = fmt.Sprintf("参数有误, ReportApproveId: %d", req.ReportApproveId)
  843. return
  844. }
  845. approveOb := new(report_approve.ReportApprove)
  846. approveItem, e := approveOb.GetItemById(req.ReportApproveId)
  847. if e != nil && !utils.IsErrNoRow(e) {
  848. br.Msg = "操作失败"
  849. br.ErrMsg = "获取审批失败, Err: " + e.Error()
  850. return
  851. }
  852. if approveItem != nil && approveItem.ReportApproveId <= 0 {
  853. br.Msg = "审批已被删除, 请刷新页面"
  854. return
  855. }
  856. if approveItem.ApplyUserId != sysUser.AdminId {
  857. br.Msg = "非申请人不可撤销"
  858. return
  859. }
  860. // 撤销审批
  861. e = services.CancelReportApprove(approveItem.ReportType, approveItem.ReportId, approveItem.ReportApproveId, sysUser.AdminId, sysUser.RealName)
  862. if e != nil {
  863. br.Msg = "操作失败"
  864. br.ErrMsg = "撤销审批失败, Err: " + e.Error()
  865. return
  866. }
  867. br.Ret = 200
  868. br.Success = true
  869. br.Msg = "操作成功"
  870. }
  871. // MessageList
  872. // @Title 审批消息列表
  873. // @Description 审批消息列表
  874. // @Param PageSize query int true "每页数据条数"
  875. // @Param CurrentIndex query int true "当前页页码"
  876. // @Success 200 {object} report_approve.ReportApproveMessageListResp
  877. // @router /message/list [get]
  878. func (this *ReportApproveController) MessageList() {
  879. br := new(models.BaseResponse).Init()
  880. defer func() {
  881. if br.ErrMsg == "" {
  882. br.IsSendEmail = false
  883. }
  884. this.Data["json"] = br
  885. this.ServeJSON()
  886. }()
  887. sysUser := this.SysUser
  888. if sysUser == nil {
  889. br.Msg = "请登录"
  890. br.ErrMsg = "请登录,SysUser Is Empty"
  891. br.Ret = 408
  892. return
  893. }
  894. params := new(report_approve.ReportApproveListReq)
  895. if e := this.ParseForm(params); e != nil {
  896. br.Msg = "获取失败"
  897. br.ErrMsg = "入参解析失败, Err: " + e.Error()
  898. return
  899. }
  900. // 分页
  901. var startSize int
  902. if params.PageSize <= 0 {
  903. params.PageSize = utils.PageSize20
  904. }
  905. if params.CurrentIndex <= 0 {
  906. params.CurrentIndex = 1
  907. }
  908. startSize = utils.StartIndex(params.CurrentIndex, params.PageSize)
  909. resp := new(report_approve.ReportApproveMessageListResp)
  910. resp.List = make([]*report_approve.ReportApproveMessageItem, 0)
  911. cond := fmt.Sprintf(` AND %s = ?`, report_approve.ReportApproveMessageCols.ReceiveUserId)
  912. pars := make([]interface{}, 0)
  913. pars = append(pars, sysUser.AdminId)
  914. order := fmt.Sprintf(`%s ASC, %s DESC`, report_approve.ReportApproveMessageCols.IsRead, report_approve.ReportApproveMessageCols.CreateTime)
  915. messageOb := new(report_approve.ReportApproveMessage)
  916. total, e := messageOb.GetCountByCondition(cond, pars)
  917. if e != nil {
  918. br.Msg = "获取失败"
  919. br.ErrMsg = "获取审批消息列表总数失败, Err: " + e.Error()
  920. return
  921. }
  922. list, e := messageOb.GetPageItemsByCondition(cond, pars, []string{}, order, startSize, params.PageSize)
  923. if e != nil {
  924. br.Msg = "获取失败"
  925. br.ErrMsg = "获取审批消息列表失败, Err: " + e.Error()
  926. return
  927. }
  928. for _, v := range list {
  929. t := report_approve.FormatReportApproveMessage2Item(v)
  930. resp.List = append(resp.List, t)
  931. }
  932. // 未读消息数
  933. cond += fmt.Sprintf(` AND %s = ?`, report_approve.ReportApproveMessageCols.IsRead)
  934. pars = append(pars, 0)
  935. unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
  936. if e != nil {
  937. br.Msg = "获取失败"
  938. br.ErrMsg = "获取审批消息列表总数失败, Err: " + e.Error()
  939. return
  940. }
  941. resp.UnreadTotal = unreadTotal
  942. page := paging.GetPaging(params.CurrentIndex, params.PageSize, total)
  943. resp.Paging = page
  944. br.Data = resp
  945. br.Ret = 200
  946. br.Success = true
  947. br.Msg = "获取成功"
  948. }
  949. // MessageRead
  950. // @Title 消息已读
  951. // @Description 消息已读
  952. // @Param request body report_approve.ReportApproveMessageReadReq true "type json string"
  953. // @Success 200 string "操作成功"
  954. // @router /message/read [post]
  955. func (this *ReportApproveController) MessageRead() {
  956. br := new(models.BaseResponse).Init()
  957. defer func() {
  958. if br.ErrMsg == "" {
  959. br.IsSendEmail = false
  960. }
  961. this.Data["json"] = br
  962. this.ServeJSON()
  963. }()
  964. sysUser := this.SysUser
  965. if sysUser == nil {
  966. br.Msg = "请登录"
  967. br.ErrMsg = "请登录,SysUser Is Empty"
  968. br.Ret = 408
  969. return
  970. }
  971. var req report_approve.ReportApproveMessageReadReq
  972. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  973. br.Msg = "参数有误"
  974. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  975. return
  976. }
  977. if req.MessageId <= 0 {
  978. br.Msg = "参数有误"
  979. br.ErrMsg = fmt.Sprintf("参数有误, MessageId: %d", req.MessageId)
  980. return
  981. }
  982. messageOb := new(report_approve.ReportApproveMessage)
  983. messageItem, e := messageOb.GetItemById(req.MessageId)
  984. if e != nil && !utils.IsErrNoRow(e) {
  985. br.Msg = "获取失败"
  986. br.ErrMsg = "获取审批消息失败, Err: " + e.Error()
  987. return
  988. }
  989. if messageItem != nil && messageItem.Id <= 0 {
  990. br.Msg = "消息不存在, 请刷新页面"
  991. return
  992. }
  993. messageItem.IsRead = 1
  994. messageItem.ModifyTime = time.Now().Local()
  995. cols := []string{"IsRead", "ModifyTime"}
  996. if e = messageItem.Update(cols); e != nil {
  997. br.Msg = "操作失败"
  998. br.ErrMsg = "更新审批消息已读失败, Err: " + e.Error()
  999. return
  1000. }
  1001. br.Ret = 200
  1002. br.Success = true
  1003. br.Msg = "操作成功"
  1004. }
  1005. // CheckApproveOpen
  1006. // @Title 校验分类是否开启审批
  1007. // @Description 校验分类是否开启审批
  1008. // @Param request body report_approve.ReportApproveCheckApproveOpenReq true "type json string"
  1009. // @Success 200 string "操作成功"
  1010. // @router /classify/check_open [post]
  1011. func (this *ReportApproveController) CheckApproveOpen() {
  1012. br := new(models.BaseResponse).Init()
  1013. defer func() {
  1014. if br.ErrMsg == "" {
  1015. br.IsSendEmail = false
  1016. }
  1017. this.Data["json"] = br
  1018. this.ServeJSON()
  1019. }()
  1020. sysUser := this.SysUser
  1021. if sysUser == nil {
  1022. br.Msg = "请登录"
  1023. br.ErrMsg = "请登录,SysUser Is Empty"
  1024. br.Ret = 408
  1025. return
  1026. }
  1027. var req report_approve.ReportApproveCheckApproveOpenReq
  1028. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1029. br.Msg = "参数有误"
  1030. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  1031. return
  1032. }
  1033. // 校验是否开启了审批流
  1034. opening, e := services.CheckReportOpenApprove(req.ReportType, req.ClassifyFirstId, req.ClassifySecondId, req.ClassifyThirdId)
  1035. if e != nil {
  1036. br.Msg = "操作失败"
  1037. br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
  1038. return
  1039. }
  1040. br.Data = opening
  1041. br.Ret = 200
  1042. br.Success = true
  1043. br.Msg = "操作成功"
  1044. }