Compare commits

...

17 Commits

Author SHA1 Message Date
曾文豪
919cd47623 publish 2.0.10 2024-09-23 15:50:36 +08:00
曾文豪
eb1c20b033 feat:授权增加一个备注字段 2024-09-19 14:13:13 +08:00
曾文豪
c1559e96be publish 2.0.9 2024-09-18 23:09:53 +08:00
曾文豪
9ef7d2d4a2 publish 2.0.8 2024-09-18 22:59:28 +08:00
曾文豪
b90e92f4cb perf: token兼容旧版本,旧版本使用的是10位数的秒作为数据 2024-09-18 22:59:10 +08:00
曾文豪
cb816d0ff0 publish 2.0.7 2024-09-18 17:27:45 +08:00
曾文豪
0470ca0b9a perf:空指针调整 2024-09-18 17:25:19 +08:00
曾文豪
d38077b0f8 perf:代码调整 2024-09-18 17:13:40 +08:00
曾文豪
2621c6dedc perf:可以不实现TsAuthorityHandler类 2024-09-18 16:47:29 +08:00
曾文豪
456a95778c publish 2.0.6 2024-09-18 16:30:49 +08:00
曾文豪
fd0976a30c Merge remote-tracking branch 'origin/master'
# Conflicts:
#	springboot-ademo/src/main/java/com/tiesheng/demo/controller/TestController.java
2024-09-18 14:53:10 +08:00
曾文豪
e519781207 fix:职位授权增加非空校验 2024-09-18 14:52:48 +08:00
曾文豪
e602f4c658 publish 2.0.5 2024-09-14 22:57:37 +08:00
曾文豪
a816acaddb fix:修复网络请求异常时,api日志记录不完整的bug 2024-09-14 22:57:03 +08:00
曾文豪
278429157a perf:钉钉单次同步调整为200 2024-09-14 22:38:07 +08:00
曾文豪
143b100819 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	springboot-platform/src/main/java/com/tiesheng/platform/config/ding/PlatformDingConfig.java
2024-09-14 22:36:38 +08:00
曾文豪
d0cd9aed0b perf:钉钉单次同步调整为200 2024-09-14 22:35:56 +08:00
32 changed files with 159 additions and 76 deletions

BIN
.DS_Store vendored

Binary file not shown.

18
pom.xml
View File

@@ -6,7 +6,7 @@
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.4</version>
<version>2.0.10</version>
<packaging>pom</packaging>
<name>springboot-parent</name>
<description>杭州铁晟科技有限公司基础依赖</description>
@@ -58,49 +58,49 @@
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-database</artifactId>
<version>2.0.4</version>
<version>2.0.10</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-login</artifactId>
<version>2.0.4</version>
<version>2.0.10</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-web</artifactId>
<version>2.0.4</version>
<version>2.0.10</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-util</artifactId>
<version>2.0.4</version>
<version>2.0.10</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-platform</artifactId>
<version>2.0.4</version>
<version>2.0.10</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-message</artifactId>
<version>2.0.4</version>
<version>2.0.10</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-role</artifactId>
<version>2.0.4</version>
<version>2.0.10</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-annotation</artifactId>
<version>2.0.4</version>
<version>2.0.10</version>
</dependency>
<dependency>

31
qodana.yaml Normal file
View File

@@ -0,0 +1,31 @@
#-------------------------------------------------------------------------------#
# Qodana analysis is configured by qodana.yaml file #
# https://www.jetbrains.com/help/qodana/qodana-yaml.html #
#-------------------------------------------------------------------------------#
version: "1.0"
#Specify inspection profile for code analysis
profile:
name: qodana.starter
#Enable inspections
#include:
# - name: <SomeEnabledInspectionId>
#Disable inspections
#exclude:
# - name: <SomeDisabledInspectionId>
# paths:
# - <path/where/not/run/inspection>
projectJDK: 17 #(Applied in CI/CD pipeline)
#Execute shell command before Qodana execution (Applied in CI/CD pipeline)
#bootstrap: sh ./prepare-qodana.sh
#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline)
#plugins:
# - id: <plugin.id> #(plugin id can be found at https://plugins.jetbrains.com)
#Specify Qodana linter for analysis (Applied in CI/CD pipeline)
linter: jetbrains/qodana-jvm:latest

