Bläddra i källkod

益寿缘-新增对接超拼网的回执接口

cgp 4 dagar sedan
förälder
incheckning
4de819b82e

+ 16 - 2
fs-admin/src/main/java/com/fs/his/controller/OpenApiFsUserInformationController.java

@@ -7,6 +7,7 @@ import com.fs.common.utils.DateUtils;
 import com.fs.his.dto.CPWUserAndAddressAddDTO;
 import com.fs.his.dto.CPWUserInfoCollectionAddDTO;
 import com.fs.his.validator.cpw.UserInformationValidator;
+import com.fs.his.vo.CPWPrescribeDataVO;
 import com.fs.his.vo.FsQuestionAndAnswerVO;
 import com.fs.his.vo.SubmitUserInformationVO;
 import com.fs.hisStore.service.IOpenApiCPWUserInformationService;
@@ -79,11 +80,24 @@ public class OpenApiFsUserInformationController extends BaseController {
     }
 
     /**
-     * 推送处方信息给第三方
+     * 模拟定时推送处方信息给第三方
      * */
     @PostMapping("/pushPrescription")
     public AjaxResult pushPrescription() {
-        return AjaxResult.success();
+        List<CPWPrescribeDataVO> cpwPrescribeDataVOS = openApiFsUserInformationService.pushPrescription();
+        return AjaxResult.success(cpwPrescribeDataVOS);
+    }
+
+    /**
+     * 推送处方回执接口
+     */
+    @PostMapping("/prescriptionReceipt")
+    public AjaxResult prescriptionReceipt(@RequestBody List<Long> prescriptionIds) {
+        int result = openApiFsUserInformationService.prescriptionReceipt(prescriptionIds);
+        if (result > 0) {
+            return AjaxResult.success();
+        }
+        return AjaxResult.error();
     }
 
 

+ 5 - 0
fs-service/src/main/java/com/fs/his/mapper/FsPrescribeDrugMapper.java

@@ -73,4 +73,9 @@ public interface FsPrescribeDrugMapper
     List<FsDoctorPrescribeDrug> selectFsPrescribeDrugListByImg2();
     @Select("select * from fs_store_product where product_name=#{drugName} and store_id=#{storeId} LIMIT 1 ")
     FsStoreProduct selectFsPrescribeDrugCode(@Param("drugName") String drugName, @Param("storeId")Long storeId);
+
+    /**
+     * 根据处方id列表查询处方药品明细
+     * */
+    List<FsPrescribeDrug> selectFsPrescribeDrugListByPrescribeIds(@Param("prescribeIds") List<Long> prescribeIds);
 }

+ 10 - 0
fs-service/src/main/java/com/fs/his/mapper/FsPrescribeMapper.java

@@ -308,4 +308,14 @@ public interface FsPrescribeMapper
      * @return 待审核的处方信息,null表示没有待审核处方
      */
     FsPrescribeListVO selectFsPrescribeListVOByThirdUserId(@Param("thirdPartyUserId") Long thirdPartyUserId);
+
+    /**
+     * 获取未推送到超拼网的处方数据列表
+     **/
+    List<FsPrescribe> selectFsPrescribeListDataPushCPW();
+
+    /**
+     * 根据处方id更新推送到超拼网的处方状态
+     **/
+    int updateFsPrescribeListDataCPWByPrescribeIds(@Param("prescriptionIds") List<Long> prescriptionIds);
 }

+ 30 - 0
fs-service/src/main/java/com/fs/his/vo/CPWPrescribeDataVO.java

@@ -0,0 +1,30 @@
+package com.fs.his.vo;
+
+import lombok.Data;
+
+import java.util.List;
+/**
+ * 待推送的处方VO对象---超拼网
+ * */
+@Data
+public class CPWPrescribeDataVO {
+    /**
+     * 患者id
+     */
+    private Long patientId;
+
+    /**
+     * 患者姓名
+     */
+    private String patientName;
+
+    /**
+     * 处方图片地址
+     */
+    private String prescribeImgUrl;
+
+    /**
+     * 药品信息
+     * */
+    private List<CPWPrescribeDrugVO> drugList;
+}

+ 38 - 0
fs-service/src/main/java/com/fs/his/vo/CPWPrescribeDrugVO.java

@@ -0,0 +1,38 @@
+package com.fs.his.vo;
+
+import lombok.Data;
+/**
+ * 处方药品Vo对象---超拼网
+ * */
+@Data
+public class CPWPrescribeDrugVO {
+    /**
+     * 处方ID
+     */
+    private Long prescribeId;
+
+    /**
+     * 药品名称
+     */
+    private String drugName;
+
+    /**
+     * 规格
+     */
+    private String drugSpec;
+
+    /**
+     * 使⽤⽅法
+     */
+    private String usageMethod;
+
+    /**
+     * 用药频次
+     */
+    private String usageFrequencyUnit;
+
+    /**
+     * 每次⽤药数量
+     */
+    private String usagePerUseCount;
+}

