1.修改以Jeecg开头的文件异常定义为一STAS开头

2.优化上传功能把文件以年月日目录方式存储
3.优化删除文件功能,同时删除生成的辅助文件
4.添加查询单条任务记录接口
This commit is contained in:
panbaolin 2025-08-15 15:42:39 +08:00
parent c74fe7e633
commit 5cb6ee52f8
54 changed files with 523 additions and 411 deletions

View File

@ -1,23 +0,0 @@
package org.jeecg.common.exception;
/**
* @Description: jeecg-boot自定义401异常
* @author: jeecg-boot
*/
public class JeecgBoot401Exception extends RuntimeException {
private static final long serialVersionUID = 1L;
public JeecgBoot401Exception(String message){
super(message);
}
public JeecgBoot401Exception(Throwable cause)
{
super(cause);
}
public JeecgBoot401Exception(String message, Throwable cause)
{
super(message,cause);
}
}

View File

@ -1,21 +0,0 @@
package org.jeecg.common.exception;
/**
* jeecgboot断言异常
* for [QQYUN-10990]AIRAG
* @author chenrui
* @date 2025/2/14 14:31
*/
public class JeecgBootAssertException extends JeecgBootException {
private static final long serialVersionUID = 1L;
public JeecgBootAssertException(String message) {
super(message);
}
public JeecgBootAssertException(String message, int errCode) {
super(message, errCode);
}
}

View File

@ -1,28 +0,0 @@
package org.jeecg.common.exception;
import lombok.Data;
/**
* @author kezhijie@wuhandsj.com
* @date 2024/1/2 11:38
*/
@Data
public class JeecgCaptchaException extends RuntimeException{
private Integer code;
private static final long serialVersionUID = -9093410345065209053L;
public JeecgCaptchaException(Integer code, String message) {
super(message);
this.code = code;
}
public JeecgCaptchaException(String message, Throwable cause) {
super(message, cause);
}
public JeecgCaptchaException(Throwable cause) {
super(cause);
}
}

View File

@ -1,23 +0,0 @@
package org.jeecg.common.exception;
/**
* @Description: jeecg-boot自定义SQL注入异常
* @author: jeecg-boot
*/
public class JeecgSqlInjectionException extends RuntimeException {
private static final long serialVersionUID = 1L;
public JeecgSqlInjectionException(String message){
super(message);
}
public JeecgSqlInjectionException(Throwable cause)
{
super(cause);
}
public JeecgSqlInjectionException(String message, Throwable cause)
{
super(message,cause);
}
}

View File

@ -0,0 +1,22 @@
package org.jeecg.common.exception;
/**
* 自定义401异常
*/
public class STAS401Exception extends RuntimeException {
private static final long serialVersionUID = 1L;
public STAS401Exception(String message){
super(message);
}
public STAS401Exception(Throwable cause)
{
super(cause);
}
public STAS401Exception(String message, Throwable cause)
{
super(message,cause);
}
}

View File

@ -0,0 +1,18 @@
package org.jeecg.common.exception;
/**
* 断言异常
*/
public class STASAssertException extends STASException {
private static final long serialVersionUID = 1L;
public STASAssertException(String message) {
super(message);
}
public STASAssertException(String message, int errCode) {
super(message, errCode);
}
}

View File

