report_push_status.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_mini_crm/models"
  5. "eta/eta_mini_crm/models/request"
  6. "eta/eta_mini_crm/models/response"
  7. "eta/eta_mini_crm/utils"
  8. "fmt"
  9. "strconv"
  10. "strings"
  11. "time"
  12. "github.com/rdlucklib/rdluck_tools/paging"
  13. )
  14. type ReportPushStatusController struct {
  15. BaseAuthController
  16. }
  17. // List
  18. // @Title pdf研报列表
  19. // @Description pdf研报列表
  20. // @Param PageSize query int true "每页数据条数"
  21. // @Param CurrentIndex query int true "当前页页码,从1开始"
  22. // @Param ClassifyIds query string true "分类id,可多选用英文,隔开"
  23. // @Param ChartPermissionIds query string true "品种id,可多选用英文,隔开"
  24. // @Param PublishStartDate query string true "发布开始时间"
  25. // @Param PublishEndDate query string true "发布结束时间"
  26. // @Param PushStartDate query string true "推送开始时间"
  27. // @Param PushEndDate query string true "推送结束时间"
  28. // @Param KeyWord query string true "报告标题/创建人"
  29. // @Param SelectedIds query string true "选择的报告id, isSelectAll:为true时,反选"
  30. // @Param IsSelectAll query bool true "是否全选"
  31. // @Param SortParam query string true "排序字段"
  32. // @Param SortType query string true "排序方式"
  33. // @Success 200 {object} models.ReportAuthorResp
  34. // @router /list [get]
  35. func (this *ReportPushStatusController) List() {
  36. br := new(models.BaseResponse).Init()
  37. defer func() {
  38. this.Data["json"] = br
  39. this.ServeJSON()
  40. }()
  41. pageSize, _ := this.GetInt("PageSize")
  42. currentIndex, _ := this.GetInt("CurrentIndex")
  43. classifyIds := this.GetString("ClassifyIds")
  44. selectedIds := this.GetString("SelectedIds")
  45. isSelectAll, _ := this.GetBool("IsSelectAll")
  46. chartPermissionIds := this.GetString("ChartPermissionIds")
  47. publishStartDate := this.GetString("PublishStartDate")
  48. publishEndDate := this.GetString("PublishEndDate")
  49. pushStartDate := this.GetString("PushStartDate")
  50. pushEndDate := this.GetString("PushEndDate")
  51. keyWord := this.GetString("KeyWord")
  52. sortParam := this.GetString("SortParam")
  53. sortType := this.GetString("SortType")
  54. if pageSize <= 0 {
  55. pageSize = utils.PageSize20
  56. }
  57. if currentIndex <= 0 {
  58. currentIndex = 1
  59. }
  60. var condition string
  61. var pars []interface{}
  62. if publishStartDate != "" && publishEndDate != "" {
  63. condition += " AND publish_time >= ?"
  64. publishStartTime, err := time.Parse(utils.FormatDate, publishStartDate)
  65. if err != nil {
  66. br.Msg = "日期格式有误"
  67. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  68. return
  69. }
  70. publishStartDateStr := publishStartTime.Format(utils.FormatDateTime)
  71. pars = append(pars, publishStartDateStr)
  72. condition += " AND publish_time <= ?"
  73. publishEndTime, err := time.Parse(utils.FormatDate, publishEndDate)
  74. if err != nil {
  75. br.Msg = "日期格式有误"
  76. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  77. return
  78. }
  79. publishEndTime = publishEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
  80. publishEndDateStr := publishEndTime.Format(utils.FormatDateTime)
  81. pars = append(pars, publishEndDateStr)
  82. }
  83. if pushStartDate != "" && pushEndDate != "" {
  84. condition += " AND push_time >= ?"
  85. pushStartTime, err := time.Parse(utils.FormatDate, pushStartDate)
  86. if err != nil {
  87. br.Msg = "日期格式有误"
  88. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  89. return
  90. }
  91. pushStartDateStr := pushStartTime.Format(utils.FormatDateTime)
  92. pars = append(pars, pushStartDateStr)
  93. condition += " AND push_time <= ?"
  94. pushEndTime, err := time.Parse(utils.FormatDate, pushEndDate)
  95. if err != nil {
  96. br.Msg = "日期格式有误"
  97. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  98. return
  99. }
  100. pushEndTime = pushEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
  101. pushEndDateStr := pushEndTime.Format(utils.FormatDateTime)
  102. pars = append(pars, pushEndDateStr)
  103. }
  104. if keyWord != "" {
  105. condition += ` AND title like ? `
  106. pars = utils.GetLikeKeywordPars(pars, keyWord, 1)
  107. }
  108. var sortCondition string
  109. if sortParam != "" && sortType != "" {
  110. sortCondition = " ORDER BY "
  111. var param, sort string
  112. switch sortParam {
  113. case "PublishTime":
  114. param = "publish_time"
  115. case "PushTime":
  116. param = "push_time"
  117. }
  118. switch sortType {
  119. case "asc":
  120. sort = " ASC "
  121. case "desc":
  122. sort = " DESC "
  123. }
  124. if param != "" && sort != "" {
  125. sortCondition += param + " " + sort
  126. } else {
  127. sortCondition = ""
  128. }
  129. }
  130. if sortCondition == "" {
  131. sortCondition = ` ORDER BY publish_time DESC `
  132. }
  133. classifyIdList := make([]int, 0)
  134. if classifyIds != "" {
  135. classifyArrStr := strings.Split(classifyIds, ",")
  136. if len(classifyArrStr) > 0 {
  137. for _, v := range classifyArrStr {
  138. tmp, _ := strconv.Atoi(v)
  139. classifyIdList = append(classifyIdList, tmp)
  140. }
  141. }
  142. }
  143. if chartPermissionIds != "" {
  144. idStrs := strings.Split(chartPermissionIds, ",")
  145. idInts := make([]int, 0)
  146. for _, id := range idStrs {
  147. tmp, _ := strconv.Atoi(id)
  148. idInts = append(idInts, tmp)
  149. }
  150. tmpClassifyIds, err := models.GetClassifyIdsListByIds(idInts)
  151. if err != nil {
  152. br.Msg = "获取研报列表失败"
  153. br.ErrMsg = "品种获取分类失败,Err:" + err.Error()
  154. return
  155. }
  156. classifyIdList = append(classifyIdList, tmpClassifyIds...)
  157. }
  158. if len(classifyIdList) > 0 {
  159. classifyStrIds := make([]string, 0)
  160. for _, v := range classifyIdList {
  161. classifyStrIds = append(classifyStrIds, strconv.Itoa(v))
  162. }
  163. classifyList, err := models.GetClassifyListByIds(classifyStrIds)
  164. if err != nil {
  165. br.Msg = "获取研报列表失败"
  166. br.ErrMsg = "获取研报分类失败,Err:" + err.Error()
  167. return
  168. }
  169. childClasifyIdList := make([]int, 0)
  170. for _, v := range classifyList {
  171. if v.HasChild == 0 {
  172. childClasifyIdList = append(childClasifyIdList, v.Id)
  173. }
  174. }
  175. condition += ` AND (classify_id_first IN (%s) AND classify_id_second IN (%s) AND classify_id_third IN (%s))`
  176. condition = fmt.Sprintf(condition, utils.GetOrmReplaceHolder(len(childClasifyIdList)), utils.GetOrmReplaceHolder(len(childClasifyIdList)), utils.GetOrmReplaceHolder(len(childClasifyIdList)))
  177. pars = append(pars, childClasifyIdList, childClasifyIdList, childClasifyIdList)
  178. }
  179. if isSelectAll {
  180. if selectedIds != "" {
  181. selectIdStrs := strings.Split(selectedIds, ",")
  182. if len(selectIdStrs) > 0 {
  183. condition += ` AND report_id NOT IN (` + utils.GetOrmReplaceHolder(len(selectIdStrs)) + `)`
  184. pars = append(pars, selectedIds)
  185. }
  186. }
  187. } else {
  188. if selectedIds != "" {
  189. selectIdStrs := strings.Split(selectedIds, ",")
  190. if len(selectIdStrs) > 0 {
  191. condition += ` AND report_id IN (` + utils.GetOrmReplaceHolder(len(selectIdStrs)) + `)`
  192. pars = append(pars, selectedIds)
  193. }
  194. }
  195. }
  196. startSize := utils.StartIndex(currentIndex, pageSize)
  197. total, err := models.GetReportCountByCondition(condition, pars)
  198. if err != nil {
  199. br.Msg = "获取研报列表失败"
  200. br.ErrMsg = "获取研报列表统计失败,Err:" + err.Error()
  201. return
  202. }
  203. reportList, err := models.GetReportPushStatusListByCondition(condition, pars, startSize, pageSize)
  204. if err != nil {
  205. br.Msg = "获取研报列表失败"
  206. br.ErrMsg = "获取研报列表失败,Err:" + err.Error()
  207. return
  208. }
  209. page := paging.GetPaging(currentIndex, pageSize, total)
  210. resp := new(response.ReportPushStatusResp)
  211. resp.List = reportList
  212. resp.Paging = page
  213. br.Data = resp
  214. br.Msg = "获取成功"
  215. br.Ret = 200
  216. br.Success = true
  217. }
  218. // PushCancel
  219. // @Title 取消推送报告
  220. // @Description 取消推送报告
  221. // @Param request body request.ReportPdfEditReq true "type json string"
  222. // @Success 200 {object} models.ReportAuthorResp
  223. // @router /pushCancel [post]
  224. func (this *ReportPushStatusController) PushCancel() {
  225. br := new(models.BaseResponse).Init()
  226. defer func() {
  227. this.Data["json"] = br
  228. this.ServeJSON()
  229. }()
  230. var req request.ReportPushStatusReq
  231. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  232. br.Msg = "参数错误"
  233. br.ErrMsg = "参数错误,Err:" + err.Error()
  234. return
  235. }
  236. reportPush, err := models.GetReportPushStatusByReportId(req.ReportId, 1)
  237. if err != nil && err.Error() != utils.ErrNoRow() {
  238. br.Msg = "推送失败"
  239. br.ErrMsg = "获取推送消息失败,Err:" + err.Error()
  240. return
  241. }
  242. if reportPush != nil {
  243. reportPush.State = 0
  244. reportPush.ModifyTime = time.Now()
  245. err = reportPush.Update([]string{"state", "modify_time"})
  246. if err != nil {
  247. br.Msg = "取消推送失败"
  248. br.ErrMsg = "取消推送失败,Err:" + err.Error()
  249. return
  250. }
  251. }
  252. br.Msg = "取消推送成功"
  253. br.Success = true
  254. br.Ret = 200
  255. }
  256. // Push
  257. // @Title 推送报告
  258. // @Description 推送报告
  259. // @Param request body request.ReportPdfEditReq true "type json string"
  260. // @Success 200 {object} models.ReportAuthorResp
  261. // @router /push [post]
  262. func (this *ReportPushStatusController) Push() {
  263. br := new(models.BaseResponse).Init()
  264. defer func() {
  265. this.Data["json"] = br
  266. this.ServeJSON()
  267. }()
  268. var req request.ReportPushStatusReq
  269. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  270. br.Msg = "参数错误"
  271. br.ErrMsg = "参数错误,Err:" + err.Error()
  272. return
  273. }
  274. count, err := models.GetReportCountById(req.ReportId)
  275. if err != nil {
  276. br.Msg = "研报未发布或已删除"
  277. br.ErrMsg = "研报查询失败,Err:" + err.Error()
  278. return
  279. }
  280. if count == 0 {
  281. br.Msg = "研报未发布或已删除"
  282. return
  283. }
  284. reportPush, err := models.GetReportPushStatusByReportId(req.ReportId, 0)
  285. if err != nil && err.Error() != utils.ErrNoRow() {
  286. br.Msg = "推送失败"
  287. br.ErrMsg = "获取推送消息失败,Err:" + err.Error()
  288. return
  289. }
  290. if reportPush != nil {
  291. reportPush.State = 1
  292. reportPush.ModifyTime = time.Now()
  293. reportPush.PushTime = time.Now()
  294. err = reportPush.Update([]string{"state", "modify_time", "push_time"})
  295. if err != nil {
  296. br.Msg = "推送失败"
  297. br.ErrMsg = "推送失败,Err:" + err.Error()
  298. return
  299. }
  300. }
  301. br.Msg = "推送成功"
  302. br.Success = true
  303. br.Ret = 200
  304. }
  305. // BatchPush
  306. // @Title 批量推送报告
  307. // @Description 批量推送报告
  308. // @Param request body request.BatchReportModifyPushStatusReq true "type json string"
  309. // @Success 200 {object} models.ReportAuthorResp
  310. // @router /batch/push [post]
  311. func (this *ReportPushStatusController) BatchPush() {
  312. br := new(models.BaseResponse).Init()
  313. defer func() {
  314. this.Data["json"] = br
  315. this.ServeJSON()
  316. }()
  317. var req request.BatchReportModifyPushStatusReq
  318. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  319. br.Msg = "参数错误"
  320. br.ErrMsg = "参数错误,Err:" + err.Error()
  321. return
  322. }
  323. var condition string
  324. var pars []interface{}
  325. if req.PublishStartDate != "" && req.PublishEndDate != "" {
  326. condition += " AND publish_time >= ?"
  327. publishStartTime, err := time.Parse(utils.FormatDate, req.PublishStartDate)
  328. if err != nil {
  329. br.Msg = "日期格式有误"
  330. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  331. return
  332. }
  333. publishStartDateStr := publishStartTime.Format(utils.FormatDateTime)
  334. pars = append(pars, publishStartDateStr)
  335. condition += " AND publish_time <= ?"
  336. publishEndTime, err := time.Parse(utils.FormatDate, req.PublishEndDate)
  337. if err != nil {
  338. br.Msg = "日期格式有误"
  339. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  340. return
  341. }
  342. publishEndTime = publishEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
  343. publishEndDateStr := publishEndTime.Format(utils.FormatDateTime)
  344. pars = append(pars, publishEndDateStr)
  345. }
  346. if req.PushStartDate != "" && req.PushEndDate != "" {
  347. condition += " AND push_time >= ?"
  348. pushStartTime, err := time.Parse(utils.FormatDate, req.PushStartDate)
  349. if err != nil {
  350. br.Msg = "日期格式有误"
  351. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  352. return
  353. }
  354. pushStartDateStr := pushStartTime.Format(utils.FormatDateTime)
  355. pars = append(pars, pushStartDateStr)
  356. condition += " AND push_time <= ?"
  357. pushEndTime, err := time.Parse(utils.FormatDate, req.PushEndDate)
  358. if err != nil {
  359. br.Msg = "日期格式有误"
  360. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  361. return
  362. }
  363. pushEndTime = pushEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
  364. pushEndDateStr := pushEndTime.Format(utils.FormatDateTime)
  365. pars = append(pars, pushEndDateStr)
  366. }
  367. if req.KeyWord != "" {
  368. condition += ` AND title like ? `
  369. pars = utils.GetLikeKeywordPars(pars, req.KeyWord, 1)
  370. }
  371. classifyIdList := make([]int, 0)
  372. classifyIdList = append(classifyIdList, req.ClassifyIds...)
  373. tmpClassifyList, err := models.GetClassifyIdsListByIds(req.ChartPermissionIds)
  374. if err != nil {
  375. br.Msg = "获取研报列表失败"
  376. br.ErrMsg = "品种获取分类失败,Err:" + err.Error()
  377. return
  378. }
  379. classifyIdList = append(classifyIdList, tmpClassifyList...)
  380. if len(classifyIdList) > 0 {
  381. classifyIdList = utils.Unique(classifyIdList)
  382. condition += ` AND (classify_id_first IN (%s) AND classify_id_second IN (%s) AND classify_id_third IN (%s))`
  383. condition = fmt.Sprintf(condition, utils.GetOrmReplaceHolder(len(classifyIdList)), utils.GetOrmReplaceHolder(len(classifyIdList)), utils.GetOrmReplaceHolder(len(classifyIdList)))
  384. pars = append(pars, classifyIdList, classifyIdList, classifyIdList)
  385. }
  386. if req.IsSelectAll {
  387. if len(req.SelectedIds) > 0 {
  388. condition += ` AND report_id NOT IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
  389. pars = append(pars, req.SelectedIds)
  390. }
  391. } else {
  392. if len(req.SelectedIds) > 0 {
  393. condition += ` AND report_id IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
  394. pars = append(pars, req.SelectedIds)
  395. }
  396. }
  397. reportIds, err := models.GetReportIdListByCondition(condition, pars)
  398. if err != nil {
  399. br.Msg = "批量推送失败"
  400. br.ErrMsg = "查询研报失败,Err:" + err.Error()
  401. return
  402. }
  403. reportPush, err := models.GetReportPushStatusByReportIdAndState(reportIds, 0)
  404. if err != nil {
  405. br.Msg = "批量推送失败"
  406. br.ErrMsg = "查询推送状态失败,Err:" + err.Error()
  407. return
  408. }
  409. existReportMap := make(map[int]struct{})
  410. for _, v := range reportPush {
  411. existReportMap[v.ReportId] = struct{}{}
  412. }
  413. existReportIds := make([]int, 0)
  414. for _, v := range reportIds {
  415. if _, ok := existReportMap[v]; ok {
  416. existReportIds = append(existReportIds, v)
  417. }
  418. }
  419. err = models.BatchPushReport(existReportIds)
  420. if err != nil {
  421. br.Msg = "批量推送失败"
  422. br.ErrMsg = "批量修改推送失败,Err:" + err.Error()
  423. return
  424. }
  425. br.Msg = "推送成功"
  426. br.Success = true
  427. br.Ret = 200
  428. }
  429. // BatchPushCancel
  430. // @Title 批量撤销推送报告
  431. // @Description 批量撤销推送报告
  432. // @Param request body request.BatchReportModifyPushStatusReq true "type json string"
  433. // @Success 200 {object} models.ReportAuthorResp
  434. // @router /batch/pushCancel [post]
  435. func (this *ReportPushStatusController) BatchPushCancel() {
  436. br := new(models.BaseResponse).Init()
  437. defer func() {
  438. this.Data["json"] = br
  439. this.ServeJSON()
  440. }()
  441. var req request.BatchReportModifyPushStatusReq
  442. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  443. br.Msg = "参数错误"
  444. br.ErrMsg = "参数错误,Err:" + err.Error()
  445. return
  446. }
  447. var condition string
  448. var pars []interface{}
  449. if req.PublishStartDate != "" && req.PublishEndDate != "" {
  450. condition += " AND publish_time >= ?"
  451. publishStartTime, err := time.Parse(utils.FormatDate, req.PublishStartDate)
  452. if err != nil {
  453. br.Msg = "日期格式有误"
  454. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  455. return
  456. }
  457. publishStartDateStr := publishStartTime.Format(utils.FormatDateTime)
  458. pars = append(pars, publishStartDateStr)
  459. condition += " AND publish_time <= ?"
  460. publishEndTime, err := time.Parse(utils.FormatDate, req.PublishEndDate)
  461. if err != nil {
  462. br.Msg = "日期格式有误"
  463. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  464. return
  465. }
  466. publishEndTime = publishEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
  467. publishEndDateStr := publishEndTime.Format(utils.FormatDateTime)
  468. pars = append(pars, publishEndDateStr)
  469. }
  470. if req.PushStartDate != "" && req.PushEndDate != "" {
  471. condition += " AND push_time >= ?"
  472. pushStartTime, err := time.Parse(utils.FormatDate, req.PushStartDate)
  473. if err != nil {
  474. br.Msg = "日期格式有误"
  475. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  476. return
  477. }
  478. pushStartDateStr := pushStartTime.Format(utils.FormatDateTime)
  479. pars = append(pars, pushStartDateStr)
  480. condition += " AND push_time <= ?"
  481. pushEndTime, err := time.Parse(utils.FormatDate, req.PushEndDate)
  482. if err != nil {
  483. br.Msg = "日期格式有误"
  484. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  485. return
  486. }
  487. pushEndTime = pushEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
  488. pushEndDateStr := pushEndTime.Format(utils.FormatDateTime)
  489. pars = append(pars, pushEndDateStr)
  490. }
  491. if req.KeyWord != "" {
  492. condition += ` AND title like ? `
  493. pars = utils.GetLikeKeywordPars(pars, req.KeyWord, 1)
  494. }
  495. classifyIdList := make([]int, 0)
  496. classifyIdList = append(classifyIdList, req.ClassifyIds...)
  497. tmpClassifyList, err := models.GetClassifyIdsListByIds(req.ChartPermissionIds)
  498. if err != nil {
  499. br.Msg = "获取研报列表失败"
  500. br.ErrMsg = "品种获取分类失败,Err:" + err.Error()
  501. return
  502. }
  503. classifyIdList = append(classifyIdList, tmpClassifyList...)
  504. if len(classifyIdList) > 0 {
  505. classifyIdList = utils.Unique(classifyIdList)
  506. condition += ` AND (classify_id_first IN (%s) AND classify_id_second IN (%s) AND classify_id_third IN (%s))`
  507. condition = fmt.Sprintf(condition, utils.GetOrmReplaceHolder(len(classifyIdList)), utils.GetOrmReplaceHolder(len(classifyIdList)), utils.GetOrmReplaceHolder(len(classifyIdList)))
  508. pars = append(pars, classifyIdList, classifyIdList, classifyIdList)
  509. }
  510. if req.IsSelectAll {
  511. if len(req.SelectedIds) > 0 {
  512. condition += ` AND report_id NOT IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
  513. pars = append(pars, req.SelectedIds)
  514. }
  515. } else {
  516. if len(req.SelectedIds) > 0 {
  517. condition += ` AND report_id IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
  518. pars = append(pars, req.SelectedIds)
  519. }
  520. }
  521. reportIds, err := models.GetReportIdListByCondition(condition, pars)
  522. if err != nil {
  523. br.Msg = "批量推送失败"
  524. br.ErrMsg = "查询研报失败,Err:" + err.Error()
  525. return
  526. }
  527. reportPush, err := models.GetReportPushStatusByReportIdAndState(reportIds, 1)
  528. if err != nil {
  529. br.Msg = "批量推送失败"
  530. br.ErrMsg = "查询推送状态失败,Err:" + err.Error()
  531. return
  532. }
  533. existReportMap := make(map[int]struct{})
  534. for _, v := range reportPush {
  535. existReportMap[v.ReportId] = struct{}{}
  536. }
  537. existReportIds := make([]int, 0)
  538. for _, v := range reportIds {
  539. if _, ok := existReportMap[v]; ok {
  540. existReportIds = append(existReportIds, v)
  541. }
  542. }
  543. err = models.BatchPushCancelReport(existReportIds)
  544. if err != nil {
  545. br.Msg = "批量取消推送失败"
  546. br.ErrMsg = "批量修改推送失败,Err:" + err.Error()
  547. return
  548. }
  549. br.Msg = "撤销推送成功"
  550. br.Success = true
  551. br.Ret = 200
  552. }