Browse Source

Merge branch 'dev' of http://47.103.65.67:3000/yeguodong/thmz into dev

yeguodong 2 weeks ago
parent
commit
40ee9bd40b

+ 281 - 0
src/main/java/cn/hnthyy/thmz/controller/mz/MzPharmacyController.java

@@ -52,6 +52,11 @@ import cn.hnthyy.thmz.vo.MzRefundMedicineVo;
 import cn.hnthyy.thmz.vo.MzSendMedicineVo;
 import cn.hnthyy.thmz.vo.PharmacyCellVo;
 import cn.hnthyy.thmz.vo.YpMzFytjVo;
+import cn.hnthyy.thmz.controller.yb.YbController;
+import cn.hnthyy.thmz.entity.yb.SelinfoSold;
+import cn.hnthyy.thmz.entity.yb.SelinfoSoldTotal;
+import cn.hnthyy.thmz.entity.yb.DrugTracCodg;
+import cn.hnthyy.thmz.entity.jy.ResultVo;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.time.DateUtils;
@@ -123,6 +128,9 @@ public class MzPharmacyController {
     private MzZdInstructionCodeService mzZdInstructionCodeService;
     @Resource
     private YpZdGroupNameService ypZdGroupNameService;
+    
+    @Autowired
+    private YbController ybController;
     /**
      * 查询处方信息
      *
@@ -1980,4 +1988,277 @@ public class MzPharmacyController {
         
         return resultMap;
     }
+
+    /**
+     * 撤销退药时调用医保销售接口
+     * 内嵌获取退药明细、追溯码查询、医保接口调用
+     */
+    @RequestMapping(value = "/cancelRefundWithYb", method = {RequestMethod.POST})
+    @UserLoginToken
+    public Map<String, Object> cancelRefundWithYb(@RequestBody Map<String, Object> params) {
+        Map<String, Object> resultMap = new HashMap<>();
+        try {
+            log.info("撤销退药医保接口调用开始,参数:{}", params);
+            
+            // 1. 使用简化版的查询方式(和 getRefundYpMx 一样)
+            ChargeFeeParamsVo chargeFeeParamsVo = new ChargeFeeParamsVo();
+            chargeFeeParamsVo.setPatientId((String) params.get("patientId"));
+            chargeFeeParamsVo.setTimes((Integer) params.get("times"));
+            // 处理 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(2); // 已退药状态
+            
+            List<Map<String, Object>> refundDetailList = mzPharmacyService.getPrescriptionYpMxCxTySimple(chargeFeeParamsVo);
+            
+            if (refundDetailList == null || refundDetailList.isEmpty()) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "未找到退药明细数据");
+                return resultMap;
+            }
+            
+            log.info("获取到退药明细数据,共{}条", refundDetailList.size());
+            
+            // 2. 遍历每个药品,获取追溯码并调用医保接口
+            int successCount = 0;
+            int failCount = 0;
+            StringBuilder errorMsg = new StringBuilder();
+            
+            for (Map<String, Object> item : refundDetailList) {
+                try {
+                    // 2.1 构建追溯码查询参数
+                    MzDrugTracCodg tracCodgQuery = new MzDrugTracCodg();
+                    tracCodgQuery.setPatientId((String) item.get("patient_id"));
+                    // 处理类型转换,支持 Short 和 Integer 两种类型
+                    Object timesObj = item.get("times");
+                    Object itemReceiptNoObj = item.get("receipt_no");
+                    Object itemOrderNoObj = item.get("order_no");
+                    Object itemNoObj = item.get("item_no");
+                    
+                    tracCodgQuery.setTimes(timesObj instanceof Short ? ((Short) timesObj).intValue() : (Integer) timesObj);
+                    // 修复:追溯码表中 receipt_no 是正数,需要转换
+                    Integer itemReceiptNo = itemReceiptNoObj instanceof Short ? ((Short) itemReceiptNoObj).intValue() : (Integer) itemReceiptNoObj;
+                    tracCodgQuery.setReceiptNo(Math.abs(itemReceiptNo)); // 转换为正数
+                    tracCodgQuery.setOrderNo(itemOrderNoObj instanceof Short ? ((Short) itemOrderNoObj).intValue() : (Integer) itemOrderNoObj);
+                    tracCodgQuery.setChargeItemCode((String) item.get("charge_item_code"));
+                    tracCodgQuery.setSerial((String) item.get("serial"));
+                    tracCodgQuery.setItemNo(itemNoObj instanceof Short ? ((Short) itemNoObj).intValue() : (Integer) itemNoObj);
+                    // 修复:添加 group_no 参数,从 params 中获取 groupNoOut
+                    String groupNoOut = (String) params.get("groupNoOut");
+                    tracCodgQuery.setGroupNo(groupNoOut);
+                    
+                    // 添加调试日志
+                    log.info("追溯码查询参数: patientId={}, times={}, receiptNo={}, orderNo={}, chargeItemCode={}, serial={}, itemNo={}, groupNo={}", 
+                            tracCodgQuery.getPatientId(), tracCodgQuery.getTimes(), tracCodgQuery.getReceiptNo(), 
+                            tracCodgQuery.getOrderNo(), tracCodgQuery.getChargeItemCode(), tracCodgQuery.getSerial(), 
+                            tracCodgQuery.getItemNo(), tracCodgQuery.getGroupNo());
+                    
+                    // 2.2 获取追溯码数据
+                    List<MzDrugTracCodg> tracCodgList = mzDrugTracCodgService.getMzDrugTracCodgData(tracCodgQuery);
+                    
+                    if (tracCodgList == null || tracCodgList.isEmpty()) {
+                        log.warn("药品{}未找到追溯码数据", item.get("charge_item_code"));
+                        continue;
+                    }
+                    
+                    // 2.3 构建医保接口参数
+                    Map<String, Object> ybParams = buildYbParamsForCancelRefund(item, params);
+                    
+                    // 2.4 记录医保接口传参日志
+                    log.info("医保接口参数: {}", ybParams);
+                    
+                    // 2.5 构建 SelinfoSoldTotal 对象
+                    SelinfoSoldTotal selinfoSoldTotal = new SelinfoSoldTotal();
+                    
+                    // 构建 SelinfoSold 对象
+                    SelinfoSold selinfoSold = new SelinfoSold();
+                    selinfoSold.setPatientId((String) item.get("patient_id"));
+                    selinfoSold.setTimes(timesObj instanceof Short ? ((Short) timesObj).intValue() : (Integer) timesObj);
+                    selinfoSold.setReceiptNo(itemReceiptNoObj instanceof Short ? ((Short) itemReceiptNoObj).intValue() : (Integer) itemReceiptNoObj);
+                    selinfoSold.setOrderNo(itemOrderNoObj instanceof Short ? ((Short) itemOrderNoObj).intValue() : (Integer) itemOrderNoObj);
+                    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("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") : "");
+                    
+                    selinfoSoldTotal.setSelinfoSold(selinfoSold);
+                    
+                    // 构建追溯码列表
+                    List<DrugTracCodg> drugTracCodgList = new ArrayList<>();
+                    for (MzDrugTracCodg tracCodg : tracCodgList) {
+                        DrugTracCodg drugTracCodg = new DrugTracCodg();
+                        drugTracCodg.setDrugTracCodg(tracCodg.getDrugTracCodg());
+                        drugTracCodgList.add(drugTracCodg);
+                    }
+                    selinfoSoldTotal.setDrugtracinfo(drugTracCodgList);
+                    
+                    log.info("最终调用医保接口参数: {}", selinfoSoldTotal);
+                    
+                    // 2.6 调用医保销售接口
+                    ResultVo ybResult = ybController.saleGoodsItem(selinfoSoldTotal);
+                    
+                    if (ybResult != null && ybResult.getCode() == 0) {
+                        successCount++;
+                        log.info("药品{}医保接口调用成功", item.get("charge_item_code"));
+                    } else {
+                        failCount++;
+                        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++;
+                    String errorMessage = "药品" + item.get("charge_item_code") + "处理异常: " + e.getMessage();
+                    errorMsg.append(errorMessage).append("; ");
+                    log.error(errorMessage, e);
+                }
+            }
+            
+            // 3. 返回结果
+            if (failCount == 0) {
+                resultMap.put("code", 0);
+                resultMap.put("message", "撤销退药医保接口调用成功,共处理" + successCount + "个药品");
+            } else {
+                resultMap.put("code", -1);
+                resultMap.put("message", "撤销退药医保接口调用部分失败,成功" + successCount + "个,失败" + failCount + "个。错误信息:" + errorMsg.toString());
+            }
+            
+            return resultMap;
+        } catch (Exception e) {
+            log.error("撤销退药医保接口调用异常", e);
+            resultMap.put("code", -1);
+            resultMap.put("message", "撤销退药医保接口调用异常:" + e.getMessage());
+            return resultMap;
+        }
+    }
+    
+    /**
+     * 构建撤销退药医保接口参数
+     */
+    private Map<String, Object> buildYbParamsForCancelRefund(Map<String, Object> item, Map<String, Object> params) {
+        Map<String, Object> ybParams = new HashMap<>();
+        
+        // 关联字段
+        ybParams.put("patientId", item.get("patientId"));
+        ybParams.put("times", item.get("times"));
+        ybParams.put("receiptNo", item.get("receiptNo"));
+        ybParams.put("orderNo", item.get("orderNo"));
+        ybParams.put("chargeItemCode", item.get("chargeItemCode"));
+        ybParams.put("realNo", item.get("realNo"));
+        
+        // 医疗目录编码(医保编码)
+        ybParams.put("medListCodg", item.get("nationalCode"));
+        
+        // 开方医师姓名(从处方明细中获取,如果没有则使用当前用户)
+        String doctorName = getCurrentDoctorName(params);
+        ybParams.put("prscDrName", doctorName);
+        
+        // 药师姓名(使用前端传递的药师姓名)
+        String pharName = getCurrentUserName(params);
+        ybParams.put("pharName", pharName);
+        
+        // 药师执业资格证号
+        String pharPracCertNo = getPharPracCertNo(params);
+        ybParams.put("pharPracCertNo", pharPracCertNo);
+        
+        // 销售/退货经办人姓名
+        ybParams.put("selRetnOpterName", pharName);
+        
+        // 就诊结算类型(1-医保结算 2-自费结算)
+        ybParams.put("mdtrtSetlType", item.get("mdtrtSetlType") != null ? item.get("mdtrtSetlType") : "2");
+        
+        // 处方药标志
+        ybParams.put("rxFlag", item.get("rxFlag") != null ? item.get("rxFlag") : "0");
+        
+        // 拆零标志(0-否;1-是)
+        ybParams.put("trdnFlag", item.get("clFlag") != null ? item.get("clFlag") : "0");
+        
+        // 患者相关参数
+        ybParams.put("psnCertType", item.get("psnCertType") != null ? item.get("psnCertType") : "01");
+        ybParams.put("certno", item.get("certno") != null ? item.get("certno") : "");
+        ybParams.put("psnName", item.get("psnName") != null ? item.get("psnName") : "");
+        
+        return ybParams;
+    }
+    
+    /**
+     * 获取当前医生姓名
+     */
+    private String getCurrentDoctorName(Map<String, Object> params) {
+        // 从前端参数中获取医生姓名
+        String doctorName = (String) params.get("doctorName");
+        if (doctorName != null && !doctorName.trim().isEmpty()) {
+            return doctorName;
+        }
+        
+        // 如果前端没有传递医生姓名,则报错
+        throw new RuntimeException("前端参数中未找到医生姓名(doctorName),请检查参数传递");
+    }
+    
+    /**
+     * 获取当前用户姓名
+     */
+    private String getCurrentUserName(Map<String, Object> params) {
+        // 从前端参数中获取药师姓名
+        String pharName = (String) params.get("pharName");
+        if (pharName != null && !pharName.trim().isEmpty()) {
+            return pharName;
+        }
+        
+        // 如果前端没有传递,则从当前用户信息获取
+        try {
+            User currentUser = TokenUtil.getUser();
+            if (currentUser != null) {
+                return currentUser.getUserName();
+            }
+        } catch (Exception e) {
+            log.warn("获取当前用户信息失败", e);
+        }
+        return "药师姓名"; // 默认值
+    }
+    
+    /**
+     * 获取药师执业资格证号
+     */
+    private String getPharPracCertNo(Map<String, Object> params) {
+        // 从前端参数中获取药师执业资格证号
+        String pharPracCertNo = (String) params.get("pharPracCertNo");
+        if (pharPracCertNo != null && !pharPracCertNo.trim().isEmpty()) {
+            return pharPracCertNo;
+        }
+        
+        // 如果前端没有传递,则从当前用户信息获取
+        try {
+            User currentUser = TokenUtil.getUser();
+            if (currentUser != null) {
+                // 根据当前用户编码查询员工信息
+                Employee employee = employeeService.queryByUserCode(currentUser.getUserCode());
+                if (employee != null) {
+                    // 获取药师执业资格证号:优先取执业证编码,如果为空则取医保赋码
+                    if (StringUtils.isNotBlank(employee.getPracticeCertificate())) {
+                        return employee.getPracticeCertificate();
+                    } else if (StringUtils.isNotBlank(employee.getYbCode())) {
+                        return employee.getYbCode();
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.warn("获取当前用户信息失败", e);
+        }
+        return "药师执业资格证号"; // 默认值
+    }
 }

+ 43 - 0
src/main/java/cn/hnthyy/thmz/mapper/his/mz/MzPharmacyMapper.java

@@ -313,6 +313,9 @@ public interface MzPharmacyMapper {
             "</script>"})
     List<Map<String, Object>> selectPrescriptionYpMx(ChargeFeeParamsVo chargeFeeParamsVo);
 
+
+
+
     /**
      * 更新发药统计状态
      *
@@ -1350,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);
 }

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

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

+ 66 - 0
src/main/java/cn/hnthyy/thmz/service/impl/his/mz/MzPharmacyServiceImpl.java

@@ -115,6 +115,72 @@ public class MzPharmacyServiceImpl implements MzPharmacyService {
         return mzPharmacyMapper.selectPrescriptionYpMx(chargeFeeParamsVo);
     }
 
+
+
+    @Override
+    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) {
+                
+                // 修复:yp_mz_fytj 表中的 receipt_no 是负数,但 mz_charge_detail 表中是正数
+                // 需要将 receiptNo 转换为正数来查询 mz_charge_detail 表
+                Integer actualReceiptNo = Math.abs(receiptNo);
+                
+                Map<String, Object> chargeDetailInfo = mzPharmacyMapper.selectChargeDetailInfo(
+                    patientId, times, actualReceiptNo, orderNo, chargeItemCode, serial, itemNo);
+                
+                if (chargeDetailInfo != null) {
+                    item.put("realNo", chargeDetailInfo.get("realNo"));
+                }
+            }
+        }
+        
+        return baseDataList;
+    }
+
     @Override
     @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
     public Map<String, Object> refundMedicineProcessing(List<MzRefundMedicineVo> mzRefundMedicineVos, String userIdCode) {

+ 30 - 172
src/main/resources/static/js/mz/west_pharmacy_send.js

@@ -1937,6 +1937,7 @@ function saveRefundMedicine() {
  */
 function saveCancelRefundMedicine() {
     var row = $("#tb_table").bootstrapTable('getSelections');
+    console.log("row11111111111111111111111111111111",row)
     if (row.length != 1) {
         return errorMesageSimaple('请选择一条处方数据');
     }
@@ -1971,7 +1972,7 @@ function saveCancelRefundMedicine() {
         let orderNo = row[0].orderNo;
         let realNo = row[0].realNo;
         let name = row[0].name;
-        
+        let doctorName = row[0].doctorName; 
         console.log('撤销退药医保接口参数:', {
             patientId: patientId,
             times: times,
@@ -1982,7 +1983,7 @@ function saveCancelRefundMedicine() {
         });
         
         // 调用撤销退药医保接口
-        callYbSaleGoodsItemForCancelRefund(realNo, orderNo, receiptNo, times, patientId, name);
+        callYbSaleGoodsItemForCancelRefund(realNo, orderNo, receiptNo, times, patientId, name, doctorName);
         
         initTbTable();
     },err =>{
@@ -3688,195 +3689,52 @@ function validateTracCodgQuantity(realNo, orderNo, receiptNo, times, patientId,
  * @param patientId 病人ID
  * @param name 病人姓名
  */
-function callYbSaleGoodsItemForCancelRefund(realNo, orderNo, receiptNo, times, patientId, name) {
-    // 获取撤销退药后的处方明细数据 - 从已恢复的收费明细表获取
-    let tableData = $("#tb_table_right").bootstrapTable('getData');
-    
-    if (!tableData || tableData.length === 0) {
-        console.log('没有处方明细数据,跳过撤销退药医保接口调用');
-        return;
-    }
+function callYbSaleGoodsItemForCancelRefund(realNo, orderNo, receiptNo, times, patientId, name, doctorName) {
+    console.log('=== 开始调用撤销退药医保接口 ===');
     
     // 获取当前用户信息(药师信息)
     let currentUserName = localStorage.getItem('userName') || '';
-    let currentUserId = localStorage.getItem('userID') || '';
-    
-    // 获取当前时间
-    let currentTime = new Date();
-    let selRetnTime = currentTime.getFullYear() + '-' + 
-                     String(currentTime.getMonth() + 1).padStart(2, '0') + '-' + 
-                     String(currentTime.getDate()).padStart(2, '0') + ' ' +
-                     String(currentTime.getHours()).padStart(2, '0') + ':' + 
-                     String(currentTime.getMinutes()).padStart(2, '0') + ':' + 
-                     String(currentTime.getSeconds()).padStart(2, '0');
+    let pharPracCertNo = localStorage.getItem('pharPracCertNo') || '';
     
-    // 为每个药品调用一次医保接口
-    for (let i = 0; i < tableData.length; i++) {
-        let item = tableData[i];
-        
-        // 构建关联字段组合(用于关联撤销退药记录)
-        let currentPatientId = item.patientId || patientId;
-        let currentTimes = item.times || times;
-        let currentReceiptNo = item.receiptNo || receiptNo;
-        let currentOrderNo = item.orderNo || orderNo;
-        let chargeItemCode = item.chargeItemCode;
-        let currentRealNo = item.realNo || realNo;
-        
-        console.log('撤销退药关联键:', {patientId: currentPatientId, times: currentTimes, receiptNo: currentReceiptNo, orderNo: currentOrderNo, chargeItemCode, realNo: currentRealNo});
-        
-        // 参数验证
-        // 从处方明细数据中获取开方医师姓名
-        let doctorName = item.doctorName || item.employeeName || '';
-        if (!doctorName) {
-            console.warn('开方医师姓名为空,使用默认值');
-            doctorName = '未知医师';
-        }
-        
-        if (!currentUserName) {
-            console.warn('药师姓名为空,使用默认值');
-            currentUserName = '未知药师';
-        }
-        
-        // 构建医保接口参数 - 与发药时相同的参数结构
-        let ybData = {
-            // 关联字段 - 直接传递到医保接口
-            patientId: currentPatientId,
-            times: currentTimes,
-            receiptNo: currentReceiptNo,
-            orderNo: currentOrderNo,
-            chargeItemCode: chargeItemCode,
-            realNo: currentRealNo,
-            
-            // 医疗目录编码(医保编码)
-            medListCodg: item.nationalCode,
-            
-            // 开方医师姓名
-            prscDrName: doctorName,
-            
-            // 药师姓名
-            pharName: currentUserName,
-            
-            // 药师执业资格证号(取当前操作者的药师执业资格证号)
-            pharPracCertNo: localStorage.getItem('pharPracCertNo') || '',
-            
-            // 销售/退货经办人姓名
-            selRetnOpterName: currentUserName,
-            
-            // 就诊结算类型(1-医保结算 2-自费结算)
-            mdtrtSetlType: item.mdtrtSetlType || '2',
-            
-            // 处方药标志
-            rxFlag: item.rxFlag || '0',
-            
-            // 拆零标志(0-否;1-是)
-            trdnFlag: item.clFlag || '0',
-            
-            // 患者相关参数(医保接口需要)
-            // 人员证件类型
-            psnCertType: item.psnCertType || '01',
-            // 证件号码
-            certno: item.certno || '',
-            // 人员姓名
-            psnName: item.psnName || item.name || name || '',
-            
-        };
-        
-        // 追溯码信息 - 从已恢复的追溯码表获取
-        let drugtracinfo = [];
-        
-        // 主动获取追溯码信息(撤销退药后,追溯码已恢复到 mz_drug_trac_codg 表)
-        let tracCodgParams = {
-            patientId: currentPatientId,
-            times: currentTimes,
-            receiptNo: currentReceiptNo,
-            orderNo: currentOrderNo,
-            chargeItemCode: chargeItemCode,
-            serial: item.serial,
-            itemNo: item.itemNo,
-            groupNo: item.groupNo || groupNo
-        };
-        
-        // 调用追溯码查询接口(异步方式)
-        // 注意:撤销退药后,追溯码已恢复到 mz_drug_trac_codg 表
-        $.ajax({
-            type: "POST",
-            url: '/thmz/getMzDrugTracCodgData',
-            contentType: "application/json;charset=UTF-8",
-            dataType: "json",
-            headers: {
-                'Accept': 'application/json',
-                'Authorization': 'Bearer ' + localStorage.getItem("token")
-            },
-            data: JSON.stringify(tracCodgParams),
-            success: function (tracRes) {
-                console.log('撤销退药追溯码查询结果:', tracRes);
-                if (tracRes.code === 0 && tracRes.data && tracRes.data.length > 0) {
-                    // 将追溯码添加到医保接口参数中
-                    for (let k = 0; k < tracRes.data.length; k++) {
-                        let tracItem = tracRes.data[k];
-                        if (tracItem.drugTracCodg && tracItem.drugTracCodg !== '') {
-                            drugtracinfo.push({
-                                drugTracCodg: tracItem.drugTracCodg
-                            });
-                        }
-                    }
-                    console.log('撤销退药成功获取追溯码:', drugtracinfo);
-                } else {
-                    console.log('撤销退药未找到追溯码信息');
-                }
-                
-                // 追溯码查询完成后,调用医保接口
-                callYbSaleGoodsItemWithDataForCancelRefund(ybData, item, drugtracinfo);
-            },
-            error: function (xhr, status, error) {
-                console.error('撤销退药追溯码查询失败:', error);
-                // 即使追溯码查询失败,也要调用医保接口
-                callYbSaleGoodsItemWithDataForCancelRefund(ybData, item, drugtracinfo);
-            }
-        });
-    }
-}
-
-/**
- * 调用撤销退药医保接口(带追溯码数据)
- * @param ybData 医保接口参数
- * @param item 药品信息
- * @param drugtracinfo 追溯码信息
- */
-function callYbSaleGoodsItemWithDataForCancelRefund(ybData, item, drugtracinfo) {
-    // 如果没有追溯码,添加空数组(保持数据结构一致)
-    if (drugtracinfo.length === 0) {
-        drugtracinfo = [];
-    }
+    // 构建调用新接口的参数
+    let params = {
+        patientId: patientId,
+        times: times,
+        receiptNo: receiptNo,
+        orderNo: orderNo,
+        groupNoOut: groupNo,
+        // 添加医生姓名、药师姓名和药师执业资格证号
+        doctorName: doctorName, // 医生姓名,从处方明细中获取
+        pharName: currentUserName, // 药师姓名
+        pharPracCertNo: pharPracCertNo // 药师执业资格证号
+    };
     
-    console.log('调用撤销退药医保接口,药品:', item.drugname, '参数:', ybData);
+    console.log('撤销退药医保接口参数:', params);
     
-    let param = {
-        selinfoSold: ybData,
-        drugtracinfo: drugtracinfo
-    }
-    console.log("调用撤销退药医保接口param11111111111111111111111111111111111",param)
-    // 调用医保接口
+    // 调用新的撤销退药医保接口
     $.ajax({
         type: "POST",
-        url: '/thmz/Yb/saleGoodsItem',
+        url: '/thmz/cancelRefundWithYb',
         contentType: "application/json;charset=UTF-8",
         dataType: "json",
         headers: {
             'Accept': 'application/json',
             'Authorization': 'Bearer ' + localStorage.getItem("token")
         },
-        data: JSON.stringify(param),
+        data: JSON.stringify(params),
         success: function (res) {
-            console.log('撤销退药医保接口调用成功:', res);
-            if (res.code !== 0) {
+            console.log('撤销退药医保接口调用结果:', res);
+            if (res.code === 0) {
+                successMesage(res);
+                console.log('撤销退药医保接口调用成功');
+            } else {
+                errorMesage(res);
                 console.error('撤销退药医保接口调用失败:', res.message);
-                // 医保接口失败不影响撤销退药流程,只记录日志
             }
         },
         error: function (xhr, status, error) {
-            console.error('撤销退药医保接口调用失败:', error);
-            // 医保接口失败不影响撤销退药流程,只记录日志
+            console.error('撤销退药医保接口调用异常:', error);
+            errorMesage({message: '撤销退药医保接口调用异常:' + error});
         }
     });
 }