diff --git a/src/main/java/cn/lihongjie/coal/base/dto/CommonQuery.java b/src/main/java/cn/lihongjie/coal/base/dto/CommonQuery.java index 62ff31ac..3b179e31 100644 --- a/src/main/java/cn/lihongjie/coal/base/dto/CommonQuery.java +++ b/src/main/java/cn/lihongjie/coal/base/dto/CommonQuery.java @@ -466,6 +466,18 @@ public class CommonQuery { } private static Predicate getPredicate(Root root, CriteriaBuilder criteriaBuilder, QueryItem x, ConversionService conversionService) { + + if (x.key.contains(".")) { + + Function4 function4 = map.get(Tuple.of(x.opt, String.class)); + + if (function4 == null) { + throw new RuntimeException("无法识别的查询 " + x); + } + + return function4.apply(root, criteriaBuilder, x, conversionService); + } + EntityType entityType = root.getModel(); diff --git a/src/main/java/cn/lihongjie/coal/coalBlend/dto/CoalBlendDto.java b/src/main/java/cn/lihongjie/coal/coalBlend/dto/CoalBlendDto.java index 791b02c7..0b109679 100644 --- a/src/main/java/cn/lihongjie/coal/coalBlend/dto/CoalBlendDto.java +++ b/src/main/java/cn/lihongjie/coal/coalBlend/dto/CoalBlendDto.java @@ -1,9 +1,10 @@ package cn.lihongjie.coal.coalBlend.dto; -import cn.lihongjie.coal.coalBlend.entity.*; import cn.lihongjie.coal.base.dto.OrgCommonDto; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; +import cn.lihongjie.coal.coalBlend.entity.CoalBlendCoalInfoEntity; +import cn.lihongjie.coal.coalBlend.entity.CoalBlendConstrainVo; +import cn.lihongjie.coal.coalBlend.entity.CoalBlendResultInfoEntity; +import cn.lihongjie.coal.coalBlend.entity.CoalParameterDefVo; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; @@ -29,10 +30,8 @@ public class CoalBlendDto extends OrgCommonDto { private List results; - @Enumerated(value = EnumType.STRING) - @NotNull() - private CoalBlendType type; - + private String blendTypeName; + private String blendType; @Comment("结果个数") private Integer count = 20; diff --git a/src/main/java/cn/lihongjie/coal/coalBlend/dto/CreateCoalBlendDto.java b/src/main/java/cn/lihongjie/coal/coalBlend/dto/CreateCoalBlendDto.java index 5acd9ea1..56949ac2 100644 --- a/src/main/java/cn/lihongjie/coal/coalBlend/dto/CreateCoalBlendDto.java +++ b/src/main/java/cn/lihongjie/coal/coalBlend/dto/CreateCoalBlendDto.java @@ -1,9 +1,10 @@ package cn.lihongjie.coal.coalBlend.dto; import cn.lihongjie.coal.base.dto.OrgCommonDto; -import cn.lihongjie.coal.coalBlend.entity.*; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; +import cn.lihongjie.coal.coalBlend.entity.CoalBlendCoalInfoEntity; +import cn.lihongjie.coal.coalBlend.entity.CoalBlendConstrainVo; +import cn.lihongjie.coal.coalBlend.entity.CoalBlendResultInfoEntity; +import cn.lihongjie.coal.coalBlend.entity.CoalParameterDefVo; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; @@ -29,9 +30,8 @@ public class CreateCoalBlendDto extends OrgCommonDto { private List results; - @Enumerated(value = EnumType.STRING) - @NotNull() - private CoalBlendType type; + private String blendTypeName; + private String blendType; @Comment("结果个数") diff --git a/src/main/java/cn/lihongjie/coal/coalBlend/dto/UpdateCoalBlendDto.java b/src/main/java/cn/lihongjie/coal/coalBlend/dto/UpdateCoalBlendDto.java index c8ffcc4c..c3755c6e 100644 --- a/src/main/java/cn/lihongjie/coal/coalBlend/dto/UpdateCoalBlendDto.java +++ b/src/main/java/cn/lihongjie/coal/coalBlend/dto/UpdateCoalBlendDto.java @@ -1,9 +1,10 @@ package cn.lihongjie.coal.coalBlend.dto; import cn.lihongjie.coal.base.dto.OrgCommonDto; -import cn.lihongjie.coal.coalBlend.entity.*; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; +import cn.lihongjie.coal.coalBlend.entity.CoalBlendCoalInfoEntity; +import cn.lihongjie.coal.coalBlend.entity.CoalBlendConstrainVo; +import cn.lihongjie.coal.coalBlend.entity.CoalBlendResultInfoEntity; +import cn.lihongjie.coal.coalBlend.entity.CoalParameterDefVo; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; @@ -28,10 +29,8 @@ public class UpdateCoalBlendDto extends OrgCommonDto { private CoalBlendConstrainVo constrains; private List results; - - @Enumerated(value = EnumType.STRING) - @NotNull() - private CoalBlendType type; + private String blendTypeName; + private String blendType; @Comment("结果个数") diff --git a/src/main/java/cn/lihongjie/coal/coalBlend/entity/CoalBlendEntity.java b/src/main/java/cn/lihongjie/coal/coalBlend/entity/CoalBlendEntity.java index 5cc69f7b..a0c9db4a 100644 --- a/src/main/java/cn/lihongjie/coal/coalBlend/entity/CoalBlendEntity.java +++ b/src/main/java/cn/lihongjie/coal/coalBlend/entity/CoalBlendEntity.java @@ -10,8 +10,11 @@ import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import lombok.Data; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.hibernate.annotations.Comment; +import org.hibernate.annotations.Formula; +import org.springframework.util.StopWatch; import java.util.ArrayList; import java.util.List; @@ -21,6 +24,7 @@ import java.util.concurrent.atomic.AtomicBoolean; @Entity @Data @Comment("配煤记录") +@Slf4j public class CoalBlendEntity extends OrgCommonEntity { @@ -44,6 +48,20 @@ public class CoalBlendEntity extends OrgCommonEntity { private CoalBlendType type; + @Comment("配煤类型") + private String blendType; + + + @Formula("(select i.name\n" + + "from t_dictionary d,\n" + + " t_dictionary_item i\n" + + "where d.id = i.dictionary_id\n" + + " and d.code = 'blend_type'\n" + + " and i.code = coal.blend_type)") + private String blendTypeName; + + + @Comment("结果个数") private Integer count = 20; @@ -68,216 +86,224 @@ public class CoalBlendEntity extends OrgCommonEntity { public void blend() { + StopWatch stopWatch = new StopWatch(); this.results = new ArrayList<>(); - + stopWatch.start("check 1"); long count1 = 0; count1 = coals.stream().map(x1 -> x1.getParam1()).filter(Objects::nonNull).count(); AtomicBoolean param1 = new AtomicBoolean(false); - if (count1 != coals.size()) { + if (count1> 0 && count1 != coals.size()) { throw new BizException("煤的参数不可以留空"); }else { - param1.set(true); + param1.set(count1>0); } count1 = coals.stream().map(x1 -> x1.getParam2()).filter(Objects::nonNull).count(); AtomicBoolean param2 = new AtomicBoolean(false); - if (count1 != coals.size()) { + if (count1> 0 && count1 != coals.size()) { throw new BizException("煤的参数不可以留空"); }else { - param2.set(true); + param2.set(count1>0); } count1 = coals.stream().map(x1 -> x1.getParam3()).filter(Objects::nonNull).count(); AtomicBoolean param3 = new AtomicBoolean(false); - if (count1 != coals.size()) { + if (count1> 0 && count1 != coals.size()) { throw new BizException("煤的参数不可以留空"); }else { - param3.set(true); + param3.set(count1>0); } count1 = coals.stream().map(x1 -> x1.getParam4()).filter(Objects::nonNull).count(); AtomicBoolean param4 = new AtomicBoolean(false); - if (count1 != coals.size()) { + if (count1> 0 && count1 != coals.size()) { throw new BizException("煤的参数不可以留空"); }else { - param4.set(true); + param4.set(count1>0); } count1 = coals.stream().map(x1 -> x1.getParam5()).filter(Objects::nonNull).count(); AtomicBoolean param5 = new AtomicBoolean(false); - if (count1 != coals.size()) { + if (count1> 0 && count1 != coals.size()) { throw new BizException("煤的参数不可以留空"); }else { - param5.set(true); + param5.set(count1>0); } count1 = coals.stream().map(x1 -> x1.getParam6()).filter(Objects::nonNull).count(); AtomicBoolean param6 = new AtomicBoolean(false); - if (count1 != coals.size()) { + if (count1> 0 && count1 != coals.size()) { throw new BizException("煤的参数不可以留空"); }else { - param6.set(true); + param6.set(count1>0); } count1 = coals.stream().map(x1 -> x1.getParam7()).filter(Objects::nonNull).count(); AtomicBoolean param7 = new AtomicBoolean(false); - if (count1 != coals.size()) { + if (count1> 0 && count1 != coals.size()) { throw new BizException("煤的参数不可以留空"); }else { - param7.set(true); + param7.set(count1>0); } count1 = coals.stream().map(x1 -> x1.getParam8()).filter(Objects::nonNull).count(); AtomicBoolean param8 = new AtomicBoolean(false); - if (count1 != coals.size()) { + if (count1> 0 && count1 != coals.size()) { throw new BizException("煤的参数不可以留空"); }else { - param8.set(true); + param8.set(count1>0); } count1 = coals.stream().map(x1 -> x1.getParam9()).filter(Objects::nonNull).count(); AtomicBoolean param9 = new AtomicBoolean(false); - if (count1 != coals.size()) { + if (count1> 0 && count1 != coals.size()) { throw new BizException("煤的参数不可以留空"); }else { - param9.set(true); + param9.set(count1>0); } count1 = coals.stream().map(x1 -> x1.getParam10()).filter(Objects::nonNull).count(); AtomicBoolean param10 = new AtomicBoolean(false); - if (count1 != coals.size()) { + if (count1> 0 && count1 != coals.size()) { throw new BizException("煤的参数不可以留空"); }else { - param10.set(true); + param10.set(count1>0); } count1 = coals.stream().map(x1 -> x1.getParam11()).filter(Objects::nonNull).count(); AtomicBoolean param11 = new AtomicBoolean(false); - if (count1 != coals.size()) { + if (count1> 0 && count1 != coals.size()) { throw new BizException("煤的参数不可以留空"); }else { - param11.set(true); + param11.set(count1>0); } count1 = coals.stream().map(x1 -> x1.getParam12()).filter(Objects::nonNull).count(); AtomicBoolean param12 = new AtomicBoolean(false); - if (count1 != coals.size()) { + if (count1> 0 && count1 != coals.size()) { throw new BizException("煤的参数不可以留空"); }else { - param12.set(true); + param12.set(count1>0); } count1 = coals.stream().map(x1 -> x1.getParam13()).filter(Objects::nonNull).count(); AtomicBoolean param13 = new AtomicBoolean(false); - if (count1 != coals.size()) { + if (count1> 0 && count1 != coals.size()) { throw new BizException("煤的参数不可以留空"); }else { - param13.set(true); + param13.set(count1>0); } count1 = coals.stream().map(x1 -> x1.getParam14()).filter(Objects::nonNull).count(); AtomicBoolean param14 = new AtomicBoolean(false); - if (count1 != coals.size()) { + if (count1> 0 && count1 != coals.size()) { throw new BizException("煤的参数不可以留空"); }else { - param14.set(true); + param14.set(count1>0); } count1 = coals.stream().map(x1 -> x1.getParam15()).filter(Objects::nonNull).count(); AtomicBoolean param15 = new AtomicBoolean(false); - if (count1 != coals.size()) { + if (count1> 0 && count1 != coals.size()) { throw new BizException("煤的参数不可以留空"); }else { - param15.set(true); + param15.set(count1>0); } count1 = coals.stream().map(x1 -> x1.getParam16()).filter(Objects::nonNull).count(); AtomicBoolean param16 = new AtomicBoolean(false); - if (count1 != coals.size()) { + if (count1> 0 && count1 != coals.size()) { throw new BizException("煤的参数不可以留空"); }else { - param16.set(true); + param16.set(count1>0); } count1 = coals.stream().map(x1 -> x1.getParam17()).filter(Objects::nonNull).count(); AtomicBoolean param17 = new AtomicBoolean(false); - if (count1 != coals.size()) { + if (count1> 0 && count1 != coals.size()) { throw new BizException("煤的参数不可以留空"); }else { - param17.set(true); + param17.set(count1>0); } count1 = coals.stream().map(x1 -> x1.getParam18()).filter(Objects::nonNull).count(); AtomicBoolean param18 = new AtomicBoolean(false); - if (count1 != coals.size()) { + if (count1> 0 && count1 != coals.size()) { throw new BizException("煤的参数不可以留空"); }else { - param18.set(true); + param18.set(count1>0); } count1 = coals.stream().map(x1 -> x1.getParam19()).filter(Objects::nonNull).count(); AtomicBoolean param19 = new AtomicBoolean(false); - if (count1 != coals.size()) { + if (count1> 0 && count1 != coals.size()) { throw new BizException("煤的参数不可以留空"); }else { - param19.set(true); + param19.set(count1>0); } count1 = coals.stream().map(x1 -> x1.getParam20()).filter(Objects::nonNull).count(); AtomicBoolean param20 = new AtomicBoolean(false); - if (count1 != coals.size()) { + if (count1> 0 && count1 != coals.size()) { throw new BizException("煤的参数不可以留空"); }else { - param20.set(true); + param20.set(count1>0); } + stopWatch.stop(); + stopWatch.start("loadNativeLibraries"); Loader.loadNativeLibraries(); + + stopWatch.stop(); + stopWatch.start("CpModel"); CpModel model = new CpModel(); - Stream percentVal = Stream.ofAll(coals).zipWithIndex((c, i) -> model.newIntVar(c.getMinPercent(), c.getMaxPercent(), "x" + i)); + Stream percentVal = Stream.ofAll(coals).zipWithIndex((c, i) -> { + return model.newIntVar(c.getMinPercent(), c.getMaxPercent(), "x" + i); + }); IntVar[] percentValArr = percentVal.toJavaArray(IntVar[]::new); // 各个煤累加和 100 model.addEquality(LinearExpr.sum(percentValArr), 100); - addBaseConstrain(model, percentValArr); - IntVar gcd = model.newIntVar(1, 100, "gcd"); - Stream gcdVal = Stream.ofAll(coals).zipWithIndex((c, i) -> model.newIntVar(c.getMinPercent(), c.getMaxPercent(), "gcdX" + i)); - IntVar[] gcdValArr = percentVal.toJavaArray(IntVar[]::new); - - if (type == CoalBlendType.TYPE2) { + IntVar gcd = model.newIntVar(2, 100, "gcd"); + Stream gcdVal = null; - percentVal.zip(gcdVal).forEach(t -> model.addModuloEquality(t._2, t._1, gcd)); + if (Objects.equals(blendType, "2")) { - model.addLessOrEqual(LinearExpr.sum(gcdValArr), type2PercentSum); + gcdVal = Stream.ofAll(coals).zipWithIndex((c, i) -> model.newIntVar(c.getMinPercent(), c.getMaxPercent(), "gcdX" + i)); + percentVal.zip(gcdVal).forEach(t -> model.addDivisionEquality(t._2, t._1, gcd)); + percentVal.zip(gcdVal).forEach(t -> model.addModuloEquality(LinearExpr.constant(0), t._1, gcd)); + + model.addLessOrEqual(LinearExpr.sum(gcdVal.toJavaArray(IntVar[]::new)) , type2PercentSum); } @@ -286,64 +312,108 @@ public class CoalBlendEntity extends OrgCommonEntity { if (targetOrder == -1) { model.maximize(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam(targetParam) * 100)).toArray())); + } else { model.minimize(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam(targetParam) * 100)).toArray())); + } } - + stopWatch.stop(); + stopWatch.start("CpSolver"); // 初始化求解器 CpSolver cpSolver = new CpSolver(); SatParameters.Builder parameters = cpSolver.getParameters(); parameters.setEnumerateAllSolutions(true); parameters.setMaxTimeInSeconds(this.getMaxTime()); - parameters.setLogSearchProgress(false); + parameters.setLogSearchProgress(true); + cpSolver.setLogCallback((x) -> { + }); parameters.setFillAdditionalSolutionsInResponse(true); - cpSolver.solve(model, new CpSolverSolutionCallback() { + Stream finalGcdVal = gcdVal; + try { - @Override - public void onSolutionCallback() { + cpSolver.solve(model, new CpSolverSolutionCallback() { - CoalBlendResultInfoEntity vo = new CoalBlendResultInfoEntity(); + @Override + public void onSolutionCallback() { + + CoalBlendResultInfoEntity vo = new CoalBlendResultInfoEntity(); - vo.setPercentInfos(Stream.ofAll(coals).zip(percentVal).zip(gcdVal).map(t -> new CoalPercentVo(t._1._1.getName(), ((double) (value(t._1._2))), (double) value(t._2))).toJavaList()); - if (param1.get()) vo.setParam1(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam1() * 100)).toArray()))/ 10000.0); - if (param2.get()) vo.setParam2(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam2() * 100)).toArray()))/ 10000.0); - if (param3.get()) vo.setParam3(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam3() * 100)).toArray()))/ 10000.0); - if (param4.get()) vo.setParam4(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam4() * 100)).toArray()))/ 10000.0); - if (param5.get()) vo.setParam5(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam5() * 100)).toArray()))/ 10000.0); - if (param6.get()) vo.setParam6(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam6() * 100)).toArray()))/ 10000.0); - if (param7.get()) vo.setParam7(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam7() * 100)).toArray()))/ 10000.0); - if (param8.get()) vo.setParam8(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam8() * 100)).toArray()))/ 10000.0); - if (param9.get()) vo.setParam9(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam9() * 100)).toArray()))/ 10000.0); - if (param10.get()) vo.setParam10(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam10() * 100)).toArray()))/ 10000.0); - if (param11.get()) vo.setParam11(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam11() * 100)).toArray()))/ 10000.0); - if (param12.get()) vo.setParam12(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam12() * 100)).toArray()))/ 10000.0); - if (param13.get()) vo.setParam13(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam13() * 100)).toArray()))/ 10000.0); - if (param14.get()) vo.setParam14(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam14() * 100)).toArray()))/ 10000.0); - if (param15.get()) vo.setParam15(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam15() * 100)).toArray()))/ 10000.0); - if (param16.get()) vo.setParam16(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam16() * 100)).toArray()))/ 10000.0); - if (param17.get()) vo.setParam17(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam17() * 100)).toArray()))/ 10000.0); - if (param18.get()) vo.setParam18(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam18() * 100)).toArray()))/ 10000.0); - if (param19.get()) vo.setParam19(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam19() * 100)).toArray()))/ 10000.0); - if (param20.get()) vo.setParam20(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam20() * 100)).toArray()))/ 10000.0); + if (finalGcdVal != null) { + + vo.setPercentInfos(Stream.ofAll(coals).zip(percentVal).zip(finalGcdVal).map(t -> new CoalPercentVo(t._1._1.getName(), ((double) (value(t._1._2))), (double) value(t._2))).toJavaList()); + } else { + vo.setPercentInfos(Stream.ofAll(coals).zip(percentVal).zip(percentVal).map(t -> new CoalPercentVo(t._1._1.getName(), ((double) (value(t._1._2))), (double) value(t._2))).toJavaList()); + } + if (param1.get()) + vo.setParam1(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam1() * 100)).toArray())) / 10000.0); + if (param2.get()) + vo.setParam2(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam2() * 100)).toArray())) / 10000.0); + if (param3.get()) + vo.setParam3(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam3() * 100)).toArray())) / 10000.0); + if (param4.get()) + vo.setParam4(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam4() * 100)).toArray())) / 10000.0); + if (param5.get()) + vo.setParam5(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam5() * 100)).toArray())) / 10000.0); + if (param6.get()) + vo.setParam6(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam6() * 100)).toArray())) / 10000.0); + if (param7.get()) + vo.setParam7(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam7() * 100)).toArray())) / 10000.0); + if (param8.get()) + vo.setParam8(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam8() * 100)).toArray())) / 10000.0); + if (param9.get()) + vo.setParam9(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam9() * 100)).toArray())) / 10000.0); + if (param10.get()) + vo.setParam10(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam10() * 100)).toArray())) / 10000.0); + if (param11.get()) + vo.setParam11(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam11() * 100)).toArray())) / 10000.0); + if (param12.get()) + vo.setParam12(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam12() * 100)).toArray())) / 10000.0); + if (param13.get()) + vo.setParam13(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam13() * 100)).toArray())) / 10000.0); + if (param14.get()) + vo.setParam14(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam14() * 100)).toArray())) / 10000.0); + if (param15.get()) + vo.setParam15(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam15() * 100)).toArray())) / 10000.0); + if (param16.get()) + vo.setParam16(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam16() * 100)).toArray())) / 10000.0); + if (param17.get()) + vo.setParam17(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam17() * 100)).toArray())) / 10000.0); + if (param18.get()) + vo.setParam18(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam18() * 100)).toArray())) / 10000.0); + if (param19.get()) + vo.setParam19(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam19() * 100)).toArray())) / 10000.0); + if (param20.get()) + vo.setParam20(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam20() * 100)).toArray())) / 10000.0); - CoalBlendEntity.this.results.add(vo); + CoalBlendEntity.this.results.add(vo); - if (CoalBlendEntity.this.results.size() >= CoalBlendEntity.this.count) { - stopSearch(); + if (CoalBlendEntity.this.results.size() >= CoalBlendEntity.this.count) { + stopSearch(); + + } } + }); + } catch (Throwable e) { + log.error("{}", e); + + }finally { + + if (stopWatch.isRunning()) { + + stopWatch.stop(); } - }); - + log.info(stopWatch.prettyPrint()); + } diff --git a/src/main/java/cn/lihongjie/coal/coalBlend/service/CoalBlendService.java b/src/main/java/cn/lihongjie/coal/coalBlend/service/CoalBlendService.java index 3b2937e1..bc535fd3 100644 --- a/src/main/java/cn/lihongjie/coal/coalBlend/service/CoalBlendService.java +++ b/src/main/java/cn/lihongjie/coal/coalBlend/service/CoalBlendService.java @@ -9,6 +9,7 @@ import cn.lihongjie.coal.coalBlend.dto.UpdateCoalBlendDto; import cn.lihongjie.coal.coalBlend.entity.CoalBlendEntity; import cn.lihongjie.coal.coalBlend.mapper.CoalBlendMapper; import cn.lihongjie.coal.coalBlend.repository.CoalBlendRepository; +import cn.lihongjie.coal.coalWashingDailyAnalysis.mapper.RoundMapper; import jakarta.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -17,6 +18,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; +import org.springframework.util.StopWatch; @Service @Slf4j @@ -86,13 +88,25 @@ public class CoalBlendService extends BaseService