Search in sources :

Example 6 with QueryWrapper

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

the class FillRuleUtil method executeRule.

/**
 * @param ruleCode ruleCode
 * @return
 */
@SuppressWarnings("unchecked")
public static Object executeRule(String ruleCode, JSONObject formData) {
    if (!StringUtils.isEmpty(ruleCode)) {
        try {
            // 获取 Service
            ServiceImpl impl = (ServiceImpl) SpringContextUtils.getBean("sysFillRuleServiceImpl");
            // 根据 ruleCode 查询出实体
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.eq("rule_code", ruleCode);
            JSONObject entity = JSON.parseObject(JSON.toJSONString(impl.getOne(queryWrapper)));
            if (entity == null) {
                log.warn("填值规则:" + ruleCode + " 不存在");
                return null;
            }
            // 获取必要的参数
            String ruleClass = entity.getString("ruleClass");
            JSONObject params = entity.getJSONObject("ruleParams");
            if (params == null) {
                params = new JSONObject();
            }
            if (formData == null) {
                formData = new JSONObject();
            }
            // 通过反射执行配置的类里的方法
            IFillRuleHandler ruleHandler = (IFillRuleHandler) Class.forName(ruleClass).newInstance();
            return ruleHandler.execute(params, formData);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : IFillRuleHandler(org.jeecg.common.handler.IFillRuleHandler) JSONObject(com.alibaba.fastjson.JSONObject) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) ServiceImpl(com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)

Example 7 with QueryWrapper

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

the class SysBaseApiImpl method queryAllUser.

@Override
public JSONObject queryAllUser(String userIds, Integer pageNo, Integer pageSize) {
    JSONObject json = new JSONObject();
    QueryWrapper<SysUser> queryWrapper = new QueryWrapper<SysUser>().eq("status", 1).eq("del_flag", 0);
    List<ComboModel> list = new ArrayList<ComboModel>();
    Page<SysUser> page = new Page<SysUser>(pageNo, pageSize);
    IPage<SysUser> pageList = userMapper.selectPage(page, queryWrapper);
    for (SysUser user : pageList.getRecords()) {
        ComboModel model = new ComboModel();
        model.setUsername(user.getUsername());
        model.setTitle(user.getRealname());
        model.setId(user.getId());
        model.setEmail(user.getEmail());
        if (oConvertUtils.isNotEmpty(userIds)) {
            String[] temp = userIds.split(",");
            for (int i = 0; i < temp.length; i++) {
                if (temp[i].equals(user.getId())) {
                    model.setChecked(true);
                }
            }
        }
        list.add(model);
    }
    json.put("list", list);
    json.put("total", pageList.getTotal());
    return json;
}
Also used : LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) JSONObject(com.alibaba.fastjson.JSONObject)

Example 8 with QueryWrapper

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

the class SysDepartPermissionServiceImpl method getPermRuleListByDeptIdAndPermId.

@Override
public List<SysPermissionDataRule> getPermRuleListByDeptIdAndPermId(String departId, String permissionId) {
    SysDepartPermission departPermission = this.getOne(new QueryWrapper<SysDepartPermission>().lambda().eq(SysDepartPermission::getDepartId, departId).eq(SysDepartPermission::getPermissionId, permissionId));
    if (departPermission != null && oConvertUtils.isNotEmpty(departPermission.getDataRuleIds())) {
        LambdaQueryWrapper<SysPermissionDataRule> query = new LambdaQueryWrapper<SysPermissionDataRule>();
        query.in(SysPermissionDataRule::getId, Arrays.asList(departPermission.getDataRuleIds().split(",")));
        query.orderByDesc(SysPermissionDataRule::getCreateTime);
        List<SysPermissionDataRule> permRuleList = this.ruleMapper.selectList(query);
        return permRuleList;
    } else {
        return null;
    }
}
Also used : SysDepartPermission(org.jeecg.modules.system.entity.SysDepartPermission) SysPermissionDataRule(org.jeecg.modules.system.entity.SysPermissionDataRule) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 9 with QueryWrapper

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

the class SysDepartPermissionServiceImpl method saveDepartPermission.

@Override
@Transactional(rollbackFor = Exception.class)
public void saveDepartPermission(String departId, String permissionIds, String lastPermissionIds) {
    List<String> add = getDiff(lastPermissionIds, permissionIds);
    if (add != null && add.size() > 0) {
        List<SysDepartPermission> list = new ArrayList<SysDepartPermission>();
        for (String p : add) {
            if (oConvertUtils.isNotEmpty(p)) {
                SysDepartPermission rolepms = new SysDepartPermission(departId, p);
                list.add(rolepms);
            }
        }
        this.saveBatch(list);
    }
    List<String> delete = getDiff(permissionIds, lastPermissionIds);
    if (delete != null && delete.size() > 0) {
        for (String permissionId : delete) {
            this.remove(new QueryWrapper<SysDepartPermission>().lambda().eq(SysDepartPermission::getDepartId, departId).eq(SysDepartPermission::getPermissionId, permissionId));
            // 删除部门权限时,删除部门角色中已授权的权限
            List<SysDepartRole> sysDepartRoleList = sysDepartRoleMapper.selectList(new LambdaQueryWrapper<SysDepartRole>().eq(SysDepartRole::getDepartId, departId));
            List<String> roleIds = sysDepartRoleList.stream().map(SysDepartRole::getId).collect(Collectors.toList());
            if (roleIds != null && roleIds.size() > 0) {
                departRolePermissionMapper.delete(new LambdaQueryWrapper<SysDepartRolePermission>().eq(SysDepartRolePermission::getPermissionId, permissionId));
            }
        }
    }
}
Also used : SysDepartPermission(org.jeecg.modules.system.entity.SysDepartPermission) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) SysDepartRole(org.jeecg.modules.system.entity.SysDepartRole) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with QueryWrapper

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

