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;
}
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);
}
}
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);
}
}
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);
}
}
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;
}
Aggregations