feat:口门对接设备

koumen
dearLin 2026-04-13 16:49:57 +08:00
parent 74bcd9c715
commit 7c3f37a0cb
9 changed files with 533 additions and 51 deletions

View File

@ -5,7 +5,7 @@ application:
name: zcloud-gbs-primeport
version:
gateway: primeport
cn-name: 一级口门管理
cn-name: 口门门禁管理
spring:
application:
name: ${application.name}${application.version}

View File

@ -1,8 +1,8 @@
sdk:
server:
# app-key: bbab676d39e443cfacc037ee15fdad37
#港务局线上appKey
app-key: c7fbb137c1a0484c8b0cca8ac9937c55
#港务局线上appKey c7fbb137c1a0484c8b0cca8ac9937c55
client:
gateway:
url: ${common.gateway.network.http.external}

View File

@ -0,0 +1,294 @@
package com.zcloud.primeport.mjDevice;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONObject;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.zcloud.primeport.domain.enums.FileTypeEnum;
import com.zcloud.primeport.domain.enums.SaveTypeEnum;
import org.apache.commons.lang.StringUtils;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
import javax.net.ssl.SSLContext;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Configuration
public class OauthUtil {
// private final String publicKeyUrl = "https://192.168.42.194/evo-apigw/evo-oauth/1.0.0/oauth/public-key";
@Value("${icc.clientId}")
private String clientId;
@Value("${icc.publicKeyUrl}")
private String publicKeyUrl;
@Value("${icc.clientSecret}")
private String clientSecret;
@Value("${icc.username}")
private String username;
@Value("${icc.password}")
private String password;
@Value("${icc.url}")
private String iccUrl;
@Value("${icc.request.getGenerateIdUrl}")
private String iccGenerateIdUrl;
@Value("${icc.request.getGenerateIdListUrl}")
private String iccGenerateIdListUrl;
@Value("${icc.request.imgInspectUrl}")
private String iccImgInspectUrl;
@Value("${icc.request.getDepartmentIdUrl}")
private String iccDepartmentIdUrl;
@Value("${icc.request.getDepartmentIdListUrl}")
private String iccDepartmentIdListUrl;
/**
* RestTemplate
* @return RestTemplate
*/
public RestTemplate getRestTemplate() {
RestTemplate restTemplate = null;
try {
// 创建一个信任所有证书的 SSL 上下文
SSLContext sslContext = new SSLContextBuilder()
.loadTrustMaterial(null, (chain, authType) -> true)
.build();
// 创建一个忽略主机名验证的 SSL 连接套接字工厂
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
// 创建 HttpClient
CloseableHttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(sslsf)
.build();
// 创建 ClientHttpRequestFactory
ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
// 创建 RestTemplate 并设置请求工厂
restTemplate = new RestTemplate(requestFactory);
} catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return restTemplate;
}
/**
*
* @return
*/
public String getPublicKey() {
ResponseEntity<String> response = getRestTemplate().getForEntity(publicKeyUrl, String.class);
System.out.println("getPublicKey,response:"+response.getBody());
Map data = (Map) JSON.parseObject(response.getBody(), new TypeReference<Map<String, Object>>(){}).get("data");
String publicKey = data.get("publicKey").toString();
System.out.println("getPublicKey, publicKey:"+ publicKey);
return publicKey;
}
/**
* token
* @return token
* @date 2025-05-10
* @author hyx
*/
public String getToken() {
String token = null;
// 准备请求头
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "application/json");
//获取公钥
OauthUtil oauthUtil = new OauthUtil();
String publicKey = oauthUtil.getPublicKey();
if (StringUtils.isEmpty(publicKey)) {
System.out.println("get publicKey failed.");
} else {
try {
// 准备请求体
Map requestBody = new HashMap();
requestBody.put("grant_type", "password");
requestBody.put("username", username);
requestBody.put("password", RSAUtils.encrypt(password,publicKey));
requestBody.put("client_id", clientId);
requestBody.put("client_secret", clientSecret);
requestBody.put("public_key", publicKey);
// 创建 HttpEntity 对象
HttpEntity<String> entity = new HttpEntity<>(JSON.toJSONString(requestBody), headers);
System.out.println("getToken, request: " + JSON.toJSONString(requestBody));
// 调用 POST 接口
String url = iccUrl + "/evo-apigw/evo-oauth/1.0.0/oauth/extend/token";
ResponseEntity<String> response = getRestTemplate().exchange(url, HttpMethod.POST, entity, String.class);
// 输出响应内容
System.out.println("getToken, response: " + response.getBody());
Map responseBody = JSON.parseObject(response.getBody(), new TypeReference<Map<String, Object>>(){});
Map data = (Map) responseBody.get("data");
String code = (String) responseBody.get("code");
if(!code.equals("0")){
System.out.println("get token failed.");
}else {
String accessToken = data.get("access_token").toString();
String tokenType = data.get("token_type").toString();
token = tokenType + ' ' + accessToken;
System.out.println("getToken, token:" + token);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return token;
}
/**
* ID
* @return ID
* @throws Exception
* @date 2025-05-10
* @author hyx
*/
public Long getGenerateId() throws Exception {
String body = HttpRequest.get(iccUrl + iccGenerateIdUrl).header("Authorization", getToken()).execute().body();
JSONObject jsonObject = new JSONObject(body);
if ("true".equals(jsonObject.get("success").toString())) {
return new JSONObject(jsonObject.get("data")).getLong("id");
}else {
throw new RuntimeException("获取全局用户ID失败");
}
}
/**
* ID
* @param idCount ID
* @return List<Long>
* @date 2025-05-10
* @author hyx
*/
public List<Long> getGenerateIdList(Integer idCount){
String body = HttpRequest
.get(iccUrl + iccGenerateIdListUrl + idCount)
.header("Authorization", getToken())
.execute()
.body();
JSONObject jsonObject = new JSONObject(body);
if ("true".equals(jsonObject.get("success").toString())) {
return JSON.parseObject(new JSONObject(jsonObject.get("data")).get("idList").toString(), new TypeReference<List<Long>>(){});
}else {
throw new RuntimeException("获取全局用户ID失败");
}
}
/**
*
*
* @param map {@link FileTypeEnum}
* FileTypeEnum
* @return R
* @date 2025-05-10
* @author hyx
*/
public HashMap imgInspect(Map<String,Object> map) {
Map<String,Object> requestMap = new HashMap<>();
requestMap.put("saveType", SaveTypeEnum.SAVE_TYPE3.getCode());
requestMap.put("ossType",1);
if (FileTypeEnum.FILE_TYPE1.getCode().equals(map.get("fileType"))){
//文件格式
requestMap.put("file", map.get("file"));
requestMap.put("fileType", FileTypeEnum.FILE_TYPE1.getCode());
} else if (FileTypeEnum.FILE_TYPE2.getCode().equals(map.get("fileType"))) {
//url格式
requestMap.put("fileUrl", map.get("fileUrl"));
requestMap.put("fileType", FileTypeEnum.FILE_TYPE2.getCode());
}else if (FileTypeEnum.FILE_TYPE3.getCode().equals(map.get("fileType"))) {
//base64格式
requestMap.put("fileBase64", map.get("fileBase64"));
requestMap.put("fileType", FileTypeEnum.FILE_TYPE3.getCode());
}
String body = HttpRequest
.post(iccUrl + iccImgInspectUrl)
.contentType("multipart/form-data")
.header("Authorization", getToken())
.form(requestMap)
.execute()
.body();
JSONObject jsonObject = new JSONObject(body);
HashMap<String,Object> result = new HashMap<String,Object>();
if ("true".equals(jsonObject.get("success").toString())) {
if ("0".equals(jsonObject.getJSONObject("data").get("result"))){
result.put("fileUrl",jsonObject.getJSONObject("data").get("fileUrl").toString());
return result;
// return R.ok("图片质检成功").put("fileUrl",jsonObject.getJSONObject("data").get("fileUrl").toString());
}else {
return result;
// return R.error("图片质检失败");
}
}else {
return result;
// return R.error(jsonObject.get("errMsg").toString());
}
}
/**
* ID
* @return ID
* @throws Exception
* @author hyx
* @date 2025-05-12
*/
public Long getDepartmentId() throws Exception {
String body = HttpRequest.get(iccUrl + iccDepartmentIdUrl).header("Authorization", getToken()).execute().body();
JSONObject jsonObject = new JSONObject(body);
if ("true".equals(jsonObject.get("success").toString())) {
return new JSONObject(jsonObject.get("data")).getLong("id");
}else {
throw new RuntimeException("获取全局部门ID失败");
}
}
/**
* ID
* @param idCount ID
* @return List<Long>
* @author hyx
* @date 2025-05-12
*/
public List<Long> getDepartmentIdList(Integer idCount){
String body = HttpRequest
.get(iccUrl + iccGenerateIdListUrl + idCount)
.header("Authorization", getToken())
.execute()
.body();
JSONObject jsonObject = new JSONObject(body);
if ("true".equals(jsonObject.get("success").toString())) {
return JSON.parseObject(new JSONObject(jsonObject.get("data")).get("idList").toString(), new TypeReference<List<Long>>(){});
}else {
throw new RuntimeException("获取全局部门ID失败");
}
}
public static void main(String[] args) throws Exception {
System.out.println(RSAUtils.encrypt("3093164@qzs"
,"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCzId+G65rq/ZSSKjOtd8VwIPdgDsz08RZK5fG/d2ZeIhg2P44kWvtZSSp7RPR/3sJdx9w0PzdQg14Sn6jn+eGfJIQsbs8af9QIqDVlv7M7eeoEabzRgU+4SBxo8dvokLMnNw3PUiZFjhchyLctlERoeTZ5rH6qdz/DtvEi9ypzVQIDAQAB"));
}
}

View File

@ -0,0 +1,56 @@
package com.zcloud.primeport.mjDevice;
import javax.crypto.Cipher;
import java.security.KeyFactory;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.X509EncodedKeySpec;
import java.util.Arrays;
public class RSATest {
/**
* RSA
* @param password
* @param publicKey
* @return
* @throws Exception
*/
public static String encrypt(String password, String publicKey) throws Exception {
//base64编码的公钥
byte[] decoded = java.util.Base64.getDecoder().decode(publicKey);
RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));
//RSA加密
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, pubKey);
String outStr;
byte[] inputArray = password.getBytes("UTF-8");
int inputLength = inputArray.length;
// 最大加密字节数,超出最大字节数需要分组加密
int MAX_ENCRYPT_BLOCK = 117;
// 标识
int offSet = 0;
byte[] resultBytes = {};
byte[] cache = {};
while (inputLength - offSet > 0) {
if (inputLength - offSet > MAX_ENCRYPT_BLOCK) {
cache = cipher.doFinal(inputArray, offSet, MAX_ENCRYPT_BLOCK);
offSet += MAX_ENCRYPT_BLOCK;
} else {
cache = cipher.doFinal(inputArray, offSet, inputLength - offSet);
offSet = inputLength;
}
resultBytes = Arrays.copyOf(resultBytes, resultBytes.length + cache.length);
System.arraycopy(cache, 0, resultBytes, resultBytes.length - cache.length, cache.length);
}
outStr = java.util.Base64.getEncoder().encodeToString(resultBytes);
return outStr;
}
public static void main(String[] args) throws Exception {
String encrypt = RSATest.encrypt("Qzs@3093164"
, "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDaZPQ5y2K8hM3uPKQRDwykl7t3e8OxxWTcIRk7WtAHOrMEvYCVvabn7jZvvBAej0MZnuFcIsHLX7jxqU7" +
"//JjHczBKvCd26x5huIKn7J3gCYF90uG9jRVqKsaorFTz9T3Y25Fhl+bTm5pYh2FX6NIgl/DICc8025zbuSq+vJxIZQIDAQAB");
System.out.println(encrypt);
}
}

