欧阳劲驰 1 месяц назад
Родитель
Сommit
c2a7c86823
58 измененных файлов с 1612 добавлено и 174 удалено
  1. 22 0
      custom-gateway-core/pom.xml
  2. 4 4
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/components/AccessKeyGenerator.java
  3. 14 5
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/SecurityConfig.java
  4. 67 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/constants/AccessMetadata.java
  5. 5 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/constants/TokenMetadata.java
  6. 101 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/domain/AccessResult.java
  7. 72 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/domain/AccessToken.java
  8. 4 5
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/domain/IntegrationKey.java
  9. 103 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/domain/TmpTokenData.java
  10. 4 4
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/domain/TokenData.java
  11. 6 2
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/domain/po/AccessKeys.java
  12. 1 1
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/domain/po/CustomerInfo.java
  13. 1 1
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/domain/po/CustomerMeterRead.java
  14. 1 1
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/domain/po/FunctionInfo.java
  15. 10 2
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/domain/po/PersonnelInfo.java
  16. 11 4
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/exception/GlobalSelfExceptionHandler.java
  17. 117 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/filter/AccessFilter.java
  18. 7 2
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/filter/TokenFilter.java
  19. 109 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/io/GeomMultiLineStringTypeHandlePg.java
  20. 120 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/io/GeomPointTypeHandlePg.java
  21. 108 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/io/GeomTypeHandlePg.java
  22. 107 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/io/StringListTypeHandle.java
  23. 2 2
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/mapper/primary/CustomerInfoMapper.java
  24. 2 2
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/mapper/primary/CustomerMeterReadMapper.java
  25. 2 2
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/mapper/primary/FunctionInfoMapper.java
  26. 10 2
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/mapper/primary/PersonnelInfoMapper.java
  27. 7 1
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/repository/embedded/AccessKeysRepository.java
  28. 8 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/service/AccessKeysService.java
  29. 2 2
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/service/CustomerInfoService.java
  30. 2 2
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/service/CustomerMeterReadService.java
  31. 2 2
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/service/FunctionInfoService.java
  32. 10 2
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/service/PersonnelInfoService.java
  33. 12 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/service/impl/AccessKeysServiceImpl.java
  34. 4 4
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/service/impl/CustomerInfoServiceImpl.java
  35. 4 4
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/service/impl/CustomerMeterReadServiceImpl.java
  36. 4 4
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/service/impl/FunctionInfoServiceImpl.java
  37. 16 4
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/service/impl/PersonnelInfoServiceImpl.java
  38. 108 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/utils/AccessUtil.java
  39. 18 3
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/utils/AesUtil.java
  40. 232 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/utils/GeomUtil.java
  41. 3 3
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/utils/HexUtil.java
  42. 13 37
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/utils/SecurityUtil.java
  43. 26 9
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/utils/TokenUtil.java
  44. 1 1
      custom-gateway-zydma/src/main/resources/mapper/CustomerInfoMapper.xml
  45. 1 1
      custom-gateway-zydma/src/main/resources/mapper/CustomerMeterReadMapper.xml
  46. 1 1
      custom-gateway-zydma/src/main/resources/mapper/FunctionInfoMapper.xml
  47. 56 7
      custom-gateway-zydma/src/main/resources/mapper/PersonnelInfoMapper.xml
  48. 0 11
      custom-gateway-zydma/pom.xml
  49. 1 1
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/components/DataCollector.java
  50. 9 20
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/components/InfoSynchronizer.java
  51. 1 1
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/constants/IotPlatformMetadata.java
  52. 1 1
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/constants/MiddlePlatformMetadata.java
  53. 37 3
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/controller/ApiController.java
  54. 4 4
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/controller/CustomerController.java
  55. 7 5
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/controller/UserController.java
  56. 1 1
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/domain/MiddlePlatformRole.java
  57. 1 1
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/domain/MiddlePlatformUser.java
  58. 10 0
      pom.xml

+ 22 - 0
custom-gateway-core/pom.xml

@@ -57,6 +57,28 @@
             <groupId>com.h2database</groupId>
             <artifactId>h2</artifactId>
         </dependency>
+        <!--jts-->
+        <dependency>
+            <groupId>org.locationtech.jts</groupId>
+            <artifactId>jts-core</artifactId>
+            <version>${jts.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.locationtech.jts.io</groupId>
+            <artifactId>jts-io-common</artifactId>
+            <version>${jts.version}</version>
+        </dependency>
+        <!--geotools-->
+        <dependency>
+            <groupId>org.geotools</groupId>
+            <artifactId>gt-shapefile</artifactId>
+            <version>${geotools.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.geotools</groupId>
+            <artifactId>gt-epsg-hsql</artifactId>
+            <version>${geotools.version}</version>
+        </dependency>
         <!--jjwt-->
         <dependency>
             <groupId>io.jsonwebtoken</groupId>

+ 4 - 4
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/components/AccessKeyGenerator.java

@@ -42,15 +42,15 @@ public class AccessKeyGenerator {
      *
      * @return 集成密钥
      */
-    public AccessKeys generateKey() {
+    public AccessKeys generateKey(String description) {
         //生成密钥
         byte[] access = accessKeyGenerator.generateKey();
         byte[] security = securityKeyGenerator.generateKey();
         //转换字符串
-        String accessKey = HexUtil.encodeHex(access).toUpperCase();
-        String securityKey = HexUtil.encodeHex(security).toUpperCase();
+        String accessKey = HexUtil.encode(access).toUpperCase();
+        String securityKey = HexUtil.encode(security).toUpperCase();
         //构建并保存
-        AccessKeys accessKeys = AccessKeys.of(accessKey, securityKey);
+        AccessKeys accessKeys = AccessKeys.of(accessKey, securityKey, description);
         service.save(accessKeys);
 
         return accessKeys;

+ 14 - 5
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/SecurityConfig.java

@@ -1,7 +1,10 @@
 package com.shkpr.service.customgateway.core.config;
 
 import com.shkpr.service.customgateway.core.components.AccessKeyGenerator;
+import com.shkpr.service.customgateway.core.constants.AccessMetadata;
 import com.shkpr.service.customgateway.core.constants.ResponseCode;
+import com.shkpr.service.customgateway.core.constants.TokenMetadata;
+import com.shkpr.service.customgateway.core.filter.AccessFilter;
 import com.shkpr.service.customgateway.core.filter.TokenFilter;
 import com.shkpr.service.customgateway.core.properties.GlobalProperties;
 import com.shkpr.service.customgateway.core.properties.SecurityProperties;
@@ -35,11 +38,14 @@ public class SecurityConfig {
     final
     SecurityProperties securityProperties;
     final
+    AccessKeysService accessKeysService;
+    final
     TokenUtil tokenUtil;
 
-    public SecurityConfig(GlobalProperties globalProperties, SecurityProperties securityProperties, TokenUtil tokenUtil) {
+    public SecurityConfig(GlobalProperties globalProperties, SecurityProperties securityProperties, AccessKeysService accessKeysService, TokenUtil tokenUtil) {
         this.globalProperties = globalProperties;
         this.securityProperties = securityProperties;
+        this.accessKeysService = accessKeysService;
         this.tokenUtil = tokenUtil;
     }
 
@@ -51,13 +57,16 @@ public class SecurityConfig {
         return http
                 //权限
                 .authorizeRequests()
-                .antMatchers(securityProperties.getPermitPattern().toArray(new String[0]))
-                .permitAll()
-                .anyRequest()
-                .authenticated()
+                //公开
+                .antMatchers(securityProperties.getPermitPattern().toArray(new String[0])).permitAll()
+                //api
+                .antMatchers(AccessMetadata.ANT_PATTERN).hasAuthority(AccessMetadata.AUTHORITY)
+                //通用
+                .anyRequest().hasAuthority(TokenMetadata.AUTHORITY)
                 .and()
                 //过滤器
                 .addFilterBefore(new TokenFilter(globalProperties, securityProperties, tokenUtil), AnonymousAuthenticationFilter.class)
+                .addFilterBefore(new AccessFilter(securityProperties, accessKeysService), TokenFilter.class)
                 //跨域防伪
                 .csrf().disable()
                 //frame

+ 67 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/constants/AccessMetadata.java

@@ -0,0 +1,67 @@
+package com.shkpr.service.customgateway.core.constants;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * 接入元数据
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+public interface AccessMetadata {
+    /**
+     * uri模式
+     */
+    String ANT_PATTERN = "/*/api/**";
+    /**
+     * 权限
+     */
+    String AUTHORITY = "api";
+
+    /**
+     * 响应码
+     */
+    @Getter
+    @AllArgsConstructor
+    enum ResponseCode {
+        SUCCESS(200, "ok"),
+        FAILURE(500, "Bad result,see the message/data for reason."),
+
+        ACCESS_KEY_MISS(2000, "访问密钥缺失"),
+        ACCESS_KEY_INVALID(2001, "访问密钥无效"),
+        ACCESS_KEY_DISABLED(2002, "访问密钥已禁用"),
+        TIMESTAMP_MISS(2003, "时间戳缺失"),
+        TIMESTAMP_EXPIRED(2004, "时间戳过期"),
+        TIMESTAMP_INVALID(2005, "时间戳格式错误"),
+        SIGNATURE_MISS(2006, "签名参数缺失"),
+        SIGNATURE_INVALID(2007, "签名验证失败"),
+        ;
+        /**
+         * 编码
+         */
+        private final int code;
+        /**
+         * 信息
+         */
+        private final String message;
+    }
+
+    /**
+     * 头
+     */
+    interface Headers {
+        /**
+         * 访问密钥
+         */
+        String ACCESS_KEY = "Access-Key";
+        /**
+         * 时间戳
+         */
+        String TIMESTAMP = "Timestamp";
+        /**
+         * 签名
+         */
+        String SIGNATURE = "Signature";
+    }
+}

+ 5 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/constants/TokenMetadata.java

@@ -8,6 +8,11 @@ package com.shkpr.service.customgateway.core.constants;
  */
 public interface TokenMetadata {
     /**
+     * 权限
+     */
+    String AUTHORITY = "common";
+
+    /**
      * 参数
      */
     interface Claims {

+ 101 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/domain/AccessResult.java

@@ -0,0 +1,101 @@
+package com.shkpr.service.customgateway.core.domain;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.apache.http.HttpStatus;
+
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+
+/**
+ * 接入响应
+ *
+ * @param <T> 数据类型
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class AccessResult<T> implements Result<T> {
+    /**
+     * 编码
+     */
+    private Integer code;
+    /**
+     * 信息
+     */
+    private String message;
+    /**
+     * 数据
+     */
+    private T data;
+    /**
+     * 时间戳
+     */
+    private long timestamp;
+
+    /**
+     * 成功
+     *
+     * @param data 数据
+     * @param <T>  数据类型
+     * @return 访问结果
+     */
+    public static <T> AccessResult<T> ok(T data) {
+        return new AccessResult<>(HttpStatus.SC_OK, "ok", data, LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
+    }
+
+
+    /**
+     * 失败
+     *
+     * @param message 消息
+     * @param <T>     数据类型
+     * @return 访问结果
+     */
+    public static <T> AccessResult<T> fail(String message) {
+        return new AccessResult<>(HttpStatus.SC_INTERNAL_SERVER_ERROR, message, null, LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
+    }
+
+    /**
+     * 获取状态码
+     *
+     * @return 状态码
+     */
+    @Override
+    public Integer getCode() {
+        return this.code;
+    }
+
+    /**
+     * 获取信息
+     *
+     * @return 信息
+     */
+    @Override
+    public String getMessage() {
+        return this.message;
+    }
+
+    /**
+     * 获取数据
+     *
+     * @return 数据
+     */
+    @Override
+    public T getData() {
+        return this.data;
+    }
+
+    /**
+     * 获取ok状态码
+     *
+     * @return ok状态码
+     */
+    @Override
+    public Boolean isOk() {
+        return HttpStatus.SC_OK == this.code;
+    }
+}

+ 72 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/domain/AccessToken.java

@@ -0,0 +1,72 @@
+package com.shkpr.service.customgateway.core.domain;
+
+import org.springframework.security.authentication.AbstractAuthenticationToken;
+import org.springframework.security.core.GrantedAuthority;
+
+import java.io.Serializable;
+import java.util.Collection;
+
+/**
+ * 接入令牌
+ *
+ * <p>principal:集成密钥</p>
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+public class AccessToken extends AbstractAuthenticationToken implements Serializable {
+    /**
+     * token信息
+     */
+    private final Object principal;
+    /**
+     * 密钥
+     */
+    private final Object credentials;
+
+    public AccessToken(Object principal, Object credentials) {
+        super(null);
+        this.principal = principal;
+        this.credentials = credentials;
+        setAuthenticated(false);
+    }
+
+    public AccessToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities) {
+        super(authorities);
+        this.principal = principal;
+        this.credentials = credentials;
+        super.setAuthenticated(true);
+    }
+
+    /**
+     * 未认证
+     *
+     * @param principal   token信息
+     * @param credentials 密码
+     * @return 未认证的token
+     */
+    public static AccessToken unauthenticated(Object principal, Object credentials) {
+        return new AccessToken(principal, credentials);
+    }
+
+    /**
+     * 已认证
+     *
+     * @param principal   token信息
+     * @param authorities 权限
+     * @return 已认证的token
+     */
+    public static AccessToken authenticated(Object principal, Collection<? extends GrantedAuthority> authorities) {
+        return new AccessToken(principal, null, authorities);
+    }
+
+    @Override
+    public Object getCredentials() {
+        return this.credentials;
+    }
+
+    @Override
+    public Object getPrincipal() {
+        return this.principal;
+    }
+}

+ 4 - 5
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/domain/IntegrationKey.java

@@ -26,9 +26,8 @@ public class IntegrationKey {
      * Secret
      */
     private String secretKey;
-
-    public IntegrationKey(String accessKey, String secretKey) {
-        this.accessKey = accessKey;
-        this.secretKey = secretKey;
-    }
+    /**
+     * 签名
+     */
+    private String signature;
 }

+ 103 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/domain/TmpTokenData.java

@@ -0,0 +1,103 @@
+package com.shkpr.service.customgateway.core.domain;
+
+import com.shkpr.service.customgateway.core.utils.AesUtil;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+
+/**
+ * 临时token数据
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class TmpTokenData {
+    /**
+     * 模式
+     */
+    private Integer model;
+    /**
+     * 账号
+     */
+    private String account;
+    /**
+     * Token字符串
+     */
+    private String token;
+    /**
+     * 签发时间(时间戳)
+     */
+    private Long issuedAt;
+
+    /**
+     * 从账号构建
+     *
+     * @param account 账号
+     * @return 未认证的token
+     */
+    public static TmpTokenData ofAccount(String account) {
+        return new TmpTokenData(0, account, null, LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
+    }
+
+    /**
+     * 从token构建
+     *
+     * @param token 秘文
+     * @return 未认证的token
+     */
+    public static TmpTokenData ofToken(String token) {
+        return new TmpTokenData(null, null, token, null);
+    }
+
+
+    /**
+     * 加密
+     *
+     */
+    public TmpTokenData encrypt(String key) {
+        final int randomLength = 8;
+
+        //构建明文
+        if (StringUtils.isAnyBlank(this.account, key)) return null;
+        String plainText = String.format("%s%d%s%s", this.model + "",
+                this.issuedAt / 1000, RandomStringUtils.randomAlphanumeric(randomLength), this.account);
+        //加密
+        this.token = AesUtil.encrypt(plainText, key);
+        return this;
+    }
+
+    /**
+     * 解密
+     *
+     */
+    public TmpTokenData decrypt(String key) {
+        final int modelLength = 1;
+        final int issuedAtLength = 10;
+        final int randomLength = 8;
+
+        //解密明文
+        if (StringUtils.isAnyBlank(this.token, key)) return null;
+        String plainText = AesUtil.decrypt(this.token, key);
+        if (StringUtils.isBlank(plainText)) return null;
+
+        //模式
+        int model = Integer.parseInt(StringUtils.substring(plainText, 0, modelLength));
+        //签发时间
+        long issuedAt = Long.parseLong(StringUtils.substring(plainText, modelLength, modelLength + issuedAtLength)) * 1000;
+        //账号
+        String account = StringUtils.substring(plainText, modelLength + issuedAtLength + randomLength);
+
+        this.model = model;
+        this.issuedAt = issuedAt;
+        this.account = account;
+        return this;
+    }
+}

+ 4 - 4
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/domain/TokenData.java

@@ -17,7 +17,7 @@ public class TokenData {
     /**
      * 用户id
      */
-    private String flagKey = "";
+    private String userId = "";
     /**
      * 角色id
      */
@@ -25,7 +25,7 @@ public class TokenData {
     /**
      * Token字符串
      */
-    private String tokenStr = "";
+    private String token = "";
     /**
      * 签发时间(时间戳)
      */
@@ -35,8 +35,8 @@ public class TokenData {
      */
     private long expiration = 0L;
 
-    public TokenData(String flagKey, String roleId) {
-        this.flagKey = flagKey;
+    public TokenData(String userId, String roleId) {
+        this.userId = userId;
         this.roleId = roleId;
     }
 }

+ 6 - 2
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/domain/po/AccessKeys.java

@@ -30,8 +30,12 @@ public class AccessKeys {
      * 认证密钥
      */
     private String securityKey;
+    /**
+     * 描述
+     */
+    private String description;
 
-    public static AccessKeys of(String accessKey, String securityKey) {
-        return new AccessKeys(null, accessKey, securityKey);
+    public static AccessKeys of(String accessKey, String securityKey, String description) {
+        return new AccessKeys(null, accessKey, securityKey, description);
     }
 }

+ 1 - 1
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/domain/po/CustomerInfo.java

@@ -1,4 +1,4 @@
-package com.shkpr.service.customgateway.zydma.domain.po;
+package com.shkpr.service.customgateway.core.domain.po;
 
 import com.shkpr.service.customgateway.core.annotation.ExcelMapping;
 import lombok.Data;

+ 1 - 1
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/domain/po/CustomerMeterRead.java

@@ -1,4 +1,4 @@
-package com.shkpr.service.customgateway.zydma.domain.po;
+package com.shkpr.service.customgateway.core.domain.po;
 
 import com.shkpr.service.customgateway.core.annotation.ExcelMapping;
 import com.shkpr.service.customgateway.core.constants.CustomerReadType;

+ 1 - 1
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/domain/po/FunctionInfo.java

@@ -1,4 +1,4 @@
-package com.shkpr.service.customgateway.zydma.domain.po;
+package com.shkpr.service.customgateway.core.domain.po;
 
 import lombok.Data;
 

+ 10 - 2
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/domain/po/PersonnelInfo.java

@@ -1,8 +1,10 @@
-package com.shkpr.service.customgateway.zydma.domain.po;
+package com.shkpr.service.customgateway.core.domain.po;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import lombok.Data;
 
 import java.time.LocalDateTime;
+import java.util.List;
 
 /**
  * 用户信息表
@@ -15,6 +17,7 @@ public class PersonnelInfo {
     /**
      * 用户uid
      */
+    @JsonIgnore
     private String uid;
     /**
      * 登录账号
@@ -59,7 +62,7 @@ public class PersonnelInfo {
     /**
      * 用户职位uid
      */
-    private String postId;
+    private List<String> postId;
     /**
      * 当前状态:-1 -- 注销; 0 -- 禁用;1 -- 启用
      */
@@ -67,21 +70,26 @@ public class PersonnelInfo {
     /**
      * 参数1
      */
+    @JsonIgnore
     private String param1;
     /**
      * 参数2
      */
+    @JsonIgnore
     private String param2;
     /**
      * 创建时间
      */
+    @JsonIgnore
     private LocalDateTime createTime;
     /**
      * 更新时间
      */
+    @JsonIgnore
     private LocalDateTime updateTime;
     /**
      * 所属组织机构
      */
+    @JsonIgnore
     private String org;
 }

+ 11 - 4
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/exception/GlobalSelfExceptionHandler.java

@@ -9,7 +9,7 @@ import org.springframework.beans.ConversionNotSupportedException;
 import org.springframework.beans.TypeMismatchException;
 import org.springframework.http.converter.HttpMessageNotReadableException;
 import org.springframework.http.converter.HttpMessageNotWritableException;
-import org.springframework.stereotype.Component;
+import org.springframework.security.access.AccessDeniedException;
 import org.springframework.web.HttpMediaTypeNotAcceptableException;
 import org.springframework.web.HttpRequestMethodNotSupportedException;
 import org.springframework.web.bind.MissingServletRequestParameterException;
@@ -40,11 +40,10 @@ import java.io.IOException;
  *
  */
 @ControllerAdvice
-@Component
 public class GlobalSelfExceptionHandler {
 
     public static ResultResponse<String> createResParam(String strCode, String strMsg) {
-        ResultResponse<String> resResult = new ResultResponse<String>();
+        ResultResponse<String> resResult = new ResultResponse<>();
         resResult.setTimestamp(System.currentTimeMillis());
         resResult.setRescode(strCode);
         resResult.setResmsg(strMsg);
@@ -53,7 +52,7 @@ public class GlobalSelfExceptionHandler {
     }
 
     public static ResultResponse<String> createResParam(String strCode, String strMsg, String strData) {
-        ResultResponse<String> resResult = new ResultResponse<String>();
+        ResultResponse<String> resResult = new ResultResponse<>();
         resResult.setTimestamp(System.currentTimeMillis());
         resResult.setRescode(strCode);
         resResult.setResmsg(strMsg);
@@ -72,6 +71,14 @@ public class GlobalSelfExceptionHandler {
         return createResParam(ex.getStrErrorCode(), ex.getMessage(), ex.getStrErrorData());
     }
 
+    //访问异常
+    @ExceptionHandler(AccessDeniedException.class)
+    @ResponseBody
+    public ResultResponse<String> accessDeniedExceptionHandler(RuntimeException runtimeException) {
+        LogPrintMgr.getInstance().printExceptionObject(LogLevelFlag.LOG_ERROR, runtimeException);
+        return createResParam(ResponseCode.STATUS_ACCESS_DENY.getCode() + "", ResponseCode.STATUS_ACCESS_DENY.getMessage());
+    }
+
     //运行时异常
     @ExceptionHandler(RuntimeException.class)
     @ResponseBody

+ 117 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/filter/AccessFilter.java

@@ -0,0 +1,117 @@
+package com.shkpr.service.customgateway.core.filter;
+
+import com.shkpr.service.customgateway.core.constants.AccessMetadata;
+import com.shkpr.service.customgateway.core.constants.AccessMetadata.ResponseCode;
+import com.shkpr.service.customgateway.core.domain.AccessToken;
+import com.shkpr.service.customgateway.core.domain.po.AccessKeys;
+import com.shkpr.service.customgateway.core.properties.SecurityProperties;
+import com.shkpr.service.customgateway.core.service.AccessKeysService;
+import com.shkpr.service.customgateway.core.utils.AccessUtil;
+import com.shkpr.service.customgateway.core.utils.SecurityUtil;
+import lombok.NonNull;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.math.NumberUtils;
+import org.springframework.http.HttpMethod;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
+import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
+import java.util.Collections;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * 接入过滤器
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+public class AccessFilter extends OncePerRequestFilter {
+    private final SecurityProperties securityProperties;
+    private final AccessKeysService accessKeysService;
+
+    public AccessFilter(SecurityProperties securityProperties, AccessKeysService accessKeysService) {
+        this.securityProperties = securityProperties;
+        this.accessKeysService = accessKeysService;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull FilterChain chain) throws IOException, ServletException {
+        //忽略非get请求
+        if (!request.getMethod().equals(HttpMethod.GET.name())) return;
+        //如果忽略列表包含该url,则直接放行
+        if (securityProperties.getPermitPattern().stream()
+                .anyMatch(s -> new AntPathRequestMatcher(s).matches(request))) {
+            chain.doFilter(request, response);
+            return;
+        }
+        //已登陆,则直接放行
+        if (SecurityUtil.isAuthenticated()) {
+            chain.doFilter(request, response);
+            return;
+        }
+        //匹配接入请求
+        if (!new AntPathRequestMatcher(AccessMetadata.ANT_PATTERN).matches(request)) {
+            chain.doFilter(request, response);
+            return;
+        }
+
+        //请求头访问密钥
+        String accessKey = request.getHeader(AccessMetadata.Headers.ACCESS_KEY);
+        if (StringUtils.isBlank(accessKey)) {
+            AccessUtil.writeResponseCode(response, ResponseCode.ACCESS_KEY_MISS);
+            return;
+        }
+        //访问密钥
+        AccessKeys accessKeys = accessKeysService.findByAccessKey(accessKey);
+        if (accessKeys == null || accessKeys.getSecurityKey() == null) {
+            AccessUtil.writeResponseCode(response, ResponseCode.ACCESS_KEY_INVALID);
+            return;
+        }
+        //请求头时间戳
+        String timestampStr = request.getHeader(AccessMetadata.Headers.TIMESTAMP);
+        if (StringUtils.isBlank(timestampStr)) {
+            AccessUtil.writeResponseCode(response, ResponseCode.TIMESTAMP_MISS);
+            return;
+        }
+        if (!NumberUtils.isDigits(timestampStr)) {
+            AccessUtil.writeResponseCode(response, ResponseCode.TIMESTAMP_INVALID);
+            return;
+        }
+        //时间戳
+        long timestamp = Long.parseLong(timestampStr);
+        if (ChronoUnit.MINUTES.between(Instant.ofEpochMilli(timestamp), Instant.now()) > 5 ||
+                ChronoUnit.MINUTES.between(Instant.ofEpochMilli(timestamp), Instant.now()) < -1) {
+            AccessUtil.writeResponseCode(response, ResponseCode.TIMESTAMP_EXPIRED);
+            return;
+        }
+        //签名
+        String signature = request.getHeader(AccessMetadata.Headers.SIGNATURE);
+        if (StringUtils.isBlank(signature)) {
+            AccessUtil.writeResponseCode(response, ResponseCode.SIGNATURE_MISS);
+            return;
+        }
+        //参数
+        Map<String, String> params = request.getParameterMap().entrySet().stream()
+                .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue()[0]));
+        //签名验证
+        boolean matched = AccessUtil.matchesSignature(params, timestamp, accessKeys.getSecurityKey(), signature);
+        if (!matched) {
+            AccessUtil.writeResponseCode(response, ResponseCode.SIGNATURE_INVALID);
+            return;
+        }
+        //签发token
+        SecurityUtil.setAuthentication(AccessToken.authenticated(accessKey, Collections.singletonList(new SimpleGrantedAuthority(AccessMetadata.AUTHORITY))));
+        chain.doFilter(request, response);
+    }
+}

+ 7 - 2
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/filter/TokenFilter.java

@@ -14,7 +14,7 @@ import org.springframework.security.authentication.AccountExpiredException;
 import org.springframework.security.authentication.BadCredentialsException;
 import org.springframework.security.authentication.CredentialsExpiredException;
 import org.springframework.security.core.Authentication;
-import org.springframework.util.AntPathMatcher;
+import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
 import org.springframework.web.filter.OncePerRequestFilter;
 
 import javax.servlet.FilterChain;
@@ -47,7 +47,12 @@ public class TokenFilter extends OncePerRequestFilter {
     protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull FilterChain chain) throws IOException, ServletException {
         //如果忽略列表包含该url,则直接放行
         if (securityProperties.getPermitPattern().stream()
-                .anyMatch(s -> new AntPathMatcher().match(String.format("%s%s", request.getContextPath(), s), request.getRequestURI()))) {
+                .anyMatch(s -> new AntPathRequestMatcher(s).matches(request))) {
+            chain.doFilter(request, response);
+            return;
+        }
+        //已登陆,则直接放行
+        if (SecurityUtil.isAuthenticated()) {
             chain.doFilter(request, response);
             return;
         }

+ 109 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/io/GeomMultiLineStringTypeHandlePg.java

@@ -0,0 +1,109 @@
+package com.shkpr.service.customgateway.core.io;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.shkpr.service.customgateway.core.utils.GeomUtil;
+import org.apache.ibatis.type.BaseTypeHandler;
+import org.apache.ibatis.type.JdbcType;
+import org.apache.ibatis.type.MappedJdbcTypes;
+import org.apache.ibatis.type.MappedTypes;
+import org.locationtech.jts.geom.MultiLineString;
+
+import java.io.IOException;
+import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * 地理多线类型处理器
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@MappedTypes({MultiLineString.class})
+@MappedJdbcTypes(JdbcType.VARCHAR)
+public class GeomMultiLineStringTypeHandlePg extends BaseTypeHandler<MultiLineString> {
+    private static final ObjectMapper objectMapper = new ObjectMapper();
+
+    /**
+     * 解析
+     *
+     * @param lineStr 值
+     * @return 多线
+     * @throws SQLException sql异常
+     */
+    public static MultiLineString parseString(String lineStr) throws SQLException {
+        //非空校验
+        if (lineStr == null || lineStr.isEmpty()) return null;
+        try {
+            //序列化
+            double[][][] array = objectMapper.readValue(lineStr, double[][][].class);
+            //构建线
+            return GeomUtil.ofArray(array);
+        } catch (IOException e) {
+            throw new SQLException("多线格式无效: " + lineStr);
+        }
+    }
+
+    /**
+     * 从多线对象转数据库字符串
+     *
+     * @param multiLineString 多线
+     * @return 字符串
+     * @throws SQLException sql异常
+     */
+    public static String toString(MultiLineString multiLineString) throws SQLException {
+        if (multiLineString == null) return null;
+        try {
+            //转数组
+            double[][][] array = GeomUtil.toArray(multiLineString);
+            //反序列化
+            return objectMapper.writeValueAsString(array);
+        } catch (IOException e) {
+            throw new SQLException("多线格式无效: " + multiLineString);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setNonNullParameter(PreparedStatement ps, int i, MultiLineString multiLineString, JdbcType jdbcType)
+            throws SQLException {
+        if (multiLineString != null && multiLineString.getCoordinates() != null) {
+            //将点序列化化为字符串
+            String lineStr = toString(multiLineString);
+            if (lineStr != null) {
+                ps.setString(i, lineStr);
+                return;
+            }
+        }
+        //处理空值
+        ps.setNull(i, JdbcType.VARCHAR.TYPE_CODE);
+
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public MultiLineString getNullableResult(ResultSet rs, String columnName) throws SQLException {
+        return rs.wasNull() ? null : parseString(rs.getString(columnName));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public MultiLineString getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
+        return rs.wasNull() ? null : parseString(rs.getString(columnIndex));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public MultiLineString getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
+        return cs.wasNull() ? null : parseString(cs.getString(columnIndex));
+    }
+}

+ 120 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/io/GeomPointTypeHandlePg.java

@@ -0,0 +1,120 @@
+package com.shkpr.service.customgateway.core.io;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.shkpr.service.customgateway.core.utils.GeomUtil;
+import org.apache.ibatis.type.BaseTypeHandler;
+import org.apache.ibatis.type.JdbcType;
+import org.apache.ibatis.type.MappedJdbcTypes;
+import org.apache.ibatis.type.MappedTypes;
+import org.locationtech.jts.geom.Coordinate;
+import org.locationtech.jts.geom.GeometryFactory;
+import org.locationtech.jts.geom.Point;
+import org.locationtech.jts.geom.PrecisionModel;
+
+import java.io.IOException;
+import java.sql.*;
+
+/**
+ * 地理点类型处理器
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@MappedTypes({Point.class})
+@MappedJdbcTypes(JdbcType.VARCHAR)
+public class GeomPointTypeHandlePg extends BaseTypeHandler<Point> {
+    private static final GeometryFactory factory = new GeometryFactory(new PrecisionModel(), 4490);
+    private static final ObjectMapper objectMapper = new ObjectMapper();
+
+    /**
+     * 从数据库字符串解析为Point对象
+     *
+     * @param pointStr 值
+     * @return 点
+     * @throws SQLException sql异常
+     */
+    public static Point parseString(String pointStr) throws SQLException {
+        //非空校验
+        if (pointStr == null || pointStr.isEmpty()) return null;
+        try {
+            //序列化
+            double[] array = objectMapper.readValue(pointStr, double[].class);
+            //判断格式
+            if (array.length == 2) {
+                //转坐标
+                Coordinate coordinate = GeomUtil.ofArray(array);
+                //构建点
+                return factory.createPoint(coordinate);
+            }
+        } catch (IOException e) {
+            throw new SQLException("点格式无效: " + pointStr);
+        }
+        throw new SQLException("点格式无效: " + pointStr);
+    }
+
+    /**
+     * 从Point对象转数据库字符串
+     *
+     * @param point 点
+     * @return 字符串
+     * @throws SQLException sql异常
+     */
+    public static String toString(Point point) throws SQLException {
+        if (point == null) return null;
+        //获取坐标
+        Coordinate coordinate = point.getCoordinate();
+        if (coordinate == null) return null;
+        try {
+            //转数组
+            double[] array = GeomUtil.toArray(coordinate);
+            //反序列化
+            return objectMapper.writeValueAsString(array);
+        } catch (IOException e) {
+            throw new SQLException("点格式无效: " + point);
+        }
+    }
+
+    /**
+     * 将Java类型Point写入数据库
+     */
+    @Override
+    public void setNonNullParameter(PreparedStatement ps, int i, Point point, JdbcType jdbcType) throws SQLException {
+        if (point != null && point.getCoordinate() != null) {
+            //将点序列化化为字符串
+            String pointStr = toString(point);
+            if (pointStr != null) {
+                ps.setString(i, pointStr);
+                return;
+            }
+        }
+        //处理空值
+        ps.setNull(i, Types.VARCHAR);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Point getNullableResult(ResultSet rs, String columnName) throws SQLException {
+        String pointStr = rs.getString(columnName);
+        return rs.wasNull() ? null : parseString(pointStr);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Point getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
+        String pointStr = rs.getString(columnIndex);
+        return rs.wasNull() ? null : parseString(pointStr);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Point getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
+        String pointStr = cs.getString(columnIndex);
+        return cs.wasNull() ? null : parseString(pointStr);
+    }
+}

+ 108 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/io/GeomTypeHandlePg.java

@@ -0,0 +1,108 @@
+package com.shkpr.service.customgateway.core.io;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.ibatis.type.BaseTypeHandler;
+import org.apache.ibatis.type.JdbcType;
+import org.apache.ibatis.type.MappedJdbcTypes;
+import org.apache.ibatis.type.MappedTypes;
+import org.locationtech.jts.geom.Geometry;
+import org.locationtech.jts.geom.MultiLineString;
+import org.locationtech.jts.geom.Point;
+
+import java.io.IOException;
+import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * 地理类型处理器
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@MappedTypes({Geometry.class})
+@MappedJdbcTypes(JdbcType.VARCHAR)
+public class GeomTypeHandlePg extends BaseTypeHandler<Geometry> {
+    private static final ObjectMapper objectMapper = new ObjectMapper();
+
+    /**
+     * 解析
+     *
+     * @param geomStr 值
+     * @return 地理对象
+     * @throws SQLException sql异常
+     */
+    public static Geometry parseGeom(String geomStr) throws SQLException {
+        //非空校验
+        if (geomStr == null || geomStr.isEmpty()) return null;
+        try {
+            JsonNode jsonNode = objectMapper.readTree(geomStr);
+            if (jsonNode.isArray() && !jsonNode.isEmpty()) {
+                //点处理
+                if (jsonNode.get(0).isNumber() && jsonNode.get(1).isNumber()) {
+                    return GeomPointTypeHandlePg.parseString(geomStr);
+                }
+                //线处理
+                else if (jsonNode.get(0).isArray()) {
+                    return GeomMultiLineStringTypeHandlePg.parseString(geomStr);
+                }
+            }
+
+        } catch (IOException e) {
+            throw new SQLException("地理数据格式无效: " + geomStr);
+        }
+        throw new SQLException("地理数据格式无效: " + geomStr);
+    }
+
+    /**
+     * 从Geometry对象转数据库字符串
+     *
+     * @param geometry 点
+     * @return 字符串
+     * @throws SQLException sql异常
+     */
+    public static String toGeomString(Geometry geometry) throws SQLException {
+        if (geometry instanceof Point) {
+            Point point = (Point) geometry;
+            //转字符串
+            return GeomPointTypeHandlePg.toString(point);
+
+        } else if (geometry instanceof MultiLineString) {
+            MultiLineString multiLineString = (MultiLineString) geometry;
+            //转字符串
+            return GeomMultiLineStringTypeHandlePg.toString(multiLineString);
+        }
+        return null;
+    }
+
+    @Override
+    public void setNonNullParameter(PreparedStatement ps, int i, Geometry geometry, JdbcType jdbcType) throws SQLException {
+        if (geometry != null && geometry.getCoordinate() != null) {
+            //将geom序列化化为字符串
+            String geomString = toGeomString(geometry);
+            if (geomString != null) {
+                ps.setString(i, geomString);
+                return;
+            }
+        }
+        //处理空值
+        ps.setNull(i, JdbcType.VARCHAR.TYPE_CODE);
+    }
+
+    @Override
+    public Geometry getNullableResult(ResultSet rs, String columnName) throws SQLException {
+        return rs.wasNull() ? null : parseGeom(rs.getString(columnName));
+    }
+
+    @Override
+    public Geometry getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
+        return rs.wasNull() ? null : parseGeom(rs.getString(columnIndex));
+    }
+
+    @Override
+    public Geometry getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
+        return cs.wasNull() ? null : parseGeom(cs.getString(columnIndex));
+    }
+}

+ 107 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/io/StringListTypeHandle.java

@@ -0,0 +1,107 @@
+package com.shkpr.service.customgateway.core.io;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.ibatis.type.BaseTypeHandler;
+import org.apache.ibatis.type.JdbcType;
+import org.apache.ibatis.type.MappedJdbcTypes;
+import org.apache.ibatis.type.MappedTypes;
+
+import java.io.IOException;
+import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+
+/**
+ * 字符串数组类型处理器
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@MappedTypes({List.class})
+@MappedJdbcTypes(JdbcType.VARCHAR)
+public class StringListTypeHandle extends BaseTypeHandler<List<String>> {
+    private static final ObjectMapper objectMapper = new ObjectMapper();
+
+    /**
+     * 解析字符串
+     *
+     * @param str 字符串
+     * @return 数据
+     * @throws SQLException sql异常
+     */
+    public static List<String> parseString(String str) throws SQLException {
+        //非空校验
+        if (StringUtils.isBlank(str)) return null;
+        try {
+            //序列化
+            return objectMapper.readValue(str, new TypeReference<List<String>>() {
+            });
+        } catch (IOException e) {
+            throw new SQLException("字符串数组格式无效: " + str);
+        }
+    }
+
+    /**
+     * 转字符串
+     *
+     * @param data 数据
+     * @return 字符串
+     * @throws SQLException sql异常
+     */
+    public static String toString(List<String> data) throws SQLException {
+        if (data == null) return null;
+        try {
+            //反序列化
+            return objectMapper.writeValueAsString(data);
+        } catch (IOException e) {
+            throw new SQLException("字符串数组格式无效: " + data);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setNonNullParameter(PreparedStatement ps, int i, List<String> data, JdbcType jdbcType)
+            throws SQLException {
+        if (data != null) {
+            //列化化为字符串
+            String string = toString(data);
+            if (StringUtils.isNotBlank(string)) {
+                ps.setString(i, string);
+                return;
+            }
+        }
+        //处理空值
+        ps.setNull(i, JdbcType.VARCHAR.TYPE_CODE);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public List<String> getNullableResult(ResultSet rs, String columnName) throws SQLException {
+        return rs.wasNull() ? null : parseString(rs.getString(columnName));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public List<String> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
+        return rs.wasNull() ? null : parseString(rs.getString(columnIndex));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public List<String> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
+        return cs.wasNull() ? null : parseString(cs.getString(columnIndex));
+    }
+}
+

+ 2 - 2
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/mapper/primary/CustomerInfoMapper.java

@@ -1,6 +1,6 @@
-package com.shkpr.service.customgateway.zydma.mapper.primary;
+package com.shkpr.service.customgateway.core.mapper.primary;
 
-import com.shkpr.service.customgateway.zydma.domain.po.CustomerInfo;
+import com.shkpr.service.customgateway.core.domain.po.CustomerInfo;
 import org.apache.ibatis.annotations.Mapper;
 
 /**

+ 2 - 2
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/mapper/primary/CustomerMeterReadMapper.java

@@ -1,6 +1,6 @@
-package com.shkpr.service.customgateway.zydma.mapper.primary;
+package com.shkpr.service.customgateway.core.mapper.primary;
 
-import com.shkpr.service.customgateway.zydma.domain.po.CustomerMeterRead;
+import com.shkpr.service.customgateway.core.domain.po.CustomerMeterRead;
 import org.apache.ibatis.annotations.Mapper;
 
 /**

+ 2 - 2
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/mapper/primary/FunctionInfoMapper.java

@@ -1,6 +1,6 @@
-package com.shkpr.service.customgateway.zydma.mapper.primary;
+package com.shkpr.service.customgateway.core.mapper.primary;
 
-import com.shkpr.service.customgateway.zydma.domain.po.FunctionInfo;
+import com.shkpr.service.customgateway.core.domain.po.FunctionInfo;
 import org.apache.ibatis.annotations.Mapper;
 
 /**

+ 10 - 2
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/mapper/primary/PersonnelInfoMapper.java

@@ -1,6 +1,6 @@
-package com.shkpr.service.customgateway.zydma.mapper.primary;
+package com.shkpr.service.customgateway.core.mapper.primary;
 
-import com.shkpr.service.customgateway.zydma.domain.po.PersonnelInfo;
+import com.shkpr.service.customgateway.core.domain.po.PersonnelInfo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -23,6 +23,14 @@ public interface PersonnelInfoMapper {
     PersonnelInfo findBydUid(@Param("uid") String uid);
 
     /**
+     * 根据账号查询
+     *
+     * @param account 账号
+     * @return 实体
+     */
+    PersonnelInfo findByAccount(@Param("account") String account);
+
+    /**
      * 查询已存在的id
      *
      * @param ids 查询的ids

+ 7 - 1
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/repository/embedded/AccessKeysRepository.java

@@ -12,5 +12,11 @@ import org.springframework.stereotype.Repository;
  */
 @Repository
 public interface AccessKeysRepository extends CrudRepository<AccessKeys, Long> {
-
+    /**
+     * 根据访问密钥查询
+     *
+     * @param accessKey 访问密钥
+     * @return 实体
+     */
+    AccessKeys findByAccessKey(String accessKey);
 }

+ 8 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/service/AccessKeysService.java

@@ -16,4 +16,12 @@ public interface AccessKeysService {
      * @return 保存状态
      */
     Boolean save(AccessKeys accessKeys);
+
+    /**
+     * 根据访问密钥查询
+     *
+     * @param accessKey 访问密钥
+     * @return 密钥
+     */
+    AccessKeys findByAccessKey(String accessKey);
 }

+ 2 - 2
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/service/CustomerInfoService.java

@@ -1,6 +1,6 @@
-package com.shkpr.service.customgateway.zydma.service;
+package com.shkpr.service.customgateway.core.service;
 
-import com.shkpr.service.customgateway.zydma.domain.po.CustomerInfo;
+import com.shkpr.service.customgateway.core.domain.po.CustomerInfo;
 
 import java.util.List;
 

+ 2 - 2
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/service/CustomerMeterReadService.java

@@ -1,6 +1,6 @@
-package com.shkpr.service.customgateway.zydma.service;
+package com.shkpr.service.customgateway.core.service;
 
-import com.shkpr.service.customgateway.zydma.domain.po.CustomerMeterRead;
+import com.shkpr.service.customgateway.core.domain.po.CustomerMeterRead;
 
 import java.util.List;
 

+ 2 - 2
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/service/FunctionInfoService.java

@@ -1,7 +1,7 @@
-package com.shkpr.service.customgateway.zydma.service;
+package com.shkpr.service.customgateway.core.service;
 
 
-import com.shkpr.service.customgateway.zydma.domain.po.FunctionInfo;
+import com.shkpr.service.customgateway.core.domain.po.FunctionInfo;
 
 import java.util.List;
 

+ 10 - 2
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/service/PersonnelInfoService.java

@@ -1,6 +1,6 @@
-package com.shkpr.service.customgateway.zydma.service;
+package com.shkpr.service.customgateway.core.service;
 
-import com.shkpr.service.customgateway.zydma.domain.po.PersonnelInfo;
+import com.shkpr.service.customgateway.core.domain.po.PersonnelInfo;
 
 import java.util.List;
 
@@ -26,4 +26,12 @@ public interface PersonnelInfoService {
      * @return 用户
      */
     PersonnelInfo findByUserId(String userId);
+
+    /**
+     * 根据账号查询
+     *
+     * @param account 账号
+     * @return 用户
+     */
+    PersonnelInfo findByAccount(String account);
 }

+ 12 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/service/impl/AccessKeysServiceImpl.java

@@ -26,7 +26,19 @@ public class AccessKeysServiceImpl implements AccessKeysService {
      * @param accessKeys 服务密钥
      * @return 保存状态
      */
+    @Override
     public Boolean save(AccessKeys accessKeys) {
         return repository.save(accessKeys).getId() != null;
     }
+
+    /**
+     * 根据访问密钥查询
+     *
+     * @param accessKey 访问密钥
+     * @return 密钥
+     */
+    @Override
+    public AccessKeys findByAccessKey(String accessKey) {
+        return repository.findByAccessKey(accessKey);
+    }
 }

+ 4 - 4
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/service/impl/CustomerInfoServiceImpl.java

@@ -1,12 +1,12 @@
-package com.shkpr.service.customgateway.zydma.service.impl;
+package com.shkpr.service.customgateway.core.service.impl;
 
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.customgateway.core.constants.DataSourceNames;
 import com.shkpr.service.customgateway.core.constants.LogFlagBusiType;
-import com.shkpr.service.customgateway.zydma.domain.po.CustomerInfo;
-import com.shkpr.service.customgateway.zydma.mapper.primary.CustomerInfoMapper;
-import com.shkpr.service.customgateway.zydma.service.CustomerInfoService;
+import com.shkpr.service.customgateway.core.domain.po.CustomerInfo;
+import com.shkpr.service.customgateway.core.mapper.primary.CustomerInfoMapper;
+import com.shkpr.service.customgateway.core.service.CustomerInfoService;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.ibatis.session.ExecutorType;
 import org.apache.ibatis.session.SqlSession;

+ 4 - 4
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/service/impl/CustomerMeterReadServiceImpl.java

@@ -1,12 +1,12 @@
-package com.shkpr.service.customgateway.zydma.service.impl;
+package com.shkpr.service.customgateway.core.service.impl;
 
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.customgateway.core.constants.DataSourceNames;
 import com.shkpr.service.customgateway.core.constants.LogFlagBusiType;
-import com.shkpr.service.customgateway.zydma.domain.po.CustomerMeterRead;
-import com.shkpr.service.customgateway.zydma.mapper.primary.CustomerMeterReadMapper;
-import com.shkpr.service.customgateway.zydma.service.CustomerMeterReadService;
+import com.shkpr.service.customgateway.core.domain.po.CustomerMeterRead;
+import com.shkpr.service.customgateway.core.mapper.primary.CustomerMeterReadMapper;
+import com.shkpr.service.customgateway.core.service.CustomerMeterReadService;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.ibatis.session.ExecutorType;
 import org.apache.ibatis.session.SqlSession;

+ 4 - 4
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/service/impl/FunctionInfoServiceImpl.java

@@ -1,12 +1,12 @@
-package com.shkpr.service.customgateway.zydma.service.impl;
+package com.shkpr.service.customgateway.core.service.impl;
 
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.customgateway.core.constants.DataSourceNames;
 import com.shkpr.service.customgateway.core.constants.LogFlagBusiType;
-import com.shkpr.service.customgateway.zydma.domain.po.FunctionInfo;
-import com.shkpr.service.customgateway.zydma.mapper.primary.FunctionInfoMapper;
-import com.shkpr.service.customgateway.zydma.service.FunctionInfoService;
+import com.shkpr.service.customgateway.core.domain.po.FunctionInfo;
+import com.shkpr.service.customgateway.core.mapper.primary.FunctionInfoMapper;
+import com.shkpr.service.customgateway.core.service.FunctionInfoService;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.ibatis.session.ExecutorType;
 import org.apache.ibatis.session.SqlSession;

+ 16 - 4
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/service/impl/PersonnelInfoServiceImpl.java

@@ -1,12 +1,12 @@
-package com.shkpr.service.customgateway.zydma.service.impl;
+package com.shkpr.service.customgateway.core.service.impl;
 
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.customgateway.core.constants.DataSourceNames;
 import com.shkpr.service.customgateway.core.constants.LogFlagBusiType;
-import com.shkpr.service.customgateway.zydma.domain.po.PersonnelInfo;
-import com.shkpr.service.customgateway.zydma.mapper.primary.PersonnelInfoMapper;
-import com.shkpr.service.customgateway.zydma.service.PersonnelInfoService;
+import com.shkpr.service.customgateway.core.domain.po.PersonnelInfo;
+import com.shkpr.service.customgateway.core.mapper.primary.PersonnelInfoMapper;
+import com.shkpr.service.customgateway.core.service.PersonnelInfoService;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.ibatis.session.ExecutorType;
@@ -134,4 +134,16 @@ public class PersonnelInfoServiceImpl implements PersonnelInfoService {
         if (StringUtils.isBlank(userId)) return null;
         return personnelInfoMapper.findBydUid(userId);
     }
+
+    /**
+     * 根据账号查询
+     *
+     * @param account 账号
+     * @return 用户
+     */
+    @Override
+    public PersonnelInfo findByAccount(String account) {
+        if (StringUtils.isBlank(account)) return null;
+        return personnelInfoMapper.findByAccount(account);
+    }
 }

+ 108 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/utils/AccessUtil.java

@@ -0,0 +1,108 @@
+package com.shkpr.service.customgateway.core.utils;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.shkpr.service.customgateway.core.constants.AccessMetadata;
+import com.shkpr.service.customgateway.core.domain.AccessResult;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.digest.HmacAlgorithms;
+import org.apache.commons.codec.digest.HmacUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.HttpStatus;
+import org.springframework.http.MediaType;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+/**
+ * 接入工具
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+public class AccessUtil {
+    private final static ObjectMapper objectMapper = new ObjectMapper();
+
+    /**
+     * 编码签名
+     *
+     * @param params      参数
+     * @param timestamp   时间戳
+     * @param securityKey 认证密钥
+     * @return 签名
+     */
+    public static String encodeSignature(Map<String, String> params, Long timestamp, String securityKey) {
+        if (timestamp == null || StringUtils.isBlank(securityKey)) return null;
+        if (params == null) params = Collections.emptyMap();
+        //参数字符
+        String paramsStr = params.entrySet().stream()
+                .sorted(Map.Entry.comparingByKey())
+                .map(entry -> {
+                    try {
+                        return URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8.name()) +
+                                "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.name());
+                    } catch (UnsupportedEncodingException e) {
+                        return null;
+                    }
+                })
+                .filter(Objects::nonNull)
+                .collect(Collectors.joining("&"));
+        //明文
+        String plainText = timestamp + "&" + paramsStr;
+        //加密密钥
+        return Base64.encodeBase64URLSafeString(
+                new HmacUtils(HmacAlgorithms.HMAC_SHA_256, HexUtil.decode(securityKey))
+                        .hmac(plainText)
+        );
+    }
+
+    /**
+     * 验证签名
+     *
+     * @param params      参数
+     * @param timestamp   时间戳
+     * @param securityKey 认证密钥
+     * @return 验证状态
+     */
+    public static boolean matchesSignature(Map<String, String> params, Long timestamp, String securityKey, String signature) {
+        if (timestamp == null || StringUtils.isBlank(securityKey)) return false;
+        //生成期望的签名
+        String expectedSignature = encodeSignature(params, timestamp, securityKey);
+        if (expectedSignature == null) return false;
+        //比较字符
+        return MessageDigest.isEqual(Base64.decodeBase64(expectedSignature), Base64.decodeBase64(signature));
+    }
+
+    /**
+     * 输出响应码
+     *
+     * @param response     response
+     * @param responseCode 响应码
+     */
+    public static void writeResponseCode(HttpServletResponse response, AccessMetadata.ResponseCode responseCode) throws IOException {
+        //跨域
+        response.setHeader("Access-Control-Allow-Origin", "*");
+        response.setHeader("Access-Control-Allow-Methods", "GET,POST,DELETE,PUT");
+        response.setHeader("Access-Control-Allow-Headers", "x-requested-with,Content-Type,Authorization");
+        //基础信息
+        response.setCharacterEncoding(StandardCharsets.UTF_8.name());
+        response.setContentType(MediaType.APPLICATION_JSON_VALUE);
+        response.setStatus(HttpStatus.SC_OK);
+        //构建结果
+        AccessResult<String> resultResponse = new AccessResult<>();
+        resultResponse.setCode(responseCode.getCode());
+        resultResponse.setMessage(responseCode.getMessage());
+        resultResponse.setData(null);
+        resultResponse.setTimestamp(System.currentTimeMillis());
+
+        //输出json
+        response.getWriter().write(objectMapper.writeValueAsString(resultResponse));
+    }
+}

+ 18 - 3
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/utils/AesUtil.java

@@ -1,5 +1,8 @@
 package com.shkpr.service.customgateway.core.utils;
 
+import com.global.base.log.LogLevelFlag;
+import com.global.base.log.LogPrintMgr;
+import com.shkpr.service.customgateway.core.constants.LogFlagBusiType;
 import org.apache.commons.codec.binary.Base64;
 
 import javax.crypto.BadPaddingException;
@@ -15,9 +18,18 @@ import java.security.NoSuchAlgorithmException;
 import java.util.Arrays;
 
 /**
- * aes
+ * aes工具类
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
  */
 public class AesUtil {
+    /**
+     * log
+     */
+    private final static String mStrClassName = "AesUtil";
+    private final static String mBizType = LogFlagBusiType.BUSI_COMMON.toStrValue();
+
     //加密算法名称
     private static final String ALGORITHM = "AES";
     //加密转换规范:算法/模式/填充方案
@@ -51,7 +63,7 @@ public class AesUtil {
             //加密密码
             byte[] encryptedBytes = cipher.doFinal(plainText.getBytes(StandardCharsets.UTF_8));
             //转base64
-            return Base64.encodeBase64String(encryptedBytes);
+            return Base64.encodeBase64URLSafeString(encryptedBytes);
         } catch (NoSuchPaddingException | NoSuchAlgorithmException | IllegalBlockSizeException | BadPaddingException |
                  InvalidAlgorithmParameterException | InvalidKeyException e) {
             return null;
@@ -59,7 +71,7 @@ public class AesUtil {
     }
 
     /**
-     * AES密方法
+     * AES密方法
      * 使用CBC模式,IV取自密钥的前16字节
      *
      * @param encryptedText 加密文本
@@ -84,6 +96,9 @@ public class AesUtil {
             return new String(decryptedBytes, StandardCharsets.UTF_8);
         } catch (NoSuchPaddingException | NoSuchAlgorithmException | IllegalBlockSizeException | BadPaddingException |
                  InvalidAlgorithmParameterException | InvalidKeyException e) {
+            LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
+                    , String.format("AES解密失败: error:%s", e));
+
             return null;
         }
     }

+ 232 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/utils/GeomUtil.java

@@ -0,0 +1,232 @@
+package com.shkpr.service.customgateway.core.utils;
+
+import com.global.base.log.LogLevelFlag;
+import com.global.base.log.LogPrintMgr;
+import com.shkpr.service.customgateway.core.constants.LogFlagBusiType;
+import org.geotools.referencing.CRS;
+import org.geotools.referencing.GeodeticCalculator;
+import org.locationtech.jts.geom.*;
+import org.locationtech.jts.util.GeometricShapeFactory;
+import org.opengis.referencing.FactoryException;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.operation.TransformException;
+
+/**
+ * 地理工具类
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+public class GeomUtil {
+    /**
+     * log
+     */
+    private final static String mStrClassName = "GeomUtil";
+    private final static String mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue();
+    /**
+     * geom工厂
+     */
+    private static final GeometryFactory geometryFactory = new GeometryFactory();
+    /**
+     * 形状工厂
+     */
+    private final static GeometricShapeFactory shapeFactory = new GeometricShapeFactory(geometryFactory);
+
+    /**
+     * 计算长度
+     *
+     * @param coordinate1 坐标1
+     * @param coordinate2 坐标2
+     * @return 长度
+     */
+    public static double calcLength(Coordinate coordinate1, Coordinate coordinate2) {
+        double x1 = coordinate1.getX();
+        double y1 = coordinate1.getY();
+        double x2 = coordinate2.getX();
+        double y2 = coordinate2.getY();
+        //计算差
+        double dx = Math.abs(x1 - x2);
+        double dy = Math.abs(y1 - y2);
+        //计算长
+        return Math.sqrt(dx * dx + dy * dy);
+    }
+
+    /**
+     * 转数组
+     *
+     * @param coordinate 坐标
+     * @return 坐标数组
+     */
+    public static double[] toArray(Coordinate coordinate) {
+        return new double[]{coordinate.getX(), coordinate.getY()};
+    }
+
+    /**
+     * 转数组
+     *
+     * @param lineString 线
+     * @return 坐标数组
+     */
+    public static double[][] toArray(LineString lineString) {
+        //获取geom的坐标
+        Coordinate[] coords = lineString.getCoordinates();
+        if (coords == null || coords.length == 0) return new double[0][2];
+        //构建坐标数组
+        double[][] result = new double[coords.length][2];
+        //存入坐标
+        for (int j = 0; j < coords.length; j++) {
+            result[j][0] = coords[j].getX();
+            result[j][1] = coords[j].getY();
+        }
+        return result;
+    }
+
+    /**
+     * 转数组
+     *
+     * @param multiLineString 线集合
+     * @return 坐标数组
+     */
+    public static double[][][] toArray(MultiLineString multiLineString) {
+        //geom长度
+        int geomLength = multiLineString.getNumGeometries();
+        //结果
+        double[][][] result = new double[geomLength][][];
+        //遍历geom
+        for (int i = 0; i < geomLength; i++) {
+            //获取geom
+            Geometry geom = multiLineString.getGeometryN(i);
+            if (geom instanceof LineString) result[i] = toArray((LineString) geom);
+            else result[i] = new double[0][];
+        }
+        return result;
+    }
+
+    /**
+     * 从数组转换
+     *
+     * @param array 数组
+     * @return 坐标
+     */
+    public static Coordinate ofArray(double[] array) {
+        if (array == null || array.length < 2) return null;
+        return new Coordinate(array[0], array[1]);
+    }
+
+    /**
+     * 从数组转换
+     *
+     * @param array 数组
+     * @return 线
+     */
+    public static LineString ofArray(double[][] array) {
+        if (array == null || array.length == 0) return geometryFactory.createLineString();
+        //遍历数组并构建坐标集合
+        Coordinate[] coordinates = new Coordinate[array.length];
+        for (int j = 0; j < array.length; j++) {
+            //坐标判断
+            if (array[j].length < 2) throw new IllegalArgumentException("坐标点必须包含 [x, y]");
+            //转坐标
+            coordinates[j] = ofArray(array[j]);
+        }
+        return geometryFactory.createLineString(coordinates);
+    }
+
+    /**
+     * 从数组转换
+     *
+     * @param array 数组
+     * @return 多线
+     */
+    public static MultiLineString ofArray(double[][][] array) {
+        if (array == null || array.length == 0) return geometryFactory.createMultiLineString();
+        //遍历数组并构建线集合
+        LineString[] lineStrings = new LineString[array.length];
+        for (int i = 0; i < array.length; i++) {
+            //转线
+            lineStrings[i] = ofArray(array[i]);
+        }
+        return geometryFactory.createMultiLineString(lineStrings);
+    }
+
+
+    /**
+     * 创建圆
+     *
+     * @param centre  圆心
+     * @param radius  半径
+     * @param crsCode 坐标系
+     * @return 圆
+     */
+    public static Polygon createCircle(Coordinate centre, double radius, String crsCode) {
+        try {
+            //端点数量
+            int extremePointsTotal = 32;
+            //经度
+            double lng = centre.getX();
+            //纬度
+            double lat = centre.getY();
+            //坐标系
+            CoordinateReferenceSystem crs = CRS.decode("EPSG:" + crsCode);
+            if (crs == null) return null;
+
+            //创建大地计算器,并设置坐标系
+            GeodeticCalculator gc = new GeodeticCalculator(crs);
+
+            //计算东点(90度),正东移动
+            gc.setStartingGeographicPoint(lng, lat);
+            gc.setDirection(90, radius);
+            //获取结果
+            double[] eastCoords = gc.getDestinationPosition().getCoordinate();
+            Coordinate eastPoint = new Coordinate(eastCoords[1], eastCoords[0]); // 创建 Coordinate 对象
+
+            //计算西点(270度),正西移动
+            gc.setStartingGeographicPoint(lng, lat);
+            gc.setDirection(270, radius);
+            //获取结果
+            double[] westCoords = gc.getDestinationPosition().getCoordinate();
+            Coordinate westPoint = new Coordinate(westCoords[1], westCoords[0]);
+
+            //计算北点(0度),正北移动
+            gc.setStartingGeographicPoint(lng, lat);
+            gc.setDirection(0, radius);
+            //获取结果
+            double[] northCoords = gc.getDestinationPosition().getCoordinate();
+            Coordinate northPoint = new Coordinate(northCoords[1], northCoords[0]);
+
+            //计算南点(180度)
+            gc.setStartingGeographicPoint(lng, lat);
+            gc.setDirection(180, radius);
+            //获取结果
+            double[] southCoords = gc.getDestinationPosition().getCoordinate();
+            Coordinate southPoint = new Coordinate(southCoords[1], southCoords[0]);
+
+            //创建边界框
+            double x1 = westPoint.x;
+            double x2 = eastPoint.x;
+            double y1 = southPoint.y;
+            double y2 = northPoint.y;
+            Envelope envelope = new Envelope(x1, x2, y1, y2);
+
+            //设置圆心
+            Coordinate coordinate = new Coordinate(lng, lat);
+            shapeFactory.setCentre(coordinate);
+            //设置边界
+            shapeFactory.setEnvelope(envelope);
+            //设置边界点数量
+            shapeFactory.setNumPoints(extremePointsTotal);
+
+            //创建圆
+            Polygon circle = shapeFactory.createCircle();
+            //设置坐标系
+            circle.setSRID(Integer.parseInt(crsCode));
+
+            return circle;
+        } catch (TransformException | FactoryException e) {
+            LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
+                    , String.format("geom创建失败: error:%s", e));
+
+            return null;
+        }
+    }
+}

+ 3 - 3
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/utils/HexUtil.java

@@ -13,7 +13,7 @@ public class HexUtil {
      * @param bytes 字节数组
      * @return 字符串
      */
-    public static String encodeHex(byte[] bytes) {
+    public static String encode(byte[] bytes) {
         StringBuilder sb = new StringBuilder();
         for (byte b : bytes) {
             String s = Integer.toHexString(b & 0xff);
@@ -28,9 +28,9 @@ public class HexUtil {
      * @param s 字符串
      * @return 字节数组
      */
-    public static byte[] decodeHex(String s) {
+    public static byte[] decode(CharSequence s) {
         //非空判断
-        if (s == null || s.isEmpty()) return null;
+        if (s == null || s.length() == 0 || s.length() % 2 != 0) return null;
         //缓存数组
         byte[] b = new byte[s.length() >> 1];
         //遍历字符串,每次位移长度2

+ 13 - 37
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/utils/SecurityUtil.java

@@ -1,5 +1,6 @@
 package com.shkpr.service.customgateway.core.utils;
 
+import org.springframework.security.authentication.AnonymousAuthenticationToken;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.context.SecurityContextHolder;
 
@@ -19,41 +20,16 @@ public class SecurityUtil {
     public static void setAuthentication(Authentication authentication) {
         SecurityContextHolder.getContext().setAuthentication(authentication);
     }
-//
-//    /**
-//     * 获取当前登陆的用户
-//     *
-//     * @return 用户
-//     */
-//    public static Mono<UserDetailsDto> getUser() {
-//        return ReactiveSecurityContextHolder.getContext().flatMap(securityContext -> {
-//            Authentication authentication = securityContext.getAuthentication();
-//            if (authentication != null && authentication.getPrincipal() instanceof UserDetailsDto) {
-//                return Mono.just((UserDetailsDto) authentication.getPrincipal());
-//            }
-//            return Mono.empty();
-//        });
-//    }
-//
-//    /**
-//     * 获取当前登陆的用户的id
-//     *
-//     * @return 用户
-//     */
-//    public static Mono<Long> getUserId() {
-//        //如用户不为空,则返回用户id
-//        return getUser().flatMap(user -> (user != null) ? Mono.just(user.getId()) : Mono.empty());
-//    }
-//
-//    /**
-//     * 获取当前登陆的用户的组织id
-//     *
-//     * @return 组织id
-//     * @deprecated 当前平台不使用组织架构, 故弃用该方法
-//     */
-//    @Deprecated
-//    public static Mono<Long> getOrgId() {
-//        //如用户不为空,则返回用户id
-//        return getUser().flatMap(user -> (user != null) ?  Mono.just(user.getId()) : Mono.empty());
-//    }`
+
+    /**
+     * 是否已认证
+     *
+     * @return 认证状态
+     */
+    public static boolean isAuthenticated() {
+        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+        return authentication != null &&
+                authentication.isAuthenticated() &&
+                !(authentication instanceof AnonymousAuthenticationToken);
+    }
 }

+ 26 - 9
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/utils/TokenUtil.java

@@ -4,16 +4,17 @@ import com.shkpr.service.customgateway.core.constants.Api;
 import com.shkpr.service.customgateway.core.constants.CommDefine;
 import com.shkpr.service.customgateway.core.constants.TokenMetadata;
 import com.shkpr.service.customgateway.core.domain.CommonToken;
+import com.shkpr.service.customgateway.core.domain.TmpTokenData;
 import com.shkpr.service.customgateway.core.domain.TokenData;
 import com.shkpr.service.customgateway.core.properties.GlobalProperties;
 import com.shkpr.service.customgateway.core.properties.SecurityProperties;
 import io.jsonwebtoken.*;
 import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.security.authentication.BadCredentialsException;
 import org.springframework.security.authentication.CredentialsExpiredException;
 import org.springframework.security.core.Authentication;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
 import org.springframework.stereotype.Component;
 
 import javax.servlet.http.HttpServletRequest;
@@ -213,24 +214,40 @@ public class TokenUtil {
             throw new CredentialsExpiredException("Invalidate token, token is expired.");
 
         //设置用户和角色信息,并返回token
-        request.setAttribute(TokenMetadata.RequestAttributes.USER_ID, tokenData.getFlagKey());
+        request.setAttribute(TokenMetadata.RequestAttributes.USER_ID, tokenData.getUserId());
         request.setAttribute(TokenMetadata.RequestAttributes.ROLE_ID, tokenData.getRoleId());
-        return CommonToken.authenticated(tokenData, Collections.emptyList());
+        return CommonToken.authenticated(tokenData, Collections.singletonList(new SimpleGrantedAuthority(TokenMetadata.AUTHORITY)));
     }
 
     /**
      * 生成临时token
      *
      * @param account 登陆账号
+     * @return 临时token
      */
-    public String generateTempToken(String account) {
+    public TmpTokenData generateTempToken(String account) {
         if (StringUtils.isBlank(account)) return null;
-        //加密数据,模式:模式0登录名,模式1用户id,时间戳,随机数,数据
-        String data = String.format("%s%d%s%s", "0",
-                System.currentTimeMillis() / 1000, RandomStringUtils.randomAlphanumeric(8), account);
         //密钥,转md5,取 8-24 字符(16 字节)
         String key = DigestUtils.md5Hex(securityProperties.getSecret()).substring(8, 24).toUpperCase();
-        //aes加密
-        return AesUtil.encrypt(data, key);
+
+        //构建临时token对象,并加密
+        return TmpTokenData.ofAccount(account)
+                .encrypt(key);
+    }
+
+    /**
+     * 解析临时token
+     *
+     * @param token 临时token
+     * @return 登陆账号
+     */
+    public TmpTokenData parseTempToken(String token) {
+        if (StringUtils.isBlank(token)) return null;
+        //密钥,转md5,取 8-24 字符(16 字节)
+        String key = DigestUtils.md5Hex(securityProperties.getSecret()).substring(8, 24).toUpperCase();
+
+        //构建临时token对象,并解密
+        return TmpTokenData.ofToken(token)
+                .decrypt(key);
     }
 }

+ 1 - 1
custom-gateway-zydma/src/main/resources/mapper/CustomerInfoMapper.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.shkpr.service.customgateway.zydma.mapper.primary.CustomerInfoMapper">
+<mapper namespace="com.shkpr.service.customgateway.core.mapper.primary.CustomerInfoMapper">
     <insert id="upsert">
         <trim prefix="insert into customer_info (" suffix=")" suffixOverrides=",">
             code,

+ 1 - 1
custom-gateway-zydma/src/main/resources/mapper/CustomerMeterReadMapper.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.shkpr.service.customgateway.zydma.mapper.primary.CustomerMeterReadMapper">
+<mapper namespace="com.shkpr.service.customgateway.core.mapper.primary.CustomerMeterReadMapper">
     <insert id="upsert">
         <trim prefix="insert into k3_customer_meter_read (" suffix=")" suffixOverrides=",">
             code,

+ 1 - 1
custom-gateway-zydma/src/main/resources/mapper/FunctionInfoMapper.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.shkpr.service.customgateway.zydma.mapper.primary.FunctionInfoMapper">
+<mapper namespace="com.shkpr.service.customgateway.core.mapper.primary.FunctionInfoMapper">
     <insert id="upsert">
         insert into k4_bs_sys_function_info (uid, "name", remark, update_time)
         values (#{uid,jdbcType=VARCHAR},

+ 56 - 7
custom-gateway-zydma/src/main/resources/mapper/PersonnelInfoMapper.xml

@@ -1,6 +1,28 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.shkpr.service.customgateway.zydma.mapper.primary.PersonnelInfoMapper">
+<mapper namespace="com.shkpr.service.customgateway.core.mapper.primary.PersonnelInfoMapper">
+    <resultMap id="BaseResultMap" type="com.shkpr.service.customgateway.core.domain.po.PersonnelInfo">
+        <id column="uid" property="uid" jdbcType="VARCHAR"/>
+        <result column="account" property="account" jdbcType="VARCHAR"/>
+        <result column="password" property="password" jdbcType="VARCHAR"/>
+        <result column="real_name" property="realName" jdbcType="VARCHAR"/>
+        <result column="address" property="address" jdbcType="VARCHAR"/>
+        <result column="sex" property="sex" jdbcType="SMALLINT"/>
+        <result column="phone" property="phone" jdbcType="VARCHAR"/>
+        <result column="email" property="email" jdbcType="VARCHAR"/>
+        <result column="avatar" property="avatar" jdbcType="VARCHAR"/>
+        <result column="role_id" property="roleId" jdbcType="VARCHAR"/>
+        <result column="dept_id" property="deptId" jdbcType="VARCHAR"/>
+        <result column="post_id" property="postId" jdbcType="VARCHAR"
+                typeHandler="com.shkpr.service.customgateway.core.io.StringListTypeHandle"/>
+        <result column="status" property="status" jdbcType="SMALLINT"/>
+        <result column="param1" property="param1" jdbcType="VARCHAR"/>
+        <result column="param2" property="param2" jdbcType="VARCHAR"/>
+        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
+        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
+        <result column="org" property="org" jdbcType="VARCHAR"/>
+    </resultMap>
+
     <select id="findExistentIds" resultType="java.lang.String">
         SELECT uid FROM k2_personnel_info
         WHERE uid IN
@@ -8,9 +30,9 @@
             #{id}
         </foreach>
     </select>
-    <select id="findBydUid" resultType="com.shkpr.service.customgateway.zydma.domain.po.PersonnelInfo">
-        select id,
-               uid,
+
+    <select id="findBydUid" resultMap="BaseResultMap">
+        select uid,
                account,
                password,
                real_name,
@@ -32,6 +54,29 @@
         where uid = #{uid,jdbcType=VARCHAR}
     </select>
 
+    <select id="findByAccount" resultMap="BaseResultMap">
+        select uid,
+               account,
+               password,
+               real_name,
+               address,
+               sex,
+               phone,
+               email,
+               avatar,
+               role_id,
+               dept_id,
+               post_id,
+               status,
+               param1,
+               param2,
+               create_time,
+               update_time,
+               org
+        from k2_personnel_info
+        where account = #{account,jdbcType=VARCHAR}
+    </select>
+
     <insert id="save">
         insert into k2_personnel_info
         <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -42,7 +87,7 @@
             <if test="phone != null and phone != ''">phone,</if>
             <if test="email != null and email != ''">email,</if>
             <if test="roleId != null and roleId != ''">role_id,</if>
-            <if test="postId != null and roleId != ''">post_id,</if>
+            <if test="postId != null">post_id,</if>
             <if test="status != null">status,</if>
             <if test="password != null">"password",</if>
             <if test="org != null and org != ''">org,</if>
@@ -56,7 +101,9 @@
             <if test="phone != null and phone != ''">#{phone,jdbcType=VARCHAR},</if>
             <if test="email != null and email != ''">#{email,jdbcType=VARCHAR},</if>
             <if test="roleId != null and roleId != ''">#{roleId,jdbcType=VARCHAR},</if>
-            <if test="postId != null and postId != ''">#{postId,jdbcType=VARCHAR},</if>
+            <if test="postId != null">
+                #{postId,jdbcType=VARCHAR,typeHandler=com.shkpr.service.customgateway.core.io.StringListTypeHandle},
+            </if>
             <if test="status != null">#{status,jdbcType=SMALLINT},</if>
             <if test="password != null">#{password,jdbcType=VARCHAR},</if>
             <if test="org != null and org != ''">#{org,jdbcType=VARCHAR},</if>
@@ -70,7 +117,9 @@
             <if test="realName != null and realName != ''">real_name = #{realName,jdbcType=VARCHAR},</if>
             <if test="phone != null and phone != ''">phone = #{phone,jdbcType=VARCHAR},</if>
             <if test="email != null and email != ''">email = #{email,jdbcType=VARCHAR},</if>
-            <if test="postId != null and postId != ''">post_id = #{postId,jdbcType=VARCHAR},</if>
+            <if test="postId != null">post_id =
+                #{postId,jdbcType=VARCHAR,typeHandler=com.shkpr.service.customgateway.core.io.StringListTypeHandle},
+            </if>
             <if test="status != null">status = #{status,jdbcType=SMALLINT},</if>
             <if test=" password != null">"password" = #{password,jdbcType=VARCHAR},</if>
             update_time = now()

+ 0 - 11
custom-gateway-zydma/pom.xml

@@ -27,17 +27,6 @@
             <artifactId>custom-gateway-core</artifactId>
             <version>${project.version}</version>
         </dependency>
-        <!--jts-->
-        <dependency>
-            <groupId>org.locationtech.jts</groupId>
-            <artifactId>jts-core</artifactId>
-            <version>${jts.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.locationtech.jts.io</groupId>
-            <artifactId>jts-io-common</artifactId>
-            <version>${jts.version}</version>
-        </dependency>
     </dependencies>
 
     <!--构建脚本-->

+ 1 - 1
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/components/DataCollector.java

@@ -98,7 +98,7 @@ public class DataCollector {
         List<Header> headers = Arrays.asList(
                 new BasicHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE),
                 new BasicHeader(IotPlatformMetadata.Headers.PANDA_TOKEN, key.getAccessKey()),
-                new BasicHeader(IotPlatformMetadata.Headers.AUTHORIZATION, key.getSecretKey())
+                new BasicHeader(IotPlatformMetadata.Headers.AUTHORIZATION, key.getSignature())
         );
         //结果
         List<Point> results = new ArrayList<>();

+ 9 - 20
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/components/InfoSynchronizer.java

@@ -1,21 +1,19 @@
 package com.shkpr.service.customgateway.zydma.components;
 
-import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.customgateway.core.constants.LogFlagBusiType;
 import com.shkpr.service.customgateway.core.domain.IntegrationKey;
+import com.shkpr.service.customgateway.core.domain.po.FunctionInfo;
+import com.shkpr.service.customgateway.core.domain.po.PersonnelInfo;
 import com.shkpr.service.customgateway.core.exception.SelfException;
 import com.shkpr.service.customgateway.core.properties.CallingProperties;
+import com.shkpr.service.customgateway.core.service.FunctionInfoService;
+import com.shkpr.service.customgateway.core.service.PersonnelInfoService;
 import com.shkpr.service.customgateway.core.utils.CallingUtil;
 import com.shkpr.service.customgateway.zydma.constants.MiddlePlatformMetadata;
 import com.shkpr.service.customgateway.zydma.domain.*;
-import com.shkpr.service.customgateway.zydma.domain.po.FunctionInfo;
-import com.shkpr.service.customgateway.zydma.domain.po.PersonnelInfo;
-import com.shkpr.service.customgateway.zydma.service.FunctionInfoService;
-import com.shkpr.service.customgateway.zydma.service.PersonnelInfoService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.http.Header;
@@ -47,17 +45,14 @@ public class InfoSynchronizer {
     final
     CallingProperties callingProperties;
     final
-    ObjectMapper objectMapper;
-    final
     PersonnelInfoService personnelInfoService;
     final
     FunctionInfoService functionInfoService;
     final
     CallingUtil callingUtil;
 
-    public InfoSynchronizer(CallingProperties callingProperties, ObjectMapper objectMapper, PersonnelInfoService personnelInfoService, FunctionInfoService functionInfoService, CallingUtil callingUtil) {
+    public InfoSynchronizer(CallingProperties callingProperties, PersonnelInfoService personnelInfoService, FunctionInfoService functionInfoService, CallingUtil callingUtil) {
         this.callingProperties = callingProperties;
-        this.objectMapper = objectMapper;
         this.personnelInfoService = personnelInfoService;
         this.functionInfoService = functionInfoService;
         this.callingUtil = callingUtil;
@@ -98,14 +93,8 @@ public class InfoSynchronizer {
                     .filter(role -> role.getRoleId() != null).mapToLong(MiddlePlatformUserRole.Role::getRoleId)
                     //去重复,排序,转字符串
                     .distinct().sorted().mapToObj(String::valueOf).collect(Collectors.toList());
-            try {
-                //设置职能信息
-                personnelInfo.setPostId(objectMapper.writeValueAsString(ids));
-            } catch (JsonProcessingException e) {
-                LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, BIZ_TYPE, CLASS_NAME
-                        , String.format("职能id集合json序列化失败 error:%s", e)
-                );
-            }
+            //设置职能信息
+            personnelInfo.setPostId(ids);
         });
 
         //批量写入用户
@@ -174,7 +163,7 @@ public class InfoSynchronizer {
                         return Arrays.asList(
                                 new BasicHeader(MiddlePlatformMetadata.Headers.APP_KEY, key.getAccessKey()),
                                 new BasicHeader(MiddlePlatformMetadata.Headers.TIMESTAMP, key.getTimestamp() + ""),
-                                new BasicHeader(MiddlePlatformMetadata.Headers.SIGN, key.getSecretKey())
+                                new BasicHeader(MiddlePlatformMetadata.Headers.SIGN, key.getSignature())
                         );
                     });
         } catch (SelfException e) {
@@ -204,7 +193,7 @@ public class InfoSynchronizer {
         List<Header> headers = Arrays.asList(
                 new BasicHeader(MiddlePlatformMetadata.Headers.APP_KEY, key.getAccessKey()),
                 new BasicHeader(MiddlePlatformMetadata.Headers.TIMESTAMP, key.getTimestamp() + ""),
-                new BasicHeader(MiddlePlatformMetadata.Headers.SIGN, key.getSecretKey())
+                new BasicHeader(MiddlePlatformMetadata.Headers.SIGN, key.getSignature())
         );
 
         //请求结果项

+ 1 - 1
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/constants/IotPlatformMetadata.java

@@ -57,7 +57,7 @@ public abstract class IotPlatformMetadata {
         if (!tokenResult.isOk() || !ObjectUtils.allNotNull(data, data.getUserToken(), data.getTokenType(), data.getAccessToken()))
             return null;
 
-        return new IntegrationKey(null, data.getUserToken(), data.getTokenType() + " " + data.getAccessToken());
+        return new IntegrationKey(null, data.getUserToken(), null, data.getTokenType() + " " + data.getAccessToken());
     }
 
     /**

+ 1 - 1
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/constants/MiddlePlatformMetadata.java

@@ -36,7 +36,7 @@ public abstract class MiddlePlatformMetadata extends IntegrationMetadata {
                 .collect(Collectors.joining("&"));
         //签名密钥
         String sign = DigestUtils.md5Hex(secretKey + "&" + timestamp + "&" + paramsStr).toUpperCase();
-        return new IntegrationKey(timestamp, accessKey, sign);
+        return new IntegrationKey(timestamp, accessKey, null, sign);
     }
 
     /**

+ 37 - 3
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/controller/ApiController.java

@@ -1,7 +1,14 @@
 package com.shkpr.service.customgateway.zydma.controller;
 
-import org.springframework.stereotype.Controller;
+import com.shkpr.service.customgateway.core.domain.AccessResult;
+import com.shkpr.service.customgateway.core.domain.TmpTokenData;
+import com.shkpr.service.customgateway.core.domain.po.PersonnelInfo;
+import com.shkpr.service.customgateway.core.service.PersonnelInfoService;
+import com.shkpr.service.customgateway.core.utils.TokenUtil;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 
 /**
  * api接入controller
@@ -9,8 +16,35 @@ import org.springframework.web.bind.annotation.RequestMapping;
  * @author 欧阳劲驰
  * @since 1.0.0
  */
-@Controller
-@RequestMapping("api")
+@RestController
+@RequestMapping("${gateway.routes.zydma}" + "/api")
 public class ApiController {
+    final
+    PersonnelInfoService personnelInfoService;
+    final
+    TokenUtil tokenUtil;
 
+    public ApiController(PersonnelInfoService personnelInfoService, TokenUtil tokenUtil) {
+        this.personnelInfoService = personnelInfoService;
+        this.tokenUtil = tokenUtil;
+    }
+
+    /**
+     * 获取用户信息
+     *
+     * @param token 临时token
+     * @return 用户信息
+     */
+    @GetMapping("getUser")
+    public AccessResult<PersonnelInfo> getUser(@RequestParam("token") String token) {
+        //解析临时token
+        TmpTokenData tmpToken = tokenUtil.parseTempToken(token);
+        if (tmpToken == null) return AccessResult.fail("token无效");
+
+        //查询用户信息
+        PersonnelInfo personnelInfo = personnelInfoService.findByAccount(tmpToken.getAccount());
+        if (personnelInfo == null) return AccessResult.fail("用户不存在");
+
+        return AccessResult.ok(personnelInfo);
+    }
 }

+ 4 - 4
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/controller/CustomerController.java

@@ -7,10 +7,10 @@ import com.shkpr.service.customgateway.core.domain.ResultResponse;
 import com.shkpr.service.customgateway.core.exception.SelfException;
 import com.shkpr.service.customgateway.core.utils.CommTool;
 import com.shkpr.service.customgateway.core.utils.ExcelUtil;
-import com.shkpr.service.customgateway.zydma.domain.po.CustomerInfo;
-import com.shkpr.service.customgateway.zydma.domain.po.CustomerMeterRead;
-import com.shkpr.service.customgateway.zydma.service.CustomerInfoService;
-import com.shkpr.service.customgateway.zydma.service.CustomerMeterReadService;
+import com.shkpr.service.customgateway.core.domain.po.CustomerInfo;
+import com.shkpr.service.customgateway.core.domain.po.CustomerMeterRead;
+import com.shkpr.service.customgateway.core.service.CustomerInfoService;
+import com.shkpr.service.customgateway.core.service.CustomerMeterReadService;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.MapUtils;
 import org.springframework.stereotype.Controller;

+ 7 - 5
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/controller/UserController.java

@@ -8,6 +8,7 @@ import com.shkpr.service.customgateway.core.constants.LogFlagBusiType;
 import com.shkpr.service.customgateway.core.constants.ResponseCode;
 import com.shkpr.service.customgateway.core.domain.IntegrationKey;
 import com.shkpr.service.customgateway.core.domain.ResultResponse;
+import com.shkpr.service.customgateway.core.domain.TmpTokenData;
 import com.shkpr.service.customgateway.core.exception.SelfException;
 import com.shkpr.service.customgateway.core.properties.CallingProperties;
 import com.shkpr.service.customgateway.core.utils.CallingUtil;
@@ -15,8 +16,8 @@ import com.shkpr.service.customgateway.core.utils.CommTool;
 import com.shkpr.service.customgateway.core.utils.TokenUtil;
 import com.shkpr.service.customgateway.zydma.constants.MiddlePlatformMetadata;
 import com.shkpr.service.customgateway.zydma.domain.MiddlePlatformResult;
-import com.shkpr.service.customgateway.zydma.domain.po.PersonnelInfo;
-import com.shkpr.service.customgateway.zydma.service.PersonnelInfoService;
+import com.shkpr.service.customgateway.core.domain.po.PersonnelInfo;
+import com.shkpr.service.customgateway.core.service.PersonnelInfoService;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.http.Header;
 import org.apache.http.message.BasicHeader;
@@ -119,7 +120,7 @@ public class UserController {
         List<Header> headers = Arrays.asList(
                 new BasicHeader(MiddlePlatformMetadata.Headers.APP_KEY, key.getAccessKey()),
                 new BasicHeader(MiddlePlatformMetadata.Headers.TIMESTAMP, key.getTimestamp() + ""),
-                new BasicHeader(MiddlePlatformMetadata.Headers.SIGN, key.getSecretKey())
+                new BasicHeader(MiddlePlatformMetadata.Headers.SIGN, key.getSignature())
         );
 
         //获取用户
@@ -133,8 +134,9 @@ public class UserController {
         PersonnelInfo personnelInfo = personnelInfoService.findByUserId(userId);
         if (personnelInfo != null && personnelInfo.getAccount() != null) {
             //签发临时token
-            String tempToken = tokenUtil.generateTempToken(personnelInfo.getAccount());
-            if (StringUtils.isNotBlank(tempToken)) resultResponse.success(tempToken);
+            TmpTokenData tempToken = tokenUtil.generateTempToken(personnelInfo.getAccount());
+            if (tempToken != null && StringUtils.isNotBlank(tempToken.getToken()))
+                resultResponse.success(tempToken.getToken());
         }
 
         //end

+ 1 - 1
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/domain/MiddlePlatformRole.java

@@ -2,7 +2,7 @@ package com.shkpr.service.customgateway.zydma.domain;
 
 
 import com.fasterxml.jackson.annotation.JsonAlias;
-import com.shkpr.service.customgateway.zydma.domain.po.FunctionInfo;
+import com.shkpr.service.customgateway.core.domain.po.FunctionInfo;
 import lombok.Data;
 
 /**

+ 1 - 1
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/domain/MiddlePlatformUser.java

@@ -1,7 +1,7 @@
 package com.shkpr.service.customgateway.zydma.domain;
 
 import com.shkpr.service.customgateway.zydma.constants.MiddlePlatformMetadata;
-import com.shkpr.service.customgateway.zydma.domain.po.PersonnelInfo;
+import com.shkpr.service.customgateway.core.domain.po.PersonnelInfo;
 import lombok.Data;
 
 import java.util.Objects;

+ 10 - 0
pom.xml

@@ -54,6 +54,7 @@
         <okhttp.version>3.14.9</okhttp.version>
         <poi.version>3.17</poi.version>
         <jts.version>1.19.0</jts.version>
+        <geotools.version>28.6.1</geotools.version>
     </properties>
 
     <!--依赖项-->
@@ -105,6 +106,15 @@
                 <enabled>true</enabled>
             </releases>
         </repository>
+        <!--地理基金会-->
+        <repository>
+            <id>osgeo</id>
+            <name>OSGeo Release Repository</name>
+            <url>https://repo.osgeo.org/repository/release/</url>
+            <releases>
+                <enabled>true</enabled>
+            </releases>
+        </repository>
     </repositories>
 
     <!--依赖控制-->