LIJU 2 months ago
parent
commit
6f76ca5835

+ 39 - 34
src/main/java/cn/hnthyy/thmz/controller/mz/MzPharmacyController.java

@@ -2000,16 +2000,19 @@ public class MzPharmacyController {
         try {
             log.info("撤销退药医保接口调用开始,参数:{}", params);
             
-            // 1. 获取退药明细数据(包含所有医保接口需要的参数
+            // 1. 使用简化版的查询方式(和 getRefundYpMx 一样
             ChargeFeeParamsVo chargeFeeParamsVo = new ChargeFeeParamsVo();
             chargeFeeParamsVo.setPatientId((String) params.get("patientId"));
             chargeFeeParamsVo.setTimes((Integer) params.get("times"));
-            chargeFeeParamsVo.setReceiptNo(String.valueOf(params.get("receiptNo")));
-            chargeFeeParamsVo.setOrderNo(String.valueOf(params.get("orderNo")));
+            // 处理 receiptNo 和 orderNo 的类型转换,支持 Integer 和 String 两种类型
+            Object receiptNoObj = params.get("receiptNo");
+            Object orderNoObj = params.get("orderNo");
+            chargeFeeParamsVo.setReceiptNo(receiptNoObj instanceof Integer ? String.valueOf(receiptNoObj) : (String) receiptNoObj);
+            chargeFeeParamsVo.setOrderNo(orderNoObj instanceof Integer ? String.valueOf(orderNoObj) : (String) orderNoObj);
             chargeFeeParamsVo.setGroupNoOut((String) params.get("groupNoOut"));
-            chargeFeeParamsVo.setConfirmFlag(3); // 已退药状态
+            chargeFeeParamsVo.setConfirmFlag(2); // 已退药状态
             
-            List<Map<String, Object>> refundDetailList = mzPharmacyService.getPrescriptionYpMxCxTy(chargeFeeParamsVo);
+            List<Map<String, Object>> refundDetailList = mzPharmacyService.getPrescriptionYpMxCxTySimple(chargeFeeParamsVo);
             
             if (refundDetailList == null || refundDetailList.isEmpty()) {
                 resultMap.put("code", -1);
@@ -2028,19 +2031,25 @@ public class MzPharmacyController {
                 try {
                     // 2.1 构建追溯码查询参数
                     MzDrugTracCodg tracCodgQuery = new MzDrugTracCodg();
-                    tracCodgQuery.setPatientId((String) item.get("patientId"));
-                    tracCodgQuery.setTimes((Integer) item.get("times"));
-                    tracCodgQuery.setReceiptNo((Integer) item.get("receiptNo"));
-                    tracCodgQuery.setOrderNo((Integer) item.get("orderNo"));
-                    tracCodgQuery.setChargeItemCode((String) item.get("chargeItemCode"));
+                    tracCodgQuery.setPatientId((String) item.get("patient_id"));
+                    // 处理类型转换,支持 Short 和 Integer 两种类型
+                    Object timesObj = item.get("times");
+                    Object receiptNoObj = item.get("receipt_no");
+                    Object orderNoObj = item.get("order_no");
+                    Object itemNoObj = item.get("item_no");
+                    
+                    tracCodgQuery.setTimes(timesObj instanceof Short ? ((Short) timesObj).intValue() : (Integer) timesObj);
+                    tracCodgQuery.setReceiptNo(receiptNoObj instanceof Short ? ((Short) receiptNoObj).intValue() : (Integer) receiptNoObj);
+                    tracCodgQuery.setOrderNo(orderNoObj instanceof Short ? ((Short) orderNoObj).intValue() : (Integer) orderNoObj);
+                    tracCodgQuery.setChargeItemCode((String) item.get("charge_item_code"));
                     tracCodgQuery.setSerial((String) item.get("serial"));
-                    tracCodgQuery.setItemNo((Integer) item.get("itemNo"));
+                    tracCodgQuery.setItemNo(itemNoObj instanceof Short ? ((Short) itemNoObj).intValue() : (Integer) itemNoObj);
                     
                     // 2.2 获取追溯码数据
                     List<MzDrugTracCodg> tracCodgList = mzDrugTracCodgService.getMzDrugTracCodgData(tracCodgQuery);
                     
                     if (tracCodgList == null || tracCodgList.isEmpty()) {
-                        log.warn("药品{}未找到追溯码数据", item.get("chargeItemCode"));
+                        log.warn("药品{}未找到追溯码数据", item.get("charge_item_code"));
                         continue;
                     }
                     
@@ -2055,20 +2064,22 @@ public class MzPharmacyController {
                     
                     // 构建 SelinfoSold 对象
                     SelinfoSold selinfoSold = new SelinfoSold();
-                    selinfoSold.setPatientId((String) item.get("patientId"));
-                    selinfoSold.setTimes((Integer) item.get("times"));
-                    selinfoSold.setReceiptNo((Integer) item.get("receiptNo"));
-                    selinfoSold.setOrderNo((Integer) item.get("orderNo"));
-                    selinfoSold.setChargeItemCode((String) item.get("chargeItemCode"));
-                    selinfoSold.setRealNo((Integer) item.get("realNo"));
-                    selinfoSold.setMedListCodg((String) item.get("nationalCode"));
+                    selinfoSold.setPatientId((String) item.get("patient_id"));
+                    selinfoSold.setTimes(timesObj instanceof Short ? ((Short) timesObj).intValue() : (Integer) timesObj);
+                    selinfoSold.setReceiptNo(receiptNoObj instanceof Short ? ((Short) receiptNoObj).intValue() : (Integer) receiptNoObj);
+                    selinfoSold.setOrderNo(orderNoObj instanceof Short ? ((Short) orderNoObj).intValue() : (Integer) orderNoObj);
+                    selinfoSold.setChargeItemCode((String) item.get("charge_item_code"));
+                    // 处理 realNo 的类型转换
+                    Object realNoObj = item.get("real_no");
+                    selinfoSold.setRealNo(realNoObj instanceof Short ? ((Short) realNoObj).intValue() : (Integer) realNoObj);
+                    selinfoSold.setMedListCodg((String) item.get("national_code"));
                     selinfoSold.setPrscDrName(getCurrentDoctorName(params));
                     selinfoSold.setPharName(getCurrentUserName(params));
                     selinfoSold.setPharPracCertNo(getPharPracCertNo(params));
                     selinfoSold.setSelRetnOpterName(getCurrentUserName(params));
                     selinfoSold.setMdtrtSetlType(item.get("mdtrtSetlType") != null ? (String) item.get("mdtrtSetlType") : "2");
-                    selinfoSold.setRxFlag(item.get("rxFlag") != null ? (String) item.get("rxFlag") : "0");
-                    selinfoSold.setTrdnFlag(item.get("clFlag") != null ? (String) item.get("clFlag") : "0");
+                    selinfoSold.setRxFlag(item.get("rx_flag") != null ? (String) item.get("rx_flag") : "0");
+                    selinfoSold.setTrdnFlag(item.get("cl_flag") != null ? (String) item.get("cl_flag") : "0");
                     selinfoSold.setPsnCertType(item.get("psnCertType") != null ? (String) item.get("psnCertType") : "01");
                     selinfoSold.setCertno(item.get("certno") != null ? (String) item.get("certno") : "");
                     selinfoSold.setPsnName(item.get("psnName") != null ? (String) item.get("psnName") : "");
@@ -2091,20 +2102,18 @@ public class MzPharmacyController {
                     
                     if (ybResult != null && ybResult.getCode() == 0) {
                         successCount++;
-                        log.info("药品{}医保接口调用成功", item.get("chargeItemCode"));
+                        log.info("药品{}医保接口调用成功", item.get("charge_item_code"));
                     } else {
                         failCount++;
-                        String errorMessage = ybResult != null ? ybResult.getMessage() : "医保接口调用失败";
-                        errorMsg.append("药品").append(item.get("chargeItemCode"))
-                                .append("医保接口调用失败:").append(errorMessage).append("; ");
-                        log.error("药品{}医保接口调用失败:{}", item.get("chargeItemCode"), errorMessage);
+                        String errorMessage = ybResult != null ? ybResult.getMessage() : "医保接口返回空结果";
+                        errorMsg.append("药品").append(item.get("charge_item_code")).append(": ").append(errorMessage).append("; ");
+                        log.error("药品{}医保接口调用失败: {}", item.get("charge_item_code"), errorMessage);
                     }
-                    
                 } catch (Exception e) {
                     failCount++;
-                    errorMsg.append("药品").append(item.get("chargeItemCode"))
-                            .append("处理异常:").append(e.getMessage()).append("; ");
-                    log.error("药品{}处理异常", item.get("chargeItemCode"), e);
+                    String errorMessage = "药品" + item.get("charge_item_code") + "处理异常: " + e.getMessage();
+                    errorMsg.append(errorMessage).append("; ");
+                    log.error(errorMessage, e);
                 }
             }
             
@@ -2112,20 +2121,16 @@ public class MzPharmacyController {
             if (failCount == 0) {
                 resultMap.put("code", 0);
                 resultMap.put("message", "撤销退药医保接口调用成功,共处理" + successCount + "个药品");
-                resultMap.put("data", null);
             } else {
                 resultMap.put("code", -1);
                 resultMap.put("message", "撤销退药医保接口调用部分失败,成功" + successCount + "个,失败" + failCount + "个。错误信息:" + errorMsg.toString());
-                resultMap.put("data", null);
             }
             
             return resultMap;
-            
         } catch (Exception e) {
             log.error("撤销退药医保接口调用异常", e);
             resultMap.put("code", -1);
             resultMap.put("message", "撤销退药医保接口调用异常:" + e.getMessage());
-            resultMap.put("data", null);
             return resultMap;
         }
     }

+ 42 - 74
src/main/java/cn/hnthyy/thmz/mapper/his/mz/MzPharmacyMapper.java

@@ -314,80 +314,8 @@ public interface MzPharmacyMapper {
     List<Map<String, Object>> selectPrescriptionYpMx(ChargeFeeParamsVo chargeFeeParamsVo);
 
 
-    /**
-     * 查询处方药品明细 撤销退药使用
-     *
-     * @param chargeFeeParamsVo
-     * @return
-     */
-    @Select({"<script>" +
-            "SELECT DISTINCT yp_mz_fytj.serial_no,   " +
-            "         yp_mz_fytj.order_no,   " +
-            "         rtrim(yp_mz_fytj.patient_id)patient_id,   " +
-            "         yp_mz_fytj.times,   " +
-            "         yp_mz_fytj.receipt_no,   " +
-            "         drugname=c.name+'('+isnull(d.abbr_name,isnull(d.name,''))+')',   " +
-            "         specification=c.specification,   " +
-            "         quantity= case when isnull(cy_fy, 0) > 0 then yp_mz_fytj.quantity * cy_fy else yp_mz_fytj.quantity  end,   " +
-            "         yp_mz_fytj.unit_price,   " +
-            "         yp_mz_fytj.item_no,   " +
-            "         yp_mz_fytj.drug_flag,   " +
-            "         yp_mz_fytj.charge_item_code,   " +
-            "         yp_mz_fytj.serial,   " +
-            "         yp_mz_fytj.confirm_time,   " +
-            "         yp_mz_fytj.group_no,   " +
-            "         yp_mz_fytj.bill_item_code,   " +
-            "         yp_mz_fytj.pay_mark,   " +
-            "         yp_mz_fytj.charge_item_type,   " +
-            "         yp_mz_fytj.name,   " +
-            "         yp_mz_fytj.charge_date,   " +
-            "         yp_mz_fytj.cy_fy,   " +
-            "         yp_mz_fytj.specification,   " +
-            "         yp_mz_fytj.drugname,   " +
-            "         yp_mz_fytj.doctor_name,   " +
-            "         yp_mz_fytj.doctor_id,   " +
-            "         warn_dept=yp_mz_fytj.warn_dept,   " +
-            "         yp_mz_fytj.country_flag,   " +
-            "         yp_mz_fytj.confirm_flag,   " +
-            "         yp_mz_fytj.self_flag,   " +
-            "         yp_mz_fytj.response_type,   " +
-            "         yp_mz_fytj.warn_dept  ," +
-            "         yp_mz_fytj.refund_medicine_remark  ," +
-            "         real_no=yp_mz_fytj.real_no," +
-            "         win_no = yp_mz_fytj.win_no, " +
-            "         -- 医保接口需要的患者信息 " +
-            "         pm.certificate_type as psnCertType, " +
-            "         pm.social_no as certno, " +
-            "         pm.name as psnName, " +
-            "         -- 医保接口需要的药品信息 " +
-            "         c.national_code as nationalCode, " +
-            "         c.cl_flag as clFlag, " +
-            "         c.rx_flag as rxFlag, " +
-            "         -- 医保接口需要的收费明细信息 " +
-            "         mcd.real_no as realNo " +
-            "    FROM yp_mz_fytj WITH(NOLOCK) " +
-            "    JOIN yp_zd_dict c WITH(NOLOCK) ON yp_mz_fytj.charge_item_code = c.code AND yp_mz_fytj.serial = c.serial " +
-            "    LEFT JOIN yp_zd_manufactory d WITH(NOLOCK) ON c.manu_code = d.code " +
-            "    -- 关联患者信息表 " +
-            "    LEFT JOIN mz_patient_mi pm WITH(NOLOCK) ON yp_mz_fytj.patient_id = pm.patient_id " +
-            "    -- 关联收费明细表 " +
-            "    LEFT JOIN mz_charge_detail mcd WITH(NOLOCK) ON yp_mz_fytj.patient_id = mcd.patient_id " +
-            "        AND yp_mz_fytj.times = mcd.times " +
-            "        AND yp_mz_fytj.receipt_no = mcd.receipt_no " +
-            "        AND yp_mz_fytj.order_no = mcd.order_no " +
-            "        AND yp_mz_fytj.charge_item_code = mcd.charge_item_code " +
-            "        AND yp_mz_fytj.serial = mcd.serial " +
-            "        AND yp_mz_fytj.item_no = mcd.item_no " +
-            "   WHERE yp_mz_fytj.patient_id = #{patientId,jdbcType=CHAR}  AND  " +
-            "          yp_mz_fytj.times = #{times,jdbcType=INTEGER}  AND  " +
-            "          yp_mz_fytj.receipt_no = #{receiptNo,jdbcType=CHAR}  AND  " +
-            "          yp_mz_fytj.order_no = #{orderNo,jdbcType=CHAR}  AND  " +
-            "         yp_mz_fytj.group_no_out = #{groupNoOut,jdbcType=CHAR} AND  " +
-            "         yp_mz_fytj.confirm_flag = #{confirmFlag,jdbcType=CHAR}   and " +
-            "         yp_mz_fytj.serial_no <![CDATA[<]]> 0 " +
-            "ORDER BY yp_mz_fytj.item_no ASC ",
-            "</script>"})
-    List<Map<String, Object>> selectPrescriptionYpMxCxTy(ChargeFeeParamsVo chargeFeeParamsVo);
+
+
     /**
      * 更新发药统计状态
      *
@@ -1425,4 +1353,44 @@ public interface MzPharmacyMapper {
             " ORDER BY create_date DESC",
             "</script>"})
     List<Map<String, Object>> selectTracCodgRecordsByAssociation(Map<String, Object> queryParams);
+
+    /**
+     * 查询患者医保信息
+     *
+     * @param patientId
+     * @return
+     */
+    @Select("SELECT certificate_type as psnCertType, social_no as certno, name as psnName " +
+            "FROM mz_patient_mi WITH(NOLOCK) " +
+            "WHERE patient_id = #{patientId}")
+    Map<String, Object> selectPatientMiInfo(@Param("patientId") String patientId);
+
+    /**
+     * 查询收费明细信息
+     *
+     * @param patientId
+     * @param times
+     * @param receiptNo
+     * @param orderNo
+     * @param chargeItemCode
+     * @param serial
+     * @param itemNo
+     * @return
+     */
+    @Select("SELECT real_no as realNo " +
+            "FROM mz_charge_detail WITH(NOLOCK) " +
+            "WHERE patient_id = #{patientId} " +
+            "AND times = #{times} " +
+            "AND receipt_no = #{receiptNo} " +
+            "AND order_no = #{orderNo} " +
+            "AND charge_item_code = #{chargeItemCode} " +
+            "AND serial = #{serial} " +
+            "AND item_no = #{itemNo}")
+    Map<String, Object> selectChargeDetailInfo(@Param("patientId") String patientId,
+                                              @Param("times") Integer times,
+                                              @Param("receiptNo") Integer receiptNo,
+                                              @Param("orderNo") Integer orderNo,
+                                              @Param("chargeItemCode") String chargeItemCode,
+                                              @Param("serial") String serial,
+                                              @Param("itemNo") Integer itemNo);
 }

+ 2 - 2
src/main/java/cn/hnthyy/thmz/service/his/mz/MzPharmacyService.java

@@ -57,11 +57,11 @@ public interface MzPharmacyService {
     List<Map<String,Object>> getPrescriptionYpMx(ChargeFeeParamsVo chargeFeeParamsVo);
 
     /**
-     * 查询处方药品明细 撤销退药
+     * 查询处方药品明细 撤销退药(简化版)
      * @param chargeFeeParamsVo
      * @return
      */
-    List<Map<String,Object>> getPrescriptionYpMxCxTy(ChargeFeeParamsVo chargeFeeParamsVo);
+    List<Map<String,Object>> getPrescriptionYpMxCxTySimple(ChargeFeeParamsVo chargeFeeParamsVo);
 
     /**
      * 退药处理

+ 59 - 2
src/main/java/cn/hnthyy/thmz/service/impl/his/mz/MzPharmacyServiceImpl.java

@@ -115,9 +115,66 @@ public class MzPharmacyServiceImpl implements MzPharmacyService {
         return mzPharmacyMapper.selectPrescriptionYpMx(chargeFeeParamsVo);
     }
 
+
+
     @Override
-    public List<Map<String, Object>> getPrescriptionYpMxCxTy(ChargeFeeParamsVo chargeFeeParamsVo) {
-        return mzPharmacyMapper.selectPrescriptionYpMxCxTy(chargeFeeParamsVo);
+    public List<Map<String, Object>> getPrescriptionYpMxCxTySimple(ChargeFeeParamsVo chargeFeeParamsVo) {
+        // 1. 使用简单的查询获取基础数据(和 getPrescriptionYpMx 一样)
+        List<Map<String, Object>> baseDataList = mzPharmacyMapper.selectPrescriptionYpMx(chargeFeeParamsVo);
+        
+        if (baseDataList == null || baseDataList.isEmpty()) {
+            return baseDataList;
+        }
+        
+        // 2. 获取患者信息(只需要查询一次)
+        Map<String, Object> patientInfo = mzPharmacyMapper.selectPatientMiInfo(chargeFeeParamsVo.getPatientId());
+        
+        // 3. 为每个药品项添加医保接口需要的额外信息
+        for (Map<String, Object> item : baseDataList) {
+            // 添加患者信息
+            if (patientInfo != null) {
+                item.put("psnCertType", patientInfo.get("psnCertType"));
+                item.put("certno", patientInfo.get("certno"));
+                item.put("psnName", patientInfo.get("psnName"));
+            }
+            
+            // 添加药品信息(从 yp_zd_dict 表获取)
+            String chargeItemCode = (String) item.get("charge_item_code");
+            String serial = (String) item.get("serial");
+            if (chargeItemCode != null && serial != null) {
+                // 这里可以从 yp_zd_dict 表获取 national_code, cl_flag, rx_flag
+                // 暂时使用默认值,如果需要可以从数据库查询
+                item.put("nationalCode", chargeItemCode); // 可以根据需要查询实际的 national_code
+                item.put("clFlag", "0"); // 默认值
+                item.put("rxFlag", "0"); // 默认值
+            }
+            
+            // 获取收费明细信息
+            String patientId = (String) item.get("patient_id");
+            // 处理类型转换,支持 Short 和 Integer 两种类型
+            Object timesObj = item.get("times");
+            Object receiptNoObj = item.get("receipt_no");
+            Object orderNoObj = item.get("order_no");
+            Object itemNoObj = item.get("item_no");
+            
+            Integer times = timesObj instanceof Short ? ((Short) timesObj).intValue() : (Integer) timesObj;
+            Integer receiptNo = receiptNoObj instanceof Short ? ((Short) receiptNoObj).intValue() : (Integer) receiptNoObj;
+            Integer orderNo = orderNoObj instanceof Short ? ((Short) orderNoObj).intValue() : (Integer) orderNoObj;
+            Integer itemNo = itemNoObj instanceof Short ? ((Short) itemNoObj).intValue() : (Integer) itemNoObj;
+            
+            if (patientId != null && times != null && receiptNo != null && 
+                orderNo != null && chargeItemCode != null && serial != null && itemNo != null) {
+                
+                Map<String, Object> chargeDetailInfo = mzPharmacyMapper.selectChargeDetailInfo(
+                    patientId, times, receiptNo, orderNo, chargeItemCode, serial, itemNo);
+                
+                if (chargeDetailInfo != null) {
+                    item.put("realNo", chargeDetailInfo.get("realNo"));
+                }
+            }
+        }
+        
+        return baseDataList;
     }
 
     @Override