Search in sources :

Example 16 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project jeecg-boot by jeecgboot.

the class SysCategoryController method loadAllData.

/**
 * [列表页面]加载分类字典数据 用于值的替换
 * @param code
 * @return
 */
@RequestMapping(value = "/loadAllData", method = RequestMethod.GET)
public Result<List<DictModel>> loadAllData(@RequestParam(name = "code", required = true) String code) {
    Result<List<DictModel>> result = new Result<List<DictModel>>();
    LambdaQueryWrapper<SysCategory> query = new LambdaQueryWrapper<SysCategory>();
    if (oConvertUtils.isNotEmpty(code) && !"0".equals(code)) {
        query.likeRight(SysCategory::getCode, code);
    }
    List<SysCategory> list = this.sysCategoryService.list(query);
    if (list == null || list.size() == 0) {
        result.setMessage("无数据,参数有误.[code]");
        result.setSuccess(false);
        return result;
    }
    List<DictModel> rdList = new ArrayList<DictModel>();
    for (SysCategory c : list) {
        rdList.add(new DictModel(c.getId(), c.getName()));
    }
    result.setSuccess(true);
    result.setResult(rdList);
    return result;
}
Also used : DictModel(org.jeecg.common.system.vo.DictModel) SysCategory(org.jeecg.modules.system.entity.SysCategory) Result(org.jeecg.common.api.vo.Result) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 17 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project jeecg-boot by jeecgboot.

the class SysPermissionController method getPermCode.

/**
 * 【vue3专用】获取
 * 1、查询用户拥有的按钮/表单访问权限
 * 2、所有权限 (菜单权限配置)
 * 3、系统安全模式 (开启则online报表的数据源必填)
 */
@RequestMapping(value = "/getPermCode", method = RequestMethod.GET)
public Result<?> getPermCode() {
    try {
        // 直接获取当前用户
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (oConvertUtils.isEmpty(loginUser)) {
            return Result.error("请登录系统!");
        }
        // 获取当前用户的权限集合
        List<SysPermission> metaList = sysPermissionService.queryByUser(loginUser.getUsername());
        // 按钮权限(用户拥有的权限集合)
        List<String> codeList = metaList.stream().filter((permission) -> CommonConstant.MENU_TYPE_2.equals(permission.getMenuType()) && CommonConstant.STATUS_1.equals(permission.getStatus())).collect(ArrayList::new, (list, permission) -> list.add(permission.getPerms()), ArrayList::addAll);
        // 
        JSONArray authArray = new JSONArray();
        this.getAuthJsonArray(authArray, metaList);
        // 查询所有的权限
        LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<>();
        query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
        query.eq(SysPermission::getMenuType, CommonConstant.MENU_TYPE_2);
        List<SysPermission> allAuthList = sysPermissionService.list(query);
        JSONArray allAuthArray = new JSONArray();
        this.getAllAuthJsonArray(allAuthArray, allAuthList);
        JSONObject result = new JSONObject();
        // 所拥有的权限编码
        result.put("codeList", codeList);
        // 按钮权限(用户拥有的权限集合)
        result.put("auth", authArray);
        // 全部权限配置集合(按钮权限,访问权限)
        result.put("allAuth", allAuthArray);
        // 系统安全模式
        result.put("sysSafeMode", jeeccgBaseConfig.getSafeMode());
        return Result.OK(result);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        return Result.error("查询失败:" + e.getMessage());
    }
}
Also used : PermissionDataUtil(org.jeecg.modules.system.util.PermissionDataUtil) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) java.util(java.util) Result(org.jeecg.common.api.vo.Result) JeeccgBaseConfig(org.jeecg.config.JeeccgBaseConfig) org.jeecg.modules.system.entity(org.jeecg.modules.system.entity) Autowired(org.springframework.beans.factory.annotation.Autowired) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) RoleIndexConfigEnum(org.jeecg.common.constant.enums.RoleIndexConfigEnum) JSONArray(com.alibaba.fastjson.JSONArray) Slf4j(lombok.extern.slf4j.Slf4j) TreeModel(org.jeecg.modules.system.model.TreeModel) LoginUser(org.jeecg.common.system.vo.LoginUser) RequiresRoles(org.apache.shiro.authz.annotation.RequiresRoles) MD5Util(org.jeecg.common.util.MD5Util) org.jeecg.common.util.oConvertUtils(org.jeecg.common.util.oConvertUtils) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) JSONObject(com.alibaba.fastjson.JSONObject) SysPermissionTree(org.jeecg.modules.system.model.SysPermissionTree) CommonConstant(org.jeecg.common.constant.CommonConstant) SecurityUtils(org.apache.shiro.SecurityUtils) org.jeecg.modules.system.service(org.jeecg.modules.system.service) JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) LoginUser(org.jeecg.common.system.vo.LoginUser) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 18 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project jeecg-boot by jeecgboot.

