格式化代码

This commit is contained in:
2023-09-21 20:00:40 +08:00
parent d4852ec5d8
commit f0e24ace09
244 changed files with 9179 additions and 8295 deletions

11
pom.xml
View File

@@ -61,11 +61,20 @@
<artifactId>groovy</artifactId>
<version>4.0.14</version>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>com.huaweicloud</groupId>
<artifactId>esdk-obs-java-bundle</artifactId>
<version>3.23.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>

View File

@@ -8,7 +8,7 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@EnableJpaRepositories
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

@@ -12,16 +12,16 @@ import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import cn.lihongjie.coal.base.mapper.BaseMapper;
import cn.lihongjie.coal.base.mapper.CommonMapper;
import cn.lihongjie.coal.base.service.BaseService;
import com.google.common.base.CaseFormat;
import com.squareup.javapoet.*;
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.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.mapstruct.Mapper;
import org.mapstruct.control.DeepClone;
@@ -37,159 +37,175 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.nio.file.Path;
import java.util.Objects;
import java.util.Scanner;
import javax.lang.model.element.Modifier;
public class Codegen {
public static final Path DIRECTORY = Path.of("src/main/java/");
public static final Path DIRECTORY = Path.of("src/main/java/");
@SneakyThrows
public static void main(String[] args) {
System.out.print("请输入模块名:");
String moduleName = new Scanner(System.in).nextLine();
@SneakyThrows
public static void main(String[] args) {
System.out.print("请输入模块名:");
String moduleName = new Scanner(System.in).nextLine();
System.out.print("请输入模块中文名:");
String moduleCNName = new Scanner(System.in).nextLine();
System.out.print("请输入模块中文名:");
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]:");
boolean orgMode =
Objects.equals(
StringUtils.defaultIfBlank(new Scanner(System.in).nextLine(), "Y"), "Y");
String lModuleName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, moduleName);
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";
String lModuleName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, moduleName);
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
// 生成entity
TypeSpec entity =
TypeSpec.classBuilder(StringUtils.capitalize(moduleName) + "Entity")
.addModifiers(Modifier.PUBLIC)
.superclass(orgMode ? OrgCommonEntity.class : CommonEntity.class)
.addAnnotation(Data.class)
.addAnnotation(Entity.class)
.build();
TypeSpec entity =
TypeSpec.classBuilder(StringUtils.capitalize(moduleName) + "Entity")
.addModifiers(Modifier.PUBLIC)
.superclass(orgMode ? OrgCommonEntity.class : CommonEntity.class)
.addAnnotation(Data.class)
.addAnnotation(Entity.class)
.build();
JavaFile.builder(entityPackage, entity).build().writeTo(DIRECTORY);
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();
// 生成dto
TypeSpec dto =
TypeSpec.classBuilder(StringUtils.capitalize(moduleName) + "Dto")
.addModifiers(Modifier.PUBLIC)
.superclass(orgMode ? OrgCommonDto.class : CommonDto.class)
.addAnnotation(Data.class)
.build();
JavaFile.builder(dtoPackage, dto).build().writeTo(DIRECTORY);
JavaFile.builder(dtoPackage, dto).build().writeTo(DIRECTORY);
// 生成createDto
TypeSpec createDto =
TypeSpec.classBuilder("Create" + StringUtils.capitalize(moduleName) + "Dto")
.addModifiers(Modifier.PUBLIC)
.superclass(orgMode ? OrgCommonDto.class : CommonDto.class)
.addAnnotation(Data.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(dtoPackage, createDto).build().writeTo(DIRECTORY);
JavaFile.builder(dtoPackage, createDto).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();
// 生成updateDto
TypeSpec updateDto =
TypeSpec.classBuilder("Update" + StringUtils.capitalize(moduleName) + "Dto")
.addModifiers(Modifier.PUBLIC)
.superclass(orgMode ? OrgCommonDto.class : CommonDto.class)
.addAnnotation(Data.class)
.build();
JavaFile.builder(dtoPackage, updateDto).build().writeTo(DIRECTORY);
JavaFile.builder(dtoPackage, updateDto).build().writeTo(DIRECTORY);
// 生成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();
// 生成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(repoPackage, repository).build().writeTo(DIRECTORY);
JavaFile.builder(repoPackage, repository).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();
// 生成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();
JavaFile.builder(mapperPackage, mapper).build().writeTo(DIRECTORY);
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(
"""
// 生成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);
this.repository.save(entity);
return getById(entity.getId())
""",
ClassName.get(entityPackage, entity.name))
.build())
.addMethod(
MethodSpec.methodBuilder("update")
.addModifiers(Modifier.PUBLIC)
.returns(ClassName.get(dtoPackage, dto.name))
.addParameter(ClassName.get(dtoPackage, updateDto.name), "request")
.addStatement(
"""
ClassName.get(entityPackage, entity.name))
.build())
.addMethod(
MethodSpec.methodBuilder("update")
.addModifiers(Modifier.PUBLIC)
.returns(ClassName.get(dtoPackage, dto.name))
.addParameter(
ClassName.get(dtoPackage, updateDto.name),
"request")
.addStatement(
"""
$T entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
@@ -197,172 +213,186 @@ public class Codegen {
return getById(entity.getId())
""",
ClassName.get(entityPackage, entity.name))
.build())
.addMethod(
MethodSpec.methodBuilder("delete")
.addModifiers(Modifier.PUBLIC)
.returns(void.class)
.addParameter(ClassName.get(IdRequest.class), "request")
.addStatement(
"""
ClassName.get(entityPackage, entity.name))
.build())
.addMethod(
MethodSpec.methodBuilder("delete")
.addModifiers(Modifier.PUBLIC)
.returns(void.class)
.addParameter(ClassName.get(IdRequest.class), "request")
.addStatement(
"""
this.repository.deleteAllById(request.getIds())
""")
.build())
.addMethod(
MethodSpec.methodBuilder("getById")
.addModifiers(Modifier.PUBLIC)
.returns(ClassName.get(dtoPackage, dto.name))
.addParameter(ClassName.get(String.class), "id")
.addStatement(
"""
.build())
.addMethod(
MethodSpec.methodBuilder("getById")
.addModifiers(Modifier.PUBLIC)
.returns(ClassName.get(dtoPackage, dto.name))
.addParameter(ClassName.get(String.class), "id")
.addStatement(
"""
$T entity = repository.get(id);
return mapper.toDto(entity)
""",
ClassName.get(entityPackage, entity.name))
.build())
.addMethod(
MethodSpec.methodBuilder("list")
.addModifiers(Modifier.PUBLIC)
.returns(
ParameterizedTypeName.get(
ClassName.get(Page.class), ClassName.get(dtoPackage, dto.name)))
.addParameter(ClassName.get(CommonQuery.class), "query")
.addStatement(
"""
ClassName.get(entityPackage, entity.name))
.build())
.addMethod(
MethodSpec.methodBuilder("list")
.addModifiers(Modifier.PUBLIC)
.returns(
ParameterizedTypeName.get(
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())));
return page.map(this.mapper::toDto)
""",
ClassName.get(Page.class),
ClassName.get(entityPackage, entity.name),
ClassName.get(PageRequest.class),
ClassName.get(Sort.class))
.build())
.build();
ClassName.get(Page.class),
ClassName.get(entityPackage, entity.name),
ClassName.get(PageRequest.class),
ClassName.get(Sort.class))
.build())
.build();
JavaFile.builder(servicePackage, service).build().writeTo(DIRECTORY);
JavaFile.builder(servicePackage, service).build().writeTo(DIRECTORY);
// 生成controller
TypeSpec.Builder controllerBuilder =
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);
// 生成controller
TypeSpec.Builder controllerBuilder =
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(
ClassName.get(servicePackage, service.name), "service", Modifier.PRIVATE)
.addAnnotation(Autowired.class)
.build())
.addMethod(
MethodSpec.methodBuilder("create")
.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(
"""
if (orgMode) {
controllerBuilder.addAnnotation(OrgScope.class);
}
controllerBuilder
.addField(
FieldSpec.builder(
ClassName.get(servicePackage, service.name),
"service",
Modifier.PRIVATE)
.addAnnotation(Autowired.class)
.build())
.addMethod(
MethodSpec.methodBuilder("create")
.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)
""")
.build())
.addMethod(
MethodSpec.methodBuilder("update")
.addModifiers(Modifier.PUBLIC)
.returns(ClassName.get(dtoPackage, dto.name))
.addAnnotation(
AnnotationSpec.builder(PostMapping.class)
.addMember("value", "$S", "/update")
.build())
.addParameter(
ParameterSpec.builder(ClassName.get(dtoPackage, updateDto.name), "request")
.addAnnotation(RequestBody.class)
.build())
.addStatement(
"""
.build())
.addMethod(
MethodSpec.methodBuilder("update")
.addModifiers(Modifier.PUBLIC)
.returns(ClassName.get(dtoPackage, dto.name))
.addAnnotation(
AnnotationSpec.builder(PostMapping.class)
.addMember("value", "$S", "/update")
.build())
.addParameter(
ParameterSpec.builder(
ClassName.get(dtoPackage, updateDto.name),
"request")
.addAnnotation(RequestBody.class)
.build())
.addStatement(
"""
return this.service.update(request)
""")
.build())
.addMethod(
MethodSpec.methodBuilder("delete")
.addModifiers(Modifier.PUBLIC)
.returns(Object.class)
.addAnnotation(
AnnotationSpec.builder(PostMapping.class)
.addMember("value", "$S", "/delete")
.build())
.addParameter(
ParameterSpec.builder(ClassName.get(IdRequest.class), "request")
.addAnnotation(RequestBody.class)
.build())
.addStatement(
"""
.build())
.addMethod(
MethodSpec.methodBuilder("delete")
.addModifiers(Modifier.PUBLIC)
.returns(Object.class)
.addAnnotation(
AnnotationSpec.builder(PostMapping.class)
.addMember("value", "$S", "/delete")
.build())
.addParameter(
ParameterSpec.builder(
ClassName.get(IdRequest.class), "request")
.addAnnotation(RequestBody.class)
.build())
.addStatement(
"""
this.service.delete(request);
return true
""")
.build())
.addMethod(
MethodSpec.methodBuilder("getById")
.addModifiers(Modifier.PUBLIC)
.returns(ClassName.get(dtoPackage, dto.name))
.addAnnotation(
AnnotationSpec.builder(PostMapping.class)
.addMember("value", "$S", "/getById")
.build())
.addParameter(
ParameterSpec.builder(ClassName.get(String.class), "request")
.addAnnotation(RequestBody.class)
.build())
.addStatement(
"""
.build())
.addMethod(
MethodSpec.methodBuilder("getById")
.addModifiers(Modifier.PUBLIC)
.returns(ClassName.get(dtoPackage, dto.name))
.addAnnotation(
AnnotationSpec.builder(PostMapping.class)
.addMember("value", "$S", "/getById")
.build())
.addParameter(
ParameterSpec.builder(
ClassName.get(String.class), "request")
.addAnnotation(RequestBody.class)
.build())
.addStatement(
"""
return this.service.getById(request)
""")
.build())
.addMethod(
MethodSpec.methodBuilder("list")
.addModifiers(Modifier.PUBLIC)
.returns(
ParameterizedTypeName.get(
ClassName.get(Page.class), ClassName.get(dtoPackage, dto.name)))
.addAnnotation(
AnnotationSpec.builder(PostMapping.class)
.addMember("value", "$S", "/list")
.build())
.addParameter(
ParameterSpec.builder(ClassName.get(CommonQuery.class), "request")
.addAnnotation(RequestBody.class)
.build())
.addStatement(
"""
.build())
.addMethod(
MethodSpec.methodBuilder("list")
.addModifiers(Modifier.PUBLIC)
.returns(
ParameterizedTypeName.get(
ClassName.get(Page.class),
ClassName.get(dtoPackage, dto.name)))
.addAnnotation(
AnnotationSpec.builder(PostMapping.class)
.addMember("value", "$S", "/list")
.build())
.addParameter(
ParameterSpec.builder(
ClassName.get(CommonQuery.class), "request")
.addAnnotation(RequestBody.class)
.build())
.addStatement(
"""
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

@@ -9,5 +9,5 @@ import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface Anonymous {
boolean value() default true;
boolean value() default true;
}

View File

@@ -9,5 +9,5 @@ import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface OrgAdmin {
boolean value() default true;
boolean value() default true;
}

View File

@@ -9,5 +9,5 @@ import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface OrgScope {
boolean value() default true;
boolean value() default true;
}

View File

@@ -9,5 +9,5 @@ import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface SysAdmin {
boolean value() default true;
boolean value() default true;
}

View File

@@ -9,9 +9,9 @@ import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface SysLog {
String module() default "";
String module() default "";
String action() default "";
String action() default "";
String message() default "";
String message() default "";
}

View File

@@ -6,11 +6,12 @@ import cn.lihongjie.coal.ip.IpQueryService;
import cn.lihongjie.coal.session.SessionService;
import cn.lihongjie.coal.syslog.entity.SysLogEntity;
import cn.lihongjie.coal.syslog.service.SysLogService;
import jakarta.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.util.Arrays;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.aspectj.lang.ProceedingJoinPoint;
@@ -24,109 +25,113 @@ import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.lang.reflect.Method;
import java.util.Arrays;
@Aspect
@Component
@Slf4j
public class ControllerAop {
@Pointcut("execution (* cn.lihongjie.coal.*.controller.*.*(..))")
public void controllerMethods() {}
@Autowired SessionService sessionService;
@Autowired IpQueryService ipQueryService;
@Autowired SysLogService sysLogService;
@Autowired SessionService sessionService;
@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);
}
}
private void saveSysLog(SysLogEntity sysLogEntity, long end, long start) {
if (sysLogEntity != null) {
sysLogEntity.setTimeCost((int) (end - start));
sysLogService.save(sysLogEntity);
}
}
private static void updateSysLog(Throwable e, SysLogEntity sysLogEntity) {
if (sysLogEntity != null) {
sysLogEntity.setOptStatus("1");
sysLogEntity.setStacktrace(ExceptionUtils.getStackTrace(e));
}
}
@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();
private static void updateSysLog(Throwable e, SysLogEntity sysLogEntity) {
if (sysLogEntity != null) {
sysLogEntity.setOptStatus("1");
sysLogEntity.setStacktrace(ExceptionUtils.getStackTrace(e));
}
}
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;
@Pointcut("execution (* cn.lihongjie.coal.*.controller.*.*(..))")
public void controllerMethods() {}
private void logException(Throwable ex, ProceedingJoinPoint proceedingJoinPoint) {
HttpServletRequest request =
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
@SneakyThrows
@Around("controllerMethods()")
public Object call(ProceedingJoinPoint proceedingJoinPoint) {
Object[] args = proceedingJoinPoint.getArgs();
Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod();
Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod();
HttpServletRequest request =
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
.getRequest();
log.info(
"接口调用异常: {}\nurl:{} {}\nmethod: {}\nargs: {}",
ex.getMessage() == null ? "no message" : ex.getMessage(),
request.getMethod(),
request.getRequestURL(),
method,
Arrays.toString(args),
ex);
long start = System.currentTimeMillis();
SysLogEntity sysLogEntity = createSysLog(method, request);
try {
request.setAttribute("__logged", true);
}
return proceedingJoinPoint.proceed();
} catch (Throwable e) {
logException(e, proceedingJoinPoint);
updateSysLog(e, sysLogEntity);
throw e;
} finally {
saveSysLog(sysLogEntity, System.currentTimeMillis(), start);
}
}
private void saveSysLog(SysLogEntity sysLogEntity, long end, long start) {
if (sysLogEntity != null) {
sysLogEntity.setTimeCost((int) (end - start));
sysLogService.save(sysLogEntity);
}
}
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;
}
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

