|
|
|
|
@ -1,6 +1,5 @@
|
|
|
|
|
package com.zhehekeji.web.service;
|
|
|
|
|
|
|
|
|
|
import codeDetector.BarcodeDetector;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.zhehekeji.common.util.PathUtil;
|
|
|
|
|
import com.zhehekeji.web.config.ConfigProperties;
|
|
|
|
|
@ -10,9 +9,6 @@ import com.zhehekeji.web.mapper.*;
|
|
|
|
|
import com.zhehekeji.web.pojo.OrderVO;
|
|
|
|
|
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 lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@ -21,11 +17,8 @@ import org.springframework.util.StringUtils;
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
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;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
@ -71,6 +64,8 @@ public class PlcService {
|
|
|
|
|
private RFIDService rfidService;
|
|
|
|
|
@Resource
|
|
|
|
|
private CheckLogMapper checkLogMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private CheckStreetSummaryMapper checkStreetSummaryMapper;
|
|
|
|
|
|
|
|
|
|
private static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1,8,200,TimeUnit.MINUTES,new ArrayBlockingQueue<>(100000));
|
|
|
|
|
|
|
|
|
|
@ -550,144 +545,28 @@ public class PlcService {
|
|
|
|
|
@Resource
|
|
|
|
|
private LightSourceMapper lightSourceMapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 给到客户端
|
|
|
|
|
* @param plcCmdInfo
|
|
|
|
|
* @param cmdCode
|
|
|
|
|
* @param wmsCode
|
|
|
|
|
* @param wmsTrayCode
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Boolean check(PlcCmdInfo plcCmdInfo,String cmdCode,String wmsCode,String wmsTrayCode){
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
if(plcCmdInfo.getSeparation1() == 1 && configProperties.getScanCodeMode().getTray() == 2){
|
|
|
|
|
//内测
|
|
|
|
|
String c = cmdCode + "-" + plcCmdInfo.getLeftRightStr(1) + "-IN";
|
|
|
|
|
log.info("camera ptz"+c);
|
|
|
|
|
gyrateCameraByCode(cameraId, c);
|
|
|
|
|
}else {
|
|
|
|
|
gyrateCameraByCode(cameraId, cmdCode);
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(configProperties.getCameraConfig().getDelayCaptureTime());
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String path = PathUtil.createFileNameByRowColumn("jpg",cameraId,plcCmdInfo.getRow1(),plcCmdInfo.getColumn1());
|
|
|
|
|
cameraCapture(cameraId,false,null,path);
|
|
|
|
|
//托盘码
|
|
|
|
|
String trayCode = null;
|
|
|
|
|
Boolean trayCheck = Boolean.TRUE;
|
|
|
|
|
//如果是用扫码枪 扫 托盘码,就直接扫
|
|
|
|
|
//if(configProperties.getScanCodeMode().getTray() == 2){
|
|
|
|
|
SensorGun sensorGun = sensorService.getSensorByPlc(street.getId(),plcCmdInfo.getLeftRight1());
|
|
|
|
|
if(plcCmdInfo.getSeparation1() == 1 && configProperties.getScanCodeMode().getTray() == 2){
|
|
|
|
|
//托盘使用sick扫码枪
|
|
|
|
|
|
|
|
|
|
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 = wmsTrayCode.equals(trayCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}else if(configProperties.getScanCodeMode().getTray() == 3){
|
|
|
|
|
//RFID
|
|
|
|
|
RFID rfid = rfidService.getRFIDByPlc(street.getId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
OrderInfo orderInfo = new OrderInfo(street,plcCmdInfo,1,cmdCode);
|
|
|
|
|
Stock stock = stockMapper.getByStreetAndDirectionAndSideAndRowColumn(orderInfo.getStreetId(),orderInfo.getLeftRight(),orderInfo.getSeparation(),orderInfo.getRow(),orderInfo.getColumn());
|
|
|
|
|
String scanCode = null;
|
|
|
|
|
Boolean codeCheck = Boolean.TRUE;
|
|
|
|
|
Boolean trayCodeCheck = Boolean.TRUE;
|
|
|
|
|
//货物使用球机扫码
|
|
|
|
|
|
|
|
|
|
if(configProperties.getScanCodeMode().getTray() == 2 && plcCmdInfo.getSeparation1() == 2){
|
|
|
|
|
//托盘使用球机扫码
|
|
|
|
|
if("".equals(wmsTrayCode)){
|
|
|
|
|
//空货物的处理
|
|
|
|
|
//如果系统货物为空,则只要扫码识别未出结果,就认为无货物
|
|
|
|
|
trayCode = BarcodeDetector.detectBestCodeUntilOK(configProperties.getSavePath().getMediaPath()+path,configProperties.getScanCodeMode().getTrayCodeTypes());
|
|
|
|
|
log.info("tray code:{},sys trayCode:{}",trayCode,wmsTrayCode);
|
|
|
|
|
if(StringUtils.isEmpty(trayCode)|| trayCode.equals("Unrecognized")){
|
|
|
|
|
trayCheck = Boolean.TRUE;
|
|
|
|
|
trayCode = "";
|
|
|
|
|
}else {
|
|
|
|
|
trayCheck = wmsTrayCode.equals(trayCode);
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
trayCode = BarcodeDetector.detectBestCodeUntilOK(configProperties.getSavePath().getMediaPath()+path,configProperties.getScanCodeMode().getTrayCodeTypes());
|
|
|
|
|
if(StringUtils.isEmpty(trayCode)){
|
|
|
|
|
log.error("row:{},cloumn:{}",plcCmdInfo.getRow1(),plcCmdInfo.getColumn1());
|
|
|
|
|
log.error("detectBestBarCode:{}",trayCode);
|
|
|
|
|
trayCode = "识别异常";
|
|
|
|
|
trayCheck = Boolean.FALSE;
|
|
|
|
|
}else {
|
|
|
|
|
trayCheck = wmsTrayCode.equals(trayCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
log.info("code:{}",scanCode);
|
|
|
|
|
//核对异常
|
|
|
|
|
Integer status = 1;
|
|
|
|
|
//托盘和货物都正确
|
|
|
|
|
if(trayCheck && codeCheck){
|
|
|
|
|
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());
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
long end = System.currentTimeMillis();
|
|
|
|
|
long s = end - startTime;
|
|
|
|
|
log.info("time:{}millisecond",s);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void checkLog(Stock stock){
|
|
|
|
|
CheckLog checkLog = new CheckLog();
|
|
|
|
|
checkLog.setCheckNum(stock.getCheckNum());
|
|
|
|
|
|