5 changed files with 233 additions and 47 deletions
-
33cclqms-java/src/main/java/com/gaotao/modules/pms/data/SubDetailValues.java
-
52cclqms-java/src/main/java/com/gaotao/modules/pms/service/Impl/EquipmentDataImportServiceImpl.java
-
58cclqms-java/src/main/java/com/gaotao/modules/pms/service/Impl/QcServiceImpl.java
-
97cclqms-java/src/main/java/com/gaotao/modules/pms/util/QcSubDetailQualifyHelper.java
-
40cclqms-java/src/main/resources/mapper/pms/QcMapper.xml
@ -0,0 +1,97 @@ |
|||
package com.gaotao.modules.pms.util; |
|||
|
|||
import com.gaotao.modules.pms.data.SubDetailValues; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
|
|||
import java.math.BigDecimal; |
|||
import java.util.regex.Pattern; |
|||
|
|||
/** |
|||
* 子明细合格判定:数字类型且存在最大/最小时,A~E 任一超限为 N,均在范围内为 Y;其余情况存空。 |
|||
* 同时写入 defectQty:A~E 不合格个数,无不合格为 0。 |
|||
*/ |
|||
public final class QcSubDetailQualifyHelper { |
|||
|
|||
private static final Pattern NUMBER_PATTERN = Pattern.compile("-?[0-9]+(\\.[0-9]+)?"); |
|||
|
|||
private QcSubDetailQualifyHelper() { |
|||
} |
|||
|
|||
public static void applyIsQualified(SubDetailValues row, String valueTypeDb, BigDecimal minValue, BigDecimal maxValue) { |
|||
if (row == null) { |
|||
return; |
|||
} |
|||
int defectQty = countOutOfSpecSubDetailRow(row, valueTypeDb, minValue, maxValue); |
|||
row.setDefectQty(defectQty); |
|||
row.setIsQualified(resolveIsQualified(row, valueTypeDb, minValue, maxValue)); |
|||
} |
|||
|
|||
public static String resolveIsQualified(SubDetailValues row, String valueTypeDb, BigDecimal minValue, BigDecimal maxValue) { |
|||
if (row == null || !"N".equals(valueTypeDb) || (minValue == null && maxValue == null)) { |
|||
return null; |
|||
} |
|||
boolean hasComparable = false; |
|||
boolean outOfSpec = false; |
|||
String[] values = { |
|||
row.getSubDetailValue(), |
|||
row.getSubDetailValueB(), |
|||
row.getSubDetailValueC(), |
|||
row.getSubDetailValueD(), |
|||
row.getSubDetailValueE() |
|||
}; |
|||
for (String value : values) { |
|||
if (StringUtils.isBlank(value)) { |
|||
continue; |
|||
} |
|||
hasComparable = true; |
|||
if (countOutOfSpecSubValue(value, valueTypeDb, minValue, maxValue) > 0) { |
|||
outOfSpec = true; |
|||
} |
|||
} |
|||
if (!hasComparable) { |
|||
return null; |
|||
} |
|||
return outOfSpec ? "N" : "Y"; |
|||
} |
|||
|
|||
public static int countOutOfSpecSubValue(String value, String valueTypeDb, BigDecimal minValue, BigDecimal maxValue) { |
|||
if (StringUtils.isBlank(value) || !"N".equals(valueTypeDb) || (minValue == null && maxValue == null)) { |
|||
return 0; |
|||
} |
|||
if (!isNumberString(value)) { |
|||
return 1; |
|||
} |
|||
return countOutOfSpecNumber(new BigDecimal(value), minValue, maxValue); |
|||
} |
|||
|
|||
public static int countOutOfSpecSubDetailRow(SubDetailValues row, String valueTypeDb, BigDecimal minValue, BigDecimal maxValue) { |
|||
if (row == null) { |
|||
return 0; |
|||
} |
|||
return countOutOfSpecSubValue(row.getSubDetailValue(), valueTypeDb, minValue, maxValue) |
|||
+ countOutOfSpecSubValue(row.getSubDetailValueB(), valueTypeDb, minValue, maxValue) |
|||
+ countOutOfSpecSubValue(row.getSubDetailValueC(), valueTypeDb, minValue, maxValue) |
|||
+ countOutOfSpecSubValue(row.getSubDetailValueD(), valueTypeDb, minValue, maxValue) |
|||
+ countOutOfSpecSubValue(row.getSubDetailValueE(), valueTypeDb, minValue, maxValue); |
|||
} |
|||
|
|||
public static int countOutOfSpecNumber(BigDecimal value, BigDecimal minValue, BigDecimal maxValue) { |
|||
if (value == null || (minValue == null && maxValue == null)) { |
|||
return 0; |
|||
} |
|||
if (maxValue != null && minValue == null) { |
|||
return value.compareTo(maxValue) > 0 ? 1 : 0; |
|||
} |
|||
if (maxValue == null) { |
|||
return value.compareTo(minValue) < 0 ? 1 : 0; |
|||
} |
|||
return (value.compareTo(maxValue) > 0 || value.compareTo(minValue) < 0) ? 1 : 0; |
|||
} |
|||
|
|||
public static boolean isNumberString(String str) { |
|||
if (str == null) { |
|||
return false; |
|||
} |
|||
return NUMBER_PATTERN.matcher(str).matches(); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue