Commit 5cffced4 by lijingjing

修约问题修改;

parent 39a65541
......@@ -13,6 +13,7 @@ public interface Operation {
/**
* 对从直读光谱中抓取过来的原铝分析结果,进行修约
*
* @param cell
* @param value
* @param roundNum
......@@ -32,21 +33,22 @@ public interface Operation {
// CEILING(ABS(TRUNC(A1,B1+1)-0.5*10^(-B1),2*10^(-B1)*SIGN(A1)))
int beginIndex = value.lastIndexOf(".") + 1, valueLength = value.length();
String intVal = value.substring(0, value.indexOf(".") + 1);
int remindLength = valueLength - beginIndex;
String truncValue = "", zeroStr = "000000000";
// bdA = TRUNC(A1,B1+5)*10^B1
if (remindLength >= roundNum + 5) {
truncValue = "0." + value.substring(beginIndex, beginIndex + roundNum + 5);
truncValue = intVal + value.substring(beginIndex, beginIndex + roundNum + 5);
} else {
truncValue = "0." + value.substring(beginIndex) + zeroStr.substring(0, roundNum + 5 - remindLength);
truncValue = intVal + value.substring(beginIndex) + zeroStr.substring(0, roundNum + 5 - remindLength);
}
BigDecimal bdDiff = new BigDecimal(truncValue).scaleByPowerOfTen(roundNum);
// bdB = TRUNC(A1,B1+5)*10^B1
if (remindLength >= roundNum) {
truncValue = "0." + value.substring(beginIndex, beginIndex + roundNum);
truncValue = intVal + value.substring(beginIndex, beginIndex + roundNum);
} else {
truncValue = "0." + value.substring(beginIndex) + zeroStr.substring(0, roundNum - remindLength);
truncValue = intVal + value.substring(beginIndex) + zeroStr.substring(0, roundNum - remindLength);
}
bdDiff = bdDiff.subtract(new BigDecimal(truncValue).scaleByPowerOfTen(roundNum)).abs();
......@@ -59,9 +61,9 @@ public interface Operation {
// 处理第三种情况
// CEILING(ABS(TRUNC(A1,B1+1)-0.5*10^(-B1),2*10^(-B1)*SIGN(A1))
if (remindLength >= roundNum + 1) {
truncValue = "0." + value.substring(beginIndex, beginIndex + roundNum + 1);
truncValue = intVal + value.substring(beginIndex, beginIndex + roundNum + 1);
} else {
truncValue = "0." + value.substring(beginIndex) + zeroStr.substring(0, roundNum + 1 - remindLength);
truncValue = intVal + value.substring(beginIndex) + zeroStr.substring(0, roundNum + 1 - remindLength);
}
bdDiff = new BigDecimal(truncValue);
......
......@@ -972,6 +972,8 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
@Override
public boolean updateQualityJudge(Long[] ids, Account account) {
logger.error("======================质量判定开始========================");
RestAssert.fail(null == ids || ids.length == 0, "样品编号不能为空");
// ==
List<EntrustSampleVO> sampleList = entrustSampleService.getVOListByIds(Arrays.asList(ids));
......@@ -990,13 +992,16 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
List<String> otherYsList = Arrays.asList("Mn", "V", "Ni");
List<EntrustSample> updateSampleList = new ArrayList<>();
// 是否外委数据
boolean isOutEntrustData = contractSampleService.isOutEntrustData(sampleList.get(0).getContractSampleId());
logger.error("是否外委数据:" + isOutEntrustData);
for (EntrustSampleVO sampleVO : sampleList) {
EntrustSample sample = sampleVO.convert(EntrustSample.class);
logger.error("====样品编号:{},样品名称:{}", sample.getCode(), sample.getName());
// 若为此标准,需要判断是否需要过滤掉稀有元素的判断
boolean isSpecStandard = sampleVO.getProductCode().contains("GB/T 1196 2017");
logger.error("====是否GB/T 1196 2017标准:" + isSpecStandard);
// 检测值【内部检测值实际为指标表中数据,外委检测值为检测项目数据】
List<EntrustSampleItemVO> sampleItemList;
// 若为外部检测
......@@ -1008,13 +1013,20 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
}
RestAssert.fail(CollectionUtils.isEmpty(sampleItemList), "样品检测项目及内容不能为空");
StringBuffer sb = new StringBuffer("====检测项目检测值:\r\n");
for (EntrustSampleItemVO item : sampleItemList) {
sb.append(String.format("itemName=%s,testValue=%s\r\n", item.getName(), item.getTestValue()));
}
logger.error(sb.toString());
// 获得产品标准信息 -- 实时最新不是根据样品中的是否组合判定进行判定
// 可能需要根据样品中的字段进行判断是否需要组合判定composeJudge
GradingStandard standard = gradingStandardService.getById(sampleVO.getProductStandardId());
RestAssert.fail(null == standard, "产品标准不能为空");
logger.error("====检验标准,名称:{},编号:{},组合标识:{}", standard.getName(), standard.getCode(), standard.getComposeJudge());
// 是否组合判定
boolean isComposeJudgment = null != standard.getComposeJudge() && 1 == standard.getComposeJudge().intValue();
logger.error("====检验标准,是否组合判定:{}", isComposeJudgment);
// 计算合计-组合判定合计值
BigDecimal totalDecimal = sampleItemList.stream().map(t -> {
if (StringUtils.isBlank(t.getTestValue())) {
......@@ -1031,9 +1043,12 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
}
return BigDecimal.ZERO;
}).reduce(BigDecimal.ZERO, BigDecimal::add);
logger.error("====杂质值:{}", totalDecimal);
// 杂质合计值修约
double totalValue = totalDecimal.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
logger.error("====修约杂质值:{}", totalValue);
logger.error("====检测项目值比较对象=====");
// 获取检测项目值对象
Map<String, Double> itemDataMap = sampleItemList.stream().filter(t -> {
// 如果检测项目为空气反应性或者是CO2反应性,则只比较残极率
......@@ -1046,6 +1061,13 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
return true;
}).collect(Collectors.toMap(EntrustSampleItemVO::getName, t -> Double.parseDouble(t.getTestValue())));
sb = new StringBuffer("====实际比较的检测项目:\r\n");
for (Map.Entry<String, Double> entry : itemDataMap.entrySet()) {
sb.append(String.format("检测项目,name:%s,testValue:%f", entry.getKey(), entry.getValue())).append("\r\n");
}
logger.error(sb.toString());
// 获得产品等级信息
List<GradingProduct> gradingProductList = gradingProductService.list(Condition.create()
.eq("grading_standard_id", standard.getId())
......@@ -1054,7 +1076,13 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
RestAssert.fail(CollectionUtils.isEmpty(gradingProductList), "产品标准不能为空");
sb = new StringBuffer("====产品标准:\r\n");
for (GradingProduct gp : gradingProductList) {
sb.append(String.format("grade:%s,sumVal:%f,symbol:%s", gp.getProductGrade(), gp.getSumValue(), gp.getSumCompare())).append("\r\n");
}
logger.error(sb.toString());
logger.error("==== 循环产品等级 ==== ");
// 循环产品标准依次判定级别
for (int i = 0; i < gradingProductList.size(); i++) {
// 最后一个判定级别
......@@ -1062,14 +1090,22 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
// ==
GradingProduct product = gradingProductList.get(i);
logger.error("==== GradingProduct, grade:{},sumVal:{},symbol:{}", product.getProductGrade(), product.getSumValue(), product.getSumCompare());
// 比较单个大小是否都符合
List<GradingItem> gradingItemList = gradingItemService.list(Condition.create().eq("grading_product_id", product.getId()).isNotNull("limit_value"));
RestAssert.fail(CollectionUtils.isEmpty(gradingItemList), "产品等级【" + product.getProductGrade() + "】下的检测项目为空");
sb = new StringBuffer("====过滤前产品下检测项目:\r\n");
// 若存在
gradingItemList.forEach(t -> {
for (GradingItem t : gradingItemList) {
RestAssert.fail(StringUtils.isBlank(t.getDecisionSymbol()), "产品等级下产品检测项目比较符为空");
RestAssert.fail(StringUtils.isBlank(t.getLimitValue()), "产品等级下产品检测项目限制值为空");
});
sb.append(String.format("name:%s,symbol:%s,limitVal:%s", t.getName(), t.getDecisionSymbol(), t.getLimitValue())).append("\r\n");
}
logger.error(sb.toString());
// 过滤 只要名称包含
List<GradingItem> gradingItems = gradingItemList.stream().filter(t -> {
// 不包含的检测项目,过滤掉
......@@ -1079,17 +1115,33 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
return true;
}).collect(Collectors.toList());
sb = new StringBuffer("====过滤后产品下检测项目:\r\n");
for (GradingItem t : gradingItemList) {
sb.append(String.format("name:%s,symbol:%s,limitVal:%s", t.getName(), t.getDecisionSymbol(), t.getLimitValue())).append("\r\n");
}
RestAssert.fail(CollectionUtils.isEmpty(gradingItems), "产品等级【" + product.getProductGrade() + "】下的检测项目过滤后为空");
logger.error(sb.toString());
logger.error("==== 循环判断是否符合判定 ====");
logger.error("==== gradingItems.stream().anyMatch ====");
logger.error("==== 若一直失败,匹配的是失败结果");
// 若失败,则进入下一判级
if (gradingItems.stream().anyMatch(t -> {
// 获取填写检测值
double testValue = getValue(itemDataMap, t.getName());
logger.error("==== name:{},testValue:{}", t.getName(), testValue);
// 若不包含正常的比较符,那么则为区间比较符
if (!CompareUtils.Comparator.containsKey(t.getDecisionSymbol())) {
logger.error("====区间判定");
String[] dataArr = t.getLimitValue().split(",");
RestAssert.fail(dataArr.length != 2, String.format("样品编号【%s】缺失检测范围值", sample.getCode()));
try {
double minV = Double.parseDouble(dataArr[0].trim()), maxV = Double.parseDouble(dataArr[1].trim());
logger.error("==== minVal:{},maxVal:{},testValue:{}", minV, maxV, testValue);
logger.error("==== 计算公式:testValue < minV || testValue > maxV");
logger.error("==== 结果:{}", (testValue < minV || testValue > maxV));
// 小于最小值 or 大于最大值
return testValue < minV || testValue > maxV;
} catch (NumberFormatException e) {
......@@ -1098,12 +1150,17 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
}
return false;
} else {
return !CompareUtils.Comparator.get(t.getDecisionSymbol()).calc(testValue, Double.parseDouble(t.getLimitValue()));
logger.error("==== 正常符号比较判定");
logger.error("==== symbol:{},testValue:{},limitValue:{}", t.getDecisionSymbol(), testValue, t.getLimitValue());
boolean res = CompareUtils.Comparator.get(t.getDecisionSymbol()).calc(testValue, Double.parseDouble(t.getLimitValue()));
logger.error("==== 判定结果:{}", res);
return !res;
}
}
)) {
// 若为最后一个级别,那么判定结果
if (isLastGrading) {
logger.error("==== 最后一条标准,结论不合格");
updateJudgeNoPass(sample, account, updateSampleList);
break;
}
......@@ -1112,33 +1169,47 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
}
// 继续判定是否为组合判定,若为组合判定,那么需要判定组合结果是否符合限定值
logger.error("==== 是否组合判定:{}", isComposeJudgment);
if (isComposeJudgment) {
RestAssert.fail(null == product.getSumValue(), "产品标准合计值不能为空");
RestAssert.fail(StringUtils.isBlank(product.getSumCompare()), "产品标准比较符不能为空");
// 根据比较符类型比较大小
if (!CompareUtils.Comparator.get(product.getSumCompare()).calc(totalValue, product.getSumValue().doubleValue())) {
logger.error("==== 组合比较判定 ==== ");
logger.error("==== symbol:{},totalValue:{},sumValue:{}", product.getSumCompare(), totalValue, product.getSumValue());
boolean res = CompareUtils.Comparator.get(product.getSumCompare()).calc(totalValue, product.getSumValue().doubleValue());
logger.error("==== 判定结果:{}", res);
// 根据比较符类型比较大小,若不符合,继续下一个
if (!res) {
if (!isLastGrading) {
continue;
}
logger.error("==== 组合判定最后一个仍旧不合格");
updateJudgeNoPass(sample, account, updateSampleList);
break;
}
}
logger.error("====############# 组合判定合格 #############==== ");
// 样品判定合格
updateSampleList.add(sample.setOkJudge("合格").setJudger(account.getUserName()).setJudgerId(account.getUserId())
.setJudgeTime(new Date()).setJudgeStatus(0).setJudgeProgress(0)
.setSampleGrading(product.getProductGrade()));
logger.error("====判定合格品级:sampleId:{},sampleName:{},sampleCode:{},grading:{}", sample.getId(), sample.getName(), sample.getCode(), sample.getSampleGrading());
break;
}
}
if (updateSampleList.size() > 0) {
entrustSampleService.updateBatchById(updateSampleList);
logger.error("====更新样品判级:]\r\n");
for(EntrustSample s : updateSampleList){
logger.error("====判定合格品级:sampleId:{},sampleName:{},sampleCode:{},grading:{}", s.getId(), s.getName(), s.getCode(), s.getSampleGrading());
}
}
// 处理正常的报告文件
handleSampleBrand(ids, false);
// 处理一级编码的报告文件
handleSampleBrand(ids, true);
logger.error("======================质量判定结束========================");
return true;
}
......
......@@ -329,7 +329,14 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
if (null != samplingId) {
ContractSampling sampling = contractSamplingService.getById(samplingId);
sample.setCode(sampling.getCode()).setFirstCode(sampling.getFirstCode())
.setSecondCode(sampling.getSecondCode()).setThirdCode(sampling.getThirdCode());
.setSecondCode(sampling.getSecondCode());
// 进场物资,使用针对进场物资的生成规则
if (1 == entrust.getType()) {
thirdCode = getSampleThirdCode(sample);
} else {
thirdCode = sampling.getThirdCode();
}
sample.setThirdCode(thirdCode);
} else {
initSampleCode(entrust, sample);
if (StringUtils.isNotBlank(sampleCode)) {
......@@ -340,6 +347,9 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
sample.setSecondCode(secondCode);
}
if (StringUtils.isNotBlank(thirdCode)) {
if (1 == entrust.getType()) {
thirdCode = getSampleThirdCode(sample);
}
sample.setThirdCode(thirdCode);
}
}
......@@ -1114,7 +1124,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
String sampleCode = sample.getCode();
sample.setId(null);
sample.setId(IdWorker.getId());
sample.setCode(null);
sample.setCode(null).setFirstCode(null).setSecondCode(null).setThirdCode(null);
//生成样品编号,可能存在为空的情况
initSampleCode(entrust, sample);
// 样品编号问题,手填的样品编号不清空
......
......@@ -243,35 +243,23 @@
WHERE e.deleted = 0
<include refid="basicCondition"/>
<if test="null!=vo.itemStatus">
<if test=" null != vo.itemStatus || null != vo.itemStatusEnumList || null != vo.testerId ">
and exists (
select 1 from entrust_sample es
join entrust_sample_item esi on esi.entrust_sample_id = es.id
where es.deleted = 0 and esi.deleted = 0 and es.entrust_id = e.id
and esi.status = #{vo.itemStatus}
)
</if>
<if test="null!=vo.itemStatusEnumList">
and exists (
select 1 from entrust_sample es
join entrust_sample_item esi on esi.entrust_sample_id = es.id
where es.deleted = 0 and esi.deleted = 0 and es.entrust_id = e.id
and esi.status IN
<foreach collection="vo.itemStatusEnumList" index="index" item="status" open="(" separator="," close=")">
#{status}
</foreach>
)
</if>
<if test="null!=vo.testerId">
and exists (
select 1 from entrust_sample es
join entrust_sample_item esi on esi.entrust_sample_id = es.id
where es.deleted = 0 and esi.deleted = 0 and es.entrust_id = e.id
and esi.tester_id = #{vo.testerId}
-- 数据录入节点,处理完成的数据不再显示
join entrust_sample_item esi on esi.entrust_sample_id = es.id and esi.deleted = 0
where es.entrust_id = e.id and es.deleted = 0
<if test="null != vo.itemStatus">
and esi.status = #{vo.itemStatus}
</if>
<if test="null != vo.itemStatusEnumList">
and esi.status IN
<foreach collection="vo.itemStatusEnumList" index="index" item="status" open="(" separator="," close=")">
#{status}
</foreach>
</if>
<if test="null!=vo.testerId">
and esi.tester_id = #{vo.testerId}
</if>
)
</if>
order by e.entrust_time desc,e.code desc
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment