Compare commits
3 Commits
9206824efb
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
632b9f7eb1 | ||
|
|
eb53915bcd | ||
|
|
4dd3e9dd70 |
@@ -44,6 +44,10 @@ public class SuperAdmin extends BaseEntity
|
|||||||
@Excel(name = "是否参与订单统计", readConverterExp = "0=否,1=是")
|
@Excel(name = "是否参与订单统计", readConverterExp = "0=否,1=是")
|
||||||
private Integer isCount;
|
private Integer isCount;
|
||||||
|
|
||||||
|
/** 接收人(企业微信用户ID,多个用逗号分隔) */
|
||||||
|
@Excel(name = "接收人")
|
||||||
|
private String touser;
|
||||||
|
|
||||||
/** 创建时间 */
|
/** 创建时间 */
|
||||||
@Excel(name = "创建时间")
|
@Excel(name = "创建时间")
|
||||||
private Date createdAt;
|
private Date createdAt;
|
||||||
@@ -151,4 +155,14 @@ public class SuperAdmin extends BaseEntity
|
|||||||
{
|
{
|
||||||
this.isCount = isCount;
|
this.isCount = isCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTouser()
|
||||||
|
{
|
||||||
|
return touser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTouser(String touser)
|
||||||
|
{
|
||||||
|
this.touser = touser;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import org.springframework.util.StringUtils;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,6 +129,43 @@ public class LogisticsServiceImpl implements ILogisticsService {
|
|||||||
|
|
||||||
logger.info("检测到waybill_no: {} - 订单ID: {}", waybillNo, orderId);
|
logger.info("检测到waybill_no: {} - 订单ID: {}", waybillNo, orderId);
|
||||||
|
|
||||||
|
// 兼容处理:检查Redis中是否已有该订单的运单号记录
|
||||||
|
// 如果存在且运单号一致,说明之前已经推送过了(可能是之前没有配置接收人但推送成功的情况)
|
||||||
|
String redisKey = REDIS_WAYBILL_KEY_PREFIX + orderId;
|
||||||
|
String existingWaybillNo = stringRedisTemplate.opsForValue().get(redisKey);
|
||||||
|
|
||||||
|
if (existingWaybillNo != null && existingWaybillNo.trim().equals(waybillNo.trim())) {
|
||||||
|
// 运单号一致,说明之前已经推送过了,直接标记为已处理,跳过推送
|
||||||
|
logger.info("订单运单号已存在且一致,说明之前已推送过,跳过重复推送 - 订单ID: {}, waybill_no: {}", orderId, waybillNo);
|
||||||
|
// 更新过期时间,确保记录不会过期
|
||||||
|
stringRedisTemplate.opsForValue().set(redisKey, waybillNo, 30, TimeUnit.DAYS);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 兼容处理:如果Redis中没有记录,但订单创建时间在30天之前,且获取到了运单号
|
||||||
|
// 说明可能是之前推送过但没标记的情况(比如之前没有配置接收人但推送成功,响应解析失败)
|
||||||
|
// 这种情况下,直接标记为已处理,跳过推送,避免重复推送旧订单
|
||||||
|
if (existingWaybillNo == null && order.getCreateTime() != null) {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.add(Calendar.DAY_OF_MONTH, -30); // 30天前
|
||||||
|
Date thresholdDate = calendar.getTime();
|
||||||
|
|
||||||
|
if (order.getCreateTime().before(thresholdDate)) {
|
||||||
|
// 订单创建时间在30天之前,且Redis中没有记录,但获取到了运单号
|
||||||
|
// 视为之前已推送过但未标记,直接标记为已处理,跳过推送
|
||||||
|
logger.info("订单创建时间较早({}),且Redis中无记录但已获取到运单号,视为之前已推送过,直接标记为已处理,跳过推送 - 订单ID: {}, waybill_no: {}",
|
||||||
|
order.getCreateTime(), orderId, waybillNo);
|
||||||
|
stringRedisTemplate.opsForValue().set(redisKey, waybillNo, 30, TimeUnit.DAYS);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果Redis中有记录但运单号不一致,记录警告
|
||||||
|
if (existingWaybillNo != null && !existingWaybillNo.trim().equals(waybillNo.trim())) {
|
||||||
|
logger.warn("订单运单号发生变化 - 订单ID: {}, 旧运单号: {}, 新运单号: {}, 将重新推送",
|
||||||
|
orderId, existingWaybillNo, waybillNo);
|
||||||
|
}
|
||||||
|
|
||||||
// 调用企业应用推送,只有推送成功才记录状态
|
// 调用企业应用推送,只有推送成功才记录状态
|
||||||
boolean pushSuccess = sendEnterprisePushNotification(order, waybillNo);
|
boolean pushSuccess = sendEnterprisePushNotification(order, waybillNo);
|
||||||
if (!pushSuccess) {
|
if (!pushSuccess) {
|
||||||
@@ -135,12 +174,13 @@ public class LogisticsServiceImpl implements ILogisticsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 保存运单号到Redis(避免重复处理)- 使用原子操作确保只写入一次
|
// 保存运单号到Redis(避免重复处理)- 使用原子操作确保只写入一次
|
||||||
String redisKey = REDIS_WAYBILL_KEY_PREFIX + orderId;
|
|
||||||
Boolean setSuccess = stringRedisTemplate.opsForValue().setIfAbsent(redisKey, waybillNo, 30, TimeUnit.DAYS);
|
Boolean setSuccess = stringRedisTemplate.opsForValue().setIfAbsent(redisKey, waybillNo, 30, TimeUnit.DAYS);
|
||||||
|
|
||||||
if (Boolean.FALSE.equals(setSuccess)) {
|
if (Boolean.FALSE.equals(setSuccess)) {
|
||||||
// 如果Redis中已存在,说明可能被其他线程处理了,记录警告但不算失败
|
// 如果Redis中已存在,说明可能被其他线程处理了,记录警告但不算失败
|
||||||
logger.warn("订单运单号已存在(可能被并发处理),但推送已成功 - 订单ID: {}, waybill_no: {}", orderId, waybillNo);
|
logger.warn("订单运单号已存在(可能被并发处理),但推送已成功 - 订单ID: {}, waybill_no: {}", orderId, waybillNo);
|
||||||
|
// 更新过期时间,确保记录不会过期
|
||||||
|
stringRedisTemplate.opsForValue().set(redisKey, waybillNo, 30, TimeUnit.DAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("物流信息获取并推送成功 - 订单ID: {}, waybill_no: {}", orderId, waybillNo);
|
logger.info("物流信息获取并推送成功 - 订单ID: {}, waybill_no: {}", orderId, waybillNo);
|
||||||
|
|||||||
@@ -11,12 +11,13 @@
|
|||||||
<result property="secretKey" column="secret_key"/>
|
<result property="secretKey" column="secret_key"/>
|
||||||
<result property="isActive" column="is_active"/>
|
<result property="isActive" column="is_active"/>
|
||||||
<result property="isCount" column="is_count"/>
|
<result property="isCount" column="is_count"/>
|
||||||
|
<result property="touser" column="touser"/>
|
||||||
<result property="createdAt" column="created_at"/>
|
<result property="createdAt" column="created_at"/>
|
||||||
<result property="updatedAt" column="updated_at"/>
|
<result property="updatedAt" column="updated_at"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectSuperAdminVo">
|
<sql id="selectSuperAdminVo">
|
||||||
select id, wxid, name, union_id, app_key, secret_key, is_active, is_count, created_at, updated_at from super_admin
|
select id, wxid, name, union_id, app_key, secret_key, is_active, is_count, touser, created_at, updated_at from super_admin
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="selectSuperAdminList" parameterType="SuperAdmin" resultMap="SuperAdminResult">
|
<select id="selectSuperAdminList" parameterType="SuperAdmin" resultMap="SuperAdminResult">
|
||||||
@@ -51,6 +52,8 @@
|
|||||||
<if test="appKey != null and appKey != ''">app_key,</if>
|
<if test="appKey != null and appKey != ''">app_key,</if>
|
||||||
<if test="secretKey != null and secretKey != ''">secret_key,</if>
|
<if test="secretKey != null and secretKey != ''">secret_key,</if>
|
||||||
<if test="isActive != null">is_active,</if>
|
<if test="isActive != null">is_active,</if>
|
||||||
|
<if test="isCount != null">is_count,</if>
|
||||||
|
<if test="touser != null and touser != ''">touser,</if>
|
||||||
created_at,
|
created_at,
|
||||||
updated_at,
|
updated_at,
|
||||||
</trim>
|
</trim>
|
||||||
@@ -61,6 +64,8 @@
|
|||||||
<if test="appKey != null and appKey != ''">#{appKey},</if>
|
<if test="appKey != null and appKey != ''">#{appKey},</if>
|
||||||
<if test="secretKey != null and secretKey != ''">#{secretKey},</if>
|
<if test="secretKey != null and secretKey != ''">#{secretKey},</if>
|
||||||
<if test="isActive != null">#{isActive},</if>
|
<if test="isActive != null">#{isActive},</if>
|
||||||
|
<if test="isCount != null">#{isCount},</if>
|
||||||
|
<if test="touser != null and touser != ''">#{touser},</if>
|
||||||
now(),
|
now(),
|
||||||
now(),
|
now(),
|
||||||
</trim>
|
</trim>
|
||||||
@@ -76,6 +81,7 @@
|
|||||||
<if test="secretKey != null and secretKey != ''">secret_key = #{secretKey},</if>
|
<if test="secretKey != null and secretKey != ''">secret_key = #{secretKey},</if>
|
||||||
<if test="isActive != null">is_active = #{isActive},</if>
|
<if test="isActive != null">is_active = #{isActive},</if>
|
||||||
<if test="isCount != null">is_count = #{isCount},</if>
|
<if test="isCount != null">is_count = #{isCount},</if>
|
||||||
|
<if test="touser != null">touser = #{touser},</if>
|
||||||
updated_at = now(),
|
updated_at = now(),
|
||||||
</trim>
|
</trim>
|
||||||
where id = #{id}
|
where id = #{id}
|
||||||
|
|||||||
4
sql/add_super_admin_touser_field.sql
Normal file
4
sql/add_super_admin_touser_field.sql
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
-- 为超级管理员表添加接收人字段
|
||||||
|
-- 字段说明:touser 存储企业微信用户ID,多个用逗号分隔
|
||||||
|
ALTER TABLE super_admin ADD COLUMN touser VARCHAR(500) DEFAULT NULL COMMENT '接收人(企业微信用户ID,多个用逗号分隔)';
|
||||||
|
|
||||||
Reference in New Issue
Block a user