终端检测代码提交

This commit is contained in:
wurui
2023-03-20 14:05:17 +08:00
parent 196e599cd8
commit e13b18d6ff
3 changed files with 45 additions and 44 deletions

View File

@@ -22,7 +22,7 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.*;
import java.util.List;
/**
@@ -124,8 +124,8 @@ public class PmsTerminalDetectionController extends BaseController {
}
@ApiOperation("检测报告下载")
@PostMapping(value = "/reportDownload")
public InputStreamResource reportDownload(@RequestBody TerminalParam.DownloadParam param) throws IOException {
@GetMapping(value = "/reportDownload")
public InputStreamResource reportDownload( TerminalParam.DownloadParam param) throws IOException {
InputStreamResource minIoUploadResDTO = pmsTerminalDetectionService.reportDownload(param);
return minIoUploadResDTO;
}

View File

@@ -1,8 +1,6 @@
package com.njcn.process.service;
import cn.hutool.json.JSONArray;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.minioss.bo.MinIoUploadResDTO;
import com.njcn.process.pojo.param.TerminalParam;
import com.njcn.process.pojo.po.PmsTerminalDetection;
import com.baomidou.mybatisplus.extension.service.IService;
@@ -12,7 +10,6 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**

View File

@@ -11,7 +11,6 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
@@ -44,11 +43,7 @@ import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.io.*;
import java.time.LocalDate;
import java.util.*;
import java.util.function.Function;
@@ -106,7 +101,7 @@ public class PmsTerminalDetectionServiceImpl extends ServiceImpl<PmsTerminalDete
ByteArrayOutputStream out = new ByteArrayOutputStream();
//创建临时文件
workbook.write(out);
byte [] bookByteAry = out.toByteArray();
byte[] bookByteAry = out.toByteArray();
InputStream in = new ByteArrayInputStream(bookByteAry);
InputStreamResource inputStreamResource = new InputStreamResource(in);
return inputStreamResource;
@@ -125,11 +120,11 @@ public class PmsTerminalDetectionServiceImpl extends ServiceImpl<PmsTerminalDete
wrapper.eq(PmsTerminalDetection::getName, param.getName())
)
);
if (count>0) {
throw new BusinessException(PmsDeviceResponseEnum.MODEL_NAME_REPEAT,"或终端编号已存在");
if (count > 0) {
throw new BusinessException(PmsDeviceResponseEnum.MODEL_NAME_REPEAT, "或终端编号已存在");
}
PmsTerminalDetection detection = BeanUtil.copyProperties(param, PmsTerminalDetection.class);
detection.setOriginalName(detection.getId()+"-原始数据报告.docx");
detection.setOriginalName(detection.getId() + "-原始数据报告.docx");
detection.setOrgNo(data.getCode());
detection.setOrgName(data.getName());
detection.setTestResults(0);
@@ -176,12 +171,12 @@ public class PmsTerminalDetectionServiceImpl extends ServiceImpl<PmsTerminalDete
}
PmsTerminalDetection detection = BeanUtil.copyProperties(param, PmsTerminalDetection.class);
boolean b = this.updateById(detection);
if(b){
if (b) {
PmsTerminalDetection cc = this.getOne(new LambdaQueryWrapper<PmsTerminalDetection>()
.eq(PmsTerminalDetection::getId, param.getId())
);
if(StrUtil.isNotBlank(cc.getOriginalReport())){
if(!cc.getOriginalReport().equals(param.getOriginalReport())){
if (StrUtil.isNotBlank(cc.getOriginalReport())) {
if (!cc.getOriginalReport().equals(param.getOriginalReport())) {
fileStorageUtil.deleteFile(cc.getOriginalReport());
}
@@ -207,6 +202,19 @@ public class PmsTerminalDetectionServiceImpl extends ServiceImpl<PmsTerminalDete
//上传的文件名称
String originalFilename = files[i].getOriginalFilename();
if (StrUtil.isNotBlank(originalFilename)) {
if(type==0){
//判断文件名称是否正确
boolean matches = Pattern.matches("^[A-Za-z0-9\\u4e00-\\u9fa5]*-原始数据报告.docx$",originalFilename );
if(!matches){
continue;
}
}else{
String time="[(]((([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29))[)]";
boolean matches1 = Pattern.matches("^[A-Za-z0-9\\u4e00-\\u9fa5]*-检测报告"+time+"$", originalFilename);
if(!matches1){
continue;
}
}
//获取编号
String terminalIds = originalFilename.substring(0, originalFilename.indexOf("-"));
//判断数据是否存在
@@ -230,9 +238,7 @@ public class PmsTerminalDetectionServiceImpl extends ServiceImpl<PmsTerminalDete
} else {
//传入的文件格式(终端编号-检测报告(2023-03-01).docx);
if (fileName.substring(0, fileName.indexOf("(")).equals("检测报告")) {
String nextInspectionTime = fileName.substring(fileName.indexOf("(") + 1, fileName.indexOf(")"));
boolean matches = Pattern.matches(PatternRegex.TIME_FORMAT, nextInspectionTime);
if (matches) {
String nextInspectionTime = fileName.substring( fileName.indexOf("(") + 1, fileName.indexOf(")"));
//文件上传的地址
String path = fileStorageUtil.uploadMultipart(files[i], OssPath.TEST_REPORT);
detection.setInspectionReport(path);
@@ -242,7 +248,6 @@ public class PmsTerminalDetectionServiceImpl extends ServiceImpl<PmsTerminalDete
data.add(detection);
}
}
}
}
}
@@ -269,11 +274,11 @@ public class PmsTerminalDetectionServiceImpl extends ServiceImpl<PmsTerminalDete
for (PmsTerminalDetection terminal : terminals) {
//用于区分是0:原始数据报告还是1:检测报告
if (type == 0) {
if(StrUtil.isNotBlank(terminal.getOriginalReport())){
if (StrUtil.isNotBlank(terminal.getOriginalReport())) {
remove.add(terminal.getOriginalReport());
}
} else {
if(StrUtil.isNotBlank(terminal.getInspectionReport())){
if (StrUtil.isNotBlank(terminal.getInspectionReport())) {
remove.add(terminal.getInspectionReport());
}
}
@@ -298,21 +303,20 @@ public class PmsTerminalDetectionServiceImpl extends ServiceImpl<PmsTerminalDete
if (StrUtil.isBlank(terminal.getInspectionReport())) {
throw new BusinessException(OssResponseEnum.DOWNLOAD_FILE_ERROR, "下载检测报告文件URL不存在请检查数据");
}
String fileUrl = fileStorageUtil.getFileUrl(terminal.getInspectionReport());
URL url = new URL(fileUrl);
return new InputStreamResource(url.openStream());
InputStream fileStream = fileStorageUtil.getFileStream(terminal.getOriginalReport());
return new InputStreamResource(fileStream);
}
if (StrUtil.isBlank(terminal.getOriginalReport())) {
throw new BusinessException(OssResponseEnum.DOWNLOAD_FILE_ERROR, "下载原始数据报告文件URL不存在请检查数据");
}
String fileUrl = fileStorageUtil.getFileUrl(terminal.getOriginalReport());
URL url = new URL(fileUrl);
return new InputStreamResource(url.openStream());
InputStream fileStream = fileStorageUtil.getFileStream(terminal.getOriginalReport());
return new InputStreamResource(fileStream);
}
@Override
public TerminalVO.TerminalStatistics getStatistics(TerminalParam param) {
TerminalVO.TerminalStatistics statistics=new TerminalVO.TerminalStatistics();
TerminalVO.TerminalStatistics statistics = new TerminalVO.TerminalStatistics();
List<Dept> deptDTOS = deptFeignClient.getDirectSonSelf(param.getId()).getData();
List<String> ids = deptDTOS.stream().map(Dept::getCode).collect(Collectors.toList());
List<TerminalVO.OrgStatistics> list = this.baseMapper.selectStatistics(param, ids);
@@ -323,7 +327,7 @@ public class PmsTerminalDetectionServiceImpl extends ServiceImpl<PmsTerminalDete
@Override
public TerminalVO.TerminalStatistics getCycleStatistics(TerminalParam param) {
TerminalVO.TerminalStatistics statistics=new TerminalVO.TerminalStatistics();
TerminalVO.TerminalStatistics statistics = new TerminalVO.TerminalStatistics();
List<Dept> deptDTOS = deptFeignClient.getDirectSonSelf(param.getId()).getData();
List<String> ids = deptDTOS.stream().map(Dept::getCode).collect(Collectors.toList());
List<TerminalVO.OrgStatistics> list = this.baseMapper.selectCycleStatistics(param, ids);
@@ -409,11 +413,11 @@ public class PmsTerminalDetectionServiceImpl extends ServiceImpl<PmsTerminalDete
addMsg(terminalExcelMsg, terminalExcel, msg, "当前部门机构模糊匹配出现多个部门,请详细编写部门机构");
continue;
}
if(!manufacturerMap.containsKey(terminalExcel.getManufacture())){
if (!manufacturerMap.containsKey(terminalExcel.getManufacture())) {
addMsg(terminalExcelMsg, terminalExcel, msg, "当前生产厂商名称不存在,请检查生产厂商名称");
continue;
}else{
terminalExcel.setManufacture( manufacturerMap.get(terminalExcel.getManufacture()));
} else {
terminalExcel.setManufacture(manufacturerMap.get(terminalExcel.getManufacture()));
}
detection = BeanUtil.copyProperties(terminalExcel, PmsTerminalDetection.class);