@@ -3,11 +3,13 @@ package cn.lihongjie.coal.aop;
import cn.lihongjie.coal.annotation.OrgScope;
import cn.lihongjie.coal.common.Ctx;
import cn.lihongjie.coal.exception.BizException;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import java.lang.reflect.Method;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
@@ -19,68 +21,69 @@ import org.hibernate.Session;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
@Aspect
@Component
@Slf4j
@Order
public class OrgScopeAop {
@PersistenceContext EntityManager entityManager;
private static final ThreadLocal<Boolean> orgScope = new ThreadLocal<>();
@PersistenceContext EntityManager entityManager;
private static ThreadLocal<Boolean> orgScope = new ThreadLocal<>();
@SneakyThrows
@Around(
value =
"@annotation(cn.lihongjie.coal.annotation.OrgScope) || @within(cn.lihongjie.coal.annotation.OrgScope)")
public Object beforeOrgScope(ProceedingJoinPoint pjp) {
@SneakyThrows
@Around(
value =
"@annotation(cn.lihongjie.coal.annotation.OrgScope) || @within(cn.lihongjie.coal.annotation.OrgScope)")
public Object beforeOrgScope(ProceedingJoinPoint pjp) {
Method method = ((MethodSignature) pjp.getSignature()).getMethod();
OrgScope annotation = method.getAnnotation(OrgScope.class);
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 (annotation == null) {
annotation = method.getDeclaringClass().getAnnotation(OrgScope.class);
}
if (session.getEnabledFilter("orgFilter") == null) {
if (annotation != null) {
boolean enabled = annotation.value();
Filter orgFilter = session.enableFilter("orgFilter");
Session session = entityManager.unwrap(Session.class);
orgFilter.setParameter("organizationId", Ctx.currentUser().getOrganizationId());
} else {
log.debug("当前session {} orgFilter已经启用, 忽略....", session.toString());
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);
}
} else {
if (session.getEnabledFilter("orgFilter") != null) {
session.disableFilter("orgFilter");
} else {
log.debug("当前session {} orgFilter已经禁用, 忽略....", session);
}
}
}
} else {
return pjp.proceed();
}
if (session.getEnabledFilter("orgFilter") != null) {
@Before(value = "@annotation(org.springframework.transaction.annotation.Transactional))")
public void beforeTransactionMethod() {
session.disableFilter("orgFilter");
if (orgScope.get() != null) {
} else {
log.debug("当前session {} orgFilter已经禁用, 忽略....", session.toString());
Session session = entityManager.unwrap(Session.class);
}
}
}
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

@@ -1,6 +1,7 @@
package cn.lihongjie.coal.base.controller;
import cn.lihongjie.coal.annotation.OrgScope;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RestController;

View File

