Search in sources :

Example 26 with JeecgBootException

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("删除定时任务失败");
    }
}
Also used : JeecgBootException(org.jeecg.common.exception.JeecgBootException) JeecgBootException(org.jeecg.common.exception.JeecgBootException)

Example 27 with 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);
    }
}
Also used : JeecgBootException(org.jeecg.common.exception.JeecgBootException) JeecgBootException(org.jeecg.common.exception.JeecgBootException)

Example 28 with JeecgBootException

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;
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) JeecgBootException(org.jeecg.common.exception.JeecgBootException) Result(org.jeecg.common.api.vo.Result) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest)

Example 29 with JeecgBootException

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;
}
Also used : Connection(java.sql.Connection) DatabaseMetaData(java.sql.DatabaseMetaData) IOException(java.io.IOException) SQLException(java.sql.SQLException) JeecgBootException(org.jeecg.common.exception.JeecgBootException)

Example 30 with JeecgBootException

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;
}
Also used : Connection(java.sql.Connection) DatabaseMetaData(java.sql.DatabaseMetaData) SQLException(java.sql.SQLException) JeecgBootException(org.jeecg.common.exception.JeecgBootException)

Aggregations

JeecgBootException (org.jeecg.common.exception.JeecgBootException)35 SQLException (java.sql.SQLException)11 SysMessageTemplate (org.jeecg.modules.message.entity.SysMessageTemplate)9 SysPermission (org.jeecg.modules.system.entity.SysPermission)9 CacheEvict (org.springframework.cache.annotation.CacheEvict)9 JSONObject (com.alibaba.fastjson.JSONObject)6 Connection (java.sql.Connection)5 DatabaseMetaData (java.sql.DatabaseMetaData)5 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 DynamicDataSourceModel (org.jeecg.common.system.vo.DynamicDataSourceModel)3 Transactional (org.springframework.transaction.annotation.Transactional)3 IOException (java.io.IOException)2 Result (org.jeecg.common.api.vo.Result)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 MultipartHttpServletRequest (org.springframework.web.multipart.MultipartHttpServletRequest)2 JeeccgBaseConfig (org.jeecg.config.JeeccgBaseConfig)1 OSSFile (org.jeecg.modules.oss.entity.OSSFile)1