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