+ 8 - 3
fs-service/src/main/java/com/fs/hisStore/service/IOpenApiCPWUserInformationService.java

@@ -2,9 +2,12 @@ package com.fs.hisStore.service;
 
 import com.fs.his.dto.CPWUserAndAddressAddDTO;
 import com.fs.his.dto.CPWUserInfoCollectionAddDTO;
+import com.fs.his.vo.CPWPrescribeDataVO;
 import com.fs.his.vo.FsQuestionAndAnswerVO;
 import com.fs.his.vo.SubmitUserInformationVO;
 
+import java.util.List;
+
 /**
  * 对接-超拼网-信息采集服务
  * */
@@ -22,7 +25,7 @@ public interface IOpenApiCPWUserInformationService {
     /**
      * 推送处方信息给第三方(超拼网)
      * */
-    public Object pushPrescription(String userId, String prescriptionId);
+    public List<CPWPrescribeDataVO> pushPrescription();
 
 
 
@@ -39,6 +42,8 @@ public interface IOpenApiCPWUserInformationService {
     public SubmitUserInformationVO submitUserInformation(CPWUserInfoCollectionAddDTO collectionAddDTO);
 
 
-
-
+    /**
+     * 处方推送到第三方成功,更新处方状态为已推送
+     * */
+    int prescriptionReceipt(List<Long> prescriptionIds);
 }

+ 79 - 17
fs-service/src/main/java/com/fs/hisStore/service/impl/OpenApiCPWUserInformationServiceImpl.java

@@ -4,21 +4,13 @@ import cn.hutool.core.util.IdUtil;
 import com.alibaba.fastjson.JSON;
 import com.fs.common.exception.CustomException;
 import com.fs.common.utils.DateUtils;
-import com.fs.his.domain.FsDoctor;
-import com.fs.his.domain.FsPrescribe;
-import com.fs.his.domain.FsUser;
-import com.fs.his.domain.FsUserAddress;
+import com.fs.his.domain.*;
 import com.fs.his.dto.*;
-import com.fs.his.mapper.FsDoctorMapper;
-import com.fs.his.mapper.FsPrescribeMapper;
-import com.fs.his.mapper.FsUserAddressMapper;
-import com.fs.his.mapper.FsUserMapper;
+import com.fs.his.mapper.*;
 import com.fs.his.service.IFsQuestionAndAnswerService;
 import com.fs.his.service.IPollingAssignDoctorService;
 import com.fs.his.utils.IdCardUtil;
-import com.fs.his.vo.FsPrescribeListVO;
-import com.fs.his.vo.FsQuestionAndAnswerVO;
-import com.fs.his.vo.SubmitUserInformationVO;
+import com.fs.his.vo.*;
 import com.fs.hisStore.domain.FsUserInformationCollection;
 import com.fs.hisStore.mapper.FsUserInformationCollectionMapper;
 import com.fs.hisStore.service.IOpenApiCPWUserInformationService;
@@ -32,9 +24,8 @@ import org.springframework.transaction.annotation.Transactional;
 import java.math.BigDecimal;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 对接-超拼网-信息采集服务实现类
@@ -61,6 +52,9 @@ public class OpenApiCPWUserInformationServiceImpl implements IOpenApiCPWUserInfo
     @Autowired
     private FsPrescribeMapper prescribeMapper;
 
+    @Autowired
+    private FsPrescribeDrugMapper prescribeDrugMapper;
+
     @Autowired
     private FsDoctorMapper doctorMapper;
 
@@ -163,7 +157,7 @@ public class OpenApiCPWUserInformationServiceImpl implements IOpenApiCPWUserInfo
         fsPrescribe.setPrescribeDoctorSignUrl(fsDoctor.getSignUrl());
 
         //分配在线的随机药师
-        fsPrescribe.setDrugDoctorId(515L);
+        fsPrescribe.setDrugDoctorId(514L);
         fsPrescribe.setDrugDoctorSignUrl("https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/ysy/20251114/7a0d28df6aa94a9c819e025c9a230c6f.png");
 //        FsDoctor fsDrugDoctor = null;
 //        try {
@@ -240,8 +234,76 @@ public class OpenApiCPWUserInformationServiceImpl implements IOpenApiCPWUserInfo
     }
 
     @Override
