|
@@ -0,0 +1,348 @@
|
|
|
+package com.ruoyi.web.controller.plugin;
|
|
|
+
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.ruoyi.basicData.domain.TCorps;
|
|
|
+import com.ruoyi.ccb.service.ForeignHttpService;
|
|
|
+import com.ruoyi.common.core.controller.BaseController;
|
|
|
+import com.ruoyi.warehouseBusiness.domain.TWarehouseBills;
|
|
|
+import com.ruoyi.warehouseBusiness.request.InventoryQueryRequest;
|
|
|
+import com.ruoyi.warehouseBusiness.request.ReceiptRegisterRequest;
|
|
|
+import com.ruoyi.warehouseBusiness.response.*;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.apache.poi.ss.formula.functions.T;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.security.*;
|
|
|
+import java.security.spec.InvalidKeySpecException;
|
|
|
+import java.security.spec.PKCS8EncodedKeySpec;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 大宗仓库接⼝
|
|
|
+ */
|
|
|
+@AllArgsConstructor
|
|
|
+@RestController
|
|
|
+@RequestMapping("/bulkWareHouse")
|
|
|
+public class BulkWareHouseController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ForeignHttpService foreignHttpService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取仓库详细信息
|
|
|
+ */
|
|
|
+ @PostMapping("/inventory/queries")
|
|
|
+ public void queries(HttpServletRequest request, HttpServletResponse response) throws InvalidKeySpecException, SignatureException, NoSuchAlgorithmException, InvalidKeyException {
|
|
|
+
|
|
|
+ String bizContentStr = (String) request.getAttribute("bizContentStr");
|
|
|
+
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(bizContentStr);
|
|
|
+ String ownerName = jsonObject.getString("currentOwnerName");//现存货人名称
|
|
|
+ String identifier = jsonObject.getString("currentOwnerSocialIdentifier");//现存货人识别号
|
|
|
+
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONArray("warehouseSerialNumbers");//仓库编号
|
|
|
+
|
|
|
+ List<String> numbersList = new ArrayList<>();
|
|
|
+ for(int i=0;i<jsonArray.size();i++){
|
|
|
+ String numbers = jsonArray.getString(i);
|
|
|
+ numbersList.add(numbers);
|
|
|
+ System.out.println(numbers);
|
|
|
+ }
|
|
|
+
|
|
|
+ InventoryQueryRequest inventoryQueryRequest = new InventoryQueryRequest();
|
|
|
+ inventoryQueryRequest.setCurrentOwnerName(ownerName);
|
|
|
+ inventoryQueryRequest.setCurrentOwnerSocialIdentifier(identifier);
|
|
|
+ inventoryQueryRequest.setWarehouseSerialNumbers(numbersList);
|
|
|
+
|
|
|
+ List<InventoryQueryResponse> list = foreignHttpService.inventoryQueries(inventoryQueryRequest);
|
|
|
+
|
|
|
+ sendRequest(Collections.singletonList(list),response);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 仓单注册指令
|
|
|
+ */
|
|
|
+ @PostMapping("/receipt/register")
|
|
|
+ public void receiptRegister(HttpServletRequest request, HttpServletResponse response) throws InvalidKeySpecException, SignatureException, NoSuchAlgorithmException, InvalidKeyException {
|
|
|
+
|
|
|
+ String bizContentStr = (String) request.getAttribute("bizContentStr");
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(bizContentStr);
|
|
|
+
|
|
|
+ String ownerName = jsonObject.getString("currentOwnerName");//现存货人名称
|
|
|
+ String identifier = jsonObject.getString("currentOwnerSocialIdentifier");//现存货人识别号
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONArray("receipts");//编号
|
|
|
+
|
|
|
+ List<ReceiptRegisterResponse> list = new ArrayList<>();
|
|
|
+ for(int i=0;i<jsonArray.size();i++){
|
|
|
+ JSONObject object = jsonArray.getJSONObject(i);
|
|
|
+ String numbers = object.getString("warehouseSerialNumber");
|
|
|
+
|
|
|
+ ReceiptRegisterResponse registerResponse = new ReceiptRegisterResponse();
|
|
|
+ int count = foreignHttpService.receiptRegister(ownerName, identifier, numbers);
|
|
|
+ if (ObjectUtil.isNull(count) || count == 0){
|
|
|
+ registerResponse.setStatus("ABNORMAL");
|
|
|
+ registerResponse.setComments("参数错误,检查参数");
|
|
|
+ }else {
|
|
|
+ registerResponse.setStatus("SUCCESS");
|
|
|
+ }
|
|
|
+ registerResponse.setWarehouseSerialNumber(numbers);
|
|
|
+ list.add(registerResponse);
|
|
|
+ }
|
|
|
+
|
|
|
+ sendRequest(Collections.singletonList(list),response);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 客户检验指令
|
|
|
+ */
|
|
|
+ @PostMapping("/customer/verification")
|
|
|
+ public void verification(HttpServletRequest request, HttpServletResponse response) throws InvalidKeySpecException, SignatureException, NoSuchAlgorithmException, InvalidKeyException {
|
|
|
+
|
|
|
+ String bizContentStr = (String) request.getAttribute("bizContentStr");
|
|
|
+
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(bizContentStr);
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONArray("customers");//客户
|
|
|
+
|
|
|
+ List<CustomerVerifyResponse> list = new ArrayList<>();
|
|
|
+ for(int i=0;i<jsonArray.size();i++){
|
|
|
+ JSONObject object = jsonArray.getJSONObject(i);
|
|
|
+ String name = object.getString("name");
|
|
|
+ String identifier = object.getString("socialIdentifier");
|
|
|
+
|
|
|
+ TCorps corps = foreignHttpService.verification(name, identifier);
|
|
|
+
|
|
|
+ CustomerVerifyResponse verifyResponse = new CustomerVerifyResponse();
|
|
|
+ if (ObjectUtil.isNull(corps)){
|
|
|
+ verifyResponse.setStatus("ABNORMAL");
|
|
|
+ verifyResponse.setComments("参数错误,检查参数");
|
|
|
+ }else {
|
|
|
+ verifyResponse.setStatus("SUCCESS");
|
|
|
+ verifyResponse.setSocialIdentifier(corps.getUscc());
|
|
|
+ }
|
|
|
+ list.add(verifyResponse);
|
|
|
+ }
|
|
|
+
|
|
|
+ sendRequest(Collections.singletonList(list),response);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 仓单过户指令
|
|
|
+ */
|
|
|
+ @PostMapping("/receipt/transfer")
|
|
|
+ public void receiptTransfer(HttpServletRequest request, HttpServletResponse response) throws InvalidKeySpecException, SignatureException, NoSuchAlgorithmException, InvalidKeyException, ParseException {
|
|
|
+
|
|
|
+ String bizContentStr = (String) request.getAttribute("bizContentStr");
|
|
|
+
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(bizContentStr);
|
|
|
+
|
|
|
+ List<ReceiptTransferResponse> list = new ArrayList<>();
|
|
|
+
|
|
|
+ String number = jsonObject.getString("warehouseSerialNumber");//仓库编码
|
|
|
+ String ownerName = jsonObject.getString("currentOwnerName");//现存货人名称
|
|
|
+ String identifier = jsonObject.getString("currentOwnerSocialIdentifier");//现存货人编码
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONArray("targetOwners");//目标存货人数组
|
|
|
+
|
|
|
+ for(int i=0;i<jsonArray.size();i++){
|
|
|
+ TWarehouseBills warehouseBills = new TWarehouseBills();
|
|
|
+ ReceiptTransferResponse transferResponse = new ReceiptTransferResponse();
|
|
|
+
|
|
|
+ JSONObject object = jsonArray.getJSONObject(i);//目标存货人
|
|
|
+ if (jsonArray.size() == 1){
|
|
|
+ //现存货人
|
|
|
+ TCorps corps = foreignHttpService.verification(ownerName, identifier);
|
|
|
+ if (ObjectUtil.isNull(corps)){
|
|
|
+ transferResponse.setStatus("ABNORMAL");
|
|
|
+ transferResponse.setComments("参数错误,检查参数");
|
|
|
+ transferResponse.setWarehouseSerialNumber(number);
|
|
|
+ list.add(transferResponse);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ warehouseBills.setfCorpid(corps.getfId());
|
|
|
+
|
|
|
+ }else if (jsonArray.size() > 1 && i > 0){
|
|
|
+ //现存货人
|
|
|
+ TCorps corps = foreignHttpService.verification(jsonArray.getJSONObject(i - 1).getString("name"),
|
|
|
+ jsonArray.getJSONObject(i - 1).getString("socialIdentifier"));
|
|
|
+ if (ObjectUtil.isNull(corps)){
|
|
|
+ transferResponse.setStatus("ABNORMAL");
|
|
|
+ transferResponse.setComments("参数错误,检查参数");
|
|
|
+ transferResponse.setWarehouseSerialNumber(number);
|
|
|
+ list.add(transferResponse);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ warehouseBills.setfCorpid(corps.getfId());
|
|
|
+ }
|
|
|
+
|
|
|
+ String name = object.getString("name");//目标存货人名称
|
|
|
+ String socialIdentifier = object.getString("socialIdentifier");//目标存货人编码
|
|
|
+
|
|
|
+ TCorps toCorps = foreignHttpService.verification(name, socialIdentifier);
|
|
|
+
|
|
|
+ if (ObjectUtil.isNull(toCorps)){
|
|
|
+ transferResponse.setStatus("ABNORMAL");
|
|
|
+ transferResponse.setComments("参数错误,检查参数");
|
|
|
+ transferResponse.setWarehouseSerialNumber(number);
|
|
|
+ list.add(transferResponse);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ warehouseBills.setfTocorpid(toCorps.getfId());
|
|
|
+
|
|
|
+ int count = foreignHttpService.receiptTransfer(warehouseBills);
|
|
|
+
|
|
|
+ if (count == 0){
|
|
|
+ transferResponse.setStatus("ABNORMAL");
|
|
|
+ transferResponse.setComments("参数错误,检查参数");
|
|
|
+ }else {
|
|
|
+ transferResponse.setStatus("SUCCESS");
|
|
|
+ }
|
|
|
+ transferResponse.setCompletionTimestamp(new Date().getTime());
|
|
|
+ transferResponse.setWarehouseSerialNumber(number);
|
|
|
+
|
|
|
+ list.add(transferResponse);
|
|
|
+ }
|
|
|
+
|
|
|
+ sendRequest(Collections.singletonList(list),response);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 仓单解锁指令
|
|
|
+ */
|
|
|
+ @PostMapping("/receipt/cancel")
|
|
|
+ public void receiptCancel(HttpServletRequest request, HttpServletResponse response) throws InvalidKeySpecException, SignatureException, NoSuchAlgorithmException, InvalidKeyException {
|
|
|
+
|
|
|
+ String bizContentStr = (String) request.getAttribute("bizContentStr");
|
|
|
+
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(bizContentStr);
|
|
|
+
|
|
|
+ String ownerName = jsonObject.getString("currentOwnerName");//现存货人名称
|
|
|
+ String identifier = jsonObject.getString("currentOwnerSocialIdentifier");//现存货人识别号
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONArray("receipts");//编号
|
|
|
+
|
|
|
+ List<ReceiptCancelResponse> list = new ArrayList<>();
|
|
|
+ for(int i=0;i<jsonArray.size();i++){
|
|
|
+ JSONObject object = jsonArray.getJSONObject(i);
|
|
|
+ String numbers = object.getString("warehouseSerialNumber");
|
|
|
+
|
|
|
+ ReceiptCancelResponse cancelResponse = new ReceiptCancelResponse();
|
|
|
+ int count = foreignHttpService.receiptCancel(ownerName, identifier, numbers);
|
|
|
+ if (count == 0){
|
|
|
+ cancelResponse.setStatus("ABNORMAL");
|
|
|
+ cancelResponse.setComments("参数错误,检查参数");
|
|
|
+ }else {
|
|
|
+ cancelResponse.setStatus("SUCCESS");
|
|
|
+ }
|
|
|
+ cancelResponse.setWarehouseSerialNumber(numbers);
|
|
|
+ list.add(cancelResponse);
|
|
|
+ }
|
|
|
+
|
|
|
+ sendRequest(Collections.singletonList(list),response);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void sendRequest(List<Object> list, HttpServletResponse response) throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException, SignatureException {
|
|
|
+ String responseBizContext;
|
|
|
+ try {
|
|
|
+ responseBizContext = new ObjectMapper().writeValueAsString(list);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ String nonceStr = UUID.randomUUID().toString().replaceAll("-", ""); // 随机串 UUID
|
|
|
+ long timestamp = System.currentTimeMillis(); // 当前系统的时间戳 精度 毫秒
|
|
|
+
|
|
|
+ String data = assembleResponseData(nonceStr, timestamp, responseBizContext);
|
|
|
+
|
|
|
+ String privateKeyBase64 = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDNftymM/qRWbLyVjHz5mTsPxZ/Owh9c9YC7wzSF4EA1lJY5TCd8v9rEoLFkH2YIrcsjNKVXNEZesAkwDDTAnntNyrP/4TOoGBwMYhjlkjje9zPNdI71VovEwwR6EFGbzK2XqWe3t8lLRMhZso5gQCI52UGPFWyWHD7n5a1QXNuwK+waLzecX7wuWvKeVmh0FVczmHAhiDmGgFeUaCI47q89/2KlxnhrbZjZCKl9fakohZuiZ4PHmH0ONjs5SCQPgeiLXlo1BZ8rN/GUYzqNZUJ1s8YtWwu+17G16MHrHlkN3iCIeSV5LOAZdyj/beTYog1j9EZheluoYr6FpAF4jonAgMBAAECggEACPoky4HzzUu83IdVcVE8UXHEGtTKXyijTceBqN/r+8xhFo8Um6HU9Kl/WwAf7Hh/xgt025+NZu6M3E4lE+LEzs8dKK8B70DkVaJkUe1ry7xKfibcw05jvTC400NxLpGHBp6F37Xey7H3ZvsllHOFQXXSXP5fxAXHEcb7/3kXgNwH9rF9jto8BmULYuKR2OmX6BN0hN1jiMD9DflMiZABIYiu/RTHmHHwjwxG7Z/8hN+/uJfMEdWw10AI5lhG4R3C5M/M0/hXPByQ/SODMPS6rbPYjQwFWNSx90jePkEJBzpRkNdvRBok2aulKWE3R67obNnKZMitkdyXIehoQqqFSQKBgQD4KfZ6FTu/XZMfDcZsUpoKyCLzILoI30+iF+fccGkn0JHe5XPlAcDNUkH/0k9pnh7iiUHhq7UTpi1oYlj096H2xjziutxFgqOyMiqU7ZeKJEaQugr1/ksDa3VULWHxK4YqVLnN+6DcD5HJyx2/Ty1iXW14wSEhikhsDwwz6LFxfQKBgQDT+/0aP+JsRYeazd7xpdFEQv/3lPxuv3qKSbCgsvFB3SAPSVPJ6YjaUHR9rtGMJM0B+HVeWtlI2xDhcMecwzRAjnFhf0cFbIHKzLVKYxiTfKF6d6bCp5v870tH3gWRDNjveIQ+s+QUnkwV+XpsP7hP+yqMsS2UQBNJb5jf/0FrcwKBgQDubLqe/omByTCRVFXAOvg+xZw2hMnXvl0u+dLNCr8s/ok3YrIfYrjPS2mXlIKxkbZQpdjDLYpyj2Tu9hZLfSOCCWHz393Ddsk5alNY9JB0q3eUkvn279M4POTj9Bo2cD+dqfs9+LTK2LaT7u7sn/CVofeMXdkr9USxdR+fO8BHrQKBgFCHKV8PZbQ7tYfZLRgfJaAI07P5pOttUd+2nqJtV7jth4BHGs1ZKePFLHuSLYhPcpGNEQkG+gPzNDZv4WRrwy3C7s9aymAFGEkx+qyHeI6Oick8Kt1HTrqHLNHgRb0UZFSUM6ieLcanW7/9RcRZcGrxvvgzVl06+hirjCeLkA6BAoGAba3JHPMxAlWzYTYUoGUka/dpZUNBZueJT1d2bKXS7rP4SHmnnJKjPmuFBukvktG2Z0VCll1FcvKET4ywEvLb4APAXKup5RQYad7WGAsUOEORVZcoMpDZyi8uGB575xjyzsixk+6A06G/JdZ/6jJOzQeT6UZuxAfL33w8/KUbE0U=";
|
|
|
+
|
|
|
+ byte[] signature = signRSA2(data.getBytes(StandardCharsets.UTF_8), privateKeyBase64);
|
|
|
+
|
|
|
+ String authorization = assembleResponseAuthorizationToken(nonceStr, timestamp, Base64.getEncoder().encodeToString(signature));
|
|
|
+
|
|
|
+ response.setStatus(HttpStatus.OK.value());
|
|
|
+ response.setHeader("Request-ID", UUID.randomUUID().toString());
|
|
|
+ response.setHeader("Authorization", authorization);
|
|
|
+ response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
|
|
+ response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
|
|
+
|
|
|
+ try {
|
|
|
+ response.getWriter().print(responseBizContext);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *签名头: 无先后顺序
|
|
|
+ * 请求随机串nonce_str
|
|
|
+ * 时间戳timestamp 精度 毫秒
|
|
|
+ * Base64编码得到签名值 signature
|
|
|
+ *
|
|
|
+ * @param nonceStr
|
|
|
+ * @param timestamp
|
|
|
+ * @param signature
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private static String assembleResponseAuthorizationToken(String nonceStr, long timestamp, String signature) {
|
|
|
+ return "nonce_str=" + nonceStr + ","
|
|
|
+ + "timestamp=" + timestamp + ","
|
|
|
+ + "signature=" + signature + "";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 响应数据签名生成规则:
|
|
|
+ * 签名串一共有三行,每一行为一个参数。
|
|
|
+ * 行尾以 \n(换行符,ASCII编码值为0x0A)结束,包括最后一行。
|
|
|
+ * 若应答报文主体为空(如HTTP状态码为204 No Content),最后一行仅为一个\n换行符。
|
|
|
+ *
|
|
|
+ * 应答时间戳\n
|
|
|
+ * 应答随机串\n
|
|
|
+ * 应答报文主体\n
|
|
|
+ *
|
|
|
+ * @param nonceStr
|
|
|
+ * @param timestamp
|
|
|
+ * @param bizContentStr
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private static String assembleResponseData(String nonceStr, long timestamp, String bizContentStr) {
|
|
|
+ return timestamp + "\n"
|
|
|
+ + nonceStr + "\n"
|
|
|
+ + bizContentStr + "\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ private static final String DEFAULT_RSA = "RSA";
|
|
|
+ private static final String DEFAULT_RSA2 = "SHA256withRSA";
|
|
|
+
|
|
|
+ public static byte[] signRSA2(byte[] data, String privateKeyBase64) throws InvalidKeySpecException, SignatureException, NoSuchAlgorithmException, InvalidKeyException {
|
|
|
+ PrivateKey privateKey = KeyFactory.getInstance(DEFAULT_RSA).generatePrivate(new PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKeyBase64)));
|
|
|
+
|
|
|
+ Signature sign = Signature.getInstance(DEFAULT_RSA2);
|
|
|
+
|
|
|
+ sign.initSign(privateKey);
|
|
|
+
|
|
|
+ sign.update(data);
|
|
|
+
|
|
|
+ return sign.sign();
|
|
|
+ }
|
|
|
+}
|