|
@@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
@@ -36,6 +37,7 @@ import com.fs.his.service.IFsExpressService;
|
|
|
import com.fs.his.service.IFsIntegralOrderService;
|
|
import com.fs.his.service.IFsIntegralOrderService;
|
|
|
import com.fs.his.service.IFsStoreOrderLogsService;
|
|
import com.fs.his.service.IFsStoreOrderLogsService;
|
|
|
import com.fs.his.service.IFsStoreOrderService;
|
|
import com.fs.his.service.IFsStoreOrderService;
|
|
|
|
|
+import com.fs.his.service.impl.FsStoreServiceImpl;
|
|
|
import com.fs.his.utils.ConfigUtil;
|
|
import com.fs.his.utils.ConfigUtil;
|
|
|
import com.fs.hisStore.domain.FsExpressScrm;
|
|
import com.fs.hisStore.domain.FsExpressScrm;
|
|
|
import com.fs.hisStore.domain.FsStoreOrderItemScrm;
|
|
import com.fs.hisStore.domain.FsStoreOrderItemScrm;
|
|
@@ -166,6 +168,8 @@ public class DfOrderServiceImpl implements IErpOrderService {
|
|
|
private FsIntegralOrderLogsMapper fsIntegralOrderLogsMapper;
|
|
private FsIntegralOrderLogsMapper fsIntegralOrderLogsMapper;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private LiveOrderItemMapper liveOrderItemMapper;
|
|
private LiveOrderItemMapper liveOrderItemMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FsStoreServiceImpl fsStoreServiceImpl;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public ErpOrderResponse addOrder(ErpOrder order) {
|
|
public ErpOrderResponse addOrder(ErpOrder order) {
|
|
@@ -724,15 +728,6 @@ public class DfOrderServiceImpl implements IErpOrderService {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- //判断物流状态是否更新 更新ai发送物流给客户
|
|
|
|
|
- try {
|
|
|
|
|
- aiSendExpress(order, stateEx);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("ai发送物流信息错误:{}", e.getMessage());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
if (OrderContextHolder.hasIntegralOrder()){
|
|
if (OrderContextHolder.hasIntegralOrder()){
|
|
|
//加积分订单的字段,然后在这里更新它
|
|
//加积分订单的字段,然后在这里更新它
|
|
|
FsIntegralOrder integralOrder = OrderContextHolder.getIntegralOrder();
|
|
FsIntegralOrder integralOrder = OrderContextHolder.getIntegralOrder();
|
|
@@ -745,6 +740,13 @@ public class DfOrderServiceImpl implements IErpOrderService {
|
|
|
fsStoreOrderMap.setDeliveryType(stateEx);
|
|
fsStoreOrderMap.setDeliveryType(stateEx);
|
|
|
fsStoreOrderMapper.updateFsStoreOrder(fsStoreOrderMap);
|
|
fsStoreOrderMapper.updateFsStoreOrder(fsStoreOrderMap);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ //判断物流状态是否更新 更新ai发送物流给客户
|
|
|
|
|
+ try {
|
|
|
|
|
+ aiSendExpress(order, stateEx);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("ai发送物流信息错误:{}", e.getMessage());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
@@ -753,25 +755,97 @@ public class DfOrderServiceImpl implements IErpOrderService {
|
|
|
|
|
|
|
|
private void aiSendExpress(FsStoreOrder order, String stateEx) {
|
|
private void aiSendExpress(FsStoreOrder order, String stateEx) {
|
|
|
Long orderId = order.getOrderId();
|
|
Long orderId = order.getOrderId();
|
|
|
- if (!Objects.equals(order.getDeliveryType(), stateEx)) {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 方法入口日志
|
|
|
|
|
+ log.info("AI发送物流消息开始 - orderId: {}, orderCode: {}, 原始deliveryType: {}, 新stateEx: {}",
|
|
|
|
|
+ orderId, order.getOrderCode(), order.getDeliveryType(), stateEx);
|
|
|
|
|
+
|
|
|
|
|
+ order = fsStoreOrderMapper.selectFsStoreOrderByOrderId(orderId); //查询更新后的订单信息
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 查询最新数据后的日志
|
|
|
|
|
+ log.info("查询最新订单数据 - orderId: {}, deliveryType: {}, deliveryStatus: {}, deliverySn: {}",
|
|
|
|
|
+ orderId, order.getDeliveryType(), order.getDeliveryStatus(), order.getDeliverySn());
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 检查deliveryType是否发生变化
|
|
|
|
|
+ boolean isStateChanged = !Objects.equals(order.getDeliveryType(), stateEx);
|
|
|
|
|
+ log.info("状态比较结果 - orderId: {}, order.getDeliveryType(): {}, stateEx: {}, 状态是否变化: {}",
|
|
|
|
|
+ orderId, order.getDeliveryType(), stateEx, isStateChanged);
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 检查Redis中是否今天已经发送过
|
|
|
|
|
+ String todayDate = cn.hutool.core.date.DateUtil.today();
|
|
|
|
|
+ String todayRedisKey = "ai:express:sent:" + orderId + ":" + todayDate;
|
|
|
|
|
+
|
|
|
|
|
+ Object sentValue = redisCache.getCacheObject(todayRedisKey);
|
|
|
|
|
+
|
|
|
|
|
+ log.info("Redis发送检查 - orderId: {}, todayDate: {}, todayRedisKey: {}, 今天是否已发送: {}",
|
|
|
|
|
+ orderId, todayDate, todayRedisKey, sentValue != null);
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 判断发送逻辑
|
|
|
|
|
+ if (isStateChanged) {
|
|
|
|
|
+ // 状态变化了,直接发送
|
|
|
|
|
+ log.info("物流状态发生变化,执行AI消息发送逻辑 - orderId: {}", orderId);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 状态没有变化,检查今天是否已发送过
|
|
|
|
|
+ if (sentValue != null) {
|
|
|
|
|
+ log.info("物流状态未变化且今天已发送过,跳过AI消息发送 - orderId: {}", orderId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("物流状态未变化但今天未发送过,执行AI消息发送逻辑 - orderId: {}", orderId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
//判断是否添加相关企微员工
|
|
//判断是否添加相关企微员工
|
|
|
if(order.getUserId() != null){
|
|
if(order.getUserId() != null){
|
|
|
|
|
+ log.info("检查企微联系人 - orderId: {}, userId: {}, companyUserId: {}",
|
|
|
|
|
+ orderId, order.getUserId(), order.getCompanyUserId());
|
|
|
|
|
+
|
|
|
List<QwExternalContact> qwExternalContact = externalContactService.selectQwExternalContactByFsUserIdAndCompany(order.getUserId(), order.getCompanyUserId());
|
|
List<QwExternalContact> qwExternalContact = externalContactService.selectQwExternalContactByFsUserIdAndCompany(order.getUserId(), order.getCompanyUserId());
|
|
|
|
|
+
|
|
|
|
|
+ log.info("企微联系人查询结果 - orderId: {}, 联系人数量: {}",
|
|
|
|
|
+ orderId, qwExternalContact != null ? qwExternalContact.size() : 0);
|
|
|
|
|
+
|
|
|
if(qwExternalContact != null && !qwExternalContact.isEmpty()) {
|
|
if(qwExternalContact != null && !qwExternalContact.isEmpty()) {
|
|
|
for (QwExternalContact externalContact : qwExternalContact) {
|
|
for (QwExternalContact externalContact : qwExternalContact) {
|
|
|
Long qwUserId = externalContact.getQwUserId();
|
|
Long qwUserId = externalContact.getQwUserId();
|
|
|
|
|
+
|
|
|
|
|
+ log.info("处理企微联系人 - orderId: {}, externalUserId: {}, qwUserId: {}",
|
|
|
|
|
+ orderId, externalContact.getExternalUserId(), qwUserId);
|
|
|
|
|
+
|
|
|
if (qwUserId != null) {
|
|
if (qwUserId != null) {
|
|
|
QwUser qwUser = qwUserMapper.selectQwUserById(qwUserId);
|
|
QwUser qwUser = qwUserMapper.selectQwUserById(qwUserId);
|
|
|
|
|
+
|
|
|
|
|
+ log.info("企微用户信息 - orderId: {}, qwUserId: {}, uid: {}, fastGptRoleId: {}, serverId: {}, serverStatus: {}, ipadStatus: {}",
|
|
|
|
|
+ orderId, qwUserId,
|
|
|
|
|
+ qwUser != null ? qwUser.getUid() : null,
|
|
|
|
|
+ qwUser != null ? qwUser.getFastGptRoleId() : null,
|
|
|
|
|
+ qwUser != null ? qwUser.getServerId() : null,
|
|
|
|
|
+ qwUser != null ? qwUser.getServerStatus() : null,
|
|
|
|
|
+ qwUser != null ? qwUser.getIpadStatus() : null);
|
|
|
|
|
+
|
|
|
if (qwUser != null && qwUser.getUid() != null && qwUser.getFastGptRoleId() != null && qwUser.getServerId() != null && qwUser.getServerStatus() == 1 && qwUser.getIpadStatus() == 1) {
|
|
if (qwUser != null && qwUser.getUid() != null && qwUser.getFastGptRoleId() != null && qwUser.getServerId() != null && qwUser.getServerStatus() == 1 && qwUser.getIpadStatus() == 1) {
|
|
|
FastGptRole fastGptRole = fastGptRoleService.selectFastGptRoleByRoleId(qwUser.getFastGptRoleId());
|
|
FastGptRole fastGptRole = fastGptRoleService.selectFastGptRoleByRoleId(qwUser.getFastGptRoleId());
|
|
|
|
|
+
|
|
|
|
|
+ log.info("AI角色信息 - orderId: {}, roleId: {}, 物流功能状态: {}",
|
|
|
|
|
+ orderId, qwUser.getFastGptRoleId(),
|
|
|
|
|
+ fastGptRole != null ? fastGptRole.getLogistics() : "角色不存在");
|
|
|
|
|
+
|
|
|
if (fastGptRole.getLogistics() == 0) {
|
|
if (fastGptRole.getLogistics() == 0) {
|
|
|
log.error("物流功能未开启,roleId:" + qwUser.getFastGptRoleId() + "订单号:" + orderId);
|
|
log.error("物流功能未开启,roleId:" + qwUser.getFastGptRoleId() + "订单号:" + orderId);
|
|
|
|
|
+ continue; // 跳过这个联系人,继续处理下一个
|
|
|
}
|
|
}
|
|
|
WxWorkUserId2VidDTO wxWorkUserId2VidDTO = new WxWorkUserId2VidDTO();
|
|
WxWorkUserId2VidDTO wxWorkUserId2VidDTO = new WxWorkUserId2VidDTO();
|
|
|
wxWorkUserId2VidDTO.setOpenid(Collections.singletonList(externalContact.getExternalUserId()));
|
|
wxWorkUserId2VidDTO.setOpenid(Collections.singletonList(externalContact.getExternalUserId()));
|
|
|
wxWorkUserId2VidDTO.setUuid(qwUser.getUid());
|
|
wxWorkUserId2VidDTO.setUuid(qwUser.getUid());
|
|
|
|
|
+
|
|
|
|
|
+ log.info("调用企微接口获取用户ID - orderId: {}, externalUserId: {}, uid: {}, serverId: {}",
|
|
|
|
|
+ orderId, externalContact.getExternalUserId(), qwUser.getUid(), qwUser.getServerId());
|
|
|
|
|
+
|
|
|
WxWorkResponseDTO<List<WxWorkVid2UserIdRespDTO>> WxWorkVid2UserIdRespDTO = wxWorkService.UserId2Vid(wxWorkUserId2VidDTO, qwUser.getServerId());
|
|
WxWorkResponseDTO<List<WxWorkVid2UserIdRespDTO>> WxWorkVid2UserIdRespDTO = wxWorkService.UserId2Vid(wxWorkUserId2VidDTO, qwUser.getServerId());
|
|
|
List<WxWorkVid2UserIdRespDTO> data = WxWorkVid2UserIdRespDTO.getData();
|
|
List<WxWorkVid2UserIdRespDTO> data = WxWorkVid2UserIdRespDTO.getData();
|
|
|
|
|
+
|
|
|
|
|
+ log.info("企微接口返回结果 - orderId: {}, 返回数据数量: {}, 返回数据: {}",
|
|
|
|
|
+ orderId, data != null ? data.size() : 0, data);
|
|
|
|
|
+
|
|
|
StringBuilder sBuilder = new StringBuilder();
|
|
StringBuilder sBuilder = new StringBuilder();
|
|
|
if (data != null && !data.isEmpty()) {
|
|
if (data != null && !data.isEmpty()) {
|
|
|
Long sendId = data.get(0).getUser_id();
|
|
Long sendId = data.get(0).getUser_id();
|
|
@@ -829,20 +903,58 @@ public class DfOrderServiceImpl implements IErpOrderService {
|
|
|
//2.发送模板中的文字内容
|
|
//2.发送模板中的文字内容
|
|
|
String content = sBuilder.toString();
|
|
String content = sBuilder.toString();
|
|
|
content = content.replace("(有事呼叫我,勿找平台,少一次投诉,多一份感恩)", "");
|
|
content = content.replace("(有事呼叫我,勿找平台,少一次投诉,多一份感恩)", "");
|
|
|
|
|
+
|
|
|
|
|
+ log.info("准备发送AI物流消息 - orderId: {}, sendId: {}, 消息内容: {}",
|
|
|
|
|
+ orderId, sendId, content);
|
|
|
|
|
+
|
|
|
WxWorkSendTextMsgDTO wxWorkSendTextMsgDTO = new WxWorkSendTextMsgDTO();
|
|
WxWorkSendTextMsgDTO wxWorkSendTextMsgDTO = new WxWorkSendTextMsgDTO();
|
|
|
wxWorkSendTextMsgDTO.setSend_userid(sendId);
|
|
wxWorkSendTextMsgDTO.setSend_userid(sendId);
|
|
|
wxWorkSendTextMsgDTO.setUuid(qwUser.getUid());
|
|
wxWorkSendTextMsgDTO.setUuid(qwUser.getUid());
|
|
|
wxWorkSendTextMsgDTO.setContent(content);
|
|
wxWorkSendTextMsgDTO.setContent(content);
|
|
|
wxWorkSendTextMsgDTO.setIsRoom(false);
|
|
wxWorkSendTextMsgDTO.setIsRoom(false);
|
|
|
- wxWorkService.SendTextMsg(wxWorkSendTextMsgDTO, qwUser.getServerId());
|
|
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ wxWorkService.SendTextMsg(wxWorkSendTextMsgDTO, qwUser.getServerId());
|
|
|
|
|
+ log.info("AI物流消息发送成功 - orderId: {}, sendId: {}", orderId, sendId);
|
|
|
|
|
+
|
|
|
|
|
+ // 发送成功后设置今天的Redis标识
|
|
|
|
|
+ // 计算到今天结束的剩余秒数(设置到明天凌晨2点过期,确保覆盖当天)
|
|
|
|
|
+ cn.hutool.core.date.DateTime tomorrow = cn.hutool.core.date.DateUtil.tomorrow();
|
|
|
|
|
+ cn.hutool.core.date.DateTime endOfToday = cn.hutool.core.date.DateUtil.endOfDay(cn.hutool.core.date.DateUtil.date());
|
|
|
|
|
+ long secondsUntilTomorrow = (endOfToday.getTime() - System.currentTimeMillis()) / 1000 + 7200; // 加2小时缓冲
|
|
|
|
|
+
|
|
|
|
|
+ redisCache.setCacheObject(todayRedisKey, "1", (int) secondsUntilTomorrow, java.util.concurrent.TimeUnit.SECONDS);
|
|
|
|
|
+ log.info("设置今天Redis发送标识 - orderId: {}, todayRedisKey: {}, 过期时间(秒): {}", orderId, todayRedisKey, secondsUntilTomorrow);
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("AI物流消息发送失败 - orderId: {}, sendId: {}, 错误信息: {}", orderId, sendId, e.getMessage(), e);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("未生成有效的消息内容 - orderId: {}, stateEx: {}, sBuilder长度: {}",
|
|
|
|
|
+ orderId, stateEx, sBuilder.length());
|
|
|
}
|
|
}
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.warn("企微接口未返回有效的用户ID - orderId: {}, data为空", orderId);
|
|
|
}
|
|
}
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.warn("企微用户配置不完整 - orderId: {}, qwUserId: {}, uid: {}, fastGptRoleId: {}, serverId: {}, serverStatus: {}, ipadStatus: {}",
|
|
|
|
|
+ orderId, qwUserId,
|
|
|
|
|
+ qwUser.getUid(),
|
|
|
|
|
+ qwUser.getFastGptRoleId(),
|
|
|
|
|
+ qwUser.getServerId(),
|
|
|
|
|
+ qwUser.getServerStatus(),
|
|
|
|
|
+ qwUser.getIpadStatus());
|
|
|
}
|
|
}
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.warn("未找到企微用户 - orderId: {}, externalUserId: {}", orderId, externalContact.getExternalUserId());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.warn("未找到有效的企微联系人 - orderId: {}, qwExternalContact为空", orderId);
|
|
|
}
|
|
}
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.warn("订单用户ID为空 - orderId: {}", orderId);
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|