Commit fbe6fbb0 by zhouhaibao

feat(sop): 添加网页描述字段并优化幂等性处理

- 在SopActionReqDTO中新增pageDesc字段用于消息类型4的网页描述
- 在SopStrategyAction实体中添加pageDesc数据库映射字段
- 从SopCustomerSnapshotService中移除硬编码的变量注入逻辑
- 修改SopIdempotentUtil幂等键生成逻辑,移除触发时间参数
- 更新幂等键Redis存储策略,移除过期时间设置
- 在快照映射器中添加groupId字段映射配置
1 parent 0388d7f3
......@@ -36,6 +36,9 @@ public class SopActionReqDTO implements Serializable {
@ApiModelProperty(notes= "素材间隔(像素)(消息类型为4时使用)")
private Integer intervalPx;
@ApiModelProperty(notes= "网页描述(消息类型为4时使用)")
private String pageDesc;
@ApiModelProperty(notes= "素材列表")
private List<SopActionMediaReqDTO> medias;
}
\ No newline at end of file
package cn.com.glsx.dj.strategy.model.sop;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.*;
......@@ -147,6 +148,10 @@ public class SopStrategyAction implements Serializable {
@Column(name = "updated_date")
private Date updatedDate;
@ApiModelProperty(notes= "网页描述(消息类型为4时使用)")
@Column(name = "page_desc")
private String pageDesc;
/**
* 素材列表(非数据库字段)
*/
......
......@@ -135,11 +135,7 @@ public class SopCustomerSnapshotService {
try {
Map<String, Object> snapshotDataMap = JSONUtil.toBean(snapshot.getSnapshotData(), Map.class);
variables.putAll(snapshotDataMap);
variables.put("depositToDeliveryDays", snapshotDataMap.get("depositToDeliveryDays"));
variables.put("deliveryRemainingDays", snapshotDataMap.get("deliveryRemainingDays"));
variables.put("unfinishedProductCategory", snapshotDataMap.get("unfinishedProductCategory"));
variables.put("finishedProductCategory", snapshotDataMap.get("finishedProductCategory"));
} catch (Exception e) {
log.warn("解析快照JSON数据失败, taskId:{}, error:{}", taskId, e.getMessage());
}
......
......@@ -148,7 +148,7 @@ public class SopStrategyTriggerService {
private Integer createPendingTask(SopStrategy strategy, Long customerInstanceId,
Date triggerTime) {
String idempotentKey = sopIdempotentUtil.generateIdempotentKey(strategy.getId(),
customerInstanceId, triggerTime, strategy.getVersion());
customerInstanceId, strategy.getVersion());
if (!sopIdempotentUtil.tryAcquire(idempotentKey)) {
log.info("任务已存在,跳过创建, strategyId:{}, customerInstanceId:{}, triggerTime:{}",
strategy.getId(), customerInstanceId, triggerTime);
......@@ -179,7 +179,7 @@ public class SopStrategyTriggerService {
private Integer createImmediateTask(SopStrategy strategy, Long customerInstanceId) {
Date triggerTime = new Date();
String idempotentKey = sopIdempotentUtil.generateIdempotentKey(strategy.getId(),
customerInstanceId, triggerTime, strategy.getVersion());
customerInstanceId, strategy.getVersion());
if (!sopIdempotentUtil.tryAcquire(idempotentKey)) {
log.info("任务已存在,跳过创建, strategyId:{}, customerInstanceId:{}, triggerTime:{}",
strategy.getId(), customerInstanceId, triggerTime);
......
......@@ -19,14 +19,13 @@ public class SopIdempotentUtil {
@Autowired
private StringRedisTemplate stringRedisTemplate;
public String generateIdempotentKey(Integer strategyId, Long customerInstanceId, Date triggerTime, Integer version) {
String triggerTimeStr = DateUtil.format(triggerTime, "yyyyMMddHHmmss");
return String.format("%s%s_%s_%s_%s", IDEMPOTENT_KEY_PREFIX, strategyId, customerInstanceId, triggerTimeStr, version);
public String generateIdempotentKey(Integer strategyId, Long customerInstanceId, Integer version) {
return String.format("%s%s_%s_%s", IDEMPOTENT_KEY_PREFIX, strategyId, customerInstanceId, version);
}
public boolean tryAcquire(String idempotentKey) {
try {
Boolean success = stringRedisTemplate.opsForValue().setIfAbsent(idempotentKey, "1", DEFAULT_EXPIRE_DAYS, TimeUnit.DAYS);
Boolean success = stringRedisTemplate.opsForValue().setIfAbsent(idempotentKey, "1");
boolean result = Boolean.TRUE.equals(success);
if (result) {
log.debug("幂等键获取成功, key:{}", idempotentKey);
......
......@@ -22,6 +22,7 @@
<result column="car_series_level" property="carSeriesLevel"/>
<result column="snapshot_data" property="snapshotData"/>
<result column="snapshot_time" property="snapshotTime"/>
<result column="groupId" property="groupId"/>
<result column="deleted_flag" property="deletedFlag"/>
<result column="created_by" property="createdBy"/>
<result column="created_date" property="createdDate"/>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!