为测量数据添加高低指标后缀

This commit is contained in:
liuchengqian 2022-03-12 14:43:52 +08:00
parent f11ae30b77
commit 7690f14c0d

View File

@ -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<Map<String, Object>> sourceList = qcSourceDao.queryQcSource(LocalStringUtils.formatEmptyValue(batchNo), LocalStringUtils.formatEmptyValue(machineNo), LocalStringUtils.formatEmptyValue(materialNo), LocalStringUtils.formatEmptyValue(mouldNo), LocalStringUtils.formatEmptyValue(varietyNo));
List<Map<String, Object>> resultList = generateResultList(sourceList, qcItemList);
List<Map<String, Object>> resultList = generateResultList(sourceList);
if (resultList.isEmpty()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该检验数据的信息!", locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, resultList, locale);
}
private List<Map<String, Object>> generateResultList(List<Map<String, Object>> sourceList, List<QcItemEntity> qcItemList) {
/**
* 生成返回结果
*/
private List<Map<String, Object>> generateResultList(List<Map<String, Object>> sourceList) {
List<Map<String, Object>> 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<String, Object> emptyRoom = findEmptyRoom(resultList, batchNo, qcItemNo);
if (emptyRoom == null) {
Map<String, Object> 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<QcSpecEntity> 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<String, Object> findEmptyRoom(List<Map<String, Object>> mapList, String batchNo, String qcItemNo) {
if (mapList == null || mapList.isEmpty() || TextUtils.isEmpty(batchNo) || TextUtils.isEmpty(qcItemNo)) {
return null;