2021与蓝度共同重构项目,服务端
liuhaonan
2022-04-01 8235bb3cebd773ba6fe29719cba7706858bbc2ee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.sandu.ximon.admin.service;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.object.BaseConditionVO;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.ximon.admin.param.IpVolumeFileParam;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.dao.domain.IpVolumeFile;
import com.sandu.ximon.dao.mapper.IpVolumeFileMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
 
/**
 * @Author liuhaonan
 * @Date 2021/12/16 10:48
 * @Version 1.0
 */
@Service
@AllArgsConstructor
public class IpVolumeFileService extends BaseServiceImpl<IpVolumeFileMapper, IpVolumeFile> {
    private final IpVolumeFileMapper ipVolumeFileMapper;
    private final ClientService clientService;
 
 
    public boolean addFile(IpVolumeFileParam fileParam) {
        IpVolumeFile file = new IpVolumeFile();
        file.setUserId(SecurityUtils.getClientId());
        if(SecurityUtils.getClientId()!=null){
            file.setUserName(SecurityUtils.getUsername());
        }
 
        if(clientService.getClientId()!=null){
            file.setClientId(clientService.getClientId());
        }
        file.setFileName(fileParam.getFileName());
        file.setFileUrl(fileParam.getFileUrl());
        file.setOriginSize(fileParam.getOriginSize());
        return save(file);
    }
 
    public boolean deleteFile(Long fileId) {
        IpVolumeFile byId = getById(fileId);
        if (byId == null) {
            throw new BusinessException("找不到对应文件");
        }
        return removeById(fileId);
    }
 
    public LambdaQueryWrapper<IpVolumeFile> listFile(BaseConditionVO baseConditionVO, String keyword) {
        PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
        LambdaQueryWrapper<IpVolumeFile> wrapper = Wrappers.lambdaQuery(IpVolumeFile.class).eq(IpVolumeFile::getClientId, clientService.getClientId());
        if (keyword.isEmpty()) {
            return wrapper;
        } else {
          return   wrapper.like(IpVolumeFile::getFileName,keyword);
        }
    }
 
}