1
This commit is contained in:
@@ -13,6 +13,8 @@ import com.ruoyi.jarvis.service.IJDOrderService;
|
||||
import com.ruoyi.jarvis.service.IOrderRowsService;
|
||||
import com.ruoyi.jarvis.service.IGiftCouponService;
|
||||
import com.ruoyi.jarvis.domain.GiftCoupon;
|
||||
import com.ruoyi.system.service.ISysConfigService;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -37,6 +39,8 @@ public class JDOrderController extends BaseController {
|
||||
private final IJDOrderService jdOrderService;
|
||||
private final IOrderRowsService orderRowsService;
|
||||
private final IGiftCouponService giftCouponService;
|
||||
private final ISysConfigService sysConfigService;
|
||||
private static final String CONFIG_KEY_PREFIX = "logistics.push.touser.";
|
||||
private static final java.util.regex.Pattern URL_DETECT_PATTERN = java.util.regex.Pattern.compile(
|
||||
"(https?://[^\\s]+)|(u\\.jd\\.com/[^\\s]+)",
|
||||
java.util.regex.Pattern.CASE_INSENSITIVE);
|
||||
@@ -47,10 +51,12 @@ public class JDOrderController extends BaseController {
|
||||
"^https?://jingfen\\.jd\\.com/detail/[A-Za-z0-9]+\\.html$",
|
||||
java.util.regex.Pattern.CASE_INSENSITIVE);
|
||||
|
||||
public JDOrderController(IJDOrderService jdOrderService, IOrderRowsService orderRowsService, IGiftCouponService giftCouponService) {
|
||||
public JDOrderController(IJDOrderService jdOrderService, IOrderRowsService orderRowsService,
|
||||
IGiftCouponService giftCouponService, ISysConfigService sysConfigService) {
|
||||
this.jdOrderService = jdOrderService;
|
||||
this.orderRowsService = orderRowsService;
|
||||
this.giftCouponService = giftCouponService;
|
||||
this.sysConfigService = sysConfigService;
|
||||
}
|
||||
|
||||
private final static String skey = "2192057370ef8140c201079969c956a3";
|
||||
@@ -1017,6 +1023,43 @@ public class JDOrderController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分销标识获取接收人列表
|
||||
* 从系统配置中读取,配置键名格式:logistics.push.touser.{分销标识}
|
||||
* 配置值格式:接收人1,接收人2,接收人3(逗号分隔)
|
||||
*
|
||||
* @param distributionMark 分销标识
|
||||
* @return 接收人列表(逗号分隔),如果未配置则返回null
|
||||
*/
|
||||
private String getTouserByDistributionMark(String distributionMark) {
|
||||
if (!StringUtils.hasText(distributionMark)) {
|
||||
logger.warn("分销标识为空,无法获取接收人配置");
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
// 构建配置键名
|
||||
String configKey = CONFIG_KEY_PREFIX + distributionMark.trim();
|
||||
|
||||
// 从系统配置中获取接收人列表
|
||||
String configValue = sysConfigService.selectConfigByKey(configKey);
|
||||
|
||||
if (StringUtils.hasText(configValue)) {
|
||||
// 清理配置值(去除空格)
|
||||
String touser = configValue.trim().replaceAll(",\\s+", ",");
|
||||
logger.info("从配置获取接收人列表 - 分销标识: {}, 配置键: {}, 接收人: {}",
|
||||
distributionMark, configKey, touser);
|
||||
return touser;
|
||||
} else {
|
||||
logger.debug("未找到接收人配置 - 分销标识: {}, 配置键: {}", distributionMark, configKey);
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("获取接收人配置失败 - 分销标识: {}, 错误: {}", distributionMark, e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用企业应用推送逻辑
|
||||
* @param order 订单信息
|
||||
@@ -1055,6 +1098,17 @@ public class JDOrderController extends BaseController {
|
||||
String content = pushContent.toString();
|
||||
pushParam.put("text", content);
|
||||
|
||||
// 根据分销标识获取接收人列表
|
||||
String touser = getTouserByDistributionMark(distributionMark);
|
||||
if (StringUtils.hasText(touser)) {
|
||||
pushParam.put("touser", touser);
|
||||
logger.info("企业微信推送设置接收人 - 订单ID: {}, 分销标识: {}, 接收人: {}",
|
||||
order.getId(), distributionMark, touser);
|
||||
} else {
|
||||
logger.warn("未找到分销标识对应的接收人配置 - 订单ID: {}, 分销标识: {}",
|
||||
order.getId(), distributionMark);
|
||||
}
|
||||
|
||||
// 使用支持自定义header的HTTP请求
|
||||
String pushResult = sendPostWithHeaders(pushUrl, pushParam.toJSONString(), token);
|
||||
logger.info("企业应用推送调用结果 - 订单ID: {}, waybill_no: {}, 推送结果: {}",
|
||||
|
||||
@@ -5,10 +5,12 @@ import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.common.utils.http.HttpUtils;
|
||||
import com.ruoyi.jarvis.domain.JDOrder;
|
||||
import com.ruoyi.jarvis.service.ILogisticsService;
|
||||
import com.ruoyi.system.service.ISysConfigService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.net.URLEncoder;
|
||||
@@ -25,10 +27,14 @@ public class LogisticsServiceImpl implements ILogisticsService {
|
||||
private static final String EXTERNAL_API_URL = "http://192.168.8.88:5001/fetch_logistics?tracking_url=";
|
||||
private static final String PUSH_URL = "https://wxts.van333.cn/wx/send/pdd";
|
||||
private static final String PUSH_TOKEN = "super_token_b62190c26";
|
||||
private static final String CONFIG_KEY_PREFIX = "logistics.push.touser.";
|
||||
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@Resource
|
||||
private ISysConfigService sysConfigService;
|
||||
|
||||
@Override
|
||||
public boolean isOrderProcessed(Long orderId) {
|
||||
if (orderId == null) {
|
||||
@@ -149,6 +155,17 @@ public class LogisticsServiceImpl implements ILogisticsService {
|
||||
pushParam.put("title", "JD物流信息推送");
|
||||
pushParam.put("text", pushContent.toString());
|
||||
|
||||
// 根据分销标识获取接收人列表
|
||||
String touser = getTouserByDistributionMark(distributionMark);
|
||||
if (StringUtils.hasText(touser)) {
|
||||
pushParam.put("touser", touser);
|
||||
logger.info("企业微信推送设置接收人 - 订单ID: {}, 分销标识: {}, 接收人: {}",
|
||||
order.getId(), distributionMark, touser);
|
||||
} else {
|
||||
logger.warn("未找到分销标识对应的接收人配置 - 订单ID: {}, 分销标识: {}",
|
||||
order.getId(), distributionMark);
|
||||
}
|
||||
|
||||
// 使用支持自定义header的HTTP请求
|
||||
String pushResult = sendPostWithHeaders(PUSH_URL, pushParam.toJSONString(), PUSH_TOKEN);
|
||||
if (pushResult == null || pushResult.trim().isEmpty()) {
|
||||
@@ -174,6 +191,43 @@ public class LogisticsServiceImpl implements ILogisticsService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分销标识获取接收人列表
|
||||
* 从系统配置中读取,配置键名格式:logistics.push.touser.{分销标识}
|
||||
* 配置值格式:接收人1,接收人2,接收人3(逗号分隔)
|
||||
*
|
||||
* @param distributionMark 分销标识
|
||||
* @return 接收人列表(逗号分隔),如果未配置则返回null
|
||||
*/
|
||||
private String getTouserByDistributionMark(String distributionMark) {
|
||||
if (!StringUtils.hasText(distributionMark)) {
|
||||
logger.warn("分销标识为空,无法获取接收人配置");
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
// 构建配置键名
|
||||
String configKey = CONFIG_KEY_PREFIX + distributionMark.trim();
|
||||
|
||||
// 从系统配置中获取接收人列表
|
||||
String configValue = sysConfigService.selectConfigByKey(configKey);
|
||||
|
||||
if (StringUtils.hasText(configValue)) {
|
||||
// 清理配置值(去除空格)
|
||||
String touser = configValue.trim().replaceAll(",\\s+", ",");
|
||||
logger.info("从配置获取接收人列表 - 分销标识: {}, 配置键: {}, 接收人: {}",
|
||||
distributionMark, configKey, touser);
|
||||
return touser;
|
||||
} else {
|
||||
logger.debug("未找到接收人配置 - 分销标识: {}, 配置键: {}", distributionMark, configKey);
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("获取接收人配置失败 - 分销标识: {}, 错误: {}", distributionMark, e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断推送返回值是否为成功状态
|
||||
* @param pushResult 推送接口返回结果
|
||||
|
||||
Reference in New Issue
Block a user