parent
f245bf582c
commit
c14541a1fa
@ -0,0 +1,13 @@
|
||||
package com.zhehekeji.web.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@Configuration
|
||||
public class RestTemplateConfig {
|
||||
@Bean
|
||||
public RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package com.zhehekeji.web.entity;
|
||||
|
||||
import com.zhehekeji.web.service.ksec.KsecDataInfo;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AlgorithmPojo {
|
||||
String ip;
|
||||
Integer port;
|
||||
private String code = "";
|
||||
private Integer streetId;
|
||||
private String taskId;
|
||||
private Integer ack =1;
|
||||
private Integer id;
|
||||
private String goodsType;
|
||||
private Integer goodsNumber;
|
||||
private Integer result;
|
||||
private String goodsTypeResult;
|
||||
private Integer goodsNumberResult;
|
||||
|
||||
public static AlgorithmPojo buildAlgorithmPojo(Street street, KsecDataInfo dataInfo) {
|
||||
AlgorithmPojo algorithmPojo = new AlgorithmPojo();
|
||||
algorithmPojo.setIp( street.getPlcIp());
|
||||
algorithmPojo.setPort( street.getPlcPort());
|
||||
algorithmPojo.setStreetId( street.getId());
|
||||
algorithmPojo.setTaskId( dataInfo.getTaskId());
|
||||
algorithmPojo.setGoodsNumber(dataInfo.getGoodsNumber());
|
||||
algorithmPojo.setGoodsType(dataInfo.getGoodsType());
|
||||
return algorithmPojo;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,190 @@
|
||||
package com.zhehekeji.web.entity;
|
||||
|
||||
import com.zhehekeji.core.pojo.HttpStatus;
|
||||
|
||||
public class ResultResp <T>{
|
||||
|
||||
private String header = "LP";
|
||||
|
||||
private Integer code;
|
||||
private String message;
|
||||
private T data;
|
||||
|
||||
public ResultResp(T data) {
|
||||
this.code = HttpStatus.SUCCESS.getCode();
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static <T> ResultResp<T> success(T data) {
|
||||
ResultResp<T> ResultResp = new ResultResp();
|
||||
ResultResp.setData(data);
|
||||
ResultResp.setCode(HttpStatus.SUCCESS.getCode());
|
||||
ResultResp.setMessage("SUCCESS");
|
||||
return ResultResp;
|
||||
}
|
||||
|
||||
public static <T> ResultResp<T> success(T data, String msg) {
|
||||
ResultResp<T> ResultResp = new ResultResp();
|
||||
ResultResp.setData(data);
|
||||
ResultResp.setCode(HttpStatus.SUCCESS.getCode());
|
||||
ResultResp.setMessage(msg);
|
||||
return ResultResp;
|
||||
}
|
||||
|
||||
public static ResultResp success() {
|
||||
return builder().code(HttpStatus.SUCCESS.getCode()).message("SUCCESS").build();
|
||||
}
|
||||
|
||||
public static <T> ResultResp<T> error(Integer code, String message) {
|
||||
ResultResp<T> ResultResp = new ResultResp();
|
||||
ResultResp.setCode(code);
|
||||
ResultResp.setMessage(message);
|
||||
return ResultResp;
|
||||
}
|
||||
|
||||
public static <T> ResultResp.ResultRespBuilder<T> builder() {
|
||||
return new ResultResp.ResultRespBuilder();
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public void setCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
} else if (!(o instanceof ResultResp)) {
|
||||
return false;
|
||||
} else {
|
||||
ResultResp<?> other = (ResultResp)o;
|
||||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
} else {
|
||||
label47: {
|
||||
Object this$code = this.getCode();
|
||||
Object other$code = other.getCode();
|
||||
if (this$code == null) {
|
||||
if (other$code == null) {
|
||||
break label47;
|
||||
}
|
||||
} else if (this$code.equals(other$code)) {
|
||||
break label47;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Object this$message = this.getMessage();
|
||||
Object other$message = other.getMessage();
|
||||
if (this$message == null) {
|
||||
if (other$message != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!this$message.equals(other$message)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Object this$data = this.getData();
|
||||
Object other$data = other.getData();
|
||||
if (this$data == null) {
|
||||
if (other$data != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!this$data.equals(other$data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean canEqual(Object other) {
|
||||
return other instanceof ResultResp;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
boolean PRIME = true;
|
||||
int ResultResp = 1;
|
||||
Object $code = this.getCode();
|
||||
ResultResp = ResultResp * 59 + ($code == null ? 43 : $code.hashCode());
|
||||
Object $message = this.getMessage();
|
||||
ResultResp = ResultResp * 59 + ($message == null ? 43 : $message.hashCode());
|
||||
Object $data = this.getData();
|
||||
ResultResp = ResultResp * 59 + ($data == null ? 43 : $data.hashCode());
|
||||
return ResultResp;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ResultResp(code=" + this.getCode() + ", message=" + this.getMessage() + ", data=" + this.getData() + ")";
|
||||
}
|
||||
|
||||
public ResultResp(Integer code, String message, T data) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public ResultResp() {
|
||||
}
|
||||
|
||||
public String getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
public void setHeader(String header) {
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
public static class ResultRespBuilder<T> {
|
||||
private Integer code;
|
||||
private String message;
|
||||
private T data;
|
||||
|
||||
ResultRespBuilder() {
|
||||
}
|
||||
|
||||
public ResultResp.ResultRespBuilder<T> code(Integer code) {
|
||||
this.code = code;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResultResp.ResultRespBuilder<T> message(String message) {
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResultResp.ResultRespBuilder<T> data(T data) {
|
||||
this.data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResultResp<T> build() {
|
||||
return new ResultResp(this.code, this.message, this.data);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ResultResp.ResultRespBuilder(code=" + this.code + ", message=" + this.message + ", data=" + this.data + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
package com.zhehekeji.web.service.algorithm;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.api.R;
|
||||
import com.zhehekeji.core.util.Assert;
|
||||
import com.zhehekeji.web.config.ConfigProperties;
|
||||
import com.zhehekeji.web.entity.AlgorithmPojo;
|
||||
import com.zhehekeji.web.entity.Street;
|
||||
import com.zhehekeji.web.service.ksec.KsecDataInfo;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Service
|
||||
public class AlgorithmService {
|
||||
@Resource
|
||||
RestTemplate restTemplate;
|
||||
@Resource
|
||||
ConfigProperties configProperties;
|
||||
|
||||
public AlgorithmPojo getGoodResult(AlgorithmPojo algorithmPojo) {
|
||||
|
||||
String url = "http://"+algorithmPojo.getIp()+":"+algorithmPojo.getPort()+configProperties.getVisualSense().getUrl();
|
||||
ResponseEntity<AlgorithmPojo> body = null;
|
||||
|
||||
try {
|
||||
body = restTemplate.postForEntity(url, algorithmPojo, AlgorithmPojo.class);
|
||||
}catch (RestClientException e){
|
||||
//Assert.isTrue(false,"请求失败,视觉服务未连接");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return body.getBody();
|
||||
}
|
||||
public AlgorithmPojo getGoodResult(Street street, KsecDataInfo dataInfo ) {
|
||||
AlgorithmPojo algorithmPojo = AlgorithmPojo.buildAlgorithmPojo(street, dataInfo);
|
||||
if(configProperties.getVisualSense().getAble()) {
|
||||
algorithmPojo = getGoodResult(algorithmPojo);
|
||||
}else {
|
||||
algorithmPojo.setResult(1);
|
||||
algorithmPojo.setGoodsNumberResult(algorithmPojo.getGoodsNumber());
|
||||
algorithmPojo.setGoodsTypeResult(algorithmPojo.getGoodsType());
|
||||
}
|
||||
return algorithmPojo;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue