zbj//1.修改资源 2.删除资源

This commit is contained in:
zhangbaojian
2023-05-29 09:46:00 +08:00
parent 8028a058de
commit 2291b360f7
4 changed files with 55 additions and 52 deletions

View File

@@ -67,4 +67,9 @@ public class ResourceData {
@TableField(value = "type")
private Integer type;
/**
* 文件名称
*/
@TableField(value = "file_name")
private String fileName;
}

View File

@@ -182,7 +182,7 @@ public class ResourceController extends BaseController {
log.info(e.getMessage());
}
} else {
throw new RuntimeException("文件路有误");
throw new RuntimeException("文件路有误");
}
outputStream.flush();
} catch (Exception e) {
@@ -206,38 +206,26 @@ public class ResourceController extends BaseController {
}
}
public static long getFileSize(InputStream inputStream) throws IOException {
byte[] buffer = new byte[1024];
int len;
long size = 0;
while ((len = inputStream.read(buffer)) != -1) {
size += len;
}
inputStream.close();
return size;
}
/**
* 修改资源
*//*
*/
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/updateFile")
@ApiOperation("修改资源")
public HttpResult<Boolean> updateFile(@ApiParam(value = "文件", required = false) MultipartFile multipartFile,
@ApiParam(value = "id", required = true) String id,
@ApiParam(value = "资源名称", required = true) String name,
@ApiParam(value = "资源类型", required = true) String type,
@ApiParam(value = "资源描述", required = true) String description,
@ApiParam(value = "系统类型Guid", required = false) String systemType) {
public HttpResult<Boolean> updateFile(@ApiParam(value = "id", required = true) String id,
@ApiParam(value = "文件", required = false) MultipartFile multipartFile,
@ApiParam(value = "文件", required = false) MultipartFile picture,
@ApiParam(value = "资源名称", required = false) String name,
@ApiParam(value = "资源状态", required = false) Integer state,
@ApiParam(value = "资源类型", required = false) Integer type) {
String methodDescribe = getMethodDescribe("updateFile");
Boolean flag = iResourceAdministrationService.updateFile(multipartFile, id, name, type, description, systemType);
Boolean flag = iResourceAdministrationService.updateFile(id, multipartFile, picture, name,state, type);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
}
*//**
/**
* 删除资源
*//*
*/
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@GetMapping("/deleteFile")
@ApiOperation("删除资源")
@@ -248,7 +236,7 @@ public class ResourceController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
}
/*
/**
* 导出数据

View File

@@ -26,12 +26,10 @@ public interface ResourceService extends IService<ResourceData> {
void previewFile(String id, HttpServletRequest request, HttpServletResponse response) throws IOException;
/*
Boolean updateFile(MultipartFile multipartFile, String id, String name, String type, String description, String systemType);
Boolean updateFile(String id, MultipartFile multipartFile, MultipartFile picture, String name, Integer state,Integer type);
Boolean deleteFile(String id);
/*
void exportData();*/
}

View File

@@ -70,10 +70,10 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, ResourceDat
resourceData.setUploadTime(LocalDateTime.now());
resourceData.setState(1);
resourceData.setType(type);
resourceData.setFileName(multipartFile.getOriginalFilename());
return this.save(resourceData);
}
@Override
public List<ResourceData> queryData() {
List<ResourceData> list = this.list();
@@ -190,46 +190,58 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, ResourceDat
//return resourceData;
}
/*
@Override
public Boolean updateFile(MultipartFile multipartFile, String id, String name, String type, String description, String systemType) {
Resinformation resinformation = resourceAdministrationMapper.selectById(id);
public Boolean updateFile(String id, MultipartFile multipartFile, MultipartFile picture, String name, Integer state, Integer type) {
ResourceData resourceData = resourceMapper.selectById(id);
//文件
if (null != multipartFile && !multipartFile.isEmpty()) {
//删除文件
fileStorageUtil.deleteFile(resinformation.getUrl());
fileStorageUtil.deleteFile(resourceData.getResUrl());
//获取路径
String url = fileStorageUtil.uploadMultipart(multipartFile, OssPath.RESOURCEADMINISTRATION);
resinformation.setUrl(url);
resinformation.setFileName(multipartFile.getOriginalFilename());
String resUrl = fileStorageUtil.uploadMultipart(multipartFile, OssPath.RESOURCEDATA);
resourceData.setResUrl(resUrl);
resourceData.setFileName(multipartFile.getOriginalFilename());
}
resinformation.setName(name);
resinformation.setDescription(description);
//获取用户id
String userIndex = RequestUtil.getUserIndex();
//String userIndex = "123456";
resinformation.setUpdateUser(userIndex);
resinformation.setUpdateTime(LocalDateTime.now());
resinformation.setState(1);
if (StringUtils.isNotBlank(systemType)) {
resinformation.setSystemType(systemType);
//图片
if (null != picture && !picture.isEmpty()) {
if (StringUtils.isNotBlank(resourceData.getPicUrl())) {
//删除图片
fileStorageUtil.deleteFile(resourceData.getResUrl());
}
//获取路径
String picUrl = fileStorageUtil.uploadMultipart(picture, OssPath.RESOURCEDATA);
resourceData.setPicUrl(picUrl);
}
resinformation.setType(type);
int i = resourceAdministrationMapper.updateById(resinformation);
if (StringUtils.isNotBlank(name)) {
resourceData.setResourceName(name);
}
if (null != state) {
resourceData.setState(state);
}
if (null != type) {
resourceData.setType(type);
}
resourceData.setUpdateTime(LocalDateTime.now());
int i = resourceMapper.updateById(resourceData);
return i > 0;
}
@Override
public Boolean deleteFile(String id) {
Resinformation resinformation = resourceAdministrationMapper.selectById(id);
ResourceData resourceData = resourceMapper.selectById(id);
//删除文件
fileStorageUtil.deleteFile(resinformation.getUrl());
fileStorageUtil.deleteFile(resourceData.getResUrl());
//存在图片删除图片
if (StringUtils.isNotBlank(resourceData.getPicUrl())){
fileStorageUtil.deleteFile(resourceData.getPicUrl());
}
//删除数据
int i = resourceAdministrationMapper.deleteById(id);
int i = resourceMapper.deleteById(id);
return i > 0;
}
/*
@Override
public void exportData() {
String fileName = "资源列表.csv";