package report import ( "hongze/hongze_yb/global" ) func GetLatestClassReportsByIDs(reportIDs []int) (reportList []*Report, err error) { sql := `SELECT max( publish_time ) as publish_time, classify_id_first, classify_name_first, title, classify_id_second, classify_name_second, id, stage FROM report WHERE state = 2 AND id IN ? GROUP BY classify_id_first` err = global.MYSQL["rddp"].Raw(sql, reportIDs).Scan(&reportList).Error return } // GetReportsByIDsAndDate 根据时间和报告ID筛选出合适的记录 func GetReportsByIDsAndDate( ids []int, publishTime string) (reportList []*Report, err error) { err = global.MYSQL["rddp"].Model(Report{}). Select("id, classify_name_first"). Where("id in (?) and state = 2 and publish_time > ? ", ids, publishTime).Scan(&reportList).Error return } // GetReportsByIDsAndDateAndClass 根据时间和报告ID筛选出合适的记录 func GetReportsByIDsAndDateAndClass( ids []int, classifyNameFirst string, publishTime string) (reportList []*Report, err error) { err = global.MYSQL["rddp"].Model(Report{}). Select("id, classify_name_first"). Where("id in (?) and state = 2 and classify_name_first = ? and publish_time > ? ", ids, classifyNameFirst, publishTime).Scan(&reportList).Error return } // GetListByIDsAndClassID 分页查询 func GetListByIDsAndClassID( ids []int, classifyNameFirst string, offset , limit int) (reportList []*Report, err error) { err = global.MYSQL["rddp"].Model(Report{}). Select("id, classify_id_first, classify_name_first, classify_id_second, classify_name_second, title, stage, publish_time"). Where("id in (?) and classify_name_first=? and state = 2 ", ids, classifyNameFirst). Order("publish_time desc, id desc"). Offset(offset). Limit(limit). Scan(&reportList).Error return } // GetListByClass 按照类型分页查询 func GetListByClass(classifyNameFirst string, offset , limit int) (reportList []*Report, err error) { err = global.MYSQL["rddp"].Model(Report{}). Select("id, classify_id_first, classify_name_first, classify_id_second, classify_name_second, title, stage, publish_time"). Where("classify_name_first=? and state = 2 ", classifyNameFirst). Order("publish_time desc, id desc"). Offset(offset). Limit(limit). Scan(&reportList).Error return } // GetByReportId 根据id获取报告 func GetByReportId(id int) (item *Report, err error) { err = global.MYSQL["rddp"].Where("id = ? and state = 2", id).First(&item).Error return } func GetLatestDay() (item *Report, err error) { err = global.MYSQL["rddp"].Where("state = 2 and classify_name_first= 'day'").Order("publish_time desc, id desc").First(&item).Error return }