灯光修改

视频时间修改
连接修改(保证同一时间只有一个链接)
随行状态修改
导出修改
泸州-视觉+扫码-昆船
LAPTOP-S9HJSOEB\昊天 2 years ago
parent beaba8206d
commit c8fdce19b9

@ -3,6 +3,7 @@ package com.zhehekeji.web.controller;
import com.github.pagehelper.PageInfo;
import com.zhehekeji.core.pojo.Result;
import com.zhehekeji.web.config.ConfigProperties;
import com.zhehekeji.web.entity.LightSource;
import com.zhehekeji.web.entity.Street;
import com.zhehekeji.web.pojo.street.StreetSearch;
import com.zhehekeji.web.pojo.street.StreetVO;
@ -77,42 +78,55 @@ public class StreetController {
@GetMapping("/lightSource/open")
@ApiOperation(value = "开启光源")
public Result openLightSource(){
ClientChanel.keys().forEach(k->{
LCTransmission lcTransmission = new LCTransmission(k,1);
ClientChanel.write(lcTransmission.toString(),k);
List<LightSource> lightSources = lightSourceService.getLightSource();
lightSources.forEach(lightSource -> {
LightSourceService.lightControllerFactory(configProperties.getLightSource(),lightSource,1);
});
return Result.success();
}
@GetMapping("/lightSource/close")
@ApiOperation(value = "关闭光源")
public Result closeLightSource(){
ClientChanel.keys().forEach(k->{
LCTransmission lcTransmission = new LCTransmission(k,0);
ClientChanel.write(lcTransmission.toString(),k);
List<LightSource> lightSources = lightSourceService.getLightSource();
lightSources.forEach(lightSource -> {
LightSourceService.lightControllerFactory(configProperties.getLightSource(),lightSource,0);
});
return Result.success();
}
@GetMapping("/lightSource/open/{streetId}")
@ApiOperation(value = "开启单个巷道光源")
public Result openStreetLightSource(@PathVariable Integer streetId){
Street street = streetService.streetById(streetId);
LCTransmission lcTransmission = new LCTransmission(street.getPlcId(),1);
ClientChanel.write(lcTransmission.toString(),street.getPlcId());
List<LightSource> lightSources = lightSourceService.getLightSourceByStreetId(streetId);
lightSources.forEach(lightSource -> {
LightSourceService.lightControllerFactory(configProperties.getLightSource(),lightSource,1);
});
return Result.success();
}
@GetMapping("/lightSource/close/{streetId}")
@ApiOperation(value = "关闭单个巷道光源")
public Result closeStreetLightSource(@PathVariable Integer streetId){
Street street = streetService.streetById(streetId);
LCTransmission lcTransmission = new LCTransmission(street.getPlcId(),0);
ClientChanel.write(lcTransmission.toString(),street.getPlcId());
List<LightSource> lightSources = lightSourceService.getLightSourceByStreetId(streetId);
lightSources.forEach(lightSource -> {
LightSourceService.lightControllerFactory(configProperties.getLightSource(),lightSource,0);
});
return Result.success();
}
}

@ -297,8 +297,7 @@ public class HikCameraControlModuleImpl implements CameraControlModule {
}
public void downloadMp4(Integer cameraId, String path, LocalDateTime start, LocalDateTime end) {
start = start.minusMinutes(1);
end = end.minusMinutes(1);
start = start.minusSeconds(10);
PathUtil.checkDirc(path);
HCNetSDK.NET_DVR_TIME startTime = new HCNetSDK.NET_DVR_TIME();
startTime.setTime(start.getYear(), start.getMonthValue(), start.getDayOfMonth(), start.getHour(), start.getMinute(), start.getSecond());

@ -105,7 +105,7 @@ public class InitService implements ApplicationRunner {
ksecNettyClient.createClient(ksec);
}catch (Exception e){
log.error("kesc connect error,url:{},port:{}",ksec.getIp(),ksec.getPort());
ksecNettyClient.reconnect(0);
//ksecNettyClient.reconnect(0);
}
}else {
log.error("ksec no config");

@ -7,10 +7,6 @@ import com.zhehekeji.web.mapper.LightSourceMapper;
import com.zhehekeji.web.service.damLightSource.JYDAMEquip;
import com.zhehekeji.web.service.damLightSource.JYDamHelper;
import com.zhehekeji.web.service.hikLightSource.HikControlSocket;
import com.zhehekeji.web.service.light.RelaySource;
import com.zhehekeji.web.service.light.damLightSource.JYDAMEquip;
import com.zhehekeji.web.service.light.damLightSource.JYDamHelper;
import com.zhehekeji.web.service.light.hikLightSource.HikControlSocket;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -28,6 +24,14 @@ public class LightSourceService {
@Resource
private LightSourceMapper lightSourceMapper;
public static void lightControllerOpen(ConfigProperties.LightSource lightSource,LightSource lightInfo) {
lightControllerFactory(lightSource, lightInfo, 1);
}
public static void lightControllerClose(ConfigProperties.LightSource lightSource,LightSource lightInfo) {
lightControllerFactory(lightSource, lightInfo, 0);
}
public static void lightControllerFactory(ConfigProperties.LightSource lightSource,LightSource lightInfo, Integer stat){
if(lightSource.getType() == 1){
@ -44,8 +48,6 @@ public class LightSourceService {
HikControlSocket.lightController(lightInfo.getIp(),lightInfo.getPort(),lightSource.getIndex(),stat);
}else if (lightSource.getType() == 3){
LightSourceService.lightController(lightInfo.getIp(),lightInfo.getPort(),stat);
}else if (lightSource.getType() == 4){
RelaySource.lightController(lightInfo.getIp(),lightInfo.getPort(),stat);
}
}

@ -47,8 +47,16 @@ public class OrderService {
}
orderVO.setGoodsLocation(location(orderVO,streetMap.get(orderVO.getStreetId())));
if (orderVO.getPicPaths() != null && orderVO.getPicPaths().split(",").length > 0){
orderVO.setGoodsLocation(location(orderVO, streetMap.get(orderVO.getStreetId())));
if(orderVO.getStartTime() != null && orderVO.getEndTime() != null){
Duration duration = Duration.between(orderVO.getStartTime(), orderVO.getEndTime());
Long seconds = duration.getSeconds();
int minutes = seconds.intValue() / 60;
int remainingSeconds = seconds.intValue() % 60;
String timeLength = String.format("%02d:%02d", minutes,remainingSeconds);
orderVO.setTimeLength(timeLength);
}
if (orderVO.getPicPaths() != null && orderVO.getPicPaths().split(",").length > 0) {
orderVO.setPics(orderVO.getPicPaths().split(","));
}
// if(orderVO.getIntoStockPic() != null ) {
@ -67,21 +75,51 @@ public class OrderService {
return order.getId();
}
public String location(OrderVO orderVO,Street street){
public String location(OrderVO orderVO, Street street) {
String location = "";
if(orderVO.getLeftRight1() != null){
String leftRightS = orderVO.getLeftRight1() == 1 ? "左" : "右";
location = leftRightS;
if (orderVO.getColumn1() != null && orderVO.getColumn1() != 0) {
if (orderVO.getLeftRight1() != null) {
String leftRightS = orderVO.getLeftRight1() == 1 ? "左侧" : "右侧";
location = leftRightS;
}
if (orderVO.getInOut1() != null) {
String side = orderVO.getInOut1() == 1 ? "浅货位" : "深货位";
location = location + side;
}
location = location + orderVO.getRow1() + "层" + orderVO.getColumn1() + "列";
} else {
location = "库外";
}
if(orderVO.getInOut1() != null){
String side = orderVO.getInOut1() == 1?"浅":"深";
location = location + "-" + side +"-";
//转
location = location + " 转 ";
if (orderVO.getColumn2() != null && orderVO.getColumn2() != 0) {
if (orderVO.getLeftRight2() != null) {
String leftRightS = orderVO.getLeftRight2() == 1 ? "左侧" : "右侧";
location = location + leftRightS;
}
if (orderVO.getInOut2() != null) {
String side = orderVO.getInOut2() == 1 ? "浅货位" : "深货位";
location = location + side;
}
location = location + orderVO.getRow2() + "层" + orderVO.getColumn2() + "列";
} else {
location =location + "库外";
}
//里外 现在无法判断 这个项目全是 里
return location +orderVO.getRow1()+"层"+orderVO.getColumn1()+"列";
return location;
}

@ -104,6 +104,15 @@ public class PlcService {
public void orderStart(PlcCmdInfo plcCmdInfo) {
Street street = streetService.getStreetByPlcId(plcCmdInfo.getPlcId());
List<LightSource> lightSources = lightSourceMapper.selectList(new QueryWrapper<LightSource>().eq("street_id",street.getId()));
lightSources.forEach(lightSource -> {
try {
LightSourceService.lightControllerOpen(configProperties.getLightSource(),lightSource);
}catch (Exception e){
log.error("open light"+lightSource.getIp()+" error",e);
}
});
if (street != null) {
if (plcCmdInfo.getLeftRight1() == 1) {
if (plcCmdInfo.getRow1() > street.getLeftRow() && plcCmdInfo.getColumn1() > street.getLeftColumn()) {
@ -116,10 +125,22 @@ public class PlcService {
return;
}
}
Integer cameraId = getCameraByPlcCmd(plcCmdInfo,plcCmdInfo.getLeftRight1());
String code = "C2-" + plcCmdInfo.getLeftRightStr(0) + plcCmdInfo.getInOutStr(0);
gyrateCameraByCode(cameraId,code);
Long delayTime = configProperties.getCameraConfig().getC1DelayCaptureTime();
String path = PathUtil.createFileNameByRowColumn("jpg",cameraId,plcCmdInfo.getRow1(),plcCmdInfo.getColumn1());
path = cameraCapture(cameraId,true,delayTime,path);
plcCmdInfo.setStreetId(street.getId());
Order order = new Order();
order.setOrderNum(plcCmdInfo.getOrderNum());
order.setStatus(0);
order.setPicPaths(path);
order.setStartTime(LocalDateTime.now());
order.setStreetId(street.getId());
order.setInOut1(plcCmdInfo.getSide1());
@ -177,6 +198,16 @@ public class PlcService {
String path = cameraVideo(street.getCamera2Id(), order.getStartTime(), endDownLoadTime);
update.setVideoPath2(path);
}
List<LightSource> lightSources = lightSourceMapper.selectList(new QueryWrapper<LightSource>().eq("street_id",street.getId()));
lightSources.forEach(lightSource -> {
try {
LightSourceService.lightControllerClose(configProperties.getLightSource(),lightSource);
}catch (Exception e){
log.error("open light"+lightSource.getIp()+" error",e);
}
});
orderMapper.updateById(update);
}
@ -272,7 +303,7 @@ public class PlcService {
*/
Integer cameraId = getCameraByPlcCmd(plcCmdInfo,orderInfo.getLeftRight());
gyrateCameraByCode(cameraId,orderInfo.getCmdCode());
if(needCapture){
if(needCapture && code.startsWith("C4")){
Boolean delay = true;
Integer row = 0;
Integer column = 0;
@ -287,24 +318,12 @@ public class PlcService {
sep = plcCmdInfo.getSeparation2();
}
long delayTime = 0;
if(code.startsWith("C1")){
delayTime = configProperties.getCameraConfig().getC1DelayCaptureTime();
}else if(code.startsWith("C2")){
if(sep == 1){
delayTime = configProperties.getCameraConfig().getC2DelayCaptureTime();
}else {
delayTime = configProperties.getCameraConfig().getC2OutDelayCaptureTime();
}
}else if(code.startsWith("C3")){
delayTime = configProperties.getCameraConfig().getC3DelayCaptureTime();
}else if(code.startsWith("C4")){
//该项目只有c1c4并且c1由b1拍照
if(sep == 1){
delayTime = configProperties.getCameraConfig().getC4DelayCaptureTime();
}else {
delayTime = configProperties.getCameraConfig().getC4OutDelayCaptureTime();
}
}
path = PathUtil.createFileNameByRowColumn("jpg",cameraId,row,column);
path = cameraCapture(cameraId,delay,delayTime,path);
}
@ -331,7 +350,7 @@ public class PlcService {
List<LightSource> lightSources = lightSourceMapper.selectList(new QueryWrapper<LightSource>().eq("street_id",street.getId()));
lightSources.forEach(lightSource -> {
try {
HikControlSocket.openLight(lightSource.getIp(),lightSource.getPort(),configProperties.getLightSource().getIndex(),1);
LightSourceService.lightControllerOpen(configProperties.getLightSource(),lightSource);
}catch (Exception e){
log.error("open light"+lightSource.getIp()+" error",e);
}
@ -541,7 +560,14 @@ public class PlcService {
long end = System.currentTimeMillis();
long s = end - startTime;
log.info("time:{}millisecond", s);
lightSources.forEach(lightSource -> {
try {
LightSourceService.lightControllerClose(configProperties.getLightSource(),lightSource);
}catch (Exception e){
log.error("open light"+lightSource.getIp()+" error",e);
}
});
return true;
}

@ -73,13 +73,13 @@ public class StockService {
return new ArrayList<>();
}
//List<String> shelves = streetService.check(street);
List<Stock> stocks = stockMapper.selectList(new QueryWrapper<Stock>().eq("street_id",streetId).orderByAsc("shelve_id", "`row`", "`column`"));
List<Stock> stocks = stockMapper.selectList(new QueryWrapper<Stock>().eq("street_id",streetId).orderByAsc("street_id", "`row`", "`column`"));
return stocks;
}
public PageInfo<Stock> page(PageSearch pageSearch) {
PageHelper.startPage(pageSearch.getPageNum(), pageSearch.getPageSize());
List<Stock> stocks = stockMapper.selectList(new QueryWrapper<Stock>().orderByAsc("shelve_id", "`row`", "`column`"));
List<Stock> stocks = stockMapper.selectList(new QueryWrapper<Stock>().orderByAsc("street_id", "`row`", "`column`"));
return new PageInfo<>(stocks);
}

@ -14,6 +14,49 @@ import java.nio.charset.StandardCharsets;
@Slf4j
public class HikControlSocket {
public static int lightController(String ip,int port,int index,int bool){
Socket socket = new Socket();
int status = 0;
OutputStream os = null;
InputStream is = null;
try {
socket.connect(new InetSocketAddress(ip,port),3000);
//socket.setSoTimeout(10000);
os = socket.getOutputStream();
Thread.sleep(100);
controlCmd(os,bool,index);
//is = socket.getInputStream();
//String s = read(socket.getInputStream());
//log.info("hik receieve:{}",s);
socket.close();
} catch (IOException e) {
log.error("hik contro time out,ip:{},info:{}",ip,e);
}finally {
if(os != null){
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(is != null){
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
return status;
}
}
/**
*
* <${},${0 1},${get\post}>

@ -13,6 +13,7 @@ import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.concurrent.atomic.AtomicBoolean;
@Slf4j
@Component
@ -29,23 +30,43 @@ public class KsecNettyClient {
*/
private static int RECONNECT_NUM = 10;
private static Channel channel;
private static Bootstrap client ;; // 单例Bootstrap
private static final AtomicBoolean reconnecting = new AtomicBoolean(false); // 标记是否正在重连
private static Channel channel;
//次数
static int num = 0;
public void createClient(ConfigProperties.KSEC ksec) throws InterruptedException {
String lotnum = FileUtil.getText("lastLotnum");
if(lotnum != null){
KsecDecoder.setLastLotnum(lotnum);
}
if (StringUtils.isEmpty(ksec.getIp()) || ksec.getPort() == null) {
return;
}
Bootstrap client = new Bootstrap();
client.group(group);
client.channel(NioSocketChannel.class);
KsecInfo heart = KsecInfo.heart();
client.handler(new KescFilter(heart, plcService,this));
// 连接服务端
channel = client.connect(ksec.getIp(), ksec.getPort()).sync().channel();
String lotnum = FileUtil.getText("lastLotnum");
if (lotnum != null) {
KsecDecoder.setLastLotnum(lotnum);
}
if (StringUtils.isEmpty(ksec.getIp()) || ksec.getPort() == null) {
return;
}
if (client == null) {
Bootstrap c = new Bootstrap();
c.group(group);
c.channel(NioSocketChannel.class);
KsecInfo heart = KsecInfo.heart();
c.handler(new KescFilter(heart, plcService, this));
client = c;
}
try {
channel = client.connect(ksec.getIp(), ksec.getPort()).sync().channel();
num = 0;
}catch (Exception e){
log.error("createClient error",e);
if (ksec.getReconnectNum() == -1 || num < ksec.getReconnectNum() && !reconnecting.get()) {
reconnect(0);
}
}
}
/**
@ -54,12 +75,7 @@ public class KsecNettyClient {
* @param upId
*/
public void reconnect(Integer upId) {
if (channel != null) {
channel.disconnect();
channel.close();
}
Boolean isConnected = false;
int num = 0;
ConfigProperties.KSEC ksec = configProperties.getKsec();
if (ksec == null) {
log.error("reconnect ,upPc is null ,id:{}", upId);
@ -70,7 +86,6 @@ public class KsecNettyClient {
} catch (InterruptedException e) {
e.printStackTrace();
}
while (ksec.getReconnectNum() == -1 || num < ksec.getReconnectNum() && !isConnected) {
try {
Thread.sleep(ksec.getReconnectInterval());
@ -78,22 +93,24 @@ public class KsecNettyClient {
e.printStackTrace();
}
try {
//关闭之前连接
if (channel != null) {
channel.disconnect();
channel.close();
}
//重连次数
num++;
log.error("reconnect error num:{}", num);
createClient(ksec);
} catch (Exception e) {
//没连上 继续
log.error("reconnect error num:{}", num);
//关闭当前链接
num++;
// try{
// Thread.sleep(ksec.getReconnectInterval());
// }catch (Exception ex){
// throw new RuntimeException(ex);
// }
continue;
}
isConnected = true;
}
if (isConnected) {
if (reconnecting.get()) {
log.info("plc reconnect success");
} else {
log.error("plc reconnect error .upPcId:{},reconnect num:{},ip:{},port:{}", upId, num, ksec.getIp(), ksec.getPort());

@ -64,9 +64,9 @@ ksec:
platformIp: 127.0.0.1
platformPort: 3000
#断点重连的次数:-1->不断重连
# reconnectNum: -1
reconnectNum: -1
# #断点重连的时间间隔(单位ms)
# reconnectInterval: 10000
reconnectInterval: 5
# 服务端IP
IP: 127.0.0.1
# 服务端TCP端口

Loading…
Cancel
Save