Search in sources :

Example 16 with BizException

use of com.albedo.java.common.core.exception.BizException in project albedo by somowhere.

the class SysLogAspect method around.

@Around("@annotation(logOperate)")
@SneakyThrows
public Object around(ProceedingJoinPoint point, com.albedo.java.common.log.annotation.LogOperate logOperate) {
    MethodSignature signature = (MethodSignature) point.getSignature();
    String strClassName = point.getTarget().getClass().getName();
    String strMethodName = point.getSignature().getName();
    SysLogAspect.log.debug("[Class]:{},[Method]:{}", strClassName, strMethodName);
    // 方法路径
    String methodName = point.getTarget().getClass().getName() + StrPool.DOT + signature.getName() + "()";
    StringBuilder params = new StringBuilder("{");
    // 参数值
    Object[] argValues = point.getArgs();
    // 参数名称
    String[] argNames = ((MethodSignature) point.getSignature()).getParameterNames();
    if (argValues != null) {
        for (int i = 0; i < argValues.length; i++) {
            params.append(" ").append(argNames[i]).append(": ").append(argValues[i]);
        }
    }
    LogOperateDo logOperateDoVo = SysLogUtils.getSysLogOperate();
    logOperateDoVo.setTitle(logOperate.value());
    logOperateDoVo.setMethod(methodName);
    logOperateDoVo.setParams(params + " }");
    logOperateDoVo.setOperatorType(logOperate.operatorType().name());
    setDescription(point, logOperate, logOperateDoVo);
    Long startTime = System.currentTimeMillis();
    Object obj;
    try {
        obj = point.proceed();
        logOperateDoVo.setLogType(LogType.INFO.name());
    } catch (Exception e) {
        logOperateDoVo.setDescription(e.getMessage());
        if (e instanceof BizException) {
            logOperateDoVo.setLogType(LogType.WARN.name());
        } else {
            logOperateDoVo.setException(ExceptionUtil.stacktraceToString(e));
            logOperateDoVo.setLogType(LogType.ERROR.name());
        }
        throw e;
    } finally {
        saveLog(System.currentTimeMillis() - startTime, logOperateDoVo, logOperate);
    }
    return obj;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) LogOperateDo(com.albedo.java.modules.sys.domain.LogOperateDo) BizException(com.albedo.java.common.core.exception.BizException) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) BizException(com.albedo.java.common.core.exception.BizException) Around(org.aspectj.lang.annotation.Around) SneakyThrows(lombok.SneakyThrows)

Example 17 with BizException

use of com.albedo.java.common.core.exception.BizException in project albedo by somowhere.

the class SchemaInitSystemStrategy method initTables.

public void initTables(ScriptRunner runner, String tenant) {
    try {
        for (String database : INIT_DATABASE_LIST) {
            this.useDb(tenant, runner, database);
            runner.runScript(Resources.getResourceAsReader(String.format(SQL_RESOURCE_PATH, database)));
        }
    } catch (Exception e) {
        log.error("初始化表失败", e);
        throw new BizException("初始化表失败", e);
    }
}
Also used : BizException(com.albedo.java.common.core.exception.BizException) BizException(com.albedo.java.common.core.exception.BizException)

Example 18 with BizException

use of com.albedo.java.common.core.exception.BizException in project albedo by somowhere.

the class SchemaInitSystemStrategy method getScriptRunner.

@SuppressWarnings("AlibabaRemoveCommentedCode")
public ScriptRunner getScriptRunner() {
    try {
        Connection connection = this.dataSource.getConnection();
        ScriptRunner runner = new ScriptRunner(connection);
        runner.setAutoCommit(false);
        // 遇见错误是否停止
        runner.setStopOnError(true);
        /*
			 * 按照那种方式执行 方式一:true则获取整个脚本并执行; 方式二:false则按照自定义的分隔符每行执行;
			 */
        runner.setSendFullScript(true);
        // 设置是否输出日志,null不输出日志,不设置自动将日志输出到控制台
        // runner.setLogWriter(null);
        Resources.setCharset(StandardCharsets.UTF_8);
        // 设置分隔符 runner.setDelimiter(";");
        runner.setFullLineDelimiter(false);
        return runner;
    } catch (Exception ex) {
        throw new BizException("获取连接失败", ex);
    }
}
Also used : BizException(com.albedo.java.common.core.exception.BizException) Connection(java.sql.Connection) ScriptRunner(org.apache.ibatis.jdbc.ScriptRunner) BizException(com.albedo.java.common.core.exception.BizException)

