添加接口

This commit is contained in:
2023-07-24 10:38:22 +08:00
parent 320c343958
commit eefd2aa24b
4 changed files with 119 additions and 0 deletions

View File

@@ -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());
}
}

View 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;
}

View 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);
}
}

View File

@@ -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;
}
} }