yeguodong 1 mēnesi atpakaļ
vecāks
revīzija
4625b73062

+ 14 - 2
src/main/java/thyyxxk/webserver/controller/medicine/YpTaoBaoController.java

@@ -169,8 +169,20 @@ public class YpTaoBaoController {
 
     @PassToken
     @PostMapping("/uploadinoutbill")
-    public ResultVo<Map<String,Object>> uploadinoutbill(){
-        return ypTaoBaoService.uploadinoutbill();
+    public ResultVo<Map<String,Object>> uploadinoutbill(@RequestParam String fromEndId, @RequestParam String traceCodes){
+        return ypTaoBaoService.uploadinoutbill(fromEndId, traceCodes);
+    }
+
+    /**
+     * 通过大包装(箱)追溯码和发货厂商id查询大包装里的小追溯码
+     * @param parentCode
+     * @param entName
+     * @return
+     */
+    @PassToken
+    @PostMapping("/getCodeByParent")
+    public ResultVo<Map<String,Object>> getCodeByParent(@RequestParam String parentCode, @RequestParam String entName){
+        return ypTaoBaoService.getCodeByParent(parentCode, entName);
     }
 
 }

+ 125 - 69
src/main/java/thyyxxk/webserver/service/medicine/YpTaoBaoService.java

@@ -2,6 +2,7 @@ package thyyxxk.webserver.service.medicine;
 
 import cn.hutool.core.convert.Convert;
 import com.alibaba.fastjson.JSONObject;
+import com.taobao.api.ApiException;
 import com.taobao.api.TaobaoClient;
 import com.taobao.api.request.*;
 import com.taobao.api.response.*;
@@ -20,6 +21,7 @@ import thyyxxk.webserver.utils.ResultVoUtil;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.UUID;
 
 /**
  * @ClassName YpTaoBaoService
@@ -62,60 +64,6 @@ public class YpTaoBaoService {
         }
     }
 
-    public ResultVo<Map<String, Object>> queryRelation(String code, String desRefEntId) {
-        if(StringUtils.isBlank(code)){
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "单码(一般是大包装码)关联关系查询失败,code参数为空");
-        }
-        Map<String, Object> resultMap = new HashMap<>();
-        try{
-            AlibabaAlihealthDrugtraceTopYljgQueryRelationRequest req = new AlibabaAlihealthDrugtraceTopYljgQueryRelationRequest();
-            req.setRefEntId(refEntId);
-            req.setCode(code);
-            req.setDesRefEntId(desRefEntId);
-            AlibabaAlihealthDrugtraceTopYljgQueryRelationResponse rsp = client.execute(req);
-            System.out.println(rsp.getBody());
-            if(rsp.getResult().getResponseSuccess()){
-                resultMap.put("code", 0);
-                resultMap.put("message", "查询单码关联关系成功");
-            } else {
-                log.error("查询单码关联关系信息,淘宝开放平台错误信息{}", rsp.getResult().getMsgInfo());
-                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "查询单码关联关系信息,淘宝开放平台错误信息: " + rsp.getResult().getMsgInfo());
-            }
-            resultMap.put("msgCode", rsp.getResult().getMsgCode());
-            resultMap.put("data", rsp.getResult().getModelList());
-            return ResultVoUtil.success(resultMap);
-        } catch(Exception e){
-            e.printStackTrace();
-            log.error("查询单码关联关系,系统错误信息{}", e.getMessage());
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "查询单码关联关系,系统错误信息: " + e.getMessage());
-        }
-    }
-
-    public ResultVo<Map<String, Object>> queryGetEntInfo(String entName) {
-        if(StringUtils.isBlank(entName)){
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "通过企业名得到唯一标识查询失败,企业名为空");
-        }
-        Map<String, Object> resultMap = new HashMap<>();
-        try{
-            AlibabaAlihealthDrugtraceTopYljgQueryGetentinfoRequest req = new AlibabaAlihealthDrugtraceTopYljgQueryGetentinfoRequest();
-            req.setEntName(entName);
-            AlibabaAlihealthDrugtraceTopYljgQueryGetentinfoResponse rsp = client.execute(req);
-            if(rsp.getResult().getResponseSuccess()){
-                resultMap.put("code", 0);
-                resultMap.put("message", "根据企业名查询企业id成功");
-            } else {
-                log.error("根据企业名查询企业id,淘宝开放平台错误信息{}", rsp.getResult().getMsgInfo());
-                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "根据企业名查询企业id,淘宝开放平台错误信息: " + rsp.getResult().getMsgInfo());
-            }
-            resultMap.put("msgCode", rsp.getResult().getMsgCode());
-            resultMap.put("data", rsp.getResult().getModel());
-            return ResultVoUtil.success(resultMap);
-        } catch(Exception e){
-            log.error("根据企业名查询企业id,系统错误信息{}", e.getMessage());
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "根据企业名查询企业id,系统错误信息: " + e.getMessage());
-        }
-    }
-
     public ResultVo<Map<String, Object>> queryCodeDetail(String codes) {
         if(StringUtils.isBlank(codes)){
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "根据追溯码查询码信息失败,codes为空");
@@ -309,35 +257,143 @@ public class YpTaoBaoService {
         }
     }
 
-    public ResultVo<Map<String, Object>> uploadinoutbill() {
+    public ResultVo<Map<String, Object>> uploadinoutbill(String fromEndId, String traceCodes) {
         Map<String, Object> resultMap = new HashMap<>();
+        AlibabaAlihealthDrugtraceTopYljgUploadinoutbillResponse rsp = uploadinoutbillItem(fromEndId, traceCodes);
+        if(rsp.getResponseSuccess()){
+            resultMap.put("code", 0);
+            resultMap.put("message", "出入库单据上传成功");
+        } else {
+            log.error("出入库单据上传,淘宝开放平台错误信息{}", rsp.getMsgInfo());
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "出入库单据上传,淘宝开放平台错误信息: " + rsp.getMsgInfo());
+        }
+        resultMap.put("msgCode", rsp.getMsgCode());
+        resultMap.put("data", rsp.getBody());
+        return ResultVoUtil.success(resultMap);
+    }
+
+    public ResultVo<Map<String, Object>> queryRelation(String code, String desRefEntId) {
+        if(StringUtils.isBlank(code)){
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "单码(一般是大包装码)关联关系查询失败,code参数为空");
+        }
+        Map<String, Object> resultMap = new HashMap<>();
+        try{
+            AlibabaAlihealthDrugtraceTopYljgQueryRelationResponse rsp = queryRelationItem(code, desRefEntId);
+            if(rsp.getResult().getResponseSuccess()){
+                resultMap.put("code", 0);
+                resultMap.put("message", "查询单码关联关系成功");
+            } else {
+                log.error("查询单码关联关系信息,淘宝开放平台错误信息{}", rsp.getResult().getMsgInfo());
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "查询单码关联关系信息,淘宝开放平台错误信息: " + rsp.getResult().getMsgInfo());
+            }
+            resultMap.put("msgCode", rsp.getResult().getMsgCode());
+            resultMap.put("data", rsp.getResult().getModelList());
+            return ResultVoUtil.success(resultMap);
+        } catch(Exception e){
+            e.printStackTrace();
+            log.error("查询单码关联关系,系统错误信息{}", e.getMessage());
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "查询单码关联关系,系统错误信息: " + e.getMessage());
+        }
+    }
+
+    private AlibabaAlihealthDrugtraceTopYljgUploadinoutbillResponse uploadinoutbillItem(String fromEndId, String traceCodes) {
+        AlibabaAlihealthDrugtraceTopYljgUploadinoutbillResponse rsp = null;
         try{
             AlibabaAlihealthDrugtraceTopYljgUploadinoutbillRequest req = new AlibabaAlihealthDrugtraceTopYljgUploadinoutbillRequest();
-            req.setBillCode("BC001_11235");
+
+            req.setBillCode("BC001_" + System.currentTimeMillis());
             req.setBillTime(new Date());
             req.setBillType(102L);
             req.setPhysicType(3L);
             req.setRefUserId(refEntId);
-            req.setFromUserId("17bf450816464a42bd7c08ba1c11208a");
+            req.setFromUserId(fromEndId);
             req.setToUserId(refEntId);
-            req.setTraceCodes("81004600150080753636");
+            req.setTraceCodes(traceCodes);
             req.setClientType("2");
-            AlibabaAlihealthDrugtraceTopYljgUploadinoutbillResponse rsp = client.execute(req);
-            if(rsp.getResponseSuccess()){
+            rsp = client.execute(req);
+        } catch(Exception e){
+            log.error("出入库单据上传,错误信息{}", e.getMessage());
+        }
+        return rsp;
+    }
+
+    private AlibabaAlihealthDrugtraceTopYljgQueryRelationResponse queryRelationItem(String code, String desRefEntId) {
+        AlibabaAlihealthDrugtraceTopYljgQueryRelationResponse rsp = null;
+        try{
+            AlibabaAlihealthDrugtraceTopYljgQueryRelationRequest req = new AlibabaAlihealthDrugtraceTopYljgQueryRelationRequest();
+            req.setRefEntId(refEntId);
+            req.setCode(code);
+            req.setDesRefEntId(desRefEntId);
+            rsp = client.execute(req);
+        } catch(Exception e){
+            log.error("查询单码关联关系信息,错误信息{}", e.getMessage());
+        }
+        return rsp;
+    }
+
+    public ResultVo<Map<String, Object>> queryGetEntInfo(String entName) {
+        if(StringUtils.isBlank(entName)){
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "通过企业名得到唯一标识查询失败,企业名为空");
+        }
+        Map<String, Object> resultMap = new HashMap<>();
+        try{
+            AlibabaAlihealthDrugtraceTopYljgQueryGetentinfoResponse rsp = queryGetEntInfoItem(entName);
+            if(rsp.getResult().getResponseSuccess()){
                 resultMap.put("code", 0);
-                resultMap.put("message", "查询往来单位列表成功");
+                resultMap.put("message", "根据企业名查询企业id成功");
             } else {
-                log.error("查询往来单位列表,淘宝开放平台错误信息{}", rsp.getMsgInfo());
-                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "查询往来单位列表,淘宝开放平台错误信息: " + rsp.getMsgInfo());
+                log.error("根据企业名查询企业id,淘宝开放平台错误信息{}", rsp.getResult().getMsgInfo());
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "根据企业名查询企业id,淘宝开放平台错误信息: " + rsp.getResult().getMsgInfo());
             }
-            resultMap.put("msgCode", rsp.getMsgCode());
-            resultMap.put("data", rsp.getBody());
+            resultMap.put("msgCode", rsp.getResult().getMsgCode());
+            resultMap.put("data", rsp.getResult().getModel());
             return ResultVoUtil.success(resultMap);
         } catch(Exception e){
-            log.error("查询往来单位列表,错误信息{}", e.getMessage());
-            resultMap.put("code", -1);
-            resultMap.put("message", "查询往来单位列表失败: " + e.getMessage());
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "查询往来单位列表,错误信息: " + e.getMessage());
+            log.error("根据企业名查询企业id,系统错误信息{}", e.getMessage());
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "根据企业名查询企业id,系统错误信息: " + e.getMessage());
+        }
+    }
+
+    private AlibabaAlihealthDrugtraceTopYljgQueryGetentinfoResponse queryGetEntInfoItem(String entName) {
+        AlibabaAlihealthDrugtraceTopYljgQueryGetentinfoResponse rsp = null;
+        try {
+            AlibabaAlihealthDrugtraceTopYljgQueryGetentinfoRequest req = new AlibabaAlihealthDrugtraceTopYljgQueryGetentinfoRequest();
+            req.setEntName(entName);
+            rsp = client.execute(req);
+        } catch (Exception e) {
+            log.error("查询单码关联关系信息,错误信息{}", e.getMessage());
+        }
+
+        return rsp;
+    }
+
+    /**
+     * 通过大包装追溯码和发货厂商id查询大包装里的小追溯码
+     * @param parentCode
+     * @param entName
+     * @return
+     */
+    public ResultVo<Map<String, Object>> getCodeByParent(String parentCode, String entName) {
+        Map<String, Object> resultMap = new HashMap<>();
+        // 1、通过企业名称查询企业id
+        AlibabaAlihealthDrugtraceTopYljgQueryGetentinfoResponse entRsp = queryGetEntInfoItem(entName);
+        if(entRsp.getResult().getResponseSuccess()){
+            String entId = entRsp.getResult().getModel().getEntId();
+            // 2、通过大包装追溯码和发货厂商企业id进行出入库单据上传
+            uploadinoutbillItem(entId, parentCode);
+            // 3、查询大包装码对应的子码信息;注意:入参的大包装码必须在本企业的码上放心平台上传入库单后再调用接口,才会返回子码信息。
+            AlibabaAlihealthDrugtraceTopYljgQueryRelationResponse relationRsp = queryRelationItem(parentCode, refEntId);
+            if(relationRsp.getResult().getResponseSuccess()){
+                resultMap.put("code", 0);
+                resultMap.put("message", "查询单码关联关系成功");
+                resultMap.put("msgCode", relationRsp.getResult().getMsgCode());
+                resultMap.put("data", relationRsp.getResult().getModelList());
+            } else {
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "查询单码关联关系信息,淘宝开放平台错误信息: " + relationRsp.getResult().getMsgInfo());
+            }
+
+
         }
+        return ResultVoUtil.success(resultMap);
     }
 }