use of com.qiwenshare.file.domain.StorageBean in project qiwen-file by qiwenshare.
the class FiletransferController method getStorage.
@Operation(summary = "获取存储信息", description = "获取存储信息", tags = { "filetransfer" })
@RequestMapping(value = "/getstorage", method = RequestMethod.GET)
@ResponseBody
public RestResult<StorageBean> getStorage() {
JwtUser sessionUserBean = SessionUtil.getSession();
StorageBean storageBean = new StorageBean();
storageBean.setUserId(sessionUserBean.getUserId());
Long storageSize = filetransferService.selectStorageSizeByUserId(sessionUserBean.getUserId());
StorageBean storage = new StorageBean();
storage.setUserId(sessionUserBean.getUserId());
storage.setStorageSize(storageSize);
Long totalStorageSize = storageService.getTotalStorageSize(sessionUserBean.getUserId());
storage.setTotalStorageSize(totalStorageSize);
return RestResult.success().data(storage);
}
use of com.qiwenshare.file.domain.StorageBean 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.qiwenshare.file.domain.StorageBean in project qiwen-file by qiwenshare.
the class StorageService method getTotalStorageSize.
public Long getTotalStorageSize(Long userId) {
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;
}
return totalStorageSize;
}
Aggregations