|
|
|
|
@ -15,6 +15,8 @@ import com.zhehekeji.web.service.client.ClientChanel;
|
|
|
|
|
import com.zhehekeji.web.service.client.ECResultMessage;
|
|
|
|
|
import com.zhehekeji.web.service.client.SCTransmission;
|
|
|
|
|
import com.zhehekeji.web.entity.EmptyCheckPic;
|
|
|
|
|
import com.zhehekeji.web.service.hikLightSource.HikControlSocket;
|
|
|
|
|
import com.zhehekeji.web.service.sick.SickSocket;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@ -254,6 +256,223 @@ public class PlcService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Boolean check(PlcCmdInfo plcCmdInfo,String cmdCode,String wmsCode,String wmsTrayCode,String wmsCatagary){
|
|
|
|
|
|
|
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
|
|
Street street = streetService.getStreetByPlcId(plcCmdInfo.getPlcId());
|
|
|
|
|
CronTab.putTime(street.getId());
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
//蜜雪冰城拍摄货物顶部时用同侧相机
|
|
|
|
|
Integer leftRightTop = plcCmdInfo.getLeftRight1() == 1 ? 2 : 1;
|
|
|
|
|
Integer cameraIdTop = getCameraByPlcCmd(plcCmdInfo, leftRightTop);
|
|
|
|
|
if(plcCmdInfo.getSeparation1() == 1 && configProperties.getScanCodeMode().getTray() == 2){
|
|
|
|
|
//内测
|
|
|
|
|
String c = cmdCode + "-" + plcCmdInfo.getLeftRightStr(1) + "-IN";
|
|
|
|
|
log.info("camera ptz"+c);
|
|
|
|
|
gyrateCameraByCode(cameraIdTop, c);
|
|
|
|
|
}else {
|
|
|
|
|
log.info("camera ptz"+cmdCode);
|
|
|
|
|
gyrateCameraByCode(cameraIdTop, cmdCode);
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(configProperties.getCameraConfig().getDelayCaptureTime());
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String path = PathUtil.createFileNameByRowColumn("jpg", cameraId, plcCmdInfo.getRow1(), plcCmdInfo.getColumn1());
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
cameraCapture(cameraId, false, null, path);
|
|
|
|
|
} catch (NullPointerException e) {
|
|
|
|
|
log.error("相机{}未连接无法拍照", cameraId);
|
|
|
|
|
}
|
|
|
|
|
//托盘码
|
|
|
|
|
String trayCode = "";
|
|
|
|
|
Boolean trayCheck = Boolean.TRUE;
|
|
|
|
|
//扫托盘码
|
|
|
|
|
if(configProperties.getScanCodeMode().getTray() == 2) {
|
|
|
|
|
log.info("扫码类型:" + configProperties.getScanCodeMode().getTray());
|
|
|
|
|
//托盘使用sick扫码枪
|
|
|
|
|
SensorGun sensorGun = sensorService.getSensorByPlc(street.getId(), plcCmdInfo.getLeftRight1());
|
|
|
|
|
if (sensorGun == null) {
|
|
|
|
|
trayCode = "扫码枪未配置";
|
|
|
|
|
trayCheck = Boolean.FALSE;
|
|
|
|
|
log.error("no sensor gun config in database ,street id:{},direction:{}", street.getId(), plcCmdInfo.getLeftRight1());
|
|
|
|
|
} else {
|
|
|
|
|
trayCode = SickSocket.readOCR(sensorGun.getIp(), sensorGun.getPort());
|
|
|
|
|
log.info("sensor tray code:{}", trayCode);
|
|
|
|
|
if ("".equals(wmsTrayCode)) {
|
|
|
|
|
//托盘码为空,无货物
|
|
|
|
|
//只要扫码枪未识别出条码,即认为盘点正确
|
|
|
|
|
if (StringUtils.isEmpty(trayCode) || trayCode.equals("NoRead")) {
|
|
|
|
|
trayCode = "无货物";
|
|
|
|
|
trayCheck = Boolean.TRUE;
|
|
|
|
|
} else {
|
|
|
|
|
trayCode = "扫码枪识别异常";
|
|
|
|
|
trayCheck = Boolean.FALSE;
|
|
|
|
|
log.warn("sick ocr error:{}", trayCode);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (StringUtils.isEmpty(trayCode) || trayCode.equals("NoRead")) {
|
|
|
|
|
trayCode = "扫码枪识别异常";
|
|
|
|
|
trayCheck = Boolean.FALSE;
|
|
|
|
|
log.warn("sick ocr error:{}", trayCode);
|
|
|
|
|
} else {
|
|
|
|
|
//扫到就认为正常
|
|
|
|
|
trayCheck = Boolean.TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else
|
|
|
|
|
if(configProperties.getScanCodeMode().getTray() == 3){
|
|
|
|
|
//扫到的码
|
|
|
|
|
Set<String> tags = new HashSet<>();
|
|
|
|
|
try {
|
|
|
|
|
RFIDCheck(plcCmdInfo);
|
|
|
|
|
Thread.sleep(1000 * configProperties.getRfid().getScanTime());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
tags = RFIDStop(plcCmdInfo);
|
|
|
|
|
log.info("盘点rfid扫描结果:" + tags);
|
|
|
|
|
}
|
|
|
|
|
if (tags !=null && tags.contains(wmsTrayCode)) {
|
|
|
|
|
//托盘码为空,无货物
|
|
|
|
|
//只要扫码枪未识别出条码,即认为盘点正确
|
|
|
|
|
trayCode = wmsTrayCode;
|
|
|
|
|
trayCheck = Boolean.TRUE;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
trayCode = trayCode+ "扫码枪识别异常";
|
|
|
|
|
trayCheck = Boolean.FALSE;
|
|
|
|
|
log.warn("rfid error:{}", trayCode);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
Boolean trayGoodCheck = Boolean.TRUE;
|
|
|
|
|
|
|
|
|
|
//扫货物
|
|
|
|
|
if(configProperties.getScanCodeMode().getGoods() == 2) {
|
|
|
|
|
log.info("扫码类型:" + configProperties.getScanCodeMode().getTray());
|
|
|
|
|
//托盘使用sick扫码枪
|
|
|
|
|
SensorGun sensorGun = sensorService.getSensorByPlc(street.getId(), plcCmdInfo.getLeftRight1());
|
|
|
|
|
if (sensorGun == null) {
|
|
|
|
|
trayCode = "扫码枪识别异常";
|
|
|
|
|
trayGoodCheck = Boolean.FALSE;
|
|
|
|
|
log.error("no sensor gun config in database ,street id:{},direction:{}", street.getId(), plcCmdInfo.getLeftRight1());
|
|
|
|
|
} else {
|
|
|
|
|
trayCode = SickSocket.readOCR(sensorGun.getIp(), sensorGun.getPort());
|
|
|
|
|
log.info("sensor tray code:{}", trayCode);
|
|
|
|
|
if ("".equals(wmsTrayCode)) {
|
|
|
|
|
//托盘码为空,无货物
|
|
|
|
|
//只要扫码枪未识别出条码,即认为盘点正确
|
|
|
|
|
if (StringUtils.isEmpty(trayCode) || trayCode.equals("NoRead")) {
|
|
|
|
|
trayCode = "";
|
|
|
|
|
trayGoodCheck = Boolean.TRUE;
|
|
|
|
|
} else {
|
|
|
|
|
trayCode = "扫码枪识别异常";
|
|
|
|
|
trayGoodCheck = Boolean.FALSE;
|
|
|
|
|
log.warn("sick ocr error:{}", trayCode);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (StringUtils.isEmpty(trayCode) || trayCode.equals("NoRead")) {
|
|
|
|
|
trayCode = "扫码枪识别异常";
|
|
|
|
|
trayGoodCheck = Boolean.FALSE;
|
|
|
|
|
log.warn("sick ocr error:{}", trayCode);
|
|
|
|
|
} else {
|
|
|
|
|
//扫到就认为正常
|
|
|
|
|
trayGoodCheck = Boolean.TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else if(configProperties.getScanCodeMode().getGoods() == 3){
|
|
|
|
|
Set<String> tags = new HashSet<>();
|
|
|
|
|
try {
|
|
|
|
|
RFIDCheck(plcCmdInfo);
|
|
|
|
|
Thread.sleep(1000 * configProperties.getRfid().getScanTime());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
tags = RFIDStop(plcCmdInfo);
|
|
|
|
|
log.info("盘点rfid扫描结果:" + tags);
|
|
|
|
|
}
|
|
|
|
|
if (tags !=null && tags.contains(wmsTrayCode)) {
|
|
|
|
|
//托盘码为空,无货物
|
|
|
|
|
//只要扫码枪未识别出条码,即认为盘点正确
|
|
|
|
|
trayCode = wmsTrayCode;
|
|
|
|
|
trayGoodCheck = Boolean.TRUE;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
trayCode = trayCode+ "扫码枪识别异常";
|
|
|
|
|
trayGoodCheck = Boolean.FALSE;
|
|
|
|
|
log.warn("rfid error:{}", trayCode);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OrderInfo orderInfo = new OrderInfo(street, plcCmdInfo, 1, cmdCode);
|
|
|
|
|
Stock stock = stockMapper.getByStreetAndDirectionAndSideAndRowColumn(orderInfo.getStreetId(), plcCmdInfo.getLeftRight1(), orderInfo.getSeparation(), orderInfo.getRow(), orderInfo.getColumn());
|
|
|
|
|
String scanCode = null;
|
|
|
|
|
|
|
|
|
|
//货物使用球机扫码
|
|
|
|
|
|
|
|
|
|
log.info("code:{}", scanCode);
|
|
|
|
|
//核对异常
|
|
|
|
|
Integer status = 1;
|
|
|
|
|
//托盘和货物都正确
|
|
|
|
|
if (trayCheck && trayGoodCheck ) {
|
|
|
|
|
status = 2;
|
|
|
|
|
}
|
|
|
|
|
if (stock == null) {
|
|
|
|
|
stock = Stock.builder()
|
|
|
|
|
.checkNum(plcCmdInfo.getOrderNum())
|
|
|
|
|
.lotnum(plcCmdInfo.getLotnum())
|
|
|
|
|
.code(scanCode)
|
|
|
|
|
.wmsCode(wmsCode)
|
|
|
|
|
.wmsTrayCode(wmsTrayCode)
|
|
|
|
|
.trayCode(trayCode)
|
|
|
|
|
.streetId(orderInfo.getStreetId())
|
|
|
|
|
.direction(plcCmdInfo.getLeftRight1())
|
|
|
|
|
.side(orderInfo.getSeparation())
|
|
|
|
|
.row(orderInfo.getRow())
|
|
|
|
|
.column(orderInfo.getColumn())
|
|
|
|
|
.status(status)
|
|
|
|
|
.checkPic(path)
|
|
|
|
|
.exportTime(LocalDateTime.now()).build();
|
|
|
|
|
stockMapper.insert(stock);
|
|
|
|
|
} else {
|
|
|
|
|
stock.setStatus(status);
|
|
|
|
|
stock.setLotnum(plcCmdInfo.getLotnum());
|
|
|
|
|
stock.setExportTime(LocalDateTime.now());
|
|
|
|
|
stock.setCheckPic(path);
|
|
|
|
|
stock.setCheckNum(plcCmdInfo.getOrderNum());
|
|
|
|
|
stock.setTrayCode(trayCode);
|
|
|
|
|
stock.setWmsTrayCode(wmsTrayCode);
|
|
|
|
|
stock.setCode(scanCode);
|
|
|
|
|
stock.setWmsCode(wmsCode);
|
|
|
|
|
stockMapper.updateById(stock);
|
|
|
|
|
}
|
|
|
|
|
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 void gyrateCamera(PlcCmdInfo plcCmdInfo,String code){
|
|
|
|
|
Street street = streetService.getStreetByPlcId(plcCmdInfo.getPlcId());
|
|
|
|
|
if(street == null){
|
|
|
|
|
|