Browse Source

【佳毅兴】【顺丰对接】【云打印面单&不带寄托物信息】

wuyx 1 year ago
parent
commit
8ca3a93761

+ 19 - 0
src/main/java/com/uas/eis/entity/sf/SFBaseApiRespData.java

@@ -0,0 +1,19 @@
+package com.uas.eis.entity.sf;
+
+import lombok.Data;
+/*
+* 基础通用API
+* #	属性名	类型	说明
+1	success	boolean	请求成功标志
+2	errorMessage	String	失败提示信息
+3	errorCode	String	失败状态码
+4	requestId	String	发送请求中的ID,原封不动返回,使客户系统能识别出哪个请求对应的响应
+5	obj	object	同步方式才有值,异步方式为空对象
+* */
+@Data
+public class SFBaseApiRespData {
+    boolean success;
+    String errorCode;
+    String errorMessage;
+    String requestId;
+}

+ 24 - 0
src/main/java/com/uas/eis/entity/sf/SFPrintFile.java

@@ -0,0 +1,24 @@
+package com.uas.eis.entity.sf;
+
+import lombok.Data;
+
+/*
+* #	属性名	类型	说明
+1	url	String	pdf文件的url下载地址,使用 GET 协议
+2	token	String	下载文件时需要的token,设置在请求头的 X-Auth-token 字段,有效期 24h
+3	waybillNo	String	顺丰运单号(子母单为子单号)
+4	seqNo	int	面单序号(批量打印场景,为documents的序号)
+5	areaNo	int	联编号(大客户面单为固定值:1)
+6	pageNo	int	每联的页号(大客户面单为固定值:1)
+7	pageCount	int	文件的页数
+* */
+@Data
+public class SFPrintFile {
+    String url;
+    String token;
+    String waybillNo;
+    Integer seqNo;
+    Integer areaNo;
+    Integer pageNo;
+    Integer pageCount;
+}

+ 20 - 0
src/main/java/com/uas/eis/entity/sf/SFPrintFileResp.java

@@ -0,0 +1,20 @@
+package com.uas.eis.entity.sf;
+
+import lombok.Data;
+
+import java.util.List;
+
+/*
+* #	属性名	类型	说明
+1	files	List<PrintFile>	pdf文件集合,不保证顺序,自行通过seqNo排序
+2	clientCode	String	客户编码
+3	templateCode	String	模板编码
+4	fileType	String	文件类型(pdf)
+* */
+@Data
+public class SFPrintFileResp{
+    List<SFPrintFile> files;
+    String clientCode;
+    String templateCode;
+    String fileType;
+}

+ 8 - 0
src/main/java/com/uas/eis/entity/sf/SFPrintToPDFResp.java

@@ -0,0 +1,8 @@
+package com.uas.eis.entity.sf;
+
+import lombok.Data;
+
+@Data
+public class SFPrintToPDFResp extends SFBaseApiRespData {
+    SFPrintFileResp obj;
+}

+ 3 - 2
src/main/java/com/uas/eis/service/Impl/ERPServiceImpl.java

