mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 15:55:18 +08:00
添加接口
This commit is contained in:
@@ -0,0 +1,43 @@
|
|||||||
|
package cn.lihongjie.coal.controller;
|
||||||
|
|
||||||
|
import cn.lihongjie.coal.dto.CoalBlendRequest;
|
||||||
|
import cn.lihongjie.coal.dto.CoalBlendResult;
|
||||||
|
import cn.lihongjie.coal.dto.CoalParameterDef;
|
||||||
|
import cn.lihongjie.coal.dto.R;
|
||||||
|
import cn.lihongjie.coal.service.CoalService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
|
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")
|
||||||
|
public class CoalController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CoalService coalService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/blend")
|
||||||
|
public R<CoalBlendResult> blend(@RequestBody CoalBlendRequest request){
|
||||||
|
|
||||||
|
return R.success(coalService.blend(request));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/params")
|
||||||
|
public R<List<CoalParameterDef>> blend(){
|
||||||
|
|
||||||
|
return R.success(coalService.paramDefs());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
12
src/main/java/cn/lihongjie/coal/dto/CoalParameterDef.java
Normal file
12
src/main/java/cn/lihongjie/coal/dto/CoalParameterDef.java
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package cn.lihongjie.coal.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CoalParameterDef {
|
||||||
|
private String code;
|
||||||
|
private String name;
|
||||||
|
private String desc;
|
||||||
|
private String type;
|
||||||
|
private Integer order;
|
||||||
|
}
|
||||||
38
src/main/java/cn/lihongjie/coal/dto/R.java
Normal file
38
src/main/java/cn/lihongjie/coal/dto/R.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package cn.lihongjie.coal.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class R<T> {
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
private String code ;
|
||||||
|
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
|
||||||
|
public R(T data, String code, String msg) {
|
||||||
|
this.data = data;
|
||||||
|
this.code = code;
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public R() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static <T> R<T> success(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> create(T data, String code, String msg) {
|
||||||
|
|
||||||
|
return new R<>(data, code, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,13 +1,20 @@
|
|||||||
package cn.lihongjie.coal.service;
|
package cn.lihongjie.coal.service;
|
||||||
|
|
||||||
import cn.lihongjie.coal.dto.*;
|
import cn.lihongjie.coal.dto.*;
|
||||||
|
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.Loader;
|
||||||
import com.google.ortools.sat.*;
|
import com.google.ortools.sat.*;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -331,4 +338,23 @@ public class CoalService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@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;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user