重连修改

增加队列,从队列里重复发送
泸州-视觉+扫码-昆船
LAPTOP-S9HJSOEB\昊天 9 months ago
parent 12cf1008cb
commit 22388b1fe5

@ -20,7 +20,7 @@ public class FusionDesignApplication {
// 使用RestTemplateBuilder来实例化RestTemplate对象spring默认已经注入了RestTemplateBuilder实例 // 使用RestTemplateBuilder来实例化RestTemplate对象spring默认已经注入了RestTemplateBuilder实例
@Bean @Bean
public RestTemplate restTemplate() { public RestTemplate restTemplate() {
return builder.setConnectTimeout(Duration.ofMinutes(5)) // 设置连接超时时间,单位毫秒 return builder.setConnectTimeout(Duration.ofMinutes(10)) // 设置连接超时时间,单位毫秒
.setReadTimeout(Duration.ofMinutes(20)) // 设置读取超时时间,单位秒 .setReadTimeout(Duration.ofMinutes(20)) // 设置读取超时时间,单位秒
.build(); .build();
} }

@ -19,4 +19,5 @@ public class IndustrialCameraVO {
private int flag; private int flag;
private String streetId; private String streetId;
private int sentCount;
} }

@ -28,6 +28,8 @@ public class CheckLogSearch {
private Integer row; private Integer row;
private String trayCode;
private Integer column; private Integer column;
private Integer pageSize; private Integer pageSize;

@ -31,15 +31,22 @@ public class CheckLogService {
}); });
PageHelper.startPage(search.getPageNum(),search.getPageSize()); PageHelper.startPage(search.getPageNum(),search.getPageSize());
QueryWrapper<CheckLog> wrapper = new QueryWrapper<>(); QueryWrapper<CheckLog> wrapper = new QueryWrapper<>();
if(!StringUtils.isEmpty(search.getLotnum())){ // if(!StringUtils.isEmpty(search.getLotnum())){
wrapper.eq("lotnum",search.getLotnum()); // wrapper.eq("lotnum",search.getLotnum());
} // }
if(search.getStartTimestamp() != null && search.getEndTimestamp() != null){ if(search.getStartTimestamp() != null && search.getEndTimestamp() != null){
wrapper.ge("create_time",search.getStartTimestamp()).le("create_time",search.getEndTimestamp()); wrapper.ge("create_time",search.getStartTimestamp()).le("create_time",search.getEndTimestamp());
} }
if(search.getLeftRight() != null && (search.getLeftRight() != 0 && search.getLeftRight() !=-1)){ if(search.getLeftRight() != null && (search.getLeftRight() != 0 && search.getLeftRight() !=-1)){
wrapper.eq("`direction`",search.getLeftRight()); wrapper.eq("`direction`",search.getLeftRight());
} }
if(search.getTrayCode() != null && !"".equals(search.getTrayCode())){
wrapper.like("`wms_tray_code`",search.getTrayCode());
}
if(search.getSide() != null &&(search.getSide() != 0 && search.getSide() !=-1)){
wrapper.eq("`side`",search.getSide());
}
if(search.getSide() != null &&(search.getSide() != 0 && search.getSide() !=-1)){ if(search.getSide() != null &&(search.getSide() != 0 && search.getSide() !=-1)){
wrapper.eq("`side`",search.getSide()); wrapper.eq("`side`",search.getSide());
} }

