1.增加光源

2.增加图片
3.修改为盘点状态,而不是使用无货等
淮阴-烟草
LAPTOP-S9HJSOEB\昊天 9 months ago
parent 1950dec57c
commit 125f75b7bf

@ -0,0 +1,20 @@
package com.zhehekeji.web.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
@Configuration
public class RestConfig {
@Bean
public RestTemplate restTemplate() {
// 创建RestTemplate实例
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
factory.setConnectTimeout(10000); // 5 seconds
factory.setReadTimeout(10000); // 5 seconds
RestTemplate restTemplate = new RestTemplate(factory);
return restTemplate;
}
}

@ -8,11 +8,11 @@ import lombok.Getter;
public enum StockStatus {
PENDING(0, "未核对"),
PENDING(0, "未盘点"),
SUCCESS(2, "盘点准确"),
SUCCESS(2, "盘点正常"),
ERROR(1, "核对错误"),
ERROR(1, "盘点异常"),
OTHER(4, "其他"),
MANUAL(3,"人工核对"),
CATEGORY_ERROR(5, "品规失败"),

@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@ -41,6 +42,37 @@ public class LightSourceService {
HikControlSocket.openLight(lightInfo.getIp(),lightInfo.getPort(),lightSource.getIndex(),stat);
}else if (lightSource.getType() == 3){
LightSourceService.lightController(lightInfo.getIp(),lightInfo.getPort(),stat);
}else if (lightSource.getType() == 4){
LightSourceService.relay(lightInfo.getIp(),lightInfo.getPort(),stat);
}
}
public static void relay(String host, int port, int status) {
byte[] data;
byte[] data1;
if (status == 1) {
data = new byte[]{0x01, 0x05, 0x00, 0x01, (byte) 0xFF, 0x00, (byte) 0xDD, (byte) 0xFA};
data1 = new byte[]{0x01, 0x05, 0x00, 0x00, (byte) 0xFF, 0x00, (byte) 0x8C, (byte) 0x3A};
} else {
data = new byte[]{0x01, 0x05, 0x00, 0x01, (byte) 0x00, 0x00, (byte) 0x9C, (byte) 0x0A};
data1 = new byte[]{0x01, 0x05, 0x00, 0x00, (byte) 0x00, 0x00, (byte) 0xcd, (byte) 0xca};
}
try (Socket socket = new Socket(host, port);
DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream())) {
socket.setSoTimeout(1000);
// 发送数据
outputStream.write(data);
outputStream.flush();
outputStream.write(data1);
outputStream.flush();
System.out.println("Data sent successfully.");
} catch (IOException e) {
System.err.println("Error sending data: " + e.getMessage());
e.printStackTrace();
}
}

