report_push_status.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  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. if len(tmpClassifyIds) == 0 {
  157. resp := new(response.ReportPushStatusResp)
  158. br.Data = resp
  159. br.Msg = "查询成功"
  160. br.Success = true
  161. br.Ret = 200
  162. return
  163. }
  164. classifyIdList = append(classifyIdList, tmpClassifyIds...)
  165. }
  166. if len(classifyIdList) > 0 {
  167. classifyStrIds := make([]string, 0)
  168. for _, v := range classifyIdList {
  169. classifyStrIds = append(classifyStrIds, strconv.Itoa(v))
  170. }
  171. classifyList, err := models.GetClassifyListByIds(classifyStrIds)
  172. if err != nil {
  173. br.Msg = "获取研报列表失败"
  174. br.ErrMsg = "获取研报分类失败,Err:" + err.Error()
  175. return
  176. }
  177. childClasifyIdList := make([]int, 0)
  178. for _, v := range classifyList {
  179. if v.HasChild == 0 {
  180. childClasifyIdList = append(childClasifyIdList, v.Id)
  181. }
  182. }
  183. condition += ` AND (classify_id_first IN (%s) OR classify_id_second IN (%s) OR classify_id_third IN (%s))`
  184. condition = fmt.Sprintf(condition, utils.GetOrmReplaceHolder(len(childClasifyIdList)), utils.GetOrmReplaceHolder(len(childClasifyIdList)), utils.GetOrmReplaceHolder(len(childClasifyIdList)))
  185. pars = append(pars, childClasifyIdList, childClasifyIdList, childClasifyIdList)
  186. }
  187. if isSelectAll {
  188. if selectedIds != "" {
  189. selectIdStrs := strings.Split(selectedIds, ",")
  190. if len(selectIdStrs) > 0 {
  191. condition += ` AND report_id NOT IN (` + utils.GetOrmReplaceHolder(len(selectIdStrs)) + `)`
  192. pars = append(pars, selectIdStrs)
  193. }
  194. }
  195. } else {
  196. if selectedIds != "" {
  197. selectIdStrs := strings.Split(selectedIds, ",")
  198. if len(selectIdStrs) > 0 {
  199. condition += ` AND report_id IN (` + utils.GetOrmReplaceHolder(len(selectIdStrs)) + `)`
  200. pars = append(pars, selectIdStrs)
  201. }
  202. }
  203. }
  204. startSize := utils.StartIndex(currentIndex, pageSize)
  205. total, err := models.GetReportCountByCondition(condition, pars)
  206. if err != nil {
  207. br.Msg = "获取研报列表失败"
  208. br.ErrMsg = "获取研报列表统计失败,Err:" + err.Error()
  209. return
  210. }
  211. reportList, err := models.GetReportPushStatusListByCondition(condition, pars, startSize, pageSize)
  212. if err != nil {
  213. br.Msg = "获取研报列表失败"
  214. br.ErrMsg = "获取研报列表失败,Err:" + err.Error()
  215. return
  216. }
  217. page := paging.GetPaging(currentIndex, pageSize, total)
  218. resp := new(response.ReportPushStatusResp)
  219. resp.List = reportList
  220. resp.Paging = page
  221. br.Data = resp
  222. br.Msg = "获取成功"
  223. br.Ret = 200
  224. br.Success = true
  225. }
  226. // PushCancel
  227. // @Title 取消推送报告
  228. // @Description 取消推送报告
  229. // @Param request body request.ReportPdfEditReq true "type json string"
  230. // @Success 200 {object} models.ReportAuthorResp
  231. // @router /pushCancel [post]
  232. func (this *ReportPushStatusController) PushCancel() {
  233. br := new(models.BaseResponse).Init()
  234. defer func() {
  235. this.Data["json"] = br
  236. this.ServeJSON()
  237. }()
  238. var req request.ReportPushStatusReq
  239. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  240. br.Msg = "参数错误"
  241. br.ErrMsg = "参数错误,Err:" + err.Error()
  242. return
  243. }
  244. reportPush, err := models.GetReportPushStatusByReportId(req.ReportId, 1)
  245. if err != nil && err.Error() != utils.ErrNoRow() {
  246. br.Msg = "推送失败"
  247. br.ErrMsg = "获取推送消息失败,Err:" + err.Error()
  248. return
  249. }
  250. if reportPush != nil {
  251. reportPush.State = 0
  252. reportPush.ModifyTime = time.Now()
  253. err = reportPush.Update([]string{"state", "modify_time"})
  254. if err != nil {
  255. br.Msg = "取消推送失败"
  256. br.ErrMsg = "取消推送失败,Err:" + err.Error()
  257. return
  258. }
  259. }
  260. br.Msg = "取消推送成功"
  261. br.Success = true
  262. br.Ret = 200
  263. }
  264. // Push
  265. // @Title 推送报告
  266. // @Description 推送报告
  267. // @Param request body request.ReportPdfEditReq true "type json string"
  268. // @Success 200 {object} models.ReportAuthorResp
  269. // @router /push [post]
  270. func (this *ReportPushStatusController) Push() {
  271. br := new(models.BaseResponse).Init()
  272. defer func() {
  273. this.Data["json"] = br
  274. this.ServeJSON()
  275. }()
  276. var req request.ReportPushStatusReq
  277. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  278. br.Msg = "参数错误"
  279. br.ErrMsg = "参数错误,Err:" + err.Error()
  280. return
  281. }
  282. count, err := models.GetReportCountById(req.ReportId)
  283. if err != nil {
  284. br.Msg = "研报未发布或已删除"
  285. br.ErrMsg = "研报查询失败,Err:" + err.Error()
  286. return
  287. }
  288. if count == 0 {
  289. br.Msg = "研报未发布或已删除"
  290. return
  291. }
  292. reportPush, err := models.GetReportPushStatusByReportId(req.ReportId, 0)
  293. if err != nil && err.Error() != utils.ErrNoRow() {
  294. br.Msg = "推送失败"
  295. br.ErrMsg = "获取推送消息失败,Err:" + err.Error()
  296. return
  297. }
  298. if reportPush != nil {
  299. reportPush.State = 1
  300. reportPush.ModifyTime = time.Now()
  301. reportPush.PushTime = time.Now()
  302. err = reportPush.Update([]string{"state", "modify_time", "push_time"})
  303. if err != nil {
  304. br.Msg = "推送失败"
  305. br.ErrMsg = "推送失败,Err:" + err.Error()
  306. return
  307. }
  308. }
  309. br.Msg = "推送成功"
  310. br.Success = true
  311. br.Ret = 200
  312. }
  313. // BatchPush
  314. // @Title 批量推送报告
  315. // @Description 批量推送报告
  316. // @Param request body request.BatchReportModifyPushStatusReq true "type json string"
  317. // @Success 200 {object} models.ReportAuthorResp
  318. // @router /batch/push [post]
  319. func (this *ReportPushStatusController) BatchPush() {
  320. br := new(models.BaseResponse).Init()
  321. defer func() {
  322. this.Data["json"] = br
  323. this.ServeJSON()
  324. }()
  325. var req request.BatchReportModifyPushStatusReq
  326. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  327. br.Msg = "参数错误"
  328. br.ErrMsg = "参数错误,Err:" + err.Error()
  329. return
  330. }
  331. var condition string
  332. var pars []interface{}
  333. if req.PublishStartDate != "" && req.PublishEndDate != "" {
  334. condition += " AND publish_time >= ?"
  335. publishStartTime, err := time.Parse(utils.FormatDate, req.PublishStartDate)
  336. if err != nil {
  337. br.Msg = "日期格式有误"
  338. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  339. return
  340. }
  341. publishStartDateStr := publishStartTime.Format(utils.FormatDateTime)
  342. pars = append(pars, publishStartDateStr)
  343. condition += " AND publish_time <= ?"
  344. publishEndTime, err := time.Parse(utils.FormatDate, req.PublishEndDate)
  345. if err != nil {
  346. br.Msg = "日期格式有误"
  347. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  348. return
  349. }
  350. publishEndTime = publishEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
  351. publishEndDateStr := publishEndTime.Format(utils.FormatDateTime)
  352. pars = append(pars, publishEndDateStr)
  353. }
  354. if req.PushStartDate != "" && req.PushEndDate != "" {
  355. condition += " AND push_time >= ?"
  356. pushStartTime, err := time.Parse(utils.FormatDate, req.PushStartDate)
  357. if err != nil {
  358. br.Msg = "日期格式有误"
  359. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  360. return
  361. }
  362. pushStartDateStr := pushStartTime.Format(utils.FormatDateTime)
  363. pars = append(pars, pushStartDateStr)
  364. condition += " AND push_time <= ?"
  365. pushEndTime, err := time.Parse(utils.FormatDate, req.PushEndDate)
  366. if err != nil {
  367. br.Msg = "日期格式有误"
  368. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  369. return
  370. }
  371. pushEndTime = pushEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
  372. pushEndDateStr := pushEndTime.Format(utils.FormatDateTime)
  373. pars = append(pars, pushEndDateStr)
  374. }
  375. if req.KeyWord != "" {
  376. condition += ` AND title like ? `
  377. pars = utils.GetLikeKeywordPars(pars, req.KeyWord, 1)
  378. }
  379. classifyIdList := make([]int, 0)
  380. classifyIdList = append(classifyIdList, req.ClassifyIds...)
  381. tmpClassifyList, err := models.GetClassifyIdsListByIds(req.ChartPermissionIds)
  382. if err != nil {
  383. br.Msg = "获取研报列表失败"
  384. br.ErrMsg = "品种获取分类失败,Err:" + err.Error()
  385. return
  386. }
  387. classifyIdList = append(classifyIdList, tmpClassifyList...)
  388. if len(classifyIdList) > 0 {
  389. classifyIdList = utils.Unique(classifyIdList)
  390. condition += ` AND (classify_id_first IN (%s) AND classify_id_second IN (%s) AND classify_id_third IN (%s))`
  391. condition = fmt.Sprintf(condition, utils.GetOrmReplaceHolder(len(classifyIdList)), utils.GetOrmReplaceHolder(len(classifyIdList)), utils.GetOrmReplaceHolder(len(classifyIdList)))
  392. pars = append(pars, classifyIdList, classifyIdList, classifyIdList)
  393. }
  394. if req.IsSelectAll {
  395. if len(req.SelectedIds) > 0 {
  396. condition += ` AND report_id NOT IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
  397. pars = append(pars, req.SelectedIds)
  398. }
  399. } else {
  400. if len(req.SelectedIds) > 0 {
  401. condition += ` AND report_id IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
  402. pars = append(pars, req.SelectedIds)
  403. }
  404. }
  405. reportIds, err := models.GetReportIdListByCondition(condition, pars)
  406. if err != nil {
  407. br.Msg = "批量推送失败"
  408. br.ErrMsg = "查询研报失败,Err:" + err.Error()
  409. return
  410. }
  411. reportPush, err := models.GetReportPushStatusByReportIdAndState(reportIds, 0)
  412. if err != nil {
  413. br.Msg = "批量推送失败"
  414. br.ErrMsg = "查询推送状态失败,Err:" + err.Error()
  415. return
  416. }
  417. existReportMap := make(map[int]struct{})
  418. for _, v := range reportPush {
  419. existReportMap[v.ReportId] = struct{}{}
  420. }
  421. existReportIds := make([]int, 0)
  422. for _, v := range reportIds {
  423. if _, ok := existReportMap[v]; ok {
  424. existReportIds = append(existReportIds, v)
  425. }
  426. }
  427. err = models.BatchPushReport(existReportIds)
  428. if err != nil {
  429. br.Msg = "批量推送失败"
  430. br.ErrMsg = "批量修改推送失败,Err:" + err.Error()
  431. return
  432. }
  433. br.Msg = "推送成功"
  434. br.Success = true
  435. br.Ret = 200
  436. }
  437. // BatchPushCancel
  438. // @Title 批量撤销推送报告
  439. // @Description 批量撤销推送报告
  440. // @Param request body request.BatchReportModifyPushStatusReq true "type json string"
  441. // @Success 200 {object} models.ReportAuthorResp
  442. // @router /batch/pushCancel [post]
  443. func (this *ReportPushStatusController) BatchPushCancel() {
  444. br := new(models.BaseResponse).Init()
  445. defer func() {
  446. this.Data["json"] = br
  447. this.ServeJSON()
  448. }()
  449. var req request.BatchReportModifyPushStatusReq
  450. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  451. br.Msg = "参数错误"
  452. br.ErrMsg = "参数错误,Err:" + err.Error()
  453. return
  454. }
  455. var condition string
  456. var pars []interface{}
  457. if req.PublishStartDate != "" && req.PublishEndDate != "" {
  458. condition += " AND publish_time >= ?"
  459. publishStartTime, err := time.Parse(utils.FormatDate, req.PublishStartDate)
  460. if err != nil {
  461. br.Msg = "日期格式有误"
  462. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  463. return
  464. }
  465. publishStartDateStr := publishStartTime.Format(utils.FormatDateTime)
  466. pars = append(pars, publishStartDateStr)
  467. condition += " AND publish_time <= ?"
  468. publishEndTime, err := time.Parse(utils.FormatDate, req.PublishEndDate)
  469. if err != nil {
  470. br.Msg = "日期格式有误"
  471. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  472. return
  473. }
  474. publishEndTime = publishEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
  475. publishEndDateStr := publishEndTime.Format(utils.FormatDateTime)
  476. pars = append(pars, publishEndDateStr)
  477. }
  478. if req.PushStartDate != "" && req.PushEndDate != "" {
  479. condition += " AND push_time >= ?"
  480. pushStartTime, err := time.Parse(utils.FormatDate, req.PushStartDate)
  481. if err != nil {
  482. br.Msg = "日期格式有误"
  483. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  484. return
  485. }
  486. pushStartDateStr := pushStartTime.Format(utils.FormatDateTime)
  487. pars = append(pars, pushStartDateStr)
  488. condition += " AND push_time <= ?"
  489. pushEndTime, err := time.Parse(utils.FormatDate, req.PushEndDate)
  490. if err != nil {
  491. br.Msg = "日期格式有误"
  492. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  493. return
  494. }
  495. pushEndTime = pushEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
  496. pushEndDateStr := pushEndTime.Format(utils.FormatDateTime)
  497. pars = append(pars, pushEndDateStr)
  498. }
  499. if req.KeyWord != "" {
  500. condition += ` AND title like ? `
  501. pars = utils.GetLikeKeywordPars(pars, req.KeyWord, 1)
  502. }
  503. classifyIdList := make([]int, 0)
  504. classifyIdList = append(classifyIdList, req.ClassifyIds...)
  505. tmpClassifyList, err := models.GetClassifyIdsListByIds(req.ChartPermissionIds)
  506. if err != nil {
  507. br.Msg = "获取研报列表失败"
  508. br.ErrMsg = "品种获取分类失败,Err:" + err.Error()
  509. return
  510. }
  511. classifyIdList = append(classifyIdList, tmpClassifyList...)
  512. if len(classifyIdList) > 0 {
  513. classifyIdList = utils.Unique(classifyIdList)
  514. condition += ` AND (classify_id_first IN (%s) AND classify_id_second IN (%s) AND classify_id_third IN (%s))`
  515. condition = fmt.Sprintf(condition, utils.GetOrmReplaceHolder(len(classifyIdList)), utils.GetOrmReplaceHolder(len(classifyIdList)), utils.GetOrmReplaceHolder(len(classifyIdList)))
  516. pars = append(pars, classifyIdList, classifyIdList, classifyIdList)
  517. }
  518. if req.IsSelectAll {
  519. if len(req.SelectedIds) > 0 {
  520. condition += ` AND report_id NOT IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
  521. pars = append(pars, req.SelectedIds)
  522. }
  523. } else {
  524. if len(req.SelectedIds) > 0 {
  525. condition += ` AND report_id IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
  526. pars = append(pars, req.SelectedIds)
  527. }
  528. }
  529. reportIds, err := models.GetReportIdListByCondition(condition, pars)
  530. if err != nil {
  531. br.Msg = "批量推送失败"
  532. br.ErrMsg = "查询研报失败,Err:" + err.Error()
  533. return
  534. }
  535. reportPush, err := models.GetReportPushStatusByReportIdAndState(reportIds, 1)
  536. if err != nil {
  537. br.Msg = "批量推送失败"
  538. br.ErrMsg = "查询推送状态失败,Err:" + err.Error()
  539. return
  540. }
  541. existReportMap := make(map[int]struct{})
  542. for _, v := range reportPush {
  543. existReportMap[v.ReportId] = struct{}{}
  544. }
  545. existReportIds := make([]int, 0)
  546. for _, v := range reportIds {
  547. if _, ok := existReportMap[v]; ok {
  548. existReportIds = append(existReportIds, v)
  549. }
  550. }
  551. err = models.BatchPushCancelReport(existReportIds)
  552. if err != nil {
  553. br.Msg = "批量取消推送失败"
  554. br.ErrMsg = "批量修改推送失败,Err:" + err.Error()
  555. return
  556. }
  557. br.Msg = "撤销推送成功"
  558. br.Success = true
  559. br.Ret = 200
  560. }