use of org.jeecg.common.exception.JeecgBootException in project jeecg-boot by jeecgboot.
the class QuartzJobServiceImpl method schedulerDelete.
/**
* 删除定时任务
*
* @param id
*/
private void schedulerDelete(String id) {
try {
scheduler.pauseTrigger(TriggerKey.triggerKey(id));
scheduler.unscheduleJob(TriggerKey.triggerKey(id));
scheduler.deleteJob(JobKey.jobKey(id));
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new JeecgBootException("删除定时任务失败");
}
}
use of org.jeecg.common.exception.JeecgBootException in project jeecg-boot by jeecgboot.
the class QuartzJobServiceImpl method schedulerAdd.
/**
* 添加定时任务
*
* @param jobClassName
* @param cronExpression
* @param parameter
*/
private void schedulerAdd(String id, String jobClassName, String cronExpression, String parameter) {
try {
// 启动调度器
scheduler.start();
// 构建job信息
JobDetail jobDetail = JobBuilder.newJob(getClass(jobClassName).getClass()).withIdentity(id).usingJobData("parameter", parameter).build();
// 表达式调度构建器(即任务执行的时间)
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression);
// 按新的cronExpression表达式构建一个新的trigger
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(id).withSchedule(scheduleBuilder).build();
scheduler.scheduleJob(jobDetail, trigger);
} catch (SchedulerException e) {
throw new JeecgBootException("创建定时任务失败", e);
} catch (RuntimeException e) {
throw new JeecgBootException(e.getMessage(), e);
} catch (Exception e) {
throw new JeecgBootException("后台找不到该类名:" + jobClassName, e);
}
}
use of org.jeecg.common.exception.JeecgBootException in project jeecg-boot by jeecgboot.
the class CommonController method upload.
/**
* 文件上传统一方法
* @param request
* @param response
* @return
*/
@PostMapping(value = "/upload")
public Result<?> upload(HttpServletRequest request, HttpServletResponse response) {
Result<?> result = new Result<>();
String savePath = "";
String bizPath = request.getParameter("biz");
// LOWCOD-2580 sys/common/upload接口存在任意文件上传漏洞
if (oConvertUtils.isNotEmpty(bizPath) && (bizPath.contains("../") || bizPath.contains("..\\"))) {
throw new JeecgBootException("上传目录bizPath,格式非法!");
}
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
// 获取上传文件对象
MultipartFile file = multipartRequest.getFile("file");
if (oConvertUtils.isEmpty(bizPath)) {
if (CommonConstant.UPLOAD_TYPE_OSS.equals(uploadType)) {
// 未指定目录,则用阿里云默认目录 upload
bizPath = "upload";
// result.setMessage("使用阿里云文件上传时,必须添加目录!");
// result.setSuccess(false);
// return result;
} else {
bizPath = "";
}
}
if (CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)) {
// update-begin-author:lvdandan date:20200928 for:修改JEditor编辑器本地上传
savePath = this.uploadLocal(file, bizPath);
// update-begin-author:lvdandan date:20200928 for:修改JEditor编辑器本地上传
/**
* 富文本编辑器及markdown本地上传时,采用返回链接方式
* //针对jeditor编辑器如何使 lcaol模式,采用 base64格式存储
* String jeditor = request.getParameter("jeditor");
* if(oConvertUtils.isNotEmpty(jeditor)){
* result.setMessage(CommonConstant.UPLOAD_TYPE_LOCAL);
* result.setSuccess(true);
* return result;
* }else{
* savePath = this.uploadLocal(file,bizPath);
* }
*/
} else {
// update-begin-author:taoyan date:20200814 for:文件上传改造
savePath = CommonUtils.upload(file, bizPath, uploadType);
// update-end-author:taoyan date:20200814 for:文件上传改造
}
if (oConvertUtils.isNotEmpty(savePath)) {
result.setMessage(savePath);
result.setSuccess(true);
} else {
result.setMessage("上传失败!");
result.setSuccess(false);
}
return result;
}
use of org.jeecg.common.exception.JeecgBootException in project kykms by mahonelau.
the class CommonUtils method getDatabaseTypeByDataSource.
/**
* 获取数据库类型
* @param dataSource
* @return
* @throws SQLException
*/
private static String getDatabaseTypeByDataSource(DataSource dataSource) throws SQLException {
if ("".equals(DB_TYPE)) {
Connection connection = dataSource.getConnection();
try {
DatabaseMetaData md = connection.getMetaData();
String dbType = md.getDatabaseProductName().toLowerCase();
if (dbType.indexOf("mysql") >= 0) {
DB_TYPE = DataBaseConstant.DB_TYPE_MYSQL;
} else if (dbType.indexOf("oracle") >= 0 || dbType.indexOf("dm") >= 0) {
DB_TYPE = DataBaseConstant.DB_TYPE_ORACLE;
} else if (dbType.indexOf("sqlserver") >= 0 || dbType.indexOf("sql server") >= 0) {
DB_TYPE = DataBaseConstant.DB_TYPE_SQLSERVER;
} else if (dbType.indexOf("postgresql") >= 0) {
DB_TYPE = DataBaseConstant.DB_TYPE_POSTGRESQL;
} else if (dbType.indexOf("mariadb") >= 0) {
DB_TYPE = DataBaseConstant.DB_TYPE_MARIADB;
} else {
log.error("数据库类型:[" + dbType + "]不识别!");
// throw new JeecgBootException("数据库类型:["+dbType+"]不识别!");
}
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
connection.close();
}
}
return DB_TYPE;
}
use of org.jeecg.common.exception.JeecgBootException in project kykms by mahonelau.
the class SysBaseApiImpl method getDatabaseTypeByDataSource.
/**
* 获取数据库类型
* @param dataSource
* @return
* @throws SQLException
*/
private String getDatabaseTypeByDataSource(DataSource dataSource) throws SQLException {
if ("".equals(DB_TYPE)) {
Connection connection = dataSource.getConnection();
try {
DatabaseMetaData md = connection.getMetaData();
String dbType = md.getDatabaseProductName().toLowerCase();
if (dbType.indexOf("mysql") >= 0) {
DB_TYPE = DataBaseConstant.DB_TYPE_MYSQL;
} else if (dbType.indexOf("oracle") >= 0) {
DB_TYPE = DataBaseConstant.DB_TYPE_ORACLE;
} else if (dbType.indexOf("sqlserver") >= 0 || dbType.indexOf("sql server") >= 0) {
DB_TYPE = DataBaseConstant.DB_TYPE_SQLSERVER;
} else if (dbType.indexOf("postgresql") >= 0) {
DB_TYPE = DataBaseConstant.DB_TYPE_POSTGRESQL;
} else if (dbType.indexOf("mariadb") >= 0) {
DB_TYPE = DataBaseConstant.DB_TYPE_MARIADB;
} else {
log.error("数据库类型:[" + dbType + "]不识别!");
// throw new JeecgBootException("数据库类型:["+dbType+"]不识别!");
}
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
connection.close();
}
}
return DB_TYPE;
}
Aggregations