Search in sources :

Example 46 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project qiwen-file by qiwenshare.

the class FiletransferService method uploadFileSpeed.

@Override
public UploadFileVo uploadFileSpeed(UploadFileDTO uploadFileDTO) {
    UploadFileVo uploadFileVo = new UploadFileVo();
    JwtUser sessionUserBean = SessionUtil.getSession();
    Map<String, Object> param = new HashMap<>();
    param.put("identifier", uploadFileDTO.getIdentifier());
    List<FileBean> list = fileMapper.selectByMap(param);
    if (list != null && !list.isEmpty()) {
        FileBean file = list.get(0);
        UserFile userFile = new UserFile();
        userFile.setUserId(sessionUserBean.getUserId());
        String relativePath = uploadFileDTO.getRelativePath();
        if (relativePath.contains("/")) {
            userFile.setFilePath(uploadFileDTO.getFilePath() + UFOPUtils.getParentPath(relativePath) + "/");
            fileDealComp.restoreParentFilePath(uploadFileDTO.getFilePath() + UFOPUtils.getParentPath(relativePath) + "/", sessionUserBean.getUserId());
            fileDealComp.deleteRepeatSubDirFile(uploadFileDTO.getFilePath(), sessionUserBean.getUserId());
        } else {
            userFile.setFilePath(uploadFileDTO.getFilePath());
        }
        String fileName = uploadFileDTO.getFilename();
        userFile.setFileName(UFOPUtils.getFileNameNotExtend(fileName));
        userFile.setExtendName(UFOPUtils.getFileExtendName(fileName));
        userFile.setDeleteFlag(0);
        List<UserFile> userFileList = userFileMapper.selectList(new QueryWrapper<>(userFile));
        if (userFileList.size() <= 0) {
            userFile.setIsDir(0);
            userFile.setUploadTime(DateUtil.getCurrentTime());
            userFile.setFileId(file.getFileId());
            userFileMapper.insert(userFile);
            fileDealComp.uploadESByUserFileId(userFile.getUserFileId());
        }
        uploadFileVo.setSkipUpload(true);
    } else {
        uploadFileVo.setSkipUpload(false);
        List<Integer> uploaded = uploadTaskDetailMapper.selectUploadedChunkNumList(uploadFileDTO.getIdentifier());
        if (uploaded != null && !uploaded.isEmpty()) {
            uploadFileVo.setUploaded(uploaded);
        } else {
            LambdaQueryWrapper<UploadTask> lambdaQueryWrapper = new LambdaQueryWrapper<>();
            lambdaQueryWrapper.eq(UploadTask::getIdentifier, uploadFileDTO.getIdentifier());
            List<UploadTask> rslist = uploadTaskMapper.selectList(lambdaQueryWrapper);
            if (rslist == null || rslist.isEmpty()) {
                UploadTask uploadTask = new UploadTask();
                uploadTask.setIdentifier(uploadFileDTO.getIdentifier());
                uploadTask.setUploadTime(DateUtil.getCurrentTime());
                uploadTask.setUploadStatus(UploadFileStatusEnum.UNCOMPLATE.getCode());
                uploadTask.setFileName(uploadFileDTO.getFilename());
                String relativePath = uploadFileDTO.getRelativePath();
                if (relativePath.contains("/")) {
                    uploadTask.setFilePath(uploadFileDTO.getFilePath() + UFOPUtils.getParentPath(relativePath) + "/");
                } else {
                    uploadTask.setFilePath(uploadFileDTO.getFilePath());
                }
                uploadTask.setExtendName(uploadTask.getExtendName());
                uploadTask.setUserId(sessionUserBean.getUserId());
                uploadTaskMapper.insert(uploadTask);
            }
        }
    }
    return uploadFileVo;
}
Also used : LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) UploadFileVo(com.qiwenshare.file.vo.file.UploadFileVo) JwtUser(com.qiwenshare.common.util.security.JwtUser)

Example 47 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project qiwen-file by qiwenshare.

the class FiletransferService method downloadFile.