the class SysPermissionController method getSystemSubmenuBatch.

/*update_end author:wuxianquan date:20190908 for:先查询一级菜单,当用户点击展开菜单时加载子菜单 */
// update_begin author:sunjianlei date:20200108 for: 新增批量根据父ID查询子级菜单的接口 -------------
/**
 * 查询子菜单
 *
 * @param parentIds 父ID(多个采用半角逗号分割)
 * @return 返回 key-value 的 Map
 */
@GetMapping("/getSystemSubmenuBatch")
public Result getSystemSubmenuBatch(@RequestParam("parentIds") String parentIds) {
    try {
        LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<>();
        List<String> parentIdList = Arrays.asList(parentIds.split(","));
        query.in(SysPermission::getParentId, parentIdList);
        query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
        query.orderByAsc(SysPermission::getSortNo);
        List<SysPermission> list = sysPermissionService.list(query);
        Map<String, List<SysPermissionTree>> listMap = new HashMap<>();
        for (SysPermission item : list) {
            String pid = item.getParentId();
            if (parentIdList.contains(pid)) {
                List<SysPermissionTree> mapList = listMap.get(pid);
                if (mapList == null) {
                    mapList = new ArrayList<>();
                }
                mapList.add(new SysPermissionTree(item));
                listMap.put(pid, mapList);
            }
        }
        return Result.ok(listMap);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        return Result.error("批量查询子菜单失败:" + e.getMessage());
    }
}
Also used : LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) SysPermissionTree(org.jeecg.modules.system.model.SysPermissionTree)

Example 19 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project jeecg-boot by jeecgboot.

the class OrgCodeRule method execute.

@Override
public Object execute(JSONObject params, JSONObject formData) {
    ISysDepartService sysDepartService = (ISysDepartService) SpringContextUtils.getBean("sysDepartServiceImpl");
    LambdaQueryWrapper<SysDepart> query = new LambdaQueryWrapper<SysDepart>();
    LambdaQueryWrapper<SysDepart> query1 = new LambdaQueryWrapper<SysDepart>();
    // 创建一个List集合,存储查询返回的所有SysDepart对象
    List<SysDepart> departList = new ArrayList<>();
    String[] strArray = new String[2];
    // 定义部门类型
    String orgType = "";
    // 定义新编码字符串
    String newOrgCode = "";
    // 定义旧编码字符串
    String oldOrgCode = "";
    String parentId = null;
    if (formData != null && formData.size() > 0) {
        Object obj = formData.get("parentId");
        if (obj != null)
            parentId = obj.toString();
    } else {
        if (params != null) {
            Object obj = params.get("parentId");
            if (obj != null)
                parentId = obj.toString();
        }
    }
    // 如果是最高级,则查询出同级的org_code, 调用工具类生成编码并返回
    if (StringUtil.isNullOrEmpty(parentId)) {
        // 线判断数据库中的表是否为空,空则直接返回初始编码
        query1.eq(SysDepart::getParentId, "").or().isNull(SysDepart::getParentId);
        query1.orderByDesc(SysDepart::getOrgCode);
        departList = sysDepartService.list(query1);
        if (departList == null || departList.size() == 0) {
            strArray[0] = YouBianCodeUtil.getNextYouBianCode(null);
            strArray[1] = "1";
            return strArray;
        } else {
            SysDepart depart = departList.get(0);
            oldOrgCode = depart.getOrgCode();
            orgType = depart.getOrgType();
            newOrgCode = YouBianCodeUtil.getNextYouBianCode(oldOrgCode);
        }
    } else {
        // 反之则查询出所有同级的部门,获取结果后有两种情况,有同级和没有同级
        // 封装查询同级的条件
        query.eq(SysDepart::getParentId, parentId);
        // 降序排序
        query.orderByDesc(SysDepart::getOrgCode);
        // 查询出同级部门的集合
        List<SysDepart> parentList = sysDepartService.list(query);
        // 查询出父级部门
        SysDepart depart = sysDepartService.getById(parentId);
        // 获取父级部门的Code
        String parentCode = depart.getOrgCode();
        // 根据父级部门类型算出当前部门的类型
        orgType = String.valueOf(Integer.valueOf(depart.getOrgType()) + 1);
        // 处理同级部门为null的情况
        if (parentList == null || parentList.size() == 0) {
            // 直接生成当前的部门编码并返回
            newOrgCode = YouBianCodeUtil.getSubYouBianCode(parentCode, null);
        } else {
            // 处理有同级部门的情况
            // 获取同级部门的编码,利用工具类
            String subCode = parentList.get(0).getOrgCode();
            // 返回生成的当前部门编码
            newOrgCode = YouBianCodeUtil.getSubYouBianCode(parentCode, subCode);
        }
    }
    // 返回最终封装了部门编码和部门类型的数组
    strArray[0] = newOrgCode;
    strArray[1] = orgType;
    return strArray;
}
Also used : ArrayList(java.util.ArrayList) SysDepart(org.jeecg.modules.system.entity.SysDepart) JSONObject(com.alibaba.fastjson.JSONObject) ISysDepartService(org.jeecg.modules.system.service.ISysDepartService) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 20 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project jeecg-boot by jeecgboot.

