google 代码格式化

This commit is contained in:
2023-09-20 14:52:38 +08:00
parent 2d52d9e5be
commit 492aebe107
240 changed files with 34529 additions and 8675 deletions

1
.mvn/jvm.config Normal file
View File

@@ -0,0 +1 @@
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED

91
pom.xml
View File

@@ -15,67 +15,10 @@
<description>coal</description> <description>coal</description>
<properties> <properties>
<java.version>17</java.version> <java.version>17</java.version>
<git-code-format-maven-plugin.version>4.2</git-code-format-maven-plugin.version>
</properties> </properties>
<profiles> <profiles>
<profile>
<id>build</id>
<repositories>
<repository>
<id>aliyun</id>
<url>http://192.168.0.118:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<releases>
<updatePolicy>never</updatePolicy>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</pluginRepository>
<pluginRepository>
<id>aliyun</id>
<url>http://192.168.0.118:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles> </profiles>
<repositories> <repositories>
@@ -382,6 +325,38 @@
</excludes> </excludes>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>com.cosium.code</groupId>
<artifactId>git-code-format-maven-plugin</artifactId>
<version>${git-code-format-maven-plugin.version}</version>
<executions>
<!-- On commit, format the modified files -->
<execution>
<id>install-formatter-hook</id>
<goals>
<goal>install-hooks</goal>
</goals>
</execution>
<!-- On Maven verify phase, fail if any file
(including unmodified) is badly formatted -->
<execution>
<id>validate-code-format</id>
<goals>
<goal>validate-code-format</goal>
</goals>
</execution>
</executions>
<dependencies>
<!-- Enable https://github.com/google/google-java-format -->
<dependency>
<groupId>com.cosium.code</groupId>
<artifactId>google-java-format</artifactId>
<version>${git-code-format-maven-plugin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins> </plugins>
</build> </build>

View File

@@ -8,11 +8,7 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@EnableJpaRepositories @EnableJpaRepositories
public class CoalApplication { public class CoalApplication {
public static void main(String[] args) {
SpringApplication.run(CoalApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(CoalApplication.class, args);
}
} }

View File

@@ -15,6 +15,10 @@ import cn.lihongjie.coal.base.service.BaseService;
import com.google.common.base.CaseFormat; import com.google.common.base.CaseFormat;
import com.squareup.javapoet.*; import com.squareup.javapoet.*;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import java.nio.file.Path;
import java.util.Objects;
import java.util.Scanner;
import javax.lang.model.element.Modifier;
import lombok.Data; import lombok.Data;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -33,316 +37,332 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.lang.model.element.Modifier;
import java.nio.file.Path;
import java.util.Objects;
import java.util.Scanner;
public class Codegen { public class Codegen {
public static final Path DIRECTORY = Path.of("src/main/java/"); public static final Path DIRECTORY = Path.of("src/main/java/");
@SneakyThrows @SneakyThrows
public static void main(String[] args) { public static void main(String[] args) {
System.out.print("请输入模块名:"); System.out.print("请输入模块名:");
String moduleName = new Scanner(System.in).nextLine(); String moduleName = new Scanner(System.in).nextLine();
System.out.print("请输入模块中文名:"); System.out.print("请输入模块中文名:");
String moduleCNName = new Scanner(System.in).nextLine(); String moduleCNName = new Scanner(System.in).nextLine();
System.out.print("机构数据[Y]:");
boolean orgMode =
Objects.equals(StringUtils.defaultIfBlank(new Scanner(System.in).nextLine(), "Y"), "Y");
System.out.print("机构数据[Y]:"); String lModuleName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, moduleName);
boolean orgMode = Objects.equals(StringUtils.defaultIfBlank(new Scanner(System.in).nextLine(), "Y"), "Y"); String prefix = Codegen.class.getPackage().getName() + "." + lModuleName;
String entityPackage = prefix + ".entity";
String dtoPackage = prefix + ".dto";
String repoPackage = prefix + ".repository";
String mapperPackage = prefix + ".mapper";
String servicePackage = prefix + ".service";
String controllerPackage = prefix + ".controller";
// 生成entity
String lModuleName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, moduleName); TypeSpec entity =
String prefix = Codegen.class.getPackage().getName() + "." + lModuleName; TypeSpec.classBuilder(StringUtils.capitalize(moduleName) + "Entity")
String entityPackage = prefix + ".entity"; .addModifiers(Modifier.PUBLIC)
String dtoPackage = prefix + ".dto"; .superclass(orgMode ? OrgCommonEntity.class : CommonEntity.class)
String repoPackage = prefix + ".repository"; .addAnnotation(Data.class)
String mapperPackage = prefix + ".mapper"; .addAnnotation(Entity.class)
String servicePackage = prefix + ".service"; .build();
String controllerPackage = prefix + ".controller";
// 生成entity JavaFile.builder(entityPackage, entity).build().writeTo(DIRECTORY);
// 生成dto
TypeSpec dto =
TypeSpec.classBuilder(StringUtils.capitalize(moduleName) + "Dto")
.addModifiers(Modifier.PUBLIC)
.superclass(orgMode ? OrgCommonDto.class : CommonDto.class)
.addAnnotation(Data.class)
.build();
TypeSpec entity = TypeSpec.classBuilder(StringUtils.capitalize(moduleName) + "Entity") JavaFile.builder(dtoPackage, dto).build().writeTo(DIRECTORY);
.addModifiers(Modifier.PUBLIC)
.superclass(orgMode ? OrgCommonEntity.class: CommonEntity.class)
.addAnnotation(Data.class)
.addAnnotation(Entity.class)
.build(); // 生成createDto
TypeSpec createDto =
TypeSpec.classBuilder("Create" + StringUtils.capitalize(moduleName) + "Dto")
.addModifiers(Modifier.PUBLIC)
.superclass(orgMode ? OrgCommonDto.class : CommonDto.class)
.addAnnotation(Data.class)
.build();
JavaFile.builder(entityPackage, entity) JavaFile.builder(dtoPackage, createDto).build().writeTo(DIRECTORY);
.build()
.writeTo(DIRECTORY);
// 生成updateDto
TypeSpec updateDto =
TypeSpec.classBuilder("Update" + StringUtils.capitalize(moduleName) + "Dto")
.addModifiers(Modifier.PUBLIC)
.superclass(orgMode ? OrgCommonDto.class : CommonDto.class)
.addAnnotation(Data.class)
.build();
// 生成dto JavaFile.builder(dtoPackage, updateDto).build().writeTo(DIRECTORY);
TypeSpec dto = TypeSpec.classBuilder(StringUtils.capitalize(moduleName) + "Dto")
.addModifiers(Modifier.PUBLIC)
.superclass(orgMode ? OrgCommonDto.class:CommonDto.class)
.addAnnotation(Data.class)
.build(); // 生成repository
TypeSpec repository =
TypeSpec.interfaceBuilder(StringUtils.capitalize(moduleName) + "Repository")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Repository.class)
.addSuperinterface(
ParameterizedTypeName.get(
ClassName.get(BaseRepository.class), ClassName.get(entityPackage, entity.name)))
.build();
JavaFile.builder(dtoPackage, dto) JavaFile.builder(repoPackage, repository).build().writeTo(DIRECTORY);
.build()
.writeTo(DIRECTORY);
// 生成mapper
TypeSpec mapper =
TypeSpec.interfaceBuilder(StringUtils.capitalize(moduleName) + "Mapper")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(
AnnotationSpec.builder(Mapper.class)
.addMember(
"componentModel",
"org.mapstruct.MappingConstants.ComponentModel.SPRING",
"")
.addMember("uses", "{$T.class}", CommonMapper.class)
.addMember("mappingControl", "$T.class", DeepClone.class)
.build())
.addSuperinterface(
ParameterizedTypeName.get(
ClassName.get(BaseMapper.class),
ClassName.get(entityPackage, entity.name),
ClassName.get(dtoPackage, dto.name),
ClassName.get(dtoPackage, createDto.name),
ClassName.get(dtoPackage, updateDto.name)))
.build();
// 生成createDto JavaFile.builder(mapperPackage, mapper).build().writeTo(DIRECTORY);
TypeSpec createDto = TypeSpec.classBuilder("Create" + StringUtils.capitalize(moduleName) + "Dto")
.addModifiers(Modifier.PUBLIC)
.superclass(orgMode ? OrgCommonDto.class:CommonDto.class)
.addAnnotation(Data.class)
.build(); // 生成service
TypeSpec service =
JavaFile.builder(dtoPackage, createDto) TypeSpec.classBuilder(StringUtils.capitalize(moduleName) + "Service")
.build() .addModifiers(Modifier.PUBLIC)
.writeTo(DIRECTORY); .addAnnotation(Service.class)
.addAnnotation(Slf4j.class)
.superclass(
// 生成updateDto ParameterizedTypeName.get(
TypeSpec updateDto = TypeSpec.classBuilder("Update" + StringUtils.capitalize(moduleName) + "Dto") ClassName.get(BaseService.class),
.addModifiers(Modifier.PUBLIC) ClassName.get(entityPackage, entity.name),
.superclass(orgMode ? OrgCommonDto.class:CommonDto.class) ClassName.get(repoPackage, repository.name)))
.addAnnotation(Data.class) .addField(
FieldSpec.builder(
.build(); ClassName.get(repoPackage, repository.name), "repository", Modifier.PRIVATE)
.addAnnotation(Autowired.class)
JavaFile.builder(dtoPackage, updateDto) .build())
.build() .addField(
.writeTo(DIRECTORY); FieldSpec.builder(
ClassName.get(mapperPackage, mapper.name), "mapper", Modifier.PRIVATE)
.addAnnotation(Autowired.class)
// 生成repository .build())
TypeSpec repository = TypeSpec.interfaceBuilder(StringUtils.capitalize(moduleName) + "Repository") .addField(
.addModifiers(Modifier.PUBLIC) FieldSpec.builder(
.addAnnotation(Repository.class) ClassName.get(ConversionService.class),
.addSuperinterface(ParameterizedTypeName.get(ClassName.get(BaseRepository.class), ClassName.get(entityPackage, entity.name))) "conversionService",
.build(); Modifier.PRIVATE)
.addAnnotation(Autowired.class)
.build())
JavaFile.builder(repoPackage, repository) .addMethod(
.build() MethodSpec.methodBuilder("create")
.writeTo(DIRECTORY); .addModifiers(Modifier.PUBLIC)
.returns(ClassName.get(dtoPackage, dto.name))
.addParameter(ClassName.get(dtoPackage, createDto.name), "request")
// 生成mapper .addStatement(
TypeSpec mapper = TypeSpec.interfaceBuilder(StringUtils.capitalize(moduleName) + "Mapper") """
.addModifiers(Modifier.PUBLIC)
.addAnnotation(AnnotationSpec.builder(Mapper.class)
.addMember("componentModel", "org.mapstruct.MappingConstants.ComponentModel.SPRING", "")
.addMember("uses", "{$T.class}", CommonMapper.class)
.addMember("mappingControl", "$T.class", DeepClone.class)
.build())
.addSuperinterface(ParameterizedTypeName.get(
ClassName.get(BaseMapper.class),
ClassName.get(entityPackage, entity.name),
ClassName.get(dtoPackage, dto.name),
ClassName.get(dtoPackage, createDto.name),
ClassName.get(dtoPackage, updateDto.name)
)
)
.build();
JavaFile.builder(mapperPackage, mapper)
.build()
.writeTo(DIRECTORY);
// 生成service
TypeSpec service = TypeSpec.classBuilder(StringUtils.capitalize(moduleName) + "Service")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Service.class)
.addAnnotation(Slf4j.class)
.superclass(ParameterizedTypeName.get(
ClassName.get(BaseService.class),
ClassName.get(entityPackage, entity.name),
ClassName.get(repoPackage, repository.name)
)
)
.addField(FieldSpec.builder(ClassName.get(repoPackage, repository.name), "repository", Modifier.PRIVATE).addAnnotation(Autowired.class).build())
.addField(FieldSpec.builder(ClassName.get(mapperPackage, mapper.name), "mapper", Modifier.PRIVATE).addAnnotation(Autowired.class).build())
.addField(FieldSpec.builder(ClassName.get(ConversionService.class), "conversionService", Modifier.PRIVATE).addAnnotation(Autowired.class).build())
.addMethod(MethodSpec.methodBuilder("create")
.addModifiers(Modifier.PUBLIC)
.returns(ClassName.get(dtoPackage, dto.name))
.addParameter(ClassName.get(dtoPackage, createDto.name), "request")
.addStatement("""
$T entity = mapper.toEntity(request); $T entity = mapper.toEntity(request);
this.repository.save(entity); this.repository.save(entity);
return getById(entity.getId()) return getById(entity.getId())
""", ClassName.get(entityPackage, entity.name)) """,
ClassName.get(entityPackage, entity.name))
.build() .build())
) .addMethod(
.addMethod(MethodSpec.methodBuilder("update") MethodSpec.methodBuilder("update")
.addModifiers(Modifier.PUBLIC) .addModifiers(Modifier.PUBLIC)
.returns(ClassName.get(dtoPackage, dto.name))
.returns(ClassName.get(dtoPackage, dto.name)) .addParameter(ClassName.get(dtoPackage, updateDto.name), "request")
.addParameter(ClassName.get(dtoPackage, updateDto.name), "request") .addStatement(
.addStatement(""" """
$T entity = this.repository.get(request.getId()); $T entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request); this.mapper.updateEntity(entity, request);
this.repository.save(entity); this.repository.save(entity);
return getById(entity.getId()) return getById(entity.getId())
""", ClassName.get(entityPackage, entity.name)) """,
.build() ClassName.get(entityPackage, entity.name))
) .build())
.addMethod(
.addMethod(MethodSpec.methodBuilder("delete") MethodSpec.methodBuilder("delete")
.addModifiers(Modifier.PUBLIC) .addModifiers(Modifier.PUBLIC)
.returns(void.class)
.returns(void.class) .addParameter(ClassName.get(IdRequest.class), "request")
.addParameter(ClassName.get(IdRequest.class), "request") .addStatement(
.addStatement(""" """
this.repository.deleteAllById(request.getIds()) this.repository.deleteAllById(request.getIds())
""") """)
.build() .build())
) .addMethod(
.addMethod(MethodSpec.methodBuilder("getById") MethodSpec.methodBuilder("getById")
.addModifiers(Modifier.PUBLIC) .addModifiers(Modifier.PUBLIC)
.returns(ClassName.get(dtoPackage, dto.name))
.returns(ClassName.get(dtoPackage, dto.name)) .addParameter(ClassName.get(String.class), "id")
.addParameter(ClassName.get(String.class), "id") .addStatement(
.addStatement(""" """
$T entity = repository.get(id); $T entity = repository.get(id);
return mapper.toDto(entity) return mapper.toDto(entity)
""", ClassName.get(entityPackage, entity.name)) """,
.build() ClassName.get(entityPackage, entity.name))
) .build())
.addMethod(MethodSpec.methodBuilder("list") .addMethod(
.addModifiers(Modifier.PUBLIC) MethodSpec.methodBuilder("list")
.addModifiers(Modifier.PUBLIC)
.returns(ParameterizedTypeName.get(ClassName.get(Page.class), ClassName.get(dtoPackage, dto.name))) .returns(
.addParameter(ClassName.get(CommonQuery.class), "query") ParameterizedTypeName.get(
.addStatement( ClassName.get(Page.class), ClassName.get(dtoPackage, dto.name)))
""" .addParameter(ClassName.get(CommonQuery.class), "query")
.addStatement(
"""
$T<$T> page = repository.findAll(query.specification(conversionService), $T.of(query.getPageNo(), query.getPageSize(), $T.by(query.getOrders()))); $T<$T> page = repository.findAll(query.specification(conversionService), $T.of(query.getPageNo(), query.getPageSize(), $T.by(query.getOrders())));
return page.map(this.mapper::toDto) return page.map(this.mapper::toDto)
""", ClassName.get(Page.class),ClassName.get(entityPackage, entity.name), ClassName.get(PageRequest.class), ClassName.get(Sort.class)) """,
.build() ClassName.get(Page.class),
) ClassName.get(entityPackage, entity.name),
.build(); ClassName.get(PageRequest.class),
ClassName.get(Sort.class))
.build())
.build();
JavaFile.builder(servicePackage, service).build().writeTo(DIRECTORY);
JavaFile.builder(servicePackage, service) // 生成controller
.build() TypeSpec.Builder controllerBuilder =
.writeTo(DIRECTORY); TypeSpec.classBuilder(StringUtils.capitalize(moduleName) + "Controller")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(RestController.class)
.addAnnotation(
AnnotationSpec.builder(RequestMapping.class)
.addMember("value", "$S", "/" + lModuleName)
.build())
.addAnnotation(
AnnotationSpec.builder(SysLog.class)
.addMember("module", "$S", StringUtils.defaultIfBlank(moduleCNName, ""))
.build())
.addAnnotation(Slf4j.class);
if (orgMode) {
controllerBuilder.addAnnotation(OrgScope.class);
}
controllerBuilder
.addField(
FieldSpec.builder(
// 生成controller ClassName.get(servicePackage, service.name), "service", Modifier.PRIVATE)
TypeSpec.Builder controllerBuilder = TypeSpec.classBuilder(StringUtils.capitalize(moduleName) + "Controller") .addAnnotation(Autowired.class)
.build())
.addMethod(
MethodSpec.methodBuilder("create")
.addModifiers(Modifier.PUBLIC) .addModifiers(Modifier.PUBLIC)
.addAnnotation(RestController.class) .returns(ClassName.get(dtoPackage, dto.name))
.addAnnotation(AnnotationSpec.builder(RequestMapping.class).addMember("value", "$S", "/" + lModuleName).build()) .addAnnotation(
.addAnnotation(AnnotationSpec.builder(SysLog.class).addMember("module", "$S", StringUtils.defaultIfBlank(moduleCNName, "")).build()) AnnotationSpec.builder(PostMapping.class)
.addAnnotation(Slf4j.class); .addMember("value", "$S", "/create")
.build())
if(orgMode) { .addParameter(
controllerBuilder.addAnnotation(OrgScope.class); ParameterSpec.builder(ClassName.get(dtoPackage, createDto.name), "request")
} .addAnnotation(RequestBody.class)
controllerBuilder.addField(FieldSpec.builder(ClassName.get(servicePackage, service.name), "service", Modifier.PRIVATE).addAnnotation(Autowired.class).build()) .build())
.addMethod(MethodSpec.methodBuilder("create") .addStatement(
.addModifiers(Modifier.PUBLIC) """
.returns(ClassName.get(dtoPackage, dto.name))
.addAnnotation(AnnotationSpec.builder(PostMapping.class).addMember("value", "$S", "/create").build())
.addParameter(ParameterSpec.builder(ClassName.get(dtoPackage, createDto.name), "request").addAnnotation(RequestBody.class).build())
.addStatement("""
return this.service.create(request) return this.service.create(request)
""") """)
.build())
.build() .addMethod(
) MethodSpec.methodBuilder("update")
.addMethod(MethodSpec.methodBuilder("update") .addModifiers(Modifier.PUBLIC)
.addModifiers(Modifier.PUBLIC) .returns(ClassName.get(dtoPackage, dto.name))
.addAnnotation(
.returns(ClassName.get(dtoPackage, dto.name)) AnnotationSpec.builder(PostMapping.class)
.addAnnotation(AnnotationSpec.builder(PostMapping.class).addMember("value", "$S", "/update").build()) .addMember("value", "$S", "/update")
.build())
.addParameter(ParameterSpec.builder(ClassName.get(dtoPackage, updateDto.name), "request").addAnnotation(RequestBody.class).build()) .addParameter(
.addStatement(""" ParameterSpec.builder(ClassName.get(dtoPackage, updateDto.name), "request")
.addAnnotation(RequestBody.class)
.build())
.addStatement(
"""
return this.service.update(request) return this.service.update(request)
""") """)
.build() .build())
) .addMethod(
MethodSpec.methodBuilder("delete")
.addMethod(MethodSpec.methodBuilder("delete") .addModifiers(Modifier.PUBLIC)
.addModifiers(Modifier.PUBLIC) .returns(Object.class)
.addAnnotation(
.returns(Object.class) AnnotationSpec.builder(PostMapping.class)
.addAnnotation(AnnotationSpec.builder(PostMapping.class).addMember("value", "$S", "/delete").build()) .addMember("value", "$S", "/delete")
.build())
.addParameter(ParameterSpec.builder(ClassName.get(IdRequest.class), "request").addAnnotation(RequestBody.class).build()) .addParameter(
.addStatement(""" ParameterSpec.builder(ClassName.get(IdRequest.class), "request")
.addAnnotation(RequestBody.class)
.build())
.addStatement(
"""
this.service.delete(request); this.service.delete(request);
return true return true
""") """)
.build() .build())
) .addMethod(
.addMethod(MethodSpec.methodBuilder("getById") MethodSpec.methodBuilder("getById")
.addModifiers(Modifier.PUBLIC) .addModifiers(Modifier.PUBLIC)
.returns(ClassName.get(dtoPackage, dto.name))
.returns(ClassName.get(dtoPackage, dto.name)) .addAnnotation(
.addAnnotation(AnnotationSpec.builder(PostMapping.class).addMember("value", "$S", "/getById").build()) AnnotationSpec.builder(PostMapping.class)
.addMember("value", "$S", "/getById")
.addParameter(ParameterSpec.builder(ClassName.get(String.class), "request").addAnnotation(RequestBody.class).build()) .build())
.addStatement(""" .addParameter(
ParameterSpec.builder(ClassName.get(String.class), "request")
.addAnnotation(RequestBody.class)
.build())
.addStatement(
"""
return this.service.getById(request) return this.service.getById(request)
""") """)
.build() .build())
) .addMethod(
.addMethod(MethodSpec.methodBuilder("list") MethodSpec.methodBuilder("list")
.addModifiers(Modifier.PUBLIC) .addModifiers(Modifier.PUBLIC)
.returns(
.returns(ParameterizedTypeName.get(ClassName.get(Page.class), ClassName.get(dtoPackage, dto.name))) ParameterizedTypeName.get(
.addAnnotation(AnnotationSpec.builder(PostMapping.class).addMember("value", "$S", "/list").build()) ClassName.get(Page.class), ClassName.get(dtoPackage, dto.name)))
.addAnnotation(
.addParameter(ParameterSpec.builder(ClassName.get(CommonQuery.class), "request").addAnnotation(RequestBody.class).build()) AnnotationSpec.builder(PostMapping.class)
.addStatement( .addMember("value", "$S", "/list")
""" .build())
.addParameter(
ParameterSpec.builder(ClassName.get(CommonQuery.class), "request")
.addAnnotation(RequestBody.class)
.build())
.addStatement(
"""
return this.service.list(request) return this.service.list(request)
""", ClassName.get(Page.class), ClassName.get(entityPackage, entity.name), ClassName.get(PageRequest.class), ClassName.get(Sort.class)) """,
.build() ClassName.get(Page.class),
) ClassName.get(entityPackage, entity.name),
; ClassName.get(PageRequest.class),
ClassName.get(Sort.class))
.build());
JavaFile.builder(controllerPackage, controllerBuilder.build()).build().writeTo(DIRECTORY);
}
JavaFile.builder(controllerPackage, controllerBuilder.build())
.build()
.writeTo(DIRECTORY);
}
} }

View File

@@ -1,6 +1,5 @@
package cn.lihongjie.coal.annotation; package cn.lihongjie.coal.annotation;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
@@ -10,10 +9,5 @@ import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.METHOD}) @Target({ElementType.TYPE, ElementType.METHOD})
public @interface Anonymous { public @interface Anonymous {
boolean value() default true; boolean value() default true;
} }

View File

@@ -1,6 +1,5 @@
package cn.lihongjie.coal.annotation; package cn.lihongjie.coal.annotation;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
@@ -10,10 +9,5 @@ import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.METHOD}) @Target({ElementType.TYPE, ElementType.METHOD})
public @interface OrgAdmin { public @interface OrgAdmin {
boolean value() default true; boolean value() default true;
} }

View File

@@ -1,6 +1,5 @@
package cn.lihongjie.coal.annotation; package cn.lihongjie.coal.annotation;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
@@ -10,10 +9,5 @@ import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.METHOD}) @Target({ElementType.TYPE, ElementType.METHOD})
public @interface OrgScope { public @interface OrgScope {
boolean value() default true; boolean value() default true;
} }

View File

@@ -1,6 +1,5 @@
package cn.lihongjie.coal.annotation; package cn.lihongjie.coal.annotation;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
@@ -10,10 +9,5 @@ import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.METHOD}) @Target({ElementType.TYPE, ElementType.METHOD})
public @interface SysAdmin { public @interface SysAdmin {
boolean value() default true; boolean value() default true;
} }

View File

@@ -1,6 +1,5 @@
package cn.lihongjie.coal.annotation; package cn.lihongjie.coal.annotation;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
@@ -10,14 +9,9 @@ import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.METHOD}) @Target({ElementType.TYPE, ElementType.METHOD})
public @interface SysLog { public @interface SysLog {
String module() default ""; String module() default "";
String action() default "";
String message() default "";
String action() default "";
String message() default "";
} }

View File

@@ -3,10 +3,12 @@ package cn.lihongjie.coal.aop;
import cn.lihongjie.coal.annotation.SysLog; import cn.lihongjie.coal.annotation.SysLog;
import cn.lihongjie.coal.common.RequestUtils; import cn.lihongjie.coal.common.RequestUtils;
import cn.lihongjie.coal.ip.IpQueryService; import cn.lihongjie.coal.ip.IpQueryService;
import cn.lihongjie.coal.syslog.entity.SysLogEntity;
import cn.lihongjie.coal.session.SessionService; import cn.lihongjie.coal.session.SessionService;
import cn.lihongjie.coal.syslog.entity.SysLogEntity;
import cn.lihongjie.coal.syslog.service.SysLogService; import cn.lihongjie.coal.syslog.service.SysLogService;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.util.Arrays;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -22,134 +24,109 @@ import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
import java.lang.reflect.Method;
import java.util.Arrays;
@Aspect @Aspect
@Component @Component
@Slf4j @Slf4j
public class ControllerAop { public class ControllerAop {
@Pointcut("execution (* cn.lihongjie.coal.*.controller.*.*(..))")
public void controllerMethods() {}
@Pointcut("execution (* cn.lihongjie.coal.*.controller.*.*(..))") @Autowired SessionService sessionService;
public void controllerMethods() {
@SneakyThrows
@Around("controllerMethods()")
public Object call(ProceedingJoinPoint proceedingJoinPoint) {
Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod();
HttpServletRequest request =
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
long start = System.currentTimeMillis();
SysLogEntity sysLogEntity = createSysLog(method, request);
try {
return proceedingJoinPoint.proceed();
} catch (Throwable e) {
logException(e, proceedingJoinPoint);
updateSysLog(e, sysLogEntity);
throw e;
} finally {
saveSysLog(sysLogEntity, System.currentTimeMillis(), start);
} }
}
@Autowired private void saveSysLog(SysLogEntity sysLogEntity, long end, long start) {
SessionService sessionService; if (sysLogEntity != null) {
sysLogEntity.setTimeCost((int) (end - start));
sysLogService.save(sysLogEntity);
}
}
@SneakyThrows private static void updateSysLog(Throwable e, SysLogEntity sysLogEntity) {
@Around("controllerMethods()") if (sysLogEntity != null) {
public Object call(ProceedingJoinPoint proceedingJoinPoint) { sysLogEntity.setOptStatus("1");
sysLogEntity.setStacktrace(ExceptionUtils.getStackTrace(e));
}
}
Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod(); @Autowired IpQueryService ipQueryService;
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
private SysLogEntity createSysLog(Method method, HttpServletRequest request) {
SysLog sysLog = AnnotationUtils.findAnnotation(method, SysLog.class);
SysLogEntity sysLogEntity = null;
String module = "";
if (sysLog != null) {
module = sysLog.module();
if (StringUtils.isEmpty(module)) {
SysLog classLog = AnnotationUtils.findAnnotation(method.getDeclaringClass(), SysLog.class);
if (classLog != null) {
module = classLog.module();
long start = System.currentTimeMillis();
SysLogEntity sysLogEntity = createSysLog(method, request);
try {
return proceedingJoinPoint.proceed();
} catch (Throwable e) {
logException(e, proceedingJoinPoint);
updateSysLog(e, sysLogEntity);
throw e;
} finally {
saveSysLog(sysLogEntity, System.currentTimeMillis(), start);
} }
}
sysLogEntity = new SysLogEntity();
sysLogEntity.setModule(module);
sysLogEntity.setMessage(sysLog.message());
sysLogEntity.setAction(sysLog.action());
sysLogEntity.setIp(RequestUtils.getIp(request));
sysLogEntity.setIpLocation(ipQueryService.query(sysLogEntity.getIp()));
sysLogEntity.setUrl(request.getRequestURI());
sysLogEntity.setOptStatus("0");
sysLogEntity.setTimeCost(0);
sysLogEntity.setUserAgent(RequestUtils.getUa(request));
} }
return sysLogEntity;
}
private void saveSysLog(SysLogEntity sysLogEntity, long end, long start) { @Autowired SysLogService sysLogService;
if (sysLogEntity != null) {
sysLogEntity.setTimeCost((int) (end - start));
sysLogService.save(sysLogEntity); private void logException(Throwable ex, ProceedingJoinPoint proceedingJoinPoint) {
HttpServletRequest request =
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
} Object[] args = proceedingJoinPoint.getArgs();
} Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod();
private static void updateSysLog(Throwable e, SysLogEntity sysLogEntity) { log.info(
if (sysLogEntity != null) { "接口调用异常: {}\nurl:{} {}\nmethod: {}\nargs: {}",
sysLogEntity.setOptStatus("1"); ex.getMessage() == null ? "no message" : ex.getMessage(),
sysLogEntity.setStacktrace(ExceptionUtils.getStackTrace(e)); request.getMethod(),
request.getRequestURL(),
method,
Arrays.toString(args),
ex);
} request.setAttribute("__logged", true);
} }
@Autowired
IpQueryService ipQueryService;
private SysLogEntity createSysLog(Method method, HttpServletRequest request) {
SysLog sysLog = AnnotationUtils.findAnnotation(method, SysLog.class);
SysLogEntity sysLogEntity = null;
String module = "";
if (sysLog != null) {
module = sysLog.module();
if (StringUtils.isEmpty(module)) {
SysLog classLog = AnnotationUtils.findAnnotation(method.getDeclaringClass(), SysLog.class);
if (classLog != null) {
module = classLog.module();
}
}
sysLogEntity = new SysLogEntity();
sysLogEntity.setModule(module);
sysLogEntity.setMessage(sysLog.message());
sysLogEntity.setAction(sysLog.action());
sysLogEntity.setIp(RequestUtils.getIp(request));
sysLogEntity.setIpLocation(ipQueryService.query(sysLogEntity.getIp()));
sysLogEntity.setUrl(request.getRequestURI());
sysLogEntity.setOptStatus("0");
sysLogEntity.setTimeCost(0);
sysLogEntity.setUserAgent(RequestUtils.getUa(request));
}
return sysLogEntity;
}
@Autowired
SysLogService sysLogService;
private void logException(Throwable ex, ProceedingJoinPoint proceedingJoinPoint) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
Object[] args = proceedingJoinPoint.getArgs();
Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod();
log.info("接口调用异常: {}\nurl:{} {}\nmethod: {}\nargs: {}",
ex.getMessage() == null ? "no message" : ex.getMessage(),
request.getMethod(),
request.getRequestURL(),
method,
Arrays.toString(args),
ex);
request.setAttribute("__logged", true);
}
} }

