|
@@ -1,5 +1,7 @@
|
|
|
package com.slibra.business.service.impl;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
@@ -17,8 +19,7 @@ import com.slibra.business.mapper.TXinyiMedicineParamMapper;
|
|
|
import com.slibra.business.domain.TXinyiMedicineParam;
|
|
|
import com.slibra.business.service.ITXinyiMedicineParamService;
|
|
|
|
|
|
-import static com.slibra.common.constant.MyConstants.INT_2;
|
|
|
-import static com.slibra.common.constant.MyConstants.INT_4;
|
|
|
+import static com.slibra.common.constant.MyConstants.*;
|
|
|
|
|
|
/**
|
|
|
* 智能投药参数设置Service业务层处理
|
|
@@ -127,7 +128,7 @@ public class TXinyiMedicineParamServiceImpl implements ITXinyiMedicineParamServi
|
|
|
if (!Objects.isNull(latestRecord)) {
|
|
|
TXinyiIndustry tXinyiIndustry = this.xinyiIndustryMapper.selectTXinyiIndustryNewest();
|
|
|
if (!Objects.isNull(tXinyiIndustry)) {
|
|
|
- latestRecord.setTytjTransientLL(DecimalUtils.getAbsAndScale(tXinyiIndustry.getSJTYJLY(), INT_4));
|
|
|
+ latestRecord.setTytjTransientLL(DecimalUtils.getNLengthHalfUp(tXinyiIndustry.getSJTYJLY(), INT_4));
|
|
|
}
|
|
|
//2024年09月14日11:02:12 有可能用户选择的是仪表或者化验,需要获取实时数据
|
|
|
//获取最新的实时数据
|
|
@@ -179,9 +180,184 @@ public class TXinyiMedicineParamServiceImpl implements ITXinyiMedicineParamServi
|
|
|
}
|
|
|
//todo 调用组态,获取投加状态
|
|
|
latestRecord.setAddType(Math.random() < 0.5 ? 0 : 1);
|
|
|
+ //2024年09月18日10:26:57 把实时的计算的碳源投加总量 和 瞬时加药量也返回
|
|
|
+ this.addExtra(latestRecord);
|
|
|
return latestRecord;
|
|
|
}
|
|
|
|
|
|
+ private void addExtra(TXinyiMedicineParam latestRecord) {
|
|
|
+ /*BigDecimal total = this.calculateMedicineByLastRecord(latestRecord);
|
|
|
+ latestRecord.setMedicineAmount(total);
|
|
|
+ BigDecimal yymd = latestRecord.getYymd();
|
|
|
+ if(!Objects.isNull(total) && !Objects.isNull(yymd) && yymd.compareTo(BigDecimal.ZERO) > 0){
|
|
|
+ latestRecord.setTytjTransientLL(DecimalUtils.getNLengthHalfUp(total.divide(yymd, NUMBER_SCALE_10, RoundingMode.HALF_UP).divide(BigDecimal_1000, NUMBER_SCALE_10, RoundingMode.HALF_UP), INT_3));
|
|
|
+ }*/
|
|
|
+ latestRecord.setMedicineAmount(this.calculateMedicineByLastRecord(latestRecord));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private BigDecimal calculateMedicineByLastRecord(TXinyiMedicineParam param) {
|
|
|
+ if (Objects.isNull(param)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ //计算用到的值
|
|
|
+ Integer hycXsyType = param.getHycXsyType();
|
|
|
+ BigDecimal hycXsyOne = param.getHycXsyOne();
|
|
|
+ BigDecimal hycXsyTwo = param.getHycXsyTwo();
|
|
|
+
|
|
|
+ BigDecimal htfksd = param.getHtfksd();
|
|
|
+
|
|
|
+ Integer qycAdType = param.getQycAdType();
|
|
|
+ BigDecimal qycAdOne = param.getQycAdOne();
|
|
|
+ BigDecimal qycAdTwo = param.getQycAdTwo();
|
|
|
+
|
|
|
+ Integer qycYxyType = param.getQycYxyType();
|
|
|
+ BigDecimal qycYxyOne = param.getQycYxyOne();
|
|
|
+ BigDecimal qycYxyTwo = param.getQycYxyTwo();
|
|
|
+
|
|
|
+ BigDecimal xzxs = param.getXzxs();
|
|
|
+
|
|
|
+ BigDecimal jzxs = param.getJzxs();
|
|
|
+
|
|
|
+ Integer jsLlType = param.getJsLlType();
|
|
|
+ BigDecimal jsLlOne = param.getJsLlOne();//两个池子的值是一样的
|
|
|
+
|
|
|
+ BigDecimal slfpxs = param.getSlfpxs();
|
|
|
+
|
|
|
+ BigDecimal kzxs = param.getKzxs();
|
|
|
+
|
|
|
+ Integer jsCodType = param.getJsCodType();
|
|
|
+ BigDecimal jsCodOne = param.getJsCodOne();
|
|
|
+ BigDecimal jsCodTwo = param.getJsCodTwo();
|
|
|
+
|
|
|
+ BigDecimal zhxs = param.getZhxs();
|
|
|
+
|
|
|
+ BigDecimal tydl = param.getTydl();
|
|
|
+
|
|
|
+ BigDecimal medicineAmount = param.getMedicineAmount();//手动需要
|
|
|
+
|
|
|
+ Integer type = param.getType();//0自动 1一号池 2二号池 3人工投放
|
|
|
+
|
|
|
+ BigDecimal yymd = param.getYymd();
|
|
|
+
|
|
|
+ //计算
|
|
|
+ if(!Objects.isNull(type)) {
|
|
|
+ if(3 == type){
|
|
|
+ return medicineAmount;
|
|
|
+ }
|
|
|
+ //计算1号池的值
|
|
|
+ BigDecimal oneResult = this.getResultByDiff(hycXsyType, hycXsyOne, htfksd, qycAdType, qycAdOne, qycYxyType, qycYxyOne, xzxs, jzxs, jsLlType, jsLlOne, slfpxs, kzxs, jsCodType, jsCodOne, zhxs, tydl, "one", yymd);
|
|
|
+ //计算二号池的值
|
|
|
+ BigDecimal twoResult = this.getResultByDiff(hycXsyType, hycXsyTwo, htfksd, qycAdType, qycAdTwo, qycYxyType, qycYxyTwo, xzxs, jzxs, jsLlType, jsLlOne, slfpxs, kzxs, jsCodType, jsCodTwo, zhxs, tydl, "two", yymd);
|
|
|
+ //判断,返回值
|
|
|
+ if(0 == type)
|
|
|
+ return oneResult.compareTo(twoResult) > 0 ? oneResult : twoResult;
|
|
|
+ else if(1 == type) {
|
|
|
+ return oneResult;
|
|
|
+ }else if(2 == type)
|
|
|
+ return twoResult;
|
|
|
+ else {
|
|
|
+ return null;//错误的配置
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private BigDecimal getResultByDiff(Integer hycXsyType, BigDecimal hycXsyVal, BigDecimal htfksd, Integer qycAdType, BigDecimal qycAdVal, Integer qycYxyType,
|
|
|
+ BigDecimal qycYxyVal, BigDecimal xzxs, BigDecimal jzxs, Integer jsLlType, BigDecimal jsLlVal, BigDecimal slfpxs, BigDecimal kzxs, Integer jsCodType,
|
|
|
+ BigDecimal jsCodVal, BigDecimal zhxs, BigDecimal tydl, String whichCZ, BigDecimal yymd) {
|
|
|
+ //2024年09月14日10:26:11 不同池子,根据不同类型,获取最新的数据,计算碳源投加量
|
|
|
+ //获取最新的实时数据
|
|
|
+ SmartAdd smartAdd = this.frontService.smartAddDataInfo();
|
|
|
+ if(!Objects.isNull(smartAdd)){
|
|
|
+ if("one".equals(whichCZ)){//一池
|
|
|
+ if(!Objects.isNull(hycXsyType)){
|
|
|
+ if(1 == hycXsyType){//化验
|
|
|
+ hycXsyVal = smartAdd.getHyXsyHYOne();
|
|
|
+ }else if(2 == hycXsyType){//预测
|
|
|
+ hycXsyVal = smartAdd.getHyXsyYCOne();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!Objects.isNull(qycAdType) && 1 == qycAdType){//化验
|
|
|
+ qycAdVal = smartAdd.getQyAdHYOne();
|
|
|
+ }
|
|
|
+ if(!Objects.isNull(qycYxyType) && 1 == qycYxyType){//化验
|
|
|
+ qycYxyVal = smartAdd.getQyXsyHYOne();
|
|
|
+ }
|
|
|
+ if(!Objects.isNull(jsCodType)){
|
|
|
+ if(1 == jsCodType){//仪表
|
|
|
+ jsCodVal = smartAdd.getJsCodYB();
|
|
|
+ }else if(2 == jsCodType){//化验
|
|
|
+ jsCodVal = smartAdd.getJsCodHY();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!Objects.isNull(jsLlType) && 1 == jsLlType){//仪表
|
|
|
+ jsLlVal = smartAdd.getJslYB();
|
|
|
+ }
|
|
|
+ }else {//二池
|
|
|
+ if(!Objects.isNull(hycXsyType)){
|
|
|
+ if(1 == hycXsyType){//化验
|
|
|
+ hycXsyVal = smartAdd.getHyXsyHYTwo();
|
|
|
+ }else if(2 == hycXsyType){//预测
|
|
|
+ hycXsyVal = smartAdd.getHyXsyYCTwo();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!Objects.isNull(qycAdType) && 1 == qycAdType){//化验
|
|
|
+ qycAdVal = smartAdd.getQyAdHYTwo();
|
|
|
+ }
|
|
|
+ if(!Objects.isNull(qycYxyType) && 1 == qycYxyType){//化验
|
|
|
+ qycYxyVal = smartAdd.getQyXsyHYTwo();
|
|
|
+ }
|
|
|
+ if(!Objects.isNull(jsCodType)){
|
|
|
+ if(1 == jsCodType){//仪表
|
|
|
+ jsCodVal = smartAdd.getJsCodYB();
|
|
|
+ }else if(2 == jsCodType){//化验
|
|
|
+ jsCodVal = smartAdd.getJsCodHY();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!Objects.isNull(jsLlType) && 1 == jsLlType){//仪表
|
|
|
+ jsLlVal = smartAdd.getJslYB();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //兜底处理
|
|
|
+ if(Objects.isNull(hycXsyVal))
|
|
|
+ hycXsyVal = BigDecimal.ZERO;
|
|
|
+ if(Objects.isNull(htfksd))
|
|
|
+ htfksd = BigDecimal.ZERO;
|
|
|
+ if(Objects.isNull(qycAdVal))
|
|
|
+ qycAdVal = BigDecimal.ZERO;
|
|
|
+ if(Objects.isNull(qycYxyVal))
|
|
|
+ qycYxyVal = BigDecimal.ZERO;
|
|
|
+ if(Objects.isNull(xzxs))
|
|
|
+ xzxs = BigDecimal.ZERO;
|
|
|
+ if(Objects.isNull(jzxs))
|
|
|
+ jzxs = BigDecimal.ZERO;
|
|
|
+ if(Objects.isNull(jsLlVal))
|
|
|
+ jsLlVal = BigDecimal.ZERO;
|
|
|
+ if(Objects.isNull(slfpxs))
|
|
|
+ slfpxs = BigDecimal.ZERO;
|
|
|
+ if(Objects.isNull(kzxs))
|
|
|
+ kzxs = BigDecimal.ZERO;
|
|
|
+ if(Objects.isNull(jsCodVal))
|
|
|
+ jsCodVal = BigDecimal.ZERO;
|
|
|
+ if(Objects.isNull(zhxs))
|
|
|
+ zhxs = BigDecimal.ZERO;
|
|
|
+ if(Objects.isNull(tydl))
|
|
|
+ tydl = BigDecimal.ZERO;
|
|
|
+ if(Objects.isNull(yymd) || yymd.compareTo(BigDecimal.ZERO) <= 0)
|
|
|
+ return null;//除数不能为0
|
|
|
+ //1)计算挟走量
|
|
|
+ BigDecimal xzl = (((BigDecimal_2.multiply(hycXsyVal).subtract(htfksd)).add(((qycAdVal.add(qycYxyVal)).multiply(xzxs).subtract(htfksd)))).multiply((jzxs.subtract(BigDecimal_1)))).multiply((jsLlVal.multiply(slfpxs))).divide(BigDecimal_1000, NUMBER_SCALE_4, RoundingMode.HALF_UP);
|
|
|
+ //2)计算碳源投加总量
|
|
|
+ BigDecimal total = (xzl.multiply(kzxs).subtract((jsLlVal.multiply(slfpxs).multiply(jsCodVal).multiply(zhxs).divide(BigDecimal_1000, NUMBER_SCALE_4, RoundingMode.HALF_UP)))).divide(tydl, NUMBER_SCALE_4, RoundingMode.HALF_UP);
|
|
|
+ //2024年09月14日15:33:37 计算出来的结果太大,是几千,把第三步公式也加上
|
|
|
+ //计算加药流量
|
|
|
+ return DecimalUtils.getNLengthHalfUp(total.divide(yymd, NUMBER_SCALE_10, RoundingMode.HALF_UP).divide(BigDecimal_1000, NUMBER_SCALE_10, RoundingMode.HALF_UP), INT_3);
|
|
|
+ }
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
|
System.out.println(Math.random() < 0.5 ? 0 : 1);
|
|
|
}
|