|
@@ -33,13 +33,13 @@ public class FileMangerService {
|
|
* @param files
|
|
* @param files
|
|
* @param sourceId
|
|
* @param sourceId
|
|
*/
|
|
*/
|
|
- public List<Integer> add(List<MultipartFile> files, Integer sourceId){
|
|
|
|
- if(files != null && files.size() != 0){
|
|
|
|
|
|
+ public List<Integer> add(List<MultipartFile> files, Integer sourceId) {
|
|
|
|
+ if (files != null && files.size() != 0) {
|
|
//1.获取文件上传到服务器,调用FileFactory的uploadFile
|
|
//1.获取文件上传到服务器,调用FileFactory的uploadFile
|
|
List<SystemFileDTO> systemFileDTOS = fileFactoryService.uploadFiles(files, sourceId);
|
|
List<SystemFileDTO> systemFileDTOS = fileFactoryService.uploadFiles(files, sourceId);
|
|
//2.根据上传后的返回实体类信息,将实体类信息入库,调用systemFileService add
|
|
//2.根据上传后的返回实体类信息,将实体类信息入库,调用systemFileService add
|
|
- if(systemFileDTOS != null && systemFileDTOS.size() != 0 ) {
|
|
|
|
- List<Integer> insertIds = systemFileService.add(systemFileDTOS,sourceId);
|
|
|
|
|
|
+ if (systemFileDTOS != null && systemFileDTOS.size() != 0) {
|
|
|
|
+ List<Integer> insertIds = systemFileService.add(systemFileDTOS, sourceId);
|
|
return insertIds;
|
|
return insertIds;
|
|
} else {
|
|
} else {
|
|
throw new XiaoShiException("入表信息为空");
|
|
throw new XiaoShiException("入表信息为空");
|
|
@@ -52,12 +52,12 @@ public class FileMangerService {
|
|
//取系统文件
|
|
//取系统文件
|
|
public byte[] download(Integer fileId) throws Exception {
|
|
public byte[] download(Integer fileId) throws Exception {
|
|
DownloadSysFileDTO downloadSysFileDTO = new DownloadSysFileDTO();
|
|
DownloadSysFileDTO downloadSysFileDTO = new DownloadSysFileDTO();
|
|
- if(fileId != null){
|
|
|
|
|
|
+ if (fileId != null) {
|
|
SystemFileVO systemFileVO = systemFileService.query(fileId);
|
|
SystemFileVO systemFileVO = systemFileService.query(fileId);
|
|
- if(systemFileVO.getIsDelete().equals(1)){
|
|
|
|
|
|
+ if (systemFileVO.getIsDelete().equals(1)) {
|
|
return null;
|
|
return null;
|
|
} else {
|
|
} else {
|
|
- BeanUtils.copyProperties(systemFileVO,downloadSysFileDTO);
|
|
|
|
|
|
+ BeanUtils.copyProperties(systemFileVO, downloadSysFileDTO);
|
|
downloadSysFileDTO.setSourceId(systemFileVO.getPType());
|
|
downloadSysFileDTO.setSourceId(systemFileVO.getPType());
|
|
return fileFactoryService.download(downloadSysFileDTO);
|
|
return fileFactoryService.download(downloadSysFileDTO);
|
|
}
|
|
}
|
|
@@ -71,19 +71,19 @@ public class FileMangerService {
|
|
* @param ids
|
|
* @param ids
|
|
* @param type
|
|
* @param type
|
|
*/
|
|
*/
|
|
- public void delete(List<Integer> ids, Integer type){
|
|
|
|
|
|
+ public void delete(List<Integer> ids, Integer type) {
|
|
//首先判断传入的需要删除的id集合不能为空
|
|
//首先判断传入的需要删除的id集合不能为空
|
|
- if(CollectionUtils.isEmpty(ids)){
|
|
|
|
|
|
+ if (CollectionUtils.isEmpty(ids)) {
|
|
throw new XiaoShiException("需要删除的id集合不能为空");
|
|
throw new XiaoShiException("需要删除的id集合不能为空");
|
|
}
|
|
}
|
|
- if(type == null){
|
|
|
|
|
|
+ if (type == null) {
|
|
throw new XiaoShiException("删除类型不能为空");
|
|
throw new XiaoShiException("删除类型不能为空");
|
|
}
|
|
}
|
|
//有逻辑删除和物理删除两种,需要进行判定,传入类型为2时,物理删除;传入类型为1时,逻辑删除
|
|
//有逻辑删除和物理删除两种,需要进行判定,传入类型为2时,物理删除;传入类型为1时,逻辑删除
|
|
//逻辑删除(更新isDelete字段为1)
|
|
//逻辑删除(更新isDelete字段为1)
|
|
- if(type.equals(1)){
|
|
|
|
|
|
+ if (type.equals(1)) {
|
|
//遍历传入的id集合,获取需要更新的对象,赋值给实体类
|
|
//遍历传入的id集合,获取需要更新的对象,赋值给实体类
|
|
- for(int i = 0; i < ids.size(); i++){
|
|
|
|
|
|
+ for (int i = 0; i < ids.size(); i++) {
|
|
SystemFileVO systemFileVO = systemFileMapper.query(ids.get(i));
|
|
SystemFileVO systemFileVO = systemFileMapper.query(ids.get(i));
|
|
systemFileVO.setIsDelete(1);
|
|
systemFileVO.setIsDelete(1);
|
|
//将查询出来的vo赋值给实体类
|
|
//将查询出来的vo赋值给实体类
|
|
@@ -91,7 +91,7 @@ public class FileMangerService {
|
|
BeanUtils.copyProperties(systemFileVO, systemFile);
|
|
BeanUtils.copyProperties(systemFileVO, systemFile);
|
|
//更新表
|
|
//更新表
|
|
int row = systemFileMapper.update(systemFile);
|
|
int row = systemFileMapper.update(systemFile);
|
|
- if(row != 1){
|
|
|
|
|
|
+ if (row != 1) {
|
|
String mes = "逻辑删除系统文件第" + i + "条失败";
|
|
String mes = "逻辑删除系统文件第" + i + "条失败";
|
|
log.info("逻辑删除失败,{}", mes);
|
|
log.info("逻辑删除失败,{}", mes);
|
|
throw new XiaoShiException(mes);
|
|
throw new XiaoShiException(mes);
|
|
@@ -100,8 +100,8 @@ public class FileMangerService {
|
|
}
|
|
}
|
|
//物理删除(删除服务器文件,删除数据库中记录)
|
|
//物理删除(删除服务器文件,删除数据库中记录)
|
|
//sftp删除文件
|
|
//sftp删除文件
|
|
- if(type.equals(2)){
|
|
|
|
- for(int i = 0; i < ids.size(); i++){
|
|
|
|
|
|
+ if (type.equals(2)) {
|
|
|
|
+ for (int i = 0; i < ids.size(); i++) {
|
|
//根据id到表中查询该文件记录的数据
|
|
//根据id到表中查询该文件记录的数据
|
|
SystemFileVO systemFileVO = systemFileService.query(ids.get(i));
|
|
SystemFileVO systemFileVO = systemFileService.query(ids.get(i));
|
|
//pType判断是服务器还是阿里云OSS
|
|
//pType判断是服务器还是阿里云OSS
|
|
@@ -109,7 +109,7 @@ public class FileMangerService {
|
|
String filePath = systemFileVO.getFilePath();
|
|
String filePath = systemFileVO.getFilePath();
|
|
fileFactoryService.delete(filePath, pType);
|
|
fileFactoryService.delete(filePath, pType);
|
|
int row = systemFileMapper.deleteById(ids.get(i));
|
|
int row = systemFileMapper.deleteById(ids.get(i));
|
|
- if(row != 1){
|
|
|
|
|
|
+ if (row != 1) {
|
|
throw new XiaoShiException("删除异常");
|
|
throw new XiaoShiException("删除异常");
|
|
} else {
|
|
} else {
|
|
log.info("删除成功");
|
|
log.info("删除成功");
|