@ -3,10 +3,9 @@ package org.jeecg.common.exception;
import org.jeecg.common.constant.CommonConstant;
/**
* @Description: jeecg-boot自定义异常
* @author: jeecg-boot
* 业务提醒异常(用于操作业务提醒)
*/
public class JeecgBootException extends RuntimeException {
public class STASBizTipException extends RuntimeException {
private static final long serialVersionUID = 1L;
/**
@ -14,11 +13,11 @@ public class JeecgBootException extends RuntimeException {
*/
private int errCode = CommonConstant.SC_INTERNAL_SERVER_ERROR_500;
public JeecgBootException(String message){
public STASBizTipException(String message){
super(message);
}
public JeecgBootException(String message, int errCode){
public STASBizTipException(String message, int errCode){
super(message);
this.errCode = errCode;
}
@ -27,12 +26,12 @@ public class JeecgBootException extends RuntimeException {
return errCode;
}
public JeecgBootException(Throwable cause)
public STASBizTipException(Throwable cause)
{
super(cause);
}
public JeecgBootException(String message,Throwable cause)
public STASBizTipException(String message, Throwable cause)
{
super(message,cause);
}

View File

@ -0,0 +1,24 @@
package org.jeecg.common.exception;
import lombok.Data;
@Data
public class STASCaptchaException extends RuntimeException{
private Integer code;
private static final long serialVersionUID = -9093410345065209053L;
public STASCaptchaException(Integer code, String message) {
super(message);
this.code = code;
}
public STASCaptchaException(String message, Throwable cause) {
super(message, cause);
}
public STASCaptchaException(Throwable cause) {
super(cause);
}
}

View File

@ -3,11 +3,9 @@ package org.jeecg.common.exception;
import org.jeecg.common.constant.CommonConstant;
/**
* @Description: 业务提醒异常(用于操作业务提醒)
* @date: 2024-04-26
* @author: scott
* 自定义异常
*/
public class JeecgBootBizTipException extends RuntimeException {
public class STASException extends RuntimeException {
private static final long serialVersionUID = 1L;
/**
@ -15,11 +13,11 @@ public class JeecgBootBizTipException extends RuntimeException {
*/
private int errCode = CommonConstant.SC_INTERNAL_SERVER_ERROR_500;
public JeecgBootBizTipException(String message){
public STASException(String message){
super(message);
}
public JeecgBootBizTipException(String message, int errCode){
public STASException(String message, int errCode){
super(message);
this.errCode = errCode;
}
@ -28,12 +26,12 @@ public class JeecgBootBizTipException extends RuntimeException {
return errCode;
}
public JeecgBootBizTipException(Throwable cause)
public STASException(Throwable cause)
{
super(cause);
}
public JeecgBootBizTipException(String message, Throwable cause)
public STASException(String message, Throwable cause)
{
super(message,cause);
}

View File

@ -39,13 +39,10 @@ import java.util.stream.Collectors;
/**
* 异常处理器
*
* @Author scott
* @Date 2019
*/
@RestControllerAdvice
@Slf4j
public class JeecgBootExceptionHandler {
public class STASExceptionHandler {
@Resource
BaseCommonService baseCommonService;
@ -54,9 +51,9 @@ public class JeecgBootExceptionHandler {
* 验证码错误异常
*/
@ExceptionHandler(JeecgCaptchaException.class)
@ExceptionHandler(STASCaptchaException.class)
@ResponseStatus(HttpStatus.OK)
public Result<?> handleJeecgCaptchaException(JeecgCaptchaException e) {
public Result<?> handleJeecgCaptchaException(STASCaptchaException e) {
log.error(e.getMessage(), e);
return Result.error(e.getCode(), e.getMessage());
}
@ -78,8 +75,8 @@ public class JeecgBootExceptionHandler {
/**
* 处理自定义异常
*/
@ExceptionHandler(JeecgBootException.class)
public Result<?> handleJeecgBootException(JeecgBootException e){
@ExceptionHandler(STASException.class)
public Result<?> handleJeecgBootException(STASException e){
log.error(e.getMessage(), e);
addSysLog(e);
return Result.error(e.getErrCode(), e.getMessage());
@ -88,8 +85,8 @@ public class JeecgBootExceptionHandler {
/**
* 处理自定义异常
*/
@ExceptionHandler(JeecgBootBizTipException.class)
public Result<?> handleJeecgBootBizTipException(JeecgBootBizTipException e){
@ExceptionHandler(STASBizTipException.class)
public Result<?> handleJeecgBootBizTipException(STASBizTipException e){
log.error(e.getMessage());
return Result.error(e.getErrCode(), e.getMessage());
}
@ -107,9 +104,9 @@ public class JeecgBootExceptionHandler {
/**
* 处理自定义异常
*/
@ExceptionHandler(JeecgBoot401Exception.class)
@ExceptionHandler(STAS401Exception.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED)
public Result<?> handleJeecgBoot401Exception(JeecgBoot401Exception e){
public Result<?> handleJeecgBoot401Exception(STAS401Exception e){
log.error(e.getMessage(), e);
addSysLog(e);
return new Result(401,e.getMessage());
@ -206,7 +203,7 @@ public class JeecgBootExceptionHandler {
* @param exception
* @return
*/
@ExceptionHandler(JeecgSqlInjectionException.class)
@ExceptionHandler(STASSqlInjectionException.class)
public Result<?> handleSQLException(Exception exception) {
String msg = exception.getMessage().toLowerCase();
final String extractvalue = "extractvalue";

View File

@ -0,0 +1,38 @@
package org.jeecg.common.exception;
import org.jeecg.common.constant.CommonConstant;
/**
* 自定义文件上传异常
*/
public class STASFileUploadException extends RuntimeException {
private static final long serialVersionUID = 1L;
/**
* 返回给前端的错误code
*/
private int errCode = CommonConstant.SC_INTERNAL_SERVER_ERROR_500;
public STASFileUploadException(String message){
super(message);
}
public STASFileUploadException(String message, int errCode){
super(message);
this.errCode = errCode;
}
public int getErrCode() {
return errCode;
}
public STASFileUploadException(Throwable cause)
{
super(cause);
}
public STASFileUploadException(String message, Throwable cause)
{
super(message,cause);
}
}

View File

@ -0,0 +1,22 @@
package org.jeecg.common.exception;
/**
* 自定义SQL注入异常
*/
public class STASSqlInjectionException extends RuntimeException {
private static final long serialVersionUID = 1L;
public STASSqlInjectionException(String message){
super(message);
}
public STASSqlInjectionException(Throwable cause)
{
super(cause);
}
public STASSqlInjectionException(String message, Throwable cause)
{
super(message,cause);
}
}

View File

@ -14,7 +14,7 @@ import java.util.stream.Collectors;
import org.apache.commons.beanutils.PropertyUtils;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.DataBaseConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.system.util.JeecgDataAutorUtils;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.system.util.SqlConcatUtil;
@ -277,7 +277,7 @@ public class QueryGenerator {
//判断column是不是当前实体的
log.debug("当前字段有:"+ allFields);
if (!allColumnExist(column, allFields)) {
throw new JeecgBootException("请注意,将要排序的列字段不存在:" + column);
throw new STASException("请注意,将要排序的列字段不存在:" + column);
}
//update-end-author:taoyan date:2022-5-16 for: issues/3676 获取系统用户列表时使用SQL注入生效

View File

@ -1,20 +1,14 @@
package org.jeecg.common.system.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTDecodeException;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Joiner;
import java.io.IOException;
import java.io.OutputStream;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
@ -22,13 +16,12 @@ import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.CommonAPI;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.DataBaseConstant;
import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.constant.TenantConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.system.vo.SysUserCacheInfo;
import org.jeecg.common.util.DateUtils;
@ -37,19 +30,11 @@ import org.jeecg.common.util.oConvertUtils;
import org.jeecg.config.security.self.SelfAuthenticationProvider;
import org.jeecg.config.security.self.SelfAuthenticationToken;
import org.jeecg.config.security.utils.SecureUtil;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.core.*;
import org.springframework.security.oauth2.jwt.JwtDecoder;
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AccessTokenAuthenticationToken;
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationToken;
import org.springframework.security.oauth2.server.authorization.client.RegisteredClient;
import org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository;
import org.springframework.security.oauth2.server.authorization.context.AuthorizationServerContextHolder;
import org.springframework.security.oauth2.server.authorization.token.DefaultOAuth2TokenContext;
import org.springframework.security.oauth2.server.authorization.token.OAuth2TokenContext;
import org.springframework.security.oauth2.server.authorization.token.OAuth2TokenGenerator;
/**
* @Author Scott
@ -153,13 +138,13 @@ public class JwtUtil {
*
* @param request
* @return
* @throws JeecgBootException
* @throws STASException
*/
public static String getUserNameByToken(HttpServletRequest request) throws JeecgBootException {
public static String getUserNameByToken(HttpServletRequest request) throws STASException {
String accessToken = request.getHeader("X-Access-Token");
String username = getUsername(accessToken);
if (oConvertUtils.isEmpty(username)) {
throw new JeecgBootException("未获取到用户");
throw new STASException("未获取到用户");
}
return username;
}

View File

@ -1,7 +1,7 @@
package org.jeecg.common.util;
import org.jeecg.common.exception.JeecgBootAssertException;
import org.jeecg.common.exception.STASAssertException;
/**
* 断言检查工具
@ -16,13 +16,13 @@ public class AssertUtils {
*
* @param msg
* @param obj
* @throws JeecgBootAssertException
* @throws STASAssertException
* @author chenrui
* @date 2017-06-22 10:05:56
*/
public static void assertEmpty(String msg, Object obj) {
if (oConvertUtils.isObjectNotEmpty(obj)) {
throw new JeecgBootAssertException(msg);
throw new STASAssertException(msg);
}
}
@ -32,13 +32,13 @@ public class AssertUtils {
*
* @param msg
* @param obj
* @throws JeecgBootAssertException
* @throws STASAssertException
* @author chenrui
* @date 2017-06-22 10:05:56
*/
public static void assertNotEmpty(String msg, Object obj) {
if (oConvertUtils.isObjectEmpty(obj)) {
throw new JeecgBootAssertException(msg);
throw new STASAssertException(msg);
}
}
@ -57,7 +57,7 @@ public class AssertUtils {
if (oConvertUtils.isEqual(expected, actual)) {
return;
}
throw new JeecgBootAssertException(message);
throw new STASAssertException(message);
}
/**
@ -72,7 +72,7 @@ public class AssertUtils {
public static void assertNotEquals(String message, Object expected,
Object actual) {
if (oConvertUtils.isEqual(expected, actual)) {
throw new JeecgBootAssertException(message);
throw new STASAssertException(message);
}
}
@ -91,7 +91,7 @@ public class AssertUtils {
if (expected == actual) {
return;
}
throw new JeecgBootAssertException(message);
throw new STASAssertException(message);
}
/**
@ -106,7 +106,7 @@ public class AssertUtils {
public static void assertNotSame(String message, Object unexpected,
Object actual) {
if (unexpected == actual) {
throw new JeecgBootAssertException(message);
throw new STASAssertException(message);
}
}
@ -118,7 +118,7 @@ public class AssertUtils {
*/
public static void assertTrue(String message, boolean condition) {
if (!condition) {
throw new JeecgBootAssertException(message);
throw new STASAssertException(message);
}
}
@ -140,7 +140,7 @@ public class AssertUtils {
* @param obj
* @param objs
* @param <T>
* @throws JeecgBootAssertException
* @throws STASAssertException
* @author chenrui
* @date 2018/1/31 22:14
*/
@ -148,7 +148,7 @@ public class AssertUtils {
assertNotEmpty(message, obj);
assertNotEmpty(message, objs);
if (!oConvertUtils.isIn(obj, objs)) {
throw new JeecgBootAssertException(message);
throw new STASAssertException(message);
}
}
@ -159,7 +159,7 @@ public class AssertUtils {
* @param obj
* @param objs
* @param <T>
* @throws JeecgBootAssertException
* @throws STASAssertException
* @author chenrui
* @date 2018/1/31 22:14
*/
@ -168,7 +168,7 @@ public class AssertUtils {
assertNotEmpty(message, obj);
assertNotEmpty(message, objs);
if (oConvertUtils.isIn(obj, objs)) {
throw new JeecgBootAssertException(message);
throw new STASAssertException(message);
}
}
@ -186,7 +186,7 @@ public class AssertUtils {
if (oConvertUtils.isGt(src, des)) {
return;
}
throw new JeecgBootAssertException(message);
throw new STASAssertException(message);
}
/**
@ -202,7 +202,7 @@ public class AssertUtils {
if (oConvertUtils.isGe(src, des)) {
return;
}
throw new JeecgBootAssertException(message);
throw new STASAssertException(message);
}
@ -217,7 +217,7 @@ public class AssertUtils {
*/
public static void assertLt(String message, Number src, Number des) {
if (oConvertUtils.isGe(src, des)) {
throw new JeecgBootAssertException(message);
throw new STASAssertException(message);
}
}
@ -232,7 +232,7 @@ public class AssertUtils {
*/
public static void assertLe(String message, Number src, Number des) {
if (oConvertUtils.isGt(src, des)) {
throw new JeecgBootAssertException(message);
throw new STASAssertException(message);
}
}

View File

@ -11,7 +11,7 @@ import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.DataBaseConstant;
import org.jeecg.common.constant.ServiceNameConstants;
import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.util.filter.SsrfFileTypeFilter;
import org.jeecg.common.util.oss.OssBootUtil;
import org.jeecgframework.poi.util.PoiPublicUtil;
@ -140,7 +140,7 @@ public class CommonUtils {
}
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new JeecgBootException(e.getMessage());
throw new STASException(e.getMessage());
}
return url;
}

View File

@ -3,7 +3,7 @@ package org.jeecg.common.util;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import java.io.*;
import java.net.URL;
@ -110,7 +110,7 @@ public class FileDownloadUtils {
}
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new JeecgBootException(e);
throw new STASException(e);
}
}
@ -142,11 +142,11 @@ public class FileDownloadUtils {
return storePath;
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new JeecgBootException(e);
throw new STASException(e);
}
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new JeecgBootException(e);
throw new STASException(e);
}
}

View File

@ -4,7 +4,7 @@ import cn.hutool.core.util.ReUtil;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.exception.JeecgSqlInjectionException;
import org.jeecg.common.exception.STASSqlInjectionException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
@ -103,7 +103,7 @@ public class SqlInjectionUtil {
if (value.indexOf(xssArr[i]) > -1) {
log.error(SqlInjectionUtil.SQL_INJECTION_KEYWORD_TIP, xssArr[i]);
log.error(SqlInjectionUtil.SQL_INJECTION_TIP_VARIABLE, value);
throw new JeecgSqlInjectionException(SqlInjectionUtil.SQL_INJECTION_TIP + value);
throw new STASSqlInjectionException(SqlInjectionUtil.SQL_INJECTION_TIP + value);
}
}
// SQL注入检测存在绕过风险 (自定义传入普通文本校验)
@ -113,7 +113,7 @@ public class SqlInjectionUtil {
if (value.indexOf(xssArr2[i]) > -1) {
log.error(SqlInjectionUtil.SQL_INJECTION_KEYWORD_TIP, xssArr2[i]);
log.error(SqlInjectionUtil.SQL_INJECTION_TIP_VARIABLE, value);
throw new JeecgSqlInjectionException(SqlInjectionUtil.SQL_INJECTION_TIP + value);
throw new STASSqlInjectionException(SqlInjectionUtil.SQL_INJECTION_TIP + value);
}
}
}
@ -124,7 +124,7 @@ public class SqlInjectionUtil {
if (Pattern.matches(regular, value)) {
log.error(SqlInjectionUtil.SQL_INJECTION_KEYWORD_TIP, regularOriginal);
log.error(SqlInjectionUtil.SQL_INJECTION_TIP_VARIABLE, value);
throw new JeecgSqlInjectionException(SqlInjectionUtil.SQL_INJECTION_TIP + value);
throw new STASSqlInjectionException(SqlInjectionUtil.SQL_INJECTION_TIP + value);
}
}
return;
@ -205,7 +205,7 @@ public class SqlInjectionUtil {
if (isExistSqlInjectKeyword(value, xssArr[i])) {
log.error(SqlInjectionUtil.SQL_INJECTION_KEYWORD_TIP, xssArr[i]);
log.error(SqlInjectionUtil.SQL_INJECTION_TIP_VARIABLE, value);
throw new JeecgSqlInjectionException(SqlInjectionUtil.SQL_INJECTION_TIP + value);
throw new STASSqlInjectionException(SqlInjectionUtil.SQL_INJECTION_TIP + value);
}
}
@ -215,7 +215,7 @@ public class SqlInjectionUtil {
if (Pattern.matches(regular, value)) {
log.error(SqlInjectionUtil.SQL_INJECTION_KEYWORD_TIP, regularOriginal);
log.error(SqlInjectionUtil.SQL_INJECTION_TIP_VARIABLE, value);
throw new JeecgSqlInjectionException(SqlInjectionUtil.SQL_INJECTION_TIP + value);
throw new STASSqlInjectionException(SqlInjectionUtil.SQL_INJECTION_TIP + value);
}
}
return;
@ -241,7 +241,7 @@ public class SqlInjectionUtil {
if (isExistSqlInjectKeyword(value, xssArr[i])) {
log.error(SqlInjectionUtil.SQL_INJECTION_KEYWORD_TIP, xssArr[i]);
log.error(SqlInjectionUtil.SQL_INJECTION_TIP_VARIABLE, value);
throw new JeecgSqlInjectionException(SqlInjectionUtil.SQL_INJECTION_TIP + value);
throw new STASSqlInjectionException(SqlInjectionUtil.SQL_INJECTION_TIP + value);
}
}
@ -251,7 +251,7 @@ public class SqlInjectionUtil {
if (Pattern.matches(regular, value)) {
log.error(SqlInjectionUtil.SQL_INJECTION_KEYWORD_TIP, regularOriginal);
log.error(SqlInjectionUtil.SQL_INJECTION_TIP_VARIABLE, value);
throw new JeecgSqlInjectionException(SqlInjectionUtil.SQL_INJECTION_TIP + value);
throw new STASSqlInjectionException(SqlInjectionUtil.SQL_INJECTION_TIP + value);
}
}
return;
@ -274,7 +274,7 @@ public class SqlInjectionUtil {
if(matcher.find()){
String error = "请注意值可能存在SQL注入风险---> \\*.*\\";
log.error(error);
throw new JeecgSqlInjectionException(error);
throw new STASSqlInjectionException(error);
}
}
@ -312,7 +312,7 @@ public class SqlInjectionUtil {
if (!isValidTableName) {
String errorMsg = "表名不合法存在SQL注入风险!--->" + table;
log.error(errorMsg);
throw new JeecgSqlInjectionException(errorMsg);
throw new STASSqlInjectionException(errorMsg);
}
//进一步验证是否存在SQL注入风险
@ -349,7 +349,7 @@ public class SqlInjectionUtil {
if (!isValidField) {
String errorMsg = "字段不合法存在SQL注入风险!--->" + field;
log.error(errorMsg);
throw new JeecgSqlInjectionException(errorMsg);
throw new STASSqlInjectionException(errorMsg);
}
//进一步验证是否存在SQL注入风险

View File

@ -8,7 +8,7 @@ import org.jeecg.common.constant.CacheConstant;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.TenantConstant;
import org.jeecg.common.desensitization.util.SensitiveInfoUtil;
import org.jeecg.common.exception.JeecgBoot401Exception;
import org.jeecg.common.exception.STAS401Exception;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.system.vo.LoginUser;
@ -95,28 +95,28 @@ public class TokenUtils {
*/
public static boolean verifyToken(String token, CommonAPI commonApi, RedisUtil redisUtil) {
if (StringUtils.isBlank(token)) {
throw new JeecgBoot401Exception("token不能为空!");
throw new STAS401Exception("token不能为空!");
}
// 解密获得username用于和数据库进行对比
String username = JwtUtil.getUsername(token);
if (username == null) {
throw new JeecgBoot401Exception("token非法无效!");
throw new STAS401Exception("token非法无效!");
}
// 查询用户信息
//LoginUser user = TokenUtils.getLoginUser(username, commonApi, redisUtil);
LoginUser user = commonApi.getUserByName(username);
if (user == null) {
throw new JeecgBoot401Exception("用户不存在!");
throw new STAS401Exception("用户不存在!");
}
// 判断用户状态
if (user.getStatus() != 1) {
throw new JeecgBoot401Exception("账号已被锁定,请联系管理员!");
throw new STAS401Exception("账号已被锁定,请联系管理员!");
}
// 校验token是否超时失效 & 或者账号密码是否错误
if (!jwtTokenRefresh(token, username, user.getPassword(), redisUtil)) {
throw new JeecgBoot401Exception(CommonConstant.TOKEN_IS_INVALID_MSG);
throw new STAS401Exception(CommonConstant.TOKEN_IS_INVALID_MSG);
}
return true;
}

View File

@ -3,15 +3,13 @@ package org.jeecg.common.util.dynamic.db;
import com.alibaba.druid.pool.DruidDataSource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.system.vo.DynamicDataSourceModel;
import org.jeecg.common.util.ReflectHelper;
import org.jeecg.common.util.oConvertUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
@ -40,7 +38,7 @@ public class DynamicDBUtil {
String url = dbSource.getDbUrl();
// url配置成 123 会触发Druid死循环一直去重复尝试连接
if (oConvertUtils.isEmpty(url) || !url.toLowerCase().startsWith("jdbc:")) {
throw new JeecgBootException("数据源URL配置格式不正确");
throw new STASException("数据源URL配置格式不正确");
}
String dbUser = dbSource.getDbUsername();
@ -90,7 +88,7 @@ public class DynamicDBUtil {
DataSourceCachePool.putCacheBasicDataSource(dbKey, dataSource);
}else{
throw new JeecgBootException("动态数据源连接失败dbKey"+dbKey);
throw new STASException("动态数据源连接失败dbKey"+dbKey);
}
log.info("--------getDbSourceBydbKey------------------创建DB数据库连接-------------------");
return dataSource;

View File

@ -2,7 +2,7 @@ package org.jeecg.common.util.security;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.exception.JeecgSqlInjectionException;
import org.jeecg.common.exception.STASSqlInjectionException;
import java.util.*;
import java.util.regex.Matcher;
@ -86,7 +86,7 @@ public abstract class AbstractQueryBlackListHandler {
// 返回黑名单校验结果不合法直接抛出异常
if(!flag){
log.error(this.getError());
throw new JeecgSqlInjectionException(this.getError());
throw new STASSqlInjectionException(this.getError());
}
return flag;
}

View File

@ -1,6 +1,6 @@
package org.jeecg.common.util.security;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.util.oConvertUtils;
/**
@ -37,7 +37,7 @@ public class JdbcSecurityUtil {
String key = temp.split("=")[0];
for(String prop: notAllowedProps){
if(prop.equalsIgnoreCase(key)){
throw new JeecgBootException("连接地址有安全风险,【"+key+"");
throw new STASException("连接地址有安全风险,【"+key+"");
}
}
}

View File

@ -5,8 +5,7 @@ import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.CommonAPI;
import org.jeecg.common.constant.CacheConstant;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.JeecgCaptchaException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.system.vo.SysDepartModel;
import org.jeecg.common.util.Md5Util;
@ -14,11 +13,9 @@ import org.jeecg.common.util.PasswordUtil;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.config.JeecgBaseConfig;
import org.jeecg.config.security.password.PasswordGrantAuthenticationToken;
import org.jeecg.modules.base.service.BaseCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
@ -298,19 +295,19 @@ public class AppGrantAuthenticationProvider implements AuthenticationProvider {
//情况1根据用户信息查询该用户不存在
if (Objects.isNull(loginUser)) {
baseCommonService.addLog("用户登录失败,用户不存在!", CommonConstant.LOG_TYPE_1, null);
throw new JeecgBootException("该用户不存在,请注册");
throw new STASException("该用户不存在,请注册");
}
//情况2根据用户信息查询该用户已注销
//update-begin---author:王帅 Date:20200601 forif条件永远为falsebug------------
if (CommonConstant.DEL_FLAG_1.equals(loginUser.getDelFlag())) {
//update-end---author:王帅 Date:20200601 forif条件永远为falsebug------------
baseCommonService.addLog("用户登录失败,用户名:" + loginUser.getUsername() + "已注销!", CommonConstant.LOG_TYPE_1, null);
throw new JeecgBootException("该用户已注销");
throw new STASException("该用户已注销");
}
//情况3根据用户信息查询该用户已冻结
if (CommonConstant.USER_FREEZE.equals(loginUser.getStatus())) {
baseCommonService.addLog("用户登录失败,用户名:" + loginUser.getUsername() + "已冻结!", CommonConstant.LOG_TYPE_1, null);
throw new JeecgBootException("该用户已冻结");
throw new STASException("该用户已冻结");
}
}

View File

@ -5,8 +5,7 @@ import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.CommonAPI;
import org.jeecg.common.constant.CacheConstant;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.JeecgCaptchaException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.system.vo.SysDepartModel;
import org.jeecg.common.util.Md5Util;
@ -17,13 +16,10 @@ import org.jeecg.config.JeecgBaseConfig;
import org.jeecg.modules.base.service.BaseCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.oauth2.core.*;
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
@ -98,11 +94,11 @@ public class PasswordGrantAuthenticationProvider implements AuthenticationProvid
// 检查登录失败次数
if(isLoginFailOvertimes(username)){
throw new JeecgBootException("该用户登录失败次数过多请于10分钟后再次登录");
throw new STASException("该用户登录失败次数过多请于10分钟后再次登录");
}
if(captcha==null){
throw new JeecgBootException("验证码无效");
throw new STASException("验证码无效");
}
String lowerCaseCaptcha = captcha.toLowerCase();
// 加入密钥作为混淆避免简单的拼接被外部利用用户自定义该密钥即可
@ -296,19 +292,19 @@ public class PasswordGrantAuthenticationProvider implements AuthenticationProvid
//情况1根据用户信息查询该用户不存在
if (Objects.isNull(loginUser)) {
baseCommonService.addLog("用户登录失败,用户不存在!", CommonConstant.LOG_TYPE_1, null);
throw new JeecgBootException("该用户不存在,请注册");
throw new STASException("该用户不存在,请注册");
}
//情况2根据用户信息查询该用户已注销
//update-begin---author:王帅 Date:20200601 forif条件永远为falsebug------------
if (CommonConstant.DEL_FLAG_1.equals(loginUser.getDelFlag())) {
//update-end---author:王帅 Date:20200601 forif条件永远为falsebug------------
baseCommonService.addLog("用户登录失败,用户名:" + loginUser.getUsername() + "已注销!", CommonConstant.LOG_TYPE_1, null);
throw new JeecgBootException("该用户已注销");
throw new STASException("该用户已注销");
}
//情况3根据用户信息查询该用户已冻结
if (CommonConstant.USER_FREEZE.equals(loginUser.getStatus())) {
baseCommonService.addLog("用户登录失败,用户名:" + loginUser.getUsername() + "已冻结!", CommonConstant.LOG_TYPE_1, null);
throw new JeecgBootException("该用户已冻结");
throw new STASException("该用户已冻结");
}
}

View File

@ -4,20 +4,15 @@ import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.CommonAPI;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.JeecgCaptchaException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.system.vo.SysDepartModel;
import org.jeecg.common.util.Md5Util;
import org.jeecg.common.util.PasswordUtil;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.config.JeecgBaseConfig;
import org.jeecg.config.security.password.PasswordGrantAuthenticationToken;
import org.jeecg.modules.base.service.BaseCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
@ -82,7 +77,7 @@ public class PhoneGrantAuthenticationProvider implements AuthenticationProvider
String phone = (String) additionalParameter.get("mobile");
if(isLoginFailOvertimes(phone)){
throw new JeecgBootException("该用户登录失败次数过多请于10分钟后再次登录");
throw new STASException("该用户登录失败次数过多请于10分钟后再次登录");
}
//请求参数权限范围
@ -270,19 +265,19 @@ public class PhoneGrantAuthenticationProvider implements AuthenticationProvider
//情况1根据用户信息查询该用户不存在
if (Objects.isNull(loginUser)) {
baseCommonService.addLog("用户登录失败,用户不存在!", CommonConstant.LOG_TYPE_1, null);
throw new JeecgBootException("该用户不存在,请注册");
throw new STASException("该用户不存在,请注册");
}
//情况2根据用户信息查询该用户已注销
//update-begin---author:王帅 Date:20200601 forif条件永远为falsebug------------
if (CommonConstant.DEL_FLAG_1.equals(loginUser.getDelFlag())) {
//update-end---author:王帅 Date:20200601 forif条件永远为falsebug------------
baseCommonService.addLog("用户登录失败,用户名:" + loginUser.getUsername() + "已注销!", CommonConstant.LOG_TYPE_1, null);
throw new JeecgBootException("该用户已注销");
throw new STASException("该用户已注销");
}
//情况3根据用户信息查询该用户已冻结
if (CommonConstant.USER_FREEZE.equals(loginUser.getStatus())) {
baseCommonService.addLog("用户登录失败,用户名:" + loginUser.getUsername() + "已冻结!", CommonConstant.LOG_TYPE_1, null);
throw new JeecgBootException("该用户已冻结");
throw new STASException("该用户已冻结");
}
}

View File

@ -2,8 +2,8 @@ package org.jeecg.config.security.self;
import org.jeecg.common.api.CommonAPI;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.exception.JeecgBoot401Exception;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STAS401Exception;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.config.JeecgBaseConfig;
@ -106,7 +106,7 @@ public class SelfAuthenticationProvider implements AuthenticationProvider {
OAuth2TokenContext tokenContext = tokenContextBuilder.tokenType(OAuth2TokenType.ACCESS_TOKEN).build();
OAuth2Token generatedAccessToken = this.tokenGenerator.generate(tokenContext);
if (generatedAccessToken == null) {
throw new JeecgBoot401Exception("无法生成刷新token请联系管理员。");
throw new STAS401Exception("无法生成刷新token请联系管理员。");
}
OAuth2AccessToken accessToken = new OAuth2AccessToken(OAuth2AccessToken.TokenType.BEARER,
generatedAccessToken.getTokenValue(), generatedAccessToken.getIssuedAt(),
@ -169,19 +169,19 @@ public class SelfAuthenticationProvider implements AuthenticationProvider {
//情况1根据用户信息查询该用户不存在
if (Objects.isNull(loginUser)) {
baseCommonService.addLog("用户登录失败,用户不存在!", CommonConstant.LOG_TYPE_1, null);
throw new JeecgBootException("该用户不存在,请注册");
throw new STASException("该用户不存在,请注册");
}
//情况2根据用户信息查询该用户已注销
//update-begin---author:王帅 Date:20200601 forif条件永远为falsebug------------
if (CommonConstant.DEL_FLAG_1.equals(loginUser.getDelFlag())) {
//update-end---author:王帅 Date:20200601 forif条件永远为falsebug------------
baseCommonService.addLog("用户登录失败,用户名:" + loginUser.getUsername() + "已注销!", CommonConstant.LOG_TYPE_1, null);
throw new JeecgBootException("该用户已注销");
throw new STASException("该用户已注销");
}
//情况3根据用户信息查询该用户已冻结
if (CommonConstant.USER_FREEZE.equals(loginUser.getStatus())) {
baseCommonService.addLog("用户登录失败,用户名:" + loginUser.getUsername() + "已冻结!", CommonConstant.LOG_TYPE_1, null);
throw new JeecgBootException("该用户已冻结");
throw new STASException("该用户已冻结");
}
}
}

View File

@ -6,13 +6,12 @@ import com.auth0.jwt.interfaces.DecodedJWT;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.CommonAPI;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.system.vo.SysDepartModel;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.config.JeecgBaseConfig;
import org.jeecg.config.security.password.PasswordGrantAuthenticationToken;
import org.jeecg.modules.base.service.BaseCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
@ -256,19 +255,19 @@ public class SocialGrantAuthenticationProvider implements AuthenticationProvider
//情况1根据用户信息查询该用户不存在
if (Objects.isNull(loginUser)) {
baseCommonService.addLog("用户登录失败,用户不存在!", CommonConstant.LOG_TYPE_1, null);
throw new JeecgBootException("该用户不存在,请注册");
throw new STASException("该用户不存在,请注册");
}
//情况2根据用户信息查询该用户已注销
//update-begin---author:王帅 Date:20200601 forif条件永远为falsebug------------
if (CommonConstant.DEL_FLAG_1.equals(loginUser.getDelFlag())) {
//update-end---author:王帅 Date:20200601 forif条件永远为falsebug------------
baseCommonService.addLog("用户登录失败,用户名:" + loginUser.getUsername() + "已注销!", CommonConstant.LOG_TYPE_1, null);
throw new JeecgBootException("该用户已注销");
throw new STASException("该用户已注销");
}
//情况3根据用户信息查询该用户已冻结
if (CommonConstant.USER_FREEZE.equals(loginUser.getStatus())) {
baseCommonService.addLog("用户登录失败,用户名:" + loginUser.getUsername() + "已冻结!", CommonConstant.LOG_TYPE_1, null);
throw new JeecgBootException("该用户已冻结");
throw new STASException("该用户已冻结");
}
}

View File

@ -3,7 +3,7 @@ package org.jeecg.config.sign.util;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.config.JeecgBaseConfig;
@ -53,7 +53,7 @@ public class SignUtil {
String signatureSecret = jeecgBaseConfig.getSignatureSecret();
String curlyBracket = SymbolConstant.DOLLAR + SymbolConstant.LEFT_CURLY_BRACKET;
if(oConvertUtils.isEmpty(signatureSecret) || signatureSecret.contains(curlyBracket)){
throw new JeecgBootException("签名密钥 ${jeecg.signatureSecret} 缺少配置 ");
throw new STASException("签名密钥 ${jeecg.signatureSecret} 缺少配置 ");
}
try {
//issues/I484RW2.4.6部署后下拉搜索框提示sign签名检验失败

View File

@ -2,7 +2,7 @@ package org.jeecg.config.firewall.SqlInjection.impl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.exception.JeecgSqlInjectionException;
import org.jeecg.common.exception.STASSqlInjectionException;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.config.JeecgBaseConfig;
import org.jeecg.config.firewall.SqlInjection.IDictTableWhiteListHandler;
@ -259,16 +259,16 @@ public class DictTableWhiteListHandlerImpl implements IDictTableWhiteListHandler
return tableName.replaceAll(reg, "");
}
private void throwException() throws JeecgSqlInjectionException {
private void throwException() throws STASSqlInjectionException {
this.throwException(this.getErrorMsg());
}
private void throwException(String message) throws JeecgSqlInjectionException {
private void throwException(String message) throws STASSqlInjectionException {
if (oConvertUtils.isEmpty(message)) {
message = this.getErrorMsg();
}
log.error(message);
throw new JeecgSqlInjectionException(message);
throw new STASSqlInjectionException(message);
}
@Override

View File

@ -4,7 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import org.jeecg.common.api.dto.message.MessageDTO;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.WebsocketConst;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.common.util.oConvertUtils;
@ -54,7 +54,7 @@ public class SystemSendMsgHandle implements ISendMsgHandle {
@Override
public void sendMsg(String esReceiver, String esTitle, String esContent) {
if(oConvertUtils.isEmpty(esReceiver)){
throw new JeecgBootException("被发送人不能为空");
throw new STASException("被发送人不能为空");
}
ISysBaseAPI sysBaseApi = SpringContextUtils.getBean(ISysBaseAPI.class);
MessageDTO messageDTO = new MessageDTO(FROM_USER,esReceiver,esTitle,esContent);

View File

@ -3,7 +3,7 @@ package org.jeecg.modules.openapi.filter;
import jakarta.servlet.*;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.modules.openapi.entity.OpenApi;
import org.jeecg.modules.openapi.entity.OpenApiAuth;
import org.jeecg.modules.openapi.entity.OpenApiLog;
@ -92,7 +92,7 @@ public class ApiAuthFilter implements Filter {
List<String> blackList = Arrays.asList(openApi.getBlackList().split(","));
if (blackList.contains(ip)) {
throw new JeecgBootException("目标接口限制IP[" + ip + "]进行访问IP已记录请停止访问");
throw new STASException("目标接口限制IP[" + ip + "]进行访问IP已记录请停止访问");
}
}
@ -105,19 +105,19 @@ public class ApiAuthFilter implements Filter {
*/
protected void checkSignValid(String appkey, String signature, String timestamp) {
if (!StringUtils.hasText(appkey)) {
throw new JeecgBootException("appkey为空");
throw new STASException("appkey为空");
}
if (!StringUtils.hasText(signature)) {
throw new JeecgBootException("signature为空");
throw new STASException("signature为空");
}
if (!StringUtils.hasText(timestamp)) {
throw new JeecgBootException("timastamp时间戳为空");
throw new STASException("timastamp时间戳为空");
}
if (!timestamp.matches("[0-9]*")) {
throw new JeecgBootException("timastamp时间戳不合法");
throw new STASException("timastamp时间戳不合法");
}
if (System.currentTimeMillis() - Long.parseLong(timestamp) > 5 * 60 * 1000) {
throw new JeecgBootException("signature签名已过期(超过五分钟)");
throw new STASException("signature签名已过期(超过五分钟)");
}
}
@ -132,15 +132,15 @@ public class ApiAuthFilter implements Filter {
*/
protected void checkSignature(String appKey, String signature, String timestamp, OpenApiAuth openApiAuth) {
if(openApiAuth==null){
throw new JeecgBootException("不存在认证信息");
throw new STASException("不存在认证信息");
}
if(!appKey.equals(openApiAuth.getAk())){
throw new JeecgBootException("appkey错误");
throw new STASException("appkey错误");
}
if (!signature.equals(md5(appKey + openApiAuth.getSk() + timestamp))) {
throw new JeecgBootException("signature签名错误");
throw new STASException("signature签名错误");
}
}
@ -156,7 +156,7 @@ public class ApiAuthFilter implements Filter {
}
if (!hasPermission) {
throw new JeecgBootException("该appKey未授权当前接口");
throw new STASException("该appKey未授权当前接口");
}
}

View File

@ -1,7 +1,7 @@
package org.jeecg.modules.oss.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.util.CommonUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.common.util.oss.OssBootUtil;
@ -11,8 +11,6 @@ import org.jeecg.modules.oss.service.IOssFileService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
/**
* @Description: OSS云存储实现类
* @author: jeecg-boot
@ -28,7 +26,7 @@ public class OssFileServiceImpl extends ServiceImpl<OssFileMapper, OssFile> impl
ossFile.setFileName(fileName);
String url = OssBootUtil.upload(multipartFile,"upload/test");
if(oConvertUtils.isEmpty(url)){
throw new JeecgBootException("上传文件失败! ");
throw new STASException("上传文件失败! ");
}
//update-begin--Author:scott Date:20201227 forJT-361文件预览阿里云原生域名可以文件预览自己映射域名kkfileview提示文件下载失败-------------------
// 返回阿里云原生域名前缀URL

View File

@ -3,7 +3,7 @@ package org.jeecg.modules.quartz.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.quartz.entity.QuartzJob;
import org.jeecg.modules.quartz.mapper.QuartzJobMapper;
@ -44,7 +44,7 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
* 保存&启动定时任务
*/
@Override
@Transactional(rollbackFor = JeecgBootException.class)
@Transactional(rollbackFor = STASException.class)
public boolean saveAndScheduleJob(QuartzJob quartzJob) {
// DB设置修改
quartzJob.setDelFlag(CommonConstant.DEL_FLAG_0);
@ -62,7 +62,7 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
* 恢复定时任务
*/
@Override
@Transactional(rollbackFor = JeecgBootException.class)
@Transactional(rollbackFor = STASException.class)
public boolean resumeJob(QuartzJob quartzJob) {
schedulerDelete(quartzJob.getId());
schedulerAdd(quartzJob.getId(), quartzJob.getJobClassName().trim(), quartzJob.getCronExpression().trim(), quartzJob.getParameter());
@ -75,7 +75,7 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
* @throws SchedulerException
*/
@Override
@Transactional(rollbackFor = JeecgBootException.class)
@Transactional(rollbackFor = STASException.class)
public boolean editAndScheduleJob(QuartzJob quartzJob) throws SchedulerException {
if (CommonConstant.STATUS_NORMAL.equals(quartzJob.getStatus())) {
schedulerDelete(quartzJob.getId());
@ -90,7 +90,7 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
* 删除&停止删除定时任务
*/
@Override
@Transactional(rollbackFor = JeecgBootException.class)
@Transactional(rollbackFor = STASException.class)
public boolean deleteAndStopJob(QuartzJob job) {
schedulerDelete(job.getId());
boolean ok = this.removeById(job.getId());
@ -121,7 +121,7 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
}
@Override
@Transactional(rollbackFor = JeecgBootException.class)
@Transactional(rollbackFor = STASException.class)
public void pause(QuartzJob quartzJob){
schedulerDelete(quartzJob.getId());
quartzJob.setStatus(CommonConstant.STATUS_DISABLE);
@ -151,11 +151,11 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
scheduler.scheduleJob(jobDetail, trigger);
} catch (SchedulerException e) {
throw new JeecgBootException("创建定时任务失败", e);
throw new STASException("创建定时任务失败", e);
} catch (RuntimeException e) {
throw new JeecgBootException(e.getMessage(), e);
throw new STASException(e.getMessage(), e);
}catch (Exception e) {
throw new JeecgBootException("后台找不到该类名:" + jobClassName, e);
throw new STASException("后台找不到该类名:" + jobClassName, e);
}
}
@ -171,7 +171,7 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
scheduler.deleteJob(JobKey.jobKey(id));
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new JeecgBootException("删除定时任务失败");
throw new STASException("删除定时任务失败");
}
}

View File

@ -4,13 +4,11 @@ import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.constant.enums.FileTypeEnum;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.util.CommonUtils;
import org.jeecg.common.util.filter.SsrfFileTypeFilter;
import org.jeecg.common.util.oConvertUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.*;
@ -69,7 +67,7 @@ public class CommonController {
//LOWCOD-2580 sys/common/upload接口存在任意文件上传漏洞
if (oConvertUtils.isNotEmpty(bizPath)) {
if(bizPath.contains(SymbolConstant.SPOT_SINGLE_SLASH) || bizPath.contains(SymbolConstant.SPOT_DOUBLE_BACKSLASH)){
throw new JeecgBootException("上传目录bizPath格式非法");
throw new STASException("上传目录bizPath格式非法");
}
}

View File

@ -3,7 +3,6 @@ package org.jeecg.modules.system.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -16,7 +15,7 @@ import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.config.TenantContext;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.dynamic.db.DataSourceCachePool;
@ -115,7 +114,7 @@ public class SysDataSourceController extends JeecgController<SysDataSource, ISys
//update-begin-author:taoyan date:2022-8-10 for: jdbc连接地址漏洞问题
try {
JdbcSecurityUtil.validate(sysDataSource.getDbUrl());
}catch (JeecgBootException e){
}catch (STASException e){
log.error(e.toString());
return Result.error("操作失败:" + e.getMessage());
}
@ -136,7 +135,7 @@ public class SysDataSourceController extends JeecgController<SysDataSource, ISys
//update-begin-author:taoyan date:2022-8-10 for: jdbc连接地址漏洞问题
try {
JdbcSecurityUtil.validate(sysDataSource.getDbUrl());
} catch (JeecgBootException e) {
} catch (STASException e) {
log.error(e.toString());
return Result.error("操作失败:" + e.getMessage());
}

View File

@ -1,17 +1,15 @@
package org.jeecg.modules.system.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.Md5Util;
import org.jeecg.common.util.oConvertUtils;
@ -27,7 +25,6 @@ import org.jeecg.modules.system.service.*;
import org.jeecg.modules.system.util.PermissionDataUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import java.util.*;
@ -491,7 +488,7 @@ public class SysPermissionController {
if (oConvertUtils.isNotEmpty(id)) {
try {
sysPermissionService.deletePermission(id);
} catch (JeecgBootException e) {
} catch (STASException e) {
if(e.getMessage()!=null && e.getMessage().contains("未找到菜单信息")){
log.warn(e.getMessage());
}else{

View File

@ -2,7 +2,7 @@ package org.jeecg.modules.system.controller;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.util.CommonUtils;
import org.jeecg.common.util.MinioUtil;
import org.jeecg.common.util.oConvertUtils;
@ -40,7 +40,7 @@ public class SysUploadController {
//LOWCOD-2580 sys/common/upload接口存在任意文件上传漏洞
boolean flag = oConvertUtils.isNotEmpty(bizPath) && (bizPath.contains("../") || bizPath.contains("..\\"));
if (flag) {
throw new JeecgBootException("上传目录bizPath格式非法");
throw new STASException("上传目录bizPath格式非法");
}
if(oConvertUtils.isEmpty(bizPath)){

View File

@ -1,7 +1,7 @@
package org.jeecg.modules.system.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.modules.system.entity.SysCategory;
import org.jeecg.modules.system.model.TreeSelectModel;
@ -40,9 +40,9 @@ public interface ISysCategoryService extends IService<SysCategory> {
* 根据父级编码加载分类字典的数据
* @param pcode
* @return
* @throws JeecgBootException
* @throws STASException
*/
public List<TreeSelectModel> queryListByCode(String pcode) throws JeecgBootException;
public List<TreeSelectModel> queryListByCode(String pcode) throws STASException;
/**
* 根据pid查询子节点集合

View File

@ -2,8 +2,7 @@ package org.jeecg.modules.system.service;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.modules.system.entity.SysPermission;
import org.jeecg.modules.system.model.TreeModel;
@ -33,29 +32,29 @@ public interface ISysPermissionService extends IService<SysPermission> {
/**
* 真实删除
* @param id 菜单id
* @throws JeecgBootException
* @throws STASException
*/
public void deletePermission(String id) throws JeecgBootException;
public void deletePermission(String id) throws STASException;
/**
* 逻辑删除
* @param id 菜单id
* @throws JeecgBootException
* @throws STASException
*/
public void deletePermissionLogical(String id) throws JeecgBootException;
public void deletePermissionLogical(String id) throws STASException;
/**
* 添加菜单
* @param sysPermission SysPermission对象
* @throws JeecgBootException
* @throws STASException
*/
public void addPermission(SysPermission sysPermission) throws JeecgBootException;
public void addPermission(SysPermission sysPermission) throws STASException;
/**
* 编辑菜单
* @param sysPermission SysPermission对象
* @throws JeecgBootException
* @throws STASException
*/
public void editPermission(SysPermission sysPermission) throws JeecgBootException;
public void editPermission(SysPermission sysPermission) throws STASException;
/**
* 获取登录用户拥有的权限

View File

@ -25,7 +25,7 @@ import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.constant.enums.DySmsEnum;
import org.jeecg.common.constant.enums.RoleIndexConfigEnum;
import org.jeecg.common.desensitization.annotation.SensitiveEncode;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.system.vo.SysUserCacheInfo;
import org.jeecg.common.util.*;
@ -39,7 +39,6 @@ import org.jeecg.modules.system.model.SysUserSysDepartModel;
import org.jeecg.modules.system.service.IAuthUserService;
import org.jeecg.modules.system.service.ISysRoleIndexService;
import org.jeecg.modules.system.vo.SysUserDepVo;
import org.jeecg.modules.system.vo.SysUserPositionVo;
import org.jeecg.modules.system.vo.UserAvatar;
import org.jeecg.modules.system.vo.lowapp.AppExportUserVo;
import org.jeecg.modules.system.vo.lowapp.DepartAndUserInfo;
@ -1525,7 +1524,7 @@ public class AuthUserServiceImpl extends ServiceImpl<AuthUserMapper, SysUser> im
Long adminRoleCount = this.authUserMapper.selectCount(query);
//大于0说明存在管理员用户不允许删除
if(adminRoleCount>0){
throw new JeecgBootException("admin用户不允许删除");
throw new STASException("admin用户不允许删除");
}
}
@ -1535,15 +1534,15 @@ public class AuthUserServiceImpl extends ServiceImpl<AuthUserMapper, SysUser> im
String phone = json.getString("phone");
String type = json.getString("type");
if(oConvertUtils.isEmpty(phone)){
throw new JeecgBootException("请填写原手机号!");
throw new STASException("请填写原手机号!");
}
if(oConvertUtils.isEmpty(smscode)){
throw new JeecgBootException("请填写验证码!");
throw new STASException("请填写验证码!");
}
//step1 验证原手机号是否和当前用户匹配
SysUser sysUser = authUserMapper.getUserByNameAndPhone(phone,username);
if (null == sysUser){
throw new JeecgBootException("原手机号不匹配,无法修改密码!");
throw new STASException("原手机号不匹配,无法修改密码!");
}
//step2 根据类型判断是验证原手机号的验证码还是新手机号的验证码
//验证原手机号
@ -1554,7 +1553,7 @@ public class AuthUserServiceImpl extends ServiceImpl<AuthUserMapper, SysUser> im
String newPhone = json.getString("newPhone");
//需要验证新手机号和原手机号是否一致一致不让修改
if(newPhone.equals(phone)){
throw new JeecgBootException("新手机号与原手机号一致,无法修改!");
throw new STASException("新手机号与原手机号一致,无法修改!");
}
this.verifyPhone(newPhone, smscode);
//step3 新手机号验证码验证成功之后即可修改手机号
@ -1574,10 +1573,10 @@ public class AuthUserServiceImpl extends ServiceImpl<AuthUserMapper, SysUser> im
String phoneKey = CommonConstant.CHANGE_PHONE_REDIS_KEY_PRE + phone;
Object phoneCode = redisUtil.get(phoneKey);
if(null == phoneCode){
throw new JeecgBootException("验证码失效,请重新发送验证码!");
throw new STASException("验证码失效,请重新发送验证码!");
}
if(!smsCode.equals(phoneCode.toString())) {
throw new JeecgBootException("短信验证码不匹配!");
throw new STASException("短信验证码不匹配!");
}
//验证完成之后清空手机验证码
redisUtil.removeAll(phoneKey);
@ -1588,20 +1587,20 @@ public class AuthUserServiceImpl extends ServiceImpl<AuthUserMapper, SysUser> im
String type = jsonObject.getString("type");
String phone = jsonObject.getString("phone");
if(oConvertUtils.isEmpty(phone)){
throw new JeecgBootException("请填写手机号!");
throw new STASException("请填写手机号!");
}
//step1 根据类型判断是发送旧手机号验证码还是新的手机号验证码
if(CommonConstant.VERIFY_ORIGINAL_PHONE.equals(type)){
//step2 旧手机号验证码需要验证手机号是否匹配
SysUser sysUser = authUserMapper.getUserByNameAndPhone(phone, username);
if(null == sysUser){
throw new JeecgBootException("旧手机号不匹配,无法修改手机号!");
throw new STASException("旧手机号不匹配,无法修改手机号!");
}
}else if(CommonConstant.UPDATE_PHONE.equals(type)){
//step3 新手机号需要验证手机号码是否已注册过
SysUser userByPhone = authUserMapper.getUserByPhone(phone);
if(null != userByPhone){
throw new JeecgBootException("手机号已被注册,请尝试其他手机号!");
throw new STASException("手机号已被注册,请尝试其他手机号!");
}
}
//step4 发送短信验证码
@ -1615,7 +1614,7 @@ public class AuthUserServiceImpl extends ServiceImpl<AuthUserMapper, SysUser> im
//通过用户名查询数据库中的手机号
SysUser userByNameAndPhone = authUserMapper.getUserByNameAndPhone(phone, username);
if (null == userByNameAndPhone) {
throw new JeecgBootException("当前用户手机号不匹配,无法修改!");
throw new STASException("当前用户手机号不匹配,无法修改!");
}
String code = CommonConstant.LOG_OFF_PHONE_REDIS_KEY_PRE + phone;
this.sendPhoneSms(phone, ipAddress, code);
@ -1629,15 +1628,15 @@ public class AuthUserServiceImpl extends ServiceImpl<AuthUserMapper, SysUser> im
//通过用户名查询数据库中的手机号
SysUser userByNameAndPhone = authUserMapper.getUserByNameAndPhone(phone, username);
if (null == userByNameAndPhone) {
throw new JeecgBootException("当前用户手机号不匹配,无法注销!");
throw new STASException("当前用户手机号不匹配,无法注销!");
}
String code = CommonConstant.LOG_OFF_PHONE_REDIS_KEY_PRE + phone;
Object redisSmdCode = redisUtil.get(code);
if (null == redisSmdCode) {
throw new JeecgBootException("验证码失效,无法注销!");
throw new STASException("验证码失效,无法注销!");
}
if (!redisSmdCode.toString().equals(smsCode)) {
throw new JeecgBootException("验证码不匹配,无法注销!");
throw new STASException("验证码不匹配,无法注销!");
}
this.deleteUser(userByNameAndPhone.getId());
redisUtil.removeAll(code);
@ -1793,13 +1792,13 @@ public class AuthUserServiceImpl extends ServiceImpl<AuthUserMapper, SysUser> im
Object object = redisUtil.get(redisKey);
if (object != null) {
throw new JeecgBootException("验证码10分钟内仍然有效");
throw new STASException("验证码10分钟内仍然有效");
}
//增加 check防止恶意刷短信接口
if(!DySmsLimit.canSendSms(clientIp)){
log.warn("--------[警告] IP地址:{}, 短信接口请求太多-------", clientIp);
throw new JeecgBootException("短信接口请求太多,请稍后再试!", CommonConstant.PHONE_SMS_FAIL_CODE);
throw new STASException("短信接口请求太多,请稍后再试!", CommonConstant.PHONE_SMS_FAIL_CODE);
}
//随机数
@ -1809,13 +1808,13 @@ public class AuthUserServiceImpl extends ServiceImpl<AuthUserMapper, SysUser> im
try {
boolean sendSmsSuccess = DySmsHelper.sendSms(phone, obj, DySmsEnum.LOGIN_TEMPLATE_CODE);
if(!sendSmsSuccess){
throw new JeecgBootException("短信验证码发送失败,请稍后重试!");
throw new STASException("短信验证码发送失败,请稍后重试!");
}
//验证码10分钟内有效
redisUtil.set(redisKey, captcha, 600);
} catch (ClientException e) {
log.error(e.getMessage(),e);
throw new JeecgBootException("短信接口未配置,请联系管理员!");
throw new STASException("短信接口未配置,请联系管理员!");
}
}
}

View File

@ -20,14 +20,13 @@ import org.apache.commons.lang3.ObjectUtils;
import org.jeecg.common.api.dto.DataLogDTO;
import org.jeecg.common.api.dto.OnlineAuthDTO;
import org.jeecg.common.api.dto.message.*;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.UrlMatchEnum;
import org.jeecg.common.constant.*;
import org.jeecg.common.constant.enums.EmailTemplateEnum;
import org.jeecg.common.constant.enums.MessageTypeEnum;
import org.jeecg.common.constant.enums.SysAnnmentTypeEnum;
import org.jeecg.common.desensitization.util.SensitiveInfoUtil;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.query.QueryCondition;
import org.jeecg.common.system.query.QueryGenerator;
@ -53,7 +52,6 @@ import org.jeecg.modules.system.vo.lowapp.SysDictVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
import org.springframework.util.AntPathMatcher;
@ -449,7 +447,7 @@ public class SysBaseApiImpl implements ISysBaseAPI {
List<SysMessageTemplate> sysSmsTemplates = sysMessageTemplateService.selectByCode(templateCode);
if(sysSmsTemplates==null||sysSmsTemplates.size()==0){
throw new JeecgBootException("消息模板不存在,模板编码:"+templateCode);
throw new STASException("消息模板不存在,模板编码:"+templateCode);
}
SysMessageTemplate sysSmsTemplate = sysSmsTemplates.get(0);
//模板标题
@ -518,7 +516,7 @@ public class SysBaseApiImpl implements ISysBaseAPI {
List<SysMessageTemplate> sysSmsTemplates = sysMessageTemplateService.selectByCode(templateCode);
if(sysSmsTemplates==null||sysSmsTemplates.size()==0){
throw new JeecgBootException("消息模板不存在,模板编码:"+templateCode);
throw new STASException("消息模板不存在,模板编码:"+templateCode);
}
SysMessageTemplate sysSmsTemplate = sysSmsTemplates.get(0);
//模板标题
@ -589,7 +587,7 @@ public class SysBaseApiImpl implements ISysBaseAPI {
Map<String, String> map = templateDTO.getTemplateParam();
List<SysMessageTemplate> sysSmsTemplates = sysMessageTemplateService.selectByCode(templateCode);
if(sysSmsTemplates==null||sysSmsTemplates.size()==0){
throw new JeecgBootException("消息模板不存在,模板编码:"+templateCode);
throw new STASException("消息模板不存在,模板编码:"+templateCode);
}
SysMessageTemplate sysSmsTemplate = sysSmsTemplates.get(0);
//模板内容
@ -1566,7 +1564,7 @@ public class SysBaseApiImpl implements ISysBaseAPI {
}
if(oConvertUtils.isEmpty(message.getContent())){
log.error("发送消息失败,消息内容为空!");
throw new JeecgBootException("发送消息失败,消息内容为空!");
throw new STASException("发送消息失败,消息内容为空!");
}
//update-end-author:taoyan date:2022-7-9 for: 将模板解析代码移至消息发送, 而不是调用的地方

View File

@ -7,7 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.constant.FillRuleConstant;
import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.util.FillRuleUtil;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.system.entity.SysCategory;
@ -73,15 +73,15 @@ public class SysCategoryServiceImpl extends ServiceImpl<SysCategoryMapper, SysCa
}
@Override
public List<TreeSelectModel> queryListByCode(String pcode) throws JeecgBootException{
public List<TreeSelectModel> queryListByCode(String pcode) throws STASException {
String pid = ROOT_PID_VALUE;
if(oConvertUtils.isNotEmpty(pcode)) {
List<SysCategory> list = baseMapper.selectList(new LambdaQueryWrapper<SysCategory>().eq(SysCategory::getCode, pcode));
if(list==null || list.size() ==0) {
throw new JeecgBootException("该编码【"+pcode+"】不存在,请核实!");
throw new STASException("该编码【"+pcode+"】不存在,请核实!");
}
if(list.size()>1) {
throw new JeecgBootException("该编码【"+pcode+"】存在多个,请核实!");
throw new STASException("该编码【"+pcode+"】存在多个,请核实!");
}
pid = list.get(0).getId();
}

View File

@ -10,7 +10,7 @@ import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.constant.enums.FileTypeEnum;
import org.jeecg.common.constant.enums.MessageTypeEnum;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.vo.SysFilesModel;
import org.jeecg.common.util.CommonUtils;
@ -26,7 +26,6 @@ import org.jeecg.modules.system.vo.SysCommentVO;
import org.jeecg.modules.system.vo.UserAvatar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.FileCopyUtils;
@ -128,7 +127,7 @@ public class SysCommentServiceImpl extends ServiceImpl<SysCommentMapper, SysComm
//LOWCOD-2580 sys/common/upload接口存在任意文件上传漏洞
if (oConvertUtils.isNotEmpty(bizPath)) {
if (bizPath.contains(SymbolConstant.SPOT_SINGLE_SLASH) || bizPath.contains(SymbolConstant.SPOT_DOUBLE_BACKSLASH)) {
throw new JeecgBootException("上传目录bizPath格式非法");
throw new STASException("上传目录bizPath格式非法");
}
}
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
@ -350,7 +349,7 @@ public class SysCommentServiceImpl extends ServiceImpl<SysCommentMapper, SysComm
private String uploadLocal(MultipartFile mf, String bizPath) {
//LOWCOD-2580 sys/common/upload接口存在任意文件上传漏洞
if (oConvertUtils.isNotEmpty(bizPath) && (bizPath.contains("../") || bizPath.contains("..\\"))) {
throw new JeecgBootException("上传目录bizPath格式非法");
throw new STASException("上传目录bizPath格式非法");
}
try {
String ctxPath = uploadpath;

View File

@ -7,14 +7,13 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import me.zhyd.oauth.model.AuthUser;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.config.TenantContext;
import org.jeecg.common.constant.CacheConstant;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.DataBaseConstant;
import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.util.ResourceUtil;
@ -114,7 +113,7 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
}catch(MyBatisSystemException e){
log.error(e.getMessage(), e);
String errorCause = "查询异常,请检查唯一校验的配置!";
throw new JeecgBootException(errorCause);
throw new STASException(errorCause);
}
// 4.返回结果
@ -830,11 +829,11 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
String id = sysDictVo.getId();
SysDict dict = baseMapper.selectById(id);
if(null == dict){
throw new JeecgBootException("字典数据不存在");
throw new STASException("字典数据不存在");
}
//判断应用id和数据库中的是否一致不一致不让修改
if(!dict.getLowAppId().equals(sysDictVo.getLowAppId())){
throw new JeecgBootException("字典数据不存在");
throw new STASException("字典数据不存在");
}
SysDict sysDict = new SysDict();
sysDict.setDictName(sysDictVo.getDictName());

View File

@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.constant.CacheConstant;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.config.mybatis.MybatisPlusSaasConfig;
import org.jeecg.modules.system.entity.SysPermission;
@ -78,10 +78,10 @@ public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, S
@Override
@Transactional(rollbackFor = Exception.class)
@CacheEvict(value = CacheConstant.SYS_DATA_PERMISSIONS_CACHE,allEntries=true)
public void deletePermission(String id) throws JeecgBootException {
public void deletePermission(String id) throws STASException {
SysPermission sysPermission = this.getById(id);
if(sysPermission==null) {
throw new JeecgBootException("未找到菜单信息");
throw new STASException("未找到菜单信息");
}
String pid = sysPermission.getParentId();
if(oConvertUtils.isNotEmpty(pid)) {
@ -153,10 +153,10 @@ public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, S
@Override
@CacheEvict(value = CacheConstant.SYS_DATA_PERMISSIONS_CACHE,allEntries=true)
//@CacheEvict(value = CacheConstant.SYS_DATA_PERMISSIONS_CACHE,allEntries=true,condition="#sysPermission.menuType==2")
public void deletePermissionLogical(String id) throws JeecgBootException {
public void deletePermissionLogical(String id) throws STASException {
SysPermission sysPermission = this.getById(id);
if(sysPermission==null) {
throw new JeecgBootException("未找到菜单信息");
throw new STASException("未找到菜单信息");
}
String pid = sysPermission.getParentId();
Long count = this.count(new QueryWrapper<SysPermission>().lambda().eq(SysPermission::getParentId, pid));
@ -170,7 +170,7 @@ public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, S
@Override
@CacheEvict(value = CacheConstant.SYS_DATA_PERMISSIONS_CACHE,allEntries=true)
public void addPermission(SysPermission sysPermission) throws JeecgBootException {
public void addPermission(SysPermission sysPermission) throws STASException {
//----------------------------------------------------------------------
//判断是否是一级菜单是的话清空父菜单
if(CommonConstant.MENU_TYPE_0.equals(sysPermission.getMenuType())) {
@ -190,11 +190,11 @@ public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, S
@Override
@CacheEvict(value = CacheConstant.SYS_DATA_PERMISSIONS_CACHE,allEntries=true)
public void editPermission(SysPermission sysPermission) throws JeecgBootException {
public void editPermission(SysPermission sysPermission) throws STASException {
SysPermission p = this.getById(sysPermission.getId());
//TODO 该节点判断是否还有子节点
if(p==null) {
throw new JeecgBootException("未找到菜单信息");
throw new STASException("未找到菜单信息");
}else {
sysPermission.setUpdateTime(new Date());
//----------------------------------------------------------------------

View File

@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.util.ImportExcelUtil;
import org.jeecg.modules.system.entity.SysRole;
import org.jeecg.modules.system.mapper.AuthRoleMapper;
@ -116,7 +116,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
query.eq(SysRole::getRoleCode,"admin");
Long adminRoleCount = sysRoleMapper.selectCount(query);
if(adminRoleCount>0){
throw new JeecgBootException("admin角色不允许删除");
throw new STASException("admin角色不允许删除");
}
}
}

View File

@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.config.firewall.SqlInjection.IDictTableWhiteListHandler;
import org.jeecg.modules.system.entity.SysTableWhiteList;
@ -59,13 +59,13 @@ public class SysTableWhiteListServiceImpl extends ServiceImpl<SysTableWhiteListM
*/
private void checkEntity(SysTableWhiteList sysTableWhiteList) {
if (sysTableWhiteList == null) {
throw new JeecgBootException("操作失败,实体为空!");
throw new STASException("操作失败,实体为空!");
}
if (oConvertUtils.isEmpty(sysTableWhiteList.getTableName())) {
throw new JeecgBootException("操作失败,表名不能为空!");
throw new STASException("操作失败,表名不能为空!");
}
if (oConvertUtils.isEmpty(sysTableWhiteList.getFieldName())) {
throw new JeecgBootException("操作失败,字段名不能为空!");
throw new STASException("操作失败,字段名不能为空!");
}
// 将表名和字段名转换成小写
sysTableWhiteList.setTableName(sysTableWhiteList.getTableName().toLowerCase());
@ -93,10 +93,10 @@ public class SysTableWhiteListServiceImpl extends ServiceImpl<SysTableWhiteListM
@Override
public SysTableWhiteList autoAdd(String tableName, String fieldName) {
if (oConvertUtils.isEmpty(tableName)) {
throw new JeecgBootException("操作失败,表名不能为空!");
throw new STASException("操作失败,表名不能为空!");
}
if (oConvertUtils.isEmpty(fieldName)) {
throw new JeecgBootException("操作失败,字段名不能为空!");
throw new STASException("操作失败,字段名不能为空!");
}
// 统一转换成小写
tableName = tableName.toLowerCase();
@ -108,7 +108,7 @@ public class SysTableWhiteListServiceImpl extends ServiceImpl<SysTableWhiteListM
if (getEntity != null) {
// 如果已经存在并且已禁用则抛出异常
if (CommonConstant.STATUS_0.equals(getEntity.getStatus())) {
throw new JeecgBootException("[白名单] 表名已存在但是已被禁用请先启用tableName=" + tableName);
throw new STASException("[白名单] 表名已存在但是已被禁用请先启用tableName=" + tableName);
}
// 合并字段
Set<String> oldFieldSet = new HashSet<>(Arrays.asList(getEntity.getFieldName().split(",")));

View File

@ -3,7 +3,7 @@ package ${bussiPackage}.${entityPackage}.service;
import org.jeecg.common.system.vo.SelectTreeModel;
import ${bussiPackage}.${entityPackage}.entity.${entityName};
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.List;

View File

@ -1,7 +1,7 @@
package ${bussiPackage}.${entityPackage}.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.common.system.vo.SelectTreeModel;
import ${bussiPackage}.${entityPackage}.entity.${entityName};

View File

@ -14,6 +14,9 @@ import org.jeecg.vo.FileVo;
import org.jeecg.vo.WeatherResultVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import ucar.ma2.Array;
import ucar.nc2.NetcdfFile;
import ucar.nc2.Variable;
import java.io.FileInputStream;
import java.io.IOException;
@ -77,11 +80,37 @@ public class WeatherDataController {
}
public static void main(String[] args) {
try {
String md5 = calculateMD5("F:\\工作\\五木\\放射性核素监测数据综合分析及氙本底源解析系统\\其他资料\\气象数据\\中国CRA40再分析数据\\CRA40\\20250523\\CRA40_AVO_2025052300_GLB_0P25_HOUR_V1_0_0.grib2");
System.out.println("MD5: " + md5);
} catch (IOException e) {
e.printStackTrace();
//reftime_ISO
String filePath = "F:\\工作\\五木\\放射性核素监测数据综合分析及氙本底源解析系统\\其他资料\\气象数据\\中国CRA40再分析数据\\CRA40\\20250523\\CRA40_AVO_2025052300_GLB_0P25_HOUR_V1_0_0.grib2";
String filePath1 = "F:\\工作\\五木\\放射性核素监测数据综合分析及氙本底源解析系统\\其他资料\\气象数据\\中国CRA40再分析数据\\GRAPES\\2024110100\\Z_NAFP_C_BABJ_20241101000000_P_NWPC-GRAPES-GFS-HNEHE-00000.grib2";
String filePath2 = "F:\\工作\\五木\\放射性核素监测数据综合分析及氙本底源解析系统\\其他资料\\气象数据\\盘古模型预测数据\\panguweather_2025073106.grib";
// try {
// String md5 = calculateMD5("F:\\工作\\五木\\放射性核素监测数据综合分析及氙本底源解析系统\\其他资料\\气象数据\\中国CRA40再分析数据\\CRA40\\20250523\\CRA40_AVO_2025052300_GLB_0P25_HOUR_V1_0_0.grib2");
// System.out.println("MD5: " + md5);
// } catch (IOException e) {
// e.printStackTrace();
// }
try (NetcdfFile ncFile = NetcdfFile.open(filePath2)) {
Variable variable = ncFile.findVariable("reftime_ISO");
if (variable != null) {
Array data = variable.read();
System.out.println(variable.getFullName());
System.out.println(data.getObject(0));
}
// int index = 0;
// for (Variable variable : ncFile.getVariables()) {
// if (variable != null) {
// Array data = variable.read();
// System.out.println(variable.getFullName());
// System.out.println(data);
// if (index == 7) {
// break;
// }
// index++;
// }
// }
}catch (Exception e){
}
}
}

View File

@ -3,6 +3,7 @@ package org.jeecg.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
@ -48,6 +49,13 @@ public class WeatherTaskController {
return Result.OK();
}
@AutoLog(value = "获取单条天气预测任务记录")
@Operation(summary = "获取单条天气预测任务记录")
@GetMapping("getById")
public Result<?> getById(@NotNull(message = "ID不能为空") String id){
return Result.OK(weatherTaskService.getById(id));
}
@AutoLog(value = "修改天气预测任务")
@Operation(summary = "修改天气预测任务")
@PutMapping("update")

View File

@ -31,6 +31,13 @@ public interface WeatherTaskService extends IService<WeatherTask> {
*/
void cteate(WeatherTask weatherTask);
/**
* 获取单条任务数据
* @param id
* @return
*/
WeatherTask getById(String id);
/**
* 修改天气预报预测任务
* @param weatherTask

View File

@ -9,10 +9,12 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.constant.enums.WeatherDataSourceEnum;
import org.jeecg.common.constant.enums.WeatherTypeEnum;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.exception.STASException;
import org.jeecg.common.exception.STASFileUploadException;
import org.jeecg.common.properties.SystemStorageProperties;
import org.jeecg.common.system.query.PageRequest;
import org.jeecg.common.util.NcUtil;
@ -24,7 +26,10 @@ import org.jeecg.vo.FileUploadResultVo;
import org.jeecg.vo.FileVo;
import org.jeecg.vo.WeatherResultVO;
import org.springframework.beans.BeanUtils;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import ucar.nc2.NetcdfFile;
@ -48,6 +53,8 @@ import java.util.Objects;
public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, WeatherData> implements WeatherDataService {
private final SystemStorageProperties systemStorageProperties;
private final DataSourceTransactionManager transactionManager;
private final TransactionDefinition transactionDefinition;
/**
* 根据类型和小时数获取天气数据
@ -80,7 +87,7 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
}
} catch (Exception e) {
log.error("文件路径构建失败: type={}, hour={}", type, hour, e);
throw new JeecgBootException("文件路径处理失败", e);
throw new STASException("文件路径处理失败", e);
}
WeatherResultVO weatherResultVO = new WeatherResultVO();
@ -91,7 +98,7 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
if (lonData == null || lonData.isEmpty() || latData == null || latData.isEmpty()) {
log.error("经纬度数据为空: file={}", filePath);
throw new JeecgBootException("基础经纬度数据缺失");
throw new STASException("基础经纬度数据缺失");
}
// 按类型处理数据
@ -107,11 +114,11 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
} else if (WeatherTypeEnum.HUMIDITY.getKey().equals(type)) {
dataList = processHumidityData(ncFile, lonData, latData);
} else {
throw new JeecgBootException("未知天气类型!");
throw new STASException("未知天气类型!");
}
} catch (Exception e) {
log.error("天气数据处理失败: type={}", type, e);
throw new JeecgBootException("天气数据处理异常", e);
throw new STASException("天气数据处理异常", e);
}
// 结果处理
@ -127,15 +134,15 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
weatherResultVO.setDataList(dataList);
} catch (Exception e) {
log.error("结果数据处理失败", e);
throw new JeecgBootException("结果数据处理异常", e);
throw new STASException("结果数据处理异常", e);
}
} catch (IOException e) {
log.error("NetCDF文件处理失败: {}", filePath, e);
throw new JeecgBootException("文件读取失败", e);
throw new STASException("文件读取失败", e);
} catch (Exception e) {
log.error("未知处理错误", e);
throw new JeecgBootException("未知处理错误", e);
throw new STASException("未知处理错误", e);
}
return weatherResultVO;
@ -189,15 +196,20 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
*
* @param fileVo
*/
@Transactional(rollbackFor = RuntimeException.class)
@Override
public FileUploadResultVo uploadFile(FileVo fileVo) {
final TransactionStatus transactionStatus = this.transactionManager.getTransaction(transactionDefinition);
//文件保存路径
String storagePath = null;
//数据ID
String id= null;
//上传成功总体标记
boolean flag = true;
try{
MultipartFile file = fileVo.getFile();
//文件保存路径
String storagePath = this.getFileStoragePath(fileVo.getDataSource(), fileVo.getFileName());
storagePath = this.getFileStoragePath(fileVo.getDataSource(), fileVo.getFileName());
fileVo.setFilePath(storagePath);
//如果上传策略是分片则加分片后缀
if(fileVo.isFileShare()) {
storagePath += StringPool.DOT;
@ -212,7 +224,6 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
file.transferTo(shareFile);
//保存文件信息入库
String id= null;
FileExistVo fileExist = this.verifyFileExist(fileVo.getMd5Value());
if(fileExist.isExist()) {
WeatherData queryResult = this.baseMapper.selectById(fileExist.getFileId());
@ -225,44 +236,90 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
this.baseMapper.insert(weatherData);
id = weatherData.getId();
}
this.transactionManager.commit(transactionStatus);
}catch (Exception e) {
flag = false;
}
boolean flag = false;
if(fileVo.isFileShare()) {
if(fileVo.getShareIndex() == (fileVo.getShareTotal()-1)) {
this.merge(fileVo);
flag = true;
}
flag = this.merge(fileVo);
}else {
flag = true;
//未合并之前需先是false不然后面就开始处理气象文件数据开始时间和计算文件大小
flag = false;
}
}
if(flag) {
final TransactionStatus updateTransactionStatus = this.transactionManager.getTransaction(transactionDefinition);
try{
//处理气象文件数据开始时间和计算文件大小
WeatherData queryResult = this.baseMapper.selectById(id);
File dataFile = new File(storagePath);
if(dataFile.exists() && dataFile.length()>0){
//获取文件数据开始日期
String reftime = NcUtil.getReftime(dataFile.getAbsolutePath());
if(StringUtils.isNotBlank(reftime)) {
if(StringUtils.isBlank(reftime)) {
throw new STASFileUploadException("解析气象文件起始时间数据异常,此文件可能损坏");
}
Instant instant = Instant.parse(reftime);
LocalDateTime utcDateTime = LocalDateTime.ofInstant(instant, ZoneId.of("UTC"));
queryResult.setDataStartTime(utcDateTime);
}
//计算文件大小M
BigDecimal divideVal = new BigDecimal("1024");
BigDecimal bg = new BigDecimal(dataFile.length());
BigDecimal fileSize = bg.divide(divideVal).divide(divideVal).setScale(2, RoundingMode.HALF_UP);
queryResult.setFileSize(fileSize.doubleValue());
//把文件移入新路径
int year = utcDateTime.getYear();
int month = utcDateTime.getMonth().getValue();
int day = utcDateTime.getDayOfMonth();
String newFileDirPath = dataFile.getParentFile().getParent()+File.separator+year+File.separator+month+File.separator+day;
String newFilePath = newFileDirPath+File.separator+dataFile.getName();
FileUtil.mkdir(newFileDirPath);
File parentDir = dataFile.getParentFile();
File[] files = parentDir.listFiles();
if(ArrayUtils.isNotEmpty(files)) {
for(File file : files) {
File targetFile = new File(newFileDirPath + File.separator + file.getName());
FileUtil.move(file,targetFile,true);
}
}
//删除临时目录
parentDir.delete();
//给原路径变量重新赋值
storagePath = newFileDirPath;
//修改文件新路径存到数据库
queryResult.setFilePath(newFilePath);
this.baseMapper.updateById(queryResult);
this.transactionManager.commit(updateTransactionStatus);
}
}catch (Exception e){
flag = false;
}
}
//如果单文件上传失败或者分片上传失败则删除数据
if((!flag && !fileVo.isFileShare()) ||
(!flag && fileVo.isFileShare() && fileVo.getShareIndex() == (fileVo.getShareTotal()-1))) {
String delDirPath = null;
File file = new File(storagePath);
if(file.exists() && file.isFile()){
delDirPath = file.getParent();
}else if(file.isDirectory()){
delDirPath = file.getAbsolutePath();
}
FileUtil.del(delDirPath);
final TransactionStatus delTransactionStatus = this.transactionManager.getTransaction(transactionDefinition);
this.baseMapper.deleteById(id);
this.transactionManager.commit(delTransactionStatus);
log.error("{}文件上传失败",fileVo.getFileName());
throw new RuntimeException(fileVo.getFileName()+"文件上传失败");
}
FileUploadResultVo result = new FileUploadResultVo();
result.setCompleted(flag);
result.setId(id);
return result;
}catch (Exception e){
throw new RuntimeException(e);
}
}
/**
@ -273,7 +330,20 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
@Transactional(rollbackFor = RuntimeException.class)
@Override
public void delete(List<String> ids) {
this.baseMapper.deleteBatchIds(ids);
List<WeatherData> weatherDatas = this.baseMapper.selectByIds(ids);
for(WeatherData weatherData : weatherDatas) {
//删除气象文件和生成的.gbx9.ncx2文件
File dataFile = new File(weatherData.getFilePath());
if(dataFile.exists()) {
File[] files = dataFile.getParentFile().listFiles();
for(File file : files) {
if(file.getName().startsWith(dataFile.getName()) || file.getName().equals(dataFile.getName())) {
file.delete();
}
}
}
this.baseMapper.deleteById(weatherData.getId());
}
}
/**
@ -281,12 +351,14 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
* @param fileVo
* @throws Exception
*/
private void merge(FileVo fileVo)throws Exception {
String storagePath = this.getFileStoragePath(fileVo.getDataSource(), fileVo.getFileName());
private boolean merge(FileVo fileVo) {
boolean mergeFlag = true;
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(storagePath,true));
String storagePath = this.getFileStoragePath(fileVo.getDataSource(), fileVo.getFileName());
BufferedOutputStream bos = null;
BufferedInputStream bis = null;
try {
bos = new BufferedOutputStream(new FileOutputStream(storagePath,true));
byte[] byt = new byte[10*1024];
int len;
for(int i=0;i<fileVo.getShareTotal();i++) {
@ -299,9 +371,10 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
}
}
} catch (Exception e) {
mergeFlag = false;
log.error(fileVo.getFileName()+"文件分片上传异常");
throw new RuntimeException("文件上传失败,请重新上传");
}finally {
try {
if(null != bos) {
bos.flush();
bos.close();
@ -309,15 +382,18 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
if(null != bis) {
bis.close();
}
}catch (Exception e){
mergeFlag = false;
}
}
//合并成功或失败都删除旧得分片
for(int i=0;i<fileVo.getShareTotal();i++) {
File file = new File(storagePath+"."+i);
if(file.exists()) {
file.delete();
}
}
return mergeFlag;
}
/**
@ -338,6 +414,8 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
storagePath.append(this.systemStorageProperties.getReAnalysis());
}
storagePath.append(File.separator);
storagePath.append(fileName.substring(0,fileName.lastIndexOf(StringPool.DOT)));
storagePath.append(File.separator);
storagePath.append(fileName);
return storagePath.toString();
}

View File

@ -77,6 +77,17 @@ public class WeatherTaskServiceImpl extends ServiceImpl<WeatherTaskMapper, Weath
this.save(weatherTask);
}
/**
* 获取单条任务数据
*
* @param id
* @return
*/
@Override
public WeatherTask getById(String id) {
return this.baseMapper.selectById(id);
}
/**
* 修改天气预报预测任务
* @param weatherTask