11
This commit is contained in:
parent
069b9892c6
commit
ebc0964988
42
backend/platform-common/pom.xml
Normal file
42
backend/platform-common/pom.xml
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?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>
|
||||||
|
|
||||||
|
<!-- Lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Hutool -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</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.system.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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
package com.yfd.platform.common.utils;
|
||||||
|
|
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
|
||||||
|
public class EncryptConfigUtil {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
// String salt = "rca20230101";
|
||||||
|
// String password = "123456";
|
||||||
|
//
|
||||||
|
// BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
|
||||||
|
// //加密所需的salt
|
||||||
|
// textEncryptor.setPassword(salt);
|
||||||
|
// //要加密的数据(数据库的用户名或密码)
|
||||||
|
// String encrypt = textEncryptor.encrypt(password);
|
||||||
|
// System.out.println("password:"+encrypt);
|
||||||
|
|
||||||
|
|
||||||
|
BCryptPasswordEncoder passwordEncoder=new BCryptPasswordEncoder();
|
||||||
|
String cryptPassword=passwordEncoder.encode("dl_2023");//设置缺省密码
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -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,102 @@
|
|||||||
|
/*
|
||||||
|
* 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 com.yfd.platform.config.MessageConfig;
|
||||||
|
import com.yfd.platform.config.thread.ThreadPoolExecutorUtil;
|
||||||
|
import com.yfd.platform.system.domain.Message;
|
||||||
|
import com.yfd.platform.system.domain.QuartzJob;
|
||||||
|
import com.yfd.platform.system.service.IMessageService;
|
||||||
|
import com.yfd.platform.system.service.IQuartzJobService;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.quartz.JobExecutionContext;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.scheduling.quartz.QuartzJobBean;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参考人人开源,https://gitee.com/renrenio/renren-security
|
||||||
|
*
|
||||||
|
* @author /
|
||||||
|
* @date 2019-01-07
|
||||||
|
*/
|
||||||
|
@Async
|
||||||
|
@SuppressWarnings({"unchecked", "all"})
|
||||||
|
public class ExecutionJob extends QuartzJobBean {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 该处仅供参考
|
||||||
|
*/
|
||||||
|
private final static ThreadPoolExecutor EXECUTOR =
|
||||||
|
ThreadPoolExecutorUtil.getPoll();
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IMessageService messageService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MessageConfig messageConfig;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeInternal(JobExecutionContext context) {
|
||||||
|
QuartzJob quartzJob =
|
||||||
|
(QuartzJob) context.getMergedJobDataMap().get(QuartzJob.JOB_KEY);
|
||||||
|
// 获取spring bean
|
||||||
|
IQuartzJobService quartzJobService =
|
||||||
|
SpringContextHolder.getBean(IQuartzJobService.class);
|
||||||
|
String uuid = quartzJob.getId();
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
String jobName = quartzJob.getJobName();
|
||||||
|
try {
|
||||||
|
// 执行任务
|
||||||
|
System.out.println(
|
||||||
|
"--------------------------------------------------------------");
|
||||||
|
System.out.println("任务开始执行,任务名称:" + jobName);
|
||||||
|
QuartzRunnable task = new QuartzRunnable(quartzJob.getJobClass(),
|
||||||
|
quartzJob.getJobMethod(),
|
||||||
|
quartzJob.getJobParams());
|
||||||
|
Future<?> future = EXECUTOR.submit(task);
|
||||||
|
future.get();
|
||||||
|
long times = System.currentTimeMillis() - startTime;
|
||||||
|
Message message = new Message();
|
||||||
|
message.setCreatetime(new Timestamp(System.currentTimeMillis()));
|
||||||
|
message.setType("1");
|
||||||
|
message.setTitle(quartzJob.getJobName());
|
||||||
|
message.setContent(quartzJob.getDescription());
|
||||||
|
message.setSenderName("定时器");
|
||||||
|
message.setReceiverCodes(quartzJob.getOrderno().toString());
|
||||||
|
message.setReceiverNames("");
|
||||||
|
message.setStatus("1");
|
||||||
|
message.setValidperiod(24);
|
||||||
|
messageConfig.addMessage(message);
|
||||||
|
// 任务状态
|
||||||
|
System.out.println("任务执行完毕,任务名称:" + jobName + ", " +
|
||||||
|
"执行时间:" + times + "毫秒");
|
||||||
|
System.out.println(
|
||||||
|
"--------------------------------------------------------------");
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("任务执行失败,任务名称:" + jobName);
|
||||||
|
System.out.println(
|
||||||
|
"--------------------------------------------------------------");
|
||||||
|
quartzJob.setStatus("0");
|
||||||
|
//更新状态
|
||||||
|
quartzJobService.updateById(quartzJob);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -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,80 @@
|
|||||||
|
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 com.yfd.platform.system.utils.PropertiesUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class MpGenerator {
|
||||||
|
/**
|
||||||
|
* 读取控制台内容
|
||||||
|
*/
|
||||||
|
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 (StringUtils.hasText(ipt)) {
|
||||||
|
return ipt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new RuntimeException("请输入正确的" + tip + "!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String projectPath = System.getProperty("user.dir");
|
||||||
|
String url = PropertiesUtils.getPropertyField("spring.datasource.url");
|
||||||
|
String username = PropertiesUtils.getPropertyField("spring.datasource.username");
|
||||||
|
String password = PropertiesUtils.getPropertyField("spring.datasource.password");
|
||||||
|
|
||||||
|
String moduleName = scanner("模块名");
|
||||||
|
String modulePath = moduleName.replace(".", "/");
|
||||||
|
|
||||||
|
Map<OutputFile, String> pathInfo = new HashMap<>();
|
||||||
|
pathInfo.put(OutputFile.entity, projectPath + "/src/main/java/com/yfd/platform/modules/domain" + modulePath + "/entity");
|
||||||
|
pathInfo.put(OutputFile.mapper, projectPath + "/src/main/java/com/yfd/platform/modules/domain/" + modulePath + "/dao");
|
||||||
|
pathInfo.put(OutputFile.controller, projectPath + "/src/main/java/com/yfd/platform/modules/domain" + modulePath + "/controller");
|
||||||
|
pathInfo.put(OutputFile.service, projectPath + "/src/main/java/com/yfd/platform/modules/domain" + modulePath + "/service");
|
||||||
|
pathInfo.put(OutputFile.serviceImpl, projectPath + "/src/main/java/com/yfd/platform/modules/domain" + modulePath + "/service/impl");
|
||||||
|
pathInfo.put(OutputFile.xml, projectPath + "/src/main/resources/mapper/" + modulePath);
|
||||||
|
|
||||||
|
FastAutoGenerator.create(url, username, password)
|
||||||
|
.globalConfig(builder -> {
|
||||||
|
builder.author("fwh")
|
||||||
|
.disableOpenDir()
|
||||||
|
.outputDir(projectPath + "/src/main/java");
|
||||||
|
})
|
||||||
|
.packageConfig(builder -> {
|
||||||
|
builder.parent(PropertiesUtils.getPropertyField("project.package.name"))
|
||||||
|
.moduleName(moduleName)
|
||||||
|
.pathInfo(pathInfo);
|
||||||
|
})
|
||||||
|
.strategyConfig(builder -> {
|
||||||
|
builder.addInclude(scanner("表名,多个英文逗号分割").split(","))
|
||||||
|
.entityBuilder()
|
||||||
|
.enableLombok()
|
||||||
|
.naming(NamingStrategy.underline_to_camel)
|
||||||
|
.columnNaming(NamingStrategy.underline_to_camel)
|
||||||
|
.controllerBuilder()
|
||||||
|
.enableRestStyle()
|
||||||
|
.mapperBuilder()
|
||||||
|
.formatMapperFileName("%sDao")
|
||||||
|
.serviceBuilder()
|
||||||
|
.formatServiceFileName("%sService")
|
||||||
|
.formatServiceImplFileName("%sServiceImpl")
|
||||||
|
.controllerBuilder()
|
||||||
|
.formatFileName("%sController");
|
||||||
|
})
|
||||||
|
.templateEngine(new FreemarkerTemplateEngine())
|
||||||
|
.execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -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,187 @@
|
|||||||
|
/*
|
||||||
|
* 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 com.yfd.platform.system.domain.QuartzJob;
|
||||||
|
import com.yfd.platform.system.utils.ExecutionJob;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.quartz.impl.triggers.CronTriggerImpl;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import static org.quartz.TriggerBuilder.newTrigger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author
|
||||||
|
* @date 2019-01-07
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class QuartzManage {
|
||||||
|
|
||||||
|
private static final String JOB_NAME = "TASK_";
|
||||||
|
|
||||||
|
@Resource(name = "scheduler")
|
||||||
|
private Scheduler scheduler;
|
||||||
|
|
||||||
|
public void addJob(QuartzJob quartzJob) {
|
||||||
|
try {
|
||||||
|
// 构建job信息
|
||||||
|
JobDetail jobDetail = JobBuilder.newJob(ExecutionJob.class).
|
||||||
|
withIdentity(JOB_NAME + quartzJob.getId()).build();
|
||||||
|
|
||||||
|
//通过触发器名和cron 表达式创建 Trigger
|
||||||
|
Trigger cronTrigger = newTrigger()
|
||||||
|
.withIdentity(JOB_NAME + quartzJob.getId())
|
||||||
|
.startNow()
|
||||||
|
.withSchedule(CronScheduleBuilder.cronSchedule(quartzJob.getJobCron()))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
cronTrigger.getJobDataMap().put(QuartzJob.JOB_KEY, quartzJob);
|
||||||
|
|
||||||
|
//重置启动时间
|
||||||
|
((CronTriggerImpl) cronTrigger).setStartTime(new Date());
|
||||||
|
|
||||||
|
//执行定时任务
|
||||||
|
scheduler.scheduleJob(jobDetail, cronTrigger);
|
||||||
|
|
||||||
|
// 暂停任务
|
||||||
|
if ("0".equals(quartzJob.getStatus())) {
|
||||||
|
pauseJob(quartzJob);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("创建定时任务失败", e);
|
||||||
|
throw new RuntimeException("创建定时任务失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新job cron表达式
|
||||||
|
*
|
||||||
|
* @param quartzJob /
|
||||||
|
*/
|
||||||
|
public void updateJobCron(QuartzJob quartzJob) {
|
||||||
|
try {
|
||||||
|
TriggerKey triggerKey =
|
||||||
|
TriggerKey.triggerKey(JOB_NAME + quartzJob.getId());
|
||||||
|
CronTrigger trigger =
|
||||||
|
(CronTrigger) scheduler.getTrigger(triggerKey);
|
||||||
|
// 如果不存在则创建一个定时任务
|
||||||
|
if (trigger == null) {
|
||||||
|
addJob(quartzJob);
|
||||||
|
trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
|
||||||
|
}
|
||||||
|
CronScheduleBuilder scheduleBuilder =
|
||||||
|
CronScheduleBuilder.cronSchedule(quartzJob.getJobCron());
|
||||||
|
trigger =
|
||||||
|
trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
|
||||||
|
//重置启动时间
|
||||||
|
((CronTriggerImpl) trigger).setStartTime(new Date());
|
||||||
|
trigger.getJobDataMap().put(QuartzJob.JOB_KEY, quartzJob);
|
||||||
|
|
||||||
|
scheduler.rescheduleJob(triggerKey, trigger);
|
||||||
|
// 暂停任务
|
||||||
|
if ("0".equals(quartzJob.getStatus())) {
|
||||||
|
pauseJob(quartzJob);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("更新定时任务失败", e);
|
||||||
|
throw new RuntimeException("更新定时任务失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除一个job
|
||||||
|
*
|
||||||
|
* @param quartzJob /
|
||||||
|
*/
|
||||||
|
public void deleteJob(QuartzJob quartzJob) {
|
||||||
|
try {
|
||||||
|
JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId());
|
||||||
|
scheduler.pauseJob(jobKey);
|
||||||
|
scheduler.deleteJob(jobKey);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("删除定时任务失败", e);
|
||||||
|
throw new RuntimeException("删除定时任务失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 恢复一个job
|
||||||
|
*
|
||||||
|
* @param quartzJob /
|
||||||
|
*/
|
||||||
|
public void resumeJob(QuartzJob quartzJob) {
|
||||||
|
try {
|
||||||
|
TriggerKey triggerKey =
|
||||||
|
TriggerKey.triggerKey(JOB_NAME + quartzJob.getId());
|
||||||
|
CronTrigger trigger =
|
||||||
|
(CronTrigger) scheduler.getTrigger(triggerKey);
|
||||||
|
// 如果不存在则创建一个定时任务
|
||||||
|
if (trigger == null) {
|
||||||
|
addJob(quartzJob);
|
||||||
|
}
|
||||||
|
JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId());
|
||||||
|
scheduler.resumeJob(jobKey);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("恢复定时任务失败", e);
|
||||||
|
throw new RuntimeException("恢复定时任务失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 立即执行job
|
||||||
|
*
|
||||||
|
* @param quartzJob /
|
||||||
|
*/
|
||||||
|
public void runJobNow(QuartzJob quartzJob) {
|
||||||
|
try {
|
||||||
|
TriggerKey triggerKey =
|
||||||
|
TriggerKey.triggerKey(JOB_NAME + quartzJob.getId());
|
||||||
|
CronTrigger trigger =
|
||||||
|
(CronTrigger) scheduler.getTrigger(triggerKey);
|
||||||
|
// 如果不存在则创建一个定时任务
|
||||||
|
if (trigger == null) {
|
||||||
|
addJob(quartzJob);
|
||||||
|
}
|
||||||
|
JobDataMap dataMap = new JobDataMap();
|
||||||
|
dataMap.put(QuartzJob.JOB_KEY, quartzJob);
|
||||||
|
JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId());
|
||||||
|
scheduler.triggerJob(jobKey, dataMap);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("定时任务执行失败", e);
|
||||||
|
throw new RuntimeException("定时任务执行失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 暂停一个job
|
||||||
|
*
|
||||||
|
* @param quartzJob /
|
||||||
|
*/
|
||||||
|
public void pauseJob(QuartzJob quartzJob) {
|
||||||
|
try {
|
||||||
|
JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId());
|
||||||
|
scheduler.pauseJob(jobKey);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("定时任务暂停失败", e);
|
||||||
|
throw new RuntimeException("定时任务暂停失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* 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 com.yfd.platform.system.utils.SpringContextHolder;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行定时任务
|
||||||
|
* @author /
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class QuartzRunnable implements Callable<Object> {
|
||||||
|
|
||||||
|
private final Object target;
|
||||||
|
private final Method method;
|
||||||
|
private final String params;
|
||||||
|
|
||||||
|
QuartzRunnable(String beanName, String methodName, String params)
|
||||||
|
throws NoSuchMethodException, SecurityException {
|
||||||
|
this.target = SpringContextHolder.getBean(beanName);
|
||||||
|
this.params = params;
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(params)) {
|
||||||
|
this.method = target.getClass().getDeclaredMethod(methodName, String.class);
|
||||||
|
} else {
|
||||||
|
this.method = target.getClass().getDeclaredMethod(methodName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object call() throws Exception {
|
||||||
|
ReflectionUtils.makeAccessible(method);
|
||||||
|
if (StringUtils.isNotBlank(params)) {
|
||||||
|
method.invoke(target, params);
|
||||||
|
} else {
|
||||||
|
method.invoke(target);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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,85 @@
|
|||||||
|
/*
|
||||||
|
* 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.json.JSONArray;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.yfd.platform.exception.BadRequestException;
|
||||||
|
import com.yfd.platform.system.utils.SpringContextHolder;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前登录的用户
|
||||||
|
* @author
|
||||||
|
* @date 2019-01-17
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class SecurityUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前登录的用户
|
||||||
|
* @return UserDetails
|
||||||
|
*/
|
||||||
|
public static UserDetails getCurrentUser() {
|
||||||
|
UserDetailsService userDetailsService = SpringContextHolder.getBean(UserDetailsService.class);
|
||||||
|
return userDetailsService.loadUserByUsername(getCurrentUsername());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取系统用户名称
|
||||||
|
*
|
||||||
|
* @return 系统用户名称
|
||||||
|
*/
|
||||||
|
public static String getCurrentUsername() {
|
||||||
|
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
if (authentication == null) {
|
||||||
|
throw new BadRequestException(HttpStatus.UNAUTHORIZED, "当前登录状态过期");
|
||||||
|
}
|
||||||
|
if (authentication.getPrincipal() instanceof UserDetails) {
|
||||||
|
UserDetails userDetails = (UserDetails) authentication.getPrincipal();
|
||||||
|
return userDetails.getUsername();
|
||||||
|
}
|
||||||
|
throw new BadRequestException(HttpStatus.UNAUTHORIZED, "找不到当前登录的信息");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取系统用户ID
|
||||||
|
* @return 系统用户ID
|
||||||
|
*/
|
||||||
|
public static Long getCurrentUserId() {
|
||||||
|
UserDetails userDetails = getCurrentUser();
|
||||||
|
return new JSONObject(new JSONObject(userDetails).get("user")).get("id", Long.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前用户的数据权限
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
public static List<Long> getCurrentUserDataScope(){
|
||||||
|
UserDetails userDetails = getCurrentUser();
|
||||||
|
JSONArray array = JSONUtil.parseArray(new JSONObject(userDetails).get("dataScopes"));
|
||||||
|
return JSONUtil.toList(array,Long.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -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 "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
49
backend/platform-system/pom.xml
Normal file
49
backend/platform-system/pom.xml
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?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>
|
||||||
|
|
||||||
|
<!-- 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>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
package com.yfd.platform.system;
|
||||||
|
|
||||||
|
import com.yfd.platform.common.utils.SpringContextHolder;
|
||||||
|
import com.yfd.platform.system.annotation.rest.AnonymousGetMapping;
|
||||||
|
import com.yfd.platform.system.datasource.DynamicDataSourceConfig;
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.data.redis.autoconfigure.DataRedisAutoConfiguration;
|
||||||
|
import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration;
|
||||||
|
import org.springframework.boot.web.server.servlet.context.ServletComponentScan;
|
||||||
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
//@SpringBootApplication
|
||||||
|
@RestController
|
||||||
|
@EnableTransactionManagement
|
||||||
|
@ServletComponentScan("com.yfd.platform.config")
|
||||||
|
@MapperScan(basePackages = "com.yfd.platform.*.*.mapper")
|
||||||
|
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class, DataRedisAutoConfiguration.class})
|
||||||
|
@Import({DynamicDataSourceConfig.class})
|
||||||
|
@EnableCaching
|
||||||
|
public class PlatformApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(PlatformApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public SpringContextHolder springContextHolder() {
|
||||||
|
return new SpringContextHolder();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 访问首页提示
|
||||||
|
*
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
@AnonymousGetMapping("/")
|
||||||
|
public String index() {
|
||||||
|
return "Backend service started successfully";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package com.yfd.platform.system;
|
||||||
|
|
||||||
|
import com.yfd.platform.env.PlatformApplication;
|
||||||
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||||
|
|
||||||
|
public class ServletInitializer extends SpringBootServletInitializer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||||
|
return application.sources(PlatformApplication.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* 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.system.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author jacky
|
||||||
|
* 用于标记匿名访问方法
|
||||||
|
*/
|
||||||
|
@Inherited
|
||||||
|
@Documented
|
||||||
|
@Target({ElementType.METHOD,ElementType.ANNOTATION_TYPE})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface AnonymousAccess {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
package com.yfd.platform.system.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author TangWei
|
||||||
|
* @date 2018-11-24
|
||||||
|
*/
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface Log {
|
||||||
|
|
||||||
|
String value() default "";
|
||||||
|
|
||||||
|
String module() default "";
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2002-2016 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.system.annotation.rest;
|
||||||
|
|
||||||
|
import com.yfd.platform.annotation.AnonymousAccess;
|
||||||
|
import org.springframework.core.annotation.AliasFor;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Annotation for mapping HTTP {@code GET} requests onto specific handler
|
||||||
|
* methods.
|
||||||
|
* <p>
|
||||||
|
* 支持匿名访问 GetMapping
|
||||||
|
*
|
||||||
|
* @author liaojinlong
|
||||||
|
* @see RequestMapping
|
||||||
|
*/
|
||||||
|
@AnonymousAccess
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
@RequestMapping(method = RequestMethod.GET)
|
||||||
|
public @interface AnonymousGetMapping {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias for {@link RequestMapping#name}.
|
||||||
|
*/
|
||||||
|
@AliasFor(annotation = RequestMapping.class)
|
||||||
|
String name() default "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias for {@link RequestMapping#value}.
|
||||||
|
*/
|
||||||
|
@AliasFor(annotation = RequestMapping.class)
|
||||||
|
String[] value() default {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias for {@link RequestMapping#path}.
|
||||||
|
*/
|
||||||
|
@AliasFor(annotation = RequestMapping.class)
|
||||||
|
String[] path() default {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias for {@link RequestMapping#params}.
|
||||||
|
*/
|
||||||
|
@AliasFor(annotation = RequestMapping.class)
|
||||||
|
String[] params() default {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias for {@link RequestMapping#headers}.
|
||||||
|
*/
|
||||||
|
@AliasFor(annotation = RequestMapping.class)
|
||||||
|
String[] headers() default {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias for {@link RequestMapping#consumes}.
|
||||||
|
*
|
||||||
|
* @since 4.3.5
|
||||||
|
*/
|
||||||
|
@AliasFor(annotation = RequestMapping.class)
|
||||||
|
String[] consumes() default {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias for {@link RequestMapping#produces}.
|
||||||
|
*/
|
||||||
|
@AliasFor(annotation = RequestMapping.class)
|
||||||
|
String[] produces() default {};
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* 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.system.aspect;
|
||||||
|
|
||||||
|
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.IUserService;
|
||||||
|
import com.yfd.platform.utils.RequestHolder;
|
||||||
|
import com.yfd.platform.utils.SecurityUtils;
|
||||||
|
import com.yfd.platform.utils.StringUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
import org.aspectj.lang.annotation.Around;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author
|
||||||
|
* @date 2018-11-24
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Aspect
|
||||||
|
@Slf4j
|
||||||
|
public class LogAspect {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private final ISysLogService sysLogService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IUserService userService;
|
||||||
|
|
||||||
|
ThreadLocal<Long> currentTime = new ThreadLocal<>();
|
||||||
|
|
||||||
|
public LogAspect(ISysLogService sysLogService) {
|
||||||
|
this.sysLogService = sysLogService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置切入点
|
||||||
|
*/
|
||||||
|
@Pointcut("@annotation(com.yfd.platform.annotation.Log)")
|
||||||
|
public void logPointcut() {
|
||||||
|
// 该方法无方法体,主要为了让同类中其他方法使用此切入点
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置环绕通知,使用在方法logPointcut()上注册的切入点
|
||||||
|
*
|
||||||
|
* @param joinPoint join point for advice
|
||||||
|
*/
|
||||||
|
@Around("logPointcut()")
|
||||||
|
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
|
Object result;
|
||||||
|
currentTime.set(System.currentTimeMillis());
|
||||||
|
result = joinPoint.proceed();
|
||||||
|
SysLog log = new SysLog("INFO");
|
||||||
|
currentTime.remove();
|
||||||
|
HttpServletRequest request = RequestHolder.getHttpServletRequest();
|
||||||
|
Map<String, String> nameInfo = userService.getNameInfo();
|
||||||
|
String nickname = nameInfo.get("nickname");
|
||||||
|
String username = nameInfo.get("username");
|
||||||
|
sysLogService.save(nickname, username, StringUtils.getBrowser(request),
|
||||||
|
StringUtils.getIp(request), joinPoint, log);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
try {
|
||||||
|
return SecurityUtils.getCurrentUsername();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,147 @@
|
|||||||
|
package com.yfd.platform.system.component;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Huhailong
|
||||||
|
* SSE Server send Event 服务器推送服务
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class ServerSendEventServer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前连接数
|
||||||
|
*/
|
||||||
|
private static AtomicInteger count = new AtomicInteger(0);
|
||||||
|
|
||||||
|
private static Map<String, SseEmitter> sseEmitterMap =
|
||||||
|
new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public static SseEmitter connect(String userId) {
|
||||||
|
//设置超时时间,0表示不过期,默认是30秒,超过时间未完成会抛出异常
|
||||||
|
SseEmitter sseEmitter = new SseEmitter(0L);
|
||||||
|
//SseEmitter sseEmitter = new SseEmitter();
|
||||||
|
//注册回调
|
||||||
|
sseEmitter.onCompletion(completionCallBack(userId));
|
||||||
|
sseEmitter.onError(errorCallBack(userId));
|
||||||
|
sseEmitter.onTimeout(timeOutCallBack(userId));
|
||||||
|
sseEmitterMap.put(userId, sseEmitter);
|
||||||
|
//数量+1
|
||||||
|
count.getAndIncrement();
|
||||||
|
log.info("create new sse connect ,current user:{}", userId);
|
||||||
|
return sseEmitter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 给指定用户发消息
|
||||||
|
*/
|
||||||
|
public static void sendMessage(String userId, String message) {
|
||||||
|
if (sseEmitterMap.containsKey(userId)) {
|
||||||
|
try {
|
||||||
|
sseEmitterMap.get(userId).send(message);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("user id:{}, send message error:{}", userId,
|
||||||
|
e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 给所有用户发消息
|
||||||
|
*/
|
||||||
|
public static void sendMessage(String message) {
|
||||||
|
if (sseEmitterMap != null && !sseEmitterMap.isEmpty()) {
|
||||||
|
sseEmitterMap.forEach((k, v) -> {
|
||||||
|
// 发送消息
|
||||||
|
sendMessage(k, message);
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 想多人发送消息,组播
|
||||||
|
*/
|
||||||
|
public static void groupSendMessage(String groupId, String message) {
|
||||||
|
if (sseEmitterMap != null && !sseEmitterMap.isEmpty()) {
|
||||||
|
sseEmitterMap.forEach((k, v) -> {
|
||||||
|
try {
|
||||||
|
if (k.startsWith(groupId)) {
|
||||||
|
v.send(message, MediaType.APPLICATION_JSON);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("user id:{}, send message error:{}", groupId,
|
||||||
|
message);
|
||||||
|
removeUser(k);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void batchSendMessage(String message) {
|
||||||
|
sseEmitterMap.forEach((k, v) -> {
|
||||||
|
try {
|
||||||
|
v.send(message, MediaType.APPLICATION_JSON);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("user id:{}, send message error:{}", k,
|
||||||
|
e.getMessage());
|
||||||
|
removeUser(k);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 群发消息
|
||||||
|
*/
|
||||||
|
public static void batchSendMessage(String message, Set<String> userIds) {
|
||||||
|
userIds.forEach(userId -> sendMessage(userId, message));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeUser(String userId) {
|
||||||
|
sseEmitterMap.remove(userId);
|
||||||
|
//数量-1
|
||||||
|
count.getAndDecrement();
|
||||||
|
log.info("remove user id:{}", userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> getIds() {
|
||||||
|
return new ArrayList<>(sseEmitterMap.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getUserCount() {
|
||||||
|
return count.intValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Runnable completionCallBack(String userId) {
|
||||||
|
return () -> {
|
||||||
|
log.info("结束连接,{}", userId);
|
||||||
|
removeUser(userId);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Runnable timeOutCallBack(String userId) {
|
||||||
|
return () -> {
|
||||||
|
log.info("连接超时,{}", userId);
|
||||||
|
removeUser(userId);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Consumer<Throwable> errorCallBack(String userId) {
|
||||||
|
return throwable -> {
|
||||||
|
log.error("连接异常,{}", userId);
|
||||||
|
removeUser(userId);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,106 @@
|
|||||||
|
package com.yfd.platform.system.component;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import jakarta.websocket.*;
|
||||||
|
import jakarta.websocket.server.PathParam;
|
||||||
|
import jakarta.websocket.server.ServerEndpoint;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
|
@ServerEndpoint("/websocket/{token}")
|
||||||
|
@Component
|
||||||
|
public class WebSocketServer {
|
||||||
|
private static int onlineCount=0;//在线人数
|
||||||
|
private static CopyOnWriteArrayList<WebSocketServer> webSocketSet=new CopyOnWriteArrayList<WebSocketServer>();//在线用户集合
|
||||||
|
private Session session;//与某个客户端的连接会话
|
||||||
|
private String currentUser;
|
||||||
|
|
||||||
|
@OnOpen
|
||||||
|
public void onOpen(@PathParam("token") String token, Session session){
|
||||||
|
this.currentUser = token;
|
||||||
|
this.session=session;
|
||||||
|
webSocketSet.add(this);//加入set中
|
||||||
|
addOnlineCount();
|
||||||
|
System.out.println("有新连接加入!当前在线人数为"+getOnlineCount());
|
||||||
|
allCurrentOnline();
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClose
|
||||||
|
public void onClose(){
|
||||||
|
webSocketSet.remove(this);
|
||||||
|
subOnlineCount();
|
||||||
|
System.out.println("有一连接关闭!当前在线人数为" + getOnlineCount());
|
||||||
|
allCurrentOnline();
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnMessage
|
||||||
|
public void onMessage(String message, Session session){
|
||||||
|
System.out.println("来自客户端的消息:"+message);
|
||||||
|
for (WebSocketServer item:webSocketSet){
|
||||||
|
try {
|
||||||
|
item.sendMessage(message);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnError
|
||||||
|
public void onError(Session session, Throwable throwable){
|
||||||
|
System.out.println("发生错误!");
|
||||||
|
throwable.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendMessage(String message) throws IOException {
|
||||||
|
this.session.getBasicRemote().sendText(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前所有在线用户名
|
||||||
|
*/
|
||||||
|
public static void allCurrentOnline(){
|
||||||
|
for (WebSocketServer item : webSocketSet) {
|
||||||
|
System.out.println(item.currentUser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送给指定用户
|
||||||
|
*/
|
||||||
|
public static void sendMessageTo(String message,String token) throws IOException {
|
||||||
|
for (WebSocketServer item : webSocketSet) {
|
||||||
|
if(item.currentUser.equals(token)){
|
||||||
|
item.session.getBasicRemote().sendText(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 群发自定义消息
|
||||||
|
*/
|
||||||
|
public static void sendInfo(String message) throws IOException {
|
||||||
|
System.out.println(message);
|
||||||
|
for (WebSocketServer item : webSocketSet) {
|
||||||
|
try {
|
||||||
|
item.sendMessage(message);
|
||||||
|
} catch (IOException e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized int getOnlineCount(){
|
||||||
|
return onlineCount;
|
||||||
|
}
|
||||||
|
public static synchronized void addOnlineCount(){
|
||||||
|
WebSocketServer.onlineCount++;
|
||||||
|
}
|
||||||
|
public static synchronized void subOnlineCount(){
|
||||||
|
WebSocketServer.onlineCount--;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package com.yfd.platform.system.config;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "app.init")
|
||||||
|
public class AppInitProperties {
|
||||||
|
private boolean enabled = false;
|
||||||
|
private String schema;
|
||||||
|
private String data;
|
||||||
|
// 用于判断是否已初始化:默认检查是否存在核心表
|
||||||
|
private String markerTable = "sys_user";
|
||||||
|
private String markerVersion = "v1.0.0";
|
||||||
|
}
|
||||||
@ -0,0 +1,129 @@
|
|||||||
|
package com.yfd.platform.system.config;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.boot.ApplicationArguments;
|
||||||
|
import org.springframework.boot.ApplicationRunner;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
import org.springframework.core.Ordered;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.core.io.ByteArrayResource;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.core.io.ResourceLoader;
|
||||||
|
import org.springframework.core.io.support.EncodedResource;
|
||||||
|
import org.springframework.jdbc.datasource.init.ScriptUtils;
|
||||||
|
import org.springframework.jdbc.datasource.init.ScriptException;
|
||||||
|
import org.springframework.jdbc.datasource.init.ScriptStatementFailedException;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import org.springframework.util.StreamUtils;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DatabaseMetaData;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@Profile({"dev","server"})
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||||
|
public class DataInitializer implements ApplicationRunner {
|
||||||
|
|
||||||
|
private final DataSource dataSource;
|
||||||
|
private final AppInitProperties properties;
|
||||||
|
private final ResourceLoader resourceLoader;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(ApplicationArguments args) throws Exception {
|
||||||
|
if (!properties.isEnabled()) {
|
||||||
|
log.info("[DataInit] 自动初始化已关闭 app.init.enabled=false");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try (Connection conn = dataSource.getConnection()) {
|
||||||
|
boolean initialized = tableExists(conn, properties.getMarkerTable());
|
||||||
|
if (initialized) {
|
||||||
|
log.info("[DataInit] 检测到标记表已存在: {},跳过初始化", properties.getMarkerTable());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("[DataInit] 未检测到标记表: {},开始导入 schema 与 data", properties.getMarkerTable());
|
||||||
|
executeIfPresent(conn, properties.getSchema());
|
||||||
|
executeIfPresent(conn, properties.getData());
|
||||||
|
log.info("[DataInit] 导入完成。marker={} version={}", properties.getMarkerTable(), properties.getMarkerVersion());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
log.error("[DataInit] 初始化失败: {}", ex.getMessage(), ex);
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean tableExists(Connection conn, String tableName) {
|
||||||
|
if (tableName == null || tableName.isEmpty()) return false;
|
||||||
|
try {
|
||||||
|
DatabaseMetaData meta = conn.getMetaData();
|
||||||
|
try (ResultSet rs = meta.getTables(conn.getCatalog(), null, tableName, null)) {
|
||||||
|
return rs.next();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("[DataInit] 检查表存在异常: {}", e.getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void executeIfPresent(Connection conn, String location) throws Exception {
|
||||||
|
if (location == null || location.isEmpty()) return;
|
||||||
|
Resource resource = resourceLoader.getResource(location);
|
||||||
|
if (!resource.exists()) {
|
||||||
|
log.warn("[DataInit] 资源不存在: {}", location);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.info("[DataInit] 执行脚本: {}", location);
|
||||||
|
// 读取并清理脚本首部的 BOM 和危险语句(CREATE DATABASE / USE schema)
|
||||||
|
String sql = StreamUtils.copyToString(resource.getInputStream(), StandardCharsets.UTF_8);
|
||||||
|
if (sql != null && !sql.isEmpty()) {
|
||||||
|
// 移除 UTF-8 BOM(\uFEFF)
|
||||||
|
if (sql.charAt(0) == '\uFEFF') {
|
||||||
|
sql = sql.substring(1);
|
||||||
|
}
|
||||||
|
// 移除 "USE xxx;" 和 "CREATE DATABASE" 等与连接无关的语句
|
||||||
|
sql = sql.lines()
|
||||||
|
.filter(line -> {
|
||||||
|
String raw = line;
|
||||||
|
String t = raw.trim();
|
||||||
|
String u = t.toUpperCase();
|
||||||
|
// 过滤与连接无关或可能引发解析问题的语句/注释
|
||||||
|
if (u.startsWith("USE ")) return false;
|
||||||
|
if (u.startsWith("CREATE DATABASE")) return false;
|
||||||
|
if (t.startsWith("--")) return false; // 单行注释
|
||||||
|
if (t.startsWith("/*") || t.startsWith("*/")) return false; // 多行注释行
|
||||||
|
if (t.startsWith("/*!")) return false; // MySQL 版本注释
|
||||||
|
if (t.matches("^-+$")) return false; // 分隔线
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
.collect(Collectors.joining("\n"));
|
||||||
|
}
|
||||||
|
if (sql != null && !sql.trim().isEmpty()) {
|
||||||
|
try {
|
||||||
|
ScriptUtils.executeSqlScript(conn, new EncodedResource(new ByteArrayResource(sql.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8));
|
||||||
|
} catch (ScriptStatementFailedException e) {
|
||||||
|
String preview = sql.lines()
|
||||||
|
.filter(s -> !s.trim().isEmpty())
|
||||||
|
.limit(10)
|
||||||
|
.collect(Collectors.joining("\n"));
|
||||||
|
log.error("[DataInit] SQL语句执行失败: {}\n前10行预览:\n{}", e.getMessage(), preview);
|
||||||
|
throw e;
|
||||||
|
} catch (ScriptException e) {
|
||||||
|
String preview = sql.lines()
|
||||||
|
.filter(s -> !s.trim().isEmpty())
|
||||||
|
.limit(10)
|
||||||
|
.collect(Collectors.joining("\n"));
|
||||||
|
log.error("[DataInit] 脚本执行失败: {}\n前10行预览:\n{}", e.getMessage(), preview);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.warn("[DataInit] 脚本在清理后为空,跳过执行: {}", location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* 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.system.config;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "file")
|
||||||
|
public class FileProperties {
|
||||||
|
|
||||||
|
/** 文件大小限制 */
|
||||||
|
private Long maxSize;
|
||||||
|
|
||||||
|
/** 头像大小限制 */
|
||||||
|
private Long avatarMaxSize;
|
||||||
|
|
||||||
|
private ElPath mac;
|
||||||
|
|
||||||
|
private ElPath linux;
|
||||||
|
|
||||||
|
private ElPath windows;
|
||||||
|
|
||||||
|
public ElPath getPath(){
|
||||||
|
String os = System.getProperty("os.name");
|
||||||
|
if(os.toLowerCase().startsWith("win")) {
|
||||||
|
return windows;
|
||||||
|
} else if(os.toLowerCase().startsWith("mac")){
|
||||||
|
return mac;
|
||||||
|
}
|
||||||
|
return linux;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class ElPath{
|
||||||
|
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
private String avatar;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package com.yfd.platform.system.config;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件空间相关配置,替换 @Value("${file-space.system}") 用法
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "file-space")
|
||||||
|
public class FileSpaceProperties {
|
||||||
|
|
||||||
|
/** 基础目录,例如 D:/data/platform/ */
|
||||||
|
private String system;
|
||||||
|
}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
package com.yfd.platform.system.config;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author TangWei
|
||||||
|
* @Date: 2023/3/27 18:07
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@ControllerAdvice
|
||||||
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
|
@ResponseBody
|
||||||
|
@ExceptionHandler(value = Throwable.class)
|
||||||
|
public ResponseResult handleException(Throwable e) {
|
||||||
|
log.error("message:{}", e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseResult.error(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* 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.system.config;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.yfd.platform.system.domain.QuartzJob;
|
||||||
|
import com.yfd.platform.system.mapper.QuartzJobMapper;
|
||||||
|
import com.yfd.platform.utils.QuartzManage;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.boot.ApplicationArguments;
|
||||||
|
import org.springframework.boot.ApplicationRunner;
|
||||||
|
import org.springframework.core.Ordered;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author
|
||||||
|
* @date 2019-01-07
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Order(Ordered.LOWEST_PRECEDENCE)
|
||||||
|
public class JobRunner implements ApplicationRunner {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(JobRunner.class);
|
||||||
|
private final QuartzJobMapper quartzJobMapper;
|
||||||
|
private final QuartzManage quartzManage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 项目启动时重新激活启用的定时任务
|
||||||
|
*
|
||||||
|
* @param applicationArguments /
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void run(ApplicationArguments applicationArguments) {
|
||||||
|
log.info("--------------------注入定时任务---------------------");
|
||||||
|
List<QuartzJob> quartzJobs =
|
||||||
|
quartzJobMapper.selectList(new LambdaQueryWrapper<QuartzJob>().eq(QuartzJob::getStatus, "1"));
|
||||||
|
quartzJobs.forEach(quartzManage::addJob);
|
||||||
|
log.info("--------------------定时任务注入完成---------------------");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,83 @@
|
|||||||
|
package com.yfd.platform.system.config;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.jwt.JWT;
|
||||||
|
import cn.hutool.jwt.JWTUtil;
|
||||||
|
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.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.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.servlet.FilterChain;
|
||||||
|
import jakarta.servlet.ServletException;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WebConfig webConfig;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doFilterInternal(HttpServletRequest httpServletRequest,
|
||||||
|
HttpServletResponse httpServletResponse,
|
||||||
|
FilterChain filterChain) throws ServletException, IOException {
|
||||||
|
//获取token
|
||||||
|
String uri = httpServletRequest.getRequestURI();
|
||||||
|
String token = httpServletRequest.getHeader("token");
|
||||||
|
if (StrUtil.isEmpty(token) || "/user/login".equals(uri)) {
|
||||||
|
filterChain.doFilter(httpServletRequest, httpServletResponse);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//解析token
|
||||||
|
boolean isok = JWTUtil.verify(token, "12345678".getBytes());
|
||||||
|
String userid = "";
|
||||||
|
if (isok) {
|
||||||
|
final JWT jwt = JWTUtil.parseToken(token);
|
||||||
|
userid = jwt.getPayload("userid").toString();
|
||||||
|
//从cachekey中获取用户信息失效时间
|
||||||
|
String cachekey = "expire_time:" + userid;
|
||||||
|
if(StrUtil.isNotEmpty(webConfig.loginuserCache().get(cachekey))){
|
||||||
|
long expire_time =Long.parseLong(webConfig.loginuserCache().get(cachekey));
|
||||||
|
if (System.currentTimeMillis() > expire_time) {
|
||||||
|
httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "Token超过期限!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//从cachekey中获取用户信息
|
||||||
|
String cachekey = "login:" + userid;
|
||||||
|
String jsonstr = webConfig.loginuserCache().get(cachekey);
|
||||||
|
LoginUser loginUser = JSON.parseObject(jsonstr, LoginUser.class);
|
||||||
|
if (ObjectUtil.isEmpty(loginUser)) {
|
||||||
|
httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN,
|
||||||
|
"登录用户已失效!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//存入SecurityContextHolder
|
||||||
|
UsernamePasswordAuthenticationToken authenticationToken =
|
||||||
|
new UsernamePasswordAuthenticationToken(loginUser, null,
|
||||||
|
loginUser.getAuthorities());
|
||||||
|
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
|
||||||
|
webConfig.loginuserCache().put(Constant.TOKEN + userid, token);
|
||||||
|
//更新了超期时间
|
||||||
|
long expireTime =System.currentTimeMillis() + ( 30L * 60L * 1000L);
|
||||||
|
webConfig.loginuserCache().put("expire_time:" + userid, String.valueOf(expireTime));
|
||||||
|
//放行过滤器
|
||||||
|
filterChain.doFilter(httpServletRequest, httpServletResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,50 @@
|
|||||||
|
package com.yfd.platform.system.config;
|
||||||
|
|
||||||
|
import cn.hutool.cache.Cache;
|
||||||
|
import cn.hutool.cache.impl.CacheObj;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.yfd.platform.component.ServerSendEventServer;
|
||||||
|
import com.yfd.platform.constant.Constant;
|
||||||
|
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.IUserService;
|
||||||
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author TangWei
|
||||||
|
* @Date: 2023/3/24 15:56
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class MessageConfig {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IMessageService messageService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IUserService userService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private WebConfig webConfig;
|
||||||
|
|
||||||
|
public void sendMessage() {
|
||||||
|
long count =
|
||||||
|
messageService.count(new LambdaQueryWrapper<Message>().eq(Message::getStatus, "1"));
|
||||||
|
String userId = userService.getUserInfo().getId();
|
||||||
|
String token = webConfig.loginuserCache().get(Constant.TOKEN + userId);
|
||||||
|
ServerSendEventServer.sendMessage(token, count + "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMessage(Message message) {
|
||||||
|
messageService.save(message);
|
||||||
|
long count =
|
||||||
|
messageService.count(new LambdaQueryWrapper<Message>().eq(Message::getStatus, "1"));
|
||||||
|
ServerSendEventServer.sendMessage(count + "");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
package com.yfd.platform.system.config;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.DbType;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/******************************
|
||||||
|
* 用途说明:
|
||||||
|
* 作者姓名: pcj
|
||||||
|
* 创建时间: 2022/10/24 10:50
|
||||||
|
******************************/
|
||||||
|
@Configuration
|
||||||
|
public class MybitsPlusConfig {
|
||||||
|
|
||||||
|
// @Bean
|
||||||
|
// public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||||
|
// MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
|
||||||
|
// mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||||
|
// return mybatisPlusInterceptor;
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页插件配置(Oracle 兼容)
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||||
|
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||||
|
// 添加分页拦截器,指定数据库类型为 Oracle
|
||||||
|
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.ORACLE));
|
||||||
|
return interceptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
package com.yfd.platform.system.config;
|
||||||
|
|
||||||
|
import jakarta.servlet.Filter;
|
||||||
|
import jakarta.servlet.FilterChain;
|
||||||
|
import jakarta.servlet.RequestDispatcher;
|
||||||
|
import jakarta.servlet.ServletException;
|
||||||
|
import jakarta.servlet.ServletRequest;
|
||||||
|
import jakarta.servlet.ServletResponse;
|
||||||
|
import jakarta.servlet.annotation.WebFilter;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将以 /prod-api/ 开头的请求转发到去掉前缀的真实后端接口路径。
|
||||||
|
* 例如:/prod-api/user/code -> /user/code
|
||||||
|
* 这样可以兼容前端生产环境仍使用 /prod-api 作为网关前缀的情况。
|
||||||
|
*/
|
||||||
|
@WebFilter(urlPatterns = "/prod-api/*", filterName = "prodApiPrefixFilter")
|
||||||
|
public class ProdApiPrefixFilter implements Filter {
|
||||||
|
|
||||||
|
private static final String PREFIX = "/prod-api";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
|
||||||
|
if (!(req instanceof HttpServletRequest) || !(res instanceof HttpServletResponse)) {
|
||||||
|
chain.doFilter(req, res);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpServletRequest request = (HttpServletRequest) req;
|
||||||
|
String uri = request.getRequestURI();
|
||||||
|
|
||||||
|
// 仅拦截 /prod-api/* 的接口请求并进行内部 forward
|
||||||
|
if (uri.startsWith(PREFIX + "/")) {
|
||||||
|
String forwardUri = uri.substring(PREFIX.length());
|
||||||
|
RequestDispatcher dispatcher = request.getRequestDispatcher(forwardUri);
|
||||||
|
dispatcher.forward(req, res);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
chain.doFilter(req, res);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* 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.system.config;
|
||||||
|
|
||||||
|
import org.quartz.Scheduler;
|
||||||
|
import org.quartz.spi.TriggerFiredBundle;
|
||||||
|
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.scheduling.quartz.AdaptableJobFactory;
|
||||||
|
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时任务配置
|
||||||
|
*
|
||||||
|
* @author /
|
||||||
|
* @date 2019-01-07
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class QuartzConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解决Job中注入Spring Bean为null的问题
|
||||||
|
*/
|
||||||
|
@Component("quartzJobFactory")
|
||||||
|
public static class QuartzJobFactory extends AdaptableJobFactory {
|
||||||
|
|
||||||
|
private final AutowireCapableBeanFactory capableBeanFactory;
|
||||||
|
|
||||||
|
public QuartzJobFactory(AutowireCapableBeanFactory capableBeanFactory) {
|
||||||
|
this.capableBeanFactory = capableBeanFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
|
||||||
|
|
||||||
|
//调用父类的方法
|
||||||
|
Object jobInstance = super.createJobInstance(bundle);
|
||||||
|
capableBeanFactory.autowireBean(jobInstance);
|
||||||
|
return jobInstance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注入scheduler到spring
|
||||||
|
*
|
||||||
|
* @param quartzJobFactory /
|
||||||
|
* @return Scheduler
|
||||||
|
* @throws Exception /
|
||||||
|
*/
|
||||||
|
@Bean(name = "scheduler")
|
||||||
|
public Scheduler scheduler(QuartzJobFactory quartzJobFactory) throws Exception {
|
||||||
|
SchedulerFactoryBean factoryBean = new SchedulerFactoryBean();
|
||||||
|
factoryBean.setJobFactory(quartzJobFactory);
|
||||||
|
factoryBean.afterPropertiesSet();
|
||||||
|
Scheduler scheduler = factoryBean.getScheduler();
|
||||||
|
scheduler.start();
|
||||||
|
return scheduler;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
package com.yfd.platform.system.config;
|
||||||
|
|
||||||
|
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,90 @@
|
|||||||
|
package com.yfd.platform.system.config;
|
||||||
|
|
||||||
|
import com.yfd.platform.config.bean.LoginProperties;
|
||||||
|
import com.yfd.platform.exception.AccessDeniedHandExcetion;
|
||||||
|
import com.yfd.platform.exception.AuthenticationException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
|
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
|
||||||
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
|
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class SecurityConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public PasswordEncoder passwordEncoder() {
|
||||||
|
return new BCryptPasswordEncoder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConfigurationProperties(prefix = "login", ignoreUnknownFields = true)
|
||||||
|
public LoginProperties loginProperties() {
|
||||||
|
return new LoginProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {
|
||||||
|
return authenticationConfiguration.getAuthenticationManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AuthenticationException authenticationException;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AccessDeniedHandExcetion accessDeniedHandExcetion;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
|
http
|
||||||
|
.csrf(csrf -> csrf.disable())
|
||||||
|
.sessionManagement(sm -> sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||||
|
.authorizeHttpRequests(auth -> auth
|
||||||
|
.requestMatchers("/user/login").anonymous()
|
||||||
|
.requestMatchers("/user/code").permitAll()
|
||||||
|
.requestMatchers(HttpMethod.GET, "/").permitAll()
|
||||||
|
.requestMatchers(HttpMethod.GET,
|
||||||
|
"/*.html",
|
||||||
|
"/webSocket/**",
|
||||||
|
"/assets/**",
|
||||||
|
"/icon/**").permitAll()
|
||||||
|
.requestMatchers(
|
||||||
|
"/swagger-ui.html",
|
||||||
|
"/swagger-ui/**",
|
||||||
|
"/v3/api-docs/**",
|
||||||
|
"/v3/api-docs.yaml",
|
||||||
|
"/swagger-resources/**",
|
||||||
|
"/webjars/**",
|
||||||
|
"/*/api-docs").permitAll()
|
||||||
|
.requestMatchers(
|
||||||
|
"/report/**",
|
||||||
|
"/images/**",
|
||||||
|
"/pageimage/**",
|
||||||
|
"/avatar/**",
|
||||||
|
"/systemurl/**",
|
||||||
|
"/api/imageserver/upload").permitAll()
|
||||||
|
.anyRequest().authenticated()
|
||||||
|
)
|
||||||
|
.cors(cors -> {});
|
||||||
|
|
||||||
|
http.addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
|
||||||
|
|
||||||
|
http.exceptionHandling(ex -> ex
|
||||||
|
.authenticationEntryPoint(authenticationException)
|
||||||
|
.accessDeniedHandler(accessDeniedHandExcetion)
|
||||||
|
);
|
||||||
|
|
||||||
|
return http.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
package com.yfd.platform.system.config;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springdoc.core.models.GroupedOpenApi;
|
||||||
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
|
import io.swagger.v3.oas.models.info.Info;
|
||||||
|
import io.swagger.v3.oas.models.info.Contact;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Springdoc OpenAPI 配置
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class SwaggerConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public OpenAPI projectOpenAPI() {
|
||||||
|
return new OpenAPI()
|
||||||
|
.info(new Info()
|
||||||
|
.title("项目API 接口文档")
|
||||||
|
.version("3.0")
|
||||||
|
.description("")
|
||||||
|
.contact(new Contact().name("郑顺利").email("13910913995@163.com"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public GroupedOpenApi groupWebsiteApi() {
|
||||||
|
return GroupedOpenApi.builder()
|
||||||
|
.group("1. 平台模块")
|
||||||
|
.packagesToScan("com.yfd.platform.modules.platformdb.controller")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public GroupedOpenApi groupQuartzApi() {
|
||||||
|
return GroupedOpenApi.builder()
|
||||||
|
.group("2. 定时任务")
|
||||||
|
.packagesToScan("com.yfd.platform.modules.quartz.controller")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public GroupedOpenApi groupSystemApi() {
|
||||||
|
return GroupedOpenApi.builder()
|
||||||
|
.group("3. 系统管理")
|
||||||
|
.packagesToScan("com.yfd.platform.system.controller")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,61 @@
|
|||||||
|
package com.yfd.platform.system.config;
|
||||||
|
|
||||||
|
import cn.hutool.cache.Cache;
|
||||||
|
import cn.hutool.cache.CacheUtil;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||||
|
import org.springframework.web.filter.CorsFilter;
|
||||||
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class WebConfig implements WebMvcConfigurer {
|
||||||
|
@Resource
|
||||||
|
private FileSpaceProperties fileSpaceProperties;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Cache<String, String> loginuserCache() {
|
||||||
|
return CacheUtil.newLRUCache(200);//用户登录缓存数 缺省200
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public CorsFilter corsFilter() {
|
||||||
|
UrlBasedCorsConfigurationSource source =
|
||||||
|
new UrlBasedCorsConfigurationSource();
|
||||||
|
CorsConfiguration config = new CorsConfiguration();
|
||||||
|
config.setAllowCredentials(true);
|
||||||
|
config.addAllowedOriginPattern("*");
|
||||||
|
config.addAllowedHeader("*");
|
||||||
|
config.addAllowedMethod("*");
|
||||||
|
config.setMaxAge(3600L);
|
||||||
|
source.registerCorsConfiguration("/**", config);
|
||||||
|
return new CorsFilter(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@Override
|
||||||
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
|
registry.addResourceHandler("/icon/**")
|
||||||
|
.addResourceLocations("classpath:/static/icon/")
|
||||||
|
.setCachePeriod(0);
|
||||||
|
|
||||||
|
registry.addResourceHandler("/assets/**")
|
||||||
|
.addResourceLocations("classpath:/static/assets/")
|
||||||
|
.setCachePeriod(0);
|
||||||
|
|
||||||
|
registry.addResourceHandler("swagger-ui.html").addResourceLocations(
|
||||||
|
"classpath:/META-INF/resources/");
|
||||||
|
|
||||||
|
String systemUrl = "file:" + fileSpaceProperties.getSystem().replace("\\", "/")+"user\\";
|
||||||
|
registry.addResourceHandler("/avatar/**").addResourceLocations(systemUrl).setCachePeriod(0);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package com.yfd.platform.system.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class WebSocketConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ServerEndpointExporter serverEndpointExporter() {
|
||||||
|
|
||||||
|
return new ServerEndpointExporter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* 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.system.config.bean;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录验证码配置信息
|
||||||
|
*
|
||||||
|
* @author: liaojinlong
|
||||||
|
* @date: 2020/6/10 18:53
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class LoginCode {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证码配置
|
||||||
|
*/
|
||||||
|
private LoginCodeEnum codeType;
|
||||||
|
/**
|
||||||
|
* 验证码有效期 分钟
|
||||||
|
*/
|
||||||
|
private Long expiration = 2L;
|
||||||
|
/**
|
||||||
|
* 验证码内容长度
|
||||||
|
*/
|
||||||
|
private int length = 2;
|
||||||
|
/**
|
||||||
|
* 验证码宽度
|
||||||
|
*/
|
||||||
|
private int width = 111;
|
||||||
|
/**
|
||||||
|
* 验证码高度
|
||||||
|
*/
|
||||||
|
private int height = 36;
|
||||||
|
/**
|
||||||
|
* 验证码字体
|
||||||
|
*/
|
||||||
|
private String fontName;
|
||||||
|
/**
|
||||||
|
* 字体大小
|
||||||
|
*/
|
||||||
|
private int fontSize = 25;
|
||||||
|
|
||||||
|
public LoginCodeEnum getCodeType() {
|
||||||
|
return codeType;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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.system.config.bean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证码配置枚举
|
||||||
|
*
|
||||||
|
* @author: liaojinlong
|
||||||
|
* @date: 2020/6/10 17:40
|
||||||
|
*/
|
||||||
|
|
||||||
|
public enum LoginCodeEnum {
|
||||||
|
/**
|
||||||
|
* 算数
|
||||||
|
*/
|
||||||
|
arithmetic,
|
||||||
|
/**
|
||||||
|
* 中文
|
||||||
|
*/
|
||||||
|
chinese,
|
||||||
|
/**
|
||||||
|
* 中文闪图
|
||||||
|
*/
|
||||||
|
chinese_gif,
|
||||||
|
/**
|
||||||
|
* 闪图
|
||||||
|
*/
|
||||||
|
gif,
|
||||||
|
spec
|
||||||
|
}
|
||||||
@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2020 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version loginCode.length.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-loginCode.length.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.system.config.bean;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.wf.captcha.*;
|
||||||
|
import com.wf.captcha.base.Captcha;
|
||||||
|
import com.yfd.platform.exception.BadConfigurationException;
|
||||||
|
import lombok.Data;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置文件读取
|
||||||
|
*
|
||||||
|
* @author liaojinlong
|
||||||
|
* @date loginCode.length0loginCode.length0/6/10 17:loginCode.length6
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class LoginProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号单用户 登录
|
||||||
|
*/
|
||||||
|
private boolean singleLogin = false;
|
||||||
|
|
||||||
|
private LoginCode loginCode;
|
||||||
|
/**
|
||||||
|
* 用户登录信息缓存
|
||||||
|
*/
|
||||||
|
private boolean cacheEnable;
|
||||||
|
|
||||||
|
public boolean isSingleLogin() {
|
||||||
|
return singleLogin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCacheEnable() {
|
||||||
|
return cacheEnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取验证码生产类
|
||||||
|
*
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
public Captcha getCaptcha() {
|
||||||
|
if (Objects.isNull(loginCode)) {
|
||||||
|
loginCode = new LoginCode();
|
||||||
|
if (Objects.isNull(loginCode.getCodeType())) {
|
||||||
|
loginCode.setCodeType(LoginCodeEnum.arithmetic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return switchCaptcha(loginCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 依据配置信息生产验证码
|
||||||
|
*
|
||||||
|
* @param loginCode 验证码配置信息
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
private Captcha switchCaptcha(LoginCode loginCode) {
|
||||||
|
Captcha captcha;
|
||||||
|
synchronized (this) {
|
||||||
|
switch (loginCode.getCodeType()) {
|
||||||
|
case arithmetic:
|
||||||
|
// 算术类型 https://gitee.com/whvse/EasyCaptcha
|
||||||
|
captcha = new ArithmeticCaptcha(loginCode.getWidth(), loginCode.getHeight());
|
||||||
|
// 几位数运算,默认是两位
|
||||||
|
captcha.setLen(loginCode.getLength());
|
||||||
|
break;
|
||||||
|
case chinese:
|
||||||
|
captcha = new ChineseCaptcha(loginCode.getWidth(), loginCode.getHeight());
|
||||||
|
captcha.setLen(loginCode.getLength());
|
||||||
|
break;
|
||||||
|
case chinese_gif:
|
||||||
|
captcha = new ChineseGifCaptcha(loginCode.getWidth(), loginCode.getHeight());
|
||||||
|
captcha.setLen(loginCode.getLength());
|
||||||
|
break;
|
||||||
|
case gif:
|
||||||
|
captcha = new GifCaptcha(loginCode.getWidth(), loginCode.getHeight());
|
||||||
|
captcha.setLen(loginCode.getLength());
|
||||||
|
break;
|
||||||
|
case spec:
|
||||||
|
captcha = new SpecCaptcha(loginCode.getWidth(), loginCode.getHeight());
|
||||||
|
captcha.setLen(loginCode.getLength());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new BadConfigurationException("验证码配置信息错误!正确配置查看 LoginCodeEnum ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(StrUtil.isNotBlank(loginCode.getFontName())){
|
||||||
|
captcha.setFont(new Font(loginCode.getFontName(), Font.PLAIN, loginCode.getFontSize()));
|
||||||
|
}
|
||||||
|
return captcha;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* 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.system.config.thread;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.scheduling.annotation.AsyncConfigurer;
|
||||||
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异步任务线程池装配类
|
||||||
|
* @author https://juejin.im/entry/5abb8f6951882555677e9da2
|
||||||
|
* @date 2019年10月31日15:06:18
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Configuration
|
||||||
|
public class AsyncTaskExecutePool implements AsyncConfigurer {
|
||||||
|
|
||||||
|
/** 注入配置类 */
|
||||||
|
private final AsyncTaskProperties config;
|
||||||
|
|
||||||
|
public AsyncTaskExecutePool(AsyncTaskProperties config) {
|
||||||
|
this.config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Executor getAsyncExecutor() {
|
||||||
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||||
|
//核心线程池大小
|
||||||
|
executor.setCorePoolSize(config.getCorePoolSize());
|
||||||
|
//最大线程数
|
||||||
|
executor.setMaxPoolSize(config.getMaxPoolSize());
|
||||||
|
//队列容量
|
||||||
|
executor.setQueueCapacity(config.getQueueCapacity());
|
||||||
|
//活跃时间
|
||||||
|
executor.setKeepAliveSeconds(config.getKeepAliveSeconds());
|
||||||
|
//线程名字前缀
|
||||||
|
executor.setThreadNamePrefix("el-async-");
|
||||||
|
// setRejectedExecutionHandler:当pool已经达到max size的时候,如何处理新任务
|
||||||
|
// CallerRunsPolicy:不在新线程中执行任务,而是由调用者所在的线程来执行
|
||||||
|
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||||
|
executor.initialize();
|
||||||
|
return executor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
|
||||||
|
return (throwable, method, objects) -> {
|
||||||
|
log.error("===="+throwable.getMessage()+"====", throwable);
|
||||||
|
log.error("exception method:"+method.getName());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* 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.system.config.thread;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 线程池配置属性类
|
||||||
|
* @author https://juejin.im/entry/5abb8f6951882555677e9da2
|
||||||
|
* @date 2019年10月31日14:58:18
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Component
|
||||||
|
@ConfigurationProperties(prefix = "task.pool")
|
||||||
|
public class AsyncTaskProperties {
|
||||||
|
|
||||||
|
private int corePoolSize;
|
||||||
|
|
||||||
|
private int maxPoolSize;
|
||||||
|
|
||||||
|
private int keepAliveSeconds;
|
||||||
|
|
||||||
|
private int queueCapacity;
|
||||||
|
}
|
||||||
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* 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.system.config.thread;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义线程名称
|
||||||
|
* @author
|
||||||
|
* @date 2019年10月31日17:49:55
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class TheadFactoryName implements ThreadFactory {
|
||||||
|
|
||||||
|
private static final AtomicInteger POOL_NUMBER = new AtomicInteger(1);
|
||||||
|
private final ThreadGroup group;
|
||||||
|
private final AtomicInteger threadNumber = new AtomicInteger(1);
|
||||||
|
private final String namePrefix;
|
||||||
|
|
||||||
|
public TheadFactoryName() {
|
||||||
|
this("el-pool");
|
||||||
|
}
|
||||||
|
|
||||||
|
private TheadFactoryName(String name){
|
||||||
|
// 使用当前线程的线程组,避免依赖已弃用的 SecurityManager
|
||||||
|
group = Thread.currentThread().getThreadGroup();
|
||||||
|
//此时namePrefix就是 name + 第几个用这个工厂创建线程池的
|
||||||
|
this.namePrefix = name +
|
||||||
|
POOL_NUMBER.getAndIncrement();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Thread newThread(Runnable r) {
|
||||||
|
//此时线程的名字 就是 namePrefix + -thread- + 这个线程池中第几个执行的线程
|
||||||
|
Thread t = new Thread(group, r,
|
||||||
|
namePrefix + "-thread-"+threadNumber.getAndIncrement(),
|
||||||
|
0);
|
||||||
|
if (t.isDaemon()) {
|
||||||
|
t.setDaemon(false);
|
||||||
|
}
|
||||||
|
if (t.getPriority() != Thread.NORM_PRIORITY) {
|
||||||
|
t.setPriority(Thread.NORM_PRIORITY);
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* 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.system.config.thread;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import com.yfd.platform.utils.SpringContextHolder;
|
||||||
|
|
||||||
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于获取自定义线程池
|
||||||
|
* @author
|
||||||
|
* @date 2019年10月31日18:16:47
|
||||||
|
*/
|
||||||
|
public class ThreadPoolExecutorUtil {
|
||||||
|
|
||||||
|
public static ThreadPoolExecutor getPoll(){
|
||||||
|
AsyncTaskProperties properties = SpringContextHolder.getBean(AsyncTaskProperties.class);
|
||||||
|
return new ThreadPoolExecutor(
|
||||||
|
properties.getCorePoolSize(),
|
||||||
|
properties.getMaxPoolSize(),
|
||||||
|
properties.getKeepAliveSeconds(),
|
||||||
|
TimeUnit.SECONDS,
|
||||||
|
new ArrayBlockingQueue<>(properties.getQueueCapacity()),
|
||||||
|
new TheadFactoryName()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
package com.yfd.platform.system.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";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package com.yfd.platform.system.datasource;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/******************************
|
||||||
|
* 用途说明:
|
||||||
|
* 作者姓名: wxy
|
||||||
|
* 创建时间: 2022/9/23 17:48
|
||||||
|
******************************/
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface DataSource {
|
||||||
|
|
||||||
|
String name() default "";
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,55 @@
|
|||||||
|
package com.yfd.platform.system.datasource;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
import org.aspectj.lang.annotation.Around;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
|
import org.aspectj.lang.reflect.MethodSignature;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
/******************************
|
||||||
|
* 用途说明:
|
||||||
|
* 作者姓名: wxy
|
||||||
|
* 创建时间: 2022/9/23 17:50
|
||||||
|
******************************/
|
||||||
|
@Aspect
|
||||||
|
@Component
|
||||||
|
public class DataSourceAspect {
|
||||||
|
|
||||||
|
@Pointcut("@annotation(com.yfd.platform.datasource.DataSource)")
|
||||||
|
public void dataSourcePointCut() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private String DataBaseName;
|
||||||
|
|
||||||
|
@Around("dataSourcePointCut()")
|
||||||
|
public Object around(ProceedingJoinPoint point) throws Throwable {
|
||||||
|
MethodSignature signature = (MethodSignature) point.getSignature();
|
||||||
|
Method method = signature.getMethod();
|
||||||
|
if (StrUtil.isNotBlank(DataBaseName)){
|
||||||
|
DynamicDataSource.setDataSource(DataBaseName);
|
||||||
|
}else {
|
||||||
|
DynamicDataSource.setDataSource("master");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return point.proceed();
|
||||||
|
} finally {
|
||||||
|
DynamicDataSource.clearDataSource();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDataBase(Integer type){
|
||||||
|
if (type == 1){
|
||||||
|
DataBaseName="master";
|
||||||
|
}else {
|
||||||
|
DataBaseName="slave";
|
||||||
|
}
|
||||||
|
return DataBaseName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
package com.yfd.platform.system.datasource;
|
||||||
|
|
||||||
|
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/******************************
|
||||||
|
* 用途说明:
|
||||||
|
* 作者姓名: wxy
|
||||||
|
* 创建时间: 2022/9/23 17:47
|
||||||
|
******************************/
|
||||||
|
public class DynamicDataSource extends AbstractRoutingDataSource {
|
||||||
|
private static final ThreadLocal<String> contextHolder = new ThreadLocal<>();
|
||||||
|
|
||||||
|
public DynamicDataSource(DataSource defaultTargetDataSource, Map<Object, Object> targetDataSources) {
|
||||||
|
super.setDefaultTargetDataSource(defaultTargetDataSource);
|
||||||
|
super.setTargetDataSources(targetDataSources);
|
||||||
|
super.afterPropertiesSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object determineCurrentLookupKey() {
|
||||||
|
return getDataSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setDataSource(String dataSource) {
|
||||||
|
contextHolder.set(dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getDataSource() {
|
||||||
|
return contextHolder.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clearDataSource() {
|
||||||
|
contextHolder.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
package com.yfd.platform.system.datasource;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import com.alibaba.druid.pool.DruidDataSource;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/******************************
|
||||||
|
* 用途说明:
|
||||||
|
* 作者姓名: wxy
|
||||||
|
* 创建时间: 2022/9/23 17:45
|
||||||
|
******************************/
|
||||||
|
@Configuration
|
||||||
|
@Component
|
||||||
|
public class DynamicDataSourceConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConfigurationProperties("spring.datasource.druid.master")
|
||||||
|
public DataSource wglMasterDataSource(){
|
||||||
|
DruidDataSource dataSource = new DruidDataSource();
|
||||||
|
dataSource.setBreakAfterAcquireFailure(true);
|
||||||
|
dataSource.setConnectionErrorRetryAttempts(0);
|
||||||
|
return dataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConfigurationProperties("spring.datasource.druid.slave")
|
||||||
|
public DataSource wglSlaveDataSource(){
|
||||||
|
DruidDataSource dataSource = new DruidDataSource();
|
||||||
|
dataSource.setBreakAfterAcquireFailure(true);
|
||||||
|
dataSource.setConnectionErrorRetryAttempts(0);
|
||||||
|
return dataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Primary
|
||||||
|
public DynamicDataSource dataSource(DataSource wglMasterDataSource, DataSource wglSlaveDataSource) {
|
||||||
|
Map<Object, Object> targetDataSources = new HashMap<>();
|
||||||
|
targetDataSources.put("master",wglMasterDataSource);
|
||||||
|
targetDataSources.put("slave",wglSlaveDataSource);
|
||||||
|
return new DynamicDataSource(wglMasterDataSource, targetDataSources);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
package com.yfd.platform.system.exception;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.security.access.AccessDeniedException;
|
||||||
|
import org.springframework.security.web.access.AccessDeniedHandler;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import jakarta.servlet.ServletException;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
@Component
|
||||||
|
public class AccessDeniedHandExcetion implements AccessDeniedHandler {
|
||||||
|
@Override
|
||||||
|
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
|
||||||
|
JSONObject jobj=new JSONObject();
|
||||||
|
jobj.putOnce("status","403");
|
||||||
|
jobj.putOnce("msg","用户权限不足,不能访问");
|
||||||
|
response.setStatus(200);
|
||||||
|
response.setContentType("application/json");
|
||||||
|
response.setCharacterEncoding("utf-8");
|
||||||
|
response.getWriter().println(JSONUtil.toJsonStr(jobj));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
package com.yfd.platform.system.exception;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import jakarta.servlet.ServletException;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
@Component
|
||||||
|
public class AuthenticationException implements AuthenticationEntryPoint {
|
||||||
|
@Override
|
||||||
|
public void commence(HttpServletRequest request, HttpServletResponse response, org.springframework.security.core.AuthenticationException authException) throws IOException, ServletException {
|
||||||
|
JSONObject jobj=new JSONObject();
|
||||||
|
if(authException.getMessage().equals("用户账号不存在!")){
|
||||||
|
jobj.putOnce("code","401");
|
||||||
|
jobj.putOnce("msg","用户账号不存在/密码错误,登录失败!");
|
||||||
|
}else{
|
||||||
|
jobj.putOnce("code","401");
|
||||||
|
jobj.putOnce("msg","用户Token失效,请重新登录!");
|
||||||
|
}
|
||||||
|
response.setStatus(200);
|
||||||
|
response.setContentType("application/json");
|
||||||
|
response.setCharacterEncoding("utf-8");
|
||||||
|
response.getWriter().println(JSONUtil.toJsonStr(jobj));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* 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.system.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一关于错误配置信息 异常
|
||||||
|
*
|
||||||
|
* @author: liaojinlong
|
||||||
|
* @date: 2020/6/10 18:06
|
||||||
|
*/
|
||||||
|
public class BadConfigurationException extends RuntimeException {
|
||||||
|
/**
|
||||||
|
* Constructs a new runtime exception with {@code null} as its
|
||||||
|
* detail message. The cause is not initialized, and may subsequently be
|
||||||
|
* initialized by a call to {@link #initCause}.
|
||||||
|
*/
|
||||||
|
public BadConfigurationException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new runtime exception with the specified detail message.
|
||||||
|
* The cause is not initialized, and may subsequently be initialized by a
|
||||||
|
* call to {@link #initCause}.
|
||||||
|
*
|
||||||
|
* @param message the detail message. The detail message is saved for
|
||||||
|
* later retrieval by the {@link #getMessage()} method.
|
||||||
|
*/
|
||||||
|
public BadConfigurationException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new runtime exception with the specified detail message and
|
||||||
|
* cause. <p>Note that the detail message associated with
|
||||||
|
* {@code cause} is <i>not</i> automatically incorporated in
|
||||||
|
* this runtime exception's detail message.
|
||||||
|
*
|
||||||
|
* @param message the detail message (which is saved for later retrieval
|
||||||
|
* by the {@link #getMessage()} method).
|
||||||
|
* @param cause the cause (which is saved for later retrieval by the
|
||||||
|
* {@link #getCause()} method). (A {@code null} value is
|
||||||
|
* permitted, and indicates that the cause is nonexistent or
|
||||||
|
* unknown.)
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
|
public BadConfigurationException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new runtime exception with the specified cause and a
|
||||||
|
* detail message of {@code (cause==null ? null : cause.toString())}
|
||||||
|
* (which typically contains the class and detail message of
|
||||||
|
* {@code cause}). This constructor is useful for runtime exceptions
|
||||||
|
* that are little more than wrappers for other throwables.
|
||||||
|
*
|
||||||
|
* @param cause the cause (which is saved for later retrieval by the
|
||||||
|
* {@link #getCause()} method). (A {@code null} value is
|
||||||
|
* permitted, and indicates that the cause is nonexistent or
|
||||||
|
* unknown.)
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
|
public BadConfigurationException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new runtime exception with the specified detail
|
||||||
|
* message, cause, suppression enabled or disabled, and writable
|
||||||
|
* stack trace enabled or disabled.
|
||||||
|
*
|
||||||
|
* @param message the detail message.
|
||||||
|
* @param cause the cause. (A {@code null} value is permitted,
|
||||||
|
* and indicates that the cause is nonexistent or unknown.)
|
||||||
|
* @param enableSuppression whether or not suppression is enabled
|
||||||
|
* or disabled
|
||||||
|
* @param writableStackTrace whether or not the stack trace should
|
||||||
|
* be writable
|
||||||
|
* @since 1.7
|
||||||
|
*/
|
||||||
|
protected BadConfigurationException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||||
|
super(message, cause, enableSuppression, writableStackTrace);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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.system.exception;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
||||||
|
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author
|
||||||
|
* @date 2018-11-23
|
||||||
|
* 统一异常处理
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public class BadRequestException extends RuntimeException{
|
||||||
|
|
||||||
|
private Integer status = BAD_REQUEST.value();
|
||||||
|
|
||||||
|
public BadRequestException(String msg){
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BadRequestException(HttpStatus status, String msg){
|
||||||
|
super(msg);
|
||||||
|
this.status = status.value();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
package com.yfd.platform.system.exception;
|
||||||
|
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author pcj
|
||||||
|
* @Date 2021/1/26 9:07
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
public class ChildrenExistException extends RuntimeException{
|
||||||
|
|
||||||
|
public ChildrenExistException(Class clazz, String field, String val) {
|
||||||
|
super(ChildrenExistException.generateMessage(clazz.getSimpleName(), field, val));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String generateMessage(String entity, String field, String val) {
|
||||||
|
return StringUtils.capitalize(entity)
|
||||||
|
+ " with " + field + " "+ val + " Children Exist";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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.system.exception;
|
||||||
|
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author
|
||||||
|
* @date 2018-11-23
|
||||||
|
*/
|
||||||
|
public class EntityExistException extends RuntimeException {
|
||||||
|
|
||||||
|
public EntityExistException(Class clazz, String field, String val) {
|
||||||
|
super(EntityExistException.generateMessage(clazz.getSimpleName(), field, val));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String generateMessage(String entity, String field, String val) {
|
||||||
|
return StringUtils.capitalize(entity)
|
||||||
|
+ " with " + field + " "+ val + " existed";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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.system.exception;
|
||||||
|
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author
|
||||||
|
* @date 2018-11-23
|
||||||
|
*/
|
||||||
|
public class EntityNotFoundException extends RuntimeException {
|
||||||
|
|
||||||
|
public EntityNotFoundException(Class clazz, String field, String val) {
|
||||||
|
super(EntityNotFoundException.generateMessage(clazz.getSimpleName(), field, val));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String generateMessage(String entity, String field, String val) {
|
||||||
|
return StringUtils.capitalize(entity)
|
||||||
|
+ " with " + field + " "+ val + " does not exist";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
package com.yfd.platform.system.system.controller;
|
||||||
|
|
||||||
|
import com.yfd.platform.config.ResponseResult;
|
||||||
|
import com.yfd.platform.datasource.DataSource;
|
||||||
|
import com.yfd.platform.datasource.DataSourceAspect;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhengsl
|
||||||
|
* @since 2022-09-20
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system")
|
||||||
|
@Tag(name = "切换数据库")
|
||||||
|
public class DataSourceController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
DataSourceAspect dataSourceAspect;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 切换数据库
|
||||||
|
*
|
||||||
|
* @DataSource(name="master") 可以通过注解方式切换数据库
|
||||||
|
*/
|
||||||
|
@GetMapping("/changeDataSource")
|
||||||
|
@Operation(summary = "切换数据库")
|
||||||
|
public ResponseResult changeDataSource(Integer type) {
|
||||||
|
if (type == null) {
|
||||||
|
return ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
String dataBase = dataSourceAspect.getDataBase(type);
|
||||||
|
String mess = "已切换为" + dataBase + "数据库";
|
||||||
|
return ResponseResult.success(mess);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,238 @@
|
|||||||
|
package com.yfd.platform.system.system.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import cn.hutool.jwt.JWTUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
|
import com.wf.captcha.base.Captcha;
|
||||||
|
import com.yfd.platform.annotation.Log;
|
||||||
|
import com.yfd.platform.config.ResponseResult;
|
||||||
|
import com.yfd.platform.config.WebConfig;
|
||||||
|
import com.yfd.platform.config.bean.LoginCodeEnum;
|
||||||
|
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.SysLog;
|
||||||
|
import com.yfd.platform.system.domain.SysUser;
|
||||||
|
import com.yfd.platform.system.service.ISysLogService;
|
||||||
|
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.Operation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author TangWei
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/user")
|
||||||
|
@Tag(name = "用户登录")
|
||||||
|
public class LoginController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AuthenticationManager authenticationManager;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WebConfig webConfig;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IUserService userService;
|
||||||
|
|
||||||
|
@Value("${rsa.private_key}")
|
||||||
|
private String privateKey;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ISysLogService sysLogService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private LoginProperties loginProperties;
|
||||||
|
|
||||||
|
@PostMapping("/login")
|
||||||
|
@Operation(summary = "登录用户")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult login(SysUser user) throws Exception {
|
||||||
|
// 密码解密
|
||||||
|
String password = RsaUtils.decryptByPrivateKey(privateKey,
|
||||||
|
user.getPassword());
|
||||||
|
|
||||||
|
// 是否需要验证码不需要改成false
|
||||||
|
boolean hascode = true;
|
||||||
|
if (hascode) {
|
||||||
|
// 查询验证码
|
||||||
|
String code = webConfig.loginuserCache().get(user.getUuid());
|
||||||
|
// 清除验证码
|
||||||
|
webConfig.loginuserCache().remove(user.getUuid());
|
||||||
|
if (StrUtil.isBlank(code)) {
|
||||||
|
return ResponseResult.error("验证码不存在或已过期");
|
||||||
|
}
|
||||||
|
if (StrUtil.isBlank(user.getCode()) || !user.getCode().equalsIgnoreCase(code)) {
|
||||||
|
return ResponseResult.error("验证码错误");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//如果认证通过了,使用userId生成token token存入ResponseResult返回
|
||||||
|
UsernamePasswordAuthenticationToken authenticationToken =
|
||||||
|
new UsernamePasswordAuthenticationToken(user.getUsername(),
|
||||||
|
password);
|
||||||
|
Authentication authenticate =
|
||||||
|
authenticationManager.authenticate(authenticationToken);
|
||||||
|
if (ObjectUtil.isNull(authenticate)) {
|
||||||
|
return ResponseResult.unlogin();
|
||||||
|
}
|
||||||
|
LoginUser loginUser = (LoginUser) authenticate.getPrincipal();
|
||||||
|
Integer status = loginUser.getUser().getStatus();
|
||||||
|
if ("0".equals(status.toString())) {
|
||||||
|
return ResponseResult.error("账号已停用");
|
||||||
|
}
|
||||||
|
HttpServletRequest request = RequestHolder.getHttpServletRequest();
|
||||||
|
SysLog sysLog = new SysLog();
|
||||||
|
sysLog.setUsercode(user.getUsername());
|
||||||
|
sysLog.setUsername(loginUser.getUser().getNickname());
|
||||||
|
sysLog.setRequestip(StringUtils.getIp(request));
|
||||||
|
sysLog.setBrowser(StringUtils.getBrowser(request));
|
||||||
|
sysLog.setOpttype("登录(login)");
|
||||||
|
sysLog.setModule("用户登录");
|
||||||
|
String className = this.getClass().getName();
|
||||||
|
String method =
|
||||||
|
Thread.currentThread().getStackTrace()[1].getMethodName();
|
||||||
|
sysLog.setMethod(className + "." + method + "()");
|
||||||
|
//sysLog.setParams(user.toString());
|
||||||
|
sysLog.setDescription(loginUser.getUser().getNickname() + "登录系统!");
|
||||||
|
sysLog.setLogtime(new Timestamp(System.currentTimeMillis()));
|
||||||
|
sysLogService.save(sysLog);
|
||||||
|
String userId = loginUser.getUser().getId();
|
||||||
|
Map<String, Object> map = new HashMap<String, Object>(10) {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
{
|
||||||
|
put("userid", userId);
|
||||||
|
put("username", loginUser.getUsername());
|
||||||
|
long expireTime =
|
||||||
|
System.currentTimeMillis() + (long) (30L * 24L * 60L * 60L * 1000L);
|
||||||
|
put("expire_time", expireTime);//个月过期
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
String token = JWTUtil.createToken(map, "12345678".getBytes());
|
||||||
|
map.put("token", token);
|
||||||
|
//把完整的用户信息存入到HuTool缓存中,userId作为key
|
||||||
|
String jsonStr = JSONUtil.toJsonStr(loginUser);
|
||||||
|
webConfig.loginuserCache().put("login:" + userId, jsonStr);
|
||||||
|
webConfig.loginuserCache().put("expire_time:" + userId, map.get("expire_time").toString());
|
||||||
|
return ResponseResult.successData(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "获取验证码")
|
||||||
|
@GetMapping(value = "/code")
|
||||||
|
public ResponseResult getCode() {
|
||||||
|
// 获取运算的结果
|
||||||
|
Captcha captcha = loginProperties.getCaptcha();
|
||||||
|
String uuid = Constant.CODE_KEY + IdUtil.simpleUUID();
|
||||||
|
//当验证码类型为 arithmetic时且长度 >= 2 时,captcha.text()的结果有几率为浮点型
|
||||||
|
String captchaValue = captcha.text();
|
||||||
|
if (captcha.getCharType() - 1 == LoginCodeEnum.arithmetic.ordinal() && captchaValue.contains(".")) {
|
||||||
|
captchaValue = captchaValue.split("\\.")[0];
|
||||||
|
}
|
||||||
|
// 保存
|
||||||
|
//redisUtils.set(uuid, captchaValue, loginProperties.getLoginCode()
|
||||||
|
// .getExpiration(), TimeUnit.MINUTES);
|
||||||
|
// 将验证码放入缓存,设置失效时间为60秒
|
||||||
|
webConfig.loginuserCache().put(uuid, captchaValue,
|
||||||
|
Constant.CODE_EXPIRATION_TIME);
|
||||||
|
// 验证码信息
|
||||||
|
Map<String, Object> imgResult = new HashMap<String, Object>(2) {{
|
||||||
|
put("img", captcha.toBase64());
|
||||||
|
put("uuid", uuid);
|
||||||
|
}};
|
||||||
|
return ResponseResult.successData(imgResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/logout")
|
||||||
|
@Operation(summary = "退出登录")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult logout() {
|
||||||
|
//获取SecurityContextHolder中的用户id
|
||||||
|
UsernamePasswordAuthenticationToken authentication =
|
||||||
|
(UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
LoginUser loginuser = (LoginUser) authentication.getPrincipal();
|
||||||
|
String userId = loginuser.getUser().getId();
|
||||||
|
//删除redis中的登陆用户信息
|
||||||
|
webConfig.loginuserCache().remove("login:" + userId);
|
||||||
|
//记录退出日志
|
||||||
|
HttpServletRequest request = RequestHolder.getHttpServletRequest();
|
||||||
|
SysLog sysLog = new SysLog();
|
||||||
|
sysLog.setUsercode(loginuser.getUsername());
|
||||||
|
sysLog.setUsername(loginuser.getUser().getNickname());
|
||||||
|
sysLog.setRequestip(StringUtils.getIp(request));
|
||||||
|
sysLog.setBrowser(StringUtils.getBrowser(request));
|
||||||
|
sysLog.setOpttype("其他(other)");
|
||||||
|
sysLog.setModule("注销退出");
|
||||||
|
sysLog.setDescription("注销退出系统!");
|
||||||
|
sysLog.setLogtime(new Timestamp(System.currentTimeMillis()));
|
||||||
|
sysLogService.save(sysLog);
|
||||||
|
return ResponseResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Log(module = "用户登录", value = "更改用户密码")
|
||||||
|
@GetMapping("/updatePassword")
|
||||||
|
@Operation(summary = "更改用户密码")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult updatePassword(@RequestBody SysUser user) throws Exception {
|
||||||
|
// 密码解密
|
||||||
|
String password = RsaUtils.decryptByPrivateKey(privateKey,
|
||||||
|
user.getPassword());
|
||||||
|
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||||
|
String cryptPassword = passwordEncoder.encode(password);
|
||||||
|
UpdateWrapper<SysUser> updateWrapper = new UpdateWrapper<>();
|
||||||
|
updateWrapper.set("password", cryptPassword);
|
||||||
|
updateWrapper.eq("id", user.getId());
|
||||||
|
userService.update(updateWrapper);
|
||||||
|
return ResponseResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/me")
|
||||||
|
@Operation(summary = "查询当前用户信息")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult getUserInfo() {
|
||||||
|
ResponseResult responseResult = userService.getLoginUserInfo();
|
||||||
|
return ResponseResult.successData(responseResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Log(module = "用户登录", value = "修改个人信息")
|
||||||
|
@PostMapping("/updatePersonalInfo")
|
||||||
|
@Operation(summary = "修改个人信息")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult updateUser(@org.springframework.web.bind.annotation.RequestBody SysUser user) {
|
||||||
|
if (StrUtil.isEmpty(user.getId())) {
|
||||||
|
return ResponseResult.error("没有用户ID");
|
||||||
|
}
|
||||||
|
//填写 当前用户名称
|
||||||
|
user.setLastmodifier(userService.getUsername());
|
||||||
|
//填写 当前日期
|
||||||
|
user.setLastmodifydate(new Timestamp(System.currentTimeMillis()));
|
||||||
|
boolean ok = userService.updateById(user);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,150 @@
|
|||||||
|
package com.yfd.platform.system.system.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateTime;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.yfd.platform.annotation.Log;
|
||||||
|
import com.yfd.platform.config.MessageConfig;
|
||||||
|
import com.yfd.platform.config.ResponseResult;
|
||||||
|
import com.yfd.platform.config.WebConfig;
|
||||||
|
import com.yfd.platform.system.domain.Message;
|
||||||
|
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.tags.Tag;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 消息通知 前端控制器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author TangWei
|
||||||
|
* @since 2023-03-19
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/message")
|
||||||
|
@Tag(name = "消息通知")
|
||||||
|
public class MessageController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IMessageService messageService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MessageConfig messageConfig;
|
||||||
|
|
||||||
|
@Operation(summary = "查询消息")
|
||||||
|
@GetMapping("/getMessageList")
|
||||||
|
public ResponseResult getMessageList(Page<Message> page,
|
||||||
|
String status, String title,
|
||||||
|
String type, String startDate,
|
||||||
|
String endDate) {
|
||||||
|
if (StrUtil.isBlank(status)) {
|
||||||
|
return ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
LambdaQueryWrapper<Message> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
if ("0".equals(status)) {
|
||||||
|
queryWrapper.eq(Message::getStatus, "1");
|
||||||
|
} else {
|
||||||
|
List<String> statusList = new ArrayList<>();
|
||||||
|
statusList.add("2");
|
||||||
|
statusList.add("9");
|
||||||
|
queryWrapper.in(Message::getStatus, statusList);
|
||||||
|
|
||||||
|
if (StrUtil.isNotBlank(title)) {
|
||||||
|
queryWrapper.like(Message::getTitle, title);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StrUtil.isNotBlank(type)) {
|
||||||
|
queryWrapper.eq(Message::getType, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
DateTime parseStartDate = DateUtil.parse(startDate);
|
||||||
|
DateTime parseEndDate = DateUtil.parse(endDate);
|
||||||
|
DateTime dateTime = DateUtil.offsetDay(parseEndDate, 1);
|
||||||
|
|
||||||
|
if (parseStartDate != null && parseEndDate != null) {
|
||||||
|
queryWrapper.ge(Message::getCreatetime, parseStartDate).lt(Message::getCreatetime, dateTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
queryWrapper.orderByDesc(Message::getCreatetime);
|
||||||
|
Page<Message> pageList = messageService.page(page, queryWrapper);
|
||||||
|
return ResponseResult.successData(pageList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "根据ID查询消息")
|
||||||
|
@GetMapping("/getMessageById")
|
||||||
|
public ResponseResult getMessageById(String id) {
|
||||||
|
if (StrUtil.isBlank(id)) {
|
||||||
|
return ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
Message message = messageService.getById(id);
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("title", message.getTitle());
|
||||||
|
map.put("content", message.getContent());
|
||||||
|
map.put("createtime", message.getCreatetime());
|
||||||
|
return ResponseResult.successData(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Log(module = "消息通知",value = "根据ID删除消息")
|
||||||
|
@Operation(summary = "根据ID删除消息")
|
||||||
|
@PostMapping("/deleteMessageById")
|
||||||
|
public ResponseResult deleteMessageById(@RequestParam String id) {
|
||||||
|
if (StrUtil.isBlank(id)) {
|
||||||
|
return ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
String[] split = id.split(",");
|
||||||
|
List<String> idList = Arrays.asList(split);
|
||||||
|
boolean ok = messageService.removeByIds(idList);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error("删除失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Log(module = "消息通知", value = "将消息标记为已阅状态")
|
||||||
|
@Operation(summary = "标记已阅")
|
||||||
|
@PostMapping("/setMessageStatus")
|
||||||
|
public ResponseResult setMessageStatus(@RequestParam String id) {
|
||||||
|
if (StrUtil.isBlank(id)) {
|
||||||
|
return ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
String[] split = id.split(",");
|
||||||
|
long time = System.currentTimeMillis();
|
||||||
|
for (String mid : split) {
|
||||||
|
Message message = messageService.getById(mid);
|
||||||
|
if ("9".equals(message.getStatus())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
message.setStatus("2");
|
||||||
|
message.setReadtime(new Timestamp(time));
|
||||||
|
messageService.updateById(message);
|
||||||
|
}
|
||||||
|
messageConfig.sendMessage();
|
||||||
|
return ResponseResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "全部已阅")
|
||||||
|
@PostMapping("/setAllMessageStatus")
|
||||||
|
public ResponseResult setAllMessageStatus() {
|
||||||
|
long time = System.currentTimeMillis();
|
||||||
|
List<Message> list =
|
||||||
|
messageService.list(new LambdaQueryWrapper<Message>().eq(Message::getStatus, "1"));
|
||||||
|
for (Message message : list) {
|
||||||
|
message.setStatus("2");
|
||||||
|
message.setReadtime(new Timestamp(time));
|
||||||
|
messageService.updateById(message);
|
||||||
|
}
|
||||||
|
messageConfig.sendMessage();
|
||||||
|
return ResponseResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,183 @@
|
|||||||
|
package com.yfd.platform.system.system.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.yfd.platform.annotation.Log;
|
||||||
|
import com.yfd.platform.config.ResponseResult;
|
||||||
|
import com.yfd.platform.system.domain.QuartzJob;
|
||||||
|
import com.yfd.platform.system.service.IQuartzJobService;
|
||||||
|
import com.yfd.platform.system.service.impl.UserServiceImpl;
|
||||||
|
import com.yfd.platform.utils.QuartzManage;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.quartz.CronExpression;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 定时任务 前端控制器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author TangWei
|
||||||
|
* @since 2023-03-19
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/quartzjob")
|
||||||
|
@Tag(name = "定时任务")
|
||||||
|
@Transactional
|
||||||
|
public class QuartzJobController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IQuartzJobService quartzJobService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UserServiceImpl currentUser;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private QuartzManage quartzManage;
|
||||||
|
|
||||||
|
@Operation(summary = "查询定时任务")
|
||||||
|
@GetMapping("/getQuartzJobList")
|
||||||
|
public ResponseResult getQuartzJobList(Page<QuartzJob> page,
|
||||||
|
String jobName) {
|
||||||
|
LambdaQueryWrapper<QuartzJob> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
if (StrUtil.isNotBlank(jobName)) {
|
||||||
|
queryWrapper.like(QuartzJob::getJobName, jobName);
|
||||||
|
}
|
||||||
|
queryWrapper.orderByAsc(QuartzJob::getOrderno);
|
||||||
|
Page<QuartzJob> pageList = quartzJobService.page(page, queryWrapper);
|
||||||
|
return ResponseResult.successData(pageList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Log(module = "定时任务管理", value = "新增定时任务")
|
||||||
|
@Operation(summary = "新增定时任务")
|
||||||
|
@PostMapping("/addQuartzJob")
|
||||||
|
public ResponseResult addQuartzJob(@RequestBody QuartzJob quartzJob) {
|
||||||
|
if (quartzJob == null) {
|
||||||
|
return ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
// 添加最近修改人
|
||||||
|
quartzJob.setLastmodifier(currentUser.getUsername());
|
||||||
|
// 添加最近修改时间
|
||||||
|
quartzJob.setLastmodifydate(new Timestamp(System.currentTimeMillis()));
|
||||||
|
if (StrUtil.isBlank(quartzJob.getJobCron()) || !CronExpression.isValidExpression(quartzJob.getJobCron())) {
|
||||||
|
return ResponseResult.error("cron表达式格式错误");
|
||||||
|
}
|
||||||
|
quartzJob.setStatus("0");
|
||||||
|
boolean ok = quartzJobService.addQuartzJob(quartzJob);
|
||||||
|
quartzManage.addJob(quartzJob);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error("新增失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Log(module = "定时任务管理", value = "设置定时任务是否有效")
|
||||||
|
@Operation(summary = "设置定时任务是否有效")
|
||||||
|
@PostMapping("/setQuartzStatus")
|
||||||
|
public ResponseResult setQuartzStatus(@RequestParam String id,
|
||||||
|
@RequestParam String status) {
|
||||||
|
if (StrUtil.isBlank(id) || StrUtil.isBlank(status)) {
|
||||||
|
return ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
LambdaUpdateWrapper<QuartzJob> updateWrapper =
|
||||||
|
new LambdaUpdateWrapper<>();
|
||||||
|
//根据id 更新状态,最近修改人,最近修改时间
|
||||||
|
updateWrapper.eq(QuartzJob::getId, id).set(QuartzJob::getStatus,
|
||||||
|
status).set(
|
||||||
|
QuartzJob::getLastmodifier, currentUser.getUsername()).set(QuartzJob::getLastmodifydate,
|
||||||
|
LocalDateTime.now());
|
||||||
|
boolean ok = quartzJobService.update(updateWrapper);
|
||||||
|
QuartzJob quartzJob = quartzJobService.getById(id);
|
||||||
|
if ("0".equals(quartzJob.getStatus())) {
|
||||||
|
quartzManage.pauseJob(quartzJob);
|
||||||
|
} else {
|
||||||
|
quartzManage.resumeJob(quartzJob);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "根据ID查询定时任务")
|
||||||
|
@GetMapping("/getQuartzJobById")
|
||||||
|
public ResponseResult getQuartzJobById(String id) {
|
||||||
|
QuartzJob quartzJob = quartzJobService.getById(id);
|
||||||
|
return ResponseResult.successData(quartzJob);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Log(module = "定时任务管理", value = "修改定时任务")
|
||||||
|
@Operation(summary = "修改定时任务")
|
||||||
|
@PostMapping("/updateQuartzJob")
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public ResponseResult updateQuartzJob(@RequestBody QuartzJob quartzJob) {
|
||||||
|
// 添加最近修改人
|
||||||
|
quartzJob.setLastmodifier(currentUser.getUsername());
|
||||||
|
// 添加最近修改时间
|
||||||
|
quartzJob.setLastmodifydate(new Timestamp(System.currentTimeMillis()));
|
||||||
|
if (StrUtil.isBlank(quartzJob.getJobCron()) || !CronExpression.isValidExpression(quartzJob.getJobCron())) {
|
||||||
|
return ResponseResult.error("cron表达式格式错误");
|
||||||
|
}
|
||||||
|
boolean ok = quartzJobService.updateById(quartzJob);
|
||||||
|
quartzManage.updateJobCron(quartzJob);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error("修改失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Log(module = "定时任务管理", value = "删除定时任务")
|
||||||
|
@Operation(summary = "删除定时任务")
|
||||||
|
@PostMapping("/deleteQuartzJob")
|
||||||
|
public ResponseResult deleteQuartzJob(@RequestParam String id) {
|
||||||
|
if (StrUtil.isBlank(id)) {
|
||||||
|
return ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
boolean ok = quartzJobService.deleteQuartzJob(id);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error("删除失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Log(module = "定时任务管理", value = "执行定时任务")
|
||||||
|
@Operation(summary = "执行定时任务")
|
||||||
|
@PostMapping("/execution")
|
||||||
|
public ResponseResult execution(@RequestParam String id) {
|
||||||
|
quartzJobService.execution(quartzJobService.getById(id));
|
||||||
|
return ResponseResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 拖动修改定时顺序
|
||||||
|
* 参数说明 fromID 当前ID toID 到达ID
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 成功或者失败
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "定时任务管理", value = "拖动定时任务")
|
||||||
|
@PostMapping("/changeDictOrder")
|
||||||
|
@Operation(summary = "拖动修改定时任务顺序")
|
||||||
|
public ResponseResult changeQuartzOrder(@RequestParam String fromID,
|
||||||
|
@RequestParam String toID) {
|
||||||
|
|
||||||
|
boolean ok = quartzJobService.changeDictOrder(fromID, toID);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
package com.yfd.platform.system.system.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
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.service.IMessageService;
|
||||||
|
import com.yfd.platform.system.service.IUserService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Huhailong
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@CrossOrigin
|
||||||
|
@RequestMapping("/sse")
|
||||||
|
@Tag(name = "SSE推送服务")
|
||||||
|
public class SSEController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IMessageService messageService;
|
||||||
|
|
||||||
|
@GetMapping("/connect/{token}")
|
||||||
|
@Operation(summary = "建立连接")
|
||||||
|
public SseEmitter connect(@PathVariable String token) {
|
||||||
|
SseEmitter connect = ServerSendEventServer.connect(token);
|
||||||
|
long count =
|
||||||
|
messageService.count(new LambdaQueryWrapper<Message>().eq(Message::getStatus, "1"));
|
||||||
|
ServerSendEventServer.sendMessage(token, count + "");
|
||||||
|
return connect;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/sendmsg")
|
||||||
|
@Operation(summary = "发送消息")
|
||||||
|
public void sendMessage(String token, String message) throws InterruptedException {
|
||||||
|
|
||||||
|
ServerSendEventServer.sendMessage(token, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/sendgroupmsg")
|
||||||
|
@Operation(summary = "多人发送消息")
|
||||||
|
public void sendgroupmsg(String groupid, String message) throws InterruptedException {
|
||||||
|
ServerSendEventServer.groupSendMessage(groupid, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/disconnect/{token}")
|
||||||
|
@Operation(summary = "关闭连接")
|
||||||
|
public void disconnect(@PathVariable String token) throws InterruptedException {
|
||||||
|
ServerSendEventServer.removeUser(token);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,68 @@
|
|||||||
|
package com.yfd.platform.system.system.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.yfd.platform.config.ResponseResult;
|
||||||
|
import com.yfd.platform.system.domain.SysConfig;
|
||||||
|
import com.yfd.platform.system.service.ISysConfigService;
|
||||||
|
import com.yfd.platform.system.service.IUserService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 系统全局配置 前端控制器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author zhengsl
|
||||||
|
* @since 2022-01-19
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/config")
|
||||||
|
@Tag(name = "系统全局配置")
|
||||||
|
public class SysConfigController {
|
||||||
|
@Resource
|
||||||
|
private ISysConfigService configService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IUserService userService;
|
||||||
|
|
||||||
|
@PostMapping("/getOneById")
|
||||||
|
@Operation(summary = "根据id查询全局配置详情记录")
|
||||||
|
@ResponseBody
|
||||||
|
public SysConfig getOneById(String id){
|
||||||
|
return configService.getById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/addConfig")
|
||||||
|
@Operation(summary = "根据id查询全局配置详情记录")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult addConfig(@RequestBody SysConfig config ) throws IOException, UnsupportedAudioFileException {
|
||||||
|
if (StrUtil.isEmpty(config.getId())){
|
||||||
|
config.setId(IdUtil.fastSimpleUUID()); }
|
||||||
|
config.setLastmodifier(userService.getUsername());
|
||||||
|
config.setLastmodifydate(new Timestamp(System.currentTimeMillis()));
|
||||||
|
boolean ok=configService.save(config);
|
||||||
|
return ResponseResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/updateById")
|
||||||
|
@Operation(summary = "根据id修改全局配置记录")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult updateById(@RequestBody SysConfig config) throws IOException, UnsupportedAudioFileException {
|
||||||
|
config.setLastmodifier(userService.getUsername());
|
||||||
|
config.setLastmodifydate(new Timestamp(System.currentTimeMillis()));
|
||||||
|
boolean ok=configService.updateById(config);
|
||||||
|
return ResponseResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,142 @@
|
|||||||
|
package com.yfd.platform.system.system.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.yfd.platform.annotation.Log;
|
||||||
|
import com.yfd.platform.config.ResponseResult;
|
||||||
|
import com.yfd.platform.system.domain.SysDictionary;
|
||||||
|
import com.yfd.platform.system.mapper.SysDictionaryItemsMapper;
|
||||||
|
import com.yfd.platform.system.service.ISysDictionaryService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 数据字典表 前端控制器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author TangWei
|
||||||
|
* @since 2023-03-08
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/dictionary")
|
||||||
|
@Tag(name = "数据字典")
|
||||||
|
public class SysDictionaryController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ISysDictionaryService sysDictionaryService;
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 获取数据字典列表
|
||||||
|
* 参数说明 dictType 字典类型
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回分页查询结果
|
||||||
|
***********************************/
|
||||||
|
@GetMapping("/dictList")
|
||||||
|
@Operation(summary = "获取数据字典列表")
|
||||||
|
public ResponseResult getDictList(String dictType) {
|
||||||
|
if (StrUtil.isBlank(dictType)) {
|
||||||
|
return ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
List<SysDictionary> sysDictionaries =
|
||||||
|
sysDictionaryService.getDictList(dictType);
|
||||||
|
return ResponseResult.successData(sysDictionaries);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 根据ID删除字典
|
||||||
|
* 参数说明 id 字典ID
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回删除结果成功或者失败
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "数据字典", value = "根据ID删除字典")
|
||||||
|
@PostMapping("/deleteById")
|
||||||
|
@Operation(summary = "根据ID删除字典")
|
||||||
|
public ResponseResult deleteDictById(@RequestParam String id) {
|
||||||
|
boolean ok = sysDictionaryService.deleteDictById(id);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 新增字典
|
||||||
|
* 参数说明 sysDictionary 字典对象
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回增加成功或者失败
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "数据字典", value = "新增数据字典")
|
||||||
|
@PostMapping("/addDict")
|
||||||
|
@Operation(summary = "新增字典")
|
||||||
|
public ResponseResult addDict(@RequestBody SysDictionary sysDictionary) {
|
||||||
|
if (sysDictionary == null) {
|
||||||
|
return ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
boolean ok = sysDictionaryService.addDict(sysDictionary);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 修改字典
|
||||||
|
* 参数说明 sysDictionary 字典对象
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回修改成功或者失败
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "数据字典", value = "修改数据字典")
|
||||||
|
@PostMapping("/updateDict")
|
||||||
|
@Operation(summary = "修改字典")
|
||||||
|
public ResponseResult updateDict(@RequestBody SysDictionary sysDictionary) {
|
||||||
|
if (sysDictionary == null) {
|
||||||
|
return ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
boolean ok = sysDictionaryService.updateById(sysDictionary);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 根据ID查询字典
|
||||||
|
* 参数说明 sysDictionary 字典对象
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回查询结果
|
||||||
|
***********************************/
|
||||||
|
@PostMapping("/getDictById")
|
||||||
|
@Operation(summary = "根据ID查询字典")
|
||||||
|
public ResponseResult getDictById(String id) {
|
||||||
|
if (StrUtil.isBlank(id)) {
|
||||||
|
return ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
SysDictionary sysDictionary = sysDictionaryService.getById(id);
|
||||||
|
return ResponseResult.successData(sysDictionary);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 拖动修改字典顺序
|
||||||
|
* 参数说明 fromID 当前ID toID 到达ID
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回拖动成功或者失败
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "数据字典", value = "拖动修改字典顺序")
|
||||||
|
@PostMapping("/changeDictOrder")
|
||||||
|
@Operation(summary = "拖动修改字典顺序")
|
||||||
|
public ResponseResult changeDictOrder(@RequestParam String fromID,
|
||||||
|
@RequestParam String toID) {
|
||||||
|
|
||||||
|
boolean ok = sysDictionaryService.changeDictOrder(fromID, toID);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,201 @@
|
|||||||
|
package com.yfd.platform.system.system.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.yfd.platform.annotation.Log;
|
||||||
|
import com.yfd.platform.config.ResponseResult;
|
||||||
|
import com.yfd.platform.system.domain.SysDictionaryItems;
|
||||||
|
import com.yfd.platform.system.mapper.SysDictionaryItemsMapper;
|
||||||
|
import com.yfd.platform.system.service.ISysDictionaryItemsService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 数据字典明细 前端控制器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author TangWei
|
||||||
|
* @since 2023-03-08
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/dictionaryItems")
|
||||||
|
@Tag(name = "数据字典项")
|
||||||
|
public class SysDictionaryItemsController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ISysDictionaryItemsService sysDictionaryItemsService;
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 分页查询字典项信息
|
||||||
|
* 参数说明 dictID 字典ID ItemName 字典项名称 pageNum 当前页
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回分页查询结果
|
||||||
|
***********************************/
|
||||||
|
@GetMapping("/page")
|
||||||
|
@Operation(summary = "分页查询字典项信息")
|
||||||
|
public ResponseResult getDictItemPage(String dictId, String dictName,
|
||||||
|
Page<SysDictionaryItems> page) {
|
||||||
|
|
||||||
|
LambdaQueryWrapper<SysDictionaryItems> queryWrapper =
|
||||||
|
new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(SysDictionaryItems::getDictId, dictId).orderByAsc(SysDictionaryItems::getOrderNo);
|
||||||
|
|
||||||
|
// 查询前将序号初始化
|
||||||
|
List<SysDictionaryItems> list =
|
||||||
|
sysDictionaryItemsService.list(queryWrapper);
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
SysDictionaryItems sysDictionaryItems = list.get(i);
|
||||||
|
sysDictionaryItems.setOrderNo(i + 1);
|
||||||
|
sysDictionaryItemsService.updateById(sysDictionaryItems);
|
||||||
|
}
|
||||||
|
Page<SysDictionaryItems> sysDictionaryItemsPage =
|
||||||
|
sysDictionaryItemsService.getDictItemPage(dictId, dictName,
|
||||||
|
page);
|
||||||
|
|
||||||
|
return ResponseResult.successData(sysDictionaryItemsPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 增加字典项
|
||||||
|
* 参数说明 sysDictionaryItems 字典项信息
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回增加成功或者失败
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "数据字典项", value = "增加字典项")
|
||||||
|
@PostMapping("/addDictionaryItem")
|
||||||
|
@Operation(summary = "增加字典项")
|
||||||
|
public ResponseResult addDictionaryItem(@RequestBody SysDictionaryItems sysDictionaryItems) {
|
||||||
|
if (sysDictionaryItems == null) {
|
||||||
|
return ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
boolean ok =
|
||||||
|
sysDictionaryItemsService.addDictionaryItem(sysDictionaryItems);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 修改字典项
|
||||||
|
* 参数说明 sysDictionaryItems 字典项信息
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回修改成功或者失败
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "数据字典项", value = "修改字典项")
|
||||||
|
@PostMapping("/updateDictionaryItem")
|
||||||
|
@Operation(summary = "修改字典项")
|
||||||
|
public ResponseResult updateDictionaryItem(@RequestBody SysDictionaryItems sysDictionaryItems) {
|
||||||
|
if (sysDictionaryItems == null) {
|
||||||
|
return ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
boolean ok =
|
||||||
|
sysDictionaryItemsService.updateById(sysDictionaryItems);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 根据ID查询字典项
|
||||||
|
* 参数说明 id 字典项ID
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回字典项信息
|
||||||
|
***********************************/
|
||||||
|
@GetMapping("/getDictItemById")
|
||||||
|
@Operation(summary = "根据ID查询字典项")
|
||||||
|
public ResponseResult getDictItemById(String id) {
|
||||||
|
if (StrUtil.isBlank(id)) {
|
||||||
|
return ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
SysDictionaryItems sysDictionaryItems =
|
||||||
|
sysDictionaryItemsService.getById(id);
|
||||||
|
return ResponseResult.successData(sysDictionaryItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 根据ID删除字典项
|
||||||
|
* 参数说明 id 字典项ID
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回删除成功或者失败
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "数据字典项", value = "根据ID删除字典项")
|
||||||
|
@PostMapping("/deleteDictItemById")
|
||||||
|
@Operation(summary = "根据ID删除字典项")
|
||||||
|
public ResponseResult deleteDictItemById(@RequestParam String id) {
|
||||||
|
if (StrUtil.isBlank(id)) {
|
||||||
|
return ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
boolean ok = sysDictionaryItemsService.removeById(id);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 批量删除字典项
|
||||||
|
* 参数说明 ids 字典项id数组
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回批量删除成功或失败
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "数据字典项", value = "批量删除字典项")
|
||||||
|
@PostMapping("/deleteDictItemByIds")
|
||||||
|
@Operation(summary = "批量删除字典项")
|
||||||
|
public ResponseResult deleteDictItemByIds(@RequestParam String id) {
|
||||||
|
if (StrUtil.isBlank(id)) {
|
||||||
|
return ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
String[] splitIds = id.split(",");
|
||||||
|
// 数组转集合
|
||||||
|
List<String> ids = Arrays.asList(splitIds);
|
||||||
|
boolean ok = sysDictionaryItemsService.removeByIds(ids);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 拖动修改字典项顺序
|
||||||
|
* 参数说明 fromID 当前ID toID 到达ID
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回拖动成功或者失败
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "数据字典项", value = "拖动修改字典项顺序")
|
||||||
|
@PostMapping("/changeItemOrder")
|
||||||
|
@Operation(summary = "拖动修改字典项顺序")
|
||||||
|
public ResponseResult changeItemOrder(@RequestParam String fromID,
|
||||||
|
@RequestParam String toID) {
|
||||||
|
boolean ok = sysDictionaryItemsService.changeItemOrder(fromID, toID);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 导出数据字典项数据
|
||||||
|
* 参数说明 sysDictionaryItemsList 所需导出的字典项集合
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回导出成功或失败
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "数据字典项", value = "导出字典数据到Excel")
|
||||||
|
@GetMapping("/exportExcel")
|
||||||
|
@Operation(summary = "导出数据字典项数据")
|
||||||
|
public void exportExcel(String dictID, String itemName,
|
||||||
|
Page<SysDictionaryItems> page,
|
||||||
|
HttpServletResponse response) {
|
||||||
|
Page<SysDictionaryItems> sysDictionaryItemsPage =
|
||||||
|
sysDictionaryItemsService.getDictItemPage(dictID, itemName,
|
||||||
|
page);
|
||||||
|
sysDictionaryItemsService.exportExcel(sysDictionaryItemsPage.getRecords(), response);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,74 @@
|
|||||||
|
package com.yfd.platform.system.system.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.yfd.platform.annotation.Log;
|
||||||
|
import com.yfd.platform.config.ResponseResult;
|
||||||
|
import com.yfd.platform.system.domain.SysLog;
|
||||||
|
import com.yfd.platform.system.service.ISysLogService;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 系统操作日志 前端控制器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author TangWei
|
||||||
|
* @since 2023-03-08
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/log")
|
||||||
|
@Tag(name = "系统日志")
|
||||||
|
public class SysLogController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ISysLogService sysLogService;
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 分页查询日志信息
|
||||||
|
* 参数说明 page分页对象、username(用户名)、(optType)
|
||||||
|
* 操作类型、startDate(开始日期)、endDate(结束日期)
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回分页查询结果
|
||||||
|
***********************************/
|
||||||
|
@PostMapping("/getLogList")
|
||||||
|
@Operation(summary = "分页查询日志信息")
|
||||||
|
public ResponseResult getLogList(String username, String optType,
|
||||||
|
String startDate,
|
||||||
|
String endDate, Page<SysLog> page) {
|
||||||
|
|
||||||
|
Page<SysLog> sysLogPage = sysLogService.getLogList(username, optType,
|
||||||
|
startDate, endDate, page);
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("list", sysLogPage.getRecords());
|
||||||
|
map.put("total", sysLogPage.getTotal());
|
||||||
|
map.put("size", sysLogPage.getSize());
|
||||||
|
map.put("current", sysLogPage.getCurrent());
|
||||||
|
return ResponseResult.successData(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 导出日志数据
|
||||||
|
* 参数说明 sysLogs 所需导出的字典项集合
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回导出成功或者失败
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "系统日志", value = "导出系统日志到Excel")
|
||||||
|
@GetMapping("/exportExcel")
|
||||||
|
@Operation(summary = "导出日志数据")
|
||||||
|
public void exportExcel(String username, String optType,
|
||||||
|
String startDate,
|
||||||
|
String endDate, Page<SysLog> page,
|
||||||
|
HttpServletResponse response) throws IOException {
|
||||||
|
|
||||||
|
Page<SysLog> sysLogPage = sysLogService.getLogList(username, optType,
|
||||||
|
startDate, endDate, page);
|
||||||
|
sysLogService.exportExcel(sysLogPage.getRecords(), response);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,310 @@
|
|||||||
|
package com.yfd.platform.system.system.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
|
import com.yfd.platform.annotation.Log;
|
||||||
|
import com.yfd.platform.config.ResponseResult;
|
||||||
|
import com.yfd.platform.system.domain.SysMenu;
|
||||||
|
import com.yfd.platform.system.domain.SysUser;
|
||||||
|
import com.yfd.platform.system.service.ISysMenuService;
|
||||||
|
import com.yfd.platform.system.service.IUserService;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
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.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 菜单及按钮 前端控制器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author zhengsl
|
||||||
|
* @since 2021-12-15
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/menu")
|
||||||
|
@Tag(name = "菜单及按钮")
|
||||||
|
public class SysMenuController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ISysMenuService sysMenuService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IUserService userService;
|
||||||
|
|
||||||
|
// 菜单图片路径通过服务层配置获取,无需在控制器注入
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:获取菜单结构树(含按钮)
|
||||||
|
* 参数说明
|
||||||
|
* systemcode 系统
|
||||||
|
* name 名称
|
||||||
|
* isdisplay 是否显示
|
||||||
|
* 返回值说明: 菜单结构树集合
|
||||||
|
***********************************/
|
||||||
|
@PostMapping("/getMenuButtonTree")
|
||||||
|
@Operation(summary = "获取菜单结构树(含按钮)")
|
||||||
|
@ResponseBody
|
||||||
|
public List<Map<String, Object>> getMenuButtonTree(String systemcode,
|
||||||
|
String name,
|
||||||
|
String isdisplay) {
|
||||||
|
return sysMenuService.getMenuButtonTree(systemcode, name, isdisplay);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:获取菜单结构树(不含按钮)
|
||||||
|
* 参数说明
|
||||||
|
* systemcode 系统
|
||||||
|
* name 名称
|
||||||
|
* isdisplay 是否显示
|
||||||
|
* 返回值说明: 菜单结构树集合
|
||||||
|
***********************************/
|
||||||
|
@PostMapping("/getMenuTree")
|
||||||
|
@Operation(summary = "获取菜单结构树(不含按钮)")
|
||||||
|
@ResponseBody
|
||||||
|
public List<Map<String, Object>> getMenuTree(String systemcode,
|
||||||
|
String name,
|
||||||
|
String isdisplay) {
|
||||||
|
return sysMenuService.getMenuTree(systemcode, name, isdisplay);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:权限分配
|
||||||
|
* 参数说明
|
||||||
|
* systemcode 系统
|
||||||
|
* name 名称
|
||||||
|
* isdisplay 是否显示
|
||||||
|
* 返回值说明: 菜单结构树集合
|
||||||
|
***********************************/
|
||||||
|
@PostMapping("/permissionAssignment")
|
||||||
|
@Operation(summary = "获取分配权限(不含按钮)")
|
||||||
|
@ResponseBody
|
||||||
|
public List<Map<String, Object>> permissionAssignment(String code, String roleId) {
|
||||||
|
if (StrUtil.isBlank(code)) {
|
||||||
|
code = "1";
|
||||||
|
}
|
||||||
|
return sysMenuService.permissionAssignment(code,roleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 获取当前用户菜单结构树
|
||||||
|
* 参数说明
|
||||||
|
* 返回值说明: java.util.List<com.yfd.platform.system.domain.SysMenu>
|
||||||
|
***********************************/
|
||||||
|
@GetMapping("/treeRoutes")
|
||||||
|
@Operation(summary = "获取当前用户菜单结构树")
|
||||||
|
@ResponseBody
|
||||||
|
public List<Map<String, Object>> getMenuTreeByUser() {
|
||||||
|
SysUser userInfo = userService.getUserInfo();
|
||||||
|
String id = "";
|
||||||
|
if (0 != userInfo.getUsertype()) {
|
||||||
|
id = userInfo.getId();
|
||||||
|
}
|
||||||
|
return sysMenuService.getMenuTree(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据id查询菜单或按钮详情
|
||||||
|
* 参数说明
|
||||||
|
* id 菜单或按钮表id
|
||||||
|
* 返回值说明: 菜单或按钮表对象
|
||||||
|
***********************************/
|
||||||
|
@PostMapping("/getOneById")
|
||||||
|
@Operation(summary = "根据id查询菜单或按钮详情")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult getOneById(String id) {
|
||||||
|
SysMenu sysMenu = sysMenuService.getById(id);
|
||||||
|
return ResponseResult.successData(sysMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:新增菜单及按钮
|
||||||
|
* 参数说明
|
||||||
|
* sysMenu 菜单或按钮表对象
|
||||||
|
* 返回值说明: 是否添加成功提示
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "菜单及按钮", value = "新增菜单及按钮!")
|
||||||
|
@PostMapping("/addMenu")
|
||||||
|
@Operation(summary = "新增菜单及按钮")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult addMenu(@RequestBody SysMenu sysMenu) {
|
||||||
|
boolean isOk = sysMenuService.addMenu(sysMenu);
|
||||||
|
if (isOk) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:修改菜单及按钮
|
||||||
|
* 参数说明
|
||||||
|
* sysMenu 菜单或按钮表对象
|
||||||
|
* 返回值说明: 是否修改成功提示
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "菜单及按钮", value = "修改菜单及按钮")
|
||||||
|
@PostMapping("/updateById")
|
||||||
|
@Operation(summary = "修改菜单及按钮")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult updateById(@RequestBody SysMenu sysMenu) {
|
||||||
|
sysMenu.setLastmodifier(userService.getUsername());
|
||||||
|
sysMenu.setLastmodifydate(new Timestamp(System.currentTimeMillis()));
|
||||||
|
boolean isOk = sysMenuService.updateById(sysMenu);
|
||||||
|
if (isOk) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据id删除单个图标
|
||||||
|
* 参数说明
|
||||||
|
* id 删除图标id
|
||||||
|
* icon 图标名称
|
||||||
|
* 返回值说明: 是否删除成功
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "菜单及按钮", value = "根据id删除单个图标!")
|
||||||
|
@PostMapping("/deleteIcon")
|
||||||
|
@Operation(summary = "根据id删除单个图标")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult deleteIcon(@RequestParam String id) {
|
||||||
|
boolean ok = sysMenuService.deleteIcon(id);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:更新菜单及按钮是否有效
|
||||||
|
* 参数说明
|
||||||
|
* id 菜单及按钮表id
|
||||||
|
* isdisplay 是否有效字段
|
||||||
|
* 返回值说明: 是否更新成功
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "菜单及按钮", value = "更新菜单及按钮是否有效!")
|
||||||
|
@PostMapping("/setIsDisplay")
|
||||||
|
@Operation(summary = "更新菜单及按钮是否有效")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult setIsDisplay(String id, String isdisplay) {
|
||||||
|
UpdateWrapper<SysMenu> updateWrapper = new UpdateWrapper<>();
|
||||||
|
//根据id 修改是否显示 ,最近修改人,最近修改时间
|
||||||
|
updateWrapper.eq("id", id).set("isdisplay", isdisplay).set(
|
||||||
|
"lastmodifier", userService.getUsername()).set(
|
||||||
|
"lastmodifydate",
|
||||||
|
new Timestamp(System.currentTimeMillis()));
|
||||||
|
boolean ok = sysMenuService.update(updateWrapper);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:菜单及按钮序号排序
|
||||||
|
* 参数说明
|
||||||
|
* parentid 上级id
|
||||||
|
* orderMap map<菜单及按钮表id,排列序号>
|
||||||
|
* 返回值说明: 是否更新成功
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "菜单及按钮", value = "菜单及按钮序号排序!")
|
||||||
|
@PostMapping("/moveOrderno")
|
||||||
|
@Operation(summary = "菜单及按钮序号排序")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult moveOrderno(@RequestParam String parentid,
|
||||||
|
@RequestParam String id,
|
||||||
|
@RequestParam int orderno) {
|
||||||
|
boolean ok = sysMenuService.moveOrderno(parentid, id, orderno);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据id删除菜单或按钮
|
||||||
|
* 参数说明
|
||||||
|
* id 删除列的id
|
||||||
|
* 返回值说明: 是否删除成功
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "菜单及按钮", value = "根据id删除菜单或按钮!")
|
||||||
|
@PostMapping("/deleteById")
|
||||||
|
@Operation(summary = "根据id删除菜单或按钮")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult deleteById(@RequestParam String id) {
|
||||||
|
boolean ok = sysMenuService.deleteById(id);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 菜单或者按钮拖动
|
||||||
|
* 参数说明 id
|
||||||
|
* 参数说明 id1
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "菜单及按钮", value = "拖动修改菜单或按钮同级顺序!")
|
||||||
|
@PostMapping("/changeMenuOrder")
|
||||||
|
@Operation(summary = "菜单或按钮切换")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult changeMenuOrder(@RequestParam String fromId,
|
||||||
|
@RequestParam String toId) {
|
||||||
|
if (StrUtil.isBlank(fromId) || StrUtil.isBlank(toId)) {
|
||||||
|
return ResponseResult.error("参数为空!");
|
||||||
|
}
|
||||||
|
if (fromId.equals(toId)) {
|
||||||
|
return ResponseResult.error("切换失败!");
|
||||||
|
}
|
||||||
|
boolean ok = sysMenuService.changeOderNoById(fromId, toId);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:上传单个图标
|
||||||
|
* 参数说明
|
||||||
|
* icon 图标
|
||||||
|
* 返回值说明: 是否上传成功
|
||||||
|
***********************************/
|
||||||
|
@PostMapping("/uploadIcon")
|
||||||
|
@Operation(summary = "上传单个图标")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult uploadIcon(MultipartFile icon, String menuId) throws FileNotFoundException {
|
||||||
|
if (StrUtil.isNotBlank(menuId)) {
|
||||||
|
SysMenu sysMenu = sysMenuService.getById(menuId);
|
||||||
|
//图片路径
|
||||||
|
String iconname =
|
||||||
|
System.getProperty("user.dir") + "\\src\\main" +
|
||||||
|
"\\resources\\static\\icon" + File.separator + sysMenu.getIcon();
|
||||||
|
//删除图标
|
||||||
|
new File(iconname).delete();
|
||||||
|
}
|
||||||
|
String filename = sysMenuService.uploadIcon(icon);
|
||||||
|
SysMenu sysMenu = new SysMenu();
|
||||||
|
sysMenu.setId(menuId);
|
||||||
|
sysMenu.setIcon(filename);
|
||||||
|
sysMenuService.updateById(sysMenu);
|
||||||
|
return ResponseResult.successData(filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,213 @@
|
|||||||
|
package com.yfd.platform.system.system.controller;
|
||||||
|
|
||||||
|
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.yfd.platform.annotation.Log;
|
||||||
|
import com.yfd.platform.config.ResponseResult;
|
||||||
|
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.IUserService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 系统组织框架 前端控制器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author zhengsl
|
||||||
|
* @since 2021-12-15
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/organization")
|
||||||
|
@Tag(name = "系统组织框架")
|
||||||
|
public class SysOrganizationController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ISysOrganizationService organizationService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IUserService userService;
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:获取组织范围树结构
|
||||||
|
* 参数说明
|
||||||
|
*parentid 上级id
|
||||||
|
* params 名称(根据名称查询二级)
|
||||||
|
* 返回值说明: 组织树集合
|
||||||
|
***********************************/
|
||||||
|
@PostMapping("/getOrgScopeTree")
|
||||||
|
@Operation(summary = "获取组织范围树结构")
|
||||||
|
@ResponseBody
|
||||||
|
public List<Map<String, Object>> getOrgScopeTree(String roleId) {
|
||||||
|
return organizationService.getOrgScopeTree(roleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:获取组织范围
|
||||||
|
* 参数说明
|
||||||
|
* 返回值说明: 组织范围集合
|
||||||
|
***********************************/
|
||||||
|
@PostMapping("/getOrgTree")
|
||||||
|
@Operation(summary = "获取组织结构树")
|
||||||
|
@ResponseBody
|
||||||
|
public List<Map<String, Object>> getOrgTree(String parentid,
|
||||||
|
String params) {
|
||||||
|
return organizationService.getOrgTree(parentid, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据企业ID查询组织详情
|
||||||
|
* 参数说明
|
||||||
|
* id 企业id
|
||||||
|
* 返回值说明: 系统组织框架对象
|
||||||
|
***********************************/
|
||||||
|
@PostMapping("/getOrganizationById")
|
||||||
|
@Operation(summary = "根据企业ID查询组织信息")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult getOrganizationById(String id, String orgName) {
|
||||||
|
if (StrUtil.isBlank(id)) {
|
||||||
|
return ResponseResult.error("查询失败!");
|
||||||
|
}
|
||||||
|
List<SysOrganization> sysOrganizations =
|
||||||
|
organizationService.getOrganizationById(id, orgName);
|
||||||
|
return ResponseResult.successData(sysOrganizations);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据ID查询组织详情
|
||||||
|
* 参数说明
|
||||||
|
* id 系统组织id
|
||||||
|
* 返回值说明: 系统组织框架对象
|
||||||
|
***********************************/
|
||||||
|
@PostMapping("/getOneById")
|
||||||
|
@Operation(summary = "根据ID查询组织详情")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult getOneById(String id) {
|
||||||
|
SysOrganization sysOrganization = organizationService.getById(id);
|
||||||
|
return ResponseResult.successData(sysOrganization);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:新增系统组织框架
|
||||||
|
* 参数说明
|
||||||
|
* sysOrganization 系统组织框架对象
|
||||||
|
* 返回值说明: 是否新增成功
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "系统组织框架", value = "新增企业或者部门!")
|
||||||
|
@PostMapping("/addOrg")
|
||||||
|
@Operation(summary = "新增系统组织框架")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult addOrg(@RequestBody SysOrganization sysOrganization) {
|
||||||
|
//判断是否是否填写 有效 否则默认为 1
|
||||||
|
if (StrUtil.isEmpty(sysOrganization.getIsvaild())) {
|
||||||
|
sysOrganization.setIsvaild("1");
|
||||||
|
}
|
||||||
|
if("".equals(sysOrganization.getId())){
|
||||||
|
sysOrganization.setId(null);
|
||||||
|
}
|
||||||
|
//填写 当前用户名称
|
||||||
|
sysOrganization.setLastmodifier(userService.getUsername());
|
||||||
|
//填写 当前日期
|
||||||
|
sysOrganization.setLastmodifydate(new Timestamp(System.currentTimeMillis()));
|
||||||
|
//新增 系统组织R
|
||||||
|
boolean isOk = organizationService.addOrg(sysOrganization);
|
||||||
|
if (isOk) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:修改系统组织框架
|
||||||
|
* 参数说明
|
||||||
|
* sysOrganization 系统组织框架对象
|
||||||
|
* 返回值说明: 是否修改成功
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "系统组织框架", value = "修改企业或者部门信息!")
|
||||||
|
@PostMapping("/updateById")
|
||||||
|
@Operation(summary = "修改系统组织框架")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult updateById(@RequestBody SysOrganization sysOrganization) {
|
||||||
|
//填写 当前用户名称
|
||||||
|
sysOrganization.setLastmodifier(userService.getUsername());
|
||||||
|
//填写 当前日期
|
||||||
|
sysOrganization.setLastmodifydate(new Timestamp(System.currentTimeMillis()));
|
||||||
|
//根据id 修改系统组织
|
||||||
|
boolean isOk = organizationService.updateById(sysOrganization);
|
||||||
|
if (isOk) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:修改系统组织框架
|
||||||
|
* 参数说明
|
||||||
|
* sysOrganization 系统组织框架对象
|
||||||
|
* 返回值说明: 是否修改成功
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "系统组织框架", value = "设置企业/部门是否有效!")
|
||||||
|
@PostMapping("/setIsValid")
|
||||||
|
@Operation(summary = "设置组织是否有效")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult setIsValid(@RequestParam String id,
|
||||||
|
@RequestParam String isvaild) {
|
||||||
|
UpdateWrapper<SysOrganization> updateWrapper = new UpdateWrapper<>();
|
||||||
|
//根据id 修改是否有效,最近修改人,最近修改时间
|
||||||
|
updateWrapper.eq("id", id).set("isvaild", isvaild).set("lastmodifier"
|
||||||
|
, userService.getUsername()).set("lastmodifydate",
|
||||||
|
new Timestamp(System.currentTimeMillis()));
|
||||||
|
boolean isOk = organizationService.update(updateWrapper);
|
||||||
|
if (isOk) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据id删除系统组织框架
|
||||||
|
* 参数说明
|
||||||
|
* id 系统组织框架id
|
||||||
|
* 返回值说明: 是否删除成功
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "系统组织框架", value = "根据ID删除企业或者部门!")
|
||||||
|
@PostMapping("/deleteById")
|
||||||
|
@Operation(summary = "根据id删除系统组织框架")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult deleteById(@RequestParam String id) {
|
||||||
|
String[] orgIds = id.split(",");
|
||||||
|
for (String orgId : orgIds) {
|
||||||
|
LambdaQueryWrapper<SysOrganization> queryWrapper =
|
||||||
|
new LambdaQueryWrapper<>();
|
||||||
|
List<SysOrganization> list =
|
||||||
|
organizationService.list(queryWrapper.eq(SysOrganization::getParentid, orgId));
|
||||||
|
List<String> ids =
|
||||||
|
list.stream().map(SysOrganization::getId).collect(Collectors.toList());
|
||||||
|
boolean isOk = organizationService.removeById(orgId);
|
||||||
|
if (!isOk) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (String oid : ids) {
|
||||||
|
organizationService.removeById(oid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ResponseResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,318 @@
|
|||||||
|
package com.yfd.platform.system.system.controller;
|
||||||
|
|
||||||
|
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.yfd.platform.annotation.Log;
|
||||||
|
import com.yfd.platform.config.ResponseResult;
|
||||||
|
import com.yfd.platform.system.domain.SysRole;
|
||||||
|
import com.yfd.platform.system.service.ISysRoleService;
|
||||||
|
import com.yfd.platform.system.service.IUserService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 系统角色 前端控制器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author zhengsl
|
||||||
|
* @since 2021-12-15
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/role")
|
||||||
|
@Tag(name = "系统角色")
|
||||||
|
public class SysRoleController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ISysRoleService roleService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IUserService userService;
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:查询所有角色
|
||||||
|
* 参数说明
|
||||||
|
* roleName 角色名称
|
||||||
|
* 返回值说明: 查询都有角色
|
||||||
|
***********************************/
|
||||||
|
@PostMapping("/list")
|
||||||
|
@Operation(summary = "查询所有角色")
|
||||||
|
@ResponseBody
|
||||||
|
public List<SysRole> list(@RequestParam(required = false) String rolename) {
|
||||||
|
return roleService.selectRoleList(rolename);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据Id获取当个角色
|
||||||
|
* 参数说明
|
||||||
|
* id 角色表id
|
||||||
|
* 返回值说明: 根据id查询到角色详情
|
||||||
|
***********************************/
|
||||||
|
@PostMapping("/getOneById")
|
||||||
|
@Operation(summary = "根据Id获取当个角色")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult getOneById(String id) {
|
||||||
|
SysRole sysRole = roleService.getById(id);
|
||||||
|
return ResponseResult.successData(sysRole);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:新增角色
|
||||||
|
* 参数说明
|
||||||
|
* sysRole 新增角色信息
|
||||||
|
* 返回值说明: 是否新增成功
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "系统角色", value = "新增角色")
|
||||||
|
@PostMapping("/addRole")
|
||||||
|
@Operation(summary = "新增角色")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult addRole(@RequestBody SysRole sysRole) {
|
||||||
|
boolean isOk = roleService.addRole(sysRole);
|
||||||
|
if (isOk) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:分配操作权限
|
||||||
|
* 参数说明
|
||||||
|
* id 角色id
|
||||||
|
* optscope 分配的权限
|
||||||
|
* 返回值说明: 是否新增成功
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "系统角色", value = "分配操作权限")
|
||||||
|
@PostMapping("/setOptScope")
|
||||||
|
@Operation(summary = "分配操作权限")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult setOptScope(@RequestParam String id,
|
||||||
|
@RequestParam String optscope) {
|
||||||
|
UpdateWrapper<SysRole> updateWrapper = new UpdateWrapper<>();
|
||||||
|
//根据id 更新权限,最近修改人,最近修改时间
|
||||||
|
updateWrapper.eq("id", id).set("optscope", optscope).set(
|
||||||
|
"lastmodifier", userService.getUsername()).set(
|
||||||
|
"lastmodifydate", LocalDateTime.now());
|
||||||
|
boolean ok = roleService.update(updateWrapper);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:角色菜单权限
|
||||||
|
* 参数说明
|
||||||
|
* id 角色id
|
||||||
|
* menuIds 权限id字符串
|
||||||
|
* 返回值说明: 是否分配成功
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "系统角色", value = "角色菜单权限")
|
||||||
|
@PostMapping("/setMenuById")
|
||||||
|
@Operation(summary = "角色菜单权限")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult setMenuById(String id, String menuIds) {
|
||||||
|
if (StrUtil.isBlank(id)) {
|
||||||
|
return ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
if (StrUtil.isBlank(menuIds)) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
}
|
||||||
|
boolean ok = roleService.setMenuById(id, menuIds);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:设置组织范围
|
||||||
|
* 参数说明
|
||||||
|
* id 角色id
|
||||||
|
* orgscope 组织范围
|
||||||
|
* 返回值说明: 是否新增成功
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "系统角色", value = "设置组织范围")
|
||||||
|
@PostMapping("/setOrgscope")
|
||||||
|
@Operation(summary = "设置组织范围")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult setOrgscope(@RequestParam String id,
|
||||||
|
@RequestParam String orgscope) {
|
||||||
|
UpdateWrapper<SysRole> updateWrapper = new UpdateWrapper<>();
|
||||||
|
//根据id 更新组织范围,最近修改人,最近修改时间
|
||||||
|
updateWrapper.eq("id", id).set("orgscope", orgscope).set(
|
||||||
|
"lastmodifier", userService.getUsername()).set(
|
||||||
|
"lastmodifydate", LocalDateTime.now());
|
||||||
|
boolean ok = roleService.update(updateWrapper);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:设置业务范围
|
||||||
|
* 参数说明
|
||||||
|
* id 角色id
|
||||||
|
* busscope 业务范围
|
||||||
|
* 返回值说明: 是否新增成功
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "系统角色", value = "设置业务范围")
|
||||||
|
@PostMapping("/setBusscope")
|
||||||
|
@Operation(summary = "设置业务范围")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult setBusscope(@RequestParam String id,
|
||||||
|
@RequestParam String busscope) {
|
||||||
|
UpdateWrapper<SysRole> updateWrapper = new UpdateWrapper<>();
|
||||||
|
//根据id 更新业务范围,最近修改人,最近修改时间
|
||||||
|
updateWrapper.eq("id", id).set("busscope", busscope).set(
|
||||||
|
"lastmodifier", userService.getUsername()).set(
|
||||||
|
"lastmodifydate", LocalDateTime.now());
|
||||||
|
boolean ok = roleService.update(updateWrapper);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:角色添加用户
|
||||||
|
* 参数说明
|
||||||
|
* roleid 角色id
|
||||||
|
* userids 用户id组
|
||||||
|
* 返回值说明: 是否新增成功
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "系统角色", value = "角色添加用户")
|
||||||
|
@PostMapping("/setRoleUsers")
|
||||||
|
@Operation(summary = "角色添加用户")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult setRoleUsers(String roleid, String userids) {
|
||||||
|
boolean isOk = true;
|
||||||
|
String[] temp = userids.split(",");
|
||||||
|
for (String userid : temp) {
|
||||||
|
isOk = isOk && userService.addUserRoles(roleid, userid);
|
||||||
|
}
|
||||||
|
if (isOk) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:删除角色用户
|
||||||
|
* 参数说明
|
||||||
|
* roleid 角色id
|
||||||
|
* 返回值说明: 是否新增成功
|
||||||
|
***********************************/
|
||||||
|
@PostMapping("/deleteRoleUser")
|
||||||
|
@Operation(summary = "删除角色用户")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult deleteRoleUsers(@RequestParam String roleid,
|
||||||
|
@RequestParam String userids) {
|
||||||
|
//根据角色id、用户id删除
|
||||||
|
boolean ok = roleService.deleteRoleUsers(roleid, userids);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:设置角色是否有效
|
||||||
|
* 参数说明
|
||||||
|
* id 角色id
|
||||||
|
*isvaild 是否有效(1 是 0 否 )
|
||||||
|
* 返回值说明: 是否新增成功
|
||||||
|
***********************************/
|
||||||
|
@PostMapping("/setIsvaild")
|
||||||
|
@Operation(summary = "设置角色是否有效")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult setIsvaild(String id, String isvaild) {
|
||||||
|
UpdateWrapper<SysRole> updateWrapper = new UpdateWrapper<>();
|
||||||
|
//根据id 更新业务范围,最近修改人,最近修改时间
|
||||||
|
updateWrapper.eq("id", id).set("isvaild", isvaild).set("lastmodifier"
|
||||||
|
, userService.getUsername()).set("lastmodifydate",
|
||||||
|
LocalDateTime.now());
|
||||||
|
boolean ok = roleService.update(updateWrapper);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:更新角色信息
|
||||||
|
* 参数说明
|
||||||
|
*sysRole 角色对象
|
||||||
|
* 返回值说明: 是否修改成功
|
||||||
|
***********************************/
|
||||||
|
@PostMapping("/updateById")
|
||||||
|
@Operation(summary = "更新角色信息")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult updateById(@RequestBody SysRole sysRole) {
|
||||||
|
//更新最近修改人
|
||||||
|
sysRole.setLastmodifier(userService.getUsername());
|
||||||
|
//更新最近修改时间
|
||||||
|
sysRole.setLastmodifydate(new Timestamp(System.currentTimeMillis()));
|
||||||
|
//根据id更新角色信息
|
||||||
|
boolean ok = roleService.updateById(sysRole);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据id删除角色
|
||||||
|
* 参数说明
|
||||||
|
*id 角色id
|
||||||
|
* 返回值说明: 是否删除成功
|
||||||
|
***********************************/
|
||||||
|
@PostMapping("/deleteById")
|
||||||
|
@Operation(summary = "根据id删除角色")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult deleteById(@RequestParam String id) {
|
||||||
|
roleService.deleteById(id);
|
||||||
|
return ResponseResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:查询已分配的用户
|
||||||
|
* 参数说明
|
||||||
|
*orgid 所属组织
|
||||||
|
*username 用户名称
|
||||||
|
*status 状态
|
||||||
|
*level 角色级别
|
||||||
|
* rolename 角色名称
|
||||||
|
* isvaild 角色是否有效
|
||||||
|
* 返回值说明: 系统用户角色数据集合
|
||||||
|
***********************************/
|
||||||
|
@PostMapping("/listRoleUsers")
|
||||||
|
@Operation(summary = "查询已分配的用户")
|
||||||
|
@ResponseBody
|
||||||
|
public List<Map> listRoleUsers(String orgid, String username,
|
||||||
|
String status, String level,
|
||||||
|
String rolename, String isvaild) {
|
||||||
|
return roleService.listRoleUsers(orgid, username, status, level,
|
||||||
|
rolename, isvaild);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,188 @@
|
|||||||
|
package com.yfd.platform.system.system.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.yfd.platform.annotation.Log;
|
||||||
|
import com.yfd.platform.config.ResponseResult;
|
||||||
|
import com.yfd.platform.datasource.DataSource;
|
||||||
|
import com.yfd.platform.system.domain.SysUser;
|
||||||
|
import com.yfd.platform.system.service.IUserService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 用户信息 前端控制器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author zhengsl
|
||||||
|
* @since 2022-09-20
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/user")
|
||||||
|
@Tag(name = "系统用户")
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IUserService userService;
|
||||||
|
|
||||||
|
@Log(module = "系统用户", value = "新增系统用户")
|
||||||
|
@PostMapping("/addUser")
|
||||||
|
@Operation(summary = "新增系统用户")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult addUser(@RequestBody SysUser user, String roleids) {
|
||||||
|
Map reslut = userService.addUser(user, roleids);
|
||||||
|
return ResponseResult.successData(reslut);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Log(module = "系统用户", value = "修改用户信息")
|
||||||
|
@PostMapping("/updateUser")
|
||||||
|
@Operation(summary = "修改用户信息")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult updateUser(@RequestBody SysUser user,
|
||||||
|
String roleids) {
|
||||||
|
if (StrUtil.isEmpty(user.getId())) {
|
||||||
|
return ResponseResult.error("没有用户ID");
|
||||||
|
}
|
||||||
|
//填写 当前用户名称
|
||||||
|
user.setLastmodifier(userService.getUsername());
|
||||||
|
//填写 当前日期
|
||||||
|
user.setLastmodifydate(new Timestamp(System.currentTimeMillis()));
|
||||||
|
Map reslut = userService.updateById(user, roleids);
|
||||||
|
return ResponseResult.successData(reslut);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/queryUsers")
|
||||||
|
@Operation(summary = "查询用户信息")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult queryUsers(String orgid,
|
||||||
|
String username, Page<SysUser> page) {
|
||||||
|
|
||||||
|
Page<SysUser> mapPage = userService.queryUsers(orgid,
|
||||||
|
username, page);
|
||||||
|
return ResponseResult.successData(mapPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:用户分配角色
|
||||||
|
* 参数说明
|
||||||
|
*idMap 用户id与角色id
|
||||||
|
* 返回值说明: 判断是否添加成功
|
||||||
|
************************************/
|
||||||
|
@Log(module = "系统用户", value = "用户分配角色")
|
||||||
|
@PostMapping("/setUserRoles")
|
||||||
|
@Operation(summary = "用户分配角色")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult setUserRoles(String roleid, String userids) {
|
||||||
|
boolean ok = userService.setUserRoles(roleid, userids);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据id删除用户
|
||||||
|
* 参数说明
|
||||||
|
*id 用户id
|
||||||
|
* 返回值说明: 判断是否删除成功
|
||||||
|
************************************/
|
||||||
|
@Log(module = "系统用户", value = "根据ID删除用户")
|
||||||
|
@PostMapping("/deleteById")
|
||||||
|
@Operation(summary = "根据ID删除用户")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult deleteById(String id) {
|
||||||
|
userService.deleteById(id);
|
||||||
|
return ResponseResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据ID批量删除用户
|
||||||
|
* 参数说明
|
||||||
|
*ids 用户id集合
|
||||||
|
* 返回值说明: 判断是否删除成功
|
||||||
|
************************************/
|
||||||
|
@Log(module = "系统用户", value = "根据ID批量删除用户")
|
||||||
|
@PostMapping("/deleteUserByIds")
|
||||||
|
@Operation(summary = "根据ID批量删除用户")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult deleteUserByIds(String id) {
|
||||||
|
if (StrUtil.isBlank(id)) {
|
||||||
|
return ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
boolean ok = userService.deleteUserByIds(id);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:重置用户密码(管理员)
|
||||||
|
* 参数说明
|
||||||
|
*id 重置密码的 用户id
|
||||||
|
* 返回值说明: 判断是否重置成功
|
||||||
|
************************************/
|
||||||
|
@Log(module = "系统用户", value = "重置用户密码")
|
||||||
|
@PostMapping("/resetPassword")
|
||||||
|
@Operation(summary = "重置用户密码")
|
||||||
|
@ResponseBody
|
||||||
|
@DataSource
|
||||||
|
public ResponseResult resetPassword(String id) throws Exception {
|
||||||
|
if (StrUtil.isBlank(id)) {
|
||||||
|
ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
boolean ok = userService.resetPassword(id);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:设置账号状态(管理员)
|
||||||
|
* 参数说明
|
||||||
|
*id 用户id
|
||||||
|
* status 设置状态
|
||||||
|
* 返回值说明: 判断是否设置成功
|
||||||
|
************************************/
|
||||||
|
@Log(module = "系统用户", value = "设置账号状态")
|
||||||
|
@PostMapping("/setStatus")
|
||||||
|
@Operation(summary = "设置账号状态")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseResult setStatus(@RequestParam String id,
|
||||||
|
@RequestParam String status) {
|
||||||
|
boolean ok = userService.setStatus(id, status);
|
||||||
|
if (ok) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:修改头像(管理员)
|
||||||
|
* 参数说明
|
||||||
|
* multipartFile 文件对象
|
||||||
|
* status 设置状态
|
||||||
|
* 返回值说明: 文件名
|
||||||
|
************************************/
|
||||||
|
@Operation(summary = "修改头像")
|
||||||
|
@PostMapping(value = "/updateAvatar")
|
||||||
|
public ResponseResult updateAvatar(String id, MultipartFile multipartFile) {
|
||||||
|
if (multipartFile == null) {
|
||||||
|
ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
boolean ok = userService.uploadAvatar(id, multipartFile);
|
||||||
|
return ResponseResult.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,78 @@
|
|||||||
|
package com.yfd.platform.system.system.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 数据字典表
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author zhengsl
|
||||||
|
* @since 2021-10-27
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("RCA_DICTIONARY")
|
||||||
|
public class Dictionary implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.ASSIGN_UUID)
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型
|
||||||
|
*/
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型名称
|
||||||
|
*/
|
||||||
|
private String typename;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码
|
||||||
|
*/
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 顺序号
|
||||||
|
*/
|
||||||
|
private String orderno;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上级代码
|
||||||
|
*/
|
||||||
|
private String parentcode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用1
|
||||||
|
*/
|
||||||
|
private String custom1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用2
|
||||||
|
*/
|
||||||
|
private String custom2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用3
|
||||||
|
*/
|
||||||
|
private String custom3;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,76 @@
|
|||||||
|
package com.yfd.platform.system.system.domain;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class LoginUser implements UserDetails {
|
||||||
|
|
||||||
|
private SysUser user;
|
||||||
|
|
||||||
|
private List<String> permissions;
|
||||||
|
|
||||||
|
public LoginUser(SysUser user, List<String> permissions) {
|
||||||
|
this.user = user;
|
||||||
|
this.permissions = permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JSONField(serialize = false)
|
||||||
|
private List<SimpleGrantedAuthority> authorities;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||||
|
// 将权限信息放入集合
|
||||||
|
authorities = permissions.stream()
|
||||||
|
.map(SimpleGrantedAuthority::new)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
return authorities;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPassword() {
|
||||||
|
return user.getPassword();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUsername() {
|
||||||
|
return user.getUsername();
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取用户昵称
|
||||||
|
public String geNickname() {
|
||||||
|
return user.getNickname();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAccountNonExpired() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAccountNonLocked() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCredentialsNonExpired() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,117 @@
|
|||||||
|
package com.yfd.platform.system.system.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 消息通知
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author TangWei
|
||||||
|
* @since 2023-03-19
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("SYS_MESSAGE")
|
||||||
|
public class Message implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.ASSIGN_UUID)
|
||||||
|
@Schema(description = "ID")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间:排序
|
||||||
|
*/
|
||||||
|
@Schema(description = "创建时间:排序")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
private Timestamp createtime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息类型:1-定时任务 2-工作流触发 3-人工触发
|
||||||
|
*/
|
||||||
|
@Schema(description = "消息类型:1-定时任务 2-工作流触发 3-人工触发")
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息标题
|
||||||
|
*/
|
||||||
|
@Schema(description = "消息标题")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息内容
|
||||||
|
*/
|
||||||
|
@Schema(description = "消息内容")
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送者名称,定时器,人员
|
||||||
|
*/
|
||||||
|
@Schema(description = "发送者名称,定时器,人员")
|
||||||
|
private String senderName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接收者代码 人员账号列表
|
||||||
|
*/
|
||||||
|
@Schema(description = "接收者代码 人员账号列表 ")
|
||||||
|
private String receiverCodes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接收者名称:为空 即为所有人,人员名称列表
|
||||||
|
*/
|
||||||
|
@Schema(description = "接收者名称:为空 即为所有人,人员名称列表")
|
||||||
|
private String receiverNames;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态:1、初始创建 2-消息已阅 9-消息过期
|
||||||
|
*/
|
||||||
|
@Schema(description = "状态:1、初始创建 2-消息已阅 9-消息过期")
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 有效期:小时
|
||||||
|
*/
|
||||||
|
@Schema(description = "有效期:小时")
|
||||||
|
private Integer validperiod;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 已阅时间
|
||||||
|
*/
|
||||||
|
@Schema(description = "已阅时间")
|
||||||
|
private Timestamp readtime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用1
|
||||||
|
*/
|
||||||
|
@Schema(description = "备用1")
|
||||||
|
private String custom1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用2
|
||||||
|
*/
|
||||||
|
@Schema(description = "备用2")
|
||||||
|
private String custom2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用3
|
||||||
|
*/
|
||||||
|
@Schema(description = "备用3")
|
||||||
|
private String custom3;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,118 @@
|
|||||||
|
package com.yfd.platform.system.system.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 定时任务
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author TangWei
|
||||||
|
* @since 2023-03-19
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("SYS_QUARTZ_JOB")
|
||||||
|
public class QuartzJob implements Serializable {
|
||||||
|
|
||||||
|
public static final String JOB_KEY = "JOB_KEY";
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID
|
||||||
|
*/
|
||||||
|
@Schema(description = "ID")
|
||||||
|
@TableId(type = IdType.ASSIGN_UUID)
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序号
|
||||||
|
*/
|
||||||
|
@Schema(description = "排序号")
|
||||||
|
private Integer orderno;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务名称
|
||||||
|
*/
|
||||||
|
@Schema(description = "任务名称")
|
||||||
|
private String jobName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行类名称
|
||||||
|
*/
|
||||||
|
@Schema(description = "执行类名称")
|
||||||
|
private String jobClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行方法名称
|
||||||
|
*/
|
||||||
|
@Schema(description = "执行方法名称")
|
||||||
|
private String jobMethod;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时间周期表达式
|
||||||
|
*/
|
||||||
|
@Schema(description = "时间周期表达式")
|
||||||
|
private String jobCron;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 方法参数
|
||||||
|
*/
|
||||||
|
@Schema(description = "方法参数")
|
||||||
|
private String jobParams;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务描述
|
||||||
|
*/
|
||||||
|
@Schema(description = "任务描述")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态:0-暂停、1-启用
|
||||||
|
*/
|
||||||
|
@Schema(description = "状态:0-暂停、1-启用")
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最近修改者
|
||||||
|
*/
|
||||||
|
@Schema(description = "最近修改者")
|
||||||
|
private String lastmodifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最近修改日期
|
||||||
|
*/
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
@Schema(description = "最近修改日期")
|
||||||
|
private Timestamp lastmodifydate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用1
|
||||||
|
*/
|
||||||
|
@Schema(description = "备用1")
|
||||||
|
private String custom1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用2
|
||||||
|
*/
|
||||||
|
@Schema(description = "备用2")
|
||||||
|
private String custom2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用3
|
||||||
|
*/
|
||||||
|
@Schema(description = "备用3")
|
||||||
|
private String custom3;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,78 @@
|
|||||||
|
package com.yfd.platform.system.system.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 系统全局配置
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author zhengsl
|
||||||
|
* @since 2022-01-19
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("SYS_CONFIG")
|
||||||
|
public class SysConfig implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.ASSIGN_UUID)
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 欢迎词
|
||||||
|
*/
|
||||||
|
private String welcome;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统功能介绍
|
||||||
|
*/
|
||||||
|
private String funcation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统版本信息
|
||||||
|
*/
|
||||||
|
private String versioninfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最近修改者
|
||||||
|
*/
|
||||||
|
private String lastmodifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最近修改日期
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.UPDATE)
|
||||||
|
private Timestamp lastmodifydate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用1
|
||||||
|
*/
|
||||||
|
private String custom1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用2
|
||||||
|
*/
|
||||||
|
private String custom2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用3
|
||||||
|
*/
|
||||||
|
private String custom3;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,73 @@
|
|||||||
|
package com.yfd.platform.system.system.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 数据字典表
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author TangWei
|
||||||
|
* @since 2023-03-08
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("SYS_DICTIONARY")
|
||||||
|
public class SysDictionary implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.ASSIGN_UUID)
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典类型 00-系统内置 01-用户配置
|
||||||
|
*/
|
||||||
|
@TableField("DICTTYPE")
|
||||||
|
private String dictType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 顺序号
|
||||||
|
*/
|
||||||
|
@TableField("ORDERNO")
|
||||||
|
private Integer orderNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典编码
|
||||||
|
*/
|
||||||
|
@TableField("DICTCODE")
|
||||||
|
private String dictCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典名称
|
||||||
|
*/
|
||||||
|
@TableField("DICTNAME")
|
||||||
|
private String dictName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用1
|
||||||
|
*/
|
||||||
|
private String custom1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用2
|
||||||
|
*/
|
||||||
|
private String custom2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用3
|
||||||
|
*/
|
||||||
|
private String custom3;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,79 @@
|
|||||||
|
package com.yfd.platform.system.system.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 数据字典明细
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author TangWei
|
||||||
|
* @since 2023-03-08
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("SYS_DICTIONARY_ITEMS")
|
||||||
|
public class SysDictionaryItems implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.ASSIGN_UUID)
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对应字典ID
|
||||||
|
*/
|
||||||
|
@TableField("DICTID")
|
||||||
|
private String dictId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 顺序号
|
||||||
|
*/
|
||||||
|
@TableField("ORDERNO")
|
||||||
|
private Integer orderNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 项编码
|
||||||
|
*/
|
||||||
|
@TableField("ITEMCODE")
|
||||||
|
private String itemCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 项名称
|
||||||
|
*/
|
||||||
|
@TableField("DICTNAME")
|
||||||
|
private String dictName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父项编码
|
||||||
|
*/
|
||||||
|
@TableField("PARENTCODE")
|
||||||
|
private String parentCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用1
|
||||||
|
*/
|
||||||
|
private String custom1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用2
|
||||||
|
*/
|
||||||
|
private String custom2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用3
|
||||||
|
*/
|
||||||
|
private String custom3;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,94 @@
|
|||||||
|
package com.yfd.platform.system.system.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 系统操作日志
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author TangWei
|
||||||
|
* @since 2023-03-08
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("SYS_LOG")
|
||||||
|
public class SysLog implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID
|
||||||
|
*/
|
||||||
|
@TableId(value = "ID", type = IdType.ASSIGN_UUID)
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户账号
|
||||||
|
*/
|
||||||
|
@TableField("USERCODE")
|
||||||
|
private String usercode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名称
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作类型 00-登录 01-新增 02-修改 03-删除 06-查询 09其他
|
||||||
|
*/
|
||||||
|
@TableField("OPTTYPE")
|
||||||
|
private String opttype;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模块名称
|
||||||
|
*/
|
||||||
|
private String module;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志描述
|
||||||
|
*/
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作方法
|
||||||
|
*/
|
||||||
|
private String method;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 方法参数
|
||||||
|
*/
|
||||||
|
private String params;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@TableField("LOGTIME")
|
||||||
|
private Timestamp logtime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求IP
|
||||||
|
*/
|
||||||
|
@TableField("REQUESTIP")
|
||||||
|
private String requestip;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 浏览器类型
|
||||||
|
*/
|
||||||
|
private String browser;
|
||||||
|
|
||||||
|
public SysLog(String opttype) {
|
||||||
|
this.opttype = opttype;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,114 @@
|
|||||||
|
package com.yfd.platform.system.system.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 菜单及按钮
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author zhengsl
|
||||||
|
* @since 2021-12-15
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("SYS_MENU")
|
||||||
|
public class SysMenu implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.ASSIGN_UUID)
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1-web 2-pad 3-mobile
|
||||||
|
*/
|
||||||
|
private String systemcode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1-菜单 2-按钮
|
||||||
|
*/
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在系统内自动生成
|
||||||
|
*/
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图标地址
|
||||||
|
*/
|
||||||
|
private String icon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否外链
|
||||||
|
*/
|
||||||
|
private String islink;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内部模块路径或者外链地址
|
||||||
|
*/
|
||||||
|
private String opturl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权限控制标识
|
||||||
|
*/
|
||||||
|
private String permission;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 顶级为0
|
||||||
|
*/
|
||||||
|
private String parentid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序号
|
||||||
|
*/
|
||||||
|
private Integer orderno;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0-不显示 1-显示
|
||||||
|
*/
|
||||||
|
private String isdisplay;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最近修改者
|
||||||
|
*/
|
||||||
|
private String lastmodifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最近修改日期
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.UPDATE)
|
||||||
|
private Timestamp lastmodifydate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用1
|
||||||
|
*/
|
||||||
|
private String custom1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用2
|
||||||
|
*/
|
||||||
|
private String custom2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用3
|
||||||
|
*/
|
||||||
|
private String custom3;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,93 @@
|
|||||||
|
package com.yfd.platform.system.system.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 系统组织框架
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author zhengsl
|
||||||
|
* @since 2021-12-15
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("SYS_ORGANIZATION")
|
||||||
|
public class SysOrganization implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.ASSIGN_UUID)
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1-公司 -2-部门
|
||||||
|
*/
|
||||||
|
private String orgtype;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 两位一级
|
||||||
|
*/
|
||||||
|
private String orgcode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组织名称
|
||||||
|
*/
|
||||||
|
private String orgname;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上级id
|
||||||
|
*/
|
||||||
|
private String parentid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组织负责人
|
||||||
|
*/
|
||||||
|
private String manager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1-是 0-否
|
||||||
|
*/
|
||||||
|
private String isvaild;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最近修改者
|
||||||
|
*/
|
||||||
|
private String lastmodifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最近修改日期
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.UPDATE)
|
||||||
|
private Timestamp lastmodifydate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用1
|
||||||
|
*/
|
||||||
|
private String custom1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用2
|
||||||
|
*/
|
||||||
|
private String custom2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用3
|
||||||
|
*/
|
||||||
|
private String custom3;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,99 @@
|
|||||||
|
package com.yfd.platform.system.system.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 系统角色
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author zhengsl
|
||||||
|
* @since 2021-12-15
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("SYS_ROLE")
|
||||||
|
public class SysRole implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.ASSIGN_UUID)
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统生成,三位编号
|
||||||
|
*/
|
||||||
|
private String rolecode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色名称
|
||||||
|
*/
|
||||||
|
private String rolename;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1-超级管理员 2-单位管理员 3-普通用户
|
||||||
|
*/
|
||||||
|
@TableField("\"LEVEL\"")
|
||||||
|
private String level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* org1,org2
|
||||||
|
*/
|
||||||
|
private String orgscope;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多个操作代码(菜单、按钮)
|
||||||
|
*/
|
||||||
|
private String optscope;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* json格式自定义业务范围
|
||||||
|
*/
|
||||||
|
private String busscope;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1-是 0-否
|
||||||
|
*/
|
||||||
|
private String isvaild;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最近修改者
|
||||||
|
*/
|
||||||
|
private String lastmodifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最近修改日期
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.UPDATE)
|
||||||
|
private Timestamp lastmodifydate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用1
|
||||||
|
*/
|
||||||
|
private String custom1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用2
|
||||||
|
*/
|
||||||
|
private String custom2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用3
|
||||||
|
*/
|
||||||
|
private String custom3;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,120 @@
|
|||||||
|
package com.yfd.platform.system.system.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 系统用户
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author zhengsl
|
||||||
|
* @since 2021-10-27
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("SYS_USER")
|
||||||
|
public class SysUser implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id 主键
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.ASSIGN_UUID)
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户类型 0-管理员 1-普通用户
|
||||||
|
*/
|
||||||
|
private Integer usertype;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名(账号)
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
/**
|
||||||
|
* 用户昵称
|
||||||
|
*/
|
||||||
|
private String nickname;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录密码(加密存储)
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 性别(0-男 1-女 )
|
||||||
|
*/
|
||||||
|
private String sex;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮箱
|
||||||
|
*/
|
||||||
|
private String email;
|
||||||
|
/**
|
||||||
|
* 手机号
|
||||||
|
*/
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 头像(预留)
|
||||||
|
*/
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号状态(1-正常 0-停用)
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门ID
|
||||||
|
*/
|
||||||
|
private String orgid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码重置时间
|
||||||
|
*/
|
||||||
|
private String pwdresettime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最近修改者
|
||||||
|
*/
|
||||||
|
private String lastmodifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最近修改日期
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.UPDATE)
|
||||||
|
private Timestamp lastmodifydate;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String uuid;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用1
|
||||||
|
*/
|
||||||
|
private String custom1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用2
|
||||||
|
*/
|
||||||
|
private String custom2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用3
|
||||||
|
*/
|
||||||
|
private String custom3;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
List<SysRole> roles;
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package com.yfd.platform.system.system.mapper;
|
||||||
|
|
||||||
|
import com.yfd.platform.system.domain.Message;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 消息通知 Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author TangWei
|
||||||
|
* @since 2023-03-19
|
||||||
|
*/
|
||||||
|
public interface MessageMapper extends BaseMapper<Message> {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package com.yfd.platform.system.system.mapper;
|
||||||
|
|
||||||
|
import com.yfd.platform.system.domain.QuartzJob;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 定时任务 Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author TangWei
|
||||||
|
* @since 2023-03-19
|
||||||
|
*/
|
||||||
|
public interface QuartzJobMapper extends BaseMapper<QuartzJob> {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package com.yfd.platform.system.system.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.yfd.platform.system.domain.SysConfig;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 系统全局配置 Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author zhengsl
|
||||||
|
* @since 2022-01-19
|
||||||
|
*/
|
||||||
|
public interface SysConfigMapper extends BaseMapper<SysConfig> {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package com.yfd.platform.system.system.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.yfd.platform.system.domain.SysDictionaryItems;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 数据字典明细 Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author TangWei
|
||||||
|
* @since 2023-03-08
|
||||||
|
*/
|
||||||
|
public interface SysDictionaryItemsMapper extends BaseMapper<SysDictionaryItems> {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
package com.yfd.platform.system.system.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.yfd.platform.system.domain.SysDictionary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 数据字典表 Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author TangWei
|
||||||
|
* @since 2023-03-08
|
||||||
|
*/
|
||||||
|
public interface SysDictionaryMapper extends BaseMapper<SysDictionary> {
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 根据字典类型获取字典最大序号
|
||||||
|
* 参数说明 sysDictionary 字典对象
|
||||||
|
* 返回值说明: 返回增加成功或者失败
|
||||||
|
***********************************/
|
||||||
|
Integer selectMaxNo(String dictType);
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package com.yfd.platform.system.system.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.yfd.platform.system.domain.SysLog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 系统操作日志 Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author TangWei
|
||||||
|
* @since 2023-03-08
|
||||||
|
*/
|
||||||
|
public interface SysLogMapper extends BaseMapper<SysLog> {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
package com.yfd.platform.system.system.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.yfd.platform.system.domain.SysMenu;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 菜单及按钮 Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author zhengsl
|
||||||
|
* @since 2021-12-15
|
||||||
|
*/
|
||||||
|
public interface SysMenuMapper extends BaseMapper<SysMenu> {
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:菜单及按钮序号向上移动
|
||||||
|
* 参数说明
|
||||||
|
* parentid 上级id
|
||||||
|
*Orderno 小于序号(原序号)
|
||||||
|
*upOrderno 大于等于序号(更改的序号加一)
|
||||||
|
* 返回值说明: 是否更新成功
|
||||||
|
***********************************/
|
||||||
|
boolean upMoveOrderno(@Param("parentid") String parentid, @Param("Orderno") int Orderno, @Param("upOrderno") int upOrderno);
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:菜单及按钮序号向下移动
|
||||||
|
* 参数说明
|
||||||
|
* parentid 上级id
|
||||||
|
*Orderno 大于序号(原序号)
|
||||||
|
*downOrderno 小于等于序号(更改的序号减一)
|
||||||
|
* 返回值说明: 是否更新成功
|
||||||
|
***********************************/
|
||||||
|
boolean downMoveOrderno(@Param("parentid") String parentid, @Param("Orderno") int Orderno, @Param("downOrderno") int downOrderno);
|
||||||
|
|
||||||
|
|
||||||
|
List<String> selectPermsByUserId(String userId);
|
||||||
|
|
||||||
|
//List<SysMenu> selectMenuByUserId(String userId);
|
||||||
|
List<SysMenu> selectMenuByUserId(String userId);
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据权限id查找系统类型
|
||||||
|
* 参数说明 id 权限id
|
||||||
|
* 返回值说明: 返回系统类型
|
||||||
|
***********************************/
|
||||||
|
String getSystemCodeById(String id);
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据角色Id查找权限
|
||||||
|
* 参数说明 id 权限id
|
||||||
|
* 返回值说明: 返回权限集合
|
||||||
|
***********************************/
|
||||||
|
List<String> selectMenuByRoleId(String id);
|
||||||
|
}
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
package com.yfd.platform.system.system.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.yfd.platform.system.domain.SysOrganization;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 系统组织框架 Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author zhengsl
|
||||||
|
* @since 2021-12-15
|
||||||
|
*/
|
||||||
|
public interface SysOrganizationMapper extends BaseMapper<SysOrganization> {
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:去重查询组织分类
|
||||||
|
* 返回值说明: 所有组织分类
|
||||||
|
***********************************/
|
||||||
|
List<String> queryOrgtype();
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据组织分类查询上级id
|
||||||
|
* 参数说明
|
||||||
|
* orgtype 组织分类
|
||||||
|
* 返回值说明: 上级id
|
||||||
|
***********************************/
|
||||||
|
List<String> queryParentid(@Param("orgtype") String orgtype);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,112 @@
|
|||||||
|
package com.yfd.platform.system.system.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.yfd.platform.system.domain.SysRole;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 系统角色 Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author zhengsl
|
||||||
|
* @since 2021-12-15
|
||||||
|
*/
|
||||||
|
public interface SysRoleMapper extends BaseMapper<SysRole> {
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据角色id查询是否存在用户
|
||||||
|
* 参数说明
|
||||||
|
* roleid 角色id
|
||||||
|
* 返回值说明: 该角色下是否存在用户
|
||||||
|
************************************/
|
||||||
|
List<Map<String, String>> isRoleUsersByroleid(String roleid);
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据角色id查询是否存在权限
|
||||||
|
* 参数说明
|
||||||
|
* roleid 角色id
|
||||||
|
* 返回值说明: 该角色下是否存在权限
|
||||||
|
************************************/
|
||||||
|
List<Map<String, String>> isRoleMenuByRoleId(String roleId);
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:查询已分配的用户
|
||||||
|
* 参数说明
|
||||||
|
*orgid 所属组织
|
||||||
|
*username 用户名称
|
||||||
|
*status 状态
|
||||||
|
*level 角色级别 '1-超级管理员 2-单位管理员 3-普通用户'
|
||||||
|
* rolename 角色名称
|
||||||
|
* isvaild 角色是否有效
|
||||||
|
* 返回值说明: 系统用户角色数据集合
|
||||||
|
***********************************/
|
||||||
|
List<Map> listRoleUsers(String orgid, String username, String status,
|
||||||
|
String level, String rolename, String isvaild);
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据 角色id和用户id 删除 (admin除外)
|
||||||
|
* 参数说明
|
||||||
|
*roleid 角色id
|
||||||
|
* urserid 用户id
|
||||||
|
* 返回值说明: 是否删除成功
|
||||||
|
***********************************/
|
||||||
|
boolean deleteRoleUsers(String roleid, String urserid);
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 根据用户id获取角色信息
|
||||||
|
* 参数说明 id 角色id
|
||||||
|
* 返回值说明: void
|
||||||
|
***********************************/
|
||||||
|
List<SysRole> getRoleByUserId(String id);
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 根据角色ID删除菜单与角色关联信息
|
||||||
|
* 参数说明 id 角色id
|
||||||
|
* 返回值说明: void
|
||||||
|
***********************************/
|
||||||
|
boolean deleteRoleMenus(String id);
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 根据角色ID删除用户与角色关联信息
|
||||||
|
* 参数说明 id 角色id
|
||||||
|
* 返回值说明: void
|
||||||
|
***********************************/
|
||||||
|
boolean deleteRoleUser(String id);
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 根据角色id获取用户id
|
||||||
|
* 参数说明 id 角色id
|
||||||
|
* 返回值说明: 用户id
|
||||||
|
***********************************/
|
||||||
|
List<String> getUserIdById(String id);
|
||||||
|
|
||||||
|
void addRoleMenu(@Param("id") String id, @Param("roleid") String roleid,
|
||||||
|
@Param("menuid") String menuid);
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明:根据用户 id 获取角色信息
|
||||||
|
* 参数说明 id 用户 id
|
||||||
|
* 返回值说明:角色列表
|
||||||
|
***********************************/
|
||||||
|
List<SysRole> getRoleListByUserId(String id);
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明:根据用户 id 获取角色 ID 列表
|
||||||
|
* 参数说明 id 用户 id
|
||||||
|
* 返回值说明:角色 ID 列表
|
||||||
|
***********************************/
|
||||||
|
List<String> getRoleIdsByUserId(String id);
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明:查询角色列表(Oracle 兼容)
|
||||||
|
* 参数说明:rolename - 角色名称
|
||||||
|
* 返回值说明:角色列表
|
||||||
|
***********************************/
|
||||||
|
List<SysRole> selectRoleList(@Param("rolename") String rolename);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,96 @@
|
|||||||
|
package com.yfd.platform.system.system.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.yfd.platform.system.domain.SysUser;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 系统用户表 Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author zhengsl
|
||||||
|
* @since 2021-10-27
|
||||||
|
*/
|
||||||
|
public interface SysUserMapper extends BaseMapper<SysUser> {
|
||||||
|
List<Map> list(@Param("total")String total, @Param("size")String size, @Param("orgid")String orgid, @Param("username")String username, @Param("mobile")String mobile , @Param("status")String status);
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:新增系统角色用户对照表 对用户分配角色
|
||||||
|
* 参数说明
|
||||||
|
* id 生成的id
|
||||||
|
* roleid 角色id
|
||||||
|
* userid 用户id
|
||||||
|
* 返回值说明:
|
||||||
|
************************************/
|
||||||
|
boolean addUserRoles(@Param("id")String id,@Param("roleid") String roleid,@Param("userid") String userid);
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据用户id 和角色id 查询 系统角色用户对照表
|
||||||
|
* 参数说明
|
||||||
|
* userid 用户id
|
||||||
|
* roleid 角色id
|
||||||
|
* 返回值说明:
|
||||||
|
************************************/
|
||||||
|
List<Map> getRoleUsersByid(@Param("roleid") String roleid,@Param("userid") String userid);
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据用户表id查询角色表所有角色
|
||||||
|
* 参数说明
|
||||||
|
* userid 用户id
|
||||||
|
* 返回值说明:
|
||||||
|
************************************/
|
||||||
|
List<Map> getLevel(@Param("userid") String userid);
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据用户表id查询角色表所有角色id
|
||||||
|
* 参数说明
|
||||||
|
* userid 用户id
|
||||||
|
* 返回值说明:
|
||||||
|
************************************/
|
||||||
|
List<String> getRoleid(@Param("userid") String userid);
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据用户表id查询角色表级别
|
||||||
|
* 参数说明
|
||||||
|
* userid 用户id
|
||||||
|
* 返回值说明:
|
||||||
|
************************************/
|
||||||
|
String getMaxLevel(@Param("userid") String userid);
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据用户id删除所分配的角色
|
||||||
|
* 参数说明
|
||||||
|
* userid 用户id
|
||||||
|
* 返回值说明:
|
||||||
|
************************************/
|
||||||
|
boolean delRoleUsersByUserid(@Param("userid") String userid);
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
* 用途说明:根据用户id删除所分配的不包含角色
|
||||||
|
* 参数说明
|
||||||
|
* userid 用户id
|
||||||
|
* roleids 多个角色id
|
||||||
|
* 返回值说明:
|
||||||
|
************************************/
|
||||||
|
boolean delInRoleUsersByUserid(@Param("userid") String userid,@Param("roleids")String[] roleids);
|
||||||
|
|
||||||
|
Page<SysUser> queryUsers(String orgid,
|
||||||
|
String username,
|
||||||
|
Page<SysUser> page);
|
||||||
|
|
||||||
|
Map<String, String> getOrganizationByid(String id);
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 根据ID删除用户与角色的关联信息
|
||||||
|
* 参数说明 ids 用户id集合
|
||||||
|
* 返回值说明: void
|
||||||
|
***********************************/
|
||||||
|
void delRoleUsersByUserIds(List<String> ids);
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package com.yfd.platform.system.system.service;
|
||||||
|
|
||||||
|
import com.yfd.platform.system.domain.Message;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 消息通知 服务类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author TangWei
|
||||||
|
* @since 2023-03-19
|
||||||
|
*/
|
||||||
|
public interface IMessageService extends IService<Message> {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
package com.yfd.platform.system.system.service;
|
||||||
|
|
||||||
|
import com.yfd.platform.system.domain.QuartzJob;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 定时任务 服务类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author TangWei
|
||||||
|
* @since 2023-03-19
|
||||||
|
*/
|
||||||
|
public interface IQuartzJobService extends IService<QuartzJob> {
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 新增定时任务
|
||||||
|
* 参数说明 quartzJob 定时对象
|
||||||
|
* 返回值说明: boolean 是否成功
|
||||||
|
***********************************/
|
||||||
|
boolean addQuartzJob(QuartzJob quartzJob);
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 删除定时任务
|
||||||
|
* 参数说明 id id
|
||||||
|
* 返回值说明: boolean 是否成功
|
||||||
|
***********************************/
|
||||||
|
boolean deleteQuartzJob(String id);
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 拖动修改定时任务顺序
|
||||||
|
* 参数说明 fromID 当前ID toID 到达ID
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回拖动成功或者失败
|
||||||
|
***********************************/
|
||||||
|
boolean changeDictOrder(String fromID, String toID);
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 执行定时任务
|
||||||
|
* 参数说明 id id
|
||||||
|
* 返回值说明: void
|
||||||
|
***********************************/
|
||||||
|
void execution(QuartzJob byId);
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user