View File

@@ -5,6 +5,7 @@ import cn.lihongjie.coal.common.Ctx;
import cn.lihongjie.coal.exception.BizException; import cn.lihongjie.coal.exception.BizException;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext; import jakarta.persistence.PersistenceContext;
import java.lang.reflect.Method;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -18,82 +19,68 @@ import org.hibernate.Session;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
@Aspect @Aspect
@Component @Component
@Slf4j @Slf4j
@Order @Order
public class OrgScopeAop { public class OrgScopeAop {
@PersistenceContext @PersistenceContext EntityManager entityManager;
EntityManager entityManager;
private static ThreadLocal<Boolean> orgScope = new ThreadLocal<>();
private static ThreadLocal<Boolean> orgScope = new ThreadLocal<>(); @SneakyThrows
@Around(
@SneakyThrows value =
@Around(value = "@annotation(cn.lihongjie.coal.annotation.OrgScope) || @within(cn.lihongjie.coal.annotation.OrgScope)") "@annotation(cn.lihongjie.coal.annotation.OrgScope) || @within(cn.lihongjie.coal.annotation.OrgScope)")
public Object beforeOrgScope(ProceedingJoinPoint pjp) { public Object beforeOrgScope(ProceedingJoinPoint pjp) {
Method method = ((MethodSignature) pjp.getSignature()).getMethod();
OrgScope annotation = method.getAnnotation(OrgScope.class);
if (annotation == null) {
annotation = method.getDeclaringClass().getAnnotation(OrgScope.class);
}
if (annotation != null) {
boolean enabled = annotation.value();
Session session = entityManager.unwrap(Session.class);
if (enabled) {
if (StringUtils.isEmpty(Ctx.currentUser().getOrganizationId())) {
throw new BizException("当前用户未绑定机构, 无法进行机构数据过滤");
}
if (session.getEnabledFilter("orgFilter") == null) {
Filter orgFilter = session.enableFilter("orgFilter");
orgFilter.setParameter("organizationId", Ctx.currentUser().getOrganizationId());
} else {
log.debug("当前session {} orgFilter已经启用, 忽略....", session.toString());
}
} else {
if (session.getEnabledFilter("orgFilter") != null) {
session.disableFilter("orgFilter");
} else {
log.debug("当前session {} orgFilter已经禁用, 忽略....", session.toString());
}
}
}
return pjp.proceed();
Method method = ((MethodSignature) pjp.getSignature()).getMethod();
OrgScope annotation = method.getAnnotation(OrgScope.class);
if (annotation == null) {
annotation = method.getDeclaringClass().getAnnotation(OrgScope.class);
} }
if (annotation != null) {
boolean enabled = annotation.value();
@Before(value = "@annotation(org.springframework.transaction.annotation.Transactional))") Session session = entityManager.unwrap(Session.class);
public void beforeTransactionMethod() {
if (enabled) {
if (orgScope.get() != null) { if (StringUtils.isEmpty(Ctx.currentUser().getOrganizationId())) {
throw new BizException("当前用户未绑定机构, 无法进行机构数据过滤");
Session session = entityManager.unwrap(Session.class);
} }
if (session.getEnabledFilter("orgFilter") == null) {
Filter orgFilter = session.enableFilter("orgFilter");
orgFilter.setParameter("organizationId", Ctx.currentUser().getOrganizationId());
} else {
log.debug("当前session {} orgFilter已经启用, 忽略....", session.toString());
}
} else {
if (session.getEnabledFilter("orgFilter") != null) {
session.disableFilter("orgFilter");
} else {
log.debug("当前session {} orgFilter已经禁用, 忽略....", session.toString());
}
}
} }
return pjp.proceed();
}
@Before(value = "@annotation(org.springframework.transaction.annotation.Transactional))")
public void beforeTransactionMethod() {
if (orgScope.get() != null) {
Session session = entityManager.unwrap(Session.class);
}
}
} }

View File

@@ -7,5 +7,4 @@ import org.springframework.web.bind.annotation.RestController;
@OrgScope @OrgScope
@Transactional @Transactional
@RestController @RestController
public abstract class BaseController { public abstract class BaseController {}
}

View File

@@ -1,34 +1,30 @@
package cn.lihongjie.coal.base.dao; package cn.lihongjie.coal.base.dao;
import jakarta.persistence.criteria.Path; import jakarta.persistence.criteria.Path;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.NoRepositoryBean; import org.springframework.data.repository.NoRepositoryBean;
import java.util.List;
@NoRepositoryBean @NoRepositoryBean
public interface BaseRepository<T> extends JpaRepository<T, String>, JpaSpecificationExecutor<T> { public interface BaseRepository<T> extends JpaRepository<T, String>, JpaSpecificationExecutor<T> {
public default T get(String id) { public default T get(String id) {
return findById(id).orElseThrow(() -> new RuntimeException("数据不存在: " + id)); return findById(id).orElseThrow(() -> new RuntimeException("数据不存在: " + id));
}
} public default List<T> findByOrganizationId(String organizationId) {
return findAll(
(root, query, cb) -> {
try {
public default List<T> findByOrganizationId(String organizationId) { Path<Object> path = root.get("organizationId");
return findAll((root, query, cb) -> { return cb.equal(path, organizationId);
try { } catch (Exception e) {
return cb.and();
Path<Object> path = root.get("organizationId"); }
return cb.equal(path, organizationId);
} catch (Exception e) {
return cb.and();
}
}); });
}
;
}
;
} }

View File

@@ -1,27 +1,23 @@
package cn.lihongjie.coal.base.dto; package cn.lihongjie.coal.base.dto;
import java.time.LocalDateTime;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.time.LocalDateTime;
@Getter @Getter
@Setter @Setter
public abstract class BaseDto { public abstract class BaseDto {
private String id; private String id;
private String createUserId; private String createUserId;
private String createUserName;
private String createUserName; private LocalDateTime createTime;
private LocalDateTime createTime; private String updateUserId;
private String updateUserName;
private String updateUserId;
private String updateUserName;
private LocalDateTime updateTime;
private LocalDateTime updateTime;
} }

View File

@@ -8,24 +8,18 @@ import org.hibernate.annotations.Comment;
@Setter @Setter
public class CommonDto extends BaseDto { public class CommonDto extends BaseDto {
@Comment("名称")
private String name;
@Comment("名称") @Comment("编码")
private String name; private String code;
@Comment("编码") @Comment("备注")
private String code; private String remarks;
@Comment("排序键")
private Integer sortKey;
@Comment("备注") @Comment("常用状态 0 禁用 1 启用")
private String remarks; private String status;
@Comment("排序键")
private Integer sortKey;
@Comment("常用状态 0 禁用 1 启用")
private String status;
} }

File diff suppressed because it is too large Load Diff

View File

@@ -1,33 +1,29 @@
package cn.lihongjie.coal.base.dto; package cn.lihongjie.coal.base.dto;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@Data @Data
public class IdRequest { public class IdRequest {
private String id; private String id;
private List<String> ids; private List<String> ids;
public List<String> getIds() { public List<String> getIds() {
if (StringUtils.isEmpty(id)) {
return ids;
} else if (CollectionUtils.isEmpty(ids)) {
return Arrays.asList(id);
}else {
ArrayList<String> dup = new ArrayList<>(ids);
dup.add(id);
return dup;
}
if (StringUtils.isEmpty(id)) {
return ids;
} else if (CollectionUtils.isEmpty(ids)) {
return Arrays.asList(id);
} else {
ArrayList<String> dup = new ArrayList<>(ids);
dup.add(id);
return dup;
} }
}
} }

View File

@@ -6,5 +6,5 @@ import lombok.Setter;
@Getter @Getter
@Setter @Setter
public class OrgCommonDto extends CommonDto { public class OrgCommonDto extends CommonDto {
private String organizationId; private String organizationId;
} }

View File

@@ -6,49 +6,46 @@ import lombok.Data;
@Data @Data
public class R<T> { public class R<T> {
private T data; private T data;
private String code; private String code;
private String msg; private String msg;
@JsonInclude(Include.NON_NULL) @JsonInclude(Include.NON_NULL)
private Integer pageNo; private Integer pageNo;
@JsonInclude(Include.NON_NULL)
private Integer pageSize;
@JsonInclude(Include.NON_NULL)
private Integer totalPage;
@JsonInclude(Include.NON_NULL)
private Integer totalCount;
@JsonInclude(Include.NON_NULL)
private Integer pageSize;
public R(T data, String code, String msg) { @JsonInclude(Include.NON_NULL)
this.data = data; private Integer totalPage;
this.code = code;
this.msg = msg;
}
@JsonInclude(Include.NON_NULL)
private Integer totalCount;
public R() { public R(T data, String code, String msg) {
} this.data = data;
this.code = code;
this.msg = msg;
}
public R() {}
public static <T> R<T> success() { public static <T> R<T> success() {
return success(null); return success(null);
} }
public static <T> R<T> success(T data) { public static <T> R<T> success(T data) {
return create(data, "ok", ""); return create(data, "ok", "");
} }
public static <T> R<T> fail(String code, String msg) { public static <T> R<T> fail(String code, String msg) {
return create(null, code, msg); return create(null, code, msg);
} }
public static <T> R<T> create(T data, String code, String msg) {
return new R<>(data, code, msg);
}
public static <T> R<T> create(T data, String code, String msg) {
return new R<>(data, code, msg);
}
} }

View File

@@ -5,178 +5,159 @@ import cn.lihongjie.coal.base.entity.CommonEntity;
import cn.lihongjie.coal.common.ReflectUtils; import cn.lihongjie.coal.common.ReflectUtils;
import cn.lihongjie.coal.dictionary.dto.DictionaryItemDto; import cn.lihongjie.coal.dictionary.dto.DictionaryItemDto;
import cn.lihongjie.coal.dictionary.entity.DictionaryItemEntity; import cn.lihongjie.coal.dictionary.entity.DictionaryItemEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.util.stream.StreamSupport; import java.util.stream.StreamSupport;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class TreeDto { public class TreeDto {
private String id; private String id;
private String code; private String code;
private String name; private String name;
private List<TreeDto> children; private List<TreeDto> children;
public static List<TreeDto> buildList(Object object, boolean flatten) {
public static List<TreeDto> buildList(Object object, boolean flatten) { List<TreeDto> ans;
List<TreeDto> ans; if (object instanceof Iterable<?>) {
if (object instanceof Iterable<?>) { ans = buildList0((Iterable<?>) object);
} else {
ans = buildList0((Iterable<?>) object); ans = buildList0(Arrays.asList(object));
} else {
ans = buildList0(Arrays.asList(object));
}
if (flatten) {
ans = flatten(ans);
}
return ans;
} }
private static List<TreeDto> flatten(List<TreeDto> ans) { if (flatten) {
ans = flatten(ans);
}
return ans;
}
return ans.stream().flatMap(x -> { private static List<TreeDto> flatten(List<TreeDto> ans) {
if (x == null) { return ans.stream()
.flatMap(
x -> {
if (x == null) {
return Stream.empty(); return Stream.empty();
} }
if (x.getChildren() != null) { if (x.getChildren() != null) {
return Stream.concat(Stream.of(x), flatten(x.getChildren()).stream()); return Stream.concat(Stream.of(x), flatten(x.getChildren()).stream());
} else { } else {
return Stream.of(x); return Stream.of(x);
} }
})
.toList();
}
}).toList(); private static List<TreeDto> buildList0(Iterable<?> object) {
return StreamSupport.stream(object.spliterator(), false).map(x -> buildTree(x)).toList();
}
public static TreeDto buildTree(Object x) {
if (x == null) {
return null;
} }
private static List<TreeDto> buildList0(Iterable<?> object) { TreeDto dto = new TreeDto();
dto.setId(getId(x));
dto.setName(getName(x));
dto.setCode(getCode(x));
dto.setChildren(getChildren(x));
return dto;
}
return StreamSupport.stream(object.spliterator(), false).map(x -> buildTree(x)).toList(); private static List<TreeDto> getChildren(Object x) {
if (x instanceof TreeDto) {
return ((TreeDto) x).getChildren().stream().map(TreeDto::buildTree).toList();
} }
public static TreeDto buildTree(Object x) { Object c = ReflectUtils.getFieldValue(x, "children");
if (c == null) {
if (x == null) { return new ArrayList<>();
return null;
}
TreeDto dto = new TreeDto();
dto.setId(getId(x));
dto.setName(getName(x));
dto.setCode(getCode(x));
dto.setChildren(getChildren(x));
return dto;
} }
private static List<TreeDto> getChildren(Object x) { if (c instanceof Iterable<?>) {
return buildList0((Iterable<?>) c);
if (x instanceof TreeDto) {
return ((TreeDto) x).getChildren().stream().map(TreeDto::buildTree).toList();
}
Object c = ReflectUtils.getFieldValue(x, "children");
if (c == null) {
return new ArrayList<>();
}
if (c instanceof Iterable<?>) {
return buildList0((Iterable<?>) c);
}
return buildList0(Arrays.asList(c));
} }
private static String getCode(Object x) { return buildList0(Arrays.asList(c));
if (x instanceof CommonEntity) { }
return ((CommonEntity) x).getCode();
}
if (x instanceof CommonDto) { private static String getCode(Object x) {
return ((CommonDto) x).getCode(); if (x instanceof CommonEntity) {
} return ((CommonEntity) x).getCode();
if (x instanceof TreeDto) {
return ((TreeDto) x).getCode();
}
return ReflectUtils.getFieldValue(x, "code") + "";
} }
private static String getName(Object x) { if (x instanceof CommonDto) {
return ((CommonDto) x).getCode();
if (x instanceof CommonEntity) {
return ((CommonEntity) x).getName();
}
if (x instanceof CommonDto) {
return ((CommonDto) x).getName();
}
if (x instanceof TreeDto) {
return ((TreeDto) x).getName();
}
return ReflectUtils.getFieldValue(x, "name") + "";
} }
private static String getId(Object x) { if (x instanceof TreeDto) {
return ((TreeDto) x).getCode();
if (x instanceof DictionaryItemEntity) {
return ((DictionaryItemEntity) x).getCode();
}
if (x instanceof DictionaryItemDto) {
return ((DictionaryItemDto) x).getCode();
}
if (x instanceof BaseEntity) {
return ((BaseEntity) x).getId();
}
if (x instanceof BaseDto) {
return ((BaseDto) x).getId();
}
if (x instanceof TreeDto) {
return ((TreeDto) x).getId();
}
return ReflectUtils.getFieldValue(x, "id") + "";
} }
return ReflectUtils.getFieldValue(x, "code") + "";
}
private static String getName(Object x) {
if (x instanceof CommonEntity) {
return ((CommonEntity) x).getName();
}
if (x instanceof CommonDto) {
return ((CommonDto) x).getName();
}
if (x instanceof TreeDto) {
return ((TreeDto) x).getName();
}
return ReflectUtils.getFieldValue(x, "name") + "";
}
private static String getId(Object x) {
if (x instanceof DictionaryItemEntity) {
return ((DictionaryItemEntity) x).getCode();
}
if (x instanceof DictionaryItemDto) {
return ((DictionaryItemDto) x).getCode();
}
if (x instanceof BaseEntity) {
return ((BaseEntity) x).getId();
}
if (x instanceof BaseDto) {
return ((BaseDto) x).getId();
}
if (x instanceof TreeDto) {
return ((TreeDto) x).getId();
}
return ReflectUtils.getFieldValue(x, "id") + "";
}
} }

View File

@@ -1,68 +1,60 @@
package cn.lihongjie.coal.base.entity; package cn.lihongjie.coal.base.entity;
import cn.lihongjie.coal.common.Ctx; import cn.lihongjie.coal.common.Ctx;
import jakarta.persistence.*; import jakarta.persistence.*;
import java.time.LocalDateTime;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.*; import org.hibernate.annotations.*;
import java.time.LocalDateTime;
@MappedSuperclass @MappedSuperclass
@Getter @Getter
@Setter @Setter
@DynamicUpdate @DynamicUpdate
public class BaseEntity { public class BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private String id;
@Id @Comment("创建用户ID")
@GeneratedValue(strategy = GenerationType.UUID) private String createUserId;
private String id;
@Formula("(select tu.name from t_user tu where tu.id = create_user_id)")
private String createUserName;
@Comment("创建用户ID") @Comment("创建时间")
private String createUserId; @CreationTimestamp(source = SourceType.VM)
private LocalDateTime createTime;
@Comment("更新用户ID")
private String updateUserId;
@Formula("(select tu.name from t_user tu where tu.id = create_user_id)") @Formula("((select tu.name from t_user tu where tu.id = create_user_id))")
private String createUserName; private String updateUserName;
@Comment("创建时间") @Comment("更新时间")
@CreationTimestamp(source = SourceType.VM) @UpdateTimestamp(source = SourceType.VM)
private LocalDateTime createTime; private LocalDateTime updateTime;
@PrePersist
public void prePersist() {
if (StringUtils.isEmpty(this.createUserId)) {
@Comment("更新用户ID") this.createUserId = Ctx.isLoggedIn() ? Ctx.getUserId() : "";
private String updateUserId;
@Formula("((select tu.name from t_user tu where tu.id = create_user_id))")
private String updateUserName;
@Comment("更新时间")
@UpdateTimestamp(source = SourceType.VM)
private LocalDateTime updateTime;
@PrePersist
public void prePersist() {
if (StringUtils.isEmpty(this.createUserId)) {
this.createUserId = Ctx.isLoggedIn() ? Ctx.getUserId() : "";
}
if (this.createTime == null) {
this.createTime = LocalDateTime.now();
}
} }
@PreUpdate if (this.createTime == null) {
public void preUpdate() { this.createTime = LocalDateTime.now();
this.updateUserId = Ctx.isLoggedIn() ? Ctx.getUserId() : "";
this.updateTime = LocalDateTime.now();
} }
}
@PreUpdate
public void preUpdate() {
this.updateUserId = Ctx.isLoggedIn() ? Ctx.getUserId() : "";
this.updateTime = LocalDateTime.now();
}
} }

View File

@@ -1,53 +1,44 @@
package cn.lihongjie.coal.base.entity; package cn.lihongjie.coal.base.entity;
import jakarta.persistence.MappedSuperclass; import jakarta.persistence.MappedSuperclass;
import java.util.Objects;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.hibernate.annotations.Comment; import org.hibernate.annotations.Comment;
import java.util.Objects;
@MappedSuperclass @MappedSuperclass
@Getter @Getter
@Setter @Setter
public class CommonEntity extends BaseEntity { public class CommonEntity extends BaseEntity {
@Comment("名称") @Comment("名称")
private String name; private String name;
@Comment("编码") @Comment("编码")
private String code; private String code;
@Comment("备注")
private String remarks;
@Comment("备注") @Comment("排序键")
private String remarks; private Integer sortKey;
@Comment("常用状态 0 禁用 1 启用")
private Integer status;
public boolean isDisabled() {
return Objects.equals(status, 0);
}
@Comment("排序键") @Override
private Integer sortKey; public void prePersist() {
this.status = this.status == null ? 1 : this.status;
super.prePersist();
}
@Override
@Comment("常用状态 0 禁用 1 启用") public void preUpdate() {
private Integer status; this.status = this.status == null ? 1 : this.status;
super.preUpdate();
}
public boolean isDisabled(){
return Objects.equals(status, 0);
}
@Override
public void prePersist() {
this.status = this.status == null ? 1 : this.status;
super.prePersist();
}
@Override
public void preUpdate() {
this.status = this.status == null ? 1 : this.status;
super.preUpdate();
}
} }

View File

@@ -11,22 +11,20 @@ import org.apache.commons.lang3.StringUtils;
@Setter @Setter
public class OrgBaseEntity extends BaseEntity { public class OrgBaseEntity extends BaseEntity {
private String organizationId;
private String organizationId; @Override
public void prePersist() {
if (StringUtils.isEmpty(organizationId)) {
this.organizationId =
@Override Ctx.isLoggedIn() ? Ctx.currentUser().getOrganizationId() : organizationId;
public void prePersist() {
if (StringUtils.isEmpty(organizationId)) {
this.organizationId = Ctx.isLoggedIn() ? Ctx.currentUser().getOrganizationId() : organizationId;
}
super.prePersist();
}
@Override
public void preUpdate() {
super.preUpdate();
} }
super.prePersist();
}
@Override
public void preUpdate() {
super.preUpdate();
}
} }

View File

@@ -16,21 +16,20 @@ import org.hibernate.annotations.ParamDef;
@Filter(name = "orgFilter", condition = "organization_id = :organizationId") @Filter(name = "orgFilter", condition = "organization_id = :organizationId")
public class OrgCommonEntity extends CommonEntity { public class OrgCommonEntity extends CommonEntity {
private String organizationId;
private String organizationId; @Override
public void prePersist() {
if (StringUtils.isEmpty(organizationId)) {
this.organizationId =
@Override Ctx.isLoggedIn() ? Ctx.currentUser().getOrganizationId() : organizationId;
public void prePersist() {
if (StringUtils.isEmpty(organizationId)) {
this.organizationId = Ctx.isLoggedIn() ? Ctx.currentUser().getOrganizationId() : organizationId;
}
super.prePersist();
} }
super.prePersist();
}
@Override @Override
public void preUpdate() { public void preUpdate() {
super.preUpdate(); super.preUpdate();
} }
} }

View File

@@ -2,15 +2,14 @@ package cn.lihongjie.coal.base.mapper;
import org.mapstruct.MappingTarget; import org.mapstruct.MappingTarget;
public interface BaseMapper<Entity, Dto, Create,Update> { public interface BaseMapper<Entity, Dto, Create, Update> {
Entity copy(Entity i); Entity copy(Entity i);
Dto copyDto(Dto i);
Dto copyDto(Dto i);
Dto toDto(Entity user); Dto toDto(Entity user);
Entity toEntity(Create request); Entity toEntity(Create request);
void updateEntity(@MappingTarget Entity entity, Update dto);
void updateEntity(@MappingTarget Entity entity, Update dto);
} }

View File

@@ -19,156 +19,144 @@ import org.mapstruct.Mapper;
@Mapper(componentModel = "spring") @Mapper(componentModel = "spring")
public interface CommonMapper { public interface CommonMapper {
public default Integer toInt(String s) { public default Integer toInt(String s) {
try { try {
return Integer.valueOf(s);
} catch (Exception e) {
return null;
}
return Integer.valueOf(s);
} catch (Exception e) {
return null;
} }
public default UserEntity createUser(String id) { }
if (StringUtils.isEmpty(id)) { public default UserEntity createUser(String id) {
return null;
}
UserEntity user = new UserEntity();
user.setId(id); if (StringUtils.isEmpty(id)) {
return null;
return user;
} }
UserEntity user = new UserEntity();
user.setId(id);
public default DictionaryEntity createDictionary(String id) { return user;
}
if (StringUtils.isEmpty(id)) { public default DictionaryEntity createDictionary(String id) {
return null;
}
DictionaryEntity e = new DictionaryEntity();
e.setId(id);
return e;
if (StringUtils.isEmpty(id)) {
return null;
} }
DictionaryEntity e = new DictionaryEntity();
e.setId(id);
return e;
}
public default DictionaryItemEntity createDictionaryItem(String id) { public default DictionaryItemEntity createDictionaryItem(String id) {
if (StringUtils.isEmpty(id)) {
return null;
}
DictionaryItemEntity e = new DictionaryItemEntity();
e.setId(id);
return e;
if (StringUtils.isEmpty(id)) {
return null;
} }
DictionaryItemEntity e = new DictionaryItemEntity();
e.setId(id);
return e;
}
public default SysLogEntity createOperat(String id) { public default SysLogEntity createOperat(String id) {
if (StringUtils.isEmpty(id)) {
return null;
}
SysLogEntity e = new SysLogEntity();
e.setId(id);
return e;
if (StringUtils.isEmpty(id)) {
return null;
} }
SysLogEntity e = new SysLogEntity();
e.setId(id);
return e;
}
public default OrganizationEntity createOrganization(String id) { public default OrganizationEntity createOrganization(String id) {
if (StringUtils.isEmpty(id)) {
return null;
}
OrganizationEntity e = new OrganizationEntity();
e.setId(id);
return e;
if (StringUtils.isEmpty(id)) {
return null;
} }
OrganizationEntity e = new OrganizationEntity();
e.setId(id);
return e;
}
public default PermissionEntity createPermission(String id) { public default PermissionEntity createPermission(String id) {
if (StringUtils.isEmpty(id)) {
return null;
}
PermissionEntity e = new PermissionEntity();
e.setId(id);
return e;
if (StringUtils.isEmpty(id)) {
return null;
} }
PermissionEntity e = new PermissionEntity();
e.setId(id);
return e;
}
public default ResourceEntity createResource(String id) { public default ResourceEntity createResource(String id) {
if (StringUtils.isEmpty(id)) {
return null;
}
ResourceEntity e = new ResourceEntity();
e.setId(id);
return e;
if (StringUtils.isEmpty(id)) {
return null;
} }
ResourceEntity e = new ResourceEntity();
e.setId(id);
return e;
}
public default RoleEntity createRole(String id) { public default RoleEntity createRole(String id) {
if (StringUtils.isEmpty(id)) { if (StringUtils.isEmpty(id)) {
return null;
}
RoleEntity e = new RoleEntity();
e.setId(id);
return e;
return null;
} }
RoleEntity e = new RoleEntity();
e.setId(id);
return e;
}
public default ScriptEntity createScript(String id) {
public default ScriptEntity createScript(String id) { if (StringUtils.isEmpty(id)) {
if (StringUtils.isEmpty(id)) {
return null;
}
ScriptEntity e = new ScriptEntity();
e.setId(id);
return e;
return null;
} }
public default SupplierEntity createSupplier(String id) { ScriptEntity e = new ScriptEntity();
e.setId(id);
return e;
}
if (StringUtils.isEmpty(id)) { public default SupplierEntity createSupplier(String id) {
return null; if (StringUtils.isEmpty(id)) {
}
SupplierEntity e = new SupplierEntity();
e.setId(id);
return e;
return null;
} }
public default CoalInfoEntity createCoalInfo(String id) { SupplierEntity e = new SupplierEntity();
e.setId(id);
return e;
}
if (StringUtils.isEmpty(id)) { public default CoalInfoEntity createCoalInfo(String id) {
return null; if (StringUtils.isEmpty(id)) {
}
CoalInfoEntity e = new CoalInfoEntity();
e.setId(id);
return e;
return null;
} }
public default String toString(Object o) { CoalInfoEntity e = new CoalInfoEntity();
e.setId(id);
return e;
}
public default String toString(Object o) {
if (o == null) { if (o == null) {
return null; return null;
} else if (o instanceof String) { } else if (o instanceof String) {
return ((String) o); return ((String) o);
} else if (o instanceof BaseEntity) { } else if (o instanceof BaseEntity) {
return ((BaseEntity) o).getId(); return ((BaseEntity) o).getId();
} else if (o instanceof BaseDto) {
return ((BaseDto) o).getId();
} else {
return o.toString();
}
} else if (o instanceof BaseDto) {
return ((BaseDto) o).getId();
} else {
return o.toString();
} }
}
} }

View File

@@ -2,58 +2,52 @@ package cn.lihongjie.coal.base.service;
import cn.lihongjie.coal.base.dao.BaseRepository; import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.base.entity.BaseEntity; import cn.lihongjie.coal.base.entity.BaseEntity;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
import java.util.List; public abstract class BaseService<
Entity extends BaseEntity, Repository extends BaseRepository<Entity>> {
public abstract class BaseService<Entity extends BaseEntity, Repository extends BaseRepository<Entity>> { @Autowired Repository dao;
@Autowired public Entity get(String id) {
Repository dao;
return dao.get(id);
}
public Entity get(String id){ public void save(Entity entity) {
return dao.get(id); dao.save(entity);
} }
public void delete(String id) {
dao.deleteById(id);
}
public void save(Entity entity){ public void delete(List<String> id) {
dao.deleteAllById(id);
}
dao.save(entity); public Page<Entity> findAll(Specification<Entity> spec, Pageable page) {
} return dao.findAll(spec, page);
}
public List<Entity> findAll(Specification<Entity> spec) {
return dao.findAll(spec);
}
public void delete(String id) { public List<Entity> findAll() {
dao.deleteById(id); return dao.findAll();
} }
public void delete(List<String> id) {
dao.deleteAllById(id);
}
public Page<Entity> findAll(Specification<Entity> spec, Pageable page){
return dao.findAll(spec, page);
}
public List<Entity> findAll(Specification<Entity> spec){
return dao.findAll(spec);
}
public List<Entity> findAll(){
return dao.findAll();
}
public Long count(Specification<Entity> spec){
return dao.count(spec);
}
public Long count(){
return dao.count();
}
public Long count(Specification<Entity> spec) {
return dao.count(spec);
}
public Long count() {
return dao.count();
}
} }