the class SysAnnouncementServiceImpl method upDateAnnouncement.

/**
 * @功能:编辑消息信息
 */
@Transactional
@Override
public boolean upDateAnnouncement(SysAnnouncement sysAnnouncement) {
    // 1.更新系统信息表数据
    sysAnnouncementMapper.updateById(sysAnnouncement);
    String userId = sysAnnouncement.getUserIds();
    if (oConvertUtils.isNotEmpty(userId) && sysAnnouncement.getMsgType().equals(CommonConstant.MSG_TYPE_UESR)) {
        // 2.补充新的通知用户数据
        String[] userIds = userId.substring(0, (userId.length() - 1)).split(",");
        String anntId = sysAnnouncement.getId();
        Date refDate = new Date();
        for (int i = 0; i < userIds.length; i++) {
            LambdaQueryWrapper<SysAnnouncementSend> queryWrapper = new LambdaQueryWrapper<SysAnnouncementSend>();
            queryWrapper.eq(SysAnnouncementSend::getAnntId, anntId);
            queryWrapper.eq(SysAnnouncementSend::getUserId, userIds[i]);
            List<SysAnnouncementSend> announcementSends = sysAnnouncementSendMapper.selectList(queryWrapper);
            if (announcementSends.size() <= 0) {
                SysAnnouncementSend announcementSend = new SysAnnouncementSend();
                announcementSend.setAnntId(anntId);
                announcementSend.setUserId(userIds[i]);
                announcementSend.setReadFlag(CommonConstant.NO_READ_FLAG);
                announcementSend.setReadTime(refDate);
                sysAnnouncementSendMapper.insert(announcementSend);
            }
        }
        // 3. 删除多余通知用户数据
        Collection<String> delUserIds = Arrays.asList(userIds);
        LambdaQueryWrapper<SysAnnouncementSend> queryWrapper = new LambdaQueryWrapper<SysAnnouncementSend>();
        queryWrapper.notIn(SysAnnouncementSend::getUserId, delUserIds);
        queryWrapper.eq(SysAnnouncementSend::getAnntId, anntId);
        sysAnnouncementSendMapper.delete(queryWrapper);
    }
    return true;
}
Also used : SysAnnouncementSend(org.jeecg.modules.system.entity.SysAnnouncementSend) Date(java.util.Date) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)381 Transactional (org.springframework.transaction.annotation.Transactional)60 JSONObject (com.alibaba.fastjson.JSONObject)52 Result (org.jeecg.common.api.vo.Result)50 ArrayList (java.util.ArrayList)42 List (java.util.List)30 Map (java.util.Map)29 Collectors (java.util.stream.Collectors)26 Service (org.springframework.stereotype.Service)24 LoginUser (org.jeecg.common.system.vo.LoginUser)22 SysPermission (org.jeecg.modules.system.entity.SysPermission)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)22 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)21 IPage (com.baomidou.mybatisplus.core.metadata.IPage)20 HashMap (java.util.HashMap)20 SysUser (org.jeecg.modules.system.entity.SysUser)20 ApiOperation (io.swagger.annotations.ApiOperation)19 ServiceException (cn.lili.common.exception.ServiceException)18 ServiceImpl (com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)18 Autowired (org.springframework.beans.factory.annotation.Autowired)18