فهرست منبع

已推送成功的报告不再重复推送

xyxie 2 روز پیش
والد
کامیت
93eba38c0a
2فایلهای تغییر یافته به همراه58 افزوده شده و 9 حذف شده
  1. 45 9
      controllers/report_ice_message.go
  2. 13 0
      models/report_message_config.go

+ 45 - 9
controllers/report_ice_message.go

@@ -285,6 +285,7 @@ func (c *ReportIceMessageController) IceMsgPush() {
 	var pptInfo *models.PptV2
 	var classifyName string
 	var url string
+	successAdminMap := make(map[int]struct{})
 	// 根据类型判断
 	if classifyType == 1 {// 推送研报
 		if req.ReportId <= 0 {
@@ -318,6 +319,17 @@ func (c *ReportIceMessageController) IceMsgPush() {
 		title = reportInfo.Title
 		content = reportInfo.Title
 		url = reportInfo.DetailPdfUrl
+
+		// 查询当前这篇报告成功的推送记录
+		recordObj := new(models.ReportMessageRecord)
+		adminIds, err := recordObj.GetSuccessRecordAdminIdsByReportId(req.ReportId, title, content, url)
+		if err != nil {
+			br.Msg = "查询失败"
+			br.ErrMsg = "查询失败,Err:" + err.Error()
+		}
+		for _, adminId := range adminIds {
+			successAdminMap[adminId] = struct{}{}
+		}
 	} else if classifyType == 2 {// 推送PPT
 		if req.PptId <= 0 {
 			br.Msg = "PPTID不能为空"
@@ -337,6 +349,17 @@ func (c *ReportIceMessageController) IceMsgPush() {
 		title = pptInfo.Title
 		content = pptInfo.Title
 		url = pptInfo.PptxUrl
+
+		// 查询当前这篇报告成功的推送记录
+		recordObj := new(models.ReportMessageRecord)
+		adminIds, err := recordObj.GetSuccessRecordAdminIdsByPptId(req.PptId, title, content, url)
+		if err != nil {
+			br.Msg = "查询失败"
+			br.ErrMsg = "查询失败,Err:" + err.Error()
+		}
+		for _, adminId := range adminIds {
+			successAdminMap[adminId] = struct{}{}
+		}
 	}
 	// 获取分类名称
 	classify, err := models.GetClassifyById(sendClassifyId)
@@ -389,8 +412,13 @@ func (c *ReportIceMessageController) IceMsgPush() {
 	// 生成推送记录
 	recordList := make([]*models.ReportMessageRecord, 0)
 	successCount := 0
+	needPush := false
     for _, item := range adminList {
 		if item.EmployeeId != "" {
+			if _, ok := successAdminMap[int(item.AdminId)]; ok {
+				continue
+			}
+			needPush = true
 			// 推送模版消息
 			sendStatus := 1
 			// 生成taskId
@@ -421,12 +449,14 @@ func (c *ReportIceMessageController) IceMsgPush() {
 		}
 	}
 	
-	recordObj := new(models.ReportMessageRecord)
-	err = recordObj.BatchAdd(recordList)
-	if err != nil {
-		br.Msg = "推送失败"
-		br.ErrMsg = "推送失败,Err:" + err.Error()
-		return
+	if len(recordList) > 0 {
+		recordObj := new(models.ReportMessageRecord)
+		err = recordObj.BatchAdd(recordList)
+		if err != nil {
+			br.Msg = "推送失败"
+			br.ErrMsg = "推送失败,Err:" + err.Error()
+			return
+		}
 	}
 
 	if successCount > 0 {
@@ -458,9 +488,15 @@ func (c *ReportIceMessageController) IceMsgPush() {
 			MsgSendTime: sendTime,
 		}
 	}else{
-		br.Msg = "推送失败"
-		br.ErrMsg = "推送失败,Err:" + err.Error()
-		br.Ret = 408
+		if !needPush {
+			br.Msg = "已推送成功,请勿重复推送!"
+			br.Success = true
+			br.Ret = 200
+		}else{
+			br.Msg = "推送失败"
+			br.ErrMsg = "推送失败,Err:" + err.Error()
+			br.Ret = 408
+		}
 	}
 }
 

+ 13 - 0
models/report_message_config.go

@@ -232,3 +232,16 @@ func (m *ReportMessageConfig) GetListByClassifyIdList(classifyIdList []int) (lis
 	return
 }
 
+// 查询消息推送记录
+func (m *ReportMessageRecord) GetSuccessRecordAdminIdsByReportId(reportId int, title, content, url string) (adminIds []int, err error) {
+	sql := fmt.Sprintf(`SELECT DISTINCT receive_admin_id FROM %s WHERE report_id = ? AND report_title = ? AND content = ? AND url = ? AND status = 1`, m.TableName())
+	err = global.DmSQL["rddp"].Raw(sql, reportId, title, content, url).Scan(&adminIds).Error
+	return
+}
+
+// 查询消息推送记录
+func (m *ReportMessageRecord) GetSuccessRecordAdminIdsByPptId(pptId int, title, content, url string) (adminIds []int, err error) {
+	sql := fmt.Sprintf(`SELECT DISTINCT receive_admin_id FROM %s WHERE ppt_id = ? AND ppt_title = ? AND ppt_content = ? AND ppt_url = ? AND status = 1`, m.TableName())
+	err = global.DmSQL["rddp"].Raw(sql, pptId, title, content, url).Scan(&adminIds).Error
+	return
+}