diff --git a/pom.xml b/pom.xml index c18b21e..26543b9 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,27 @@ + + + + + + + com.itextpdf + layout + 7.1.16 + + + com.itextpdf + itextpdf + 5.5.12 + + + com.itextpdf + forms + 7.1.16 + + com.squareup.okhttp3 okhttp diff --git a/src/main/java/com/bonus/aqgqj/app/controller/ExperimentalAppController.java b/src/main/java/com/bonus/aqgqj/app/controller/ExperimentalAppController.java index 2d2b98a..085b277 100644 --- a/src/main/java/com/bonus/aqgqj/app/controller/ExperimentalAppController.java +++ b/src/main/java/com/bonus/aqgqj/app/controller/ExperimentalAppController.java @@ -107,13 +107,13 @@ public class ExperimentalAppController { * 试验数据详情 */ @PostMapping(value = "viewTestData") - @DecryptAndVerify(decryptedClass = ParamsAppDto.class)//加解密统一管理 + @DecryptAndVerify(decryptedClass = ParamsAppDto.class) public ServerResponse viewTestData(EncryptedReq data) { return service.viewTestData(data.getData()); } @PostMapping(value = "commitCheckTestData") - @DecryptAndVerify(decryptedClass = ParamsAppDto.class)//加解密统一管理 + @DecryptAndVerify(decryptedClass = ParamsAppDto.class) @LogAnnotation(operModul = "试验管理", operation = "提交审查数据", operDesc = "业务级事件", operType = "提交审查") // @PreAuthorize("@pms.hasPermission('sys:experimentalTest:commitCheck')") public ServerResponse commitCheckTestData(EncryptedReq data) { diff --git a/src/main/java/com/bonus/aqgqj/app/controller/PrimaryDataAppController.java b/src/main/java/com/bonus/aqgqj/app/controller/PrimaryDataAppController.java index 7b8fee2..835b520 100644 --- a/src/main/java/com/bonus/aqgqj/app/controller/PrimaryDataAppController.java +++ b/src/main/java/com/bonus/aqgqj/app/controller/PrimaryDataAppController.java @@ -6,17 +6,15 @@ import com.bonus.aqgqj.annotation.DecryptAndVerify; import com.bonus.aqgqj.annotation.LogAnnotation; import com.bonus.aqgqj.app.entity.ExperimentalAppVo; import com.bonus.aqgqj.app.entity.ExperimentalDetailAppVo; -import com.bonus.aqgqj.app.entity.SamplesManageAppVo; import com.bonus.aqgqj.app.entity.dto.ParamsAppDto; import com.bonus.aqgqj.app.service.PrimaryDataAppService; import com.bonus.aqgqj.basis.entity.dto.ParamsDto; import com.bonus.aqgqj.basis.entity.vo.*; -import com.bonus.aqgqj.primaryData.dao.PrimaryDataDao; -import com.bonus.aqgqj.primaryData.service.PrimaryDataService; import com.bonus.aqgqj.system.vo.EncryptedReq; import com.bonus.aqgqj.utils.ExcelStyleUtil; import com.bonus.aqgqj.utils.FileUtil; import com.bonus.aqgqj.utils.ServerResponse; +import com.bonus.aqgqj.utils.SystemUtils; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import io.swagger.annotations.Api; @@ -32,19 +30,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.*; -import java.nio.file.Files; -import java.nio.file.Paths; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Base64; @@ -65,8 +57,6 @@ public class PrimaryDataAppController { private static final Logger log = LoggerFactory.getLogger("adminLogger"); - @Value("${file.windwos.upload_path}") - private String uploadPath; @Autowired private PrimaryDataAppService primaryDataAppService; @@ -164,8 +154,6 @@ public class PrimaryDataAppController { return ServerResponse.createErroe("查看失败"); } } - - /** * 批量下载原始记录压缩文件 * @@ -178,12 +166,13 @@ public class PrimaryDataAppController { */ @PostMapping(value = "downLoadExcelZip") @DecryptAndVerify(decryptedClass = ParamsDto.class) - public void downLoadExcelZip(HttpServletRequest request, HttpServletResponse response, EncryptedReq dto) { + public ServerResponse downLoadExcelZip(HttpServletRequest request, HttpServletResponse response, EncryptedReq dto) { List fileList = new ArrayList(); List fileNameList = new ArrayList(); + String fileNames="检测原始记录_" + System.currentTimeMillis()+".zip"; + String outputZipFilePath = SystemUtils.getUploadPath()+ fileNames; try { Long[] ids = dto.getData().getIds(); - ParamsDto paramsDto = new ParamsDto(); if (ids != null && ids.length > 0) { for (int h = 0; h < ids.length; h++) { String excelModelPath = createExcelModel(ids[h]); @@ -192,8 +181,10 @@ public class PrimaryDataAppController { fileNameList.add(excelModelPath); } } - downloadZip(response, fileList); +// downloadZip(response, fileList); + zipFiles(fileList, outputZipFilePath); } + return ServerResponse.createSuccess("statics/"+fileNames); } catch (Exception e) { log.error("zip导出错误-异常信息", e); } finally { @@ -203,6 +194,7 @@ public class PrimaryDataAppController { } } } + return ServerResponse.createErroe("下载失败"); } public String createExcelModel(Long experId) { @@ -246,7 +238,7 @@ public class PrimaryDataAppController { } sheet = handleNineRow(vo, sheet, commonStyle2, rowNum++, hbNum); sheet = handleTenRow(vo, sheet, commonStyle, rowNum++, hbNum); - String fileName = uploadPath + vo.getDevTypeName() + "检测原始记录_" + System.currentTimeMillis() + ".xlsx"; + String fileName = SystemUtils.getUploadPath() + vo.getDevTypeName() + "检测原始记录_" + System.currentTimeMillis() + ".xlsx"; File file = new File(fileName); //生成文件夹 if (!file.getParentFile().exists()) { @@ -265,6 +257,7 @@ public class PrimaryDataAppController { // 设置响应头信息,‌指定下载的文件名为"files.zip" response.setContentType("application/zip"); response.setHeader("Content-Disposition", "attachment; filename=files.zip"); + response.setHeader("code","200"); try (ZipOutputStream zos = new ZipOutputStream(response.getOutputStream())) { for (File file : filesToZip) { try (FileInputStream fis = new FileInputStream(file)) { @@ -282,6 +275,30 @@ public class PrimaryDataAppController { } } + public void zipFiles(List filesToZip, String outputZipFilePath) throws IOException { + File outputFile = new File(outputZipFilePath); + try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(outputFile))) { + for (File file : filesToZip) { + try (FileInputStream fis = new FileInputStream(file)) { + ZipEntry zipEntry = new ZipEntry(file.getName()); + zos.putNextEntry(zipEntry); + + byte[] buffer = new byte[1024]; + int len; + while ((len = fis.read(buffer)) > 0) { + zos.write(buffer, 0, len); + } + } + } + zos.closeEntry(); + } catch (IOException e) { + // 处理异常,例如记录日志 + e.printStackTrace(); + } + // 可以在这里添加额外的逻辑,比如检查文件是否成功创建 + System.out.println("ZIP文件已保存到: " + outputFile.getAbsolutePath()); + } + /** * 第一行表头 diff --git a/src/main/java/com/bonus/aqgqj/app/controller/TestReportManageAppController.java b/src/main/java/com/bonus/aqgqj/app/controller/TestReportManageAppController.java index 3714ee5..8a343b7 100644 --- a/src/main/java/com/bonus/aqgqj/app/controller/TestReportManageAppController.java +++ b/src/main/java/com/bonus/aqgqj/app/controller/TestReportManageAppController.java @@ -263,10 +263,10 @@ public class TestReportManageAppController { */ @PostMapping(value = "downLoadExcelZip") @DecryptAndVerify(decryptedClass = TestReportManageAppVo.class) - public void downLoadExcelZip(HttpServletRequest request, HttpServletResponse response, EncryptedReq dto) { + public ServerResponse downLoadExcelZip(HttpServletRequest request, HttpServletResponse response, EncryptedReq dto) { List fileNameList = new ArrayList(); try { - service.downLoadExcelZip(response, dto.getData(),fileNameList); + return service.downLoadExcelZip(response, dto.getData(),fileNameList); } catch (Exception e) { log.error("zip导出错误-异常信息", e); } finally { @@ -276,6 +276,7 @@ public class TestReportManageAppController { } } } + return ServerResponse.createErroe("下载失败"); } diff --git a/src/main/java/com/bonus/aqgqj/app/dao/CertificateAppDao.java b/src/main/java/com/bonus/aqgqj/app/dao/CertificateAppDao.java index c2ed5b9..7b8908e 100644 --- a/src/main/java/com/bonus/aqgqj/app/dao/CertificateAppDao.java +++ b/src/main/java/com/bonus/aqgqj/app/dao/CertificateAppDao.java @@ -122,6 +122,7 @@ public interface CertificateAppDao { /** * 根据设备编码查询设备数量 * @param devCode + * @param sampleTools * @return */ int getCountByDevCode(String devCode,String sampleTools); diff --git a/src/main/java/com/bonus/aqgqj/app/dao/ExperimentalAppMapper.java b/src/main/java/com/bonus/aqgqj/app/dao/ExperimentalAppMapper.java index 4591eb4..95b6df5 100644 --- a/src/main/java/com/bonus/aqgqj/app/dao/ExperimentalAppMapper.java +++ b/src/main/java/com/bonus/aqgqj/app/dao/ExperimentalAppMapper.java @@ -134,6 +134,7 @@ public interface ExperimentalAppMapper { * 添加试验项内容 * * @param configItemVo + * @param experId * @return void * @author cwchen * @date 2024/7/21 17:28 @@ -361,17 +362,16 @@ public interface ExperimentalAppMapper { // * @date 2024/7/22 0:36 // */ // void delExperItem(List experItemsIds); -// -// /** -// * 查询试验设备数量 -// * -// * @param experId -// * @return List -// * @author cwchen -// * @date 2024/7/22 10:58 -// */ -// @MapKey("id") -// List> getExperDevItemsNum(Long experId); + + /** + * 查询试验设备数量 + * + * @param experId + * @return List + * @author cwchen + * @date 2024/7/22 10:58 + */ + List getExperDevItemsNum(Long experId); /** * 判断是否处于审核流程中的数据 diff --git a/src/main/java/com/bonus/aqgqj/app/dao/PrimaryDataAppDao.java b/src/main/java/com/bonus/aqgqj/app/dao/PrimaryDataAppDao.java index 03ec03c..c9781f4 100644 --- a/src/main/java/com/bonus/aqgqj/app/dao/PrimaryDataAppDao.java +++ b/src/main/java/com/bonus/aqgqj/app/dao/PrimaryDataAppDao.java @@ -44,8 +44,7 @@ public interface PrimaryDataAppDao { * @author cwchen * @date 2024/7/22 10:58 */ - @MapKey("id") - List> getExperDevItemsNum(Long experId); + List getExperDevItemsNum(Long experId); /** * 试验数据详情 diff --git a/src/main/java/com/bonus/aqgqj/app/dao/SamplesManageAppDao.java b/src/main/java/com/bonus/aqgqj/app/dao/SamplesManageAppDao.java index 747e14b..663f3c7 100644 --- a/src/main/java/com/bonus/aqgqj/app/dao/SamplesManageAppDao.java +++ b/src/main/java/com/bonus/aqgqj/app/dao/SamplesManageAppDao.java @@ -129,6 +129,7 @@ public interface SamplesManageAppDao { /** * 根据设备编码查询设备数量 * @param devCode + * @param sampleTools * @return */ int getCountByDevCode(String devCode,String sampleTools); diff --git a/src/main/java/com/bonus/aqgqj/app/entity/ExperimentalDetailAppVo.java b/src/main/java/com/bonus/aqgqj/app/entity/ExperimentalDetailAppVo.java index c743c27..845affd 100644 --- a/src/main/java/com/bonus/aqgqj/app/entity/ExperimentalDetailAppVo.java +++ b/src/main/java/com/bonus/aqgqj/app/entity/ExperimentalDetailAppVo.java @@ -95,6 +95,11 @@ public class ExperimentalDetailAppVo { */ private String remarks; + /** + * 是否合格 + */ + private Integer isHg; + /** * 样品 */ diff --git a/src/main/java/com/bonus/aqgqj/app/service/TestReportManageAppService.java b/src/main/java/com/bonus/aqgqj/app/service/TestReportManageAppService.java index 0bc433f..78b8d77 100644 --- a/src/main/java/com/bonus/aqgqj/app/service/TestReportManageAppService.java +++ b/src/main/java/com/bonus/aqgqj/app/service/TestReportManageAppService.java @@ -82,7 +82,8 @@ public interface TestReportManageAppService { * 检测报告下载 * @param data * @param response + * @param fileNameList * @return */ - void downLoadExcelZip(HttpServletResponse response, TestReportManageAppVo data, List fileNameList); + ServerResponse downLoadExcelZip(HttpServletResponse response, TestReportManageAppVo data, List fileNameList); } diff --git a/src/main/java/com/bonus/aqgqj/app/service/impl/ExperimentalAppServiceImpl.java b/src/main/java/com/bonus/aqgqj/app/service/impl/ExperimentalAppServiceImpl.java index 6d3b2a0..14b90bb 100644 --- a/src/main/java/com/bonus/aqgqj/app/service/impl/ExperimentalAppServiceImpl.java +++ b/src/main/java/com/bonus/aqgqj/app/service/impl/ExperimentalAppServiceImpl.java @@ -67,6 +67,20 @@ public class ExperimentalAppServiceImpl implements ExperimentalAppService { List list = new ArrayList<>(); try { list = mapper.getDetailList(dto); + for (ExperimentalDetailAppVo experimentalDetailAppVo : list){ + Integer isHg=0; + if (experimentalDetailAppVo.getExperId()!=null){ + //查询个试验设备是否合格 + List mapList = mapper.getExperDevItemsNum(experimentalDetailAppVo.getExperId()); + for (String s : mapList){ + if ("不合格".equals(s)){ + isHg=1; + break; + } + } + } + experimentalDetailAppVo.setIsHg(isHg); + } } catch (Exception e) { log.error(e.toString(), e); } diff --git a/src/main/java/com/bonus/aqgqj/app/service/impl/PrimaryDataAppServiceImpl.java b/src/main/java/com/bonus/aqgqj/app/service/impl/PrimaryDataAppServiceImpl.java index 271eec9..cf817da 100644 --- a/src/main/java/com/bonus/aqgqj/app/service/impl/PrimaryDataAppServiceImpl.java +++ b/src/main/java/com/bonus/aqgqj/app/service/impl/PrimaryDataAppServiceImpl.java @@ -57,16 +57,17 @@ public class PrimaryDataAppServiceImpl implements PrimaryDataAppService { list = primaryDataAppDao.getDetailList(dto); if (CollectionUtils.isNotEmpty(list)) { for (ExperimentalDetailAppVo detailVo : list) { - // 样品试验结果、样品数量、送样总数 - List sampleList = new ArrayList<>(); - if (detailVo.getExperId() != null) { - List> mapList = primaryDataAppDao.getExperDevItemsNum(detailVo.getExperId()); - JSONArray jsonArray = new JSONArray(); - jsonArray.addAll(mapList); - sampleList = jsonArray.toJavaList(ExperimentalDetailAppVo.Sample.class); + Integer isHg=0; + if (detailVo.getExperId()!=null){ + List mapList = primaryDataAppDao.getExperDevItemsNum(detailVo.getExperId()); + for (String s : mapList){ + if ("不合格".equals(s)){ + isHg=1; + break; + } + } } - detailVo.setSampleList(sampleList); - detailVo.setSampleQuantity(sampleList.size()); + detailVo.setIsHg(isHg); } } } catch (Exception e) { diff --git a/src/main/java/com/bonus/aqgqj/app/service/impl/TestReportManageAppServiceImpl.java b/src/main/java/com/bonus/aqgqj/app/service/impl/TestReportManageAppServiceImpl.java index b017561..48df088 100644 --- a/src/main/java/com/bonus/aqgqj/app/service/impl/TestReportManageAppServiceImpl.java +++ b/src/main/java/com/bonus/aqgqj/app/service/impl/TestReportManageAppServiceImpl.java @@ -9,10 +9,7 @@ import com.bonus.aqgqj.app.entity.TestReportManageAppVo; import com.bonus.aqgqj.app.service.TestReportManageAppService; import com.bonus.aqgqj.basis.entity.vo.*; import com.bonus.aqgqj.basis.service.TestReportManageService; -import com.bonus.aqgqj.utils.DateTimeHelper; -import com.bonus.aqgqj.utils.ListHelper; -import com.bonus.aqgqj.utils.ServerResponse; -import com.bonus.aqgqj.utils.StringHelper; +import com.bonus.aqgqj.utils.*; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.poi.ss.usermodel.*; @@ -46,9 +43,6 @@ import java.util.zip.ZipOutputStream; @Service public class TestReportManageAppServiceImpl implements TestReportManageAppService { - @Value("${file.windwos.upload_path}") - private String uploadPath; - @Resource private TestReportManageAppDao testReportManageAppDao; @@ -231,10 +225,12 @@ public class TestReportManageAppServiceImpl implements TestReportManageAppServic } @Override - public void downLoadExcelZip(HttpServletResponse response, TestReportManageAppVo data,List fileNameList) { + public ServerResponse downLoadExcelZip(HttpServletResponse response, TestReportManageAppVo data,List fileNameList) { List fileList = new ArrayList(); JSONArray jsonArray = JSONObject.parseArray(data.getParamsList()); List list = jsonArray.toJavaList(TestReportManageAppVo.class); + String fileNames="检测报告_" + System.currentTimeMillis()+".zip"; + String outputZipFilePath = SystemUtils.getUploadPath()+ fileNames; if (list != null && list.size() > 0) { try { for (TestReportManageAppVo testReportManageAppVo : list) { @@ -251,11 +247,14 @@ public class TestReportManageAppServiceImpl implements TestReportManageAppServic } } } - downloadZip(response, fileList); +// downloadZip(response, fileList); + zipFiles(fileList, outputZipFilePath); + return ServerResponse.createSuccess("statics/"+fileNames); }catch (Exception e){ log.error("zip导出错误-异常信息", e); } } + return ServerResponse.createErroe("下载失败"); } /** @@ -442,7 +441,8 @@ public class TestReportManageAppServiceImpl implements TestReportManageAppServic AtomicInteger row = new AtomicInteger(5); AtomicInteger cellNum = new AtomicInteger(0); - AtomicInteger serialNumber = new AtomicInteger(1); // 用于追踪序号 + // 用于追踪序号 + AtomicInteger serialNumber = new AtomicInteger(1); if (ListHelper.isNotEmpty(devList)) { devList.forEach(dev -> { @@ -497,7 +497,6 @@ public class TestReportManageAppServiceImpl implements TestReportManageAppServic }); }); } - // row.set(row.get() + 1); Row row8= sheet.createRow(row.get()); Cell cell81 = row8.createCell(0); @@ -570,7 +569,7 @@ public class TestReportManageAppServiceImpl implements TestReportManageAppServic if (type==1){ - String fileName = uploadPath + "检测报告_" + bean.getReportCode() + "_"+DateTimeHelper.getNowDMS()+".xlsx"; + String fileName =SystemUtils.getUploadPath() + "检测报告_" + bean.getReportCode() + "_"+DateTimeHelper.getNowDMS()+".xlsx"; File file = new File(fileName); //生成文件夹 if (!file.getParentFile().exists()) { @@ -715,4 +714,29 @@ public class TestReportManageAppServiceImpl implements TestReportManageAppServic } } + + public void zipFiles(List filesToZip, String outputZipFilePath) throws IOException { + File outputFile = new File(outputZipFilePath); + try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(outputFile))) { + for (File file : filesToZip) { + try (FileInputStream fis = new FileInputStream(file)) { + ZipEntry zipEntry = new ZipEntry(file.getName()); + zos.putNextEntry(zipEntry); + + byte[] buffer = new byte[1024]; + int len; + while ((len = fis.read(buffer)) > 0) { + zos.write(buffer, 0, len); + } + } + } + zos.closeEntry(); + } catch (IOException e) { + // 处理异常,例如记录日志 + e.printStackTrace(); + } + // 可以在这里添加额外的逻辑,比如检查文件是否成功创建 + System.out.println("ZIP文件已保存到: " + outputFile.getAbsolutePath()); + } + } diff --git a/src/main/java/com/bonus/aqgqj/utils/SystemUtils.java b/src/main/java/com/bonus/aqgqj/utils/SystemUtils.java index b52ef94..fd3ea25 100644 --- a/src/main/java/com/bonus/aqgqj/utils/SystemUtils.java +++ b/src/main/java/com/bonus/aqgqj/utils/SystemUtils.java @@ -63,9 +63,9 @@ public class SystemUtils { public static String getUploadPath() { String os = getSystem(); System.err.println("当前系统是=" + os); - if (os.equals("windows")) { + if ("windows".equals(os)) { return windowsPath; - } else if (os.equals("linux")) { + } else if ("linux".equals(os)) { return linuxPath; } else { return windowsPath; diff --git a/src/main/resources/mappers/app/ExperimentalAppMapper.xml b/src/main/resources/mappers/app/ExperimentalAppMapper.xml index e8a2b1b..1471a80 100644 --- a/src/main/resources/mappers/app/ExperimentalAppMapper.xml +++ b/src/main/resources/mappers/app/ExperimentalAppMapper.xml @@ -525,9 +525,8 @@ SELECT id FROM tb_exper_items WHERE exper_id = #{id} - + SELECT case is_hg WHEN '1' THEN '不合格' WHEN '0' THEN '合格' ELSE '不合格' END AS testResult FROM tb_exper_dev diff --git a/src/main/resources/mappers/app/PrimaryDataAppMapper.xml b/src/main/resources/mappers/app/PrimaryDataAppMapper.xml index 233bb5e..c0553f1 100644 --- a/src/main/resources/mappers/app/PrimaryDataAppMapper.xml +++ b/src/main/resources/mappers/app/PrimaryDataAppMapper.xml @@ -71,9 +71,8 @@ - + SELECT case is_hg WHEN '1' THEN '不合格' WHEN '0' THEN '合格' ELSE '不合格' END AS testResult FROM tb_exper_dev diff --git a/src/main/resources/mappers/system/UserMapper.xml b/src/main/resources/mappers/system/UserMapper.xml index 44c76f4..4a09af1 100644 --- a/src/main/resources/mappers/system/UserMapper.xml +++ b/src/main/resources/mappers/system/UserMapper.xml @@ -66,11 +66,12 @@