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)));
}
}
}
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);
}
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;
}
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;
}
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);
}
Aggregations