From b94067697eaaa0a726d151c0efb0070c146cfb27 Mon Sep 17 00:00:00 2001 From: anthonywj Date: Sat, 22 Jul 2023 13:45:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=85=A5=E5=A4=A9=E7=9C=BC=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/sup/UserComanyController.java | 27 ++++- .../entity/basic/TyCompanySearchEntity.java | 65 +++++++++++ .../java/com/glxp/api/http/YyHttpClient.java | 35 ++++++ .../com/glxp/api/util/UnifiedCodeUtil.java | 108 ++++++++++++++++++ src/main/resources/application-dev.yml | 8 +- src/main/resources/application-pro.yml | 4 +- 6 files changed, 238 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/glxp/api/entity/basic/TyCompanySearchEntity.java create mode 100644 src/main/java/com/glxp/api/http/YyHttpClient.java create mode 100644 src/main/java/com/glxp/api/util/UnifiedCodeUtil.java diff --git a/src/main/java/com/glxp/api/controller/sup/UserComanyController.java b/src/main/java/com/glxp/api/controller/sup/UserComanyController.java index 1167eb3..df2ed40 100644 --- a/src/main/java/com/glxp/api/controller/sup/UserComanyController.java +++ b/src/main/java/com/glxp/api/controller/sup/UserComanyController.java @@ -12,9 +12,11 @@ import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.controller.BaseController; import com.glxp.api.entity.basic.ProductInfoEntity; +import com.glxp.api.entity.basic.TyCompanySearchEntity; import com.glxp.api.entity.sup.UserCompanyEntity; import com.glxp.api.entity.sup.UserCompanyOnlineEntity; import com.glxp.api.exception.JsonException; +import com.glxp.api.http.YyHttpClient; import com.glxp.api.req.auth.FilterUserComapanyRequest; import com.glxp.api.req.basic.ProductInfoFilterRequest; import com.glxp.api.res.PageSimpleResponse; @@ -24,6 +26,7 @@ import com.glxp.api.res.sup.UserCompanyResponse; import com.glxp.api.service.sup.UserCompanyOnlineService; import com.glxp.api.service.sup.UserCompanyService; import com.glxp.api.util.DateUtil; +import com.glxp.api.util.UnifiedCodeUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; @@ -111,21 +114,39 @@ public class UserComanyController extends BaseController { return ResultVOUtils.success(userCompanyResponse); } + @Resource + YyHttpClient yyHttpClient; @ApiOperation(value = "查询用户企业信息", response = UserCompanyEntity.class) @GetMapping("udi/auth/user/comapny/info") public BaseResponse getCompanyInfo(FilterUserComapanyRequest filterUserComapanyRequest) { + + if (StrUtil.isNotEmpty(filterUserComapanyRequest.getCreditNum())) { + if (!UnifiedCodeUtil.CodeValidate(filterUserComapanyRequest.getCreditNum())) { + return ResultVOUtils.error(500, "非正确统一社会信用代码!"); + } + } UserCompanyResponse userCompanyResponse = new UserCompanyResponse(); List userCompanyEntities = userCompanyService.filterCompanyName(filterUserComapanyRequest); if (CollUtil.isNotEmpty(userCompanyEntities)) { UserCompanyEntity userCompanyEntity = userCompanyEntities.get(0); BeanUtil.copyProperties(userCompanyEntity, userCompanyResponse); userCompanyResponse.setRegStatus(1); + return ResultVOUtils.success(userCompanyResponse); } else { - userCompanyResponse.setCreditNum(filterUserComapanyRequest.getCreditNum()); - userCompanyResponse.setRegStatus(3); + BaseResponse baseResponse = yyHttpClient.findBycCeditCode(filterUserComapanyRequest.getCreditNum()); + if (baseResponse != null && baseResponse.getCode() == 20000) { + TyCompanySearchEntity tyCompanySearchEntity = baseResponse.getData(); + userCompanyResponse.setCompanyName(tyCompanySearchEntity.getName()); + userCompanyResponse.setLegalPerson(tyCompanySearchEntity.getLegalPersonName()); + userCompanyResponse.setCreditNum(filterUserComapanyRequest.getCreditNum()); + userCompanyResponse.setRegStatus(3); + return ResultVOUtils.success(userCompanyResponse); + } else + return ResultVOUtils.error(500, "查无此企业!"); + } - return ResultVOUtils.success(userCompanyResponse); + } diff --git a/src/main/java/com/glxp/api/entity/basic/TyCompanySearchEntity.java b/src/main/java/com/glxp/api/entity/basic/TyCompanySearchEntity.java new file mode 100644 index 0000000..eddbc54 --- /dev/null +++ b/src/main/java/com/glxp/api/entity/basic/TyCompanySearchEntity.java @@ -0,0 +1,65 @@ +package com.glxp.api.entity.basic; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class TyCompanySearchEntity implements Serializable { + private String id; + + @TableField(value = "regStatus") + @ApiModelProperty(value = "") + private String regStatus; + + @TableField(value = "estiblishTime") + @ApiModelProperty(value = "") + private String estiblishTime; + + @TableField(value = "regCapital") + @ApiModelProperty(value = "") + private String regCapital; + + @TableField(value = "companyType") + @ApiModelProperty(value = "") + private String companyType; + + @TableField(value = "matchType") + @ApiModelProperty(value = "") + private String matchType; + + @TableField(value = "`type`") + @ApiModelProperty(value = "") + private String type; + + @TableField(value = "legalPersonName") + @ApiModelProperty(value = "") + private String legalPersonName; + + @TableField(value = "regNumber") + @ApiModelProperty(value = "") + private String regNumber; + + @TableField(value = "creditCode") + @ApiModelProperty(value = "") + private String creditCode; + + @TableField(value = "`name`") + @ApiModelProperty(value = "") + private String name; + + @TableField(value = "orgNumber") + @ApiModelProperty(value = "") + private String orgNumber; + + @TableField(value = "base") + @ApiModelProperty(value = "") + private String base; + + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/com/glxp/api/http/YyHttpClient.java b/src/main/java/com/glxp/api/http/YyHttpClient.java new file mode 100644 index 0000000..a89c452 --- /dev/null +++ b/src/main/java/com/glxp/api/http/YyHttpClient.java @@ -0,0 +1,35 @@ +package com.glxp.api.http; + +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; +import com.glxp.api.common.res.BaseResponse; +import com.glxp.api.common.util.ResultVOUtils; +import com.glxp.api.entity.basic.TyCompanySearchEntity; +import com.glxp.api.util.HttpClient; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.Map; + +@Service +public class YyHttpClient { + @Value("${UDI_SERVER_URL}") + private String udiUrl; + + public BaseResponse findBycCeditCode(String creditCode) { + try { + Map paramMap = new HashMap<>(16); + paramMap.put("creditCode", creditCode); + String response = HttpClient.mipsGet(udiUrl + "/udidl/ty/company/findBycCeditCode", paramMap); + + BaseResponse baseResponse = + JSONObject.parseObject(response, new TypeReference>() { + }); + return baseResponse; + } catch (Exception e) { + e.printStackTrace(); + return ResultVOUtils.error(500, "查询统一社会信用号出错!"); + } + } +} diff --git a/src/main/java/com/glxp/api/util/UnifiedCodeUtil.java b/src/main/java/com/glxp/api/util/UnifiedCodeUtil.java new file mode 100644 index 0000000..b07cd92 --- /dev/null +++ b/src/main/java/com/glxp/api/util/UnifiedCodeUtil.java @@ -0,0 +1,108 @@ +package com.glxp.api.util; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +import org.apache.commons.lang3.StringUtils; + +//import plugin.template.TemplateStepMeta; + +/** + * 统一社会信用代码规则验证器 + * + * @author balizuoan + */ +public class UnifiedCodeUtil { + + //正则校验 如果想要不区分大小写,就在最后一个数组中加入 abcsefghjklmnpqrtuwxy + private static final String REGEX = "[1-9NY]{1}[1-9]{1}[1-6]{1}[0-9]{5}[0123456789ABCDEFGHJKLMNPQRTUWXYabcsefghjklmnpqrtuwxy]{10}"; + + private static final int[] WEIGHT = {1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28}; + + private static final String BASE_CODE_STRING = "0123456789ABCDEFGHJKLMNPQRTUWXYabcsefghjklmnpqrtuwxy"; + + private static final char[] BASE_CODE_ARRAY = BASE_CODE_STRING.toCharArray(); + + private static final List BASE_CODES = new ArrayList<>(); + + /** + * 登记管理部门+机构类别代码 + * http://www.sohu.com/a/332134717_120209852 + */ + private static final List REGIST_CODE = Arrays.asList( + "11", "12", "13", "19", + "21", "29", + "31", "32", "33", "34", "35", "39", + "41", "49", + "51", "52", "53", "59", + "61", "62", "69", + "71", "72", "79", + "81", "89", + "91", "92", "93", + "A1", "A9", + "N1", "N2", "N3", "N9", + "Y1" + ); + + /** + * 省级行政区划代码 + */ + private static final List PROVINCE_REGION_CODE = Arrays.asList( + "11", "12", "13", "14", "15", "21", "22", "23", "31", "32", "33", "34", "35", "36", "37", "41", "42", "43", "44", "45", "46", + "50", "51", "52", "53", "54", "61", "62", "63", "64", "65", "71", "81", "82", "91" + ); + + static { + for (char c : BASE_CODE_ARRAY) { + BASE_CODES.add(c); + } + } + + /** + * 校验方法 + * + * @param value 信用代码 + * @return + */ + public static boolean CodeValidate(String value) { + if (StringUtils.isEmpty(value)) { + return true; + } + // 长度验证 + if (value.length() != 18) { + return false; + } + // 登记管理部门+机构类别代码验证 + if (!REGIST_CODE.contains(value.substring(0, 2))) { + return false; + } + // 省级行政区划代码验证 + if (!PROVINCE_REGION_CODE.contains(value.substring(2, 4))) { + return false; + } + // 正则初验 + if (!Pattern.matches(REGEX, value)) { + return false; + } + + // 效验码校验 + char[] businessCodeArray = value.toCharArray(); +// char check= businessCodeArray[17]; + String check = Character.toString(businessCodeArray[17]); + int sum = 0; + for (int i = 0; i < 17; i++) { + char key = businessCodeArray[i]; + sum += (BASE_CODES.indexOf(key) * WEIGHT[i]); + } + int checkCode = 31 - sum % 31; + String s = Character.toString(BASE_CODE_ARRAY[checkCode % 31]); + //对比时将两个字符转为字符串,不区分大小写对比最后一位 + return s.equalsIgnoreCase(check); + } +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 68d8160..2946190 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -4,9 +4,9 @@ server: spring: datasource: driver-class-name: com.p6spy.engine.spy.P6SpyDriver - jdbc-url: jdbc:p6spy:mysql://192.168.0.66:3364/udi_cpt?allowMultiQueries=true&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true + jdbc-url: jdbc:p6spy:mysql://127.0.0.1:3306/udi_cpt?allowMultiQueries=true&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true username: root - password: Glxp@6066 + password: 123456 hikari: connection-timeout: 60000 maximum-pool-size: 20 @@ -76,8 +76,8 @@ logging: file_path: D:/udi/inUdiwms/udiwmsfile/ UDI_KEY: 6b137c66-6286-46c6-8efa-c2f5dd9237df -#UDI_SERVER_URL: https://www.udims.com/UDI_DL_Server_test -UDI_SERVER_URL: http://127.0.0.1:9994 +UDI_SERVER_URL: https://www.udims.com/UDI_DL_Server_test +#UDI_SERVER_URL: http://127.0.0.1:9994 SPMS_KEY: lCOdWCBKS6Kw45wdnnqUTELXyuSKnXEs back_file_path: D:/share/udisps/back/ diff --git a/src/main/resources/application-pro.yml b/src/main/resources/application-pro.yml index 828ddef..54dae5b 100644 --- a/src/main/resources/application-pro.yml +++ b/src/main/resources/application-pro.yml @@ -4,9 +4,9 @@ server: spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver - jdbc-url: jdbc:mysql://192.168.0.66:3364/udi_cpt?allowMultiQueries=true&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true + jdbc-url: jdbc:mysql://127.0.0.1:3306/udi_cpt?allowMultiQueries=true&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true username: root - password: Glxp@6066 + password: 123456 hikari: connection-timeout: 60000 maximum-pool-size: 60