View File

@@ -6,11 +6,11 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.4</version>
<version>2.0.10</version>
</parent>
<artifactId>springboot-ademo</artifactId>
<version>2.0.4</version>
<version>2.0.10</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>

View File

@@ -16,10 +16,6 @@ import java.util.Objects;
@Component
public class DemoWebConfigurer implements TieshengWebConfigurer, TsLoginConfigurer {
@Autowired
GlobalConfig globalConfig;
@Override
public RequestUserInfo getCurrentUserName(TokenBean tokenBean) {
RequestUserInfo info = new RequestUserInfo();

View File

@@ -1,8 +1,6 @@
package com.tiesheng.demo.config;
import com.tiesheng.web.service.CoreConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@@ -13,9 +11,6 @@ import javax.annotation.PostConstruct;
@Component
public class TestJobConfig {
@Autowired
CoreConfigService coreConfigService;
@PostConstruct
public void init() {
}

View File

@@ -84,6 +84,9 @@ public class TestController {
String jsonString = JSON.toJSONString(jsonTest);
LogFactory.get().info(jsonString);
String s = OkHttpUtil.get("http://toolbox.tieshengkeji.com/test/login/23232/3232");
LogFactory.get().info(s);
// ArrayList<String> strings = CollUtil.newArrayList("11111", "22222");
// coreLogService.addProcess("fdfd", strings, new ProcessImportConsumer<String>() {
// @Override
@@ -216,8 +219,10 @@ public class TestController {
"83_7xqG36kdgwuf8zzWLY3jtz7bg4ucziN-0oxbE0X9zBzwbjZ4S4Ss2RM9uHeSIcRp2K-wEp6MLzWhqo2AXj0Jpzd6IiJdUsRxqdHPvEWqAdOgt83vzZwdDf7tZBkGNGeAFASZS",
paramJson);
Response execute1 = OkHttpUtil.ofHttpClient().build().newCall(request).execute();
FileUtil.writeFromStream(execute1.body().byteStream(), file.getAbsolutePath());
execute1.close();
if (execute1.body() != null) {
FileUtil.writeFromStream(execute1.body().byteStream(), file.getAbsolutePath());
execute1.close();
}
} catch (Exception e) {
throw new ApiException("每分钟最多生成5000个二维码请稍后再试");
}

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.4</version>
<version>2.0.10</version>
</parent>
<artifactId>springboot-annotation</artifactId>

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.4</version>
<version>2.0.10</version>
</parent>
<artifactId>springboot-database</artifactId>

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.4</version>
<version>2.0.10</version>
</parent>
<artifactId>springboot-login</artifactId>

View File

@@ -20,8 +20,7 @@ public class DoLoginInfo {
this.info = info;
// 设置IP
HttpServletRequest request = ServletKit.getRequest();
this.loginIp = ServletKit.getClientIP(request);
this.loginIp = ServletKit.getClientIP();
}
///////////////////////////////////////////////////////////////////////////

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.4</version>
<version>2.0.10</version>
</parent>
<artifactId>springboot-message</artifactId>

View File

@@ -99,7 +99,7 @@ public class AliyunSmsSender implements TsMessageSender {
String signature = specialUrlEncode(digest);
queryMap.put("Signature", signature);
String respBody = "";
String respBody;
try {
respBody = OkHttpUtil.get(ENDPOINT + "?Signature=" + signature + sortQueryStringTmp);
} catch (Exception e) {

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.4</version>
<version>2.0.10</version>
</parent>
<artifactId>springboot-platform</artifactId>

View File

@@ -76,15 +76,16 @@ public class PlatformDingConfig {
request = OkHttpUtil.ofPost(url, body);
}
request = request.newBuilder().header("x-acs-dingtalk-access-token", accessToken).build();
try {
Response response = OkHttpUtil.ofHttpClient().build().newCall(request).execute();
try (Response response = OkHttpUtil.ofHttpClient().build().newCall(request).execute()) {
if (response.isSuccessful() && response.body() != null) {
String rawBody = response.body().string();
DingResponse<T> bean = JSON.parseObject(rawBody, typeReference);
bean.setRawBody(rawBody);
return bean;
} else {
LogFactory.get().info(response.body().string());
if (response.body() != null) {
LogFactory.get().info(response.body().string());
}
}
} catch (Exception e) {
LogFactory.get().error(e);

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.4</version>
<version>2.0.10</version>
</parent>
<artifactId>springboot-role</artifactId>

View File

@@ -30,6 +30,12 @@ public class CoreRoleUser extends DaoBase {
@TableField(value = "type_id")
private String typeId;
/**
* 说明
*/
@TableField(value = "remark")
private String remark;
/**
* 过期时间,无则不过期
*/
@@ -108,6 +114,14 @@ public class CoreRoleUser extends DaoBase {
this.typeId = typeId;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
/**
* 获取过期时间,无则不过期
*
@@ -179,4 +193,4 @@ public class CoreRoleUser extends DaoBase {
public void setExt3(String ext3) {
this.ext3 = ext3;
}
}
}

View File

@@ -138,7 +138,6 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
coreRoleGroupRxMapper.batchInsert(list);
onRoleChange(dto.getId(), "");
}
}
@@ -148,6 +147,9 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
* @param roleUser
*/
public void roleUserUpdate(CoreRoleUser roleUser) {
Validator.validateNotEmpty(roleUser.getType(), "请选择授权方式");
Validator.validateNotEmpty(roleUser.getTypeId(), "请选择授权" + (Objects.equals(roleUser.getType(), "menu") ? "菜单" : "职位"));
if (StrUtil.isNotEmpty(roleUser.getId())) {
coreRoleUserMapper.updateById(roleUser);
} else {

View File

@@ -108,4 +108,7 @@ alter table core_role_authority
alter table core_role_group_rx
add type varchar(10) null comment '关联类型dep-依赖bind-绑定';
alter table core_role_user
add remark varchar(500) null comment '说明' after type_id;
SET FOREIGN_KEY_CHECKS = 1;

View File

@@ -11,6 +11,7 @@
<result column="user_id" jdbcType="VARCHAR" property="userId" />
<result column="type" jdbcType="VARCHAR" property="type" />
<result column="type_id" jdbcType="VARCHAR" property="typeId" />
<result column="remark" jdbcType="VARCHAR" property="remark" />
<result column="expire_time" jdbcType="TIMESTAMP" property="expireTime" />
<result column="ext1" jdbcType="VARCHAR" property="ext1" />
<result column="ext2" jdbcType="VARCHAR" property="ext2" />
@@ -18,7 +19,7 @@
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
id, create_time, update_time, is_deleted, user_id, `type`, type_id, expire_time,
id, create_time, update_time, is_deleted, user_id, `type`, type_id, remark, expire_time,
ext1, ext2, ext3
</sql>

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.4</version>
<version>2.0.10</version>
</parent>
<artifactId>springboot-util</artifactId>

View File

@@ -17,7 +17,25 @@ public class ServletKit extends ServletUtil {
public static HttpServletRequest getRequest() {
ServletRequestAttributes attributes = (ServletRequestAttributes)
RequestContextHolder.getRequestAttributes();
return attributes.getRequest();
if (attributes != null) {
return attributes.getRequest();
}
return null;
}
/**
* 获取请求头
*
* @param name 请求头
* @return 请求头
*/
public static String getHeader(String name) {
HttpServletRequest request = getRequest();
if (request == null) {
return "";
}
return getHeader(request, name, "utf-8");
}
/**
@@ -27,6 +45,9 @@ public class ServletKit extends ServletUtil {
*/
public static String getClientIP() {
HttpServletRequest request = getRequest();
if (request == null) {
return "";
}
return getClientIP(request);
}

View File

@@ -384,7 +384,7 @@ public class JWT implements RegisteredPayload<JWT> {
* @since 5.7.4
*/
public boolean validate(long leeway) {
if (false == verify()) {
if (!verify()) {
return false;
}

View File

@@ -2,6 +2,7 @@ package com.tiesheng.util.jwt;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.exceptions.ValidateException;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.tiesheng.util.jwt.signers.JWTSigner;
import com.tiesheng.util.jwt.signers.NoneJWTSigner;
@@ -160,13 +161,13 @@ public class JWTValidator {
}
final String algorithmIdInSigner = signer.getAlgorithmId();
if (false == StrUtil.equals(algorithmId, algorithmIdInSigner)) {
if (!StrUtil.equals(algorithmId, algorithmIdInSigner)) {
throw new ValidateException("Algorithm [{}] defined in header doesn't match to [{}]!"
, algorithmId, algorithmIdInSigner);
}
// 通过算法验证签名是否正确
if (false == jwt.verify(signer)) {
if (!jwt.verify(signer)) {
throw new ValidateException("Signature verification failed!");
}
}
@@ -200,7 +201,10 @@ public class JWTValidator {
validateNotAfter(JWTPayload.NOT_BEFORE, notBefore, now, leeway);
// 检查失效时间(失效时间不能早于当前时间)
final Date expiresAt = payload.getClaimsJson().getDate(JWTPayload.EXPIRES_AT);
// 这里兼容一下旧版本旧版本使用的是10位数的秒作为数据
String string = payload.getClaimsJson().getString(JWTPayload.EXPIRES_AT);
Date expiresAt = StrUtil.length(string) == 10 ? DateUtil.date(NumberUtil.parseLong(string) * 1000L)
: DateUtil.parse(string);
validateNotBefore(JWTPayload.EXPIRES_AT, expiresAt, now, leeway);
// 检查签发时间(签发时间不能晚于当前时间)

View File

@@ -84,7 +84,7 @@ public class TsCacheService {
* 验证 图片验证码
*/
public void verifyCaptcha(String value) {
String captchaKey = ServletUtil.getHeader(ServletKit.getRequest(), "captcha", "utf-8");
String captchaKey = ServletKit.getHeader("captcha");
String cache = get(captchaKey);
if (StrUtil.isEmpty(cache) || !StrUtil.equals(cache, value)) {
throw new ApiException("验证码不正确");

View File

@@ -10,7 +10,7 @@ import java.util.Set;
import java.util.stream.Collectors;
@Configuration
@ConditionalOnMissingBean(value = TsCacheHandler.class, ignored = {TsCacheTimedHandler.class, TsCacheTimedHandler.class})
@ConditionalOnMissingBean(value = TsCacheHandler.class, ignored = {TsCacheTimedHandler.class})
public class TsCacheTimedHandler implements TsCacheHandler {
private static volatile TimedCache<String, String> timedCache;

View File

@@ -83,9 +83,11 @@ public class OkHttpUtil {
}
public static String get(String urlString, int timeout) {
try {
return ofHttpClient().connectTimeout(timeout, TimeUnit.MILLISECONDS)
.build().newCall(ofGet(urlString)).execute().body().string();
try (Response execute = ofHttpClient().connectTimeout(timeout, TimeUnit.MILLISECONDS)
.build().newCall(ofGet(urlString)).execute()) {
if (execute.body() != null) {
return execute.body().string();
}
} catch (IOException ignored) {
}
return null;
@@ -117,9 +119,11 @@ public class OkHttpUtil {
}
public static String post(String urlString, RequestBody body, int timeout) {
try {
return ofHttpClient().connectTimeout(timeout, TimeUnit.MILLISECONDS)
.build().newCall(ofPost(urlString, body)).execute().body().string();
try (Response response = ofHttpClient().connectTimeout(timeout, TimeUnit.MILLISECONDS)
.build().newCall(ofPost(urlString, body)).execute()) {
if (response.body() != null) {
return response.body().string();
}
} catch (IOException ignored) {
}
return null;
@@ -135,11 +139,10 @@ public class OkHttpUtil {
}
public static File downloadFile(String url, File destFile) {
try {
Response response = ofHttpClient()
.connectTimeout(0, TimeUnit.MILLISECONDS)
.readTimeout(0, TimeUnit.MILLISECONDS)
.build().newCall(ofGet(url)).execute();
try (Response response = ofHttpClient()
.connectTimeout(0, TimeUnit.MILLISECONDS)
.readTimeout(0, TimeUnit.MILLISECONDS)
.build().newCall(ofGet(url)).execute()) {
if (response.isSuccessful() && response.body() != null) {
FileUtil.writeFromStream(response.body().byteStream(), destFile);
}
@@ -150,11 +153,10 @@ public class OkHttpUtil {
}
public static byte[] downloadBytes(String url) {
try {
Response response = ofHttpClient()
.connectTimeout(0, TimeUnit.MILLISECONDS)
.readTimeout(0, TimeUnit.MILLISECONDS)
.build().newCall(ofGet(url)).execute();
try (Response response = ofHttpClient()
.connectTimeout(0, TimeUnit.MILLISECONDS)
.readTimeout(0, TimeUnit.MILLISECONDS)
.build().newCall(ofGet(url)).execute()) {
if (response.isSuccessful() && response.body() != null) {
return response.body().bytes();
}

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.4</version>
<version>2.0.10</version>
</parent>
<artifactId>springboot-web</artifactId>

View File

@@ -56,8 +56,12 @@ public class OperationAspect {
@Around("methodArgs()")
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
// GET请求不处理
HttpServletRequest request = ServletKit.getRequest();
if (request == null) {
return joinPoint.proceed();
}
// GET请求不处理
if (StrUtil.equalsIgnoreCase(request.getMethod(), "GET")) {
return joinPoint.proceed(joinPoint.getArgs());
}

View File

@@ -15,6 +15,7 @@ import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@@ -24,6 +25,7 @@ import java.util.stream.Collectors;
@Aspect
@Component
@ConditionalOnBean(value = TsAuthorityHandler.class)
public class RoleAuthorityAspect {
@Resource

View File

@@ -5,12 +5,13 @@ import cn.hutool.core.date.DateUtil;
import com.tiesheng.annotation.role.RoleAuthority;
import com.tiesheng.util.service.role.TsAuthorityHandler;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
@@ -18,19 +19,15 @@ import java.util.List;
import java.util.Map;
@Service
@ConditionalOnBean(value = TsAuthorityHandler.class)
public class RoleAuthorityCreator implements ApplicationListener<ContextRefreshedEvent> {
@Autowired(required = false)
@Resource
TsAuthorityHandler tsAuthorityHandler;
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
if (tsAuthorityHandler == null) {
return;
}
ApplicationContext applicationContext = event.getApplicationContext();
Map<String, Object> beansOfType = applicationContext.getBeansWithAnnotation(RoleAuthority.class);

View File

@@ -14,7 +14,7 @@ import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
@Component
public class LogApiOkHttpInterceptor implements Interceptor {
public class OkHttpLogInterceptor implements Interceptor {
@Resource
CoreLogApiMapper coreLogApiMapper;
@@ -36,11 +36,14 @@ public class LogApiOkHttpInterceptor implements Interceptor {
logApi.setResult(response.code());
// 如果是json,xml,text则保存记录
if (response.body() != null && StrUtil.containsAll(response.body().contentType().toString(),
"json", "xml", "text")) {
ResponseBody peekBody = response.peekBody(Long.MAX_VALUE);
logApi.setRespBody(peekBody.string());
peekBody.close();
if (response.body() != null) {
MediaType mediaType = response.body().contentType();
String contentType = mediaType == null ? "" : mediaType.toString();
if (StrUtil.containsAny(contentType, "json", "xml", "text")) {
ResponseBody peekBody = response.peekBody(Long.MAX_VALUE);
logApi.setRespBody(peekBody.string());
peekBody.close();
}
}
} catch (Exception e) {
@@ -52,6 +55,9 @@ public class LogApiOkHttpInterceptor implements Interceptor {
response = new Response.Builder()
.request(request)
.protocol(Protocol.HTTP_1_1)
.code(logApi.getResult())
.message(e.getMessage())
.body(OkHttpUtil.ofJsonResponse(logApi.getRespBody()))
.build();
}