Search in sources :

Example 21 with JeecgBootException

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

the class SignUtil method getParamsSign.

/**
 * @param params
 *            所有的请求参数都会在这里进行排序加密
 * @return 得到签名
 */
public static String getParamsSign(SortedMap<String, String> params) {
    // 去掉 Url 里的时间戳
    params.remove("_t");
    String paramsJsonStr = JSONObject.toJSONString(params);
    log.info("Param paramsJsonStr : {}", paramsJsonStr);
    // 设置签名秘钥
    JeeccgBaseConfig jeeccgBaseConfig = SpringContextUtils.getBean(JeeccgBaseConfig.class);
    String signatureSecret = jeeccgBaseConfig.getSignatureSecret();
    if (oConvertUtils.isEmpty(signatureSecret) || signatureSecret.contains("${")) {
        throw new JeecgBootException("签名密钥 ${jeecg.signatureSecret} 缺少配置 !!");
    }
    return DigestUtils.md5DigestAsHex((paramsJsonStr + signatureSecret).getBytes()).toUpperCase();
}
Also used : JeeccgBaseConfig(org.jeecg.config.JeeccgBaseConfig) JeecgBootException(org.jeecg.common.exception.JeecgBootException)

Example 22 with JeecgBootException

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

the class SysPermissionServiceImpl method deletePermissionLogical.

/**
 * 逻辑删除
 */
@Override
@CacheEvict(value = CacheConstant.SYS_DATA_PERMISSIONS_CACHE, allEntries = true)
public // @CacheEvict(value = CacheConstant.SYS_DATA_PERMISSIONS_CACHE,allEntries=true,condition="#sysPermission.menuType==2")
void deletePermissionLogical(String id) throws JeecgBootException {
    SysPermission sysPermission = this.getById(id);
    if (sysPermission == null) {
        throw new JeecgBootException("未找到菜单信息");
    }
    String pid = sysPermission.getParentId();
    int count = this.count(new QueryWrapper<SysPermission>().lambda().eq(SysPermission::getParentId, pid));
    if (count == 1) {
        // 若父节点无其他子节点,则该父节点是叶子节点
        this.sysPermissionMapper.setMenuLeaf(pid, 1);
    }
    sysPermission.setDelFlag(1);
    this.updateById(sysPermission);
}
Also used : SysPermission(org.jeecg.modules.system.entity.SysPermission) JeecgBootException(org.jeecg.common.exception.JeecgBootException) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 23 with JeecgBootException

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

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)

Example 24 with JeecgBootException

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

the class SysPermissionServiceImpl method deletePermission.

/**
 * 真实删除
 */
@Override
@Transactional
@CacheEvict(value = CacheConstant.SYS_DATA_PERMISSIONS_CACHE, allEntries = true)
public void deletePermission(String id) throws JeecgBootException {
    SysPermission sysPermission = this.getById(id);
    if (sysPermission == null) {
        throw new JeecgBootException("未找到菜单信息");
    }
    String pid = sysPermission.getParentId();
    if (oConvertUtils.isNotEmpty(pid)) {
        int count = this.count(new QueryWrapper<SysPermission>().lambda().eq(SysPermission::getParentId, pid));
        if (count == 1) {
            // 若父节点无其他子节点,则该父节点是叶子节点
            this.sysPermissionMapper.setMenuLeaf(pid, 1);
        }
    }
    sysPermissionMapper.deleteById(id);
    // 该节点可能是子节点但也可能是其它节点的父节点,所以需要级联删除
    this.removeChildrenBy(sysPermission.getId());
    // 关联删除
    Map map = new HashMap<>();
    map.put("permission_id", id);
    // 删除数据规则
    this.deletePermRuleByPermId(id);
    // 删除角色授权表
    sysRolePermissionMapper.deleteByMap(map);
    // 删除部门权限表
    sysDepartPermissionMapper.deleteByMap(map);
    // 删除部门角色授权
    sysDepartRolePermissionMapper.deleteByMap(map);
}
Also used : HashMap(java.util.HashMap) SysPermission(org.jeecg.modules.system.entity.SysPermission) JeecgBootException(org.jeecg.common.exception.JeecgBootException) HashMap(java.util.HashMap) Map(java.util.Map) CacheEvict(org.springframework.cache.annotation.CacheEvict) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with JeecgBootException

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

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)

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