From 1e6c1143da3ad453a6ab28458034d7e0e07a7da5 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Thu, 17 Mar 2022 14:07:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BAExcel=E8=A1=A8=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/controller/QcSourceController.java | 2 +- src/main/java/com/xkrs/dao/QcSourceDao.java | 5 +- src/main/java/com/xkrs/dao/QcSpecDao.java | 8 +- .../xkrs/service/impl/FileServiceImpl.java | 93 +++++++++---------- .../service/impl/QcSourceServiceImpl.java | 29 ++++-- .../xkrs/service/impl/QcSpecServiceImpl.java | 10 +- 6 files changed, 88 insertions(+), 59 deletions(-) diff --git a/src/main/java/com/xkrs/controller/QcSourceController.java b/src/main/java/com/xkrs/controller/QcSourceController.java index 44e24da..62407b5 100644 --- a/src/main/java/com/xkrs/controller/QcSourceController.java +++ b/src/main/java/com/xkrs/controller/QcSourceController.java @@ -42,7 +42,7 @@ public class QcSourceController { /** * 导出Excel表格 */ - @GetMapping("/exportExcel") + @PostMapping("/exportExcel") public String exportExcel(@RequestBody ExportExcelQo exportExcelQo) throws Exception { return qcSourceService.exportExcel(exportExcelQo); } diff --git a/src/main/java/com/xkrs/dao/QcSourceDao.java b/src/main/java/com/xkrs/dao/QcSourceDao.java index 6d5d7eb..ce16aef 100644 --- a/src/main/java/com/xkrs/dao/QcSourceDao.java +++ b/src/main/java/com/xkrs/dao/QcSourceDao.java @@ -15,7 +15,10 @@ import java.util.Map; @Component public interface QcSourceDao extends JpaRepository, JpaSpecificationExecutor { - @Query(value = "SELECT id, batch_no AS batchNo, machine_no AS machineNo, material_no AS materialNo, mould_no AS mouldNo, variety_no AS varietyNo, craft_item_no AS craftItemNo, qc_item_no AS qcItemNo, qc_value AS qcValue FROM qc_source WHERE batch_no LIKE %?1% AND machine_no LIKE %?2% AND material_no LIKE %?3% AND mould_no LIKE %?4% AND variety_no LIKE %?5% AND craft_item_no LIKE %?6% ORDER BY create_time DESC", nativeQuery = true) + @Query(value = "SELECT id, batch_no AS batchNo, machine_no AS machineNo, material_no AS materialNo, mould_no AS mouldNo, variety_no AS varietyNo, craft_item_no AS craftItemNo, qc_item_no AS qcItemNo, qc_value AS qcValue FROM qc_source WHERE batch_no LIKE %?1% AND machine_no LIKE %?2% AND material_no LIKE %?3% AND mould_no LIKE %?4% AND variety_no LIKE %?5% ORDER BY create_time DESC", nativeQuery = true) + List> queryQcSource(String batchNo, String machineNo, String materialNo, String mouldNo, String varietyNo); + + @Query(value = "SELECT id, batch_no AS batchNo, machine_no AS machineNo, material_no AS materialNo, mould_no AS mouldNo, variety_no AS varietyNo, craft_item_no AS craftItemNo, qc_item_no AS qcItemNo, qc_value AS qcValue FROM qc_source WHERE batch_no LIKE %?1% AND machine_no LIKE %?2% AND material_no LIKE %?3% AND mould_no LIKE %?4% AND variety_no LIKE %?5% AND craft_item_no = ?6 ORDER BY create_time DESC", nativeQuery = true) List> queryQcSource(String batchNo, String machineNo, String materialNo, String mouldNo, String varietyNo, String craftItemNo); } \ No newline at end of file diff --git a/src/main/java/com/xkrs/dao/QcSpecDao.java b/src/main/java/com/xkrs/dao/QcSpecDao.java index 93a7f19..a2bf312 100644 --- a/src/main/java/com/xkrs/dao/QcSpecDao.java +++ b/src/main/java/com/xkrs/dao/QcSpecDao.java @@ -27,6 +27,12 @@ public interface QcSpecDao extends JpaRepository, JpaSpec /** * 查询检验规格 */ - @Query(value = "SELECT id, variety_no AS varietyNo, craft_item_no AS craftItemNo, qc_item_no AS qcItemNo, max, mean, min, unit, method, standard, remark FROM qc_spec WHERE variety_no LIKE %?1% AND craft_item_no LIKE %?2% AND qc_item_no LIKE %?3% ORDER BY create_time ASC", nativeQuery = true) + @Query(value = "SELECT id, variety_no AS varietyNo, craft_item_no AS craftItemNo, qc_item_no AS qcItemNo, max, mean, min, unit, method, standard, remark FROM qc_spec WHERE variety_no LIKE %?1% AND qc_item_no LIKE %?2% ORDER BY create_time ASC", nativeQuery = true) + List> queryQcSpec(String varietyNo, String qcItemNo); + + /** + * 查询检验规格 + */ + @Query(value = "SELECT id, variety_no AS varietyNo, craft_item_no AS craftItemNo, qc_item_no AS qcItemNo, max, mean, min, unit, method, standard, remark FROM qc_spec WHERE variety_no LIKE %?1% AND craft_item_no = ?2 AND qc_item_no LIKE %?3% ORDER BY create_time ASC", nativeQuery = true) List> queryQcSpec(String varietyNo, String craftItemNo, String qcItemNo); } \ No newline at end of file diff --git a/src/main/java/com/xkrs/service/impl/FileServiceImpl.java b/src/main/java/com/xkrs/service/impl/FileServiceImpl.java index 250715d..5532701 100644 --- a/src/main/java/com/xkrs/service/impl/FileServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FileServiceImpl.java @@ -3,11 +3,8 @@ package com.xkrs.service.impl; import com.xkrs.dao.FileDao; import com.xkrs.dao.QcSourceDao; import com.xkrs.encapsulation.PromptMessageEnum; -import com.xkrs.model.entity.FileEntity; import com.xkrs.model.qo.FileQo; import com.xkrs.service.FileService; -import com.xkrs.util.ExcelUploadUtil; -import com.xkrs.util.ExportExcel; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; @@ -16,7 +13,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.transaction.Transactional; import java.io.IOException; -import java.util.*; +import java.util.Locale; import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject; @@ -41,29 +38,29 @@ public class FileServiceImpl implements FileService { */ @Override public String insertFileExcel(FileQo fileQo, MultipartFile fileExcel) throws IOException { - String lotNo = fileQo.getLotNo(); - String machineNo = fileQo.getMachineNo(); - String materialNo = fileQo.getMaterialNo(); - String modelNo = fileQo.getModelNo(); - String machineTypeNo = fileQo.getMachineTypeNo(); - String craftItemName = fileQo.getCraftItemName(); +// String lotNo = fileQo.getLotNo(); +// String machineNo = fileQo.getMachineNo(); +// String materialNo = fileQo.getMaterialNo(); +// String modelNo = fileQo.getModelNo(); +// String machineTypeNo = fileQo.getMachineTypeNo(); +// String craftItemName = fileQo.getCraftItemName(); Locale locale = LocaleContextHolder.getLocale(); - Optional fileEntity = fileDao.selectFile(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName); - if (fileEntity.isPresent()) { - return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "已存在该产品的模板!", locale); - } - if (fileExcel == null) { - return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "模板不能为空!", locale); - } - String file = ExcelUploadUtil.memoryFile(fileExcel, 1); - FileEntity fileEntity1 = new FileEntity(); - fileEntity1.setLotNo(fileQo.getLotNo()); - fileEntity1.setMachineNo(fileQo.getMachineNo()); - fileEntity1.setMaterialNo(fileQo.getMaterialNo()); - fileEntity1.setModelNo(fileQo.getModelNo()); - fileEntity1.setMachineTypeNo(fileQo.getMachineTypeNo()); - fileEntity1.setFileUploadPath(file); - fileDao.save(fileEntity1); +// Optional fileEntity = fileDao.selectFile(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName); +// if (fileEntity.isPresent()) { +// return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "已存在该产品的模板!", locale); +// } +// if (fileExcel == null) { +// return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "模板不能为空!", locale); +// } +// String file = ExcelUploadUtil.memoryFile(fileExcel, 1); +// FileEntity fileEntity1 = new FileEntity(); +// fileEntity1.setLotNo(fileQo.getLotNo()); +// fileEntity1.setMachineNo(fileQo.getMachineNo()); +// fileEntity1.setMaterialNo(fileQo.getMaterialNo()); +// fileEntity1.setModelNo(fileQo.getModelNo()); +// fileEntity1.setMachineTypeNo(fileQo.getMachineTypeNo()); +// fileEntity1.setFileUploadPath(file); +// fileDao.save(fileEntity1); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale); } @@ -76,28 +73,28 @@ public class FileServiceImpl implements FileService { @Transactional(rollbackOn = Exception.class) @Override public String exportExcel(FileQo fileQo) throws IOException, InvalidFormatException { - String lotNo = fileQo.getLotNo(); - String machineNo = fileQo.getMachineNo(); - String materialNo = fileQo.getMaterialNo(); - String modelNo = fileQo.getModelNo(); - String machineTypeNo = fileQo.getMachineTypeNo(); - String craftItemName = fileQo.getCraftItemName(); +// String lotNo = fileQo.getLotNo(); +// String machineNo = fileQo.getMachineNo(); +// String materialNo = fileQo.getMaterialNo(); +// String modelNo = fileQo.getModelNo(); +// String machineTypeNo = fileQo.getMachineTypeNo(); +// String craftItemName = fileQo.getCraftItemName(); Locale locale = LocaleContextHolder.getLocale(); - Optional fileEntity = fileDao.selectFile(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName); - if (fileEntity.isEmpty()) { - return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的模板,请添加!", locale); - } - String fileUploadPath = fileEntity.get().getFileUploadPath(); - List> resultList = qcSourceDao.queryQcSource(lotNo, machineNo, materialNo, modelNo, machineTypeNo, ""); - if (resultList == null || resultList.size() == 0) { - return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的信息!", locale); - } - Map map = new HashMap<>(); - for (Map result : resultList) { - map.put((String) result.get("qcItemNo"), (String) result.get("qcValue")); - } - String fill = ExportExcel.exportToProveExcel(map, fileUploadPath); - fileDao.updateFileDownloadPath(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName, fill); - return outputEncapsulationObject(PromptMessageEnum.SUCCESS, fill, locale); +// Optional fileEntity = fileDao.selectFile(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName); +// if (fileEntity.isEmpty()) { +// return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的模板,请添加!", locale); +// } +// String fileUploadPath = fileEntity.get().getFileUploadPath(); +// List> resultList = qcSourceDao.queryQcSource(lotNo, machineNo, materialNo, modelNo, machineTypeNo, ""); +// if (resultList == null || resultList.size() == 0) { +// return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的信息!", locale); +// } +// Map map = new HashMap<>(); +// for (Map result : resultList) { +// map.put((String) result.get("qcItemNo"), (String) result.get("qcValue")); +// } +// String fill = ExportExcel.exportToProveExcel(map, fileUploadPath); +// fileDao.updateFileDownloadPath(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName, fill); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "导出成功", locale); } } diff --git a/src/main/java/com/xkrs/service/impl/QcSourceServiceImpl.java b/src/main/java/com/xkrs/service/impl/QcSourceServiceImpl.java index c947c03..7e0cedb 100644 --- a/src/main/java/com/xkrs/service/impl/QcSourceServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/QcSourceServiceImpl.java @@ -149,7 +149,17 @@ public class QcSourceServiceImpl implements QcSourceService { if (qcItemList.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "未添加检验项目,请先添加检验项目!", locale); } - List> sourceList = qcSourceDao.queryQcSource(LocalStringUtils.formatEmptyValue(batchNo), LocalStringUtils.formatEmptyValue(machineNo), LocalStringUtils.formatEmptyValue(materialNo), LocalStringUtils.formatEmptyValue(mouldNo), LocalStringUtils.formatEmptyValue(varietyNo), LocalStringUtils.formatEmptyValue(craftItemNo)); + String finalBatchNo = LocalStringUtils.formatEmptyValue(batchNo).trim(); + String finalMachineNo = LocalStringUtils.formatEmptyValue(machineNo).trim(); + String finalMaterialNo = LocalStringUtils.formatEmptyValue(materialNo).trim(); + String finalMouldNo = LocalStringUtils.formatEmptyValue(mouldNo).trim(); + String finalVarietyNo = LocalStringUtils.formatEmptyValue(varietyNo).trim(); + List> sourceList; + if (TextUtils.isEmpty(craftItemNo)) { + sourceList = qcSourceDao.queryQcSource(finalBatchNo, finalMachineNo, finalMaterialNo, finalMouldNo, finalVarietyNo); + } else { + sourceList = qcSourceDao.queryQcSource(finalBatchNo, finalMachineNo, finalMaterialNo, finalMouldNo, finalVarietyNo, craftItemNo.trim()); + } List> resultList = generateResultList(sourceList); if (resultList.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该检验数据的信息!", locale); @@ -252,11 +262,11 @@ public class QcSourceServiceImpl implements QcSourceService { @Override public String exportExcel(ExportExcelQo exportExcelQo) throws Exception { String host = exportExcelQo.getHost(); - String batchNo = exportExcelQo.getBatchNo(); - String machineNo = exportExcelQo.getMachineNo(); - String materialNo = exportExcelQo.getMaterialNo(); - String mouldNo = exportExcelQo.getMouldNo(); - String varietyNo = exportExcelQo.getVarietyNo(); + String finalBatchNo = LocalStringUtils.formatEmptyValue(exportExcelQo.getBatchNo()).trim(); + String finalMachineNo = LocalStringUtils.formatEmptyValue(exportExcelQo.getMachineNo()).trim(); + String finalMaterialNo = LocalStringUtils.formatEmptyValue(exportExcelQo.getMaterialNo()).trim(); + String finalMouldNo = LocalStringUtils.formatEmptyValue(exportExcelQo.getMouldNo()).trim(); + String finalVarietyNo = LocalStringUtils.formatEmptyValue(exportExcelQo.getVarietyNo()).trim(); String craftItemNo = exportExcelQo.getCraftItemNo(); List craftItemList = craftItemDao.findAll(); if (craftItemList.isEmpty()) { @@ -266,7 +276,12 @@ public class QcSourceServiceImpl implements QcSourceService { if (qcItemList.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "未添加检验项目,请先添加检验项目!", locale); } - List> sourceList = qcSourceDao.queryQcSource(LocalStringUtils.formatEmptyValue(batchNo), LocalStringUtils.formatEmptyValue(machineNo), LocalStringUtils.formatEmptyValue(materialNo), LocalStringUtils.formatEmptyValue(mouldNo), LocalStringUtils.formatEmptyValue(varietyNo), LocalStringUtils.formatEmptyValue(craftItemNo)); + List> sourceList; + if (TextUtils.isEmpty(craftItemNo)) { + sourceList = qcSourceDao.queryQcSource(finalBatchNo, finalMachineNo, finalMaterialNo, finalMouldNo, finalVarietyNo); + } else { + sourceList = qcSourceDao.queryQcSource(finalBatchNo, finalMachineNo, finalMaterialNo, finalMouldNo, finalVarietyNo, craftItemNo.trim()); + } List> resultList = generateResultList(sourceList); String finalHost = host.endsWith("/") ? host : host + "/"; List> formattedResultList = formatResultList(finalHost, resultList, qcItemList); diff --git a/src/main/java/com/xkrs/service/impl/QcSpecServiceImpl.java b/src/main/java/com/xkrs/service/impl/QcSpecServiceImpl.java index 613bb88..14a1914 100644 --- a/src/main/java/com/xkrs/service/impl/QcSpecServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/QcSpecServiceImpl.java @@ -13,6 +13,7 @@ import com.xkrs.model.qo.QcSpecQoUpdate; import com.xkrs.service.QcSpecService; import com.xkrs.util.LocalDateUtils; import com.xkrs.util.LocalStringUtils; +import org.apache.http.util.TextUtils; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; @@ -132,7 +133,14 @@ public class QcSpecServiceImpl implements QcSpecService { */ @Override public String queryQcSpec(String varietyNo, String craftItemNo, String qcItemNo) { - List> resultList = qcSpecDao.queryQcSpec(LocalStringUtils.formatEmptyValue(varietyNo), LocalStringUtils.formatEmptyValue(craftItemNo), LocalStringUtils.formatEmptyValue(qcItemNo)); + String finalVarietyNo = LocalStringUtils.formatEmptyValue(varietyNo).trim(); + String finalQcItemNo = LocalStringUtils.formatEmptyValue(qcItemNo).trim(); + List> resultList; + if (TextUtils.isEmpty(craftItemNo)) { + resultList = qcSpecDao.queryQcSpec(finalVarietyNo, finalQcItemNo); + } else { + resultList = qcSpecDao.queryQcSpec(finalVarietyNo, craftItemNo.trim(), finalQcItemNo); + } if (resultList == null || resultList.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该检验规格的信息!", locale); }