@ -39,6 +39,7 @@ import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
@ -688,7 +689,7 @@ public class PlcService {
//默认未盘点
checkLog.setStatus(StockStatus.PENDING.getStatus());
checkLog.setCreateTime(LocalDateTime.now());
checkLog.setWmsTrayCode(dataInfo.getTypeNum());
checkLog.setWmsTrayCode(dataInfo.getTrayCode());
checkLog.setWmsCount(dataInfo.getQuantity());
checkLog.setWmsCategory(dataInfo.getTypeNum());
@ -714,20 +715,27 @@ public class PlcService {
stock.setCount(dataInfo.getQuantity());
stock.setWmsCategoryName(dataInfo.getCategoryName());
stock.setTaskId((dataInfo.getTaskId()));
stock.setWmsTrayCode(dataInfo.getTrayCode());
//默认未盘点
if(stock.getCategory().length() == 6) {
stock.setStatus(StockStatus.PENDING.getStatus());
}
//进行品规识别,完成进行拍照
// if( stock.getCategory() != null && "20".equals(stock.getCategory())) {
// checkLog.setStatus(StockStatus.OTHER.getStatus());
// stock.setStatus(StockStatus.OTHER.getStatus());
// }
//algorithmPojo true为无货位false为有货位
Boolean algorithmPojo = sendHttp(street,plcCmdInfo);
if (algorithmPojo!=null){
if (algorithmPojo){
// 获取当前日期时间
LocalDateTime now = LocalDateTime.now();
// 定义格式化模式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// 格式化为字符串
String formattedDate = now.format(formatter);
if (algorithmPojo!=null ){
if (algorithmPojo.equals(Objects.equals(dataInfo.getTrayCode(), "0"))){
checkLog.setStatus(StockStatus.SUCCESS.getStatus());
stock.setStatus(StockStatus.SUCCESS.getStatus());
// stock.setCategory(dataInfo.getTypeNum());
@ -739,8 +747,8 @@ public class PlcService {
stock.setStatus(StockStatus.ERROR.getStatus());
}
//
// checkLog.setPic("http://"+street.getPlcIp()+":9007/pic/"+algorithmPojo.getDeterminePath());
// stock.setCheckPic("http://"+street.getPlcIp()+":9007/pic/"+algorithmPojo.getDeterminePath());
checkLog.setPic("http://"+street.getPlcIp()+":9007/pic/"+formattedDate+"/"+plcCmdInfo.getTaskId()+".png");
stock.setCheckPic("http://"+street.getPlcIp()+":9007/pic/"+formattedDate+"/"+plcCmdInfo.getTaskId()+".png");
}else {
checkLog.setStatus(StockStatus.ERROR.getStatus());
stock.setStatus(StockStatus.ERROR.getStatus());
@ -930,21 +938,18 @@ public class PlcService {
stockMapper.updateById(stock);
return checkLog.getStatus()>2?1:0;
}
@Resource
RestTemplate restTemplate;
public boolean sendHttp(Street street ,PlcCmdInfo plcCmdInfo){
// 创建RestTemplate实例
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
factory.setConnectTimeout(10000); // 5 seconds
factory.setReadTimeout(10000); // 5 seconds
RestTemplate restTemplate = new RestTemplate(factory);
// 定义 URL
String url = "http://"+street.getPlcIp()+":8097/judge/judge?direction={direction}&separation={separation}";
String url = "http://"+street.getPlcIp()+":8097/judge/judge?direction={direction}&separation={separation}&taskId={taskId}";
boolean flag = false;
try {
// 发起 GET 请求
ResponseEntity<Boolean> response = restTemplate.getForEntity(url, Boolean.class,plcCmdInfo.getLeftRight1(),plcCmdInfo.getSeparation1());
ResponseEntity<Boolean> response = restTemplate.getForEntity(url, Boolean.class,plcCmdInfo.getLeftRight1(),plcCmdInfo.getSeparation1(),plcCmdInfo.getTaskId());
flag = response.getBody();
// 输出响应状态码和响应体
System.out.println("Status Code: " + response.getStatusCode());

@ -360,7 +360,7 @@ public class StockService {
// String shelveId = streetService.getShevelId(stockCheckSearch.getSRMNumber(),stockCheckSearch.getDirection(),stockCheckSearch.getSeparation());
// Assert.notNull(shelveId,"无该货架信息");
Street street = streetService.getStreetByPlcId(stockCheckSearch.getSRMNumber());
Stock stock = stockMapper.getByStreetAndDirectionAndSideAndRowColumn(street.getId(),stockCheckSearch.getDirection(),1,stockCheckSearch.getRow(),stockCheckSearch.getColumn());
Stock stock = stockMapper.getByStreetAndDirectionAndSideAndRowColumn(street.getId(),stockCheckSearch.getDirection(),stockCheckSearch.getSeparation(),stockCheckSearch.getRow(),stockCheckSearch.getColumn());
if(stock != null && stock.getCheckPic()!=null){
stock.setCheckPics(stock.getCheckPic().split(";"));
}

@ -62,7 +62,7 @@ ksec:
ip: 127.0.0.1
port: 8001
#断点重连的次数:-1->不断重连
# reconnectNum: -1
reconnectNum: -1
# #断点重连的时间间隔(单位ms)
# reconnectInterval: 10000
# 服务端IP

Loading…
Cancel
Save