View File

@ -0,0 +1,122 @@
package com.zcloud.primeport.mjDevice;
import javax.crypto.Cipher;
import java.io.ByteArrayOutputStream;
import java.security.*;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* RSA//
* <p>
* BASE64<br/>
* 使使<br/>
*
* </p>
*
*/
public class RSAUtils {
/** */
/**
* RSA
*/
public static final String KEY_ALGORITHM = "RSA";
/** */
/**
*
*/
public static final String SIGNATURE_ALGORITHM = "MD5withRSA";
/** */
/**
* key
*/
private static final String PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDUoHAavCikaZxjlDM6Km8cX+ye78F4oF39AcEfnE1p2Yn9pJ9WFxYZ4Vkh6F8SKMi7k4nYsKceqB1RwG996SvHQ5C3pM3nbXCP4K15ad6QhN4a7lzlbLhiJcyIKszvvK8ncUDw8mVQ0j/2mwxv05yH6LN9OKU6Hzm1ninpWeE+awIDAQAB\n";
/** */
/**
* key
*/
private static final String PRIVATE_KEY = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBANSgcBq8KKRpnGOUMzoqbxxf7J7vwXigXf0BwR+cTWnZif2kn1YXFhnhWSHoXxIoyLuTidiwpx6oHVHAb33pK8dDkLekzedtcI/grXlp3pCE3hruXOVsuGIlzIgqzO+8rydxQPDyZVDSP/abDG/TnIfos304pTofObWeKelZ4T5rAgMBAAECgYEAt2Dvjn885h+Xm2JTlBTI40Xvw1uwFqLorK54qxSYx3OwySrTqOIcU5HA17ebVwQJq40hU9t3Jr+DGeDHx2X0NEJ0LXuDMzeWxUwUMbdxxM7OXS6Zuhy73C99DyAweLP9K1H2J/y1+eJ4Zx/0mTiAgCKJFNWAQBZwGl5Zu2zoHOECQQDw0UlrOUfloxK3hfVSWlfL7+onP+z/qa9bzemSg676sAJqA8d5ao8V532OBOtZxfPSlh4igC0lpY2vnCRHrwJZAkEA4ggpMS4o+rfFmNslNzI0m3VFDiLYmghYIqTLHtLYqAbY8QVfFd8bl920t5LQAlTsI3q9Spsu8y7AnAWmYydGYwJAN+tBMya/7TDqvbbbel4EGRUCuE59x/gtAhJUdHMjhI6uYNOz1BvMUffJDdtSkywGLBYztSsyUJWayvZk7khTMQJAALM7xW46LESjdQzAucILDaw4UYnkF94Mv9a41lia2TJkO6Ljn4K4aCkEpUjsIgW3UYjQy0ldxN0RNaqC0G3PtwJAFafiLzcls6qzyAlh5PqM5cJrs+Xa0rHR322/AlSyuxW6wRzUX/zSoorP34JCjRPT5DzUeHMVvr6S2BE8k/8XYg==";
/** */
/**
* RSA
*/
private static final int MAX_ENCRYPT_BLOCK = 117;
/** */
/**
* RSA
*/
private static final int MAX_DECRYPT_BLOCK = 128;
/** */
/**
* <p>
* ()
* </p>
*
* @return
* @throws Exception
*/
public static Map<String, Object> genKeyPair() throws Exception {
KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM);
keyPairGen.initialize(1024);
KeyPair keyPair = keyPairGen.generateKeyPair();
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
Map<String, Object> keyMap = new HashMap<String, Object>(2);
keyMap.put(PUBLIC_KEY, publicKey);
keyMap.put(PRIVATE_KEY, privateKey);
return keyMap;
}
/**
* RSA
* @param password
* @param publicKey
* @return
* @throws Exception
*/
public static String encrypt(String password, String publicKey) throws Exception {
//base64编码的公钥
byte[] decoded = java.util.Base64.getDecoder().decode(publicKey);
RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));
//RSA加密
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, pubKey);
String outStr;
byte[] inputArray = password.getBytes("UTF-8");
int inputLength = inputArray.length;
// 最大加密字节数,超出最大字节数需要分组加密
int MAX_ENCRYPT_BLOCK = 117;
// 标识
int offSet = 0;
byte[] resultBytes = {};
byte[] cache = {};
while (inputLength - offSet > 0) {
if (inputLength - offSet > MAX_ENCRYPT_BLOCK) {
cache = cipher.doFinal(inputArray, offSet, MAX_ENCRYPT_BLOCK);
offSet += MAX_ENCRYPT_BLOCK;
} else {
cache = cipher.doFinal(inputArray, offSet, inputLength - offSet);
offSet = inputLength;
}
resultBytes = Arrays.copyOf(resultBytes, resultBytes.length + cache.length);
System.arraycopy(cache, 0, resultBytes, resultBytes.length - cache.length, cache.length);
}
outStr = java.util.Base64.getEncoder().encodeToString(resultBytes);
return outStr;
}
}

