report_approve_flow.go 22 KB

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