Search in sources :

Example 6 with JeecgBootException

use of org.jeecg.common.exception.JeecgBootException in project kms 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 7 with JeecgBootException

use of org.jeecg.common.exception.JeecgBootException in project kms 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 8 with JeecgBootException

use of org.jeecg.common.exception.JeecgBootException in project kms 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)

Example 9 with JeecgBootException

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

the class SysBaseApiImpl method sendBusTemplateAnnouncement.

@Override
public void sendBusTemplateAnnouncement(BusTemplateMessageDTO message) {
    String templateCode = message.getTemplateCode();
    String title = message.getTitle();
    Map<String, String> map = message.getTemplateParam();
    String fromUser = message.getFromUser();
    String toUser = message.getToUser();
    String busId = message.getBusId();
    String busType = message.getBusType();
    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() + "}";
            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));
    announcement.setBusId(busId);
    announcement.setBusType(busType);
    announcement.setOpenType(SysAnnmentTypeEnum.getByType(busType).getOpenType());
    announcement.setOpenPage(SysAnnmentTypeEnum.getByType(busType).getOpenPage());
    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)

Example 10 with JeecgBootException

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

the class SysPermissionServiceImpl method editPermission.

@Override
@CacheEvict(value = CacheConstant.SYS_DATA_PERMISSIONS_CACHE, allEntries = true)
public void editPermission(SysPermission sysPermission) throws JeecgBootException {
    SysPermission p = this.getById(sysPermission.getId());
    // TODO 该节点判断是否还有子节点
    if (p == null) {
        throw new JeecgBootException("未找到菜单信息");
    } else {
        sysPermission.setUpdateTime(new Date());
        // Step1.判断是否是一级菜单,是的话清空父菜单ID
        if (CommonConstant.MENU_TYPE_0.equals(sysPermission.getMenuType())) {
            sysPermission.setParentId("");
        }
        // Step2.判断菜单下级是否有菜单,无则设置为叶子节点
        int count = this.count(new QueryWrapper<SysPermission>().lambda().eq(SysPermission::getParentId, sysPermission.getId()));
        if (count == 0) {
            sysPermission.setLeaf(true);
        }
        // ----------------------------------------------------------------------
        this.updateById(sysPermission);
        // 如果当前菜单的父菜单变了,则需要修改新父菜单和老父菜单的,叶子节点状态
        String pid = sysPermission.getParentId();
        if ((oConvertUtils.isNotEmpty(pid) && !pid.equals(p.getParentId())) || oConvertUtils.isEmpty(pid) && oConvertUtils.isNotEmpty(p.getParentId())) {
            // a.设置新的父菜单不为叶子节点
            this.sysPermissionMapper.setMenuLeaf(pid, 0);
            // b.判断老的菜单下是否还有其他子菜单,没有的话则设置为叶子节点
            int cc = this.count(new QueryWrapper<SysPermission>().lambda().eq(SysPermission::getParentId, p.getParentId()));
            if (cc == 0) {
                if (oConvertUtils.isNotEmpty(p.getParentId())) {
                    this.sysPermissionMapper.setMenuLeaf(p.getParentId(), 1);
                }
            }
        }
    }
}
Also used : SysPermission(org.jeecg.modules.system.entity.SysPermission) JeecgBootException(org.jeecg.common.exception.JeecgBootException) Date(java.util.Date) CacheEvict(org.springframework.cache.annotation.CacheEvict)

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