query.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package report
  2. import (
  3. "hongze/hongze_yb/global"
  4. )
  5. func GetLatestClassReportsByIDs(reportIDs []int) (reportList []*Report, err error) {
  6. sql := `SELECT
  7. max( publish_time ) as publish_time,
  8. classify_id_first,
  9. classify_name_first,
  10. title,
  11. classify_id_second,
  12. classify_name_second,
  13. id,
  14. stage
  15. FROM
  16. report
  17. WHERE
  18. state = 2
  19. AND id IN ?
  20. GROUP BY
  21. classify_id_first`
  22. err = global.MYSQL["rddp"].Raw(sql, reportIDs).Scan(&reportList).Error
  23. return
  24. }
  25. // GetReportsByIDsAndDate 根据时间和报告ID筛选出合适的记录
  26. func GetReportsByIDsAndDate( ids []int, publishTime string) (reportList []*Report, err error) {
  27. err = global.MYSQL["rddp"].Model(Report{}).
  28. Select("id, classify_name_first").
  29. Where("id in (?) and state = 2 and publish_time > ? ", ids, publishTime).Scan(&reportList).Error
  30. return
  31. }
  32. // GetReportsByIDsAndDateAndClass 根据时间和报告ID筛选出合适的记录
  33. func GetReportsByIDsAndDateAndClass( ids []int, classifyNameFirst string, publishTime string) (reportList []*Report, err error) {
  34. err = global.MYSQL["rddp"].Model(Report{}).
  35. Select("id, classify_name_first").
  36. Where("id in (?) and state = 2 and classify_name_first = ? and publish_time > ? ", ids, classifyNameFirst, publishTime).Scan(&reportList).Error
  37. return
  38. }
  39. // GetListByIDsAndClassID 分页查询
  40. func GetListByIDsAndClassID( ids []int, classifyNameFirst string, offset , limit int) (reportList []*Report, err error) {
  41. err = global.MYSQL["rddp"].Model(Report{}).
  42. Select("id, classify_id_first, classify_name_first, classify_id_second, classify_name_second, title, stage, publish_time").
  43. Where("id in (?) and classify_name_first=? and state = 2 ", ids, classifyNameFirst).
  44. Order("publish_time desc, id desc").
  45. Offset(offset).
  46. Limit(limit).
  47. Scan(&reportList).Error
  48. return
  49. }
  50. // GetListByClass 按照类型分页查询
  51. func GetListByClass(classifyNameFirst string, offset , limit int) (reportList []*Report, err error) {
  52. err = global.MYSQL["rddp"].Model(Report{}).
  53. Select("id, classify_id_first, classify_name_first, classify_id_second, classify_name_second, title, stage, publish_time").
  54. Where("classify_name_first=? and state = 2 ", classifyNameFirst).
  55. Order("publish_time desc, id desc").
  56. Offset(offset).
  57. Limit(limit).
  58. Scan(&reportList).Error
  59. return
  60. }
  61. // GetByReportId 根据id获取报告
  62. func GetByReportId(id int) (item *Report, err error) {
  63. err = global.MYSQL["rddp"].Where("id = ? and state = 2", id).First(&item).Error
  64. return
  65. }
  66. func GetLatestDay() (item *Report, err error) {
  67. err = global.MYSQL["rddp"].Where("state = 2 and classify_name_first= 'day'").Order("publish_time desc, id desc").First(&item).Error
  68. return
  69. }