Example 19 with BizException

use of com.albedo.java.common.core.exception.BizException in project albedo by somowhere.

the class SchemaInitSystemStrategy method initData.

/**
 * 角色表
 * 菜单表
 * 资源表
 *
 * @param tenant 租户编码
 */
public void initData(ScriptRunner runner, String tenant) {
    try {
        for (String database : INIT_DATABASE_LIST) {
            this.useDb(tenant, runner, database);
            String dataScript = database + "_data";
            runner.runScript(Resources.getResourceAsReader(String.format(SQL_RESOURCE_PATH, dataScript)));
        }
    } catch (Exception e) {
        log.error("初始化数据失败", e);
        throw new BizException("初始化数据失败", e);
    }
}
Also used : BizException(com.albedo.java.common.core.exception.BizException) BizException(com.albedo.java.common.core.exception.BizException)

Example 20 with BizException

use of com.albedo.java.common.core.exception.BizException in project albedo by somowhere.

the class FileUploadUtil method upload.

/**
 * 文件上传
 *
 * @param baseDir          相对应用的基目录
 * @param file             上传的文件
 * @param allowedExtension 上传文件类型
 * @return 返回上传成功的文件名
 * @throws IOException 比如读写文件出错时
 */
public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension) throws IOException {
    int fileNamelength = file.getOriginalFilename().length();
    if (fileNamelength > FileUploadUtil.DEFAULT_FILE_NAME_LENGTH) {
        throw new BizException("最大文件名长度:" + FileUploadUtil.DEFAULT_FILE_NAME_LENGTH);
    }
    assertAllowed(file, allowedExtension);
    String fileName = extractFilename(file);
    File desc = getAbsoluteFile(baseDir, fileName);
    file.transferTo(desc);
    String pathFileName = getPathFileName(baseDir, fileName);
    return pathFileName;
}
Also used : BizException(com.albedo.java.common.core.exception.BizException) MultipartFile(org.springframework.web.multipart.MultipartFile) File(java.io.File)

Aggregations

BizException (com.albedo.java.common.core.exception.BizException)22 UserDo (com.albedo.java.modules.sys.domain.UserDo)3 SneakyThrows (lombok.SneakyThrows)3 RoleDo (com.albedo.java.modules.sys.domain.RoleDo)2 AlipayClient (com.alipay.api.AlipayClient)2 DefaultAlipayClient (com.alipay.api.DefaultAlipayClient)2 IORuntimeException (cn.hutool.core.io.IORuntimeException)1 TableColumnDo (com.albedo.java.modules.gen.domain.TableColumnDo)1 TableDo (com.albedo.java.modules.gen.domain.TableDo)1 SchemeDto (com.albedo.java.modules.gen.domain.dto.SchemeDto)1 TableDto (com.albedo.java.modules.gen.domain.dto.TableDto)1 TemplateVo (com.albedo.java.modules.gen.domain.vo.TemplateVo)1 GenConfig (com.albedo.java.modules.gen.domain.xml.GenConfig)1 Job (com.albedo.java.modules.quartz.domain.Job)1 DictCacheKeyBuilder (com.albedo.java.modules.sys.cache.DictCacheKeyBuilder)1 DeptDo (com.albedo.java.modules.sys.domain.DeptDo)1 DictDo (com.albedo.java.modules.sys.domain.DictDo)1 LogOperateDo (com.albedo.java.modules.sys.domain.LogOperateDo)1 MenuDo (com.albedo.java.modules.sys.domain.MenuDo)1 RoleMenuDo (com.albedo.java.modules.sys.domain.RoleMenuDo)1