feat:模块名称调整

This commit is contained in:
曾文豪
2023-01-11 11:21:01 +08:00
parent 61a4a6494a
commit c721e4877f
125 changed files with 56 additions and 56 deletions

View File

@@ -0,0 +1,106 @@
package com.tiesheng.util.config;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.log.LogFactory;
import com.tiesheng.util.exception.ApiException;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author hao
*/
@Configuration
@ConfigurationProperties(prefix = "tiesheng.global")
public class GlobalConfig {
private String host;
private String service;
private String version;
///////////////////////////////////////////////////////////////////////////
// 逻辑方法
///////////////////////////////////////////////////////////////////////////
public String getContextPath() {
String context = SpringUtil.getProperty("server.servlet.context-path");
if (StrUtil.isEmpty(context)) {
context = "";
}
return context;
}
/**
* 构建完整的路径
*
* @param path
* @return
*/
public String buildPath(String path) {
if (StrUtil.isEmpty(path)) {
path = "";
}
if (!StrUtil.isEmpty(host) && !StrUtil.startWith(path, "http")) {
path = host + getContextPath() + path;
}
return path;
}
/**
* 重定向
*
* @param htmlDir 资源目录
* @param route
*/
public void redirect(String htmlDir, String route, HttpServletResponse response) {
PathMatchingResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
try {
Resource[] resources = patternResolver.getResources(String.format("classpath*:static/%s/*/index.html", htmlDir));
if (resources.length == 0) {
throw new ApiException("无法重定向,请检查资源");
}
String filename = resources[resources.length - 1].getURL().getPath();
filename = FileUtil.normalize(filename);
String path = buildPath(String.format("/%s%s#%s", htmlDir, StrUtil.subAfter(filename, htmlDir, true), route));
response.sendRedirect(path);
} catch (IOException e) {
LogFactory.get().info(e);
}
}
///////////////////////////////////////////////////////////////////////////
// setter\getter
///////////////////////////////////////////////////////////////////////////
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public String getService() {
return service;
}
public void setService(String service) {
this.service = service;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
}

View File

@@ -0,0 +1,68 @@
package com.tiesheng.util.config;
import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.log.LogFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
import java.io.FileNotFoundException;
import java.io.RandomAccessFile;
/**
* @author hao
*/
@Configuration
@ConfigurationProperties(prefix = "tiesheng.ip2region")
public class Ip2regionConfig {
private String dbUrl = "http://git.kepai365.com/zeng_wenhao/kepai-repo/raw/master/ipdb/ip2region.db";
private String dbPath = System.getProperty("user.dir") + "/ipdb/ip2region.db";
///////////////////////////////////////////////////////////////////////////
// 逻辑方法
///////////////////////////////////////////////////////////////////////////
@PostConstruct
public void downloadDbFile() {
if (!FileUtil.exist(dbPath)) {
LogFactory.get().info("download ip2region file start");
HttpUtil.downloadFile(dbUrl, dbPath);
LogFactory.get().info("download ip2region file finish");
}
}
/**
* 获取db文件
*
* @return
*/
public RandomAccessFile getDbAccessFile() throws FileNotFoundException {
if (!FileUtil.exist(dbPath)) {
downloadDbFile();
}
return new RandomAccessFile(dbPath, "r");
}
///////////////////////////////////////////////////////////////////////////
// setter\getter
///////////////////////////////////////////////////////////////////////////
public String getDbUrl() {
return dbUrl;
}
public void setDbUrl(String dbUrl) {
this.dbUrl = dbUrl;
}
public String getDbPath() {
return dbPath;
}
public void setDbPath(String dbPath) {
this.dbPath = dbPath;
}
}