Search in sources :

Example 11 with JeecgBootException

use of org.jeecg.common.exception.JeecgBootException in project kykms by mahonelau.

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 12 with JeecgBootException

use of org.jeecg.common.exception.JeecgBootException in project kykms by mahonelau.

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 13 with JeecgBootException

use of org.jeecg.common.exception.JeecgBootException in project kykms by mahonelau.

the class DynamicDBUtil method getDbSourceByDbKey.

/**
 * 通过 dbKey ,获取数据源
 *
 * @param dbKey
 * @return
 */
public static DruidDataSource getDbSourceByDbKey(final String dbKey) {
    // 获取多数据源配置
    DynamicDataSourceModel dbSource = DataSourceCachePool.getCacheDynamicDataSourceModel(dbKey);
    // 先判断缓存中是否存在数据库链接
    DruidDataSource cacheDbSource = DataSourceCachePool.getCacheBasicDataSource(dbKey);
    if (cacheDbSource != null && !cacheDbSource.isClosed()) {
        log.debug("--------getDbSourceBydbKey------------------从缓存中获取DB连接-------------------");
        return cacheDbSource;
    } else {
        DruidDataSource dataSource = getJdbcDataSource(dbSource);
        if (dataSource != null && dataSource.isEnable()) {
            DataSourceCachePool.putCacheBasicDataSource(dbKey, dataSource);
        } else {
            throw new JeecgBootException("动态数据源连接失败,dbKey:" + dbKey);
        }
        log.info("--------getDbSourceBydbKey------------------创建DB数据库连接-------------------");
        return dataSource;
    }
}
Also used : JeecgBootException(org.jeecg.common.exception.JeecgBootException) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) DynamicDataSourceModel(org.jeecg.common.system.vo.DynamicDataSourceModel)

Example 14 with JeecgBootException

use of org.jeecg.common.exception.JeecgBootException in project kms by mahonelau.

the class DynamicDBUtil method getDbSourceByDbKey.

/**
 * 通过 dbKey ,获取数据源
 *
 * @param dbKey
 * @return
 */
public static DruidDataSource getDbSourceByDbKey(final String dbKey) {
    // 获取多数据源配置
    DynamicDataSourceModel dbSource = DataSourceCachePool.getCacheDynamicDataSourceModel(dbKey);
    // 先判断缓存中是否存在数据库链接
    DruidDataSource cacheDbSource = DataSourceCachePool.getCacheBasicDataSource(dbKey);
    if (cacheDbSource != null && !cacheDbSource.isClosed()) {
        log.debug("--------getDbSourceBydbKey------------------从缓存中获取DB连接-------------------");
        return cacheDbSource;
    } else {
        DruidDataSource dataSource = getJdbcDataSource(dbSource);
        if (dataSource != null && dataSource.isEnable()) {
            DataSourceCachePool.putCacheBasicDataSource(dbKey, dataSource);
        } else {
            throw new JeecgBootException("动态数据源连接失败,dbKey:" + dbKey);
        }
        log.info("--------getDbSourceBydbKey------------------创建DB数据库连接-------------------");
        return dataSource;
    }
}
Also used : JeecgBootException(org.jeecg.common.exception.JeecgBootException) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) DynamicDataSourceModel(org.jeecg.common.system.vo.DynamicDataSourceModel)

Example 15 with JeecgBootException

use of org.jeecg.common.exception.JeecgBootException in project kms by mahonelau.

the class SysBaseApiImpl method sendTemplateAnnouncement.

@Override
public void sendTemplateAnnouncement(TemplateMessageDTO message) {
    String templateCode = message.getTemplateCode();
    String title = message.getTitle();
    Map<String, String> map = message.getTemplateParam();
    String fromUser = message.getFromUser();
    String toUser = message.getToUser();
    List<SysMessageTemplate> sysSmsTemplates = sysMessageTemplateService.selectByCode(templateCode);
    if (sysSmsTemplates == null || sysSmsTemplates.size() == 0) {
        throw new JeecgBootException("消息模板不存在,模板编码:" + templateCode);
    }
    SysMessageTemplate sysSmsTemplate = sysSmsTemplates.get(0);
    // 模板标题
    title = title == null ? sysSmsTemplate.getTemplateName() : title;
    // 模板内容
    String content = sysSmsTemplate.getTemplateContent();
    if (map != null) {
        for (Map.Entry<String, String> entry : map.entrySet()) {
            String str = "${" + entry.getKey() + "}";
            if (oConvertUtils.isNotEmpty(title)) {
                title = title.replace(str, entry.getValue());
            }
            content = content.replace(str, entry.getValue());
        }
    }
    SysAnnouncement announcement = new SysAnnouncement();
    announcement.setTitile(title);
    announcement.setMsgContent(content);
    announcement.setSender(fromUser);
    announcement.setPriority(CommonConstant.PRIORITY_M);
    announcement.setMsgType(CommonConstant.MSG_TYPE_UESR);
    announcement.setSendStatus(CommonConstant.HAS_SEND);
    announcement.setSendTime(new Date());
    announcement.setMsgCategory(CommonConstant.MSG_CATEGORY_2);
    announcement.setDelFlag(String.valueOf(CommonConstant.DEL_FLAG_0));
    sysAnnouncementMapper.insert(announcement);
    // 2.插入用户通告阅读标记表记录
    String userId = toUser;
    String[] userIds = userId.split(",");
    String anntId = announcement.getId();
    for (int i = 0; i < userIds.length; i++) {
        if (oConvertUtils.isNotEmpty(userIds[i])) {
            SysUser sysUser = userMapper.getUserByName(userIds[i]);
            if (sysUser == null) {
                continue;
            }
            SysAnnouncementSend announcementSend = new SysAnnouncementSend();
            announcementSend.setAnntId(anntId);
            announcementSend.setUserId(sysUser.getId());
            announcementSend.setReadFlag(CommonConstant.NO_READ_FLAG);
            sysAnnouncementSendMapper.insert(announcementSend);
            JSONObject obj = new JSONObject();
            obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_USER);
            obj.put(WebsocketConst.MSG_USER_ID, sysUser.getId());
            obj.put(WebsocketConst.MSG_ID, announcement.getId());
            obj.put(WebsocketConst.MSG_TXT, announcement.getTitile());
            webSocket.sendMessage(sysUser.getId(), obj.toJSONString());
        }
    }
    try {
        // 同步企业微信、钉钉的消息通知
        dingtalkService.sendActionCardMessage(announcement, true);
        wechatEnterpriseService.sendTextCardMessage(announcement, true);
    } catch (Exception e) {
        log.error("同步发送第三方APP消息失败!", e);
    }
}
Also used : SQLException(java.sql.SQLException) JeecgBootException(org.jeecg.common.exception.JeecgBootException) JSONObject(com.alibaba.fastjson.JSONObject) SysMessageTemplate(org.jeecg.modules.message.entity.SysMessageTemplate) 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