report_approve.go 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053
  1. package services
  2. import (
  3. "eta_gn/eta_api/models"
  4. "eta_gn/eta_api/models/report_approve"
  5. "eta_gn/eta_api/models/smart_report"
  6. "eta_gn/eta_api/services/alarm_msg"
  7. "eta_gn/eta_api/utils"
  8. "fmt"
  9. "sort"
  10. "time"
  11. )
  12. // GetReportClassifyTreeRecursive 递归获取报告分类树
  13. func GetReportClassifyTreeRecursive(list []*models.Classify, parentId int) []*report_approve.ReportClassifyTreeItem {
  14. res := make([]*report_approve.ReportClassifyTreeItem, 0)
  15. for _, v := range list {
  16. if v.ParentId == parentId {
  17. t := new(report_approve.ReportClassifyTreeItem)
  18. t.ClassifyId = v.Id
  19. t.ClassifyName = v.ClassifyName
  20. t.ParentId = v.ParentId
  21. t.Children = GetReportClassifyTreeRecursive(list, v.Id)
  22. res = append(res, t)
  23. }
  24. }
  25. return res
  26. }
  27. // CheckReportApproveFlowChange 校验是否可变更分类
  28. func CheckReportApproveFlowChange(reportType, classifyFirstId, classifySecondId, classifyThirdId int) (ok bool, err error) {
  29. var count int
  30. cond := ` AND classify_id_first = ? AND classify_id_second = ? AND state = ?`
  31. pars := make([]interface{}, 0)
  32. pars = append(pars, classifyFirstId, classifySecondId, models.ReportStateWaitApprove)
  33. switch reportType {
  34. case report_approve.FlowReportTypeChinese:
  35. cond += ` AND classify_id_third = ? `
  36. pars = append(pars, classifyThirdId)
  37. ct, e := models.GetReportListCount(cond, pars)
  38. if e != nil {
  39. err = fmt.Errorf("GetReportListCount err: %s", e.Error())
  40. return
  41. }
  42. count = ct
  43. case report_approve.FlowReportTypeEnglish:
  44. ct, e := models.GetEnglishReportListCount(cond, pars, "")
  45. if e != nil {
  46. err = fmt.Errorf("GetEnglishReportListCount err: %s", e.Error())
  47. return
  48. }
  49. count = ct
  50. case report_approve.FlowReportTypeSmart:
  51. ob := new(smart_report.SmartReport)
  52. ct, e := ob.GetCountByCondition(cond, pars)
  53. if e != nil {
  54. err = fmt.Errorf("SmartReport GetCountByCondition err: %s", e.Error())
  55. return
  56. }
  57. count = ct
  58. default:
  59. err = fmt.Errorf("报告类型有误")
  60. return
  61. }
  62. if count <= 0 {
  63. ok = true
  64. }
  65. return
  66. }
  67. // CheckReportOpenApprove 校验报告是否开启了审批流
  68. func CheckReportOpenApprove(reportType, firstId, secondId, thirdId int) (opening bool, err error) {
  69. // 获取审批配置
  70. confMap, e := models.GetBusinessConf()
  71. if e != nil {
  72. err = fmt.Errorf("GetBusinessConf err: %s", e.Error())
  73. return
  74. }
  75. openMap := map[string]bool{"false": false, "true": true}
  76. openApprove := openMap[confMap[models.BusinessConfIsReportApprove]]
  77. // 查询对应分类是否有审批流
  78. flowOb := new(report_approve.ReportApproveFlow)
  79. flowCond := 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.ClassifyThirdId)
  80. flowPars := make([]interface{}, 0)
  81. flowPars = append(flowPars, reportType, firstId, secondId, thirdId)
  82. flowItem, e := flowOb.GetItemByCondition(flowCond, flowPars, "")
  83. if e != nil && e.Error() != utils.ErrNoRow() {
  84. err = fmt.Errorf("ApproveFlow GetItemByCondition err: %s", e.Error())
  85. return
  86. }
  87. // 开启审批/有审批流
  88. if openApprove && (flowItem != nil || confMap[models.BusinessConfReportApproveType] == models.BusinessConfReportApproveTypeOther) {
  89. opening = true
  90. return
  91. }
  92. return
  93. }
  94. // CheckReportCurrState 校验报告当前应有的状态
  95. func CheckReportCurrState(reportType, firstId, secondId, thirdId, operate int) (state int, err error) {
  96. // 获取审批配置
  97. confMap, e := models.GetBusinessConf()
  98. if e != nil {
  99. err = fmt.Errorf("GetBusinessConf err: %s", e.Error())
  100. return
  101. }
  102. openMap := map[string]bool{"false": false, "true": true}
  103. openApprove := openMap[confMap[models.BusinessConfIsReportApprove]]
  104. // 查询对应分类是否有审批流
  105. flowOb := new(report_approve.ReportApproveFlow)
  106. flowCond := 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.ClassifyThirdId)
  107. flowPars := make([]interface{}, 0)
  108. flowPars = append(flowPars, reportType, firstId, secondId, thirdId)
  109. flowItem, e := flowOb.GetItemByCondition(flowCond, flowPars, "")
  110. if e != nil && e.Error() != utils.ErrNoRow() {
  111. err = fmt.Errorf("ApproveFlow GetItemByCondition err: %s", e.Error())
  112. return
  113. }
  114. // 开启审批/有审批流
  115. if openApprove && (flowItem != nil || confMap[models.BusinessConfReportApproveType] == models.BusinessConfReportApproveTypeOther) {
  116. // 操作为无审批的操作时, 会转为有审批的初始状态-待提交
  117. stateMap := map[int]int{
  118. models.ReportOperateAdd: models.ReportStateWaitSubmit, // 新增
  119. models.ReportOperateEdit: models.ReportStateWaitSubmit, // 编辑
  120. models.ReportOperatePublish: models.ReportStateWaitSubmit, // 发布
  121. models.ReportOperateCancelPublish: models.ReportStateWaitSubmit, // 取消发布
  122. models.ReportOperateSubmitApprove: models.ReportStateWaitApprove, // 提审
  123. models.ReportOperateCancelApprove: models.ReportStateWaitSubmit, // 撤回
  124. }
  125. state = stateMap[operate]
  126. return
  127. }
  128. // 关闭审批/分类无审批
  129. // 操作为有审批的操作时, 会转为无审批的初始状态-未发布
  130. stateMap := map[int]int{
  131. models.ReportOperateAdd: models.ReportStateUnpublished, // 新增
  132. models.ReportOperateEdit: models.ReportStateUnpublished, // 编辑
  133. models.ReportOperatePublish: models.ReportStatePublished, // 发布
  134. models.ReportOperateCancelPublish: models.ReportStateUnpublished, // 取消发布
  135. models.ReportOperateSubmitApprove: models.ReportStateUnpublished, // 提审
  136. models.ReportOperateCancelApprove: models.ReportStateUnpublished, // 撤回
  137. }
  138. state = stateMap[operate]
  139. return
  140. }
  141. // SubmitReportApprove 提交审批
  142. func SubmitReportApprove(reportType, reportId int, reportTitle string, firstId, secondId, thirdId int, sysAdminId int, sysAdminName string) (approveId int, err error) {
  143. // 默认内部审批, 如果是走的第三方审批, 那么仅修改状态
  144. confMap, e := models.GetBusinessConf()
  145. if e != nil {
  146. err = fmt.Errorf("GetBusinessConf err: %s", e.Error())
  147. return
  148. }
  149. openMap := map[string]bool{"false": false, "true": true}
  150. openApprove := openMap[confMap[models.BusinessConfIsReportApprove]]
  151. if !openApprove {
  152. err = fmt.Errorf("未开启审批")
  153. return
  154. }
  155. confApproveType := confMap[models.BusinessConfReportApproveType]
  156. if confApproveType == "" {
  157. confApproveType = models.BusinessConfReportApproveTypeEta
  158. }
  159. if confApproveType == models.BusinessConfReportApproveTypeOther {
  160. return
  161. }
  162. // 查询审批流
  163. flowOb := new(report_approve.ReportApproveFlow)
  164. flowCond := 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.ClassifyThirdId)
  165. flowPars := make([]interface{}, 0)
  166. flowPars = append(flowPars, reportType, firstId, secondId, thirdId)
  167. flowItem, e := flowOb.GetItemByCondition(flowCond, flowPars, "")
  168. if e != nil {
  169. err = fmt.Errorf("ApproveFlow GetItemByCondition err: %s", e.Error())
  170. return
  171. }
  172. // 查询审批节点
  173. nodeOb := new(report_approve.ReportApproveNode)
  174. nodeCond := fmt.Sprintf(` AND %s = ? AND %s = ?`, report_approve.ReportApproveNodeCols.ReportApproveFlowId, report_approve.ReportApproveNodeCols.CurrVersion)
  175. nodePars := make([]interface{}, 0)
  176. nodePars = append(nodePars, flowItem.ReportApproveFlowId, flowItem.CurrVersion)
  177. nodeItems, e := nodeOb.GetItemsByCondition(nodeCond, nodePars, []string{}, "")
  178. if e != nil {
  179. err = fmt.Errorf("ApproveNodes GetItemsByCondition err: %s", e.Error())
  180. return
  181. }
  182. if len(nodeItems) == 0 {
  183. err = fmt.Errorf("无审批节点")
  184. return
  185. }
  186. // 取出首个节点
  187. firstNodeItem := new(report_approve.ReportApproveNode)
  188. for _, v := range nodeItems {
  189. if v.PrevNodeId == 0 {
  190. firstNodeItem = v
  191. continue
  192. }
  193. }
  194. if firstNodeItem == nil {
  195. err = fmt.Errorf("首个审批节点有误")
  196. return
  197. }
  198. // 审批信息
  199. now := time.Now().Local()
  200. newApprove := new(report_approve.ReportApprove)
  201. newApprove.ReportType = reportType
  202. newApprove.ReportId = reportId
  203. newApprove.ReportTitle = reportTitle
  204. newApprove.ClassifyFirstId = firstId
  205. newApprove.ClassifySecondId = secondId
  206. newApprove.ClassifyThirdId = thirdId
  207. newApprove.State = report_approve.ReportApproveStateApproving
  208. newApprove.FlowId = flowItem.ReportApproveFlowId
  209. newApprove.FlowVersion = flowItem.CurrVersion
  210. newApprove.StartNodeId = firstNodeItem.ReportApproveNodeId
  211. newApprove.CurrNodeId = firstNodeItem.ReportApproveNodeId
  212. newApprove.ApplyUserId = sysAdminId
  213. newApprove.ApplyUserName = sysAdminName
  214. newApprove.CreateTime = now
  215. newApprove.ModifyTime = now
  216. if e = newApprove.Create(); e != nil {
  217. err = fmt.Errorf("生成审批信息失败, Err: %s", e.Error())
  218. return
  219. }
  220. approveId = newApprove.ReportApproveId
  221. // 生成节点审批记录
  222. err = BuildNextNodeRecordAndMsg(firstNodeItem, newApprove.ReportApproveId, sysAdminId, sysAdminName)
  223. return
  224. }
  225. // CancelReportApprove 撤回审批
  226. func CancelReportApprove(reportType, reportId, approveId, sysAdminId int, sysAdminName string) (err error) {
  227. // 默认内部审批, 如果是走的第三方审批, 那么仅修改状态
  228. confMap, e := models.GetBusinessConf()
  229. if e != nil {
  230. err = fmt.Errorf("GetBusinessConf err: %s", e.Error())
  231. return
  232. }
  233. openMap := map[string]bool{"false": false, "true": true}
  234. openApprove := openMap[confMap[models.BusinessConfIsReportApprove]]
  235. if !openApprove {
  236. //err = fmt.Errorf("未开启审批")
  237. return
  238. }
  239. confApproveType := confMap[models.BusinessConfReportApproveType]
  240. if confApproveType == "" {
  241. confApproveType = models.BusinessConfReportApproveTypeEta
  242. }
  243. // 第三方审批仅修改报告状态
  244. if confApproveType == models.BusinessConfReportApproveTypeOther {
  245. e = updateReportApproveState(reportType, reportId, 0, models.ReportStateWaitSubmit)
  246. if e != nil {
  247. err = fmt.Errorf("更新报告审批撤回失败, Err: %s", e.Error())
  248. return
  249. }
  250. return
  251. }
  252. // 修改审批信息状态
  253. approveOb := new(report_approve.ReportApprove)
  254. approveItem, e := approveOb.GetItemById(approveId)
  255. if e != nil {
  256. if e.Error() == utils.ErrNoRow() {
  257. return
  258. }
  259. err = fmt.Errorf("approve GetItemById err: %s", e.Error())
  260. return
  261. }
  262. if approveItem.State == report_approve.ReportApproveStateCancel {
  263. return
  264. }
  265. approveItem.State = report_approve.ReportApproveStateCancel
  266. cols := []string{"State", "ModifyTime"}
  267. if e = approveItem.Update(cols); e != nil {
  268. err = fmt.Errorf("approve Update err: %s", e.Error())
  269. return
  270. }
  271. // 修改报告状态
  272. e = updateReportApproveState(reportType, reportId, 0, models.ReportStateWaitSubmit)
  273. if e != nil {
  274. err = fmt.Errorf("更新报告审批撤回失败, Err: %s", e.Error())
  275. return
  276. }
  277. // 推送撤回消息
  278. go func() {
  279. recordOb := new(report_approve.ReportApproveRecord)
  280. recordCond := fmt.Sprintf(` AND %s = ?`, report_approve.ReportApproveRecordCols.ReportApproveId)
  281. recordPars := make([]interface{}, 0)
  282. recordPars = append(recordPars, approveId)
  283. recordItems, e := recordOb.GetItemsByCondition(recordCond, recordPars, []string{}, "")
  284. if e != nil {
  285. utils.FileLog.Info(fmt.Sprintf("approve record GetItemsByCondition err: %s", e.Error()))
  286. return
  287. }
  288. messageOb := new(report_approve.ReportApproveMessage)
  289. messages := make([]*report_approve.ReportApproveMessage, 0)
  290. for _, v := range recordItems {
  291. m := new(report_approve.ReportApproveMessage)
  292. m.SendUserId = sysAdminId
  293. m.ReceiveUserId = v.ApproveUserId
  294. m.Content = fmt.Sprintf("%s提交的【研报审批】已撤回", sysAdminName)
  295. m.ReportApproveId = approveId
  296. m.ApproveState = report_approve.ReportApproveStateCancel
  297. m.CreateTime = time.Now().Local()
  298. m.ModifyTime = time.Now().Local()
  299. messages = append(messages, m)
  300. }
  301. e = messageOb.CreateMulti(messages)
  302. if e != nil {
  303. utils.FileLog.Info(fmt.Sprintf("CancelReportApprove messages err: %s", e.Error()))
  304. return
  305. }
  306. }()
  307. return
  308. }
  309. // updateReportApproveState 更新报告审批状态
  310. func updateReportApproveState(reportType, reportId, approveId, state int) (err error) {
  311. updateCols := []string{"ApproveId", "State", "ModifyTime"}
  312. if reportType == report_approve.FlowReportTypeChinese {
  313. reportOb := new(models.Report)
  314. reportItem, e := reportOb.GetItemById(reportId)
  315. // 报告可能会被删除, 这里查不到就忽略掉
  316. if e != nil && e.Error() != utils.ErrNoRow() {
  317. err = fmt.Errorf("获取中文研报失败, Err: %s", e.Error())
  318. return
  319. }
  320. if reportItem != nil {
  321. reportItem.ApproveId = approveId
  322. reportItem.State = state
  323. reportItem.ModifyTime = time.Now().Local()
  324. if state == models.ReportStatePass || state == models.ReportStateRefused {
  325. updateCols = append(updateCols, "ApproveTime")
  326. reportItem.ApproveTime = time.Now().Local()
  327. }
  328. if state == models.ReportStatePass {
  329. updateCols = append(updateCols, "PublishTime")
  330. reportItem.PublishTime = time.Now().Local()
  331. }
  332. if e = reportItem.UpdateReport(updateCols); e != nil {
  333. err = fmt.Errorf("更新中文研报审批状态失败, Err: %s", e.Error())
  334. return
  335. }
  336. }
  337. }
  338. if reportType == report_approve.FlowReportTypeEnglish {
  339. reportItem, e := models.GetEnglishReportItemById(reportId)
  340. if e != nil && e.Error() != utils.ErrNoRow() {
  341. err = fmt.Errorf("获取英文研报失败, Err: %s", e.Error())
  342. return
  343. }
  344. if reportItem != nil {
  345. reportItem.ApproveId = approveId
  346. reportItem.State = state
  347. reportItem.ModifyTime = time.Now().Local()
  348. if state == models.ReportStatePass || state == models.ReportStateRefused {
  349. updateCols = append(updateCols, "ApproveTime")
  350. reportItem.ApproveTime = time.Now().Local()
  351. }
  352. if state == models.ReportStatePass {
  353. updateCols = append(updateCols, "PublishTime")
  354. reportItem.PublishTime = time.Now().Local()
  355. }
  356. if e = reportItem.UpdateReport(updateCols); e != nil {
  357. err = fmt.Errorf("更新英文研报审批状态失败, Err: %s", e.Error())
  358. return
  359. }
  360. }
  361. }
  362. if reportType == report_approve.FlowReportTypeSmart {
  363. reportOb := new(smart_report.SmartReport)
  364. reportItem, e := reportOb.GetItemById(reportId)
  365. if e != nil && e.Error() != utils.ErrNoRow() {
  366. err = fmt.Errorf("获取智能研报失败, Err: %s", e.Error())
  367. return
  368. }
  369. if reportItem != nil {
  370. reportItem.ApproveId = approveId
  371. reportItem.State = state
  372. reportItem.ModifyTime = time.Now().Local()
  373. if state == models.ReportStatePass || state == models.ReportStateRefused {
  374. updateCols = append(updateCols, "ApproveTime")
  375. reportItem.ApproveTime = time.Now().Local()
  376. }
  377. if state == models.ReportStatePass {
  378. updateCols = append(updateCols, "PublishTime")
  379. reportItem.PublishTime = time.Now().Local()
  380. }
  381. if e = reportItem.Update(updateCols); e != nil {
  382. err = fmt.Errorf("更新智能研报审批状态失败, Err: %s", e.Error())
  383. return
  384. }
  385. }
  386. }
  387. return
  388. }
  389. // PassReportApprove 通过审批
  390. func PassReportApprove(approveItem *report_approve.ReportApprove, recordItem *report_approve.ReportApproveRecord, sysAdminId int, reportUrl string) (tips string, err error) {
  391. if approveItem == nil {
  392. err = fmt.Errorf("审批信息有误")
  393. return
  394. }
  395. if recordItem == nil {
  396. err = fmt.Errorf("审批记录有误")
  397. return
  398. }
  399. // 查询审批流和审批流节点
  400. flowOb := new(report_approve.ReportApproveFlow)
  401. flowItem, e := flowOb.GetItemById(approveItem.FlowId)
  402. if e != nil {
  403. err = fmt.Errorf("获取审批流失败, Err: %s", e.Error())
  404. return
  405. }
  406. nodeOb := new(report_approve.ReportApproveNode)
  407. nodeCond := fmt.Sprintf(` AND %s = ? AND %s = ?`, report_approve.ReportApproveNodeCols.ReportApproveFlowId, report_approve.ReportApproveNodeCols.CurrVersion)
  408. nodePars := make([]interface{}, 0)
  409. nodePars = append(nodePars, flowItem.ReportApproveFlowId, flowItem.CurrVersion)
  410. nodeItems, e := nodeOb.GetItemsByCondition(nodeCond, nodePars, []string{}, "")
  411. if e != nil {
  412. err = fmt.Errorf("ApproveNodes GetItemsByCondition err: %s", e.Error())
  413. return
  414. }
  415. if len(nodeItems) == 0 {
  416. err = fmt.Errorf("无审批节点")
  417. return
  418. }
  419. nodeMap := make(map[int]*report_approve.ReportApproveNode)
  420. for _, v := range nodeItems {
  421. nodeMap[v.ReportApproveNodeId] = v
  422. }
  423. // 取出审批记录的节点
  424. currNodeItem := nodeMap[recordItem.NodeId]
  425. if currNodeItem == nil {
  426. err = fmt.Errorf("当前节点信息有误")
  427. return
  428. }
  429. currNode, e := report_approve.FormatReportApproveNode2Item(currNodeItem)
  430. if e != nil {
  431. err = fmt.Errorf("当前节点信息有误, Err: %s", e.Error())
  432. return
  433. }
  434. now := time.Now().Local()
  435. recordItem.State = report_approve.ReportApproveStatePass
  436. recordItem.ApproveTime = now
  437. recordItem.ModifyTime = now
  438. recordItem.NodeState = report_approve.ReportApproveStatePass
  439. recordItem.NodeApproveUserId = recordItem.ApproveUserId
  440. recordItem.NodeApproveUserName = recordItem.ApproveUserName
  441. recordItem.NodeApproveTime = now
  442. recordCols := []string{"State", "ApproveTime", "ModifyTime", "NodeState", "NodeApproveUserId", "NodeApproveUserName", "NodeApproveTime"}
  443. lastApprove := false
  444. // 依次审批
  445. if currNode.ApproveType == report_approve.NodeApproveTypeRoll {
  446. if e = recordItem.Update(recordCols); e != nil {
  447. err = fmt.Errorf("更新审批记录状态失败, Err: %s", e.Error())
  448. return
  449. }
  450. // 检查依次审批情况
  451. sort.Slice(currNode.Users, func(k, j int) bool {
  452. return currNode.Users[k].Sort < currNode.Users[j].Sort
  453. })
  454. userLen := len(currNode.Users)
  455. //lastRoll := false
  456. nextUser := new(report_approve.ReportApproveNodeUserReq) // 下一个审批人, 为nil则表示当前审批人即为最后
  457. for k, v := range currNode.Users {
  458. // 当前审批人
  459. if v.UserId == sysAdminId && recordItem.ApproveUserSort == v.Sort {
  460. //if k == (userLen - 1) {
  461. // lastRoll = true
  462. // break
  463. //}
  464. if (k + 1) < userLen {
  465. nextUser = currNode.Users[k+1]
  466. }
  467. }
  468. }
  469. //if lastRoll && currNode.NextNodeId == 0 {
  470. // lastApprove = true
  471. //}
  472. // 当前节点下一个审批人, 生成下一个审批记录且return
  473. if nextUser.UserId > 0 {
  474. newRecord := new(report_approve.ReportApproveRecord)
  475. newRecord.ReportApproveId = recordItem.ReportApproveId
  476. newRecord.State = report_approve.ReportApproveStateApproving
  477. newRecord.NodeId = currNode.ReportApproveNodeId
  478. newRecord.PrevNodeId = currNode.PrevNodeId
  479. newRecord.NextNodeId = currNode.NextNodeId
  480. newRecord.ApproveType = currNode.ApproveType
  481. newRecord.ApproveUserId = nextUser.UserId
  482. newRecord.ApproveUserName = nextUser.UserName
  483. newRecord.ApproveUserSort = nextUser.Sort
  484. newRecord.CreateTime = now
  485. newRecord.ModifyTime = now
  486. newRecord.NodeState = report_approve.ReportApproveStateApproving
  487. if e = newRecord.Create(); e != nil {
  488. err = fmt.Errorf("生成审批记录失败, Err: %s", e.Error())
  489. return
  490. }
  491. // 推送审批消息
  492. go func() {
  493. messageItem := new(report_approve.ReportApproveMessage)
  494. messageItem.SendUserId = approveItem.ApplyUserId
  495. messageItem.ReceiveUserId = nextUser.UserId
  496. messageItem.Content = "您有新的待办任务"
  497. messageItem.Remark = fmt.Sprintf("%s提交的【研报审批】需要您审批,请及时处理", approveItem.ApplyUserName)
  498. messageItem.ReportApproveId = approveItem.ReportApproveId
  499. messageItem.ApproveState = report_approve.ReportApproveStateApproving
  500. messageItem.CreateTime = now
  501. messageItem.ModifyTime = now
  502. if e = messageItem.Create(); e != nil {
  503. utils.FileLog.Info(fmt.Sprintf("PassReportApprove message err: %s", e.Error()))
  504. return
  505. }
  506. }()
  507. return
  508. }
  509. // 更新审批当前节点并进入下一个节点
  510. if currNode.NextNodeId > 0 {
  511. nextNode := nodeMap[currNode.NextNodeId]
  512. approveItem.CurrNodeId = currNode.NextNodeId
  513. approveItem.ModifyTime = now
  514. if e = approveItem.Update([]string{"CurrNodeId", "ModifyTime"}); e != nil {
  515. err = fmt.Errorf("更新审批当前节点失败, Err: %s", e.Error())
  516. return
  517. }
  518. err = BuildNextNodeRecordAndMsg(nextNode, approveItem.ReportApproveId, approveItem.ApplyUserId, approveItem.ApplyUserName)
  519. return
  520. } else {
  521. // 最后一个节点
  522. lastApprove = true
  523. }
  524. }
  525. // 会签
  526. if currNode.ApproveType == report_approve.NodeApproveTypeAll {
  527. // 查询其他审批人是否已审批
  528. otherOb := new(report_approve.ReportApproveRecord)
  529. otherCond := fmt.Sprintf(` AND %s = ? AND %s = ? AND %s <> ?`, report_approve.ReportApproveRecordCols.ReportApproveId, report_approve.ReportApproveRecordCols.NodeId, report_approve.ReportApproveRecordCols.ApproveUserId)
  530. otherPars := make([]interface{}, 0)
  531. otherPars = append(otherPars, approveItem.ReportApproveId, recordItem.NodeId, sysAdminId)
  532. otherRecords, e := otherOb.GetItemsByCondition(otherCond, otherPars, []string{}, "")
  533. if e != nil {
  534. err = fmt.Errorf("获取节点审批记录失败, Err: %s", e.Error())
  535. return
  536. }
  537. otherPass := true
  538. for _, v := range otherRecords {
  539. if v.State != report_approve.ReportApproveStatePass {
  540. otherPass = false
  541. }
  542. }
  543. // 其他人未审批, 仅更新当前审批记录
  544. if e = recordItem.Update(recordCols); e != nil {
  545. err = fmt.Errorf("更新审批记录状态失败, Err: %s", e.Error())
  546. return
  547. }
  548. // 其他人已审批且为最后节点
  549. if otherPass && currNode.NextNodeId == 0 {
  550. lastApprove = true
  551. }
  552. // 其他人已审批且不为最后节点, 进入下一节点
  553. if otherPass && currNode.NextNodeId > 0 {
  554. nextNode := nodeMap[currNode.NextNodeId]
  555. approveItem.CurrNodeId = currNode.NextNodeId
  556. approveItem.ModifyTime = now
  557. if e = approveItem.Update([]string{"CurrNodeId", "ModifyTime"}); e != nil {
  558. err = fmt.Errorf("更新审批当前节点失败, Err: %s", e.Error())
  559. return
  560. }
  561. err = BuildNextNodeRecordAndMsg(nextNode, approveItem.ReportApproveId, approveItem.ApplyUserId, approveItem.ApplyUserName)
  562. return
  563. }
  564. }
  565. // 或签
  566. if currNode.ApproveType == report_approve.NodeApproveTypeAny {
  567. // 需检查一下审批的当前节点和记录的节点是否匹配, 不匹配可能是因为另外的审批人已通过, 所以此处应给提示
  568. // 前端也有做相应的判断,但是两个人同时进入审批详情页时就可能出现这种情况
  569. if approveItem.CurrNodeId != recordItem.NodeId {
  570. tips = "该节点已完成审批, 请刷新页面"
  571. return
  572. }
  573. if e = recordItem.Update(recordCols); e != nil {
  574. err = fmt.Errorf("更新审批记录状态失败, Err: %s", e.Error())
  575. return
  576. }
  577. // 将该审批的同一个节点的记录标记为已审批
  578. if e = recordItem.UpdateNodeState(recordItem.ReportApproveId, recordItem.NodeId, recordItem.NodeState, recordItem.NodeApproveUserId, recordItem.NodeApproveUserName, recordItem.NodeApproveTime); e != nil {
  579. err = fmt.Errorf("更新同一节点的其他审批记录状态失败, Err: %s", e.Error())
  580. return
  581. }
  582. if currNode.NextNodeId == 0 {
  583. lastApprove = true
  584. }
  585. if currNode.NextNodeId > 0 {
  586. nextNode := nodeMap[currNode.NextNodeId]
  587. approveItem.CurrNodeId = currNode.NextNodeId
  588. approveItem.ModifyTime = now
  589. if e = approveItem.Update([]string{"CurrNodeId", "ModifyTime"}); e != nil {
  590. err = fmt.Errorf("更新审批当前节点失败, Err: %s", e.Error())
  591. return
  592. }
  593. err = BuildNextNodeRecordAndMsg(nextNode, approveItem.ReportApproveId, approveItem.ApplyUserId, approveItem.ApplyUserName)
  594. return
  595. }
  596. }
  597. // 最后一个审批, 更新审批记录、审批、报告状态、推送消息给申请人
  598. if lastApprove {
  599. if e = recordItem.Update(recordCols); e != nil {
  600. err = fmt.Errorf("更新审批记录状态失败, Err: %s", e.Error())
  601. return
  602. }
  603. approveItem.State = report_approve.ReportApproveStatePass
  604. approveItem.ApproveTime = now
  605. approveItem.ModifyTime = now
  606. approveCols := []string{"State", "ApproveTime", "ModifyTime"}
  607. if e = approveItem.Update(approveCols); e != nil {
  608. err = fmt.Errorf("更新审批信息失败, Err: %s", e.Error())
  609. return
  610. }
  611. if e = updateReportApproveState(approveItem.ReportType, approveItem.ReportId, approveItem.ReportApproveId, models.ReportStatePass); e != nil {
  612. err = fmt.Errorf("更新报告审批状态失败, Err: %s", e.Error())
  613. return
  614. }
  615. go func() {
  616. messageItem := new(report_approve.ReportApproveMessage)
  617. messageItem.SendUserId = sysAdminId
  618. messageItem.ReceiveUserId = approveItem.ApplyUserId
  619. messageItem.Content = "您提交的审批已通过"
  620. messageItem.Remark = "您提交的【研报审批】已通过"
  621. messageItem.ReportApproveId = approveItem.ReportApproveId
  622. messageItem.ApproveState = report_approve.ReportApproveStatePass
  623. messageItem.CreateTime = now
  624. messageItem.ModifyTime = now
  625. if e = messageItem.Create(); e != nil {
  626. utils.FileLog.Info(fmt.Sprintf("PassReportApprove message err: %s", e.Error()))
  627. return
  628. }
  629. }()
  630. // 审批通过之后的处理
  631. go func() {
  632. if e = AfterReportApprovePass(approveItem.ReportType, approveItem.ReportId); e != nil {
  633. utils.FileLog.Info(fmt.Sprintf("AfterReportApprovePass err: %s, ReportType: %d, ReportId: %d", e.Error(), approveItem.ReportType, approveItem.ReportId))
  634. return
  635. }
  636. }()
  637. }
  638. return
  639. }
  640. // RefuseReportApprove 驳回审批
  641. func RefuseReportApprove(approveItem *report_approve.ReportApprove, recordItem *report_approve.ReportApproveRecord, approveRemark string, sysAdminId int) (err error) {
  642. if approveItem == nil {
  643. err = fmt.Errorf("审批信息有误")
  644. return
  645. }
  646. if recordItem == nil {
  647. err = fmt.Errorf("审批记录有误")
  648. return
  649. }
  650. // 更新审批记录
  651. now := time.Now().Local()
  652. recordItem.State = report_approve.ReportApproveStateRefuse
  653. recordItem.ApproveRemark = approveRemark
  654. recordItem.ApproveTime = now
  655. recordItem.ModifyTime = now
  656. recordItem.NodeState = report_approve.ReportApproveStateRefuse
  657. recordItem.NodeApproveUserId = recordItem.ApproveUserId
  658. recordItem.NodeApproveUserName = recordItem.ApproveUserName
  659. recordItem.NodeApproveTime = now
  660. recordCols := []string{"State", "ApproveRemark", "ApproveTime", "ModifyTime", "NodeState", "NodeApproveUserId", "NodeApproveUserName", "NodeApproveTime"}
  661. if e := recordItem.Update(recordCols); e != nil {
  662. err = fmt.Errorf("更新审批记录状态失败, Err: %s", e.Error())
  663. return
  664. }
  665. // 将该审批的同一个节点的记录标记为已审批
  666. if e := recordItem.UpdateNodeState(recordItem.ReportApproveId, recordItem.NodeId, recordItem.NodeState, recordItem.NodeApproveUserId, recordItem.NodeApproveUserName, recordItem.NodeApproveTime); e != nil {
  667. err = fmt.Errorf("更新同一节点的其他审批记录状态失败, Err: %s", e.Error())
  668. return
  669. }
  670. // 驳回-更新审批, 报告状态, 推送消息
  671. approveItem.State = report_approve.ReportApproveStateRefuse
  672. approveItem.ApproveRemark = approveRemark
  673. approveItem.ApproveTime = now
  674. approveItem.ModifyTime = now
  675. approveCols := []string{"State", "ApproveRemark", "ApproveTime", "ModifyTime"}
  676. if e := approveItem.Update(approveCols); e != nil {
  677. err = fmt.Errorf("更新审批状态失败, Err: %s", e.Error())
  678. return
  679. }
  680. if e := updateReportApproveState(approveItem.ReportType, approveItem.ReportId, approveItem.ReportApproveId, models.ReportStateRefused); e != nil {
  681. err = fmt.Errorf("更新报告状态失败, Err: %s", e.Error())
  682. return
  683. }
  684. // 推送驳回消息给申请人
  685. go func() {
  686. messageItem := new(report_approve.ReportApproveMessage)
  687. messageItem.SendUserId = sysAdminId
  688. messageItem.ReceiveUserId = approveItem.ApplyUserId
  689. messageItem.Content = "您提交的审批被驳回"
  690. messageItem.Remark = "您提交的【研报审批】已被驳回"
  691. messageItem.ReportApproveId = approveItem.ReportApproveId
  692. messageItem.ApproveState = report_approve.ReportApproveStateRefuse
  693. messageItem.CreateTime = now
  694. messageItem.ModifyTime = now
  695. if e := messageItem.Create(); e != nil {
  696. utils.FileLog.Info(fmt.Sprintf("ApproveReport message err: %s", e.Error()))
  697. return
  698. }
  699. }()
  700. return
  701. }
  702. // BuildNextNodeRecordAndMsg 生成下一个节点的审批记录并推送消息
  703. func BuildNextNodeRecordAndMsg(approveNodeItem *report_approve.ReportApproveNode, approveId, sysAdminId int, sysAdminName string) (err error) {
  704. if approveNodeItem == nil {
  705. err = fmt.Errorf("approve node nil")
  706. return
  707. }
  708. // 根据节点审批方式生成审批记录
  709. now := time.Now().Local()
  710. approveNode, e := report_approve.FormatReportApproveNode2Item(approveNodeItem)
  711. if e != nil {
  712. err = fmt.Errorf("FormatReportApproveNode2Item err: %s", e.Error())
  713. return
  714. }
  715. if len(approveNode.Users) == 0 {
  716. err = fmt.Errorf("审批节点用户有误")
  717. return
  718. }
  719. newRecords := make([]*report_approve.ReportApproveRecord, 0)
  720. sort.Slice(approveNode.Users, func(k, j int) bool {
  721. return approveNode.Users[k].Sort < approveNode.Users[j].Sort
  722. })
  723. for _, u := range approveNode.Users {
  724. r := new(report_approve.ReportApproveRecord)
  725. r.ReportApproveId = approveId
  726. r.State = report_approve.ReportApproveStateApproving
  727. r.NodeId = approveNode.ReportApproveNodeId
  728. r.PrevNodeId = approveNode.PrevNodeId
  729. r.NextNodeId = approveNode.NextNodeId
  730. r.ApproveType = approveNode.ApproveType
  731. r.ApproveUserId = u.UserId
  732. r.ApproveUserName = u.UserName
  733. r.ApproveUserSort = u.Sort
  734. r.CreateTime = now
  735. r.ModifyTime = now
  736. r.NodeState = report_approve.ReportApproveStateApproving // 当前节点审批状态
  737. newRecords = append(newRecords, r)
  738. // 依次审批仅生成一条记录
  739. if approveNode.ApproveType == report_approve.NodeApproveTypeRoll {
  740. break
  741. }
  742. }
  743. recordOb := new(report_approve.ReportApproveRecord)
  744. if e = recordOb.CreateMulti(newRecords); e != nil {
  745. err = fmt.Errorf("生成节点审批记录失败, Err: %s", e.Error())
  746. return
  747. }
  748. // 推送审批消息
  749. go func() {
  750. messageOb := new(report_approve.ReportApproveMessage)
  751. messages := make([]*report_approve.ReportApproveMessage, 0)
  752. for _, v := range newRecords {
  753. m := new(report_approve.ReportApproveMessage)
  754. m.SendUserId = sysAdminId
  755. m.ReceiveUserId = v.ApproveUserId
  756. m.Content = "您有新的待办任务"
  757. m.Remark = fmt.Sprintf("%s提交的【研报审批】需要您审批,请及时处理", sysAdminName)
  758. m.ReportApproveId = approveId
  759. m.ApproveState = report_approve.ReportApproveStateApproving
  760. m.CreateTime = now
  761. m.ModifyTime = now
  762. messages = append(messages, m)
  763. }
  764. e = messageOb.CreateMulti(messages)
  765. if e != nil {
  766. utils.FileLog.Info(fmt.Sprintf("BuildNextNodeRecordAndMsg messages err: %s", e.Error()))
  767. return
  768. }
  769. }()
  770. return
  771. }
  772. // AfterReportApprovePass 报告审批通过后的处理
  773. func AfterReportApprovePass(reportType, reportId int) (err error) {
  774. // 中文研报
  775. if reportType == report_approve.FlowReportTypeChinese {
  776. reportInfo, e := models.GetReportByReportId(reportId)
  777. if e != nil {
  778. if e.Error() == utils.ErrNoRow() {
  779. return
  780. }
  781. err = fmt.Errorf("获取研报信息失败, Err: %s", e.Error())
  782. return
  783. }
  784. // 重新生成音频,里面还涉及到章节类型的报告
  785. go UpdateReportVideo(reportInfo)
  786. // 生成报告pdf和长图
  787. {
  788. reportPdfUrl := GetGeneralPdfUrl(reportInfo.ReportCode, reportInfo.ClassifyNameFirst, reportInfo.ReportLayout)
  789. go Report2pdfAndJpeg(reportPdfUrl, reportId, 1)
  790. }
  791. //_ = CreateVideo(reportInfo)
  792. _ = UpdateReportEs(reportInfo.Id, models.ReportStatePublished)
  793. return
  794. }
  795. // 英文研报
  796. if reportType == report_approve.FlowReportTypeEnglish {
  797. _ = UpdateEnglishReportEs(reportId, models.ReportStatePublished)
  798. return
  799. }
  800. // 智能研报
  801. if reportType == report_approve.FlowReportTypeSmart {
  802. ob := new(smart_report.SmartReport)
  803. item, e := ob.GetItemById(reportId)
  804. if e != nil {
  805. if e.Error() == utils.ErrNoRow() {
  806. return
  807. }
  808. err = fmt.Errorf("获取智能研报信息失败, Err: %s", e.Error())
  809. return
  810. }
  811. // 写入队列
  812. //var queue smart_report.Report2ImgQueueReq
  813. //queue.ReportType = 2
  814. //queue.ReportCode = item.ReportCode
  815. //_ = utils.Rc.LPush(utils.CACHE_CREATE_REPORT_IMGPDF_QUEUE, queue)
  816. // 生成音频
  817. if item.VideoUrl == "" {
  818. SmartReportBuildVideoAndUpdate(item)
  819. }
  820. // ES更新报告
  821. _ = SmartReportElasticUpsert(item.SmartReportId, models.ReportStatePublished)
  822. }
  823. return
  824. }
  825. // CheckCloseReportApproveConf 校验是否可以关闭报告审批
  826. func CheckCloseReportApproveConf() (yes bool, err error) {
  827. // 查询待审批中的报告数量
  828. count, e := models.GetReportStateCount(models.ReportStateWaitApprove)
  829. if e != nil {
  830. err = fmt.Errorf("查询审批中的报告数量失败, Err: %s", e.Error())
  831. return
  832. }
  833. if count > 0 {
  834. return
  835. }
  836. count, e = models.GetEnglishReportStateCount(models.ReportStateWaitApprove)
  837. if e != nil {
  838. err = fmt.Errorf("查询审批中的英文报告数量失败, Err: %s", e.Error())
  839. return
  840. }
  841. if count > 0 {
  842. return
  843. }
  844. smartOb := new(smart_report.SmartReport)
  845. cond := ` AND state = ?`
  846. pars := make([]interface{}, 0)
  847. pars = append(pars, models.ReportStateWaitApprove)
  848. count, e = smartOb.GetCountByCondition(cond, pars)
  849. if e != nil {
  850. err = fmt.Errorf("查询审批中的智能报告数量失败, Err: %s", e.Error())
  851. return
  852. }
  853. if count > 0 {
  854. return
  855. }
  856. yes = true
  857. return
  858. }
  859. // FlowOperateResetReportState 审批流变化-重置报告的初始状态
  860. func FlowOperateResetReportState(reportType, classifyFirstId, classifySecondId, classifyThirdId, oldState, State int) (err error) {
  861. defer func() {
  862. if err != nil {
  863. tips := fmt.Sprintf("审批流变化-重置报告初始状态失败, ErrMsg: %s", err.Error())
  864. utils.FileLog.Info(tips)
  865. go alarm_msg.SendAlarmMsg(tips, 2)
  866. }
  867. }()
  868. // 中文研报
  869. if reportType == report_approve.FlowReportTypeChinese {
  870. e := models.UpdateReportsStateByCond(classifyFirstId, classifySecondId, classifyThirdId, oldState, State)
  871. if e != nil {
  872. err = fmt.Errorf("UpdateReportsStateByCond err: %s", e.Error())
  873. }
  874. return
  875. }
  876. // 英文研报
  877. if reportType == report_approve.FlowReportTypeEnglish {
  878. e := models.UpdateEnglishReportsStateByCond(classifyFirstId, classifySecondId, oldState, State)
  879. if e != nil {
  880. err = fmt.Errorf("UpdateEnglishReportsStateByCond err: %s", e.Error())
  881. }
  882. return
  883. }
  884. // 智能研报
  885. if reportType == report_approve.FlowReportTypeSmart {
  886. e := smart_report.UpdateSmartReportsStateByCond(classifyFirstId, classifySecondId, oldState, State)
  887. if e != nil {
  888. err = fmt.Errorf("UpdateSmartReportsStateByCond err: %s", e.Error())
  889. }
  890. return
  891. }
  892. return
  893. }
  894. // ConfigChangeResetReportState 审批配置变化-重置报告的初始状态
  895. func ConfigChangeResetReportState(changeType string) (err error) {
  896. defer func() {
  897. if err != nil {
  898. tips := fmt.Sprintf("审批配置变化-重置报告初始状态失败, ErrMsg: %s", err.Error())
  899. utils.FileLog.Info(tips)
  900. go alarm_msg.SendAlarmMsg(tips, 2)
  901. }
  902. }()
  903. // 关闭审批-待提交->未发布
  904. if changeType == "" {
  905. e := models.UpdateReportsStateByCond(0, 0, 0, models.ReportStateWaitSubmit, models.ReportStateUnpublished)
  906. if e != nil {
  907. err = fmt.Errorf("UpdateReportsStateByCond err: %s", e.Error())
  908. }
  909. e = models.UpdateEnglishReportsStateByCond(0, 0, models.ReportStateWaitSubmit, models.ReportStateUnpublished)
  910. if e != nil {
  911. err = fmt.Errorf("UpdateEnglishReportsStateByCond err: %s", e.Error())
  912. }
  913. e = smart_report.UpdateSmartReportsStateByCond(0, 0, models.ReportStateWaitSubmit, models.ReportStateUnpublished)
  914. if e != nil {
  915. err = fmt.Errorf("UpdateSmartReportsStateByCond err: %s", e.Error())
  916. }
  917. return
  918. }
  919. // 开启内部审批-未发布->部分待提交
  920. if changeType == models.BusinessConfReportApproveTypeEta {
  921. flowOb := new(report_approve.ReportApproveFlow)
  922. flows, e := flowOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
  923. if e != nil {
  924. err = fmt.Errorf("GetApproveFlows err: %s", e.Error())
  925. return
  926. }
  927. reportSecondIds, englishSecondIds, smartSecondIds := make([]int, 0), make([]int, 0), make([]int, 0)
  928. for _, v := range flows {
  929. if v.ReportType == report_approve.FlowReportTypeChinese {
  930. reportSecondIds = append(reportSecondIds, v.ClassifySecondId)
  931. continue
  932. }
  933. if v.ReportType == report_approve.FlowReportTypeEnglish {
  934. englishSecondIds = append(englishSecondIds, v.ClassifySecondId)
  935. continue
  936. }
  937. if v.ReportType == report_approve.FlowReportTypeSmart {
  938. smartSecondIds = append(smartSecondIds, v.ClassifySecondId)
  939. }
  940. }
  941. if len(reportSecondIds) > 0 {
  942. e = models.UpdateReportsStateBySecondIds(models.ReportStateUnpublished, models.ReportStateWaitSubmit, reportSecondIds)
  943. if e != nil {
  944. err = fmt.Errorf("UpdateReportsStateBySecondIds err: %s", e.Error())
  945. return
  946. }
  947. }
  948. if len(englishSecondIds) > 0 {
  949. e = models.UpdateEnglishReportsStateBySecondIds(models.ReportStateUnpublished, models.ReportStateWaitSubmit, englishSecondIds)
  950. if e != nil {
  951. err = fmt.Errorf("UpdateEnglishReportsStateBySecondIds err: %s", e.Error())
  952. return
  953. }
  954. }
  955. if len(smartSecondIds) > 0 {
  956. e = smart_report.UpdateSmartReportsStateBySecondIds(models.ReportStateUnpublished, models.ReportStateWaitSubmit, smartSecondIds)
  957. if e != nil {
  958. err = fmt.Errorf("UpdateSmartReportsStateBySecondIds err: %s", e.Error())
  959. return
  960. }
  961. }
  962. return
  963. }
  964. // 开启第三方审批->未发布->待提交
  965. if changeType == models.BusinessConfReportApproveTypeOther {
  966. e := models.UpdateReportsStateByCond(0, 0, 0, models.ReportStateUnpublished, models.ReportStateWaitSubmit)
  967. if e != nil {
  968. err = fmt.Errorf("UpdateReportsStateByCond err: %s", e.Error())
  969. }
  970. e = models.UpdateEnglishReportsStateByCond(0, 0, models.ReportStateUnpublished, models.ReportStateWaitSubmit)
  971. if e != nil {
  972. err = fmt.Errorf("UpdateEnglishReportsStateByCond err: %s", e.Error())
  973. }
  974. e = smart_report.UpdateSmartReportsStateByCond(0, 0, models.ReportStateUnpublished, models.ReportStateWaitSubmit)
  975. if e != nil {
  976. err = fmt.Errorf("UpdateSmartReportsStateByCond err: %s", e.Error())
  977. }
  978. return
  979. }
  980. return
  981. }