|
|
|
|
@ -1,18 +1,25 @@
|
|
|
|
|
package com.zhehekeji.web.service;
|
|
|
|
|
|
|
|
|
|
import codeDetector.BarcodeDetector;
|
|
|
|
|
import com.alibaba.druid.support.json.JSONUtils;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
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.entity.*;
|
|
|
|
|
import com.zhehekeji.web.lib.*;
|
|
|
|
|
import com.zhehekeji.web.mapper.*;
|
|
|
|
|
import com.zhehekeji.web.pojo.OrderVO;
|
|
|
|
|
import com.zhehekeji.web.pojo.websocket.WebSocketVo;
|
|
|
|
|
import com.zhehekeji.web.service.RFID.RFIDMap;
|
|
|
|
|
import com.zhehekeji.web.service.RFID.RFIDSocket;
|
|
|
|
|
import com.zhehekeji.web.service.hikLightSource.HikControlSocket;
|
|
|
|
|
import com.zhehekeji.web.service.ksec.KsecNettyClient;
|
|
|
|
|
import com.zhehekeji.web.service.sick.SickSocket;
|
|
|
|
|
import com.zhehekeji.web.ws.WebSocketServer;
|
|
|
|
|
import io.swagger.models.auth.In;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.collections4.SetUtils;
|
|
|
|
|
import org.apache.poi.util.ArrayUtil;
|
|
|
|
|
@ -23,6 +30,7 @@ import org.springframework.util.StringUtils;
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileWriter;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
@ -44,6 +52,9 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class PlcService {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
WebSocketServer webSocketServer;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private OrderMapper orderMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
@ -555,6 +566,15 @@ public class PlcService {
|
|
|
|
|
@Resource
|
|
|
|
|
private LightSourceMapper lightSourceMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void webSocketSendInfo(PlcCmdInfo plcCmdInfo,String cmdCode) throws IOException {
|
|
|
|
|
WebSocketVo<PlcCmdInfo> webSocketVo = new WebSocketVo<>();
|
|
|
|
|
webSocketVo.setMessage(plcCmdInfo);
|
|
|
|
|
webSocketVo.setType("wmsCmdCode-"+cmdCode);
|
|
|
|
|
webSocketVo.setMessageType("object");
|
|
|
|
|
WebSocketServer.sendInfo(JSONObject.toJSONString(webSocketVo),null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Boolean check(PlcCmdInfo plcCmdInfo,String cmdCode,String wmsCode,String wmsTrayCode){
|
|
|
|
|
|
|
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
|
|
@ -572,6 +592,7 @@ public class PlcService {
|
|
|
|
|
log.info("camera ptz"+c);
|
|
|
|
|
gyrateCameraByCode(cameraId, c);
|
|
|
|
|
}else {
|
|
|
|
|
String c = cmdCode+"1";
|
|
|
|
|
gyrateCameraByCode(cameraId, cmdCode);
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(configProperties.getCameraConfig().getDelayCaptureTime());
|
|
|
|
|
@ -621,11 +642,9 @@ public class PlcService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}else if(configProperties.getScanCodeMode().getTray() == 3){
|
|
|
|
|
//RFID
|
|
|
|
|
RFID rfid = rfidService.getRFIDByPlc(street.getId());
|
|
|
|
|
|
|
|
|
|
// //RFID
|
|
|
|
|
// RFID rfid = rfidService.getRFIDByPlc(street.getId(),plcCmdInfo.getLeftRight1());
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
|
|
RFIDCheck(plcCmdInfo);
|
|
|
|
|
Thread.sleep(1000*configProperties.getRfid().getScanTime());
|
|
|
|
|
Set<String> tags = RFIDStop(plcCmdInfo);
|
|
|
|
|
@ -640,11 +659,9 @@ public class PlcService {
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
OrderInfo orderInfo = new OrderInfo(street,plcCmdInfo,1,cmdCode);
|
|
|
|
|
Stock stock = stockMapper.getByStreetAndDirectionAndSideAndRowColumn(orderInfo.getStreetId(),orderInfo.getLeftRight(),orderInfo.getSeparation(),orderInfo.getRow(),orderInfo.getColumn());
|
|
|
|
|
Stock stock = stockMapper.getByStreetAndDirectionAndSideAndRowColumn(orderInfo.getStreetId(),plcCmdInfo.getFromDirection(),orderInfo.getSeparation(),orderInfo.getRow(),orderInfo.getColumn());
|
|
|
|
|
String scanCode = null;
|
|
|
|
|
Boolean codeCheck = Boolean.TRUE;
|
|
|
|
|
Boolean trayCodeCheck = Boolean.TRUE;
|
|
|
|
|
@ -684,7 +701,21 @@ public class PlcService {
|
|
|
|
|
status = 2;
|
|
|
|
|
}
|
|
|
|
|
if(stock == null){
|
|
|
|
|
stock = new Stock(null,null,plcCmdInfo.getOrderNum(),plcCmdInfo.getLotnum(),scanCode, null,null,wmsCode,null,null,wmsTrayCode,trayCode,orderInfo.getStreetId(),orderInfo.getLeftRight(),orderInfo.getSeparation(),orderInfo.getRow(),orderInfo.getColumn(),status,null,null,path, LocalDateTime.now());
|
|
|
|
|
stock = Stock.builder()
|
|
|
|
|
.checkNum(plcCmdInfo.getOrderNum())
|
|
|
|
|
.lotnum(plcCmdInfo.getLotnum())
|
|
|
|
|
.code(scanCode)
|
|
|
|
|
.wmsCode(wmsCode)
|
|
|
|
|
.wmsTrayCode(wmsTrayCode)
|
|
|
|
|
.trayCode(trayCode)
|
|
|
|
|
.streetId(orderInfo.getStreetId())
|
|
|
|
|
.direction(plcCmdInfo.getFromDirection())
|
|
|
|
|
.side(orderInfo.getSeparation())
|
|
|
|
|
.row(orderInfo.getRow())
|
|
|
|
|
.column(orderInfo.getColumn())
|
|
|
|
|
.status(status)
|
|
|
|
|
.checkPic(path)
|
|
|
|
|
.exportTime(LocalDateTime.now()).build();
|
|
|
|
|
stockMapper.insert(stock);
|
|
|
|
|
}else {
|
|
|
|
|
stock.setStatus(status);
|
|
|
|
|
@ -707,6 +738,20 @@ public class PlcService {
|
|
|
|
|
log.info("time:{}millisecond",s);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
public Boolean checkRfid(PlcCmdInfo plcCmdInfo,String wmsTrayCode){
|
|
|
|
|
RFIDCheck(plcCmdInfo);
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(1000*configProperties.getRfid().getScanTime());
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
Set<String> tags = RFIDStop(plcCmdInfo);
|
|
|
|
|
if(tags!= null && tags.size()>0 && tags.contains(wmsTrayCode)){
|
|
|
|
|
return Boolean.TRUE;
|
|
|
|
|
}else {
|
|
|
|
|
return Boolean.FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void checkLog(Stock stock){
|
|
|
|
|
CheckLog checkLog = new CheckLog();
|
|
|
|
|
checkLog.setCheckNum(stock.getCheckNum());
|
|
|
|
|
@ -732,16 +777,17 @@ public class PlcService {
|
|
|
|
|
public void RFIDCheck(PlcCmdInfo plcCmdInfo){
|
|
|
|
|
Street street = streetService.getStreetByPlcId(plcCmdInfo.getPlcId());
|
|
|
|
|
if(street != null){
|
|
|
|
|
RFID rfid = rfidService.getRFIDByPlc(street.getId());
|
|
|
|
|
//rfid不分左右,rfid使用同一ip和端口,依靠传递字符调整方向
|
|
|
|
|
RFID rfid = rfidService.getRFIDByPlc(street.getId(),null);
|
|
|
|
|
if(rfid != null){
|
|
|
|
|
RFIDStart(rfid.getIp(),rfid.getPort(),street.getId());
|
|
|
|
|
RFIDStart(rfid.getIp(),rfid.getPort(),street.getId(), plcCmdInfo.getFromDirection());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RFIDStart(String ip,Integer port,Integer streetId){
|
|
|
|
|
public void RFIDStart(String ip, Integer port, Integer streetId, Integer direction){
|
|
|
|
|
RFIDSocket rfidSocket = new RFIDSocket(ip,port);
|
|
|
|
|
rfidSocket.startCheck();
|
|
|
|
|
rfidSocket.startCheck(direction);
|
|
|
|
|
rfidSocket.readData();
|
|
|
|
|
RFIDMap.put(streetId,rfidSocket);
|
|
|
|
|
}
|
|
|
|
|
|