Compare commits
113 Commits
2.0.0.rc20
...
2.0.31
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a8a4ff337 | ||
|
|
e8cc8cf8f7 | ||
|
|
bb0e5098af | ||
|
|
6d91cc7c13 | ||
|
|
94f93f8a80 | ||
|
|
9363d08308 | ||
|
|
3797c0edd2 | ||
|
|
1cf97feabf | ||
|
|
bce848af7e | ||
|
|
a6b0062f8d | ||
| 885303e555 | |||
| 0cf30770f1 | |||
| 6a66f41925 | |||
|
|
2d8208e4dc | ||
|
|
c4ba637de7 | ||
|
|
7b0b9e0925 | ||
|
|
463ddf1b1e | ||
|
|
6fdc69fc2d | ||
|
|
fde73e57b9 | ||
|
|
8a517b09fd | ||
|
|
217d044940 | ||
|
|
9ecf58d75e | ||
|
|
5c0d47a011 | ||
|
|
08066f1367 | ||
|
|
9e7ed69d37 | ||
|
|
2793b2a634 | ||
|
|
9885e640e9 | ||
|
|
9b285db5bd | ||
|
|
abbfac2f08 | ||
|
|
fba88da506 | ||
|
|
cb6e1c85b2 | ||
|
|
2649070850 | ||
|
|
48a9d46d20 | ||
|
|
f8d7e49290 | ||
|
|
2cf88cefa7 | ||
|
|
9a56994342 | ||
|
|
a987689bd6 | ||
|
|
690dffa779 | ||
|
|
3ccbd6cd8e | ||
|
|
89e0c5d1d5 | ||
|
|
b15dbc6d4c | ||
|
|
2f6b5b0b05 | ||
|
|
832d615273 | ||
|
|
383a82e530 | ||
|
|
6531709c69 | ||
|
|
6aaf91a755 | ||
|
|
f1ac7d6886 | ||
|
|
2f07f9eb66 | ||
|
|
919cd47623 | ||
|
|
eb1c20b033 | ||
|
|
c1559e96be | ||
|
|
9ef7d2d4a2 | ||
|
|
b90e92f4cb | ||
|
|
cb816d0ff0 | ||
|
|
0470ca0b9a | ||
|
|
d38077b0f8 | ||
|
|
2621c6dedc | ||
|
|
456a95778c | ||
|
|
fd0976a30c | ||
|
|
e519781207 | ||
|
|
e602f4c658 | ||
|
|
a816acaddb | ||
|
|
278429157a | ||
|
|
143b100819 | ||
|
|
d0cd9aed0b | ||
|
|
3080d8a936 | ||
|
|
3f951dfe47 | ||
|
|
9c66dafe6b | ||
|
|
d6ed2b8037 | ||
|
|
02c2ccc0ff | ||
|
|
f27d8d1658 | ||
|
|
ba9d0da33f | ||
|
|
4690fa9f88 | ||
|
|
a9f218de89 | ||
|
|
55324199cd | ||
|
|
0b32559630 | ||
|
|
01cc4f16ad | ||
|
|
2b70c8121d | ||
|
|
fd30c5cf36 | ||
|
|
0310bd4a15 | ||
|
|
80ec6d2e3d | ||
|
|
d96f17b847 | ||
|
|
7648eef981 | ||
|
|
79087f33e4 | ||
|
|
d0289d38b3 | ||
|
|
90029faa53 | ||
|
|
ecb5aa1b29 | ||
|
|
1db8ef9d85 | ||
|
|
4bcae2f8d1 | ||
|
|
9bab4cdb25 | ||
|
|
856a9f01dd | ||
|
|
e57cd5e1c8 | ||
|
|
542e23ac1b | ||
|
|
6949f50c7c | ||
|
|
7b43ae3ce1 | ||
|
|
8ca283ca85 | ||
|
|
3728291e73 | ||
|
|
6997dea968 | ||
|
|
7f601c8e60 | ||
|
|
7adc2a7c4b | ||
|
|
f4f082cc86 | ||
|
|
d21d84bc87 | ||
|
|
60f996137f | ||
|
|
11c8d234ff | ||
|
|
125c681669 | ||
|
|
b9347013f0 | ||
|
|
3415f0836f | ||
|
|
22672c8a9e | ||
|
|
a405aa7057 | ||
|
|
e39dd646f5 | ||
|
|
2ca224f7a5 | ||
|
|
d4e97babf4 | ||
|
|
a1c75d010b |
25
.gitea/workflows/mvn-deploy.yaml
Normal file
25
.gitea/workflows/mvn-deploy.yaml
Normal file
@@ -0,0 +1,25 @@
|
||||
## 工作流触发时机
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
jobs:
|
||||
|
||||
## 任务名称
|
||||
local-deploy:
|
||||
|
||||
## 任务执行的服务器
|
||||
runs-on: tiesheng-local
|
||||
|
||||
## 任务步骤
|
||||
steps:
|
||||
|
||||
## 检出代码(固定配置)
|
||||
- name: Check out repository code
|
||||
uses: https://git.tieshengkeji.com/actions/checkout@v4
|
||||
|
||||
## maven打包
|
||||
- name: Maven deploy
|
||||
run: |
|
||||
mvn deploy
|
||||
14
CHANGELOG.md
14
CHANGELOG.md
@@ -1,3 +1,17 @@
|
||||
## 2.0.12
|
||||
|
||||
- 调整OkHttp日志
|
||||
|
||||
|
||||
## 2.0.0.rc46
|
||||
|
||||
现在导入导出都接入底层流程,无需新增接口,只需要实现接口即可。
|
||||
|
||||
- 过程日志不再和操作日志同时存在
|
||||
- 过程日志新增params参数
|
||||
- 通过实现*TsImportHandler*接口编写导入逻辑
|
||||
- 通过实现*TsExportHandler*接口编写导出逻辑
|
||||
|
||||
## 2.0.0.rc4
|
||||
|
||||
- perf:TsTokenConfig不在提供静态方法
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>kepai-repo</id>
|
||||
<url>http://git.kepai365.com/tiesheng/repository/raw/master</url>
|
||||
<url>https://git.tieshengkeji.com/api/packages/tieshengkeji/maven</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
```
|
||||
|
||||
46
pom.xml
46
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
<version>2.0.31</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>springboot-parent</name>
|
||||
<description>杭州铁晟科技有限公司基础依赖</description>
|
||||
@@ -23,18 +23,19 @@
|
||||
<module>springboot-login</module>
|
||||
<module>springboot-web</module>
|
||||
<module>springboot-util</module>
|
||||
<module>springboot-poi</module>
|
||||
<module>springboot-platform</module>
|
||||
<module>springboot-message</module>
|
||||
<module>springboot-encrypt</module>
|
||||
<module>springboot-annotation</module>
|
||||
<module>springboot-role</module>
|
||||
<module>springboot-chart</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<hutool.version>5.8.31</hutool.version>
|
||||
</properties>
|
||||
|
||||
<developers>
|
||||
@@ -58,61 +59,49 @@
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-database</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
<version>2.0.31</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-login</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
<version>2.0.31</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-web</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
<version>2.0.31</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-util</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
<version>2.0.31</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-platform</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
<version>2.0.31</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-message</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-encrypt</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
<version>2.0.31</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-role</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
<version>2.0.31</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-annotation</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-poi</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
<version>2.0.31</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -132,11 +121,18 @@
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>kepai-repo-plugin</id>
|
||||
<url>http://git.kepai365.com/tiesheng/repository/raw/master</url>
|
||||
<id>tiesheng-repo-plugin</id>
|
||||
<url>https://git.tieshengkeji.com/api/packages/tieshengkeji/maven</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>gitea</id>
|
||||
<url>https://git.tieshengkeji.com/api/packages/tieshengkeji/maven</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
|
||||
31
qodana.yaml
Normal file
31
qodana.yaml
Normal file
@@ -0,0 +1,31 @@
|
||||
#-------------------------------------------------------------------------------#
|
||||
# Qodana analysis is configured by qodana.yaml file #
|
||||
# https://www.jetbrains.com/help/qodana/qodana-yaml.html #
|
||||
#-------------------------------------------------------------------------------#
|
||||
version: "1.0"
|
||||
|
||||
#Specify inspection profile for code analysis
|
||||
profile:
|
||||
name: qodana.starter
|
||||
|
||||
#Enable inspections
|
||||
#include:
|
||||
# - name: <SomeEnabledInspectionId>
|
||||
|
||||
#Disable inspections
|
||||
#exclude:
|
||||
# - name: <SomeDisabledInspectionId>
|
||||
# paths:
|
||||
# - <path/where/not/run/inspection>
|
||||
|
||||
projectJDK: 17 #(Applied in CI/CD pipeline)
|
||||
|
||||
#Execute shell command before Qodana execution (Applied in CI/CD pipeline)
|
||||
#bootstrap: sh ./prepare-qodana.sh
|
||||
|
||||
#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline)
|
||||
#plugins:
|
||||
# - id: <plugin.id> #(plugin id can be found at https://plugins.jetbrains.com)
|
||||
|
||||
#Specify Qodana linter for analysis (Applied in CI/CD pipeline)
|
||||
linter: jetbrains/qodana-jvm:latest
|
||||
BIN
springboot-ademo/.DS_Store
vendored
BIN
springboot-ademo/.DS_Store
vendored
Binary file not shown.
@@ -6,11 +6,11 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
<version>2.0.31</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-ademo</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
<version>2.0.31</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
@@ -46,8 +46,8 @@
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>kepai-repo</id>
|
||||
<url>http://git.kepai365.com/tiesheng/repository/raw/master</url>
|
||||
<id>tiesheng-repo</id>
|
||||
<url>https://git.tieshengkeji.com/api/packages/tieshengkeji/maven</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
||||
@@ -16,16 +16,11 @@ import java.util.Objects;
|
||||
@Component
|
||||
public class DemoWebConfigurer implements TieshengWebConfigurer, TsLoginConfigurer {
|
||||
|
||||
@Autowired
|
||||
GlobalConfig globalConfig;
|
||||
|
||||
|
||||
@Override
|
||||
public RequestUserInfo getCurrentUserName(TokenBean tokenBean) {
|
||||
RequestUserInfo info = new RequestUserInfo();
|
||||
if (Objects.equals(tokenBean.getId(), "1")) {
|
||||
return info;
|
||||
}
|
||||
info.setId(tokenBean.getId());
|
||||
info.setName(tokenBean.getExtra());
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.tiesheng.demo.config;
|
||||
|
||||
|
||||
import com.tiesheng.web.service.CoreConfigService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
@@ -13,9 +11,6 @@ import javax.annotation.PostConstruct;
|
||||
@Component
|
||||
public class TestJobConfig {
|
||||
|
||||
@Autowired
|
||||
CoreConfigService coreConfigService;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
}
|
||||
|
||||
@@ -1,28 +1,34 @@
|
||||
package com.tiesheng.demo.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.date.TimeInterval;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.log.LogFactory;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.context.AnalysisContext;
|
||||
import com.alibaba.excel.read.listener.ReadListener;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tiesheng.annotation.role.RoleAuthority;
|
||||
import com.tiesheng.annotation.token.TokenIgnore;
|
||||
import com.tiesheng.database.config.DbBackupConfig;
|
||||
import com.tiesheng.demo.pojos.CustTokenBean;
|
||||
import com.tiesheng.demo.pojos.JsonTest;
|
||||
import com.tiesheng.demo.pojos.PoiBean;
|
||||
import com.tiesheng.demo.pojos.TestFile;
|
||||
import com.tiesheng.platform.config.ding.PlatformDingConfig;
|
||||
import com.tiesheng.platform.config.ding.bean.DingUserInfo;
|
||||
import com.tiesheng.util.config.EncryptConfig;
|
||||
import com.tiesheng.util.config.GlobalConfig;
|
||||
import com.tiesheng.util.config.Ip2regionConfig;
|
||||
import com.tiesheng.util.config.TsTokenConfig;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
import com.tiesheng.util.pojos.FileUploadPath;
|
||||
import com.tiesheng.util.service.TsCacheService;
|
||||
import com.tiesheng.util.service.http.OkHttpUtil;
|
||||
import com.tiesheng.web.service.CoreLogService;
|
||||
import com.tiesheng.web.util.ProcessImportConsumer;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -31,8 +37,6 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
@@ -40,7 +44,6 @@ import java.util.function.Consumer;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/test")
|
||||
@RoleAuthority(value = "test", group = "test")
|
||||
public class TestController {
|
||||
|
||||
@Autowired
|
||||
@@ -62,15 +65,27 @@ public class TestController {
|
||||
|
||||
|
||||
@RequestMapping("/index")
|
||||
@TokenIgnore
|
||||
public void index(HttpServletResponse response) {
|
||||
globalConfig.redirect("mobile", "/test", response);
|
||||
globalConfig.redirectWithVer("mobile", "/test", response);
|
||||
}
|
||||
|
||||
@RequestMapping("/redirect")
|
||||
@TokenIgnore
|
||||
@RoleAuthority("redirect")
|
||||
public ApiResp<String> redirect(HttpServletResponse response) {
|
||||
public ApiResp<JsonTest> redirect(HttpServletResponse response) {
|
||||
|
||||
String s1 = encryptConfig.passwdCreate("qU3?wE3{bX", "");
|
||||
LogFactory.get().info(s1);
|
||||
|
||||
JsonTest jsonTest = new JsonTest();
|
||||
jsonTest.setNow(DateUtil.date());
|
||||
jsonTest.setNow1(DateUtil.date());
|
||||
|
||||
String jsonString = JSON.toJSONString(jsonTest);
|
||||
LogFactory.get().info(jsonString);
|
||||
|
||||
String s = OkHttpUtil.get("http://toolbox.tieshengkeji.com/test/login/23232/3232");
|
||||
LogFactory.get().info(s);
|
||||
|
||||
// ArrayList<String> strings = CollUtil.newArrayList("11111", "22222");
|
||||
// coreLogService.addProcess("fdfd", strings, new ProcessImportConsumer<String>() {
|
||||
@@ -92,13 +107,14 @@ public class TestController {
|
||||
|
||||
// tsTokenConfig.validToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NzYwMDY4NzUsImlkIjoiMSIsImVudmlyb25tZW50VHlwZSI6Im1vYmlsZSIsInNlcnZpY2UiOiJjb250ZXN0LXJlc2VydmUiLCJleHRyYSI6IiJ9.nsfxEFpCNHC7eNCS5DJXdu1VDdnHrTjSfgrozND70Lc", true);
|
||||
// globalConfig.redirect("mobile", "/test", response);
|
||||
return ApiResp.respOK("");
|
||||
return ApiResp.respOK(jsonTest);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/send")
|
||||
@TokenIgnore
|
||||
public ApiResp<String> sendMessage() {
|
||||
public ApiResp<String> sendMessage(CustTokenBean tokenBean) {
|
||||
|
||||
tokenBean.test();
|
||||
|
||||
// MessageReqResp reqResp = coreMessageService.send(new UserChannel("13567116463", "sms"),
|
||||
// JSONUtil.createObj().putOpt("action", "sms-visitor-invite"));
|
||||
@@ -148,16 +164,6 @@ public class TestController {
|
||||
return ApiResp.respOK(search);
|
||||
}
|
||||
|
||||
@RequestMapping("desensitize")
|
||||
@TokenIgnore
|
||||
public ApiResp<List<TestFile>> desensitize() {
|
||||
TestFile file = new TestFile("11111");
|
||||
file.setTest("111111");
|
||||
TestFile file1 = new TestFile("22222");
|
||||
file1.setTest("22222");
|
||||
return ApiResp.respOK(CollUtil.newArrayList(file, file1));
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("passwd")
|
||||
@TokenIgnore
|
||||
@@ -195,18 +201,33 @@ public class TestController {
|
||||
return ApiResp.respOK("");
|
||||
}
|
||||
|
||||
@RequestMapping("poiTool")
|
||||
|
||||
@GetMapping("getwxacode")
|
||||
@TokenIgnore
|
||||
public ApiResp<String> poiTool() {
|
||||
TimeInterval timeInterval = new TimeInterval();
|
||||
|
||||
FileUploadPath file = FileUploadPath.file("/upload/test.xlsx");
|
||||
|
||||
ExcelUtil.getReader(new File(file.getAbsolutePath())).read();
|
||||
|
||||
System.out.println("timeInterval: " + timeInterval.interval());
|
||||
|
||||
return ApiResp.respOK("");
|
||||
public ApiResp<String> getwxacode() {
|
||||
String id = "test_1111111";
|
||||
FileUploadPath path = FileUploadPath.random("png");
|
||||
JSONObject paramJson = new JSONObject();
|
||||
paramJson.put("page", "pages/login/index");
|
||||
paramJson.put("scene", "no=" + id);
|
||||
paramJson.put("env_version", "develop");
|
||||
paramJson.put("width", 430);
|
||||
paramJson.put("is_hyaline", false);
|
||||
paramJson.put("auto_color", false);
|
||||
FileUploadPath file = FileUploadPath.file(id + ".png");
|
||||
try {
|
||||
Request request = OkHttpUtil.ofPost("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" +
|
||||
"83_7xqG36kdgwuf8zzWLY3jtz7bg4ucziN-0oxbE0X9zBzwbjZ4S4Ss2RM9uHeSIcRp2K-wEp6MLzWhqo2AXj0Jpzd6IiJdUsRxqdHPvEWqAdOgt83vzZwdDf7tZBkGNGeAFASZS",
|
||||
paramJson);
|
||||
Response execute1 = OkHttpUtil.ofHttpClient().build().newCall(request).execute();
|
||||
if (execute1.body() != null) {
|
||||
FileUtil.writeFromStream(execute1.body().byteStream(), file.getAbsolutePath());
|
||||
execute1.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ApiException("每分钟最多生成5000个二维码,请稍后再试!");
|
||||
}
|
||||
return ApiResp.respOK(path.getHttpPath());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.tiesheng.demo.pojos;
|
||||
|
||||
import com.tiesheng.util.pojos.TokenBean;
|
||||
|
||||
public class CustTokenBean extends TokenBean {
|
||||
|
||||
|
||||
public void test() {
|
||||
System.out.println("test: " + getId());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.tiesheng.demo.pojos;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class JsonTest {
|
||||
|
||||
private Date now;
|
||||
@JSONField(format = "yyyy-MM-dd")
|
||||
private Date now1;
|
||||
private String no;
|
||||
private String name;
|
||||
|
||||
private JsonTest child;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// setter\getter
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public Date getNow() {
|
||||
return now;
|
||||
}
|
||||
|
||||
public void setNow(Date now) {
|
||||
this.now = now;
|
||||
}
|
||||
|
||||
public Date getNow1() {
|
||||
return now1;
|
||||
}
|
||||
|
||||
public void setNow1(Date now1) {
|
||||
this.now1 = now1;
|
||||
}
|
||||
|
||||
public String getNo() {
|
||||
return no;
|
||||
}
|
||||
|
||||
public void setNo(String no) {
|
||||
this.no = no;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public JsonTest getChild() {
|
||||
return child;
|
||||
}
|
||||
|
||||
public void setChild(JsonTest child) {
|
||||
this.child = child;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.tiesheng.demo.pojos;
|
||||
|
||||
import com.tiesheng.poi.pojos.PoiWriteBase;
|
||||
|
||||
|
||||
public class TestFile extends TestParent implements PoiWriteBase {
|
||||
|
||||
private String name;
|
||||
|
||||
public TestFile(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.tiesheng.demo.pojos;
|
||||
|
||||
import com.tiesheng.annotation.desensitize.Desensitize;
|
||||
import com.tiesheng.poi.pojos.PoiWriteBase;
|
||||
|
||||
|
||||
public class TestParent implements PoiWriteBase {
|
||||
|
||||
private String id;
|
||||
|
||||
@Desensitize()
|
||||
private String test;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// setter、getter
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTest() {
|
||||
return test;
|
||||
}
|
||||
|
||||
public void setTest(String test) {
|
||||
this.test = test;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.tiesheng.demo.service;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tiesheng.message.config.aliyun.AliyunSmsHandler;
|
||||
import com.tiesheng.message.config.aliyun.AliyunTempParam;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -15,16 +14,17 @@ public class DemoSmsHandler implements AliyunSmsHandler {
|
||||
@Override
|
||||
public AliyunTempParam handler(JSONObject obj) {
|
||||
|
||||
String action = obj.getStr("action");
|
||||
String action = obj.getString("action");
|
||||
|
||||
AliyunTempParam param = new AliyunTempParam();
|
||||
param.setSignName("智慧校园");
|
||||
|
||||
if (Objects.equals(action, "sms-visitor-invite")) {
|
||||
param.setTemplateCode("SMS_276125463");
|
||||
param.setTemplateParam(JSONUtil.createObj()
|
||||
.putOpt("date", DateUtil.today())
|
||||
);
|
||||
|
||||
JSONObject object = new JSONObject();
|
||||
object.put("date", DateUtil.today());
|
||||
param.setTemplateParam(object);
|
||||
}
|
||||
|
||||
return param;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.tiesheng.demo.service;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.tiesheng.util.pojos.TokenBean;
|
||||
import com.tiesheng.web.pojos.imex.ImportDealDTO;
|
||||
import com.tiesheng.web.service.imex.TsImportHandler;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Service
|
||||
public class UserImportHandler implements TsImportHandler<String> {
|
||||
|
||||
@Override
|
||||
public List<String> ready(ImportDealDTO dto, TokenBean token) {
|
||||
return CollUtil.newArrayList("11111");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateUrl() {
|
||||
return "/template/xsxxzx_teacher_leader.xlsx";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAction() {
|
||||
return "user_import";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int batchHandler(List<String> list) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResultFile() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,9 @@ spring:
|
||||
url: jdbc:mysql://47.96.30.85:3306/com_tiesheng_web?useSSL=false&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&queryTimeout=5400&allowMultiQueries=true&serverTimezone=GMT%2B8
|
||||
username: com_tiesheng_web
|
||||
password: 4Xo$XheGFc
|
||||
# redis:
|
||||
# url: redis://kyF0zUL3011111@47.96.30.85:6234
|
||||
redis:
|
||||
url: redis://kyF0zUL3011111@47.96.30.85:6234
|
||||
database: 1
|
||||
|
||||
platform:
|
||||
ding:
|
||||
@@ -27,11 +28,11 @@ tiesheng:
|
||||
test-map:
|
||||
"1111":
|
||||
id: "1"
|
||||
role-id: "super"
|
||||
role-id: "1822829641023524865"
|
||||
global:
|
||||
version: 2
|
||||
host: http://localhost:8100
|
||||
service: demo
|
||||
service: yrx
|
||||
aliyun:
|
||||
access-key-id: LTAI5tJtbgBCnTY5eS4SmrTf
|
||||
access-key-secret: JIHqpRUFffCHhXaJEVvWN31WcexWqG
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,42 @@
|
||||
package com.tiesheng.demo;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.log.LogFactory;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONPath;
|
||||
import com.tiesheng.demo.pojos.JsonTest;
|
||||
import com.tiesheng.login.pojos.RequestUserInfo;
|
||||
|
||||
public class MainTest {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
MainTest test = new MainTest();
|
||||
test.testJsonSelf();
|
||||
|
||||
}
|
||||
|
||||
private void testJsonSelf() {
|
||||
RequestUserInfo info = new RequestUserInfo();
|
||||
info.setId("1");
|
||||
info.setName("name");
|
||||
info.setData(info);
|
||||
String jsonStr = JSON.toJSONString(info);
|
||||
LogFactory.get().info(jsonStr);
|
||||
}
|
||||
|
||||
|
||||
private void testJsonPath() {
|
||||
JsonTest jsonTest = new JsonTest();
|
||||
jsonTest.setNo("1111");
|
||||
jsonTest.setName("1111");
|
||||
jsonTest.setNow(DateUtil.date());
|
||||
jsonTest.setChild(jsonTest);
|
||||
|
||||
JSONPath jsonPath = JSONPath.compile("child.no");
|
||||
String eval = jsonPath.eval(jsonTest, String.class);
|
||||
LogFactory.get().info(eval);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
<version>2.0.31</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-annotation</artifactId>
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.tiesheng.annotation.desensitize;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* @author hao
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Desensitize {
|
||||
|
||||
int prefix() default 1;
|
||||
|
||||
int suffix() default 1;
|
||||
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public @interface RoleAuthority {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String platform() default "web";
|
||||
String platform() default "";
|
||||
|
||||
|
||||
/**
|
||||
@@ -30,4 +30,12 @@ public @interface RoleAuthority {
|
||||
*/
|
||||
String[] group() default {};
|
||||
|
||||
|
||||
/**
|
||||
* 依赖其他权限
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String[] deps() default {};
|
||||
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
<version>2.0.31</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-poi</artifactId>
|
||||
<artifactId>springboot-chart</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
@@ -18,17 +18,21 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.22</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>easyexcel</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-util</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.tiesheng.role.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.write.style.row.SimpleRowHeightStyleStrategy;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tiesheng.annotation.operation.OperationIgnore;
|
||||
import com.tiesheng.annotation.role.RoleAuthority;
|
||||
import com.tiesheng.role.pojos.dto.ChartTemplateCheck;
|
||||
import com.tiesheng.role.pojos.vo.TsTableVO;
|
||||
import com.tiesheng.role.service.ChartService;
|
||||
import com.tiesheng.role.util.AliExcelUtil;
|
||||
import com.tiesheng.util.config.GlobalConfig;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
import com.tiesheng.util.pojos.FileUploadPath;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/chart/record")
|
||||
@RoleAuthority(value = "template", group = "chart")
|
||||
public class ChartRecordController {
|
||||
|
||||
@Resource
|
||||
ChartService chartService;
|
||||
@Resource
|
||||
GlobalConfig globalConfig;
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/check")
|
||||
@OperationIgnore
|
||||
public ApiResp<TsTableVO> check(@RequestBody @Valid ChartTemplateCheck dto) {
|
||||
|
||||
if (dto.getTemplate() == null) {
|
||||
dto.setTemplate(chartService.getById(dto.getTemplateId()));
|
||||
}
|
||||
if (dto.getTemplate() == null) {
|
||||
throw new ApiException("请选择或创建一个模版");
|
||||
}
|
||||
|
||||
try {
|
||||
List<JSONObject> chartRecordVOS = chartService.getBaseMapper()
|
||||
.recordCheck(dto.getTemplate().getTableName(), dto.getCountType(),
|
||||
dto.getTableXField(), dto.getWhere(),
|
||||
dto.getTemplate().getSField(),
|
||||
dto.getTableGroupBy());
|
||||
chartRecordVOS.forEach(it -> {
|
||||
it.put("xField", StrUtil.emptyToDefault(it.getString("xField"), "未分类"));
|
||||
});
|
||||
|
||||
return ApiResp.respOK(TsTableVO.of(dto.getTemplate(), chartRecordVOS));
|
||||
} catch (Exception e) {
|
||||
throw new ApiException("表或字段配置有误,请检查");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/export")
|
||||
@OperationIgnore
|
||||
public ApiResp<String> export(@RequestBody @Valid ChartTemplateCheck dto) {
|
||||
TsTableVO tsTableVO = check(dto).getData();
|
||||
if (tsTableVO.getDataSource().isEmpty()) {
|
||||
return ApiResp.respOK("");
|
||||
}
|
||||
|
||||
List<List<String>> headers = new ArrayList<>();
|
||||
for (TsTableVO.TableColumn column : tsTableVO.getColumns()) {
|
||||
headers.add(CollUtil.newArrayList(column.getTitle()));
|
||||
}
|
||||
|
||||
List<List<String>> contents = new ArrayList<>();
|
||||
|
||||
for (JSONObject obj : tsTableVO.getDataSource()) {
|
||||
List<String> data = new ArrayList<>();
|
||||
|
||||
for (TsTableVO.TableColumn column : tsTableVO.getColumns()) {
|
||||
data.add(obj.getString(column.getDataIndex()));
|
||||
}
|
||||
contents.add(data);
|
||||
}
|
||||
|
||||
FileUploadPath xls = FileUploadPath.random("xls");
|
||||
EasyExcel.write(xls.getAbsolutePath())
|
||||
.sheet("数据统计")
|
||||
.registerWriteHandler(new AliExcelUtil.ChatColumnWidthStyleStrategy())
|
||||
.registerWriteHandler(new SimpleRowHeightStyleStrategy((short) 24, null))
|
||||
.registerWriteHandler(AliExcelUtil.getCustomStyle())
|
||||
.head(headers)
|
||||
.doWrite(contents);
|
||||
|
||||
return ApiResp.respOK(globalConfig.buildPath(xls.getHttpPath()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package com.tiesheng.role.controller;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.tiesheng.annotation.role.RoleAuthority;
|
||||
import com.tiesheng.annotation.token.TokenIgnore;
|
||||
import com.tiesheng.role.pojos.dao.CoreChartTable;
|
||||
import com.tiesheng.role.pojos.dao.CoreChartTemplate;
|
||||
import com.tiesheng.role.pojos.dto.ChartTableEditDTO;
|
||||
import com.tiesheng.role.pojos.dto.ChartTemplateEditDTO;
|
||||
import com.tiesheng.role.service.ChartService;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
import com.tiesheng.util.pojos.IdDTO;
|
||||
import com.tiesheng.util.pojos.PageDTO;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/chart/template")
|
||||
@RoleAuthority(value = "template", group = "chart")
|
||||
public class ChartTemplateController {
|
||||
|
||||
@Resource
|
||||
ChartService chartService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取模版列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
public ApiResp<List<CoreChartTemplate>> page(PageDTO dto) {
|
||||
|
||||
QueryWrapper<CoreChartTemplate> queryWrapper = new QueryWrapper<CoreChartTemplate>()
|
||||
.eq("is_deleted", 0)
|
||||
.like(StrUtil.isNotEmpty(dto.getKeyword()), "table_name", dto.getKeyword())
|
||||
.orderByAsc("sort");
|
||||
dto.likeColumns(queryWrapper, "name", "table_name", "table_title");
|
||||
|
||||
Page<CoreChartTemplate> page = dto.pageObj();
|
||||
chartService.page(page, queryWrapper);
|
||||
return ApiResp.respOK(page.getRecords(), page.getTotal());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模版列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/edit")
|
||||
public ApiResp<String> edit(@RequestBody @Valid ChartTemplateEditDTO dto) {
|
||||
dto.setSField(StrUtil.emptyToDefault(dto.getSField(), ""));
|
||||
CoreChartTemplate template = BeanUtil.copyProperties(dto, CoreChartTemplate.class);
|
||||
template.setExts(JSON.toJSONString(dto.getExts()));
|
||||
chartService.saveOrUpdate(template);
|
||||
return ApiResp.respOK("");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取模版列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/del")
|
||||
public ApiResp<String> del(@RequestBody @Valid IdDTO dto) {
|
||||
chartService.update(null, new UpdateWrapper<CoreChartTemplate>()
|
||||
.set("is_deleted", 1)
|
||||
.eq("id", dto.getId())
|
||||
.eq("is_deleted", 0)
|
||||
);
|
||||
return ApiResp.respOK("");
|
||||
}
|
||||
|
||||
///////////////////////////// 表信息
|
||||
|
||||
|
||||
/**
|
||||
* 获取模版列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/table/list")
|
||||
public ApiResp<List<CoreChartTable>> tableList(PageDTO dto) {
|
||||
List<CoreChartTable> list = chartService.getCoreChartTableMapper()
|
||||
.selectList(new QueryWrapper<CoreChartTable>()
|
||||
.eq("is_deleted", 0)
|
||||
.like(StrUtil.isNotEmpty(dto.getKeyword()), "table_name", dto.getKeyword())
|
||||
);
|
||||
return ApiResp.respOK(list, list.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模版列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/table/edit")
|
||||
public ApiResp<String> tableEdit(@RequestBody @Valid ChartTableEditDTO dto) {
|
||||
|
||||
CoreChartTable exist = chartService.getCoreChartTableMapper().selectOne(
|
||||
new QueryWrapper<CoreChartTable>()
|
||||
.eq("table_name", dto.getTableName())
|
||||
.ne(StrUtil.isNotEmpty(dto.getId()), "id", dto.getId())
|
||||
.last("limit 1")
|
||||
);
|
||||
if (exist != null) {
|
||||
throw new ApiException("不可添加重复的表名");
|
||||
}
|
||||
|
||||
CoreChartTable template = BeanUtil.copyProperties(dto, CoreChartTable.class);
|
||||
template.setIsDeleted(0);
|
||||
template.setColumns(JSON.toJSONString(dto.getColumns()));
|
||||
if (StrUtil.isNotEmpty(dto.getId())) {
|
||||
chartService.getCoreChartTableMapper().updateById(template);
|
||||
} else {
|
||||
chartService.getCoreChartTableMapper().insert(template);
|
||||
}
|
||||
return ApiResp.respOK("");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取模版列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/table/del")
|
||||
public ApiResp<String> tableDel(@RequestBody @Valid IdDTO dto) {
|
||||
chartService.getCoreChartTableMapper().update(null, new UpdateWrapper<CoreChartTable>()
|
||||
.set("is_deleted", 1)
|
||||
.eq("id", dto.getId())
|
||||
.eq("is_deleted", 0)
|
||||
);
|
||||
return ApiResp.respOK("");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取table详情
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/table/info")
|
||||
@TokenIgnore
|
||||
public ApiResp<CoreChartTable> getTableInfo(String tableName) {
|
||||
return ApiResp.respOK(chartService.getCoreChartTableMapper().selectOne(new QueryWrapper<CoreChartTable>()
|
||||
.eq("is_deleted", 0)
|
||||
.eq("table_name", tableName)
|
||||
.last("limit 1")
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.tiesheng.role.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.tiesheng.role.pojos.dao.CoreChartTable;
|
||||
|
||||
public interface CoreChartTableMapper extends BaseMapper<CoreChartTable> {
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.tiesheng.role.mapper;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.tiesheng.role.pojos.dao.CoreChartTemplate;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CoreChartTemplateMapper extends BaseMapper<CoreChartTemplate> {
|
||||
/**
|
||||
* 根据字段查询数据
|
||||
*
|
||||
* @param table
|
||||
* @param xField
|
||||
* @param where
|
||||
* @param sField
|
||||
* @return
|
||||
*/
|
||||
List<JSONObject> recordCheck(@Param("table") String table,
|
||||
@Param("type") String type,
|
||||
@Param("xField") String xField,
|
||||
@Param("where") String where,
|
||||
@Param("sField") String sField,
|
||||
@Param("groupBy") String groupBy
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.tiesheng.role.pojos.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.tiesheng.util.pojos.DaoBase;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 图表-表信息
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName(value = "core_chart_table")
|
||||
public class CoreChartTable extends DaoBase {
|
||||
/**
|
||||
* 表名
|
||||
*/
|
||||
@TableField(value = "`table_name`")
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@TableField(value = "table_title")
|
||||
private String tableTitle;
|
||||
|
||||
/**
|
||||
* 所有字段
|
||||
*/
|
||||
@TableField(value = "`columns`")
|
||||
private String columns;
|
||||
|
||||
/**
|
||||
* 其他说明
|
||||
*/
|
||||
@TableField(value = "remark")
|
||||
private String remark;
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.tiesheng.role.pojos.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.tiesheng.util.pojos.DaoBase;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 图表-表信息
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName(value = "core_chart_template")
|
||||
public class CoreChartTemplate extends DaoBase {
|
||||
/**
|
||||
* 模版名称
|
||||
*/
|
||||
@TableField(value = "`name`")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 表名
|
||||
*/
|
||||
@TableField(value = "`table_name`")
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@TableField(value = "table_title")
|
||||
private String tableTitle;
|
||||
|
||||
/**
|
||||
* 统计方式
|
||||
*/
|
||||
@TableField(value = "`type`")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* X轴字段
|
||||
*/
|
||||
@TableField(value = "x_field")
|
||||
private String xField;
|
||||
|
||||
@TableField(value = "x_field_name")
|
||||
private String xFieldName;
|
||||
|
||||
/**
|
||||
* X轴格式化,只有X轴字段为date时有效
|
||||
*/
|
||||
@TableField(value = "x_format")
|
||||
private String xFormat;
|
||||
|
||||
/**
|
||||
* S轴字段
|
||||
*/
|
||||
@TableField(value = "s_field")
|
||||
private String sField;
|
||||
|
||||
@TableField(value = "s_field_name")
|
||||
private String sFieldName;
|
||||
|
||||
/**
|
||||
* 附件条件
|
||||
*/
|
||||
@TableField(value = "exts")
|
||||
private String exts;
|
||||
|
||||
/**
|
||||
* 其他说明
|
||||
*/
|
||||
@TableField(value = "remark")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@TableField(value = "sort")
|
||||
private Integer sort;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.tiesheng.role.pojos.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ChartTableEditDTO {
|
||||
|
||||
private String id;
|
||||
|
||||
@NotEmpty(message = "请输入【表名】")
|
||||
private String tableName;
|
||||
|
||||
@NotEmpty(message = "请输入【名称】")
|
||||
private String tableTitle;
|
||||
|
||||
@Size(min = 1, message = "请配置【表字段】")
|
||||
private List<TableColumn> columns;
|
||||
private String remark;
|
||||
|
||||
|
||||
@Data
|
||||
public static class TableColumn {
|
||||
private String key;
|
||||
private String type;
|
||||
private String remark;
|
||||
private String enums;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.tiesheng.role.pojos.dto;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.tiesheng.role.pojos.dao.CoreChartTemplate;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Data
|
||||
public class ChartTemplateCheck {
|
||||
|
||||
private String templateId;
|
||||
private CoreChartTemplate template;
|
||||
private String xFormat;
|
||||
private List<ChartTemplateEditDTO.TemplateExt> exts;
|
||||
|
||||
|
||||
@JSONField(serialize = false)
|
||||
public String getTableXField() {
|
||||
String tmpXFormat = StrUtil.emptyToDefault(getXFormat(), getTemplate().getXFormat());
|
||||
if (StrUtil.isNotEmpty(tmpXFormat)) {
|
||||
return StrUtil.format("DATE_FORMAT({},'{}')", getTemplate().getXField(), tmpXFormat);
|
||||
}
|
||||
return getTemplate().getXField();
|
||||
}
|
||||
|
||||
@JSONField(serialize = false)
|
||||
public String getTableGroupBy() {
|
||||
if (StrUtil.isNotEmpty(getTemplate().getSField())) {
|
||||
return StrUtil.format("{},{}", getTableXField(), getTemplate().getSField());
|
||||
}
|
||||
return getTableXField();
|
||||
}
|
||||
|
||||
public String getCountType() {
|
||||
if (Objects.equals(getTemplate().getType(), "count_1")) {
|
||||
return "count(1)";
|
||||
}
|
||||
return "sum(" + getTemplate().getType() + ")";
|
||||
}
|
||||
|
||||
|
||||
@JSONField(serialize = false)
|
||||
public String getWhere() {
|
||||
if (CollUtil.isEmpty(getExts())) {
|
||||
setExts(JSON.parseArray(getTemplate().getExts(), ChartTemplateEditDTO.TemplateExt.class));
|
||||
}
|
||||
if (CollUtil.isEmpty(getExts())) {
|
||||
return "";
|
||||
}
|
||||
|
||||
List<String> list = new ArrayList<>();
|
||||
for (ChartTemplateEditDTO.TemplateExt templateExt : getExts()) {
|
||||
if (templateExt.isErrorExt()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Objects.equals(templateExt.getAction(), "eq")) {
|
||||
list.add(StrUtil.format("{} = '{}'", templateExt.getKey(), templateExt.getValue()));
|
||||
} else if (Objects.equals(templateExt.getAction(), "ne")) {
|
||||
list.add(StrUtil.format("{} != '{}'", templateExt.getKey(), templateExt.getValue()));
|
||||
} else if (Objects.equals(templateExt.getAction(), "btw")) {
|
||||
List<String> split = StrUtil.split(templateExt.getValue(), ",");
|
||||
if (split.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (split.size() == 1) {
|
||||
list.add(StrUtil.format("{} > '{}'", templateExt.getKey(), split.get(0)));
|
||||
} else {
|
||||
list.add(StrUtil.format("{} between '{}' and '{}'", templateExt.getKey(), split.get(0), split.get(1)));
|
||||
}
|
||||
} else if (Objects.equals(templateExt.getAction(), "nbtw")) {
|
||||
List<String> split = StrUtil.split(templateExt.getValue(), ",");
|
||||
if (split.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (split.size() == 1) {
|
||||
list.add(StrUtil.format("{} < '{}'", templateExt.getKey(), split.get(0)));
|
||||
} else {
|
||||
list.add(StrUtil.format("{} not between '{}' and '{}'", templateExt.getKey(), split.get(0), split.get(1)));
|
||||
}
|
||||
} else if (Objects.equals(templateExt.getAction(), "in")) {
|
||||
List<String> split = StrUtil.split(templateExt.getValue(), ",");
|
||||
if (split.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
list.add(StrUtil.format("{} in ({})", templateExt.getKey(), split.stream().map(it -> "'" + it + "'")
|
||||
.collect(Collectors.joining(","))));
|
||||
} else if (Objects.equals(templateExt.getAction(), "nin")) {
|
||||
List<String> split = StrUtil.split(templateExt.getValue(), ",");
|
||||
if (split.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
list.add(StrUtil.format("{} not in ({})", templateExt.getKey(), split.stream().map(it -> "'" + it + "'")
|
||||
.collect(Collectors.joining(","))));
|
||||
}
|
||||
}
|
||||
|
||||
return StrUtil.join(" and ", list);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.tiesheng.role.pojos.dto;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ChartTemplateEditDTO {
|
||||
|
||||
private String id;
|
||||
|
||||
@NotEmpty(message = "请输入【模版名称】")
|
||||
private String name;
|
||||
|
||||
@NotEmpty(message = "请选择【表名】")
|
||||
private String tableName;
|
||||
private String tableTitle;
|
||||
|
||||
@NotEmpty(message = "请选择【X轴字段】")
|
||||
private String xField;
|
||||
private String xFieldName;
|
||||
private String xFormat;
|
||||
|
||||
private String sField;
|
||||
private String sFieldName;
|
||||
private String type;
|
||||
private List<TemplateExt> exts;
|
||||
private String remark;
|
||||
private Integer sort;
|
||||
|
||||
|
||||
@Data
|
||||
public static class TemplateExt {
|
||||
private String key;
|
||||
private String action;
|
||||
private String value;
|
||||
|
||||
|
||||
/**
|
||||
* 该数据是否有效
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
public boolean isErrorExt() {
|
||||
return StrUtil.isEmpty(getKey()) || StrUtil.isEmpty(getAction()) || StrUtil.isEmpty(getValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.tiesheng.role.pojos.vo;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tiesheng.role.pojos.dao.CoreChartTemplate;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class TsTableVO {
|
||||
|
||||
private List<TableColumn> columns;
|
||||
private List<JSONObject> dataSource;
|
||||
|
||||
|
||||
@Data
|
||||
public static class TableColumn {
|
||||
private String title;
|
||||
private String dataIndex;
|
||||
private String width;
|
||||
|
||||
public TableColumn(String title, String dataIndex) {
|
||||
this.title = title;
|
||||
this.dataIndex = dataIndex;
|
||||
}
|
||||
}
|
||||
|
||||
public TsTableVO addHeader(String title, String dataIndex) {
|
||||
if (getColumns() == null) {
|
||||
setColumns(CollUtil.newArrayList());
|
||||
}
|
||||
getColumns().add(new TableColumn(title, dataIndex));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TsTableVO addData(JSONObject obj) {
|
||||
if (getDataSource() == null) {
|
||||
setDataSource(CollUtil.newArrayList());
|
||||
}
|
||||
getDataSource().add(obj);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public static TsTableVO of(CoreChartTemplate template, List<JSONObject> originData) {
|
||||
|
||||
TsTableVO tsTableVO = new TsTableVO();
|
||||
tsTableVO.addHeader(template.getXFieldName(), "xField");
|
||||
List<String> split = StrUtil.split(template.getSField(), ",");
|
||||
List<String> sFieldNameList = StrUtil.split(template.getSFieldName(), ",");
|
||||
if (!split.isEmpty() && split.size() == sFieldNameList.size()) {
|
||||
int idx = 0;
|
||||
for (String dataIndex : split) {
|
||||
tsTableVO.addHeader(CollUtil.get(sFieldNameList, idx), StrUtil.toCamelCase(dataIndex));
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
tsTableVO.addHeader("统计", "yField");
|
||||
tsTableVO.setDataSource(originData);
|
||||
return tsTableVO;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.tiesheng.role.service;
|
||||
|
||||
import com.tiesheng.role.mapper.CoreChartTableMapper;
|
||||
import com.tiesheng.role.mapper.CoreChartTemplateMapper;
|
||||
import com.tiesheng.role.pojos.dao.CoreChartTemplate;
|
||||
import com.tiesheng.util.service.TsServiceBase;
|
||||
import lombok.Getter;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Service
|
||||
public class ChartService extends TsServiceBase<CoreChartTemplateMapper, CoreChartTemplate> {
|
||||
|
||||
@Getter
|
||||
@Resource
|
||||
CoreChartTableMapper coreChartTableMapper;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.tiesheng.role.util;
|
||||
|
||||
import com.alibaba.excel.metadata.Head;
|
||||
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
||||
import com.alibaba.excel.write.metadata.style.WriteFont;
|
||||
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
|
||||
import com.alibaba.excel.write.style.column.AbstractHeadColumnWidthStyleStrategy;
|
||||
import org.apache.poi.ss.usermodel.FillPatternType;
|
||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
public class AliExcelUtil {
|
||||
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static HorizontalCellStyleStrategy getCustomStyle() {
|
||||
|
||||
// 头的策略
|
||||
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
|
||||
WriteFont headWriteFont = new WriteFont();
|
||||
headWriteFont.setBold(true);
|
||||
headWriteFont.setFontHeightInPoints((short) 12);
|
||||
headWriteCellStyle.setWriteFont(headWriteFont);
|
||||
headWriteCellStyle.setFillBackgroundColor(IndexedColors.ROYAL_BLUE.getIndex());
|
||||
headWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
|
||||
|
||||
// 内容的策略
|
||||
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
|
||||
WriteFont contentWriteFont = new WriteFont();
|
||||
contentWriteFont.setFontHeightInPoints((short) 11);
|
||||
contentWriteCellStyle.setWriteFont(contentWriteFont);
|
||||
contentWriteCellStyle.setWrapped(true);
|
||||
contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
||||
|
||||
return new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
|
||||
}
|
||||
|
||||
public static class ChatColumnWidthStyleStrategy extends AbstractHeadColumnWidthStyleStrategy {
|
||||
|
||||
@Override
|
||||
protected Integer columnWidth(Head head, Integer integer) {
|
||||
if (head.getColumnIndex() == 0) {
|
||||
return 20;
|
||||
}
|
||||
return (head.getHeadNameList().get(0).length()) * 2 + 10;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
create table core_chart_table
|
||||
(
|
||||
id varchar(50) not null
|
||||
primary key,
|
||||
create_time datetime not null,
|
||||
update_time datetime not null,
|
||||
is_deleted int default 0 not null,
|
||||
table_name varchar(100) not null comment '表名',
|
||||
table_title varchar(500) not null comment '名称',
|
||||
columns text not null comment '所有字段',
|
||||
remark text null comment '其他说明'
|
||||
)
|
||||
ENGINE = InnoDB
|
||||
CHARACTER SET = utf8mb4
|
||||
COLLATE = utf8mb4_general_ci
|
||||
comment '图表-表信息'
|
||||
row_format = DYNAMIC;
|
||||
|
||||
create table core_chart_template
|
||||
(
|
||||
id varchar(50) not null
|
||||
primary key,
|
||||
create_time datetime not null,
|
||||
update_time datetime not null,
|
||||
is_deleted int default 0 not null,
|
||||
name varchar(100) not null comment '模版名称',
|
||||
table_name varchar(100) not null comment '表名',
|
||||
table_title varchar(100) not null comment '名称',
|
||||
type varchar(50) default 'count_1' null comment '统计方式',
|
||||
x_field varchar(100) not null comment 'X轴字段',
|
||||
x_field_name varchar(500) not null comment 'X轴字段',
|
||||
x_format varchar(100) null comment 'X轴格式化,只有X轴字段为date时有效',
|
||||
s_field varchar(100) null comment 'S轴字段',
|
||||
s_field_name varchar(500) null comment 'S轴字段',
|
||||
exts text null comment '附件条件',
|
||||
remark text null comment '其他说明',
|
||||
sort int default 0 null comment '排序'
|
||||
)
|
||||
ENGINE = InnoDB
|
||||
CHARACTER SET = utf8mb4
|
||||
COLLATE = utf8mb4_general_ci
|
||||
comment '图表-表信息'
|
||||
row_format = DYNAMIC;
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.tiesheng.zaxy.alarm.mapper.CoreChartTableMapper">
|
||||
<resultMap id="BaseResultMap" type="com.tiesheng.zaxy.alarm.pojos.dao.CoreChartTable">
|
||||
<!--@mbg.generated-->
|
||||
<!--@Table core_chart_table-->
|
||||
<id column="id" jdbcType="VARCHAR" property="id" />
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
|
||||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
|
||||
<result column="is_deleted" jdbcType="INTEGER" property="isDeleted" />
|
||||
<result column="table_name" jdbcType="VARCHAR" property="tableName" />
|
||||
<result column="table_title" jdbcType="VARCHAR" property="tableTitle" />
|
||||
<result column="columns" jdbcType="LONGVARCHAR" property="columns" />
|
||||
<result column="remark" jdbcType="LONGVARCHAR" property="remark" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
id, create_time, update_time, is_deleted, `table_name`, table_title, `columns`, remark
|
||||
</sql>
|
||||
</mapper>
|
||||
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.tiesheng.zaxy.alarm.mapper.CoreChartTemplateMapper">
|
||||
<resultMap id="BaseResultMap" type="com.tiesheng.zaxy.alarm.pojos.dao.CoreChartTemplate">
|
||||
<!--@mbg.generated-->
|
||||
<!--@Table core_chart_template-->
|
||||
<id column="id" jdbcType="VARCHAR" property="id" />
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
|
||||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
|
||||
<result column="is_deleted" jdbcType="INTEGER" property="isDeleted" />
|
||||
<result column="name" jdbcType="VARCHAR" property="name" />
|
||||
<result column="table_name" jdbcType="VARCHAR" property="tableName" />
|
||||
<result column="table_title" jdbcType="VARCHAR" property="tableTitle" />
|
||||
<result column="type" jdbcType="VARCHAR" property="type" />
|
||||
<result column="x_field" jdbcType="VARCHAR" property="xField" />
|
||||
<result column="x_field_name" jdbcType="VARCHAR" property="xFieldName" />
|
||||
<result column="x_format" jdbcType="VARCHAR" property="xFormat" />
|
||||
<result column="s_field" jdbcType="VARCHAR" property="sField" />
|
||||
<result column="s_field_name" jdbcType="VARCHAR" property="sFieldName" />
|
||||
<result column="exts" jdbcType="LONGVARCHAR" property="exts" />
|
||||
<result column="remark" jdbcType="LONGVARCHAR" property="remark" />
|
||||
<result column="sort" jdbcType="INTEGER" property="sort" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
id, create_time, update_time, is_deleted, `name`, `table_name`, table_title, `type`,
|
||||
x_field, x_field_name, x_format, s_field, s_field_name, exts, remark, sort
|
||||
</sql>
|
||||
|
||||
<select id="recordCheck" resultType="com.alibaba.fastjson.JSONObject">
|
||||
select ${xField} x_field,
|
||||
<if test="sField != null and sField != ''">
|
||||
${sField},
|
||||
</if>
|
||||
${type} y_field
|
||||
from ${table}
|
||||
where 1 = 1
|
||||
<if test="where != null and where != ''">
|
||||
and ${where}
|
||||
</if>
|
||||
<if test="groupBy != null and groupBy != ''">
|
||||
group by ${groupBy}
|
||||
</if>
|
||||
order by ${groupBy} asc
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
<version>2.0.31</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-database</artifactId>
|
||||
|
||||
BIN
springboot-encrypt/.DS_Store
vendored
BIN
springboot-encrypt/.DS_Store
vendored
Binary file not shown.
@@ -1,40 +0,0 @@
|
||||
<?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.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-encrypt</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-util</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-annotation</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.tiesheng.encrypt;
|
||||
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@ComponentScan({
|
||||
"com.tiesheng.encrypt.**.*",
|
||||
})
|
||||
public class EncryptAutoConfigurer {
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
<version>2.0.31</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-login</artifactId>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.tiesheng.login.config;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.tiesheng.annotation.token.TokenIgnore;
|
||||
@@ -40,7 +41,7 @@ public class TokenWebMvcConfigurer implements WebMvcConfigurer {
|
||||
resolvers.add(new HandlerMethodArgumentResolver() {
|
||||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
return parameter.getParameterType().isAssignableFrom(TokenBean.class);
|
||||
return TokenBean.class.isAssignableFrom(parameter.getParameterType());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,7 +55,9 @@ public class TokenWebMvcConfigurer implements WebMvcConfigurer {
|
||||
TokenIgnore annotation = method.getAnnotation(TokenIgnore.class);
|
||||
thrExp = annotation == null;
|
||||
}
|
||||
return tsTokenConfig.validToken(header, thrExp);
|
||||
|
||||
TokenBean tokenBean = tsTokenConfig.validToken(header, thrExp);
|
||||
return BeanUtil.copyProperties(tokenBean, parameter.getParameterType());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -105,7 +108,7 @@ public class TokenWebMvcConfigurer implements WebMvcConfigurer {
|
||||
TokenBean tokenBean = tsTokenConfig.validToken(request, true);
|
||||
|
||||
// 验证用户是否存在
|
||||
RequestUserInfo cachedUserInfo = tsLoginConfigurer.getCachedUserInfo(tokenBean);
|
||||
RequestUserInfo cachedUserInfo = tsLoginConfigurer.getCachedUserInfo(tokenBean, false);
|
||||
if (cachedUserInfo == null) {
|
||||
throw new ApiException("非法TOKEN,请重新登录");
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class LoginController {
|
||||
@OperationIgnore
|
||||
public void uniqueIndex(UniqueIndexDTO dto, HttpServletResponse response) {
|
||||
if (tsTokenConfig.isValidLoginSign() && !dto.validSign()) {
|
||||
corePlatformUniqueService.onSignError(response);
|
||||
corePlatformUniqueService.redirect(null, dto.getTo(), dto.getExtra(), response);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public class LoginController {
|
||||
public ApiResp<String> uniqueIndex(@RequestBody UniqueIndexDTO dto) {
|
||||
TokenBean tokenBean = corePlatformUniqueService.login(new DoLoginInfo("web_unique_index",
|
||||
dto.getNo(), dto.getPlatform(), dto.getInfo()));
|
||||
if (tokenBean == null || StrUtil.isEmpty(tokenBean.getId())) {
|
||||
if (!TsTokenConfig.validToken(tokenBean)) {
|
||||
throw new ApiException("登录失败");
|
||||
}
|
||||
return ApiResp.respOK(tokenBean.toToken());
|
||||
@@ -170,7 +170,7 @@ public class LoginController {
|
||||
extra = "";
|
||||
}
|
||||
String configUrl = globalConfig.buildPath("/login/wxmp/oauth2/" + service + "?extra=" + extra);
|
||||
String authorizationUrl = platformWxmpConfig.buildAuthorizationUrl(service, configUrl, "snsapi_userinfo");
|
||||
String authorizationUrl = platformWxmpConfig.buildAuthorizationUrl(service, configUrl);
|
||||
response.sendRedirect(authorizationUrl);
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ public class LoginController {
|
||||
|
||||
WxminiLoginVo loginVo = new WxminiLoginVo();
|
||||
loginVo.setOpenid(openid);
|
||||
if (tokenBean != null) {
|
||||
if (TsTokenConfig.validToken(tokenBean)) {
|
||||
loginVo.setToken(tokenBean.toToken());
|
||||
}
|
||||
return ApiResp.respOK(loginVo);
|
||||
|
||||
@@ -2,6 +2,17 @@ package com.tiesheng.login.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.tiesheng.login.pojos.dao.CoreLogLogin;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
public interface CoreLogLoginMapper extends BaseMapper<CoreLogLogin> {
|
||||
|
||||
|
||||
/**
|
||||
* 获取登录失败的次数
|
||||
*
|
||||
* @param ip
|
||||
* @return
|
||||
*/
|
||||
int getLoginErrorTimes(@Param("ip") String ip);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.tiesheng.login.pojos;
|
||||
|
||||
import com.tiesheng.util.ServletKit;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class DoLoginInfo {
|
||||
|
||||
private String appId;
|
||||
@@ -7,12 +11,16 @@ public class DoLoginInfo {
|
||||
private String platform;
|
||||
private String info;
|
||||
private String extra;
|
||||
private String loginIp;
|
||||
|
||||
public DoLoginInfo(String appId, String unique, String platform, String info) {
|
||||
this.appId = appId;
|
||||
this.unique = unique;
|
||||
this.platform = platform;
|
||||
this.info = info;
|
||||
|
||||
// 设置IP
|
||||
this.loginIp = ServletKit.getClientIP();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@@ -58,4 +66,12 @@ public class DoLoginInfo {
|
||||
public void setExtra(String extra) {
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
public String getLoginIp() {
|
||||
return loginIp;
|
||||
}
|
||||
|
||||
public void setLoginIp(String loginIp) {
|
||||
this.loginIp = loginIp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,13 @@ public class CoreLogLogin extends DaoBase {
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
* 用户姓名
|
||||
*/
|
||||
@TableField(value = "user_name")
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* ip
|
||||
* 登录方式
|
||||
*/
|
||||
@TableField(value = "platform")
|
||||
private String platform;
|
||||
@@ -39,6 +39,18 @@ public class CoreLogLogin extends DaoBase {
|
||||
@TableField(value = "address")
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 登录结果,0否,1是
|
||||
*/
|
||||
@TableField(value = "`result`")
|
||||
private Integer result;
|
||||
|
||||
/**
|
||||
* 请求参数
|
||||
*/
|
||||
@TableField(value = "params")
|
||||
private String params;
|
||||
|
||||
/**
|
||||
* 获取用户id
|
||||
*
|
||||
@@ -57,18 +69,38 @@ public class CoreLogLogin extends DaoBase {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户姓名
|
||||
*
|
||||
* @return user_name - 用户姓名
|
||||
*/
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置用户姓名
|
||||
*
|
||||
* @param userName 用户姓名
|
||||
*/
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录方式
|
||||
*
|
||||
* @return platform - 登录方式
|
||||
*/
|
||||
public String getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置登录方式
|
||||
*
|
||||
* @param platform 登录方式
|
||||
*/
|
||||
public void setPlatform(String platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
@@ -108,4 +140,40 @@ public class CoreLogLogin extends DaoBase {
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录结果,0否,1是
|
||||
*
|
||||
* @return result - 登录结果,0否,1是
|
||||
*/
|
||||
public Integer getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置登录结果,0否,1是
|
||||
*
|
||||
* @param result 登录结果,0否,1是
|
||||
*/
|
||||
public void setResult(Integer result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求参数
|
||||
*
|
||||
* @return params - 请求参数
|
||||
*/
|
||||
public String getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置请求参数
|
||||
*
|
||||
* @param params 请求参数
|
||||
*/
|
||||
public void setParams(String params) {
|
||||
this.params = params;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
package com.tiesheng.login.service;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.tiesheng.login.mapper.CoreLogLoginMapper;
|
||||
import com.tiesheng.login.mapper.CorePlatformUniqueMapper;
|
||||
import com.tiesheng.login.pojos.DoLoginInfo;
|
||||
import com.tiesheng.login.pojos.RequestUserInfo;
|
||||
import com.tiesheng.login.pojos.dao.CoreLogLogin;
|
||||
import com.tiesheng.login.pojos.dao.CorePlatformUnique;
|
||||
import com.tiesheng.util.ServletKit;
|
||||
import com.tiesheng.util.config.Ip2regionConfig;
|
||||
import com.tiesheng.util.config.TsTokenConfig;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
import com.tiesheng.util.pojos.TokenBean;
|
||||
import com.tiesheng.util.service.TsCacheService;
|
||||
import com.tiesheng.util.service.TsServiceBase;
|
||||
import com.tiesheng.util.service.role.TsAuthorityHandler;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -34,9 +35,22 @@ public class CorePlatformUniqueService extends TsServiceBase<CorePlatformUniqueM
|
||||
TsLoginConfigurer tsLoginConfigurer;
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
/**
|
||||
* 登录操作
|
||||
*
|
||||
* @param loginInfo
|
||||
* @return
|
||||
*/
|
||||
public TokenBean login(DoLoginInfo loginInfo) {
|
||||
|
||||
int loginErrorTimes = tsLoginConfigurer.getLoginErrorTimes();
|
||||
if (loginErrorTimes > 0) {
|
||||
int currentErrorTimes = coreLogLoginMapper.getLoginErrorTimes(loginInfo.getLoginIp());
|
||||
if (currentErrorTimes >= loginErrorTimes) {
|
||||
throw new ApiException("登录失败已达" + loginErrorTimes + "次,请10分钟后再试");
|
||||
}
|
||||
}
|
||||
|
||||
CorePlatformUnique platformUnique = getOneByColumn("unique_id", loginInfo.getUnique());
|
||||
if (platformUnique == null) {
|
||||
platformUnique = new CorePlatformUnique();
|
||||
@@ -47,21 +61,34 @@ public class CorePlatformUniqueService extends TsServiceBase<CorePlatformUniqueM
|
||||
platformUnique.setInfo(loginInfo.getInfo());
|
||||
saveOrUpdate(platformUnique);
|
||||
|
||||
String oldUserId = platformUnique.getUserId();
|
||||
TokenBean tokenBean = tsLoginConfigurer.login(platformUnique);
|
||||
if (tokenBean != null) {
|
||||
TokenBean tokenBean = null;
|
||||
String errorMsg = null;
|
||||
try {
|
||||
tokenBean = tsLoginConfigurer.login(platformUnique);
|
||||
} catch (Exception e) {
|
||||
errorMsg = e.getMessage();
|
||||
}
|
||||
|
||||
// 添加登录日志
|
||||
addLoginLog(platformUnique, tokenBean);
|
||||
if (TsTokenConfig.validToken(tokenBean)) {
|
||||
|
||||
// 清除授权信息
|
||||
TsCacheService.of().remove(StrUtil.format(TsAuthorityHandler.CACHE_AUTHORITY,
|
||||
tokenBean.getRoleId(), tokenBean.getId()));
|
||||
|
||||
// 更新唯一值
|
||||
if (!StrUtil.isEmpty(tokenBean.getId()) &&
|
||||
!Objects.equals(oldUserId, tokenBean.getId())) {
|
||||
String oldUserId = platformUnique.getUserId();
|
||||
if (!Objects.equals(oldUserId, tokenBean.getId())) {
|
||||
platformUnique.setUserId(tokenBean.getId());
|
||||
saveOrUpdate(platformUnique);
|
||||
}
|
||||
}
|
||||
|
||||
addLoginLog(tokenBean, loginInfo);
|
||||
|
||||
if (StrUtil.isNotEmpty(errorMsg)) {
|
||||
throw new ApiException(errorMsg);
|
||||
}
|
||||
|
||||
return tokenBean;
|
||||
}
|
||||
|
||||
@@ -72,40 +99,37 @@ public class CorePlatformUniqueService extends TsServiceBase<CorePlatformUniqueM
|
||||
* @param bean
|
||||
*/
|
||||
public void redirect(TokenBean bean, String to, String extra, HttpServletResponse response) {
|
||||
tsLoginConfigurer.redirect(bean, to, extra, response);
|
||||
if (TsTokenConfig.validToken(bean)) {
|
||||
tsLoginConfigurer.redirect(bean, to, extra, response);
|
||||
} else {
|
||||
tsLoginConfigurer.onLoginError(to, response);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 签名错误的时候
|
||||
*/
|
||||
public void onSignError(HttpServletResponse response) {
|
||||
tsLoginConfigurer.onSignError(response);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// 登录日志
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* 添加登录日志
|
||||
*
|
||||
* @param platformUnique
|
||||
* @param tokenBean
|
||||
* @param info
|
||||
*/
|
||||
public void addLoginLog(CorePlatformUnique platformUnique, TokenBean tokenBean) {
|
||||
|
||||
HttpServletRequest request = ServletKit.getRequest();
|
||||
String ip = ServletUtil.getClientIP(request);
|
||||
public void addLoginLog(TokenBean tokenBean, DoLoginInfo info) {
|
||||
|
||||
CoreLogLogin login = new CoreLogLogin();
|
||||
login.setUserId(tokenBean.getId());
|
||||
login.setPlatform(platformUnique.getPlatform());
|
||||
login.setPlatform(info.getPlatform());
|
||||
login.setParams(JSON.toJSONString(info));
|
||||
|
||||
RequestUserInfo requestUserInfo = tsLoginConfigurer.getCachedUserInfo(tokenBean);
|
||||
login.setUserName(requestUserInfo.getName());
|
||||
if (TsTokenConfig.validToken(tokenBean)) {
|
||||
RequestUserInfo requestUserInfo = tsLoginConfigurer.getCachedUserInfo(tokenBean, true);
|
||||
login.setUserId(tokenBean.getId());
|
||||
login.setUserName(requestUserInfo.getName());
|
||||
login.setResult(1);
|
||||
} else {
|
||||
login.setUserName(info.getUnique());
|
||||
login.setResult(0);
|
||||
}
|
||||
|
||||
login.setIp(ip);
|
||||
login.setIp(info.getLoginIp());
|
||||
login.setAddress(ip2regionConfig.search(login.getIp()));
|
||||
coreLogLoginMapper.insert(login);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.tiesheng.login.service;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import com.tiesheng.login.pojos.RequestUserInfo;
|
||||
import com.tiesheng.login.pojos.dao.CorePlatformUnique;
|
||||
import com.tiesheng.util.ServletKit;
|
||||
import com.tiesheng.util.config.TsTokenConfig;
|
||||
import com.tiesheng.util.pojos.TokenBean;
|
||||
import com.tiesheng.util.service.TsCacheService;
|
||||
@@ -34,10 +34,10 @@ public interface TsLoginConfigurer {
|
||||
|
||||
|
||||
/**
|
||||
* 签名错误的时候
|
||||
* 登录失败的时候
|
||||
*/
|
||||
default void onSignError(HttpServletResponse response) {
|
||||
ServletUtil.write(response, "404", "text");
|
||||
default void onLoginError(String to, HttpServletResponse response) {
|
||||
ServletKit.write(response, "404", "text");
|
||||
}
|
||||
|
||||
|
||||
@@ -47,10 +47,10 @@ public interface TsLoginConfigurer {
|
||||
* @param tokenBean
|
||||
* @return
|
||||
*/
|
||||
default RequestUserInfo getCachedUserInfo(TokenBean tokenBean) {
|
||||
default RequestUserInfo getCachedUserInfo(TokenBean tokenBean, boolean force) {
|
||||
String key = StrUtil.format(TsTokenConfig.CACHE_REQUEST_LOGIN_KEY, tokenBean.getId());
|
||||
RequestUserInfo obj = TsCacheService.of().getObj(key, RequestUserInfo.class, -1);
|
||||
if (obj == null) {
|
||||
if (obj == null || force) {
|
||||
obj = getCurrentUserName(tokenBean);
|
||||
}
|
||||
if (obj != null) {
|
||||
@@ -66,4 +66,14 @@ public interface TsLoginConfigurer {
|
||||
*/
|
||||
RequestUserInfo getCurrentUserName(TokenBean userId);
|
||||
|
||||
|
||||
/**
|
||||
* 获取登录失败的次数,默认0次,不校验
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
default int getLoginErrorTimes() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@ CREATE TABLE `core_log_login`
|
||||
`address` varchar(255) DEFAULT NULL COMMENT 'ip地址',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4 COMMENT ='日志-登录';
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_general_ci COMMENT ='日志-登录';
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for core_platform_unique
|
||||
@@ -35,6 +36,7 @@ CREATE TABLE `core_platform_unique`
|
||||
`info` text COMMENT '其他参数',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4 COMMENT ='平台-唯一值';
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_general_ci COMMENT ='平台-唯一值';
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
||||
@@ -13,9 +13,21 @@
|
||||
<result column="platform" jdbcType="VARCHAR" property="platform" />
|
||||
<result column="ip" jdbcType="VARCHAR" property="ip" />
|
||||
<result column="address" jdbcType="VARCHAR" property="address" />
|
||||
<result column="result" jdbcType="INTEGER" property="result" />
|
||||
<result column="params" jdbcType="LONGVARCHAR" property="params" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
id, create_time, update_time, is_deleted, user_id, user_name, platform, ip, address
|
||||
id, create_time, update_time, is_deleted, user_id, user_name, platform, ip, address,
|
||||
`result`, params
|
||||
</sql>
|
||||
|
||||
<select id="getLoginErrorTimes" resultType="int">
|
||||
select count(1)
|
||||
from core_log_login
|
||||
where ip = #{ip}
|
||||
and result = 0
|
||||
and create_time > date_add(now(), interval -10 minute)
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
<version>2.0.31</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-message</artifactId>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.tiesheng.message.config.aliyun;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
public interface AliyunSmsHandler {
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tiesheng.message.service.TsMessageSender;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
@@ -99,14 +99,14 @@ public class AliyunSmsSender implements TsMessageSender {
|
||||
String signature = specialUrlEncode(digest);
|
||||
queryMap.put("Signature", signature);
|
||||
|
||||
String respBody = "";
|
||||
String respBody;
|
||||
try {
|
||||
respBody = OkHttpUtil.get(ENDPOINT + "?Signature=" + signature + sortQueryStringTmp);
|
||||
} catch (Exception e) {
|
||||
respBody = JSONUtil.createObj()
|
||||
.putOpt("Code", "Error")
|
||||
.putOpt("Message", "消息通道异常")
|
||||
.toString();
|
||||
JSONObject object = new JSONObject();
|
||||
object.put("Code", "Error");
|
||||
object.put("Message", "消息通道异常");
|
||||
respBody = object.toJSONString();
|
||||
}
|
||||
return respBody;
|
||||
}
|
||||
@@ -130,9 +130,9 @@ public class AliyunSmsSender implements TsMessageSender {
|
||||
queryMap.put("TemplateParam", tempParam.getTemplateParam().toString());
|
||||
}
|
||||
|
||||
JSONObject respObj = JSONUtil.parseObj(request("SendSms", queryMap));
|
||||
if (!Objects.equals(respObj.getStr("Code"), "OK")) {
|
||||
return ApiResp.resp130(respObj.getStr("Message"));
|
||||
JSONObject respObj = JSON.parseObject(request("SendSms", queryMap));
|
||||
if (!Objects.equals(respObj.getString("Code"), "OK")) {
|
||||
return ApiResp.resp130(respObj.getString("Message"));
|
||||
}
|
||||
|
||||
return ApiResp.respOK("");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.tiesheng.message.config.aliyun;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
public class AliyunTempParam {
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.tiesheng.message.service;
|
||||
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.tiesheng.message.service;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tiesheng.message.pojos.UserChannel;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
<version>2.0.31</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-platform</artifactId>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.tiesheng.platform.config.ding;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.TypeReference;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.log.LogFactory;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.tiesheng.platform.config.ding.bean.*;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
import com.tiesheng.util.service.TsCacheService;
|
||||
@@ -76,15 +76,16 @@ public class PlatformDingConfig {
|
||||
request = OkHttpUtil.ofPost(url, body);
|
||||
}
|
||||
request = request.newBuilder().header("x-acs-dingtalk-access-token", accessToken).build();
|
||||
try {
|
||||
Response response = OkHttpUtil.ofHttpClient().build().newCall(request).execute();
|
||||
try (Response response = OkHttpUtil.ofHttpClient().build().newCall(request).execute()) {
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
String rawBody = response.body().string();
|
||||
DingResponse<T> bean = JSONUtil.toBean(rawBody, typeReference, true);
|
||||
DingResponse<T> bean = JSON.parseObject(rawBody, typeReference);
|
||||
bean.setRawBody(rawBody);
|
||||
return bean;
|
||||
} else {
|
||||
LogFactory.get().info(response.body().string());
|
||||
if (response.body() != null) {
|
||||
LogFactory.get().info(response.body().string());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogFactory.get().error(e);
|
||||
@@ -116,8 +117,8 @@ public class PlatformDingConfig {
|
||||
query.put("appkey", dingConfigBean.getAppKey());
|
||||
query.put("appsecret", dingConfigBean.getAppSecret());
|
||||
String response = OkHttpUtil.get("https://oapi.dingtalk.com/gettoken", query);
|
||||
JSONObject respJson = JSONUtil.parseObj(response);
|
||||
accessToken = respJson.getStr("access_token");
|
||||
JSONObject respJson = JSON.parseObject(response);
|
||||
accessToken = respJson.getString("access_token");
|
||||
TsCacheService.of().put(CACHE_ACCESS_TOKEN + dingConfigBean.getAppKey(),
|
||||
accessToken, respJson.getLong("expires_in"));
|
||||
|
||||
@@ -174,8 +175,12 @@ public class PlatformDingConfig {
|
||||
* @see <a href="https://open.dingtalk.com/document/isvapp-server/obtain-the-userid-of-a-user-by-using-the-log-free"></a>
|
||||
*/
|
||||
public DingUserSimple getUserIdByCode(String service, String code) {
|
||||
|
||||
JSONObject object = new JSONObject();
|
||||
object.put("code", code);
|
||||
|
||||
DingResponse<DingUserSimple> resp = doRequest(service, "https://oapi.dingtalk.com/topapi/v2/user/getuserinfo",
|
||||
JSONUtil.createObj().putOpt("code", code), new TypeReference<DingResponse<DingUserSimple>>() {
|
||||
object, new TypeReference<DingResponse<DingUserSimple>>() {
|
||||
});
|
||||
return resp.getResult();
|
||||
}
|
||||
@@ -192,9 +197,13 @@ public class PlatformDingConfig {
|
||||
public DingUserInfo topapiV2UserGet(String service, String ddUserId) {
|
||||
DingConfigBean dingConfigBean = getConfigBean(service);
|
||||
|
||||
JSONObject object = new JSONObject();
|
||||
object.put("userid", ddUserId);
|
||||
|
||||
DingUserInfo userInfo = doRequest(service, "https://oapi.dingtalk.com/topapi/v2/user/get",
|
||||
JSONUtil.createObj().putOpt("userid", ddUserId), new TypeReference<DingResponse<DingUserInfo>>() {
|
||||
object, new TypeReference<DingResponse<DingUserInfo>>() {
|
||||
}).getResult();
|
||||
|
||||
// 设置一下job_number
|
||||
userInfo.setJobNumber(userInfo.getJobNumber());
|
||||
userInfo.setAppId(dingConfigBean.getAppKey());
|
||||
@@ -214,8 +223,11 @@ public class PlatformDingConfig {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
JSONObject object = new JSONObject();
|
||||
object.put("dept_id", deptId);
|
||||
|
||||
return doRequest(service, "https://oapi.dingtalk.com/topapi/v2/department/listsub",
|
||||
JSONUtil.createObj().putOpt("dept_id", deptId), new TypeReference<DingResponse<List<DingDeptVo>>>() {
|
||||
object, new TypeReference<DingResponse<List<DingDeptVo>>>() {
|
||||
}).getResult();
|
||||
}
|
||||
|
||||
@@ -232,9 +244,13 @@ public class PlatformDingConfig {
|
||||
return DingUserListVo.fail();
|
||||
}
|
||||
|
||||
JSONObject object = new JSONObject();
|
||||
object.put("dept_id", deptId);
|
||||
object.put("cursor", cursor);
|
||||
object.put("size", 100);
|
||||
|
||||
return doRequest(service, "https://oapi.dingtalk.com/topapi/v2/user/list",
|
||||
JSONUtil.createObj().putOpt("dept_id", deptId).putOpt("cursor", cursor).putOpt("size", 100),
|
||||
new TypeReference<DingResponse<DingUserListVo>>() {
|
||||
object, new TypeReference<DingResponse<DingUserListVo>>() {
|
||||
}).getResult();
|
||||
}
|
||||
|
||||
@@ -293,24 +309,28 @@ public class PlatformDingConfig {
|
||||
DingConfigBean configBean = getConfigBean(service);
|
||||
|
||||
JSONObject msg = new JSONObject();
|
||||
|
||||
if (StrUtil.isEmpty(actionUrl)) {
|
||||
msg.set("msgtype", "markdown");
|
||||
msg.set("markdown", JSONUtil.createObj()
|
||||
.set("title", title).set("text", markdown)
|
||||
);
|
||||
JSONObject markdownObj = new JSONObject();
|
||||
markdownObj.put("title", title);
|
||||
markdownObj.put("text", markdown);
|
||||
|
||||
msg.put("msgtype", "markdown");
|
||||
msg.put("markdown", markdownObj);
|
||||
} else {
|
||||
msg.set("msgtype", "action_card");
|
||||
msg.set("action_card", JSONUtil.createObj()
|
||||
.set("title", title).set("markdown", markdown)
|
||||
.set("single_title", "点击查看").set("single_url", actionUrl)
|
||||
);
|
||||
JSONObject actionCard = new JSONObject();
|
||||
actionCard.put("title", title);
|
||||
actionCard.put("markdown", markdown);
|
||||
actionCard.put("single_title", "点击查看");
|
||||
actionCard.put("single_url", actionUrl);
|
||||
|
||||
msg.put("msgtype", "action_card");
|
||||
msg.put("action_card", actionCard);
|
||||
}
|
||||
|
||||
JSONObject body = new JSONObject();
|
||||
body.putOpt("agent_id", configBean.getAgentId());
|
||||
body.putOpt("userid_list", CollUtil.join(userIds, ","));
|
||||
body.putOpt("msg", msg);
|
||||
body.put("agent_id", configBean.getAgentId());
|
||||
body.put("userid_list", CollUtil.join(userIds, ","));
|
||||
body.put("msg", msg);
|
||||
return doRequest(service, "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2", body,
|
||||
new TypeReference<DingResponse<String>>() {
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.tiesheng.platform.config.ding.bean;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONPath;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -41,7 +42,8 @@ public class DingResponse<T> {
|
||||
* @return
|
||||
*/
|
||||
public <E> E getRawValue(String path, Class<E> tClass) {
|
||||
return JSONUtil.parse(getRawBody()).getByPath(path, tClass);
|
||||
JSONPath jsonPath = JSONPath.compile(path);
|
||||
return jsonPath.eval(JSON.parseObject(getRawBody()), tClass);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.tiesheng.platform.config.wxmini;
|
||||
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tiesheng.platform.config.wxmp.bean.WxConfigBean;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
import com.tiesheng.util.service.http.OkHttpUtil;
|
||||
@@ -56,8 +56,8 @@ public class PlatformWxminiConfig {
|
||||
+ "&secret=" + configBean.getAppSecret()
|
||||
+ "&js_code=" + code + "&grant_type=authorization_code");
|
||||
|
||||
JSONObject object = JSONUtil.parseObj(body);
|
||||
return object.getStr("openid");
|
||||
JSONObject object = JSON.parseObject(body);
|
||||
return object.getString("openid");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,8 +72,8 @@ public class PlatformWxminiConfig {
|
||||
+ "?grant_type=client_credential&appid=" + configBean.getAppId()
|
||||
+ "&secret=" + configBean.getAppSecret());
|
||||
|
||||
JSONObject object = JSONUtil.parseObj(body);
|
||||
return object.getStr("access_token");
|
||||
JSONObject object = JSON.parseObject(body);
|
||||
return object.getString("access_token");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ package com.tiesheng.platform.config.wxmp;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.log.LogFactory;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tiesheng.platform.config.wxmp.bean.WxConfigBean;
|
||||
import com.tiesheng.platform.config.wxmp.bean.WxJsapiSignature;
|
||||
import com.tiesheng.platform.config.wxmp.bean.WxOAuth2AccessToken;
|
||||
@@ -70,8 +70,8 @@ public class PlatformWxmpConfig {
|
||||
query.put("appid", configBean.getAppId());
|
||||
query.put("secret", configBean.getAppSecret());
|
||||
String response = OkHttpUtil.get("https://api.weixin.qq.com/cgi-bin/token", query);
|
||||
JSONObject respJson = JSONUtil.parseObj(response);
|
||||
accessToken = respJson.getStr("access_token");
|
||||
JSONObject respJson = JSON.parseObject(response);
|
||||
accessToken = respJson.getString("access_token");
|
||||
TsCacheService.of().put(CACHE_ACCESS_TOKEN + configBean.getAppId(), accessToken,
|
||||
respJson.getLong("expires_in"));
|
||||
}
|
||||
@@ -93,8 +93,8 @@ public class PlatformWxmpConfig {
|
||||
query.put("type", "jsapi");
|
||||
String response = OkHttpUtil.get("https://api.weixin.qq.com/cgi-bin/ticket/getticket", query);
|
||||
LogFactory.get().info("getJsapiTicket: " + response);
|
||||
JSONObject respJson = JSONUtil.parseObj(response);
|
||||
jsapiTicket = respJson.getStr("ticket");
|
||||
JSONObject respJson = JSON.parseObject(response);
|
||||
jsapiTicket = respJson.getString("ticket");
|
||||
TsCacheService.of().put(CACHE_JSAPI_TICKET + configBean.getAppId(), jsapiTicket,
|
||||
respJson.getLong("expires_in"));
|
||||
}
|
||||
@@ -122,12 +122,12 @@ public class PlatformWxmpConfig {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String buildAuthorizationUrl(String service, String redirectUrl, String scope) {
|
||||
public String buildAuthorizationUrl(String service, String redirectUrl) {
|
||||
WxConfigBean configBean = getConfigBean(service);
|
||||
return "https://open.weixin.qq.com/connect/oauth2/authorize"
|
||||
+ "?appid=" + configBean.getAppId()
|
||||
+ "&redirect_uri=" + URLUtil.encodeAll(redirectUrl)
|
||||
+ "&response_type=code&scope=" + scope
|
||||
+ "&response_type=code&scope=" + configBean.getScope()
|
||||
+ "&state=STATE#wechat_redirect";
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,12 @@ public class WxConfigBean {
|
||||
|
||||
private String appId;
|
||||
private String appSecret;
|
||||
private String scope = "snsapi_base";
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// setter\getter
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// ////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public String getAppId() {
|
||||
return appId;
|
||||
@@ -27,4 +29,12 @@ public class WxConfigBean {
|
||||
public void setAppSecret(String appSecret) {
|
||||
this.appSecret = appSecret;
|
||||
}
|
||||
|
||||
public String getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
public void setScope(String scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.tiesheng.platform.config.wxmp.bean;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tiesheng.util.service.http.OkHttpUtil;
|
||||
|
||||
/**
|
||||
@@ -15,11 +15,11 @@ public class WxOAuth2AccessToken {
|
||||
public static WxOAuth2AccessToken create(String appId, String secret, String code) {
|
||||
String response = OkHttpUtil.get("https://api.weixin.qq.com/sns/oauth2/access_token" +
|
||||
"?appid=" + appId + "&secret=" + secret + "&code=" + code + "&grant_type=authorization_code");
|
||||
JSONObject respJson = JSONUtil.parseObj(response);
|
||||
JSONObject respJson = JSON.parseObject(response);
|
||||
|
||||
WxOAuth2AccessToken oAuth2AccessToken = new WxOAuth2AccessToken();
|
||||
oAuth2AccessToken.setOpenid(respJson.getStr("openid"));
|
||||
oAuth2AccessToken.setAccessToken(respJson.getStr("access_token"));
|
||||
oAuth2AccessToken.setOpenid(respJson.getString("openid"));
|
||||
oAuth2AccessToken.setAccessToken(respJson.getString("access_token"));
|
||||
return oAuth2AccessToken;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.tiesheng.platform.config.wxmp.bean;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.tiesheng.util.service.http.OkHttpUtil;
|
||||
|
||||
/**
|
||||
@@ -33,7 +33,7 @@ public class WxUserInfo {
|
||||
String s = OkHttpUtil.get("https://api.weixin.qq.com/sns/userinfo"
|
||||
+ "?access_token=" + oAuth2AccessToken.getAccessToken()
|
||||
+ "&openid=" + oAuth2AccessToken.getOpenid() + "&lang=zh_CN");
|
||||
return JSONUtil.toBean(s, WxUserInfo.class);
|
||||
return JSON.parseObject(s, WxUserInfo.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
BIN
springboot-poi/.DS_Store
vendored
BIN
springboot-poi/.DS_Store
vendored
Binary file not shown.
@@ -1,8 +0,0 @@
|
||||
package com.tiesheng.poi.pojos;
|
||||
|
||||
/**
|
||||
* @author hao
|
||||
*/
|
||||
public interface PoiReadBase {
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.tiesheng.poi.pojos;
|
||||
|
||||
import com.alibaba.excel.annotation.write.style.*;
|
||||
import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum;
|
||||
import com.alibaba.excel.enums.poi.VerticalAlignmentEnum;
|
||||
|
||||
/**
|
||||
* @author hao
|
||||
*/
|
||||
@HeadRowHeight(24)
|
||||
@HeadFontStyle(fontHeightInPoints = 13)
|
||||
@HeadStyle(horizontalAlignment = HorizontalAlignmentEnum.LEFT)
|
||||
@ContentRowHeight(20)
|
||||
@ContentFontStyle(fontHeightInPoints = 12)
|
||||
@ContentStyle(verticalAlignment = VerticalAlignmentEnum.CENTER)
|
||||
@ColumnWidth(20)
|
||||
public interface PoiWriteBase {
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.tiesheng.poi.util;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.read.listener.ReadListener;
|
||||
import com.tiesheng.poi.pojos.PoiReadBase;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class PoiReadUtil {
|
||||
|
||||
|
||||
/**
|
||||
* 读取文件
|
||||
*
|
||||
* @param file
|
||||
* @param readListener
|
||||
* @return
|
||||
*/
|
||||
public static <T extends PoiReadBase> void read(File file, Class<T> tClass, ReadListener<T> readListener) {
|
||||
EasyExcel.read(file, tClass, readListener).autoTrim(true).headRowNumber(1).sheet().doRead();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.tiesheng.poi.util;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.annotation.write.style.*;
|
||||
import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum;
|
||||
import com.alibaba.excel.enums.poi.VerticalAlignmentEnum;
|
||||
import com.alibaba.excel.support.ExcelTypeEnum;
|
||||
import com.tiesheng.poi.pojos.PoiWriteBase;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author hao
|
||||
*/
|
||||
@HeadRowHeight(24)
|
||||
@HeadFontStyle(fontHeightInPoints = 13)
|
||||
@HeadStyle(horizontalAlignment = HorizontalAlignmentEnum.LEFT)
|
||||
@ContentRowHeight(20)
|
||||
@ContentFontStyle(fontHeightInPoints = 12)
|
||||
@ContentStyle(verticalAlignment = VerticalAlignmentEnum.CENTER)
|
||||
@ColumnWidth(20)
|
||||
public class PoiWriteUtil {
|
||||
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
public static <T extends PoiWriteBase> boolean export(List<T> list, Class<T> tClass, String absPath, String sheetName) {
|
||||
EasyExcel.write(absPath, tClass).excelType(ExcelTypeEnum.XLSX)
|
||||
.sheet(sheetName)
|
||||
.doWrite(list);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
<version>2.0.31</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-role</artifactId>
|
||||
|
||||
@@ -3,13 +3,17 @@ package com.tiesheng.role.controller;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.tiesheng.role.pojos.dao.CoreRoleAuthority;
|
||||
import com.tiesheng.role.pojos.dao.CoreRoleGroup;
|
||||
import com.tiesheng.role.pojos.dao.CoreRoleServer;
|
||||
import com.tiesheng.role.pojos.dto.OwnerMenuDTO;
|
||||
import com.tiesheng.role.pojos.dto.OwnerPointDTO;
|
||||
import com.tiesheng.role.pojos.vo.GroupTypeDTO;
|
||||
import com.tiesheng.role.pojos.vo.ServiceMenuVO;
|
||||
import com.tiesheng.role.service.CoreRoleService;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
import com.tiesheng.util.pojos.DaoBase;
|
||||
import com.tiesheng.util.pojos.TokenBean;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -40,12 +44,21 @@ public class CommRoleController {
|
||||
List<CoreRoleAuthority> allOwnerMenus = coreRoleService.getOwnerAuthorityLeafList(tokenBean.getId(), tokenBean.getRoleId());
|
||||
List<String> list = allOwnerMenus.stream().map(CoreRoleAuthority::getService).collect(Collectors.toList());
|
||||
|
||||
// 添加公开服务
|
||||
list.addAll(coreRoleService.getServerMapper().selectList(new QueryWrapper<CoreRoleServer>()
|
||||
.eq("is_public", 1).eq("is_deleted", 0).eq("is_open", 1)
|
||||
).stream().map(DaoBase::getId).collect(Collectors.toList()));
|
||||
|
||||
// 去除重复
|
||||
list = CollUtil.distinct(list);
|
||||
|
||||
List<CoreRoleServer> roleServerList = new ArrayList<>();
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
roleServerList = coreRoleService.getServerMapper().selectList(new QueryWrapper<CoreRoleServer>()
|
||||
.in("id", list)
|
||||
.eq(CoreRoleServer.IS_DELETED, 0)
|
||||
.eq("is_open", 1)
|
||||
.orderByAsc("sort")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -101,4 +114,24 @@ public class CommRoleController {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 角色、职位列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/group")
|
||||
public ApiResp<List<CoreRoleGroup>> groupPage(@Valid GroupTypeDTO dto) {
|
||||
|
||||
QueryWrapper<CoreRoleGroup> queryWrapper = new QueryWrapper<CoreRoleGroup>()
|
||||
.eq("is_deleted", 0)
|
||||
.eq(StrUtil.isNotEmpty(dto.getType()), "type", dto.getType())
|
||||
.orderByAsc("sort");
|
||||
dto.likeColumns(queryWrapper, "name");
|
||||
|
||||
Page<CoreRoleGroup> page = dto.pageObj();
|
||||
coreRoleService.page(page, queryWrapper);
|
||||
|
||||
return ApiResp.respOK(page.getRecords(), page.getTotal());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -103,6 +103,7 @@ public class RoleGroupController {
|
||||
List<CoreRoleGroupRx> list = coreRoleService.getGroupRxMapper().selectList(new QueryWrapper<CoreRoleGroupRx>()
|
||||
.eq(CoreRoleGroupRx.IS_DELETED, 0)
|
||||
.eq("group_id", dto.getId())
|
||||
.eq("type", "bind")
|
||||
);
|
||||
return ApiResp.respOK(list);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.tiesheng.annotation.role.RoleAuthority;
|
||||
import com.tiesheng.role.pojos.dao.CoreRoleAuthority;
|
||||
import com.tiesheng.role.pojos.dao.CoreRoleServer;
|
||||
import com.tiesheng.role.pojos.dto.MenuListDTO;
|
||||
import com.tiesheng.role.pojos.dto.ServerListDTO;
|
||||
import com.tiesheng.role.pojos.vo.ServiceMenuVO;
|
||||
import com.tiesheng.role.service.CoreRoleService;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
@@ -29,10 +30,11 @@ public class RoleServerController {
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/server/list")
|
||||
public ApiResp<List<CoreRoleServer>> list() {
|
||||
public ApiResp<List<CoreRoleServer>> list(ServerListDTO dto) {
|
||||
return ApiResp.respOK(coreRoleService.getServerMapper().selectList(new QueryWrapper<CoreRoleServer>()
|
||||
.eq(CoreRoleServer.IS_DELETED, 0)
|
||||
.eq("is_open", 1)
|
||||
.eq(StrUtil.isNotEmpty(dto.getIsOpen()), "is_open", dto.getIsOpen())
|
||||
.orderByAsc("sort")
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -14,4 +14,4 @@ public interface CoreRoleGroupRxMapper extends BaseMapper<CoreRoleGroupRx> {
|
||||
* @return
|
||||
*/
|
||||
int batchInsert(@Param("list") List<CoreRoleGroupRx> coreRoleGroupRxs);
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public interface CoreRoleUserMapper extends BaseMapper<CoreRoleUser> {
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<CoreRoleAuthority> getOwnerAuthorityLeafList(@Param("userId") String userId,
|
||||
@Param("roleId") String roleId);
|
||||
List<CoreRoleAuthority> getOwnerAuthorityLeafList(@Param("userId") String userId, @Param("roleId") String roleId,
|
||||
@Param("type") String type);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.tiesheng.role.pojos.dao;
|
||||
|
||||
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 com.tiesheng.util.pojos.DaoBase;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 角色-权限
|
||||
@@ -81,6 +84,18 @@ public class CoreRoleAuthority extends DaoBase {
|
||||
@TableField(value = "version")
|
||||
private String version;
|
||||
|
||||
/**
|
||||
* 权限来源:auto-自动生成,input-添加
|
||||
*/
|
||||
@TableField(value = "`source`")
|
||||
private String source;
|
||||
|
||||
/**
|
||||
* 依赖权限
|
||||
*/
|
||||
@TableField(value = "deps")
|
||||
private String deps;
|
||||
|
||||
/**
|
||||
* 扩展1
|
||||
*/
|
||||
@@ -315,6 +330,42 @@ public class CoreRoleAuthority extends DaoBase {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取权限来源:auto-自动生成,input-添加
|
||||
*
|
||||
* @return source - 权限来源:auto-自动生成,input-添加
|
||||
*/
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置权限来源:auto-自动生成,input-添加
|
||||
*
|
||||
* @param source 权限来源:auto-自动生成,input-添加
|
||||
*/
|
||||
public void setSource(String source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取依赖权限
|
||||
*
|
||||
* @return deps - 依赖权限
|
||||
*/
|
||||
public String getDeps() {
|
||||
return deps;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置依赖权限
|
||||
*
|
||||
* @param deps 依赖权限
|
||||
*/
|
||||
public void setDeps(String deps) {
|
||||
this.deps = deps;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取扩展1
|
||||
*
|
||||
@@ -368,4 +419,4 @@ public class CoreRoleAuthority extends DaoBase {
|
||||
public void setExt3(String ext3) {
|
||||
this.ext3 = ext3;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,12 @@ public class CoreRoleGroupRx extends DaoBase {
|
||||
@TableField(value = "menu_id")
|
||||
private String menuId;
|
||||
|
||||
/**
|
||||
* 关联类型:dep-依赖,bind-绑定
|
||||
*/
|
||||
@TableField(value = "`type`")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 获取角色id
|
||||
*
|
||||
@@ -59,4 +65,22 @@ public class CoreRoleGroupRx extends DaoBase {
|
||||
public void setMenuId(String menuId) {
|
||||
this.menuId = menuId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取关联类型:dep-依赖,bind-绑定
|
||||
*
|
||||
* @return type - 关联类型:dep-依赖,bind-绑定
|
||||
*/
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置关联类型:dep-依赖,bind-绑定
|
||||
*
|
||||
* @param type 关联类型:dep-依赖,bind-绑定
|
||||
*/
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
@@ -66,6 +66,12 @@ public class CoreRoleServer extends DaoBase {
|
||||
@TableField(value = "ext3")
|
||||
private String ext3;
|
||||
|
||||
/**
|
||||
* 是否公开
|
||||
*/
|
||||
@TableField(value = "is_public")
|
||||
private Integer isPublic;
|
||||
|
||||
/**
|
||||
* 获取名称
|
||||
*
|
||||
@@ -227,4 +233,22 @@ public class CoreRoleServer extends DaoBase {
|
||||
public void setExt3(String ext3) {
|
||||
this.ext3 = ext3;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取是否公开
|
||||
*
|
||||
* @return is_public - 是否公开
|
||||
*/
|
||||
public Integer getIsPublic() {
|
||||
return isPublic;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置是否公开
|
||||
*
|
||||
* @param isPublic 是否公开
|
||||
*/
|
||||
public void setIsPublic(Integer isPublic) {
|
||||
this.isPublic = isPublic;
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,12 @@ public class CoreRoleUser extends DaoBase {
|
||||
@TableField(value = "type_id")
|
||||
private String typeId;
|
||||
|
||||
/**
|
||||
* 说明
|
||||
*/
|
||||
@TableField(value = "remark")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 过期时间,无则不过期
|
||||
*/
|
||||
@@ -108,6 +114,14 @@ public class CoreRoleUser extends DaoBase {
|
||||
this.typeId = typeId;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取过期时间,无则不过期
|
||||
*
|
||||
@@ -179,4 +193,4 @@ public class CoreRoleUser extends DaoBase {
|
||||
public void setExt3(String ext3) {
|
||||
this.ext3 = ext3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.tiesheng.role.pojos.dto;
|
||||
|
||||
public class ServerListDTO {
|
||||
|
||||
private String isOpen;
|
||||
|
||||
|
||||
public String getIsOpen() {
|
||||
return isOpen;
|
||||
}
|
||||
|
||||
public void setIsOpen(String isOpen) {
|
||||
this.isOpen = isOpen;
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,23 @@ package com.tiesheng.role.pojos.vo;
|
||||
|
||||
import com.tiesheng.role.pojos.dao.CoreRoleAuthority;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ServiceMenuVO extends CoreRoleAuthority {
|
||||
|
||||
private List<ServiceMenuVO> children;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
public ServiceMenuVO sortChildren() {
|
||||
children = children.stream().sorted(Comparator.comparingInt(ServiceMenuVO::getSort))
|
||||
.collect(Collectors.toList());
|
||||
return this;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// setter\getter
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package com.tiesheng.role.service;
|
||||
|
||||
import cn.hutool.core.annotation.AnnotationUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.tiesheng.annotation.role.RoleAuthority;
|
||||
import com.tiesheng.role.mapper.*;
|
||||
import com.tiesheng.role.pojos.dao.CoreRoleAuthority;
|
||||
import com.tiesheng.role.pojos.dao.CoreRoleGroup;
|
||||
@@ -20,21 +19,15 @@ import com.tiesheng.util.exception.ApiException;
|
||||
import com.tiesheng.util.service.TsCacheService;
|
||||
import com.tiesheng.util.service.TsServiceBase;
|
||||
import com.tiesheng.util.service.role.TsAuthorityHandler;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRoleGroup>
|
||||
implements ApplicationListener<ContextRefreshedEvent> {
|
||||
public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRoleGroup> {
|
||||
|
||||
@Resource
|
||||
CoreRoleUserMapper coreRoleUserMapper;
|
||||
@@ -44,8 +37,7 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
|
||||
CoreRoleAuthorityMapper coreRoleAuthorityMapper;
|
||||
@Resource
|
||||
CoreRoleServerMapper coreRoleServerMapper;
|
||||
@Resource
|
||||
TsAuthorityHandler tsAuthorityHandler;
|
||||
|
||||
|
||||
public CoreRoleServerMapper getServerMapper() {
|
||||
return coreRoleServerMapper;
|
||||
@@ -72,7 +64,18 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
|
||||
* @return
|
||||
*/
|
||||
public List<ServiceMenuVO> menuChildrenWrap(List<CoreRoleAuthority> coreServiceMenuList, String parent) {
|
||||
List<CoreRoleAuthority> distinctList = coreServiceMenuList.stream().distinct().collect(Collectors.toList());
|
||||
|
||||
HashMap<String, String> keyMaps = MapUtil.newHashMap();
|
||||
|
||||
List<CoreRoleAuthority> distinctList = coreServiceMenuList.stream()
|
||||
.filter(it -> {
|
||||
if (keyMaps.containsKey(it.getId())) {
|
||||
return false;
|
||||
}
|
||||
keyMaps.put(it.getId(), it.getId());
|
||||
return true;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<ServiceMenuVO> list = new ArrayList<>();
|
||||
|
||||
@@ -101,6 +104,10 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
|
||||
.eq("group_id", dto.getId())
|
||||
);
|
||||
|
||||
if (CollUtil.isEmpty(dto.getMenuIds())) {
|
||||
return;
|
||||
}
|
||||
|
||||
CoreRoleGroup roleGroup = getById(dto.getId());
|
||||
Validator.validateNotEmpty(roleGroup, "角色不存在");
|
||||
|
||||
@@ -114,14 +121,23 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
|
||||
CoreRoleGroupRx coreRoleGroupRx = new CoreRoleGroupRx();
|
||||
coreRoleGroupRx.setGroupId(roleGroup.getId());
|
||||
coreRoleGroupRx.setMenuId(authority.getId());
|
||||
coreRoleGroupRx.setType("bind");
|
||||
list.add(coreRoleGroupRx);
|
||||
|
||||
List<String> deps = JSON.parseArray(authority.getDeps(), String.class);
|
||||
for (String dep : deps) {
|
||||
CoreRoleGroupRx depRx = new CoreRoleGroupRx();
|
||||
depRx.setGroupId(roleGroup.getId());
|
||||
depRx.setMenuId(StrUtil.format("{}_{}", authority.getService(), dep));
|
||||
depRx.setType("dep");
|
||||
list.add(depRx);
|
||||
}
|
||||
}
|
||||
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
coreRoleGroupRxMapper.batchInsert(list);
|
||||
onRoleChange(dto.getId(), "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -131,13 +147,16 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
|
||||
* @param roleUser
|
||||
*/
|
||||
public void roleUserUpdate(CoreRoleUser roleUser) {
|
||||
Validator.validateNotEmpty(roleUser.getType(), "请选择授权方式");
|
||||
Validator.validateNotEmpty(roleUser.getTypeId(), "请选择授权" + (Objects.equals(roleUser.getType(), "menu") ? "菜单" : "职位"));
|
||||
|
||||
if (StrUtil.isNotEmpty(roleUser.getId())) {
|
||||
coreRoleUserMapper.updateById(roleUser);
|
||||
} else {
|
||||
coreRoleUserMapper.insert(roleUser);
|
||||
}
|
||||
|
||||
onRoleChange(roleUser.getTypeId(), roleUser.getUserId());
|
||||
onRoleChange("", roleUser.getUserId());
|
||||
}
|
||||
|
||||
|
||||
@@ -154,7 +173,7 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
|
||||
coreRoleUser.setIsDeleted(1);
|
||||
coreRoleUserMapper.updateById(coreRoleUser);
|
||||
|
||||
onRoleChange(coreRoleUser.getTypeId(), coreRoleUser.getUserId());
|
||||
onRoleChange("", coreRoleUser.getUserId());
|
||||
}
|
||||
|
||||
|
||||
@@ -162,8 +181,13 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
|
||||
* 当授权发生变化时
|
||||
*/
|
||||
public void onRoleChange(String roleId, String userId) {
|
||||
TsCacheService.of().keys(StrUtil.format(TsAuthorityHandler.CACHE_HAS_AUTHORITY,
|
||||
roleId, userId)).forEach(key -> TsCacheService.of().remove(key));
|
||||
if (StrUtil.isEmpty(roleId)) {
|
||||
TsCacheService.of().keys(StrUtil.replace(TsAuthorityHandler.CACHE_AUTHORITY,
|
||||
":{}", "")).forEach(key -> TsCacheService.of().remove(key));
|
||||
} else {
|
||||
TsCacheService.of().keys(StrUtil.format(TsAuthorityHandler.CACHE_AUTHORITY,
|
||||
roleId, userId)).forEach(key -> TsCacheService.of().remove(key));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -173,7 +197,7 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
|
||||
* @return
|
||||
*/
|
||||
public List<CoreRoleAuthority> getOwnerAuthorityLeafList(String userId, String roleId) {
|
||||
return coreRoleUserMapper.getOwnerAuthorityLeafList(userId, roleId);
|
||||
return coreRoleUserMapper.getOwnerAuthorityLeafList(userId, roleId, "bind");
|
||||
}
|
||||
|
||||
|
||||
@@ -214,38 +238,11 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
|
||||
|
||||
return menuChildrenWrap(ownerAuthorityList.stream()
|
||||
.filter(it -> Objects.equals(it.getType(), "group") || Objects.equals(it.getType(), "menu"))
|
||||
.collect(Collectors.toList()), null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||
ApplicationContext applicationContext = event.getApplicationContext();
|
||||
Map<String, Object> beansOfType = applicationContext.getBeansWithAnnotation(RoleAuthority.class);
|
||||
|
||||
String version = DateUtil.format(new Date(), "yyyyMMddHHmmss");
|
||||
|
||||
for (Map.Entry<String, Object> entry : beansOfType.entrySet()) {
|
||||
|
||||
Class<?> targetClass = AopUtils.getTargetClass(entry.getValue());
|
||||
RoleAuthority menu = targetClass.getAnnotation(RoleAuthority.class);
|
||||
|
||||
List<RoleAuthority> points = new ArrayList<>();
|
||||
Method[] methods = targetClass.getDeclaredMethods();
|
||||
for (Method method : methods) {
|
||||
RoleAuthority methodAuthority = AnnotationUtil.getAnnotation(method, RoleAuthority.class);
|
||||
if (methodAuthority != null) {
|
||||
points.add(methodAuthority);
|
||||
}
|
||||
}
|
||||
|
||||
tsAuthorityHandler.addRoleAuthority(version, menu, points);
|
||||
}
|
||||
|
||||
coreRoleAuthorityMapper.delete(new QueryWrapper<CoreRoleAuthority>()
|
||||
.ne("version", version)
|
||||
);
|
||||
|
||||
.filter(it -> Objects.equals(it.getService(), dto.getService()) && Objects.equals(it.getPlatform(), dto.getPlatform()))
|
||||
.collect(Collectors.toList()), null)
|
||||
.stream().sorted(Comparator.comparingInt(ServiceMenuVO::getSort))
|
||||
.map(ServiceMenuVO::sortChildren)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.tiesheng.role.service;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.tiesheng.annotation.role.RoleAuthority;
|
||||
import com.tiesheng.role.mapper.CoreRoleAuthorityMapper;
|
||||
import com.tiesheng.role.mapper.CoreRoleUserMapper;
|
||||
@@ -32,6 +34,8 @@ public class RoleAuthorityHandler implements TsAuthorityHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
String menuPlatform = StrUtil.emptyToDefault(menu.platform(), "web");
|
||||
|
||||
List<CoreRoleAuthority> list = new ArrayList<>();
|
||||
|
||||
// 分组
|
||||
@@ -39,7 +43,7 @@ public class RoleAuthorityHandler implements TsAuthorityHandler {
|
||||
groupAuthority.setLevel(0);
|
||||
for (String group : menu.group()) {
|
||||
|
||||
String parentId = groupAuthority.getParent();
|
||||
String parentId = groupAuthority.getId();
|
||||
int level = groupAuthority.getLevel() + 1;
|
||||
String no = group;
|
||||
if (StrUtil.isNotEmpty(groupAuthority.getNo())) {
|
||||
@@ -52,9 +56,11 @@ public class RoleAuthorityHandler implements TsAuthorityHandler {
|
||||
groupAuthority.setService(globalConfig.getService());
|
||||
groupAuthority.setType("group");
|
||||
groupAuthority.setLevel(level);
|
||||
groupAuthority.setPlatform(menu.platform());
|
||||
groupAuthority.setPlatform(menuPlatform);
|
||||
groupAuthority.setParent(parentId);
|
||||
groupAuthority.setVersion(version);
|
||||
groupAuthority.setSource("auto");
|
||||
groupAuthority.setDeps("[]");
|
||||
groupAuthority.setId(StrUtil.join("_", groupAuthority.getService(), groupAuthority.getNo()));
|
||||
list.add(groupAuthority);
|
||||
}
|
||||
@@ -68,8 +74,10 @@ public class RoleAuthorityHandler implements TsAuthorityHandler {
|
||||
menuAuthority.setType("menu");
|
||||
menuAuthority.setLevel(groupAuthority.getLevel() + 1);
|
||||
menuAuthority.setParent(groupAuthority.getId());
|
||||
menuAuthority.setPlatform(menu.platform());
|
||||
menuAuthority.setPlatform(menuPlatform);
|
||||
menuAuthority.setVersion(version);
|
||||
menuAuthority.setSource("auto");
|
||||
menuAuthority.setDeps(JSON.toJSONString(menu.deps()));
|
||||
menuAuthority.setId(StrUtil.join("_", menuAuthority.getService(), menuAuthority.getNo()));
|
||||
list.add(menuAuthority);
|
||||
|
||||
@@ -83,7 +91,9 @@ public class RoleAuthorityHandler implements TsAuthorityHandler {
|
||||
point.setLevel(menuAuthority.getLevel() + 1);
|
||||
point.setParent(menuAuthority.getId());
|
||||
point.setVersion(version);
|
||||
point.setPlatform(StrUtil.emptyToDefault(authority.platform(), menu.platform()));
|
||||
point.setSource("auto");
|
||||
point.setDeps(JSON.toJSONString(authority.deps()));
|
||||
point.setPlatform(StrUtil.emptyToDefault(authority.platform(), menuPlatform));
|
||||
point.setId(StrUtil.join("_", point.getService(), point.getNo()));
|
||||
list.add(point);
|
||||
}
|
||||
@@ -95,8 +105,17 @@ public class RoleAuthorityHandler implements TsAuthorityHandler {
|
||||
@Override
|
||||
public List<String> getAuthorities(TokenBean tokenBean) {
|
||||
List<CoreRoleAuthority> list = coreRoleUserMapper.getOwnerAuthorityLeafList(tokenBean.getId(),
|
||||
tokenBean.getRoleId());
|
||||
tokenBean.getRoleId(), "");
|
||||
return list.stream().map(CoreRoleAuthority::getNo).distinct().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateAfter(String version) {
|
||||
coreRoleAuthorityMapper.delete(new QueryWrapper<CoreRoleAuthority>()
|
||||
.ne("version", version)
|
||||
.eq("service", globalConfig.getService())
|
||||
.eq("source", "auto")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ create table core_role_authority
|
||||
ext3 varchar(500) null comment '扩展3'
|
||||
) ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_general_ci
|
||||
comment '角色-权限';
|
||||
|
||||
create table core_role_group
|
||||
@@ -43,6 +44,7 @@ create table core_role_group
|
||||
ext3 varchar(500) null comment '扩展3'
|
||||
) ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_general_ci
|
||||
comment '角色-分组';
|
||||
|
||||
create table core_role_group_rx
|
||||
@@ -56,6 +58,7 @@ create table core_role_group_rx
|
||||
menu_id varchar(50) not null comment '菜单id'
|
||||
) ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_general_ci
|
||||
comment '角色-分组-关系';
|
||||
|
||||
create table core_role_server
|
||||
@@ -76,6 +79,7 @@ create table core_role_server
|
||||
ext3 varchar(500) null comment '扩展3'
|
||||
) ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_general_ci
|
||||
comment '角色-服务';
|
||||
|
||||
create table core_role_user
|
||||
@@ -94,9 +98,22 @@ create table core_role_user
|
||||
ext3 varchar(500) null comment '扩展3'
|
||||
) ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_general_ci
|
||||
comment '角色-用户';
|
||||
|
||||
alter table core_role_authority
|
||||
add version varchar(50) null comment '版本号' after platform;
|
||||
|
||||
alter table core_role_authority
|
||||
add source varchar(10) null comment '权限来源:auto-自动生成,input-添加' after version;
|
||||
|
||||
alter table core_role_authority
|
||||
add deps text null comment '依赖权限' after source;
|
||||
|
||||
alter table core_role_group_rx
|
||||
add type varchar(10) null comment '关联类型:dep-依赖,bind-绑定';
|
||||
|
||||
alter table core_role_user
|
||||
add remark varchar(500) null comment '说明' after type_id;
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
alter table core_role_server
|
||||
add is_public int default 0 null comment '是否公开';
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
<result column="link" jdbcType="LONGVARCHAR" property="link" />
|
||||
<result column="platform" jdbcType="VARCHAR" property="platform" />
|
||||
<result column="version" jdbcType="VARCHAR" property="version" />
|
||||
<result column="source" jdbcType="VARCHAR" property="source" />
|
||||
<result column="deps" jdbcType="LONGVARCHAR" property="deps" />
|
||||
<result column="ext1" jdbcType="VARCHAR" property="ext1" />
|
||||
<result column="ext2" jdbcType="VARCHAR" property="ext2" />
|
||||
<result column="ext3" jdbcType="VARCHAR" property="ext3" />
|
||||
@@ -27,12 +29,12 @@
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
id, create_time, update_time, is_deleted, service, `no`, `name`, sort, `level`, parent,
|
||||
remark, is_open, `type`, link, platform, version, ext1, ext2, ext3
|
||||
remark, is_open, `type`, link, platform, version, `source`, deps, ext1, ext2, ext3
|
||||
</sql>
|
||||
|
||||
<insert id="batchInsert">
|
||||
insert into core_role_authority(id, create_time, update_time, is_deleted, service, no, name, level, parent,
|
||||
type, platform, is_open, version)
|
||||
type, platform, is_open, version, source, deps)
|
||||
values
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(#{item.id}, now(), now(), 0,
|
||||
@@ -42,7 +44,7 @@
|
||||
#{item.level},
|
||||
#{item.parent},
|
||||
#{item.type},
|
||||
#{item.platform}, 1, #{item.version})
|
||||
#{item.platform}, 1, #{item.version}, #{item.source}, #{item.deps})
|
||||
</foreach>
|
||||
|
||||
on duplicate key update update_time=now(),
|
||||
@@ -51,6 +53,8 @@
|
||||
parent=values(parent),
|
||||
type=values(type),
|
||||
platform=values(platform),
|
||||
source=values(source),
|
||||
deps=values(deps),
|
||||
version=values(version)
|
||||
</insert>
|
||||
|
||||
|
||||
@@ -10,19 +10,20 @@
|
||||
<result column="is_deleted" jdbcType="INTEGER" property="isDeleted" />
|
||||
<result column="group_id" jdbcType="VARCHAR" property="groupId" />
|
||||
<result column="menu_id" jdbcType="VARCHAR" property="menuId" />
|
||||
<result column="type" jdbcType="VARCHAR" property="type" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
id, create_time, update_time, is_deleted, group_id, menu_id
|
||||
id, create_time, update_time, is_deleted, group_id, menu_id, `type`
|
||||
</sql>
|
||||
|
||||
<insert id="batchInsert">
|
||||
insert into core_role_group_rx(id, create_time, update_time, is_deleted, group_id, menu_id)
|
||||
insert into core_role_group_rx(id, create_time, update_time, is_deleted, group_id, menu_id,type)
|
||||
values
|
||||
<foreach collection="list" separator="," item="item">
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(uuid(), now(), now(), 0,
|
||||
#{item.groupId},
|
||||
#{item.menuId})
|
||||
#{item.menuId}, #{item.type})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
|
||||
@@ -17,10 +17,11 @@
|
||||
<result column="ext1" jdbcType="VARCHAR" property="ext1" />
|
||||
<result column="ext2" jdbcType="VARCHAR" property="ext2" />
|
||||
<result column="ext3" jdbcType="VARCHAR" property="ext3" />
|
||||
<result column="is_public" jdbcType="INTEGER" property="isPublic" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
id, create_time, update_time, is_deleted, `name`, remark, logo, sort, is_open, link,
|
||||
ext1, ext2, ext3
|
||||
ext1, ext2, ext3, is_public
|
||||
</sql>
|
||||
</mapper>
|
||||
@@ -11,6 +11,7 @@
|
||||
<result column="user_id" jdbcType="VARCHAR" property="userId" />
|
||||
<result column="type" jdbcType="VARCHAR" property="type" />
|
||||
<result column="type_id" jdbcType="VARCHAR" property="typeId" />
|
||||
<result column="remark" jdbcType="VARCHAR" property="remark" />
|
||||
<result column="expire_time" jdbcType="TIMESTAMP" property="expireTime" />
|
||||
<result column="ext1" jdbcType="VARCHAR" property="ext1" />
|
||||
<result column="ext2" jdbcType="VARCHAR" property="ext2" />
|
||||
@@ -18,7 +19,7 @@
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
id, create_time, update_time, is_deleted, user_id, `type`, type_id, expire_time,
|
||||
id, create_time, update_time, is_deleted, user_id, `type`, type_id, remark, expire_time,
|
||||
ext1, ext2, ext3
|
||||
</sql>
|
||||
|
||||
@@ -50,10 +51,13 @@
|
||||
select crgr.menu_id
|
||||
from core_role_user cru
|
||||
left join core_role_group_rx crgr on crgr.group_id = cru.type_id
|
||||
where type = 'job'
|
||||
and user_id = #{userId}
|
||||
where cru.type = 'job'
|
||||
and cru.user_id = #{userId}
|
||||
and cru.is_deleted = 0
|
||||
and (cru.expire_time is null or cru.expire_time > now())
|
||||
<if test="type != null and type != ''">
|
||||
and crgr.type=#{type}
|
||||
</if>
|
||||
|
||||
<if test="roleId != null and roleId != ''">
|
||||
union
|
||||
@@ -61,6 +65,9 @@
|
||||
select menu_id
|
||||
from core_role_group_rx
|
||||
where group_id = #{roleId}
|
||||
<if test="type != null and type != ''">
|
||||
and type=#{type}
|
||||
</if>
|
||||
</if>
|
||||
)
|
||||
order by sort
|
||||
|
||||
BIN
springboot-util/.DS_Store
vendored
BIN
springboot-util/.DS_Store
vendored
Binary file not shown.
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>2.0.0.rc20</version>
|
||||
<version>2.0.31</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-util</artifactId>
|
||||
@@ -32,15 +32,44 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-bom</artifactId>
|
||||
<version>5.8.16</version>
|
||||
<type>pom</type>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-http</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<artifactId>hutool-core</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-cache</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-captcha</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-log</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-crypto</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-extra</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-db</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -53,7 +82,7 @@
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.30</version>
|
||||
<version>8.0.33</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -78,7 +107,7 @@
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15to18</artifactId>
|
||||
<version>1.68</version>
|
||||
<version>1.80</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -4,10 +4,8 @@ package com.tiesheng.util;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
|
||||
import java.util.Map;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
public class CharacterUtils {
|
||||
|
||||
@@ -24,19 +22,24 @@ public class CharacterUtils {
|
||||
/**
|
||||
* 移除特殊字符
|
||||
*
|
||||
* @param o 类
|
||||
* @param o 类
|
||||
* @param searchStr 规则
|
||||
*/
|
||||
public static void removeSymbol(Object o, String searchStr) {
|
||||
JSONObject object = JSONUtil.parseObj(o, false);
|
||||
for (Map.Entry<String, Object> entry : object) {
|
||||
if (ObjectUtil.isEmpty(entry.getValue()) || StrUtil.equals("null", String.valueOf(entry.getValue()))) {
|
||||
entry.setValue("");
|
||||
JSONObject object = JSON.parseObject(JSON.toJSONString(o));
|
||||
for (String key : object.keySet()) {
|
||||
if (StrUtil.isEmpty(key)) {
|
||||
continue;
|
||||
}
|
||||
if (StrUtil.isNotEmpty(entry.getKey())) {
|
||||
entry.setValue(StrUtil.trim(StrUtil.replace(entry.getValue().toString(), searchStr, "")));
|
||||
|
||||
Object value = object.get(key);
|
||||
if (ObjectUtil.isEmpty(value) || StrUtil.equals("null", String.valueOf(value))) {
|
||||
object.put(key, "");
|
||||
continue;
|
||||
}
|
||||
|
||||
String replace = StrUtil.replace(String.valueOf(value), searchStr, "");
|
||||
object.put(key, StrUtil.trim(replace));
|
||||
}
|
||||
BeanUtil.copyProperties(object, o);
|
||||
}
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
package com.tiesheng.util;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
||||
import com.tiesheng.util.config.DesensitizeValueFilter;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class CommonUtil {
|
||||
|
||||
|
||||
/**
|
||||
* FastJson配置
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static FastJsonConfig fastJsonConfig() {
|
||||
FastJsonConfig config = new FastJsonConfig();
|
||||
config.setSerializerFeatures(SerializerFeature.WriteMapNullValue,
|
||||
SerializerFeature.WriteNullStringAsEmpty,
|
||||
SerializerFeature.WriteEnumUsingName,
|
||||
SerializerFeature.DisableCircularReferenceDetect
|
||||
);
|
||||
config.setDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
config.setSerializeFilters(new DesensitizeValueFilter());
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 格式化数据
|
||||
*
|
||||
* @param value
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static String writeJsonString(Object value) throws IOException {
|
||||
FastJsonConfig fastJsonConfig = fastJsonConfig();
|
||||
ByteArrayOutputStream outnew = new ByteArrayOutputStream();
|
||||
JSON.writeJSONStringWithFastJsonConfig(outnew, fastJsonConfig.getCharset(),
|
||||
value, fastJsonConfig.getSerializeConfig(),
|
||||
fastJsonConfig.getSerializeFilters(),
|
||||
fastJsonConfig.getDateFormat(), JSON.DEFAULT_GENERATE_FEATURE,
|
||||
fastJsonConfig.getSerializerFeatures());
|
||||
return outnew.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,7 +17,25 @@ public class ServletKit extends ServletUtil {
|
||||
public static HttpServletRequest getRequest() {
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes)
|
||||
RequestContextHolder.getRequestAttributes();
|
||||
return attributes.getRequest();
|
||||
if (attributes != null) {
|
||||
return attributes.getRequest();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取请求头
|
||||
*
|
||||
* @param name 请求头
|
||||
* @return 请求头
|
||||
*/
|
||||
public static String getHeader(String name) {
|
||||
HttpServletRequest request = getRequest();
|
||||
if (request == null) {
|
||||
return "";
|
||||
}
|
||||
return getHeader(request, name, "utf-8");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,6 +45,9 @@ public class ServletKit extends ServletUtil {
|
||||
*/
|
||||
public static String getClientIP() {
|
||||
HttpServletRequest request = getRequest();
|
||||
if (request == null) {
|
||||
return "";
|
||||
}
|
||||
return getClientIP(request);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.tiesheng.util.config;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.serializer.ValueFilter;
|
||||
import com.tiesheng.annotation.desensitize.Desensitize;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* 脱敏过滤类
|
||||
*
|
||||
* @author hao
|
||||
*/
|
||||
public class DesensitizeValueFilter implements ValueFilter {
|
||||
|
||||
@Override
|
||||
public Object process(Object object, String name, Object value) {
|
||||
if (ObjectUtil.isEmpty(value) || !(value instanceof String)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
Field field = ReflectUtil.getField(object.getClass(), name);
|
||||
if (ObjectUtil.isEmpty(field)) {
|
||||
return value;
|
||||
}
|
||||
Desensitize desensitize = field.getAnnotation(Desensitize.class);
|
||||
if (String.class != field.getType() || ObjectUtil.isEmpty(desensitize)) {
|
||||
return value;
|
||||
}
|
||||
String originVal = String.valueOf(value);
|
||||
return StrUtil.hide(originVal, desensitize.prefix(),
|
||||
StrUtil.length(originVal) - desensitize.suffix());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,12 @@
|
||||
package com.tiesheng.util.config;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.crypto.SmUtil;
|
||||
import cn.hutool.crypto.symmetric.SM4;
|
||||
import com.tiesheng.util.ServletKit;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
import com.tiesheng.util.service.TsCacheService;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -31,6 +28,7 @@ public class EncryptConfig {
|
||||
private String key = "WmdUzPJXbngVNiaSsQrihg==";
|
||||
private Integer saltSize = 8;
|
||||
private boolean body = false;
|
||||
private String pwdPatten = "^(?![A-Za-z0-9]+$)(?![a-z0-9\\W]+$)(?![A-Za-z\\W]+$)(?![A-Z0-9\\W]+$)[a-zA-Z0-9\\W]{8,}$";
|
||||
|
||||
public EncryptConfig() {
|
||||
sm4 = SmUtil.sm4(Base64.decode(getKey()));
|
||||
@@ -76,25 +74,13 @@ public class EncryptConfig {
|
||||
if (StrUtil.isEmpty(salt) || StrUtil.length(salt) != getSaltSize()) {
|
||||
salt = RandomUtil.randomString(saltSize);
|
||||
}
|
||||
if (!passwdComplexity(inputPasswd)) {
|
||||
throw new ApiException("需要包含数字、大小写字母、特殊符号,且长度不低于8位");
|
||||
if (!inputPasswd.matches(getPwdPatten())) {
|
||||
throw new ApiException("密码复杂度不够,请重新设置");
|
||||
}
|
||||
return encrypt(salt + SecureUtil.sha1(salt + inputPasswd));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 复杂度校验
|
||||
*
|
||||
* @param inputPasswd
|
||||
* @return
|
||||
*/
|
||||
public boolean passwdComplexity(String inputPasswd) {
|
||||
String password = "^(?![A-Za-z0-9]+$)(?![a-z0-9\\W]+$)(?![A-Za-z\\W]+$)(?![A-Z0-9\\W]+$)[a-zA-Z0-9\\W]{8,}$";
|
||||
return inputPasswd.matches(password);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 密码校验
|
||||
*
|
||||
@@ -104,12 +90,6 @@ public class EncryptConfig {
|
||||
String salt = decrypt(encrypted).substring(0, saltSize);
|
||||
String inputEncrypted = passwdCreate(inputPasswd, salt);
|
||||
if (!StrUtil.equals(inputEncrypted, encrypted)) {
|
||||
String clientIp = "passwdVerify_" + ServletKit.getClientIP();
|
||||
int num = NumberUtil.parseInt(TsCacheService.of().get(clientIp, -1));
|
||||
if (num > 5) {
|
||||
throw new ApiException("登录失败已达6次,请10分钟后再试");
|
||||
}
|
||||
TsCacheService.of().put(clientIp, String.valueOf(num + 1), 10 * 60);
|
||||
throw new ApiException("账号或密码错误");
|
||||
}
|
||||
}
|
||||
@@ -142,4 +122,12 @@ public class EncryptConfig {
|
||||
public void setBody(boolean body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public String getPwdPatten() {
|
||||
return pwdPatten;
|
||||
}
|
||||
|
||||
public void setPwdPatten(String pwdPatten) {
|
||||
this.pwdPatten = pwdPatten;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.hutool.log.LogFactory;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -26,6 +28,18 @@ import java.util.List;
|
||||
@ConfigurationProperties(prefix = "tiesheng.global")
|
||||
public class GlobalConfig {
|
||||
|
||||
static {
|
||||
JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
// FASTJSON 设置全局序列化配置
|
||||
JSON.DEFAULT_GENERATE_FEATURE |= SerializerFeature.WriteMapNullValue.getMask();
|
||||
JSON.DEFAULT_GENERATE_FEATURE |= SerializerFeature.WriteNullStringAsEmpty.getMask();
|
||||
JSON.DEFAULT_GENERATE_FEATURE |= SerializerFeature.WriteEnumUsingName.getMask();
|
||||
JSON.DEFAULT_GENERATE_FEATURE |= SerializerFeature.WriteDateUseDateFormat.getMask();
|
||||
JSON.DEFAULT_GENERATE_FEATURE |= SerializerFeature.DisableCircularReferenceDetect.getMask();
|
||||
}
|
||||
|
||||
|
||||
private String host;
|
||||
private String service;
|
||||
private String version;
|
||||
@@ -81,12 +95,13 @@ public class GlobalConfig {
|
||||
|
||||
|
||||
/**
|
||||
* 重定向
|
||||
* 构建待版本号的路径
|
||||
*
|
||||
* @param htmlDir 资源目录
|
||||
* @param htmlDir
|
||||
* @param route
|
||||
* @return
|
||||
*/
|
||||
public void redirect(String htmlDir, String route, HttpServletResponse response) {
|
||||
public String buildByVersion(String htmlDir, String route) {
|
||||
if (!StrUtil.endWith(htmlDir, "/")) {
|
||||
htmlDir = htmlDir + "/";
|
||||
}
|
||||
@@ -115,16 +130,32 @@ public class GlobalConfig {
|
||||
throw new ApiException("无法重定向,请检查资源");
|
||||
}
|
||||
CollUtil.sort(versions, (o1, o2) -> -VersionComparator.INSTANCE.compare(o1, o2));
|
||||
String path = buildPath(String.format("/%s%s/index.html#%s", htmlDir, versions.get(0), route));
|
||||
response.sendRedirect(path);
|
||||
return buildPath(String.format("/%s%s/index.html#%s", htmlDir, versions.get(0), route));
|
||||
} catch (IOException e) {
|
||||
LogFactory.get().info(e);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 重定向
|
||||
*
|
||||
* @param htmlDir 资源目录
|
||||
* @param route
|
||||
*/
|
||||
public void redirectWithVer(String htmlDir, String route, HttpServletResponse response) {
|
||||
try {
|
||||
response.sendRedirect(buildByVersion(htmlDir, route));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// setter\getter
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// ////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public String getUploadDir() {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user