View File

@ -0,0 +1,28 @@
package com.zcloud.primeport.domain.enums;
import lombok.Getter;
@Getter
public enum FileTypeEnum {
FILE_TYPE1(1,"File格式"),
FILE_TYPE2(2,"url格式"),
FILE_TYPE3(3,"base64格式")
;
private Integer code;
private String typeName;
FileTypeEnum(Integer code, String typeName) {
this.code = code;
this.typeName = typeName;
}
public FileTypeEnum setCode(Integer code) {
this.code = code;
return this;
}
public FileTypeEnum setTypeName(String typeName) {
this.typeName = typeName;
return this;
}
}

View File

@ -0,0 +1,28 @@
package com.zcloud.primeport.domain.enums;
import lombok.Getter;
@Getter
public enum SaveTypeEnum {
SAVE_TYPE1(1,"无论检测结果如何,保留图片"),
SAVE_TYPE2(2,"无论检测结果如何删除oss图片"),
SAVE_TYPE3(3,"检测通过保留,否则删除")
;
private Integer code;
private String typeName;
SaveTypeEnum(Integer code, String typeName) {
this.code = code;
this.typeName = typeName;
}
public SaveTypeEnum setCode(Integer code) {
this.code = code;
return this;
}
public SaveTypeEnum setTypeName(String typeName) {
this.typeName = typeName;
return this;
}
}

View File

@ -1,5 +1,6 @@
package com.zcloud.primeport.persistence.mapper;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -32,7 +33,7 @@ public interface VehicleApplyMapper extends BaseMapper<VehicleApplyDO> {
IPage<FgsVehicleCountDto> fgsCount(Page<Map<String, Object>> page, @Param("params") HashMap<String, String> qry);
VehicleApplyDO getInfoById(Long id);
@InterceptorIgnore(tenantLine = "true")
List<VehicleApplyDO> getAppCount(@Param("params") Map<String, Object> parmas);
}

View File

@ -153,54 +153,7 @@
tmp.audit_user_id,
COUNT( 1 ) wait_audit_count
FROM
(
SELECT
'one_level_car' type,
vap.vehicle_belong_type belong_type,
va.audit_user_id,
va.audit_user_name,
va.audit_status
FROM
vehicle_audit va
LEFT JOIN vehicle_apply vap ON va.vehicle_apply_id = vap.id
WHERE
va.delete_enum = 'FALSE'
AND va.audit_status = 1
AND vap.delete_enum = 'FALSE' UNION ALL
SELECT
'two_level_car' type,
caca.car_belong_type belong_type,
caca.audit_person_user_id audit_user_id,
caca.audit_person_user_name audit_user_name,
caca.audit_flag audit_status
FROM
closed_area_car_apply caca
WHERE
caca.delete_enum = 'FALSE'
AND caca.audit_flag = 1 UNION ALL
SELECT
'one_level_person' type,
xap.person_belong_type,
xap.audit_user_id,
xap.audit_user_name,
xap.audit_flag
FROM
xgf_apply_person xap
WHERE
xap.delete_enum = 'FALSE'
AND xap.audit_flag = 1 UNION ALL
SELECT
'two_level_person' type,
capa.person_belong_type,
capa.audit_person_user_id audit_user_id,
capa.audit_person_user_name audit_user_name,
capa.audit_flag
FROM
closed_area_person_apply capa
WHERE
capa.delete_enum = 'FALSE'
AND capa.audit_flag = 1
) tmp
vi_app_user_todo tmp
where tmp.audit_user_id = #{params.userId}
GROUP BY
tmp.type,