|
|
@@ -276,6 +276,16 @@ public class Task {
|
|
|
private QwExternalContactMapper qwExternalContactMapper;
|
|
|
|
|
|
public static final String SOP_TEMP_VOICE_KEY = "sop:tempVoice";
|
|
|
+
|
|
|
+ // sop升单客户类型
|
|
|
+ private static final Map<String, Integer> TYPE_MAPPING = new HashMap<>();
|
|
|
+
|
|
|
+ static {
|
|
|
+ TYPE_MAPPING.put("1,1,1", 1); // 小品未购 主品未购 -> 1
|
|
|
+ TYPE_MAPPING.put("2,2,1", 2); // 小品已购 主品未购 -> 2
|
|
|
+ TYPE_MAPPING.put("3,1,2", 3); // 小品未购 主品已购 -> 3
|
|
|
+ TYPE_MAPPING.put("4,2,2", 4); // 小品已购 主品已购 -> 4
|
|
|
+ }
|
|
|
public void syncExpressToWx() {
|
|
|
List<FsWxExpressTask> fsWxExpressTasks = fsWxExpressTaskMapper.selectPendingData();
|
|
|
if (CollectionUtils.isEmpty(fsWxExpressTasks)) {
|
|
|
@@ -2323,9 +2333,12 @@ public class Task {
|
|
|
Long doctorId = companyUser.getDoctorId(); // 医生ID
|
|
|
|
|
|
// 确定 type:1~4
|
|
|
+ Integer isProductBuy = qwExternalContact.getIsProductBuy();
|
|
|
+ Integer isUpsellProductBuy = qwExternalContact.getIsUpsellProductBuy();
|
|
|
Integer isBuy = log.getIsBuy();
|
|
|
- Integer type = determineType(isBuy, exId);
|
|
|
+ Integer type = determineType(isBuy, isProductBuy,isUpsellProductBuy);
|
|
|
if (type == null) {
|
|
|
+ logger.error("无法确定任务类型!,externalId:{}",exId);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
@@ -2335,7 +2348,7 @@ public class Task {
|
|
|
logger.warn("orderSendType 为空,跳过 exId: {}", exId);
|
|
|
continue;
|
|
|
}
|
|
|
- // 处理订单发送类型
|
|
|
+ // 处理订单发送对象类型
|
|
|
boolean success = processOrderSendType(orderSendType, fsUserId, companyUserId, doctorId, type, log.getExId());
|
|
|
if (success) {
|
|
|
ids.add(log.getId());
|
|
|
@@ -2354,25 +2367,22 @@ public class Task {
|
|
|
/**
|
|
|
* 确定类型值
|
|
|
*/
|
|
|
- private Integer determineType(Integer isBuy, Long exId) {
|
|
|
- if (isBuy == null) {
|
|
|
- logger.warn("isBuy 为空,跳过 exId: {}", exId);
|
|
|
+ private Integer determineType(Integer isBuy, Integer isProductBuy, Integer isUpsellProductBuy) {
|
|
|
+ if (isBuy == null || isProductBuy == null || isUpsellProductBuy == null) {
|
|
|
+ logger.error("参数不能为空: isBuy={}, isProductBuy={}, isUpsellProductBuy={}",
|
|
|
+ isBuy, isProductBuy, isUpsellProductBuy);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- switch (isBuy) {
|
|
|
- case 1:
|
|
|
- return 1; // 未升单未购
|
|
|
- case 2:
|
|
|
- return 2; // 未升单已购
|
|
|
- case 3:
|
|
|
- return 3; // 升单未购
|
|
|
- case 4:
|
|
|
- return 4; // 升单已购
|
|
|
- default:
|
|
|
- logger.warn("未知 isBuy 值: {}, 跳过 exId: {}", isBuy, exId);
|
|
|
- return null;
|
|
|
+ String key = String.join(",", isBuy.toString(), isProductBuy.toString(), isUpsellProductBuy.toString());
|
|
|
+ Integer result = TYPE_MAPPING.get(key);
|
|
|
+
|
|
|
+ if (result == null) {
|
|
|
+ logger.error("未找到匹配的类型配置: isBuy={}, isProductBuy={}, isUpsellProductBuy={}",
|
|
|
+ isBuy, isProductBuy, isUpsellProductBuy);
|
|
|
}
|
|
|
+
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -2397,120 +2407,13 @@ public class Task {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 定时向销售和医生分发SOP任务。
|
|
|
- * */
|
|
|
-// public void obtainSopInfoData2() {
|
|
|
-// List<SopOrderLog> sopOrderLogs = sopOrderLogMapper.queryUnsentSOPData();
|
|
|
-// if (CollectionUtils.isEmpty(sopOrderLogs)) {
|
|
|
-// return;
|
|
|
-// }
|
|
|
-//
|
|
|
-// for (SopOrderLog log : sopOrderLogs) {
|
|
|
-// List<SopUserLogsInfo> logsInfo = sopUserLogsInfoMapper.querySopUserLogsRecord(log.getSopId(),log.getIsBuy());
|
|
|
-// if (CollectionUtils.isEmpty(logsInfo)){
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 过滤 externalId 非空
|
|
|
-// List<Long> externalIds = logsInfo.stream()
|
|
|
-// .filter(info -> info.getExternalId() != null)
|
|
|
-// .map(SopUserLogsInfo::getExternalId)
|
|
|
-// .collect(Collectors.toList());
|
|
|
-//
|
|
|
-// if (CollectionUtils.isEmpty(externalIds)) {
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 构建 productBuyMap:根据 isBuy 类型选择字段
|
|
|
-// Map<Long, Integer> productBuyMap;
|
|
|
-// boolean isUpsell = (log.getIsBuy() == 3 || log.getIsBuy() == 4); // 是否升单
|
|
|
-//
|
|
|
-// if (isUpsell) {//升单就取IsUpsellProductBuy属性值
|
|
|
-// productBuyMap = logsInfo.stream()
|
|
|
-// .filter(info -> info.getExternalId() != null)
|
|
|
-// .collect(Collectors.toMap(
|
|
|
-// SopUserLogsInfo::getExternalId,
|
|
|
-// SopUserLogsInfo::getIsUpsellProductBuy,
|
|
|
-// (v1, v2) -> v1//防止重复key,一般同一个营期内不会有重复的
|
|
|
-// ));
|
|
|
-// } else {//未升单就取IsProductBuy属性值
|
|
|
-// productBuyMap = logsInfo.stream()
|
|
|
-// .filter(info -> info.getExternalId() != null)
|
|
|
-// .collect(Collectors.toMap(
|
|
|
-// SopUserLogsInfo::getExternalId,
|
|
|
-// SopUserLogsInfo::getIsProductBuy,
|
|
|
-// (v1, v2) -> v1//防止重复key
|
|
|
-// ));
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 查询qw_external_contact 表获取客户id,销售id
|
|
|
-// List<QwExternalContact> contacts = qwExternalContactMapper.selectQwExternalContactByIds(externalIds);
|
|
|
-// if (CollectionUtils.isEmpty(contacts)) {
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-//
|
|
|
-// for (QwExternalContact contact : contacts) {
|
|
|
-// Long fsUserId = contact.getFsUserId(); // 客户ID
|
|
|
-// Long companyUserId = contact.getCompanyUserId();//销售ID
|
|
|
-//
|
|
|
-// CompanyUser companyUser = companyUserMapper.selectCompanyUserByCompanyUserId(companyUserId);
|
|
|
-// if (companyUser == null) continue; // 防空指针
|
|
|
-//
|
|
|
-// Long doctorId = companyUser.getDoctorId();//医生ID
|
|
|
-// // - 根据当前外部联系人 ID(contact.getId()),从购买sop_user_logs_info表中获取其购买状态
|
|
|
-// // - 如果是“未升单”场景,buyStatus 来自字段 isProductBuy(1=未购,2=已购)
|
|
|
-// // - 如果是“升单”场景,buyStatus 来自字段 isUpsellProductBuy(1=未购,2=已购)
|
|
|
-// Integer buyStatus = productBuyMap.get(contact.getId());
|
|
|
-//
|
|
|
-//
|
|
|
-// // 安全校验:确保 buyStatus 为 1(未购)或 2(已购)
|
|
|
-// if (buyStatus == null || (buyStatus != 1 && buyStatus != 2)) {
|
|
|
-// logger.error("方法obtainSopInfoData():buyStatus 异常,externalId: {}, 值: {}", contact.getId(), buyStatus);
|
|
|
-// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
-// throw new CustomException("分发医生和销售sop任务失败");
|
|
|
-// }
|
|
|
-//
|
|
|
-// //核心映射:1/2 → 1/2(未升单),1/2 → 3/4(升单)
|
|
|
-// int type = isUpsell ? (buyStatus + 2) : buyStatus;
|
|
|
-//
|
|
|
-// // 分发任务
|
|
|
-// switch (log.getOrderSendType()) {
|
|
|
-// case 1:
|
|
|
-// //分发给销售sop数据
|
|
|
-// obtainSopCompanyUserTaskData(fsUserId, companyUserId, doctorId, type,contact.getId());
|
|
|
-// break;
|
|
|
-// case 2:
|
|
|
-// //分发给医生sop数据
|
|
|
-// obtainSopDoctorTaskData(fsUserId, companyUserId, doctorId, type,contact.getId());
|
|
|
-// break;
|
|
|
-// case 3:
|
|
|
-// //分发给销售和医生sop数据
|
|
|
-// obtainSopCompanyUserTaskData(fsUserId, companyUserId, doctorId, type,contact.getId());
|
|
|
-// obtainSopDoctorTaskData(fsUserId, companyUserId, doctorId, type,contact.getId());
|
|
|
-// break;
|
|
|
-// default:
|
|
|
-// logger.error("未知的type: {}", type);
|
|
|
-// break;
|
|
|
-// }
|
|
|
-//
|
|
|
-// }
|
|
|
-// }
|
|
|
-// //对于已经推送的数据需要修改sop库的sop_order_log表的status状态为1:已推送
|
|
|
-// List<Long> ids = sopOrderLogs.stream().map(SopOrderLog::getId).collect(Collectors.toList());
|
|
|
-// int i = sopOrderLogMapper.updateIsSentSOPDataByIds(ids);
|
|
|
-// if (i > 0){
|
|
|
-// logger.info("修改了{}条sop_order_log表的status状态为1:已推送", i);
|
|
|
-// }
|
|
|
-// }
|
|
|
//辅助方法 增加医生和销售的sop推送数据
|
|
|
/**
|
|
|
* 增加sop医生推送数据
|
|
|
* @param fsUserId 用户id
|
|
|
* @param companyUserId 销售人员id
|
|
|
* @param doctorId 医生id
|
|
|
- * @param type 1:未升单未购 2:未升单已购 3:升单未购 4:升单已购
|
|
|
+ * @param type 1:小品未购 主品未购 2:小品已购 主品未购 3:小品未购 主品已购 4:小品已购 主品已购
|
|
|
* */
|
|
|
public int obtainSopDoctorTaskData(Long fsUserId, Long companyUserId,Long doctorId, Integer type,Long qwExternalContactId) {
|
|
|
if (doctorId==null){
|
|
|
@@ -2532,7 +2435,7 @@ public class Task {
|
|
|
* @param fsUserId 用户id
|
|
|
* @param companyUserId 销售人员id
|
|
|
* @param doctorId 医生id
|
|
|
- * @param type 1:未升单未购 2:未升单已购 3:升单未购 4:升单已购
|
|
|
+ * @param type 1:小品未购 主品未购 2:小品已购 主品未购 3:小品未购 主品已购 4:小品已购 主品已购
|
|
|
* */
|
|
|
public int obtainSopCompanyUserTaskData(Long fsUserId, Long companyUserId,Long doctorId, Integer type,Long qwExternalContactId) {
|
|
|
FsSopCompanyUserTask fsSopCompanyUserTask = new FsSopCompanyUserTask();
|