Quellcode durchsuchen

医生搭销任务提交接口

cgp vor 1 Woche
Ursprung
Commit
198d14a2d3

+ 8 - 152
fs-admin/src/main/java/com/fs/his/task/Task.java

@@ -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);
-    }
-
 
     /**
      *  医生在线状态兜底任务

+ 14 - 0
fs-doctor-app/src/main/java/com/fs/app/controller/FsSopDoctorTaskController.java

@@ -11,6 +11,7 @@ import com.fs.common.utils.StringUtils;
 import com.fs.his.domain.FsPatient;
 import com.fs.his.domain.FsUser;
 import com.fs.his.domain.FsUserAddress;
+import com.fs.his.dto.FsDoctorTaskDTO;
 import com.fs.his.dto.SopDoctorTaskDto;
 import com.fs.his.param.FsStoreOrderParam;
 import com.fs.his.param.FsUserCouponParam;
@@ -273,4 +274,17 @@ public class FsSopDoctorTaskController extends BaseController
         PageInfo<FsSopDoctorTask> listPageInfo=new PageInfo<>(taskList);
         return R.ok().put("data", listPageInfo);
     }
+    /**
+     * 提交搭销会员任务
+     * */
+    @PutMapping("/submitDoctorTask")
+    public R submitDoctorTask(@RequestBody FsDoctorTaskDTO addTaskDto){
+        //当前登录医生id
+        addTaskDto.setDoctorId(Long.valueOf(getDoctorId()));
+        int update = fsSopDoctorTaskService.submitDoctorTask(addTaskDto);
+        if (update>0){
+            return R.ok();
+        }
+        return R.error("提交失败");
+    }
 }

+ 21 - 0
fs-service/src/main/java/com/fs/his/dto/FsDoctorTaskDTO.java

@@ -0,0 +1,21 @@
+package com.fs.his.dto;
+
+import lombok.Data;
+
+@Data
+public class FsDoctorTaskDTO {
+    //任务id fs_sop_doctor_task表的主键
+    private Long id;
+    //医生id
+    private Long doctorId;
+    //提醒时间天数
+    private Integer sendDays;
+    //处理方式 1:签收,2:提醒时间
+    private Integer handleType;
+    //订单编号
+    private String orderCode;
+    //处理结果
+    private String remark;
+    //医生会员搭销id
+    private Long doctorMemberSalesId;
+}

+ 1 - 0
fs-service/src/main/java/com/fs/his/mapper/FsStoreOrderMapper.java

@@ -350,6 +350,7 @@ public interface FsStoreOrderMapper
             "            <if test=\"tuiMoneyStatus != null\">tui_money_status = #{tuiMoneyStatus},</if>\n" +
             "            <if test=\"tuiUserId != null\">tui_user_id = #{tuiUserId},</if>\n" +
             "            <if test=\"orderCreateType != null\">order_create_type = #{orderCreateType},</if>\n" +
+            "            <if test=\"isReceiveNotice != null\">is_receive_notice = #{isReceiveNotice},</if>\n" +
             "        </trim>\n" +
             "        where order_code = #{orderCode}"+
             "</script>"})

+ 6 - 0
fs-service/src/main/java/com/fs/his/service/IFsSopDoctorTaskService.java

@@ -3,6 +3,7 @@ package com.fs.his.service;
 import java.util.List;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.fs.his.domain.FsSopDoctorTask;
+import com.fs.his.dto.FsDoctorTaskDTO;
 import com.fs.his.dto.SopDoctorTaskDto;
 import com.fs.his.vo.SopDoctorTaskVo;
 
@@ -65,4 +66,9 @@ public interface IFsSopDoctorTaskService extends IService<FsSopDoctorTask>{
 
 
     List<FsSopDoctorTask> selectFsSopDoctorTaskList(FsSopDoctorTask task);
+
+    /**
+     * 提交搭销会员任务
+     * */
+    int submitDoctorTask(FsDoctorTaskDTO addTaskDto);
 }

+ 115 - 1
fs-service/src/main/java/com/fs/his/service/impl/FsSopDoctorTaskServiceImpl.java

@@ -1,14 +1,25 @@
 package com.fs.his.service.impl;
 
 import java.text.SimpleDateFormat;
-import java.util.Collections;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
 import java.util.Date;
 import java.util.List;
+
+import com.fs.common.core.redis.RedisCache;
+import com.fs.common.exception.CustomException;
 import com.fs.common.utils.DateUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fs.his.domain.FsStoreOrder;
+import com.fs.his.dto.FsDoctorTaskDTO;
 import com.fs.his.dto.SopDoctorTaskDto;
+import com.fs.his.mapper.FsStoreOrderMapper;
 import com.fs.his.service.IFsSopDoctorTaskService;
 import com.fs.his.vo.SopDoctorTaskVo;
+import com.fs.qw.domain.FsDoctorMemberSales;
+import com.fs.qw.mapper.FsDoctorMemberSalesMapper;
+import com.fs.sop.domain.SopOrderLog;
+import com.fs.sop.mapper.SopOrderLogMapper;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -29,6 +40,18 @@ public class FsSopDoctorTaskServiceImpl extends ServiceImpl<FsSopDoctorTaskMappe
 
     @Autowired
     private FsSopDoctorTaskMapper fsSopDoctorTaskMapper;
+
+    @Autowired
+    private SopOrderLogMapper sopOrderLogMapper;
+
+    @Autowired
+    private FsDoctorMemberSalesMapper doctorMemberSalesMapper;
+
+    @Autowired
+    private FsStoreOrderMapper fsStoreOrderMapper;
+
+    @Autowired
+    private RedisCache redisCache;
     /**
      * 查询医生处理sop任务
      * 
@@ -122,4 +145,95 @@ public class FsSopDoctorTaskServiceImpl extends ServiceImpl<FsSopDoctorTaskMappe
     public List<FsSopDoctorTask> selectFsSopDoctorTaskList(FsSopDoctorTask task) {
         return fsSopDoctorTaskMapper.selectFsSopDoctorTaskList(task);
     }
+
+    @Override
+    public int submitDoctorTask(FsDoctorTaskDTO addTaskDto) {
+        // --- 1. 验证输入参数 ---
+        if (addTaskDto == null || addTaskDto.getId() == null) {
+            throw new CustomException("任务ID不能为空");
+        }
+        if (addTaskDto.getDoctorMemberSalesId() == null) {
+            throw new CustomException("医生会员搭销ID不能为空");
+        }
+        // 对于签收类型,检查订单号是否提供
+        if (addTaskDto.getHandleType() != null && addTaskDto.getHandleType() == 1
+                && (addTaskDto.getOrderCode() == null || addTaskDto.getOrderCode().isEmpty())) {
+            throw new CustomException("签收类型必须提供订单号");
+        }
+        // 对于提醒类型,检查天数是否提供且有效
+        if (addTaskDto.getHandleType() != null && addTaskDto.getHandleType() == 2
+                && (addTaskDto.getSendDays() == null || addTaskDto.getSendDays() <= 0)) {
+            throw new CustomException("提醒类型必须提供大于0的天数");
+        }
+
+        FsDoctorMemberSales fsDoctorMemberSales = doctorMemberSalesMapper.selectFsDoctorMemberSalesById(addTaskDto.getDoctorMemberSalesId());
+        if (fsDoctorMemberSales == null) {
+            log.error("会员搭销数据不存在,doctorMemberSalesId:{}", addTaskDto.getDoctorMemberSalesId());
+            throw new CustomException("会员搭销ID不存在");
+        }
+        // --- 2. 更新主任务表 ---
+        FsSopDoctorTask doctorTask = new FsSopDoctorTask();
+        doctorTask.setId(addTaskDto.getId());
+        doctorTask.setDoctorId(addTaskDto.getDoctorId());
+        doctorTask.setStatus(1); // 0:待处理,1:已处理
+        doctorTask.setUserId(fsDoctorMemberSales.getFsUserId()); // 会员id
+        doctorTask.setHandleType(addTaskDto.getHandleType());
+        doctorTask.setRemark(addTaskDto.getRemark());
+        doctorTask.setUpdateTime(DateUtils.getNowDate());
+
+        if (addTaskDto.getHandleType() != null && addTaskDto.getHandleType() == 1) {
+            doctorTask.setOrderCode(addTaskDto.getOrderCode());
+            //签收的订单号存入缓存中
+            String signOffOrderCacheKey = "SIGN_OFF_ORDERS_CODE:"+addTaskDto.getId();
+            redisCache.setCacheObject(signOffOrderCacheKey,addTaskDto.getOrderCode());
+            //修改fs_store_order表的is_receive_notice为已签收
+            FsStoreOrder fsStoreOrder=new FsStoreOrder();
+            fsStoreOrder.setIsReceiveNotice(1);//已签收
+            fsStoreOrder.setOrderCode(addTaskDto.getOrderCode());
+            fsStoreOrderMapper.updateFsStoreOrderByOrderCode(fsStoreOrder);
+        }
+
+        int updateResult = fsSopDoctorTaskMapper.updateById(doctorTask);
+
+        // --- 3. 根据处理类型执行后续操作 ---
+        if (addTaskDto.getHandleType() != null && addTaskDto.getHandleType() == 2) {
+            // --- 3.1 计算提醒时间 ---
+            Date now = DateUtils.getNowDate();
+            Date futureDate = calculateFutureDate(now, addTaskDto.getSendDays());
+
+            // --- 3.2 插入sop_order_log表 ---
+            SopOrderLog sopOrderLog = new SopOrderLog();
+            sopOrderLog.setDoctorId(addTaskDto.getDoctorId());// 医生ID
+            sopOrderLog.setStatus(0); // 0:未发送,1:已发送
+            sopOrderLog.setFsUserId(fsDoctorMemberSales.getFsUserId());
+            sopOrderLog.setCreateTime(now);
+            sopOrderLog.setSendTime(futureDate);
+            sopOrderLogMapper.insert(sopOrderLog);
+        }
+
+        return updateResult;
+    }
+
+    /**
+     * 计算未来日期
+     * @param baseDate 基准日期
+     * @param daysToAdd 需要增加的天数
+     * @return 计算后的未来日期
+     */
+    private Date calculateFutureDate(Date baseDate, Integer daysToAdd) {
+        if (baseDate == null || daysToAdd == null || daysToAdd <= 0) {
+            // 根据业务需求决定如何处理无效输入,这里抛异常
+            throw new IllegalArgumentException("基准日期和增加天数都不能为空且天数需大于0");
+        }
+        // 1. 将 Date 转换为 LocalDateTime (注意时区,这里假设使用系统默认时区)
+        LocalDateTime localDateTimeNow = baseDate.toInstant()
+                .atZone(ZoneId.systemDefault())
+                .toLocalDateTime();
+
+        // 2. 使用 plusDays 添加天数
+        LocalDateTime futureDateTime = localDateTimeNow.plusDays(daysToAdd);
+
+        // 3. 将 LocalDateTime 转换回 Date
+        return Date.from(futureDateTime.atZone(ZoneId.systemDefault()).toInstant());
+    }
 }

