From f11ae30b77f640983f3d307f8ebcb5b9e10f1f9d Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Sat, 12 Mar 2022 13:52:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=9F=A5=E8=AF=A2=E6=B5=8B?= =?UTF-8?q?=E9=87=8F=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/service/impl/QcItemServiceImpl.java | 3 +- .../service/impl/QcSourceServiceImpl.java | 78 +++++++++++++++---- .../xkrs/service/impl/QcSpecServiceImpl.java | 5 +- .../java/com/xkrs/util/ExcelUploadUtil.java | 12 +-- 4 files changed, 74 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/xkrs/service/impl/QcItemServiceImpl.java b/src/main/java/com/xkrs/service/impl/QcItemServiceImpl.java index 25a675a..41b6e0b 100644 --- a/src/main/java/com/xkrs/service/impl/QcItemServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/QcItemServiceImpl.java @@ -1,7 +1,7 @@ package com.xkrs.service.impl; -import com.xkrs.encapsulation.PromptMessageEnum; import com.xkrs.dao.QcItemDao; +import com.xkrs.encapsulation.PromptMessageEnum; import com.xkrs.model.entity.QcItemEntity; import com.xkrs.model.qo.QcItemQoDelete; import com.xkrs.model.qo.QcItemQoInsert; @@ -54,6 +54,7 @@ public class QcItemServiceImpl implements QcItemService { /** * 删除检验项目 */ + @Transactional(rollbackOn = Exception.class) @Override public String deleteQcItem(QcItemQoDelete deleteQo) { Integer id = deleteQo.getId(); diff --git a/src/main/java/com/xkrs/service/impl/QcSourceServiceImpl.java b/src/main/java/com/xkrs/service/impl/QcSourceServiceImpl.java index 4d6d33b..245d0e6 100644 --- a/src/main/java/com/xkrs/service/impl/QcSourceServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/QcSourceServiceImpl.java @@ -1,27 +1,26 @@ package com.xkrs.service.impl; -import com.xkrs.encapsulation.PromptMessageEnum; import com.xkrs.dao.QcItemDao; import com.xkrs.dao.QcSourceDao; +import com.xkrs.encapsulation.PromptMessageEnum; import com.xkrs.model.entity.QcItemEntity; import com.xkrs.model.entity.QcSourceEntity; import com.xkrs.model.qo.QcSourceQoDelete; import com.xkrs.model.qo.QcSourceQoInsert; import com.xkrs.service.QcSourceService; import com.xkrs.util.Constant; +import com.xkrs.util.ExcelUploadUtil; import com.xkrs.util.LocalDateUtils; import com.xkrs.util.LocalStringUtils; -import com.xkrs.util.ExcelUploadUtil; +import org.apache.http.util.TextUtils; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import javax.transaction.Transactional; import java.io.IOException; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Optional; +import java.util.*; import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject; @@ -94,6 +93,7 @@ public class QcSourceServiceImpl implements QcSourceService { /** * 删除检验数据 */ + @Transactional(rollbackOn = Exception.class) @Override public String deleteQcSource(QcSourceQoDelete deleteQo) { Integer id = deleteQo.getId(); @@ -110,17 +110,63 @@ public class QcSourceServiceImpl implements QcSourceService { */ @Override public String queryQcSource(String batchNo, String machineNo, String materialNo, String mouldNo, String varietyNo) { - List> resultList = qcSourceDao.queryQcSource(LocalStringUtils.formatEmptyValue(batchNo), LocalStringUtils.formatEmptyValue(machineNo), LocalStringUtils.formatEmptyValue(materialNo), LocalStringUtils.formatEmptyValue(mouldNo), LocalStringUtils.formatEmptyValue(varietyNo)); - if (resultList == null || resultList.isEmpty()) { + List qcItemList = qcItemDao.findAll(); + 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)); + List> resultList = generateResultList(sourceList, qcItemList); + if (resultList.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该检验数据的信息!", locale); } - if (1 == 1) { - return outputEncapsulationObject(PromptMessageEnum.SUCCESS, resultList, locale); - } - - - - - return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "查询成功!", locale); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, resultList, locale); } + + private List> generateResultList(List> sourceList, List qcItemList) { + List> resultList = new ArrayList<>(); + if (sourceList == null || sourceList.isEmpty()) { + return resultList; + } + for (Map source : sourceList) { + String batchNo = (String) source.getOrDefault("batchNo", ""); + String machineNo = (String) source.getOrDefault("machineNo", ""); + String materialNo = (String) source.getOrDefault("materialNo", ""); + String mouldNo = (String) source.getOrDefault("mouldNo", ""); + String varietyNo = (String) source.getOrDefault("varietyNo", ""); + String qcItemNo = (String) source.getOrDefault("qcItemNo", ""); + String qcValue = (String) source.getOrDefault("qcValue", ""); + if (TextUtils.isEmpty(qcItemNo) || TextUtils.isEmpty(qcValue)) { + continue; + } + Map emptyRoom = findEmptyRoom(resultList, batchNo, qcItemNo); + if (emptyRoom == null) { + Map newRoom = new HashMap<>(); + newRoom.put("batchNo", batchNo); + newRoom.put("machineNo", machineNo); + newRoom.put("materialNo", materialNo); + newRoom.put("mouldNo", mouldNo); + newRoom.put("varietyNo", varietyNo); + newRoom.put(qcItemNo, qcValue); + resultList.add(newRoom); + } else { + emptyRoom.put(qcItemNo, qcValue); + } + } + return resultList; + } + + private Map findEmptyRoom(List> mapList, String batchNo, String qcItemNo) { + if (mapList == null || mapList.isEmpty() || TextUtils.isEmpty(batchNo) || TextUtils.isEmpty(qcItemNo)) { + return null; + } + for (Map room : mapList) { + if (room.getOrDefault("batchNo", "").equals(batchNo)) { + if (!room.containsKey(qcItemNo)) { + return room; + } + } + } + return null; + } + } diff --git a/src/main/java/com/xkrs/service/impl/QcSpecServiceImpl.java b/src/main/java/com/xkrs/service/impl/QcSpecServiceImpl.java index f613eed..a144a4c 100644 --- a/src/main/java/com/xkrs/service/impl/QcSpecServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/QcSpecServiceImpl.java @@ -1,8 +1,8 @@ package com.xkrs.service.impl; -import com.xkrs.encapsulation.PromptMessageEnum; import com.xkrs.dao.QcItemDao; import com.xkrs.dao.QcSpecDao; +import com.xkrs.encapsulation.PromptMessageEnum; import com.xkrs.model.entity.QcItemEntity; import com.xkrs.model.entity.QcSpecEntity; import com.xkrs.model.qo.QcSpecQoDelete; @@ -15,6 +15,7 @@ import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import javax.transaction.Transactional; import java.util.List; import java.util.Locale; import java.util.Map; @@ -78,6 +79,7 @@ public class QcSpecServiceImpl implements QcSpecService { /** * 删除检验规格 */ + @Transactional(rollbackOn = Exception.class) @Override public String deleteQcSpec(QcSpecQoDelete deleteQo) { Integer id = deleteQo.getId(); @@ -92,6 +94,7 @@ public class QcSpecServiceImpl implements QcSpecService { /** * 更新检验规格 */ + @Transactional(rollbackOn = Exception.class) @Override public String updateQcSpec(QcSpecQoUpdate updateQo) { diff --git a/src/main/java/com/xkrs/util/ExcelUploadUtil.java b/src/main/java/com/xkrs/util/ExcelUploadUtil.java index 90ef579..bb4e494 100644 --- a/src/main/java/com/xkrs/util/ExcelUploadUtil.java +++ b/src/main/java/com/xkrs/util/ExcelUploadUtil.java @@ -39,17 +39,17 @@ public class ExcelUploadUtil { String suffix = originalFilename.substring(index); //uuid生成新的文件名 String newName = UUID.randomUUID().toString() + suffix; -// File file = new File("/Users/liuchengqian/Desktop/DaJiang/" + subDir); - File file = new File("/home/sxy/server/industrial_measurement/" + subDir); + File file = new File("/Users/liuchengqian/Desktop/DaJiang/" + subDir); +// File file = new File("/home/sxy/server/industrial_measurement/" + subDir); if (!file.exists()) { file.mkdirs(); } -// String path = "/Users/liuchengqian/Desktop/DaJiang/" + subDir + newName; - String path = "/home/sxy/server/industrial_measurement/" + subDir + newName; + String path = "/Users/liuchengqian/Desktop/DaJiang/" + subDir + newName; +// String path = "/home/sxy/server/industrial_measurement/" + subDir + newName; //实现上传 fileInput.transferTo(new File(path)); -// return path; - return subDir + newName; + return path; +// return subDir + newName; } return null; }