|
|
|
|
@ -16,8 +16,10 @@ 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.interfaces.RfidLiveService;
|
|
|
|
|
import com.zhehekeji.web.service.ksec.KsecNettyClient;
|
|
|
|
|
import com.zhehekeji.web.service.sick.SickSocket;
|
|
|
|
|
import com.zhehekeji.web.util.ToolUtil;
|
|
|
|
|
import com.zhehekeji.web.ws.WebSocketServer;
|
|
|
|
|
import io.swagger.models.auth.In;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
@ -33,10 +35,7 @@ import java.io.FileWriter;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.ArrayBlockingQueue;
|
|
|
|
|
import java.util.concurrent.BlockingDeque;
|
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
|
@ -65,6 +64,9 @@ public class PlcService {
|
|
|
|
|
private WarnMapper warnMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private OrderService orderService;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
RFIDMapper rfidMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private StockLogMapper stockLogMapper;
|
|
|
|
|
|
|
|
|
|
@ -87,6 +89,8 @@ public class PlcService {
|
|
|
|
|
private RFIDService rfidService;
|
|
|
|
|
@Resource
|
|
|
|
|
private CheckLogMapper checkLogMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private RfidLiveService rfidLiveService;
|
|
|
|
|
|
|
|
|
|
private static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 8, 200, TimeUnit.MINUTES, new ArrayBlockingQueue<>(100000));
|
|
|
|
|
|
|
|
|
|
@ -299,6 +303,7 @@ public class PlcService {
|
|
|
|
|
gyrateCameraByCodeTimeLater(street.getCamera1Id(), "C5", configProperties.getCameraConfig().getC2OutDelayCaptureTime() + 500);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
rfidLiveService.rfidOrderStock(plcCmdInfo, times, code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void gyrateCamera(PlcCmdInfo plcCmdInfo, String code) {
|
|
|
|
|
@ -548,11 +553,11 @@ public class PlcService {
|
|
|
|
|
} else {
|
|
|
|
|
if (street.getCamera1Id() != null && street.getCamera2Id() != null && street.getCamera1Id() != 0 && street.getCamera2Id() != 0) {
|
|
|
|
|
//双伸 todo 这个因项目而异,看现场的情况
|
|
|
|
|
//默认是 左侧返回camera2 右侧返回camera1
|
|
|
|
|
//默认是 左侧返回camera1 右侧返回camera2
|
|
|
|
|
if (plcCmdInfo.getLeftRight1() == 1) {
|
|
|
|
|
return street.getCamera2Id();
|
|
|
|
|
}else {
|
|
|
|
|
return street.getCamera1Id();
|
|
|
|
|
} else {
|
|
|
|
|
return street.getCamera2Id();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Integer cameraId = street.getCamera1Id() != null && street.getCamera1Id() != 0 ? street.getCamera1Id() : street.getCamera2Id();
|
|
|
|
|
@ -562,17 +567,27 @@ public class PlcService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Integer getCameraByPlcCmdE(PlcCmdInfo plcCmdInfo, Integer leftRight) {
|
|
|
|
|
Street street = streetService.getStreetByPlcId(plcCmdInfo.getPlcId());
|
|
|
|
|
//判断单双伸 type=0 单伸 1为双伸
|
|
|
|
|
Integer type;
|
|
|
|
|
if (plcCmdInfo.getFromSeparation() == 1) {
|
|
|
|
|
return street.getCamera1Id();
|
|
|
|
|
} else {
|
|
|
|
|
return street.getCamera2Id();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@Resource
|
|
|
|
|
private LightSourceMapper lightSourceMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void webSocketSendInfo(PlcCmdInfo plcCmdInfo,String cmdCode) throws IOException {
|
|
|
|
|
public String 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);
|
|
|
|
|
return JSONObject.toJSONString(webSocketVo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Boolean check(PlcCmdInfo plcCmdInfo, String cmdCode, String wmsCode, String wmsTrayCode) {
|
|
|
|
|
@ -580,11 +595,13 @@ public class PlcService {
|
|
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
|
|
Street street = streetService.getStreetByPlcId(plcCmdInfo.getPlcId());
|
|
|
|
|
CronTab.putTime(street.getId());
|
|
|
|
|
plcCmdInfo.setStreetName(street.getName());
|
|
|
|
|
List<LightSource> lightSources = lightSourceMapper.selectList(new QueryWrapper<LightSource>().eq("street_id", street.getId()));
|
|
|
|
|
lightSources.forEach(lightSource -> {
|
|
|
|
|
HikControlSocket.openLight(lightSource.getIp(), lightSource.getPort(), configProperties.getLightSource().getIndex(), 1);
|
|
|
|
|
});
|
|
|
|
|
Integer cameraId = getCameraByPlcCmd(plcCmdInfo,plcCmdInfo.getLeftRight1());
|
|
|
|
|
log.info("盘点摄像头变化参数:"+plcCmdInfo.toString());
|
|
|
|
|
Integer cameraId = getCameraByPlcCmdE(plcCmdInfo, plcCmdInfo.getLeftRight1());
|
|
|
|
|
|
|
|
|
|
if (plcCmdInfo.getSeparation1() == 1 && configProperties.getScanCodeMode().getTray() == 2) {
|
|
|
|
|
//内测
|
|
|
|
|
@ -593,7 +610,7 @@ public class PlcService {
|
|
|
|
|
gyrateCameraByCode(cameraId, c);
|
|
|
|
|
} else {
|
|
|
|
|
String c = cmdCode + "1";
|
|
|
|
|
gyrateCameraByCode(cameraId, cmdCode);
|
|
|
|
|
gyrateCameraByCode(cameraId, c);
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(configProperties.getCameraConfig().getDelayCaptureTime());
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
@ -644,21 +661,44 @@ public class PlcService {
|
|
|
|
|
} else if (configProperties.getScanCodeMode().getTray() == 3) {
|
|
|
|
|
// //RFID
|
|
|
|
|
// RFID rfid = rfidService.getRFIDByPlc(street.getId(),plcCmdInfo.getLeftRight1());
|
|
|
|
|
Set<String> tags = new HashSet<>();
|
|
|
|
|
try {
|
|
|
|
|
RFIDCheck(plcCmdInfo);
|
|
|
|
|
RFIDCheck(plcCmdInfo,true);
|
|
|
|
|
Thread.sleep(1000 * configProperties.getRfid().getScanTime());
|
|
|
|
|
Set<String> tags = RFIDStop(plcCmdInfo);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
tags = RFIDStop(plcCmdInfo);
|
|
|
|
|
}
|
|
|
|
|
if (tags != null && tags.size() > 0 && tags.contains(wmsTrayCode)) {
|
|
|
|
|
|
|
|
|
|
trayCode = wmsTrayCode;
|
|
|
|
|
trayCheck = Boolean.TRUE;
|
|
|
|
|
if(! rfidLiveService.getRfidLive(plcCmdInfo,street,wmsTrayCode)){
|
|
|
|
|
|
|
|
|
|
RFID rfid = rfidMapper.selectOne(new QueryWrapper<RFID>().eq("street_id", street.getId()));
|
|
|
|
|
rfidLiveService.rfidRemoveLive(plcCmdInfo,street,rfid);
|
|
|
|
|
rfidLiveService.rfidSave(plcCmdInfo,trayCode,street,rfid);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.warn("sick ocr error:{}", "");
|
|
|
|
|
//查看数据库里数据
|
|
|
|
|
RfidLive rfidLive = rfidLiveService.getOne(new QueryWrapper<RfidLive>()
|
|
|
|
|
.eq("street_Id", street.getId())
|
|
|
|
|
.eq("direction", plcCmdInfo.getFromDirection())
|
|
|
|
|
.eq("side", plcCmdInfo.getSide1())
|
|
|
|
|
.eq("rfid_row", plcCmdInfo.getRow1())
|
|
|
|
|
.eq("rfid_column", plcCmdInfo.getRow1()));
|
|
|
|
|
if (ToolUtil.isNotEmpty(rfidLive) && ToolUtil.isNotEmpty(rfidLive.getRfidTrayCode()) && rfidLive.getRfidTrayCode().equals(wmsTrayCode)) {
|
|
|
|
|
trayCode = wmsTrayCode;
|
|
|
|
|
trayCheck = Boolean.TRUE;
|
|
|
|
|
log.info("数据库查询rfid", trayCode);
|
|
|
|
|
} else {
|
|
|
|
|
trayCode = "";
|
|
|
|
|
trayCheck = Boolean.FALSE;
|
|
|
|
|
log.warn("sick ocr error:{}",trayCode);
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
OrderInfo orderInfo = new OrderInfo(street, plcCmdInfo, 1, cmdCode);
|
|
|
|
|
Stock stock = stockMapper.getByStreetAndDirectionAndSideAndRowColumn(orderInfo.getStreetId(), plcCmdInfo.getFromDirection(), orderInfo.getSeparation(), orderInfo.getRow(), orderInfo.getColumn());
|
|
|
|
|
@ -732,26 +772,25 @@ public class PlcService {
|
|
|
|
|
checkLog(stock);
|
|
|
|
|
// StockCheckRunnable stockCheckRunnable = new StockCheckRunnable(street,plcCmdInfo,cmdCode,stockMapper,path,checkLogMapper,configProperties.getScanCodeMode().getGoods(),wmsCode,wmsTrayCode,trayCode,trayCheck,configProperties,sensorGun);
|
|
|
|
|
// threadPoolExecutor.execute(stockCheckRunnable);
|
|
|
|
|
|
|
|
|
|
//还原相机
|
|
|
|
|
gyrateCameraByCode(cameraId, "C5");
|
|
|
|
|
long end = System.currentTimeMillis();
|
|
|
|
|
long s = end - startTime;
|
|
|
|
|
log.info("time:{}millisecond", s);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
public Boolean checkRfid(PlcCmdInfo plcCmdInfo,String wmsTrayCode){
|
|
|
|
|
RFIDCheck(plcCmdInfo);
|
|
|
|
|
WebSocketVo<PlcCmdInfo> webSocketVo = WebSocketVo.<PlcCmdInfo>builder()
|
|
|
|
|
.message(plcCmdInfo)
|
|
|
|
|
.messageType("object")
|
|
|
|
|
.type("InventoryPush")
|
|
|
|
|
.build();
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(1000*configProperties.getRfid().getScanTime());
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
WebSocketServer.sendInfo(JSONObject.toJSONString(webSocketVo),"");
|
|
|
|
|
} catch (IOException 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;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void checkLog(Stock stock) {
|
|
|
|
|
CheckLog checkLog = new CheckLog();
|
|
|
|
|
checkLog.setCheckNum(stock.getCheckNum());
|
|
|
|
|
@ -770,23 +809,33 @@ public class PlcService {
|
|
|
|
|
checkLog.setLotnum(stock.getLotnum());
|
|
|
|
|
checkLogMapper.insert(checkLog);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void truncateStock() {
|
|
|
|
|
stockMapper.truncate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RFIDCheck(PlcCmdInfo plcCmdInfo){
|
|
|
|
|
/**
|
|
|
|
|
* 根据信息开启rfid链接
|
|
|
|
|
* @param plcCmdInfo 相关信息
|
|
|
|
|
* @param fromOrTo 确定方向
|
|
|
|
|
*/
|
|
|
|
|
public void RFIDCheck(PlcCmdInfo plcCmdInfo, boolean fromOrTo) {
|
|
|
|
|
Street street = streetService.getStreetByPlcId(plcCmdInfo.getPlcId());
|
|
|
|
|
if (street != null) {
|
|
|
|
|
//rfid不分左右,rfid使用同一ip和端口,依靠传递字符调整方向
|
|
|
|
|
RFID rfid = rfidService.getRFIDByPlc(street.getId(), null);
|
|
|
|
|
if (rfid != null) {
|
|
|
|
|
if (fromOrTo) {
|
|
|
|
|
RFIDStart(rfid.getIp(), rfid.getPort(), street.getId(), plcCmdInfo.getFromDirection());
|
|
|
|
|
}else
|
|
|
|
|
RFIDStart(rfid.getIp(), rfid.getPort(), street.getId(), plcCmdInfo.getToDirection());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RFIDStart(String ip, Integer port, Integer streetId, Integer direction) {
|
|
|
|
|
RFIDSocket rfidSocket = new RFIDSocket(ip, port);
|
|
|
|
|
log.info("rfid调用,ip:"+ip+";port:"+port);
|
|
|
|
|
rfidSocket.startCheck(direction);
|
|
|
|
|
rfidSocket.readData();
|
|
|
|
|
RFIDMap.put(streetId, rfidSocket);
|
|
|
|
|
@ -805,6 +854,21 @@ public class PlcService {
|
|
|
|
|
return tags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String RFIDStopGetRFID(PlcCmdInfo plcCmdInfo) {
|
|
|
|
|
|
|
|
|
|
Street street = streetService.getStreetByPlcId(plcCmdInfo.getPlcId());
|
|
|
|
|
RFIDSocket rfidSocket = RFIDMap.get(street.getId());
|
|
|
|
|
String tags = "";
|
|
|
|
|
if (rfidSocket != null) {
|
|
|
|
|
tags = rfidSocket.getTag();
|
|
|
|
|
log.info("tag:{}", tags);
|
|
|
|
|
rfidSocket.close();
|
|
|
|
|
RFIDMap.remove(street.getId());
|
|
|
|
|
}
|
|
|
|
|
return tags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ConfigProperties getConfigProperties() {
|
|
|
|
|
return configProperties;
|
|
|
|
|
}
|
|
|
|
|
|