11
13693261870
2024-11-05 0f4da6101dd8552cc91475b1a0468e2847316c7d
11
已添加1个文件
已修改6个文件
134 ■■■■■ 文件已修改
pom.xml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/config/InitConfig.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/controller/TestController.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/helper/CaffeineHelper.java 86 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/service/GedbService.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application.yml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/logback-spring.xml 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml
@@ -135,6 +135,12 @@
            <scope>system</scope>
            <systemPath>${project.basedir}/libs/simu.jar</systemPath>
        </dependency>
        <!--Caffeine缓存-->
        <dependency>
            <groupId>com.github.ben-manes.caffeine</groupId>
            <artifactId>caffeine</artifactId>
            <version>2.9.3</version>
        </dependency>
    </dependencies>
    <build>
src/main/java/com/se/simu/config/InitConfig.java
@@ -1,5 +1,6 @@
package com.se.simu.config;
import com.se.simu.helper.CaffeineHelper;
import com.se.simu.helper.GdalHelper;
import com.se.simu.helper.WebHelper;
import lombok.extern.slf4j.Slf4j;
@@ -26,6 +27,9 @@
    @Value("${server.port}")
    String serverPort;
    @Value("${config.cacheTime}")
    Integer cacheTime;
    @Value("${server.servlet.context-path}")
    String contextPath;
@@ -35,6 +39,7 @@
        try {
            log.info("***************** åˆå§‹åŒ– GDAL *****************" + "\n");
            GdalHelper.init(env.getProperty("config.gdalPath"));
            CaffeineHelper.init(cacheTime);
            String path = null != contextPath && contextPath.length() > 1 ? contextPath : "";
            log.info("API文档:http://localhost:" + serverPort + path + "/doc.html");
src/main/java/com/se/simu/controller/TestController.java
@@ -113,4 +113,16 @@
            return fail(ex, null);
        }
    }
    @ApiOperation(value = "testToken *")
    @GetMapping("/testToken")
    public R<Object> testToken() {
        try {
            String token = gedbService.getToken();
            return success(token);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
}
src/main/java/com/se/simu/helper/CaffeineHelper.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,86 @@
package com.se.simu.helper;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import lombok.extern.slf4j.Slf4j;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
 * Caffeine帮助类
 *
 * @author WWW
 * @date 2024-11-05
 */
@Slf4j
public class CaffeineHelper {
    private static Cache<String, Object> cache;
    public static void init(Integer cacheTime) {
        cache = Caffeine.newBuilder()
                .initialCapacity(16)
                .maximumSize(4096)
                .expireAfterWrite(cacheTime, TimeUnit.MINUTES)
                .build();
    }
    public static Object get(String key) {
        return cache.getIfPresent(key);
    }
    public static void put(String key, Object obj) {
        cache.put(key, obj);
    }
    public static void remove(String key) {
        cache.invalidate(key);
    }
    public static void clear() {
        cache.invalidateAll();
    }
    public static <T> List<T> getListByKey(String key) {
        Object obj = get(key);
        if (obj instanceof List<?>) {
            return (List<T>) obj;
        }
        return null;
    }
    public static <T> void putListByKey(String key, List<T> list) {
        if (null != list && list.size() > 0) {
            put(key, list);
        }
    }
    public static String getMd5(String str) {
        if (StringHelper.isEmpty(str)) {
            return null;
        }
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(str.getBytes());
            byte[] byteArray = md5.digest();
            BigInteger bigInt = new BigInteger(1, byteArray);
            // å‚æ•°16表示16进制
            String result = bigInt.toString(16);
            // ä¸è¶³32位高位补零
            while (result.length() < 32) {
                result = "0" + result;
            }
            return result;
        } catch (Exception e) {
            return null;
        }
    }
}
src/main/java/com/se/simu/service/GedbService.java
@@ -10,6 +10,7 @@
import com.se.simu.domain.dto.GeFile;
import com.se.simu.domain.dto.GeLayer;
import com.se.simu.domain.po.DataPo;
import com.se.simu.helper.CaffeineHelper;
import com.se.simu.helper.RsaHelper;
import com.se.simu.helper.ShpHelper;
import com.se.simu.helper.StringHelper;
@@ -51,6 +52,8 @@
    @Resource
    RestTemplate restTemplate;
    private final static String TOKEN_KEY = "gedb_token";
    public boolean test(DataPo data) throws Exception {
        createPath(config.getInPath() + File.separator + data.getInPath());
@@ -73,11 +76,26 @@
    }
    public String getToken() throws Exception {
        Object obj = CaffeineHelper.get(TOKEN_KEY);
        if (obj instanceof String) {
            return obj.toString();
        }
        String token = getTokenByServer();
        if (null == token) throw new Exception("获取GEDB令牌失败");
        CaffeineHelper.put(TOKEN_KEY, token);
        return token;
    }
    private String getTokenByServer() throws Exception {
        Map<String, Object> map = new HashMap<>(2);
        map.put("userid", config.getUser());
        map.put("password", getPassword());
        JSONObject obj = restTemplate.postForObject(config.getHost() + "account-service/security/login", map, JSONObject.class);
        log.info(obj.toString());
        JSONObject data = obj.getJSONObject("data");
src/main/resources/application.yml
@@ -93,6 +93,7 @@
config:
  ver: 0.2
  cacheTime: 60
  # Gdal驱动目录
  gdalPath: E:/terrait/TianJin/Zip/release-1928-x64-dev/release-1928-x64/bin
  #inPath: D:\simu\in
src/main/resources/logback-spring.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- scan é…ç½®æ–‡ä»¶å¦‚果发生改变,将会被重新加载  scanPeriod æ£€æµ‹é—´é𔿗¶é—´-->
<configuration scan="true" scanPeriod="60 seconds" debug="false">
    <contextName>LFServer</contextName>
    <contextName>SimuServer</contextName>
    <!-- æ–‡ä»¶åç§° -->
    <property name="log.name.info" value="info" />
@@ -31,8 +31,8 @@
        </rollingPolicy>
        <append>true</append>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger Line:%-3L - %msg%n</pattern>
            <charset>utf-8</charset>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger Line:%-3L - %msg%n</pattern>
        </encoder>
        <!-- æ—¥å¿—级别过滤器 -->
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
@@ -79,8 +79,8 @@
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <!-- æ—¥å¿—格式 -->
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger Line:%-3L - %msg%n</pattern>
            <charset>utf-8</charset>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger Line:%-3L - %msg%n</pattern>
        </encoder>
        <!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息-->
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">