Search in sources :

Example 96 with QueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project codingmore-learning by itwanger.

the class UsersServiceImpl method register.

@Override
public boolean register(Users users) {
    QueryWrapper<Users> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("user_login", users.getUserLogin());
    int count = this.baseMapper.selectCount(queryWrapper);
    if (count > 0) {
        return false;
    }
    users.setUserRegistered(new Date());
    users.setUserType(UserType.BACKEND.getUserType());
    users.setUserStatus(UserStatus.ENABLE.getStatus());
    String encodePassword = passwordEncoder.encode(users.getUserPass());
    users.setUserPass(encodePassword);
    return save(users);
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Users(com.codingmore.model.Users) Date(java.util.Date)

Example 97 with QueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project codingmore-learning by itwanger.

the class PostsServiceImpl method getPostsById.

@Override
public PostsVo getPostsById(Long id) {
    Posts posts = this.getById(id);
    PostsVo postsVo = new PostsVo();
    BeanUtils.copyProperties(posts, postsVo);
    QueryWrapper<TermRelationships> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("object_id", posts.getId());
    List<TermRelationships> termRelationshipsList = iTermRelationshipsService.list(queryWrapper);
    if (termRelationshipsList.size() > 0) {
        postsVo.setTermTaxonomyId(termRelationshipsList.get(0).getTermTaxonomyId());
    }
    return postsVo;
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) PostsVo(com.codingmore.vo.PostsVo)

Example 98 with QueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project springbootquickstart by Pace2Car.

the class ShiroRealm method doGetAuthenticationInfo.

/**
 * 认证
 *
 * @param token
 * @return
 * @throws AuthenticationException
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    logger.info("用户登录,登录信息-->{}", token);
    // 获取用户的输入的账号.
    String username = (String) token.getPrincipal();
    // 通过username从数据库中查找 User对象,如果找到,没找到.
    // 实际项目中,这里可以根据实际情况做缓存,如果不做,Shiro自己也是有时间间隔机制,2分钟内不会重复执行该方法
    UUser user = uUserService.getOne(new QueryWrapper<UUser>().eq("username", username));
    logger.info("用户登录,登录信息-->{}", user);
    if (user == null) {
        // 没有返回登录用户名对应的SimpleAuthenticationInfo对象时,就会在LoginController中抛出UnknownAccountException异常
        return null;
    } else {
        user.setLastLoginTime(new Timestamp(System.currentTimeMillis()));
        uUserService.updateById(user);
    }
    SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(username, user.getPassword(), getName());
    return authenticationInfo;
}
Also used : SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) UUser(com.pace2car.springbootdemo.shiro.entity.UUser) Timestamp(java.sql.Timestamp)

Example 99 with QueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project aurora-mall by besscroft.

the class ResourceServiceImpl method getAllResourceTree.

@Override
public List<ResourceParam> getAllResourceTree() {
    List<ResourceParam> list = new ArrayList<>();
    List<AuthResourceSort> resourceSorts = authResourceSortMapper.selectList(new QueryWrapper<>());
    resourceSorts.forEach(r -> {
        ResourceParam resourceParam = new ResourceParam();
        QueryWrapper<AuthResource> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("category_id", r.getId());
        List<AuthResource> resources = this.baseMapper.selectList(queryWrapper);
        resourceParam.setName(r.getCategoryName());
        resourceParam.setDisabled(true);
        resourceParam.setChildren(resources);
        list.add(resourceParam);
    });
    return list;
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) AuthResourceSort(com.besscroft.aurora.mall.common.entity.AuthResourceSort) ResourceParam(com.besscroft.aurora.mall.admin.domain.param.ResourceParam) AuthResource(com.besscroft.aurora.mall.common.entity.AuthResource)

Example 100 with QueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project su-sunday-cloud by illeagalName.

the class ResourcePreloadRunner method run.

@Override
public void run(ApplicationArguments args) {
    clearCache(CacheConstants.AUTHORIZATION_USER_ROLE + "*");
    log.info("加载角色菜单资源开始 {}", LocalDateTime.now());
    QueryWrapper<Role> roleWrapper = new QueryWrapper<>();
    roleWrapper.eq("status", 0).eq("is_delete", 0);
    List<Role> roles = roleMapper.selectList(roleWrapper);
    roles.parallelStream().forEach(item -> {
        List<Menu> menus = menuMapper.listMenusByRoleId(item.getRoleId());
        RoleVO role = new RoleVO();
        BeanUtils.copyProperties(item, role);
        role.setMenus(menus.stream().map(Menu::getSymbol).filter(Objects::nonNull).collect(Collectors.toList()));
        // 缓存起来
        redisService.setObject(CacheConstants.AUTHORIZATION_USER_ROLE + role.getRoleId(), role);
    });
    clearCache(CacheConstants.AUTHORIZATION_USER_MENU + "*");
    QueryWrapper<Menu> menuWrapper = new QueryWrapper<>();
    menuWrapper.orderByAsc("parent_id", "menu_sort");
    List<Menu> menus = menuMapper.selectList(menuWrapper);
    menus.forEach(item -> {
        MenuVO menu = new MenuVO();
        BeanUtils.copyProperties(item, menu);
        redisService.setObject(CacheConstants.AUTHORIZATION_USER_MENU + item.getMenuId(), menu);
    });
    clearCache(CacheConstants.AUTHORIZATION_USER_CLIENT + "*");
    log.info("加载client资源开始 {}", LocalDateTime.now());
    List<AuthClient> authClients = authClientMapper.listAuthClients();
    authClients.stream().map(client -> {
        ClientVO clientVO = new ClientVO();
        clientVO.setClientId(client.getClientId());
        clientVO.setTime(client.getAccessTokenValidity());
        clientVO.setRemark(client.getRemark());
        return clientVO;
    }).forEach(m -> {
        redisService.setObject(CacheConstants.AUTHORIZATION_USER_CLIENT + m.getClientId(), m);
    });
    log.info("加载资源结束 {}", LocalDateTime.now());
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) RoleVO(com.haier.api.user.domain.RoleVO) AuthClientMapper(com.haier.user.dao.AuthClientMapper) AuthClient(com.haier.user.domain.AuthClient) ApplicationArguments(org.springframework.boot.ApplicationArguments) ApplicationRunner(org.springframework.boot.ApplicationRunner) Menu(com.haier.user.domain.Menu) MenuVO(com.haier.api.user.domain.MenuVO) LocalDateTime(java.time.LocalDateTime) ClientVO(com.haier.api.user.domain.ClientVO) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) RedisService(com.haier.redis.service.RedisService) CacheConstants(com.haier.core.constant.CacheConstants) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) MenuMapper(com.haier.user.dao.MenuMapper) RoleMapper(com.haier.user.dao.RoleMapper) Role(com.haier.user.domain.Role) BeanUtils(org.springframework.beans.BeanUtils) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) AuthClient(com.haier.user.domain.AuthClient) Role(com.haier.user.domain.Role) MenuVO(com.haier.api.user.domain.MenuVO) RoleVO(com.haier.api.user.domain.RoleVO) Objects(java.util.Objects) Menu(com.haier.user.domain.Menu) ClientVO(com.haier.api.user.domain.ClientVO)

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