完善配煤

This commit is contained in:
2023-09-18 22:12:11 +08:00
parent 04dd31c55e
commit 86d5c7f85b
10 changed files with 271 additions and 31 deletions

View File

@@ -0,0 +1,105 @@
package cn.lihongjie.coal.coalBlend.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import cn.lihongjie.coal.coalBlend.entity.CoalBlendEntity;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.hibernate.annotations.Comment;
import org.hibernate.validator.constraints.Range;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CoalBlendCoalInfoDto extends OrgCommonDto {
@NotEmpty(message = "煤名称不能为空")
private String name;
@Comment("比例最小值")
@Range(groups = CoalBlendEntity.BlendGroup.class,min = 0, max = 100, message = "无效的比例")
private Integer minPercent;
@Comment("比例最大值")
@Range(groups = CoalBlendEntity.BlendGroup.class,min = 0, max = 100, message = "无效的比例")
private Integer maxPercent;
@Comment("参数 1 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param1;
@Comment("参数 2 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param2;
@Comment("参数 3 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param3;
@Comment("参数 4 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param4;
@Comment("参数 5 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param5;
@Comment("参数 6 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param6;
@Comment("参数 7 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param7;
@Comment("参数 8 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param8;
@Comment("参数 9 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param9;
@Comment("参数 10 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param10;
@Comment("参数 11 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param11;
@Comment("参数 12 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param12;
@Comment("参数 13 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param13;
@Comment("参数 14 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param14;
@Comment("参数 15 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param15;
@Comment("参数 16 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param16;
@Comment("参数 17 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param17;
@Comment("参数 18 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param18;
@Comment("参数 19 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param19;
@Comment("参数 20 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param20;
@SneakyThrows
public Double getParam(String param) {
return (Double) FieldUtils.getField(this.getClass(), param, true).get(this);
}
}

View File

@@ -1,9 +1,7 @@
package cn.lihongjie.coal.coalBlend.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
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;
@@ -24,11 +22,11 @@ public class CoalBlendDto extends OrgCommonDto {
@NotEmpty(message = "煤不能为空")
@Size(message = "至少需要两种煤", min = 2)
private List<CoalBlendCoalInfoEntity> coals;
private List<CoalBlendCoalInfoDto> coals;
@NotNull(message = "约束条件不能为空")
private CoalBlendConstrainVo constrains;
private List<CoalBlendResultInfoEntity> results;
private List<CoalBlendResultInfoDto> results;
private String blendTypeName;
private String blendType;

View File

@@ -0,0 +1,114 @@
package cn.lihongjie.coal.coalBlend.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import cn.lihongjie.coal.coalBlend.entity.CoalBlendEntity;
import cn.lihongjie.coal.coalBlend.entity.CoalPercentVo;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.hibernate.annotations.Comment;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CoalBlendResultInfoDto extends OrgCommonDto {
@NotEmpty(message = "煤名称不能为空")
private String name;
private List<CoalPercentVo> percentInfos;
@Comment("参数 1 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param1;
@Comment("参数 2 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param2;
@Comment("参数 3 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param3;
@Comment("参数 4 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param4;
@Comment("参数 5 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param5;
@Comment("参数 6 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param6;
@Comment("参数 7 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param7;
@Comment("参数 8 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param8;
@Comment("参数 9 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param9;
@Comment("参数 10 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param10;
@Comment("参数 11 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param11;
@Comment("参数 12 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param12;
@Comment("参数 13 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param13;
@Comment("参数 14 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param14;
@Comment("参数 15 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param15;
@Comment("参数 16 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param16;
@Comment("参数 17 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param17;
@Comment("参数 18 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param18;
@Comment("参数 19 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param19;
@Comment("参数 20 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param20;
@SneakyThrows
public Double getParam(String param) {
return (Double) FieldUtils.getField(this.getClass(), param, true).get(this);
}
public long getHashKey(){
return
Arrays.hashCode(this.getPercentInfos().stream().sorted(Comparator.comparing(x->x.getPercent())).toArray(CoalPercentVo[]::new));
}
}

View File

@@ -1,9 +1,7 @@
package cn.lihongjie.coal.coalBlend.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
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;
@@ -24,11 +22,11 @@ public class CreateCoalBlendDto extends OrgCommonDto {
@NotEmpty(message = "煤不能为空")
@Size(message = "至少需要两种煤", min = 2)
private List<CoalBlendCoalInfoEntity> coals;
private List<CoalBlendCoalInfoDto> coals;
@NotNull(message = "约束条件不能为空")
private CoalBlendConstrainVo constrains;
private List<CoalBlendResultInfoEntity> results;
private List<CoalBlendResultInfoDto> results;
private String blendTypeName;
private String blendType;

View File

@@ -1,9 +1,7 @@
package cn.lihongjie.coal.coalBlend.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
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;
@@ -24,11 +22,11 @@ public class UpdateCoalBlendDto extends OrgCommonDto {
@NotEmpty(message = "煤不能为空")
@Size(message = "至少需要两种煤", min = 2)
private List<CoalBlendCoalInfoEntity> coals;
private List<CoalBlendCoalInfoDto> coals;
@NotNull(message = "约束条件不能为空")
private CoalBlendConstrainVo constrains;
private List<CoalBlendResultInfoEntity> results;
private List<CoalBlendResultInfoDto> results;
private String blendTypeName;
private String blendType;

View File

@@ -1,7 +1,6 @@
package cn.lihongjie.coal.coalBlend.entity;
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.DecimalMin;
@@ -11,8 +10,6 @@ import org.apache.commons.lang3.reflect.FieldUtils;
import org.hibernate.annotations.Comment;
import org.hibernate.validator.constraints.Range;
import java.util.List;
@Data
@AllArgsConstructor
@@ -25,7 +22,7 @@ public class CoalBlendCoalInfoEntity extends OrgCommonEntity {
private String name;
@ManyToOne
@ManyToOne()
private CoalBlendEntity coal;

View File

@@ -17,6 +17,7 @@ import org.hibernate.annotations.Formula;
import org.springframework.util.StopWatch;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -35,17 +36,15 @@ public class CoalBlendEntity extends OrgCommonEntity {
@NotEmpty(message = "煤不能为空")
@Size(message = "至少需要两种煤", min = 2)
@OneToMany(mappedBy = "coal" )
@OneToMany(mappedBy = "coal", cascade = CascadeType.ALL, orphanRemoval = true)
private List<CoalBlendCoalInfoEntity> coals;
@NotNull(message = "约束条件不能为空")
private CoalBlendConstrainVo constrains;
@OneToMany(mappedBy = "result")
@OneToMany(mappedBy = "coal", cascade = CascadeType.ALL, orphanRemoval = true)
private List<CoalBlendResultInfoEntity> results;
@Enumerated(value = EnumType.STRING)
@NotNull()
private CoalBlendType type;
@Comment("配煤类型")
@@ -56,8 +55,8 @@ public class CoalBlendEntity extends OrgCommonEntity {
"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)")
" and d.code = 'coal.blendType'\n" +
" and i.code = blend_type)")
private String blendTypeName;
@@ -329,11 +328,11 @@ public class CoalBlendEntity extends OrgCommonEntity {
parameters.setEnumerateAllSolutions(true);
parameters.setMaxTimeInSeconds(this.getMaxTime());
parameters.setLogSearchProgress(true);
cpSolver.setLogCallback((x) -> {
});
parameters.setFillAdditionalSolutionsInResponse(true);
parameters.setFillAdditionalSolutionsInResponse(false);
HashSet<Object> seen = new HashSet<>();
Stream<IntVar> finalGcdVal = gcdVal;
try {
@@ -351,6 +350,10 @@ public class CoalBlendEntity extends OrgCommonEntity {
} 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 (!seen.add(vo.getHashKey())) {
return;
}
if (param1.get())
vo.setParam1(value(LinearExpr.weightedSum(percentValArr, coals.stream().mapToLong(x -> (long) (x.getParam1() * 100)).toArray())) / 10000.0);
if (param2.get())

View File

@@ -5,12 +5,12 @@ import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.NotEmpty;
import lombok.*;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.hibernate.annotations.Comment;
import org.hibernate.validator.constraints.Range;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
@Data
@@ -21,7 +21,6 @@ import java.util.List;
@Entity
public class CoalBlendResultInfoEntity extends OrgCommonEntity {
@NotEmpty(message = "煤名称不能为空")
private String name;
@@ -31,7 +30,7 @@ public class CoalBlendResultInfoEntity extends OrgCommonEntity {
private List<CoalPercentVo> percentInfos;
@ManyToOne
private CoalBlendEntity result;
private CoalBlendEntity coal;
@@ -103,4 +102,14 @@ public class CoalBlendResultInfoEntity extends OrgCommonEntity {
return (Double) FieldUtils.getField(this.getClass(), param, true).get(this);
}
public long getHashKey(){
return
Arrays.hashCode(this.getPercentInfos().stream().sorted(Comparator.comparing(x->x.getPercent())).toArray(CoalPercentVo[]::new));
}
}

View File

@@ -7,8 +7,11 @@ import cn.lihongjie.coal.coalBlend.dto.CoalBlendDto;
import cn.lihongjie.coal.coalBlend.dto.CreateCoalBlendDto;
import cn.lihongjie.coal.coalBlend.dto.UpdateCoalBlendDto;
import cn.lihongjie.coal.coalBlend.entity.CoalBlendEntity;
import org.apache.commons.collections4.CollectionUtils;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.MappingTarget;
import org.mapstruct.control.DeepClone;
@Mapper(
@@ -20,4 +23,19 @@ import org.mapstruct.control.DeepClone;
public interface CoalBlendMapper extends BaseMapper<CoalBlendEntity, CoalBlendDto, CreateCoalBlendDto, UpdateCoalBlendDto> {
@AfterMapping
public default void convertNameToUpperCase(CreateCoalBlendDto dto, @MappingTarget CoalBlendEntity entity) {
if (CollectionUtils.isNotEmpty(entity.getCoals())) {
entity.getCoals().forEach(x -> x.setId(null));
entity.getCoals().forEach(x -> x.setCoal(entity));
}
if (CollectionUtils.isNotEmpty(entity.getResults())) {
entity.getResults().forEach(x -> x.setCoal(entity));
}
}
}

View File

@@ -39,7 +39,7 @@ public class CoalBlendService extends BaseService<CoalBlendEntity, CoalBlendRepo
public CoalBlendDto create(CreateCoalBlendDto request) {
request.getCoals().forEach(x -> x.setId(null));
CoalBlendEntity entity = mapper.toEntity(request);