|
|
@@ -2294,76 +2294,17 @@ public class Task {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 1. 提取非空 externalIds
|
|
|
- List<Long> externalIds = sopOrderLogs.stream()
|
|
|
- .filter(info -> info.getExId() != null)
|
|
|
- .map(SopOrderLog::getExId)
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- if (CollectionUtils.isEmpty(externalIds)) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 2. 批量查询外部联系人;从qw_external_contact 表获取客户id,销售id
|
|
|
- List<QwExternalContact> contacts = qwExternalContactMapper.selectQwExternalContactByIds(externalIds);
|
|
|
- Map<Long, QwExternalContact> contactMap = contacts.stream()
|
|
|
- .collect(Collectors.toMap(QwExternalContact::getId, contact -> contact));
|
|
|
-
|
|
|
- // 3. 批量查询所有需要的公司用户
|
|
|
- Set<Long> companyUserIds = contacts.stream()
|
|
|
- .map(QwExternalContact::getCompanyUserId)
|
|
|
- .filter(Objects::nonNull)
|
|
|
- .collect(Collectors.toSet());
|
|
|
- List<CompanyUser> companyUsers = companyUserMapper.selectCompanyUserByCompanyUserIds(companyUserIds);
|
|
|
- Map<Long, CompanyUser> companyUserMap = companyUsers.stream()
|
|
|
- .collect(Collectors.toMap(CompanyUser::getUserId, user -> user));
|
|
|
-
|
|
|
// 4. 遍历处理每条 SOP 日志信息
|
|
|
List<Long> ids = new ArrayList<>();
|
|
|
for (SopOrderLog log : sopOrderLogs) {
|
|
|
- Long exId = log.getExId();
|
|
|
- if (exId == null) {
|
|
|
- logger.warn("跳过 exId 为空的记录");
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // 获取联系人
|
|
|
- QwExternalContact qwExternalContact = contactMap.get(exId);
|
|
|
- if (qwExternalContact == null) {
|
|
|
- logger.warn("未找到 exId: {} 对应的外部联系人", exId);
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- Long fsUserId = qwExternalContact.getFsUserId(); // 客户ID
|
|
|
- Long companyUserId = qwExternalContact.getCompanyUserId(); // 销售ID
|
|
|
-
|
|
|
- CompanyUser companyUser = companyUserMap.get(companyUserId);
|
|
|
- if (companyUser == null) {
|
|
|
- logger.warn("未找到 companyUserId: {} 对应的销售人员", companyUserId);
|
|
|
- continue; // 防空指针
|
|
|
- }
|
|
|
-
|
|
|
- Long doctorId = companyUser.getDoctorId(); // 医生ID
|
|
|
-
|
|
|
- // 确定 type:1~4
|
|
|
- Integer isProductBuy = qwExternalContact.getIsProductBuy();
|
|
|
- Integer isUpsellProductBuy = qwExternalContact.getIsUpsellProductBuy();
|
|
|
- Integer isBuy = log.getIsBuy();
|
|
|
- Integer type = determineType(isBuy, isProductBuy,isUpsellProductBuy);
|
|
|
- if (type == null) {
|
|
|
- logger.error("无法确定任务类型!,externalId:{}",exId);
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // 根据 orderSendType 分发任务
|
|
|
- Integer orderSendType = log.getOrderSendType();
|
|
|
- if (orderSendType == null) {
|
|
|
- logger.warn("orderSendType 为空,跳过 exId: {}", exId);
|
|
|
- continue;
|
|
|
- }
|
|
|
- // 处理订单发送对象类型
|
|
|
- boolean success = processOrderSendType(orderSendType, fsUserId, companyUserId, doctorId, type, log.getExId());
|
|
|
- if (success) {
|
|
|
+ FsSopDoctorTask fsSopDoctorTask = new FsSopDoctorTask();
|
|
|
+ fsSopDoctorTask.setUserId(log.getFsUserId()); // 客户ID
|
|
|
+ fsSopDoctorTask.setDoctorId(log.getDoctorId()); // 医生ID
|
|
|
+ fsSopDoctorTask.setStatus(0);//默认未处理状态
|
|
|
+ fsSopDoctorTask.setCreateTime(DateUtils.getNowDate());
|
|
|
+ fsSopDoctorTask.setDoctorMemberSalesId(log.getDoctorMemberSalesId());
|
|
|
+ int result = sopDoctorTaskMapper.insertFsSopDoctorTask(fsSopDoctorTask);;
|
|
|
+ if (result>0) {
|
|
|
ids.add(log.getId());
|
|
|
}
|
|
|
}
|
|
|
@@ -2393,91 +2334,6 @@ public class Task {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 确定类型值
|
|
|
- */
|
|
|
- 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;
|
|
|
- }
|
|
|
-
|
|
|
- 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;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 处理订单发送类型
|
|
|
- */
|
|
|
- private boolean processOrderSendType(Integer orderSendType, Long fsUserId, Long companyUserId, Long doctorId, Integer type, Long exId) {
|
|
|
- switch (orderSendType) {
|
|
|
- case 1:
|
|
|
- // 分发给销售sop数据
|
|
|
- return obtainSopCompanyUserTaskData(fsUserId, companyUserId, doctorId, type, exId) == 1;
|
|
|
- case 2:
|
|
|
- // 分发给医生sop数据
|
|
|
- return obtainSopDoctorTaskData(fsUserId, companyUserId, doctorId, type, exId) == 1;
|
|
|
- case 3:
|
|
|
- // 分发给销售和医生sop数据
|
|
|
- int result1 = obtainSopCompanyUserTaskData(fsUserId, companyUserId, doctorId, type, exId);
|
|
|
- int result2 = obtainSopDoctorTaskData(fsUserId, companyUserId, doctorId, type, exId);
|
|
|
- return result1 == 1 && result2 == 1;
|
|
|
- default:
|
|
|
- logger.error("未知的orderSendType: {}", orderSendType);
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //辅助方法 增加医生和销售的sop推送数据
|
|
|
- /**
|
|
|
- * 增加sop医生推送数据
|
|
|
- * @param fsUserId 用户id
|
|
|
- * @param companyUserId 销售人员id
|
|
|
- * @param doctorId 医生id
|
|
|
- * @param type 1:小品未购 主品未购 2:小品已购 主品未购 3:小品未购 主品已购 4:小品已购 主品已购
|
|
|
- * */
|
|
|
- public int obtainSopDoctorTaskData(Long fsUserId, Long companyUserId,Long doctorId, Integer type,Long qwExternalContactId) {
|
|
|
- if (doctorId==null){
|
|
|
- logger.info("销售人员companyUserId:{},未绑定医生不触发医生sop数据",companyUserId);
|
|
|
- return 1;
|
|
|
- }
|
|
|
- FsSopDoctorTask fsSopDoctorTask = new FsSopDoctorTask();
|
|
|
- fsSopDoctorTask.setUserId(fsUserId);
|
|
|
- fsSopDoctorTask.setCompanyUserId(companyUserId);
|
|
|
- fsSopDoctorTask.setDoctorId(doctorId);
|
|
|
- fsSopDoctorTask.setType(type);
|
|
|
- fsSopDoctorTask.setQwExternalContactId(qwExternalContactId);
|
|
|
- fsSopDoctorTask.setStatus(0);//默认未处理状态
|
|
|
- fsSopDoctorTask.setCreateTime(DateUtils.getNowDate());
|
|
|
- return sopDoctorTaskMapper.insertFsSopDoctorTask(fsSopDoctorTask);
|
|
|
- }
|
|
|
- /**
|
|
|
- * 增加sop销售推送数据
|
|
|
- * @param fsUserId 用户id
|
|
|
- * @param companyUserId 销售人员id
|
|
|
- * @param doctorId 医生id
|
|
|
- * @param type 1:小品未购 主品未购 2:小品已购 主品未购 3:小品未购 主品已购 4:小品已购 主品已购
|
|
|
- * */
|
|
|
- public int obtainSopCompanyUserTaskData(Long fsUserId, Long companyUserId,Long doctorId, Integer type,Long qwExternalContactId) {
|
|
|
- FsSopCompanyUserTask fsSopCompanyUserTask = new FsSopCompanyUserTask();
|
|
|
- fsSopCompanyUserTask.setUserId(fsUserId);
|
|
|
- fsSopCompanyUserTask.setCompanyUserId(companyUserId);
|
|
|
- fsSopCompanyUserTask.setDoctorId(doctorId);
|
|
|
- fsSopCompanyUserTask.setType(type);
|
|
|
- fsSopCompanyUserTask.setQwExternalContactId(qwExternalContactId);
|
|
|
- fsSopCompanyUserTask.setStatus(0);//默认未处理状态
|
|
|
- fsSopCompanyUserTask.setCreateTime(DateUtils.getNowDate());
|
|
|
- return sopCompanyUserTaskMapper.insertFsSopCompanyUserTask(fsSopCompanyUserTask);
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
/**
|
|
|
* 医生在线状态兜底任务
|