Commit a7fe5e1d by lijingjing

霍煤需求修改;

parent 56639177
package com.patzn.cloud.service.lims.hmhj.original; package com.patzn.cloud.service.lims.hmhj.original;
import com.patzn.cloud.service.lims.common.StringHandleUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import java.math.BigDecimal;
import java.math.RoundingMode;
public interface Operation { public interface Operation {
void doMakeOriginal();
void doMakeOriginal();
/**
* 对从直读光谱中抓取过来的原铝分析结果,进行修约
* @param cell
* @param value
* @param roundNum
*/
default void rounding(Cell cell, String value, Integer roundNum) {
if (StringUtils.isNotBlank(value)) {
if (!StringHandleUtils.validateNumber(value)) {
if (value.startsWith("!")) {
value = value.substring(1);
} else {
cell.setCellValue(value);
return;
}
}
// IF(ABS(TRUNC(A1,B1+5)*10^B1-TRUNC(A1,B1+5)*10^B1)<0.499999,ROUND(A1,B1),
// IF(ABS(TRUNC(A1,B1+5)*10^B1-TRUNC(A1,B1+5)*10^B1)>0.500001,ROUND(A1,B1),
// CEILING(ABS(TRUNC(A1,B1+1)-0.5*10^(-B1),2*10^(-B1)*SIGN(A1)))
int beginIndex = value.lastIndexOf(".") + 1, valueLength = value.length();
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);
} else {
truncValue = "0." + 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);
} else {
truncValue = "0." + value.substring(beginIndex) + zeroStr.substring(0, roundNum - remindLength);
}
bdDiff = bdDiff.subtract(new BigDecimal(truncValue).scaleByPowerOfTen(roundNum)).abs();
// 若 < 0.499999 或 大于 0.500001
if (bdDiff.compareTo(new BigDecimal("0.499999")) < 0 || bdDiff.compareTo(new BigDecimal("0.500001")) > 0) {
cell.setCellValue(new BigDecimal(value).setScale(roundNum, RoundingMode.HALF_EVEN).toPlainString());
return;
}
// 处理第三种情况
// 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);
} else {
truncValue = "0." + value.substring(beginIndex) + zeroStr.substring(0, roundNum + 1 - remindLength);
}
bdDiff = new BigDecimal(truncValue);
bdDiff = bdDiff.subtract(new BigDecimal("0.5").scaleByPowerOfTen(-roundNum)).abs();
int signValue = Integer.valueOf(value).compareTo(0);
BigDecimal significance = new BigDecimal("2").scaleByPowerOfTen(-roundNum).multiply(BigDecimal.valueOf(signValue)).abs();
// ceiling
BigDecimal[] result = bdDiff.divideAndRemainder(significance);
if (result[1].compareTo(BigDecimal.ZERO) == 0) {
cell.setCellValue(bdDiff.toPlainString());
} else {
cell.setCellValue(result[0].add(BigDecimal.ONE).multiply(significance).setScale(roundNum).toPlainString());
}
}
}
} }
...@@ -1199,9 +1199,20 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI ...@@ -1199,9 +1199,20 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
String objectKey = entry.getKey(); String objectKey = entry.getKey();
Long reportId = entry.getValue(); Long reportId = entry.getValue();
entrustReport.setId(reportId); entrustReport.setId(reportId);
Map<String, String> sampleMap = reportSampleList.stream().filter(t -> t.getObjectKey().equals(objectKey)).collect(Collectors.toMap(t -> { Map<String, String> sampleMap = null;
return finalIsOther ? t.getFirstCode() : t.getSampleCode(); // 根据是否一级编码确定使用得objectKey
}, ReportSampleVO::getSampleGrading)); if (finalIsOther) {
sampleMap = reportSampleList.stream().filter(t -> t.getOtherObjectKey().equals(objectKey)).collect(Collectors.toMap(ReportSampleVO::getFirstCode, ReportSampleVO::getSampleGrading));
} else {
sampleMap = reportSampleList.stream().filter(t -> t.getObjectKey().equals(objectKey)).collect(Collectors.toMap(t -> {
if (StringUtils.isNotBlank(t.getThirdCode())) {
return t.getThirdCode();
} else if (StringUtils.isNotBlank(t.getSecondCode())) {
return t.getSecondCode();
}
return t.getFirstCode();
}, ReportSampleVO::getSampleGrading));
}
if (StringUtils.isBlank(objectKey)) { if (StringUtils.isBlank(objectKey)) {
continue; continue;
...@@ -1306,7 +1317,7 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI ...@@ -1306,7 +1317,7 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
private void updateJudgeNoPass(EntrustSample sample, Account account, List<EntrustSample> sampleList) { private void updateJudgeNoPass(EntrustSample sample, Account account, List<EntrustSample> sampleList) {
sampleList.add(sample.setOkJudge("不合格").setJudger(account.getUserName()).setJudgerId(account.getUserId()) sampleList.add(sample.setOkJudge("不合格").setJudger(account.getUserName()).setJudgerId(account.getUserId())
.setJudgeTime(new Date()).setJudgeStatus(0).setJudgeProgress(0) .setJudgeTime(new Date()).setJudgeStatus(0).setJudgeProgress(0)
.setSampleGrading("-")); .setSampleGrading("等外"));
} }
......
package com.patzn.cloud.service.lims.test; package com.patzn.cloud.service.lims.test;
import com.patzn.cloud.service.lims.common.DateKit; import com.patzn.cloud.service.lims.common.StringHandleUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.List; import java.math.BigDecimal;
import java.math.RoundingMode;
public class Test { public class Test {
public static void main(String[] args) { public static void main(String[] args) {
List<String> dateList = DateKit.dateInMonth("2021-09"); System.out.println(getTestValue("0.1841", 2));
dateList.stream().forEach(System.out::print); System.out.println(getTestValue("0.1952", 2));
System.out.println(getTestValue("0.2056", 2));
}
private static String getTestValue(String value, int roundNum) {
if (StringUtils.isNotBlank(value)) {
if (!StringHandleUtils.validateNumber(value)) {
if (value.startsWith("!")) {
value = value.substring(1);
} else {
return value;
}
}
// IF(ABS(TRUNC(A1,B1+5)*10^B1-TRUNC(A1,B1+5)*10^B1)<0.499999,ROUND(A1,B1),
// IF(ABS(TRUNC(A1,B1+5)*10^B1-TRUNC(A1,B1+5)*10^B1)>0.500001,ROUND(A1,B1),
// CEILING(ABS(TRUNC(A1,B1+1)-0.5*10^(-B1),2*10^(-B1)*SIGN(A1)))
int beginIndex = value.lastIndexOf(".") + 1, valueLength = value.length();
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);
} else {
truncValue = "0." + 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);
} else {
truncValue = "0." + value.substring(beginIndex) + zeroStr.substring(0, roundNum - remindLength);
}
bdDiff = bdDiff.subtract(new BigDecimal(truncValue).scaleByPowerOfTen(roundNum)).abs();
// 若 < 0.499999 或 大于 0.500001
if (bdDiff.compareTo(new BigDecimal("0.499999")) < 0 || bdDiff.compareTo(new BigDecimal("0.500001")) > 0) {
return new BigDecimal(value).setScale(roundNum, RoundingMode.HALF_EVEN).toPlainString();
}
// 处理第三种情况
// 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);
} else {
truncValue = "0." + value.substring(beginIndex) + zeroStr.substring(0, roundNum + 1 - remindLength);
}
bdDiff = new BigDecimal(truncValue);
bdDiff = bdDiff.subtract(new BigDecimal("0.5").scaleByPowerOfTen(-roundNum)).abs();
int signValue = Double.valueOf(value).compareTo(0.0);
BigDecimal significance = new BigDecimal("2").scaleByPowerOfTen(-roundNum).multiply(BigDecimal.valueOf(signValue)).abs();
// ceiling
BigDecimal[] result = bdDiff.divideAndRemainder(significance);
if (result[1].compareTo(BigDecimal.ZERO) == 0) {
return bdDiff.setScale(roundNum).toPlainString();
} else {
return result[0].add(BigDecimal.ONE).multiply(significance).setScale(roundNum).toPlainString();
}
}
return value;
}
private static String rounding(String value, Integer roundNum) {
if (StringUtils.isNotBlank(value)) {
if (!StringHandleUtils.validateNumber(value)) {
if (value.startsWith("!")) {
value = value.substring(1);
} else {
return value;
}
}
BigDecimal bd1 = new BigDecimal(value);
BigDecimal bd2 = bd1.setScale(roundNum, BigDecimal.ROUND_HALF_EVEN);
return bd2.toPlainString();
}
return "";
} }
} }
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