Ver Fonte

商城处方推送

wjj há 3 dias atrás
pai
commit
0518e2bba4

+ 30 - 0
fs-company/src/main/java/com/fs/company/controller/his/FsPrescribeDataController.java

@@ -0,0 +1,30 @@
+package com.fs.company.controller.his;
+
+import com.fs.common.core.controller.BaseController;
+import com.fs.common.core.domain.AjaxResult;
+import com.fs.common.exception.CustomException;
+import com.fs.his.service.IFsPrescribeDataScrmService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/his/prescribeData")
+public class FsPrescribeDataController extends BaseController {
+
+    @Autowired
+    private IFsPrescribeDataScrmService prescribeDataScrmService;
+
+    @PostMapping("/generatePrescribeData/{companyCustomerId}")
+    public AjaxResult generatePrescribeData(@PathVariable("companyCustomerId") Long companyCustomerId){
+        try {
+            prescribeDataScrmService.generatePrescribeData(companyCustomerId);
+            return AjaxResult.success();
+        } catch (Exception e) {
+            throw new CustomException("开方失败,请联系管理员");
+        }
+
+    }
+}

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

@@ -115,6 +115,12 @@ public interface IFsPrescribeDataScrmService
      * */
     int addDoctorAdvice(BeforePrescribeAddDoctorAdviceDTO addDoctorAdviceDTO);
 
+    /**
+     * 生成商城处方数据
+     * @param companyCustomerId 客户信息ID
+     */
+    void generatePrescribeData(Long companyCustomerId);
+
     /**
      * 商城处方-医生提交建议-开方前的操作
      * */

+ 80 - 0
fs-service/src/main/java/com/fs/his/service/impl/FsPrescribeDataScrmServiceImpl.java

@@ -1,20 +1,25 @@
 package com.fs.his.service.impl;
 
+import cn.hutool.core.util.IdUtil;
 import com.fs.common.BeanCopyUtils;
 import com.fs.common.exception.CustomException;
 import com.fs.common.utils.DateUtils;
+import com.fs.common.utils.uuid.UUID;
 import com.fs.his.domain.*;
 import com.fs.his.dto.*;
 import com.fs.his.enums.DoctorTypeEnum;
 import com.fs.his.mapper.*;
 import com.fs.his.param.PrescribeXyImgParam;
 import com.fs.his.service.IFsPrescribeDataScrmService;
+import com.fs.his.service.IPollingAssignDoctorService;
 import com.fs.his.service.PrescriptionImageService;
 import com.fs.his.vo.DoctorSignVO;
 import com.fs.his.vo.FsPrescribeDataScrmImgVO;
 import com.fs.hisStore.domain.FsStoreProductScrm;
 import com.fs.hisStore.mapper.FsStoreProductScrmMapper;
+import com.fs.qw.domain.FsCompanyCustomer;
 import com.fs.qw.mapper.FsCompanyCustomerMapper;
+import com.fs.qw.service.IFsCompanyCustomerService;
 import com.fs.qw.vo.FsPrescribeDataScrmVO;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
@@ -61,6 +66,12 @@ public class FsPrescribeDataScrmServiceImpl implements IFsPrescribeDataScrmServi
     @Autowired
     private ApplicationContext applicationContext;
 
+    @Autowired
+    private IFsCompanyCustomerService companyCustomerService;
+
+    @Autowired
+    private IPollingAssignDoctorService pollingAssignDoctorService;
+
     private IFsPrescribeDataScrmService self() {
         return applicationContext.getBean(IFsPrescribeDataScrmService.class);
     }
@@ -292,6 +303,75 @@ public class FsPrescribeDataScrmServiceImpl implements IFsPrescribeDataScrmServi
         }
     }
 
+    @Override
+    @Transactional
+    public void generatePrescribeData(Long companyCustomerId) {
+        FsCompanyCustomer customer = companyCustomerService.selectFsCompanyCustomerById(companyCustomerId);
+        if (customer == null) {
+            log.error("未查询到有效客户信息, 客户id:{}", companyCustomerId);
+            throw new CustomException("未查询到有效客户信息");
+        }
+        if (customer.getTemplateId() == null) {
+            log.error("未查询到有效病例模板信息, 客户id:{}", companyCustomerId);
+        }
+        if (customer.getProcessStatus() == 0) {
+            log.error("客户未完善信息, 客户id:{}", companyCustomerId);
+            throw new CustomException("客户未完善信息");
+        }
+        if (customer.getProcessStatus() != 1) {
+            log.error("状态错误, 客户id:{}", companyCustomerId);
+            throw new CustomException("状态错误");
+        }
+        FsPrescribeDataScrm data = new FsPrescribeDataScrm();
+        data.setCompanyCustomerId(companyCustomerId);
+        // 设置患者信息
+        // 患者名称
+        data.setPatientName(customer.getCustomerName());
+        // 患者年龄
+        if (customer.getAge() != null) {
+            data.setPatientAge(customer.getAge().toString());
+        }
+        // 患者性别
+        data.setPatientGender(Integer.valueOf(customer.getSex()));
+        // 患者手机号
+        data.setPatientTel(customer.getPhone());
+        // 处方单号
+        String prescribeCode= IdUtil.getSnowflake(0, 0).nextIdStr();
+        data.setPrescribeCode(prescribeCode);
+        // 医生id
+        data.setDoctorId(customer.getDoctorId());
+        data.setStatus(0);
+        data.setCreateTime(DateUtils.getNowDate());
+        data.setDoctorConfirm(0);
+        data.setIsDocument(0);
+
+        //分配在线的随机药师
+        FsDoctor fsDrugDoctor = null;
+        try {
+            // 使用新写的轮询服务分配药师,传入处方编号
+            fsDrugDoctor = pollingAssignDoctorService.getNextPharmacist(prescribeCode);
+
+            data.setDrugDoctorId(fsDrugDoctor.getDoctorId());
+            data.setDrugDoctorSignUrl(fsDrugDoctor.getSignUrl());
+
+            log.info("轮询分配药师成功 - 处方号:{}, 药师ID:{}, 药师姓名:{}",
+                    prescribeCode, fsDrugDoctor.getDoctorId(), fsDrugDoctor.getDoctorName());
+        } catch (Exception e) {
+            log.error("分配药师失败 - 处方号:{}", prescribeCode, e);
+            data.setDrugDoctorId(1L);//为了不影响主业务执行设置默认值
+        }
+        //出入开方信息
+        fsPrescribeDataScrmMapper.insertFsPrescribeDataScrm(data);
+
+        FsCompanyCustomer mapCustomer = new FsCompanyCustomer();
+        mapCustomer.setId(companyCustomerId);
+        mapCustomer.setProcessStatus(2);
+        mapCustomer.setUpdateTime(DateUtils.getNowDate());
+
+        //更新客户信息
+        companyCustomerMapper.updateFsCompanyCustomer(mapCustomer);
+    }
+
     // ==================== 处方图片生成 ====================
     /**
      * 生成处方图片(异步任务调用)