Search in sources :

Example 1 with SysParam

use of com.qiwenshare.file.domain.SysParam 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 2 with SysParam

use of com.qiwenshare.file.domain.SysParam in project qiwen-file by qiwenshare.

the class SysParamController method groupList.

@Operation(summary = "查询系统参数组", tags = { "系统参数管理" })
@RequestMapping(value = "/grouplist", method = RequestMethod.GET)
@ResponseBody
public RestResult<Map> groupList(@Parameter(description = "查询参数dto", required = false) QueryGroupParamDTO queryGroupParamDTO) {
    List<SysParam> list = sysParamService.list(new QueryWrapper<SysParam>().lambda().eq(SysParam::getGroupName, queryGroupParamDTO.getGroupName()));
    Map<String, Object> result = new HashMap<>();
    for (SysParam sysParam : list) {
        result.put(sysParam.getSysParamKey(), sysParam.getSysParamValue());
    }
    return RestResult.success().data(result);
}
Also used : HashMap(java.util.HashMap) SysParam(com.qiwenshare.file.domain.SysParam) Operation(io.swagger.v3.oas.annotations.Operation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with SysParam

use of com.qiwenshare.file.domain.SysParam 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)

Example 4 with SysParam

use of com.qiwenshare.file.domain.SysParam in project qiwen-file by qiwenshare.

the class SysParamService method getValue.

@Override
public String getValue(String key) {
    SysParam sysParam = new SysParam();
    sysParam.setSysParamKey(key);
    List<SysParam> list = sysParamMapper.selectList(new QueryWrapper<>(sysParam));
    if (list != null && !list.isEmpty()) {
        return list.get(0).getSysParamValue();
    }
    return null;
}
Also used : SysParam(com.qiwenshare.file.domain.SysParam)

Aggregations

SysParam (com.qiwenshare.file.domain.SysParam)4 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)2 StorageBean (com.qiwenshare.file.domain.StorageBean)2 Operation (io.swagger.v3.oas.annotations.Operation)1 HashMap (java.util.HashMap)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1