report_push_status.go 19 KB

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