@@ -117,16 +117,17 @@ public class ERPServiceImpl implements ERPService {
             contactInfoList.add(receiveInfo);
             sfOrder.setContactInfoList(contactInfoList);
             List<SFCargoDetail> cargoDetails = new ArrayList<>();
-            SqlRowList outList = baseDao.queryForRowSet(" select pr_detail,pr_unit,sum(pd_outqty) outqty from prodiodetail left join product on pr_code = pd_prodcode where pd_piid = ? and pr_detail is not null group by pr_detail,pr_unit",id);
+            /*SqlRowList outList = baseDao.queryForRowSet(" select pr_detail,pr_unit,sum(pd_outqty) outqty from prodiodetail left join product on pr_code = pd_prodcode where pd_piid = ? and pr_detail is not null group by pr_detail,pr_unit",id);
             while (outList.next()){
                 SFCargoDetail cargoDetail = new SFCargoDetail();
                 cargoDetail.setName(outList.getGeneralString("pr_detail"));
                 cargoDetail.setUnit(outList.getGeneralString("pr_unit"));
                 cargoDetail.setCount(outList.getGeneralDouble("outqty"));
                 cargoDetails.add(cargoDetail);
-            }
+            }*/
             sfOrder.setCargoDetails(cargoDetails);
             msgData = FlexJsonUtil.toJsonDeep(sfOrder);
+//            System.out.println("====请求msgData:" + msgData);
             try {
                 params.put("partnerID", CLIENT_CODE);  // 顾客编码 ,对应丰桥上获取的clientCode
                 params.put("requestID", UUID.randomUUID().toString().replace("-", ""));

+ 168 - 2
src/test/java/com/uas/eis/UasEisApplicationTests.java

@@ -15,7 +15,11 @@ import com.sf.csim.express.service.HttpClientUtil;
 import com.sf.csim.express.service.IServiceCodeStandard;
 import com.sf.csim.express.service.code.ExpressServiceCodeEnum;
 
+import java.io.FileOutputStream;
+import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.URL;
 import java.util.*;
 
 @RunWith(SpringRunner.class)
@@ -136,13 +140,175 @@ public class UasEisApplicationTests {
 
 	@Test
 	public void TestCreatSFOrder(){
-		Map<String, Object> res = erpService.creatSFOrder("JYX_TEST", 50734826,"ADMIN");
+		Map<String, Object> res = erpService.creatSFOrder("JYX_TEST", 50734919,"ADMIN");
 		System.out.println("res==="+res.get("success")+":"+res.get("message"));
 	}
 
 	@Test
 	public void TestCancelSFOrder(){
-		Map<String, Object> res = erpService.cancelSFOrder("JYX_TEST", 50734826,"ADMIN");
+		Map<String, Object> res = erpService.cancelSFOrder("JYX_TEST", 50734919,"ADMIN");
 		System.out.println("res==="+res.get("success")+":"+res.get("message"));
 	}
+	@Test
+	public void TestPrintPDF() throws UnsupportedEncodingException {
+		/**ExpressServiceCodeEnum     对应速运类-快递APIs
+		 POSTServiceCodeEnum        对应速运类-驿站APIs
+		 YJTServiceCodeEnum         对应解决方案-医寄通APIs
+		 EPSServiceCodeEnum         对应解决方案-快递管家APIs
+		 HZTServiceCodeEnum         对应解决方案-函证通APIs    2022-2-24 新增
+		 详情见code目录下枚举类,客户可自行修改引用的该类
+		 **/
+		IServiceCodeStandard standardService = ExpressServiceCodeEnum.COM_RECE_CLOUD_PRINT_WAYBILLS; //下订单
+		//	IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_SEARCH_ORDER_RESP; //查订单
+		//  IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_UPDATE_ORDER;//订单取消
+		// 	IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_FILTER_ORDER_BSP;//订单筛选
+		//  IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_SEARCH_ROUTES;//查路由
+		//	IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_GET_SUB_MAILNO;//子单号
+		//	IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_QUERY_SFWAYBILL;//查运费
+		//	IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_REGISTER_ROUTE;//注册路由
+		//	IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_CREATE_REVERSE_ORDER;//退货下单
+		//	IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_CANCEL_REVERSE_ORDER;//退货消单
+		//	IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_WANTED_INTERCEPT;//截单转寄
+		// 	IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_QUERY_DELIVERTM;//时效标准及价格查询
+		//  IServiceCodeStandard standardService = ExpressServiceCodeEnum.COM_RECE_CLOUD_PRINT_WAYBILLS;//面单打印
+		//  IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_UPLOAD_ROUTE;//路由上传
+		//   IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_SEARCH_PROMITM;//预计派送时间查询
+		//  IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_EXCE_CHECK_PICKUP_TIME;//揽件服务时间查询
+		//  IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_VALIDATE_WAYBILLNO;//运单号合法性校验
+
+
+		CallExpressServiceTools tools=CallExpressServiceTools.getInstance();
+		Map<String, String> params = new HashMap<String, String>();
+		String timeStamp = String.valueOf(System.currentTimeMillis());
+		Map<String, Object> msgDataMap = new HashMap<>();
+		msgDataMap.put("templateCode","fm_76130_standard_JYXKJWFFJ88E");
+		msgDataMap.put("version","2.0");
+		msgDataMap.put("fileType","pdf");
+		msgDataMap.put("sync","true");
+		List<Map<String,Object>> docList = new ArrayList<>();
+		Map<String,Object> doc = new HashMap<>();
+		doc.put("masterWaybillNo","SF7444488564898");
+		docList.add(doc);
+		doc = new HashMap<>();
+		doc.put("masterWaybillNo","SF7444488606478");
+		docList.add(doc);
+		msgDataMap.put("documents",docList);
+		String msgData = FlexJsonUtil.toJsonDeep(msgDataMap);
+		params.put("partnerID", CLIENT_CODE);  // 顾客编码 ,对应丰桥上获取的clientCode
+		params.put("requestID", UUID.randomUUID().toString().replace("-", ""));
+		params.put("serviceCode",standardService.getCode());// 接口服务码
+		params.put("timestamp", timeStamp);
+		params.put("msgData", msgData);
+		params.put("msgDigest", tools.getMsgDigest(msgData,timeStamp,CHECK_WORD_BOX));
+		long startTime = System.currentTimeMillis();
+//		System.out.println("====调用请求:" + params.get("msgData"));
+		System.out.println("====调用实际请求:" + params);
+		String result = HttpClientUtil.post(CALL_URL_BOX, params);
+		System.out.println("====调用丰桥的接口服务代码:" + String.valueOf(standardService.getCode()) + " 接口耗时:"+ String.valueOf(System.currentTimeMillis()-startTime)+"====");
+		System.out.println("===调用地址 ==="+CALL_URL_BOX);
+		System.out.println("===顾客编码 ==="+CLIENT_CODE);
+		System.out.println("===返回结果:" +result);
+//		Map<String,Object> resData = JacksonUtil.fromJson(result);
+		SFApiResp sfApiResp = FlexJsonUtil.fromJson(result, SFApiResp.class);
+		if(sfApiResp!=null){
+			if("A1000".equals(sfApiResp.getApiResultCode())){
+				String apiResultData = sfApiResp.getApiResultData();
+				SFPrintToPDFResp sfPrintToPDFResp =  FlexJsonUtil.fromJson(apiResultData, SFCreatOrderResp.class);
+				if(sfPrintToPDFResp.isSuccess()){
+					SFPrintFileResp sfPrintFileResp =  sfPrintToPDFResp.getObj();
+					List<SFPrintFile> files = sfPrintFileResp.getFiles();
+					if(!CollectionUtil.isEmpty(files)){
+						files.stream().sorted(Comparator.comparingInt(SFPrintFile::getSeqNo));
+						for (SFPrintFile file : files) {
+							pdfDownLoad(file.getUrl(),file.getToken(),file.getWaybillNo());
+						}
+					}
+				}else {
+					System.out.println("errorCode:"+sfPrintToPDFResp.getErrorCode()+"====errorMsg:"+sfPrintToPDFResp.getErrorMessage());
+				}
+			}else {
+				System.out.println("code:"+sfApiResp.getApiResultCode()
+						+"===apiResponseID:"+sfApiResp.getApiResponseID()
+						+"===apiErrorMsg:"+sfApiResp.getApiErrorMsg());
+			}
+		}
+	}
+
+	@Test
+	public void TestpdfDownLoad(){
+		String fileUrl="https://eos-scp-core-shenzhen-futian1-oss.sf-express.com:443/v1.2/AUTH_EOS-SCP-CORE/print-file-sbox/AAABkcBBzkdSfT1fJRhKjpLt-VFNcr-a_SF7444488607870_fm_76130_standard_JYXKJWFFJ88E_1_1.pdf";
+		String token="AUTH_tkv12_f146d1855480549d262b5c46ab0ab597ff20a97d9d0db45c16bedeb4fabd112b012deadd477ee524b1d690ce01baa3cdffbb125a6ccf69b73778dba2eb5157eb29d9b3c970d295a3ca38c86f265339b4e7673f13379eb30a5b06511e78f70544cc4cdfc6c2876b2b6b012fdd1261d4dc0a993336de84ff3d3ef08dcf6775c715ea8f1ccf7c6c82a84ac370b171a5ac5311e398d02ff8a80d4a3a5acb161165ebbbfe1b7a686c5f0c6fb838db2b8c7625d1d8540df26f87d4f8e135ecce42d062";
+		String fileName="SF7444488607870";
+		pdfDownLoad(fileUrl,token,fileName);
+	}
+	private void pdfDownLoad(String fileUrl,String token,String fileName){
+		//下载地址
+//		String fileUrl = ioList.getGeneralString("ei_pdfurl"); // "https://inv.jss.com.cn/fp2/2zpnwyKkdvu9dWzE8BhmSnER0Iux3xQRMLidDJhiIE2PziVXY4lL3k83OsK0K06YctW5cf1FFHxraffj-bf16A.pdf";
+		// 定义要保存的文件的路径
+//		String fileName = ioList.getGeneralString("cu_name")+ioList.getGeneralString("ei_refno")+".pdf";//
+		String fileBasePath = "C:\\jyxsf\\"+fileName+".pdf";
+//		fileBasePath = String.valueOf(obs[5])+fileName;//发票储存路径
+		try {//X-Auth-token
+			// 创建URL对象
+			URL url = new URL(fileUrl);
+			HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
+			// 设置请求方法为GET
+			httpURLConnection.setRequestMethod("GET");
+			// 添加请求头
+			httpURLConnection.setRequestProperty("X-Auth-token", token); // 假设你的token是通过Bearer模式传递的
+			// 连接服务器
+			httpURLConnection.connect();
+			// 检查响应码
+			int responseCode = httpURLConnection.getResponseCode();
+			if (responseCode == HttpURLConnection.HTTP_OK) {
+				// 读取输入流
+				InputStream inputStream = httpURLConnection.getInputStream();
+				// 写入文件
+				FileOutputStream fileOutputStream = new FileOutputStream(fileBasePath);
+				byte[] buffer = new byte[4096];
+				int bytesRead = -1;
+				while ((bytesRead = inputStream.read(buffer)) != -1) {
+					fileOutputStream.write(buffer, 0, bytesRead);
+				}
+				// 关闭流
+				fileOutputStream.close();
+				inputStream.close();
+
+				System.out.println("下载成功");
+			} else {
+				System.out.println("下载失败 : " + responseCode);
+			}
+			// 断开连接
+			httpURLConnection.disconnect();
+			// 打开连接
+//			URLConnection conn = url.openConnection();
+//			// 获取输入流
+//			InputStream in = conn.getInputStream();
+//			// 创建输出流
+//			FileOutputStream out = new FileOutputStream(fileBasePath);
+//			// 创建缓冲区
+//			byte[] buffer = new byte[104857600];
+//			// 读取并写入数据
+//			int len;
+//			while ((len = in.read(buffer)) != -1) {
+//				out.write(buffer, 0, len);
+//			}
+//			long size = out.getChannel().size();
+//			// 关闭流
+//			in.close();
+//			out.close();
+//                        System.out.println("size:"+size);
+			//存文件 filepath
+//			int id = commonService.saveFilePath(fileBasePath, (int) size, fileName, "管理员");
+//			baseDao.execute("update ELECINVOICE set ei_pdfattach ='"+id+";' where ei_id = "+ioList.getGeneralInt("ei_id"));
+		} catch (Exception e) {
+			e.printStackTrace();
+			String errMsg = "文件转存异常";
+			if(StringUtil.hasText(e.getMessage())){
+				errMsg = e.getMessage();
+			}else if(e.getCause()!=null&&StringUtil.hasText(e.getCause().getMessage())){
+				errMsg = e.getCause().getMessage();
+			}
+		}
+	}
 }