附属属性删除文件

This commit is contained in:
huguanghan 2024-12-25 09:37:48 +08:00
parent 472098a2d1
commit fa5d39677d
3 changed files with 37 additions and 1 deletions

View File

@ -208,7 +208,7 @@ public class EquipmentController {
return R.success(fileList);
}
@RequestMapping(value = "/file/read", method = RequestMethod.GET)
@RequestMapping(value = "/file/read", method = RequestMethod.POST)
public void readFile(String path, HttpServletResponse response) throws IOException {
if (StringUtils.isBlank(path)){
throw new ServiceException("请输入浏览的文件路径");
@ -217,4 +217,14 @@ public class EquipmentController {
sysEquipmentService.readFileToSteam(path, response.getOutputStream());
}
@RequestMapping(value = "/file/delete", method = RequestMethod.GET)
public void deleteFile(String path, HttpServletResponse response) throws IOException {
if (StringUtils.isBlank(path)){
throw new ServiceException("请输入浏览的文件路径");
}
response.setContentType("application/octet-stream");
sysEquipmentService.readFileToSteam(path, response.getOutputStream());
}
}

View File

@ -45,4 +45,6 @@ public interface SysEquipmentService {
List<SysEquipmentDocs> getFileList(Long deviceId, String component);
void readFileToSteam(String path, OutputStream stream);
void deleteFile(String path);
}

View File

@ -420,6 +420,17 @@ public class SysEquipmentServiceImpl implements SysEquipmentService {
@Override
public void deleteSysEquipmentExtProps(Long id) {
sysGenExtPropsMapper.deleteById(id);
//查询设备下的所有图片
QueryWrapper<SysEquipmentDocs> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("deviceid",id);
List<SysEquipmentDocs> sysEquipmentDocsList = sysEquipmentDocsMapper.selectList(queryWrapper);
if (CollectionUtils.isNotEmpty(sysEquipmentDocsList)){
for (SysEquipmentDocs item : sysEquipmentDocsList){
deleteFile(item.getUrl());
sysEquipmentDocsMapper.deleteById(item.getId());
}
}
}
@Override
@ -471,6 +482,19 @@ public class SysEquipmentServiceImpl implements SysEquipmentService {
minioViewsServcie.readFileToStream(path, stream);
}
@Override
public void deleteFile(String path) {
try {
minioViewsServcie.removeFile(minioAutoProperties.getPublicBucket(), path,false);
//删除缩略图
String thumbnailPath = path.replace("pic", "thumbnailPic");
minioViewsServcie.removeFile(minioAutoProperties.getPublicBucket(), thumbnailPath,false);
}catch (Exception e){
log.error("文件删除失败");
}
}
public File scale(MultipartFile file) throws IOException {
// 获取原始文件名和文件类型
String originalFileName = file.getOriginalFilename();