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 3f1408c4..4efbfd6b 100644 --- a/src/main/java/cn/lihongjie/coal/coalBlend/entity/CoalBlendEntity.java +++ b/src/main/java/cn/lihongjie/coal/coalBlend/entity/CoalBlendEntity.java @@ -60,6 +60,18 @@ public class CoalBlendEntity extends OrgCommonEntity { + " and i.code = blend_type)") private String blendTypeName; + @Comment("煤类型") + private String coalType; + + @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 = 'coalBlend.coalType'\n" + + " and i.code = coal_type)") + private String coalTypeName; + @Comment("结果个数") private Integer count = 20; @@ -282,52 +294,83 @@ public class CoalBlendEntity extends OrgCommonEntity { }); IntVar[] percentValArr = percentVal.toJavaArray(IntVar[]::new); - // 各个煤累加和 100 - model.addEquality(LinearExpr.sum(percentValArr), 100); + + boolean isJM = StringUtils.isEmpty(coalType) || StringUtils.equalsIgnoreCase(coalType, "0"); + boolean isYM = StringUtils.equalsIgnoreCase(coalType, "2"); + if (isJM) { + + // 各个煤累加和 100 + model.addEquality(LinearExpr.sum(percentValArr), 100); + } else { + if (isYM) { + // 原煤配煤比例小于等于 100 + model.addLessOrEqual(LinearExpr.sum(percentValArr), 100); + } + } addBaseConstrain(model, percentValArr); IntVar gcd = model.newIntVar(2, 100, "gcd"); Stream gcdVal = null; - if (Objects.equals(blendType, "2")) { + if (isJM) { - 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)); + if (Objects.equals(blendType, "2")) { - model.addLessOrEqual( - LinearExpr.sum(gcdVal.toJavaArray(IntVar[]::new)), 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)); - if (StringUtils.isNotEmpty(targetParam)) { - if (targetOrder == -1) { + model.addLessOrEqual( + LinearExpr.sum(gcdVal.toJavaArray(IntVar[]::new)), type2PercentSum); + } - model.maximize( - LinearExpr.weightedSum( - percentValArr, - coals.stream() - .mapToLong(x -> (long) (x.getParam(targetParam) * 100)) - .toArray())); + if (StringUtils.isNotEmpty(targetParam)) { + if (targetOrder == -1) { - } else { + model.maximize( + LinearExpr.weightedSum( + percentValArr, + coals.stream() + .mapToLong(x -> (long) (x.getParam(targetParam) * 100)) + .toArray())); - model.minimize( - 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())); + } } } + + if (isYM){ + + + int coalSize = coals.size(); + long[] weightArr = new long[coalSize]; + + for (int i = 0; i < coalSize; i++) { + + + weightArr[i] = (long) (Math.pow(100, coalSize - i)); + + } + + model.maximize(LinearExpr.weightedSum(percentValArr, weightArr)); + } + stopWatch.stop(); stopWatch.start("CpSolver"); diff --git a/src/main/resources/config/dictionary.json b/src/main/resources/config/dictionary.json index 11abcaf8..eb256637 100644 --- a/src/main/resources/config/dictionary.json +++ b/src/main/resources/config/dictionary.json @@ -1930,6 +1930,22 @@ ] }, + + { + "code": "coalBlend.coalType", + "name": "配煤-煤类型", + "item": [ + { + "code": "0", + "name": "精煤" + }, + { + "code": "2", + "name": "原煤" + } + + ] + }, { "code": "inventoryCheck.type", "name": "库存盘点类型", diff --git a/src/main/resources/db/migration/V25__coalBlendCoalType.sql b/src/main/resources/db/migration/V25__coalBlendCoalType.sql new file mode 100644 index 00000000..85d18483 --- /dev/null +++ b/src/main/resources/db/migration/V25__coalBlendCoalType.sql @@ -0,0 +1 @@ +update t_coal_blend set coal_type = '0' where coal_type is null;