Przeglądaj źródła

Merge branch 'master' into 'master'

优化追溯码上传

See merge request lighter/web-server!157
huangshuhua 6 dni temu
rodzic
commit
d830395a04

+ 6 - 2
src/main/java/thyyxxk/webserver/dao/his/medicine/YpInvinfoDao.java

@@ -46,9 +46,13 @@ public interface YpInvinfoDao {
 
     @Select("<script> " +
             " select mo.* from yp_invinfo_modify as mo " +
-            " where mo.inv_chg_time &gt;= #{dto.startTime} " +
+            " where mo.group_no = #{dto.groupNo} " +
+            " <if test=\"dto.startTime != null and dto.startTime != ''\"> " +
+            " and mo.inv_chg_time &gt;= #{dto.startTime} " +
+            " </if> " +
+            " <if test=\"dto.endTime != null and dto.endTime != ''\"> " +
             " and mo.inv_chg_time &lt;= #{dto.endTime} " +
-            " and mo.group_no = #{dto.groupNo}  " +
+            " </if> " +
             " <if test=\"dto.docuNo != null and dto.docuNo != ''\"> " +
             " and mo.docu_no = #{dto.docuNo} " +
             " </if> " +

+ 9 - 4
src/main/java/thyyxxk/webserver/dao/his/medicine/YpTracCodgDao.java

@@ -198,7 +198,7 @@ public interface YpTracCodgDao {
             "</script>")
     List<YpSelinfoSold> selectYpSelinfoSoldThDetailByXyfOld(@Param("dto") YpCodgUpload dto);
 
-    @Select(" select drug_trac_codg as ypCodg, charge_item_code as chargeCode from ${tableName} " +
+    @Select(" select drug_trac_codg as ypCodg, charge_item_code as chargeCode, convert(varchar(100), confirm_time, 20) as confirmTime from ${tableName} " +
             " where flag = '0' and patient_id = #{patNo} and times = #{times} and charge_item_code = #{chargeCode} and serial = #{serial} ")
     List<Map<String, String>> selectCodgInfoById(@Param("tableName") String tableName, @Param("patNo") String patNo, @Param("times") Integer times,
                                                  @Param("chargeCode") String chargeCode, @Param("serial") String serial);
@@ -206,8 +206,9 @@ public interface YpTracCodgDao {
     @Select(" select top 1 * from yp_out_detl where confirm_flag = '1' and out_type = '0' and charge_code = #{chargeCode} and group_no_out = #{groupNo} order by out_date desc ")
     YpOutDetl selectCodgInfoManu(@Param("chargeCode") String chargeCode, @Param("groupNo") String groupNo);
 
-    @Select(" select top 1 * from yp_in_detl where confirm_flag = '1' and in_type in ('0', '1') and charge_code = #{chargeCode} and serial = #{serial} and manu_no = #{manuNo} order by in_date desc ")
-    YpInDetl selectCodgInfoProdTime(@Param("chargeCode") String chargeCode, @Param("serial") String serial, @Param("manuNo") String manuNo);
+    @Select(" select top 1 * from yp_in_detl where confirm_flag = '1' and in_type in ('0', '1') and charge_code = #{chargeCode} " +
+            "and serial = #{serial} and manu_no = #{manuNo} and in_date <= #{confirmTime} order by in_date desc ")
+    YpInDetl selectCodgInfoProdTime(@Param("chargeCode") String chargeCode, @Param("serial") String serial, @Param("manuNo") String manuNo, @Param("confirmTime") String confirmTime);
 
     @Select("<script> " +
             " select case when zd.national_code = '' then 'NMLC999' else rtrim(isnull(zd.national_code, 'NMLC999')) end as medListCodg, " +
@@ -226,9 +227,13 @@ public interface YpTracCodgDao {
             " select 1 from yp_invinfo_modify mo where mo.upload_flag = '1' " +
             " and de.in_docu_no = mo.docu_no and de.in_seri = mo.seri )" +
             " and de.confirm_flag = '1' and de.in_type in ('0', '1') " +
+            " and de.group_no = #{dto.groupNo} " +
+            " <if test=\"dto.startTime != null and dto.startTime != ''\"> " +
             " and de.in_date &gt;= #{dto.startTime} " +
+            " </if> " +
+            " <if test=\"dto.endTime != null and dto.endTime != ''\"> " +
             " and de.in_date &lt;= #{dto.endTime} " +
-            " and de.group_no = #{dto.groupNo} " +
+            " </if> " +
             " <if test=\"dto.docuNo != null and dto.docuNo != ''\"> " +
             " and de.in_docu_no = #{dto.docuNo} " +
             " </if> " +

+ 5 - 0
src/main/java/thyyxxk/webserver/service/medicine/YpInvinfoService.java

@@ -2,6 +2,7 @@ package thyyxxk.webserver.service.medicine;
 
 import cn.hutool.core.collection.CollUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 import thyyxxk.webserver.config.exception.ExceptionEnum;
 import thyyxxk.webserver.dao.his.medicine.YpInvinfoDao;
@@ -54,6 +55,10 @@ public class YpInvinfoService {
      * @Date 2025/6/3 0003 11:24
      */
     public ResultVo<List<YpInvinfoModify>> selectYpInvinfoResult(YpCodgUpload dto) {
+        if(StringUtils.isNotEmpty(dto.getDocuNo())){
+            dto.setStartTime(null);
+            dto.setEndTime(null);
+        }
         List<YpInvinfoModify> invinfoList = dao.selectYpInvinfoResult(dto);
         return ResultVoUtil.success(invinfoList);
     }

+ 3 - 1
src/main/java/thyyxxk/webserver/service/medicine/YpTaoBaoService.java

@@ -140,7 +140,9 @@ public class YpTaoBaoService {
             req.setRefEntId(refEntId);
             req.setCodes(codes);
             AlibabaAlihealthDrugtraceTopYljgQueryCodedetailResponse rsp = client.execute(req);
-            if(rsp.getResult().getResponseSuccess()){
+            if(null == rsp.getResult().getModels()){
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "根据追溯码【" + codes + "】查询码信息,淘宝开放平台查不到药品信息!");
+            } else if(rsp.getResult().getResponseSuccess()){
                 resultMap.put("code", 0);
                 resultMap.put("message", "根据追溯码查询码信息成功");
             } else {

+ 32 - 13
src/main/java/thyyxxk/webserver/service/medicine/YpTracCodgService.java

@@ -438,16 +438,25 @@ public class YpTracCodgService {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有销售数量,请检查!");
         }
         List<SelinfoSold> selinfoS = new ArrayList<>();
+        int fail = 0;
         for(YpSelinfoSold yp : list){
             SelinfoSold pb = new SelinfoSold();
             yp.setIsTy("0");
             String msg = callYpCodgInfo(yp, "0");
             if(StringUtils.isNotBlank(msg)){
-                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, msg);
+                yp.setMsgErr(msg);
+                yp.setUploadFlag("0");
+                fail++;
+                continue;
             }
             BeanUtils.copyProperties(yp, pb);
             selinfoS.add(pb);
         }
+        if(selinfoS.isEmpty()){
+            soldService.updateYpSelinfoSoldBatch(list);
+            resultMap.put("msg", "批量上传药品销售信息结果: 成功【" + (list.size() - fail) + "】条,失败【" + fail + "】条。");
+            return ResultVoUtil.success(resultMap);
+        }
         ResultVo<JSONObject> str = sv.saleGoods(selinfoS);
         if(YpDictConstant.ERROR_STATUS == str.getCode()){
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "批量上传药品销售信息失败:" + str.getMessage());
@@ -456,12 +465,11 @@ public class YpTracCodgService {
         JSONObject output = result.getJSONObject("output");
         JSONArray s = output.getJSONArray("selinfoDetail");
         List<Map> sd = s.toJavaList(Map.class);
-        boolean status = false;
         for(Map m : sd){
             String retRslt = String.valueOf(m.get("retRslt"));
             String fixmedinsBchno = String.valueOf(m.get("fixmedins_bchno"));
             if(YpDictConstant.UPLOAD_ERROR.equals(retRslt)){
-                status = true;
+                fail++;
             }
             for(YpSelinfoSold in : list){
                 if(in.getFixmedinsBchno().equals(fixmedinsBchno)){
@@ -472,11 +480,7 @@ public class YpTracCodgService {
             }
         }
         soldService.updateYpSelinfoSoldBatch(list);
-        if(status){
-            resultMap.put("msg", "批量上传药品销售信息存在失败情况,请检查!");
-        } else {
-            resultMap.put("msg", "批量上传药品销售信息全部成功!");
-        }
+        resultMap.put("msg", "批量上传药品销售信息结果: 成功【" + (list.size() - fail) + "】条,失败【" + fail + "】条。");
         return ResultVoUtil.success(resultMap);
     }
 
@@ -495,6 +499,7 @@ public class YpTracCodgService {
             List<DrugTracCodg> list = new ArrayList<>();
             String ypCodg = "";
             String errCodg = "";
+            String confirmTime = "";
             for(Map<String, String> map : zsmList){
                 String c = map.get("ypCodg");
                 if(null != c && c.length() != 20){
@@ -503,6 +508,7 @@ public class YpTracCodgService {
                 }
                 if(StringUtils.isBlank(ypCodg)){
                     ypCodg = c;
+                    confirmTime = map.get("confirmTime");
                 }
                 DrugTracCodg codg = new DrugTracCodg();
                 codg.setDrugTracCodg(c);
@@ -540,23 +546,32 @@ public class YpTracCodgService {
             }
             ResultVo<Map<String, Object>> resultVo = tbService.queryCodeDetail(ypCodg);
             Map<String, Object> map = resultVo.getData();
+            if(null == map){
+                return resultVo.getMessage();
+            }
             List<AlibabaAlihealthDrugtraceTopYljgQueryCodedetailResponse.CodeFullInfoDto> ss = (List<AlibabaAlihealthDrugtraceTopYljgQueryCodedetailResponse.CodeFullInfoDto>) map.get("data");
             yp.setManuDate(ss.get(0).getCodeProduceInfoDTO().getProduceInfoList().get(0).getProduceDateStr());
             yp.setManuLotnum(ss.get(0).getCodeProduceInfoDTO().getProduceInfoList().get(0).getBatchNo());
             yp.setExpyEnd(ss.get(0).getCodeProduceInfoDTO().getProduceInfoList().get(0).getExpireDate());
-            YpInDetl inDetl = dao.selectCodgInfoProdTime(yp.getChargeCode(), yp.getSerial(), yp.getManuLotnum());
+            YpInDetl inDetl = dao.selectCodgInfoProdTime(yp.getChargeCode(), yp.getSerial(), yp.getManuLotnum(), confirmTime);
 
             if(null == inDetl){
                 if(YpDictConstant.SERIAL_01.equals(yp.getSerial())){
-                    YpInDetl deal = dao.selectCodgInfoProdTime(yp.getChargeCode(), YpDictConstant.SERIAL_99, yp.getManuLotnum());
+                    YpInDetl deal = dao.selectCodgInfoProdTime(yp.getChargeCode(), YpDictConstant.SERIAL_99, yp.getManuLotnum(), confirmTime);
                     if(null == deal){
-                        return "批量上传药品销售失败,根据追溯码【" + ypCodg + "】查出药品【" + ss.get(0).getDrugEntBaseDTO().getPhysicName() + "】品名与销售药品【" + yp.getChargeName() + "】品名不符合,请核对!" ;
+                        return "批量上传药品销售失败,根据追溯码【" + ypCodg +
+                                "】查出药品【" + ss.get(0).getDrugEntBaseDTO().getPhysicName() + "】品名,生产批号【"
+                                + ss.get(0).getCodeProduceInfoDTO().getProduceInfoList().get(0).getBatchNo()
+                                + "】与销售药品【" + yp.getChargeName() + "】品名不符合或者生产批号不存在,请核对!" ;
                     } else {
                         yp.setTrdnFlag("1");
                         yp.setFixmedinsBchno(StringUtils.trim(deal.getInDocuNo()) + "_" + deal.getInSeri());
                     }
                 } else {
-                    return "批量上传药品销售失败,根据追溯码【" + ypCodg + "】查出药品【" + ss.get(0).getDrugEntBaseDTO().getPhysicName() + "】品名与销售药品【" + yp.getChargeName() + "】品名不符合,请核对!" ;
+                    return "批量上传药品销售失败,根据追溯码【" + ypCodg +
+                            "】查出药品【" + ss.get(0).getDrugEntBaseDTO().getPhysicName() + "】品名,生产批号【"
+                            + ss.get(0).getCodeProduceInfoDTO().getProduceInfoList().get(0).getBatchNo()
+                            + "】与销售药品【" + yp.getChargeName() + "】品名不符合或者生产批号不存在,请核对!" ;
                 }
             } else {
                 yp.setTrdnFlag("0");
@@ -566,7 +581,7 @@ public class YpTracCodgService {
         } else {
             YpOutDetl outDetl = dao.selectCodgInfoManu(yp.getChargeCode(), yp.getGroupNo());
             if(null != outDetl){
-                YpInDetl inDetl = dao.selectCodgInfoProdTime(outDetl.getChargeCode(), outDetl.getSerial(), outDetl.getManuNo());
+                YpInDetl inDetl = dao.selectCodgInfoProdTime(outDetl.getChargeCode(), outDetl.getSerial(), outDetl.getManuNo(), DateUtil.formatDate(outDetl.getConfirmDate(), "yyyy-MM-dd HH:mm:ss"));
                 if(null != inDetl){
                     yp.setManuLotnum(StringUtils.trim(inDetl.getManuNo()));
                     yp.setManuDate(DateUtil.formatDate(inDetl.getProducingDate(), "yyyy-MM-dd"));
@@ -655,6 +670,10 @@ public class YpTracCodgService {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "查询药品库存变更信息, 请选择库存变更类型!");
         }
         List<YpInvinfoModify> invinfoList = new ArrayList<>();
+        if(StringUtils.isNotEmpty(dto.getDocuNo())){
+            dto.setStartTime(null);
+            dto.setEndTime(null);
+        }
         List<YpInvinfoModify> invinfoRk = dao.selectYpInvinfoModifyDetailRk(dto);
         if(null != invinfoRk && !invinfoRk.isEmpty()){
             for (YpInvinfoModify mo : invinfoRk){