View File

@@ -1,15 +1,13 @@
package cn.lihongjie.coal.coal; package cn.lihongjie.coal.coal;
import lombok.Data; import lombok.Data;
@Data @Data
public class CoalConstraint{ public class CoalConstraint {
private String code;
private Double min;
private Double max;
private Integer priority;
private Integer order;
private String code;
private Double min;
private Double max;
private Integer priority;
private Integer order;
} }

View File

@@ -4,39 +4,29 @@ import cn.lihongjie.coal.annotation.Anonymous;
import cn.lihongjie.coal.base.controller.BaseController; import cn.lihongjie.coal.base.controller.BaseController;
import cn.lihongjie.coal.coalBlend.dto.CoalBlendRequest; import cn.lihongjie.coal.coalBlend.dto.CoalBlendRequest;
import cn.lihongjie.coal.coalBlend.dto.CoalBlendResult; import cn.lihongjie.coal.coalBlend.dto.CoalBlendResult;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController @RestController
@RequestMapping("/coal") @RequestMapping("/coal")
@Anonymous @Anonymous
public class CoalController extends BaseController { public class CoalController extends BaseController {
@Autowired @Autowired CoalService coalService;
CoalService coalService;
@PostMapping("/blend")
public CoalBlendResult blend(@RequestBody CoalBlendRequest request) {
return coalService.blend(request);
}
@PostMapping("/params")
public List<CoalParameterDef> params() {
@PostMapping("/blend") return coalService.paramDefs();
public CoalBlendResult blend(@RequestBody CoalBlendRequest request){ }
return coalService.blend(request);
}
@PostMapping("/params")
public List<CoalParameterDef> params(){
return coalService.paramDefs();
}
} }

View File

@@ -1,75 +1,61 @@
package cn.lihongjie.coal.coal; package cn.lihongjie.coal.coal;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import lombok.Data;
@Data @Data
public class CoalInfo { public class CoalInfo {
private String id;
private String id; private String name;
private String name; /** 配煤比例明细 */
private List<CoalPercent> percents;
/** private Integer min = 1;
* 配煤比例明细 private Integer max = 99;
*/
private List<CoalPercent> percents;
private Integer min = 1; private List<CoalParameter> parameters;
private Integer max = 99;
@JsonIgnore private Map<String, CoalParameter> parameterMap;
private List<CoalParameter> parameters; public Map<String, CoalParameter> getParameterMap() {
if (parameterMap == null) {
@JsonIgnore parameterMap = parameters.stream().collect(Collectors.toMap(e -> e.getCode(), e -> e));
private Map<String, CoalParameter> parameterMap;
public Map<String, CoalParameter> getParameterMap() {
if (parameterMap == null) {
parameterMap = parameters.stream().collect(Collectors.toMap(e -> e.getCode(), e -> e));
}
return parameterMap;
} }
return parameterMap;
}
public Double getParamVal(String code) { public Double getParamVal(String code) {
CoalParameter coalParameter = getParameterMap().get(code);
return coalParameter == null ? null : coalParameter.getValue();
}
CoalParameter coalParameter = getParameterMap().get(code); public String rowString() {
return coalParameter == null ? null : coalParameter.getValue();
} String percentString =
percents.stream()
.map(x -> String.format("%5s %-3s(%1s)", x.getName(), x.getPercent(), x.getPercent2()))
.collect(Collectors.joining("\t"));
String paramString =
parameters.stream()
.map(x -> String.format("%5s:%-6.2f", x.getCode(), x.getValue()))
.collect(Collectors.joining("\t"));
public String rowString() { return String.format("%s\t%20s\t%s", name, percentString, paramString);
}
String percentString = public void calPercent2() {
percents.stream().map(x -> String.format("%5s %-3s(%1s)", x.getName(), x.getPercent(),
x.getPercent2())).collect(Collectors.joining("\t"));
String paramString =
parameters.stream().map(x -> String.format("%5s:%-6.2f", x.getCode(), x.getValue())).collect(Collectors.joining(
"\t"));
// percents.stream().reduce(x -> x.)
return String.format("%s\t%20s\t%s", name, percentString, paramString); }
}
public void calPercent2() {
// percents.stream().reduce(x -> x.)
}
} }

View File

@@ -5,8 +5,7 @@ import lombok.Data;
@Data @Data
public class CoalParameter { public class CoalParameter {
private String code; private String code;
private Double value;
private Double value;
} }

View File

@@ -4,9 +4,9 @@ import lombok.Data;
@Data @Data
public class CoalParameterDef { public class CoalParameterDef {
private String code; private String code;
private String name; private String name;
private String desc; private String desc;
private Integer status; private Integer status;
private Integer order; private Integer order;
} }

View File

@@ -4,14 +4,12 @@ import lombok.Data;
@Data @Data
public class CoalPercent { public class CoalPercent {
private String id; private String id;
private String name; private String name;
private Long percent; private Long percent;
/** /** gcd之后的比例 */
* gcd之后的比例 private Long percent2;
*/
private Long percent2;
} }

View File

