use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project demo-SpringBoot by Max-Qiu.
the class TestGroupByAndHaving method testGroup.
/**
* 分组
*/
@Test
public void testGroup() {
// SELECT classes_id, count(*) FROM smp_student GROUP BY classes_id
QueryWrapper<Student> wrapper = new QueryWrapper<>();
wrapper.select("classes_id, count(*)").groupBy("classes_id");
List<Map<String, Object>> maplist = studentMapper.selectMaps(wrapper);
for (Map<String, Object> mp : maplist) {
System.out.println(mp);
}
// lambda语法可能不太方便获取count(*)这种
// lambdaQueryWrapper groupBy
LambdaQueryWrapper<Student> lambdaQueryWrapper = new QueryWrapper<Student>().lambda().select(Student::getClassesId).groupBy(Student::getClassesId);
for (Student user : studentMapper.selectList(lambdaQueryWrapper)) {
System.out.println(user);
}
}
use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project weather-push by yangh124.
the class RedisServiceImpl method redisHolidayByKey.
@Override
public Holiday redisHolidayByKey(LocalDate date) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String dateStr = date.format(formatter);
String key = "holiday:" + date.getYear() + ":map";
Boolean b = redisTemplate.hasKey(key);
Map<String, Holiday> map = new HashMap<>();
if (!BooleanUtil.isTrue(b)) {
int year = LocalDate.now().getYear();
LambdaQueryWrapper<Holiday> queryWrapper = new QueryWrapper<Holiday>().lambda().eq(Holiday::getYear, year);
List<Holiday> list = holidayService.list(queryWrapper);
if (CollUtil.isNotEmpty(list)) {
map = list.stream().collect(Collectors.toMap(a -> a.getHolidayDate().format(formatter), a -> a));
List<Object> argList = new ArrayList<>();
argList.add(map.size() << 1 + 2);
argList.add(86400L);
for (String s : map.keySet()) {
argList.add(s);
argList.add(map.get(s));
}
Object[] args = argList.toArray();
redisTemplate.execute(RedisScript.of(hmsetLua), Collections.singletonList(key), args);
}
return map.get(dateStr);
} else {
Object o = redisTemplate.opsForHash().get(key, dateStr);
if (null != o) {
return (Holiday) o;
} else {
return null;
}
}
}
use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project qiwen-file by qiwenshare.
the class AsyncTaskComp method deleteUserFile.
public Future<String> deleteUserFile(Long userFileId) {
long begin = System.currentTimeMillis();
UserFile userFile = userFileService.getById(userFileId);
if (userFile.getIsDir() == 1) {
LambdaQueryWrapper<UserFile> userFileLambdaQueryWrapper = new LambdaQueryWrapper<>();
userFileLambdaQueryWrapper.eq(UserFile::getDeleteBatchNum, userFile.getDeleteBatchNum());
List<UserFile> list = userFileService.list(userFileLambdaQueryWrapper);
recoveryFileService.deleteUserFileByDeleteBatchNum(userFile.getDeleteBatchNum());
for (UserFile userFileItem : list) {
Long filePointCount = getFilePointCount(userFileItem.getFileId());
if (filePointCount != null && filePointCount == 0 && userFileItem.getIsDir() == 0) {
FileBean fileBean = fileMapper.selectById(userFileItem.getFileId());
try {
filetransferService.deleteFile(fileBean);
fileMapper.deleteById(fileBean.getFileId());
} catch (Exception e) {
log.error("删除本地文件失败:" + JSON.toJSONString(fileBean));
}
}
}
} else {
recoveryFileService.deleteUserFileByDeleteBatchNum(userFile.getDeleteBatchNum());
Long filePointCount = getFilePointCount(userFile.getFileId());
if (filePointCount != null && filePointCount == 0 && userFile.getIsDir() == 0) {
FileBean fileBean = fileMapper.selectById(userFile.getFileId());
try {
filetransferService.deleteFile(fileBean);
fileMapper.deleteById(fileBean.getFileId());
} catch (Exception e) {
log.error("删除本地文件失败:" + JSON.toJSONString(fileBean));
}
}
}
long end = System.currentTimeMillis();
System.out.println("任务 deleteUserFile 耗时=" + (end - begin));
return new AsyncResult<String>("deleteUserFile");
}
use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project qiwen-file by qiwenshare.
the class ShareController method shareType.
@Operation(summary = "分享类型", description = "可用此接口判断是否需要提取码", tags = { "share" })
@GetMapping(value = "/sharetype")
@ResponseBody
public RestResult<ShareTypeVO> shareType(ShareTypeDTO shareTypeDTO) {
LambdaQueryWrapper<Share> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(Share::getShareBatchNum, shareTypeDTO.getShareBatchNum());
Share share = shareService.getOne(lambdaQueryWrapper);
ShareTypeVO shareTypeVO = new ShareTypeVO();
shareTypeVO.setShareType(share.getShareType());
return RestResult.success().data(shareTypeVO);
}
use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project qiwen-file by qiwenshare.
the class UserController method checkUserLoginInfo.
@Operation(summary = "检查用户登录信息", description = "验证token的有效性", tags = { "user" })
@GetMapping("/checkuserlogininfo")
@ResponseBody
public RestResult<UserLoginVo> checkUserLoginInfo() {
UserLoginVo userLoginVo = new UserLoginVo();
JwtUser sessionUserBean = SessionUtil.getSession();
if (sessionUserBean != null && !"anonymousUser".equals(sessionUserBean.getUsername())) {
LambdaQueryWrapper<UserLoginInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(UserLoginInfo::getUserId, sessionUserBean.getUserId());
lambdaQueryWrapper.likeRight(UserLoginInfo::getUserloginDate, DateUtil.getCurrentTime().substring(0, 10));
userLoginInfoService.remove(lambdaQueryWrapper);
UserLoginInfo userLoginInfo = new UserLoginInfo();
userLoginInfo.setUserId(sessionUserBean.getUserId());
userLoginInfo.setUserloginDate(DateUtil.getCurrentTime());
userLoginInfoService.save(userLoginInfo);
UserBean user = userService.getById(sessionUserBean.getUserId());
BeanUtil.copyProperties(user, userLoginVo);
return RestResult.success().data(userLoginVo);
} else {
return RestResult.fail().message("用户暂未登录");
}
}
Aggregations