1.采用http连接视觉服务器

2.关灯web控制
3.
bozhou-古井贡酒
LAPTOP-S9HJSOEB\昊天 2 years ago
parent 93f1ba0d77
commit 97826be003

@ -62,6 +62,10 @@
<artifactId>netty-all</artifactId>
<version>4.1.50.Final</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency>
<groupId>com.zhehekeji</groupId>
<artifactId>filter</artifactId>

@ -11,9 +11,14 @@ import org.springframework.cache.jcache.JCacheCache;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;

@ -0,0 +1,23 @@
package com.zhehekeji.web.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import java.util.Arrays;
import java.util.Collections;
public class CustomJacksonHttpMessageConverter extends MappingJackson2HttpMessageConverter {
public CustomJacksonHttpMessageConverter() {
this(Jackson2ObjectMapperBuilder.json().build());
}
public CustomJacksonHttpMessageConverter(ObjectMapper objectMapper) {
super(objectMapper);
// 这里是重点,增加支持的类型,看你的情况加
// 我这里目前只需要加个 TEXT/PLAIN
setSupportedMediaTypes(Arrays.asList(MediaType.TEXT_PLAIN,
MediaType.APPLICATION_JSON,
new MediaType("application", "*+json")));
}
}

@ -3,6 +3,10 @@ package com.zhehekeji.web.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
@ -11,6 +15,9 @@ import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.Iterator;
import java.util.List;
@Configuration
@EnableSwagger2
@Profile({"test", "dev","prod"})

@ -7,6 +7,7 @@ import com.zhehekeji.core.pojo.Result;
import com.zhehekeji.web.entity.Stock;
import com.zhehekeji.web.pojo.category.PageSearch;
import com.zhehekeji.web.pojo.stock.*;
import com.zhehekeji.web.service.IOImportListener;
import com.zhehekeji.web.service.StockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -163,13 +164,9 @@ public class StockController {
}
public static void main(String[] args) {
String s = "4";
String ss = String.format("%03d", 4);
System.out.println(ss);
String bb = "10";
String bbb = String.format("%03d", 10);
System.out.println(bbb);
Integer i = 0;
String str=new String("");
System.out.println(i);
}
}

@ -2,6 +2,7 @@ package com.zhehekeji.web.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhehekeji.web.config.ConfigProperties;
import com.zhehekeji.web.controller.StreetController;
import com.zhehekeji.web.entity.LightSource;
import com.zhehekeji.web.mapper.LightSourceMapper;
import com.zhehekeji.web.service.damLightSource.JYDAMEquip;
@ -39,6 +40,9 @@ public class CronTab {
private ConfigProperties configProperties;
@Resource
private LightSourceMapper lightSourceMapper;
@Resource
private StreetController streetController;
private static LocalDateTime now;
@ -98,6 +102,12 @@ public class CronTab {
}
@Scheduled(cron = "0 0 0 * * ? ")
public void lightCloseAll() {
streetController.closeLightSource();
}
public static void checkFileTime(File dir,int days) {
if(!dir.exists()){
return;

@ -18,7 +18,6 @@ import java.util.stream.Collectors;
*/
@Slf4j
public class IOImportListener extends AnalysisEventListener<IOImport> {
private static Integer LENGTH = 5000;
private CameraIOConfigMapper configMapper;

@ -1,6 +1,7 @@
package com.zhehekeji.web.service;
import com.zhehekeji.web.config.ConfigProperties;
import com.zhehekeji.web.controller.StreetController;
import com.zhehekeji.web.entity.Camera;
import com.zhehekeji.web.entity.Street;
import com.zhehekeji.web.lib.*;
@ -46,6 +47,9 @@ public class InitService implements ApplicationRunner {
@Resource
private ConfigProperties configProperties;
@Resource
StreetController streetController;
@Resource
private PlcService plcService;
@Resource
@ -117,6 +121,7 @@ public class InitService implements ApplicationRunner {
}
}else if(configProperties.getServerMode() == 3){}
TaskDelayExecutor.runMp4DownloadExecutor();
streetController.closeLightSource();
}
class LoginThread extends Thread{

@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhehekeji.common.util.PathUtil;
import com.zhehekeji.web.config.ConfigProperties;
import com.zhehekeji.web.config.WebSocketConfig;
import com.zhehekeji.web.controller.StreetController;
import com.zhehekeji.web.entity.*;
import com.zhehekeji.web.lib.*;
import com.zhehekeji.web.mapper.*;
@ -33,6 +34,7 @@ import org.apache.poi.util.ArrayUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import javax.annotation.Resource;
import java.io.*;
@ -76,6 +78,9 @@ public class PlcService {
@Resource
private OrderService orderService;
@Resource
StreetController streetController;
@Resource
RFIDMapper rfidMapper;
@Resource
@ -133,6 +138,8 @@ public class PlcService {
*/
public void orderStart(PlcCmdInfo plcCmdInfo) {
Street street = streetService.getStreetByPlcId(plcCmdInfo.getPlcId());
//打开光源
streetController.openStreetLightSource( street.getId());
Integer cameraId = (plcCmdInfo.getFromAround() == 1) ? street.getCamera1Id() : street.getCamera2Id();
gyrateCameraByCode(cameraId, "C5", plcCmdInfo.getTaskId());
@ -206,6 +213,9 @@ public class PlcService {
Street street = streetMapper.selectById(order.getStreetId());
//关闭光源
streetController.closeStreetLightSource(street.getId());
LocalDateTime endDownLoadTime = endTime.plusSeconds(5);
Duration duration = Duration.between(order.getStartTime(), endDownLoadTime);
@ -606,6 +616,9 @@ public class PlcService {
long startTime = System.currentTimeMillis();
Street street = streetService.getStreetByPlcId(plcCmdInfo.getPlcId());
//打开光源
streetController.openStreetLightSource( street.getId());
CronTab.putTime(street.getId());
plcCmdInfo.setStreetName(street.getName());
List<LightSource> lightSources = lightSourceMapper.selectList(new QueryWrapper<LightSource>().eq("street_id", street.getId()));
@ -677,6 +690,8 @@ public class PlcService {
long s = end - startTime;
log.info("time:{}millisecond", s);
//关闭光源
streetController.closeStreetLightSource(street.getId());
return algorithmPojo;
}
@ -807,6 +822,7 @@ public class PlcService {
} else if (Cmd.B.name().equals(ksecInfo.getType())) {
//任务
if (Cmd.B1.name().equals(cmdName)) {
//打开灯
//昆船盘点模式下也会发B1 ,但是不会发送B2
//任务开始 旋转到原点位
@ -845,6 +861,7 @@ public class PlcService {
} else if (Cmd.E.name().equals(ksecInfo.getType())) {
String code = dataInfo.getCmdName();
log.info("盘点指令:{}", ksecInfo);
AlgorithmPojo algorithmPojo = check(plcCmdInfo, ksecInfo.getType(), dataInfo);
@ -859,6 +876,7 @@ public class PlcService {
}
}
return dataInfo;
}

@ -1,18 +1,21 @@
package com.zhehekeji.web.service.algorithm;
import com.baomidou.mybatisplus.extension.api.R;
import com.zhehekeji.core.util.Assert;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
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;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Service
public class AlgorithmService {
@ -21,18 +24,28 @@ public class AlgorithmService {
@Resource
ConfigProperties configProperties;
public AlgorithmPojo getGoodResult(AlgorithmPojo algorithmPojo) {
String url = "http://"+algorithmPojo.getIp()+":"+algorithmPojo.getPort()+configProperties.getVisualSense().getUrl();
ResponseEntity<AlgorithmPojo> body = null;
url = "http://127.0.0.1:8083"+configProperties.getVisualSense().getUrl();
ResponseEntity<String> body = null;
try {
body = restTemplate.postForEntity(url, algorithmPojo, AlgorithmPojo.class);
System.out.println(algorithmPojo);
body = restTemplate.postForEntity(url, algorithmPojo, String.class);
algorithmPojo = JSONObject.parseObject(body.getBody(), AlgorithmPojo.class);
if( algorithmPojo.getGoodsTypeResult().equals(algorithmPojo.getGoodsType())){
algorithmPojo.setResult(1);
}
System.out.println(body);
}catch (RestClientException e){
//Assert.isTrue(false,"请求失败,视觉服务未连接");
e.printStackTrace();
}
return body.getBody();
return algorithmPojo;
}
public AlgorithmPojo getGoodResult(Street street, KsecDataInfo dataInfo ) {
AlgorithmPojo algorithmPojo = AlgorithmPojo.buildAlgorithmPojo(street, dataInfo);

@ -3,6 +3,7 @@ package com.zhehekeji.web.service.ksec;
import com.zhehekeji.web.service.StreetConn;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import lombok.extern.slf4j.Slf4j;
@ -58,9 +59,9 @@ public class KescNettyHandler extends ChannelInboundHandlerAdapter {
ctx.channel().writeAndFlush(heart);
IdleStateEvent event = (IdleStateEvent) obj;
// if (IdleState.WRITER_IDLE.equals(event.state())) { // 如果写通道处于空闲状态就发送心跳命令
//
// }
if (IdleState.WRITER_IDLE.equals(event.state())) { // 如果写通道处于空闲状态就发送心跳命令
}
}
}

@ -0,0 +1,28 @@
package com.zhehekeji.web.test;
import java.io.IOException;
import java.net.Socket;
public class TR {
public static void main(String[] args) {
for (;;){
// 创建TCP客户端并连接到服务器
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
String serverAddress = "127.0.0.1";
int serverPort = 8888;
try {
Socket clientSocket = new Socket(serverAddress, serverPort);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
thread.start();
}
}
}

@ -27,18 +27,24 @@ public class MyServer {
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
//给pipeline管道设置处理器
socketChannel.pipeline().addLast(new MyServerHandler());
socketChannel.pipeline().addLast(new MyServerHandler())
;
}
});//给workerGroup的EventLoop对应的管道设置处理器
System.out.println("java技术爱好者的服务端已经准备就绪...");
ChannelFuture channelFuture ;
//绑定端口号,启动服务端
try {
ChannelFuture channelFuture = bootstrap.bind(6666).sync();
channelFuture= bootstrap.bind(6666).sync();
channelFuture.channel().closeFuture().sync();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}finally {
}
}
}

@ -89,8 +89,8 @@ scanCodeMode:
# 照片 視頻保存多久
deleteFileDays: 365
visualSense:
url: "/api/test/2"
able: false
url: "/visionCompute"
able: true
#rfid
rfid:
#rfid连续扫描时间默认5s 单位s

Loading…
Cancel
Save