From 7690f14c0da15c876bcdd5c9cc61358e8a56aaf5 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Sat, 12 Mar 2022 14:43:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=E6=B5=8B=E9=87=8F=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=AB=98=E4=BD=8E=E6=8C=87=E6=A0=87=E5=90=8E?= =?UTF-8?q?=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/QcSourceServiceImpl.java | 53 +++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/xkrs/service/impl/QcSourceServiceImpl.java b/src/main/java/com/xkrs/service/impl/QcSourceServiceImpl.java index 245d0e6..077d539 100644 --- a/src/main/java/com/xkrs/service/impl/QcSourceServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/QcSourceServiceImpl.java @@ -2,9 +2,11 @@ package com.xkrs.service.impl; import com.xkrs.dao.QcItemDao; import com.xkrs.dao.QcSourceDao; +import com.xkrs.dao.QcSpecDao; import com.xkrs.encapsulation.PromptMessageEnum; import com.xkrs.model.entity.QcItemEntity; import com.xkrs.model.entity.QcSourceEntity; +import com.xkrs.model.entity.QcSpecEntity; import com.xkrs.model.qo.QcSourceQoDelete; import com.xkrs.model.qo.QcSourceQoInsert; import com.xkrs.service.QcSourceService; @@ -35,6 +37,9 @@ public class QcSourceServiceImpl implements QcSourceService { @Resource private QcSourceDao qcSourceDao; + @Resource + private QcSpecDao qcSpecDao; + /** * 添加检验数据 */ @@ -115,14 +120,17 @@ public class QcSourceServiceImpl implements QcSourceService { 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); + List> resultList = generateResultList(sourceList); if (resultList.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该检验数据的信息!", locale); } return outputEncapsulationObject(PromptMessageEnum.SUCCESS, resultList, locale); } - private List> generateResultList(List> sourceList, List qcItemList) { + /** + * 生成返回结果 + */ + private List> generateResultList(List> sourceList) { List> resultList = new ArrayList<>(); if (sourceList == null || sourceList.isEmpty()) { return resultList; @@ -138,6 +146,7 @@ public class QcSourceServiceImpl implements QcSourceService { if (TextUtils.isEmpty(qcItemNo) || TextUtils.isEmpty(qcValue)) { continue; } + String formatValue = getFormatValue(varietyNo, qcItemNo, qcValue); Map emptyRoom = findEmptyRoom(resultList, batchNo, qcItemNo); if (emptyRoom == null) { Map newRoom = new HashMap<>(); @@ -146,15 +155,51 @@ public class QcSourceServiceImpl implements QcSourceService { newRoom.put("materialNo", materialNo); newRoom.put("mouldNo", mouldNo); newRoom.put("varietyNo", varietyNo); - newRoom.put(qcItemNo, qcValue); + newRoom.put(qcItemNo, formatValue); resultList.add(newRoom); } else { - emptyRoom.put(qcItemNo, qcValue); + emptyRoom.put(qcItemNo, formatValue); } } return resultList; } + /** + * 获取添加了 ##H 或 ##L 后缀的测量值(如果可能的话) + */ + private String getFormatValue(String varietyNo, String qcItemNo, String qcValue) { + Optional entityByVarietyNoAndQcItemNo = qcSpecDao.findByVarietyNoAndQcItemNo(varietyNo, qcItemNo); + if (entityByVarietyNoAndQcItemNo.isEmpty()) { + return qcValue; + } + QcSpecEntity qcSpec = entityByVarietyNoAndQcItemNo.get(); + double valueMax = stringToDouble(qcSpec.getMax()); + double valueMin = stringToDouble(qcSpec.getMin()); + double value = stringToDouble(qcValue); + if (valueMax >= 0 && value >= 0 && value >= valueMax) { + return qcValue + "##H"; + } + if (valueMin >= 0 && value >= 0 && value <= valueMin) { + return qcValue + "##L"; + } + return qcValue; + } + + /** + * 格式化字符串为Double + */ + private Double stringToDouble(String stringValue) { + try { + return Double.parseDouble(stringValue); + } catch (Exception e) { + e.printStackTrace(); + return -1D; + } + } + + /** + * 尝试找到一个qcItemNo有空位置的Map + */ private Map findEmptyRoom(List> mapList, String batchNo, String qcItemNo) { if (mapList == null || mapList.isEmpty() || TextUtils.isEmpty(batchNo) || TextUtils.isEmpty(qcItemNo)) { return null;