From f935a98184892d3788a3f1535abb2c400f3c27c9 Mon Sep 17 00:00:00 2001 From: liuxinxin Date: Fri, 10 Feb 2023 15:17:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=B0=E7=AB=A0=E9=85=8D=E7=BD=AE=20?= =?UTF-8?q?=E8=B4=A2=E6=94=BF=E7=BC=96=E7=A0=81=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/GeneratorCodeKingbaseConfig.java | 2 +- .../com/ningdatech/pmapi/api/tiangu/SealApi.java | 13 + .../pmapi/ding/task/EmployeeBatchGetTask.java | 21 ++ .../pmapi/ding/task/OrganizationBatchGetTask.java | 7 - .../controller/NdCompanyFiscalCodeController.java | 20 ++ .../pmapi/fiscal/entity/NdCompanyFiscalCode.java | 39 +++ .../fiscal/mapper/NdCompanyFiscalCodeMapper.java | 16 + .../fiscal/mapper/NdCompanyFiscalCodeMapper.xml | 5 + .../service/INdCompanyFiscalCodeService.java | 16 + .../impl/NdCompanyFiscalCodeServiceImpl.java | 20 ++ .../ningdatech/pmapi/irs/sign/IRSAPIRequest.java | 353 +++++++++++++++++++++ .../controller/NdCompanySignatureController.java | 20 ++ .../pmapi/signature/entity/NdCompanySignature.java | 38 +++ .../signature/mapper/NdCompanySignatureMapper.java | 16 + .../signature/mapper/NdCompanySignatureMapper.xml | 5 + .../service/INdCompanySignatureService.java | 16 + .../impl/NdCompanySignatureServiceImpl.java | 20 ++ 17 files changed, 619 insertions(+), 8 deletions(-) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/api/tiangu/SealApi.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/ding/task/EmployeeBatchGetTask.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/fiscal/controller/NdCompanyFiscalCodeController.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/fiscal/entity/NdCompanyFiscalCode.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/fiscal/mapper/NdCompanyFiscalCodeMapper.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/fiscal/mapper/NdCompanyFiscalCodeMapper.xml create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/fiscal/service/INdCompanyFiscalCodeService.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/fiscal/service/impl/NdCompanyFiscalCodeServiceImpl.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/irs/sign/IRSAPIRequest.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/signature/controller/NdCompanySignatureController.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/signature/entity/NdCompanySignature.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/signature/mapper/NdCompanySignatureMapper.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/signature/mapper/NdCompanySignatureMapper.xml create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/signature/service/INdCompanySignatureService.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/signature/service/impl/NdCompanySignatureServiceImpl.java diff --git a/ningda-generator/src/main/java/com/ningdatech/generator/config/GeneratorCodeKingbaseConfig.java b/ningda-generator/src/main/java/com/ningdatech/generator/config/GeneratorCodeKingbaseConfig.java index 3e1ed7f..fe5ff53 100644 --- a/ningda-generator/src/main/java/com/ningdatech/generator/config/GeneratorCodeKingbaseConfig.java +++ b/ningda-generator/src/main/java/com/ningdatech/generator/config/GeneratorCodeKingbaseConfig.java @@ -56,7 +56,7 @@ public class GeneratorCodeKingbaseConfig { } public static void main(String[] args) { - generate("Lierbao", "organization", PATH_LXX, "ding_organization"); + generate("Lierbao", "signature", PATH_LXX, "nd_company_signature"); } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/api/tiangu/SealApi.java b/pmapi/src/main/java/com/ningdatech/pmapi/api/tiangu/SealApi.java new file mode 100644 index 0000000..24c1175 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/api/tiangu/SealApi.java @@ -0,0 +1,13 @@ +package com.ningdatech.pmapi.api.tiangu; + +import com.aliyuncs.http.IHttpClient; +import org.springframework.stereotype.Component; + +/** + * @author liuxinxin + * @date 2023/2/10 上午11:15 + */ +@Component +public class SealApi { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/ding/task/EmployeeBatchGetTask.java b/pmapi/src/main/java/com/ningdatech/pmapi/ding/task/EmployeeBatchGetTask.java new file mode 100644 index 0000000..f7cc263 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/ding/task/EmployeeBatchGetTask.java @@ -0,0 +1,21 @@ +package com.ningdatech.pmapi.ding.task; + +import com.ningdatech.zwdd.client.ZwddClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +/** + * @author liuxinxin + * @date 2023/2/10 上午9:52 + */ + +public class EmployeeBatchGetTask { + + @Autowired + private ZwddClient zwddClient; + + @Transactional(rollbackFor = Exception.class) + public void batchGetEmployeeTask() { + + } +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/ding/task/OrganizationBatchGetTask.java b/pmapi/src/main/java/com/ningdatech/pmapi/ding/task/OrganizationBatchGetTask.java index 9f45951..87790b0 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/ding/task/OrganizationBatchGetTask.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/ding/task/OrganizationBatchGetTask.java @@ -8,7 +8,6 @@ import com.ningdatech.basic.model.GenericResult; import com.ningdatech.pmapi.ding.model.DingOrgInfoTreeDTO; import com.ningdatech.pmapi.organization.entity.DingOrganization; import com.ningdatech.pmapi.organization.service.IDingOrganizationService; -import com.ningdatech.zwdd.client.ZwddAuthClient; import com.ningdatech.zwdd.client.ZwddClient; import com.ningdatech.zwdd.model.dto.DingOrgInfoDTO; import com.ningdatech.zwdd.model.dto.DingScopesV2DTO; @@ -35,9 +34,6 @@ public class OrganizationBatchGetTask { @Autowired private ZwddClient zwddClient; - @Autowired - private ZwddAuthClient zwddAuthClient; - private static final Integer GROUP_SIZE = 100; @Autowired @@ -83,11 +79,9 @@ public class OrganizationBatchGetTask { childDingOrgInfoTreeDTO.setChildCodes(new ArrayList<>()); getDingOrgChild(childDingOrgInfoTreeDTO); treeDTOList.add(childDingOrgInfoTreeDTO); - if (CollectionUtils.isNotEmpty(treeDTOList)) { List saveRecordList = new ArrayList<>(); buildSaveRecordList(treeDTOList, saveRecordList); - // 批量保存 if (saveRecordList.size() <= GROUP_SIZE) { iDingOrganizationService.saveBatch(saveRecordList); @@ -122,7 +116,6 @@ public class OrganizationBatchGetTask { buildSaveRecordList(childCodes, saveRecordList); } } - } private void getDingOrgChild(DingOrgInfoTreeDTO parentDingOrgInfoTreeDTO) { diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/fiscal/controller/NdCompanyFiscalCodeController.java b/pmapi/src/main/java/com/ningdatech/pmapi/fiscal/controller/NdCompanyFiscalCodeController.java new file mode 100644 index 0000000..24809eb --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/fiscal/controller/NdCompanyFiscalCodeController.java @@ -0,0 +1,20 @@ +package com.ningdatech.pmapi.fiscal.controller; + + +import org.springframework.web.bind.annotation.RequestMapping; + +import org.springframework.stereotype.Controller; + +/** + *

+ * 前端控制器 + *

+ * + * @author Lierbao + * @since 2023-02-10 + */ +@Controller +@RequestMapping("/pmapi.fiscal/nd-company-fiscal-code") +public class NdCompanyFiscalCodeController { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/fiscal/entity/NdCompanyFiscalCode.java b/pmapi/src/main/java/com/ningdatech/pmapi/fiscal/entity/NdCompanyFiscalCode.java new file mode 100644 index 0000000..f985b78 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/fiscal/entity/NdCompanyFiscalCode.java @@ -0,0 +1,39 @@ +package com.ningdatech.pmapi.fiscal.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import lombok.Data; + +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + *

+ * + *

+ * + * @author Lierbao + * @since 2023-02-10 + */ +@Data +@TableName("nd_company_fiscal_code") +@ApiModel(value = "NdCompanyFiscalCode对象", description = "") +public class NdCompanyFiscalCode implements Serializable { + + private static final long serialVersionUID = 1L; + + private Long id; + + private String fiscalCode; + + private Long companyId; + + private LocalDateTime createOn; + + private LocalDateTime updateOn; + + private Long createBy; + + private Long updateBy; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/fiscal/mapper/NdCompanyFiscalCodeMapper.java b/pmapi/src/main/java/com/ningdatech/pmapi/fiscal/mapper/NdCompanyFiscalCodeMapper.java new file mode 100644 index 0000000..8ea4cab --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/fiscal/mapper/NdCompanyFiscalCodeMapper.java @@ -0,0 +1,16 @@ +package com.ningdatech.pmapi.fiscal.mapper; + +import com.ningdatech.pmapi.fiscal.entity.NdCompanyFiscalCode; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author Lierbao + * @since 2023-02-10 + */ +public interface NdCompanyFiscalCodeMapper extends BaseMapper { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/fiscal/mapper/NdCompanyFiscalCodeMapper.xml b/pmapi/src/main/java/com/ningdatech/pmapi/fiscal/mapper/NdCompanyFiscalCodeMapper.xml new file mode 100644 index 0000000..710124e --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/fiscal/mapper/NdCompanyFiscalCodeMapper.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/fiscal/service/INdCompanyFiscalCodeService.java b/pmapi/src/main/java/com/ningdatech/pmapi/fiscal/service/INdCompanyFiscalCodeService.java new file mode 100644 index 0000000..3435df2 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/fiscal/service/INdCompanyFiscalCodeService.java @@ -0,0 +1,16 @@ +package com.ningdatech.pmapi.fiscal.service; + +import com.ningdatech.pmapi.fiscal.entity.NdCompanyFiscalCode; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author Lierbao + * @since 2023-02-10 + */ +public interface INdCompanyFiscalCodeService extends IService { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/fiscal/service/impl/NdCompanyFiscalCodeServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/fiscal/service/impl/NdCompanyFiscalCodeServiceImpl.java new file mode 100644 index 0000000..9018260 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/fiscal/service/impl/NdCompanyFiscalCodeServiceImpl.java @@ -0,0 +1,20 @@ +package com.ningdatech.pmapi.fiscal.service.impl; + +import com.ningdatech.pmapi.fiscal.entity.NdCompanyFiscalCode; +import com.ningdatech.pmapi.fiscal.mapper.NdCompanyFiscalCodeMapper; +import com.ningdatech.pmapi.fiscal.service.INdCompanyFiscalCodeService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author Lierbao + * @since 2023-02-10 + */ +@Service +public class NdCompanyFiscalCodeServiceImpl extends ServiceImpl implements INdCompanyFiscalCodeService { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/irs/sign/IRSAPIRequest.java b/pmapi/src/main/java/com/ningdatech/pmapi/irs/sign/IRSAPIRequest.java new file mode 100644 index 0000000..203b4ab --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/irs/sign/IRSAPIRequest.java @@ -0,0 +1,353 @@ +package com.ningdatech.pmapi.irs.sign; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; +import javafx.util.Pair; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ByteArrayEntity; +import org.apache.http.entity.ContentType; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import sun.misc.BASE64Decoder; +import sun.misc.BASE64Encoder; + +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; +import javax.xml.bind.DatatypeConverter; +import java.io.*; +import java.net.URI; +import java.net.URL; +import java.net.URLEncoder; +import java.security.Key; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + + +public class IRSAPIRequest { + //天印服务器接口信息 +// private static String ProjectID = "XXX"; +// private static String ProjectSecret = "XXXX"; +// private static String accessKey = "XXXX"; +// private static String secretKey = "XXXX"; +// private static String apiUrl = "https://ibcdsg.zj.gov.cn:8443/restapi/prod/IC33000020220309000004/seal-platform/seal/v1/rest/sign/signPdf"; + + private static String ProjectID = "XXX"; + private static String ProjectSecret = "XXXX"; + private static String accessKey = "XXXX"; + private static String secretKey = "XXXX"; + private static String apiUrl = "https://ibcdsg.zj.gov.cn:8443/restapi/prod/IC33000020220309000004/seal-platform/seal/v1/rest/sign/signPdf"; + + + public static void main(String[] args) throws Exception { + + createSignPdf(); + + } + + /** + * pdf文件盖章 + * 接口地址:/V1/accounts/outerAccounts/create + * + * @return + */ + public static JSONObject createSignPdf() { + JSONObject obj = null; + String resp = null; + try { + JSONObject ReqData = new JSONObject(); + String pathname = "D://001.pdf"; + File file = new File(pathname); + String fileByte1 = IRSAPIRequest.PDFToBase64(file); + ReqData.put("fileBase64", fileByte1); + ReqData.put("sealSn", "33012108041829053952"); + ReqData.put("posX", "200"); + ReqData.put("posY", "200"); + ReqData.put("signType", "1"); + // ReqData.put("key", "单位"); + ReqData.put("posPage", "1"); + ReqData.put("fileName", "01.pdf"); + + resp = post(ReqData, "post"); + JSONObject jsonObject = JSON.parseObject(resp); + String data = jsonObject.getString("data"); + JSONObject jsondata = JSON.parseObject(data); + String signFileB64 = jsondata.getString("signFileB64"); + IRSAPIRequest.base64StringToPdf(signFileB64, "D:\\test21.pdf"); + } catch (Exception e) { + e.printStackTrace(); + } + return obj; + } + + + public static String post(JSONObject data, String requestMethod) throws Exception { + + //计算irs请求头里面参数信息 + DateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); + dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); + String date = dateFormat.format(new Date()); + URL url = new URL(apiUrl); + URI uri = new URI(url.getProtocol(), url.getHost(), url.getPath(), url.getQuery(), null); + String canonicalQueryString = getCanonicalQueryString(uri.getQuery()); + String message = requestMethod.toUpperCase() + "\n" + uri.getPath() + "\n" + canonicalQueryString + "\n" + accessKey + "\n" + date + "\n"; + Mac hasher = Mac.getInstance("HmacSHA256"); + hasher.init(new SecretKeySpec(secretKey.getBytes(), "HmacSHA256")); + byte[] hash = hasher.doFinal(message.getBytes()); + DatatypeConverter.printHexBinary(hash); + String sign = DatatypeConverter.printBase64Binary(hash); + /*byte[] stream1 = message.toString().getBytes("UTF-8"); + String sign = sign1(stream1);*/ + + // 计算电子印章组件signature值 + String myData = data.toString(); + System.out.println(myData); + byte[] stream = data.toString().getBytes("UTF-8"); + // 签名数据,根据签名算法,对请求数据进行签名 + String signature = sign(stream); + //System.out.println(signature); + // 设置HTTP请求头 + HttpEntityEnclosingRequestBase req = new HttpPost(apiUrl); + // project-id为用户的projectId + req.addHeader("appId", ProjectID); + // signature为之前生成的签名 + req.addHeader("signature", signature); + req.addHeader("X-BG-HMAC-SIGNATURE", sign); + req.addHeader("X-BG-HMAC-ALGORITHM", "hmac-sha256"); + req.addHeader("X-BG-HMAC-ACCESS-KEY", accessKey); + req.addHeader("X-BG-DATE-TIME", date); + req.addHeader("Content-Type", "application/json"); + + // 设置HTTP请求体 + HttpEntity entity = new ByteArrayEntity(stream, ContentType + .create(ContentType.APPLICATION_JSON.getMimeType(), "UTF-8")); + req.setEntity(entity); + + // 执行请求 + HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); + CloseableHttpClient cli = httpClientBuilder.build(); + HttpResponse res = cli.execute(req); + int statusCode = res.getStatusLine().getStatusCode(); + System.out.println(statusCode); + if (200 != statusCode) { + System.out.println(statusCode); + } + // 获取响应 + InputStream in = res.getEntity().getContent(); + + byte[] resp = readStream(in); + String strRes = new String(resp, "UTF-8"); + System.out.println(strRes); + cli.close(); + return strRes; + } + + private static String sign(byte[] stream) + throws Exception { + // 获取消息验证码类的实例,算法选择"HmacSHA256" + Mac mac = Mac.getInstance("HmacSHA256"); + + // 获取安全密钥 + Key secKey = new SecretKeySpec( + ProjectSecret.getBytes("UTF-8"), + mac.getAlgorithm()); + + // 初始化 + mac.init(secKey); + + // 获得签名 + byte[] sign = mac.doFinal(stream); + + // 将byte[]格式的签名用binary编码转化为字符串返回 + return binaryEncode(sign); + + } + + private static String sign1(byte[] stream) + throws Exception { + // 获取消息验证码类的实例,算法选择"HmacSHA256" + Mac mac = Mac.getInstance("HmacSHA256"); + + // 获取安全密钥 + Key secKey = new SecretKeySpec( + secretKey.getBytes("UTF-8"), + mac.getAlgorithm()); + + // 初始化 + mac.init(secKey); + + // 获得签名 + byte[] sign = mac.doFinal(stream); + + // 将byte[]格式的签名用binary编码转化为字符串返回 + return binaryEncode(sign); + + } + + public static String binaryEncode(byte[] data) { + final char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', + '9', 'a', 'b', 'c', 'd', 'e', 'f'}; + + StringBuilder builder = new StringBuilder(); + + for (byte i : data) { + builder.append(hexDigits[i >>> 4 & 0xf]); + builder.append(hexDigits[i & 0xf]); + } + + return builder.toString(); + } + + public static byte[] readStream(InputStream in) throws IOException { + + ByteArrayOutputStream output = new ByteArrayOutputStream(); + + byte[] buffer = new byte[1024 * 10]; + try { + + int n = 0; + while ((n = in.read(buffer)) != -1) { + output.write(buffer, 0, n); + } + + return output.toByteArray(); + + } finally { + in.close(); + output.close(); + } + } + + /** + * Description: 将pdf文件转换为Base64编码 + * +// * @param 要转的的pdf文件 + * @Author fuyuwei + * Create Date: 2015年8月3日 下午9:52:30 + */ + public static String PDFToBase64(File file) { + BASE64Encoder encoder = new BASE64Encoder(); + FileInputStream fin = null; + BufferedInputStream bin = null; + ByteArrayOutputStream baos = null; + BufferedOutputStream bout = null; + try { + fin = new FileInputStream(file); + bin = new BufferedInputStream(fin); + baos = new ByteArrayOutputStream(); + bout = new BufferedOutputStream(baos); + byte[] buffer = new byte[1024]; + int len = bin.read(buffer); + while (len != -1) { + bout.write(buffer, 0, len); + len = bin.read(buffer); + } + //刷新此输出流并强制写出所有缓冲的输出字节 + bout.flush(); + byte[] bytes = baos.toByteArray(); + return Base64.encode(bytes); + //return encoder.encodeBuffer(bytes); + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + fin.close(); + bin.close(); + bout.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return null; + } + + /** + * Description: 将base64编码内容转换为Pdf + * +// * @param base64编码内容,文件的存储路径(含文件名) + * @Author fuyuwei + * Create Date: 2015年7月30日 上午9:40:23 + */ + public static void base64StringToPdf(String base64Content, String filePath) { + BASE64Decoder decoder = new BASE64Decoder(); + BufferedInputStream bis = null; + FileOutputStream fos = null; + BufferedOutputStream bos = null; + + try { + byte[] bytes = decoder.decodeBuffer(base64Content);//base64编码内容转换为字节数组 + ByteArrayInputStream byteInputStream = new ByteArrayInputStream(bytes); + bis = new BufferedInputStream(byteInputStream); + File file = new File(filePath); + File path = file.getParentFile(); + if (!path.exists()) { + path.mkdirs(); + } + fos = new FileOutputStream(file); + bos = new BufferedOutputStream(fos); + + byte[] buffer = new byte[1024]; + int length = bis.read(buffer); + while (length != -1) { + bos.write(buffer, 0, length); + length = bis.read(buffer); + } + bos.flush(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + //closeStream(bis, fos, bos); + } + } + + + private static String getCanonicalQueryString(String query) { + if (query == null || query.trim().length() == 0) { + return ""; + } + List> queryParamList = new ArrayList<>(); + String[] params = query.split("&"); + for (String param : params) { + int eqIndex = param.indexOf("="); + String key = param.substring(0, eqIndex); + String value = param.substring(eqIndex + 1); + Pair pair = new Pair(key, value); + queryParamList.add(pair); + } + + List> sortedParamList = queryParamList.stream().sorted(Comparator.comparing(param -> param.getKey() + "=" + Optional.ofNullable(param.getValue()).orElse(""))).collect(Collectors.toList()); + List> encodeParamList = new ArrayList<>(); + sortedParamList.stream().forEach(param -> { + try { + String key = URLEncoder.encode(param.getKey(), "utf-8"); + String value = URLEncoder.encode(Optional.ofNullable(param.getValue()).orElse(""), "utf-8") + .replaceAll("\\%2B", "%20") + .replaceAll("\\+", "%20") + .replaceAll("\\%21", "!") + .replaceAll("\\%27", "'") + .replaceAll("\\%28", "(") + .replaceAll("\\%29", ")") + .replaceAll("\\%7E", "~") + .replaceAll("\\%25", "%"); + encodeParamList.add(new Pair<>(key, value)); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException("encoding error"); + } + }); + StringBuilder queryParamString = new StringBuilder(64); + for (Pair encodeParam : encodeParamList) { + queryParamString.append(encodeParam.getKey()).append("=").append(Optional.ofNullable(encodeParam.getValue()).orElse("")); + queryParamString.append("&"); + } + + return queryParamString.substring(0, queryParamString.length() - 1); + } +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/signature/controller/NdCompanySignatureController.java b/pmapi/src/main/java/com/ningdatech/pmapi/signature/controller/NdCompanySignatureController.java new file mode 100644 index 0000000..d5269da --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/signature/controller/NdCompanySignatureController.java @@ -0,0 +1,20 @@ +package com.ningdatech.pmapi.signature.controller; + + +import org.springframework.web.bind.annotation.RequestMapping; + +import org.springframework.stereotype.Controller; + +/** + *

+ * 前端控制器 + *

+ * + * @author Lierbao + * @since 2023-02-10 + */ +@Controller +@RequestMapping("/pmapi.signature/nd-company-signature") +public class NdCompanySignatureController { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/signature/entity/NdCompanySignature.java b/pmapi/src/main/java/com/ningdatech/pmapi/signature/entity/NdCompanySignature.java new file mode 100644 index 0000000..73a2514 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/signature/entity/NdCompanySignature.java @@ -0,0 +1,38 @@ +package com.ningdatech.pmapi.signature.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import lombok.Data; + +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + *

+ * + *

+ * + * @author Lierbao + * @since 2023-02-10 + */ +@TableName("nd_company_signature") +@Data +@ApiModel(value = "NdCompanySignature对象", description = "") +public class NdCompanySignature implements Serializable { + + private static final long serialVersionUID = 1L; + + private Long id; + + private String sealSn; + + private Long companyId; + + private LocalDateTime createOn; + + private Long createBy; + + private LocalDateTime updateOn; + + private Long updateBy; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/signature/mapper/NdCompanySignatureMapper.java b/pmapi/src/main/java/com/ningdatech/pmapi/signature/mapper/NdCompanySignatureMapper.java new file mode 100644 index 0000000..b952e35 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/signature/mapper/NdCompanySignatureMapper.java @@ -0,0 +1,16 @@ +package com.ningdatech.pmapi.signature.mapper; + +import com.ningdatech.pmapi.signature.entity.NdCompanySignature; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author Lierbao + * @since 2023-02-10 + */ +public interface NdCompanySignatureMapper extends BaseMapper { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/signature/mapper/NdCompanySignatureMapper.xml b/pmapi/src/main/java/com/ningdatech/pmapi/signature/mapper/NdCompanySignatureMapper.xml new file mode 100644 index 0000000..848530f --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/signature/mapper/NdCompanySignatureMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/signature/service/INdCompanySignatureService.java b/pmapi/src/main/java/com/ningdatech/pmapi/signature/service/INdCompanySignatureService.java new file mode 100644 index 0000000..d8039ce --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/signature/service/INdCompanySignatureService.java @@ -0,0 +1,16 @@ +package com.ningdatech.pmapi.signature.service; + +import com.ningdatech.pmapi.signature.entity.NdCompanySignature; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author Lierbao + * @since 2023-02-10 + */ +public interface INdCompanySignatureService extends IService { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/signature/service/impl/NdCompanySignatureServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/signature/service/impl/NdCompanySignatureServiceImpl.java new file mode 100644 index 0000000..d3f7d7b --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/signature/service/impl/NdCompanySignatureServiceImpl.java @@ -0,0 +1,20 @@ +package com.ningdatech.pmapi.signature.service.impl; + +import com.ningdatech.pmapi.signature.entity.NdCompanySignature; +import com.ningdatech.pmapi.signature.mapper.NdCompanySignatureMapper; +import com.ningdatech.pmapi.signature.service.INdCompanySignatureService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author Lierbao + * @since 2023-02-10 + */ +@Service +public class NdCompanySignatureServiceImpl extends ServiceImpl implements INdCompanySignatureService { + +}