瀏覽代碼

只展示最新的推送记录

xyxie 1 周之前
父節點
當前提交
ad8a10216e
共有 2 個文件被更改,包括 30 次插入4 次删除
  1. 5 0
      controllers/report_ice_message.go
  2. 25 4
      models/report_message_config.go

+ 5 - 0
controllers/report_ice_message.go

@@ -114,6 +114,7 @@ func (c *ReportIceMessageController) IceMsgRecord() {
 	classifyType, _ := c.GetInt("ClassifyType")
 	sendStatus, _ := c.GetInt("Status")
 	sendTime := c.GetString("SendTime")
+	reportTitle := c.GetString("ReportTitle")
     
 	if pageSize <= 0 {
 		pageSize = utils.PageSize20
@@ -152,6 +153,10 @@ func (c *ReportIceMessageController) IceMsgRecord() {
 		pars = append(pars, sendStatus)
 	}
 
+	if reportTitle != "" {
+		condition += " AND report_title like ?"
+		pars = append(pars, "%"+reportTitle+"%")
+	}
 	recordObj := new(models.ReportMessageRecord)
 	total, err := recordObj.GetListCount(condition, pars)
 	if err != nil {

+ 25 - 4
models/report_message_config.go

@@ -168,9 +168,24 @@ func (m *ReportMessageConfig) IsExist(classifyId int) (bool, error) {
 
 // 查询消息推送记录列表
 func (m *ReportMessageRecord) GetList(condition string, pars []interface{}, startSize, pageSize int) (list []*ReportMessageRecord, err error) {
-	fields := "*"
-	order := " ORDER BY create_time DESC, message_id DESC"
-	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
+    // 使用子查询获取每组最新的一条记录
+    fields := "*"
+    subQuery := fmt.Sprintf(`
+        SELECT MAX(message_id) as max_id 
+        FROM %s 
+        WHERE 1=1 %s 
+        GROUP BY COALESCE(report_id, ''), COALESCE(ppt_id, ''), receive_admin_id
+    `, m.TableName(), condition)
+    
+    // 主查询使用 IN 子查询获取完整记录
+    sql := fmt.Sprintf(`
+        SELECT %s 
+        FROM %s 
+        WHERE message_id IN (%s)
+        ORDER BY create_time DESC, message_id DESC 
+        LIMIT ?,?
+    `, fields, m.TableName(), subQuery)
+
 	pars = append(pars, startSize)
 	pars = append(pars, pageSize)
 	err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&list).Error
@@ -179,7 +194,13 @@ func (m *ReportMessageRecord) GetList(condition string, pars []interface{}, star
 
 // 查询消息推送记录列表数量
 func (m *ReportMessageRecord) GetListCount(condition string, pars []interface{}) (count int, err error) {
-	sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
+	sql := fmt.Sprintf(`SELECT COUNT(*) 
+        FROM (
+            SELECT 1 
+            FROM %s 
+            WHERE 1=1 %s 
+            GROUP BY COALESCE(report_id, ''), COALESCE(ppt_id, ''), receive_admin_id
+        ) t`, m.TableName(), condition)
 	err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
 	return
 }