the class SysDepartRolePermissionServiceImpl method saveDeptRolePermission.

@Override
public void saveDeptRolePermission(String roleId, String permissionIds, String lastPermissionIds) {
    String ip = "";
    try {
        // 获取request
        HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
        // 获取IP地址
        ip = IPUtils.getIpAddr(request);
    } catch (Exception e) {
        ip = "127.0.0.1";
    }
    List<String> add = getDiff(lastPermissionIds, permissionIds);
    if (add != null && add.size() > 0) {
        List<SysDepartRolePermission> list = new ArrayList<SysDepartRolePermission>();
        for (String p : add) {
            if (oConvertUtils.isNotEmpty(p)) {
                SysDepartRolePermission rolepms = new SysDepartRolePermission(roleId, p);
                rolepms.setOperateDate(new Date());
                rolepms.setOperateIp(ip);
                list.add(rolepms);
            }
        }
        this.saveBatch(list);
    }
    List<String> delete = getDiff(permissionIds, lastPermissionIds);
    if (delete != null && delete.size() > 0) {
        for (String permissionId : delete) {
            this.remove(new QueryWrapper<SysDepartRolePermission>().lambda().eq(SysDepartRolePermission::getRoleId, roleId).eq(SysDepartRolePermission::getPermissionId, permissionId));
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SysDepartRolePermission(org.jeecg.modules.system.entity.SysDepartRolePermission) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)

Aggregations

QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)723 Transactional (org.springframework.transaction.annotation.Transactional)98 IPage (com.baomidou.mybatisplus.core.metadata.IPage)82 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)74 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)72 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)65 ArrayList (java.util.ArrayList)61 Session (org.apache.shiro.session.Session)61 StatusFailException (top.hcode.hoj.common.exception.StatusFailException)60 StatusForbiddenException (top.hcode.hoj.common.exception.StatusForbiddenException)55 Problem (top.hcode.hoj.pojo.entity.problem.Problem)50 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)45 Date (java.util.Date)44 HttpServletRequest (javax.servlet.http.HttpServletRequest)35 HashMap (java.util.HashMap)34 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)34 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)34 ApiOperation (io.swagger.annotations.ApiOperation)32 HttpSession (javax.servlet.http.HttpSession)31 Judge (top.hcode.hoj.pojo.entity.judge.Judge)30