report_approve_flow.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  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. "github.com/rdlucklib/rdluck_tools/paging"
  11. "strings"
  12. "sync"
  13. "time"
  14. )
  15. // ReportApproveFlowController 智能研报
  16. type ReportApproveFlowController struct {
  17. controllers.BaseAuthController
  18. }
  19. // List
  20. // @Title 报告列表
  21. // @Description 报告列表
  22. // @Param PageSize query int true "每页数据条数"
  23. // @Param CurrentIndex query int true "当前页页码"
  24. // @Param ReportType query int false "报告类型:1-中文研报;2-英文研报;3-智能研报"
  25. // @Param ClassifyIdFirst query int false "一级分类ID"
  26. // @Param ClassifyIdSecond query int false "二级分类ID"
  27. // @Param Keyword query string false "搜索关键词"
  28. // @Param SortRule query int false "排序方式: 1-正序; 2-倒序(默认)"
  29. // @Success 200 {object} report_approve.ReportApproveFlowListResp
  30. // @router /list [get]
  31. func (this *ReportApproveFlowController) List() {
  32. br := new(models.BaseResponse).Init()
  33. defer func() {
  34. if br.ErrMsg == "" {
  35. br.IsSendEmail = false
  36. }
  37. this.Data["json"] = br
  38. this.ServeJSON()
  39. }()
  40. sysUser := this.SysUser
  41. if sysUser == nil {
  42. br.Msg = "请登录"
  43. br.ErrMsg = "请登录,SysUser Is Empty"
  44. br.Ret = 408
  45. return
  46. }
  47. params := new(report_approve.ReportApproveFlowListReq)
  48. if e := this.ParseForm(params); e != nil {
  49. br.Msg = "获取失败"
  50. br.ErrMsg = "入参解析失败, Err: " + e.Error()
  51. return
  52. }
  53. var cond, orderRule string
  54. var pars []interface{}
  55. // 筛选项
  56. {
  57. keyword := strings.TrimSpace(params.Keyword)
  58. if keyword != "" {
  59. kw := fmt.Sprint("%", keyword, "%")
  60. cond += fmt.Sprintf(` AND %s LIKE ?`, report_approve.ReportApproveFlowCols.FlowName)
  61. pars = append(pars, kw)
  62. }
  63. if params.ReportType > 0 && params.ClassifySecondId > 0 {
  64. cond += fmt.Sprintf(` AND %s = ? AND %s = ?`, report_approve.ReportApproveFlowCols.ReportType, report_approve.ReportApproveFlowCols.ClassifySecondId)
  65. pars = append(pars, params.ReportType, params.ClassifySecondId)
  66. }
  67. if params.SortRule > 0 {
  68. orderMap := map[int]string{1: "ASC", 2: "DESC"}
  69. orderRule = fmt.Sprintf("%s %s", report_approve.ReportApproveFlowCols.CreateTime, orderMap[params.SortRule])
  70. }
  71. }
  72. resp := new(report_approve.ReportApproveFlowListResp)
  73. flowOb := new(report_approve.ReportApproveFlow)
  74. total, e := flowOb.GetCountByCondition(cond, pars)
  75. if e != nil {
  76. br.Msg = "获取失败"
  77. br.ErrMsg = "获取审批流总数失败, Err:" + e.Error()
  78. return
  79. }
  80. if total <= 0 {
  81. page := paging.GetPaging(params.CurrentIndex, params.PageSize, total)
  82. resp.Paging = page
  83. br.Ret = 200
  84. br.Success = true
  85. br.Msg = "获取成功"
  86. br.Data = resp
  87. return
  88. }
  89. // 分页列表
  90. var startSize int
  91. if params.PageSize <= 0 {
  92. params.PageSize = utils.PageSize20
  93. }
  94. if params.CurrentIndex <= 0 {
  95. params.CurrentIndex = 1
  96. }
  97. startSize = utils.StartIndex(params.CurrentIndex, params.PageSize)
  98. list, e := flowOb.GetPageItemsByCondition(cond, pars, []string{}, orderRule, startSize, params.PageSize)
  99. if e != nil {
  100. br.Msg = "获取失败"
  101. br.ErrMsg = "获取审批流分页列表失败, Err:" + e.Error()
  102. return
  103. }
  104. // 指标分类
  105. cnClassifyIdName, enClassifyIdName := make(map[int]string), make(map[int]string)
  106. cnClassify, e := models.GetAllClassify()
  107. if e != nil {
  108. br.Msg = "获取失败"
  109. br.ErrMsg = "获取中文分类失败, Err: " + e.Error()
  110. return
  111. }
  112. for _, v := range cnClassify {
  113. cnClassifyIdName[v.Id] = v.ClassifyName
  114. }
  115. enClassify, e := models.GetAllEnglishClassify()
  116. if e != nil {
  117. br.Msg = "获取失败"
  118. br.ErrMsg = "获取英文分类失败, Err: " + e.Error()
  119. return
  120. }
  121. for _, v := range enClassify {
  122. enClassifyIdName[v.Id] = v.ClassifyName
  123. }
  124. for _, v := range list {
  125. t := report_approve.FormatReportApproveFlow2Item(v)
  126. if v.ReportType == report_approve.FlowReportTypeEnglish {
  127. t.ReportClassify = fmt.Sprintf("%s/%s/%s", report_approve.FlowReportTypeMap[v.ReportType], enClassifyIdName[v.ClassifyFirstId], enClassifyIdName[v.ClassifySecondId])
  128. } else {
  129. t.ReportClassify = fmt.Sprintf("%s/%s/%s", report_approve.FlowReportTypeMap[v.ReportType], cnClassifyIdName[v.ClassifyFirstId], cnClassifyIdName[v.ClassifySecondId])
  130. }
  131. resp.List = append(resp.List, t)
  132. }
  133. page := paging.GetPaging(params.CurrentIndex, params.PageSize, total)
  134. resp.Paging = page
  135. br.Ret = 200
  136. br.Success = true
  137. br.Msg = "获取成功"
  138. br.Data = resp
  139. }
  140. // Add
  141. // @Title 新增审批流
  142. // @Description 新增审批流
  143. // @Param request body report_approve.ReportApproveFlowAddReq true "type json string"
  144. // @Success 200 {object} report_approve.ReportApproveDetailItem
  145. // @router /add [post]
  146. func (this *ReportApproveFlowController) Add() {
  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 report_approve.ReportApproveFlowAddReq
  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. req.FlowName = strings.TrimSpace(req.FlowName)
  169. if req.FlowName == "" {
  170. br.Msg = "请输入审批流名称"
  171. return
  172. }
  173. if len([]rune(req.FlowName)) > 20 {
  174. br.Msg = "审批流名称最多输入20个字符"
  175. return
  176. }
  177. reportTypes := []int{report_approve.FlowReportTypeChinese, report_approve.FlowReportTypeEnglish, report_approve.FlowReportTypeSmart}
  178. if !utils.InArrayByInt(reportTypes, req.ReportType) {
  179. br.Msg = "审批流报告类型有误"
  180. br.ErrMsg = fmt.Sprintf("审批流报告类型有误, ReportType: %d", req.ReportType)
  181. return
  182. }
  183. if req.ClassifyFirstId <= 0 || req.ClassifySecondId <= 0 {
  184. br.Msg = "请选择报告分类"
  185. return
  186. }
  187. if len(req.Nodes) <= 0 {
  188. br.Msg = "请添加审批流程"
  189. return
  190. }
  191. approveTypes := []int{report_approve.NodeApproveTypeRoll, report_approve.NodeApproveTypeAll, report_approve.NodeApproveTypeAny}
  192. approveUserTypes := []string{report_approve.NodeUserTypeNormal, report_approve.NodeUserTypeRole}
  193. for _, v := range req.Nodes {
  194. if !utils.InArrayByInt(approveTypes, v.ApproveType) {
  195. br.Msg = "审批流类型有误"
  196. br.ErrMsg = fmt.Sprintf("审批流类型有误, ApproveType: %d", v.ApproveType)
  197. return
  198. }
  199. for _, v2 := range v.Users {
  200. if !utils.InArrayByStr(approveUserTypes, v2.UserType) {
  201. br.Msg = "审批流用户类型有误"
  202. br.ErrMsg = fmt.Sprintf("审批流用户类型有误, UserType: %d", v2.UserType)
  203. return
  204. }
  205. }
  206. }
  207. // 审批流是否已存在
  208. {
  209. flowOb := new(report_approve.ReportApproveFlow)
  210. existCond := fmt.Sprintf(` AND %s = ? AND %s = ? AND %s = ?`, report_approve.ReportApproveFlowCols.ReportType, report_approve.ReportApproveFlowCols.ClassifyFirstId, report_approve.ReportApproveFlowCols.ClassifySecondId)
  211. existPars := make([]interface{}, 0)
  212. existPars = append(existPars, req.ReportType, req.ClassifyFirstId, req.ClassifySecondId)
  213. exist, e := flowOb.GetItemByCondition(existCond, existPars, "")
  214. if e != nil && e.Error() != utils.ErrNoRow() {
  215. br.Msg = "获取失败"
  216. br.ErrMsg = "获取审批流是否已存在失败, Err: " + e.Error()
  217. return
  218. }
  219. if exist != nil {
  220. br.Msg = "该分类已有审批流, 请勿重复添加"
  221. return
  222. }
  223. }
  224. flowItem := new(report_approve.ReportApproveFlow)
  225. flowItem.FlowName = req.FlowName
  226. flowItem.ReportType = req.ReportType
  227. flowItem.ClassifyFirstId = req.ClassifyFirstId
  228. flowItem.ClassifySecondId = req.ClassifySecondId
  229. flowItem.CurrVersion = 1
  230. flowItem.CreateTime = time.Now().Local()
  231. flowItem.ModifyTime = time.Now().Local()
  232. nodeItems := make([]*report_approve.ReportApproveNode, 0)
  233. for _, v := range req.Nodes {
  234. n := new(report_approve.ReportApproveNode)
  235. n.ApproveType = v.ApproveType
  236. n.CurrVersion = flowItem.CurrVersion
  237. j, _ := json.Marshal(v.Users)
  238. n.Users = string(j)
  239. n.CreateTime = time.Now().Local()
  240. nodeItems = append(nodeItems, n)
  241. }
  242. // 新增审批流和节点
  243. if e := flowItem.CreateFlowAndNodes(flowItem, nodeItems); e != nil {
  244. br.Msg = "操作失败"
  245. br.ErrMsg = "新增审批流和节点失败, Err: " + e.Error()
  246. return
  247. }
  248. // 返回详情
  249. detail, e := report_approve.FormatFlowAndNodesItem2Detail(flowItem, nodeItems)
  250. if e != nil {
  251. br.Msg = "获取失败"
  252. br.ErrMsg = "获取审批详情失败, Err: " + e.Error()
  253. return
  254. }
  255. br.Data = detail
  256. br.Ret = 200
  257. br.Success = true
  258. br.Msg = "操作成功"
  259. }
  260. // Edit
  261. // @Title 编辑审批流
  262. // @Description 编辑审批流
  263. // @Param request body report_approve.ReportApproveFlowEditReq true "type json string"
  264. // @Success 200 {object} report_approve.ReportApproveDetailItem
  265. // @router /edit [post]
  266. func (this *ReportApproveFlowController) Edit() {
  267. br := new(models.BaseResponse).Init()
  268. defer func() {
  269. if br.ErrMsg == "" {
  270. br.IsSendEmail = false
  271. }
  272. this.Data["json"] = br
  273. this.ServeJSON()
  274. }()
  275. sysUser := this.SysUser
  276. if sysUser == nil {
  277. br.Msg = "请登录"
  278. br.ErrMsg = "请登录,SysUser Is Empty"
  279. br.Ret = 408
  280. return
  281. }
  282. var req report_approve.ReportApproveFlowEditReq
  283. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  284. br.Msg = "参数有误"
  285. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  286. return
  287. }
  288. if req.ReportApproveFlowId <= 0 {
  289. br.Msg = "参数有误"
  290. br.ErrMsg = fmt.Sprintf("参数有误, ReportApproveFlowId: %d", req.ReportApproveFlowId)
  291. return
  292. }
  293. req.FlowName = strings.TrimSpace(req.FlowName)
  294. if req.FlowName == "" {
  295. br.Msg = "请输入审批流名称"
  296. return
  297. }
  298. if len([]rune(req.FlowName)) > 20 {
  299. br.Msg = "审批流名称最多输入20个字符"
  300. return
  301. }
  302. reportTypes := []int{report_approve.FlowReportTypeChinese, report_approve.FlowReportTypeEnglish, report_approve.FlowReportTypeSmart}
  303. if !utils.InArrayByInt(reportTypes, req.ReportType) {
  304. br.Msg = "审批流报告类型有误"
  305. br.ErrMsg = fmt.Sprintf("审批流报告类型有误, ReportType: %d", req.ReportType)
  306. return
  307. }
  308. if req.ClassifyFirstId <= 0 || req.ClassifySecondId <= 0 {
  309. br.Msg = "请选择报告分类"
  310. return
  311. }
  312. if len(req.Nodes) <= 0 {
  313. br.Msg = "请添加审批流程"
  314. return
  315. }
  316. approveTypes := []int{report_approve.NodeApproveTypeRoll, report_approve.NodeApproveTypeAll, report_approve.NodeApproveTypeAny}
  317. approveUserTypes := []string{report_approve.NodeUserTypeNormal, report_approve.NodeUserTypeRole}
  318. for _, v := range req.Nodes {
  319. if !utils.InArrayByInt(approveTypes, v.ApproveType) {
  320. br.Msg = "审批流类型有误"
  321. br.ErrMsg = fmt.Sprintf("审批流类型有误, ApproveType: %d", v.ApproveType)
  322. return
  323. }
  324. for _, v2 := range v.Users {
  325. if !utils.InArrayByStr(approveUserTypes, v2.UserType) {
  326. br.Msg = "审批流用户类型有误"
  327. br.ErrMsg = fmt.Sprintf("审批流用户类型有误, UserType: %d", v2.UserType)
  328. return
  329. }
  330. }
  331. }
  332. flowOb := new(report_approve.ReportApproveFlow)
  333. flowItem, e := flowOb.GetItemById(req.ReportApproveFlowId)
  334. if e != nil {
  335. if e.Error() == utils.ErrNoRow() {
  336. br.Msg = "审批流已被删除, 请刷新页面"
  337. return
  338. }
  339. br.Msg = "操作失败"
  340. br.ErrMsg = "获取审批流信息失败, Err: " + e.Error()
  341. return
  342. }
  343. // 审批流是否已存在
  344. {
  345. existCond := fmt.Sprintf(` AND %s = ? AND %s = ? AND %s = ? AND %s <> ?`, report_approve.ReportApproveFlowCols.ReportType, report_approve.ReportApproveFlowCols.ClassifyFirstId, report_approve.ReportApproveFlowCols.ClassifySecondId, report_approve.ReportApproveFlowCols.ReportApproveFlowId)
  346. existPars := make([]interface{}, 0)
  347. existPars = append(existPars, req.ReportType, req.ClassifyFirstId, req.ClassifySecondId, req.ReportApproveFlowId)
  348. exist, e := flowOb.GetItemByCondition(existCond, existPars, "")
  349. if e != nil && e.Error() != utils.ErrNoRow() {
  350. br.Msg = "操作失败"
  351. br.ErrMsg = "获取审批流是否已存在失败, Err: " + e.Error()
  352. return
  353. }
  354. if exist != nil {
  355. br.Msg = "该分类已有审批流, 请勿重复添加"
  356. return
  357. }
  358. }
  359. // 变更了报告分类时, 判断是否允许变更
  360. if req.ReportType != flowItem.ReportType || req.ClassifyFirstId != flowItem.ClassifyFirstId || req.ClassifySecondId != flowItem.ClassifySecondId {
  361. checkOk, e := services.CheckReportApproveFlowChange(flowItem.ReportType, flowItem.ClassifyFirstId, flowItem.ClassifySecondId)
  362. if e != nil {
  363. br.Msg = "操作失败"
  364. br.ErrMsg = "校验审批流是否可变更失败, Err: " + e.Error()
  365. return
  366. }
  367. if !checkOk {
  368. br.Msg = "当前有未走完流程的报告, 请走完流程后再做变更!"
  369. return
  370. }
  371. }
  372. flowItem.FlowName = req.FlowName
  373. flowItem.ReportType = req.ReportType
  374. flowItem.ClassifyFirstId = req.ClassifyFirstId
  375. flowItem.ClassifySecondId = req.ClassifySecondId
  376. flowItem.CurrVersion += 1
  377. flowItem.ModifyTime = time.Now().Local()
  378. nodeItems := make([]*report_approve.ReportApproveNode, 0)
  379. for _, v := range req.Nodes {
  380. n := new(report_approve.ReportApproveNode)
  381. n.ApproveType = v.ApproveType
  382. n.CurrVersion = flowItem.CurrVersion
  383. j, _ := json.Marshal(v.Users)
  384. n.Users = string(j)
  385. n.CreateTime = time.Now().Local()
  386. nodeItems = append(nodeItems, n)
  387. }
  388. // 更新审批流和节点
  389. if e := flowItem.UpdateFlowAndNodes(flowItem, nodeItems); e != nil {
  390. br.Msg = "操作失败"
  391. br.ErrMsg = "更新审批流和节点失败, Err: " + e.Error()
  392. return
  393. }
  394. // 返回详情
  395. detail, e := report_approve.FormatFlowAndNodesItem2Detail(flowItem, nodeItems)
  396. if e != nil {
  397. br.Msg = "获取失败"
  398. br.ErrMsg = "获取审批详情失败, Err: " + e.Error()
  399. return
  400. }
  401. br.Data = detail
  402. br.Ret = 200
  403. br.Success = true
  404. br.Msg = "操作成功"
  405. }
  406. // Detail
  407. // @Title 审批流详情
  408. // @Description 审批流详情
  409. // @Param ReportApproveFlowId query int true "审批流ID"
  410. // @Success 200 {object} report_approve.ReportApproveDetailItem
  411. // @router /detail [get]
  412. func (this *ReportApproveFlowController) Detail() {
  413. br := new(models.BaseResponse).Init()
  414. defer func() {
  415. if br.ErrMsg == "" {
  416. br.IsSendEmail = false
  417. }
  418. this.Data["json"] = br
  419. this.ServeJSON()
  420. }()
  421. sysUser := this.SysUser
  422. if sysUser == nil {
  423. br.Msg = "请登录"
  424. br.ErrMsg = "请登录,SysUser Is Empty"
  425. br.Ret = 408
  426. return
  427. }
  428. flowId, _ := this.GetInt("ReportApproveFlowId")
  429. if flowId <= 0 {
  430. br.Msg = "参数有误"
  431. br.ErrMsg = fmt.Sprintf("参数有误, ReportApproveFlowId: %d", flowId)
  432. return
  433. }
  434. flowOb := new(report_approve.ReportApproveFlow)
  435. flowItem, e := flowOb.GetItemById(flowId)
  436. if e != nil {
  437. if e.Error() == utils.ErrNoRow() {
  438. br.Msg = "审批流已被删除, 请刷新页面"
  439. return
  440. }
  441. br.Msg = "获取失败"
  442. br.ErrMsg = "获取审批流信息失败, Err: " + e.Error()
  443. return
  444. }
  445. // 审批节点
  446. nodeOb := new(report_approve.ReportApproveNode)
  447. nodeCond := fmt.Sprintf(` AND %s = ? AND %s = ?`, report_approve.ReportApproveNodeCols.ReportApproveFlowId, report_approve.ReportApproveNodeCols.CurrVersion)
  448. nodePars := make([]interface{}, 0)
  449. nodePars = append(nodePars, flowItem.ReportApproveFlowId, flowItem.CurrVersion)
  450. nodes, e := nodeOb.GetItemsByCondition(nodeCond, nodePars, []string{}, "")
  451. if e != nil {
  452. br.Msg = "获取失败"
  453. br.ErrMsg = "获取审批节点失败, Err: " + e.Error()
  454. return
  455. }
  456. detail, e := report_approve.FormatFlowAndNodesItem2Detail(flowItem, nodes)
  457. if e != nil {
  458. br.Msg = "获取失败"
  459. br.ErrMsg = "获取审批详情失败, Err: " + e.Error()
  460. return
  461. }
  462. br.Data = detail
  463. br.Ret = 200
  464. br.Success = true
  465. br.Msg = "获取成功"
  466. }
  467. // Remove
  468. // @Title 删除审批流
  469. // @Description 删除审批流
  470. // @Param request body report_approve.ReportApproveFlowRemoveReq true "type json string"
  471. // @Success 200 string "操作成功"
  472. // @router /remove [post]
  473. func (this *ReportApproveFlowController) Remove() {
  474. br := new(models.BaseResponse).Init()
  475. defer func() {
  476. if br.ErrMsg == "" {
  477. br.IsSendEmail = false
  478. }
  479. this.Data["json"] = br
  480. this.ServeJSON()
  481. }()
  482. sysUser := this.SysUser
  483. if sysUser == nil {
  484. br.Msg = "请登录"
  485. br.ErrMsg = "请登录,SysUser Is Empty"
  486. br.Ret = 408
  487. return
  488. }
  489. var req report_approve.ReportApproveFlowRemoveReq
  490. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  491. br.Msg = "参数有误"
  492. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  493. return
  494. }
  495. if req.ReportApproveFlowId <= 0 {
  496. br.Msg = "参数有误"
  497. br.ErrMsg = fmt.Sprintf("参数有误, ReportApproveFlowId: %d", req.ReportApproveFlowId)
  498. return
  499. }
  500. flowOb := new(report_approve.ReportApproveFlow)
  501. flowItem, e := flowOb.GetItemById(req.ReportApproveFlowId)
  502. if e != nil {
  503. if e.Error() == utils.ErrNoRow() {
  504. br.Msg = "审批流已被删除, 请刷新页面"
  505. return
  506. }
  507. br.Msg = "操作失败"
  508. br.ErrMsg = "获取审批流信息失败, Err: " + e.Error()
  509. return
  510. }
  511. // 校验是否允许删除
  512. checkOk, e := services.CheckReportApproveFlowChange(flowItem.ReportType, flowItem.ClassifyFirstId, flowItem.ClassifySecondId)
  513. if e != nil {
  514. br.Msg = "操作失败"
  515. br.ErrMsg = "校验审批流是否可变更失败, Err: " + e.Error()
  516. return
  517. }
  518. if !checkOk {
  519. br.Msg = "当前有未走完流程的报告, 请走完流程后再做删除!"
  520. return
  521. }
  522. // 删除审批流, 保留审批节点, 历史审批回显会用得到
  523. if e = flowItem.Del(); e != nil {
  524. br.Msg = "操作失败"
  525. br.ErrMsg = "删除审批流失败, Err: " + e.Error()
  526. return
  527. }
  528. br.Ret = 200
  529. br.Success = true
  530. br.Msg = "操作成功"
  531. }
  532. // ReportClassifyTree
  533. // @Title 报告分类树
  534. // @Description 报告分类树
  535. // @Param ReportApproveFlowId query int false "审批流ID"
  536. // @Success 200 {object} report_approve.ReportClassifyTreeItem
  537. // @router /report/classify_tree [get]
  538. func (this *ReportApproveFlowController) ReportClassifyTree() {
  539. br := new(models.BaseResponse).Init()
  540. defer func() {
  541. if br.ErrMsg == "" {
  542. br.IsSendEmail = false
  543. }
  544. this.Data["json"] = br
  545. this.ServeJSON()
  546. }()
  547. sysUser := this.SysUser
  548. if sysUser == nil {
  549. br.Msg = "请登录"
  550. br.ErrMsg = "请登录,SysUser Is Empty"
  551. br.Ret = 408
  552. return
  553. }
  554. flowId, _ := this.GetInt("ReportApproveFlowId")
  555. // 获取审批流信息, 用于查询分类是否可选
  556. var flowKey string
  557. if flowId > 0 {
  558. flowOb := new(report_approve.ReportApproveFlow)
  559. flowItem, e := flowOb.GetItemById(flowId)
  560. if e != nil {
  561. if e.Error() == utils.ErrNoRow() {
  562. br.Msg = "审批流已被删除, 请刷新页面"
  563. return
  564. }
  565. br.Msg = "获取失败"
  566. br.ErrMsg = "获取审批流信息失败, Err: " + e.Error()
  567. return
  568. }
  569. flowKey = fmt.Sprintf("%d-%d-%d", flowItem.ReportType, flowItem.ClassifyFirstId, flowItem.ClassifySecondId)
  570. }
  571. // 获取审批流列表
  572. flowOb := new(report_approve.ReportApproveFlow)
  573. flows, e := flowOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
  574. if e != nil {
  575. br.Msg = "获取失败"
  576. br.ErrMsg = "获取审批流列表失败, Err: " + e.Error()
  577. return
  578. }
  579. hasFlowMap := make(map[string]bool)
  580. for _, v := range flows {
  581. k := fmt.Sprintf("%d-%d-%d", v.ReportType, v.ClassifyFirstId, v.ClassifySecondId)
  582. if k == flowKey {
  583. // 当前审批流对应的分类标记为可选状态
  584. continue
  585. }
  586. hasFlowMap[k] = true
  587. }
  588. resp, cnTree, smartTree, enTree := make([]*report_approve.ReportClassifyTreeItem, 0), make([]*report_approve.ReportClassifyTreeItem, 0), make([]*report_approve.ReportClassifyTreeItem, 0), make([]*report_approve.ReportClassifyTreeItem, 0)
  589. var cnErr, enErr error
  590. wg := sync.WaitGroup{}
  591. wg.Add(2)
  592. // 中文/智能研报分类
  593. go func() {
  594. defer func() {
  595. wg.Done()
  596. }()
  597. classify, e := models.GetAllClassify()
  598. if e != nil {
  599. cnErr = fmt.Errorf("GetAllClassify err: %s", e.Error())
  600. return
  601. }
  602. cnTree = services.GetReportClassifyTreeRecursive(classify, 0)
  603. for _, v := range cnTree {
  604. for _, v2 := range v.Children {
  605. k := fmt.Sprintf("%d-%d-%d", report_approve.FlowReportTypeChinese, v.ClassifyId, v2.ClassifyId)
  606. v2.HasFlow = hasFlowMap[k]
  607. }
  608. }
  609. smartTree = services.GetReportClassifyTreeRecursive(classify, 0)
  610. for _, v := range smartTree {
  611. for _, v2 := range v.Children {
  612. k := fmt.Sprintf("%d-%d-%d", report_approve.FlowReportTypeSmart, v.ClassifyId, v2.ClassifyId)
  613. v2.HasFlow = hasFlowMap[k]
  614. }
  615. }
  616. }()
  617. // 英文研报分类
  618. go func() {
  619. defer func() {
  620. wg.Done()
  621. }()
  622. classify, e := models.GetAllEnglishClassify()
  623. if e != nil {
  624. enErr = fmt.Errorf("GetAllEnglishClassify err: %s", e.Error())
  625. return
  626. }
  627. enTree = services.GetReportClassifyTreeRecursive(classify, 0)
  628. for _, v := range enTree {
  629. for _, v2 := range v.Children {
  630. k := fmt.Sprintf("%d-%d-%d", report_approve.FlowReportTypeEnglish, v.ClassifyId, v2.ClassifyId)
  631. v2.HasFlow = hasFlowMap[k]
  632. }
  633. }
  634. }()
  635. wg.Wait()
  636. if cnErr != nil {
  637. br.Msg = "获取失败"
  638. br.ErrMsg = "获取中文分类失败, Err: " + cnErr.Error()
  639. return
  640. }
  641. if enErr != nil {
  642. br.Msg = "获取失败"
  643. br.ErrMsg = "获取英文分类失败, Err: " + enErr.Error()
  644. return
  645. }
  646. resp = append(resp, &report_approve.ReportClassifyTreeItem{
  647. ClassifyId: report_approve.FlowReportTypeChinese,
  648. ClassifyName: "研报列表",
  649. Children: cnTree,
  650. }, &report_approve.ReportClassifyTreeItem{
  651. ClassifyId: report_approve.FlowReportTypeEnglish,
  652. ClassifyName: "英文研报",
  653. Children: enTree,
  654. }, &report_approve.ReportClassifyTreeItem{
  655. ClassifyId: report_approve.FlowReportTypeSmart,
  656. ClassifyName: "智能研报",
  657. Children: smartTree,
  658. })
  659. br.Data = resp
  660. br.Ret = 200
  661. br.Success = true
  662. br.Msg = "获取成功"
  663. }