yeguodong 2 weeks ago
parent
commit
13eb0b0816

+ 5 - 0
src/main/java/cn/hnthyy/thmz/controller/yb/YbController.java

@@ -43,4 +43,9 @@ public class YbController {
         return ybService.getGoodsByCode(map);
     }
 
+    @RequestMapping(value = "/getErrorCodes", method = {RequestMethod.GET})
+    public ResultVo getErrorCodes() {
+        return ybService.getErrorCodes();
+    }
+
 }

+ 8 - 1
src/main/java/cn/hnthyy/thmz/mapper/his/yb/SelinfoSoldMapper.java

@@ -18,7 +18,14 @@ public interface SelinfoSoldMapper extends BaseMapper<SelinfoSold> {
     @Select("select * from selinfo_sold where patient_id=#{patientId} and times=#{times} and order_no=#{orderNo} and charge_item_code=#{chargeItemCode} and real_no=#{realNo}")
     List<SelinfoSold> getSelinfoSoldList(String patientId, Integer times, Integer orderNo, String chargeItemCode, Integer realNo);
 
-    @Select("select * from selinfo_sold_drugtrac where selinfo_sold_id=#{selinfoSoldId}")
+    @Select("<script>" +
+            "select * from selinfo_sold_drugtrac " +
+            "<where>" +
+            "   <if test='selinfoSoldId != null and selinfoSoldId != \"\"'>" +
+            "       and selinfo_sold_id = #{selinfoSoldId}" +
+            "   </if>" +
+            "</where>" +
+            "</script>")
     List<Map<String, String>> getSelinfoSoldDrugtracById(String selinfoSoldId);
 
     @Select("select * from selinfo_sold")

+ 34 - 17
src/main/java/cn/hnthyy/thmz/service/yb/YbService.java

@@ -358,19 +358,14 @@ public class YbService {
     public ResultVo getGoodsByCode(Map<String, String> map) {
         ResultVo response = null;
 
-        String realUrl = siInventoryServiceUrl + "/selectSalesGoodsItem";
         JSONArray output = null;
         try {
-            String jsonString = JSONObject.toJSONString(map, SerializerFeature.WriteNonStringKeyAsString);
-            String ybResult = HttpUtil.sendHttpPost(realUrl, jsonString, 8000);
-            JSONObject ybResultJson = JSONObject.parseObject(ybResult);
-            int responseCode = 0;
-            if(ybResultJson.getInteger("code") != 200) {
-                responseCode = ybResultJson.getInteger("code");
-            }
-//                response = new ResultVo(responseCode, ybResultJson.getString("message"), ybResultJson.get("data"));
+            JSONObject ybResultJson = getGoodsItemByCode(map);
             JSONObject data = ybResultJson.getJSONObject("data");
-            output = data.getJSONArray("output");
+            if(ybResultJson.getInteger("code") == 200) {
+                output = data.getJSONArray("output");
+                response = new ResultVo(0, "查询成功", output);
+            }
             // 记录医保接口调用结果
             // 通过关联键可以快速定位具体的退药记录,便于问题排查和审计
             log.info("医保查询接口调用结果 - 结果: {}", response);
@@ -381,18 +376,40 @@ public class YbService {
             // 记录错误信息时包含关联键,便于快速定位问题
             log.error("医保查询接口调用失败 - 错误: {}", e.getMessage());
         }
-        response = new ResultVo(0, "查询成功", output);
 
         return response;
     }
 
-    public ResultVo getGoodsByCode() {
-        ResultVo response = null;
-        List<SelinfoSold> selinfoSoldListNoWhere = selinfoSoldMapper.getSelinfoSoldListNoWhere();
-        for(SelinfoSold sold : selinfoSoldListNoWhere) {
-            selinfoSoldMapper.getSelinfoSoldDrugtracById(sold.getId());
+    public JSONObject getGoodsItemByCode(Map<String, String> map) throws Exception {
+        String realUrl = siInventoryServiceUrl + "/selectSalesGoodsItem";
+        String jsonString = JSONObject.toJSONString(map, SerializerFeature.WriteNonStringKeyAsString);
+        String ybResult = HttpUtil.sendHttpPost(realUrl, jsonString, 8000);
+        return JSONObject.parseObject(ybResult);
+
+    }
+
+    public ResultVo getErrorCodes() {
+        List<Map<String, String>> errors = new ArrayList<>();
+        List<Map<String, String>> selinfoSoldDrugtracList = selinfoSoldMapper.getSelinfoSoldDrugtracById(null);
+        for(Map<String, String> drug : selinfoSoldDrugtracList) {
+            Map<String, String> param = new HashMap<>();
+            param.put("med_list_codg", drug.get("med_list_codg"));
+            param.put("trac_codg", drug.get("trac_codg"));
+            try {
+                JSONObject result = getGoodsItemByCode(param);
+                JSONObject data = result.getJSONObject("data");
+                if(result.getInteger("code") == 200) {
+                    JSONArray output = data.getJSONArray("output");
+                    if(output == null || output.isEmpty()) {
+                        errors.add(drug);
+                    }
+                }
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
         }
-        return response;
+
+        return new ResultVo(0, "查询成功", errors);
     }
 
 }