Compare commits
98 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0cb1581176 | ||
|
|
5ed663e112 | ||
|
|
b5fd837ccf | ||
|
|
38d6bae04f | ||
|
|
e49bf32117 | ||
|
|
bc3ea0e10c | ||
|
|
305dc743b2 | ||
|
|
6f0360bad5 | ||
|
|
5012c4bd53 | ||
|
|
dd69b3bb1f | ||
|
|
33d20c518e | ||
|
|
d0935cbda0 | ||
|
|
3ed9a47c66 | ||
|
|
3f6989d039 | ||
|
|
6f6e997fd3 | ||
|
|
d9987b41ea | ||
|
|
c33ad6075e | ||
|
|
a32c333a6c | ||
|
|
ed66f035e5 | ||
|
|
f5dd706e6e | ||
|
|
6766694272 | ||
|
|
2f22b64c0e | ||
|
|
4e6b108e7e | ||
|
|
24629f06b4 | ||
|
|
47c9251389 | ||
|
|
dda5f64910 | ||
|
|
704030729a | ||
|
|
c708809a19 | ||
|
|
2bbec9b79a | ||
|
|
e19f27f597 | ||
|
|
68781d4685 | ||
|
|
da69124968 | ||
|
|
8d9632bcaa | ||
|
|
1c0e63bf98 | ||
|
|
c04d45431c | ||
|
|
c5f8508a9e | ||
|
|
06f295bb66 | ||
|
|
bfc578e77c | ||
|
|
b5c10fc224 | ||
|
|
60580b40a4 | ||
|
|
af70808da6 | ||
|
|
c446ee8f75 | ||
|
|
86384a1f23 | ||
|
|
d63b6ab094 | ||
|
|
020d1d99e1 | ||
|
|
32fb562775 | ||
|
|
af50468743 | ||
|
|
cab794ecc4 | ||
|
|
0c511940aa | ||
|
|
60dea50e43 | ||
|
|
cbfeb09a22 | ||
|
|
ef97488ea0 | ||
|
|
8873053c06 | ||
|
|
a65ea27485 | ||
|
|
4343601da1 | ||
|
|
f07e6d99e3 | ||
|
|
fc4b3139aa | ||
|
|
fe9d107eef | ||
|
|
0094bf2e69 | ||
|
|
c0fb149558 | ||
|
|
eb55969063 | ||
|
|
488c53def0 | ||
|
|
c02e67f85f | ||
|
|
9f62986a1e | ||
|
|
07136a6679 | ||
|
|
c3edb50e80 | ||
|
|
aee1861630 | ||
|
|
4196b2531d | ||
|
|
dfaeacae92 | ||
|
|
b304c48dd1 | ||
|
|
d045534be6 | ||
|
|
56b923f5db | ||
|
|
f3e8231814 | ||
|
|
2ca04e654f | ||
|
|
149f4ab061 | ||
|
|
a22c08738a | ||
|
|
d28f3250e3 | ||
|
|
bf3b88b43b | ||
|
|
0a98e81109 | ||
|
|
e3c051d443 | ||
|
|
282a46458a | ||
|
|
637a9d1ace | ||
|
|
959eff62df | ||
|
|
fdbdf79383 | ||
|
|
800c53c6fd | ||
|
|
c3f4f91a37 | ||
|
|
31f6babb97 | ||
|
|
668e7069f7 | ||
|
|
5cd4994624 | ||
|
|
941bd0f65e | ||
|
|
5cf6e1f8d4 | ||
|
|
def1b4e06a | ||
|
|
f5b8e989b7 | ||
|
|
1918dfbaa0 | ||
|
|
7fcc407514 | ||
|
|
b79895aa56 | ||
|
|
4700d4e061 | ||
|
|
a8be751e65 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,3 +5,4 @@ rebel.xml
|
|||||||
*.iml
|
*.iml
|
||||||
/static/
|
/static/
|
||||||
/config/
|
/config/
|
||||||
|
/runtime/
|
||||||
|
|||||||
@@ -9,11 +9,10 @@ deploy-jar:
|
|||||||
rules:
|
rules:
|
||||||
- if: $CI_COMMIT_TAG
|
- if: $CI_COMMIT_TAG
|
||||||
script:
|
script:
|
||||||
- mvn clean deploy -Dmaven.test.skip -DaltDeploymentRepository=master::default::file:/usr/local/nginx/html/kepai-repo
|
- mvn clean deploy -Dmaven.test.skip -DaltDeploymentRepository=master::default::file:$TAG_REPO_FOLDER
|
||||||
- cd /usr/local/nginx/html/kepai-repo
|
- cd $TAG_REPO_FOLDER
|
||||||
- git checkout master
|
- git checkout master
|
||||||
- git pull
|
- git pull
|
||||||
- git add .
|
- git add .
|
||||||
- git commit -m "deploy $CI_PROJECT_NAME $CI_COMMIT_TAG"
|
- git commit -m "deploy $CI_PROJECT_NAME $CI_COMMIT_TAG"
|
||||||
- git push origin master
|
- git push origin master
|
||||||
|
|
||||||
|
|||||||
37
CHANGELOG.md
Normal file
37
CHANGELOG.md
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
## 0.9.3
|
||||||
|
|
||||||
|
> 1,增加版本对比器,防止某些情况下版本对比失效;
|
||||||
|
>
|
||||||
|
|
||||||
|
## 0.8.3
|
||||||
|
|
||||||
|
### 调整
|
||||||
|
|
||||||
|
> 1,优化返回数据加密;
|
||||||
|
> 2,上传文件接口调整,统一为**application/json**格式;
|
||||||
|
|
||||||
|
## 0.8.0
|
||||||
|
|
||||||
|
### 调整
|
||||||
|
|
||||||
|
> 1,移除**PasswordUtil**类,新增**EncryptConfig**配置;
|
||||||
|
> 2,默认启用网络请求的加解密,前端请配合接口使用。
|
||||||
|
|
||||||
|
## 0.7.4
|
||||||
|
|
||||||
|
### 新增
|
||||||
|
|
||||||
|
> 现在操作日志默认收集(不包括GET请求):使用方法名称和接口作为参数存储。如果存在OperationLog注解,则使用注解的内容。
|
||||||
|
|
||||||
|
## 0.7.3
|
||||||
|
|
||||||
|
### 增加
|
||||||
|
|
||||||
|
> 1,TsTokenConfig增加新的属性**ignorePaths**,用于通过路径忽略token;
|
||||||
|
> 2,PasswordUtils增加密码复杂度校验方法;
|
||||||
|
> 3,PasswordUtils.verifyPassword增加登录次数限制:10分钟内不能错误6次;
|
||||||
|
>
|
||||||
|
|
||||||
|
### 调整
|
||||||
|
|
||||||
|
> 1,TsTokenConfig中的**ignores**属性调整为**testMap**;
|
||||||
4
README.md
Normal file
4
README.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
## 杭州铁晟科技有限公司基础项目
|
||||||
|
|
||||||
|
更新日志可点击查看[changelog](./CHANGELOG.md ':include')
|
||||||
|
|
||||||
31
pom.xml
31
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>1.0.1</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>springboot-parent</name>
|
<name>springboot-parent</name>
|
||||||
<description>杭州铁晟科技有限公司基础依赖</description>
|
<description>杭州铁晟科技有限公司基础依赖</description>
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>springboot-ademo</module>
|
<module>springboot-ademo</module>
|
||||||
<module>springboot-db-migration</module>
|
<module>springboot-database</module>
|
||||||
<module>springboot-login</module>
|
<module>springboot-login</module>
|
||||||
<module>springboot-web</module>
|
<module>springboot-web</module>
|
||||||
<module>springboot-util</module>
|
<module>springboot-util</module>
|
||||||
@@ -56,56 +56,56 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-db-migration</artifactId>
|
<artifactId>springboot-database</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>1.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-login</artifactId>
|
<artifactId>springboot-login</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>1.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-web</artifactId>
|
<artifactId>springboot-web</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>1.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-util</artifactId>
|
<artifactId>springboot-util</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>1.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-platform</artifactId>
|
<artifactId>springboot-platform</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>1.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-message</artifactId>
|
<artifactId>springboot-message</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>1.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-encrypt</artifactId>
|
<artifactId>springboot-encrypt</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>1.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-annotation</artifactId>
|
<artifactId>springboot-annotation</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>1.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-poi</artifactId>
|
<artifactId>springboot-poi</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>1.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -117,7 +117,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.baomidou</groupId>
|
<groupId>com.baomidou</groupId>
|
||||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
<version>3.5.1</version>
|
<version>3.5.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@@ -126,7 +126,7 @@
|
|||||||
<pluginRepositories>
|
<pluginRepositories>
|
||||||
<pluginRepository>
|
<pluginRepository>
|
||||||
<id>kepai-repo-plugin</id>
|
<id>kepai-repo-plugin</id>
|
||||||
<url>http://git.kepai365.com/zeng_wenhao/kepai-repo/raw/master</url>
|
<url>http://git.kepai365.com/tiesheng/repository/raw/master</url>
|
||||||
</pluginRepository>
|
</pluginRepository>
|
||||||
</pluginRepositories>
|
</pluginRepositories>
|
||||||
|
|
||||||
@@ -136,12 +136,13 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.tiesheng.springboot-plugin</groupId>
|
<groupId>com.tiesheng.springboot-plugin</groupId>
|
||||||
<artifactId>tiesheng-maven-plugin</artifactId>
|
<artifactId>tiesheng-maven-plugin</artifactId>
|
||||||
<version>0.0.3</version>
|
<version>0.0.5</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>initStartScript</goal>
|
<goal>initStartScript</goal>
|
||||||
<goal>mysqlComparison</goal>
|
<goal>mysqlComparison</goal>
|
||||||
|
<goal>mysqlDoc</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
|
|||||||
BIN
springboot-ademo/.DS_Store
vendored
Normal file
BIN
springboot-ademo/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -6,11 +6,11 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-ademo</artifactId>
|
<artifactId>springboot-ademo</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
@@ -25,12 +25,18 @@
|
|||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-web</artifactId>
|
<artifactId>springboot-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>easyexcel</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>kepai-repo</id>
|
<id>kepai-repo</id>
|
||||||
<url>http://git.kepai365.com/zeng_wenhao/kepai-repo/raw/master</url>
|
<url>http://git.kepai365.com/tiesheng/repository/raw/master</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.tiesheng.demo;
|
|||||||
|
|
||||||
import com.tiesheng.core.EnableTieshengWeb;
|
import com.tiesheng.core.EnableTieshengWeb;
|
||||||
import com.tiesheng.demo.config.DemoWebConfigurer;
|
import com.tiesheng.demo.config.DemoWebConfigurer;
|
||||||
|
import com.tiesheng.encrypt.EnableEncryptConfig;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
@@ -13,6 +14,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableTieshengWeb(webConfigurer = DemoWebConfigurer.class)
|
@EnableTieshengWeb(webConfigurer = DemoWebConfigurer.class)
|
||||||
|
//@EnableEncryptConfig
|
||||||
public class DemoApplication {
|
public class DemoApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.tiesheng.demo.config;
|
package com.tiesheng.demo.config;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.tiesheng.core.pojos.CurrentWebUser;
|
import com.tiesheng.core.pojos.RequestUserInfo;
|
||||||
import com.tiesheng.core.pojos.dao.CorePlatformUnique;
|
import com.tiesheng.core.pojos.dao.CorePlatformUnique;
|
||||||
import com.tiesheng.core.service.TieshengWebConfigurer;
|
import com.tiesheng.core.service.TieshengWebConfigurer;
|
||||||
import com.tiesheng.login.config.token.bean.TokenBean;
|
import com.tiesheng.login.config.token.bean.TokenBean;
|
||||||
@@ -19,35 +19,36 @@ public class DemoWebConfigurer implements TieshengWebConfigurer {
|
|||||||
GlobalConfig globalConfig;
|
GlobalConfig globalConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CurrentWebUser getCurrentUserName(TokenBean tokenBean) {
|
public RequestUserInfo getCurrentUserName(TokenBean tokenBean) {
|
||||||
return null;
|
RequestUserInfo info = new RequestUserInfo();
|
||||||
|
info.setId("1");
|
||||||
|
info.setName("test");
|
||||||
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LoginConfigurer loginConfigurer() {
|
public TokenBean login(CorePlatformUnique platformUnique) {
|
||||||
return new LoginConfigurer() {
|
TokenBean tokenBean = null;
|
||||||
@Override
|
if (!StrUtil.isEmpty(platformUnique.getUserId())) {
|
||||||
public TokenBean doLogin(CorePlatformUnique platformUnique, String to) {
|
tokenBean = new TokenBean(platformUnique.getUserId(), "", globalConfig.getService());
|
||||||
|
} else {
|
||||||
|
// 获取用户信息判断是否可登录
|
||||||
|
|
||||||
// 默认跳转到mobile
|
}
|
||||||
to = StrUtil.emptyToDefault(to, "mobile");
|
|
||||||
|
|
||||||
TokenBean tokenBean = null;
|
return tokenBean;
|
||||||
if (!StrUtil.isEmpty(platformUnique.getUserId())) {
|
|
||||||
tokenBean = new TokenBean(platformUnique.getUserId(), to, globalConfig.getService());
|
|
||||||
} else {
|
|
||||||
// 获取用户信息判断是否可登录
|
|
||||||
}
|
|
||||||
|
|
||||||
return tokenBean;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void redirect(TokenBean bean, String to, String extra, HttpServletResponse response) {
|
|
||||||
if (Objects.equals(bean.getEnvironmentType(), "mobile")) {
|
|
||||||
globalConfig.redirect("mobile", "/?token=" + bean.toToken(), response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void redirect(TokenBean bean, String to, String extra, HttpServletResponse response) {
|
||||||
|
|
||||||
|
// 默认跳转到mobile
|
||||||
|
to = StrUtil.emptyToDefault(to, "mobile");
|
||||||
|
bean.setEnvironmentType(to);
|
||||||
|
|
||||||
|
if (Objects.equals(bean.getEnvironmentType(), "mobile")) {
|
||||||
|
globalConfig.redirect("mobile", "/?token=" + bean.toToken(), response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.tiesheng.demo.config;
|
||||||
|
|
||||||
|
|
||||||
|
import com.tiesheng.core.service.CoreConfigService;
|
||||||
|
import com.tiesheng.core.service.CoreJobService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class TestJobConfig {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CoreJobService coreJobService;
|
||||||
|
@Autowired
|
||||||
|
CoreConfigService coreConfigService;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
|
||||||
|
coreConfigService.refreshFunc("230328001", "demo", "辅导员统计", "辅导员责任班级,学生展示");
|
||||||
|
|
||||||
|
// 辅导员职位
|
||||||
|
coreJobService.refresh("class_fdy", "辅导员", "辅导员", 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,13 +1,26 @@
|
|||||||
package com.tiesheng.demo.controller;
|
package com.tiesheng.demo.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.date.TimeInterval;
|
||||||
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import cn.hutool.log.LogFactory;
|
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.tiesheng.annotation.token.TokenIgnore;
|
import com.tiesheng.annotation.token.TokenIgnore;
|
||||||
|
import com.tiesheng.core.service.CoreLogService;
|
||||||
|
import com.tiesheng.core.service.CoreMessageService;
|
||||||
|
import com.tiesheng.core.util.ProcessImportConsumer;
|
||||||
|
import com.tiesheng.demo.pojos.PoiBean;
|
||||||
|
import com.tiesheng.demo.pojos.TestFile;
|
||||||
import com.tiesheng.login.config.token.TsTokenConfig;
|
import com.tiesheng.login.config.token.TsTokenConfig;
|
||||||
import com.tiesheng.login.config.token.bean.TokenBean;
|
import com.tiesheng.login.config.token.bean.TokenBean;
|
||||||
import com.tiesheng.message.config.aliyun.AliyunSmsConfig;
|
|
||||||
import com.tiesheng.message.pojos.MessageReqResp;
|
import com.tiesheng.message.pojos.MessageReqResp;
|
||||||
|
import com.tiesheng.util.config.EncryptConfig;
|
||||||
import com.tiesheng.util.config.GlobalConfig;
|
import com.tiesheng.util.config.GlobalConfig;
|
||||||
|
import com.tiesheng.util.config.Ip2regionConfig;
|
||||||
import com.tiesheng.util.pojos.ApiResp;
|
import com.tiesheng.util.pojos.ApiResp;
|
||||||
import com.tiesheng.util.pojos.FileUploadPath;
|
import com.tiesheng.util.pojos.FileUploadPath;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -15,6 +28,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hao
|
* @author hao
|
||||||
@@ -26,12 +42,18 @@ public class TestController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
GlobalConfig globalConfig;
|
GlobalConfig globalConfig;
|
||||||
@Autowired
|
@Autowired
|
||||||
AliyunSmsConfig aliyunSmsConfig;
|
|
||||||
@Autowired
|
|
||||||
TsTokenConfig tsTokenConfig;
|
TsTokenConfig tsTokenConfig;
|
||||||
|
@Autowired
|
||||||
|
Ip2regionConfig ip2regionConfig;
|
||||||
|
@Autowired
|
||||||
|
EncryptConfig encryptConfig;
|
||||||
|
@Autowired
|
||||||
|
CoreMessageService coreMessageService;
|
||||||
|
@Autowired
|
||||||
|
CoreLogService coreLogService;
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping("/index")
|
@RequestMapping("/index")
|
||||||
@TokenIgnore
|
|
||||||
public ApiResp<String> index() {
|
public ApiResp<String> index() {
|
||||||
|
|
||||||
TokenBean tokenBean = new TokenBean("11", "", "fdfd");
|
TokenBean tokenBean = new TokenBean("11", "", "fdfd");
|
||||||
@@ -43,22 +65,42 @@ public class TestController {
|
|||||||
@RequestMapping("/redirect")
|
@RequestMapping("/redirect")
|
||||||
@TokenIgnore
|
@TokenIgnore
|
||||||
public void redirect(HttpServletResponse response) {
|
public void redirect(HttpServletResponse response) {
|
||||||
tsTokenConfig.validToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NzYwMDY4NzUsImlkIjoiMSIsImVudmlyb25tZW50VHlwZSI6Im1vYmlsZSIsInNlcnZpY2UiOiJjb250ZXN0LXJlc2VydmUiLCJleHRyYSI6IiJ9.nsfxEFpCNHC7eNCS5DJXdu1VDdnHrTjSfgrozND70Lc", true);
|
|
||||||
// globalConfig.redirect("mobile", "/test", response);
|
ArrayList<String> strings = CollUtil.newArrayList("11111","22222");
|
||||||
|
coreLogService.addProcess("fdfd", strings, new ProcessImportConsumer<String>() {
|
||||||
|
@Override
|
||||||
|
public int accept(List<String> list) {
|
||||||
|
LogFactory.get().info("list: " + list.size());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFailFile() {
|
||||||
|
LogFactory.get().info("getFailFile: " + strings.size());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
LogFactory.get().info("strings: " + strings.size());
|
||||||
|
|
||||||
|
|
||||||
|
// tsTokenConfig.validToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NzYwMDY4NzUsImlkIjoiMSIsImVudmlyb25tZW50VHlwZSI6Im1vYmlsZSIsInNlcnZpY2UiOiJjb250ZXN0LXJlc2VydmUiLCJleHRyYSI6IiJ9.nsfxEFpCNHC7eNCS5DJXdu1VDdnHrTjSfgrozND70Lc", true);
|
||||||
|
globalConfig.redirect("mobile", "/test", response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping("/send")
|
@RequestMapping("/send")
|
||||||
@TokenIgnore
|
@TokenIgnore
|
||||||
public ApiResp<MessageReqResp> sendMessage() {
|
public ApiResp<MessageReqResp> sendMessage() {
|
||||||
MessageReqResp reqResp = aliyunSmsConfig.sendSms("13567116463", "SMS_154950909",
|
|
||||||
JSONUtil.createObj().putOpt("code", "123456"));
|
MessageReqResp reqResp = coreMessageService.send("13567116463", "SMS_154950909",
|
||||||
|
JSONUtil.createObj().putOpt("code", "123456"), "sms");
|
||||||
|
|
||||||
return ApiResp.respOK(reqResp);
|
return ApiResp.respOK(reqResp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping("/export")
|
@RequestMapping("/export")
|
||||||
@TokenIgnore
|
|
||||||
public ApiResp<String> export() {
|
public ApiResp<String> export() {
|
||||||
|
|
||||||
// List<TestFile> list = new ArrayList<>();
|
// List<TestFile> list = new ArrayList<>();
|
||||||
@@ -80,4 +122,74 @@ public class TestController {
|
|||||||
return ApiResp.respOK(uploadPath.getAbsolutePath());
|
return ApiResp.respOK(uploadPath.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping("searchIP")
|
||||||
|
@TokenIgnore
|
||||||
|
public ApiResp<String> searchIp() {
|
||||||
|
String search = ip2regionConfig.search("127.0.0.1");
|
||||||
|
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
|
||||||
|
public ApiResp<String> passwd() {
|
||||||
|
|
||||||
|
String passwdCreate = encryptConfig.passwdCreate("12345Zeng!", "");
|
||||||
|
LogFactory.get().info(passwdCreate);
|
||||||
|
encryptConfig.passwdVerify("12345Zeng!", passwdCreate);
|
||||||
|
|
||||||
|
return ApiResp.respOK("");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping("poi")
|
||||||
|
@TokenIgnore
|
||||||
|
public ApiResp<String> poi() {
|
||||||
|
TimeInterval timeInterval = new TimeInterval();
|
||||||
|
|
||||||
|
FileUploadPath file = FileUploadPath.file("/upload/test.xlsx");
|
||||||
|
|
||||||
|
EasyExcel.read(new File(file.getAbsolutePath()), PoiBean.class, new ReadListener<PoiBean>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invoke(PoiBean poiBean, AnalysisContext analysisContext) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}).sheet().doRead();
|
||||||
|
|
||||||
|
System.out.println("timeInterval: " + timeInterval.interval());
|
||||||
|
return ApiResp.respOK("");
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("poiTool")
|
||||||
|
@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("");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package com.tiesheng.demo.pojos;
|
||||||
|
|
||||||
|
import com.alibaba.excel.annotation.ExcelProperty;
|
||||||
|
|
||||||
|
public class PoiBean {
|
||||||
|
|
||||||
|
@ExcelProperty("学院")
|
||||||
|
private String college;
|
||||||
|
private String type;
|
||||||
|
private String name;
|
||||||
|
private String no;
|
||||||
|
private String sex;
|
||||||
|
private String fdy;
|
||||||
|
private String fdyNo;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// setter\getter
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public String getCollege() {
|
||||||
|
return college;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCollege(String college) {
|
||||||
|
this.college = college;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNo() {
|
||||||
|
return no;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNo(String no) {
|
||||||
|
this.no = no;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSex() {
|
||||||
|
return sex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSex(String sex) {
|
||||||
|
this.sex = sex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFdy() {
|
||||||
|
return fdy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFdy(String fdy) {
|
||||||
|
this.fdy = fdy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFdyNo() {
|
||||||
|
return fdyNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFdyNo(String fdyNo) {
|
||||||
|
this.fdyNo = fdyNo;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,27 +1,21 @@
|
|||||||
//package com.tiesheng.demo.pojos;
|
package com.tiesheng.demo.pojos;
|
||||||
//
|
|
||||||
//import com.alibaba.excel.annotation.ExcelProperty;
|
import com.tiesheng.poi.pojos.PoiWriteBase;
|
||||||
//import com.tiesheng.poi.pojos.PoiWriteBase;
|
|
||||||
//
|
|
||||||
//public class TestFile implements PoiWriteBase {
|
public class TestFile extends TestParent implements PoiWriteBase {
|
||||||
//
|
|
||||||
//
|
private String name;
|
||||||
// @ExcelProperty("测试")
|
|
||||||
// private String test;
|
public TestFile(String name) {
|
||||||
//
|
this.name = name;
|
||||||
// public TestFile(String test) {
|
}
|
||||||
// this.test = test;
|
|
||||||
// }
|
public String getName() {
|
||||||
//
|
return name;
|
||||||
// ///////////////////////////////////////////////////////////////////////////
|
}
|
||||||
// // setter、getter
|
|
||||||
// ///////////////////////////////////////////////////////////////////////////
|
public void setName(String name) {
|
||||||
//
|
this.name = name;
|
||||||
// public String getTest() {
|
}
|
||||||
// return test;
|
}
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void setTest(String test) {
|
|
||||||
// this.test = test;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,12 +16,12 @@ platform:
|
|||||||
|
|
||||||
tiesheng:
|
tiesheng:
|
||||||
token:
|
token:
|
||||||
ignores:
|
test-map:
|
||||||
"1111":
|
"1111":
|
||||||
id: "1111"
|
id: "1111"
|
||||||
global:
|
global:
|
||||||
version: 2
|
version: 2
|
||||||
host: http://localhost:8080
|
host: http://localhost:8100
|
||||||
aliyun:
|
aliyun:
|
||||||
access-key-id: LTAI5tJtbgBCnTY5eS4SmrTf
|
access-key-id: LTAI5tJtbgBCnTY5eS4SmrTf
|
||||||
access-key-secret: JIHqpRUFffCHhXaJEVvWN31WcexWqG
|
access-key-secret: JIHqpRUFffCHhXaJEVvWN31WcexWqG
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
server:
|
server:
|
||||||
compression:
|
compression:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
port: 8100
|
||||||
|
|
||||||
## Spring配置
|
## Spring配置
|
||||||
spring:
|
spring:
|
||||||
@@ -19,3 +20,7 @@ spring:
|
|||||||
logging:
|
logging:
|
||||||
file:
|
file:
|
||||||
name: runtime/logs/tiesheng.log
|
name: runtime/logs/tiesheng.log
|
||||||
|
tiesheng:
|
||||||
|
token:
|
||||||
|
ignore-paths:
|
||||||
|
- /test/index
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<meta content="IE=edge" http-equiv="X-UA-Compatible"/>
|
||||||
|
<meta
|
||||||
|
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
|
||||||
|
name="viewport"
|
||||||
|
/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<meta content="IE=edge" http-equiv="X-UA-Compatible"/>
|
||||||
|
<meta
|
||||||
|
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
|
||||||
|
name="viewport"
|
||||||
|
/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8"/>
|
|
||||||
<meta content="IE=edge" http-equiv="X-UA-Compatible"/>
|
|
||||||
<meta
|
|
||||||
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
|
|
||||||
name="viewport"
|
|
||||||
/>
|
|
||||||
<title>钉钉授权</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<script src="dingtalk.open.js"></script>
|
|
||||||
<script type="text/javascript">
|
|
||||||
|
|
||||||
function getQueryString(name) {
|
|
||||||
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
|
|
||||||
var r = window.location.search.substr(1).match(reg);
|
|
||||||
if (r != null) return decodeURI(r[2]);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
dd.runtime.permission.requestAuthCode({
|
|
||||||
corpId: getQueryString("corpId"),
|
|
||||||
onSuccess: function (result) {
|
|
||||||
let search = window.location.search + "&code=" + result.code;
|
|
||||||
window.location.href = "/auth/ding/oauth2/" + getQueryString("service") + search;
|
|
||||||
},
|
|
||||||
onFail: function (err) {
|
|
||||||
window.location.href = "./error.html?message=" + JSON.stringify(err);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8"/>
|
|
||||||
<meta content="IE=edge" http-equiv="X-UA-Compatible"/>
|
|
||||||
<meta
|
|
||||||
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
|
|
||||||
name="viewport"
|
|
||||||
/>
|
|
||||||
<title>钉钉授权</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<script src="dingtalk.open.js"></script>
|
|
||||||
<script type="text/javascript">
|
|
||||||
|
|
||||||
function getQueryString(name) {
|
|
||||||
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
|
|
||||||
var r = window.location.search.substr(1).match(reg);
|
|
||||||
if (r != null) return decodeURI(r[2]);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
dd.runtime.permission.requestAuthCode({
|
|
||||||
corpId: getQueryString("corpId"),
|
|
||||||
onSuccess: function (result) {
|
|
||||||
let search = window.location.search + "&code=" + result.code;
|
|
||||||
window.location.href = "/auth/ding/oauth2/" + getQueryString("service") + search;
|
|
||||||
},
|
|
||||||
onFail: function (err) {
|
|
||||||
window.location.href = "./error.html?message=" + JSON.stringify(err);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-annotation</artifactId>
|
<artifactId>springboot-annotation</artifactId>
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.tiesheng.annotation.encrypt;
|
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author hao
|
|
||||||
*/
|
|
||||||
@Target({ElementType.TYPE})
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Documented
|
|
||||||
public @interface EncryptedRespBody {
|
|
||||||
}
|
|
||||||
@@ -6,10 +6,10 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-db-migration</artifactId>
|
<artifactId>springboot-database</artifactId>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.tiesheng.database;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
@ComponentScan({
|
||||||
|
"com.tiesheng.database.**.*"
|
||||||
|
})
|
||||||
|
public class DatabaseAutoConfigurer {
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package com.tiesheng.database.config;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.util.RuntimeUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
|
import cn.hutool.log.LogFactory;
|
||||||
|
import com.tiesheng.database.utls.TieshengDbUtil;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "tiesheng.db-backup")
|
||||||
|
public class DbBackupConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库备份的路径
|
||||||
|
*/
|
||||||
|
private String path = "/root/backup/";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备份文件的时间格式
|
||||||
|
*/
|
||||||
|
private String format = "yyyyMMdd";
|
||||||
|
|
||||||
|
|
||||||
|
public void dbBackup() {
|
||||||
|
String url = SpringUtil.getProperty("spring.datasource.url");
|
||||||
|
String username = SpringUtil.getProperty("spring.datasource.username");
|
||||||
|
String password = SpringUtil.getProperty("spring.datasource.password");
|
||||||
|
String dbName = TieshengDbUtil.getTableSchema(url);
|
||||||
|
|
||||||
|
try {
|
||||||
|
String saveFile = StrUtil.format("{}{}/{}.sql", getPath(), dbName, DateUtil.format(new Date(), format));
|
||||||
|
FileUtil.mkParentDirs(saveFile);
|
||||||
|
String cmd = StrUtil.format("mysqldump -u{} -p {} > {}", username, dbName, saveFile);
|
||||||
|
LogFactory.get().info("cmd: " + cmd);
|
||||||
|
String forStr = RuntimeUtil.execForStr(cmd);
|
||||||
|
LogFactory.get().info("dbBackup: " + forStr);
|
||||||
|
forStr = RuntimeUtil.execForStr(password);
|
||||||
|
LogFactory.get().info("dbBackup: " + forStr);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// setter\getter
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public String getPath() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPath(String path) {
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFormat() {
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFormat(String format) {
|
||||||
|
this.format = format;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.tiesheng.migration.config;
|
package com.tiesheng.database.config;
|
||||||
|
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.tiesheng.database.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public interface DbDataInitializer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化数据
|
||||||
|
*/
|
||||||
|
void init();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
package com.tiesheng.migration.service;
|
package com.tiesheng.database.service;
|
||||||
|
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.lang.func.VoidFunc1;
|
import cn.hutool.core.lang.func.VoidFunc1;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.db.Db;
|
import cn.hutool.db.Db;
|
||||||
import cn.hutool.db.Entity;
|
import cn.hutool.db.Entity;
|
||||||
import com.tiesheng.migration.config.DbMigrationConfig;
|
import cn.hutool.log.LogFactory;
|
||||||
|
import com.tiesheng.database.config.DbMigrationConfig;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.web.servlet.ServletContextInitializer;
|
import org.springframework.boot.web.servlet.ServletContextInitializer;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
@@ -20,7 +20,10 @@ import javax.servlet.ServletContext;
|
|||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.zip.Checksum;
|
import java.util.zip.Checksum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,12 +38,17 @@ public class DbMigrationInitializer implements ServletContextInitializer {
|
|||||||
DataSource dataSource;
|
DataSource dataSource;
|
||||||
@Autowired
|
@Autowired
|
||||||
DbMigrationConfig dbMigrationConfig;
|
DbMigrationConfig dbMigrationConfig;
|
||||||
|
@Autowired(required = false)
|
||||||
|
List<DbDataInitializer> dbDataInitializerList;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStartup(ServletContext servletContext) {
|
public void onStartup(ServletContext servletContext) {
|
||||||
try {
|
try {
|
||||||
startDeal();
|
startDeal();
|
||||||
|
if (dbDataInitializerList != null) {
|
||||||
|
dbDataInitializerList.forEach(DbDataInitializer::init);
|
||||||
|
}
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,14 +64,16 @@ public class DbMigrationInitializer implements ServletContextInitializer {
|
|||||||
dbMigrationConfig.checkDbExists(coreDb);
|
dbMigrationConfig.checkDbExists(coreDb);
|
||||||
|
|
||||||
PathMatchingResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
|
PathMatchingResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
|
||||||
|
List<Resource> resourceList = new ArrayList<>();
|
||||||
for (String location : dbMigrationConfig.getLocations()) {
|
for (String location : dbMigrationConfig.getLocations()) {
|
||||||
Resource[] resources = patternResolver.getResources(location);
|
Resource[] resources = patternResolver.getResources(location);
|
||||||
if (ArrayUtil.isEmpty(resources)) {
|
resourceList.addAll(Arrays.asList(resources));
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
for (Resource resource : resources) {
|
// 排序后执行sql
|
||||||
migrationByResource(resource, coreDb);
|
resourceList.sort((o1, o2) -> StrUtil.compare(o1.getFilename(), o2.getFilename(), true));
|
||||||
}
|
for (Resource resource : resourceList) {
|
||||||
|
migrationByResource(resource, coreDb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,6 +94,8 @@ public class DbMigrationInitializer implements ServletContextInitializer {
|
|||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
AtomicReference<Integer> success= new AtomicReference<>(0);
|
||||||
|
AtomicReference<Integer> fail= new AtomicReference<>(0);
|
||||||
db.tx((VoidFunc1<Db>) parameter -> {
|
db.tx((VoidFunc1<Db>) parameter -> {
|
||||||
List<String> split = StrUtil.split(readUtf8, ";");
|
List<String> split = StrUtil.split(readUtf8, ";");
|
||||||
for (String sql : split) {
|
for (String sql : split) {
|
||||||
@@ -96,11 +108,13 @@ public class DbMigrationInitializer implements ServletContextInitializer {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
parameter.execute(sql);
|
parameter.execute(sql);
|
||||||
|
success.getAndSet(success.get() + 1);
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
|
fail.getAndSet(fail.get() + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
LogFactory.get().info("执行sql文件{},成功数:{},失败数:{}。",filename,success.get(),fail.get());
|
||||||
entity.set("checksum", checksum.getValue());
|
entity.set("checksum", checksum.getValue());
|
||||||
entity.set("update_time", DateUtil.date());
|
entity.set("update_time", DateUtil.date());
|
||||||
db.update(entity, Entity.create(dbMigrationConfig.getTable()).set("id", entity.get("id")));
|
db.update(entity, Entity.create(dbMigrationConfig.getTable()).set("id", entity.get("id")));
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.tiesheng.database.utls;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
|
public class TieshengDbUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过url获取table_schema
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getTableSchema(String url) {
|
||||||
|
return StrUtil.sub(url, url.lastIndexOf('/') + 1, StrUtil.indexOf(url, '?'));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.tiesheng.migration;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author hao
|
|
||||||
*/
|
|
||||||
@ComponentScan({
|
|
||||||
"com.tiesheng.migration.**.*"
|
|
||||||
})
|
|
||||||
public class MigrationAutoConfigurer {
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-encrypt</artifactId>
|
<artifactId>springboot-encrypt</artifactId>
|
||||||
@@ -18,11 +18,6 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>org.bouncycastle</groupId>
|
|
||||||
<artifactId>bcprov-jdk15to18</artifactId>
|
|
||||||
<version>1.68</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
package com.tiesheng.encrypt;
|
package com.tiesheng.encrypt;
|
||||||
|
|
||||||
|
|
||||||
import com.tiesheng.encrypt.config.EncryptConfig;
|
import com.tiesheng.encrypt.config.DecryptRequestBodyAdvice;
|
||||||
import com.tiesheng.encrypt.config.EncryptRequestBodyAdvice;
|
|
||||||
import com.tiesheng.encrypt.config.EncryptResponseBodyAdvice;
|
import com.tiesheng.encrypt.config.EncryptResponseBodyAdvice;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hao
|
* @author hao
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@ComponentScan(basePackageClasses = {
|
@Target({ElementType.TYPE})
|
||||||
EncryptConfig.class,
|
@Documented
|
||||||
EncryptRequestBodyAdvice.class,
|
@Import({
|
||||||
|
DecryptRequestBodyAdvice.class,
|
||||||
EncryptResponseBodyAdvice.class,
|
EncryptResponseBodyAdvice.class,
|
||||||
})
|
})
|
||||||
public class EnableEncryptConfig {
|
public @interface EnableEncryptConfig {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,8 @@ package com.tiesheng.encrypt.config;
|
|||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.util.CharsetUtil;
|
import cn.hutool.core.util.CharsetUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.crypto.ECKeyUtil;
|
|
||||||
import cn.hutool.crypto.SmUtil;
|
|
||||||
import cn.hutool.crypto.asymmetric.KeyType;
|
|
||||||
import cn.hutool.crypto.asymmetric.SM2;
|
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
|
import com.tiesheng.util.config.EncryptConfig;
|
||||||
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
@@ -26,7 +21,7 @@ import java.nio.charset.Charset;
|
|||||||
* @author hao
|
* @author hao
|
||||||
*/
|
*/
|
||||||
@ControllerAdvice
|
@ControllerAdvice
|
||||||
public class EncryptRequestBodyAdvice implements RequestBodyAdvice {
|
public class DecryptRequestBodyAdvice implements RequestBodyAdvice {
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -42,12 +37,8 @@ public class EncryptRequestBodyAdvice implements RequestBodyAdvice {
|
|||||||
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
|
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
|
||||||
Class<? extends HttpMessageConverter<?>> converterType) {
|
Class<? extends HttpMessageConverter<?>> converterType) {
|
||||||
|
|
||||||
if (!encryptConfig.isEnable()) {
|
|
||||||
return inputMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new DecryptHttpInputMessage(inputMessage, encryptConfig.getPrivateQ());
|
return new DecryptHttpInputMessage(inputMessage, encryptConfig);
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,16 +63,12 @@ public class EncryptRequestBodyAdvice implements RequestBodyAdvice {
|
|||||||
private HttpHeaders headers;
|
private HttpHeaders headers;
|
||||||
private InputStream body;
|
private InputStream body;
|
||||||
|
|
||||||
DecryptHttpInputMessage(HttpInputMessage inputMessage, String privateQ) throws Exception {
|
DecryptHttpInputMessage(HttpInputMessage inputMessage, EncryptConfig encryptConfig) throws Exception {
|
||||||
this.headers = inputMessage.getHeaders();
|
this.headers = inputMessage.getHeaders();
|
||||||
String bodyStr = IoUtil.read(inputMessage.getBody(), CharsetUtil.CHARSET_UTF_8);
|
String bodyStr = IoUtil.read(inputMessage.getBody(), CharsetUtil.CHARSET_UTF_8);
|
||||||
String encryptData = JSONUtil.parseObj(bodyStr).getStr("encryptData");
|
String encryptData = JSONUtil.parseObj(bodyStr).getStr("encryptData");
|
||||||
if (!StrUtil.isEmpty(encryptData)) {
|
if (!StrUtil.isEmpty(encryptData)) {
|
||||||
// 部分语言加密之后缺少04前缀,如果解密失败,可尝试增加04
|
String decrypt = encryptConfig.decrypt(encryptData);
|
||||||
ECPrivateKeyParameters privateKeyParameters = ECKeyUtil.toSm2PrivateParams(privateQ);
|
|
||||||
ECPublicKeyParameters publicKeyParameters = ECKeyUtil.getPublicParams(privateKeyParameters);
|
|
||||||
SM2 sm2 = SmUtil.sm2(privateKeyParameters, publicKeyParameters);
|
|
||||||
String decrypt = sm2.decryptStr(encryptData, KeyType.PrivateKey);
|
|
||||||
this.body = IoUtil.toStream(decrypt, Charset.defaultCharset());
|
this.body = IoUtil.toStream(decrypt, Charset.defaultCharset());
|
||||||
} else {
|
} else {
|
||||||
this.body = IoUtil.toStream(bodyStr, Charset.defaultCharset());
|
this.body = IoUtil.toStream(bodyStr, Charset.defaultCharset());
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
package com.tiesheng.encrypt.config;
|
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author hao
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
@ConfigurationProperties(prefix = "tiesheng.encrypt")
|
|
||||||
public class EncryptConfig {
|
|
||||||
|
|
||||||
public String publicD;
|
|
||||||
public String privateQ;
|
|
||||||
private boolean enable = false;
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
// setter\getter
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
public boolean isEnable() {
|
|
||||||
return enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnable(boolean enable) {
|
|
||||||
this.enable = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPublicD() {
|
|
||||||
return publicD;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPublicD(String publicD) {
|
|
||||||
this.publicD = publicD;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPrivateQ() {
|
|
||||||
return privateQ;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPrivateQ(String privateQ) {
|
|
||||||
this.privateQ = privateQ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +1,10 @@
|
|||||||
package com.tiesheng.encrypt.config;
|
package com.tiesheng.encrypt.config;
|
||||||
|
|
||||||
import cn.hutool.core.annotation.AnnotationUtil;
|
import cn.hutool.core.annotation.AnnotationUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import cn.hutool.crypto.ECKeyUtil;
|
|
||||||
import cn.hutool.crypto.SmUtil;
|
|
||||||
import cn.hutool.crypto.asymmetric.KeyType;
|
|
||||||
import cn.hutool.crypto.asymmetric.SM2;
|
|
||||||
import cn.hutool.json.JSONObject;
|
|
||||||
import cn.hutool.json.JSONUtil;
|
|
||||||
import cn.hutool.log.LogFactory;
|
import cn.hutool.log.LogFactory;
|
||||||
import com.tiesheng.annotation.encrypt.EncryptedRespBody;
|
import com.tiesheng.util.CommonUtil;
|
||||||
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
|
import com.tiesheng.util.config.EncryptConfig;
|
||||||
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
|
import com.tiesheng.util.pojos.ApiResp;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
@@ -19,6 +12,7 @@ import org.springframework.http.converter.HttpMessageConverter;
|
|||||||
import org.springframework.http.server.ServerHttpRequest;
|
import org.springframework.http.server.ServerHttpRequest;
|
||||||
import org.springframework.http.server.ServerHttpResponse;
|
import org.springframework.http.server.ServerHttpResponse;
|
||||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
|
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
|
||||||
|
|
||||||
|
|
||||||
@@ -26,50 +20,30 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
|
|||||||
* @author hao
|
* @author hao
|
||||||
*/
|
*/
|
||||||
@ControllerAdvice
|
@ControllerAdvice
|
||||||
public class EncryptResponseBodyAdvice implements ResponseBodyAdvice<Object> {
|
public class EncryptResponseBodyAdvice implements ResponseBodyAdvice<ApiResp> {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
EncryptConfig encryptConfig;
|
EncryptConfig encryptConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
|
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
|
||||||
return true;
|
return AnnotationUtil.getAnnotation(returnType.getContainingClass(), RestController.class) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends
|
public ApiResp beforeBodyWrite(ApiResp body, MethodParameter returnType, MediaType selectedContentType, Class<? extends
|
||||||
HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
|
HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
|
||||||
|
|
||||||
if (!encryptConfig.isEnable()) {
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean encrypt = AnnotationUtil.getAnnotation(returnType.getContainingClass(), EncryptedRespBody.class) != null;
|
|
||||||
if (!encrypt) {
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String content = JSONUtil.toJsonStr(body);
|
Object data = body.getData();
|
||||||
String respData = JSONUtil.parseObj(content).getStr("data");
|
if (data == null || !body.successful()) {
|
||||||
|
|
||||||
if (StrUtil.isEmpty(respData)) {
|
|
||||||
// 无需加密
|
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONObject resp = JSONUtil.parseObj(content);
|
body.setEncrypt(true);
|
||||||
resp.set("encrypted", true);
|
body.setData(encryptConfig.encrypt(CommonUtil.writeJsonString(data)));
|
||||||
if (resp.getInt("code") == 200) {
|
return body;
|
||||||
// 用公钥进行加密
|
|
||||||
ECPrivateKeyParameters privateKeyParameters = ECKeyUtil.toSm2PrivateParams(encryptConfig.getPrivateQ());
|
|
||||||
ECPublicKeyParameters publicKeyParameters = ECKeyUtil.getPublicParams(privateKeyParameters);
|
|
||||||
SM2 sm2 = SmUtil.sm2(privateKeyParameters, publicKeyParameters);
|
|
||||||
String decrypt = sm2.encryptHex(respData, KeyType.PublicKey);
|
|
||||||
resp.set("data", decrypt.substring(2));
|
|
||||||
}
|
|
||||||
return resp;
|
|
||||||
} catch (Exception var17) {
|
} catch (Exception var17) {
|
||||||
LogFactory.get().info("加密数据异常", var17);
|
LogFactory.get().info("加密数据异常", var17);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-login</artifactId>
|
<artifactId>springboot-login</artifactId>
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package com.tiesheng.login.config.token;
|
package com.tiesheng.login.config.token;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.tiesheng.annotation.token.TokenIgnore;
|
import com.tiesheng.annotation.token.TokenIgnore;
|
||||||
|
import com.tiesheng.util.ServletKit;
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Before;
|
import org.aspectj.lang.annotation.Before;
|
||||||
@@ -46,13 +49,28 @@ public class TsTokenAspect {
|
|||||||
@Before("methodArgs()")
|
@Before("methodArgs()")
|
||||||
public void before(JoinPoint joinPoint) {
|
public void before(JoinPoint joinPoint) {
|
||||||
|
|
||||||
|
// 过滤不要需要验证的接口(path)
|
||||||
|
String requestURI = ServletKit.getRequest().getRequestURI();
|
||||||
|
String[] ignorePaths = tsTokenConfig.getIgnorePaths();
|
||||||
|
if (ObjUtil.isNotEmpty(ignorePaths)) {
|
||||||
|
for (String path : ignorePaths) {
|
||||||
|
if (path.contains("/**") &&
|
||||||
|
StrUtil.startWith(requestURI, path.replace("/**", ""))) {
|
||||||
|
// 通配路径
|
||||||
|
return;
|
||||||
|
} else if (requestURI.equals(path)) {
|
||||||
|
// 完整路径
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 过滤不要需要验证的接口(注解)
|
||||||
Object aThis = joinPoint.getTarget();
|
Object aThis = joinPoint.getTarget();
|
||||||
TokenIgnore annotation = aThis.getClass().getAnnotation(TokenIgnore.class);
|
TokenIgnore annotation = aThis.getClass().getAnnotation(TokenIgnore.class);
|
||||||
if (annotation != null) {
|
if (annotation != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 过滤不要需要验证的接口
|
|
||||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||||
Method method = signature.getMethod();
|
Method method = signature.getMethod();
|
||||||
TokenIgnore apiTokenIgnore = method.getAnnotation(TokenIgnore.class);
|
TokenIgnore apiTokenIgnore = method.getAnnotation(TokenIgnore.class);
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.tiesheng.login.config.token;
|
package com.tiesheng.login.config.token;
|
||||||
|
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.extra.servlet.ServletUtil;
|
import cn.hutool.extra.servlet.ServletUtil;
|
||||||
@@ -24,9 +23,10 @@ import java.util.Map;
|
|||||||
@ConfigurationProperties("tiesheng.token")
|
@ConfigurationProperties("tiesheng.token")
|
||||||
public class TsTokenConfig {
|
public class TsTokenConfig {
|
||||||
|
|
||||||
private Map<String, TokenBean> ignores = MapUtil.newHashMap();
|
private Map<String, TokenBean> testMap = MapUtil.newHashMap();
|
||||||
private String encryptKey = "%kIp9frQCu";
|
private String encryptKey = "%kIp9frQCu";
|
||||||
private Integer expireHours = 48;
|
private Integer expireHours = 48;
|
||||||
|
private String[] ignorePaths;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,11 +57,11 @@ public class TsTokenConfig {
|
|||||||
* @param token
|
* @param token
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public TokenBean isIgnored(String token) {
|
public TokenBean isTestToken(String token) {
|
||||||
if (ignores == null) {
|
if (testMap == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return ignores.get(token);
|
return testMap.get(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ public class TsTokenConfig {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public TokenBean validToken(String token, boolean thrExp) {
|
public TokenBean validToken(String token, boolean thrExp) {
|
||||||
TokenBean tokenBean = isIgnored(token);
|
TokenBean tokenBean = isTestToken(token);
|
||||||
if (tokenBean != null) {
|
if (tokenBean != null) {
|
||||||
return tokenBean;
|
return tokenBean;
|
||||||
}
|
}
|
||||||
@@ -101,7 +101,8 @@ public class TsTokenConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tokenBean == null && thrExp) {
|
if (tokenBean == null && thrExp) {
|
||||||
throw new ApiException(StrUtil.isEmpty(token) ? "请先登录" : "登录过期,请重新登陆");
|
throw new ApiException(StrUtil.isEmpty(token) ? 110 : 112,
|
||||||
|
StrUtil.isEmpty(token) ? "请先登录" : "登录过期,请重新登陆");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tokenBean == null) {
|
if (tokenBean == null) {
|
||||||
@@ -116,12 +117,12 @@ public class TsTokenConfig {
|
|||||||
// setter\getter
|
// setter\getter
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
public Map<String, TokenBean> getIgnores() {
|
public Map<String, TokenBean> getTestMap() {
|
||||||
return ignores;
|
return testMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIgnores(Map<String, TokenBean> ignores) {
|
public void setTestMap(Map<String, TokenBean> testMap) {
|
||||||
this.ignores = ignores;
|
this.testMap = testMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEncryptKey() {
|
public String getEncryptKey() {
|
||||||
@@ -139,4 +140,12 @@ public class TsTokenConfig {
|
|||||||
public void setExpireHours(Integer expireHours) {
|
public void setExpireHours(Integer expireHours) {
|
||||||
this.expireHours = expireHours;
|
this.expireHours = expireHours;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String[] getIgnorePaths() {
|
||||||
|
return ignorePaths;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIgnorePaths(String[] ignorePaths) {
|
||||||
|
this.ignorePaths = ignorePaths;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,94 +0,0 @@
|
|||||||
package com.tiesheng.login.config.zust;
|
|
||||||
|
|
||||||
public class CasLoginDTO {
|
|
||||||
|
|
||||||
private String data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 工号
|
|
||||||
*/
|
|
||||||
private String casUser;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户容器
|
|
||||||
*/
|
|
||||||
private String casUserContainerId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户姓名
|
|
||||||
*/
|
|
||||||
private String casUserCn;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户别名
|
|
||||||
*/
|
|
||||||
private String casUserAlias;
|
|
||||||
/**
|
|
||||||
* 用户所在组
|
|
||||||
*/
|
|
||||||
private String casUserMemberOf;
|
|
||||||
/**
|
|
||||||
* 用户性别
|
|
||||||
*/
|
|
||||||
private String casUserGender;
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
// setter\getter
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
public String getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setData(String data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCasUser() {
|
|
||||||
return casUser;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCasUser(String casUser) {
|
|
||||||
this.casUser = casUser;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCasUserContainerId() {
|
|
||||||
return casUserContainerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCasUserContainerId(String casUserContainerId) {
|
|
||||||
this.casUserContainerId = casUserContainerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCasUserCn() {
|
|
||||||
return casUserCn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCasUserCn(String casUserCn) {
|
|
||||||
this.casUserCn = casUserCn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCasUserAlias() {
|
|
||||||
return casUserAlias;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCasUserAlias(String casUserAlias) {
|
|
||||||
this.casUserAlias = casUserAlias;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCasUserMemberOf() {
|
|
||||||
return casUserMemberOf;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCasUserMemberOf(String casUserMemberOf) {
|
|
||||||
this.casUserMemberOf = casUserMemberOf;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCasUserGender() {
|
|
||||||
return casUserGender;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCasUserGender(String casUserGender) {
|
|
||||||
this.casUserGender = casUserGender;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,11 +9,14 @@ import com.tiesheng.login.config.token.bean.TokenBean;
|
|||||||
import com.tiesheng.login.pojos.CodeExtraDTO;
|
import com.tiesheng.login.pojos.CodeExtraDTO;
|
||||||
import com.tiesheng.login.pojos.DoLoginInfo;
|
import com.tiesheng.login.pojos.DoLoginInfo;
|
||||||
import com.tiesheng.login.pojos.UniqueIndexDTO;
|
import com.tiesheng.login.pojos.UniqueIndexDTO;
|
||||||
|
import com.tiesheng.login.pojos.WxminiLoginVo;
|
||||||
import com.tiesheng.login.service.TieshengLoginConfigurer;
|
import com.tiesheng.login.service.TieshengLoginConfigurer;
|
||||||
import com.tiesheng.platform.config.ding.PlatformDingConfig;
|
import com.tiesheng.platform.config.ding.PlatformDingConfig;
|
||||||
import com.tiesheng.platform.config.ding.bean.DingJsapiSignature;
|
import com.tiesheng.platform.config.ding.bean.DingJsapiSignature;
|
||||||
import com.tiesheng.platform.config.ding.bean.DingUserInfo;
|
import com.tiesheng.platform.config.ding.bean.DingUserInfo;
|
||||||
|
import com.tiesheng.platform.config.wxmini.PlatformWxminiConfig;
|
||||||
import com.tiesheng.platform.config.wxmp.PlatformWxmpConfig;
|
import com.tiesheng.platform.config.wxmp.PlatformWxmpConfig;
|
||||||
|
import com.tiesheng.platform.config.wxmp.bean.WxConfigBean;
|
||||||
import com.tiesheng.platform.config.wxmp.bean.WxJsapiSignature;
|
import com.tiesheng.platform.config.wxmp.bean.WxJsapiSignature;
|
||||||
import com.tiesheng.platform.config.wxmp.bean.WxUserInfo;
|
import com.tiesheng.platform.config.wxmp.bean.WxUserInfo;
|
||||||
import com.tiesheng.util.config.GlobalConfig;
|
import com.tiesheng.util.config.GlobalConfig;
|
||||||
@@ -32,6 +35,7 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/login")
|
@RequestMapping("/login")
|
||||||
|
@TokenIgnore
|
||||||
public class LoginController {
|
public class LoginController {
|
||||||
|
|
||||||
|
|
||||||
@@ -40,6 +44,8 @@ public class LoginController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
PlatformDingConfig platformDingConfig;
|
PlatformDingConfig platformDingConfig;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
PlatformWxminiConfig platformWxminiConfig;
|
||||||
|
@Autowired
|
||||||
TieshengLoginConfigurer tieshengLoginConfigurer;
|
TieshengLoginConfigurer tieshengLoginConfigurer;
|
||||||
@Autowired
|
@Autowired
|
||||||
GlobalConfig globalConfig;
|
GlobalConfig globalConfig;
|
||||||
@@ -51,10 +57,9 @@ public class LoginController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping("/unique/redirect")
|
@GetMapping("/unique/redirect")
|
||||||
@TokenIgnore
|
|
||||||
public void uniqueIndex(UniqueIndexDTO dto, HttpServletResponse response) {
|
public void uniqueIndex(UniqueIndexDTO dto, HttpServletResponse response) {
|
||||||
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo("unique_index_web",
|
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo("web_unique_redirect",
|
||||||
dto.getNo(), "web", dto.getTo(), dto.getInfo()));
|
dto.getNo(), dto.getPlatform(), dto.getInfo()));
|
||||||
tieshengLoginConfigurer.onLoginRedirect(tokenBean, dto.getTo(), dto.getExtra(), response);
|
tieshengLoginConfigurer.onLoginRedirect(tokenBean, dto.getTo(), dto.getExtra(), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,10 +71,9 @@ public class LoginController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@PostMapping("/unique/index")
|
@PostMapping("/unique/index")
|
||||||
@TokenIgnore
|
|
||||||
public ApiResp<String> uniqueIndex(@RequestBody UniqueIndexDTO dto) {
|
public ApiResp<String> uniqueIndex(@RequestBody UniqueIndexDTO dto) {
|
||||||
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo("unique_index_web",
|
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo("web_unique_index",
|
||||||
dto.getNo(), "web", dto.getTo(), dto.getInfo()));
|
dto.getNo(), dto.getPlatform(), dto.getInfo()));
|
||||||
if (tokenBean == null) {
|
if (tokenBean == null) {
|
||||||
throw new ApiException("登录失败");
|
throw new ApiException("登录失败");
|
||||||
}
|
}
|
||||||
@@ -89,7 +93,6 @@ public class LoginController {
|
|||||||
* @param response
|
* @param response
|
||||||
*/
|
*/
|
||||||
@GetMapping("/ding/index/{service}")
|
@GetMapping("/ding/index/{service}")
|
||||||
@TokenIgnore
|
|
||||||
public void dingIndex(@PathVariable String service, String extra, HttpServletResponse response) {
|
public void dingIndex(@PathVariable String service, String extra, HttpServletResponse response) {
|
||||||
if (StrUtil.isEmpty(extra)) {
|
if (StrUtil.isEmpty(extra)) {
|
||||||
extra = "";
|
extra = "";
|
||||||
@@ -113,13 +116,11 @@ public class LoginController {
|
|||||||
* @param service
|
* @param service
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/ding/oauth2/{service}")
|
@RequestMapping("/ding/oauth2/{service}")
|
||||||
@TokenIgnore
|
|
||||||
public void dingOauth2(@PathVariable String service, CodeExtraDTO dto, HttpServletResponse response) {
|
public void dingOauth2(@PathVariable String service, CodeExtraDTO dto, HttpServletResponse response) {
|
||||||
String ddUserId = platformDingConfig.getUserIdByCode(service, dto.getCode());
|
String ddUserId = platformDingConfig.getUserIdByCode(service, dto.getCode());
|
||||||
DingUserInfo dingUserInfo = platformDingConfig.topapiV2UserGet(service, ddUserId);
|
DingUserInfo dingUserInfo = platformDingConfig.topapiV2UserGet(service, ddUserId);
|
||||||
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo(dingUserInfo.getAppId(),
|
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo(dingUserInfo.getAppId(),
|
||||||
dingUserInfo.getUserid(), "ding", dto.getTo(),
|
dingUserInfo.getUserid(), "ding", JSON.toJSONString(dingUserInfo)));
|
||||||
JSON.toJSONString(dingUserInfo)));
|
|
||||||
tieshengLoginConfigurer.onLoginRedirect(tokenBean, dto.getTo(), dto.getExtra(), response);
|
tieshengLoginConfigurer.onLoginRedirect(tokenBean, dto.getTo(), dto.getExtra(), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +132,6 @@ public class LoginController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping("/ding/jssdk/{service}")
|
@GetMapping("/ding/jssdk/{service}")
|
||||||
@TokenIgnore
|
|
||||||
public ApiResp<DingJsapiSignature> dingJssdk(@PathVariable String service, String url) {
|
public ApiResp<DingJsapiSignature> dingJssdk(@PathVariable String service, String url) {
|
||||||
DingJsapiSignature jsapiSignature = platformDingConfig.createJsapiSignature(service, url);
|
DingJsapiSignature jsapiSignature = platformDingConfig.createJsapiSignature(service, url);
|
||||||
return ApiResp.respOK(jsapiSignature);
|
return ApiResp.respOK(jsapiSignature);
|
||||||
@@ -149,7 +149,6 @@ public class LoginController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/wxmp/index/{service}")
|
@RequestMapping("/wxmp/index/{service}")
|
||||||
@TokenIgnore
|
|
||||||
public void wxmpIndex(@PathVariable String service, String extra, HttpServletResponse response) throws IOException {
|
public void wxmpIndex(@PathVariable String service, String extra, HttpServletResponse response) throws IOException {
|
||||||
if (StrUtil.isEmpty(extra)) {
|
if (StrUtil.isEmpty(extra)) {
|
||||||
extra = "";
|
extra = "";
|
||||||
@@ -164,11 +163,10 @@ public class LoginController {
|
|||||||
* 微信授权回调
|
* 微信授权回调
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/wxmp/oauth2/{service}")
|
@RequestMapping("/wxmp/oauth2/{service}")
|
||||||
@TokenIgnore
|
|
||||||
public void wxmpOauth2(@PathVariable String service, CodeExtraDTO dto, HttpServletResponse response) {
|
public void wxmpOauth2(@PathVariable String service, CodeExtraDTO dto, HttpServletResponse response) {
|
||||||
WxUserInfo wxUserInfo = platformWxmpConfig.getOAuth2AccessToken(service, dto.getCode());
|
WxUserInfo wxUserInfo = platformWxmpConfig.getOAuth2AccessToken(service, dto.getCode());
|
||||||
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo(wxUserInfo.getAppId(),
|
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo(wxUserInfo.getAppId(),
|
||||||
wxUserInfo.getOpenid(), "wxmp", dto.getTo(), JSON.toJSONString(wxUserInfo)));
|
wxUserInfo.getOpenid(), "wxmp", JSON.toJSONString(wxUserInfo)));
|
||||||
tieshengLoginConfigurer.onLoginRedirect(tokenBean, dto.getTo(), dto.getExtra(), response);
|
tieshengLoginConfigurer.onLoginRedirect(tokenBean, dto.getTo(), dto.getExtra(), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,11 +178,34 @@ public class LoginController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping("/wxmp/jssdk/{service}")
|
@GetMapping("/wxmp/jssdk/{service}")
|
||||||
@TokenIgnore
|
|
||||||
public ApiResp<WxJsapiSignature> wxmpJssdk(@PathVariable String service, String url) {
|
public ApiResp<WxJsapiSignature> wxmpJssdk(@PathVariable String service, String url) {
|
||||||
WxJsapiSignature jsapiSignature = platformWxmpConfig.createJsapiSignature(service, url);
|
WxJsapiSignature jsapiSignature = platformWxmpConfig.createJsapiSignature(service, url);
|
||||||
return ApiResp.respOK(jsapiSignature);
|
return ApiResp.respOK(jsapiSignature);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// 小程序相关
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信小程序登录
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping("/wxmini/index/{service}")
|
||||||
|
public ApiResp<WxminiLoginVo> wxminiIndex(@PathVariable String service, String code) {
|
||||||
|
String openid = platformWxminiConfig.jscode2session(service, code);
|
||||||
|
WxConfigBean configBean = platformWxminiConfig.getConfigBean(service);
|
||||||
|
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo(configBean.getAppId(),
|
||||||
|
openid, "wxmini", "{}"));
|
||||||
|
|
||||||
|
WxminiLoginVo loginVo = new WxminiLoginVo();
|
||||||
|
loginVo.setOpenid(openid);
|
||||||
|
if (tokenBean != null) {
|
||||||
|
loginVo.setToken(tokenBean.toToken());
|
||||||
|
}
|
||||||
|
return ApiResp.respOK(loginVo);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,15 +5,13 @@ public class DoLoginInfo {
|
|||||||
private String appId;
|
private String appId;
|
||||||
private String unique;
|
private String unique;
|
||||||
private String platform;
|
private String platform;
|
||||||
private String to;
|
|
||||||
private String info;
|
private String info;
|
||||||
private String extra;
|
private String extra;
|
||||||
|
|
||||||
public DoLoginInfo(String appId, String unique, String platform, String to, String info) {
|
public DoLoginInfo(String appId, String unique, String platform, String info) {
|
||||||
this.appId = appId;
|
this.appId = appId;
|
||||||
this.unique = unique;
|
this.unique = unique;
|
||||||
this.platform = platform;
|
this.platform = platform;
|
||||||
this.to = to;
|
|
||||||
this.info = info;
|
this.info = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,14 +43,6 @@ public class DoLoginInfo {
|
|||||||
this.platform = platform;
|
this.platform = platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTo() {
|
|
||||||
return to;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTo(String to) {
|
|
||||||
this.to = to;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getInfo() {
|
public String getInfo() {
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ public class UniqueIndexDTO extends LoginToInfo {
|
|||||||
private String no;
|
private String no;
|
||||||
private String extra;
|
private String extra;
|
||||||
private String info;
|
private String info;
|
||||||
|
private String platform = "web";
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// setter\getter
|
// setter\getter
|
||||||
@@ -38,4 +39,12 @@ public class UniqueIndexDTO extends LoginToInfo {
|
|||||||
public void setInfo(String info) {
|
public void setInfo(String info) {
|
||||||
this.info = info;
|
this.info = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPlatform() {
|
||||||
|
return platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlatform(String platform) {
|
||||||
|
this.platform = platform;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.tiesheng.login.pojos;
|
||||||
|
|
||||||
|
public class WxminiLoginVo {
|
||||||
|
|
||||||
|
private String openid;
|
||||||
|
private String token;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// setter\getter
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public String getOpenid() {
|
||||||
|
return openid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOpenid(String openid) {
|
||||||
|
this.openid = openid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getToken() {
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setToken(String token) {
|
||||||
|
this.token = token;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,7 +23,7 @@ public interface TieshengLoginConfigurer {
|
|||||||
/**
|
/**
|
||||||
* 授权登录回调
|
* 授权登录回调
|
||||||
*
|
*
|
||||||
* @param tokenBean
|
* @param bean
|
||||||
*/
|
*/
|
||||||
void onLoginRedirect(TokenBean bean, String to, String extra, HttpServletResponse response);
|
void onLoginRedirect(TokenBean bean, String to, String extra, HttpServletResponse response);
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-message</artifactId>
|
<artifactId>springboot-message</artifactId>
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ package com.tiesheng.message.config.aliyun;
|
|||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
import cn.hutool.http.HttpUtil;
|
import cn.hutool.http.HttpUtil;
|
||||||
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.tiesheng.message.pojos.MessageReqResp;
|
import com.tiesheng.message.pojos.MessageReqResp;
|
||||||
import com.tiesheng.message.service.TieshengMessageConfigurer;
|
import com.tiesheng.message.service.TieshengMessageSender;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@@ -22,16 +22,13 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConfigurationProperties(prefix = "tiesheng.aliyun")
|
@ConfigurationProperties(prefix = "tiesheng.aliyun")
|
||||||
public class AliyunSmsConfig {
|
public class AliyunSmsSender implements TieshengMessageSender {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求地址
|
* 请求地址
|
||||||
*/
|
*/
|
||||||
private static final String ENDPOINT = "https://dysmsapi.aliyuncs.com";
|
private static final String ENDPOINT = "https://dysmsapi.aliyuncs.com";
|
||||||
|
|
||||||
@Autowired
|
|
||||||
TieshengMessageConfigurer tieshengMessageConfigurer;
|
|
||||||
|
|
||||||
private String accessKeyId;
|
private String accessKeyId;
|
||||||
private String accessKeySecret;
|
private String accessKeySecret;
|
||||||
private String signName;
|
private String signName;
|
||||||
@@ -62,7 +59,7 @@ public class AliyunSmsConfig {
|
|||||||
*/
|
*/
|
||||||
public MessageReqResp sendSms(String phoneNumbers, String templateCode, JSONObject params) {
|
public MessageReqResp sendSms(String phoneNumbers, String templateCode, JSONObject params) {
|
||||||
|
|
||||||
MessageReqResp reqResp = new MessageReqResp();
|
MessageReqResp reqResp = new MessageReqResp("阿里云短信");
|
||||||
reqResp.setTarget(phoneNumbers);
|
reqResp.setTarget(phoneNumbers);
|
||||||
reqResp.setResult(1);
|
reqResp.setResult(1);
|
||||||
reqResp.setContent(JSONUtil.createObj()
|
reqResp.setContent(JSONUtil.createObj()
|
||||||
@@ -115,11 +112,24 @@ public class AliyunSmsConfig {
|
|||||||
reqResp.setToast(respObj.getStr("Message"));
|
reqResp.setToast(respObj.getStr("Message"));
|
||||||
}
|
}
|
||||||
|
|
||||||
tieshengMessageConfigurer.onMessageSend("阿里云短信", reqResp);
|
|
||||||
|
|
||||||
return reqResp;
|
return reqResp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MessageReqResp send(String user, String title, Object body) {
|
||||||
|
return sendSms(user, title, (JSONObject) body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getChannel() {
|
||||||
|
return "sms";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean support() {
|
||||||
|
return StrUtil.isAllNotEmpty(accessKeyId, accessKeySecret, signName);
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// setter\getter
|
// setter\getter
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
@@ -2,6 +2,8 @@ package com.tiesheng.message.pojos;
|
|||||||
|
|
||||||
public class MessageReqResp {
|
public class MessageReqResp {
|
||||||
|
|
||||||
|
private String type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送对象
|
* 发送对象
|
||||||
*/
|
*/
|
||||||
@@ -28,10 +30,22 @@ public class MessageReqResp {
|
|||||||
*/
|
*/
|
||||||
private String toast;
|
private String toast;
|
||||||
|
|
||||||
|
public MessageReqResp(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// setter\getter
|
// setter\getter
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
public String getTarget() {
|
public String getTarget() {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
package com.tiesheng.message.service;
|
|
||||||
|
|
||||||
|
|
||||||
import cn.hutool.json.JSONUtil;
|
|
||||||
import cn.hutool.log.LogFactory;
|
|
||||||
import com.tiesheng.message.pojos.MessageReqResp;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author hao
|
|
||||||
*/
|
|
||||||
public interface TieshengMessageConfigurer {
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息发送后
|
|
||||||
*
|
|
||||||
* @param reqResp
|
|
||||||
*/
|
|
||||||
default void onMessageSend(String type, MessageReqResp reqResp) {
|
|
||||||
LogFactory.get().info(JSONUtil.toJsonStr(reqResp));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.tiesheng.message.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.tiesheng.message.pojos.MessageReqResp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
public interface TieshengMessageSender {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送消息
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
* @param title
|
||||||
|
* @param content
|
||||||
|
* @param body
|
||||||
|
* @param channel 消息通道,如果为空表示所有通道
|
||||||
|
* @return 返回的内容,如果为空表示发送成功
|
||||||
|
*/
|
||||||
|
MessageReqResp send(String user, String title, Object body);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取通道
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String getChannel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否支持
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean support();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package com.tiesheng.message.service.impl;
|
|
||||||
|
|
||||||
import com.tiesheng.message.service.TieshengMessageConfigurer;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@ConditionalOnMissingBean(value = TieshengMessageConfigurer.class, ignored = DefaultMessageConfigurer.class)
|
|
||||||
public class DefaultMessageConfigurer implements TieshengMessageConfigurer {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-platform</artifactId>
|
<artifactId>springboot-platform</artifactId>
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package com.tiesheng.platform.config.wxmini;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.core.map.MapUtil;
|
||||||
|
import cn.hutool.http.HttpRequest;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.tiesheng.platform.config.wxmp.bean.WxConfigBean;
|
||||||
|
import com.tiesheng.util.exception.ApiException;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "platform.wxmini")
|
||||||
|
public class PlatformWxminiConfig {
|
||||||
|
|
||||||
|
private WxConfigBean global;
|
||||||
|
private Map<String, WxConfigBean> configs = MapUtil.newHashMap();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取一个DingConfigBean
|
||||||
|
*
|
||||||
|
* @param service
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public WxConfigBean getConfigBean(String service) {
|
||||||
|
WxConfigBean bean = configs.get(service);
|
||||||
|
if (bean == null) {
|
||||||
|
bean = global;
|
||||||
|
}
|
||||||
|
if (bean == null) {
|
||||||
|
throw new ApiException("该服务未配置微信小程序授权");
|
||||||
|
}
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// 业务逻辑
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过code获取openid
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String jscode2session(String service, String code) {
|
||||||
|
WxConfigBean configBean = getConfigBean(service);
|
||||||
|
String body = HttpRequest.get("https://api.weixin.qq.com/sns/jscode2session"
|
||||||
|
+ "?appid=" + configBean.getAppId()
|
||||||
|
+ "&secret=" + configBean.getAppSecret()
|
||||||
|
+ "&js_code=" + code + "&grant_type=authorization_code").execute().body();
|
||||||
|
JSONObject object = JSONUtil.parseObj(body);
|
||||||
|
return object.getStr("openid");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取access_token
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getAccessToken(String service) {
|
||||||
|
WxConfigBean configBean = getConfigBean(service);
|
||||||
|
String body = HttpRequest.get("https://api.weixin.qq.com/cgi-bin/token"
|
||||||
|
+ "?grant_type=client_credential&appid=" + configBean.getAppId()
|
||||||
|
+ "&secret=" + configBean.getAppSecret()).execute().body();
|
||||||
|
JSONObject object = JSONUtil.parseObj(body);
|
||||||
|
return object.getStr("access_token");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// setter\getter
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public Map<String, WxConfigBean> getConfigs() {
|
||||||
|
return configs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConfigs(Map<String, WxConfigBean> configs) {
|
||||||
|
this.configs = configs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WxConfigBean getGlobal() {
|
||||||
|
return global;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGlobal(WxConfigBean global) {
|
||||||
|
this.global = global;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-poi</artifactId>
|
<artifactId>springboot-poi</artifactId>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-util</artifactId>
|
<artifactId>springboot-util</artifactId>
|
||||||
@@ -25,18 +25,31 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
|
<artifactId>springboot-annotation</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.hutool</groupId>
|
<groupId>cn.hutool</groupId>
|
||||||
<artifactId>hutool-all</artifactId>
|
<artifactId>hutool-all</artifactId>
|
||||||
<version>5.8.11</version>
|
<version>5.8.16</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- fastJson -->
|
<!-- fastJson -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>fastjson</artifactId>
|
<artifactId>fastjson</artifactId>
|
||||||
<version>1.2.78</version>
|
<version>1.2.83</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 加解密 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bouncycastle</groupId>
|
||||||
|
<artifactId>bcprov-jdk15to18</artifactId>
|
||||||
|
<version>1.68</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
package com.tiesheng.util;
|
|
||||||
|
|
||||||
import cn.hutool.core.util.RandomUtil;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import cn.hutool.crypto.SecureUtil;
|
|
||||||
import com.tiesheng.util.exception.ApiException;
|
|
||||||
|
|
||||||
public class PasswordUtils {
|
|
||||||
|
|
||||||
private static final int PREFIX_SIZE = 8;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取加密密码
|
|
||||||
*
|
|
||||||
* @param password
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String buildPassword(String password) {
|
|
||||||
String prefix = RandomUtil.randomString(PREFIX_SIZE);
|
|
||||||
return prefix + SecureUtil.sha1(password);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证密码
|
|
||||||
*
|
|
||||||
* @param userInput
|
|
||||||
* @param encrypted
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static void verifyPassword(String userInput, String encrypted) {
|
|
||||||
String userEncrypted = buildPassword(userInput);
|
|
||||||
|
|
||||||
userEncrypted = StrUtil.subSuf(userEncrypted, PREFIX_SIZE);
|
|
||||||
encrypted = StrUtil.subSuf(encrypted, PREFIX_SIZE);
|
|
||||||
|
|
||||||
if (!StrUtil.equals(userEncrypted, encrypted)) {
|
|
||||||
throw new ApiException("账号或密码错误");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -20,5 +20,14 @@ public class ServletKit extends ServletUtil {
|
|||||||
return attributes.getRequest();
|
return attributes.getRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取客户端IP
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getClientIP() {
|
||||||
|
return getClientIP(getRequest());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
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());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
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.TimedCacheHelper;
|
||||||
|
import com.tiesheng.util.exception.ApiException;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "tiesheng.encrypt")
|
||||||
|
public class EncryptConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加解密对象
|
||||||
|
*/
|
||||||
|
private final SM4 sm4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密密钥
|
||||||
|
*/
|
||||||
|
private String key = "WmdUzPJXbngVNiaSsQrihg==";
|
||||||
|
private Integer saltSize = 8;
|
||||||
|
|
||||||
|
public EncryptConfig() {
|
||||||
|
sm4 = SmUtil.sm4(Base64.decode(getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String encrypt(String content) {
|
||||||
|
if (StrUtil.isEmpty(content)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return sm4.encryptBase64(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解密
|
||||||
|
*
|
||||||
|
* @param base64
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String decrypt(String base64) {
|
||||||
|
try {
|
||||||
|
return sm4.decryptStr(base64);
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
}
|
||||||
|
return base64;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建密码
|
||||||
|
*
|
||||||
|
* @param inputPasswd
|
||||||
|
* @param salt 盐,不存将自动生成
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String passwdCreate(String inputPasswd, String salt) {
|
||||||
|
if (StrUtil.isEmpty(salt)) {
|
||||||
|
salt = RandomUtil.randomString(saltSize);
|
||||||
|
}
|
||||||
|
if (!passwdComplexity(inputPasswd)) {
|
||||||
|
throw new ApiException("需要包含数字、大小写字母、特殊符号,且长度不低于8位");
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码校验
|
||||||
|
*
|
||||||
|
* @param inputPasswd
|
||||||
|
*/
|
||||||
|
public void passwdVerify(String inputPasswd, String encrypted) {
|
||||||
|
String salt = decrypt(encrypted).substring(0, saltSize);
|
||||||
|
String inputEncrypted = passwdCreate(inputPasswd, salt);
|
||||||
|
if (!StrUtil.equals(inputEncrypted, encrypted)) {
|
||||||
|
String clientIp = ServletKit.getClientIP();
|
||||||
|
int num = NumberUtil.parseInt(TimedCacheHelper.getTimedCache().get(clientIp, false));
|
||||||
|
if (num > 5) {
|
||||||
|
throw new ApiException("登录失败已达6次,请10分钟后再试");
|
||||||
|
}
|
||||||
|
TimedCacheHelper.getTimedCache().put(clientIp, String.valueOf(num + 1), 10 * 60 * 1000);
|
||||||
|
throw new ApiException("账号或密码错误");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// setter\getter
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKey(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getSaltSize() {
|
||||||
|
return saltSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSaltSize(Integer saltSize) {
|
||||||
|
this.saltSize = saltSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
package com.tiesheng.util.config;
|
package com.tiesheng.util.config;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.comparator.VersionComparator;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
import cn.hutool.log.LogFactory;
|
import cn.hutool.log.LogFactory;
|
||||||
import com.tiesheng.util.exception.ApiException;
|
import com.tiesheng.util.exception.ApiException;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
@@ -11,7 +14,10 @@ import org.springframework.core.io.Resource;
|
|||||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hao
|
* @author hao
|
||||||
@@ -23,6 +29,7 @@ public class GlobalConfig {
|
|||||||
private String host;
|
private String host;
|
||||||
private String service;
|
private String service;
|
||||||
private String version;
|
private String version;
|
||||||
|
private String uploadDir = System.getProperty("user.dir");
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// 逻辑方法
|
// 逻辑方法
|
||||||
@@ -61,15 +68,34 @@ public class GlobalConfig {
|
|||||||
* @param route
|
* @param route
|
||||||
*/
|
*/
|
||||||
public void redirect(String htmlDir, String route, HttpServletResponse response) {
|
public void redirect(String htmlDir, String route, HttpServletResponse response) {
|
||||||
|
if (!StrUtil.endWith(htmlDir, "/")) {
|
||||||
|
htmlDir = htmlDir + "/";
|
||||||
|
}
|
||||||
PathMatchingResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
|
PathMatchingResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
|
||||||
try {
|
try {
|
||||||
Resource[] resources = patternResolver.getResources(String.format("classpath*:static/%s/*/index.html", htmlDir));
|
List<String> versions = new ArrayList<>();
|
||||||
if (resources.length == 0) {
|
|
||||||
|
// jar包中的资源
|
||||||
|
Resource[] resources = patternResolver.getResources(String.format("classpath*:static/%s*/index.html", htmlDir));
|
||||||
|
for (Resource resource : resources) {
|
||||||
|
String path = FileUtil.normalize(resource.getURL().getPath());
|
||||||
|
versions.add(StrUtil.subBetween(path, htmlDir, "/index.html"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 目录中的资源
|
||||||
|
String folder = String.format("%s/static/%s", System.getProperty("user.dir"), htmlDir);
|
||||||
|
if (FileUtil.exist(folder)) {
|
||||||
|
File[] files = FileUtil.ls(folder);
|
||||||
|
for (File file : files) {
|
||||||
|
versions.add(StrUtil.subAfter(file.getAbsolutePath(), htmlDir, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CollUtil.isEmpty(versions)) {
|
||||||
throw new ApiException("无法重定向,请检查资源");
|
throw new ApiException("无法重定向,请检查资源");
|
||||||
}
|
}
|
||||||
String filename = resources[resources.length - 1].getURL().getPath();
|
CollUtil.sort(versions, (o1, o2) -> -VersionComparator.INSTANCE.compare(o1, o2));
|
||||||
filename = FileUtil.normalize(filename);
|
String path = buildPath(String.format("/%s%s/index.html#%s", htmlDir, versions.get(0), route));
|
||||||
String path = buildPath(String.format("/%s%s#%s", htmlDir, StrUtil.subAfter(filename, htmlDir, true), route));
|
|
||||||
response.sendRedirect(path);
|
response.sendRedirect(path);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogFactory.get().info(e);
|
LogFactory.get().info(e);
|
||||||
@@ -80,6 +106,15 @@ public class GlobalConfig {
|
|||||||
// setter\getter
|
// setter\getter
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
public String getUploadDir() {
|
||||||
|
return uploadDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUploadDir(String uploadDir) {
|
||||||
|
this.uploadDir = uploadDir;
|
||||||
|
}
|
||||||
|
|
||||||
public String getHost() {
|
public String getHost() {
|
||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,11 @@ package com.tiesheng.util.config;
|
|||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.http.HttpUtil;
|
import cn.hutool.http.HttpUtil;
|
||||||
import cn.hutool.log.LogFactory;
|
import cn.hutool.log.LogFactory;
|
||||||
|
import com.tiesheng.util.ip2region.Searcher;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.RandomAccessFile;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hao
|
* @author hao
|
||||||
@@ -17,8 +16,8 @@ import java.io.RandomAccessFile;
|
|||||||
@ConfigurationProperties(prefix = "tiesheng.ip2region")
|
@ConfigurationProperties(prefix = "tiesheng.ip2region")
|
||||||
public class Ip2regionConfig {
|
public class Ip2regionConfig {
|
||||||
|
|
||||||
private String dbUrl = "http://git.kepai365.com/zeng_wenhao/kepai-repo/raw/master/ipdb/ip2region.db";
|
private String dbUrl = "http://git.kepai365.com/tiesheng/repository/raw/master/ipdb/ip2region.xdb";
|
||||||
private String dbPath = System.getProperty("user.dir") + "/runtime/ip2region.db";
|
private String dbPath = System.getProperty("user.dir") + "/runtime/ip2region/ip2region.xdb";
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// 逻辑方法
|
// 逻辑方法
|
||||||
@@ -35,15 +34,20 @@ public class Ip2regionConfig {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取db文件
|
* 搜索ip
|
||||||
*
|
*
|
||||||
|
* @param ip
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public RandomAccessFile getDbAccessFile() throws FileNotFoundException {
|
public String search(String ip) {
|
||||||
if (!FileUtil.exist(dbPath)) {
|
String region = "";
|
||||||
downloadDbFile();
|
try {
|
||||||
|
Searcher searcher = Searcher.newWithFileOnly(dbPath);
|
||||||
|
region = searcher.search(ip);
|
||||||
|
searcher.close();
|
||||||
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
return new RandomAccessFile(dbPath, "r");
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -1,76 +0,0 @@
|
|||||||
package com.tiesheng.util.ip2region;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* data block class
|
|
||||||
*
|
|
||||||
* @author chenxin<chenxin619315 @ gmail.com>
|
|
||||||
*/
|
|
||||||
public class DataBlock {
|
|
||||||
/**
|
|
||||||
* city id
|
|
||||||
*/
|
|
||||||
private int cityId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* region address
|
|
||||||
*/
|
|
||||||
private String region;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* region ptr in the db file
|
|
||||||
*/
|
|
||||||
private int dataPtr;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* construct method
|
|
||||||
*
|
|
||||||
* @param cityId
|
|
||||||
* @param region region string
|
|
||||||
* @param dataPtr data ptr
|
|
||||||
*/
|
|
||||||
public DataBlock(int cityId, String region, int dataPtr) {
|
|
||||||
this.cityId = cityId;
|
|
||||||
this.region = region;
|
|
||||||
this.dataPtr = dataPtr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DataBlock(int cityId, String region) {
|
|
||||||
this(cityId, region, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCityId() {
|
|
||||||
return cityId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DataBlock setCityId(int cityId) {
|
|
||||||
this.cityId = cityId;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRegion() {
|
|
||||||
return region;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DataBlock setRegion(String region) {
|
|
||||||
this.region = region;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDataPtr() {
|
|
||||||
return dataPtr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DataBlock setDataPtr(int dataPtr) {
|
|
||||||
this.dataPtr = dataPtr;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append(cityId).append('|').append(region).append('|').append(dataPtr);
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
package com.tiesheng.util.ip2region;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* database configuration class
|
|
||||||
*
|
|
||||||
* @author chenxin<chenxin619315 @ gmail.com>
|
|
||||||
*/
|
|
||||||
public class DbConfig {
|
|
||||||
/**
|
|
||||||
* total header data block size
|
|
||||||
*/
|
|
||||||
private int totalHeaderSize;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* max index data block size
|
|
||||||
* u should always choice the fastest read block size
|
|
||||||
*/
|
|
||||||
private int indexBlockSize;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* construct method
|
|
||||||
*
|
|
||||||
* @param totalHeaderSize
|
|
||||||
*/
|
|
||||||
public DbConfig(int totalHeaderSize) {
|
|
||||||
this.totalHeaderSize = totalHeaderSize;
|
|
||||||
this.indexBlockSize = 8192;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DbConfig() {
|
|
||||||
this(8 * 2048);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTotalHeaderSize() {
|
|
||||||
return totalHeaderSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DbConfig setTotalHeaderSize(int totalHeaderSize) {
|
|
||||||
this.totalHeaderSize = totalHeaderSize;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIndexBlockSize() {
|
|
||||||
return indexBlockSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DbConfig setIndexBlockSize(int dataBlockSize) {
|
|
||||||
this.indexBlockSize = dataBlockSize;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.tiesheng.util.ip2region;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
public class Header {
|
||||||
|
public final int version;
|
||||||
|
public final int indexPolicy;
|
||||||
|
public final int createdAt;
|
||||||
|
public final int startIndexPtr;
|
||||||
|
public final int endIndexPtr;
|
||||||
|
public final byte[] buffer;
|
||||||
|
|
||||||
|
public Header(byte[] buff) {
|
||||||
|
assert buff.length >= 16;
|
||||||
|
version = Searcher.getInt2(buff, 0);
|
||||||
|
indexPolicy = Searcher.getInt2(buff, 2);
|
||||||
|
createdAt = Searcher.getInt(buff, 4);
|
||||||
|
startIndexPtr = Searcher.getInt(buff, 8);
|
||||||
|
endIndexPtr = Searcher.getInt(buff, 12);
|
||||||
|
buffer = buff;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "{" +
|
||||||
|
"Version: " + version + ',' +
|
||||||
|
"IndexPolicy: " + indexPolicy + ',' +
|
||||||
|
"CreatedAt: " + createdAt + ',' +
|
||||||
|
"StartIndexPtr: " + startIndexPtr + ',' +
|
||||||
|
"EndIndexPtr: " + endIndexPtr +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
package com.tiesheng.util.ip2region;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* item index class
|
|
||||||
*
|
|
||||||
* @author chenxin<chenxin619315 @ gmail.com>
|
|
||||||
*/
|
|
||||||
public class IndexBlock {
|
|
||||||
|
|
||||||
private static int LENGTH = 12;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* start ip address
|
|
||||||
*/
|
|
||||||
private long startIp;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* end ip address
|
|
||||||
*/
|
|
||||||
private long endIp;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* data ptr and data length
|
|
||||||
*/
|
|
||||||
private int dataPtr;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* data length
|
|
||||||
*/
|
|
||||||
private int dataLen;
|
|
||||||
|
|
||||||
public IndexBlock(long startIp, long endIp, int dataPtr, int dataLen) {
|
|
||||||
this.startIp = startIp;
|
|
||||||
this.endIp = endIp;
|
|
||||||
this.dataPtr = dataPtr;
|
|
||||||
this.dataLen = dataLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getIndexBlockLength() {
|
|
||||||
return LENGTH;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getStartIp() {
|
|
||||||
return startIp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IndexBlock setStartIp(long startIp) {
|
|
||||||
this.startIp = startIp;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getEndIp() {
|
|
||||||
return endIp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IndexBlock setEndIp(long endIp) {
|
|
||||||
this.endIp = endIp;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDataPtr() {
|
|
||||||
return dataPtr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IndexBlock setDataPtr(int dataPtr) {
|
|
||||||
this.dataPtr = dataPtr;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDataLen() {
|
|
||||||
return dataLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IndexBlock setDataLen(int dataLen) {
|
|
||||||
this.dataLen = dataLen;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the bytes for storage
|
|
||||||
*
|
|
||||||
* @return byte[]
|
|
||||||
*/
|
|
||||||
public byte[] getBytes() {
|
|
||||||
/*
|
|
||||||
* +------------+-----------+-----------+
|
|
||||||
* | 4bytes | 4bytes | 4bytes |
|
|
||||||
* +------------+-----------+-----------+
|
|
||||||
* start ip end ip data ptr + len
|
|
||||||
*/
|
|
||||||
byte[] b = new byte[12];
|
|
||||||
|
|
||||||
IpUtil.writeIntLong(b, 0, startIp); //start ip
|
|
||||||
IpUtil.writeIntLong(b, 4, endIp); //end ip
|
|
||||||
|
|
||||||
//write the data ptr and the length
|
|
||||||
long mix = dataPtr | ((dataLen << 24) & 0xFF000000L);
|
|
||||||
IpUtil.writeIntLong(b, 8, mix);
|
|
||||||
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,416 +0,0 @@
|
|||||||
package com.tiesheng.util.ip2region;
|
|
||||||
|
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
|
||||||
import com.tiesheng.util.config.Ip2regionConfig;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.RandomAccessFile;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ip db searcher class (Not thread safe)
|
|
||||||
*
|
|
||||||
* @author chenxin<chenxin619315 @ gmail.com>
|
|
||||||
*/
|
|
||||||
public class Ip2Region {
|
|
||||||
|
|
||||||
|
|
||||||
private static Ip2Region ip2Region;
|
|
||||||
/**
|
|
||||||
* db config
|
|
||||||
*/
|
|
||||||
private final DbConfig dbConfig;
|
|
||||||
/**
|
|
||||||
* db file access handler
|
|
||||||
*/
|
|
||||||
private RandomAccessFile raf = null;
|
|
||||||
/**
|
|
||||||
* header blocks buffer
|
|
||||||
*/
|
|
||||||
private long[] headerSip = null;
|
|
||||||
private int[] headerPtr = null;
|
|
||||||
private int headerLength;
|
|
||||||
/**
|
|
||||||
* super blocks info
|
|
||||||
*/
|
|
||||||
private long firstIndexPtr = 0;
|
|
||||||
private long lastIndexPtr = 0;
|
|
||||||
private int totalIndexBlocks = 0;
|
|
||||||
/**
|
|
||||||
* for memory mode
|
|
||||||
* the original db binary string
|
|
||||||
*/
|
|
||||||
private byte[] dbBinStr = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* construct class
|
|
||||||
*/
|
|
||||||
public Ip2Region() {
|
|
||||||
this.dbConfig = new DbConfig();
|
|
||||||
try {
|
|
||||||
Ip2regionConfig ip2regionConfig = SpringUtil.getBean(Ip2regionConfig.class);
|
|
||||||
raf = ip2regionConfig.getDbAccessFile();
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取单例
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Ip2Region getInstance() {
|
|
||||||
if (ip2Region == null) {
|
|
||||||
synchronized (Ip2Region.class) {
|
|
||||||
if (ip2Region == null) {
|
|
||||||
ip2Region = new Ip2Region();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ip2Region;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the region with an int ip address with memory binary search algorithm
|
|
||||||
*
|
|
||||||
* @param ip
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public DataBlock memorySearch(long ip) throws IOException {
|
|
||||||
int blen = IndexBlock.getIndexBlockLength();
|
|
||||||
if (dbBinStr == null) {
|
|
||||||
dbBinStr = new byte[(int) raf.length()];
|
|
||||||
raf.seek(0L);
|
|
||||||
raf.readFully(dbBinStr, 0, dbBinStr.length);
|
|
||||||
|
|
||||||
//initialize the global vars
|
|
||||||
firstIndexPtr = IpUtil.getIntLong(dbBinStr, 0);
|
|
||||||
lastIndexPtr = IpUtil.getIntLong(dbBinStr, 4);
|
|
||||||
totalIndexBlocks = (int) ((lastIndexPtr - firstIndexPtr) / blen) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//search the index blocks to define the data
|
|
||||||
int l = 0, h = totalIndexBlocks;
|
|
||||||
long sip, eip, dataptr = 0;
|
|
||||||
while (l <= h) {
|
|
||||||
int m = (l + h) >> 1;
|
|
||||||
int p = (int) (firstIndexPtr + m * blen);
|
|
||||||
|
|
||||||
sip = IpUtil.getIntLong(dbBinStr, p);
|
|
||||||
if (ip < sip) {
|
|
||||||
h = m - 1;
|
|
||||||
} else {
|
|
||||||
eip = IpUtil.getIntLong(dbBinStr, p + 4);
|
|
||||||
if (ip > eip) {
|
|
||||||
l = m + 1;
|
|
||||||
} else {
|
|
||||||
dataptr = IpUtil.getIntLong(dbBinStr, p + 8);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//not matched
|
|
||||||
if (dataptr == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//get the data
|
|
||||||
int dataLen = (int) ((dataptr >> 24) & 0xFF);
|
|
||||||
int dataPtr = (int) ((dataptr & 0x00FFFFFF));
|
|
||||||
int cityId = (int) IpUtil.getIntLong(dbBinStr, dataPtr);
|
|
||||||
String region = new String(dbBinStr, dataPtr + 4, dataLen - 4, StandardCharsets.UTF_8);
|
|
||||||
|
|
||||||
return new DataBlock(cityId, region, dataPtr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the region throught the ip address with memory binary search algorithm
|
|
||||||
*
|
|
||||||
* @return DataBlock
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public DataBlock memorySearch() throws IOException {
|
|
||||||
return memorySearch(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the region throught the ip address with memory binary search algorithm
|
|
||||||
*
|
|
||||||
* @param ip
|
|
||||||
* @return DataBlock
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public DataBlock memorySearch(String ip) throws IOException {
|
|
||||||
return memorySearch(IpUtil.ip2long(ip));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get by index ptr
|
|
||||||
*
|
|
||||||
* @param ptr
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public DataBlock getByIndexPtr(long ptr) throws IOException {
|
|
||||||
raf.seek(ptr);
|
|
||||||
byte[] buffer = new byte[12];
|
|
||||||
raf.readFully(buffer, 0, buffer.length);
|
|
||||||
long extra = IpUtil.getIntLong(buffer, 8);
|
|
||||||
|
|
||||||
int dataLen = (int) ((extra >> 24) & 0xFF);
|
|
||||||
int dataPtr = (int) ((extra & 0x00FFFFFF));
|
|
||||||
|
|
||||||
raf.seek(dataPtr);
|
|
||||||
byte[] data = new byte[dataLen];
|
|
||||||
raf.readFully(data, 0, data.length);
|
|
||||||
|
|
||||||
int cityId = (int) IpUtil.getIntLong(data, 0);
|
|
||||||
String region = new String(data, 4, data.length - 4, StandardCharsets.UTF_8);
|
|
||||||
|
|
||||||
return new DataBlock(cityId, region, dataPtr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the region with an int ip address with b-tree algorithm
|
|
||||||
*
|
|
||||||
* @param ip
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public DataBlock btreeSearch(long ip) throws IOException {
|
|
||||||
//check and load the header
|
|
||||||
if (headerSip == null) {
|
|
||||||
raf.seek(8L);
|
|
||||||
byte[] b = new byte[dbConfig.getTotalHeaderSize()];
|
|
||||||
raf.readFully(b, 0, b.length);
|
|
||||||
|
|
||||||
//fill the header
|
|
||||||
int len = b.length >> 3, idx = 0;
|
|
||||||
headerSip = new long[len];
|
|
||||||
headerPtr = new int[len];
|
|
||||||
long startIp, dataPtr;
|
|
||||||
for (int i = 0; i < b.length; i += 8) {
|
|
||||||
startIp = IpUtil.getIntLong(b, i);
|
|
||||||
dataPtr = IpUtil.getIntLong(b, i + 4);
|
|
||||||
if (dataPtr == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
headerSip[idx] = startIp;
|
|
||||||
headerPtr[idx] = (int) dataPtr;
|
|
||||||
idx++;
|
|
||||||
}
|
|
||||||
|
|
||||||
headerLength = idx;
|
|
||||||
}
|
|
||||||
|
|
||||||
//1. define the index block with the binary search
|
|
||||||
if (ip == headerSip[0]) {
|
|
||||||
return getByIndexPtr(headerPtr[0]);
|
|
||||||
} else if (ip == headerSip[headerLength - 1]) {
|
|
||||||
return getByIndexPtr(headerPtr[headerLength - 1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
int l = 0, h = headerLength, sptr = 0, eptr = 0;
|
|
||||||
while (l <= h) {
|
|
||||||
int m = (l + h) >> 1;
|
|
||||||
|
|
||||||
//perfetc matched, just return it
|
|
||||||
if (ip == headerSip[m]) {
|
|
||||||
if (m > 0) {
|
|
||||||
sptr = headerPtr[m - 1];
|
|
||||||
eptr = headerPtr[m];
|
|
||||||
} else {
|
|
||||||
sptr = headerPtr[m];
|
|
||||||
eptr = headerPtr[m + 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//less then the middle value
|
|
||||||
if (ip < headerSip[m]) {
|
|
||||||
if (m == 0) {
|
|
||||||
sptr = headerPtr[m];
|
|
||||||
eptr = headerPtr[m + 1];
|
|
||||||
break;
|
|
||||||
} else if (ip > headerSip[m - 1]) {
|
|
||||||
sptr = headerPtr[m - 1];
|
|
||||||
eptr = headerPtr[m];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
h = m - 1;
|
|
||||||
} else {
|
|
||||||
if (m == headerLength - 1) {
|
|
||||||
sptr = headerPtr[m - 1];
|
|
||||||
eptr = headerPtr[m];
|
|
||||||
break;
|
|
||||||
} else if (ip <= headerSip[m + 1]) {
|
|
||||||
sptr = headerPtr[m];
|
|
||||||
eptr = headerPtr[m + 1];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
l = m + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//match nothing just stop it
|
|
||||||
if (sptr == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//2. search the index blocks to define the data
|
|
||||||
int blockLen = eptr - sptr, blen = IndexBlock.getIndexBlockLength();
|
|
||||||
//include the right border block
|
|
||||||
byte[] iBuffer = new byte[blockLen + blen];
|
|
||||||
raf.seek(sptr);
|
|
||||||
raf.readFully(iBuffer, 0, iBuffer.length);
|
|
||||||
|
|
||||||
l = 0;
|
|
||||||
h = blockLen / blen;
|
|
||||||
long sip, eip, dataptr = 0;
|
|
||||||
while (l <= h) {
|
|
||||||
int m = (l + h) >> 1;
|
|
||||||
int p = m * blen;
|
|
||||||
sip = IpUtil.getIntLong(iBuffer, p);
|
|
||||||
if (ip < sip) {
|
|
||||||
h = m - 1;
|
|
||||||
} else {
|
|
||||||
eip = IpUtil.getIntLong(iBuffer, p + 4);
|
|
||||||
if (ip > eip) {
|
|
||||||
l = m + 1;
|
|
||||||
} else {
|
|
||||||
dataptr = IpUtil.getIntLong(iBuffer, p + 8);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//not matched
|
|
||||||
if (dataptr == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//3. get the data
|
|
||||||
int dataLen = (int) ((dataptr >> 24) & 0xFF);
|
|
||||||
int dataPtr = (int) ((dataptr & 0x00FFFFFF));
|
|
||||||
|
|
||||||
raf.seek(dataPtr);
|
|
||||||
byte[] data = new byte[dataLen];
|
|
||||||
raf.readFully(data, 0, data.length);
|
|
||||||
|
|
||||||
int cityId = (int) IpUtil.getIntLong(data, 0);
|
|
||||||
String region = new String(data, 4, data.length - 4, StandardCharsets.UTF_8);
|
|
||||||
|
|
||||||
return new DataBlock(cityId, region, dataPtr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the region throught the ip address with b-tree search algorithm
|
|
||||||
*
|
|
||||||
* @param ip
|
|
||||||
* @return DataBlock
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public DataBlock btreeSearch(String ip) {
|
|
||||||
try {
|
|
||||||
return btreeSearch(IpUtil.ip2long(ip));
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
return new DataBlock(0, "未知IP");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the region with a int ip address with binary search algorithm
|
|
||||||
*
|
|
||||||
* @param ip
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public DataBlock binarySearch(long ip) throws IOException {
|
|
||||||
int blen = IndexBlock.getIndexBlockLength();
|
|
||||||
if (totalIndexBlocks == 0) {
|
|
||||||
raf.seek(0L);
|
|
||||||
byte[] superBytes = new byte[8];
|
|
||||||
raf.readFully(superBytes, 0, superBytes.length);
|
|
||||||
//initialize the global vars
|
|
||||||
firstIndexPtr = IpUtil.getIntLong(superBytes, 0);
|
|
||||||
lastIndexPtr = IpUtil.getIntLong(superBytes, 4);
|
|
||||||
totalIndexBlocks = (int) ((lastIndexPtr - firstIndexPtr) / blen) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//search the index blocks to define the data
|
|
||||||
int l = 0, h = totalIndexBlocks;
|
|
||||||
byte[] buffer = new byte[blen];
|
|
||||||
long sip, eip, dataptr = 0;
|
|
||||||
while (l <= h) {
|
|
||||||
int m = (l + h) >> 1;
|
|
||||||
raf.seek(firstIndexPtr + m * blen);
|
|
||||||
raf.readFully(buffer, 0, buffer.length);
|
|
||||||
sip = IpUtil.getIntLong(buffer, 0);
|
|
||||||
if (ip < sip) {
|
|
||||||
h = m - 1;
|
|
||||||
} else {
|
|
||||||
eip = IpUtil.getIntLong(buffer, 4);
|
|
||||||
if (ip > eip) {
|
|
||||||
l = m + 1;
|
|
||||||
} else {
|
|
||||||
dataptr = IpUtil.getIntLong(buffer, 8);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//not matched
|
|
||||||
if (dataptr == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//get the data
|
|
||||||
int dataLen = (int) ((dataptr >> 24) & 0xFF);
|
|
||||||
int dataPtr = (int) ((dataptr & 0x00FFFFFF));
|
|
||||||
|
|
||||||
raf.seek(dataPtr);
|
|
||||||
byte[] data = new byte[dataLen];
|
|
||||||
raf.readFully(data, 0, data.length);
|
|
||||||
|
|
||||||
int cityId = (int) IpUtil.getIntLong(data, 0);
|
|
||||||
String region = new String(data, 4, data.length - 4, StandardCharsets.UTF_8);
|
|
||||||
|
|
||||||
return new DataBlock(cityId, region, dataPtr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the region throught the ip address with binary search algorithm
|
|
||||||
*
|
|
||||||
* @param ip
|
|
||||||
* @return DataBlock
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public DataBlock binarySearch(String ip) throws IOException {
|
|
||||||
return binarySearch(IpUtil.ip2long(ip));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the db config
|
|
||||||
*
|
|
||||||
* @return DbConfig
|
|
||||||
*/
|
|
||||||
public DbConfig getDbConfig() {
|
|
||||||
return dbConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* close the db
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public void close() throws IOException {
|
|
||||||
headerSip = null;
|
|
||||||
headerPtr = null;
|
|
||||||
dbBinStr = null;
|
|
||||||
if (raf != null) {
|
|
||||||
raf.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
package com.tiesheng.util.ip2region;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* util class
|
|
||||||
*
|
|
||||||
* @author chenxin<chenxin619315 @ gmail.com>
|
|
||||||
*/
|
|
||||||
public class IpUtil {
|
|
||||||
/**
|
|
||||||
* write specfield bytes to a byte array start from offset
|
|
||||||
*
|
|
||||||
* @param b
|
|
||||||
* @param offset
|
|
||||||
* @param v
|
|
||||||
* @param bytes
|
|
||||||
*/
|
|
||||||
public static void write(byte[] b, int offset, long v, int bytes) {
|
|
||||||
for (int i = 0; i < bytes; i++) {
|
|
||||||
b[offset++] = (byte) ((v >>> (8 * i)) & 0xFF);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* write a int to a byte array
|
|
||||||
*
|
|
||||||
* @param b
|
|
||||||
* @param offset
|
|
||||||
* @param v
|
|
||||||
*/
|
|
||||||
public static void writeIntLong(byte[] b, int offset, long v) {
|
|
||||||
b[offset++] = (byte) ((v >> 0) & 0xFF);
|
|
||||||
b[offset++] = (byte) ((v >> 8) & 0xFF);
|
|
||||||
b[offset++] = (byte) ((v >> 16) & 0xFF);
|
|
||||||
b[offset] = (byte) ((v >> 24) & 0xFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get a int from a byte array start from the specifiled offset
|
|
||||||
*
|
|
||||||
* @param b
|
|
||||||
* @param offset
|
|
||||||
*/
|
|
||||||
public static long getIntLong(byte[] b, int offset) {
|
|
||||||
return (
|
|
||||||
((b[offset++] & 0x000000FFL)) |
|
|
||||||
((b[offset++] << 8) & 0x0000FF00L) |
|
|
||||||
((b[offset++] << 16) & 0x00FF0000L) |
|
|
||||||
((b[offset] << 24) & 0xFF000000L)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get a int from a byte array start from the specifield offset
|
|
||||||
*
|
|
||||||
* @param b
|
|
||||||
* @param offset
|
|
||||||
*/
|
|
||||||
public static int getInt3(byte[] b, int offset) {
|
|
||||||
return (
|
|
||||||
(b[offset++] & 0x000000FF) |
|
|
||||||
(b[offset++] & 0x0000FF00) |
|
|
||||||
(b[offset] & 0x00FF0000)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getInt2(byte[] b, int offset) {
|
|
||||||
return (
|
|
||||||
(b[offset++] & 0x000000FF) |
|
|
||||||
(b[offset] & 0x0000FF00)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getInt1(byte[] b, int offset) {
|
|
||||||
return (
|
|
||||||
(b[offset] & 0x000000FF)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* string ip to long ip
|
|
||||||
*
|
|
||||||
* @param ip
|
|
||||||
* @return long
|
|
||||||
*/
|
|
||||||
public static long ip2long(String ip) {
|
|
||||||
String[] p = ip.split("\\.");
|
|
||||||
if (p.length != 4) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int p1 = ((Integer.valueOf(p[0]) << 24) & 0xFF000000);
|
|
||||||
int p2 = ((Integer.valueOf(p[1]) << 16) & 0x00FF0000);
|
|
||||||
int p3 = ((Integer.valueOf(p[2]) << 8) & 0x0000FF00);
|
|
||||||
int p4 = ((Integer.valueOf(p[3]) << 0) & 0x000000FF);
|
|
||||||
|
|
||||||
return ((p1 | p2 | p3 | p4) & 0xFFFFFFFFL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* int to ip string
|
|
||||||
*
|
|
||||||
* @param ip
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static String long2ip(long ip) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
|
|
||||||
sb
|
|
||||||
.append((ip >> 24) & 0xFF).append('.')
|
|
||||||
.append((ip >> 16) & 0xFF).append('.')
|
|
||||||
.append((ip >> 8) & 0xFF).append('.')
|
|
||||||
.append((ip >> 0) & 0xFF);
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,258 @@
|
|||||||
|
package com.tiesheng.util.ip2region;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.RandomAccessFile;
|
||||||
|
|
||||||
|
public class Searcher {
|
||||||
|
// constant defined copied from the xdb maker
|
||||||
|
public static final int HeaderInfoLength = 256;
|
||||||
|
public static final int VectorIndexRows = 256;
|
||||||
|
public static final int VectorIndexCols = 256;
|
||||||
|
public static final int VectorIndexSize = 8;
|
||||||
|
public static final int SegmentIndexSize = 14;
|
||||||
|
public static final byte[] shiftIndex = {24, 16, 8, 0};
|
||||||
|
// random access file handle for file based search
|
||||||
|
private final RandomAccessFile handle;
|
||||||
|
// vector index.
|
||||||
|
// use the byte[] instead of VectorIndex entry array to keep
|
||||||
|
// the minimal memory allocation.
|
||||||
|
private final byte[] vectorIndex;
|
||||||
|
|
||||||
|
// xdb content buffer, used for in-memory search
|
||||||
|
private final byte[] contentBuff;
|
||||||
|
|
||||||
|
// --- static method to create searchers
|
||||||
|
private int ioCount = 0;
|
||||||
|
|
||||||
|
public Searcher(String dbFile, byte[] vectorIndex, byte[] cBuff) throws IOException {
|
||||||
|
if (cBuff != null) {
|
||||||
|
this.handle = null;
|
||||||
|
this.vectorIndex = null;
|
||||||
|
this.contentBuff = cBuff;
|
||||||
|
} else {
|
||||||
|
this.handle = new RandomAccessFile(dbFile, "r");
|
||||||
|
this.vectorIndex = vectorIndex;
|
||||||
|
this.contentBuff = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Searcher newWithFileOnly(String dbPath) throws IOException {
|
||||||
|
return new Searcher(dbPath, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- End of creator
|
||||||
|
|
||||||
|
public static Searcher newWithVectorIndex(String dbPath, byte[] vectorIndex) throws IOException {
|
||||||
|
return new Searcher(dbPath, vectorIndex, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Searcher newWithBuffer(byte[] cBuff) throws IOException {
|
||||||
|
return new Searcher(null, null, cBuff);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Header loadHeader(RandomAccessFile handle) throws IOException {
|
||||||
|
handle.seek(0);
|
||||||
|
final byte[] buff = new byte[HeaderInfoLength];
|
||||||
|
handle.read(buff);
|
||||||
|
return new Header(buff);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Header loadHeaderFromFile(String dbPath) throws IOException {
|
||||||
|
final RandomAccessFile handle = new RandomAccessFile(dbPath, "r");
|
||||||
|
final Header header = loadHeader(handle);
|
||||||
|
handle.close();
|
||||||
|
return header;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] loadVectorIndex(RandomAccessFile handle) throws IOException {
|
||||||
|
handle.seek(HeaderInfoLength);
|
||||||
|
int len = VectorIndexRows * VectorIndexCols * VectorIndexSize;
|
||||||
|
final byte[] buff = new byte[len];
|
||||||
|
int rLen = handle.read(buff);
|
||||||
|
if (rLen != len) {
|
||||||
|
throw new IOException("incomplete read: read bytes should be " + len);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buff;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] loadVectorIndexFromFile(String dbPath) throws IOException {
|
||||||
|
final RandomAccessFile handle = new RandomAccessFile(dbPath, "r");
|
||||||
|
final byte[] vIndex = loadVectorIndex(handle);
|
||||||
|
handle.close();
|
||||||
|
return vIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- static cache util function
|
||||||
|
|
||||||
|
public static byte[] loadContent(RandomAccessFile handle) throws IOException {
|
||||||
|
handle.seek(0);
|
||||||
|
final byte[] buff = new byte[(int) handle.length()];
|
||||||
|
int rLen = handle.read(buff);
|
||||||
|
if (rLen != buff.length) {
|
||||||
|
throw new IOException("incomplete read: read bytes should be " + buff.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buff;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] loadContentFromFile(String dbPath) throws IOException {
|
||||||
|
final RandomAccessFile handle = new RandomAccessFile(dbPath, "r");
|
||||||
|
final byte[] content = loadContent(handle);
|
||||||
|
handle.close();
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get an int from a byte array start from the specified offset */
|
||||||
|
public static long getIntLong(byte[] b, int offset) {
|
||||||
|
return (
|
||||||
|
((b[offset++] & 0x000000FFL)) |
|
||||||
|
((b[offset++] << 8) & 0x0000FF00L) |
|
||||||
|
((b[offset++] << 16) & 0x00FF0000L) |
|
||||||
|
((b[offset] << 24) & 0xFF000000L)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getInt(byte[] b, int offset) {
|
||||||
|
return (
|
||||||
|
((b[offset++] & 0x000000FF)) |
|
||||||
|
((b[offset++] << 8) & 0x0000FF00) |
|
||||||
|
((b[offset++] << 16) & 0x00FF0000) |
|
||||||
|
((b[offset] << 24) & 0xFF000000)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getInt2(byte[] b, int offset) {
|
||||||
|
return (
|
||||||
|
((b[offset++] & 0x000000FF)) |
|
||||||
|
((b[offset] << 8) & 0x0000FF00)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* long int to ip string */
|
||||||
|
public static String long2ip(long ip) {
|
||||||
|
return String.valueOf((ip >> 24) & 0xFF) + '.' +
|
||||||
|
((ip >> 16) & 0xFF) + '.' + ((ip >> 8) & 0xFF) + '.' + ((ip) & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- End cache load util function
|
||||||
|
|
||||||
|
// --- static util method
|
||||||
|
|
||||||
|
/* check the specified ip address */
|
||||||
|
public static long checkIP(String ip) throws Exception {
|
||||||
|
String[] ps = ip.split("\\.");
|
||||||
|
if (ps.length != 4) {
|
||||||
|
throw new Exception("invalid ip address `" + ip + "`");
|
||||||
|
}
|
||||||
|
|
||||||
|
long ipDst = 0;
|
||||||
|
for (int i = 0; i < ps.length; i++) {
|
||||||
|
int val = Integer.parseInt(ps[i]);
|
||||||
|
if (val > 255) {
|
||||||
|
throw new Exception("ip part `" + ps[i] + "` should be less then 256");
|
||||||
|
}
|
||||||
|
|
||||||
|
ipDst |= ((long) val << shiftIndex[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ipDst & 0xFFFFFFFFL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() throws IOException {
|
||||||
|
if (this.handle != null) {
|
||||||
|
this.handle.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIOCount() {
|
||||||
|
return ioCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String search(String ipStr) throws Exception {
|
||||||
|
long ip = checkIP(ipStr);
|
||||||
|
return search(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String search(long ip) throws IOException {
|
||||||
|
// reset the global counter
|
||||||
|
this.ioCount = 0;
|
||||||
|
|
||||||
|
// locate the segment index block based on the vector index
|
||||||
|
int sPtr = 0, ePtr = 0;
|
||||||
|
int il0 = (int) ((ip >> 24) & 0xFF);
|
||||||
|
int il1 = (int) ((ip >> 16) & 0xFF);
|
||||||
|
int idx = il0 * VectorIndexCols * VectorIndexSize + il1 * VectorIndexSize;
|
||||||
|
// System.out.printf("il0: %d, il1: %d, idx: %d\n", il0, il1, idx);
|
||||||
|
if (vectorIndex != null) {
|
||||||
|
sPtr = getInt(vectorIndex, idx);
|
||||||
|
ePtr = getInt(vectorIndex, idx + 4);
|
||||||
|
} else if (contentBuff != null) {
|
||||||
|
sPtr = getInt(contentBuff, HeaderInfoLength + idx);
|
||||||
|
ePtr = getInt(contentBuff, HeaderInfoLength + idx + 4);
|
||||||
|
} else {
|
||||||
|
final byte[] buff = new byte[VectorIndexSize];
|
||||||
|
read(HeaderInfoLength + idx, buff);
|
||||||
|
sPtr = getInt(buff, 0);
|
||||||
|
ePtr = getInt(buff, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
// System.out.printf("sPtr: %d, ePtr: %d\n", sPtr, ePtr);
|
||||||
|
|
||||||
|
// binary search the segment index block to get the region info
|
||||||
|
final byte[] buff = new byte[SegmentIndexSize];
|
||||||
|
int dataLen = -1, dataPtr = -1;
|
||||||
|
int l = 0, h = (ePtr - sPtr) / SegmentIndexSize;
|
||||||
|
while (l <= h) {
|
||||||
|
int m = (l + h) >> 1;
|
||||||
|
int p = sPtr + m * SegmentIndexSize;
|
||||||
|
|
||||||
|
// read the segment index
|
||||||
|
read(p, buff);
|
||||||
|
long sip = getIntLong(buff, 0);
|
||||||
|
if (ip < sip) {
|
||||||
|
h = m - 1;
|
||||||
|
} else {
|
||||||
|
long eip = getIntLong(buff, 4);
|
||||||
|
if (ip > eip) {
|
||||||
|
l = m + 1;
|
||||||
|
} else {
|
||||||
|
dataLen = getInt2(buff, 8);
|
||||||
|
dataPtr = getInt(buff, 10);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// empty match interception
|
||||||
|
// System.out.printf("dataLen: %d, dataPtr: %d\n", dataLen, dataPtr);
|
||||||
|
if (dataPtr < 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// load and return the region data
|
||||||
|
final byte[] regionBuff = new byte[dataLen];
|
||||||
|
read(dataPtr, regionBuff);
|
||||||
|
return new String(regionBuff, "utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void read(int offset, byte[] buffer) throws IOException {
|
||||||
|
// check the in-memory buffer first
|
||||||
|
if (contentBuff != null) {
|
||||||
|
// @TODO: reduce data copying, directly decode the data ?
|
||||||
|
System.arraycopy(contentBuff, offset, buffer, 0, buffer.length);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// read from the file handle
|
||||||
|
assert handle != null;
|
||||||
|
handle.seek(offset);
|
||||||
|
|
||||||
|
this.ioCount++;
|
||||||
|
int rLen = handle.read(buffer);
|
||||||
|
if (rLen != buffer.length) {
|
||||||
|
throw new IOException("incomplete read: read bytes should be " + buffer.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -129,6 +129,15 @@ public class ApiResp<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否成功
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean successful() {
|
||||||
|
return code == CODE_OK;
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// setter\getter
|
// setter\getter
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import cn.hutool.core.io.FileUtil;
|
|||||||
import cn.hutool.core.util.CharUtil;
|
import cn.hutool.core.util.CharUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import cn.hutool.http.HttpUtil;
|
import cn.hutool.http.HttpUtil;
|
||||||
|
import com.tiesheng.util.config.GlobalConfig;
|
||||||
|
|
||||||
public class FileUploadPath {
|
public class FileUploadPath {
|
||||||
|
|
||||||
@@ -46,7 +48,7 @@ public class FileUploadPath {
|
|||||||
}
|
}
|
||||||
pathBean.setHttpPath(tempPath);
|
pathBean.setHttpPath(tempPath);
|
||||||
|
|
||||||
String tempAbs = String.format("%s/static%s", System.getProperty("user.dir"), tempPath);
|
String tempAbs = String.format("%s/static%s", SpringUtil.getBean(GlobalConfig.class).getUploadDir(), tempPath);
|
||||||
tempAbs = FileUtil.normalize(tempAbs);
|
tempAbs = FileUtil.normalize(tempAbs);
|
||||||
pathBean.setAbsolutePath(tempAbs);
|
pathBean.setAbsolutePath(tempAbs);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.tiesheng.util.pojos;
|
||||||
|
|
||||||
|
public class IdName {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
private String extra;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// setter\getter
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExtra() {
|
||||||
|
return extra;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExtra(String extra) {
|
||||||
|
this.extra = extra;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-web</artifactId>
|
<artifactId>springboot-web</artifactId>
|
||||||
@@ -64,7 +64,7 @@
|
|||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-db-migration</artifactId>
|
<artifactId>springboot-database</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -72,11 +72,6 @@
|
|||||||
<artifactId>springboot-poi</artifactId>
|
<artifactId>springboot-poi</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
|
||||||
<artifactId>springboot-annotation</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-login</artifactId>
|
<artifactId>springboot-login</artifactId>
|
||||||
@@ -87,6 +82,11 @@
|
|||||||
<artifactId>springboot-message</artifactId>
|
<artifactId>springboot-message</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
|
<artifactId>springboot-encrypt</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.tiesheng.core;
|
package com.tiesheng.core;
|
||||||
|
|
||||||
import com.tiesheng.core.service.TieshengWebConfigurer;
|
import com.tiesheng.core.service.TieshengWebConfigurer;
|
||||||
|
import com.tiesheng.database.DatabaseAutoConfigurer;
|
||||||
import com.tiesheng.login.LoginAutoConfigurer;
|
import com.tiesheng.login.LoginAutoConfigurer;
|
||||||
import com.tiesheng.message.MessageAutoConfigurer;
|
import com.tiesheng.message.MessageAutoConfigurer;
|
||||||
import com.tiesheng.migration.MigrationAutoConfigurer;
|
|
||||||
import com.tiesheng.util.UtilAutoConfigurer;
|
import com.tiesheng.util.UtilAutoConfigurer;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ import java.lang.annotation.*;
|
|||||||
MessageAutoConfigurer.class,
|
MessageAutoConfigurer.class,
|
||||||
CoreAutoConfigurer.class,
|
CoreAutoConfigurer.class,
|
||||||
LoginAutoConfigurer.class,
|
LoginAutoConfigurer.class,
|
||||||
MigrationAutoConfigurer.class
|
DatabaseAutoConfigurer.class
|
||||||
})
|
})
|
||||||
public @interface EnableTieshengWeb {
|
public @interface EnableTieshengWeb {
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
package com.tiesheng.core.config.json;
|
package com.tiesheng.core.config.json;
|
||||||
|
|
||||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
||||||
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
|
||||||
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
||||||
|
import com.tiesheng.util.CommonUtil;
|
||||||
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -25,14 +24,9 @@ public class FastJsonMessageConverter {
|
|||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public HttpMessageConverters fastJsonHttpMessageConverters() {
|
public HttpMessageConverters fastJsonHttpMessageConverters() {
|
||||||
FastJsonConfig config = new FastJsonConfig();
|
|
||||||
config.setSerializerFeatures(SerializerFeature.WriteMapNullValue,
|
|
||||||
SerializerFeature.WriteNullStringAsEmpty,
|
|
||||||
SerializerFeature.WriteEnumUsingName);
|
|
||||||
config.setDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
||||||
|
|
||||||
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
|
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
|
||||||
fastConverter.setFastJsonConfig(config);
|
fastConverter.setFastJsonConfig(CommonUtil.fastJsonConfig());
|
||||||
fastConverter.setDefaultCharset(StandardCharsets.UTF_8);
|
fastConverter.setDefaultCharset(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
List<MediaType> mediaTypes = new ArrayList<>();
|
List<MediaType> mediaTypes = new ArrayList<>();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import cn.hutool.core.map.MapUtil;
|
|||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.tiesheng.annotation.operation.OperationLog;
|
import com.tiesheng.annotation.operation.OperationLog;
|
||||||
import com.tiesheng.core.service.CoreLogService;
|
import com.tiesheng.core.service.CoreLogService;
|
||||||
|
import com.tiesheng.util.ServletKit;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.annotation.Around;
|
import org.aspectj.lang.annotation.Around;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
@@ -13,6 +14,7 @@ import org.aspectj.lang.reflect.MethodSignature;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -35,7 +37,7 @@ public class OperationAspect {
|
|||||||
CoreLogService coreLogService;
|
CoreLogService coreLogService;
|
||||||
|
|
||||||
|
|
||||||
@Pointcut("@annotation(com.tiesheng.annotation.operation.OperationLog)")
|
@Pointcut("execution(* com..controller..*.*(..))")
|
||||||
public void methodArgs() {
|
public void methodArgs() {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -48,11 +50,24 @@ public class OperationAspect {
|
|||||||
*/
|
*/
|
||||||
@Around("methodArgs()")
|
@Around("methodArgs()")
|
||||||
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
|
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
|
|
||||||
|
// GET请求不处理
|
||||||
|
HttpServletRequest request = ServletKit.getRequest();
|
||||||
|
if (StrUtil.equalsIgnoreCase(request.getMethod(), "GET")) {
|
||||||
|
return joinPoint.proceed(joinPoint.getArgs());
|
||||||
|
}
|
||||||
|
|
||||||
|
String title = "", subject = "";
|
||||||
|
String insertKey = "";
|
||||||
|
|
||||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||||
Method method = signature.getMethod();
|
Method method = signature.getMethod();
|
||||||
OperationLog operationLog = method.getAnnotation(OperationLog.class);
|
OperationLog operationLog = method.getAnnotation(OperationLog.class);
|
||||||
String subject = operationLog.subject();
|
if (operationLog != null) {
|
||||||
String insertKey = operationLog.insertKey();
|
title = operationLog.title();
|
||||||
|
subject = operationLog.subject();
|
||||||
|
insertKey = operationLog.insertKey();
|
||||||
|
}
|
||||||
|
|
||||||
Object reqObj = null;
|
Object reqObj = null;
|
||||||
Map<String, Object> allParams = new HashMap<>(16);
|
Map<String, Object> allParams = new HashMap<>(16);
|
||||||
@@ -65,7 +80,6 @@ public class OperationAspect {
|
|||||||
allParams.putAll(BeanUtil.beanToMap(response));
|
allParams.putAll(BeanUtil.beanToMap(response));
|
||||||
|
|
||||||
if (!StrUtil.isEmpty(subject)) {
|
if (!StrUtil.isEmpty(subject)) {
|
||||||
|
|
||||||
// 添加、编辑关键字处理
|
// 添加、编辑关键字处理
|
||||||
if (!StrUtil.isEmpty(insertKey)) {
|
if (!StrUtil.isEmpty(insertKey)) {
|
||||||
String insertVal = MapUtil.getStr(allParams, insertKey);
|
String insertVal = MapUtil.getStr(allParams, insertKey);
|
||||||
@@ -74,9 +88,12 @@ public class OperationAspect {
|
|||||||
|
|
||||||
// 占位符处理
|
// 占位符处理
|
||||||
subject = StrUtil.format(subject, allParams);
|
subject = StrUtil.format(subject, allParams);
|
||||||
|
} else {
|
||||||
|
title = method.getName();
|
||||||
|
subject = ServletKit.getRequest().getRequestURI();
|
||||||
}
|
}
|
||||||
|
|
||||||
coreLogService.addOperationLog(operationLog.title(), subject, reqObj);
|
coreLogService.addOperationLog(title, subject, reqObj);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,26 @@
|
|||||||
package com.tiesheng.core.controller;
|
package com.tiesheng.core.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.tiesheng.annotation.token.TokenIgnore;
|
import com.tiesheng.annotation.token.TokenIgnore;
|
||||||
import com.tiesheng.core.pojos.dao.CoreConfigEnum;
|
import com.tiesheng.core.pojos.dao.CoreConfigEnum;
|
||||||
|
import com.tiesheng.core.pojos.dao.CoreConfigFunc;
|
||||||
import com.tiesheng.core.pojos.dao.CoreConfigSystem;
|
import com.tiesheng.core.pojos.dao.CoreConfigSystem;
|
||||||
import com.tiesheng.core.pojos.dto.PageDTO;
|
import com.tiesheng.core.pojos.dto.PageDTO;
|
||||||
|
import com.tiesheng.core.pojos.dto.config.ConfigFuncDTO;
|
||||||
import com.tiesheng.core.pojos.dto.config.ConfigSystemDTO;
|
import com.tiesheng.core.pojos.dto.config.ConfigSystemDTO;
|
||||||
import com.tiesheng.core.pojos.dto.config.EnumTypeDTO;
|
import com.tiesheng.core.pojos.dto.config.EnumTypeDTO;
|
||||||
import com.tiesheng.core.service.CoreConfigService;
|
import com.tiesheng.core.service.CoreConfigService;
|
||||||
|
import com.tiesheng.core.service.TieshengWebConfigurer;
|
||||||
import com.tiesheng.util.exception.ApiException;
|
import com.tiesheng.util.exception.ApiException;
|
||||||
import com.tiesheng.util.pojos.ApiResp;
|
import com.tiesheng.util.pojos.ApiResp;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,6 +32,8 @@ public class ConfigController {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
CoreConfigService coreConfigService;
|
CoreConfigService coreConfigService;
|
||||||
|
@Autowired
|
||||||
|
TieshengWebConfigurer tieshengWebConfigurer;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,6 +75,8 @@ public class ConfigController {
|
|||||||
configKey.setConfigVal(dto.getConfigVal());
|
configKey.setConfigVal(dto.getConfigVal());
|
||||||
configKey.setRemark(dto.getRemark());
|
configKey.setRemark(dto.getRemark());
|
||||||
configKey.setExtra(dto.getExtra());
|
configKey.setExtra(dto.getExtra());
|
||||||
|
|
||||||
|
tieshengWebConfigurer.configSystemCheck(configKey);
|
||||||
coreConfigService.updateById(configKey);
|
coreConfigService.updateById(configKey);
|
||||||
|
|
||||||
return ApiResp.respOK("");
|
return ApiResp.respOK("");
|
||||||
@@ -95,4 +104,34 @@ public class ConfigController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 功能点列表
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/func/page")
|
||||||
|
public ApiResp<List<CoreConfigFunc>> funcList(Integer isUsed, PageDTO dto) {
|
||||||
|
QueryWrapper<CoreConfigFunc> queryWrapper = new QueryWrapper<CoreConfigFunc>().eq("is_deleted", 0);
|
||||||
|
if (isUsed != null) {
|
||||||
|
queryWrapper.eq("is_used", isUsed);
|
||||||
|
}
|
||||||
|
dto.likeColumns(queryWrapper, "name");
|
||||||
|
Page<CoreConfigFunc> page = dto.pageObj();
|
||||||
|
coreConfigService.getFuncMapper().selectPage(page, queryWrapper);
|
||||||
|
return ApiResp.respOK(page.getRecords(), page.getTotal());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 功能点更新
|
||||||
|
*
|
||||||
|
* @param dto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/func/update")
|
||||||
|
public ApiResp<String> funcUpdate(@Valid @RequestBody ConfigFuncDTO dto) {
|
||||||
|
CoreConfigFunc configFunc = BeanUtil.copyProperties(dto, CoreConfigFunc.class);
|
||||||
|
coreConfigService.getFuncMapper().updateById(configFunc);
|
||||||
|
return ApiResp.respOK("");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,120 @@
|
|||||||
|
package com.tiesheng.core.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.tiesheng.core.pojos.dao.CoreJob;
|
||||||
|
import com.tiesheng.core.pojos.dto.IdDTO;
|
||||||
|
import com.tiesheng.core.pojos.dto.PageDTO;
|
||||||
|
import com.tiesheng.core.pojos.dto.job.JobUpdateDTO;
|
||||||
|
import com.tiesheng.core.pojos.dto.job.JobUpdateRxDTO;
|
||||||
|
import com.tiesheng.core.pojos.dto.job.JobUserAssignDTO;
|
||||||
|
import com.tiesheng.core.pojos.dto.job.JobUserOwner;
|
||||||
|
import com.tiesheng.core.service.CoreJobService;
|
||||||
|
import com.tiesheng.login.config.token.TsTokenConfig;
|
||||||
|
import com.tiesheng.util.exception.ApiException;
|
||||||
|
import com.tiesheng.util.pojos.ApiResp;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/job")
|
||||||
|
public class JobController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CoreJobService coreJobService;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取职位列表
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/list")
|
||||||
|
public ApiResp<List<CoreJob>> list(PageDTO dto) {
|
||||||
|
QueryWrapper<CoreJob> queryWrapper = new QueryWrapper<CoreJob>().eq("is_deleted", 0);
|
||||||
|
dto.likeColumns(queryWrapper, "name");
|
||||||
|
List<CoreJob> jobList = coreJobService.list(queryWrapper);
|
||||||
|
return ApiResp.respOK(jobList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加、编辑职位
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/update")
|
||||||
|
public ApiResp<String> update(@Valid @RequestBody JobUpdateDTO dto) {
|
||||||
|
CoreJob job = BeanUtil.copyProperties(dto, CoreJob.class);
|
||||||
|
if (!StrUtil.isEmpty(job.getId())) {
|
||||||
|
CoreJob byId = coreJobService.getById(job.getId());
|
||||||
|
if (byId != null && byId.getIsSystem() == 1) {
|
||||||
|
throw new ApiException("系统配置,无法编辑");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
coreJobService.saveOrUpdate(job);
|
||||||
|
return ApiResp.respOK("");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取关系
|
||||||
|
*
|
||||||
|
* @param dto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/func/rx")
|
||||||
|
public ApiResp<List<String>> funcRx(@Valid IdDTO dto) {
|
||||||
|
List<String> list = coreJobService.getBaseMapper().getJobFunc(dto.getId(), null);
|
||||||
|
return ApiResp.respOK(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新职位关系
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/func/rx")
|
||||||
|
public ApiResp<String> updateJobRx(@Valid @RequestBody JobUpdateRxDTO dto) {
|
||||||
|
coreJobService.updateJobRx(dto.getJobId(), StrUtil.split(dto.getPoints(), ","));
|
||||||
|
return ApiResp.respOK("");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户职位分配
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/user/assign")
|
||||||
|
public ApiResp<String> userAssign(@Valid @RequestBody JobUserAssignDTO dto) {
|
||||||
|
coreJobService.userAssign(dto.getUserId(), dto.getJobId());
|
||||||
|
return ApiResp.respOK("");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户自己的
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/user/owner")
|
||||||
|
public ApiResp<List<JobUserOwner>> userOwner() {
|
||||||
|
List<JobUserOwner> coreJobUsers = coreJobService.getJobUserMapper().list(TsTokenConfig.get().getId());
|
||||||
|
coreJobUsers.forEach(it -> {
|
||||||
|
List<String> list = coreJobService.getBaseMapper().getJobFunc(it.getJobId(), 1);
|
||||||
|
it.setPoints(list);
|
||||||
|
});
|
||||||
|
return ApiResp.respOK(coreJobUsers);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,7 +6,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.tiesheng.core.pojos.dao.CoreLogLogin;
|
import com.tiesheng.core.pojos.dao.CoreLogLogin;
|
||||||
import com.tiesheng.core.pojos.dao.CoreLogMessage;
|
import com.tiesheng.core.pojos.dao.CoreLogMessage;
|
||||||
import com.tiesheng.core.pojos.dao.CoreLogOperation;
|
import com.tiesheng.core.pojos.dao.CoreLogOperation;
|
||||||
|
import com.tiesheng.core.pojos.dao.CoreLogProcess;
|
||||||
import com.tiesheng.core.pojos.dto.PageDTO;
|
import com.tiesheng.core.pojos.dto.PageDTO;
|
||||||
|
import com.tiesheng.core.pojos.vo.ProcessDetailVo;
|
||||||
import com.tiesheng.core.service.CoreLogService;
|
import com.tiesheng.core.service.CoreLogService;
|
||||||
import com.tiesheng.util.pojos.ApiResp;
|
import com.tiesheng.util.pojos.ApiResp;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -88,4 +90,36 @@ public class LogController {
|
|||||||
return ApiResp.respOK(page.getRecords(), page.getTotal());
|
return ApiResp.respOK(page.getRecords(), page.getTotal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 过程日志列表
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/process/page")
|
||||||
|
public ApiResp<List<CoreLogProcess>> processPage(String type, @Valid PageDTO dto) {
|
||||||
|
|
||||||
|
QueryWrapper<CoreLogProcess> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("is_deleted", 0);
|
||||||
|
if (!StrUtil.isEmpty(type)) {
|
||||||
|
queryWrapper.eq("type", type);
|
||||||
|
}
|
||||||
|
dto.likeColumns(queryWrapper, "title");
|
||||||
|
queryWrapper.orderByDesc("create_time");
|
||||||
|
|
||||||
|
Page<CoreLogProcess> page = dto.pageObj();
|
||||||
|
coreLogService.getCoreLogProcessMapper().selectPage(page, queryWrapper);
|
||||||
|
return ApiResp.respOK(page.getRecords(), page.getTotal());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 过程日志详情
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/process/detail")
|
||||||
|
public ApiResp<ProcessDetailVo> processPage(String id) {
|
||||||
|
ProcessDetailVo processDetail = coreLogService.getProcessDetail(id);
|
||||||
|
return ApiResp.respOK(processDetail);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ package com.tiesheng.core.controller;
|
|||||||
import cn.hutool.captcha.LineCaptcha;
|
import cn.hutool.captcha.LineCaptcha;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import com.tiesheng.annotation.token.TokenIgnore;
|
import com.tiesheng.annotation.token.TokenIgnore;
|
||||||
|
import com.tiesheng.core.pojos.dto.ChunkCheckDTO;
|
||||||
|
import com.tiesheng.core.pojos.dto.ChunkMergeDTO;
|
||||||
|
import com.tiesheng.core.pojos.dto.ChunkStartDTO;
|
||||||
import com.tiesheng.core.pojos.dto.ImageCodeDTO;
|
import com.tiesheng.core.pojos.dto.ImageCodeDTO;
|
||||||
import com.tiesheng.core.pojos.vo.PicVerifyVo;
|
import com.tiesheng.core.pojos.vo.PicVerifyVo;
|
||||||
import com.tiesheng.core.service.FileUploadService;
|
import com.tiesheng.core.service.FileUploadService;
|
||||||
@@ -68,8 +71,8 @@ public class ToolController {
|
|||||||
*/
|
*/
|
||||||
@TokenIgnore
|
@TokenIgnore
|
||||||
@PostMapping(value = "/file/chunk_start")
|
@PostMapping(value = "/file/chunk_start")
|
||||||
public ApiResp<String> fileChunkStart(String fileExt) {
|
public ApiResp<String> fileChunkStart(@RequestBody ChunkStartDTO dto) {
|
||||||
fileUploadService.chunkStart(fileExt);
|
fileUploadService.chunkStart(dto.getFileExt());
|
||||||
return ApiResp.respOK("");
|
return ApiResp.respOK("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,8 +84,8 @@ public class ToolController {
|
|||||||
*/
|
*/
|
||||||
@TokenIgnore
|
@TokenIgnore
|
||||||
@PostMapping("/file/chunk_check")
|
@PostMapping("/file/chunk_check")
|
||||||
public ApiResp<Boolean> fileChunkCheck(String fileMd5, Integer chunk) {
|
public ApiResp<Boolean> fileChunkCheck(@RequestBody ChunkCheckDTO dto) {
|
||||||
boolean exist = fileUploadService.chunkCheck(fileMd5, chunk);
|
boolean exist = fileUploadService.chunkCheck(dto.getFileMd5(), dto.getChunk());
|
||||||
return ApiResp.respOK(exist);
|
return ApiResp.respOK(exist);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,8 +111,8 @@ public class ToolController {
|
|||||||
*/
|
*/
|
||||||
@TokenIgnore
|
@TokenIgnore
|
||||||
@PostMapping("/file/chunk_merge")
|
@PostMapping("/file/chunk_merge")
|
||||||
public ApiResp<String> fileChunkMerge(String fileMd5, String fileExt) {
|
public ApiResp<String> fileChunkMerge(@RequestBody ChunkMergeDTO dto) {
|
||||||
String path = fileUploadService.chunkMerge(fileMd5, fileExt);
|
String path = fileUploadService.chunkMerge(dto.getFileMd5(), dto.getFileExt());
|
||||||
return ApiResp.respOK(path);
|
return ApiResp.respOK(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.tiesheng.core.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.tiesheng.core.pojos.dao.CoreConfigFunc;
|
||||||
|
import com.tiesheng.util.pojos.IdName;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface CoreConfigFuncMapper extends BaseMapper<CoreConfigFunc> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.tiesheng.core.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.tiesheng.core.pojos.dao.CoreJob;
|
||||||
|
import com.tiesheng.util.pojos.IdName;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface CoreJobMapper extends BaseMapper<CoreJob> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除职位的关联关系
|
||||||
|
*
|
||||||
|
* @param jobId
|
||||||
|
*/
|
||||||
|
void clearJobFunc(@Param("jobId") String jobId);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新关联关系
|
||||||
|
*
|
||||||
|
* @param pointList
|
||||||
|
*/
|
||||||
|
void updateJobFunc(@Param("list") List<IdName> pointList);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取关联的func
|
||||||
|
*
|
||||||
|
* @param jobId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<String> getJobFunc(@Param("jobId") String jobId, @Param("isUsed") Integer isUsed);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.tiesheng.core.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.tiesheng.core.pojos.dao.CoreJobUser;
|
||||||
|
import com.tiesheng.core.pojos.dto.job.JobUserOwner;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface CoreJobUserMapper extends BaseMapper<CoreJobUser> {
|
||||||
|
/**
|
||||||
|
* 获取指定用户的职位和功能点
|
||||||
|
*
|
||||||
|
* @param userId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<JobUserOwner> list(@Param("userId") String userId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.tiesheng.core.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.tiesheng.core.pojos.dao.CoreLogProcess;
|
||||||
|
|
||||||
|
public interface CoreLogProcessMapper extends BaseMapper<CoreLogProcess> {
|
||||||
|
}
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
package com.tiesheng.core.pojos;
|
package com.tiesheng.core.pojos;
|
||||||
|
|
||||||
public class CurrentWebUser {
|
/**
|
||||||
|
* 当前token的数据
|
||||||
|
*
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
public class RequestUserInfo {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
private String name;
|
private String name;
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package com.tiesheng.core.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.core.pojos.DaoBase;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 职位-功能点
|
||||||
|
*/
|
||||||
|
@TableName(value = "core_config_func")
|
||||||
|
public class CoreConfigFunc extends DaoBase {
|
||||||
|
/**
|
||||||
|
* 业务
|
||||||
|
*/
|
||||||
|
@TableField(value = "service")
|
||||||
|
private String service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 名称
|
||||||
|
*/
|
||||||
|
@TableField(value = "`name`")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 其他说明
|
||||||
|
*/
|
||||||
|
@TableField(value = "remark")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否启用
|
||||||
|
*/
|
||||||
|
@TableField(value = "is_used")
|
||||||
|
private Integer isUsed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取业务
|
||||||
|
*
|
||||||
|
* @return service - 业务
|
||||||
|
*/
|
||||||
|
public String getService() {
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置业务
|
||||||
|
*
|
||||||
|
* @param service 业务
|
||||||
|
*/
|
||||||
|
public void setService(String service) {
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取名称
|
||||||
|
*
|
||||||
|
* @return name - 名称
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置名称
|
||||||
|
*
|
||||||
|
* @param name 名称
|
||||||
|
*/
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取其他说明
|
||||||
|
*
|
||||||
|
* @return remark - 其他说明
|
||||||
|
*/
|
||||||
|
public String getRemark() {
|
||||||
|
return remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置其他说明
|
||||||
|
*
|
||||||
|
* @param remark 其他说明
|
||||||
|
*/
|
||||||
|
public void setRemark(String remark) {
|
||||||
|
this.remark = remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取是否启用
|
||||||
|
*
|
||||||
|
* @return is_used - 是否启用
|
||||||
|
*/
|
||||||
|
public Integer getIsUsed() {
|
||||||
|
return isUsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置是否启用
|
||||||
|
*
|
||||||
|
* @param isUsed 是否启用
|
||||||
|
*/
|
||||||
|
public void setIsUsed(Integer isUsed) {
|
||||||
|
this.isUsed = isUsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package com.tiesheng.core.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.core.pojos.DaoBase;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 职位
|
||||||
|
*/
|
||||||
|
@TableName(value = "core_job")
|
||||||
|
public class CoreJob extends DaoBase {
|
||||||
|
/**
|
||||||
|
* 名称
|
||||||
|
*/
|
||||||
|
@TableField(value = "`name`")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 其他说明
|
||||||
|
*/
|
||||||
|
@TableField(value = "remark")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否系统
|
||||||
|
*/
|
||||||
|
@TableField(value = "is_system")
|
||||||
|
private Integer isSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取名称
|
||||||
|
*
|
||||||
|
* @return name - 名称
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置名称
|
||||||
|
*
|
||||||
|
* @param name 名称
|
||||||
|
*/
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取其他说明
|
||||||
|
*
|
||||||
|
* @return remark - 其他说明
|
||||||
|
*/
|
||||||
|
public String getRemark() {
|
||||||
|
return remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置其他说明
|
||||||
|
*
|
||||||
|
* @param remark 其他说明
|
||||||
|
*/
|
||||||
|
public void setRemark(String remark) {
|
||||||
|
this.remark = remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取是否系统
|
||||||
|
*
|
||||||
|
* @return is_system - 是否系统
|
||||||
|
*/
|
||||||
|
public Integer getIsSystem() {
|
||||||
|
return isSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置是否系统
|
||||||
|
*
|
||||||
|
* @param isSystem 是否系统
|
||||||
|
*/
|
||||||
|
public void setIsSystem(Integer isSystem) {
|
||||||
|
this.isSystem = isSystem;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
package com.tiesheng.core.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.core.pojos.DaoBase;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 职位-用户
|
||||||
|
*/
|
||||||
|
@TableName(value = "core_job_user")
|
||||||
|
public class CoreJobUser extends DaoBase {
|
||||||
|
/**
|
||||||
|
* 用户id
|
||||||
|
*/
|
||||||
|
@TableField(value = "user_id")
|
||||||
|
private String userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户
|
||||||
|
*/
|
||||||
|
@TableField(value = "job_id")
|
||||||
|
private String jobId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扩展1
|
||||||
|
*/
|
||||||
|
@TableField(value = "ext1")
|
||||||
|
private String ext1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扩展2
|
||||||
|
*/
|
||||||
|
@TableField(value = "ext2")
|
||||||
|
private String ext2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扩展3
|
||||||
|
*/
|
||||||
|
@TableField(value = "ext3")
|
||||||
|
private String ext3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扩展文本
|
||||||
|
*/
|
||||||
|
@TableField(value = "ext_text")
|
||||||
|
private String extText;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户id
|
||||||
|
*
|
||||||
|
* @return user_id - 用户id
|
||||||
|
*/
|
||||||
|
public String getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置用户id
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
*/
|
||||||
|
public void setUserId(String userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户
|
||||||
|
*
|
||||||
|
* @return job_id - 用户
|
||||||
|
*/
|
||||||
|
public String getJobId() {
|
||||||
|
return jobId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置用户
|
||||||
|
*
|
||||||
|
* @param jobId 用户
|
||||||
|
*/
|
||||||
|
public void setJobId(String jobId) {
|
||||||
|
this.jobId = jobId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取扩展1
|
||||||
|
*
|
||||||
|
* @return ext1 - 扩展1
|
||||||
|
*/
|
||||||
|
public String getExt1() {
|
||||||
|
return ext1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置扩展1
|
||||||
|
*
|
||||||
|
* @param ext1 扩展1
|
||||||
|
*/
|
||||||
|
public void setExt1(String ext1) {
|
||||||
|
this.ext1 = ext1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取扩展2
|
||||||
|
*
|
||||||
|
* @return ext2 - 扩展2
|
||||||
|
*/
|
||||||
|
public String getExt2() {
|
||||||
|
return ext2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置扩展2
|
||||||
|
*
|
||||||
|
* @param ext2 扩展2
|
||||||
|
*/
|
||||||
|
public void setExt2(String ext2) {
|
||||||
|
this.ext2 = ext2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取扩展3
|
||||||
|
*
|
||||||
|
* @return ext3 - 扩展3
|
||||||
|
*/
|
||||||
|
public String getExt3() {
|
||||||
|
return ext3;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置扩展3
|
||||||
|
*
|
||||||
|
* @param ext3 扩展3
|
||||||
|
*/
|
||||||
|
public void setExt3(String ext3) {
|
||||||
|
this.ext3 = ext3;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取扩展文本
|
||||||
|
*
|
||||||
|
* @return ext_text - 扩展文本
|
||||||
|
*/
|
||||||
|
public String getExtText() {
|
||||||
|
return extText;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置扩展文本
|
||||||
|
*
|
||||||
|
* @param extText 扩展文本
|
||||||
|
*/
|
||||||
|
public void setExtText(String extText) {
|
||||||
|
this.extText = extText;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,230 @@
|
|||||||
|
package com.tiesheng.core.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.core.pojos.DaoBase;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志-过程
|
||||||
|
*/
|
||||||
|
@TableName(value = "core_log_process")
|
||||||
|
public class CoreLogProcess extends DaoBase {
|
||||||
|
/**
|
||||||
|
* 标题
|
||||||
|
*/
|
||||||
|
@TableField(value = "title")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总数
|
||||||
|
*/
|
||||||
|
@TableField(value = "total")
|
||||||
|
private Integer total;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功数
|
||||||
|
*/
|
||||||
|
@TableField(value = "success_num")
|
||||||
|
private Integer successNum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败数
|
||||||
|
*/
|
||||||
|
@TableField(value = "fail_num")
|
||||||
|
private Integer failNum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型(import-导入,sync-同步)
|
||||||
|
*/
|
||||||
|
@TableField(value = "`type`")
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态(0-未完成,1-已完成)
|
||||||
|
*/
|
||||||
|
@TableField(value = "`status`")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败的文件
|
||||||
|
*/
|
||||||
|
@TableField(value = "fail_file")
|
||||||
|
private String failFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异常说明
|
||||||
|
*/
|
||||||
|
@TableField(value = "error")
|
||||||
|
private String error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 进度
|
||||||
|
*/
|
||||||
|
@TableField(value = "`process`")
|
||||||
|
private Integer process;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取标题
|
||||||
|
*
|
||||||
|
* @return title - 标题
|
||||||
|
*/
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置标题
|
||||||
|
*
|
||||||
|
* @param title 标题
|
||||||
|
*/
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取总数
|
||||||
|
*
|
||||||
|
* @return total - 总数
|
||||||
|
*/
|
||||||
|
public Integer getTotal() {
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置总数
|
||||||
|
*
|
||||||
|
* @param total 总数
|
||||||
|
*/
|
||||||
|
public void setTotal(Integer total) {
|
||||||
|
this.total = total;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取成功数
|
||||||
|
*
|
||||||
|
* @return success_num - 成功数
|
||||||
|
*/
|
||||||
|
public Integer getSuccessNum() {
|
||||||
|
return successNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置成功数
|
||||||
|
*
|
||||||
|
* @param successNum 成功数
|
||||||
|
*/
|
||||||
|
public void setSuccessNum(Integer successNum) {
|
||||||
|
this.successNum = successNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取失败数
|
||||||
|
*
|
||||||
|
* @return fail_num - 失败数
|
||||||
|
*/
|
||||||
|
public Integer getFailNum() {
|
||||||
|
return failNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置失败数
|
||||||
|
*
|
||||||
|
* @param failNum 失败数
|
||||||
|
*/
|
||||||
|
public void setFailNum(Integer failNum) {
|
||||||
|
this.failNum = failNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取类型(import-导入,sync-同步)
|
||||||
|
*
|
||||||
|
* @return type - 类型(import-导入,sync-同步)
|
||||||
|
*/
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置类型(import-导入,sync-同步)
|
||||||
|
*
|
||||||
|
* @param type 类型(import-导入,sync-同步)
|
||||||
|
*/
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取状态(0-未完成,1-已完成)
|
||||||
|
*
|
||||||
|
* @return status - 状态(0-未完成,1-已完成)
|
||||||
|
*/
|
||||||
|
public Integer getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置状态(0-未完成,1-已完成)
|
||||||
|
*
|
||||||
|
* @param status 状态(0-未完成,1-已完成)
|
||||||
|
*/
|
||||||
|
public void setStatus(Integer status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取失败的文件
|
||||||
|
*
|
||||||
|
* @return fail_file - 失败的文件
|
||||||
|
*/
|
||||||
|
public String getFailFile() {
|
||||||
|
return failFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置失败的文件
|
||||||
|
*
|
||||||
|
* @param failFile 失败的文件
|
||||||
|
*/
|
||||||
|
public void setFailFile(String failFile) {
|
||||||
|
this.failFile = failFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取异常说明
|
||||||
|
*
|
||||||
|
* @return error - 异常说明
|
||||||
|
*/
|
||||||
|
public String getError() {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置异常说明
|
||||||
|
*
|
||||||
|
* @param error 异常说明
|
||||||
|
*/
|
||||||
|
public void setError(String error) {
|
||||||
|
this.error = error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取进度
|
||||||
|
*
|
||||||
|
* @return process - 进度
|
||||||
|
*/
|
||||||
|
public Integer getProcess() {
|
||||||
|
return process;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置进度
|
||||||
|
*
|
||||||
|
* @param process 进度
|
||||||
|
*/
|
||||||
|
public void setProcess(Integer process) {
|
||||||
|
this.process = process;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.tiesheng.core.pojos.dto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
public class ChunkCheckDTO {
|
||||||
|
|
||||||
|
private String fileMd5;
|
||||||
|
private Integer chunk;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// setter\getter
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public String getFileMd5() {
|
||||||
|
return fileMd5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileMd5(String fileMd5) {
|
||||||
|
this.fileMd5 = fileMd5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getChunk() {
|
||||||
|
return chunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChunk(Integer chunk) {
|
||||||
|
this.chunk = chunk;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.tiesheng.core.pojos.dto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
public class ChunkMergeDTO {
|
||||||
|
|
||||||
|
private String fileMd5;
|
||||||
|
private String fileExt;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// setter\getter
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public String getFileMd5() {
|
||||||
|
return fileMd5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileMd5(String fileMd5) {
|
||||||
|
this.fileMd5 = fileMd5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileExt() {
|
||||||
|
return fileExt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileExt(String fileExt) {
|
||||||
|
this.fileExt = fileExt;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.tiesheng.core.pojos.dto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
public class ChunkStartDTO {
|
||||||
|
|
||||||
|
private String fileExt;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// setter\getter
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public String getFileExt() {
|
||||||
|
return fileExt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileExt(String fileExt) {
|
||||||
|
this.fileExt = fileExt;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.tiesheng.core.pojos.dto;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
|
||||||
|
public class IdDTO {
|
||||||
|
|
||||||
|
@NotEmpty(message = "需要ID")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// setter\getter
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.tiesheng.core.pojos.dto.config;
|
||||||
|
|
||||||
|
public class ConfigFuncDTO {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
private String remark;
|
||||||
|
private Integer isUsed;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// setter\getter
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRemark() {
|
||||||
|
return remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemark(String remark) {
|
||||||
|
this.remark = remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getIsUsed() {
|
||||||
|
return isUsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsUsed(Integer isUsed) {
|
||||||
|
this.isUsed = isUsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.tiesheng.core.pojos.dto.job;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
|
||||||
|
public class JobUpdateDTO {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@NotEmpty(message = "请输入职位名称")
|
||||||
|
private String name;
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// setter\getter
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRemark() {
|
||||||
|
return remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemark(String remark) {
|
||||||
|
this.remark = remark;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.tiesheng.core.pojos.dto.job;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
|
||||||
|
public class JobUpdateRxDTO {
|
||||||
|
|
||||||
|
@NotEmpty(message = "请选择职位")
|
||||||
|
private String jobId;
|
||||||
|
private String points;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// setter\getter
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public String getJobId() {
|
||||||
|
return jobId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJobId(String jobId) {
|
||||||
|
this.jobId = jobId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPoints() {
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPoints(String points) {
|
||||||
|
this.points = points;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.tiesheng.core.pojos.dto.job;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
|
||||||
|
public class JobUserAssignDTO {
|
||||||
|
|
||||||
|
@NotEmpty(message = "请选择用户")
|
||||||
|
private String userId;
|
||||||
|
@NotEmpty(message = "请选择职位")
|
||||||
|
private String jobId;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// setter\getter
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public String getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserId(String userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getJobId() {
|
||||||
|
return jobId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJobId(String jobId) {
|
||||||
|
this.jobId = jobId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.tiesheng.core.pojos.dto.job;
|
||||||
|
|
||||||
|
import com.tiesheng.util.pojos.IdName;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class JobUserOwner {
|
||||||
|
|
||||||
|
private String jobId;
|
||||||
|
private String jobName;
|
||||||
|
private List<String> points;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// setter\getter
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public String getJobId() {
|
||||||
|
return jobId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJobId(String jobId) {
|
||||||
|
this.jobId = jobId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getJobName() {
|
||||||
|
return jobName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJobName(String jobName) {
|
||||||
|
this.jobName = jobName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getPoints() {
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPoints(List<String> points) {
|
||||||
|
this.points = points;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
package com.tiesheng.core.pojos.vo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lgc
|
||||||
|
*/
|
||||||
|
public class ProcessDetailVo {
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
private Integer total;
|
||||||
|
|
||||||
|
private Integer successNum;
|
||||||
|
|
||||||
|
private Integer failNum;
|
||||||
|
|
||||||
|
private Integer process;
|
||||||
|
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
private String failFile;
|
||||||
|
|
||||||
|
private String error;
|
||||||
|
|
||||||
|
public Integer getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(Integer status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getTotal() {
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotal(Integer total) {
|
||||||
|
this.total = total;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getSuccessNum() {
|
||||||
|
return successNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSuccessNum(Integer successNum) {
|
||||||
|
this.successNum = successNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getFailNum() {
|
||||||
|
return failNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFailNum(Integer failNum) {
|
||||||
|
this.failNum = failNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFailFile() {
|
||||||
|
return failFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFailFile(String failFile) {
|
||||||
|
this.failFile = failFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getProcess() {
|
||||||
|
return process;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProcess(Integer process) {
|
||||||
|
this.process = process;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getError() {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setError(String error) {
|
||||||
|
this.error = error;
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user