Search in sources :

Example 1 with StorageBean

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);
}
Also used : StorageBean(com.qiwenshare.file.domain.StorageBean) JwtUser(com.qiwenshare.common.util.security.JwtUser) Operation(io.swagger.v3.oas.annotations.Operation)

Example 2 with StorageBean

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;
}
Also used : StorageBean(com.qiwenshare.file.domain.StorageBean) SysParam(com.qiwenshare.file.domain.SysParam) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 3 with StorageBean

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;
}
Also used : StorageBean(com.qiwenshare.file.domain.StorageBean) SysParam(com.qiwenshare.file.domain.SysParam) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Aggregations

StorageBean (com.qiwenshare.file.domain.StorageBean)3 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)2 SysParam (com.qiwenshare.file.domain.SysParam)2 JwtUser (com.qiwenshare.common.util.security.JwtUser)1 Operation (io.swagger.v3.oas.annotations.Operation)1