@Override
public void downloadFile(HttpServletResponse httpServletResponse, DownloadFileDTO downloadFileDTO) {
    UserFile userFile = userFileMapper.selectById(downloadFileDTO.getUserFileId());
    if (userFile.getIsDir() == 0) {
        FileBean fileBean = fileMapper.selectById(userFile.getFileId());
        Downloader downloader = ufopFactory.getDownloader(fileBean.getStorageType());
        if (downloader == null) {
            log.error("下载失败,文件存储类型不支持下载,storageType:{}", fileBean.getStorageType());
            throw new DownloadException("下载失败");
        }
        DownloadFile downloadFile = new DownloadFile();
        downloadFile.setFileUrl(fileBean.getFileUrl());
        downloadFile.setFileSize(fileBean.getFileSize());
        httpServletResponse.setContentLengthLong(fileBean.getFileSize());
        downloader.download(httpServletResponse, downloadFile);
    } else {
        LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.likeRight(UserFile::getFilePath, userFile.getFilePath() + userFile.getFileName() + "/").eq(UserFile::getUserId, userFile.getUserId()).eq(UserFile::getIsDir, 0).eq(UserFile::getDeleteFlag, 0);
        List<UserFile> userFileList = userFileMapper.selectList(lambdaQueryWrapper);
        String staticPath = UFOPUtils.getStaticPath();
        String tempPath = staticPath + "temp" + File.separator;
        File tempDirFile = new File(tempPath);
        if (!tempDirFile.exists()) {
            tempDirFile.mkdirs();
        }
        FileOutputStream f = null;
        try {
            f = new FileOutputStream(tempPath + userFile.getFileName() + ".zip");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        CheckedOutputStream csum = new CheckedOutputStream(f, new Adler32());
        ZipOutputStream zos = new ZipOutputStream(csum);
        BufferedOutputStream out = new BufferedOutputStream(zos);
        try {
            for (UserFile userFile1 : userFileList) {
                FileBean fileBean = fileMapper.selectById(userFile1.getFileId());
                Downloader downloader = ufopFactory.getDownloader(fileBean.getStorageType());
                if (downloader == null) {
                    log.error("下载失败,文件存储类型不支持下载,storageType:{}", fileBean.getStorageType());
                    throw new UploadException("下载失败");
                }
                DownloadFile downloadFile = new DownloadFile();
                downloadFile.setFileUrl(fileBean.getFileUrl());
                downloadFile.setFileSize(fileBean.getFileSize());
                InputStream inputStream = downloader.getInputStream(downloadFile);
                BufferedInputStream bis = new BufferedInputStream(inputStream);
                try {
                    zos.putNextEntry(new ZipEntry(userFile1.getFilePath().replace(userFile.getFilePath(), "/") + userFile1.getFileName() + "." + userFile1.getExtendName()));
                    byte[] buffer = new byte[1024];
                    int i = bis.read(buffer);
                    while (i != -1) {
                        out.write(buffer, 0, i);
                        i = bis.read(buffer);
                    }
                } catch (IOException e) {
                    log.error("" + e);
                    e.printStackTrace();
                } finally {
                    try {
                        bis.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    try {
                        out.flush();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        } catch (Exception e) {
            log.error("压缩过程中出现异常:" + e);
        } finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        String zipPath = "";
        try {
            Downloader downloader = ufopFactory.getDownloader(StorageTypeEnum.LOCAL.getCode());
            DownloadFile downloadFile = new DownloadFile();
            downloadFile.setFileUrl("temp" + File.separator + userFile.getFileName() + ".zip");
            File tempFile = new File(UFOPUtils.getStaticPath() + downloadFile.getFileUrl());
            httpServletResponse.setContentLengthLong(tempFile.length());
            downloader.download(httpServletResponse, downloadFile);
            zipPath = UFOPUtils.getStaticPath() + "temp" + File.separator + userFile.getFileName() + ".zip";
        } catch (Exception e) {
            // org.apache.catalina.connector.ClientAbortException: java.io.IOException: Connection reset by peer
            if (e.getMessage().contains("ClientAbortException")) {
            // 该异常忽略不做处理
            } else {
                log.error("下传zip文件出现异常:{}", e.getMessage());
            }
        } finally {
            File file = new File(zipPath);
            if (file.exists()) {
                file.delete();
            }
        }
    }
}
Also used : DownloadFile(com.qiwenshare.ufop.operation.download.domain.DownloadFile) ImageInputStream(javax.imageio.stream.ImageInputStream) UploadException(com.qiwenshare.ufop.exception.operation.UploadException) ZipEntry(java.util.zip.ZipEntry) Downloader(com.qiwenshare.ufop.operation.download.Downloader) Adler32(java.util.zip.Adler32) UploadException(com.qiwenshare.ufop.exception.operation.UploadException) DownloadException(com.qiwenshare.ufop.exception.operation.DownloadException) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) ZipOutputStream(java.util.zip.ZipOutputStream) DownloadException(com.qiwenshare.ufop.exception.operation.DownloadException) CheckedOutputStream(java.util.zip.CheckedOutputStream) DeleteFile(com.qiwenshare.ufop.operation.delete.domain.DeleteFile) UploadFile(com.qiwenshare.ufop.operation.upload.domain.UploadFile) DownloadFile(com.qiwenshare.ufop.operation.download.domain.DownloadFile) PreviewFile(com.qiwenshare.ufop.operation.preview.domain.PreviewFile)

Example 48 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project qiwen-file by qiwenshare.

the class StorageService method checkStorage.

public boolean checkStorage(Long userId, Long fileSize) {
    LambdaQueryWrapper<StorageBean> lambdaQueryWrapper = new LambdaQueryWrapper<>();
    lambdaQueryWrapper.eq(StorageBean::getUserId, userId);
    StorageBean storageBean = storageMapper.selectOne(lambdaQueryWrapper);
    Long totalStorageSize = null;
    if (storageBean == null || storageBean.getTotalStorageSize() == null) {
        LambdaQueryWrapper<SysParam> lambdaQueryWrapper1 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper1.eq(SysParam::getSysParamKey, "totalStorageSize");
        SysParam sysParam = sysParamMapper.selectOne(lambdaQueryWrapper1);
        totalStorageSize = Long.parseLong(sysParam.getSysParamValue());
        storageBean = new StorageBean();
        storageBean.setUserId(userId);
        storageBean.setTotalStorageSize(totalStorageSize);
        storageMapper.insert(storageBean);
    } else {
        totalStorageSize = storageBean.getTotalStorageSize();
    }
    if (totalStorageSize != null) {
        totalStorageSize = totalStorageSize * 1024 * 1024;
    }
    Long storageSize = userFileMapper.selectStorageSizeByUserId(userId);
    if (storageSize == null) {
        storageSize = 0L;
    }
    if (storageSize + fileSize > totalStorageSize) {
        return false;
    }
    return true;
}
Also used : StorageBean(com.qiwenshare.file.domain.StorageBean) SysParam(com.qiwenshare.file.domain.SysParam) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 49 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project jeeagile by jeeagile.

the class AgileSysRoleServiceImpl method selectRoleDeptIdList.

/**
 * 查询角色已分配数据权限
 *
 * @param roleId
 * @return
 */
private List<String> selectRoleDeptIdList(Serializable roleId) {
    LambdaQueryWrapper<AgileSysRoleDept> lambdaQueryWrapper = new LambdaQueryWrapper<>();
    lambdaQueryWrapper.eq(AgileSysRoleDept::getRoleId, roleId);
    List<AgileSysRoleDept> roleDeptList = agileSysRoleDeptService.list(lambdaQueryWrapper);
    List<String> roleDeptIdList = new ArrayList<>();
    for (AgileSysRoleDept sysRoleDept : roleDeptList) {
        if (agileSysDeptService.countChild(sysRoleDept.getDeptId()) < 1) {
            roleDeptIdList.add(sysRoleDept.getDeptId());
        }
    }
    return roleDeptIdList;
}
Also used : AgileSysRoleDept(com.jeeagile.system.entity.AgileSysRoleDept) ArrayList(java.util.ArrayList) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 50 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project usercenteradmin by caijiya.

the class LoginServiceImpl method login.

@Override
public String login(LoginDTO loginDTO, String captchaKey) {
    String captchaCode = stringRedisTemplate.opsForValue().get(Constants.REDIS_KEY_CAPTCHA + captchaKey);
    if (StrUtil.isBlank(captchaCode) || !loginDTO.getCaptchaCode().equals(captchaCode)) {
        log.warn("验证码校验失败");
        throw new BaseException(ResultCodeEnum.CAPTCHA_ERROR);
    }
    String username = loginDTO.getUsername();
    User user = userMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getUsername, username));
    if (user == null) {
        throw new BaseException(ResultCodeEnum.USERNAME_PASSWORD_ERROR);
    }
    String salt = user.getSalt();
    if (!DigestUtil.md5Hex(salt + loginDTO.getPassword()).equals(user.getPassword())) {
        throw new BaseException(ResultCodeEnum.USERNAME_PASSWORD_ERROR);
    }
    // 将用户信息、权限信息缓存到redis todo 暂时只存基本信息
    String ticket = UUID.randomUUID().toString();
    // 存储token与id的映射
    redisTemplate.opsForValue().set(Constants.TOKEN_PREFIX + ticket, user.getId(), 30, TimeUnit.MINUTES);
    // 存储用户信息
    redisTemplate.opsForValue().set(Constants.REDIS_KEY_USER_PREFIX + user.getId(), user, 30, TimeUnit.MINUTES);
    return ticket;
}
Also used : BaseException(com.zy.usercenteradmin.common.BaseException) User(com.zy.usercenteradmin.entity.User) 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