@ -15,6 +15,7 @@ import com.zhehekeji.web.service.algorithm.InventoryService;
import com.zhehekeji.web.service.client.ClientChanel; import com.zhehekeji.web.service.client.ClientChanel;
import com.zhehekeji.web.service.client.NettyServer; import com.zhehekeji.web.service.client.NettyServer;
import com.zhehekeji.web.service.com.SerialPortManager; import com.zhehekeji.web.service.com.SerialPortManager;
import com.zhehekeji.web.service.ksec.CommandQueue;
import com.zhehekeji.web.service.ksec.KsecNettyClient; import com.zhehekeji.web.service.ksec.KsecNettyClient;
import com.zhehekeji.web.service.putian.PuTianNettyClient; import com.zhehekeji.web.service.putian.PuTianNettyClient;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -22,6 +23,7 @@ import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner; import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashMap; import java.util.HashMap;
@ -85,6 +87,8 @@ public class InitService implements ApplicationRunner {
@Resource @Resource
HikSaveImage hikSaveImage; HikSaveImage hikSaveImage;
@Resource
RestTemplate restTemplate;
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
@ -93,6 +97,7 @@ public class InitService implements ApplicationRunner {
SerialPortManager.connectSerialPort(configProperties.getComConfig()); SerialPortManager.connectSerialPort(configProperties.getComConfig());
ConfigProperties.KSEC ksec = configProperties.getKsec(); ConfigProperties.KSEC ksec = configProperties.getKsec();
inventoryService.init(); inventoryService.init();
CommandQueue.sentHttp(restTemplate, configProperties);
if (configProperties.getCameraConfig()!=null if (configProperties.getCameraConfig()!=null
&& configProperties.getCameraConfig().getIndustrialCamera()!=null && configProperties.getCameraConfig().getIndustrialCamera()!=null
&& !configProperties.getCameraConfig().getIndustrialCamera().equals("")) && !configProperties.getCameraConfig().getIndustrialCamera().equals(""))

@ -29,6 +29,8 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static com.zhehekeji.web.service.ksec.CommandQueue.addCommand;
@Service @Service
@Slf4j @Slf4j
public class KuKouService extends ServiceImpl<KukouMapper,KuKou> implements IService<KuKou> { public class KuKouService extends ServiceImpl<KukouMapper,KuKou> implements IService<KuKou> {
@ -53,7 +55,7 @@ public class KuKouService extends ServiceImpl<KukouMapper,KuKou> implements IS
private ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(10); // 初始化一个包含2个线程的调度池; // 可以通过配置注入或使用 @Async 的 scheduler private ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(10); // 初始化一个包含2个线程的调度池; // 可以通过配置注入或使用 @Async 的 scheduler
public void setHttp(IndustrialCameraVO scTransmission, Boolean flag) { public void setHttp(IndustrialCameraVO scTransmission, Boolean flag) {
sendWithRetry(scTransmission, flag, 0); addCommand(scTransmission);
} }
private void sendWithRetry(IndustrialCameraVO scTransmission, Boolean flag, int retryCount) { private void sendWithRetry(IndustrialCameraVO scTransmission, Boolean flag, int retryCount) {

@ -0,0 +1,103 @@
package com.zhehekeji.web.service.ksec;
import cn.hutool.core.bean.BeanUtil;
import com.zhehekeji.common.util.SpringContextUtil;
import com.zhehekeji.core.pojo.Result;
import com.zhehekeji.web.config.ConfigProperties;
import com.zhehekeji.web.entity.IndustrialCameraReqVO;
import com.zhehekeji.web.lib.CameraControlModule;
import com.zhehekeji.web.lib.CameraDelayTask;
import com.zhehekeji.web.lib.TaskDelayExecutor;
import com.zhehekeji.web.pojo.IndustrialCameraVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import java.time.LocalDateTime;
import java.util.concurrent.*;
import static com.zhehekeji.web.service.KuKouService.setTrayCode;
@Slf4j
public class CommandQueue {
// 增加queue
public static void addCommand(IndustrialCameraVO scTransmission) {
queue.add(scTransmission);
}
private static ExecutorService exec = Executors.newFixedThreadPool(1);
private static LinkedBlockingQueue<IndustrialCameraVO> queue = new LinkedBlockingQueue<>();
public static void sentHttp(RestTemplate restTemplate, ConfigProperties configProperties){
exec.execute(new Consumer(restTemplate, configProperties));
}
private static class Consumer implements Runnable {
RestTemplate restTemplate ;
ConfigProperties configProperties;
Consumer(RestTemplate restTemplate, ConfigProperties configProperties){
this.restTemplate = restTemplate;
this.configProperties = configProperties;
}
@Override
public void run() {
while (true) {
try {
// CameraControlModule cameraControlModule = SpringContextUtil.getBean(CameraControlModule.class);
IndustrialCameraVO scTransmission = queue.take();
if(scTransmission != null){
try {
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "application/json");
headers.set("User-Agent", "Mozilla/5.0");
scTransmission.setTrayCode(setTrayCode(scTransmission.getTrayCode()));
IndustrialCameraReqVO industrialCameraReqVO = new IndustrialCameraReqVO();
BeanUtil.copyProperties(scTransmission, industrialCameraReqVO);
industrialCameraReqVO.setFlag(1);
log.info("发送盘点请求: {}", scTransmission.toString());
Result<IndustrialCameraReqVO> result = Result.success(industrialCameraReqVO, "图像识别完成");
HttpEntity<Result<IndustrialCameraReqVO>> entity = new HttpEntity<>(result, headers);
ResponseEntity<String> response = restTemplate.exchange(
configProperties.getKsec().getReportHttp(),
HttpMethod.POST,
entity,
new ParameterizedTypeReference<String>() {}
);
if (response.getStatusCode().is2xxSuccessful()) {
log.info("请求成功,响应:{}", response.getBody());
} else {
log.warn("请求未成功,状态码:{}", response.getStatusCode());
addCommand(scTransmission);
}
} catch (Exception e) {
scTransmission.setSentCount(scTransmission.getSentCount() + 1);
log.error("第{}请求失败 参数{}", scTransmission.getSentCount() , scTransmission.toString(), e);
if (scTransmission.getSentCount() < 30) {
addCommand(scTransmission);
}
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}

@ -100,7 +100,7 @@ videoStyleConfig:
# ----------- num:总共多少个光源端口 index:需要控制的是哪个 # ----------- num:总共多少个光源端口 index:需要控制的是哪个
# ------------ 利珀视觉控制器id从1开始光源控制器从0开始 # ------------ 利珀视觉控制器id从1开始光源控制器从0开始
lightSource: lightSource:
type: 2 type: 7
num: 4 num: 4
index: 1 index: 1
# -----tray 托盘 # -----tray 托盘

Loading…
Cancel
Save