1. file 删除时, 同步删除 fileSource
This commit is contained in:
parent
e66dc52858
commit
4bd86c2e0e
|
|
@ -0,0 +1,18 @@
|
|||
package com.chushang.inspection.work.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Range;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class ImageDTO implements Serializable {
|
||||
|
||||
@NotNull(message = "图片类型不能为空")
|
||||
@Range(min = 1, max = 30, message = "非法的图片类型")
|
||||
private Integer imgType;
|
||||
|
||||
@NotNull(message = "工单id不能为空")
|
||||
private Long wrkId;
|
||||
}
|
||||
|
|
@ -1,12 +1,65 @@
|
|||
package com.chushang.inspection.work.controller;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import com.chushang.common.core.web.AjaxResult;
|
||||
import com.chushang.common.log.annotation.SysLog;
|
||||
import com.chushang.common.log.enums.BusinessType;
|
||||
import com.chushang.inspection.work.dto.ImageDTO;
|
||||
import com.chushang.inspection.work.service.WrkImgService;
|
||||
import lombok.extern.java.Log;
|
||||
import org.aspectj.weaver.loadtime.Aj;
|
||||
import org.hibernate.validator.constraints.Range;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* 工单图片(wrk_img)表控制层
|
||||
*
|
||||
* @author xxxxx
|
||||
*/
|
||||
* 工单图片(wrk_img)表控制层
|
||||
*
|
||||
* @author xxxxx
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/wrk_img")
|
||||
@RequestMapping("/wrk/img")
|
||||
public class WrkImgController {
|
||||
|
||||
@Resource
|
||||
private WrkImgService wrkImgService;
|
||||
|
||||
/**
|
||||
* 工单图片上传
|
||||
* @param file 文件
|
||||
* @param imgType 文件类型
|
||||
* @param wrkId 工单id
|
||||
* @param locationAddress 定位地址
|
||||
*/
|
||||
@Validated
|
||||
@SysLog("图片上传")
|
||||
@PostMapping(value = "/picture")
|
||||
public AjaxResult uploadPicture(@RequestParam("file") MultipartFile file,
|
||||
@NotNull(message = "图片类型不能为空")
|
||||
@Range(min = 1, max = 30, message = "非法的图片类型")
|
||||
Integer imgType,
|
||||
@NotNull(message = "工单id不能为空")
|
||||
Long wrkId,
|
||||
@Size(max = 255, message = "定位地址不能超过255个字符")
|
||||
String locationAddress) {
|
||||
Assert.isFalse(file.isEmpty(), "【{}】是空的", file.getOriginalFilename());
|
||||
String url = wrkImgService.uploadPicture(file, imgType, wrkId, locationAddress);
|
||||
return AjaxResult.success(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除工单图片
|
||||
*/
|
||||
@DeleteMapping("/delete")
|
||||
@SysLog(value = "删除图片", businessType = BusinessType.DELETE)
|
||||
public AjaxResult delete(@RequestBody @Validated ImageDTO image) {
|
||||
wrkImgService.removeImg(image);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,18 @@
|
|||
package com.chushang.inspection.work.service;
|
||||
|
||||
import com.chushang.inspection.work.dto.ImageDTO;
|
||||
import com.chushang.inspection.work.po.WrkImg;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
/**
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @auther: zhao
|
||||
* @date: 2024/6/28 11:25
|
||||
*/
|
||||
public interface WrkImgService extends IService<WrkImg>{
|
||||
public interface WrkImgService extends IService<WrkImg> {
|
||||
|
||||
|
||||
String uploadPicture(MultipartFile file, Integer imgType, Long wrkId, String locationAddress);
|
||||
|
||||
void removeImg(ImageDTO image);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
package com.chushang.inspection.work.service.impl;
|
||||
|
||||
import com.chushang.inspection.work.dto.ImageDTO;
|
||||
import com.chushang.inspection.work.service.WrkImgService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.chushang.inspection.work.mapper.WrkImgMapper;
|
||||
import com.chushang.inspection.work.po.WrkImg;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @auther: zhao
|
||||
|
|
@ -13,4 +15,13 @@ import com.chushang.inspection.work.po.WrkImg;
|
|||
@Service
|
||||
public class WrkImgServiceImpl extends ServiceImpl<WrkImgMapper, WrkImg> implements WrkImgService {
|
||||
|
||||
@Override
|
||||
public String uploadPicture(MultipartFile file, Integer imgType, Long wrkId, String locationAddress) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeImg(ImageDTO image) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,8 +90,7 @@ public class FileController {
|
|||
@PostMapping(value = "/del/batch")
|
||||
@RequiresPermissions("system:file:del")
|
||||
public AjaxResult delFile(@RequestBody List<String> fids) {
|
||||
fileSourceService.delFileBatch(fids);
|
||||
return AjaxResult.success();
|
||||
return AjaxResult.success( fileSourceService.delFileBatch(fids));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,16 +34,15 @@ import org.apache.tika.mime.MimeTypes;
|
|||
import org.redisson.api.RMap;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @auther: zhao
|
||||
|
|
@ -178,6 +177,7 @@ public class FileSourceService
|
|||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void delFile(String fid) {
|
||||
// 文件信息
|
||||
FileSourceInfo info = getOne(new LambdaQueryWrapper<FileSourceInfo>()
|
||||
|
|
@ -185,19 +185,24 @@ public class FileSourceService
|
|||
.last(Operator.LIMIT_ONE.getCharacter()));
|
||||
if (ObjUtil.isEmpty(info)) return;
|
||||
ossService.delFile(info.getPath());
|
||||
removeById(fid);
|
||||
}
|
||||
|
||||
public void delFileBatch(List<String> fids) {
|
||||
@Transactional
|
||||
public String delFileBatch(List<String> fids) {
|
||||
// 文件信息
|
||||
List<FileSourceInfo> list = list(new LambdaQueryWrapper<FileSourceInfo>()
|
||||
.in(FileSourceInfo::getFid, fids));
|
||||
if (CollectionUtil.isEmpty(list)) return;
|
||||
if (CollectionUtil.isEmpty(list)) return "success";
|
||||
List<String> strings
|
||||
= ossService.delFileBatch(list.stream().map(FileSourceInfo::getPath).toList());
|
||||
Set<String> removeFids = fids.stream().filter(f -> !strings.contains(f)).collect(Collectors.toSet());
|
||||
removeBatchByIds(removeFids);
|
||||
if (CollectionUtil.isNotEmpty(strings)){
|
||||
String key = String.join(",", strings);
|
||||
throw new ResultException("以下文件未删除: [" + key + "].");
|
||||
return "以下文件未删除: [" + key + "].";
|
||||
}
|
||||
return "success";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue