|
|
@@ -18,6 +18,10 @@ import com.fs.huifuPay.domain.HuifuOrderConfirmResult;
|
|
|
import com.fs.huifuPay.sdk.opps.core.request.V2TradePaymentScanpayQueryRequest;
|
|
|
import com.fs.huifuPay.sdk.opps.core.utils.DateTools;
|
|
|
import com.fs.huifuPay.service.HuiFuService;
|
|
|
+import com.fs.qw.domain.FsSopCompanyUserTask;
|
|
|
+import com.fs.qw.domain.QwExternalContact;
|
|
|
+import com.fs.qw.mapper.FsSopCompanyUserTaskMapper;
|
|
|
+import com.fs.qw.mapper.QwExternalContactMapper;
|
|
|
import com.fs.sop.domain.QwSopTempVoice;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
@@ -74,6 +78,10 @@ import com.fs.qw.domain.QwCompany;
|
|
|
import com.fs.qw.mapper.QwRestrictionPushRecordMapper;
|
|
|
import com.fs.qw.service.*;
|
|
|
import com.fs.qwApi.service.QwApiService;
|
|
|
+import com.fs.sop.domain.SopOrderLog;
|
|
|
+import com.fs.sop.domain.SopUserLogsInfo;
|
|
|
+import com.fs.sop.mapper.SopOrderLogMapper;
|
|
|
+import com.fs.sop.mapper.SopUserLogsInfoMapper;
|
|
|
import com.fs.sop.service.IQwSopTempVoiceService;
|
|
|
import com.fs.system.domain.SysConfig;
|
|
|
import com.fs.system.mapper.SysConfigMapper;
|
|
|
@@ -89,6 +97,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
@@ -251,6 +260,21 @@ public class Task {
|
|
|
@Autowired
|
|
|
private IFsAmountsShareMerchantService amountShareMerchantService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SopOrderLogMapper sopOrderLogMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsSopDoctorTaskMapper sopDoctorTaskMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsSopCompanyUserTaskMapper sopCompanyUserTaskMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SopUserLogsInfoMapper sopUserLogsInfoMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private QwExternalContactMapper qwExternalContactMapper;
|
|
|
+
|
|
|
public static final String SOP_TEMP_VOICE_KEY = "sop:tempVoice";
|
|
|
public void syncExpressToWx() {
|
|
|
List<FsWxExpressTask> fsWxExpressTasks = fsWxExpressTaskMapper.selectPendingData();
|
|
|
@@ -2214,4 +2238,142 @@ public class Task {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public void obtainSopInfoData() {
|
|
|
+ List<SopOrderLog> sopOrderLogs = sopOrderLogMapper.queryUnsentSOPData();
|
|
|
+ if (CollectionUtils.isEmpty(sopOrderLogs)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (SopOrderLog log : sopOrderLogs) {
|
|
|
+ List<SopUserLogsInfo> logsInfo = sopUserLogsInfoMapper.querySopUserLogsRecord(log.getSopId());
|
|
|
+
|
|
|
+ // 过滤 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);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ //分发给医生sop数据
|
|
|
+ obtainSopDoctorTaskData(fsUserId, companyUserId, doctorId, type);
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ //分发给销售和医生sop数据
|
|
|
+ obtainSopCompanyUserTaskData(fsUserId, companyUserId, doctorId, type);
|
|
|
+ obtainSopDoctorTaskData(fsUserId, companyUserId, doctorId, type);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ logger.error("未知的type: {}", type);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //对于已经推送的数据需要修改sop库的sop_order_log表的status状态为1:已推送
|
|
|
+ List<Long> ids = sopOrderLogs.stream().map(SopOrderLog::getId).collect(Collectors.toList());
|
|
|
+ sopOrderLogMapper.updateIsSentSOPDataByIds(ids);
|
|
|
+ }
|
|
|
+ //辅助方法 增加医生和销售的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) {
|
|
|
+ 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.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) {
|
|
|
+ FsSopCompanyUserTask fsSopCompanyUserTask = new FsSopCompanyUserTask();
|
|
|
+ fsSopCompanyUserTask.setUserId(fsUserId);
|
|
|
+ fsSopCompanyUserTask.setCompanyUserId(companyUserId);
|
|
|
+ fsSopCompanyUserTask.setDoctorId(doctorId);
|
|
|
+ fsSopCompanyUserTask.setType(type);
|
|
|
+ fsSopCompanyUserTask.setStatus(0);//默认未处理状态
|
|
|
+ fsSopCompanyUserTask.setCreateTime(DateUtils.getNowDate());
|
|
|
+ return sopCompanyUserTaskMapper.insertFsSopCompanyUserTask(fsSopCompanyUserTask);
|
|
|
+ }
|
|
|
+
|
|
|
}
|