Search in sources :

Example 1 with JeecgBootException

use of org.jeecg.common.exception.JeecgBootException in project jeecg-boot by jeecgboot.

the class SysUploadController method uploadMinio.

/**
 * 上传
 * @param request
 */
@PostMapping(value = "/uploadMinio")
public Result<?> uploadMinio(HttpServletRequest request) {
    Result<?> result = new Result<>();
    String bizPath = request.getParameter("biz");
    // LOWCOD-2580 sys/common/upload接口存在任意文件上传漏洞
    if (oConvertUtils.isNotEmpty(bizPath) && (bizPath.contains("../") || bizPath.contains("..\\"))) {
        throw new JeecgBootException("上传目录bizPath,格式非法!");
    }
    if (oConvertUtils.isEmpty(bizPath)) {
        bizPath = "";
    }
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    // 获取上传文件对象
    MultipartFile file = multipartRequest.getFile("file");
    // 获取文件名
    String orgName = file.getOriginalFilename();
    orgName = CommonUtils.getFileName(orgName);
    String file_url = MinioUtil.upload(file, bizPath);
    if (oConvertUtils.isEmpty(file_url)) {
        return Result.error("上传失败,请检查配置信息是否正确!");
    }
    // 保存文件信息
    OSSFile minioFile = new OSSFile();
    minioFile.setFileName(orgName);
    minioFile.setUrl(file_url);
    ossFileService.save(minioFile);
    result.setMessage(file_url);
    result.setSuccess(true);
    return result;
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) OSSFile(org.jeecg.modules.oss.entity.OSSFile) JeecgBootException(org.jeecg.common.exception.JeecgBootException) Result(org.jeecg.common.api.vo.Result) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 2 with JeecgBootException

use of org.jeecg.common.exception.JeecgBootException in project jeecg-boot by jeecgboot.

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

use of org.jeecg.common.exception.JeecgBootException in project jeecg-boot by jeecgboot.

the class SysBaseApiImpl method parseTemplateByCode.

@Override
public String parseTemplateByCode(TemplateDTO templateDTO) {
    String templateCode = templateDTO.getTemplateCode();
    Map<String, String> map = templateDTO.getTemplateParam();
    List<SysMessageTemplate> sysSmsTemplates = sysMessageTemplateService.selectByCode(templateCode);
    if (sysSmsTemplates == null || sysSmsTemplates.size() == 0) {
        throw new JeecgBootException("消息模板不存在,模板编码:" + templateCode);
    }
    SysMessageTemplate sysSmsTemplate = sysSmsTemplates.get(0);
    // 模板内容
    String content = sysSmsTemplate.getTemplateContent();
    if (map != null) {
        for (Map.Entry<String, String> entry : map.entrySet()) {
            String str = "${" + entry.getKey() + "}";
            content = content.replace(str, entry.getValue());
        }
    }
    return content;
}
Also used : SysMessageTemplate(org.jeecg.modules.message.entity.SysMessageTemplate) JeecgBootException(org.jeecg.common.exception.JeecgBootException)

Example 4 with JeecgBootException

use of org.jeecg.common.exception.JeecgBootException in project jeecg-boot by jeecgboot.

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)

Example 5 with JeecgBootException

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

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