ソースを参照

营销系统-手动推送

wangcl 1 週間 前
コミット
a9c790383b

+ 3 - 0
pig-marketing/pig-marketing-api/src/main/java/com/pig4cloud/pig/marketing/api/dto/MktMgmtPushRecordSaveDTO.java

@@ -28,5 +28,8 @@ public class MktMgmtPushRecordSaveDTO implements Serializable {
     @Schema(description = "推送域名", example = "baidu.com")
     private String pushDomain;
 
+	@Schema(description = "客户端id", example = "admin")
+	private String clientId;
+
 
 }

+ 7 - 0
pig-marketing/pig-marketing-api/src/main/java/com/pig4cloud/pig/marketing/api/entity/MktMgmtPushRecord.java

@@ -61,6 +61,13 @@ public class MktMgmtPushRecord extends Model<MktMgmtPushRecord> {
 	@Schema(description = "推送方式")
 	private String pushAction;
 
+	/**
+	 * 客户端id
+	 */
+    @Schema(description = "客户端id")
+	private String clientId;
+
+
 	/**
 	 * 延时推送时间
 	 */

+ 3 - 0
pig-marketing/pig-marketing-api/src/main/java/com/pig4cloud/pig/marketing/api/vo/rule/push/HandPushVO.java

@@ -35,6 +35,9 @@ public class HandPushVO {
 	@Schema(description = "推送状态")
 	private Boolean pushStatus;
 
+	@Schema(description = "客户端id", example = "admin")
+	private String clientId;
+
 	/**
 	 * 推送方式
 	 */

+ 2 - 1
pig-marketing/pig-marketing-biz/src/main/java/com/pig4cloud/pig/marketing/service/impl/MktMgmtHandPushServiceImpl.java

@@ -98,7 +98,7 @@ public class MktMgmtHandPushServiceImpl implements MktMgmtHandPushService {
             }
             
             // 4. 校验推送频率
-            if (!PushFrequencyUtil.checkPushFrequency(globalRule.getPushFrequency(), 0L, saveDTO.getPushContent(), redisTemplate)) {
+            if (!PushFrequencyUtil.checkPushFrequency(globalRule.getPushFrequency(), 0L, saveDTO.getClientId(), redisTemplate)) {
                 return "推送频率检查未通过,推送频率:" + globalRule.getPushFrequency();
             }
             
@@ -246,6 +246,7 @@ public class MktMgmtHandPushServiceImpl implements MktMgmtHandPushService {
         pushRecord.setRuleId(0L); // 全局规则ID为0
         pushRecord.setRuleName("全局手动推送规则");
         pushRecord.setPushContent(globalRule.getPushContent());
+		pushRecord.setClientId(saveDTO.getClientId());
         pushRecord.setAutoPush(1);
         pushRecord.setPushStatus(true);
 		pushRecord.setPushFrequency(globalRule.getPushFrequency());

+ 1 - 0
pig-marketing/pig-marketing-biz/src/main/java/com/pig4cloud/pig/marketing/service/impl/MktMgmtPushRecordServiceImpl.java

@@ -164,6 +164,7 @@ public class MktMgmtPushRecordServiceImpl implements MktMgmtPushRecordService {
 
 		MktMgmtPushRecord record = new MktMgmtPushRecord();
 		record.setPushContent(selectedRule.getPushContent());
+		record.setClientId(saveDTO.getClientId());
 		record.setRuleName(selectedRule.getRuleName());
 		record.setPushFrequency(selectedRule.getPushFrequency());
 		record.setPushStatus(true); // 总为1-成功

+ 2 - 6
pig-marketing/pig-marketing-biz/src/main/java/com/pig4cloud/pig/marketing/service/impl/TcpDataServiceImpl.java

@@ -213,20 +213,16 @@ import java.util.stream.Collectors;
 		message.setReportTime(LocalDateTime.now().format(DATE_TIME_FORMATTER));
 		Message save = messageRepository.save(message);
 		MktMgmtPushRecordSaveDTO saveRecordDTO = new MktMgmtPushRecordSaveDTO();
-		MktMgmtPushRecordSaveDTO handDTO = new MktMgmtPushRecordSaveDTO();
 		String s = "";
 		String hand = "";
 		if (save.getId() != null) {
 			saveRecordDTO.setPushContent(reqDto.getMsgData());
 			saveRecordDTO.setPushIP(reqDto.getClientIP());
 			saveRecordDTO.setPushDomain(reqDto.getClientDomain());
-
-			handDTO.setPushContent(reqDto.getMsgData());
-			handDTO.setPushIP(reqDto.getClientIP());
-			handDTO.setPushDomain(reqDto.getClientDomain());
+			saveRecordDTO.setClientId(reqDto.getClientID());
 
 			s = mktMgmtPushRecordService.saveRecord(saveRecordDTO);
-			hand = mktMgmtHandPushService.handPush(handDTO);
+			hand = mktMgmtHandPushService.handPush(saveRecordDTO);
 		}
 
 

+ 9 - 11
pig-marketing/pig-marketing-biz/src/main/java/com/pig4cloud/pig/marketing/util/PushFrequencyUtil.java

@@ -5,7 +5,6 @@ import org.springframework.data.redis.core.RedisTemplate;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.util.UUID;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -23,11 +22,11 @@ public class PushFrequencyUtil {
      * 
      * @param pushFrequency 推送频率字符串
      * @param ruleId 规则ID
-     * @param pushContent 推送内容
+     * @param clientId 客户端id
      * @param redisTemplate Redis模板
      * @return 是否应该推送
      */
-    public static boolean checkPushFrequency(String pushFrequency, Long ruleId, String pushContent, RedisTemplate<String, Object> redisTemplate) {
+    public static boolean checkPushFrequency(String pushFrequency, Long ruleId, String clientId, RedisTemplate<String, Object> redisTemplate) {
         if (pushFrequency == null || pushFrequency.trim().isEmpty()) {
             log.debug("规则{}的推送频率为空,默认推送", ruleId);
             return true;
@@ -52,7 +51,7 @@ public class PushFrequencyUtil {
                 log.debug("规则{}推送频率{}大于1,向上取整为周期{}", ruleId, frequency, cycle);
                 
                 // 使用Redis管理周期计数
-                return checkPushCycleWithRedis(ruleId, pushContent, cycle, redisTemplate);
+                return checkPushCycleWithRedis(ruleId, clientId, cycle, redisTemplate);
             }
         } catch (NumberFormatException e) {
             log.warn("规则{}的推送频率格式错误:{},默认推送", ruleId, pushFrequency);
@@ -64,26 +63,25 @@ public class PushFrequencyUtil {
      * 使用Redis检查推送周期
      * 
      * @param ruleId 规则ID
-     * @param pushContent 推送内容
+     * @param clientId 客户端id
      * @param cycle 周期
      * @param redisTemplate Redis模板
      * @return 是否应该推送
      */
-    private static boolean checkPushCycleWithRedis(Long ruleId, String pushContent, int cycle, RedisTemplate<String, Object> redisTemplate) {
+    private static boolean checkPushCycleWithRedis(Long ruleId, String clientId, int cycle, RedisTemplate<String, Object> redisTemplate) {
         if (cycle < 1) {
             return false;
         }
         
-        String uuid = UUID.randomUUID().toString();
-        
+
         // 构建Redis key,使用规则ID和推送内容作为唯一标识
-        String countKey = String.format("mkt:push:count:%d:%s", ruleId, uuid);
+        String countKey = String.format("mkt:push:count:%d:%s", ruleId, clientId);
         
         try {
             // Redis原子自增计数
             Long currentCount = redisTemplate.opsForValue().increment(countKey);
             if (currentCount == null) {
-                log.warn("Redis自增失败,规则ID:{},推送内容:{}", ruleId, pushContent);
+                log.warn("Redis自增失败,规则ID:{},推送内容:{}", ruleId, clientId);
                 return false;
             }
             
@@ -103,7 +101,7 @@ public class PushFrequencyUtil {
             return false;
             
         } catch (Exception e) {
-            log.error("Redis操作异常,规则ID:{},推送内容:{}", ruleId, pushContent, e);
+            log.error("Redis操作异常,规则ID:{},推送内容:{}", ruleId, clientId, e);
             // Redis异常时默认推送,避免影响业务
             return true;
         }