@@ -8,13 +8,6 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.ortools.Loader; import com.google.ortools.Loader;
import com.google.ortools.sat.*; import com.google.ortools.sat.*;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
@@ -22,113 +15,114 @@ import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
@Slf4j @Slf4j
@Service @Service
public class CoalService { public class CoalService {
/**
* 配煤
*
* @return
*/
public CoalBlendResult blend(CoalBlendRequest request) {
/** if (CollectionUtils.isEmpty(request.getCoals())) {
* 配煤 throw new BizException("煤不能为空");
* }
* @return
*/
public CoalBlendResult blend(CoalBlendRequest request) {
if (CollectionUtils.isEmpty(request.getCoals())) { if (CollectionUtils.isEmpty(request.getConstraints())) {
throw new BizException("不能为空"); throw new BizException("参数配置不能为空");
} }
if (CollectionUtils.isEmpty(request.getConstraints())) { Loader.loadNativeLibraries();
throw new BizException("参数配置不能为空"); CoalBlendResult result = new CoalBlendResult();
}
CpModel model = new CpModel();
List<IntVar> vars = createPercentVars(request, model);
// 添加各种约束条件
addConstrains(request, model, vars);
// 初始化求解器
CpSolver cpSolver = new CpSolver();
cpSolver.setLogCallback(x -> log.info(x));
SatParameters.Builder parameters = cpSolver.getParameters();
parameters.setEnumerateAllSolutions(false);
parameters.setMaxTimeInSeconds(request.getMaxTime());
parameters.setLogSearchProgress(false);
parameters.setFillAdditionalSolutionsInResponse(true);
// 开始求最优解
Loader.loadNativeLibraries(); List<CoalConstraint> sorted =
CoalBlendResult result = new CoalBlendResult(); request.getConstraints().stream()
.filter(x -> x.getPriority() != null)
.sorted(Comparator.comparing(CoalConstraint::getPriority))
.toList();
CpModel model = new CpModel(); for (CoalConstraint constraint : sorted) {
log.info("使用约束 {}", constraint);
List<IntVar> vars = createPercentVars(request, model); LinearExpr weightedSum =
LinearExpr.weightedSum(
vars.toArray(new IntVar[0]),
request.getCoals().stream()
.mapToLong(x -> (long) (x.getParamVal(constraint.getCode()) * 100))
.toArray());
if (constraint.getOrder() == -1) {
model.maximize(weightedSum);
// 添加各种约束条件 } else {
addConstrains(request, model, vars); model.minimize(weightedSum);
}
CpSolverStatus status = cpSolver.solve(model);
// 初始化求解器 if (status == CpSolverStatus.FEASIBLE || status == CpSolverStatus.OPTIMAL) {
CpSolver cpSolver = new CpSolver();
cpSolver.setLogCallback(x -> log.info(x));
SatParameters.Builder parameters = cpSolver.getParameters();
parameters.setEnumerateAllSolutions(false);
parameters.setMaxTimeInSeconds(request.getMaxTime());
parameters.setLogSearchProgress(false);
parameters.setFillAdditionalSolutionsInResponse(true);
// 开始求最优解
List<CoalConstraint> sorted = request.getConstraints().stream().filter(x -> x.getPriority()!=null).sorted(Comparator.comparing(CoalConstraint::getPriority)).toList();
for (CoalConstraint constraint : sorted) {
log.info("使用约束 {}", constraint);
LinearExpr weightedSum = LinearExpr.weightedSum(vars.toArray(new IntVar[0]), request.getCoals().stream().mapToLong(x -> (long) (x.getParamVal(constraint.getCode()) * 100)).toArray());
if (constraint.getOrder() == -1) {
model.maximize(weightedSum);
} else {
model.minimize(weightedSum);
}
CpSolverStatus status = cpSolver.solve(model);
if (status == CpSolverStatus.FEASIBLE || status == CpSolverStatus.OPTIMAL) {
double constrainVal = cpSolver.objectiveValue();
// model.clearHints();
//
// for (IntVar var : vars) {
// model.addHint(var, cpSolver.value(var));
//
// }
if (constraint.getOrder() == -1) {
model.addLessOrEqual(weightedSum, (long) constrainVal);
log.info("添加新的条件 sum({}) <= {}", constraint.getCode(), constrainVal);
} else {
model.addGreaterOrEqual(weightedSum, (long) constrainVal);
log.info("添加新的条件 sum({}) >= {}", constraint.getCode(), constrainVal);
}
String validate = model.validate();
log.info(validate);
} else {
log.warn("无法求解: " + status);
}
}
// 记录结果
double constrainVal = cpSolver.objectiveValue();
// model.clearHints();
// //
cpSolver.getParameters().setEnumerateAllSolutions(true); // for (IntVar var : vars) {
CpSolverStatus solverStatus = cpSolver.solve(model, new CpSolverSolutionCallback() { // model.addHint(var, cpSolver.value(var));
@Override //
public void onSolutionCallback() { // }
if (constraint.getOrder() == -1) {
model.addLessOrEqual(weightedSum, (long) constrainVal);
log.info("添加新的条件 sum({}) <= {}", constraint.getCode(), constrainVal);
} else {
model.addGreaterOrEqual(weightedSum, (long) constrainVal);
log.info("添加新的条件 sum({}) >= {}", constraint.getCode(), constrainVal);
}
String validate = model.validate();
log.info(validate);
} else {
log.warn("无法求解: " + status);
}
}
// 记录结果
//
cpSolver.getParameters().setEnumerateAllSolutions(true);
CpSolverStatus solverStatus =
cpSolver.solve(
model,
new CpSolverSolutionCallback() {
@Override
public void onSolutionCallback() {
CoalInfo solution = new CoalInfo(); CoalInfo solution = new CoalInfo();
List<Long> gcdVals = new ArrayList<>(); List<Long> gcdVals = new ArrayList<>();
@@ -137,239 +131,222 @@ public class CoalService {
solution.setParameters(new ArrayList<>()); solution.setParameters(new ArrayList<>());
for (int i = 0; i < vars.size(); i++) { for (int i = 0; i < vars.size(); i++) {
long percent = this.value(vars.get(i)); long percent = this.value(vars.get(i));
CoalInfo coal = request.getCoals().get(i); CoalInfo coal = request.getCoals().get(i);
// 累加 // 累加
try { try {
acc(solution, percent, coal); acc(solution, percent, coal);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
CoalPercent e = new CoalPercent(); CoalPercent e = new CoalPercent();
e.setId(coal.getId()); e.setId(coal.getId());
e.setName(coal.getName()); e.setName(coal.getName());
e.setPercent(percent); e.setPercent(percent);
if (CollectionUtils.isNotEmpty(gcdVals)) { if (CollectionUtils.isNotEmpty(gcdVals)) {
e.setPercent2(gcdVals.get(i)); e.setPercent2(gcdVals.get(i));
}
} solution.getPercents().add(e);
solution.getPercents().add(e);
} }
// 四舍五入 // 四舍五入
round(solution); round(solution);
result.getCoals().add(solution); result.getCoals().add(solution);
}
});
sortAndSelect(request, result);
} return result;
}
});
sortAndSelect(request, result);
return result;
private static List<IntVar> createPercentVars(CoalBlendRequest request, CpModel model) {
int index = 0;
List<IntVar> vars = new ArrayList<>();
for (CoalInfo coal : request.getCoals()) {
IntVar x =
model.newIntVar(Math.max(coal.getMin(), 0), Math.min(coal.getMax(), 100), "x" + index++);
vars.add(x);
} }
return vars;
}
private static List<IntVar> createPercentVars(CoalBlendRequest request, CpModel model) { private void sortAndSelect(CoalBlendRequest request, CoalBlendResult result) {
int index = 0;
List<IntVar> vars = new ArrayList<>(); List<CoalConstraint> list =
for (CoalInfo coal : request.getCoals()) { request.getConstraints().stream()
IntVar x = model.newIntVar(Math.max(coal.getMin(), 0), Math.min(coal.getMax(), 100), "x" + index++); .filter(x -> x.getPriority() != null)
vars.add(x); .sorted(Comparator.comparing(x -> x.getPriority()))
.collect(Collectors.toList());
Comparator<CoalInfo> c = Comparator.comparing(x -> 1);
if (!list.isEmpty()) {
for (CoalConstraint constraint : list) {
if (constraint.getOrder() == null || constraint.getOrder() == 1) {
c =
c.thenComparing(
Comparator.<CoalInfo, Double>comparing(x -> x.getParamVal(constraint.getCode())));
} else {
c =
c.thenComparing(
Comparator.<CoalInfo, Double>comparing(x -> x.getParamVal(constraint.getCode()))
.reversed());
} }
return vars; }
} }
result.setCoals(
result.getCoals().stream()
.sorted(c)
.limit(request.getCount())
.collect(Collectors.toList()));
private void sortAndSelect(CoalBlendRequest request, CoalBlendResult result) { result.getCoals().forEach(x -> x.calPercent2());
}
private void round(CoalInfo solution) {
List<CoalConstraint> list = request.getConstraints() solution
.stream() .getParameters()
.filter(x -> x.getPriority() != null) .forEach(
.sorted(Comparator.comparing(x -> x.getPriority())) x ->
.collect(Collectors.toList()); x.setValue(
x.getValue() == null
? x.getValue()
: BigDecimal.valueOf(x.getValue())
.setScale(2, RoundingMode.HALF_UP)
.doubleValue()));
}
private void acc(CoalInfo solution, long percent, CoalInfo coal) {
Comparator<CoalInfo> c = Comparator.comparing(x -> 1); for (CoalParameter parameter : coal.getParameters()) {
if (!list.isEmpty()) {
boolean found = false;
for (CoalConstraint constraint : list) { for (CoalParameter solutionParameter : solution.getParameters()) {
if (constraint.getOrder() == null || constraint.getOrder() == 1) {
c =
c.thenComparing(Comparator.<CoalInfo, Double>comparing(x -> x.getParamVal(constraint.getCode())));
} else {
c =
c.thenComparing(Comparator.<CoalInfo, Double>comparing(x -> x.getParamVal(constraint.getCode())).reversed());
}
}
if (StringUtils.equalsIgnoreCase(parameter.getCode(), solutionParameter.getCode())) {
solutionParameter.setValue(
solutionParameter.getValue() + (parameter.getValue() * percent / 100.0));
found = true;
break;
} }
result.setCoals(result.getCoals().stream().sorted(c).limit(request.getCount()).collect(Collectors.toList())); }
result.getCoals().forEach(x -> x.calPercent2()); if (!found) {
CoalParameter e = new CoalParameter();
e.setCode(parameter.getCode());
e.setValue(parameter.getValue() * percent / 100.0);
solution.getParameters().add(e);
}
}
}
private void addConstrains(CoalBlendRequest request, CpModel model, List<IntVar> vars) {
// 各种煤比例之和为 100
model.addEquality(LinearExpr.sum(vars.toArray(new LinearArgument[0])), 100);
if (request.getType() == 2) {
IntVar gcd = model.newIntVar(1, 100, "gcd");
List<IntVar> varGcdList = new ArrayList<>();
for (IntVar var : vars) {
model.addModuloEquality(model.newConstant(0), var, gcd);
// 定义一个变量,表示 percent / gcd
IntVar varGcd = model.newIntVar(1, 100, var.getName() + "_gcd");
// 约束这个变量
model.addDivisionEquality(varGcd, var, gcd);
varGcdList.add(varGcd);
}
// 约束 sum(percent / gcd) < request.getPercent2Sum()
model.addLessOrEqual(
LinearExpr.sum(varGcdList.toArray(new IntVar[0])), request.getPercent2Sum());
} }
for (CoalConstraint constrain : request.getConstraints()) {
private void round(CoalInfo solution) { if (StringUtils.isBlank(constrain.getCode())) {
continue;
}
solution.getParameters().forEach(x -> x.setValue(x.getValue() == null ? x.getValue() : if (constrain.getMin() == null && constrain.getMax() == null) {
BigDecimal.valueOf(x.getValue()).setScale(2, RoundingMode.HALF_UP).doubleValue())); continue;
}
} long[] paramsOfEachCoal = new long[request.getCoals().size()];
int index = 0;
private void acc(CoalInfo solution, long percent, CoalInfo coal) { for (CoalInfo coal : request.getCoals()) {
boolean found = false;
for (CoalParameter parameter : coal.getParameters()) { for (CoalParameter parameter : coal.getParameters()) {
boolean found = false; if (StringUtils.equalsIgnoreCase(parameter.getCode(), constrain.getCode())) {
for (CoalParameter solutionParameter : solution.getParameters()) {
if (StringUtils.equalsIgnoreCase(parameter.getCode(), solutionParameter.getCode())) {
solutionParameter.setValue(solutionParameter.getValue() + (parameter.getValue() * percent / 100.0));
found = true;
break;
}
}
if (!found) {
CoalParameter e = new CoalParameter();
e.setCode(parameter.getCode());
e.setValue(parameter.getValue() * percent / 100.0);
solution.getParameters().add(e);
}
paramsOfEachCoal[index++] = (long) (parameter.getValue() * 100);
found = true;
break;
}
} }
if (!found) {
throw new RuntimeException(
String.format(
"煤 %s 没有找到指标 %s, 但是存在条件 %s <= %s <= %s",
coal.getName(),
constrain.getCode(),
constrain.getMin(),
constrain.getCode(),
constrain.getMax()));
}
}
if (constrain.getMin() != null) {
model.addGreaterOrEqual(
LinearExpr.weightedSum(vars.toArray(new LinearArgument[0]), paramsOfEachCoal),
(long) ((constrain.getMin()) * 10000));
}
if (constrain.getMax() != null) {
model.addLessOrEqual(
LinearExpr.weightedSum(vars.toArray(new LinearArgument[0]), paramsOfEachCoal),
(long) ((constrain.getMax()) * 10000));
}
}
}
@SneakyThrows
public List<CoalParameterDef> paramDefs() {
ClassPathResource classPathResource = new ClassPathResource("/config/CoalParameterDef.json");
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
List<CoalParameterDef> coalParameterDefs;
try (InputStream inputStream = classPathResource.getInputStream()) {
coalParameterDefs =
mapper.readValue(inputStream, new TypeReference<List<CoalParameterDef>>() {});
} }
private void addConstrains(CoalBlendRequest request, CpModel model, List<IntVar> vars) { return coalParameterDefs;
// 各种煤比例之和为 100 }
model.addEquality(LinearExpr.sum(vars.toArray(new LinearArgument[0])), 100);
if (request.getType() == 2) {
IntVar gcd = model.newIntVar(1, 100, "gcd");
List<IntVar> varGcdList = new ArrayList<>();
for (IntVar var : vars) {
model.addModuloEquality(model.newConstant(0), var, gcd);
// 定义一个变量,表示 percent / gcd
IntVar varGcd = model.newIntVar(1, 100, var.getName() + "_gcd");
// 约束这个变量
model.addDivisionEquality(varGcd, var, gcd);
varGcdList.add(varGcd);
}
// 约束 sum(percent / gcd) < request.getPercent2Sum()
model.addLessOrEqual(LinearExpr.sum(varGcdList.toArray(new IntVar[0])), request.getPercent2Sum());
}
for (CoalConstraint constrain : request.getConstraints()) {
if (StringUtils.isBlank(constrain.getCode())) {
continue;
}
if (constrain.getMin() == null && constrain.getMax() == null) {
continue;
}
long[] paramsOfEachCoal = new long[request.getCoals().size()];
int index = 0;
for (CoalInfo coal : request.getCoals()) {
boolean found = false;
for (CoalParameter parameter : coal.getParameters()) {
if (StringUtils.equalsIgnoreCase(parameter.getCode(), constrain.getCode())) {
paramsOfEachCoal[index++] = (long) (parameter.getValue() * 100);
found = true;
break;
}
}
if (!found) {
throw new RuntimeException(String.format("煤 %s 没有找到指标 %s, 但是存在条件 %s <= %s <= %s", coal.getName(),
constrain.getCode(), constrain.getMin(), constrain.getCode(), constrain.getMax()));
}
}
if (constrain.getMin() != null) {
model.addGreaterOrEqual(LinearExpr.weightedSum(vars.toArray(new LinearArgument[0]), paramsOfEachCoal),
(long) ((constrain.getMin()) * 10000));
}
if (constrain.getMax() != null) {
model.addLessOrEqual(LinearExpr.weightedSum(vars.toArray(new LinearArgument[0]), paramsOfEachCoal),
(long) ((constrain.getMax()) * 10000));
}
}
}
@SneakyThrows
public List<CoalParameterDef> paramDefs() {
ClassPathResource classPathResource = new ClassPathResource("/config/CoalParameterDef.json");
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
List<CoalParameterDef> coalParameterDefs;
try (InputStream inputStream = classPathResource.getInputStream()) {
coalParameterDefs = mapper.readValue(inputStream, new TypeReference<List<CoalParameterDef>>() {
});
}
return coalParameterDefs;
}
} }

View File

@@ -18,47 +18,40 @@ import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping("/coalAnalysis") @RequestMapping("/coalAnalysis")
@SysLog( @SysLog(module = "煤源化验")
module = "煤源化验"
)
@Slf4j @Slf4j
@OrgScope @OrgScope
public class CoalAnalysisController { public class CoalAnalysisController {
@Autowired @Autowired private CoalAnalysisService service;
private CoalAnalysisService service;
@PostMapping("/create") @PostMapping("/create")
public CoalAnalysisDto create(@RequestBody CreateCoalAnalysisDto request) { public CoalAnalysisDto create(@RequestBody CreateCoalAnalysisDto request) {
return this.service.create(request) return this.service.create(request);
;
} }
@PostMapping("/calculate") @PostMapping("/calculate")
public CoalAnalysisDto calculate(@RequestBody CoalAnalysisDto request) { public CoalAnalysisDto calculate(@RequestBody CoalAnalysisDto request) {
return this.service.calculate(request) return this.service.calculate(request);
;
} }
@PostMapping("/update") @PostMapping("/update")
public CoalAnalysisDto update(@RequestBody UpdateCoalAnalysisDto request) { public CoalAnalysisDto update(@RequestBody UpdateCoalAnalysisDto request) {
return this.service.update(request) return this.service.update(request);
;
} }
@PostMapping("/delete") @PostMapping("/delete")
public Object delete(@RequestBody IdRequest request) { public Object delete(@RequestBody IdRequest request) {
this.service.delete(request); this.service.delete(request);
return true return true;
;
} }
@PostMapping("/getById") @PostMapping("/getById")
public CoalAnalysisDto getById(@RequestBody String request) { public CoalAnalysisDto getById(@RequestBody String request) {
return this.service.getById(request) return this.service.getById(request);
;
} }
@PostMapping("/list") @PostMapping("/list")
public Page<CoalAnalysisDto> list(@RequestBody CommonQuery request) { public Page<CoalAnalysisDto> list(@RequestBody CommonQuery request) {
return this.service.list(request) return this.service.list(request);
;
} }
} }

View File

@@ -3,132 +3,145 @@ package cn.lihongjie.coal.coalAnalysis.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto; import cn.lihongjie.coal.base.dto.OrgCommonDto;
import cn.lihongjie.coal.coalInfo.entity.CoalInfoEntity; import cn.lihongjie.coal.coalInfo.entity.CoalInfoEntity;
import jakarta.validation.constraints.DecimalMin; import jakarta.validation.constraints.DecimalMin;
import java.util.HashMap;
import java.util.Map;
import lombok.Data; import lombok.Data;
import org.hibernate.annotations.Comment; import org.hibernate.annotations.Comment;
import java.util.HashMap;
import java.util.Map;
@Data @Data
public class CoalAnalysisDto extends OrgCommonDto { public class CoalAnalysisDto extends OrgCommonDto {
@Comment("关联的煤源信息") @Comment("关联的煤源信息")
private CoalInfoEntity coalInfo; private CoalInfoEntity coalInfo;
@Comment("参数 1 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param1;
@Comment("参数 1 ") @Comment("参数 2 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param1; private Double param2;
@Comment("参数 2 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param2;
@Comment("参数 3 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param3;
@Comment("参数 4 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param4;
@Comment("参数 5 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param5;
@Comment("参数 6 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param6;
@Comment("参数 7 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param7;
@Comment("参数 8 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param8;
@Comment("参数 9 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param9;
@Comment("参数 10 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param10;
@Comment("参数 11 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param11;
@Comment("参数 12 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param12;
@Comment("参数 13 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param13;
@Comment("参数 14 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param14;
@Comment("参数 15 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param15;
@Comment("参数 16 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param16;
@Comment("参数 17 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param17;
@Comment("参数 18 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param18;
@Comment("参数 19 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param19;
@Comment("参数 20 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param20;
@Comment("参数 3 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param3;
public Map<String, Object> toMap() { @Comment("参数 4 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param4;
@Comment("参数 5 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param5;
HashMap<String, Object> ma = new HashMap<>(); @Comment("参数 6 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param6;
@Comment("参数 7 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param7;
ma.put("param1", param1); @Comment("参数 8 ")
ma.put("param2", param2); @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
ma.put("param3", param3); private Double param8;
ma.put("param4", param4);
ma.put("param5", param5);
ma.put("param6", param6);
ma.put("param7", param7);
ma.put("param8", param8);
ma.put("param9", param9);
ma.put("param10", param10);
ma.put("param11", param11);
ma.put("param12", param12);
ma.put("param13", param13);
ma.put("param14", param14);
ma.put("param15", param15);
ma.put("param16", param16);
ma.put("param17", param17);
ma.put("param18", param18);
ma.put("param19", param19);
ma.put("param20", param20);
return ma; @Comment("参数 9 ")
} @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param9;
@Comment("参数 10 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param10;
public void updateFromMap(Map<String, Object> map) { @Comment("参数 11 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param11;
this.param1 = (Double) map.getOrDefault("param1", null); @Comment("参数 12 ")
this.param2 = (Double) map.getOrDefault("param2", null); @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
this.param3 = (Double) map.getOrDefault("param3", null); private Double param12;
this.param4 = (Double) map.getOrDefault("param4", null);
this.param5 = (Double) map.getOrDefault("param5", null); @Comment("参数 13 ")
this.param6 = (Double) map.getOrDefault("param6", null); @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
this.param7 = (Double) map.getOrDefault("param7", null); private Double param13;
this.param8 = (Double) map.getOrDefault("param8", null);
this.param9 = (Double) map.getOrDefault("param9", null); @Comment("参数 14 ")
this.param10 = (Double) map.getOrDefault("param10", null); @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
this.param11 = (Double) map.getOrDefault("param11", null); private Double param14;
this.param12 = (Double) map.getOrDefault("param12", null);
this.param13 = (Double) map.getOrDefault("param13", null); @Comment("参数 15 ")
this.param14 = (Double) map.getOrDefault("param14", null); @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
this.param15 = (Double) map.getOrDefault("param15", null); private Double param15;
this.param16 = (Double) map.getOrDefault("param16", null);
this.param17 = (Double) map.getOrDefault("param17", null); @Comment("参数 16 ")
this.param18 = (Double) map.getOrDefault("param18", null); @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
this.param19 = (Double) map.getOrDefault("param19", null); private Double param16;
this.param20 = (Double) map.getOrDefault("param20", null);
} @Comment("参数 17 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param17;
@Comment("参数 18 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param18;
@Comment("参数 19 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param19;
@Comment("参数 20 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param20;
public Map<String, Object> toMap() {
HashMap<String, Object> ma = new HashMap<>();
ma.put("param1", param1);
ma.put("param2", param2);
ma.put("param3", param3);
ma.put("param4", param4);
ma.put("param5", param5);
ma.put("param6", param6);
ma.put("param7", param7);
ma.put("param8", param8);
ma.put("param9", param9);
ma.put("param10", param10);
ma.put("param11", param11);
ma.put("param12", param12);
ma.put("param13", param13);
ma.put("param14", param14);
ma.put("param15", param15);
ma.put("param16", param16);
ma.put("param17", param17);
ma.put("param18", param18);
ma.put("param19", param19);
ma.put("param20", param20);
return ma;
}
public void updateFromMap(Map<String, Object> map) {
this.param1 = (Double) map.getOrDefault("param1", null);
this.param2 = (Double) map.getOrDefault("param2", null);
this.param3 = (Double) map.getOrDefault("param3", null);
this.param4 = (Double) map.getOrDefault("param4", null);
this.param5 = (Double) map.getOrDefault("param5", null);
this.param6 = (Double) map.getOrDefault("param6", null);
this.param7 = (Double) map.getOrDefault("param7", null);
this.param8 = (Double) map.getOrDefault("param8", null);
this.param9 = (Double) map.getOrDefault("param9", null);
this.param10 = (Double) map.getOrDefault("param10", null);
this.param11 = (Double) map.getOrDefault("param11", null);
this.param12 = (Double) map.getOrDefault("param12", null);
this.param13 = (Double) map.getOrDefault("param13", null);
this.param14 = (Double) map.getOrDefault("param14", null);
this.param15 = (Double) map.getOrDefault("param15", null);
this.param16 = (Double) map.getOrDefault("param16", null);
this.param17 = (Double) map.getOrDefault("param17", null);
this.param18 = (Double) map.getOrDefault("param18", null);
this.param19 = (Double) map.getOrDefault("param19", null);
this.param20 = (Double) map.getOrDefault("param20", null);
}
} }

View File

@@ -7,68 +7,86 @@ import org.hibernate.annotations.Comment;
@Data @Data
public class CreateCoalAnalysisDto extends OrgCommonDto { public class CreateCoalAnalysisDto extends OrgCommonDto {
@Comment("关联的煤源信息") @Comment("关联的煤源信息")
private String coalInfo; private String coalInfo;
@Comment("参数 1 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param1;
@Comment("参数 1 ") @Comment("参数 2 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param1; private Double param2;
@Comment("参数 2 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @Comment("参数 3 ")
private Double param2; @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
@Comment("参数 3 ") private Double param3;
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param3; @Comment("参数 4 ")
@Comment("参数 4 ") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") private Double param4;
private Double param4;
@Comment("参数 5 ") @Comment("参数 5 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param5; private Double param5;
@Comment("参数 6 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @Comment("参数 6 ")
private Double param6; @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
@Comment("参数 7 ") private Double param6;
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param7; @Comment("参数 7 ")
@Comment("参数 8 ") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") private Double param7;
private Double param8;
@Comment("参数 9 ") @Comment("参数 8 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param9; private Double param8;
@Comment("参数 10 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @Comment("参数 9 ")
private Double param10; @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
@Comment("参数 11 ") private Double param9;
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param11; @Comment("参数 10 ")
@Comment("参数 12 ") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") private Double param10;
private Double param12;
@Comment("参数 13 ") @Comment("参数 11 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param13; private Double param11;
@Comment("参数 14 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @Comment("参数 12 ")
private Double param14; @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
@Comment("参数 15 ") private Double param12;
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param15; @Comment("参数 13 ")
@Comment("参数 16 ") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") private Double param13;
private Double param16;
@Comment("参数 17 ") @Comment("参数 14 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param17; private Double param14;
@Comment("参数 18 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @Comment("参数 15 ")
private Double param18; @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
@Comment("参数 19 ") private Double param15;
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param19; @Comment("参数 16 ")
@Comment("参数 20 ") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") private Double param16;
private Double param20;
@Comment("参数 17 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param17;
@Comment("参数 18 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param18;
@Comment("参数 19 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param19;
@Comment("参数 20 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param20;
} }

View File

@@ -1,76 +1,92 @@
package cn.lihongjie.coal.coalAnalysis.dto; package cn.lihongjie.coal.coalAnalysis.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto; import cn.lihongjie.coal.base.dto.OrgCommonDto;
import cn.lihongjie.coal.coalInfo.entity.CoalInfoEntity;
import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.DecimalMin; import jakarta.validation.constraints.DecimalMin;
import lombok.Data; import lombok.Data;
import org.hibernate.annotations.Comment; import org.hibernate.annotations.Comment;
@Data @Data
public class UpdateCoalAnalysisDto extends OrgCommonDto { public class UpdateCoalAnalysisDto extends OrgCommonDto {
@Comment("关联的煤源信息") @Comment("关联的煤源信息")
private String coalInfo; private String coalInfo;
@Comment("参数 1 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param1;
@Comment("参数 1 ") @Comment("参数 2 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param1; private Double param2;
@Comment("参数 2 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @Comment("参数 3 ")
private Double param2; @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
@Comment("参数 3 ") private Double param3;
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param3; @Comment("参数 4 ")
@Comment("参数 4 ") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") private Double param4;
private Double param4;
@Comment("参数 5 ") @Comment("参数 5 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param5; private Double param5;
@Comment("参数 6 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @Comment("参数 6 ")
private Double param6; @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
@Comment("参数 7 ") private Double param6;
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param7; @Comment("参数 7 ")
@Comment("参数 8 ") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") private Double param7;
private Double param8;
@Comment("参数 9 ") @Comment("参数 8 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param9; private Double param8;
@Comment("参数 10 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @Comment("参数 9 ")
private Double param10; @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
@Comment("参数 11 ") private Double param9;
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param11; @Comment("参数 10 ")
@Comment("参数 12 ") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") private Double param10;
private Double param12;
@Comment("参数 13 ") @Comment("参数 11 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param13; private Double param11;
@Comment("参数 14 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @Comment("参数 12 ")
private Double param14; @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
@Comment("参数 15 ") private Double param12;
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param15; @Comment("参数 13 ")
@Comment("参数 16 ") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") private Double param13;
private Double param16;
@Comment("参数 17 ") @Comment("参数 14 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param17; private Double param14;
@Comment("参数 18 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @Comment("参数 15 ")
private Double param18; @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
@Comment("参数 19 ") private Double param15;
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param19; @Comment("参数 16 ")
@Comment("参数 20 ") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") private Double param16;
private Double param20;
@Comment("参数 17 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param17;
@Comment("参数 18 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param18;
@Comment("参数 19 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param19;
@Comment("参数 20 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param20;
} }

View File

@@ -11,70 +11,87 @@ import org.hibernate.annotations.Comment;
@Data @Data
@Entity @Entity
public class CoalAnalysisEntity extends OrgCommonEntity { public class CoalAnalysisEntity extends OrgCommonEntity {
@ManyToOne @ManyToOne
@Comment("关联的煤源信息") @Comment("关联的煤源信息")
private CoalInfoEntity coalInfo; private CoalInfoEntity coalInfo;
@Comment("参数 1 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param1;
@Comment("参数 1 ") @Comment("参数 2 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1") @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param1; private Double param2;
@Comment("参数 2 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param2;
@Comment("参数 3 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param3;
@Comment("参数 4 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param4;
@Comment("参数 5 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param5;
@Comment("参数 6 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param6;
@Comment("参数 7 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param7;
@Comment("参数 8 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param8;
@Comment("参数 9 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param9;
@Comment("参数 10 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param10;
@Comment("参数 11 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param11;
@Comment("参数 12 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param12;
@Comment("参数 13 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param13;
@Comment("参数 14 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param14;
@Comment("参数 15 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param15;
@Comment("参数 16 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param16;
@Comment("参数 17 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param17;
@Comment("参数 18 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param18;
@Comment("参数 19 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param19;
@Comment("参数 20 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param20;
@Comment("参数 3 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param3;
@Comment("参数 4 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param4;
@Comment("参数 5 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param5;
@Comment("参数 6 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param6;
@Comment("参数 7 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param7;
@Comment("参数 8 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param8;
@Comment("参数 9 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param9;
@Comment("参数 10 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param10;
@Comment("参数 11 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param11;
@Comment("参数 12 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param12;
@Comment("参数 13 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param13;
@Comment("参数 14 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param14;
@Comment("参数 15 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param15;
@Comment("参数 16 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param16;
@Comment("参数 17 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param17;
@Comment("参数 18 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param18;
@Comment("参数 19 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param19;
@Comment("参数 20 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param20;
} }

View File

@@ -12,7 +12,7 @@ import org.mapstruct.control.DeepClone;
@Mapper( @Mapper(
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING, componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
uses = {CommonMapper.class}, uses = {CommonMapper.class},
mappingControl = DeepClone.class mappingControl = DeepClone.class)
) public interface CoalAnalysisMapper
public interface CoalAnalysisMapper extends BaseMapper<CoalAnalysisEntity, CoalAnalysisDto, CreateCoalAnalysisDto, UpdateCoalAnalysisDto> { extends BaseMapper<
} CoalAnalysisEntity, CoalAnalysisDto, CreateCoalAnalysisDto, UpdateCoalAnalysisDto> {}

View File

@@ -5,5 +5,4 @@ import cn.lihongjie.coal.coalAnalysis.entity.CoalAnalysisEntity;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@Repository @Repository
public interface CoalAnalysisRepository extends BaseRepository<CoalAnalysisEntity> { public interface CoalAnalysisRepository extends BaseRepository<CoalAnalysisEntity> {}
}

View File

@@ -14,6 +14,11 @@ import cn.lihongjie.coal.coalParameterDef.repository.CoalParameterDefRepository;
import cn.lihongjie.coal.common.Ctx; import cn.lihongjie.coal.common.Ctx;
import cn.lihongjie.coal.common.GroovyScriptUtils; import cn.lihongjie.coal.common.GroovyScriptUtils;
import cn.lihongjie.coal.exception.BizException; import cn.lihongjie.coal.exception.BizException;
import java.math.BigDecimal;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -25,98 +30,82 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service @Service
@Slf4j @Slf4j
public class CoalAnalysisService extends BaseService<CoalAnalysisEntity, CoalAnalysisRepository> { public class CoalAnalysisService extends BaseService<CoalAnalysisEntity, CoalAnalysisRepository> {
@Autowired @Autowired private CoalAnalysisRepository repository;
private CoalAnalysisRepository repository;
@Autowired @Autowired private CoalAnalysisMapper mapper;
private CoalAnalysisMapper mapper;
@Autowired @Autowired private ConversionService conversionService;
private ConversionService conversionService;
public CoalAnalysisDto create(CreateCoalAnalysisDto request) { public CoalAnalysisDto create(CreateCoalAnalysisDto request) {
CoalAnalysisEntity entity = mapper.toEntity(request); CoalAnalysisEntity entity = mapper.toEntity(request);
this.repository.save(entity);
this.repository.save(entity); return getById(entity.getId());
return getById(entity.getId())
;
} }
@Autowired @Autowired CoalParameterDefRepository coalParameterDefRepository;
CoalParameterDefRepository coalParameterDefRepository;
public CoalAnalysisDto calculate(CoalAnalysisDto dto) { public CoalAnalysisDto calculate(CoalAnalysisDto dto) {
List<CoalParameterDefEntity> parameters = coalParameterDefRepository.findByOrganizationId(Ctx.currentUser().getOrganizationId()); List<CoalParameterDefEntity> parameters =
coalParameterDefRepository.findByOrganizationId(Ctx.currentUser().getOrganizationId());
List<CoalParameterDefEntity> toCalculate =
parameters.stream()
.filter(x -> StringUtils.equalsIgnoreCase(x.getInputType(), "1"))
.sorted(Comparator.comparing(x -> ObjectUtils.defaultIfNull(x.getPriority(), -1)))
.collect(Collectors.toList());
List<CoalParameterDefEntity> toCalculate = parameters.stream().filter(x -> StringUtils.equalsIgnoreCase(x.getInputType(), "1")).sorted(Comparator.comparing(x -> ObjectUtils.defaultIfNull(x.getPriority(), -1))).collect(Collectors.toList()); Map<String, Object> map = dto.toMap();
for (CoalParameterDefEntity def : toCalculate) {
Map<String, Object> map = dto.toMap(); Object exec = GroovyScriptUtils.exec(def.getFormula0(), map);
for (CoalParameterDefEntity def : toCalculate) {
Object exec = GroovyScriptUtils.exec(def.getFormula0(), map);
if (exec!=null && !(exec instanceof Number)) {
throw new BizException("计算结果不是数字");
}
Double value = exec != null ? NumberUtils.toDouble(exec + "") : null;
if (value != null) {
value = BigDecimal.valueOf(value).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
}
map.put(def.getCode(), value);
}
dto.updateFromMap(map);
return dto;
if (exec != null && !(exec instanceof Number)) {
throw new BizException("计算结果不是数字");
}
Double value = exec != null ? NumberUtils.toDouble(exec + "") : null;
if (value != null) {
value = BigDecimal.valueOf(value).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
}
map.put(def.getCode(), value);
} }
dto.updateFromMap(map);
return dto;
}
public CoalAnalysisDto update(UpdateCoalAnalysisDto request) { public CoalAnalysisDto update(UpdateCoalAnalysisDto request) {
CoalAnalysisEntity entity = this.repository.get(request.getId()); CoalAnalysisEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request); this.mapper.updateEntity(entity, request);
this.repository.save(entity); this.repository.save(entity);
return getById(entity.getId()) return getById(entity.getId());
;
} }
public void delete(IdRequest request) { public void delete(IdRequest request) {
this.repository.deleteAllById(request.getIds()) this.repository.deleteAllById(request.getIds());
;
} }
public CoalAnalysisDto getById(String id) { public CoalAnalysisDto getById(String id) {
CoalAnalysisEntity entity = repository.get(id); CoalAnalysisEntity entity = repository.get(id);
return mapper.toDto(entity);
return mapper.toDto(entity)
;
} }
public Page<CoalAnalysisDto> list(CommonQuery query) { public Page<CoalAnalysisDto> list(CommonQuery query) {
Page<CoalAnalysisEntity> page = repository.findAll(query.specification(conversionService), PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders()))); Page<CoalAnalysisEntity> page =
repository.findAll(
query.specification(conversionService),
PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders())));
return page.map(this.mapper::toDto);
return page.map(this.mapper::toDto)
;
} }
} }

View File

@@ -6,9 +6,9 @@ import cn.lihongjie.coal.base.controller.BaseController;
import cn.lihongjie.coal.base.dto.CommonQuery; import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest; import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.coalBlend.dto.CoalBlendDto; import cn.lihongjie.coal.coalBlend.dto.CoalBlendDto;
import cn.lihongjie.coal.coalBlend.service.CoalBlendService;
import cn.lihongjie.coal.coalBlend.dto.CreateCoalBlendDto; import cn.lihongjie.coal.coalBlend.dto.CreateCoalBlendDto;
import cn.lihongjie.coal.coalBlend.dto.UpdateCoalBlendDto; import cn.lihongjie.coal.coalBlend.dto.UpdateCoalBlendDto;
import cn.lihongjie.coal.coalBlend.service.CoalBlendService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@@ -22,45 +22,40 @@ import org.springframework.web.bind.annotation.RestController;
@Anonymous @Anonymous
public class CoalBlendController extends BaseController { public class CoalBlendController extends BaseController {
@Autowired @Autowired CoalBlendService service;
CoalBlendService service;
@PostMapping("/blend")
@SysLog(action = "配煤")
public CoalBlendDto blend(@RequestBody CreateCoalBlendDto dto) {
return this.service.blend(dto);
}
@PostMapping("/blend") @PostMapping("/create")
@SysLog(action = "配煤") @SysLog(action = "新增")
public CoalBlendDto blend(@RequestBody CreateCoalBlendDto dto) { public CoalBlendDto create(@RequestBody CreateCoalBlendDto dto) {
return this.service.blend(dto); return this.service.create(dto);
} }
@PostMapping("/create") @PostMapping("/update")
@SysLog(action = "新增") @SysLog(action = "编辑")
public CoalBlendDto create(@RequestBody CreateCoalBlendDto dto) { public CoalBlendDto update(@RequestBody UpdateCoalBlendDto dto) {
return this.service.create(dto); return this.service.update(dto);
} }
@PostMapping("/update") @PostMapping("/delete")
@SysLog(action = "编辑") @SysLog(action = "删除")
public CoalBlendDto update(@RequestBody UpdateCoalBlendDto dto) { public Object delete(@RequestBody IdRequest dto) {
return this.service.update(dto); this.service.delete(dto);
} return true;
}
@PostMapping("/list")
public Page<CoalBlendDto> list(@RequestBody CommonQuery dto) {
return this.service.list(dto);
}
@PostMapping("/delete") @PostMapping("/getById")
@SysLog(action = "删除") public CoalBlendDto getById(@RequestBody IdRequest dto) {
public Object delete(@RequestBody IdRequest dto) { return this.service.getById(dto.getId());
this.service.delete(dto); }
return true;
}
@PostMapping("/list")
public Page<CoalBlendDto> list(@RequestBody CommonQuery dto) {
return this.service.list(dto);
}
@PostMapping("/getById")
public CoalBlendDto getById(@RequestBody IdRequest dto) {
return this.service.getById(dto.getId());
}
} }

View File

@@ -14,92 +14,182 @@ import org.hibernate.validator.constraints.Range;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class CoalBlendCoalInfoDto extends OrgCommonDto { public class CoalBlendCoalInfoDto extends OrgCommonDto {
@NotEmpty(message = "煤名称不能为空") @NotEmpty(message = "煤名称不能为空")
private String name; 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("比例最小值") @Comment("参数 6 ")
@Range(groups = CoalBlendEntity.BlendGroup.class,min = 0, max = 100, message = "无效的比例") @DecimalMin(
private Integer minPercent; groups = CoalBlendEntity.BlendGroup.class,
@Comment("比例最大值") value = "0.1",
@Range(groups = CoalBlendEntity.BlendGroup.class,min = 0, max = 100, message = "无效的比例") inclusive = true,
private Integer maxPercent; message = "参数不能小于0.1")
private Double param6;
@Comment("参数 1 ") @Comment("参数 7 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1") @DecimalMin(
private Double param1; groups = CoalBlendEntity.BlendGroup.class,
@Comment("参数 2 ") value = "0.1",
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1") inclusive = true,
private Double param2; message = "参数不能小于0.1")
@Comment("参数 3 ") private Double param7;
@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;
@Comment("参数 8 ")
@DecimalMin(
groups = CoalBlendEntity.BlendGroup.class,
value = "0.1",
inclusive = true,
message = "参数不能小于0.1")
private Double param8;
@SneakyThrows @Comment("参数 9 ")
public Double getParam(String param) { @DecimalMin(
return (Double) FieldUtils.getField(this.getClass(), param, true).get(this); 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

@@ -6,47 +6,41 @@ import cn.lihongjie.coal.coalBlend.entity.CoalParameterDefVo;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size; import jakarta.validation.constraints.Size;
import java.util.List;
import lombok.Data; import lombok.Data;
import org.hibernate.annotations.Comment; import org.hibernate.annotations.Comment;
import java.util.List;
@Data @Data
@Comment("配煤记录") @Comment("配煤记录")
public class CoalBlendDto extends OrgCommonDto { public class CoalBlendDto extends OrgCommonDto {
@NotEmpty(message = "煤参数定义不能为空")
private List<CoalParameterDefVo> parameterDefs;
@NotEmpty(message = "参数定义不能为空") @NotEmpty(message = "煤不能为空")
private List<CoalParameterDefVo> parameterDefs; @Size(message = "至少需要两种煤", min = 2)
private List<CoalBlendCoalInfoDto> coals;
@NotNull(message = "约束条件不能为空")
private CoalBlendConstrainVo constrains;
@NotEmpty(message = "煤不能为空") private List<CoalBlendResultInfoDto> results;
@Size(message = "至少需要两种煤", min = 2)
private List<CoalBlendCoalInfoDto> coals;
@NotNull(message = "约束条件不能为空")
private CoalBlendConstrainVo constrains;
private List<CoalBlendResultInfoDto> results; private String blendTypeName;
private String blendType;
private String blendTypeName; @Comment("结果个数")
private String blendType; private Integer count = 20;
@Comment("结果个数") @Comment("最长等待时间")
private Integer count = 20; private Integer maxTime = 10;
@Comment("铲车配煤 配比之和 最大值")
private Integer type2PercentSum = 10;
@Comment("最长等待时间") @Comment("目标参数, 比如: param1 param2")
private Integer maxTime = 10; private String targetParam = "";
@Comment("铲车配煤 配比之和 最大值")
private Integer type2PercentSum = 10;
@Comment("目标参数, 比如: param1 param2")
private String targetParam = "";
@Comment("求目标参数最大值 -1 最小值 1")
private Integer targetOrder = -1;
@Comment("求目标参数最大值 -1 最小值 1")
private Integer targetOrder = -1;
} }

View File

@@ -3,57 +3,39 @@ package cn.lihongjie.coal.coalBlend.dto;
import cn.lihongjie.coal.coal.CoalConstraint; import cn.lihongjie.coal.coal.CoalConstraint;
import cn.lihongjie.coal.coal.CoalInfo; import cn.lihongjie.coal.coal.CoalInfo;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import lombok.Data;
@Data @Data
public class CoalBlendRequest { public class CoalBlendRequest {
private List<CoalInfo> coals; private List<CoalInfo> coals;
private List<CoalConstraint> constraints;
@JsonIgnore private Map<String, CoalConstraint> constraintMap;
private List<CoalConstraint> constraints; /** 1 高精度 2 低精度(用于铲车配煤 类似 1:3 整比例) */
@JsonIgnore private Integer type = 1;
private Map<String, CoalConstraint> constraintMap; /** 低精度配比之和最大值 */
private int percent2Sum = 10;
/** public Map<String, CoalConstraint> getConstraintMap() {
* 1 高精度 if (constraintMap == null) {
* 2 低精度(用于铲车配煤 类似 1:3 整比例) if (constraints != null) {
*/
private Integer type = 1;
/**
* 低精度配比之和最大值
*/
private int percent2Sum = 10;
constraintMap = constraints.stream().collect(Collectors.toMap(e -> e.getCode(), e -> e));
} else {
public Map<String, CoalConstraint> getConstraintMap() { constraintMap = new HashMap<>();
if (constraintMap == null) { }
if (constraints != null) {
constraintMap = constraints.stream().collect(Collectors.toMap(e -> e.getCode(), e -> e));
}else {
constraintMap = new HashMap<>();
}
}
return constraintMap;
} }
return constraintMap;
}
/** /** 结果个数 */
* 结果个数 private Long count = 10L;
*/
private Long count = 10L;
/**
* 最长等待时间
*/
private Long maxTime = 10L;
/** 最长等待时间 */
private Long maxTime = 10L;
} }

View File

@@ -1,31 +1,27 @@
package cn.lihongjie.coal.coalBlend.dto; package cn.lihongjie.coal.coalBlend.dto;
import cn.lihongjie.coal.coal.CoalInfo; import cn.lihongjie.coal.coal.CoalInfo;
import lombok.Data;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import lombok.Data;
@Data @Data
public class CoalBlendResult { public class CoalBlendResult {
private long numBranches = 0; private long numBranches = 0;
private long numConflicts = 0; private long numConflicts = 0;
private long wallTime = 0; private long wallTime = 0;
private long userTime = 0; private long userTime = 0;
private List<CoalInfo> coals = new ArrayList<>(); private List<CoalInfo> coals = new ArrayList<>();
private int totalCount; private int totalCount;
public String tableString() {
String headerLine = String.format("totalCount %s numBranches %s numConflicts %s wallTime %s userTime %s \n",
totalCount, numBranches,
numConflicts, wallTime, userTime);
String collect = coals.stream().map(x -> x.rowString()).collect(Collectors.joining("\n"));
return headerLine + collect;
}
public String tableString() {
String headerLine =
String.format(
"totalCount %s numBranches %s numConflicts %s wallTime %s userTime %s \n",
totalCount, numBranches, numConflicts, wallTime, userTime);
String collect = coals.stream().map(x -> x.rowString()).collect(Collectors.joining("\n"));
return headerLine + collect;
}
} }

View File

@@ -5,6 +5,9 @@ import cn.lihongjie.coal.coalBlend.entity.CoalBlendEntity;
import cn.lihongjie.coal.coalBlend.entity.CoalPercentVo; import cn.lihongjie.coal.coalBlend.entity.CoalPercentVo;
import jakarta.validation.constraints.DecimalMin; import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@@ -12,103 +15,186 @@ import lombok.SneakyThrows;
import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.commons.lang3.reflect.FieldUtils;
import org.hibernate.annotations.Comment; import org.hibernate.annotations.Comment;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class CoalBlendResultInfoDto extends OrgCommonDto { public class CoalBlendResultInfoDto extends OrgCommonDto {
@NotEmpty(message = "煤名称不能为空") @NotEmpty(message = "煤名称不能为空")
private String name; 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;
private List<CoalPercentVo> percentInfos; @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("参数 1 ") @Comment("参数 8 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1") @DecimalMin(
private Double param1; groups = CoalBlendEntity.BlendGroup.class,
@Comment("参数 2 ") value = "0.1",
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1") inclusive = true,
private Double param2; message = "参数不能小于0.1")
@Comment("参数 3 ") private Double param8;
@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;
@Comment("参数 9 ")
@DecimalMin(
groups = CoalBlendEntity.BlendGroup.class,
value = "0.1",
inclusive = true,
message = "参数不能小于0.1")
private Double param9;
@SneakyThrows @Comment("参数 10 ")
public Double getParam(String param) { @DecimalMin(
return (Double) FieldUtils.getField(this.getClass(), param, true).get(this); 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;
public long getHashKey(){ @Comment("参数 13 ")
@DecimalMin(
groups = CoalBlendEntity.BlendGroup.class,
value = "0.1",
inclusive = true,
message = "参数不能小于0.1")
private Double param13;
return @Comment("参数 14 ")
Arrays.hashCode(this.getPercentInfos().stream().sorted(Comparator.comparing(x->x.getPercent())).toArray(CoalPercentVo[]::new)); @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

@@ -6,48 +6,41 @@ import cn.lihongjie.coal.coalBlend.entity.CoalParameterDefVo;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size; import jakarta.validation.constraints.Size;
import java.util.List;
import lombok.Data; import lombok.Data;
import org.hibernate.annotations.Comment; import org.hibernate.annotations.Comment;
import java.util.List;
@Data @Data
@Comment("配煤记录") @Comment("配煤记录")
public class CreateCoalBlendDto extends OrgCommonDto { public class CreateCoalBlendDto extends OrgCommonDto {
@NotEmpty(message = "煤参数定义不能为空")
private List<CoalParameterDefVo> parameterDefs;
@NotEmpty(message = "参数定义不能为空") @NotEmpty(message = "煤不能为空")
private List<CoalParameterDefVo> parameterDefs; @Size(message = "至少需要两种煤", min = 2)
private List<CoalBlendCoalInfoDto> coals;
@NotNull(message = "约束条件不能为空")
private CoalBlendConstrainVo constrains;
@NotEmpty(message = "煤不能为空") private List<CoalBlendResultInfoDto> results;
@Size(message = "至少需要两种煤", min = 2)
private List<CoalBlendCoalInfoDto> coals;
@NotNull(message = "约束条件不能为空")
private CoalBlendConstrainVo constrains;
private List<CoalBlendResultInfoDto> results; private String blendTypeName;
private String blendType;
private String blendTypeName; @Comment("结果个数")
private String blendType; private Integer count = 20;
@Comment("最长等待时间")
private Integer maxTime = 10;
@Comment("结果个数") @Comment("铲车配煤 配比之和 最大值")
private Integer count = 20; private Integer type2PercentSum = 10;
@Comment("最长等待时间")
private Integer maxTime = 10;
@Comment("铲车配煤 配比之和 最大值")
private Integer type2PercentSum = 10;
@Comment("目标参数, 比如: param1 param2")
private String targetParam = "";
@Comment("求目标参数最大值 -1 最小值 1")
private Integer targetOrder = -1;
@Comment("目标参数, 比如: param1 param2")
private String targetParam = "";
@Comment("求目标参数最大值 -1 最小值 1")
private Integer targetOrder = -1;
} }

View File

@@ -6,47 +6,40 @@ import cn.lihongjie.coal.coalBlend.entity.CoalParameterDefVo;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size; import jakarta.validation.constraints.Size;
import java.util.List;
import lombok.Data; import lombok.Data;
import org.hibernate.annotations.Comment; import org.hibernate.annotations.Comment;
import java.util.List;
@Data @Data
@Comment("配煤记录") @Comment("配煤记录")
public class UpdateCoalBlendDto extends OrgCommonDto { public class UpdateCoalBlendDto extends OrgCommonDto {
@NotEmpty(message = "煤参数定义不能为空")
private List<CoalParameterDefVo> parameterDefs;
@NotEmpty(message = "参数定义不能为空") @NotEmpty(message = "煤不能为空")
private List<CoalParameterDefVo> parameterDefs; @Size(message = "至少需要两种煤", min = 2)
private List<CoalBlendCoalInfoDto> coals;
@NotNull(message = "约束条件不能为空")
private CoalBlendConstrainVo constrains;
@NotEmpty(message = "煤不能为空") private List<CoalBlendResultInfoDto> results;
@Size(message = "至少需要两种煤", min = 2) private String blendTypeName;
private List<CoalBlendCoalInfoDto> coals; private String blendType;
@NotNull(message = "约束条件不能为空")
private CoalBlendConstrainVo constrains;
private List<CoalBlendResultInfoDto> results; @Comment("结果个数")
private String blendTypeName; private Integer count = 20;
private String blendType;
@Comment("最长等待时间")
private Integer maxTime = 10;
@Comment("结果个数") @Comment("铲车配煤 配比之和 最大值")
private Integer count = 20; private Integer type2PercentSum = 10;
@Comment("最长等待时间")
private Integer maxTime = 10;
@Comment("铲车配煤 配比之和 最大值")
private Integer type2PercentSum = 10;
@Comment("目标参数, 比如: param1 param2")
private String targetParam = "";
@Comment("求目标参数最大值 -1 最小值 1")
private Integer targetOrder = -1;
@Comment("目标参数, 比如: param1 param2")
private String targetParam = "";
@Comment("求目标参数最大值 -1 最小值 1")
private Integer targetOrder = -1;
} }

View File

@@ -12,95 +12,186 @@ import org.hibernate.validator.constraints.Range;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@With @With
@Entity @Entity
public class CoalBlendCoalInfoEntity extends OrgCommonEntity { public class CoalBlendCoalInfoEntity extends OrgCommonEntity {
@NotEmpty(message = "煤名称不能为空") @NotEmpty(message = "煤名称不能为空")
private String name; private String name;
@ManyToOne() private CoalBlendEntity coal;
@ManyToOne() @Comment("比例最小值")
private CoalBlendEntity coal; @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("比例最小值") @Comment("参数 4 ")
@Range(groups = CoalBlendEntity.BlendGroup.class,min = 0, max = 100, message = "无效的比例") @DecimalMin(
private Integer minPercent; groups = CoalBlendEntity.BlendGroup.class,
@Comment("比例最大值") value = "0.1",
@Range(groups = CoalBlendEntity.BlendGroup.class,min = 0, max = 100, message = "无效的比例") inclusive = true,
private Integer maxPercent; message = "参数不能小于0.1")
private Double param4;
@Comment("参数 1 ") @Comment("参数 5 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1") @DecimalMin(
private Double param1; groups = CoalBlendEntity.BlendGroup.class,
@Comment("参数 2 ") value = "0.1",
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1") inclusive = true,
private Double param2; message = "参数不能小于0.1")
@Comment("参数 3 ") private Double param5;
@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;
@Comment("参数 6 ")
@DecimalMin(
groups = CoalBlendEntity.BlendGroup.class,
value = "0.1",
inclusive = true,
message = "参数不能小于0.1")
private Double param6;
@SneakyThrows @Comment("参数 7 ")
public Double getParam(String param) { @DecimalMin(
return (Double) FieldUtils.getField(this.getClass(), param, true).get(this); 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

@@ -10,207 +10,203 @@ import org.hibernate.annotations.Comment;
@Data @Data
public class CoalBlendConstrainVo { public class CoalBlendConstrainVo {
@Comment("参数1最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param1Max;
@Comment("参数1最") @Comment("参数1最")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param1Max; private Double param1Min;
@Comment("参数1最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效")
private Double param1Min;
@Comment("参数2最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效")
private Double param2Min;
@Comment("参数2最") @Comment("参数2最")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param2Max; private Double param2Min;
@Comment("参数3最小") @Comment("参数2最大")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param3Min; private Double param2Max;
@Comment("参数3最") @Comment("参数3最")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param3Max; private Double param3Min;
@Comment("参数4最小") @Comment("参数3最大")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param4Min; private Double param3Max;
@Comment("参数4最") @Comment("参数4最")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param4Max; private Double param4Min;
@Comment("参数5最小") @Comment("参数4最大")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param5Min; private Double param4Max;
@Comment("参数5最") @Comment("参数5最")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param5Max; private Double param5Min;
@Comment("参数6最小") @Comment("参数5最大")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param6Min; private Double param5Max;
@Comment("参数6最") @Comment("参数6最")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param6Max; private Double param6Min;
@Comment("参数7最小") @Comment("参数6最大")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param7Min; private Double param6Max;
@Comment("参数7最") @Comment("参数7最")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param7Max; private Double param7Min;
@Comment("参数8最小") @Comment("参数7最大")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param8Min; private Double param7Max;
@Comment("参数8最") @Comment("参数8最")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param8Max; private Double param8Min;
@Comment("参数9最小") @Comment("参数8最大")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param9Min; private Double param8Max;
@Comment("参数9最") @Comment("参数9最")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param9Max; private Double param9Min;
@Comment("参数10最小") @Comment("参数9最大")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param10Min; private Double param9Max;
@Comment("参数10最") @Comment("参数10最")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param10Max; private Double param10Min;
@Comment("参数11最小") @Comment("参数10最大")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param11Min; private Double param10Max;
@Comment("参数11最") @Comment("参数11最")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param11Max; private Double param11Min;
@Comment("参数12最小") @Comment("参数11最大")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param12Min; private Double param11Max;
@Comment("参数12最") @Comment("参数12最")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param12Max; private Double param12Min;
@Comment("参数13最小") @Comment("参数12最大")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param13Min; private Double param12Max;
@Comment("参数13最") @Comment("参数13最")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param13Max; private Double param13Min;
@Comment("参数14最小") @Comment("参数13最大")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param14Min; private Double param13Max;
@Comment("参数14最") @Comment("参数14最")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param14Max; private Double param14Min;
@Comment("参数15最小") @Comment("参数14最大")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param15Min; private Double param14Max;
@Comment("参数15最") @Comment("参数15最")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param15Max; private Double param15Min;
@Comment("参数16最小") @Comment("参数15最大")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param16Min; private Double param15Max;
@Comment("参数16最") @Comment("参数16最")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param16Max; private Double param16Min;
@Comment("参数17最小") @Comment("参数16最大")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param17Min; private Double param16Max;
@Comment("参数17最") @Comment("参数17最")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param17Max; private Double param17Min;
@Comment("参数18最小") @Comment("参数17最大")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param18Min; private Double param17Max;
@Comment("参数18最") @Comment("参数18最")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效") @DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效") @DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param18Max; private Double param18Min;
@Comment("参数19最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效")
private Double param19Min;
@Comment("参数19最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效")
private Double param19Max;
@Comment("参数20最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效")
private Double param20Min;
@Comment("参数20最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class,value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class,value = "0.1", message = "最小值无效")
private Double param20Max;
@Comment("参数18最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param18Max;
@Comment("参数19最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param19Min;
@Comment("参数19最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param19Max;
@Comment("参数20最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param20Min;
@Comment("参数20最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param20Max;
} }

View File

@@ -5,111 +5,196 @@ import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.DecimalMin; import jakarta.validation.constraints.DecimalMin;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import lombok.*; import lombok.*;
import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.commons.lang3.reflect.FieldUtils;
import org.hibernate.annotations.Comment; import org.hibernate.annotations.Comment;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@With @With
@Entity @Entity
public class CoalBlendResultInfoEntity extends OrgCommonEntity { public class CoalBlendResultInfoEntity extends OrgCommonEntity {
private String name; private String name;
@ElementCollection private List<CoalPercentVo> percentInfos;
@ManyToOne private CoalBlendEntity coal;
@Comment("参数 1 ")
@DecimalMin(
groups = CoalBlendEntity.BlendGroup.class,
value = "0.1",
inclusive = true,
message = "参数不能小于0.1")
private Double param1;
@ElementCollection @Comment("参数 2 ")
private List<CoalPercentVo> percentInfos; @DecimalMin(
groups = CoalBlendEntity.BlendGroup.class,
value = "0.1",
inclusive = true,
message = "参数不能小于0.1")
private Double param2;
@ManyToOne @Comment("参数 3 ")
private CoalBlendEntity coal; @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("参数 1 ") @Comment("参数 7 ")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1") @DecimalMin(
private Double param1; groups = CoalBlendEntity.BlendGroup.class,
@Comment("参数 2 ") value = "0.1",
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", inclusive = true, message = "参数不能小于0.1") inclusive = true,
private Double param2; message = "参数不能小于0.1")
@Comment("参数 3 ") private Double param7;
@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;
@Comment("参数 8 ")
@DecimalMin(
groups = CoalBlendEntity.BlendGroup.class,
value = "0.1",
inclusive = true,
message = "参数不能小于0.1")
private Double param8;
@SneakyThrows @Comment("参数 9 ")
public Double getParam(String param) { @DecimalMin(
return (Double) FieldUtils.getField(this.getClass(), param, true).get(this); 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;
public long getHashKey(){ @Comment("参数 12 ")
@DecimalMin(
groups = CoalBlendEntity.BlendGroup.class,
value = "0.1",
inclusive = true,
message = "参数不能小于0.1")
private Double param12;
return @Comment("参数 13 ")
Arrays.hashCode(this.getPercentInfos().stream().sorted(Comparator.comparing(x->x.getPercent())).toArray(CoalPercentVo[]::new)); @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,5 +1,6 @@
package cn.lihongjie.coal.coalBlend.entity; package cn.lihongjie.coal.coalBlend.entity;
public enum CoalBlendType { public enum CoalBlendType {
TYPE1, TYPE2 TYPE1,
TYPE2
} }

View File

@@ -7,27 +7,23 @@ import org.hibernate.annotations.Comment;
@Embeddable @Embeddable
@Data @Data
public class CoalParameterDefVo { public class CoalParameterDefVo {
@Comment("名称") @Comment("名称")
private String name; private String name;
@Comment("编码") @Comment("编码")
private String code; private String code;
@Comment("备注")
private String remarks;
@Comment("备注") @Comment("备注")
private String remarks; private String parentName;
@Comment("备注") @Comment("排序键")
private String parentName; private Integer sortKey;
@Comment("常用状态 0 禁用 1 启用")
private Integer status;
private String id;
@Comment("排序键")
private Integer sortKey;
@Comment("常用状态 0 禁用 1 启用")
private Integer status;
private String id;
} }

View File

@@ -1,6 +1,5 @@
package cn.lihongjie.coal.coalBlend.entity; package cn.lihongjie.coal.coalBlend.entity;
import jakarta.persistence.Embeddable; import jakarta.persistence.Embeddable;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@@ -13,14 +12,12 @@ import org.hibernate.annotations.Comment;
@NoArgsConstructor @NoArgsConstructor
public class CoalPercentVo { public class CoalPercentVo {
@Comment("煤名称") @Comment("煤名称")
private String name; private String name;
@Comment("煤的精确比例")
private Double percent;
@Comment("煤的铲车配煤比例")
private Double type2Percent;
@Comment("煤的精确比例")
private Double percent;
@Comment("煤的铲车配煤比例")
private Double type2Percent;
} }

View File

@@ -1,6 +1,5 @@
package cn.lihongjie.coal.coalBlend.mapper; package cn.lihongjie.coal.coalBlend.mapper;
import cn.lihongjie.coal.base.mapper.BaseMapper; import cn.lihongjie.coal.base.mapper.BaseMapper;
import cn.lihongjie.coal.base.mapper.CommonMapper; import cn.lihongjie.coal.base.mapper.CommonMapper;
import cn.lihongjie.coal.coalBlend.dto.CoalBlendDto; import cn.lihongjie.coal.coalBlend.dto.CoalBlendDto;
@@ -15,27 +14,24 @@ import org.mapstruct.MappingTarget;
import org.mapstruct.control.DeepClone; import org.mapstruct.control.DeepClone;
@Mapper( @Mapper(
componentModel = MappingConstants.ComponentModel.SPRING, componentModel = MappingConstants.ComponentModel.SPRING,
uses = {CommonMapper.class}, uses = {CommonMapper.class},
mappingControl = DeepClone.class mappingControl = DeepClone.class)
public interface CoalBlendMapper
extends BaseMapper<CoalBlendEntity, CoalBlendDto, CreateCoalBlendDto, UpdateCoalBlendDto> {
) @AfterMapping
public interface CoalBlendMapper extends BaseMapper<CoalBlendEntity, CoalBlendDto, CreateCoalBlendDto, UpdateCoalBlendDto> { public default void convertNameToUpperCase(
CreateCoalBlendDto dto, @MappingTarget CoalBlendEntity entity) {
if (CollectionUtils.isNotEmpty(entity.getCoals())) {
@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));
}
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

@@ -5,5 +5,4 @@ import cn.lihongjie.coal.coalBlend.entity.CoalBlendEntity;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@Repository @Repository
public interface CoalBlendRepository extends BaseRepository<CoalBlendEntity> { public interface CoalBlendRepository extends BaseRepository<CoalBlendEntity> {}
}

View File

@@ -24,89 +24,73 @@ import org.springframework.util.StopWatch;
@Slf4j @Slf4j
public class CoalBlendService extends BaseService<CoalBlendEntity, CoalBlendRepository> { public class CoalBlendService extends BaseService<CoalBlendEntity, CoalBlendRepository> {
@Autowired @Autowired CoalBlendRepository repository;
CoalBlendRepository repository;
@Autowired @Autowired CoalBlendMapper mapper;
CoalBlendMapper mapper;
@PostConstruct
public void init() {}
@PostConstruct public CoalBlendDto create(CreateCoalBlendDto request) {
public void init() { request.getCoals().forEach(x -> x.setId(null));
CoalBlendEntity entity = mapper.toEntity(request);
} this.repository.save(entity);
return getById(entity.getId());
}
public CoalBlendDto update(UpdateCoalBlendDto request) {
CoalBlendEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
public CoalBlendDto create(CreateCoalBlendDto request) { this.repository.save(entity);
request.getCoals().forEach(x -> x.setId(null));
CoalBlendEntity entity = mapper.toEntity(request); return getById(entity.getId());
}
public void delete(IdRequest request) {
this.repository.save(entity); this.repository.deleteAllById(request.getIds());
return getById(entity.getId()); }
} public CoalBlendDto getById(String id) {
CoalBlendEntity entity = repository.get(id);
public CoalBlendDto update(UpdateCoalBlendDto request) { return mapper.toDto(entity);
CoalBlendEntity entity = this.repository.get(request.getId()); }
this.mapper.updateEntity(entity, request);
this.repository.save(entity); @Autowired ConversionService conversionService;
return getById(entity.getId()); public Page<CoalBlendDto> list(CommonQuery query) {
}
Page<CoalBlendEntity> page =
repository.findAll(
query.specification(conversionService),
PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders())));
public void delete(IdRequest request) { return page.map(this.mapper::toDto);
}
this.repository.deleteAllById(request.getIds()); @Autowired RoundMapper roundMapper;
} public CoalBlendDto blend(CreateCoalBlendDto dto) {
StopWatch stopWatch = new StopWatch();
public CoalBlendDto getById(String id) { stopWatch.start("toEntity");
CoalBlendEntity entity = this.mapper.toEntity(dto);
stopWatch.stop();
stopWatch.start("blend");
entity.blend();
stopWatch.stop();
stopWatch.start("toDto");
CoalBlendDto blendDto = this.mapper.toDto(entity);
CoalBlendEntity entity = repository.get(id); stopWatch.stop();
log.info(stopWatch.prettyPrint());
return mapper.toDto(entity); return roundMapper.round(blendDto);
} }
@Autowired
ConversionService conversionService;
public Page<CoalBlendDto> list(CommonQuery query) {
Page<CoalBlendEntity> page = repository.findAll(query.specification(conversionService), PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders())));
return page.map(this.mapper::toDto);
}
@Autowired
RoundMapper roundMapper;
public CoalBlendDto blend(CreateCoalBlendDto dto) {
StopWatch stopWatch = new StopWatch();
stopWatch.start("toEntity");
CoalBlendEntity entity = this.mapper.toEntity(dto);
stopWatch.stop();
stopWatch.start("blend");
entity.blend();
stopWatch.stop();
stopWatch.start("toDto");
CoalBlendDto blendDto = this.mapper.toDto(entity);
stopWatch.stop();
log.info(stopWatch.prettyPrint());
return roundMapper.round(blendDto);
}
} }

View File

@@ -18,42 +18,35 @@ import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping("/coalInfo") @RequestMapping("/coalInfo")
@SysLog( @SysLog(module = "煤源信息")
module = "煤源信息"
)
@Slf4j @Slf4j
@OrgScope @OrgScope
public class CoalInfoController { public class CoalInfoController {
@Autowired @Autowired private CoalInfoService service;
private CoalInfoService service;
@PostMapping("/create") @PostMapping("/create")
public CoalInfoDto create(@RequestBody CreateCoalInfoDto request) { public CoalInfoDto create(@RequestBody CreateCoalInfoDto request) {
return this.service.create(request) return this.service.create(request);
;
} }
@PostMapping("/update") @PostMapping("/update")
public CoalInfoDto update(@RequestBody UpdateCoalInfoDto request) { public CoalInfoDto update(@RequestBody UpdateCoalInfoDto request) {
return this.service.update(request) return this.service.update(request);
;
} }
@PostMapping("/delete") @PostMapping("/delete")
public Object delete(@RequestBody IdRequest request) { public Object delete(@RequestBody IdRequest request) {
this.service.delete(request); this.service.delete(request);
return true return true;
;
} }
@PostMapping("/getById") @PostMapping("/getById")
public CoalInfoDto getById(@RequestBody String request) { public CoalInfoDto getById(@RequestBody String request) {
return this.service.getById(request) return this.service.getById(request);
;
} }
@PostMapping("/list") @PostMapping("/list")
public Page<CoalInfoDto> list(@RequestBody CommonQuery request) { public Page<CoalInfoDto> list(@RequestBody CommonQuery request) {
return this.service.list(request) return this.service.list(request);
;
} }
} }

View File

@@ -7,13 +7,14 @@ import org.hibernate.annotations.Comment;
@Data @Data
public class CoalInfoDto extends OrgCommonDto { public class CoalInfoDto extends OrgCommonDto {
@Comment("供应商") @Comment("供应商")
private String supplier; private String supplier;
private String supplierName; private String supplierName;
private String coalTypeName; private String coalTypeName;
private String coalType; private String coalType;
@Comment("初始报价")
private Double initPrice; @Comment("初始报价")
private Double initPrice;
} }

View File

@@ -7,11 +7,11 @@ import org.hibernate.annotations.Comment;
@Data @Data
public class CreateCoalInfoDto extends OrgCommonDto { public class CreateCoalInfoDto extends OrgCommonDto {
@Comment("供应商") @Comment("供应商")
private String supplier; private String supplier;
private String coalType; private String coalType;
@Comment("初始报价") @Comment("初始报价")
private Double initPrice; private Double initPrice;
} }

View File

@@ -6,11 +6,11 @@ import org.hibernate.annotations.Comment;
@Data @Data
public class UpdateCoalInfoDto extends OrgCommonDto { public class UpdateCoalInfoDto extends OrgCommonDto {
@Comment("供应商") @Comment("供应商")
private String supplier; private String supplier;
private String coalType;
private String coalType; @Comment("初始报价")
@Comment("初始报价") private Double initPrice;
private Double initPrice;
} }

View File

@@ -12,43 +12,32 @@ import org.hibernate.annotations.Formula;
@Entity @Entity
public class CoalInfoEntity extends OrgCommonEntity { public class CoalInfoEntity extends OrgCommonEntity {
@ManyToOne @ManyToOne
@Comment("供应商") @Comment("供应商")
private SupplierEntity supplier; private SupplierEntity supplier;
@Comment("煤源类型")
private String coalType;
@Comment("煤源类型") @Formula(
private String coalType; "(select i.name\n"
+ "from t_dictionary d,\n"
+ " t_dictionary_item i\n"
+ "where d.id = i.dictionary_id\n"
+ " and d.code = 'coal.type'\n"
+ " and i.code = coal_type)")
private String coalTypeName;
@Comment("初始报价")
private Double initPrice;
@Formula("(select i.name\n" + public String getSupplierName() {
"from t_dictionary d,\n" +
" t_dictionary_item i\n" +
"where d.id = i.dictionary_id\n" +
" and d.code = 'coal.type'\n" +
" and i.code = coal_type)")
private String coalTypeName;
if (supplier != null) {
return supplier.getName();
} else {
return "";
@Comment("初始报价")
private Double initPrice;
public String getSupplierName() {
if (supplier != null) {
return supplier.getName();
}else {
return "";
}
} }
}
} }

View File

@@ -7,16 +7,14 @@ import cn.lihongjie.coal.coalInfo.dto.CreateCoalInfoDto;
import cn.lihongjie.coal.coalInfo.dto.UpdateCoalInfoDto; import cn.lihongjie.coal.coalInfo.dto.UpdateCoalInfoDto;
import cn.lihongjie.coal.coalInfo.entity.CoalInfoEntity; import cn.lihongjie.coal.coalInfo.entity.CoalInfoEntity;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.control.DeepClone; import org.mapstruct.control.DeepClone;
@Mapper( @Mapper(
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING, componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
uses = {CommonMapper.class}, uses = {CommonMapper.class},
mappingControl = DeepClone.class mappingControl = DeepClone.class)
) public interface CoalInfoMapper
public interface CoalInfoMapper extends BaseMapper<CoalInfoEntity, CoalInfoDto, CreateCoalInfoDto, UpdateCoalInfoDto> { extends BaseMapper<CoalInfoEntity, CoalInfoDto, CreateCoalInfoDto, UpdateCoalInfoDto> {
@Override @Override
CoalInfoDto toDto(CoalInfoEntity user); CoalInfoDto toDto(CoalInfoEntity user);
} }

View File

@@ -5,5 +5,4 @@ import cn.lihongjie.coal.coalInfo.entity.CoalInfoEntity;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@Repository @Repository
public interface CoalInfoRepository extends BaseRepository<CoalInfoEntity> { public interface CoalInfoRepository extends BaseRepository<CoalInfoEntity> {}
}

View File

@@ -11,6 +11,7 @@ import cn.lihongjie.coal.coalInfo.mapper.CoalInfoMapper;
import cn.lihongjie.coal.coalInfo.repository.CoalInfoRepository; import cn.lihongjie.coal.coalInfo.repository.CoalInfoRepository;
import cn.lihongjie.coal.coalPrice.entity.CoalPriceEntity; import cn.lihongjie.coal.coalPrice.entity.CoalPriceEntity;
import cn.lihongjie.coal.coalPrice.service.CoalPriceService; import cn.lihongjie.coal.coalPrice.service.CoalPriceService;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
@@ -19,74 +20,63 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Objects;
@Service @Service
@Slf4j @Slf4j
public class CoalInfoService extends BaseService<CoalInfoEntity, CoalInfoRepository> { public class CoalInfoService extends BaseService<CoalInfoEntity, CoalInfoRepository> {
@Autowired @Autowired private CoalInfoRepository repository;
private CoalInfoRepository repository;
@Autowired @Autowired private CoalInfoMapper mapper;
private CoalInfoMapper mapper;
@Autowired @Autowired private ConversionService conversionService;
private ConversionService conversionService;
@Autowired @Autowired CoalPriceService coalPriceService;
CoalPriceService coalPriceService;
public CoalInfoDto create(CreateCoalInfoDto request) { public CoalInfoDto create(CreateCoalInfoDto request) {
CoalInfoEntity entity = mapper.toEntity(request); CoalInfoEntity entity = mapper.toEntity(request);
this.repository.save(entity);
this.repository.save(entity); updatePrice(entity);
return getById(entity.getId());
}
updatePrice(entity); private void updatePrice(CoalInfoEntity entity) {
return getById(entity.getId()) CoalPriceEntity coalPrice = new CoalPriceEntity();
; coalPrice.setCoalInfo(entity);
coalPrice.setPrice(entity.getInitPrice());
coalPriceService.save(coalPrice);
}
public CoalInfoDto update(UpdateCoalInfoDto request) {
CoalInfoEntity entity = this.repository.get(request.getId());
Double old = entity.getInitPrice();
this.mapper.updateEntity(entity, request);
this.repository.save(entity);
if (!Objects.equals(old, request.getInitPrice())) {
updatePrice(entity);
} }
return getById(entity.getId());
}
private void updatePrice(CoalInfoEntity entity) { public void delete(IdRequest request) {
CoalPriceEntity coalPrice = new CoalPriceEntity(); this.repository.deleteAllById(request.getIds());
coalPrice.setCoalInfo(entity); }
coalPrice.setPrice(entity.getInitPrice());
coalPriceService.save(coalPrice); public CoalInfoDto getById(String id) {
} CoalInfoEntity entity = repository.get(id);
public CoalInfoDto update(UpdateCoalInfoDto request) { return mapper.toDto(entity);
CoalInfoEntity entity = this.repository.get(request.getId()); }
Double old = entity.getInitPrice();
this.mapper.updateEntity(entity, request);
this.repository.save(entity); public Page<CoalInfoDto> list(CommonQuery query) {
if (!Objects.equals(old, request.getInitPrice())) { Page<CoalInfoEntity> page =
repository.findAll(
query.specification(conversionService),
PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders())));
updatePrice(entity); return page.map(this.mapper::toDto);
} }
return getById(entity.getId())
;
}
public void delete(IdRequest request) {
this.repository.deleteAllById(request.getIds())
;
}
public CoalInfoDto getById(String id) {
CoalInfoEntity entity = repository.get(id);
return mapper.toDto(entity)
;
}
public Page<CoalInfoDto> list(CommonQuery query) {
Page<CoalInfoEntity> page = repository.findAll(query.specification(conversionService), PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders())));
return page.map(this.mapper::toDto)
;
}
} }

View File

@@ -7,9 +7,9 @@ import cn.lihongjie.coal.base.controller.BaseController;
import cn.lihongjie.coal.base.dto.CommonQuery; import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest; import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.coalParameterDef.dto.CoalParameterDefDto; import cn.lihongjie.coal.coalParameterDef.dto.CoalParameterDefDto;
import cn.lihongjie.coal.coalParameterDef.service.CoalParameterDefService;
import cn.lihongjie.coal.coalParameterDef.dto.CreateCoalParameterDefDto; import cn.lihongjie.coal.coalParameterDef.dto.CreateCoalParameterDefDto;
import cn.lihongjie.coal.coalParameterDef.dto.UpdateCoalParameterDefDto; import cn.lihongjie.coal.coalParameterDef.dto.UpdateCoalParameterDefDto;
import cn.lihongjie.coal.coalParameterDef.service.CoalParameterDefService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@@ -24,38 +24,34 @@ import org.springframework.web.bind.annotation.RestController;
@OrgScope @OrgScope
public class CoalParameterDefController extends BaseController { public class CoalParameterDefController extends BaseController {
@Autowired @Autowired CoalParameterDefService service;
CoalParameterDefService service;
@PostMapping("/create") @PostMapping("/create")
@SysLog(action = "新增") @SysLog(action = "新增")
public CoalParameterDefDto create(@RequestBody CreateCoalParameterDefDto dto) { public CoalParameterDefDto create(@RequestBody CreateCoalParameterDefDto dto) {
return this.service.create(dto); return this.service.create(dto);
} }
@PostMapping("/update") @PostMapping("/update")
@SysLog(action = "编辑") @SysLog(action = "编辑")
public CoalParameterDefDto update(@RequestBody UpdateCoalParameterDefDto dto) { public CoalParameterDefDto update(@RequestBody UpdateCoalParameterDefDto dto) {
return this.service.update(dto); return this.service.update(dto);
} }
@PostMapping("/delete")
@SysLog(action = "删除")
public Object delete(@RequestBody IdRequest dto) {
this.service.delete(dto);
return true;
}
@PostMapping("/delete") @PostMapping("/list")
@SysLog(action = "删除") public Page<CoalParameterDefDto> list(@RequestBody CommonQuery dto) {
public Object delete(@RequestBody IdRequest dto) { return this.service.list(dto);
this.service.delete(dto); }
return true;
}
@PostMapping("/getById")
@PostMapping("/list") public CoalParameterDefDto getById(@RequestBody IdRequest dto) {
public Page<CoalParameterDefDto> list(@RequestBody CommonQuery dto) { return this.service.getById(dto.getId());
return this.service.list(dto); }
}
@PostMapping("/getById")
public CoalParameterDefDto getById(@RequestBody IdRequest dto) {
return this.service.getById(dto.getId());
}
} }

View File

@@ -7,13 +7,14 @@ import org.hibernate.annotations.Comment;
@Data @Data
public class CoalParameterDefDto extends OrgCommonDto { public class CoalParameterDefDto extends OrgCommonDto {
@Comment("上级名称")
private String parentName;
@Comment("上级名称") @Comment("类型 0 手动输入 1 自动计算")
private String parentName; private String inputType;
@Comment("类型 0 手动输入 1 自动计算" )
private String inputType;
private String inputTypeName;
@Comment("计算公式" ) private String inputTypeName;
private String formula;
@Comment("计算公式")
private String formula;
} }

View File

@@ -7,14 +7,12 @@ import org.hibernate.annotations.Comment;
@Data @Data
public class CreateCoalParameterDefDto extends OrgCommonDto { public class CreateCoalParameterDefDto extends OrgCommonDto {
@Comment("上级名称") @Comment("上级名称")
private String parentName; private String parentName;
@Comment("类型 0 手动输入 1 自动计算")
private String inputType;
@Comment("类型 0 手动输入 1 自动计算" ) @Comment("计算公式")
private String inputType; private String formula;
@Comment("计算公式" )
private String formula;
} }

View File

@@ -7,16 +7,12 @@ import org.hibernate.annotations.Comment;
@Data @Data
public class UpdateCoalParameterDefDto extends OrgCommonDto { public class UpdateCoalParameterDefDto extends OrgCommonDto {
@Comment("上级名称")
private String parentName;
@Comment("上级名称") @Comment("类型 0 手动输入 1 自动计算")
private String parentName; private String inputType;
@Comment("类型 0 手动输入 1 自动计算" )
private String inputType;
@Comment("计算公式" )
private String formula;
@Comment("计算公式")
private String formula;
} }

View File

@@ -10,36 +10,30 @@ import org.hibernate.annotations.Formula;
@Data @Data
public class CoalParameterDefEntity extends OrgCommonEntity { public class CoalParameterDefEntity extends OrgCommonEntity {
@Comment("上级名称")
private String parentName;
@Comment("上级名称") @Comment("类型 0 手动输入 1 自动计算")
private String parentName; private String inputType;
@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 = 'coalParameter.inputType'\n"
+ " and i.code = input_type)")
private String inputTypeName;
@Comment("类型 0 手动输入 1 自动计算" ) @Comment("计算公式")
private String inputType; private String formula;
@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 = 'coalParameter.inputType'\n" +
" and i.code = input_type)")
private String inputTypeName;
@Comment("计算公式" )
private String formula;
@Comment("解析后的公式" )
private String formula0;
@Comment("依赖的字段" )
private String dependents;
@Comment("计算优先级" )
private Integer priority;
@Comment("解析后的公式")
private String formula0;
@Comment("依赖的字段")
private String dependents;
@Comment("计算优先级")
private Integer priority;
} }

View File

@@ -1,6 +1,5 @@
package cn.lihongjie.coal.coalParameterDef.mapper; package cn.lihongjie.coal.coalParameterDef.mapper;
import cn.lihongjie.coal.base.mapper.BaseMapper; import cn.lihongjie.coal.base.mapper.BaseMapper;
import cn.lihongjie.coal.base.mapper.CommonMapper; import cn.lihongjie.coal.base.mapper.CommonMapper;
import cn.lihongjie.coal.coalParameterDef.dto.CoalParameterDefDto; import cn.lihongjie.coal.coalParameterDef.dto.CoalParameterDefDto;
@@ -9,15 +8,15 @@ import cn.lihongjie.coal.coalParameterDef.dto.UpdateCoalParameterDefDto;
import cn.lihongjie.coal.coalParameterDef.entity.CoalParameterDefEntity; import cn.lihongjie.coal.coalParameterDef.entity.CoalParameterDefEntity;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants; import org.mapstruct.MappingConstants;
import org.mapstruct.MappingTarget;
import org.mapstruct.control.DeepClone; import org.mapstruct.control.DeepClone;
@Mapper( @Mapper(
componentModel = MappingConstants.ComponentModel.SPRING, componentModel = MappingConstants.ComponentModel.SPRING,
uses = {CommonMapper.class}, uses = {CommonMapper.class},
mappingControl = DeepClone.class mappingControl = DeepClone.class)
public interface CoalParameterDefMapper
) extends BaseMapper<
public interface CoalParameterDefMapper extends BaseMapper<CoalParameterDefEntity, CoalParameterDefDto, CreateCoalParameterDefDto, UpdateCoalParameterDefDto>{ CoalParameterDefEntity,
CoalParameterDefDto,
} CreateCoalParameterDefDto,
UpdateCoalParameterDefDto> {}

View File

@@ -6,5 +6,5 @@ import org.springframework.stereotype.Repository;
@Repository @Repository
public interface CoalParameterDefRepository extends BaseRepository<CoalParameterDefEntity> { public interface CoalParameterDefRepository extends BaseRepository<CoalParameterDefEntity> {
long countByOrganizationId(String organizationId); long countByOrganizationId(String organizationId);
} }

View File

@@ -17,6 +17,9 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import jakarta.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
import java.io.InputStream;
import java.util.List;
import java.util.Optional;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -31,197 +34,153 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.InputStream;
import java.util.List;
import java.util.Optional;
@Service @Service
@Slf4j @Slf4j
public class CoalParameterDefService extends BaseService<CoalParameterDefEntity, CoalParameterDefRepository> { public class CoalParameterDefService
extends BaseService<CoalParameterDefEntity, CoalParameterDefRepository> {
@Autowired @Autowired CoalParameterDefRepository repository;
CoalParameterDefRepository repository;
@Autowired @Autowired CoalParameterDefMapper mapper;
CoalParameterDefMapper mapper;
@PostConstruct
public void init() {}
@PostConstruct public CoalParameterDefDto create(CreateCoalParameterDefDto request) {
public void init() {
CoalParameterDefEntity entity = mapper.toEntity(request);
if (StringUtils.equalsIgnoreCase(entity.getInputType(), "1")) {
GroovyScriptUtils.validate(entity.getFormula());
} }
this.repository.save(entity);
updateFormula(entity);
return getById(entity.getId());
}
public CoalParameterDefDto create(CreateCoalParameterDefDto request) { private void updateFormula(CoalParameterDefEntity entity) {
DefaultDirectedGraph<Object, DefaultEdge> graph = new DefaultDirectedGraph<>(DefaultEdge.class);
List<CoalParameterDefEntity> all =
this.repository.findByOrganizationId(entity.getOrganizationId());
CoalParameterDefEntity entity = mapper.toEntity(request); String formula = entity.getFormula();
entity.setFormula0(formula);
if (StringUtils.equalsIgnoreCase(entity.getInputType(), "1")) { entity.setDependents(StringUtils.join(GroovyScriptUtils.variables(formula), ","));
GroovyScriptUtils.validate(entity.getFormula());
for (CoalParameterDefEntity def : all) {
if (StringUtils.equalsIgnoreCase(def.getInputType(), "1")) {
Iterable<String> dependents =
Splitter.on(",").trimResults().omitEmptyStrings().split(def.getDependents());
for (String d : dependents) {
graph.addVertex(def.getCode());
graph.addVertex(d);
graph.addEdge(d, def.getCode());
} }
}
this.repository.save(entity);
updateFormula(entity);
return getById(entity.getId());
} }
private void updateFormula(CoalParameterDefEntity entity) { TopologicalOrderIterator<Object, DefaultEdge> iterator = new TopologicalOrderIterator<>(graph);
int order = 0;
while (iterator.hasNext()) {
Object next = (String) iterator.next();
DefaultDirectedGraph<Object, DefaultEdge> graph = new DefaultDirectedGraph<>(DefaultEdge.class); for (CoalParameterDefEntity coalParameterDefEntity : all) {
List<CoalParameterDefEntity> all = this.repository.findByOrganizationId(entity.getOrganizationId());
String formula = entity.getFormula();
entity.setFormula0(formula);
entity.setDependents(StringUtils.join(GroovyScriptUtils.variables(formula), ","));
for (CoalParameterDefEntity def : all) {
if (StringUtils.equalsIgnoreCase(def.getInputType(), "1")) {
Iterable<String> dependents = Splitter.on(",").trimResults().omitEmptyStrings().split(def.getDependents());
for (String d : dependents) {
graph.addVertex(def.getCode());
graph.addVertex(d);
graph.addEdge(d, def.getCode());
}
}
if (StringUtils.equalsIgnoreCase(coalParameterDefEntity.getCode(), next + "")) {
coalParameterDefEntity.setPriority(order++);
break;
} }
}
TopologicalOrderIterator<Object, DefaultEdge> iterator = new TopologicalOrderIterator<>(graph);
int order = 0;
while (iterator.hasNext()) {
Object next = (String) iterator.next();
for (CoalParameterDefEntity coalParameterDefEntity : all) {
if (StringUtils.equalsIgnoreCase(coalParameterDefEntity.getCode(), next + "")) {
coalParameterDefEntity.setPriority(order++);
break;
}
}
}
this.repository.saveAll(all);
} }
this.repository.saveAll(all);
}
public CoalParameterDefDto update(UpdateCoalParameterDefDto request) { public CoalParameterDefDto update(UpdateCoalParameterDefDto request) {
CoalParameterDefEntity entity = this.repository.get(request.getId()); CoalParameterDefEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request); this.mapper.updateEntity(entity, request);
if (StringUtils.equalsIgnoreCase(entity.getInputType(), "1")) { if (StringUtils.equalsIgnoreCase(entity.getInputType(), "1")) {
GroovyScriptUtils.validate(entity.getFormula()); GroovyScriptUtils.validate(entity.getFormula());
}
this.repository.save(entity);
updateFormula(entity);
return getById(entity.getId());
} }
this.repository.save(entity);
updateFormula(entity);
return getById(entity.getId());
}
public void delete(IdRequest request) { public void delete(IdRequest request) {
this.repository.deleteAllById(request.getIds()); this.repository.deleteAllById(request.getIds());
List<CoalParameterDefEntity> allDef = this.repository.findByOrganizationId(Ctx.currentUser().getOrganizationId()); List<CoalParameterDefEntity> allDef =
this.repository.findByOrganizationId(Ctx.currentUser().getOrganizationId());
Optional<CoalParameterDefEntity> type1 = allDef.stream().filter(x -> StringUtils.equalsIgnoreCase(x.getInputType(), "1")).findAny(); Optional<CoalParameterDefEntity> type1 =
allDef.stream().filter(x -> StringUtils.equalsIgnoreCase(x.getInputType(), "1")).findAny();
type1.ifPresent(this::updateFormula); type1.ifPresent(this::updateFormula);
}
}
public CoalParameterDefDto getById(String id) {
CoalParameterDefEntity entity = repository.get(id);
return mapper.toDto(entity);
}
@Autowired
ConversionService conversionService;
public Page<CoalParameterDefDto> list(CommonQuery query) {
Page<CoalParameterDefEntity> page = repository.findAll(query.specification(conversionService), PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders())));
return page.map(this.mapper::toDto);
}
@Autowired
OrganizationService organizationService;
public void initDefault() {
organizationService.findAll().forEach(organizationEntity -> initDefault(organizationEntity.getId()));
}
@SneakyThrows
public void initDefault(String orgId) {
if (repository.countByOrganizationId(orgId) == 0) {
ClassPathResource classPathResource = new ClassPathResource("/config/CoalParameterDef.json");
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
List<CoalParameterDefEntity> coalParameterDefs;
try (InputStream inputStream = classPathResource.getInputStream()) {
coalParameterDefs = mapper.readValue(inputStream, new TypeReference<List<CoalParameterDefEntity>>() {
});
coalParameterDefs.forEach(x -> x.setOrganizationId(orgId));
this.repository.saveAll(coalParameterDefs);
}
}
public CoalParameterDefDto getById(String id) {
CoalParameterDefEntity entity = repository.get(id);
return mapper.toDto(entity);
}
@Autowired ConversionService conversionService;
public Page<CoalParameterDefDto> list(CommonQuery query) {
Page<CoalParameterDefEntity> page =
repository.findAll(
query.specification(conversionService),
PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders())));
return page.map(this.mapper::toDto);
}
@Autowired OrganizationService organizationService;
public void initDefault() {
organizationService
.findAll()
.forEach(organizationEntity -> initDefault(organizationEntity.getId()));
}
@SneakyThrows
public void initDefault(String orgId) {
if (repository.countByOrganizationId(orgId) == 0) {
ClassPathResource classPathResource = new ClassPathResource("/config/CoalParameterDef.json");
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
List<CoalParameterDefEntity> coalParameterDefs;
try (InputStream inputStream = classPathResource.getInputStream()) {
coalParameterDefs =
mapper.readValue(inputStream, new TypeReference<List<CoalParameterDefEntity>>() {});
coalParameterDefs.forEach(x -> x.setOrganizationId(orgId));
this.repository.saveAll(coalParameterDefs);
}
} }
}
} }

View File

@@ -18,42 +18,35 @@ import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping("/coalPrice") @RequestMapping("/coalPrice")
@SysLog( @SysLog(module = "煤源价格记录")
module = "煤源价格记录"
)
@Slf4j @Slf4j
@OrgScope @OrgScope
public class CoalPriceController { public class CoalPriceController {
@Autowired @Autowired private CoalPriceService service;
private CoalPriceService service;
@PostMapping("/create") @PostMapping("/create")
public CoalPriceDto create(@RequestBody CreateCoalPriceDto request) { public CoalPriceDto create(@RequestBody CreateCoalPriceDto request) {
return this.service.create(request) return this.service.create(request);
;
} }
@PostMapping("/update") @PostMapping("/update")
public CoalPriceDto update(@RequestBody UpdateCoalPriceDto request) { public CoalPriceDto update(@RequestBody UpdateCoalPriceDto request) {
return this.service.update(request) return this.service.update(request);
;
} }
@PostMapping("/delete") @PostMapping("/delete")
public Object delete(@RequestBody IdRequest request) { public Object delete(@RequestBody IdRequest request) {
this.service.delete(request); this.service.delete(request);
return true return true;
;
} }
@PostMapping("/getById") @PostMapping("/getById")
public CoalPriceDto getById(@RequestBody String request) { public CoalPriceDto getById(@RequestBody String request) {
return this.service.getById(request) return this.service.getById(request);
;
} }
@PostMapping("/list") @PostMapping("/list")
public Page<CoalPriceDto> list(@RequestBody CommonQuery request) { public Page<CoalPriceDto> list(@RequestBody CommonQuery request) {
return this.service.list(request) return this.service.list(request);
;
} }
} }

View File

@@ -2,17 +2,14 @@ package cn.lihongjie.coal.coalPrice.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto; import cn.lihongjie.coal.base.dto.OrgCommonDto;
import cn.lihongjie.coal.coalInfo.entity.CoalInfoEntity; import cn.lihongjie.coal.coalInfo.entity.CoalInfoEntity;
import jakarta.persistence.ManyToOne;
import lombok.Data; import lombok.Data;
import org.hibernate.annotations.Comment; import org.hibernate.annotations.Comment;
@Data @Data
public class CoalPriceDto extends OrgCommonDto { public class CoalPriceDto extends OrgCommonDto {
@Comment("煤源") @Comment("煤源")
private CoalInfoEntity coalInfo; private CoalInfoEntity coalInfo;
@Comment("价格")
private Double price;
@Comment("价格")
private Double price;
} }

View File

@@ -6,11 +6,9 @@ import org.hibernate.annotations.Comment;
@Data @Data
public class CreateCoalPriceDto extends OrgCommonDto { public class CreateCoalPriceDto extends OrgCommonDto {
@Comment("煤源") @Comment("煤源")
private String coalInfo; private String coalInfo;
@Comment("价格")
private Double price;
@Comment("价格")
private Double price;
} }

View File

@@ -6,11 +6,9 @@ import org.hibernate.annotations.Comment;
@Data @Data
public class UpdateCoalPriceDto extends OrgCommonDto { public class UpdateCoalPriceDto extends OrgCommonDto {
@Comment("煤源") @Comment("煤源")
private String coalInfo; private String coalInfo;
@Comment("价格")
private Double price;
@Comment("价格")
private Double price;
} }

View File

@@ -11,12 +11,10 @@ import org.hibernate.annotations.Comment;
@Entity @Entity
public class CoalPriceEntity extends OrgCommonEntity { public class CoalPriceEntity extends OrgCommonEntity {
@Comment("煤源") @Comment("煤源")
@ManyToOne @ManyToOne
private CoalInfoEntity coalInfo; private CoalInfoEntity coalInfo;
@Comment("价格")
private Double price;
@Comment("价格")
private Double price;
} }

View File

@@ -12,7 +12,6 @@ import org.mapstruct.control.DeepClone;
@Mapper( @Mapper(
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING, componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
uses = {CommonMapper.class}, uses = {CommonMapper.class},
mappingControl = DeepClone.class mappingControl = DeepClone.class)
) public interface CoalPriceMapper
public interface CoalPriceMapper extends BaseMapper<CoalPriceEntity, CoalPriceDto, CreateCoalPriceDto, UpdateCoalPriceDto> { extends BaseMapper<CoalPriceEntity, CoalPriceDto, CreateCoalPriceDto, UpdateCoalPriceDto> {}
}

View File

@@ -5,5 +5,4 @@ import cn.lihongjie.coal.coalPrice.entity.CoalPriceEntity;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@Repository @Repository
public interface CoalPriceRepository extends BaseRepository<CoalPriceEntity> { public interface CoalPriceRepository extends BaseRepository<CoalPriceEntity> {}
}

View File

@@ -9,7 +9,6 @@ import cn.lihongjie.coal.coalPrice.dto.UpdateCoalPriceDto;
import cn.lihongjie.coal.coalPrice.entity.CoalPriceEntity; import cn.lihongjie.coal.coalPrice.entity.CoalPriceEntity;
import cn.lihongjie.coal.coalPrice.mapper.CoalPriceMapper; import cn.lihongjie.coal.coalPrice.mapper.CoalPriceMapper;
import cn.lihongjie.coal.coalPrice.repository.CoalPriceRepository; import cn.lihongjie.coal.coalPrice.repository.CoalPriceRepository;
import java.lang.String;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
@@ -21,52 +20,44 @@ import org.springframework.stereotype.Service;
@Service @Service
@Slf4j @Slf4j
public class CoalPriceService extends BaseService<CoalPriceEntity, CoalPriceRepository> { public class CoalPriceService extends BaseService<CoalPriceEntity, CoalPriceRepository> {
@Autowired @Autowired private CoalPriceRepository repository;
private CoalPriceRepository repository;
@Autowired @Autowired private CoalPriceMapper mapper;
private CoalPriceMapper mapper;
@Autowired @Autowired private ConversionService conversionService;
private ConversionService conversionService;
public CoalPriceDto create(CreateCoalPriceDto request) { public CoalPriceDto create(CreateCoalPriceDto request) {
CoalPriceEntity entity = mapper.toEntity(request); CoalPriceEntity entity = mapper.toEntity(request);
this.repository.save(entity);
this.repository.save(entity); return getById(entity.getId());
return getById(entity.getId())
;
} }
public CoalPriceDto update(UpdateCoalPriceDto request) { public CoalPriceDto update(UpdateCoalPriceDto request) {
CoalPriceEntity entity = this.repository.get(request.getId()); CoalPriceEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request); this.mapper.updateEntity(entity, request);
this.repository.save(entity); this.repository.save(entity);
return getById(entity.getId()) return getById(entity.getId());
;
} }
public void delete(IdRequest request) { public void delete(IdRequest request) {
this.repository.deleteAllById(request.getIds()) this.repository.deleteAllById(request.getIds());
;
} }
public CoalPriceDto getById(String id) { public CoalPriceDto getById(String id) {
CoalPriceEntity entity = repository.get(id); CoalPriceEntity entity = repository.get(id);
return mapper.toDto(entity);
return mapper.toDto(entity)
;
} }
public Page<CoalPriceDto> list(CommonQuery query) { public Page<CoalPriceDto> list(CommonQuery query) {
Page<CoalPriceEntity> page = repository.findAll(query.specification(conversionService), PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders()))); Page<CoalPriceEntity> page =
repository.findAll(
query.specification(conversionService),
PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders())));
return page.map(this.mapper::toDto);
return page.map(this.mapper::toDto)
;
} }
} }

View File

@@ -5,10 +5,10 @@ import cn.lihongjie.coal.annotation.SysLog;
import cn.lihongjie.coal.base.controller.BaseController; import cn.lihongjie.coal.base.controller.BaseController;
import cn.lihongjie.coal.base.dto.CommonQuery; import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest; import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.coalWashingDailyAnalysis.service.CoalWashingDailyAnalysisService;
import cn.lihongjie.coal.coalWashingDailyAnalysis.dto.CoalWashingDailyAnalysisDto; import cn.lihongjie.coal.coalWashingDailyAnalysis.dto.CoalWashingDailyAnalysisDto;
import cn.lihongjie.coal.coalWashingDailyAnalysis.dto.CreateCoalWashingDailyAnalysisDto; import cn.lihongjie.coal.coalWashingDailyAnalysis.dto.CreateCoalWashingDailyAnalysisDto;
import cn.lihongjie.coal.coalWashingDailyAnalysis.dto.UpdateCoalWashingDailyAnalysisDto; import cn.lihongjie.coal.coalWashingDailyAnalysis.dto.UpdateCoalWashingDailyAnalysisDto;
import cn.lihongjie.coal.coalWashingDailyAnalysis.service.CoalWashingDailyAnalysisService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@@ -22,42 +22,40 @@ import org.springframework.web.bind.annotation.RestController;
@Anonymous @Anonymous
public class CoalWashingDailyAnalysisController extends BaseController { public class CoalWashingDailyAnalysisController extends BaseController {
@Autowired @Autowired CoalWashingDailyAnalysisService service;
CoalWashingDailyAnalysisService service;
@PostMapping("/calculate")
@SysLog(action = "计算")
public CoalWashingDailyAnalysisDto calculate(@RequestBody CreateCoalWashingDailyAnalysisDto dto) {
return this.service.calculate(dto);
}
@PostMapping("/create")
@SysLog(action = "新增")
public CoalWashingDailyAnalysisDto create(@RequestBody CreateCoalWashingDailyAnalysisDto dto) {
return this.service.create(dto);
}
@PostMapping("/update") @PostMapping("/calculate")
@SysLog(action = "编辑") @SysLog(action = "计算")
public CoalWashingDailyAnalysisDto update(@RequestBody UpdateCoalWashingDailyAnalysisDto dto) { public CoalWashingDailyAnalysisDto calculate(@RequestBody CreateCoalWashingDailyAnalysisDto dto) {
return this.service.update(dto); return this.service.calculate(dto);
} }
@PostMapping("/create")
@SysLog(action = "新增")
public CoalWashingDailyAnalysisDto create(@RequestBody CreateCoalWashingDailyAnalysisDto dto) {
return this.service.create(dto);
}
@PostMapping("/delete") @PostMapping("/update")
@SysLog(action = "删除") @SysLog(action = "编辑")
public Object delete(@RequestBody IdRequest dto) { public CoalWashingDailyAnalysisDto update(@RequestBody UpdateCoalWashingDailyAnalysisDto dto) {
this.service.delete(dto); return this.service.update(dto);
return true; }
}
@PostMapping("/delete")
@SysLog(action = "删除")
public Object delete(@RequestBody IdRequest dto) {
this.service.delete(dto);
return true;
}
@PostMapping("/list") @PostMapping("/list")
public Page<CoalWashingDailyAnalysisDto> list(@RequestBody CommonQuery dto) { public Page<CoalWashingDailyAnalysisDto> list(@RequestBody CommonQuery dto) {
return this.service.list(dto); return this.service.list(dto);
} }
@PostMapping("/getById")
@PostMapping("/getById") public CoalWashingDailyAnalysisDto getById(@RequestBody IdRequest dto) {
public CoalWashingDailyAnalysisDto getById(@RequestBody IdRequest dto) { return this.service.getById(dto.getId());
return this.service.getById(dto.getId()); }
}
} }

View File

@@ -6,59 +6,44 @@ import jakarta.persistence.CollectionTable;
import jakarta.persistence.ConstraintMode; import jakarta.persistence.ConstraintMode;
import jakarta.persistence.ElementCollection; import jakarta.persistence.ElementCollection;
import jakarta.persistence.ForeignKey; import jakarta.persistence.ForeignKey;
import java.time.LocalDate;
import java.util.List;
import lombok.Data; import lombok.Data;
import org.hibernate.annotations.Comment; import org.hibernate.annotations.Comment;
import java.time.LocalDate; /** */
import java.util.List;
/**
*
*/
@Data @Data
@Comment("洗煤报告表") @Comment("洗煤报告表")
public class CoalWashingDailyAnalysisDto extends OrgCommonDto { public class CoalWashingDailyAnalysisDto extends OrgCommonDto {
@Comment("日期")
private LocalDate date;
@Comment("日期") @ElementCollection
private LocalDate date; @Comment("用户手动录入的记录")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisItemVo> inputItems;
@ElementCollection @ElementCollection
@Comment("用户手动录入的记录") @Comment("连续平均值")
@CollectionTable( foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) @CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisItemVo> inputItems; private List<CoalWashingDailyAnalysisItemVo> rollingAvgItems;
@Comment("目标大堆 灰")
private Double ddp1;
@ElementCollection @Comment("目标大堆 硫")
@Comment("连续平均值") private Double ddp2;
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisItemVo> rollingAvgItems;
@Comment("目标大堆 灰")
private Double ddp1;
@Comment("目标大堆 硫")
private Double ddp2;
@Comment("目标大堆 挥发")
private Double ddp3;
@Comment("目标大堆 粘结")
private Double ddp4;
@Comment("目标大堆 备用")
private Double ddp5;
@Comment("产量初始值")
private Double initTotalNumber = 0.0;
@Comment("目标大堆 挥发")
private Double ddp3;
@Comment("目标大堆 粘结")
private Double ddp4;
@Comment("目标大堆 备用")
private Double ddp5;
@Comment("产量初始值")
private Double initTotalNumber = 0.0;
} }

View File

@@ -6,59 +6,44 @@ import jakarta.persistence.CollectionTable;
import jakarta.persistence.ConstraintMode; import jakarta.persistence.ConstraintMode;
import jakarta.persistence.ElementCollection; import jakarta.persistence.ElementCollection;
import jakarta.persistence.ForeignKey; import jakarta.persistence.ForeignKey;
import java.time.LocalDate;
import java.util.List;
import lombok.Data; import lombok.Data;
import org.hibernate.annotations.Comment; import org.hibernate.annotations.Comment;
import java.time.LocalDate; /** */
import java.util.List;
/**
*
*/
@Data @Data
@Comment("洗煤报告表") @Comment("洗煤报告表")
public class CreateCoalWashingDailyAnalysisDto extends OrgCommonDto { public class CreateCoalWashingDailyAnalysisDto extends OrgCommonDto {
@Comment("日期")
private LocalDate date;
@Comment("日期") @ElementCollection
private LocalDate date; @Comment("用户手动录入的记录")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisItemVo> inputItems;
@ElementCollection @ElementCollection
@Comment("用户手动录入的记录") @Comment("连续平均值")
@CollectionTable( foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) @CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisItemVo> inputItems; private List<CoalWashingDailyAnalysisItemVo> rollingAvgItems;
@Comment("目标大堆 灰")
private Double ddp1;
@ElementCollection @Comment("目标大堆 硫")
@Comment("连续平均值") private Double ddp2;
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisItemVo> rollingAvgItems;
@Comment("目标大堆 灰")
private Double ddp1;
@Comment("目标大堆 硫")
private Double ddp2;
@Comment("目标大堆 挥发")
private Double ddp3;
@Comment("目标大堆 粘结")
private Double ddp4;
@Comment("目标大堆 备用")
private Double ddp5;
@Comment("产量初始值")
private Double initTotalNumber = 0.0;
@Comment("目标大堆 挥发")
private Double ddp3;
@Comment("目标大堆 粘结")
private Double ddp4;
@Comment("目标大堆 备用")
private Double ddp5;
@Comment("产量初始值")
private Double initTotalNumber = 0.0;
} }

View File

@@ -6,59 +6,44 @@ import jakarta.persistence.CollectionTable;
import jakarta.persistence.ConstraintMode; import jakarta.persistence.ConstraintMode;
import jakarta.persistence.ElementCollection; import jakarta.persistence.ElementCollection;
import jakarta.persistence.ForeignKey; import jakarta.persistence.ForeignKey;
import java.time.LocalDate;
import java.util.List;
import lombok.Data; import lombok.Data;
import org.hibernate.annotations.Comment; import org.hibernate.annotations.Comment;
import java.time.LocalDate; /** */
import java.util.List;
/**
*
*/
@Data @Data
@Comment("洗煤报告表") @Comment("洗煤报告表")
public class UpdateCoalWashingDailyAnalysisDto extends OrgCommonDto { public class UpdateCoalWashingDailyAnalysisDto extends OrgCommonDto {
@Comment("日期")
private LocalDate date;
@Comment("日期") @ElementCollection
private LocalDate date; @Comment("用户手动录入的记录")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisItemVo> inputItems;
@ElementCollection @ElementCollection
@Comment("用户手动录入的记录") @Comment("连续平均值")
@CollectionTable( foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) @CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisItemVo> inputItems; private List<CoalWashingDailyAnalysisItemVo> rollingAvgItems;
@Comment("目标大堆 灰")
private Double ddp1;
@ElementCollection @Comment("目标大堆 硫")
@Comment("连续平均值") private Double ddp2;
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisItemVo> rollingAvgItems;
@Comment("目标大堆 灰")
private Double ddp1;
@Comment("目标大堆 硫")
private Double ddp2;
@Comment("目标大堆 挥发")
private Double ddp3;
@Comment("目标大堆 粘结")
private Double ddp4;
@Comment("目标大堆 备用")
private Double ddp5;
@Comment("产量初始值")
private Double initTotalNumber = 0.0;
@Comment("目标大堆 挥发")
private Double ddp3;
@Comment("目标大堆 粘结")
private Double ddp4;
@Comment("目标大堆 备用")
private Double ddp5;
@Comment("产量初始值")
private Double initTotalNumber = 0.0;
} }

View File

@@ -2,279 +2,277 @@ package cn.lihongjie.coal.coalWashingDailyAnalysis.entity;
import cn.lihongjie.coal.base.entity.OrgCommonEntity; import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import jakarta.persistence.*; import jakarta.persistence.*;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.hibernate.annotations.Comment;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.hibernate.annotations.Comment;
/** /** */
*
*/
@Entity @Entity
@Data @Data
@Comment("洗煤报告表") @Comment("洗煤报告表")
public class CoalWashingDailyAnalysisEntity extends OrgCommonEntity { public class CoalWashingDailyAnalysisEntity extends OrgCommonEntity {
@Comment("日期")
private LocalDate date;
@Comment("日期") @ElementCollection
private LocalDate date; @Comment("用户手动录入的记录")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisItemVo> inputItems;
@ElementCollection @ElementCollection
@Comment("用户手动录入的记录") @Comment("连续平均值")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) @CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisItemVo> inputItems; private List<CoalWashingDailyAnalysisItemVo> rollingAvgItems;
@Comment("目标大堆 灰")
private Double ddp1;
@ElementCollection @Comment("目标大堆 硫")
@Comment("连续平均值") private Double ddp2;
@CollectionTable( foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisItemVo> rollingAvgItems;
@Comment("目标大堆 挥发")
private Double ddp3;
@Comment("目标大堆 ") @Comment("目标大堆 粘结")
private Double ddp1; private Double ddp4;
@Comment("目标大堆 备用")
private Double ddp5;
@Comment("目标大堆 硫") @Comment("产量初始值")
private Double ddp2; private Double initTotalNumber = 0.0;
public void rollingAvg() {
@Comment("目标大堆 挥发") rollingAvgItems = new ArrayList<>();
private Double ddp3;
if (CollectionUtils.isEmpty(inputItems)) {
return;
}
inputItems.sort(
Comparator.comparing(x -> ObjectUtils.defaultIfNull(x.getTime(), LocalTime.MIN)));
inputItems.forEach(x -> x.calculate());
@Comment("目标大堆 粘结") for (int i = 0; i < inputItems.size(); i++) {
private Double ddp4;
List<CoalWashingDailyAnalysisItemVo> current = inputItems.subList(0, i + 1);
rollingAvgItems.add(rollingAvg(current));
}
}
@Comment("目标大堆 备用") private CoalWashingDailyAnalysisItemVo rollingAvg(List<CoalWashingDailyAnalysisItemVo> current) {
private Double ddp5;
@Comment("产量初始值") CoalWashingDailyAnalysisItemVo vo = new CoalWashingDailyAnalysisItemVo();
private Double initTotalNumber = 0.0; int size = current.size();
vo.setTime(current.get(size - 1).getTime());
vo.setTotalNumber(current.get(size - 1).getTotalNumber());
vo.setC0p0(current.get(size - 1).getC0p0());
public void rollingAvg() { vo.setC1p0(current.get(size - 1).getC1p0());
rollingAvgItems = new ArrayList<>(); vo.setC2p0(current.get(size - 1).getC2p0());
if (CollectionUtils.isEmpty(inputItems)) { vo.setC3p0(current.get(size - 1).getC3p0());
return;
vo.setC4p0(current.get(size - 1).getC4p0());
vo.setC5p0(current.get(size - 1).getC5p0());
vo.setC6p0(current.get(size - 1).getC6p0());
vo.setC7p0(current.get(size - 1).getC7p0());
vo.setC8p0(current.get(size - 1).getC8p0());
vo.setC9p0(current.get(size - 1).getC9p0());
for (int i = 0; i < size; i++) {
var c = current.get(i);
var p = i == 0 ? c.withTotalNumber(initTotalNumber) : current.get(i - 1);
double diff = c.getTotalNumber() - p.getTotalNumber();
if (vo.getC0p0() != null && vo.getC0p0() > 0) {
vo.setC0p1(ObjectUtils.defaultIfNull(vo.getC0p1(), 0.0) + diff * c.getC0p1());
vo.setC0p2(ObjectUtils.defaultIfNull(vo.getC0p2(), 0.0) + diff * c.getC0p1());
if (i == size - 1) {
vo.setC0p1(vo.getC0p1() / c.getTotalNumber());
vo.setC0p2(vo.getC0p2() / c.getTotalNumber());
} }
inputItems.sort(Comparator.comparing(x -> ObjectUtils.defaultIfNull(x.getTime(), LocalTime.MIN))); }
inputItems.forEach(x -> x.calculate()); if (vo.getC1p0() != null && vo.getC1p0() > 0) {
vo.setC1p1(ObjectUtils.defaultIfNull(vo.getC1p1(), 0.0) + diff * c.getC1p1());
for (int i = 0; i < inputItems.size(); i++) { vo.setC1p2(ObjectUtils.defaultIfNull(vo.getC1p2(), 0.0) + diff * c.getC1p1());
if (i == size - 1) {
List<CoalWashingDailyAnalysisItemVo> current = inputItems.subList(0, i + 1); vo.setC1p1(vo.getC1p1() / c.getTotalNumber());
rollingAvgItems.add(rollingAvg(current)); vo.setC1p2(vo.getC1p2() / c.getTotalNumber());
} }
}
if (vo.getC2p0() != null && vo.getC2p0() > 0) {
vo.setC2p1(ObjectUtils.defaultIfNull(vo.getC2p1(), 0.0) + diff * c.getC2p1());
vo.setC2p2(ObjectUtils.defaultIfNull(vo.getC2p2(), 0.0) + diff * c.getC2p1());
if (i == size - 1) {
vo.setC2p1(vo.getC2p1() / c.getTotalNumber());
vo.setC2p2(vo.getC2p2() / c.getTotalNumber());
}
}
if (vo.getC3p0() != null && vo.getC3p0() > 0) {
vo.setC3p1(ObjectUtils.defaultIfNull(vo.getC3p1(), 0.0) + diff * c.getC3p1());
vo.setC3p2(ObjectUtils.defaultIfNull(vo.getC3p2(), 0.0) + diff * c.getC3p1());
if (i == size - 1) {
vo.setC3p1(vo.getC3p1() / c.getTotalNumber());
vo.setC3p2(vo.getC3p2() / c.getTotalNumber());
}
}
if (vo.getC4p0() != null && vo.getC4p0() > 0) {
vo.setC4p1(ObjectUtils.defaultIfNull(vo.getC4p1(), 0.0) + diff * c.getC4p1());
vo.setC4p2(ObjectUtils.defaultIfNull(vo.getC4p2(), 0.0) + diff * c.getC4p1());
if (i == size - 1) {
vo.setC4p1(vo.getC4p1() / c.getTotalNumber());
vo.setC4p2(vo.getC4p2() / c.getTotalNumber());
}
}
if (vo.getC5p0() != null && vo.getC5p0() > 0) {
vo.setC5p1(ObjectUtils.defaultIfNull(vo.getC5p1(), 0.0) + diff * c.getC5p1());
vo.setC5p2(ObjectUtils.defaultIfNull(vo.getC5p2(), 0.0) + diff * c.getC5p1());
if (i == size - 1) {
vo.setC5p1(vo.getC5p1() / c.getTotalNumber());
vo.setC5p2(vo.getC5p2() / c.getTotalNumber());
}
}
if (vo.getC6p0() != null && vo.getC6p0() > 0) {
vo.setC6p1(ObjectUtils.defaultIfNull(vo.getC6p1(), 0.0) + diff * c.getC6p1());
vo.setC6p2(ObjectUtils.defaultIfNull(vo.getC6p2(), 0.0) + diff * c.getC6p1());
if (i == size - 1) {
vo.setC6p1(vo.getC6p1() / c.getTotalNumber());
vo.setC6p2(vo.getC6p2() / c.getTotalNumber());
}
}
if (vo.getC7p0() != null && vo.getC7p0() > 0) {
vo.setC7p1(ObjectUtils.defaultIfNull(vo.getC7p1(), 0.0) + diff * c.getC7p1());
vo.setC7p2(ObjectUtils.defaultIfNull(vo.getC7p2(), 0.0) + diff * c.getC7p1());
if (i == size - 1) {
vo.setC7p1(vo.getC7p1() / c.getTotalNumber());
vo.setC7p2(vo.getC7p2() / c.getTotalNumber());
}
}
if (vo.getC8p0() != null && vo.getC8p0() > 0) {
vo.setC8p1(ObjectUtils.defaultIfNull(vo.getC8p1(), 0.0) + diff * c.getC8p1());
vo.setC8p2(ObjectUtils.defaultIfNull(vo.getC8p2(), 0.0) + diff * c.getC8p1());
if (i == size - 1) {
vo.setC8p1(vo.getC8p1() / c.getTotalNumber());
vo.setC8p2(vo.getC8p2() / c.getTotalNumber());
}
}
if (vo.getC9p0() != null && vo.getC9p0() > 0) {
vo.setC9p1(ObjectUtils.defaultIfNull(vo.getC9p1(), 0.0) + diff * c.getC9p1());
vo.setC9p2(ObjectUtils.defaultIfNull(vo.getC9p2(), 0.0) + diff * c.getC9p1());
if (i == size - 1) {
vo.setC9p1(vo.getC9p1() / c.getTotalNumber());
vo.setC9p2(vo.getC9p2() / c.getTotalNumber());
}
}
vo.setDdp1(
ObjectUtils.defaultIfNull(vo.getDdp1(), 0.0)
+ diff * ObjectUtils.defaultIfNull(c.getDdp1(), 0.0));
if (i == size - 1) {
vo.setDdp1(vo.getDdp1() / c.getTotalNumber());
}
vo.setDdp2(
ObjectUtils.defaultIfNull(vo.getDdp2(), 0.0)
+ diff * ObjectUtils.defaultIfNull(c.getDdp2(), 0.0));
if (i == size - 1) {
vo.setDdp2(vo.getDdp2() / c.getTotalNumber());
}
vo.setDdp3(
ObjectUtils.defaultIfNull(vo.getDdp3(), 0.0)
+ diff * ObjectUtils.defaultIfNull(c.getDdp3(), 0.0));
if (i == size - 1) {
vo.setDdp3(vo.getDdp3() / c.getTotalNumber());
}
vo.setDdp4(
ObjectUtils.defaultIfNull(vo.getDdp4(), 0.0)
+ diff * ObjectUtils.defaultIfNull(c.getDdp4(), 0.0));
if (i == size - 1) {
vo.setDdp4(vo.getDdp4() / c.getTotalNumber());
}
vo.setDdp5(
ObjectUtils.defaultIfNull(vo.getDdp5(), 0.0)
+ diff * ObjectUtils.defaultIfNull(c.getDdp5(), 0.0));
if (i == size - 1) {
vo.setDdp5(vo.getDdp5() / c.getTotalNumber());
}
vo.setSysDdp1(
ObjectUtils.defaultIfNull(vo.getSysDdp1(), 0.0)
+ diff * ObjectUtils.defaultIfNull(c.getSysDdp1(), 0.0));
if (i == size - 1) {
vo.setSysDdp1(vo.getSysDdp1() / c.getTotalNumber());
}
vo.setSysDdp2(
ObjectUtils.defaultIfNull(vo.getSysDdp2(), 0.0)
+ diff * ObjectUtils.defaultIfNull(c.getSysDdp2(), 0.0));
if (i == size - 1) {
vo.setSysDdp2(vo.getSysDdp2() / c.getTotalNumber());
}
vo.setSysDdp3(
ObjectUtils.defaultIfNull(vo.getSysDdp3(), 0.0)
+ diff * ObjectUtils.defaultIfNull(c.getSysDdp3(), 0.0));
if (i == size - 1) {
vo.setSysDdp3(vo.getSysDdp3() / c.getTotalNumber());
}
vo.setSysDdp4(
ObjectUtils.defaultIfNull(vo.getSysDdp4(), 0.0)
+ diff * ObjectUtils.defaultIfNull(c.getSysDdp4(), 0.0));
if (i == size - 1) {
vo.setSysDdp4(vo.getSysDdp4() / c.getTotalNumber());
}
vo.setSysDdp5(
ObjectUtils.defaultIfNull(vo.getSysDdp5(), 0.0)
+ diff * ObjectUtils.defaultIfNull(c.getSysDdp5(), 0.0));
if (i == size - 1) {
vo.setSysDdp5(vo.getSysDdp5() / c.getTotalNumber());
}
vo.setAvgDdp1(
ObjectUtils.defaultIfNull(vo.getAvgDdp1(), 0.0)
+ diff * ObjectUtils.defaultIfNull(c.getAvgDdp1(), 0.0));
if (i == size - 1) {
vo.setAvgDdp1(vo.getAvgDdp1() / c.getTotalNumber());
}
vo.setAvgDdp2(
ObjectUtils.defaultIfNull(vo.getAvgDdp2(), 0.0)
+ diff * ObjectUtils.defaultIfNull(c.getAvgDdp2(), 0.0));
if (i == size - 1) {
vo.setAvgDdp2(vo.getAvgDdp2() / c.getTotalNumber());
}
vo.setAvgDdp3(
ObjectUtils.defaultIfNull(vo.getAvgDdp3(), 0.0)
+ diff * ObjectUtils.defaultIfNull(c.getAvgDdp3(), 0.0));
if (i == size - 1) {
vo.setAvgDdp3(vo.getAvgDdp3() / c.getTotalNumber());
}
vo.setAvgDdp4(
ObjectUtils.defaultIfNull(vo.getAvgDdp4(), 0.0)
+ diff * ObjectUtils.defaultIfNull(c.getAvgDdp4(), 0.0));
if (i == size - 1) {
vo.setAvgDdp4(vo.getAvgDdp4() / c.getTotalNumber());
}
vo.setAvgDdp5(
ObjectUtils.defaultIfNull(vo.getAvgDdp5(), 0.0)
+ diff * ObjectUtils.defaultIfNull(c.getAvgDdp5(), 0.0));
if (i == size - 1) {
vo.setAvgDdp5(vo.getAvgDdp5() / c.getTotalNumber());
}
} }
private CoalWashingDailyAnalysisItemVo rollingAvg(List<CoalWashingDailyAnalysisItemVo> current) { return vo;
}
CoalWashingDailyAnalysisItemVo vo = new CoalWashingDailyAnalysisItemVo();
int size = current.size();
vo.setTime(current.get(size - 1).getTime());
vo.setTotalNumber(current.get(size - 1).getTotalNumber());
vo.setC0p0(current.get(size - 1).getC0p0());
vo.setC1p0(current.get(size - 1).getC1p0());
vo.setC2p0(current.get(size - 1).getC2p0());
vo.setC3p0(current.get(size - 1).getC3p0());
vo.setC4p0(current.get(size - 1).getC4p0());
vo.setC5p0(current.get(size - 1).getC5p0());
vo.setC6p0(current.get(size - 1).getC6p0());
vo.setC7p0(current.get(size - 1).getC7p0());
vo.setC8p0(current.get(size - 1).getC8p0());
vo.setC9p0(current.get(size - 1).getC9p0());
for (int i = 0; i < size; i++) {
var c = current.get(i);
var p = i == 0 ? c.withTotalNumber(initTotalNumber) : current.get(i - 1);
double diff = c.getTotalNumber() - p.getTotalNumber();
if (vo.getC0p0() != null && vo.getC0p0() > 0) {
vo.setC0p1(ObjectUtils.defaultIfNull(vo.getC0p1(), 0.0) + diff * c.getC0p1());
vo.setC0p2(ObjectUtils.defaultIfNull(vo.getC0p2(), 0.0) + diff * c.getC0p1());
if (i == size - 1) {
vo.setC0p1(vo.getC0p1() / c.getTotalNumber());
vo.setC0p2(vo.getC0p2() / c.getTotalNumber());
}
}
if (vo.getC1p0() != null && vo.getC1p0() > 0) {
vo.setC1p1(ObjectUtils.defaultIfNull(vo.getC1p1(), 0.0) + diff * c.getC1p1());
vo.setC1p2(ObjectUtils.defaultIfNull(vo.getC1p2(), 0.0) + diff * c.getC1p1());
if (i == size - 1) {
vo.setC1p1(vo.getC1p1() / c.getTotalNumber());
vo.setC1p2(vo.getC1p2() / c.getTotalNumber());
}
}
if (vo.getC2p0() != null && vo.getC2p0() > 0) {
vo.setC2p1(ObjectUtils.defaultIfNull(vo.getC2p1(), 0.0) + diff * c.getC2p1());
vo.setC2p2(ObjectUtils.defaultIfNull(vo.getC2p2(), 0.0) + diff * c.getC2p1());
if (i == size - 1) {
vo.setC2p1(vo.getC2p1() / c.getTotalNumber());
vo.setC2p2(vo.getC2p2() / c.getTotalNumber());
}
}
if (vo.getC3p0() != null && vo.getC3p0() > 0) {
vo.setC3p1(ObjectUtils.defaultIfNull(vo.getC3p1(), 0.0) + diff * c.getC3p1());
vo.setC3p2(ObjectUtils.defaultIfNull(vo.getC3p2(), 0.0) + diff * c.getC3p1());
if (i == size - 1) {
vo.setC3p1(vo.getC3p1() / c.getTotalNumber());
vo.setC3p2(vo.getC3p2() / c.getTotalNumber());
}
}
if (vo.getC4p0() != null && vo.getC4p0() > 0) {
vo.setC4p1(ObjectUtils.defaultIfNull(vo.getC4p1(), 0.0) + diff * c.getC4p1());
vo.setC4p2(ObjectUtils.defaultIfNull(vo.getC4p2(), 0.0) + diff * c.getC4p1());
if (i == size - 1) {
vo.setC4p1(vo.getC4p1() / c.getTotalNumber());
vo.setC4p2(vo.getC4p2() / c.getTotalNumber());
}
}
if (vo.getC5p0() != null && vo.getC5p0() > 0) {
vo.setC5p1(ObjectUtils.defaultIfNull(vo.getC5p1(), 0.0) + diff * c.getC5p1());
vo.setC5p2(ObjectUtils.defaultIfNull(vo.getC5p2(), 0.0) + diff * c.getC5p1());
if (i == size - 1) {
vo.setC5p1(vo.getC5p1() / c.getTotalNumber());
vo.setC5p2(vo.getC5p2() / c.getTotalNumber());
}
}
if (vo.getC6p0() != null && vo.getC6p0() > 0) {
vo.setC6p1(ObjectUtils.defaultIfNull(vo.getC6p1(), 0.0) + diff * c.getC6p1());
vo.setC6p2(ObjectUtils.defaultIfNull(vo.getC6p2(), 0.0) + diff * c.getC6p1());
if (i == size - 1) {
vo.setC6p1(vo.getC6p1() / c.getTotalNumber());
vo.setC6p2(vo.getC6p2() / c.getTotalNumber());
}
}
if (vo.getC7p0() != null && vo.getC7p0() > 0) {
vo.setC7p1(ObjectUtils.defaultIfNull(vo.getC7p1(), 0.0) + diff * c.getC7p1());
vo.setC7p2(ObjectUtils.defaultIfNull(vo.getC7p2(), 0.0) + diff * c.getC7p1());
if (i == size - 1) {
vo.setC7p1(vo.getC7p1() / c.getTotalNumber());
vo.setC7p2(vo.getC7p2() / c.getTotalNumber());
}
}
if (vo.getC8p0() != null && vo.getC8p0() > 0) {
vo.setC8p1(ObjectUtils.defaultIfNull(vo.getC8p1(), 0.0) + diff * c.getC8p1());
vo.setC8p2(ObjectUtils.defaultIfNull(vo.getC8p2(), 0.0) + diff * c.getC8p1());
if (i == size - 1) {
vo.setC8p1(vo.getC8p1() / c.getTotalNumber());
vo.setC8p2(vo.getC8p2() / c.getTotalNumber());
}
}
if (vo.getC9p0() != null && vo.getC9p0() > 0) {
vo.setC9p1(ObjectUtils.defaultIfNull(vo.getC9p1(), 0.0) + diff * c.getC9p1());
vo.setC9p2(ObjectUtils.defaultIfNull(vo.getC9p2(), 0.0) + diff * c.getC9p1());
if (i == size - 1) {
vo.setC9p1(vo.getC9p1() / c.getTotalNumber());
vo.setC9p2(vo.getC9p2() / c.getTotalNumber());
}
}
vo.setDdp1(ObjectUtils.defaultIfNull(vo.getDdp1(), 0.0) + diff * ObjectUtils.defaultIfNull(c.getDdp1(), 0.0));
if (i == size - 1) {
vo.setDdp1(vo.getDdp1() / c.getTotalNumber());
}
vo.setDdp2(ObjectUtils.defaultIfNull(vo.getDdp2(), 0.0) + diff * ObjectUtils.defaultIfNull(c.getDdp2(), 0.0));
if (i == size - 1) {
vo.setDdp2(vo.getDdp2() / c.getTotalNumber());
}
vo.setDdp3(ObjectUtils.defaultIfNull(vo.getDdp3(), 0.0) + diff * ObjectUtils.defaultIfNull(c.getDdp3(), 0.0));
if (i == size - 1) {
vo.setDdp3(vo.getDdp3() / c.getTotalNumber());
}
vo.setDdp4(ObjectUtils.defaultIfNull(vo.getDdp4(), 0.0) + diff * ObjectUtils.defaultIfNull(c.getDdp4(), 0.0));
if (i == size - 1) {
vo.setDdp4(vo.getDdp4() / c.getTotalNumber());
}
vo.setDdp5(ObjectUtils.defaultIfNull(vo.getDdp5(), 0.0) + diff * ObjectUtils.defaultIfNull(c.getDdp5(), 0.0));
if (i == size - 1) {
vo.setDdp5(vo.getDdp5() / c.getTotalNumber());
}
vo.setSysDdp1(ObjectUtils.defaultIfNull(vo.getSysDdp1(), 0.0) + diff * ObjectUtils.defaultIfNull(c.getSysDdp1(), 0.0));
if (i == size - 1) {
vo.setSysDdp1(vo.getSysDdp1() / c.getTotalNumber());
}
vo.setSysDdp2(ObjectUtils.defaultIfNull(vo.getSysDdp2(), 0.0) + diff * ObjectUtils.defaultIfNull(c.getSysDdp2(), 0.0));
if (i == size - 1) {
vo.setSysDdp2(vo.getSysDdp2() / c.getTotalNumber());
}
vo.setSysDdp3(ObjectUtils.defaultIfNull(vo.getSysDdp3(), 0.0) + diff * ObjectUtils.defaultIfNull(c.getSysDdp3(), 0.0));
if (i == size - 1) {
vo.setSysDdp3(vo.getSysDdp3() / c.getTotalNumber());
}
vo.setSysDdp4(ObjectUtils.defaultIfNull(vo.getSysDdp4(), 0.0) + diff * ObjectUtils.defaultIfNull(c.getSysDdp4(), 0.0));
if (i == size - 1) {
vo.setSysDdp4(vo.getSysDdp4() / c.getTotalNumber());
}
vo.setSysDdp5(ObjectUtils.defaultIfNull(vo.getSysDdp5(), 0.0) + diff * ObjectUtils.defaultIfNull(c.getSysDdp5(), 0.0));
if (i == size - 1) {
vo.setSysDdp5(vo.getSysDdp5() / c.getTotalNumber());
}
vo.setAvgDdp1(ObjectUtils.defaultIfNull(vo.getAvgDdp1(), 0.0) + diff * ObjectUtils.defaultIfNull(c.getAvgDdp1(), 0.0));
if (i == size - 1) {
vo.setAvgDdp1(vo.getAvgDdp1() / c.getTotalNumber());
}
vo.setAvgDdp2(ObjectUtils.defaultIfNull(vo.getAvgDdp2(), 0.0) + diff * ObjectUtils.defaultIfNull(c.getAvgDdp2(), 0.0));
if (i == size - 1) {
vo.setAvgDdp2(vo.getAvgDdp2() / c.getTotalNumber());
}
vo.setAvgDdp3(ObjectUtils.defaultIfNull(vo.getAvgDdp3(), 0.0) + diff * ObjectUtils.defaultIfNull(c.getAvgDdp3(), 0.0));
if (i == size - 1) {
vo.setAvgDdp3(vo.getAvgDdp3() / c.getTotalNumber());
}
vo.setAvgDdp4(ObjectUtils.defaultIfNull(vo.getAvgDdp4(), 0.0) + diff * ObjectUtils.defaultIfNull(c.getAvgDdp4(), 0.0));
if (i == size - 1) {
vo.setAvgDdp4(vo.getAvgDdp4() / c.getTotalNumber());
}
vo.setAvgDdp5(ObjectUtils.defaultIfNull(vo.getAvgDdp5(), 0.0) + diff * ObjectUtils.defaultIfNull(c.getAvgDdp5(), 0.0));
if (i == size - 1) {
vo.setAvgDdp5(vo.getAvgDdp5() / c.getTotalNumber());
}
}
return vo;
}
} }

View File

@@ -3,273 +3,277 @@ package cn.lihongjie.coal.coalWashingDailyAnalysis.entity;
import cn.lihongjie.coal.exception.BizException; import cn.lihongjie.coal.exception.BizException;
import io.vavr.collection.Stream; import io.vavr.collection.Stream;
import jakarta.persistence.Embeddable; import jakarta.persistence.Embeddable;
import java.time.LocalTime;
import java.util.Objects;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.With; import lombok.With;
import org.hibernate.annotations.Comment; import org.hibernate.annotations.Comment;
import java.time.LocalTime;
import java.util.Objects;
@Data @Data
@Embeddable @Embeddable
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class CoalWashingDailyAnalysisItemVo { public class CoalWashingDailyAnalysisItemVo {
@Comment("时间")
private LocalTime time;
@Comment("时间") @Comment("产量")
private LocalTime time; @With
private Double totalNumber;
@Comment("产量") @Comment("成分0 比例")
@With private Double c0p0;
private Double totalNumber;
@Comment("成分0 灰")
private Double c0p1;
@Comment("成分0 比例") @Comment("成分0 ")
private Double c0p0; private Double c0p2;
@Comment("成分1 比例")
private Double c1p0;
@Comment("成分0") @Comment("成分1")
private Double c0p1; private Double c1p1;
@Comment("成分1 硫")
private Double c1p2;
@Comment("成分0 硫") @Comment("成分2 比例")
private Double c0p2; private Double c2p0;
@Comment("成分2 灰")
private Double c2p1;
@Comment("成分1 比例") @Comment("成分2 硫")
private Double c1p0; private Double c2p2;
@Comment("成分3 比例")
private Double c3p0;
@Comment("成分1") @Comment("成分3")
private Double c1p1; private Double c3p1;
@Comment("成分3 硫")
private Double c3p2;
@Comment("成分1 硫") @Comment("成分4 比例")
private Double c1p2; private Double c4p0;
@Comment("成分4 灰")
private Double c4p1;
@Comment("成分2 比例") @Comment("成分4 硫")
private Double c2p0; private Double c4p2;
@Comment("成分5 比例")
private Double c5p0;
@Comment("成分2") @Comment("成分5")
private Double c2p1; private Double c5p1;
@Comment("成分5 硫")
private Double c5p2;
@Comment("成分2 硫") @Comment("成分6 比例")
private Double c2p2; private Double c6p0;
@Comment("成分6 灰")
private Double c6p1;
@Comment("成分3 比例") @Comment("成分6 硫")
private Double c3p0; private Double c6p2;
@Comment("成分7 比例")
private Double c7p0;
@Comment("成分3") @Comment("成分7")
private Double c3p1; private Double c7p1;
@Comment("成分7 硫")
private Double c7p2;
@Comment("成分3 硫") @Comment("成分8 比例")
private Double c3p2; private Double c8p0;
@Comment("成分8 灰")
private Double c8p1;
@Comment("成分4 比例") @Comment("成分8 硫")
private Double c4p0; private Double c8p2;
@Comment("成分9 比例")
private Double c9p0;
@Comment("成分4") @Comment("成分9")
private Double c4p1; private Double c9p1;
@Comment("成分9 硫")
private Double c9p2;
@Comment("成分4 硫") @Comment("用户输入 大堆 灰")
private Double c4p2; private Double ddp1;
@Comment("用户输入 大堆 硫")
private Double ddp2;
@Comment("成分5 比例") @Comment("用户输入 大堆 挥发")
private Double c5p0; private Double ddp3;
@Comment("用户输入 大堆 粘结")
private Double ddp4;
@Comment("成分5 灰") @Comment("用户输入 大堆 备用")
private Double c5p1; private Double ddp5;
@Comment("成分5 硫")
private Double c5p2;
@Comment("成分6 比例")
private Double c6p0;
@Comment("成分6 灰")
private Double c6p1;
@Comment("成分6 硫")
private Double c6p2;
@Comment("成分7 比例")
private Double c7p0;
@Comment("成分7 灰")
private Double c7p1;
@Comment("成分7 硫")
private Double c7p2;
@Comment("成分8 比例")
private Double c8p0;
@Comment("成分8 灰")
private Double c8p1;
@Comment("成分8 硫")
private Double c8p2;
@Comment("成分9 比例")
private Double c9p0;
@Comment("成分9 灰")
private Double c9p1;
@Comment("成分9 硫")
private Double c9p2;
@Comment("用户输入 大堆 灰")
private Double ddp1;
@Comment("用户输入 大堆 硫")
private Double ddp2;
@Comment("用户输入 大堆 挥发")
private Double ddp3;
@Comment("用户输入 大堆 粘结")
private Double ddp4;
@Comment("用户输入 大堆 备用")
private Double ddp5;
@Comment("用户输入 翻大堆 灰")
private Double fddp1;
@Comment("用户输入 翻大堆 硫")
private Double fddp2;
@Comment("用户输入 翻大堆 挥发")
private Double fddp3;
@Comment("用户输入 翻大堆 粘结")
private Double fddp4;
@Comment("用户输入 翻大堆 备用")
private Double fddp5;
@Comment("系统计算 大堆 灰")
private Double sysDdp1;
@Comment("系统计算 大堆 硫")
private Double sysDdp2;
@Comment("系统计算 大堆 挥发")
private Double sysDdp3;
@Comment("系统计算 大堆 粘结")
private Double sysDdp4;
@Comment("系统计算 大堆 备用")
private Double sysDdp5;
@Comment("用户输入与系统计算的平均值 大堆 灰")
private Double avgDdp1;
@Comment("用户输入与系统计算的平均值 大堆 硫")
private Double avgDdp2;
@Comment("用户输入与系统计算的平均值 大堆 挥发")
private Double avgDdp3;
@Comment("用户输入与系统计算的平均值 大堆 粘结")
private Double avgDdp4;
@Comment("用户输入与系统计算的平均值 大堆 备用")
private Double avgDdp5;
public void calculate() {
if (Stream.of(c0p0, c1p0, c2p0, c3p0, c4p0, c5p0, c6p0, c7p0, c8p0, c9p0).filter(Objects::nonNull).sum().doubleValue() != 100)
throw new BizException("比例相加应该等于100!");
sysDdp1 = 0.0;
sysDdp2 = 0.0;
int count1 = 0;
int count2 = 0;
if (c0p0 != null && c0p1!=null) {sysDdp1 += c0p1 * c0p0 / 100.00; count1++;}
if (c0p0 != null && c0p2!=null) {sysDdp2 += c0p2 * c0p0 / 100.00; count2++;}
if (c1p0 != null && c1p1!=null) {sysDdp1 += c1p1 * c1p0 / 100.00; count1++;}
if (c1p0 != null && c1p2!=null) {sysDdp2 += c1p2 * c1p0 / 100.00; count2++;}
if (c2p0 != null && c2p1!=null) {sysDdp1 += c2p1 * c2p0 / 100.00; count1++;}
if (c2p0 != null && c2p2!=null) {sysDdp2 += c2p2 * c2p0 / 100.00; count2++;}
if (c3p0 != null && c3p1!=null) {sysDdp1 += c3p1 * c3p0 / 100.00; count1++;}
if (c3p0 != null && c3p2!=null) {sysDdp2 += c3p2 * c3p0 / 100.00; count2++;}
if (c4p0 != null && c4p1!=null) {sysDdp1 += c4p1 * c4p0 / 100.00; count1++;}
if (c4p0 != null && c4p2!=null) {sysDdp2 += c4p2 * c4p0 / 100.00; count2++;}
if (c5p0 != null && c5p1!=null) {sysDdp1 += c5p1 * c5p0 / 100.00; count1++;}
if (c5p0 != null && c5p2!=null) {sysDdp2 += c5p2 * c5p0 / 100.00; count2++;}
if (c6p0 != null && c6p1!=null) {sysDdp1 += c6p1 * c6p0 / 100.00; count1++;}
if (c6p0 != null && c6p2!=null) {sysDdp2 += c6p2 * c6p0 / 100.00; count2++;}
if (c7p0 != null && c7p1!=null) {sysDdp1 += c7p1 * c7p0 / 100.00; count1++;}
if (c7p0 != null && c7p2!=null) {sysDdp2 += c7p2 * c7p0 / 100.00; count2++;}
if (c8p0 != null && c8p1!=null) {sysDdp1 += c8p1 * c8p0 / 100.00; count1++;}
if (c8p0 != null && c8p2!=null) {sysDdp2 += c8p2 * c8p0 / 100.00; count2++;}
if (c9p0 != null && c9p1!=null) {sysDdp1 += c9p1 * c9p0 / 100.00; count1++;}
if (c9p0 != null && c9p2!=null) {sysDdp2 += c9p2 * c9p0 / 100.00; count2++;}
if (count1==0) sysDdp1 = null;
if (count2==0) sysDdp2 = null;
if (ddp1 != null && sysDdp1 != null) avgDdp1 = (ddp1 + sysDdp1) / 2.0;
if (ddp2 != null && sysDdp2 != null) avgDdp2 = (ddp2 + sysDdp2) / 2.0;
if (ddp3 != null && sysDdp3 != null) avgDdp3 = (ddp3 + sysDdp3) / 2.0;
if (ddp4 != null && sysDdp4 != null) avgDdp4 = (ddp4 + sysDdp4) / 2.0;
if (ddp5 != null && sysDdp5 != null) avgDdp5 = (ddp5 + sysDdp5) / 2.0;
@Comment("用户输入 翻大堆 灰")
private Double fddp1;
@Comment("用户输入 翻大堆 硫")
private Double fddp2;
@Comment("用户输入 翻大堆 挥发")
private Double fddp3;
@Comment("用户输入 翻大堆 粘结")
private Double fddp4;
@Comment("用户输入 翻大堆 备用")
private Double fddp5;
@Comment("系统计算 大堆 灰")
private Double sysDdp1;
@Comment("系统计算 大堆 硫")
private Double sysDdp2;
@Comment("系统计算 大堆 挥发")
private Double sysDdp3;
@Comment("系统计算 大堆 粘结")
private Double sysDdp4;
@Comment("系统计算 大堆 备用")
private Double sysDdp5;
@Comment("用户输入与系统计算的平均值 大堆 灰")
private Double avgDdp1;
@Comment("用户输入与系统计算的平均值 大堆 硫")
private Double avgDdp2;
@Comment("用户输入与系统计算的平均值 大堆 挥发")
private Double avgDdp3;
@Comment("用户输入与系统计算的平均值 大堆 粘结")
private Double avgDdp4;
@Comment("用户输入与系统计算的平均值 大堆 备用")
private Double avgDdp5;
public void calculate() {
if (Stream.of(c0p0, c1p0, c2p0, c3p0, c4p0, c5p0, c6p0, c7p0, c8p0, c9p0)
.filter(Objects::nonNull)
.sum()
.doubleValue()
!= 100) throw new BizException("比例相加应该等于100!");
sysDdp1 = 0.0;
sysDdp2 = 0.0;
int count1 = 0;
int count2 = 0;
if (c0p0 != null && c0p1 != null) {
sysDdp1 += c0p1 * c0p0 / 100.00;
count1++;
}
if (c0p0 != null && c0p2 != null) {
sysDdp2 += c0p2 * c0p0 / 100.00;
count2++;
}
if (c1p0 != null && c1p1 != null) {
sysDdp1 += c1p1 * c1p0 / 100.00;
count1++;
}
if (c1p0 != null && c1p2 != null) {
sysDdp2 += c1p2 * c1p0 / 100.00;
count2++;
}
if (c2p0 != null && c2p1 != null) {
sysDdp1 += c2p1 * c2p0 / 100.00;
count1++;
}
if (c2p0 != null && c2p2 != null) {
sysDdp2 += c2p2 * c2p0 / 100.00;
count2++;
}
if (c3p0 != null && c3p1 != null) {
sysDdp1 += c3p1 * c3p0 / 100.00;
count1++;
}
if (c3p0 != null && c3p2 != null) {
sysDdp2 += c3p2 * c3p0 / 100.00;
count2++;
}
if (c4p0 != null && c4p1 != null) {
sysDdp1 += c4p1 * c4p0 / 100.00;
count1++;
}
if (c4p0 != null && c4p2 != null) {
sysDdp2 += c4p2 * c4p0 / 100.00;
count2++;
}
if (c5p0 != null && c5p1 != null) {
sysDdp1 += c5p1 * c5p0 / 100.00;
count1++;
}
if (c5p0 != null && c5p2 != null) {
sysDdp2 += c5p2 * c5p0 / 100.00;
count2++;
}
if (c6p0 != null && c6p1 != null) {
sysDdp1 += c6p1 * c6p0 / 100.00;
count1++;
}
if (c6p0 != null && c6p2 != null) {
sysDdp2 += c6p2 * c6p0 / 100.00;
count2++;
}
if (c7p0 != null && c7p1 != null) {
sysDdp1 += c7p1 * c7p0 / 100.00;
count1++;
}
if (c7p0 != null && c7p2 != null) {
sysDdp2 += c7p2 * c7p0 / 100.00;
count2++;
}
if (c8p0 != null && c8p1 != null) {
sysDdp1 += c8p1 * c8p0 / 100.00;
count1++;
}
if (c8p0 != null && c8p2 != null) {
sysDdp2 += c8p2 * c8p0 / 100.00;
count2++;
}
if (c9p0 != null && c9p1 != null) {
sysDdp1 += c9p1 * c9p0 / 100.00;
count1++;
}
if (c9p0 != null && c9p2 != null) {
sysDdp2 += c9p2 * c9p0 / 100.00;
count2++;
} }
if (count1 == 0) sysDdp1 = null;
if (count2 == 0) sysDdp2 = null;
if (ddp1 != null && sysDdp1 != null) avgDdp1 = (ddp1 + sysDdp1) / 2.0;
if (ddp2 != null && sysDdp2 != null) avgDdp2 = (ddp2 + sysDdp2) / 2.0;
if (ddp3 != null && sysDdp3 != null) avgDdp3 = (ddp3 + sysDdp3) / 2.0;
if (ddp4 != null && sysDdp4 != null) avgDdp4 = (ddp4 + sysDdp4) / 2.0;
if (ddp5 != null && sysDdp5 != null) avgDdp5 = (ddp5 + sysDdp5) / 2.0;
}
} }

View File

@@ -1,6 +1,5 @@
package cn.lihongjie.coal.coalWashingDailyAnalysis.mapper; package cn.lihongjie.coal.coalWashingDailyAnalysis.mapper;
import cn.lihongjie.coal.base.mapper.BaseMapper; import cn.lihongjie.coal.base.mapper.BaseMapper;
import cn.lihongjie.coal.base.mapper.CommonMapper; import cn.lihongjie.coal.base.mapper.CommonMapper;
import cn.lihongjie.coal.coalWashingDailyAnalysis.dto.CoalWashingDailyAnalysisDto; import cn.lihongjie.coal.coalWashingDailyAnalysis.dto.CoalWashingDailyAnalysisDto;
@@ -9,16 +8,15 @@ import cn.lihongjie.coal.coalWashingDailyAnalysis.dto.UpdateCoalWashingDailyAnal
import cn.lihongjie.coal.coalWashingDailyAnalysis.entity.CoalWashingDailyAnalysisEntity; import cn.lihongjie.coal.coalWashingDailyAnalysis.entity.CoalWashingDailyAnalysisEntity;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants; import org.mapstruct.MappingConstants;
import org.mapstruct.MappingTarget;
import org.mapstruct.control.DeepClone; import org.mapstruct.control.DeepClone;
@Mapper( @Mapper(
componentModel = MappingConstants.ComponentModel.SPRING, componentModel = MappingConstants.ComponentModel.SPRING,
uses = {CommonMapper.class}, uses = {CommonMapper.class},
mappingControl = DeepClone.class mappingControl = DeepClone.class)
public interface CoalWashingDailyAnalysisMapper
extends BaseMapper<
) CoalWashingDailyAnalysisEntity,
public interface CoalWashingDailyAnalysisMapper extends BaseMapper<CoalWashingDailyAnalysisEntity, CoalWashingDailyAnalysisDto, CreateCoalWashingDailyAnalysisDto, UpdateCoalWashingDailyAnalysisDto>{ CoalWashingDailyAnalysisDto,
CreateCoalWashingDailyAnalysisDto,
} UpdateCoalWashingDailyAnalysisDto> {}

View File

@@ -4,37 +4,30 @@ import cn.lihongjie.coal.base.mapper.CommonMapper;
import cn.lihongjie.coal.coalBlend.dto.CoalBlendDto; import cn.lihongjie.coal.coalBlend.dto.CoalBlendDto;
import cn.lihongjie.coal.coalWashingDailyAnalysis.entity.CoalWashingDailyAnalysisEntity; import cn.lihongjie.coal.coalWashingDailyAnalysis.entity.CoalWashingDailyAnalysisEntity;
import cn.lihongjie.coal.coalWashingDailyAnalysis.entity.CoalWashingDailyAnalysisItemVo; import cn.lihongjie.coal.coalWashingDailyAnalysis.entity.CoalWashingDailyAnalysisItemVo;
import java.math.BigDecimal;
import java.math.RoundingMode;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants; import org.mapstruct.MappingConstants;
import org.mapstruct.control.DeepClone; import org.mapstruct.control.DeepClone;
import java.math.BigDecimal;
import java.math.RoundingMode;
@Mapper( @Mapper(
componentModel = MappingConstants.ComponentModel.SPRING, componentModel = MappingConstants.ComponentModel.SPRING,
uses = {CommonMapper.class}, uses = {CommonMapper.class},
mappingControl = DeepClone.class mappingControl = DeepClone.class)
)
public interface RoundMapper { public interface RoundMapper {
CoalWashingDailyAnalysisEntity round(CoalWashingDailyAnalysisEntity entity);
CoalWashingDailyAnalysisEntity round(CoalWashingDailyAnalysisEntity entity); CoalWashingDailyAnalysisItemVo round(CoalWashingDailyAnalysisItemVo entity);
CoalWashingDailyAnalysisItemVo round(CoalWashingDailyAnalysisItemVo entity); CoalBlendDto round(CoalBlendDto entity);
CoalBlendDto round(CoalBlendDto entity);
default Double formatDouble(Double d) {
default Double formatDouble(Double d) { if (d == null) {
return d;
if (d == null) {
return d;
}
return new BigDecimal(d).setScale(2, RoundingMode.HALF_UP).doubleValue();
} }
return new BigDecimal(d).setScale(2, RoundingMode.HALF_UP).doubleValue();
}
} }

View File

@@ -5,5 +5,5 @@ import cn.lihongjie.coal.coalWashingDailyAnalysis.entity.CoalWashingDailyAnalysi
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@Repository @Repository
public interface CoalWashingDailyAnalysisRepository extends BaseRepository<CoalWashingDailyAnalysisEntity> { public interface CoalWashingDailyAnalysisRepository
} extends BaseRepository<CoalWashingDailyAnalysisEntity> {}

View File

@@ -3,13 +3,13 @@ package cn.lihongjie.coal.coalWashingDailyAnalysis.service;
import cn.lihongjie.coal.base.dto.CommonQuery; import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest; import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.base.service.BaseService; import cn.lihongjie.coal.base.service.BaseService;
import cn.lihongjie.coal.coalWashingDailyAnalysis.repository.CoalWashingDailyAnalysisRepository;
import cn.lihongjie.coal.coalWashingDailyAnalysis.dto.CoalWashingDailyAnalysisDto; import cn.lihongjie.coal.coalWashingDailyAnalysis.dto.CoalWashingDailyAnalysisDto;
import cn.lihongjie.coal.coalWashingDailyAnalysis.dto.CreateCoalWashingDailyAnalysisDto; import cn.lihongjie.coal.coalWashingDailyAnalysis.dto.CreateCoalWashingDailyAnalysisDto;
import cn.lihongjie.coal.coalWashingDailyAnalysis.dto.UpdateCoalWashingDailyAnalysisDto; import cn.lihongjie.coal.coalWashingDailyAnalysis.dto.UpdateCoalWashingDailyAnalysisDto;
import cn.lihongjie.coal.coalWashingDailyAnalysis.entity.CoalWashingDailyAnalysisEntity; import cn.lihongjie.coal.coalWashingDailyAnalysis.entity.CoalWashingDailyAnalysisEntity;
import cn.lihongjie.coal.coalWashingDailyAnalysis.mapper.CoalWashingDailyAnalysisMapper; import cn.lihongjie.coal.coalWashingDailyAnalysis.mapper.CoalWashingDailyAnalysisMapper;
import cn.lihongjie.coal.coalWashingDailyAnalysis.mapper.RoundMapper; import cn.lihongjie.coal.coalWashingDailyAnalysis.mapper.RoundMapper;
import cn.lihongjie.coal.coalWashingDailyAnalysis.repository.CoalWashingDailyAnalysisRepository;
import jakarta.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -21,80 +21,65 @@ import org.springframework.stereotype.Service;
@Service @Service
@Slf4j @Slf4j
public class CoalWashingDailyAnalysisService extends BaseService<CoalWashingDailyAnalysisEntity, CoalWashingDailyAnalysisRepository> { public class CoalWashingDailyAnalysisService
extends BaseService<CoalWashingDailyAnalysisEntity, CoalWashingDailyAnalysisRepository> {
@Autowired @Autowired CoalWashingDailyAnalysisRepository repository;
CoalWashingDailyAnalysisRepository repository;
@Autowired @Autowired CoalWashingDailyAnalysisMapper mapper;
CoalWashingDailyAnalysisMapper mapper;
@Autowired @Autowired RoundMapper roundMapper;
RoundMapper roundMapper;
@PostConstruct @PostConstruct
public void init() { public void init() {}
public CoalWashingDailyAnalysisDto create(CreateCoalWashingDailyAnalysisDto request) {
} CoalWashingDailyAnalysisEntity entity = mapper.toEntity(request);
this.repository.save(entity);
return getById(entity.getId());
}
public CoalWashingDailyAnalysisDto create(CreateCoalWashingDailyAnalysisDto request) { public CoalWashingDailyAnalysisDto calculate(CreateCoalWashingDailyAnalysisDto request) {
CoalWashingDailyAnalysisEntity entity = mapper.toEntity(request);
CoalWashingDailyAnalysisEntity entity = mapper.toEntity(request); entity.rollingAvg();
return mapper.toDto(roundMapper.round(entity));
}
this.repository.save(entity); public CoalWashingDailyAnalysisDto update(UpdateCoalWashingDailyAnalysisDto request) {
return getById(entity.getId()); CoalWashingDailyAnalysisEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
} this.repository.save(entity);
public CoalWashingDailyAnalysisDto calculate(CreateCoalWashingDailyAnalysisDto request) {
return getById(entity.getId());
}
CoalWashingDailyAnalysisEntity entity = mapper.toEntity(request); public void delete(IdRequest request) {
entity.rollingAvg(); this.repository.deleteAllById(request.getIds());
}
return mapper.toDto(roundMapper.round(entity)); public CoalWashingDailyAnalysisDto getById(String id) {
} CoalWashingDailyAnalysisEntity entity = repository.get(id);
public CoalWashingDailyAnalysisDto update(UpdateCoalWashingDailyAnalysisDto request) { return mapper.toDto(entity);
CoalWashingDailyAnalysisEntity entity = this.repository.get(request.getId()); }
this.mapper.updateEntity(entity, request);
this.repository.save(entity); @Autowired ConversionService conversionService;
return getById(entity.getId()); public Page<CoalWashingDailyAnalysisDto> list(CommonQuery query) {
}
Page<CoalWashingDailyAnalysisEntity> page =
repository.findAll(
query.specification(conversionService),
PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders())));
public void delete(IdRequest request) { return page.map(this.mapper::toDto);
}
this.repository.deleteAllById(request.getIds());
}
public CoalWashingDailyAnalysisDto getById(String id) {
CoalWashingDailyAnalysisEntity entity = repository.get(id);
return mapper.toDto(entity);
}
@Autowired
ConversionService conversionService;
public Page<CoalWashingDailyAnalysisDto> list(CommonQuery query) {
Page<CoalWashingDailyAnalysisEntity> page = repository.findAll(query.specification(conversionService), PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders())));
return page.map(this.mapper::toDto);
}
} }

View File

@@ -1,9 +1,6 @@
package cn.lihongjie.coal.common; package cn.lihongjie.coal.common;
import io.vavr.Tuple2; import io.vavr.Tuple2;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.ObjectUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -13,69 +10,90 @@ import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.util.stream.StreamSupport; import java.util.stream.StreamSupport;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.ObjectUtils;
@UtilityClass @UtilityClass
public class CollectionUtils { public class CollectionUtils {
public static <Data, T> List<T> map(Iterable<Data> data, Function<Data, T> fn) { public static <Data, T> List<T> map(Iterable<Data> data, Function<Data, T> fn) {
return StreamSupport.stream(data.spliterator(), false).map(fn).collect(java.util.stream.Collectors.toList()); return StreamSupport.stream(data.spliterator(), false)
} .map(fn)
.collect(java.util.stream.Collectors.toList());
}
public static <A, B, K> List<Tuple2<A, B>> innerHashJoin(Iterable<A> a, Iterable<B> b, Function<A, K> ak, Function<B, K> bk) { public static <A, B, K> List<Tuple2<A, B>> innerHashJoin(
Map<K, List<A>> aMap = newStream(a).collect(Collectors.groupingBy(ak)); Iterable<A> a, Iterable<B> b, Function<A, K> ak, Function<B, K> bk) {
Map<K, List<B>> bMap = newStream(b).collect(Collectors.groupingBy(bk)); Map<K, List<A>> aMap = newStream(a).collect(Collectors.groupingBy(ak));
return aMap.keySet().stream().flatMap(k -> aMap.getOrDefault(k, new ArrayList<>()).stream().flatMap(av -> bMap.getOrDefault(k, new ArrayList<>()).stream().map(bv -> new Tuple2<>(av, bv)))).collect(java.util.stream.Collectors.toList()); Map<K, List<B>> bMap = newStream(b).collect(Collectors.groupingBy(bk));
} return aMap.keySet().stream()
.flatMap(
k ->
aMap.getOrDefault(k, new ArrayList<>()).stream()
.flatMap(
av ->
bMap.getOrDefault(k, new ArrayList<>()).stream()
.map(bv -> new Tuple2<>(av, bv))))
.collect(java.util.stream.Collectors.toList());
}
public static <A, B> List<Tuple2<A, B>> innerNestJoin(Iterable<A> a, Iterable<B> b, BiFunction<A, B, Boolean> test) { public static <A, B> List<Tuple2<A, B>> innerNestJoin(
a = ObjectUtils.defaultIfNull(a, new ArrayList<>()); Iterable<A> a, Iterable<B> b, BiFunction<A, B, Boolean> test) {
b = ObjectUtils.defaultIfNull(b, new ArrayList<>()); a = ObjectUtils.defaultIfNull(a, new ArrayList<>());
b = ObjectUtils.defaultIfNull(b, new ArrayList<>());
List<Tuple2<A, B>> ans = new ArrayList<>(); List<Tuple2<A, B>> ans = new ArrayList<>();
for (A a1 : a) {
for (B b1 : b) {
if (test.apply(a1, b1)) {
ans.add(new Tuple2<>(a1, b1));
}
}
for (A a1 : a) {
for (B b1 : b) {
if (test.apply(a1, b1)) {
ans.add(new Tuple2<>(a1, b1));
} }
return ans; }
} }
return ans;
}
public static <A, B, K> List<Tuple2<A, B>> leftHashJoin(Iterable<A> a, Iterable<B> b, Function<A, K> ak, Function<B, K> bk) { public static <A, B, K> List<Tuple2<A, B>> leftHashJoin(
Map<K, List<A>> aMap = newStream(a).collect(Collectors.groupingBy(ak)); Iterable<A> a, Iterable<B> b, Function<A, K> ak, Function<B, K> bk) {
Map<K, List<B>> bMap = newStream(b).collect(Collectors.groupingBy(bk)); Map<K, List<A>> aMap = newStream(a).collect(Collectors.groupingBy(ak));
return aMap.keySet().stream().flatMap(k -> aMap.getOrDefault(k, new ArrayList<>()).stream().flatMap(av -> bMap.getOrDefault(k, new ArrayList<>(Arrays.asList((B)null))).stream().map(bv -> new Tuple2<>(av, bv)))).collect(java.util.stream.Collectors.toList()); Map<K, List<B>> bMap = newStream(b).collect(Collectors.groupingBy(bk));
} return aMap.keySet().stream()
.flatMap(
k ->
aMap.getOrDefault(k, new ArrayList<>()).stream()
.flatMap(
av ->
bMap.getOrDefault(k, new ArrayList<>(Arrays.asList((B) null))).stream()
.map(bv -> new Tuple2<>(av, bv))))
.collect(java.util.stream.Collectors.toList());
}
public static <A, B> List<Tuple2<A, B>> leftNestJoin(Iterable<A> a, Iterable<B> b, BiFunction<A, B, Boolean> test) { public static <A, B> List<Tuple2<A, B>> leftNestJoin(
a = ObjectUtils.defaultIfNull(a, new ArrayList<>()); Iterable<A> a, Iterable<B> b, BiFunction<A, B, Boolean> test) {
b = ObjectUtils.defaultIfNull(b, new ArrayList<>()); a = ObjectUtils.defaultIfNull(a, new ArrayList<>());
b = ObjectUtils.defaultIfNull(b, new ArrayList<>());
List<Tuple2<A, B>> ans = new ArrayList<>(); List<Tuple2<A, B>> ans = new ArrayList<>();
for (A a1 : a) { for (A a1 : a) {
boolean find = false; boolean find = false;
for (B b1 : b) { for (B b1 : b) {
if (test.apply(a1, b1)) { if (test.apply(a1, b1)) {
ans.add(new Tuple2<>(a1, b1)); ans.add(new Tuple2<>(a1, b1));
find = true; find = true;
}
}
if (!find) {
ans.add(new Tuple2<>(a1, null));
}
} }
return ans; }
if (!find) {
ans.add(new Tuple2<>(a1, null));
}
} }
return ans;
}
private static <A> Stream<A> newStream(Iterable<A> a) {
private static <A> Stream<A> newStream(Iterable<A> a) { return StreamSupport.stream(
return StreamSupport.stream(a == null ? new ArrayList<A>().spliterator() : a.spliterator(), false); a == null ? new ArrayList<A>().spliterator() : a.spliterator(), false);
} }
} }

View File

@@ -3,5 +3,5 @@ package cn.lihongjie.coal.common;
import java.util.*; import java.util.*;
public class Constants { public class Constants {
public static String SYSCONFIG_ENABLE_CAPTCHA = "enable_captcha"; public static String SYSCONFIG_ENABLE_CAPTCHA = "enable_captcha";
} }

View File

@@ -1,6 +1,5 @@
package cn.lihongjie.coal.common; package cn.lihongjie.coal.common;
import cn.lihongjie.coal.session.SessionService; import cn.lihongjie.coal.session.SessionService;
import cn.lihongjie.coal.user.entity.UserEntity; import cn.lihongjie.coal.user.entity.UserEntity;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
@@ -9,44 +8,34 @@ import org.springframework.security.core.context.SecurityContextHolder;
@UtilityClass @UtilityClass
public class Ctx { public class Ctx {
public static String getUserId() {
return getAuthentication().getUser().getId();
}
public static boolean isLoggedIn() {
public static String getUserId(){ return getAuthentication() != null && getAuthentication().isAuthenticated();
return getAuthentication().getUser().getId(); }
} public static String getSessionId() {
return getAuthentication().getSessionId();
}
public static boolean isLoggedIn(){ private static SessionService.MyAuthentication getAuthentication() {
return (SessionService.MyAuthentication) SecurityContextHolder.getContext().getAuthentication();
}
return getAuthentication() != null && getAuthentication().isAuthenticated(); public static boolean isOrgAdmin() {
}
return getAuthentication().getUser().getOrgAdmin();
}
public static String getSessionId(){ public static boolean isSysAdmin() {
return getAuthentication().getSessionId();
}
private static SessionService.MyAuthentication getAuthentication() {
return (SessionService.MyAuthentication) SecurityContextHolder.getContext().getAuthentication();
}
public static boolean isOrgAdmin() {
return getAuthentication().getUser().getOrgAdmin();
}
public static boolean isSysAdmin() {
return getAuthentication().getUser().getSysAdmin();
}
public static UserEntity currentUser() {
return getAuthentication().getUser();
}
return getAuthentication().getUser().getSysAdmin();
}
public static UserEntity currentUser() {
return getAuthentication().getUser();
}
} }

View File

@@ -3,6 +3,10 @@ package cn.lihongjie.coal.common;
import cn.lihongjie.coal.exception.BizException; import cn.lihongjie.coal.exception.BizException;
import groovy.lang.Binding; import groovy.lang.Binding;
import groovy.lang.GroovyShell; import groovy.lang.GroovyShell;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -11,59 +15,51 @@ import org.codehaus.groovy.ast.GroovyCodeVisitorAdapter;
import org.codehaus.groovy.ast.builder.AstStringCompiler; import org.codehaus.groovy.ast.builder.AstStringCompiler;
import org.codehaus.groovy.ast.expr.VariableExpression; import org.codehaus.groovy.ast.expr.VariableExpression;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@UtilityClass @UtilityClass
@Slf4j @Slf4j
public class GroovyScriptUtils { public class GroovyScriptUtils {
public static void validate(String formula) { public static void validate(String formula) {
if (StringUtils.isEmpty(formula)) { if (StringUtils.isEmpty(formula)) {
return; return;
} }
AstStringCompiler compiler = new AstStringCompiler(); AstStringCompiler compiler = new AstStringCompiler();
try { try {
List<ASTNode> astNodes = compiler.compile(formula); List<ASTNode> astNodes = compiler.compile(formula);
} catch (Exception e) { } catch (Exception e) {
log.info(formula, e); log.info(formula, e);
throw new BizException("无效的计算公式"); throw new BizException("无效的计算公式");
} }
}
public static List<String> variables(String formula) {
if (StringUtils.isEmpty(formula)) {
return new ArrayList<>();
} }
AstStringCompiler compiler = new AstStringCompiler();
public static List<String> variables(String formula) { return compiler.compile(formula).stream()
if (StringUtils.isEmpty(formula)) { .flatMap(
return new ArrayList<>(); x -> {
} ArrayList<String> ans = new ArrayList<>();
x.visit(
new GroovyCodeVisitorAdapter() {
@Override
public void visitVariableExpression(VariableExpression expression) {
ans.add(expression.getName());
}
});
AstStringCompiler compiler = new AstStringCompiler(); return ans.stream();
})
.collect(Collectors.toList());
}
return compiler.compile(formula).stream().flatMap(x -> { public static Object exec(String formula0, Map<String, Object> map) {
ArrayList<String> ans = new ArrayList<>(); GroovyShell shell = new GroovyShell(new Binding(map));
x.visit(new GroovyCodeVisitorAdapter() {
@Override
public void visitVariableExpression(VariableExpression expression) {
ans.add(expression.getName());
}
});
return ans.stream(); return shell.evaluate(formula0);
}
}).collect(Collectors.toList());
}
public static Object exec(String formula0, Map<String, Object> map) {
GroovyShell shell = new GroovyShell(new Binding(map));
return shell.evaluate(formula0);
}
} }

View File

@@ -1,29 +1,28 @@
package cn.lihongjie.coal.common; package cn.lihongjie.coal.common;
import java.lang.reflect.Field;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Field;
@UtilityClass @UtilityClass
public class ReflectUtils { public class ReflectUtils {
public static Object getFieldValue(Object object, String fieldName) { public static Object getFieldValue(Object object, String fieldName) {
if (object == null) { if (object == null) {
return null; return null;
}
if (StringUtils.isEmpty(fieldName)) {
return null;
}
Field field = ReflectionUtils.findField(object.getClass(), fieldName);
if (field != null) {
field.setAccessible(true);
return ReflectionUtils.getField(field, object);
}
return null;
} }
if (StringUtils.isEmpty(fieldName)) {
return null;
}
Field field = ReflectionUtils.findField(object.getClass(), fieldName);
if (field != null) {
field.setAccessible(true);
return ReflectionUtils.getField(field, object);
}
return null;
}
} }

View File

@@ -11,58 +11,57 @@ import org.apache.commons.lang3.StringUtils;
@UtilityClass @UtilityClass
public class RequestUtils { public class RequestUtils {
private static final String[] HEADERS_TO_TRY = {
"X-Forwarded-For",
"Proxy-Client-IP",
"WL-Proxy-Client-IP",
"HTTP_X_FORWARDED_FOR",
"HTTP_X_FORWARDED",
"HTTP_X_CLUSTER_CLIENT_IP",
"HTTP_CLIENT_IP",
"HTTP_FORWARDED_FOR",
"HTTP_FORWARDED",
"HTTP_VIA",
"REMOTE_ADDR"
};
private String getClientIpAddress(HttpServletRequest request) {
private static final String[] HEADERS_TO_TRY = { for (String header : HEADERS_TO_TRY) {
"X-Forwarded-For", String ip = request.getHeader(header);
"Proxy-Client-IP", if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
"WL-Proxy-Client-IP", return ip;
"HTTP_X_FORWARDED_FOR", }
"HTTP_X_FORWARDED",
"HTTP_X_CLUSTER_CLIENT_IP",
"HTTP_CLIENT_IP",
"HTTP_FORWARDED_FOR",
"HTTP_FORWARDED",
"HTTP_VIA",
"REMOTE_ADDR" };
private String getClientIpAddress(HttpServletRequest request) {
for (String header : HEADERS_TO_TRY) {
String ip = request.getHeader(header);
if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
return ip;
}
}
return request.getRemoteAddr();
}
public static String getIp(HttpServletRequest request) {
return getClientIpAddress(request);
} }
public static String getUa(HttpServletRequest request) { return request.getRemoteAddr();
}
try { public static String getIp(HttpServletRequest request) {
return getClientIpAddress(request);
}
String header = request.getHeader("User-Agent"); public static String getUa(HttpServletRequest request) {
if (StringUtils.isEmpty(header)) {
return "";
}
UserAgent userAgent = UserAgent.parseUserAgentString(header);
Browser browser = userAgent.getBrowser();
String browserName = browser.getName(); try {
//or
// String browserName = browser.getGroup().getName();
Version browserVersion = userAgent.getBrowserVersion();
OperatingSystem os = userAgent.getOperatingSystem(); String header = request.getHeader("User-Agent");
if (StringUtils.isEmpty(header)) {
return "";
}
UserAgent userAgent = UserAgent.parseUserAgentString(header);
Browser browser = userAgent.getBrowser();
return os.getName() + " " + browserName + browserVersion.toString(); String browserName = browser.getName();
// or
// String browserName = browser.getGroup().getName();
Version browserVersion = userAgent.getBrowserVersion();
} catch (Exception e) { OperatingSystem os = userAgent.getOperatingSystem();
return "";
}
return os.getName() + " " + browserName + browserVersion.toString();
} catch (Exception e) {
return "";
} }
}
} }

Some files were not shown because too many files have changed in this diff Show More