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