批量上传案件证据 #126

Merged
wangqiong123 merged 1 commits from wq into dev 2023-10-19 02:47:54 +00:00
3 changed files with 107 additions and 0 deletions
@@ -1,5 +1,6 @@
package com.ruoyi.web.controller.wisdomarbitrate;
import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
@@ -55,6 +56,30 @@ public class CaseEvidenceController extends BaseController {
Long userId = this.getUserId();
return caseEvidenceService.uploadEvidence(file, annexType, id, username, userId);
}
@PostMapping("/batchUpload")
public AjaxResult batchUpload(@RequestParam("file") MultipartFile[] file, Integer annexType, Long id) {
if(file==null){
return error("请选择要上传的文件");
}
String username = this.getUsername();
Long userId = this.getUserId();
return caseEvidenceService.batchUpload(file, annexType, id, username, userId);
}
/**
* 获取附件
* @param caseAppliId
* @param annexTypeList
* @param
* @return
*/
@GetMapping("/fileList")
public AjaxResult fileList(Long caseAppliId, @RequestParam("annexTypeList") List<Integer> annexTypeList){
if(caseAppliId==null){
return error("案件id不能为空");
}
return caseEvidenceService.fileList(caseAppliId, annexTypeList);
}
/**
* 查询当前用户案件列表
@@ -20,4 +20,17 @@ public interface ICaseEvidenceService {
AjaxResult evidenceConfirmation(CaseApplication caseApplication);
AjaxResult caseCrossexamination(CaseEvidenceDTO caseEvidenceDTO);
/**
* 批量上传文件
* @param file
* @param annexType
* @param id
* @param username
* @param userId
* @return
*/
AjaxResult batchUpload(MultipartFile[] file, Integer annexType, Long id, String username, Long userId);
AjaxResult fileList(Long caseAppliId, List<Integer> annexTypeList);
}
@@ -1,5 +1,6 @@
package com.ruoyi.wisdomarbitrate.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.constant.CaseApplicationConstants;
import com.ruoyi.common.core.domain.AjaxResult;
@@ -21,6 +22,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@@ -195,6 +197,73 @@ IdentityAuthenticationMapper identityAuthenticationMapper;
}
return null;
}
@Transactional
@Override
public AjaxResult batchUpload(MultipartFile[] files, Integer annexType, Long id, String userName, Long userId) {
List<CaseAttach> successList= new ArrayList<>();
try {
String filePath = RuoYiConfig.getUploadPath();
for (MultipartFile file : files) {
// 上传
String fileName = FileUploadUtils.upload(filePath, file);
CaseAttach caseAttach = CaseAttach.builder().caseAppliId(id)
.annexName(fileName)
.annexPath(filePath)
.annexType(annexType)
.userId(userId)
.userName(userName)
.build();
int count = caseAttachMapper.save(caseAttach);
if (count > 0 && annexType!=null && annexType!=8) {
if(id!=null){
//修改案件状态
CaseApplication caseApplication = new CaseApplication();
caseApplication.setId(id);
caseApplication.setCaseStatus(4);
caseApplicationMapper.submitCaseApplication(caseApplication);
}
CaseAttach caseAttachselect = new CaseAttach();
caseAttachselect.setAnnexId(caseAttach.getAnnexId());
caseAttachselect.setAnnexName(caseAttach.getAnnexName());
caseAttachselect.setAnnexType(caseAttach.getAnnexType());
successList.add(caseAttachselect);
}
}
} catch (IOException e) {
e.printStackTrace();
return AjaxResult.error("上传失败");
}
return AjaxResult.success("上传成功",successList);
}
@Override
public AjaxResult fileList(Long caseAppliId, List<Integer> annexTypeList) {
CaseApplication caseApplication = new CaseApplication();
caseApplication.setId(caseAppliId);
caseApplication.setAnnexTypeList(annexTypeList);
List<CaseAttach> caseAttachList = caseAttachMapper.queryCaseAttachList(caseApplication);
if(CollectionUtil.isNotEmpty(caseAttachList)){
for (CaseAttach caseAttach : caseAttachList) {
String annexName = caseAttach.getAnnexName();
String prefix = "/profile";
int startIndex = annexName.indexOf(prefix);
startIndex += prefix.length();
String annexPath = "/uploadPath" + annexName.substring(startIndex);
caseAttach.setAnnexPath(annexPath);
int startIndexnew = annexName.lastIndexOf("/");
if(startIndexnew!=-1){
String annexNamenew = annexName.substring(startIndexnew+1);
caseAttach.setAnnexName(annexNamenew);
}
}
return AjaxResult.success(caseAttachList);
}
return null;
}
private List<CaseEvidenceVO> getCaseEvidenceVOList(String identityNum, List<Integer> caseStatusList, Integer identityType) {
List<CaseEvidenceVO> caseListByRespondent = caseEvidenceMapper.getCaseListByRespondent(identityNum, caseStatusList, identityType);