Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1736b5d991 | ||
|
|
fad3b80fae | ||
|
|
c5555cff1f | ||
|
|
ebc0964988 | ||
|
|
069b9892c6 |
110
backend/platform-common/pom.xml
Normal file
110
backend/platform-common/pom.xml
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.yfd</groupId>
|
||||||
|
<artifactId>platform</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>platform-common</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>Platform Common</name>
|
||||||
|
<description>Platform Common Module</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- Spring Boot Starter -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Spring Boot Quartz -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-quartz</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Spring Boot Security -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Hutool -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Apache Commons -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-codec</groupId>
|
||||||
|
<artifactId>commons-codec</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- POI -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi-ooxml</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- IP2Region -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.lionsoul</groupId>
|
||||||
|
<artifactId>ip2region</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- UserAgentUtils -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>eu.bitwalker</groupId>
|
||||||
|
<artifactId>UserAgentUtils</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- MyBatis-Plus Generator -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-generator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Freemarker (for MyBatis-Plus Generator) -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.freemarker</groupId>
|
||||||
|
<artifactId>freemarker</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<skip>true</skip>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
@ -0,0 +1,48 @@
|
|||||||
|
package com.yfd.platform.common.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一请求参数结构
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class RequestParams {
|
||||||
|
/**
|
||||||
|
* 分页参数
|
||||||
|
*/
|
||||||
|
private PageParams page;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序参数
|
||||||
|
*/
|
||||||
|
private SortParams sort;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 筛选条件
|
||||||
|
*/
|
||||||
|
private Map<String, Object> filter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 业务参数
|
||||||
|
*/
|
||||||
|
private Map<String, Object> params;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页参数类
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class PageParams {
|
||||||
|
private int pageSize;
|
||||||
|
private int pageNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序参数类
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class SortParams {
|
||||||
|
private String field;
|
||||||
|
private String direction;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
package com.yfd.platform.common.response;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一返回结构
|
||||||
|
*/
|
||||||
|
public class ResponseResult extends HashMap<String, Object> {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public ResponseResult() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResponseResult unlogin() {
|
||||||
|
return message("401", "未登录");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResponseResult error() {
|
||||||
|
return error("操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResponseResult success() {
|
||||||
|
return success("操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResponseResult error(String msg) {
|
||||||
|
ResponseResult json = new ResponseResult();
|
||||||
|
json.put((String)"code", "1");//错误
|
||||||
|
json.put((String)"msg", msg);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResponseResult message(String code, String msg) {
|
||||||
|
ResponseResult json = new ResponseResult();
|
||||||
|
json.put((String)"code", code);
|
||||||
|
json.put((String)"msg", msg);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResponseResult success(String msg) {
|
||||||
|
ResponseResult json = new ResponseResult();
|
||||||
|
json.put((String)"code", "0");//正常
|
||||||
|
json.put((String)"msg", msg);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResponseResult successData(Object obj) {
|
||||||
|
ResponseResult json = new ResponseResult();
|
||||||
|
json.put((String)"code", "0");//正常
|
||||||
|
json.put((String)"msg", "操作成功");
|
||||||
|
json.put("data", obj);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ResponseResult put(String key, Object value) {
|
||||||
|
super.put(key, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2020 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.yfd.platform.common.utils;
|
||||||
|
|
||||||
|
import com.yfd.platform.common.utils.SpringContextHolder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: liaojinlong
|
||||||
|
* @date: 2020/6/9 17:02
|
||||||
|
* @since: 1.0
|
||||||
|
* @see {@link SpringContextHolder}
|
||||||
|
* 针对某些初始化方法,在SpringContextHolder 初始化前时,<br>
|
||||||
|
* 可提交一个 提交回调任务。<br>
|
||||||
|
* 在SpringContextHolder 初始化后,进行回调使用
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface CallBack {
|
||||||
|
/**
|
||||||
|
* 回调执行方法
|
||||||
|
*/
|
||||||
|
void executor();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本回调任务名称
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
default String getCallBackName() {
|
||||||
|
return Thread.currentThread().getId() + ":" + this.getClass().getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,75 @@
|
|||||||
|
package com.yfd.platform.common.utils;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.OutputFile;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||||
|
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
// 演示例子,执行 main 方法控制台输入模块表名回车自动生成对应项目目录中
|
||||||
|
public class CodeGenerator {
|
||||||
|
|
||||||
|
public static String scanner(String tip) {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
StringBuilder help = new StringBuilder();
|
||||||
|
help.append("请输入" + tip + ":");
|
||||||
|
System.out.println(help.toString());
|
||||||
|
if (scanner.hasNext()) {
|
||||||
|
String ipt = scanner.next();
|
||||||
|
if (ipt != null && !ipt.trim().isEmpty()) {
|
||||||
|
return ipt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new RuntimeException("请输入正确的" + tip + "!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String projectPath = System.getProperty("user.dir");
|
||||||
|
String module = scanner("模块名称");
|
||||||
|
|
||||||
|
Map<OutputFile, String> pathInfo = new HashMap<>();
|
||||||
|
pathInfo.put(OutputFile.entity, projectPath + "/src/main/java/com/yfd/platform/" + module + "/domain");
|
||||||
|
pathInfo.put(OutputFile.mapper, projectPath + "/src/main/java/com/yfd/platform/" + module + "/mapper");
|
||||||
|
pathInfo.put(OutputFile.controller, projectPath + "/src/main/java/com/yfd/platform/" + module + "/controller");
|
||||||
|
pathInfo.put(OutputFile.serviceImpl, projectPath + "/src/main/java/com/yfd/platform/" + module + "/service/impl");
|
||||||
|
pathInfo.put(OutputFile.service, projectPath + "/src/main/java/com/yfd/platform/" + module + "/service");
|
||||||
|
pathInfo.put(OutputFile.xml, projectPath + "/src/main/resources/mapper/" + module);
|
||||||
|
|
||||||
|
FastAutoGenerator.create(
|
||||||
|
"jdbc:mysql://43.143.220.7:3306/frameworkdb2023?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&failOverReadOnly=false&allowMultiQueries=true&serverTimezone=Asia/Shanghai",
|
||||||
|
"root",
|
||||||
|
"zhengg7QkXa<gRqqQ2023")
|
||||||
|
.globalConfig(builder -> {
|
||||||
|
builder.author("TangWei")
|
||||||
|
.disableOpenDir()
|
||||||
|
.outputDir(projectPath + "/src/main/java");
|
||||||
|
})
|
||||||
|
.packageConfig(builder -> {
|
||||||
|
builder.parent("com.yfd.platform")
|
||||||
|
.moduleName(module)
|
||||||
|
.pathInfo(pathInfo);
|
||||||
|
})
|
||||||
|
.strategyConfig(builder -> {
|
||||||
|
builder.addInclude(scanner("表名,多个英文逗号分割").split(","))
|
||||||
|
.entityBuilder()
|
||||||
|
.enableLombok()
|
||||||
|
.naming(NamingStrategy.underline_to_camel)
|
||||||
|
.columnNaming(NamingStrategy.underline_to_camel)
|
||||||
|
.controllerBuilder()
|
||||||
|
.enableRestStyle()
|
||||||
|
.mapperBuilder()
|
||||||
|
.formatMapperFileName("%sMapper")
|
||||||
|
.serviceBuilder()
|
||||||
|
.formatServiceFileName("%sService")
|
||||||
|
.formatServiceImplFileName("%sServiceImpl")
|
||||||
|
.controllerBuilder()
|
||||||
|
.formatFileName("%sController");
|
||||||
|
})
|
||||||
|
.templateEngine(new FreemarkerTemplateEngine())
|
||||||
|
.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,8 +1,5 @@
|
|||||||
package com.yfd.platform.utils;
|
package com.yfd.platform.common.utils;
|
||||||
|
|
||||||
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
|
|
||||||
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
|
|
||||||
import org.jasypt.util.text.BasicTextEncryptor;
|
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
|
||||||
public class EncryptConfigUtil {
|
public class EncryptConfigUtil {
|
||||||
@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.yfd.platform.common.utils;
|
||||||
|
|
||||||
|
import javax.crypto.Cipher;
|
||||||
|
import javax.crypto.SecretKey;
|
||||||
|
import javax.crypto.SecretKeyFactory;
|
||||||
|
import javax.crypto.spec.DESKeySpec;
|
||||||
|
import javax.crypto.spec.IvParameterSpec;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密
|
||||||
|
* @author
|
||||||
|
* @date 2018-11-23
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class EncryptUtils {
|
||||||
|
|
||||||
|
private static final String STR_PARAM = "Passw0rd";
|
||||||
|
|
||||||
|
private static Cipher cipher;
|
||||||
|
|
||||||
|
private static final IvParameterSpec IV = new IvParameterSpec(STR_PARAM.getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
private static DESKeySpec getDesKeySpec(String source) throws Exception {
|
||||||
|
if (source == null || source.length() == 0){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
|
||||||
|
String strKey = "Passw0rd";
|
||||||
|
return new DESKeySpec(strKey.getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对称加密
|
||||||
|
*/
|
||||||
|
public static String desEncrypt(String source) throws Exception {
|
||||||
|
DESKeySpec desKeySpec = getDesKeySpec(source);
|
||||||
|
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
|
||||||
|
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
|
||||||
|
cipher.init(Cipher.ENCRYPT_MODE, secretKey, IV);
|
||||||
|
return byte2hex(
|
||||||
|
cipher.doFinal(source.getBytes(StandardCharsets.UTF_8))).toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对称解密
|
||||||
|
*/
|
||||||
|
public static String desDecrypt(String source) throws Exception {
|
||||||
|
byte[] src = hex2byte(source.getBytes(StandardCharsets.UTF_8));
|
||||||
|
DESKeySpec desKeySpec = getDesKeySpec(source);
|
||||||
|
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
|
||||||
|
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
|
||||||
|
cipher.init(Cipher.DECRYPT_MODE, secretKey, IV);
|
||||||
|
byte[] retByte = cipher.doFinal(src);
|
||||||
|
return new String(retByte);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String byte2hex(byte[] inStr) {
|
||||||
|
String stmp;
|
||||||
|
StringBuilder out = new StringBuilder(inStr.length * 2);
|
||||||
|
for (byte b : inStr) {
|
||||||
|
stmp = Integer.toHexString(b & 0xFF);
|
||||||
|
if (stmp.length() == 1) {
|
||||||
|
// 如果是0至F的单位字符串,则添加0
|
||||||
|
out.append("0").append(stmp);
|
||||||
|
} else {
|
||||||
|
out.append(stmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] hex2byte(byte[] b) {
|
||||||
|
int size = 2;
|
||||||
|
if ((b.length % size) != 0){
|
||||||
|
throw new IllegalArgumentException("长度不是偶数");
|
||||||
|
}
|
||||||
|
byte[] b2 = new byte[b.length / 2];
|
||||||
|
for (int n = 0; n < b.length; n += size) {
|
||||||
|
String item = new String(b, n, 2);
|
||||||
|
b2[n / 2] = (byte) Integer.parseInt(item, 16);
|
||||||
|
}
|
||||||
|
return b2;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,395 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.yfd.platform.common.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.io.IoUtil;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.poi.excel.BigExcelWriter;
|
||||||
|
import cn.hutool.poi.excel.ExcelUtil;
|
||||||
|
import com.yfd.platform.exception.BadRequestException;
|
||||||
|
import jakarta.servlet.ServletOutputStream;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.apache.poi.util.IOUtils;
|
||||||
|
import org.apache.poi.xssf.streaming.SXSSFSheet;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File工具类,扩展 hutool 工具包
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @date 2018-12-27
|
||||||
|
*/
|
||||||
|
public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(FileUtil.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统临时目录
|
||||||
|
* <br>
|
||||||
|
* windows 包含路径分割符,但Linux 不包含,
|
||||||
|
* 在windows \\==\ 前提下,
|
||||||
|
* 为安全起见 同意拼装 路径分割符,
|
||||||
|
* <pre>
|
||||||
|
* java.io.tmpdir
|
||||||
|
* windows : C:\Users/xxx\AppData\Local\Temp\
|
||||||
|
* linux: /temp
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public static final String SYS_TEM_DIR = System.getProperty("java.io.tmpdir") + File.separator;
|
||||||
|
/**
|
||||||
|
* 定义GB的计算常量
|
||||||
|
*/
|
||||||
|
private static final int GB = 1024 * 1024 * 1024;
|
||||||
|
/**
|
||||||
|
* 定义MB的计算常量
|
||||||
|
*/
|
||||||
|
private static final int MB = 1024 * 1024;
|
||||||
|
/**
|
||||||
|
* 定义KB的计算常量
|
||||||
|
*/
|
||||||
|
private static final int KB = 1024;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化小数
|
||||||
|
*/
|
||||||
|
private static final DecimalFormat DF = new DecimalFormat("0.00");
|
||||||
|
|
||||||
|
public static final String IMAGE = "image";
|
||||||
|
public static final String TXT = "document";
|
||||||
|
public static final String MUSIC = "music";
|
||||||
|
public static final String VIDEO = "video";
|
||||||
|
public static final String OTHER = "other";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MultipartFile转File
|
||||||
|
*/
|
||||||
|
public static File toFile(MultipartFile multipartFile) {
|
||||||
|
// 获取文件名
|
||||||
|
String fileName = multipartFile.getOriginalFilename();
|
||||||
|
// 获取文件后缀
|
||||||
|
String prefix = "." + getExtensionName(fileName);
|
||||||
|
File file = null;
|
||||||
|
try {
|
||||||
|
// 用uuid作为文件名,防止生成的临时文件重复
|
||||||
|
file = File.createTempFile(IdUtil.simpleUUID(), prefix);
|
||||||
|
// MultipartFile to File
|
||||||
|
multipartFile.transferTo(file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件扩展名,不带 .
|
||||||
|
*/
|
||||||
|
public static String getExtensionName(String filename) {
|
||||||
|
if ((filename != null) && (filename.length() > 0)) {
|
||||||
|
int dot = filename.lastIndexOf('.');
|
||||||
|
if ((dot > -1) && (dot < (filename.length() - 1))) {
|
||||||
|
return filename.substring(dot + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Java文件操作 获取不带扩展名的文件名
|
||||||
|
*/
|
||||||
|
public static String getFileNameNoEx(String filename) {
|
||||||
|
if ((filename != null) && (filename.length() > 0)) {
|
||||||
|
int dot = filename.lastIndexOf('.');
|
||||||
|
if ((dot > -1) && (dot < (filename.length()))) {
|
||||||
|
return filename.substring(0, dot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件大小转换
|
||||||
|
*/
|
||||||
|
public static String getSize(long size) {
|
||||||
|
String resultSize;
|
||||||
|
if (size / GB >= 1) {
|
||||||
|
//如果当前Byte的值大于等于1GB
|
||||||
|
resultSize = DF.format(size / (float) GB) + "GB ";
|
||||||
|
} else if (size / MB >= 1) {
|
||||||
|
//如果当前Byte的值大于等于1MB
|
||||||
|
resultSize = DF.format(size / (float) MB) + "MB ";
|
||||||
|
} else if (size / KB >= 1) {
|
||||||
|
//如果当前Byte的值大于等于1KB
|
||||||
|
resultSize = DF.format(size / (float) KB) + "KB ";
|
||||||
|
} else {
|
||||||
|
resultSize = size + "B ";
|
||||||
|
}
|
||||||
|
return resultSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* inputStream 转 File
|
||||||
|
*/
|
||||||
|
static File inputStreamToFile(InputStream ins, String name) throws Exception {
|
||||||
|
File file = new File(SYS_TEM_DIR + name);
|
||||||
|
if (file.exists()) {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
OutputStream os = new FileOutputStream(file);
|
||||||
|
int bytesRead;
|
||||||
|
int len = 8192;
|
||||||
|
byte[] buffer = new byte[len];
|
||||||
|
while ((bytesRead = ins.read(buffer, 0, len)) != -1) {
|
||||||
|
os.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
os.close();
|
||||||
|
ins.close();
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将文件名解析成文件的上传路径
|
||||||
|
*/
|
||||||
|
public static File upload(MultipartFile file, String filePath) {
|
||||||
|
Date date = new Date();
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmssS");
|
||||||
|
String name = getFileNameNoEx(file.getOriginalFilename());
|
||||||
|
String suffix = getExtensionName(file.getOriginalFilename());
|
||||||
|
String nowStr = "-" + format.format(date);
|
||||||
|
try {
|
||||||
|
String fileName = name + "." + suffix;
|
||||||
|
String path = filePath +File.separator + fileName;
|
||||||
|
// getCanonicalFile 可解析正确各种路径
|
||||||
|
File dest = new File(path).getCanonicalFile();
|
||||||
|
// 检测是否存在目录
|
||||||
|
if (!dest.getParentFile().exists()) {
|
||||||
|
if (!dest.getParentFile().mkdirs()) {
|
||||||
|
System.out.println("was not successful.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 文件写入
|
||||||
|
file.transferTo(dest);
|
||||||
|
return dest;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将文件名解析成文件的上传路径
|
||||||
|
* file 上传的文件
|
||||||
|
* filePath 存储路径
|
||||||
|
* tofilename 保存文件名称
|
||||||
|
|
||||||
|
*/
|
||||||
|
public static File upload(MultipartFile file, String filePath,String tofilename) {
|
||||||
|
try {
|
||||||
|
String filename = filePath + File.separator + tofilename;
|
||||||
|
File dest = new File(filename).getCanonicalFile();
|
||||||
|
// 检测是否存在目录
|
||||||
|
if (!dest.getParentFile().exists()) {
|
||||||
|
if (!dest.getParentFile().mkdirs()) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 文件写入
|
||||||
|
file.transferTo(dest);
|
||||||
|
return dest;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出excel
|
||||||
|
*/
|
||||||
|
public static void downloadExcel(List<Map<String, Object>> list, HttpServletResponse response) throws IOException {
|
||||||
|
String tempPath = SYS_TEM_DIR + IdUtil.fastSimpleUUID() + ".xlsx";
|
||||||
|
String filename = "record"+cn.hutool.core.date.DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
|
||||||
|
File file = new File(tempPath);
|
||||||
|
BigExcelWriter writer = ExcelUtil.getBigWriter(file);
|
||||||
|
// 一次性写出内容,使用默认样式,强制输出标题
|
||||||
|
writer.write(list, true);
|
||||||
|
SXSSFSheet sheet = (SXSSFSheet)writer.getSheet();
|
||||||
|
//上面需要强转SXSSFSheet 不然没有trackAllColumnsForAutoSizing方法
|
||||||
|
sheet.trackAllColumnsForAutoSizing();
|
||||||
|
//列宽自适应
|
||||||
|
writer.autoSizeColumnAll();
|
||||||
|
//response为HttpServletResponse对象
|
||||||
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
||||||
|
//test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
|
||||||
|
response.setHeader("Content-Disposition", "attachment;filename="+filename+".xlsx");
|
||||||
|
ServletOutputStream out = response.getOutputStream();
|
||||||
|
// 终止后删除临时文件
|
||||||
|
file.deleteOnExit();
|
||||||
|
writer.flush(out, true);
|
||||||
|
//此处记得关闭输出Servlet流
|
||||||
|
IoUtil.close(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getFileType(String type) {
|
||||||
|
String documents = "txt doc pdf ppt pps xlsx xls docx";
|
||||||
|
String music = "mp3 wav wma mpa ram ra aac aif m4a";
|
||||||
|
String video = "avi mpg mpe mpeg asf wmv mov qt rm mp4 flv m4v webm ogv ogg";
|
||||||
|
String image = "bmp dib pcp dif wmf gif jpg tif eps psd cdr iff tga pcd mpt png jpeg";
|
||||||
|
if (image.contains(type)) {
|
||||||
|
return IMAGE;
|
||||||
|
} else if (documents.contains(type)) {
|
||||||
|
return TXT;
|
||||||
|
} else if (music.contains(type)) {
|
||||||
|
return MUSIC;
|
||||||
|
} else if (video.contains(type)) {
|
||||||
|
return VIDEO;
|
||||||
|
} else {
|
||||||
|
return OTHER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkSize(long maxSize, long size) {
|
||||||
|
// 1M
|
||||||
|
int len = 1024 * 1024;
|
||||||
|
if (size > (maxSize * len)) {
|
||||||
|
throw new BadRequestException("文件超出规定大小");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断两个文件是否相同
|
||||||
|
*/
|
||||||
|
public static boolean check(File file1, File file2) {
|
||||||
|
String img1Md5 = getMd5(file1);
|
||||||
|
String img2Md5 = getMd5(file2);
|
||||||
|
return img1Md5.equals(img2Md5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断两个文件是否相同
|
||||||
|
*/
|
||||||
|
public static boolean check(String file1Md5, String file2Md5) {
|
||||||
|
return file1Md5.equals(file2Md5);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] getByte(File file) {
|
||||||
|
// 得到文件长度
|
||||||
|
byte[] b = new byte[(int) file.length()];
|
||||||
|
try {
|
||||||
|
InputStream in = new FileInputStream(file);
|
||||||
|
try {
|
||||||
|
System.out.println(in.read(b));
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getMd5(byte[] bytes) {
|
||||||
|
// 16进制字符
|
||||||
|
char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||||
|
try {
|
||||||
|
MessageDigest mdTemp = MessageDigest.getInstance("MD5");
|
||||||
|
mdTemp.update(bytes);
|
||||||
|
byte[] md = mdTemp.digest();
|
||||||
|
int j = md.length;
|
||||||
|
char[] str = new char[j * 2];
|
||||||
|
int k = 0;
|
||||||
|
// 移位 输出字符串
|
||||||
|
for (byte byte0 : md) {
|
||||||
|
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
|
||||||
|
str[k++] = hexDigits[byte0 & 0xf];
|
||||||
|
}
|
||||||
|
return new String(str);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载文件
|
||||||
|
*
|
||||||
|
* @param request /
|
||||||
|
* @param response /
|
||||||
|
* @param file /
|
||||||
|
*/
|
||||||
|
public static void downloadFile(HttpServletRequest request, HttpServletResponse response, File file, boolean deleteOnExit) {
|
||||||
|
response.setCharacterEncoding(request.getCharacterEncoding());
|
||||||
|
response.setContentType("application/octet-stream");
|
||||||
|
FileInputStream fis = null;
|
||||||
|
try {
|
||||||
|
fis = new FileInputStream(file);
|
||||||
|
response.setHeader("Content-Disposition", "attachment; filename=" + file.getName());
|
||||||
|
IOUtils.copy(fis, response.getOutputStream());
|
||||||
|
response.flushBuffer();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
} finally {
|
||||||
|
if (fis != null) {
|
||||||
|
try {
|
||||||
|
fis.close();
|
||||||
|
if (deleteOnExit) {
|
||||||
|
file.deleteOnExit();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 预览PDF文件
|
||||||
|
*
|
||||||
|
* @param filepath /
|
||||||
|
* @param response /
|
||||||
|
*/
|
||||||
|
public static void viewPDF(String filepath, HttpServletResponse response) throws IOException {
|
||||||
|
File file=new File(filepath);
|
||||||
|
String originFileName=file.getName(); //中文编码
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
String showName= StrUtil.isNotBlank(originFileName)?originFileName:file.getName();
|
||||||
|
showName= URLDecoder.decode(showName,"UTF-8");
|
||||||
|
response.setHeader("Content-Disposition","inline;fileName="+new String(showName.getBytes(), "ISO8859-1")+";fileName*=UTF-8''"+ new String(showName.getBytes(), "ISO8859-1"));
|
||||||
|
FileInputStream fis = new FileInputStream(file);
|
||||||
|
response.setHeader("content-type", "application/pdf");
|
||||||
|
response.setContentType("application/pdf; charset=utf-8");
|
||||||
|
IOUtils.copy(fis, response.getOutputStream());
|
||||||
|
fis.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getMd5(File file) {
|
||||||
|
return getMd5(getByte(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,152 @@
|
|||||||
|
package com.yfd.platform.common.utils;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class ObjectConverterUtil {
|
||||||
|
|
||||||
|
// 日期时间格式
|
||||||
|
private static final DateTimeFormatter DATE_TIME_FORMATTER =
|
||||||
|
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 List<Map> 中的大写字段名转换为与实体类一致的小写格式
|
||||||
|
* 适用于 Oracle 数据库查询结果转换
|
||||||
|
* 时间类型字段会转换为字符串格式
|
||||||
|
*
|
||||||
|
* @param entityClass 实体类 Class 对象
|
||||||
|
* @param sourceList 源数据列表(字段名为大写)
|
||||||
|
* @return 转换后的列表(字段名与实体类一致)
|
||||||
|
*/
|
||||||
|
public static <T> List<Map<String, Object>> convertMapFieldsToEntityFormat(
|
||||||
|
Class<T> entityClass,
|
||||||
|
List<Map<String, Object>> sourceList) {
|
||||||
|
|
||||||
|
if (sourceList == null || sourceList.isEmpty()) {
|
||||||
|
return sourceList;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取实体类的所有字段及类型
|
||||||
|
Map<String, Field> fieldMap = new HashMap<>();
|
||||||
|
for (Field field : entityClass.getDeclaredFields()) {
|
||||||
|
fieldMap.put(field.getName(), field);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 转换每个 Map
|
||||||
|
return sourceList.stream().map(sourceMap -> {
|
||||||
|
Map<String, Object> targetMap = new HashMap<>();
|
||||||
|
|
||||||
|
for (Map.Entry<String, Object> entry : sourceMap.entrySet()) {
|
||||||
|
String dbColumnName = entry.getKey(); // 数据库列名(大写)
|
||||||
|
Object value = entry.getValue();
|
||||||
|
|
||||||
|
// 将大写列名转为小写
|
||||||
|
String lowerCaseName = dbColumnName.toLowerCase();
|
||||||
|
|
||||||
|
// 如果实体类中有对应的字段
|
||||||
|
if (fieldMap.containsKey(lowerCaseName)) {
|
||||||
|
Field field = fieldMap.get(lowerCaseName);
|
||||||
|
String fieldType = field.getType().getSimpleName();
|
||||||
|
|
||||||
|
// 处理时间类型,转换为字符串
|
||||||
|
if ("Timestamp".equals(fieldType) || "Date".equals(fieldType) ||
|
||||||
|
"LocalDateTime".equals(fieldType)) {
|
||||||
|
targetMap.put(lowerCaseName, formatDateTimeValue(value));
|
||||||
|
} else {
|
||||||
|
targetMap.put(lowerCaseName, value);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 如果实体类中没有对应字段,保留原列名(转小写)
|
||||||
|
targetMap.put(lowerCaseName, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return targetMap;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用方法:将单个 Map 的大写字段转换为实体类格式
|
||||||
|
* 时间类型字段会转换为字符串格式
|
||||||
|
*
|
||||||
|
* @param entityClass 实体类 Class 对象
|
||||||
|
* @param sourceMap 源 Map(字段名为大写)
|
||||||
|
* @return 转换后的 Map(字段名与实体类一致)
|
||||||
|
*/
|
||||||
|
public static <T> Map<String, Object> convertSingleMapFieldsToEntityFormat(
|
||||||
|
Class<T> entityClass,
|
||||||
|
Map<String, Object> sourceMap) {
|
||||||
|
|
||||||
|
if (sourceMap == null) {
|
||||||
|
return sourceMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取实体类的所有字段及类型
|
||||||
|
Map<String, Field> fieldMap = new HashMap<>();
|
||||||
|
for (Field field : entityClass.getDeclaredFields()) {
|
||||||
|
fieldMap.put(field.getName(), field);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Object> targetMap = new HashMap<>();
|
||||||
|
|
||||||
|
for (Map.Entry<String, Object> entry : sourceMap.entrySet()) {
|
||||||
|
String dbColumnName = entry.getKey();
|
||||||
|
Object value = entry.getValue();
|
||||||
|
|
||||||
|
// 将大写列名转为小写
|
||||||
|
String lowerCaseName = dbColumnName.toLowerCase();
|
||||||
|
|
||||||
|
// 验证字段是否存在于实体类中
|
||||||
|
if (fieldMap.containsKey(lowerCaseName)) {
|
||||||
|
Field field = fieldMap.get(lowerCaseName);
|
||||||
|
String fieldType = field.getType().getSimpleName();
|
||||||
|
|
||||||
|
// 处理时间类型,转换为字符串
|
||||||
|
if ("Timestamp".equals(fieldType) || "Date".equals(fieldType) ||
|
||||||
|
"LocalDateTime".equals(fieldType)) {
|
||||||
|
targetMap.put(lowerCaseName, formatDateTimeValue(value));
|
||||||
|
} else {
|
||||||
|
targetMap.put(lowerCaseName, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return targetMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化时间类型值为字符串
|
||||||
|
*
|
||||||
|
* @param value 时间值(可能是 Timestamp、Date 或 LocalDateTime)
|
||||||
|
* @return 格式化后的字符串,如果为 null 则返回 null
|
||||||
|
*/
|
||||||
|
private static String formatDateTimeValue(Object value) {
|
||||||
|
if (value == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value instanceof Timestamp) {
|
||||||
|
LocalDateTime localDateTime = ((Timestamp) value).toLocalDateTime();
|
||||||
|
return localDateTime.format(DATE_TIME_FORMATTER);
|
||||||
|
} else if (value instanceof Date) {
|
||||||
|
// 包括 java.sql.Date 和 java.util.Date
|
||||||
|
LocalDateTime localDateTime = ((Date) value).toInstant()
|
||||||
|
.atZone(java.time.ZoneId.systemDefault())
|
||||||
|
.toLocalDateTime();
|
||||||
|
return localDateTime.format(DATE_TIME_FORMATTER);
|
||||||
|
} else if (value instanceof LocalDateTime) {
|
||||||
|
return ((LocalDateTime) value).format(DATE_TIME_FORMATTER);
|
||||||
|
} else {
|
||||||
|
// 其他类型直接转字符串
|
||||||
|
return value.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
package com.yfd.platform.common.utils;
|
||||||
|
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.Properties;
|
||||||
|
/******************************
|
||||||
|
* 用途说明:
|
||||||
|
* 作者姓名: pcj
|
||||||
|
* 创建时间: 2022/9/20 14:31
|
||||||
|
******************************/
|
||||||
|
public class PropertiesUtils {
|
||||||
|
public final static String RESOURCE_PATH = "application.properties";
|
||||||
|
|
||||||
|
public final static Properties properties = new Properties();
|
||||||
|
|
||||||
|
public static String getPropertyField(String parameter) {
|
||||||
|
//对应resources目录下的资源路径
|
||||||
|
ClassPathResource resource = new ClassPathResource(RESOURCE_PATH);
|
||||||
|
try {
|
||||||
|
properties.load(new InputStreamReader(resource.getInputStream(), "gbk"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return properties.getProperty(parameter);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.yfd.platform.common.utils;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 HttpServletRequest
|
||||||
|
* @author
|
||||||
|
* @date 2018-11-24
|
||||||
|
*/
|
||||||
|
public class RequestHolder {
|
||||||
|
|
||||||
|
public static HttpServletRequest getHttpServletRequest() {
|
||||||
|
return ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,190 @@
|
|||||||
|
package com.yfd.platform.common.utils;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
|
||||||
|
import javax.crypto.Cipher;
|
||||||
|
import java.security.*;
|
||||||
|
import java.security.interfaces.RSAPrivateKey;
|
||||||
|
import java.security.interfaces.RSAPublicKey;
|
||||||
|
import java.security.spec.PKCS8EncodedKeySpec;
|
||||||
|
import java.security.spec.X509EncodedKeySpec;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author https://www.cnblogs.com/nihaorz/p/10690643.html
|
||||||
|
* @description Rsa 工具类,公钥私钥生成,加解密
|
||||||
|
* @date 2020-05-18
|
||||||
|
**/
|
||||||
|
public class RsaUtils {
|
||||||
|
|
||||||
|
private static final String SRC = "123456";
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
System.out.println("\n");
|
||||||
|
// RsaKeyPair keyPair = generateKeyPair();
|
||||||
|
String publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANL378k3RiZHWx5AfJqdH9xRNBmD9wGD2iRe41HdTNF8RUhNnHit5NpMNtGL0NPTSSpPjjI1kJfVorRvaQerUgkCAwEAAQ==";
|
||||||
|
String privateKey = "MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEA0vfvyTdGJkdbHkB8\n" +
|
||||||
|
"mp0f3FE0GYP3AYPaJF7jUd1M0XxFSE2ceK3k2kw20YvQ09NJKk+OMjWQl9WitG9p\n" +
|
||||||
|
"B6tSCQIDAQABAkA2SimBrWC2/wvauBuYqjCFwLvYiRYqZKThUS3MZlebXJiLB+Ue\n" +
|
||||||
|
"/gUifAAKIg1avttUZsHBHrop4qfJCwAI0+YRAiEA+W3NK/RaXtnRqmoUUkb59zsZ\n" +
|
||||||
|
"UBLpvZgQPfj1MhyHDz0CIQDYhsAhPJ3mgS64NbUZmGWuuNKp5coY2GIj/zYDMJp6\n" +
|
||||||
|
"vQIgUueLFXv/eZ1ekgz2Oi67MNCk5jeTF2BurZqNLR3MSmUCIFT3Q6uHMtsB9Eha\n" +
|
||||||
|
"4u7hS31tj1UWE+D+ADzp59MGnoftAiBeHT7gDMuqeJHPL4b+kC+gzV4FGTfhR9q3\n" +
|
||||||
|
"tTbklZkD2A==";
|
||||||
|
RsaKeyPair keyPair =new RsaKeyPair(publicKey, privateKey);
|
||||||
|
System.out.println("私钥:" + keyPair.getPrivateKey());
|
||||||
|
System.out.println("\n");
|
||||||
|
test1(keyPair);
|
||||||
|
System.out.println("\n");
|
||||||
|
// test2(keyPair);
|
||||||
|
System.out.println("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公钥加密私钥解密
|
||||||
|
*/
|
||||||
|
private static void test1(RsaKeyPair keyPair) throws Exception {
|
||||||
|
System.out.println("***************** 公钥加密私钥解密开始 *****************");
|
||||||
|
String text1 = encryptByPublicKey(keyPair.getPublicKey(), RsaUtils.SRC);
|
||||||
|
String text2 = decryptByPrivateKey(keyPair.getPrivateKey(), text1);
|
||||||
|
System.out.println("加密前:" + RsaUtils.SRC);
|
||||||
|
System.out.println("加密后:" + text1);
|
||||||
|
System.out.println("解密后:" + text2);
|
||||||
|
if (RsaUtils.SRC.equals(text2)) {
|
||||||
|
System.out.println("解密字符串和原始字符串一致,解密成功");
|
||||||
|
} else {
|
||||||
|
System.out.println("解密字符串和原始字符串不一致,解密失败");
|
||||||
|
}
|
||||||
|
System.out.println("***************** 公钥加密私钥解密结束 *****************");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 私钥加密公钥解密
|
||||||
|
* @throws Exception /
|
||||||
|
*/
|
||||||
|
private static void test2(RsaKeyPair keyPair) throws Exception {
|
||||||
|
System.out.println("***************** 私钥加密公钥解密开始 *****************");
|
||||||
|
String text1 = encryptByPrivateKey(keyPair.getPrivateKey(), RsaUtils.SRC);
|
||||||
|
String text2 = decryptByPublicKey(keyPair.getPublicKey(), text1);
|
||||||
|
System.out.println("加密前:" + RsaUtils.SRC);
|
||||||
|
System.out.println("加密后:" + text1);
|
||||||
|
System.out.println("解密后:" + text2);
|
||||||
|
if (RsaUtils.SRC.equals(text2)) {
|
||||||
|
System.out.println("解密字符串和原始字符串一致,解密成功");
|
||||||
|
} else {
|
||||||
|
System.out.println("解密字符串和原始字符串不一致,解密失败");
|
||||||
|
}
|
||||||
|
System.out.println("***************** 私钥加密公钥解密结束 *****************");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公钥解密
|
||||||
|
*
|
||||||
|
* @param publicKeyText 公钥
|
||||||
|
* @param text 待解密的信息
|
||||||
|
* @return /
|
||||||
|
* @throws Exception /
|
||||||
|
*/
|
||||||
|
public static String decryptByPublicKey(String publicKeyText, String text) throws Exception {
|
||||||
|
X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(Base64.decodeBase64(publicKeyText));
|
||||||
|
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||||
|
PublicKey publicKey = keyFactory.generatePublic(x509EncodedKeySpec);
|
||||||
|
Cipher cipher = Cipher.getInstance("RSA");
|
||||||
|
cipher.init(Cipher.DECRYPT_MODE, publicKey);
|
||||||
|
byte[] result = cipher.doFinal(Base64.decodeBase64(text));
|
||||||
|
return new String(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 私钥加密
|
||||||
|
*
|
||||||
|
* @param privateKeyText 私钥
|
||||||
|
* @param text 待加密的信息
|
||||||
|
* @return /
|
||||||
|
* @throws Exception /
|
||||||
|
*/
|
||||||
|
public static String encryptByPrivateKey(String privateKeyText, String text) throws Exception {
|
||||||
|
PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(Base64.decodeBase64(privateKeyText));
|
||||||
|
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||||
|
PrivateKey privateKey = keyFactory.generatePrivate(pkcs8EncodedKeySpec);
|
||||||
|
Cipher cipher = Cipher.getInstance("RSA");
|
||||||
|
cipher.init(Cipher.ENCRYPT_MODE, privateKey);
|
||||||
|
byte[] result = cipher.doFinal(text.getBytes());
|
||||||
|
return Base64.encodeBase64String(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 私钥解密
|
||||||
|
*
|
||||||
|
* @param privateKeyText 私钥
|
||||||
|
* @param text 待解密的文本
|
||||||
|
* @return /
|
||||||
|
* @throws Exception /
|
||||||
|
*/
|
||||||
|
public static String decryptByPrivateKey(String privateKeyText, String text) throws Exception {
|
||||||
|
PKCS8EncodedKeySpec pkcs8EncodedKeySpec5 = new PKCS8EncodedKeySpec(Base64.decodeBase64(privateKeyText));
|
||||||
|
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||||
|
PrivateKey privateKey = keyFactory.generatePrivate(pkcs8EncodedKeySpec5);
|
||||||
|
Cipher cipher = Cipher.getInstance("RSA");
|
||||||
|
cipher.init(Cipher.DECRYPT_MODE, privateKey);
|
||||||
|
byte[] result = cipher.doFinal(Base64.decodeBase64(text));
|
||||||
|
return new String(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公钥加密
|
||||||
|
*
|
||||||
|
* @param publicKeyText 公钥
|
||||||
|
* @param text 待加密的文本
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
public static String encryptByPublicKey(String publicKeyText, String text) throws Exception {
|
||||||
|
X509EncodedKeySpec x509EncodedKeySpec2 = new X509EncodedKeySpec(Base64.decodeBase64(publicKeyText));
|
||||||
|
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||||
|
PublicKey publicKey = keyFactory.generatePublic(x509EncodedKeySpec2);
|
||||||
|
Cipher cipher = Cipher.getInstance("RSA");
|
||||||
|
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
|
||||||
|
byte[] result = cipher.doFinal(text.getBytes());
|
||||||
|
return Base64.encodeBase64String(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建RSA密钥对
|
||||||
|
*
|
||||||
|
* @return /
|
||||||
|
* @throws NoSuchAlgorithmException /
|
||||||
|
*/
|
||||||
|
public static RsaKeyPair generateKeyPair() throws NoSuchAlgorithmException {
|
||||||
|
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
|
||||||
|
keyPairGenerator.initialize(1024);
|
||||||
|
KeyPair keyPair = keyPairGenerator.generateKeyPair();
|
||||||
|
RSAPublicKey rsaPublicKey = (RSAPublicKey) keyPair.getPublic();
|
||||||
|
RSAPrivateKey rsaPrivateKey = (RSAPrivateKey) keyPair.getPrivate();
|
||||||
|
String publicKeyString = Base64.encodeBase64String(rsaPublicKey.getEncoded());
|
||||||
|
String privateKeyString = Base64.encodeBase64String(rsaPrivateKey.getEncoded());
|
||||||
|
return new RsaKeyPair(publicKeyString, privateKeyString);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RSA密钥对对象
|
||||||
|
*/
|
||||||
|
public static class RsaKeyPair {
|
||||||
|
|
||||||
|
private final String publicKey;
|
||||||
|
private final String privateKey;
|
||||||
|
|
||||||
|
public RsaKeyPair(String publicKey, String privateKey) {
|
||||||
|
this.publicKey = publicKey;
|
||||||
|
this.privateKey = privateKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPublicKey() {
|
||||||
|
return publicKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrivateKey() {
|
||||||
|
return privateKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,145 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.yfd.platform.common.utils;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.factory.DisposableBean;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
/**
|
||||||
|
* @author Jie
|
||||||
|
* @date 2019-01-07
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class SpringContextHolder implements ApplicationContextAware, DisposableBean {
|
||||||
|
|
||||||
|
private static ApplicationContext applicationContext = null;
|
||||||
|
private static final List<CallBack> CALL_BACKS = new ArrayList<>();
|
||||||
|
private static boolean addCallback = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 针对 某些初始化方法,在SpringContextHolder 未初始化时 提交回调方法。
|
||||||
|
* 在SpringContextHolder 初始化后,进行回调使用
|
||||||
|
*
|
||||||
|
* @param callBack 回调函数
|
||||||
|
*/
|
||||||
|
public synchronized static void addCallBacks(CallBack callBack) {
|
||||||
|
if (addCallback) {
|
||||||
|
SpringContextHolder.CALL_BACKS.add(callBack);
|
||||||
|
} else {
|
||||||
|
log.warn("CallBack:{} 已无法添加!立即执行", callBack.getCallBackName());
|
||||||
|
callBack.executor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T> T getBean(String name) {
|
||||||
|
assertContextInjected();
|
||||||
|
return (T) applicationContext.getBean(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型.
|
||||||
|
*/
|
||||||
|
public static <T> T getBean(Class<T> requiredType) {
|
||||||
|
assertContextInjected();
|
||||||
|
return applicationContext.getBean(requiredType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取SpringBoot 配置信息
|
||||||
|
*
|
||||||
|
* @param property 属性key
|
||||||
|
* @param defaultValue 默认值
|
||||||
|
* @param requiredType 返回类型
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
public static <T> T getProperties(String property, T defaultValue, Class<T> requiredType) {
|
||||||
|
T result = defaultValue;
|
||||||
|
try {
|
||||||
|
result = getBean(Environment.class).getProperty(property, requiredType);
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取SpringBoot 配置信息
|
||||||
|
*
|
||||||
|
* @param property 属性key
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
public static String getProperties(String property) {
|
||||||
|
return getProperties(property, null, String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取SpringBoot 配置信息
|
||||||
|
*
|
||||||
|
* @param property 属性key
|
||||||
|
* @param requiredType 返回类型
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
public static <T> T getProperties(String property, Class<T> requiredType) {
|
||||||
|
return getProperties(property, null, requiredType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查ApplicationContext不为空.
|
||||||
|
*/
|
||||||
|
private static void assertContextInjected() {
|
||||||
|
if (applicationContext == null) {
|
||||||
|
throw new IllegalStateException("applicaitonContext属性未注入, 请在applicationContext" +
|
||||||
|
".xml中定义SpringContextHolder或在SpringBoot启动类中注册SpringContextHolder.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除SpringContextHolder中的ApplicationContext为Null.
|
||||||
|
*/
|
||||||
|
private static void clearHolder() {
|
||||||
|
log.debug("清除SpringContextHolder中的ApplicationContext:"
|
||||||
|
+ applicationContext);
|
||||||
|
applicationContext = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
SpringContextHolder.clearHolder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||||
|
if (SpringContextHolder.applicationContext != null) {
|
||||||
|
log.warn("SpringContextHolder中的ApplicationContext被覆盖, 原有ApplicationContext为:" + SpringContextHolder.applicationContext);
|
||||||
|
}
|
||||||
|
SpringContextHolder.applicationContext = applicationContext;
|
||||||
|
if (addCallback) {
|
||||||
|
for (CallBack callBack : SpringContextHolder.CALL_BACKS) {
|
||||||
|
callBack.executor();
|
||||||
|
}
|
||||||
|
CALL_BACKS.clear();
|
||||||
|
}
|
||||||
|
SpringContextHolder.addCallback = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,306 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.yfd.platform.common.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.http.HttpUtil;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.yfd.platform.constant.Constant;
|
||||||
|
import eu.bitwalker.useragentutils.Browser;
|
||||||
|
import eu.bitwalker.useragentutils.UserAgent;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.lionsoul.ip2region.DataBlock;
|
||||||
|
import org.lionsoul.ip2region.DbConfig;
|
||||||
|
import org.lionsoul.ip2region.DbSearcher;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author
|
||||||
|
* 字符串工具类, 继承org.apache.commons.lang3.StringUtils类
|
||||||
|
*/
|
||||||
|
public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(StringUtils.class);
|
||||||
|
private static boolean ipLocal = false;
|
||||||
|
private static File file ;
|
||||||
|
private static DbConfig config;
|
||||||
|
private static final char SEPARATOR = '_';
|
||||||
|
private static final String UNKNOWN = "unknown";
|
||||||
|
|
||||||
|
static {
|
||||||
|
SpringContextHolder.addCallBacks(() -> {
|
||||||
|
StringUtils.ipLocal = SpringContextHolder.getProperties("ip.local-parsing", false, Boolean.class);
|
||||||
|
if (ipLocal) {
|
||||||
|
/*
|
||||||
|
* 此文件为独享 ,不必关闭
|
||||||
|
*/
|
||||||
|
String path = "ip2region/ip2region.db";
|
||||||
|
String name = "ip2region.db";
|
||||||
|
try {
|
||||||
|
config = new DbConfig();
|
||||||
|
file = FileUtil.inputStreamToFile(new ClassPathResource(path).getInputStream(), name);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 驼峰命名法工具
|
||||||
|
*
|
||||||
|
* @return toCamelCase(" hello_world ") == "helloWorld"
|
||||||
|
* toCapitalizeCamelCase("hello_world") == "HelloWorld"
|
||||||
|
* toUnderScoreCase("helloWorld") = "hello_world"
|
||||||
|
*/
|
||||||
|
public static String toCamelCase(String s) {
|
||||||
|
if (s == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
s = s.toLowerCase();
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder(s.length());
|
||||||
|
boolean upperCase = false;
|
||||||
|
for (int i = 0; i < s.length(); i++) {
|
||||||
|
char c = s.charAt(i);
|
||||||
|
|
||||||
|
if (c == SEPARATOR) {
|
||||||
|
upperCase = true;
|
||||||
|
} else if (upperCase) {
|
||||||
|
sb.append(Character.toUpperCase(c));
|
||||||
|
upperCase = false;
|
||||||
|
} else {
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 驼峰命名法工具
|
||||||
|
*
|
||||||
|
* @return toCamelCase(" hello_world ") == "helloWorld"
|
||||||
|
* toCapitalizeCamelCase("hello_world") == "HelloWorld"
|
||||||
|
* toUnderScoreCase("helloWorld") = "hello_world"
|
||||||
|
*/
|
||||||
|
public static String toCapitalizeCamelCase(String s) {
|
||||||
|
if (s == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
s = toCamelCase(s);
|
||||||
|
return s.substring(0, 1).toUpperCase() + s.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 驼峰命名法工具
|
||||||
|
*
|
||||||
|
* @return toCamelCase(" hello_world ") == "helloWorld"
|
||||||
|
* toCapitalizeCamelCase("hello_world") == "HelloWorld"
|
||||||
|
* toUnderScoreCase("helloWorld") = "hello_world"
|
||||||
|
*/
|
||||||
|
static String toUnderScoreCase(String s) {
|
||||||
|
if (s == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
boolean upperCase = false;
|
||||||
|
for (int i = 0; i < s.length(); i++) {
|
||||||
|
char c = s.charAt(i);
|
||||||
|
|
||||||
|
boolean nextUpperCase = true;
|
||||||
|
|
||||||
|
if (i < (s.length() - 1)) {
|
||||||
|
nextUpperCase = Character.isUpperCase(s.charAt(i + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((i > 0) && Character.isUpperCase(c)) {
|
||||||
|
if (!upperCase || !nextUpperCase) {
|
||||||
|
sb.append(SEPARATOR);
|
||||||
|
}
|
||||||
|
upperCase = true;
|
||||||
|
} else {
|
||||||
|
upperCase = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append(Character.toLowerCase(c));
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取ip地址
|
||||||
|
*/
|
||||||
|
public static String getIp(HttpServletRequest request) {
|
||||||
|
String ip = request.getHeader("x-forwarded-for");
|
||||||
|
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
|
||||||
|
ip = request.getHeader("Proxy-Client-IP");
|
||||||
|
}
|
||||||
|
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
|
||||||
|
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||||
|
}
|
||||||
|
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
|
||||||
|
ip = request.getRemoteAddr();
|
||||||
|
}
|
||||||
|
String comma = ",";
|
||||||
|
String localhost = "127.0.0.1";
|
||||||
|
if (ip.contains(comma)) {
|
||||||
|
ip = ip.split(",")[0];
|
||||||
|
}
|
||||||
|
if (localhost.equals(ip)) {
|
||||||
|
// 获取本机真正的ip地址
|
||||||
|
try {
|
||||||
|
ip = InetAddress.getLocalHost().getHostAddress();
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ip获取详细地址
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
public static String getCityInfo(String ip) {
|
||||||
|
if (ipLocal) {
|
||||||
|
return getLocalCityInfo(ip);
|
||||||
|
} else {
|
||||||
|
return getHttpCityInfo(ip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ip获取详细地址
|
||||||
|
*/
|
||||||
|
public static String getHttpCityInfo(String ip) {
|
||||||
|
String host = "202.108.22.5";
|
||||||
|
//超时应该在3钞以上
|
||||||
|
int timeOut = 3000;
|
||||||
|
boolean status = false;
|
||||||
|
try {
|
||||||
|
status = InetAddress.getByName(host).isReachable(timeOut);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
String api ="";
|
||||||
|
if (status){
|
||||||
|
api = HttpUtil.get(String.format(Constant.Url.IP_URL, ip));
|
||||||
|
}else {
|
||||||
|
api = "{\"ip\":\"127.0.0.1\",\"pro\":\"\",\"proCode\":\"999999\",\"city\":\"\",\"cityCode\":\"0\",\"region\":\"\",\"regionCode\":\"0\",\"addr\":\" 局域网\",\"regionNames\":\"\",\"err\":\"noprovince\"}";
|
||||||
|
}
|
||||||
|
JSONObject object = JSONUtil.parseObj(api);
|
||||||
|
return object.get("addr", String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ip获取详细地址
|
||||||
|
*/
|
||||||
|
public static String getLocalCityInfo(String ip) {
|
||||||
|
try {
|
||||||
|
DataBlock dataBlock = new DbSearcher(config, file.getPath())
|
||||||
|
.binarySearch(ip);
|
||||||
|
String region = dataBlock.getRegion();
|
||||||
|
String address = region.replace("0|", "");
|
||||||
|
char symbol = '|';
|
||||||
|
if (address.charAt(address.length() - 1) == symbol) {
|
||||||
|
address = address.substring(0, address.length() - 1);
|
||||||
|
}
|
||||||
|
return address.equals(Constant.REGION) ? "内网IP" : address;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getBrowser(HttpServletRequest request) {
|
||||||
|
UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
|
||||||
|
Browser browser = userAgent.getBrowser();
|
||||||
|
return browser.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得当天是周几
|
||||||
|
*/
|
||||||
|
public static String getWeekDay() {
|
||||||
|
String[] weekDays = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTime(new Date());
|
||||||
|
|
||||||
|
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
|
||||||
|
if (w < 0) {
|
||||||
|
w = 0;
|
||||||
|
}
|
||||||
|
return weekDays[w];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前机器的IP
|
||||||
|
*
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
public static String getLocalIp() {
|
||||||
|
try {
|
||||||
|
InetAddress candidateAddress = null;
|
||||||
|
// 遍历所有的网络接口
|
||||||
|
for (Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); interfaces.hasMoreElements();) {
|
||||||
|
NetworkInterface anInterface = interfaces.nextElement();
|
||||||
|
// 在所有的接口下再遍历IP
|
||||||
|
for (Enumeration<InetAddress> inetAddresses = anInterface.getInetAddresses(); inetAddresses.hasMoreElements();) {
|
||||||
|
InetAddress inetAddr = inetAddresses.nextElement();
|
||||||
|
// 排除loopback类型地址
|
||||||
|
if (!inetAddr.isLoopbackAddress()) {
|
||||||
|
if (inetAddr.isSiteLocalAddress()) {
|
||||||
|
// 如果是site-local地址,就是它了
|
||||||
|
return inetAddr.getHostAddress();
|
||||||
|
} else if (candidateAddress == null) {
|
||||||
|
// site-local类型的地址未被发现,先记录候选地址
|
||||||
|
candidateAddress = inetAddr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (candidateAddress != null) {
|
||||||
|
return candidateAddress.getHostAddress();
|
||||||
|
}
|
||||||
|
// 如果没有发现 non-loopback地址.只能用最次选的方案
|
||||||
|
InetAddress jdkSuppliedAddress = InetAddress.getLocalHost();
|
||||||
|
if (jdkSuppliedAddress == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return jdkSuppliedAddress.getHostAddress();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package com.yfd.platform.exception;
|
package com.yfd.platform.system.exception;
|
||||||
|
|
||||||
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
@ -1,16 +1,13 @@
|
|||||||
package com.yfd.platform.exception;
|
package com.yfd.platform.system.exception;
|
||||||
|
|
||||||
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.yfd.platform.config.ResponseResult;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import jakarta.servlet.ServletException;
|
import jakarta.servlet.ServletException;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@Component
|
@Component
|
||||||
public class AuthenticationException implements AuthenticationEntryPoint {
|
public class AuthenticationException implements AuthenticationEntryPoint {
|
||||||
@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.yfd.platform.exception;
|
package com.yfd.platform.system.exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统一关于错误配置信息 异常
|
* 统一关于错误配置信息 异常
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package com.yfd.platform.exception;
|
package com.yfd.platform.system.exception;
|
||||||
|
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.yfd.platform.exception;
|
package com.yfd.platform.system.exception;
|
||||||
|
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.yfd.platform.exception;
|
package com.yfd.platform.system.exception;
|
||||||
|
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
134
backend/platform-system/pom.xml
Normal file
134
backend/platform-system/pom.xml
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.yfd</groupId>
|
||||||
|
<artifactId>platform</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>platform-system</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>Platform System</name>
|
||||||
|
<description>Platform System Module</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- Common Module -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.yfd</groupId>
|
||||||
|
<artifactId>platform-common</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Spring Boot Starter -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Spring Boot Web -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Spring Boot WebSocket -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- MyBatis Plus -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-spring-boot4-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Spring Security -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- AspectJ -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.aspectj</groupId>
|
||||||
|
<artifactId>aspectjweaver</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Druid -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>druid</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Easy Captcha -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.whvcse</groupId>
|
||||||
|
<artifactId>easy-captcha</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openjdk.nashorn</groupId>
|
||||||
|
<artifactId>nashorn-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- SpringDoc OpenAPI -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springdoc</groupId>
|
||||||
|
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-jsqlparser</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.fastjson2</groupId>
|
||||||
|
<artifactId>fastjson2</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Oracle JDBC Driver -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.oracle.database.jdbc</groupId>
|
||||||
|
<artifactId>ojdbc8</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.oracle.database.nls</groupId>
|
||||||
|
<artifactId>orai18n</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<!-- <build>-->
|
||||||
|
<!-- <plugins>-->
|
||||||
|
<!-- <plugin>-->
|
||||||
|
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||||
|
<!-- <artifactId>spring-boot-maven-plugin</artifactId>-->
|
||||||
|
<!-- <configuration>-->
|
||||||
|
<!-- <mainClass>com.yfd.platform.system.PlatformApplication</mainClass>-->
|
||||||
|
<!-- </configuration>-->
|
||||||
|
<!-- </plugin>-->
|
||||||
|
<!-- </plugins>-->
|
||||||
|
<!-- </build>-->
|
||||||
|
|
||||||
|
</project>
|
||||||
@ -16,7 +16,6 @@
|
|||||||
package com.yfd.platform.aspect;
|
package com.yfd.platform.aspect;
|
||||||
|
|
||||||
import com.yfd.platform.system.domain.SysLog;
|
import com.yfd.platform.system.domain.SysLog;
|
||||||
import com.yfd.platform.system.mapper.SysUserMapper;
|
|
||||||
import com.yfd.platform.system.service.ISysLogService;
|
import com.yfd.platform.system.service.ISysLogService;
|
||||||
import com.yfd.platform.system.service.IUserService;
|
import com.yfd.platform.system.service.IUserService;
|
||||||
import com.yfd.platform.utils.RequestHolder;
|
import com.yfd.platform.utils.RequestHolder;
|
||||||
@ -2,22 +2,18 @@ package com.yfd.platform.config;
|
|||||||
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
import cn.hutool.jwt.JWT;
|
import cn.hutool.jwt.JWT;
|
||||||
import cn.hutool.jwt.JWTUtil;
|
import cn.hutool.jwt.JWTUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
//import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.yfd.platform.component.ServerSendEventServer;
|
|
||||||
import com.yfd.platform.constant.Constant;
|
import com.yfd.platform.constant.Constant;
|
||||||
import com.yfd.platform.system.domain.LoginUser;
|
import com.yfd.platform.system.domain.LoginUser;
|
||||||
import com.yfd.platform.system.domain.Message;
|
|
||||||
import com.yfd.platform.system.service.IMessageService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.filter.OncePerRequestFilter;
|
import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import jakarta.servlet.FilterChain;
|
import jakarta.servlet.FilterChain;
|
||||||
import jakarta.servlet.ServletException;
|
import jakarta.servlet.ServletException;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
@ -61,7 +57,7 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
|
|||||||
//从cachekey中获取用户信息
|
//从cachekey中获取用户信息
|
||||||
String cachekey = "login:" + userid;
|
String cachekey = "login:" + userid;
|
||||||
String jsonstr = webConfig.loginuserCache().get(cachekey);
|
String jsonstr = webConfig.loginuserCache().get(cachekey);
|
||||||
LoginUser loginUser = JSON.parseObject(jsonstr, LoginUser.class);
|
LoginUser loginUser = JSONUtil.toBean(jsonstr, LoginUser.class);
|
||||||
if (ObjectUtil.isEmpty(loginUser)) {
|
if (ObjectUtil.isEmpty(loginUser)) {
|
||||||
httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN,
|
httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN,
|
||||||
"登录用户已失效!");
|
"登录用户已失效!");
|
||||||
@ -1,20 +1,14 @@
|
|||||||
package com.yfd.platform.config;
|
package com.yfd.platform.config;
|
||||||
|
|
||||||
import cn.hutool.cache.Cache;
|
|
||||||
import cn.hutool.cache.impl.CacheObj;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.yfd.platform.component.ServerSendEventServer;
|
import com.yfd.platform.component.ServerSendEventServer;
|
||||||
import com.yfd.platform.constant.Constant;
|
import com.yfd.platform.constant.Constant;
|
||||||
import com.yfd.platform.system.domain.Message;
|
import com.yfd.platform.system.domain.Message;
|
||||||
import com.yfd.platform.system.domain.SysUser;
|
|
||||||
import com.yfd.platform.system.service.IMessageService;
|
import com.yfd.platform.system.service.IMessageService;
|
||||||
import com.yfd.platform.system.service.IUserService;
|
import com.yfd.platform.system.service.IUserService;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author TangWei
|
* @author TangWei
|
||||||
@ -1,8 +1,8 @@
|
|||||||
package com.yfd.platform.config;
|
package com.yfd.platform.config;
|
||||||
|
|
||||||
import com.yfd.platform.config.bean.LoginProperties;
|
import com.yfd.platform.config.bean.LoginProperties;
|
||||||
import com.yfd.platform.exception.AccessDeniedHandExcetion;
|
import com.yfd.platform.system.exception.AccessDeniedHandExcetion;
|
||||||
import com.yfd.platform.exception.AuthenticationException;
|
import com.yfd.platform.system.exception.AuthenticationException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@ -18,7 +18,7 @@ package com.yfd.platform.config.bean;
|
|||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.wf.captcha.*;
|
import com.wf.captcha.*;
|
||||||
import com.wf.captcha.base.Captcha;
|
import com.wf.captcha.base.Captcha;
|
||||||
import com.yfd.platform.exception.BadConfigurationException;
|
import com.yfd.platform.system.exception.BadConfigurationException;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -17,7 +17,7 @@ package com.yfd.platform.config.thread;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
import com.yfd.platform.utils.SpringContextHolder;
|
import com.yfd.platform.common.utils.SpringContextHolder;
|
||||||
|
|
||||||
import java.util.concurrent.ArrayBlockingQueue;
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
package com.yfd.platform.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author TangWei
|
||||||
|
* @Date: 2023/3/3 17:40
|
||||||
|
* @Description: 常量类
|
||||||
|
*/
|
||||||
|
public class Constant {
|
||||||
|
|
||||||
|
public static final String LOGIN = "login:";
|
||||||
|
public static final String TOKEN = "token:";
|
||||||
|
public static final String USER_ID = "userid";
|
||||||
|
public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||||
|
|
||||||
|
public static final String CODE_KEY = "code-key-";
|
||||||
|
public static final long CODE_EXPIRATION_TIME = 1000 * 60;
|
||||||
|
/**
|
||||||
|
* 用于IP定位转换
|
||||||
|
*/
|
||||||
|
public static final String REGION = "内网IP|内网IP";
|
||||||
|
/**
|
||||||
|
* win 系统
|
||||||
|
*/
|
||||||
|
public static final String WIN = "win";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mac 系统
|
||||||
|
*/
|
||||||
|
public static final String MAC = "mac";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 常用接口
|
||||||
|
*/
|
||||||
|
public static class Url {
|
||||||
|
|
||||||
|
// IP归属地查询
|
||||||
|
// public static final String IP_URL = "http://whois.pconline.com
|
||||||
|
// .cn/ipJson.jsp?ip=%s&json=true";
|
||||||
|
public static final String IP_URL = "http://whois.pconline.com" +
|
||||||
|
".cn/ipJson.jsp?ip=%s&json=true";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,7 +1,6 @@
|
|||||||
package com.yfd.platform.system.controller;
|
package com.yfd.platform.system.controller;
|
||||||
|
|
||||||
import com.yfd.platform.config.ResponseResult;
|
import com.yfd.platform.common.response.ResponseResult;
|
||||||
import com.yfd.platform.datasource.DataSource;
|
|
||||||
import com.yfd.platform.datasource.DataSourceAspect;
|
import com.yfd.platform.datasource.DataSourceAspect;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
@ -7,20 +7,20 @@ import cn.hutool.json.JSONUtil;
|
|||||||
import cn.hutool.jwt.JWTUtil;
|
import cn.hutool.jwt.JWTUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.wf.captcha.base.Captcha;
|
import com.wf.captcha.base.Captcha;
|
||||||
|
import com.yfd.platform.common.response.ResponseResult;
|
||||||
|
import com.yfd.platform.constant.Constant;
|
||||||
|
import com.yfd.platform.common.utils.RequestHolder;
|
||||||
|
import com.yfd.platform.common.utils.RsaUtils;
|
||||||
|
import com.yfd.platform.common.utils.StringUtils;
|
||||||
import com.yfd.platform.annotation.Log;
|
import com.yfd.platform.annotation.Log;
|
||||||
import com.yfd.platform.config.ResponseResult;
|
|
||||||
import com.yfd.platform.config.WebConfig;
|
import com.yfd.platform.config.WebConfig;
|
||||||
import com.yfd.platform.config.bean.LoginCodeEnum;
|
import com.yfd.platform.config.bean.LoginCodeEnum;
|
||||||
import com.yfd.platform.config.bean.LoginProperties;
|
import com.yfd.platform.config.bean.LoginProperties;
|
||||||
import com.yfd.platform.constant.Constant;
|
|
||||||
import com.yfd.platform.system.domain.LoginUser;
|
import com.yfd.platform.system.domain.LoginUser;
|
||||||
import com.yfd.platform.system.domain.SysLog;
|
import com.yfd.platform.system.domain.SysLog;
|
||||||
import com.yfd.platform.system.domain.SysUser;
|
import com.yfd.platform.system.domain.SysUser;
|
||||||
import com.yfd.platform.system.service.ISysLogService;
|
import com.yfd.platform.system.service.ISysLogService;
|
||||||
import com.yfd.platform.system.service.IUserService;
|
import com.yfd.platform.system.service.IUserService;
|
||||||
import com.yfd.platform.utils.RequestHolder;
|
|
||||||
import com.yfd.platform.utils.RsaUtils;
|
|
||||||
import com.yfd.platform.utils.StringUtils;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -7,11 +7,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.yfd.platform.annotation.Log;
|
import com.yfd.platform.annotation.Log;
|
||||||
import com.yfd.platform.config.MessageConfig;
|
import com.yfd.platform.config.MessageConfig;
|
||||||
import com.yfd.platform.config.ResponseResult;
|
import com.yfd.platform.common.response.ResponseResult;
|
||||||
import com.yfd.platform.config.WebConfig;
|
|
||||||
import com.yfd.platform.system.domain.Message;
|
import com.yfd.platform.system.domain.Message;
|
||||||
import com.yfd.platform.system.service.IMessageService;
|
import com.yfd.platform.system.service.IMessageService;
|
||||||
import com.yfd.platform.system.service.IUserService;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.yfd.platform.annotation.Log;
|
import com.yfd.platform.annotation.Log;
|
||||||
import com.yfd.platform.config.ResponseResult;
|
import com.yfd.platform.common.response.ResponseResult;
|
||||||
import com.yfd.platform.system.domain.QuartzJob;
|
import com.yfd.platform.system.domain.QuartzJob;
|
||||||
import com.yfd.platform.system.service.IQuartzJobService;
|
import com.yfd.platform.system.service.IQuartzJobService;
|
||||||
import com.yfd.platform.system.service.impl.UserServiceImpl;
|
import com.yfd.platform.system.service.impl.UserServiceImpl;
|
||||||
@ -2,11 +2,8 @@ package com.yfd.platform.system.controller;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.yfd.platform.component.ServerSendEventServer;
|
import com.yfd.platform.component.ServerSendEventServer;
|
||||||
import com.yfd.platform.config.WebConfig;
|
|
||||||
import com.yfd.platform.constant.Constant;
|
|
||||||
import com.yfd.platform.system.domain.Message;
|
import com.yfd.platform.system.domain.Message;
|
||||||
import com.yfd.platform.system.service.IMessageService;
|
import com.yfd.platform.system.service.IMessageService;
|
||||||
import com.yfd.platform.system.service.IUserService;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -3,7 +3,7 @@ package com.yfd.platform.system.controller;
|
|||||||
|
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.yfd.platform.config.ResponseResult;
|
import com.yfd.platform.common.response.ResponseResult;
|
||||||
import com.yfd.platform.system.domain.SysConfig;
|
import com.yfd.platform.system.domain.SysConfig;
|
||||||
import com.yfd.platform.system.service.ISysConfigService;
|
import com.yfd.platform.system.service.ISysConfigService;
|
||||||
import com.yfd.platform.system.service.IUserService;
|
import com.yfd.platform.system.service.IUserService;
|
||||||
@ -2,18 +2,15 @@ package com.yfd.platform.system.controller;
|
|||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.yfd.platform.annotation.Log;
|
import com.yfd.platform.annotation.Log;
|
||||||
import com.yfd.platform.config.ResponseResult;
|
import com.yfd.platform.common.response.ResponseResult;
|
||||||
import com.yfd.platform.system.domain.SysDictionary;
|
import com.yfd.platform.system.domain.SysDictionary;
|
||||||
import com.yfd.platform.system.mapper.SysDictionaryItemsMapper;
|
|
||||||
import com.yfd.platform.system.service.ISysDictionaryService;
|
import com.yfd.platform.system.service.ISysDictionaryService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@ -4,9 +4,8 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.yfd.platform.annotation.Log;
|
import com.yfd.platform.annotation.Log;
|
||||||
import com.yfd.platform.config.ResponseResult;
|
import com.yfd.platform.common.response.ResponseResult;
|
||||||
import com.yfd.platform.system.domain.SysDictionaryItems;
|
import com.yfd.platform.system.domain.SysDictionaryItems;
|
||||||
import com.yfd.platform.system.mapper.SysDictionaryItemsMapper;
|
|
||||||
import com.yfd.platform.system.service.ISysDictionaryItemsService;
|
import com.yfd.platform.system.service.ISysDictionaryItemsService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
@ -2,7 +2,7 @@ package com.yfd.platform.system.controller;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.yfd.platform.annotation.Log;
|
import com.yfd.platform.annotation.Log;
|
||||||
import com.yfd.platform.config.ResponseResult;
|
import com.yfd.platform.common.response.ResponseResult;
|
||||||
import com.yfd.platform.system.domain.SysLog;
|
import com.yfd.platform.system.domain.SysLog;
|
||||||
import com.yfd.platform.system.service.ISysLogService;
|
import com.yfd.platform.system.service.ISysLogService;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
@ -13,7 +13,6 @@ import jakarta.annotation.Resource;
|
|||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1,18 +1,15 @@
|
|||||||
package com.yfd.platform.system.controller;
|
package com.yfd.platform.system.controller;
|
||||||
|
|
||||||
import cn.hutool.core.util.IdUtil;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.yfd.platform.annotation.Log;
|
import com.yfd.platform.annotation.Log;
|
||||||
import com.yfd.platform.config.ResponseResult;
|
import com.yfd.platform.common.response.ResponseResult;
|
||||||
import com.yfd.platform.system.domain.SysMenu;
|
import com.yfd.platform.system.domain.SysMenu;
|
||||||
import com.yfd.platform.system.domain.SysUser;
|
import com.yfd.platform.system.domain.SysUser;
|
||||||
import com.yfd.platform.system.service.ISysMenuService;
|
import com.yfd.platform.system.service.ISysMenuService;
|
||||||
import com.yfd.platform.system.service.IUserService;
|
import com.yfd.platform.system.service.IUserService;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import org.apache.catalina.User;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
@ -22,7 +19,6 @@ import java.io.FileNotFoundException;
|
|||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@ -2,14 +2,10 @@ package com.yfd.platform.system.controller;
|
|||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.yfd.platform.annotation.Log;
|
import com.yfd.platform.annotation.Log;
|
||||||
import com.yfd.platform.config.ResponseResult;
|
import com.yfd.platform.common.response.ResponseResult;
|
||||||
import com.yfd.platform.system.domain.SysOrganization;
|
import com.yfd.platform.system.domain.SysOrganization;
|
||||||
import com.yfd.platform.system.domain.SysRole;
|
|
||||||
import com.yfd.platform.system.domain.SysUser;
|
|
||||||
import com.yfd.platform.system.mapper.SysRoleMapper;
|
|
||||||
import com.yfd.platform.system.service.ISysOrganizationService;
|
import com.yfd.platform.system.service.ISysOrganizationService;
|
||||||
import com.yfd.platform.system.service.IUserService;
|
import com.yfd.platform.system.service.IUserService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
@ -20,7 +16,6 @@ import jakarta.annotation.Resource;
|
|||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@ -1,11 +1,9 @@
|
|||||||
package com.yfd.platform.system.controller;
|
package com.yfd.platform.system.controller;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.yfd.platform.annotation.Log;
|
import com.yfd.platform.annotation.Log;
|
||||||
import com.yfd.platform.config.ResponseResult;
|
import com.yfd.platform.common.response.ResponseResult;
|
||||||
import com.yfd.platform.system.domain.SysRole;
|
import com.yfd.platform.system.domain.SysRole;
|
||||||
import com.yfd.platform.system.service.ISysRoleService;
|
import com.yfd.platform.system.service.ISysRoleService;
|
||||||
import com.yfd.platform.system.service.IUserService;
|
import com.yfd.platform.system.service.IUserService;
|
||||||
@ -3,7 +3,7 @@ package com.yfd.platform.system.controller;
|
|||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.yfd.platform.annotation.Log;
|
import com.yfd.platform.annotation.Log;
|
||||||
import com.yfd.platform.config.ResponseResult;
|
import com.yfd.platform.common.response.ResponseResult;
|
||||||
import com.yfd.platform.datasource.DataSource;
|
import com.yfd.platform.datasource.DataSource;
|
||||||
import com.yfd.platform.system.domain.SysUser;
|
import com.yfd.platform.system.domain.SysUser;
|
||||||
import com.yfd.platform.system.service.IUserService;
|
import com.yfd.platform.system.service.IUserService;
|
||||||
@ -1,6 +1,6 @@
|
|||||||
package com.yfd.platform.system.domain;
|
package com.yfd.platform.system.domain;
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson2.annotation.JSONField;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@ -8,7 +8,6 @@ import org.springframework.security.core.GrantedAuthority;
|
|||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -33,6 +32,10 @@ public class LoginUser implements UserDetails {
|
|||||||
@Override
|
@Override
|
||||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||||
// 将权限信息放入集合
|
// 将权限信息放入集合
|
||||||
|
if (permissions == null || permissions.isEmpty()) {
|
||||||
|
authorities = new java.util.ArrayList<>();
|
||||||
|
return authorities;
|
||||||
|
}
|
||||||
authorities = permissions.stream()
|
authorities = permissions.stream()
|
||||||
.map(SimpleGrantedAuthority::new)
|
.map(SimpleGrantedAuthority::new)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@ -1,7 +1,6 @@
|
|||||||
package com.yfd.platform.system.mapper;
|
package com.yfd.platform.system.mapper;
|
||||||
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.yfd.platform.system.domain.SysUser;
|
import com.yfd.platform.system.domain.SysUser;
|
||||||
@ -3,10 +3,6 @@ package com.yfd.platform.system.service;
|
|||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.yfd.platform.system.domain.SysConfig;
|
import com.yfd.platform.system.domain.SysConfig;
|
||||||
|
|
||||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 系统全局配置 服务类
|
* 系统全局配置 服务类
|
||||||
@ -8,7 +8,6 @@ import org.aspectj.lang.ProceedingJoinPoint;
|
|||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user