-    public Object pushPrescription(String userId, String prescriptionId) {
-        return null;
+    public int prescriptionReceipt(List<Long> prescriptionIds) {
+        if (CollectionUtils.isEmpty(prescriptionIds)){
+            return 0;
+        }
+        log.info("超拼网-推送回执处方id:{}", prescriptionIds);
+        return prescribeMapper.updateFsPrescribeListDataCPWByPrescribeIds(prescriptionIds);
+    }
+
+    @Override
+    public List<CPWPrescribeDataVO> pushPrescription() {
+        // 获取待推送到"超拼网"的处方数据
+        List<FsPrescribe> fsPrescribes = prescribeMapper.selectFsPrescribeListDataPushCPW();
+
+        if (CollectionUtils.isEmpty(fsPrescribes)) {
+            log.info("无待推送超拼网的处方");
+            return new ArrayList<>();
+        }
+
+        // 获取所有处方的ID列表
+        List<Long> prescribeIds = fsPrescribes.stream()
+                .map(FsPrescribe::getPrescribeId)
+                .collect(Collectors.toList());
+
+        // 批量查询药品信息
+        List<FsPrescribeDrug> prescribeDrugList = prescribeDrugMapper.selectFsPrescribeDrugListByPrescribeIds(prescribeIds);
+
+        // 按处方ID分组药品
+        Map<Long, List<FsPrescribeDrug>> prescribeDrugMap = new HashMap<>();
+        if (CollectionUtils.isNotEmpty(prescribeDrugList)) {
+            prescribeDrugMap = prescribeDrugList.stream()
+                    .collect(Collectors.groupingBy(FsPrescribeDrug::getPrescribeId));
+        }
+
+        // 组装返回结果
+        List<CPWPrescribeDataVO> resultList = new ArrayList<>();
+        for (FsPrescribe item : fsPrescribes) {
+            CPWPrescribeDataVO resultVO = new CPWPrescribeDataVO();
+            resultVO.setPatientId(item.getPatientId());
+            resultVO.setPatientName(item.getPatientName());
+            resultVO.setPrescribeImgUrl(item.getPrescribeImgUrl());
+
+            // 获取该处方的药品列表并转换为VO
+            List<FsPrescribeDrug> drugList = prescribeDrugMap.getOrDefault(item.getPrescribeId(), new ArrayList<>());
+            List<CPWPrescribeDrugVO> drugVOList = convertToCPWPrescribeDrugVO(drugList);
+            resultVO.setDrugList(drugVOList);
+
+            resultList.add(resultVO);
+        }
+
+        return resultList;
+    }
+
+    /**
+     * 将FsPrescribeDrug转换为CPWPrescribeDrugVO
+     */
+    private List<CPWPrescribeDrugVO> convertToCPWPrescribeDrugVO(List<FsPrescribeDrug> drugList) {
+        if (CollectionUtils.isEmpty(drugList)) {
+            return new ArrayList<>();
+        }
+
+        return drugList.stream().map(drug -> {
+            CPWPrescribeDrugVO vo = new CPWPrescribeDrugVO();
+            vo.setPrescribeId(drug.getPrescribeId());
+            vo.setDrugName(drug.getDrugName());
+            vo.setDrugSpec(drug.getDrugSpec());
+            vo.setUsageMethod(drug.getUsageMethod());
+            vo.setUsageFrequencyUnit(drug.getUsageFrequencyUnit());
+            vo.setUsagePerUseCount(drug.getUsagePerUseCount());
+            return vo;
+        }).collect(Collectors.toList());
     }
 
     /**

+ 17 - 0
fs-service/src/main/resources/mapper/his/FsPrescribeDrugMapper.xml

@@ -51,6 +51,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         where drug_id = #{drugId}
     </select>
 
+    <select id="selectFsPrescribeDrugListByPrescribeIds" resultMap="FsPrescribeDrugResult">
+        <include refid="selectFsPrescribeDrugVo"/>
+        <where>
+            <choose>
+                <when test="prescribeIds != null and prescribeIds.size() > 0">
+                    prescribe_id IN
+                    <foreach item="item" collection="prescribeIds" separator="," open="(" close=")">
+                        #{item}
+                    </foreach>
+                </when>
+                <otherwise>
+                    AND 1=2  <!-- 永远为false,返回空结果 -->
+                </otherwise>
+            </choose>
+        </where>
+    </select>
+
     <insert id="insertFsPrescribeDrug" parameterType="FsPrescribeDrug" useGeneratedKeys="true" keyProperty="drugId">
         insert into fs_prescribe_drug
         <trim prefix="(" suffix=")" suffixOverrides=",">

+ 21 - 0
fs-service/src/main/resources/mapper/his/FsPrescribeMapper.xml

@@ -440,4 +440,25 @@
         where third_party_user_id = #{thirdPartyUserId}
           and (status = 0 or status = 2) <!--  医师、药师审核中,以及药师审核不通过的状态 -->
     </select>
+
+    <select id="selectFsPrescribeListDataPushCPW" resultMap="FsPrescribeResult">
+        <include refid="selectFsPrescribeVo"/>
+        where status =1 and is_send_to_third_party =0 and prescribe_img_url is NOT NULL
+        order by create_time asc
+        limit 10
+    </select>
+
+    <update id="updateFsPrescribeListDataCPWByPrescribeIds" parameterType="java.util.List">
+        update fs_prescribe
+        set
+        is_send_to_third_party = 1  <!-- 标记为已推送 -->
+        where
+        prescribe_id in
+        <foreach collection="prescriptionIds" item="prescribeId" separator="," open="(" close=")">
+            #{prescribeId}
+        </foreach>
+        and status = 1
+        and is_send_to_third_party = 0
+        and prescribe_img_url is not null
+    </update>
 </mapper>