+ 8 - 0
fs-service/src/main/java/com/fs/sop/domain/SopOrderLog.java

@@ -53,5 +53,13 @@ public class SopOrderLog extends BaseEntity{
     //销售id
     private Long companyUserId;
 
+    //医生id
+    private Long doctorId;
+
+    //会员id
+    private Long fsUserId;
+
+    //医生会员搭销id
+    private Long doctorMemberSalesId;
 
 }

+ 14 - 2
fs-service/src/main/resources/mapper/sop/SopOrderLogMapper.xml

@@ -14,10 +14,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="updateTime"    column="update_time"    />
         <result property="sendTime"    column="send_time"    />
         <result property="status"    column="status"    />
+        <result property="doctorId"    column="doctor_id"    />
+        <result property="doctorMemberSalesId"    column="doctor_member_sales_id"    />
     </resultMap>
 
     <sql id="selectSopOrderLogVo">
-        select id, sop_id, fs_user_id, is_buy, order_send_type, crate_time, update_time, send_time,status from sop_order_log
+        select id, sop_id, fs_user_id, is_buy, order_send_type, crate_time, update_time, send_time,status,doctor_id,doctor_member_sales_id from sop_order_log
     </sql>
 
     <select id="selectSopOrderLogList" parameterType="SopOrderLog" resultMap="SopOrderLogResult">
@@ -30,6 +32,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="crateTime != null "> and crate_time = #{crateTime}</if>
             <if test="sendTime != null "> and send_time = #{sendTime}</if>
             <if test="status != null "> and status = #{status}</if>
+            <if test="doctorId != null "> and doctor_id = #{doctorId}</if>
+            <if test="doctorMemberSalesId != null "> and doctor_member_sales_id = #{doctorMemberSalesId}</if>
         </where>
     </select>
     
@@ -38,7 +42,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         where id = #{id}
     </select>
     <select id="queryUnsentSOPData" resultType="com.fs.sop.domain.SopOrderLog">
-        SELECT sol.id,sol.sop_id,sol.is_buy,sol.order_send_type,sol.status,sol.ex_id,sol.company_user_id FROM sop_order_log sol WHERE sol.send_time &lt;=NOW() and sol.status=0
+        SELECT sol.id,sol.sop_id,sol.is_buy,sol.order_send_type,sol.status,sol.ex_id,sol.company_user_id,sol.doctor_id,sol.fs_user_id,sol.doctor_member_sales_id FROM sop_order_log sol WHERE sol.send_time &lt;=NOW() and sol.status=0
     </select>
 
     <insert id="insertSopOrderLog" parameterType="SopOrderLog" useGeneratedKeys="true" keyProperty="id">
@@ -53,6 +57,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="sendTime != null">send_time,</if>
             <if test="status != null">status,</if>
             <if test="companyUserId != null">company_user_id,</if>
+            <if test="doctorId != null">doctor_id,</if>
+            <if test="fsUserId != null">fs_user_id,</if>
+            <if test="doctorMemberSalesId != null">doctor_member_sales_id,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="sopId != null">#{sopId},</if>
@@ -64,6 +71,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="sendTime != null">#{sendTime},</if>
             <if test="status != null">#{status},</if>
             <if test="companyUserId != null">#{companyUserId},</if>
+            <if test="doctorId != null">#{doctorId},</if>
+            <if test="fsUserId != null">#{fsUserId},</if>
+            <if test="doctorMemberSalesId != null">#{doctorMemberSalesId},</if>
          </trim>
     </insert>
 
@@ -78,6 +88,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="updateTime != null">update_time = #{updateTime},</if>
             <if test="sendTime != null">send_time = #{sendTime},</if>
             <if test="status != null">status = #{status},</if>
+            <if test="doctorId != null">doctor_id = #{doctorId},</if>
+            <if test="doctorMemberSalesId != null">doctor_member_sales_id = #{doctorMemberSalesId},</if>
         </trim>
         where id = #{id}
     </update>