Search in sources :

Example 6 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project diboot by dibo-software.

the class TestEntityListBinder method testSimpleBinder.

/**
 * 验证直接关联的绑定
 */
@Test
public void testSimpleBinder() {
    // 加载测试数据
    LambdaQueryWrapper<Department> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.in(Department::getId, 10001L, 10003L);
    List<Department> entityList = departmentService.list(queryWrapper);
    // 自动绑定
    List<EntityListSimpleVO> voList = Binder.convertAndBindRelations(entityList, EntityListSimpleVO.class);
    // 验证绑定结果
    Assert.assertTrue(V.notEmpty(voList));
    for (EntityListSimpleVO vo : voList) {
        // 验证直接关联的绑定
        Assert.assertTrue(V.notEmpty(vo.getChildren()));
        System.out.println(JSON.stringify(vo));
        Assert.assertTrue(V.notEmpty(vo.getChildrenNames()));
        for (int i = 0; i < vo.getChildren().size(); i++) {
            Department dept = vo.getChildren().get(i);
            Assert.assertTrue(dept.getName().equals(vo.getChildrenNames().get(i)));
        }
    }
}
Also used : Department(diboot.core.test.binder.entity.Department) EntityListSimpleVO(diboot.core.test.binder.vo.EntityListSimpleVO) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project diboot by dibo-software.

the class BaseServiceTest method testGet.

@Test
public void testGet() {
    // 查询总数
    long count = dictionaryService.getEntityListCount(null);
    Assert.assertTrue(count > 0);
    // 查询list
    List<Dictionary> dictionaryList = dictionaryService.getEntityList(null);
    Assert.assertTrue(V.notEmpty(dictionaryList));
    Assert.assertTrue(dictionaryList.size() == count);
    // 第一页数据
    List<Dictionary> pageList = dictionaryService.getEntityList(null, new Pagination());
    Assert.assertTrue(pageList.size() > 0 && pageList.size() <= BaseConfig.getPageSize());
    // 查询单个记录
    Long id = dictionaryList.get(0).getId();
    Dictionary first = dictionaryService.getEntity(id);
    Assert.assertTrue(first != null);
    // 只查询第一条记录对应type类型的
    LambdaQueryWrapper<Dictionary> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.eq(Dictionary::getType, first.getType());
    dictionaryList = dictionaryService.getEntityList(queryWrapper);
    Assert.assertTrue(V.notEmpty(dictionaryList));
    // 结果type值一致
    dictionaryList.stream().forEach(m -> {
        Assert.assertTrue(m.getType().equals(first.getType()));
    });
    // 根据id集合去批量查询
    List<Long> ids = BeanUtils.collectIdToList(dictionaryList);
    dictionaryList = dictionaryService.getEntityListByIds(ids);
    Assert.assertTrue(V.notEmpty(dictionaryList));
    // 获取map
    List<Map<String, Object>> mapList = dictionaryService.getMapList(null, new Pagination());
    Assert.assertTrue(mapList.size() > 0 && mapList.size() <= BaseConfig.getPageSize());
    List<Long> userIds = Arrays.asList(1001L, 1002L);
    Map<Long, String> id2NameMap = userService.getId2NameMap(userIds, User::getUsername);
    Assert.assertTrue(id2NameMap != null);
    Assert.assertTrue(id2NameMap.get(1001) != null);
}
Also used : Dictionary(com.diboot.core.entity.Dictionary) User(diboot.core.test.binder.entity.User) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with LambdaQueryWrapper

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

the class SysPermissionController method getSystemSubmenu.

/**
 * 查询子菜单
 * @param parentId
 * @return
 */
@RequestMapping(value = "/getSystemSubmenu", method = RequestMethod.GET)
public Result<List<SysPermissionTree>> getSystemSubmenu(@RequestParam("parentId") String parentId) {
    Result<List<SysPermissionTree>> result = new Result<>();
    try {
        LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
        query.eq(SysPermission::getParentId, parentId);
        query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
        query.orderByAsc(SysPermission::getSortNo);
        List<SysPermission> list = sysPermissionService.list(query);
        List<SysPermissionTree> sysPermissionTreeList = new ArrayList<SysPermissionTree>();
        for (SysPermission sysPermission : list) {
            SysPermissionTree sysPermissionTree = new SysPermissionTree(sysPermission);
            sysPermissionTreeList.add(sysPermissionTree);
        }
        result.setResult(sysPermissionTreeList);
        result.setSuccess(true);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return result;
}
Also used : SysPermissionTree(org.jeecg.modules.system.model.SysPermissionTree) Result(org.jeecg.common.api.vo.Result) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 9 with LambdaQueryWrapper

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

the class SysUserAgentController method queryByUserName.

/**
 * 通过userName查询
 * @param userName
 * @return
 */
@GetMapping(value = "/queryByUserName")
public Result<SysUserAgent> queryByUserName(@RequestParam(name = "userName", required = true) String userName) {
    Result<SysUserAgent> result = new Result<SysUserAgent>();
    LambdaQueryWrapper<SysUserAgent> queryWrapper = new LambdaQueryWrapper<SysUserAgent>();
    queryWrapper.eq(SysUserAgent::getUserName, userName);
    SysUserAgent sysUserAgent = sysUserAgentService.getOne(queryWrapper);
    if (sysUserAgent == null) {
        result.error500("未找到对应实体");
    } else {
        result.setResult(sysUserAgent);
        result.setSuccess(true);
    }
    return result;
}
Also used : SysUserAgent(org.jeecg.modules.system.entity.SysUserAgent) Result(org.jeecg.common.api.vo.Result) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 10 with LambdaQueryWrapper

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

the class SysUserController method updatePassword.

/**
 * 首页用户重置密码
 */
// @RequiresRoles({"admin"})
@RequestMapping(value = "/updatePassword", method = RequestMethod.PUT)
public Result<?> updatePassword(@RequestBody JSONObject json) {
    String username = json.getString("username");
    String oldpassword = json.getString("oldpassword");
    String password = json.getString("password");
    String confirmpassword = json.getString("confirmpassword");
    LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
    if (!sysUser.getUsername().equals(username)) {
        return Result.error("只允许修改自己的密码!");
    }
    SysUser user = this.sysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, username));
    if (user == null) {
        return Result.error("用户不存在!");
    }
    return sysUserService.resetPassword(username, oldpassword, password, confirmpassword);
}
Also used : LoginUser(org.jeecg.common.system.vo.LoginUser) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

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