@@ -1,30 +1,31 @@
package cn.lihongjie.coal.base.dao;
import jakarta.persistence.criteria.Path;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.NoRepositoryBean;
import java.util.List;
@NoRepositoryBean
public interface BaseRepository<T> extends JpaRepository<T, String>, JpaSpecificationExecutor<T> {
public default T get(String id) {
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 {
default List<T> findByOrganizationId(String organizationId) {
return findAll(
(root, query, cb) -> {
try {
Path<Object> path = root.get("organizationId");
return cb.equal(path, organizationId);
} 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,23 +1,24 @@
package cn.lihongjie.coal.base.dto;
import java.time.LocalDateTime;
import lombok.Getter;
import lombok.Setter;
import java.time.LocalDateTime;
@Getter
@Setter
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

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

File diff suppressed because it is too large Load Diff

View File

@@ -1,29 +1,32 @@
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.Arrays;
import java.util.Collections;
import java.util.List;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@Data
public class IdRequest {
private String id;
private List<String> ids;
private String id;
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 {
if (StringUtils.isEmpty(id)) {
return ids;
} else if (CollectionUtils.isEmpty(ids)) {
return Collections.singletonList(id);
} else {
ArrayList<String> dup = new ArrayList<>(ids);
dup.add(id);
return dup;
ArrayList<String> dup = new ArrayList<>(ids);
dup.add(id);
return dup;
}
}
}
}

View File

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

View File

@@ -2,50 +2,51 @@ package cn.lihongjie.coal.base.dto;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import lombok.Data;
@Data
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)
private Integer pageNo;
@JsonInclude(Include.NON_NULL)
private Integer pageNo;
@JsonInclude(Include.NON_NULL)
private Integer pageSize;
@JsonInclude(Include.NON_NULL)
private Integer pageSize;
@JsonInclude(Include.NON_NULL)
private Integer totalPage;
@JsonInclude(Include.NON_NULL)
private Integer totalPage;
@JsonInclude(Include.NON_NULL)
private Integer totalCount;
@JsonInclude(Include.NON_NULL)
private Integer totalCount;
public R(T data, String code, String msg) {
this.data = data;
this.code = code;
this.msg = msg;
}
public R(T data, String code, String msg) {
this.data = data;
this.code = code;
this.msg = msg;
}
public R() {}
public R() {}
public static <T> R<T> success() {
return success(null);
}
public static <T> R<T> success() {
return success(null);
}
public static <T> R<T> success(T data) {
return create(data, "ok", "");
}
public static <T> R<T> success(T data) {
return create(data, "ok", "");
}
public static <T> R<T> fail(String code, String msg) {
return create(null, code, msg);
}
public static <T> R<T> fail(String code, String msg) {
return create(null, code, msg);
}
public static <T> R<T> create(T data, String code, String msg) {
public static <T> R<T> create(T data, String code, String msg) {
return new R<>(data, code, msg);
}
return new R<>(data, code, msg);
}
}

View File

@@ -5,159 +5,163 @@ import cn.lihongjie.coal.base.entity.CommonEntity;
import cn.lihongjie.coal.common.ReflectUtils;
import cn.lihongjie.coal.dictionary.dto.DictionaryItemDto;
import cn.lihongjie.coal.dictionary.entity.DictionaryItemEntity;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
@Data
@AllArgsConstructor
@NoArgsConstructor
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);
} else {
ans = buildList0(Arrays.asList(object));
ans = buildList0(Collections.singletonList(object));
}
if (flatten) {
ans = flatten(ans);
}
return ans;
}
if (flatten) {
ans = flatten(ans);
}
return ans;
}
private static List<TreeDto> flatten(List<TreeDto> ans) {
private static List<TreeDto> flatten(List<TreeDto> ans) {
return ans.stream()
.flatMap(
x -> {
if (x == null) {
return Stream.empty();
}
return ans.stream()
.flatMap(
x -> {
if (x == null) {
return Stream.empty();
}
if (x.getChildren() != null) {
if (x.getChildren() != null) {
return Stream.concat(Stream.of(x), flatten(x.getChildren()).stream());
} else {
return Stream.of(x);
}
})
.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;
return Stream.concat(
Stream.of(x), flatten(x.getChildren()).stream());
} else {
return Stream.of(x);
}
})
.toList();
}
TreeDto dto = new TreeDto();
private static List<TreeDto> buildList0(Iterable<?> object) {
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 (x instanceof TreeDto) {
return ((TreeDto) x).getChildren().stream().map(TreeDto::buildTree).toList();
return StreamSupport.stream(object.spliterator(), false).map(x -> buildTree(x)).toList();
}
Object c = ReflectUtils.getFieldValue(x, "children");
public static TreeDto buildTree(Object x) {
if (c == null) {
return new ArrayList<>();
if (x == null) {
return null;
}
TreeDto dto = new TreeDto();
dto.setId(getId(x));
dto.setName(getName(x));
dto.setCode(getCode(x));
dto.setChildren(getChildren(x));
return dto;
}
if (c instanceof Iterable<?>) {
return buildList0((Iterable<?>) c);
private static List<TreeDto> getChildren(Object x) {
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(List.of(c));
}
return buildList0(Arrays.asList(c));
}
private static String getCode(Object x) {
if (x instanceof CommonEntity) {
return ((CommonEntity) x).getCode();
}
private static String getCode(Object x) {
if (x instanceof CommonEntity) {
return ((CommonEntity) x).getCode();
if (x instanceof CommonDto) {
return ((CommonDto) x).getCode();
}
if (x instanceof TreeDto) {
return ((TreeDto) x).getCode();
}
return ReflectUtils.getFieldValue(x, "code") + "";
}
if (x instanceof CommonDto) {
return ((CommonDto) x).getCode();
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") + "";
}
if (x instanceof TreeDto) {
return ((TreeDto) x).getCode();
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") + "";
}
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,60 +1,64 @@
package cn.lihongjie.coal.base.entity;
import cn.lihongjie.coal.common.Ctx;
import jakarta.persistence.*;
import java.time.LocalDateTime;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.*;
import java.time.LocalDateTime;
@MappedSuperclass
@Getter
@Setter
@DynamicUpdate
public class BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private String id;
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private String id;
@Comment("创建用户ID")
private String createUserId;
@Comment("创建用户ID")
private String createUserId;
@Formula("(select tu.name from t_user tu where tu.id = create_user_id)")
private String createUserName;
@Formula("(select tu.name from t_user tu where tu.id = create_user_id)")
private String createUserName;
@Comment("创建时间")
@CreationTimestamp(source = SourceType.VM)
private LocalDateTime createTime;
@Comment("创建时间")
@CreationTimestamp(source = SourceType.VM)
private LocalDateTime createTime;
@Comment("更新用户ID")
private String updateUserId;
@Comment("更新用户ID")
private String updateUserId;
@Formula("((select tu.name from t_user tu where tu.id = create_user_id))")
private String updateUserName;
@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;
@Comment("更新时间")
@UpdateTimestamp(source = SourceType.VM)
private LocalDateTime updateTime;
@PrePersist
public void prePersist() {
if (StringUtils.isEmpty(this.createUserId)) {
@PrePersist
public void prePersist() {
if (StringUtils.isEmpty(this.createUserId)) {
this.createUserId = Ctx.isLoggedIn() ? Ctx.getUserId() : "";
this.createUserId = Ctx.isLoggedIn() ? Ctx.getUserId() : "";
}
if (this.createTime == null) {
this.createTime = LocalDateTime.now();
}
}
if (this.createTime == null) {
this.createTime = LocalDateTime.now();
@PreUpdate
public void preUpdate() {
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,44 +1,47 @@
package cn.lihongjie.coal.base.entity;
import jakarta.persistence.MappedSuperclass;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Comment;
import java.util.Objects;
@MappedSuperclass
@Getter
@Setter
public class CommonEntity extends BaseEntity {
@Comment("名称")
private String name;
@Comment("名称")
private String name;
@Comment("编码")
private String code;
@Comment("编码")
private String code;
@Comment("备注")
private String remarks;
@Comment("备注")
private String remarks;
@Comment("排序键")
private Integer sortKey;
@Comment("排序键")
private Integer sortKey;
@Comment("常用状态 0 禁用 1 启用")
private Integer status;
@Comment("常用状态 0 禁用 1 启用")
private Integer status;
public boolean isDisabled() {
return Objects.equals(status, 0);
}
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 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();
}
@Override
public void preUpdate() {
this.status = this.status == null ? 1 : this.status;
super.preUpdate();
}
}

View File

@@ -1,9 +1,12 @@
package cn.lihongjie.coal.base.entity;
import cn.lihongjie.coal.common.Ctx;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
@MappedSuperclass
@@ -11,20 +14,20 @@ import org.apache.commons.lang3.StringUtils;
@Setter
public class OrgBaseEntity extends BaseEntity {
private String organizationId;
private String organizationId;
@Override
public void prePersist() {
if (StringUtils.isEmpty(organizationId)) {
@Override
public void prePersist() {
if (StringUtils.isEmpty(organizationId)) {
this.organizationId =
Ctx.isLoggedIn() ? Ctx.currentUser().getOrganizationId() : organizationId;
this.organizationId =
Ctx.isLoggedIn() ? Ctx.currentUser().getOrganizationId() : organizationId;
}
super.prePersist();
}
super.prePersist();
}
@Override
public void preUpdate() {
super.preUpdate();
}
@Override
public void preUpdate() {
super.preUpdate();
}
}

View File

@@ -1,9 +1,12 @@
package cn.lihongjie.coal.base.entity;
import cn.lihongjie.coal.common.Ctx;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.Filter;
import org.hibernate.annotations.FilterDef;
@@ -16,20 +19,20 @@ import org.hibernate.annotations.ParamDef;
@Filter(name = "orgFilter", condition = "organization_id = :organizationId")
public class OrgCommonEntity extends CommonEntity {
private String organizationId;
private String organizationId;
@Override
public void prePersist() {
if (StringUtils.isEmpty(organizationId)) {
@Override
public void prePersist() {
if (StringUtils.isEmpty(organizationId)) {
this.organizationId =
Ctx.isLoggedIn() ? Ctx.currentUser().getOrganizationId() : organizationId;
this.organizationId =
Ctx.isLoggedIn() ? Ctx.currentUser().getOrganizationId() : organizationId;
}
super.prePersist();
}
super.prePersist();
}
@Override
public void preUpdate() {
super.preUpdate();
}
@Override
public void preUpdate() {
super.preUpdate();
}
}

View File

@@ -3,13 +3,13 @@ package cn.lihongjie.coal.base.mapper;
import org.mapstruct.MappingTarget;
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

@@ -13,150 +13,151 @@ import cn.lihongjie.coal.script.entity.ScriptEntity;
import cn.lihongjie.coal.supplier.entity.SupplierEntity;
import cn.lihongjie.coal.syslog.entity.SysLogEntity;
import cn.lihongjie.coal.user.entity.UserEntity;
import org.apache.commons.lang3.StringUtils;
import org.mapstruct.Mapper;
@Mapper(componentModel = "spring")
public interface CommonMapper {
public default Integer toInt(String s) {
try {
default Integer toInt(String s) {
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) {
default UserEntity createUser(String id) {
if (StringUtils.isEmpty(id)) {
return null;
if (StringUtils.isEmpty(id)) {
return null;
}
UserEntity user = new UserEntity();
user.setId(id);
return user;
}
UserEntity user = new UserEntity();
user.setId(id);
default DictionaryEntity createDictionary(String id) {
return user;
}
public default DictionaryEntity createDictionary(String id) {
if (StringUtils.isEmpty(id)) {
return null;
if (StringUtils.isEmpty(id)) {
return null;
}
DictionaryEntity e = new DictionaryEntity();
e.setId(id);
return e;
}
DictionaryEntity e = new DictionaryEntity();
e.setId(id);
return e;
}
public default DictionaryItemEntity createDictionaryItem(String id) {
default DictionaryItemEntity createDictionaryItem(String id) {
if (StringUtils.isEmpty(id)) {
return null;
if (StringUtils.isEmpty(id)) {
return null;
}
DictionaryItemEntity e = new DictionaryItemEntity();
e.setId(id);
return e;
}
DictionaryItemEntity e = new DictionaryItemEntity();
e.setId(id);
return e;
}
public default SysLogEntity createOperat(String id) {
default SysLogEntity createOperat(String id) {
if (StringUtils.isEmpty(id)) {
return null;
if (StringUtils.isEmpty(id)) {
return null;
}
SysLogEntity e = new SysLogEntity();
e.setId(id);
return e;
}
SysLogEntity e = new SysLogEntity();
e.setId(id);
return e;
}
public default OrganizationEntity createOrganization(String id) {
default OrganizationEntity createOrganization(String id) {
if (StringUtils.isEmpty(id)) {
return null;
if (StringUtils.isEmpty(id)) {
return null;
}
OrganizationEntity e = new OrganizationEntity();
e.setId(id);
return e;
}
OrganizationEntity e = new OrganizationEntity();
e.setId(id);
return e;
}
public default PermissionEntity createPermission(String id) {
default PermissionEntity createPermission(String id) {
if (StringUtils.isEmpty(id)) {
return null;
if (StringUtils.isEmpty(id)) {
return null;
}
PermissionEntity e = new PermissionEntity();
e.setId(id);
return e;
}
PermissionEntity e = new PermissionEntity();
e.setId(id);
return e;
}
public default ResourceEntity createResource(String id) {
default ResourceEntity createResource(String id) {
if (StringUtils.isEmpty(id)) {
return null;
if (StringUtils.isEmpty(id)) {
return null;
}
ResourceEntity e = new ResourceEntity();
e.setId(id);
return e;
}
ResourceEntity e = new ResourceEntity();
e.setId(id);
return e;
}
public default RoleEntity createRole(String id) {
default RoleEntity createRole(String id) {
if (StringUtils.isEmpty(id)) {
if (StringUtils.isEmpty(id)) {
return null;
return null;
}
RoleEntity e = new RoleEntity();
e.setId(id);
return e;
}
RoleEntity e = new RoleEntity();
e.setId(id);
return e;
}
public default ScriptEntity createScript(String id) {
default ScriptEntity createScript(String id) {
if (StringUtils.isEmpty(id)) {
if (StringUtils.isEmpty(id)) {
return null;
return null;
}
ScriptEntity e = new ScriptEntity();
e.setId(id);
return e;
}
ScriptEntity e = new ScriptEntity();
e.setId(id);
return e;
}
public default SupplierEntity createSupplier(String id) {
default SupplierEntity createSupplier(String id) {
if (StringUtils.isEmpty(id)) {
if (StringUtils.isEmpty(id)) {
return null;
return null;
}
SupplierEntity e = new SupplierEntity();
e.setId(id);
return e;
}
SupplierEntity e = new SupplierEntity();
e.setId(id);
return e;
}
public default CoalInfoEntity createCoalInfo(String id) {
default CoalInfoEntity createCoalInfo(String id) {
if (StringUtils.isEmpty(id)) {
if (StringUtils.isEmpty(id)) {
return null;
return null;
}
CoalInfoEntity e = new CoalInfoEntity();
e.setId(id);
return e;
}
CoalInfoEntity e = new CoalInfoEntity();
e.setId(id);
return e;
}
public default String toString(Object o) {
default String toString(Object o) {
if (o == null) {
return null;
} else if (o instanceof String) {
return ((String) o);
} else if (o instanceof BaseEntity) {
return ((BaseEntity) o).getId();
if (o == null) {
return null;
} else if (o instanceof String) {
return ((String) o);
} else if (o instanceof BaseEntity) {
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,52 +2,54 @@ package cn.lihongjie.coal.base.service;
import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.base.entity.BaseEntity;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import java.util.List;
public abstract class BaseService<
Entity extends BaseEntity, Repository extends BaseRepository<Entity>> {
Entity extends BaseEntity, Repository extends BaseRepository<Entity>> {
@Autowired Repository dao;
@Autowired Repository dao;
public Entity get(String id) {
public Entity get(String id) {
return dao.get(id);
}
return dao.get(id);
}
public void save(Entity entity) {
public void save(Entity entity) {
dao.save(entity);
}
dao.save(entity);
}
public void delete(String id) {
dao.deleteById(id);
}
public void delete(String id) {
dao.deleteById(id);
}
public void delete(List<String> id) {
dao.deleteAllById(id);
}
public void delete(List<String> id) {
dao.deleteAllById(id);
}
public Page<Entity> findAll(Specification<Entity> spec, Pageable page) {
return dao.findAll(spec, page);
}
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(Specification<Entity> spec) {
return dao.findAll(spec);
}
public List<Entity> findAll() {
return dao.findAll();
}
public List<Entity> findAll() {
return dao.findAll();
}
public Long count(Specification<Entity> spec) {
return dao.count(spec);
}
public Long count(Specification<Entity> spec) {
return dao.count(spec);
}
public Long count() {
return dao.count();
}
public Long count() {
return dao.count();
}
}

View File

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

View File

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

View File

@@ -5,7 +5,7 @@ import lombok.Data;
@Data
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
public class CoalParameterDef {
private String code;
private String name;
private String desc;
private Integer status;
private Integer order;
private String code;
private String name;
private String desc;
private Integer status;
private Integer order;
}

View File

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

View File

@@ -3,11 +3,21 @@ package cn.lihongjie.coal.coal;
import cn.lihongjie.coal.coalBlend.dto.CoalBlendRequest;
import cn.lihongjie.coal.coalBlend.dto.CoalBlendResult;
import cn.lihongjie.coal.exception.BizException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.ortools.Loader;
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.math.BigDecimal;
import java.math.RoundingMode;
@@ -15,338 +25,342 @@ import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
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
@Service
public class CoalService {
/**
* 配煤
*
* @return
*/
public CoalBlendResult blend(CoalBlendRequest request) {
private static List<IntVar> createPercentVars(CoalBlendRequest request, CpModel model) {
int index = 0;
if (CollectionUtils.isEmpty(request.getCoals())) {
throw new BizException("煤不能为空");
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;
}
if (CollectionUtils.isEmpty(request.getConstraints())) {
throw new BizException("参数配置不能为空");
}
/**
* 配煤
*
* @return
*/
public CoalBlendResult blend(CoalBlendRequest request) {
Loader.loadNativeLibraries();
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);
// 开始求最优解
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);
if (CollectionUtils.isEmpty(request.getCoals())) {
throw new BizException("煤不能为空");
}
String validate = model.validate();
log.info(validate);
if (CollectionUtils.isEmpty(request.getConstraints())) {
throw new BizException("参数配置不能为空");
}
} else {
log.warn("无法求解: " + status);
}
}
Loader.loadNativeLibraries();
CoalBlendResult result = new CoalBlendResult();
// 记录结果
CpModel model = new CpModel();
//
cpSolver.getParameters().setEnumerateAllSolutions(true);
CpSolverStatus solverStatus =
cpSolver.solve(
model,
new CpSolverSolutionCallback() {
@Override
public void onSolutionCallback() {
List<IntVar> vars = createPercentVars(request, model);
CoalInfo solution = new CoalInfo();
List<Long> gcdVals = new ArrayList<>();
// 添加各种约束条件
addConstrains(request, model, vars);
solution.setPercents(new ArrayList<>());
solution.setParameters(new ArrayList<>());
for (int i = 0; i < vars.size(); i++) {
// 初始化求解器
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);
long percent = this.value(vars.get(i));
// 开始求最优解
CoalInfo coal = request.getCoals().get(i);
// 累加
try {
List<CoalConstraint> sorted =
request.getConstraints().stream()
.filter(x -> x.getPriority() != null)
.sorted(Comparator.comparing(CoalConstraint::getPriority))
.toList();
acc(solution, percent, coal);
} catch (Exception e) {
e.printStackTrace();
}
for (CoalConstraint constraint : sorted) {
CoalPercent e = new CoalPercent();
e.setId(coal.getId());
e.setName(coal.getName());
e.setPercent(percent);
if (CollectionUtils.isNotEmpty(gcdVals)) {
e.setPercent2(gcdVals.get(i));
}
solution.getPercents().add(e);
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);
round(solution);
result.getCoals().add(solution);
}
});
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 void sortAndSelect(CoalBlendRequest request, CoalBlendResult result) {
List<CoalConstraint> list =
request.getConstraints().stream()
.filter(x -> x.getPriority() != null)
.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());
} else {
log.warn("无法求解: " + status);
}
}
}
// 记录结果
//
cpSolver.getParameters().setEnumerateAllSolutions(true);
CpSolverStatus solverStatus =
cpSolver.solve(
model,
new CpSolverSolutionCallback() {
@Override
public void onSolutionCallback() {
CoalInfo solution = new CoalInfo();
List<Long> gcdVals = new ArrayList<>();
solution.setPercents(new ArrayList<>());
solution.setParameters(new ArrayList<>());
for (int i = 0; i < vars.size(); i++) {
long percent = this.value(vars.get(i));
CoalInfo coal = request.getCoals().get(i);
// 累加
try {
acc(solution, percent, coal);
} catch (Exception e) {
e.printStackTrace();
}
CoalPercent e = new CoalPercent();
e.setId(coal.getId());
e.setName(coal.getName());
e.setPercent(percent);
if (CollectionUtils.isNotEmpty(gcdVals)) {
e.setPercent2(gcdVals.get(i));
}
solution.getPercents().add(e);
}
// 四舍五入
round(solution);
result.getCoals().add(solution);
}
});
sortAndSelect(request, result);
return result;
}
result.setCoals(
result.getCoals().stream()
.sorted(c)
.limit(request.getCount())
.collect(Collectors.toList()));
result.getCoals().forEach(x -> x.calPercent2());
}
private void sortAndSelect(CoalBlendRequest request, CoalBlendResult result) {
private void round(CoalInfo solution) {
List<CoalConstraint> list =
request.getConstraints().stream()
.filter(x -> x.getPriority() != null)
.sorted(Comparator.comparing(x -> x.getPriority()))
.collect(Collectors.toList());
solution
.getParameters()
.forEach(
x ->
x.setValue(
x.getValue() == null
? x.getValue()
: BigDecimal.valueOf(x.getValue())
.setScale(2, RoundingMode.HALF_UP)
.doubleValue()));
}
Comparator<CoalInfo> c = Comparator.comparing(x -> 1);
if (!list.isEmpty()) {
private void acc(CoalInfo solution, long percent, CoalInfo coal) {
for (CoalConstraint constraint : list) {
for (CoalParameter parameter : coal.getParameters()) {
if (constraint.getOrder() == null || constraint.getOrder() == 1) {
c =
c.thenComparing(
Comparator.comparing(
x -> x.getParamVal(constraint.getCode())));
} else {
boolean found = false;
for (CoalParameter solutionParameter : solution.getParameters()) {
if (StringUtils.equalsIgnoreCase(parameter.getCode(), solutionParameter.getCode())) {
solutionParameter.setValue(
solutionParameter.getValue() + (parameter.getValue() * percent / 100.0));
found = true;
break;
c =
c.thenComparing(
Comparator.<CoalInfo, Double>comparing(
x -> x.getParamVal(constraint.getCode()))
.reversed());
}
}
}
}
result.setCoals(
result.getCoals().stream()
.sorted(c)
.limit(request.getCount())
.collect(Collectors.toList()));
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());
result.getCoals().forEach(x -> x.calPercent2());
}
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()
: BigDecimal.valueOf(x.getValue())
.setScale(2, RoundingMode.HALF_UP)
.doubleValue()));
}
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;
private void acc(CoalInfo solution, long percent, CoalInfo coal) {
for (CoalParameter parameter : coal.getParameters()) {
if (StringUtils.equalsIgnoreCase(parameter.getCode(), constrain.getCode())) {
boolean found = false;
paramsOfEachCoal[index++] = (long) (parameter.getValue() * 100);
found = true;
break;
}
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);
}
}
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;
}
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()) {
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

@@ -8,7 +8,9 @@ import cn.lihongjie.coal.coalAnalysis.dto.CoalAnalysisDto;
import cn.lihongjie.coal.coalAnalysis.dto.CreateCoalAnalysisDto;
import cn.lihongjie.coal.coalAnalysis.dto.UpdateCoalAnalysisDto;
import cn.lihongjie.coal.coalAnalysis.service.CoalAnalysisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
@@ -22,36 +24,36 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j
@OrgScope
public class CoalAnalysisController {
@Autowired private CoalAnalysisService service;
@Autowired private CoalAnalysisService service;
@PostMapping("/create")
public CoalAnalysisDto create(@RequestBody CreateCoalAnalysisDto request) {
return this.service.create(request);
}
@PostMapping("/create")
public CoalAnalysisDto create(@RequestBody CreateCoalAnalysisDto request) {
return this.service.create(request);
}
@PostMapping("/calculate")
public CoalAnalysisDto calculate(@RequestBody CoalAnalysisDto request) {
return this.service.calculate(request);
}
@PostMapping("/calculate")
public CoalAnalysisDto calculate(@RequestBody CoalAnalysisDto request) {
return this.service.calculate(request);
}
@PostMapping("/update")
public CoalAnalysisDto update(@RequestBody UpdateCoalAnalysisDto request) {
return this.service.update(request);
}
@PostMapping("/update")
public CoalAnalysisDto update(@RequestBody UpdateCoalAnalysisDto request) {
return this.service.update(request);
}
@PostMapping("/delete")
public Object delete(@RequestBody IdRequest request) {
this.service.delete(request);
return true;
}
@PostMapping("/delete")
public Object delete(@RequestBody IdRequest request) {
this.service.delete(request);
return true;
}
@PostMapping("/getById")
public CoalAnalysisDto getById(@RequestBody String request) {
return this.service.getById(request);
}
@PostMapping("/getById")
public CoalAnalysisDto getById(@RequestBody String request) {
return this.service.getById(request);
}
@PostMapping("/list")
public Page<CoalAnalysisDto> list(@RequestBody CommonQuery request) {
return this.service.list(request);
}
@PostMapping("/list")
public Page<CoalAnalysisDto> list(@RequestBody CommonQuery request) {
return this.service.list(request);
}
}

View File

@@ -2,146 +2,150 @@ package cn.lihongjie.coal.coalAnalysis.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import cn.lihongjie.coal.coalInfo.entity.CoalInfoEntity;
import jakarta.validation.constraints.DecimalMin;
import lombok.Data;
import org.hibernate.annotations.Comment;
import java.util.HashMap;
import java.util.Map;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
public class CoalAnalysisDto extends OrgCommonDto {
@Comment("关联的煤源信息")
private CoalInfoEntity coalInfo;
@Comment("关联的煤源信息")
private CoalInfoEntity coalInfo;
@Comment("参数 1 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param1;
@Comment("参数 1 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param1;
@Comment("参数 2 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 20 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param20;
public Map<String, Object> toMap() {
public Map<String, Object> toMap() {
HashMap<String, Object> ma = new HashMap<>();
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);
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;
}
return ma;
}
public void updateFromMap(Map<String, Object> map) {
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);
}
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

@@ -1,92 +1,95 @@
package cn.lihongjie.coal.coalAnalysis.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import jakarta.validation.constraints.DecimalMin;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
public class CreateCoalAnalysisDto extends OrgCommonDto {
@Comment("关联的煤源信息")
private String coalInfo;
@Comment("关联的煤源信息")
private String coalInfo;
@Comment("参数 1 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param1;
@Comment("参数 1 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param1;
@Comment("参数 2 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 20 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param20;
}

View File

@@ -1,92 +1,95 @@
package cn.lihongjie.coal.coalAnalysis.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import jakarta.validation.constraints.DecimalMin;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
public class UpdateCoalAnalysisDto extends OrgCommonDto {
@Comment("关联的煤源信息")
private String coalInfo;
@Comment("关联的煤源信息")
private String coalInfo;
@Comment("参数 1 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param1;
@Comment("参数 1 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param1;
@Comment("参数 2 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 20 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param20;
}

View File

@@ -2,96 +2,99 @@ package cn.lihongjie.coal.coalAnalysis.entity;
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import cn.lihongjie.coal.coalInfo.entity.CoalInfoEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.DecimalMin;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
@Entity
public class CoalAnalysisEntity extends OrgCommonEntity {
@ManyToOne
@Comment("关联的煤源信息")
private CoalInfoEntity coalInfo;
@ManyToOne
@Comment("关联的煤源信息")
private CoalInfoEntity coalInfo;
@Comment("参数 1 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param1;
@Comment("参数 1 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param1;
@Comment("参数 2 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 20 ")
@DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
private Double param20;
}

View File

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

View File

@@ -2,6 +2,7 @@ package cn.lihongjie.coal.coalAnalysis.repository;
import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.coalAnalysis.entity.CoalAnalysisEntity;
import org.springframework.stereotype.Repository;
@Repository

View File

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

View File

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

View File

@@ -2,12 +2,15 @@ package cn.lihongjie.coal.coalBlend.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import cn.lihongjie.coal.coalBlend.entity.CoalBlendEntity;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.hibernate.annotations.Comment;
import org.hibernate.validator.constraints.Range;
@@ -17,179 +20,179 @@ import org.hibernate.validator.constraints.Range;
@NoArgsConstructor
public class CoalBlendCoalInfoDto extends OrgCommonDto {
@NotEmpty(message = "煤名称不能为空")
private String name;
@NotEmpty(message = "煤名称不能为空")
private String name;
@Comment("比例最小值")
@Range(groups = CoalBlendEntity.BlendGroup.class, min = 0, max = 100, message = "无效的比例")
private Integer minPercent;
@Comment("比例最小值")
@Range(groups = CoalBlendEntity.BlendGroup.class, min = 0, max = 100, message = "无效的比例")
private Integer minPercent;
@Comment("比例最大值")
@Range(groups = CoalBlendEntity.BlendGroup.class, min = 0, max = 100, message = "无效的比例")
private Integer maxPercent;
@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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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);
}
@SneakyThrows
public Double getParam(String param) {
return (Double) FieldUtils.getField(this.getClass(), param, true).get(this);
}
}

View File

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

View File

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

View File

@@ -1,27 +1,29 @@
package cn.lihongjie.coal.coalBlend.dto;
import cn.lihongjie.coal.coal.CoalInfo;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import lombok.Data;
@Data
public class CoalBlendResult {
private long numBranches = 0;
private long numConflicts = 0;
private long wallTime = 0;
private long userTime = 0;
private List<CoalInfo> coals = new ArrayList<>();
private int totalCount;
private long numBranches = 0;
private long numConflicts = 0;
private long wallTime = 0;
private long userTime = 0;
private List<CoalInfo> coals = new ArrayList<>();
private int totalCount;
public String tableString() {
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;
}
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

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

View File

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

View File

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

View File

@@ -1,11 +1,14 @@
package cn.lihongjie.coal.coalBlend.entity;
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.NotEmpty;
import lombok.*;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.hibernate.annotations.Comment;
import org.hibernate.validator.constraints.Range;
@@ -17,181 +20,181 @@ import org.hibernate.validator.constraints.Range;
@Entity
public class CoalBlendCoalInfoEntity extends OrgCommonEntity {
@NotEmpty(message = "煤名称不能为空")
private String name;
@NotEmpty(message = "煤名称不能为空")
private String name;
@ManyToOne() private CoalBlendEntity coal;
@ManyToOne() private CoalBlendEntity coal;
@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 minPercent;
@Comment("比例最大值")
@Range(groups = CoalBlendEntity.BlendGroup.class, min = 0, max = 100, message = "无效的比例")
private Integer maxPercent;
@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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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);
}
@SneakyThrows
public Double getParam(String param) {
return (Double) FieldUtils.getField(this.getClass(), param, true).get(this);
}
}

View File

@@ -3,210 +3,212 @@ package cn.lihongjie.coal.coalBlend.entity;
import jakarta.persistence.Embeddable;
import jakarta.validation.constraints.DecimalMax;
import jakarta.validation.constraints.DecimalMin;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Embeddable
@Data
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最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param1Max;
@Comment("参数1最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
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最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param2Min;
@Comment("参数2最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param2Max;
@Comment("参数2最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param2Max;
@Comment("参数3最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param3Min;
@Comment("参数3最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param3Min;
@Comment("参数3最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param3Max;
@Comment("参数3最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param3Max;
@Comment("参数4最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param4Min;
@Comment("参数4最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param4Min;
@Comment("参数4最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param4Max;
@Comment("参数4最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param4Max;
@Comment("参数5最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param5Min;
@Comment("参数5最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param5Min;
@Comment("参数5最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param5Max;
@Comment("参数5最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param5Max;
@Comment("参数6最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param6Min;
@Comment("参数6最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param6Min;
@Comment("参数6最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param6Max;
@Comment("参数6最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param6Max;
@Comment("参数7最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param7Min;
@Comment("参数7最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param7Min;
@Comment("参数7最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param7Max;
@Comment("参数7最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param7Max;
@Comment("参数8最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param8Min;
@Comment("参数8最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param8Min;
@Comment("参数8最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param8Max;
@Comment("参数8最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param8Max;
@Comment("参数9最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param9Min;
@Comment("参数9最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param9Min;
@Comment("参数9最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param9Max;
@Comment("参数9最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param9Max;
@Comment("参数10最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param10Min;
@Comment("参数10最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param10Min;
@Comment("参数10最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param10Max;
@Comment("参数10最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param10Max;
@Comment("参数11最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param11Min;
@Comment("参数11最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param11Min;
@Comment("参数11最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param11Max;
@Comment("参数11最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param11Max;
@Comment("参数12最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param12Min;
@Comment("参数12最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param12Min;
@Comment("参数12最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param12Max;
@Comment("参数12最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param12Max;
@Comment("参数13最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param13Min;
@Comment("参数13最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param13Min;
@Comment("参数13最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param13Max;
@Comment("参数13最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param13Max;
@Comment("参数14最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param14Min;
@Comment("参数14最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param14Min;
@Comment("参数14最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param14Max;
@Comment("参数14最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param14Max;
@Comment("参数15最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param15Min;
@Comment("参数15最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param15Min;
@Comment("参数15最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param15Max;
@Comment("参数15最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param15Max;
@Comment("参数16最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param16Min;
@Comment("参数16最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param16Min;
@Comment("参数16最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param16Max;
@Comment("参数16最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param16Max;
@Comment("参数17最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param17Min;
@Comment("参数17最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param17Min;
@Comment("参数17最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param17Max;
@Comment("参数17最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param17Max;
@Comment("参数18最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param18Min;
@Comment("参数18最小值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param18Min;
@Comment("参数18最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param18Max;
@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 param19Min;
@Comment("参数19最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param19Max;
@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 param20Min;
@Comment("参数20最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param20Max;
@Comment("参数20最大值")
@DecimalMax(groups = CoalBlendEntity.BlendGroup.class, value = "10000", message = "最大值无效")
@DecimalMin(groups = CoalBlendEntity.BlendGroup.class, value = "0.1", message = "最小值无效")
private Double param20Max;
}

View File

@@ -1,16 +1,20 @@
package cn.lihongjie.coal.coalBlend.entity;
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.DecimalMin;
import lombok.*;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.hibernate.annotations.Comment;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import lombok.*;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.hibernate.annotations.Comment;
@Data
@AllArgsConstructor
@@ -19,182 +23,182 @@ import org.hibernate.annotations.Comment;
@Entity
public class CoalBlendResultInfoEntity extends OrgCommonEntity {
private String name;
private String name;
@ElementCollection private List<CoalPercentVo> percentInfos;
@ElementCollection private List<CoalPercentVo> percentInfos;
@ManyToOne private CoalBlendEntity coal;
@ManyToOne private CoalBlendEntity coal;
@Comment("参数 1 ")
@DecimalMin(
groups = CoalBlendEntity.BlendGroup.class,
value = "0.1",
inclusive = true,
message = "参数不能小于0.1")
private Double param1;
@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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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("参数 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);
}
@SneakyThrows
public Double getParam(String param) {
return (Double) FieldUtils.getField(this.getClass(), param, true).get(this);
}
public long getHashKey() {
public long getHashKey() {
return Arrays.hashCode(
this.getPercentInfos().stream()
.sorted(Comparator.comparing(x -> x.getPercent()))
.toArray(CoalPercentVo[]::new));
}
return Arrays.hashCode(
this.getPercentInfos().stream()
.sorted(Comparator.comparing(x -> x.getPercent()))
.toArray(CoalPercentVo[]::new));
}
}

View File

@@ -1,6 +1,6 @@
package cn.lihongjie.coal.coalBlend.entity;
public enum CoalBlendType {
TYPE1,
TYPE2
TYPE1,
TYPE2
}

View File

@@ -1,29 +1,31 @@
package cn.lihongjie.coal.coalBlend.entity;
import jakarta.persistence.Embeddable;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Embeddable
@Data
public class CoalParameterDefVo {
@Comment("名称")
private String name;
@Comment("名称")
private String name;
@Comment("编码")
private String code;
@Comment("编码")
private String code;
@Comment("备注")
private String remarks;
@Comment("备注")
private String remarks;
@Comment("备注")
private String parentName;
@Comment("备注")
private String parentName;
@Comment("排序键")
private Integer sortKey;
@Comment("排序键")
private Integer sortKey;
@Comment("常用状态 0 禁用 1 启用")
private Integer status;
@Comment("常用状态 0 禁用 1 启用")
private Integer status;
private String id;
private String id;
}

View File

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

View File

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

View File

@@ -2,6 +2,7 @@ package cn.lihongjie.coal.coalBlend.repository;
import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.coalBlend.entity.CoalBlendEntity;
import org.springframework.stereotype.Repository;
@Repository

View File

@@ -10,8 +10,11 @@ import cn.lihongjie.coal.coalBlend.entity.CoalBlendEntity;
import cn.lihongjie.coal.coalBlend.mapper.CoalBlendMapper;
import cn.lihongjie.coal.coalBlend.repository.CoalBlendRepository;
import cn.lihongjie.coal.coalWashingDailyAnalysis.mapper.RoundMapper;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.domain.Page;
@@ -24,73 +27,74 @@ import org.springframework.util.StopWatch;
@Slf4j
public class CoalBlendService extends BaseService<CoalBlendEntity, CoalBlendRepository> {
@Autowired CoalBlendRepository repository;
@Autowired CoalBlendRepository repository;
@Autowired CoalBlendMapper mapper;
@Autowired CoalBlendMapper mapper;
@Autowired ConversionService conversionService;
@Autowired RoundMapper roundMapper;
@PostConstruct
public void init() {}
@PostConstruct
public void init() {}
public CoalBlendDto create(CreateCoalBlendDto request) {
request.getCoals().forEach(x -> x.setId(null));
public CoalBlendDto create(CreateCoalBlendDto request) {
request.getCoals().forEach(x -> x.setId(null));
CoalBlendEntity entity = mapper.toEntity(request);
CoalBlendEntity entity = mapper.toEntity(request);
this.repository.save(entity);
return getById(entity.getId());
}
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 update(UpdateCoalBlendDto request) {
CoalBlendEntity entity = this.repository.get(request.getId());
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 CoalBlendDto getById(String id) {
public CoalBlendDto getById(String id) {
CoalBlendEntity entity = repository.get(id);
CoalBlendEntity entity = repository.get(id);
return mapper.toDto(entity);
}
return mapper.toDto(entity);
}
@Autowired ConversionService conversionService;
public Page<CoalBlendDto> list(CommonQuery query) {
public Page<CoalBlendDto> list(CommonQuery query) {
Page<CoalBlendEntity> page =
repository.findAll(
query.specification(conversionService),
PageRequest.of(
query.getPageNo(),
query.getPageSize(),
Sort.by(query.getOrders())));
Page<CoalBlendEntity> 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);
}
public CoalBlendDto blend(CreateCoalBlendDto dto) {
@Autowired RoundMapper roundMapper;
StopWatch stopWatch = new StopWatch();
public CoalBlendDto blend(CreateCoalBlendDto dto) {
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 stopWatch = new StopWatch();
stopWatch.stop();
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);
}
log.info(stopWatch.prettyPrint());
return roundMapper.round(blendDto);
}
}

View File

@@ -8,7 +8,9 @@ import cn.lihongjie.coal.coalInfo.dto.CoalInfoDto;
import cn.lihongjie.coal.coalInfo.dto.CreateCoalInfoDto;
import cn.lihongjie.coal.coalInfo.dto.UpdateCoalInfoDto;
import cn.lihongjie.coal.coalInfo.service.CoalInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
@@ -22,31 +24,31 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j
@OrgScope
public class CoalInfoController {
@Autowired private CoalInfoService service;
@Autowired private CoalInfoService service;
@PostMapping("/create")
public CoalInfoDto create(@RequestBody CreateCoalInfoDto request) {
return this.service.create(request);
}
@PostMapping("/create")
public CoalInfoDto create(@RequestBody CreateCoalInfoDto request) {
return this.service.create(request);
}
@PostMapping("/update")
public CoalInfoDto update(@RequestBody UpdateCoalInfoDto request) {
return this.service.update(request);
}
@PostMapping("/update")
public CoalInfoDto update(@RequestBody UpdateCoalInfoDto request) {
return this.service.update(request);
}
@PostMapping("/delete")
public Object delete(@RequestBody IdRequest request) {
this.service.delete(request);
return true;
}
@PostMapping("/delete")
public Object delete(@RequestBody IdRequest request) {
this.service.delete(request);
return true;
}
@PostMapping("/getById")
public CoalInfoDto getById(@RequestBody String request) {
return this.service.getById(request);
}
@PostMapping("/getById")
public CoalInfoDto getById(@RequestBody String request) {
return this.service.getById(request);
}
@PostMapping("/list")
public Page<CoalInfoDto> list(@RequestBody CommonQuery request) {
return this.service.list(request);
}
@PostMapping("/list")
public Page<CoalInfoDto> list(@RequestBody CommonQuery request) {
return this.service.list(request);
}
}

View File

@@ -1,20 +1,22 @@
package cn.lihongjie.coal.coalInfo.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
public class CoalInfoDto extends OrgCommonDto {
@Comment("供应商")
private String supplier;
@Comment("供应商")
private String supplier;
private String supplierName;
private String supplierName;
private String coalTypeName;
private String coalType;
private String coalTypeName;
private String coalType;
@Comment("初始报价")
private Double initPrice;
@Comment("初始报价")
private Double initPrice;
}

View File

@@ -1,17 +1,19 @@
package cn.lihongjie.coal.coalInfo.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
public class CreateCoalInfoDto extends OrgCommonDto {
@Comment("供应商")
private String supplier;
@Comment("供应商")
private String supplier;
private String coalType;
private String coalType;
@Comment("初始报价")
private Double initPrice;
@Comment("初始报价")
private Double initPrice;
}

View File

@@ -1,16 +1,18 @@
package cn.lihongjie.coal.coalInfo.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
public class UpdateCoalInfoDto extends OrgCommonDto {
@Comment("供应商")
private String supplier;
@Comment("供应商")
private String supplier;
private String coalType;
private String coalType;
@Comment("初始报价")
private Double initPrice;
@Comment("初始报价")
private Double initPrice;
}

View File

@@ -2,9 +2,12 @@ package cn.lihongjie.coal.coalInfo.entity;
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import cn.lihongjie.coal.supplier.entity.SupplierEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToOne;
import lombok.Data;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;
@@ -12,32 +15,32 @@ import org.hibernate.annotations.Formula;
@Entity
public class CoalInfoEntity extends OrgCommonEntity {
@ManyToOne
@Comment("供应商")
private SupplierEntity supplier;
@ManyToOne
@Comment("供应商")
private SupplierEntity supplier;
@Comment("煤源类型")
private String coalType;
@Comment("煤源类型")
private String coalType;
@Formula(
"(select i.name\n"
+ "from t_dictionary d,\n"
+ " t_dictionary_item i\n"
+ "where d.id = i.dictionary_id\n"
+ " and d.code = 'coal.type'\n"
+ " and i.code = coal_type)")
private String coalTypeName;
@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 = 'coal.type'\n"
+ " and i.code = coal_type)")
private String coalTypeName;
@Comment("初始报价")
private Double initPrice;
@Comment("初始报价")
private Double initPrice;
public String getSupplierName() {
public String getSupplierName() {
if (supplier != null) {
if (supplier != null) {
return supplier.getName();
} else {
return "";
return supplier.getName();
} else {
return "";
}
}
}
}

View File

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

View File

@@ -2,6 +2,7 @@ package cn.lihongjie.coal.coalInfo.repository;
import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.coalInfo.entity.CoalInfoEntity;
import org.springframework.stereotype.Repository;
@Repository

View File

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

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

View File

@@ -1,20 +1,22 @@
package cn.lihongjie.coal.coalParameterDef.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
public class CoalParameterDefDto extends OrgCommonDto {
@Comment("上级名称")
private String parentName;
@Comment("上级名称")
private String parentName;
@Comment("类型 0 手动输入 1 自动计算")
private String inputType;
@Comment("类型 0 手动输入 1 自动计算")
private String inputType;
private String inputTypeName;
private String inputTypeName;
@Comment("计算公式")
private String formula;
@Comment("计算公式")
private String formula;
}

View File

@@ -1,18 +1,20 @@
package cn.lihongjie.coal.coalParameterDef.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
public class CreateCoalParameterDefDto extends OrgCommonDto {
@Comment("上级名称")
private String parentName;
@Comment("上级名称")
private String parentName;
@Comment("类型 0 手动输入 1 自动计算")
private String inputType;
@Comment("类型 0 手动输入 1 自动计算")
private String inputType;
@Comment("计算公式")
private String formula;
@Comment("计算公式")
private String formula;
}

View File

@@ -1,18 +1,20 @@
package cn.lihongjie.coal.coalParameterDef.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
public class UpdateCoalParameterDefDto extends OrgCommonDto {
@Comment("上级名称")
private String parentName;
@Comment("上级名称")
private String parentName;
@Comment("类型 0 手动输入 1 自动计算")
private String inputType;
@Comment("类型 0 手动输入 1 自动计算")
private String inputType;
@Comment("计算公式")
private String formula;
@Comment("计算公式")
private String formula;
}

View File

@@ -1,8 +1,11 @@
package cn.lihongjie.coal.coalParameterDef.entity;
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import jakarta.persistence.Entity;
import lombok.Data;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;
@@ -10,30 +13,30 @@ import org.hibernate.annotations.Formula;
@Data
public class CoalParameterDefEntity extends OrgCommonEntity {
@Comment("上级名称")
private String parentName;
@Comment("上级名称")
private String parentName;
@Comment("类型 0 手动输入 1 自动计算")
private String inputType;
@Comment("类型 0 手动输入 1 自动计算")
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;
@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 formula;
@Comment("解析后的公式")
private String formula0;
@Comment("解析后的公式")
private String formula0;
@Comment("依赖的字段")
private String dependents;
@Comment("依赖的字段")
private String dependents;
@Comment("计算优先级")
private Integer priority;
@Comment("计算优先级")
private Integer priority;
}

View File

@@ -11,12 +11,12 @@ import org.mapstruct.MappingConstants;
import org.mapstruct.control.DeepClone;
@Mapper(
componentModel = MappingConstants.ComponentModel.SPRING,
uses = {CommonMapper.class},
mappingControl = DeepClone.class)
componentModel = MappingConstants.ComponentModel.SPRING,
uses = {CommonMapper.class},
mappingControl = DeepClone.class)
public interface CoalParameterDefMapper
extends BaseMapper<
CoalParameterDefEntity,
CoalParameterDefDto,
CreateCoalParameterDefDto,
UpdateCoalParameterDefDto> {}
extends BaseMapper<
CoalParameterDefEntity,
CoalParameterDefDto,
CreateCoalParameterDefDto,
UpdateCoalParameterDefDto> {}

View File

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

View File

@@ -12,16 +12,17 @@ import cn.lihongjie.coal.coalParameterDef.repository.CoalParameterDefRepository;
import cn.lihongjie.coal.common.Ctx;
import cn.lihongjie.coal.common.GroovyScriptUtils;
import cn.lihongjie.coal.organization.service.OrganizationService;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Splitter;
import jakarta.annotation.PostConstruct;
import java.io.InputStream;
import java.util.List;
import java.util.Optional;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jgrapht.graph.DefaultDirectedGraph;
import org.jgrapht.graph.DefaultEdge;
@@ -34,153 +35,167 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import java.io.InputStream;
import java.util.List;
import java.util.Optional;
@Service
@Slf4j
public class CoalParameterDefService
extends BaseService<CoalParameterDefEntity, CoalParameterDefRepository> {
extends BaseService<CoalParameterDefEntity, CoalParameterDefRepository> {
@Autowired CoalParameterDefRepository repository;
@Autowired CoalParameterDefRepository repository;
@Autowired CoalParameterDefMapper mapper;
@Autowired CoalParameterDefMapper mapper;
@Autowired ConversionService conversionService;
@Autowired OrganizationService organizationService;
@PostConstruct
public void init() {}
@PostConstruct
public void init() {}
public CoalParameterDefDto create(CreateCoalParameterDefDto request) {
public CoalParameterDefDto create(CreateCoalParameterDefDto request) {
CoalParameterDefEntity entity = mapper.toEntity(request);
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());
}
private void updateFormula(CoalParameterDefEntity entity) {
DefaultDirectedGraph<Object, DefaultEdge> graph = new DefaultDirectedGraph<>(DefaultEdge.class);
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(entity.getInputType(), "1")) {
GroovyScriptUtils.validate(entity.getFormula());
}
}
this.repository.save(entity);
updateFormula(entity);
return getById(entity.getId());
}
TopologicalOrderIterator<Object, DefaultEdge> iterator = new TopologicalOrderIterator<>(graph);
private void updateFormula(CoalParameterDefEntity entity) {
int order = 0;
while (iterator.hasNext()) {
Object next = (String) iterator.next();
DefaultDirectedGraph<Object, DefaultEdge> graph =
new DefaultDirectedGraph<>(DefaultEdge.class);
List<CoalParameterDefEntity> all =
this.repository.findByOrganizationId(entity.getOrganizationId());
for (CoalParameterDefEntity coalParameterDefEntity : all) {
String formula = entity.getFormula();
if (StringUtils.equalsIgnoreCase(coalParameterDefEntity.getCode(), next + "")) {
coalParameterDefEntity.setPriority(order++);
break;
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());
}
}
}
}
TopologicalOrderIterator<Object, DefaultEdge> iterator =
new TopologicalOrderIterator<>(graph);
int order = 0;
while (iterator.hasNext()) {
Object next = 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) {
CoalParameterDefEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
public CoalParameterDefDto update(UpdateCoalParameterDefDto request) {
CoalParameterDefEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
if (StringUtils.equalsIgnoreCase(entity.getInputType(), "1")) {
GroovyScriptUtils.validate(entity.getFormula());
}
if (StringUtils.equalsIgnoreCase(entity.getInputType(), "1")) {
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);
}
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);
}
type1.ifPresent(this::updateFormula);
}
public CoalParameterDefDto getById(String id) {
CoalParameterDefEntity entity = repository.get(id);
return mapper.toDto(entity);
}
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);
}
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

@@ -8,7 +8,9 @@ import cn.lihongjie.coal.coalPrice.dto.CoalPriceDto;
import cn.lihongjie.coal.coalPrice.dto.CreateCoalPriceDto;
import cn.lihongjie.coal.coalPrice.dto.UpdateCoalPriceDto;
import cn.lihongjie.coal.coalPrice.service.CoalPriceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
@@ -22,31 +24,31 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j
@OrgScope
public class CoalPriceController {
@Autowired private CoalPriceService service;
@Autowired private CoalPriceService service;
@PostMapping("/create")
public CoalPriceDto create(@RequestBody CreateCoalPriceDto request) {
return this.service.create(request);
}
@PostMapping("/create")
public CoalPriceDto create(@RequestBody CreateCoalPriceDto request) {
return this.service.create(request);
}
@PostMapping("/update")
public CoalPriceDto update(@RequestBody UpdateCoalPriceDto request) {
return this.service.update(request);
}
@PostMapping("/update")
public CoalPriceDto update(@RequestBody UpdateCoalPriceDto request) {
return this.service.update(request);
}
@PostMapping("/delete")
public Object delete(@RequestBody IdRequest request) {
this.service.delete(request);
return true;
}
@PostMapping("/delete")
public Object delete(@RequestBody IdRequest request) {
this.service.delete(request);
return true;
}
@PostMapping("/getById")
public CoalPriceDto getById(@RequestBody String request) {
return this.service.getById(request);
}
@PostMapping("/getById")
public CoalPriceDto getById(@RequestBody String request) {
return this.service.getById(request);
}
@PostMapping("/list")
public Page<CoalPriceDto> list(@RequestBody CommonQuery request) {
return this.service.list(request);
}
@PostMapping("/list")
public Page<CoalPriceDto> list(@RequestBody CommonQuery request) {
return this.service.list(request);
}
}

View File

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

View File

@@ -1,14 +1,16 @@
package cn.lihongjie.coal.coalPrice.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
public class CreateCoalPriceDto extends OrgCommonDto {
@Comment("煤源")
private String coalInfo;
@Comment("煤源")
private String coalInfo;
@Comment("价格")
private Double price;
@Comment("价格")
private Double price;
}

View File

@@ -1,14 +1,16 @@
package cn.lihongjie.coal.coalPrice.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
public class UpdateCoalPriceDto extends OrgCommonDto {
@Comment("煤源")
private String coalInfo;
@Comment("煤源")
private String coalInfo;
@Comment("价格")
private Double price;
@Comment("价格")
private Double price;
}

View File

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

View File

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

View File

@@ -2,6 +2,7 @@ package cn.lihongjie.coal.coalPrice.repository;
import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.coalPrice.entity.CoalPriceEntity;
import org.springframework.stereotype.Repository;
@Repository

View File

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

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

View File

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

View File

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

View File

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

View File

@@ -1,16 +1,20 @@
package cn.lihongjie.coal.coalWashingDailyAnalysis.entity;
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
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.LocalTime;
import java.util.ArrayList;
import java.util.Comparator;
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
@@ -18,261 +22,262 @@ import org.hibernate.annotations.Comment;
@Comment("洗煤报告表")
public class CoalWashingDailyAnalysisEntity extends OrgCommonEntity {
@Comment("日期")
private LocalDate date;
@Comment("日期")
private LocalDate date;
@ElementCollection
@Comment("用户手动录入的记录")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisItemVo> inputItems;
@ElementCollection
@Comment("用户手动录入的记录")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisItemVo> inputItems;
@ElementCollection
@Comment("连续平均值")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisItemVo> rollingAvgItems;
@ElementCollection
@Comment("连续平均值")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisItemVo> rollingAvgItems;
@Comment("目标大堆 灰")
private Double ddp1;
@Comment("目标大堆 灰")
private Double ddp1;
@Comment("目标大堆 硫")
private Double ddp2;
@Comment("目标大堆 硫")
private Double ddp2;
@Comment("目标大堆 挥发")
private Double ddp3;
@Comment("目标大堆 挥发")
private Double ddp3;
@Comment("目标大堆 粘结")
private Double ddp4;
@Comment("目标大堆 粘结")
private Double ddp4;
@Comment("目标大堆 备用")
private Double ddp5;
@Comment("目标大堆 备用")
private Double ddp5;
@Comment("产量初始值")
private Double initTotalNumber = 0.0;
@Comment("产量初始值")
private Double initTotalNumber = 0.0;
public void rollingAvg() {
public void rollingAvg() {
rollingAvgItems = new ArrayList<>();
rollingAvgItems = new ArrayList<>();
if (CollectionUtils.isEmpty(inputItems)) {
return;
}
inputItems.sort(
Comparator.comparing(x -> ObjectUtils.defaultIfNull(x.getTime(), LocalTime.MIN)));
inputItems.forEach(x -> x.calculate());
for (int i = 0; i < inputItems.size(); i++) {
List<CoalWashingDailyAnalysisItemVo> current = inputItems.subList(0, i + 1);
rollingAvgItems.add(rollingAvg(current));
}
}
private CoalWashingDailyAnalysisItemVo rollingAvg(List<CoalWashingDailyAnalysisItemVo> current) {
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 (CollectionUtils.isEmpty(inputItems)) {
return;
}
}
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());
}
}
inputItems.sort(
Comparator.comparing(x -> ObjectUtils.defaultIfNull(x.getTime(), LocalTime.MIN)));
inputItems.forEach(x -> x.calculate());
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());
}
for (int i = 0; i < inputItems.size(); i++) {
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());
}
List<CoalWashingDailyAnalysisItemVo> current = inputItems.subList(0, i + 1);
rollingAvgItems.add(rollingAvg(current));
}
}
return vo;
}
private CoalWashingDailyAnalysisItemVo rollingAvg(
List<CoalWashingDailyAnalysisItemVo> current) {
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

@@ -1,279 +1,284 @@
package cn.lihongjie.coal.coalWashingDailyAnalysis.entity;
import cn.lihongjie.coal.exception.BizException;
import io.vavr.collection.Stream;
import jakarta.persistence.Embeddable;
import java.time.LocalTime;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.With;
import org.hibernate.annotations.Comment;
import java.time.LocalTime;
import java.util.Objects;
@Data
@Embeddable
@NoArgsConstructor
@AllArgsConstructor
public class CoalWashingDailyAnalysisItemVo {
@Comment("时间")
private LocalTime time;
@Comment("时间")
private LocalTime time;
@Comment("产量")
@With
private Double totalNumber;
@Comment("产量")
@With
private Double totalNumber;
@Comment("成分0 比例")
private Double c0p0;
@Comment("成分0 比例")
private Double c0p0;
@Comment("成分0 灰")
private Double c0p1;
@Comment("成分0 灰")
private Double c0p1;
@Comment("成分0 硫")
private Double c0p2;
@Comment("成分0 硫")
private Double c0p2;
@Comment("成分1 比例")
private Double c1p0;
@Comment("成分1 比例")
private Double c1p0;
@Comment("成分1 灰")
private Double c1p1;
@Comment("成分1 灰")
private Double c1p1;
@Comment("成分1 硫")
private Double c1p2;
@Comment("成分1 硫")
private Double c1p2;
@Comment("成分2 比例")
private Double c2p0;
@Comment("成分2 比例")
private Double c2p0;
@Comment("成分2 灰")
private Double c2p1;
@Comment("成分2 灰")
private Double c2p1;
@Comment("成分2 硫")
private Double c2p2;
@Comment("成分2 硫")
private Double c2p2;
@Comment("成分3 比例")
private Double c3p0;
@Comment("成分3 比例")
private Double c3p0;
@Comment("成分3 灰")
private Double c3p1;
@Comment("成分3 灰")
private Double c3p1;
@Comment("成分3 硫")
private Double c3p2;
@Comment("成分3 硫")
private Double c3p2;
@Comment("成分4 比例")
private Double c4p0;
@Comment("成分4 比例")
private Double c4p0;
@Comment("成分4 灰")
private Double c4p1;
@Comment("成分4 灰")
private Double c4p1;
@Comment("成分4 硫")
private Double c4p2;
@Comment("成分4 硫")
private Double c4p2;
@Comment("成分5 比例")
private Double c5p0;
@Comment("成分5 比例")
private Double c5p0;
@Comment("成分5 灰")
private Double c5p1;
@Comment("成分5 灰")
private Double c5p1;
@Comment("成分5 硫")
private Double c5p2;
@Comment("成分5 硫")
private Double c5p2;
@Comment("成分6 比例")
private Double c6p0;
@Comment("成分6 比例")
private Double c6p0;
@Comment("成分6 灰")
private Double c6p1;
@Comment("成分6 灰")
private Double c6p1;
@Comment("成分6 硫")
private Double c6p2;
@Comment("成分6 硫")
private Double c6p2;
@Comment("成分7 比例")
private Double c7p0;
@Comment("成分7 比例")
private Double c7p0;
@Comment("成分7 灰")
private Double c7p1;
@Comment("成分7 灰")
private Double c7p1;
@Comment("成分7 硫")
private Double c7p2;
@Comment("成分7 硫")
private Double c7p2;
@Comment("成分8 比例")
private Double c8p0;
@Comment("成分8 比例")
private Double c8p0;
@Comment("成分8 灰")
private Double c8p1;
@Comment("成分8 灰")
private Double c8p1;
@Comment("成分8 硫")
private Double c8p2;
@Comment("成分8 硫")
private Double c8p2;
@Comment("成分9 比例")
private Double c9p0;
@Comment("成分9 比例")
private Double c9p0;
@Comment("成分9 灰")
private Double c9p1;
@Comment("成分9 灰")
private Double c9p1;
@Comment("成分9 硫")
private Double c9p2;
@Comment("成分9 硫")
private Double c9p2;
@Comment("用户输入 大堆 灰")
private Double ddp1;
@Comment("用户输入 大堆 灰")
private Double ddp1;
@Comment("用户输入 大堆 硫")
private Double ddp2;
@Comment("用户输入 大堆 硫")
private Double ddp2;
@Comment("用户输入 大堆 挥发")
private Double ddp3;
@Comment("用户输入 大堆 挥发")
private Double ddp3;
@Comment("用户输入 大堆 粘结")
private Double ddp4;
@Comment("用户输入 大堆 粘结")
private Double ddp4;
@Comment("用户输入 大堆 备用")
private Double ddp5;
@Comment("用户输入 大堆 备用")
private Double ddp5;
@Comment("用户输入 翻大堆 灰")
private Double fddp1;
@Comment("用户输入 翻大堆 灰")
private Double fddp1;
@Comment("用户输入 翻大堆 硫")
private Double fddp2;
@Comment("用户输入 翻大堆 硫")
private Double fddp2;
@Comment("用户输入 翻大堆 挥发")
private Double fddp3;
@Comment("用户输入 翻大堆 挥发")
private Double fddp3;
@Comment("用户输入 翻大堆 粘结")
private Double fddp4;
@Comment("用户输入 翻大堆 粘结")
private Double fddp4;
@Comment("用户输入 翻大堆 备用")
private Double fddp5;
@Comment("用户输入 翻大堆 备用")
private Double fddp5;
@Comment("系统计算 大堆 灰")
private Double sysDdp1;
@Comment("系统计算 大堆 灰")
private Double sysDdp1;
@Comment("系统计算 大堆 硫")
private Double sysDdp2;
@Comment("系统计算 大堆 硫")
private Double sysDdp2;
@Comment("系统计算 大堆 挥发")
private Double sysDdp3;
@Comment("系统计算 大堆 挥发")
private Double sysDdp3;
@Comment("系统计算 大堆 粘结")
private Double sysDdp4;
@Comment("系统计算 大堆 粘结")
private Double sysDdp4;
@Comment("系统计算 大堆 备用")
private Double sysDdp5;
@Comment("系统计算 大堆 备用")
private Double sysDdp5;
@Comment("用户输入与系统计算的平均值 大堆 灰")
private Double avgDdp1;
@Comment("用户输入与系统计算的平均值 大堆 灰")
private Double avgDdp1;
@Comment("用户输入与系统计算的平均值 大堆 硫")
private Double avgDdp2;
@Comment("用户输入与系统计算的平均值 大堆 硫")
private Double avgDdp2;
@Comment("用户输入与系统计算的平均值 大堆 挥发")
private Double avgDdp3;
@Comment("用户输入与系统计算的平均值 大堆 挥发")
private Double avgDdp3;
@Comment("用户输入与系统计算的平均值 大堆 粘结")
private Double avgDdp4;
@Comment("用户输入与系统计算的平均值 大堆 粘结")
private Double avgDdp4;
@Comment("用户输入与系统计算的平均值 大堆 备用")
private Double avgDdp5;
@Comment("用户输入与系统计算的平均值 大堆 备用")
private Double avgDdp5;
public void calculate() {
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!");
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++;
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;
}
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

@@ -6,17 +6,18 @@ import cn.lihongjie.coal.coalWashingDailyAnalysis.dto.CoalWashingDailyAnalysisDt
import cn.lihongjie.coal.coalWashingDailyAnalysis.dto.CreateCoalWashingDailyAnalysisDto;
import cn.lihongjie.coal.coalWashingDailyAnalysis.dto.UpdateCoalWashingDailyAnalysisDto;
import cn.lihongjie.coal.coalWashingDailyAnalysis.entity.CoalWashingDailyAnalysisEntity;
import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.control.DeepClone;
@Mapper(
componentModel = MappingConstants.ComponentModel.SPRING,
uses = {CommonMapper.class},
mappingControl = DeepClone.class)
componentModel = MappingConstants.ComponentModel.SPRING,
uses = {CommonMapper.class},
mappingControl = DeepClone.class)
public interface CoalWashingDailyAnalysisMapper
extends BaseMapper<
CoalWashingDailyAnalysisEntity,
CoalWashingDailyAnalysisDto,
CreateCoalWashingDailyAnalysisDto,
UpdateCoalWashingDailyAnalysisDto> {}
extends BaseMapper<
CoalWashingDailyAnalysisEntity,
CoalWashingDailyAnalysisDto,
CreateCoalWashingDailyAnalysisDto,
UpdateCoalWashingDailyAnalysisDto> {}

View File

@@ -4,30 +4,32 @@ import cn.lihongjie.coal.base.mapper.CommonMapper;
import cn.lihongjie.coal.coalBlend.dto.CoalBlendDto;
import cn.lihongjie.coal.coalWashingDailyAnalysis.entity.CoalWashingDailyAnalysisEntity;
import cn.lihongjie.coal.coalWashingDailyAnalysis.entity.CoalWashingDailyAnalysisItemVo;
import java.math.BigDecimal;
import java.math.RoundingMode;
import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.control.DeepClone;
import java.math.BigDecimal;
import java.math.RoundingMode;
@Mapper(
componentModel = MappingConstants.ComponentModel.SPRING,
uses = {CommonMapper.class},
mappingControl = DeepClone.class)
componentModel = MappingConstants.ComponentModel.SPRING,
uses = {CommonMapper.class},
mappingControl = DeepClone.class)
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

@@ -2,8 +2,9 @@ package cn.lihongjie.coal.coalWashingDailyAnalysis.repository;
import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.coalWashingDailyAnalysis.entity.CoalWashingDailyAnalysisEntity;
import org.springframework.stereotype.Repository;
@Repository
public interface CoalWashingDailyAnalysisRepository
extends BaseRepository<CoalWashingDailyAnalysisEntity> {}
extends BaseRepository<CoalWashingDailyAnalysisEntity> {}

View File

@@ -10,8 +10,11 @@ import cn.lihongjie.coal.coalWashingDailyAnalysis.entity.CoalWashingDailyAnalysi
import cn.lihongjie.coal.coalWashingDailyAnalysis.mapper.CoalWashingDailyAnalysisMapper;
import cn.lihongjie.coal.coalWashingDailyAnalysis.mapper.RoundMapper;
import cn.lihongjie.coal.coalWashingDailyAnalysis.repository.CoalWashingDailyAnalysisRepository;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.domain.Page;
@@ -22,64 +25,66 @@ import org.springframework.stereotype.Service;
@Service
@Slf4j
public class CoalWashingDailyAnalysisService
extends BaseService<CoalWashingDailyAnalysisEntity, CoalWashingDailyAnalysisRepository> {
extends BaseService<CoalWashingDailyAnalysisEntity, CoalWashingDailyAnalysisRepository> {
@Autowired CoalWashingDailyAnalysisRepository repository;
@Autowired CoalWashingDailyAnalysisRepository repository;
@Autowired CoalWashingDailyAnalysisMapper mapper;
@Autowired CoalWashingDailyAnalysisMapper mapper;
@Autowired RoundMapper roundMapper;
@Autowired RoundMapper roundMapper;
@Autowired ConversionService conversionService;
@PostConstruct
public void init() {}
@PostConstruct
public void init() {}
public CoalWashingDailyAnalysisDto create(CreateCoalWashingDailyAnalysisDto request) {
public CoalWashingDailyAnalysisDto create(CreateCoalWashingDailyAnalysisDto request) {
CoalWashingDailyAnalysisEntity entity = mapper.toEntity(request);
CoalWashingDailyAnalysisEntity entity = mapper.toEntity(request);
this.repository.save(entity);
return getById(entity.getId());
}
this.repository.save(entity);
return getById(entity.getId());
}
public CoalWashingDailyAnalysisDto calculate(CreateCoalWashingDailyAnalysisDto request) {
public CoalWashingDailyAnalysisDto calculate(CreateCoalWashingDailyAnalysisDto request) {
CoalWashingDailyAnalysisEntity entity = mapper.toEntity(request);
CoalWashingDailyAnalysisEntity entity = mapper.toEntity(request);
entity.rollingAvg();
entity.rollingAvg();
return mapper.toDto(roundMapper.round(entity));
}
return mapper.toDto(roundMapper.round(entity));
}
public CoalWashingDailyAnalysisDto update(UpdateCoalWashingDailyAnalysisDto request) {
CoalWashingDailyAnalysisEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
public CoalWashingDailyAnalysisDto update(UpdateCoalWashingDailyAnalysisDto request) {
CoalWashingDailyAnalysisEntity entity = this.repository.get(request.getId());
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 CoalWashingDailyAnalysisDto getById(String id) {
public CoalWashingDailyAnalysisDto getById(String id) {
CoalWashingDailyAnalysisEntity entity = repository.get(id);
CoalWashingDailyAnalysisEntity entity = repository.get(id);
return mapper.toDto(entity);
}
return mapper.toDto(entity);
}
@Autowired ConversionService conversionService;
public Page<CoalWashingDailyAnalysisDto> list(CommonQuery query) {
public Page<CoalWashingDailyAnalysisDto> list(CommonQuery query) {
Page<CoalWashingDailyAnalysisEntity> page =
repository.findAll(
query.specification(conversionService),
PageRequest.of(
query.getPageNo(),
query.getPageSize(),
Sort.by(query.getOrders())));
Page<CoalWashingDailyAnalysisEntity> 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

@@ -1,99 +1,107 @@
package cn.lihongjie.coal.common;
import io.vavr.Tuple2;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.ObjectUtils;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.ObjectUtils;
@UtilityClass
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());
}
public static <A, B, K> List<Tuple2<A, B>> innerHashJoin(
Iterable<A> a, Iterable<B> b, Function<A, K> ak, Function<B, K> bk) {
Map<K, List<A>> aMap = newStream(a).collect(Collectors.groupingBy(ak));
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) {
a = ObjectUtils.defaultIfNull(a, new ArrayList<>());
b = ObjectUtils.defaultIfNull(b, 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));
}
}
return StreamSupport.stream(data.spliterator(), false)
.map(fn)
.collect(java.util.stream.Collectors.toList());
}
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) {
Map<K, List<A>> aMap = newStream(a).collect(Collectors.groupingBy(ak));
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) {
a = ObjectUtils.defaultIfNull(a, new ArrayList<>());
b = ObjectUtils.defaultIfNull(b, new ArrayList<>());
List<Tuple2<A, B>> ans = new ArrayList<>();
for (A a1 : a) {
boolean find = false;
for (B b1 : b) {
if (test.apply(a1, b1)) {
ans.add(new Tuple2<>(a1, b1));
find = true;
}
}
if (!find) {
ans.add(new Tuple2<>(a1, null));
}
public static <A, B, K> List<Tuple2<A, B>> innerHashJoin(
Iterable<A> a, Iterable<B> b, Function<A, K> ak, Function<B, K> bk) {
Map<K, List<A>> aMap = newStream(a).collect(Collectors.groupingBy(ak));
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());
}
return ans;
}
private static <A> Stream<A> newStream(Iterable<A> a) {
return StreamSupport.stream(
a == null ? new ArrayList<A>().spliterator() : a.spliterator(), false);
}
public static <A, B> List<Tuple2<A, B>> innerNestJoin(
Iterable<A> a, Iterable<B> b, BiFunction<A, B, Boolean> test) {
a = ObjectUtils.defaultIfNull(a, new ArrayList<>());
b = ObjectUtils.defaultIfNull(b, 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));
}
}
}
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) {
Map<K, List<A>> aMap = newStream(a).collect(Collectors.groupingBy(ak));
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<>(
Collections.singletonList(
(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) {
a = ObjectUtils.defaultIfNull(a, new ArrayList<>());
b = ObjectUtils.defaultIfNull(b, new ArrayList<>());
List<Tuple2<A, B>> ans = new ArrayList<>();
for (A a1 : a) {
boolean find = false;
for (B b1 : b) {
if (test.apply(a1, b1)) {
ans.add(new Tuple2<>(a1, b1));
find = true;
}
}
if (!find) {
ans.add(new Tuple2<>(a1, null));
}
}
return ans;
}
private static <A> Stream<A> newStream(Iterable<A> a) {
return StreamSupport.stream(
a == null ? new ArrayList<A>().spliterator() : a.spliterator(), false);
}
}

View File

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

View File

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

View File

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

View File

@@ -8,21 +8,21 @@ import org.springframework.util.ReflectionUtils;
@UtilityClass
public class ReflectUtils {
public static Object getFieldValue(Object object, String fieldName) {
public static Object getFieldValue(Object object, String fieldName) {
if (object == null) {
return null;
}
if (object == null) {
return null;
}
if (StringUtils.isEmpty(fieldName)) {
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);
Field field = ReflectionUtils.findField(object.getClass(), fieldName);
if (field != null) {
field.setAccessible(true);
return ReflectionUtils.getField(field, object);
}
return null;
}
return null;
}
}

View File

@@ -4,64 +4,67 @@ import eu.bitwalker.useragentutils.Browser;
import eu.bitwalker.useragentutils.OperatingSystem;
import eu.bitwalker.useragentutils.UserAgent;
import eu.bitwalker.useragentutils.Version;
import jakarta.servlet.http.HttpServletRequest;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.StringUtils;
@UtilityClass
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 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) {
for (String header : HEADERS_TO_TRY) {
String ip = request.getHeader(header);
if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
return ip;
}
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();
}
return request.getRemoteAddr();
}
public static String getIp(HttpServletRequest request) {
return getClientIpAddress(request);
}
public static String getUa(HttpServletRequest request) {
try {
String header = request.getHeader("User-Agent");
if (StringUtils.isEmpty(header)) {
return "";
}
UserAgent userAgent = UserAgent.parseUserAgentString(header);
Browser browser = userAgent.getBrowser();
String browserName = browser.getName();
// or
// String browserName = browser.getGroup().getName();
Version browserVersion = userAgent.getBrowserVersion();
OperatingSystem os = userAgent.getOperatingSystem();
return os.getName() + " " + browserName + browserVersion.toString();
} catch (Exception e) {
return "";
public static String getIp(HttpServletRequest request) {
return getClientIpAddress(request);
}
public static String getUa(HttpServletRequest request) {
try {
String header = request.getHeader("User-Agent");
if (StringUtils.isEmpty(header)) {
return "";
}
UserAgent userAgent = UserAgent.parseUserAgentString(header);
Browser browser = userAgent.getBrowser();
String browserName = browser.getName();
// or
// String browserName = browser.getGroup().getName();
Version browserVersion = userAgent.getBrowserVersion();
OperatingSystem os = userAgent.getOperatingSystem();
return os.getName() + " " + browserName + browserVersion.toString();
} catch (Exception e) {
return "";
}
}
}
}

View File

@@ -8,6 +8,7 @@ import cn.lihongjie.coal.department.dto.CreateDepartmentDto;
import cn.lihongjie.coal.department.dto.DepartmentDto;
import cn.lihongjie.coal.department.dto.UpdateDepartmentDto;
import cn.lihongjie.coal.department.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
@@ -21,34 +22,34 @@ import org.springframework.web.bind.annotation.RestController;
@OrgScope
public class DepartmentController {
@Autowired DepartmentService service;
@Autowired DepartmentService service;
@PostMapping("/create")
@SysLog(action = "新增")
public DepartmentDto create(@RequestBody CreateDepartmentDto dto) {
return this.service.create(dto);
}
@PostMapping("/create")
@SysLog(action = "新增")
public DepartmentDto create(@RequestBody CreateDepartmentDto dto) {
return this.service.create(dto);
}
@PostMapping("/update")
@SysLog(action = "编辑")
public DepartmentDto update(@RequestBody UpdateDepartmentDto dto) {
return this.service.update(dto);
}
@PostMapping("/update")
@SysLog(action = "编辑")
public DepartmentDto update(@RequestBody UpdateDepartmentDto dto) {
return this.service.update(dto);
}
@PostMapping("/delete")
@SysLog(action = "删除")
public Object delete(@RequestBody IdRequest dto) {
this.service.delete(dto);
return true;
}
@PostMapping("/delete")
@SysLog(action = "删除")
public Object delete(@RequestBody IdRequest dto) {
this.service.delete(dto);
return true;
}
@PostMapping("/list")
public Page<DepartmentDto> list(@RequestBody CommonQuery dto) {
return this.service.list(dto);
}
@PostMapping("/list")
public Page<DepartmentDto> list(@RequestBody CommonQuery dto) {
return this.service.list(dto);
}
@PostMapping("/getById")
public DepartmentDto getById(@RequestBody IdRequest dto) {
return this.service.getById(dto.getId());
}
@PostMapping("/getById")
public DepartmentDto getById(@RequestBody IdRequest dto) {
return this.service.getById(dto.getId());
}
}

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