Search in sources :

Example 41 with LambdaQueryWrapper

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);
    }
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Student(com.maxqiu.demo.entity.Student) Map(java.util.Map) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 42 with LambdaQueryWrapper

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;
        }
    }
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Holiday(com.yh.weatherpush.entity.Holiday) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 43 with LambdaQueryWrapper

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");
}
Also used : UserFile(com.qiwenshare.file.domain.UserFile) FileBean(com.qiwenshare.file.domain.FileBean) AsyncResult(org.springframework.scheduling.annotation.AsyncResult) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 44 with LambdaQueryWrapper

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);
}
Also used : ShareTypeVO(com.qiwenshare.file.vo.share.ShareTypeVO) Share(com.qiwenshare.file.domain.Share) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Operation(io.swagger.v3.oas.annotations.Operation)

Example 45 with LambdaQueryWrapper

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("用户暂未登录");
    }
}
Also used : UserLoginVo(com.qiwenshare.file.vo.user.UserLoginVo) UserBean(com.qiwenshare.file.domain.user.UserBean) JwtUser(com.qiwenshare.common.util.security.JwtUser) UserLoginInfo(com.qiwenshare.file.domain.UserLoginInfo) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Operation(io.swagger.v3.oas.annotations.Operation)

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