添加文件-文件夹
This commit is contained in:
@@ -43,4 +43,7 @@ public class File extends BaseEntity {
|
||||
|
||||
@ApiModelProperty(value = "用户类型")
|
||||
private String userEnums;
|
||||
|
||||
@ApiModelProperty(value = "文件夹ID")
|
||||
private String fileDirectoryId;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package cn.lili.modules.file.entity;
|
||||
|
||||
import cn.lili.common.security.enums.UserEnums;
|
||||
import cn.lili.mybatis.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
|
||||
@Data
|
||||
@TableName("li_file_directory")
|
||||
@ApiModel(value = "文件目录")
|
||||
public class FileDirectory extends BaseEntity {
|
||||
|
||||
/**
|
||||
* @see UserEnums
|
||||
*/
|
||||
@ApiModelProperty(value = "文件目录类型")
|
||||
private String directoryType;
|
||||
@ApiModelProperty(value = "拥有者名称")
|
||||
private String directoryName;
|
||||
@ApiModelProperty(value = "拥有者id")
|
||||
private String ownerId;
|
||||
@ApiModelProperty(value = "父分类ID")
|
||||
private String parentId;
|
||||
@ApiModelProperty(value = "层级")
|
||||
@Min(value = 0, message = "层级最小为0")
|
||||
@Max(value = 2, message = "层级最大为2")
|
||||
private Integer level;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cn.lili.modules.file.entity.dto;
|
||||
|
||||
import cn.lili.common.utils.BeanUtil;
|
||||
import cn.lili.modules.file.entity.FileDirectory;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class FileDirectoryDTO extends FileDirectory{
|
||||
|
||||
@ApiModelProperty(value = "文件目录列表")
|
||||
private List<FileDirectory> children= new ArrayList<>();
|
||||
|
||||
public FileDirectoryDTO(FileDirectory fileDirectory){
|
||||
BeanUtil.copyProperties(fileDirectory, this);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,16 @@
|
||||
package cn.lili.modules.file.entity.dto;
|
||||
|
||||
import cn.lili.common.utils.DateUtil;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import com.alipay.api.internal.util.StringUtils;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 文件查询所属者参数对象
|
||||
*
|
||||
@@ -14,7 +20,7 @@ import lombok.NoArgsConstructor;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class FileOwnerDTO {
|
||||
public class FileOwnerDTO extends PageVO {
|
||||
|
||||
@ApiModelProperty(value = "拥有者id")
|
||||
private String ownerId;
|
||||
@@ -22,4 +28,42 @@ public class FileOwnerDTO {
|
||||
@ApiModelProperty(value = "用户类型")
|
||||
private String userEnums;
|
||||
|
||||
@ApiModelProperty(value = "原文件名")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "存储文件名")
|
||||
private String fileKey;
|
||||
|
||||
@ApiModelProperty(value = "文件类型")
|
||||
private String fileType;
|
||||
|
||||
@ApiModelProperty(value = "文件夹ID")
|
||||
private String fileDirectoryId;
|
||||
|
||||
@ApiModelProperty(value = "起始日期")
|
||||
private String startDate;
|
||||
|
||||
@ApiModelProperty(value = "结束日期")
|
||||
private String endDate;
|
||||
|
||||
public Date getConvertStartDate() {
|
||||
if (StringUtils.isEmpty(startDate)) {
|
||||
return null;
|
||||
}
|
||||
return DateUtil.toDate(startDate, DateUtil.STANDARD_DATE_FORMAT);
|
||||
}
|
||||
|
||||
public Date getConvertEndDate() {
|
||||
if (StringUtils.isEmpty(endDate)) {
|
||||
return null;
|
||||
}
|
||||
//结束时间等于结束日期+1天 -1秒,
|
||||
Date date = DateUtil.toDate(endDate, DateUtil.STANDARD_DATE_FORMAT);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + 1);
|
||||
calendar.set(Calendar.SECOND, -1);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.lili.modules.file.entity.dto;
|
||||
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.common.vo.SearchVO;
|
||||
import cn.lili.modules.file.entity.File;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class FileSearchParams extends PageVO {
|
||||
|
||||
@ApiModelProperty(value = "文件")
|
||||
private File file;
|
||||
@ApiModelProperty(value = "搜索VO")
|
||||
private SearchVO searchVO;
|
||||
@ApiModelProperty(value = "文件夹ID")
|
||||
private String fileDirectoryId;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package cn.lili.modules.file.mapper;
|
||||
|
||||
import cn.lili.modules.file.entity.FileDirectory;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* 文件管理数据处理层
|
||||
*
|
||||
* @author Chopper
|
||||
* @since 2021-02-22 17:20
|
||||
*/
|
||||
public interface FileDirectoryMapper extends BaseMapper<FileDirectory> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package cn.lili.modules.file.service;
|
||||
|
||||
import cn.lili.common.security.enums.UserEnums;
|
||||
import cn.lili.modules.file.entity.FileDirectory;
|
||||
import cn.lili.modules.file.entity.dto.FileDirectoryDTO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文件管理业务层
|
||||
*
|
||||
* @author Chopper
|
||||
*/
|
||||
public interface FileDirectoryService extends IService<FileDirectory> {
|
||||
|
||||
/**
|
||||
* 添加目录
|
||||
*
|
||||
* @param userEnum
|
||||
* @param id
|
||||
* @param ownerName
|
||||
*/
|
||||
void addFileDirectory(UserEnums userEnum, String id, String ownerName);
|
||||
|
||||
/**
|
||||
* 获取文件目录
|
||||
*
|
||||
* @param ownerId 拥有者
|
||||
* @return
|
||||
*/
|
||||
List<FileDirectoryDTO> getFileDirectoryList(String ownerId);
|
||||
}
|
||||
@@ -24,6 +24,12 @@ public interface FileService extends IService<File> {
|
||||
* @param ids
|
||||
*/
|
||||
void batchDelete(List<String> ids);
|
||||
/**
|
||||
* 根据文件夹ID批量删除
|
||||
*
|
||||
* @param directoryId 文件夹ID
|
||||
*/
|
||||
void batchDeleteByDirectory(String directoryId);
|
||||
|
||||
/**
|
||||
* 所有者批量删除
|
||||
@@ -37,22 +43,19 @@ public interface FileService extends IService<File> {
|
||||
/**
|
||||
* 自定义搜索分页
|
||||
*
|
||||
* @param file
|
||||
* @param searchVO
|
||||
* @param pageVo
|
||||
|
||||
* @param fileOwnerDTO 文件查询
|
||||
|
||||
* @return
|
||||
*/
|
||||
IPage<File> customerPage(File file, SearchVO searchVO, PageVO pageVo);
|
||||
IPage<File> customerPage(FileOwnerDTO fileOwnerDTO);
|
||||
|
||||
/**
|
||||
* 所属文件数据查询
|
||||
*
|
||||
* @param file
|
||||
* @param searchVO
|
||||
* @param pageVo
|
||||
* @param ownerDTO
|
||||
* @param ownerDTO 文件查询
|
||||
* @return
|
||||
*/
|
||||
IPage<File> customerPageOwner(FileOwnerDTO ownerDTO, File file, SearchVO searchVO, PageVO pageVo);
|
||||
IPage<File> customerPageOwner(FileOwnerDTO ownerDTO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package cn.lili.modules.file.serviceimpl;
|
||||
|
||||
import cn.lili.common.security.enums.UserEnums;
|
||||
import cn.lili.modules.file.entity.FileDirectory;
|
||||
import cn.lili.modules.file.entity.dto.FileDirectoryDTO;
|
||||
import cn.lili.modules.file.mapper.FileDirectoryMapper;
|
||||
import cn.lili.modules.file.service.FileDirectoryService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文件管理业务层实现
|
||||
*
|
||||
* @author Chopper
|
||||
* @since 2020/11/26 17:50
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class FileDirectoryServiceImpl extends ServiceImpl<FileDirectoryMapper, FileDirectory> implements FileDirectoryService {
|
||||
|
||||
|
||||
@Override
|
||||
public void addFileDirectory(UserEnums userEnum, String id, String ownerName) {
|
||||
FileDirectory fileDirectory = new FileDirectory();
|
||||
fileDirectory.setOwnerId(id);
|
||||
fileDirectory.setDirectoryName(ownerName);
|
||||
fileDirectory.setDirectoryType(userEnum.name());
|
||||
this.save(fileDirectory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileDirectoryDTO> getFileDirectoryList(String scene) {
|
||||
|
||||
List<FileDirectory> fileDirectoryList = this.list();
|
||||
List<FileDirectoryDTO> fileDirectoryDTOList = new ArrayList<>();
|
||||
|
||||
fileDirectoryList.forEach(item -> {
|
||||
if (item.getLevel() == 0) {
|
||||
FileDirectoryDTO fileDirectoryDTO = new FileDirectoryDTO(item);
|
||||
initChild(fileDirectoryDTO, fileDirectoryList);
|
||||
fileDirectoryDTOList.add(fileDirectoryDTO);
|
||||
}
|
||||
});
|
||||
|
||||
return fileDirectoryDTOList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 递归初始化子树
|
||||
*/
|
||||
private void initChild(FileDirectoryDTO fileDirectoryDTO, List<FileDirectory> fileDirectoryList) {
|
||||
if (fileDirectoryList == null) {
|
||||
return;
|
||||
}
|
||||
fileDirectoryList.stream()
|
||||
.filter(item -> (item.getParentId().equals(fileDirectoryDTO.getId())))
|
||||
.forEach(child -> {
|
||||
FileDirectoryDTO childTree = new FileDirectoryDTO(child);
|
||||
initChild(childTree, fileDirectoryList);
|
||||
fileDirectoryDTO.getChildren().add(childTree);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,14 @@ import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.common.security.AuthUser;
|
||||
import cn.lili.mybatis.util.PageUtil;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.common.vo.SearchVO;
|
||||
import cn.lili.modules.file.entity.File;
|
||||
import cn.lili.modules.file.entity.dto.FileOwnerDTO;
|
||||
import cn.lili.modules.file.mapper.FileMapper;
|
||||
import cn.lili.modules.file.plugin.FilePlugin;
|
||||
import cn.lili.modules.file.plugin.FilePluginFactory;
|
||||
import cn.lili.modules.file.service.FileService;
|
||||
import cn.lili.mybatis.util.PageUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@@ -47,6 +46,18 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, File> implements Fi
|
||||
this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchDeleteByDirectory(String directoryId) {
|
||||
LambdaQueryWrapper<File> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(File::getFileDirectoryId, directoryId);
|
||||
|
||||
List<File> files = this.list(queryWrapper);
|
||||
List<String> keys = new ArrayList<>();
|
||||
files.forEach(item -> keys.add(item.getFileKey()));
|
||||
filePluginFactory.filePlugin().deleteFile(keys);
|
||||
this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchDelete(List<String> ids, AuthUser authUser) {
|
||||
LambdaQueryWrapper<File> queryWrapper = new LambdaQueryWrapper<>();
|
||||
@@ -74,26 +85,28 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, File> implements Fi
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<File> customerPage(File file, SearchVO searchVO, PageVO pageVo) {
|
||||
public IPage<File> customerPage(FileOwnerDTO fileOwnerDTO) {
|
||||
LambdaQueryWrapper<File> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.like(CharSequenceUtil.isNotEmpty(file.getName()), File::getName, file.getName())
|
||||
.like(CharSequenceUtil.isNotEmpty(file.getFileKey()), File::getFileKey, file.getFileKey())
|
||||
.like(CharSequenceUtil.isNotEmpty(file.getFileType()), File::getFileType, file.getFileType())
|
||||
.between(CharSequenceUtil.isNotEmpty(searchVO.getStartDate()) && CharSequenceUtil.isNotEmpty(searchVO.getEndDate()),
|
||||
File::getCreateTime, searchVO.getStartDate(), searchVO.getEndDate());
|
||||
return this.page(PageUtil.initPage(pageVo), queryWrapper);
|
||||
queryWrapper.like(CharSequenceUtil.isNotEmpty(fileOwnerDTO.getName()), File::getName, fileOwnerDTO.getName())
|
||||
.eq(CharSequenceUtil.isNotEmpty(fileOwnerDTO.getFileDirectoryId()),File::getFileDirectoryId, fileOwnerDTO.getFileDirectoryId())
|
||||
.like(CharSequenceUtil.isNotEmpty(fileOwnerDTO.getFileKey()), File::getFileKey, fileOwnerDTO.getFileKey())
|
||||
.like(CharSequenceUtil.isNotEmpty(fileOwnerDTO.getFileType()), File::getFileType, fileOwnerDTO.getFileType())
|
||||
.between(CharSequenceUtil.isNotEmpty(fileOwnerDTO.getStartDate()) && CharSequenceUtil.isNotEmpty(fileOwnerDTO.getEndDate()),
|
||||
File::getCreateTime, fileOwnerDTO.getStartDate(), fileOwnerDTO.getEndDate());
|
||||
return this.page(PageUtil.initPage(fileOwnerDTO), queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<File> customerPageOwner(FileOwnerDTO ownerDTO, File file, SearchVO searchVO, PageVO pageVo) {
|
||||
public IPage<File> customerPageOwner(FileOwnerDTO fileOwnerDTO) {
|
||||
LambdaQueryWrapper<File> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(CharSequenceUtil.isNotEmpty(ownerDTO.getOwnerId()), File::getOwnerId, ownerDTO.getOwnerId())
|
||||
.eq(File::getUserEnums, ownerDTO.getUserEnums())
|
||||
.like(CharSequenceUtil.isNotEmpty(file.getName()), File::getName, file.getName())
|
||||
.like(CharSequenceUtil.isNotEmpty(file.getFileKey()), File::getFileKey, file.getFileKey())
|
||||
.like(CharSequenceUtil.isNotEmpty(file.getFileType()), File::getFileType, file.getFileType())
|
||||
.between(CharSequenceUtil.isNotEmpty(searchVO.getStartDate()) && CharSequenceUtil.isNotEmpty(searchVO.getEndDate()),
|
||||
File::getCreateTime, searchVO.getStartDate(), searchVO.getEndDate());
|
||||
return this.page(PageUtil.initPage(pageVo), queryWrapper);
|
||||
queryWrapper.eq(CharSequenceUtil.isNotEmpty(fileOwnerDTO.getOwnerId()), File::getOwnerId, fileOwnerDTO.getOwnerId())
|
||||
.eq(File::getUserEnums, fileOwnerDTO.getUserEnums())
|
||||
.eq(CharSequenceUtil.isNotEmpty(fileOwnerDTO.getFileDirectoryId()),File::getFileDirectoryId, fileOwnerDTO.getFileDirectoryId())
|
||||
.like(CharSequenceUtil.isNotEmpty(fileOwnerDTO.getName()), File::getName, fileOwnerDTO.getName())
|
||||
.like(CharSequenceUtil.isNotEmpty(fileOwnerDTO.getFileKey()), File::getFileKey, fileOwnerDTO.getFileKey())
|
||||
.like(CharSequenceUtil.isNotEmpty(fileOwnerDTO.getFileType()), File::getFileType, fileOwnerDTO.getFileType())
|
||||
.between(CharSequenceUtil.isNotEmpty(fileOwnerDTO.getStartDate()) && CharSequenceUtil.isNotEmpty(fileOwnerDTO.getEndDate()),
|
||||
File::getCreateTime, fileOwnerDTO.getStartDate(), fileOwnerDTO.getEndDate());
|
||||
return this.page(PageUtil.initPage(fileOwnerDTO), queryWrapper);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user