@ -11,14 +11,16 @@ import com.zhehekeji.web.lib.*;
import com.zhehekeji.web.mapper.* ;
import com.zhehekeji.web.pojo.CameraPtzPojo ;
import com.zhehekeji.web.pojo.OrderVO ;
import com.zhehekeji.web.pojo.stock.StockStatus ;
import com.zhehekeji.web.service.RFID.RFIDMap ;
import com.zhehekeji.web.service.RFID.RFIDSocket ;
import com.zhehekeji.web.service.RFID.RFIDSocketFactory ;
import com.zhehekeji.web.service.client.ClientChanel ;
import com.zhehekeji.web.service.client.SCTransmission ;
import com.zhehekeji.web.service.client.* ;
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.ksec.KsecDataInfo ;
import com.zhehekeji.web.service.ksec.KsecInfo ;
import com.zhehekeji.web.service.ksec.KsecNettyClient ;
import com.zhehekeji.web.service.sick.SickSocket ;
import lombok.extern.slf4j.Slf4j ;
@ -38,6 +40,9 @@ import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingDeque ;
import java.util.concurrent.ThreadPoolExecutor ;
import java.util.concurrent.TimeUnit ;
import java.util.concurrent.locks.Lock ;
import java.util.concurrent.locks.ReentrantLock ;
import java.util.stream.Collectors ;
import static org.aspectj.weaver.tools.cache.SimpleCacheFactory.path ;
@ -642,13 +647,33 @@ public class PlcService {
}
Lock lock = new ReentrantLock ( ) ;
@Resource
private LightSourceMapper lightSourceMapper ;
public Boolean check ( PlcCmdInfo plcCmdInfo , String cmdCode , String wmsCode , String wmsTrayCode , String wmsCatagary ) {
long startTime = System . currentTimeMillis ( ) ;
Street street = streetService . getStreetByPlcId ( plcCmdInfo . getPlcId ( ) ) ;
//开始盘点具体货位
CheckLog checkLog = new CheckLog ( ) ;
checkLog . setStreetId ( street . getId ( ) ) ;
checkLog . setLotnum ( plcCmdInfo . getLotnum ( ) ) ;
checkLog . setDirection ( plcCmdInfo . getLeftRight1 ( ) ) ;
checkLog . setSide ( plcCmdInfo . getSide1 ( ) ) ;
checkLog . setRow ( plcCmdInfo . getRow1 ( ) ) ;
checkLog . setColumn ( plcCmdInfo . getColumn1 ( ) ) ;
checkLog . setWmsCode ( plcCmdInfo . getCode ( ) ) ;
checkLog . setTaskId ( ( plcCmdInfo . getTaskId ( ) ) ) ;
//默认未盘点
checkLog . setStatus ( StockStatus . PENDING . getStatus ( ) ) ;
checkLog . setCreateTime ( LocalDateTime . now ( ) ) ;
checkLog . setWmsCategory ( plcCmdInfo . getTypeNum ( ) ) ;
checkLog . setWmsCount ( plcCmdInfo . getQuantity ( ) ) ;
CronTab . putTime ( street . getId ( ) ) ;
List < LightSource > lightSources = lightSourceMapper . selectList ( new QueryWrapper < LightSource > ( ) . eq ( "street_id" , street . getId ( ) ) ) ;
lightSources . forEach ( lightSource - > {
@ -676,76 +701,26 @@ public class PlcService {
String path = PathUtil . createFileNameByRowColumn ( "jpg" , cameraId , plcCmdInfo . getRow1 ( ) , plcCmdInfo . getColumn1 ( ) ) ;
try {
cameraCapture ( cameraId , false , null , path ) ;
} catch ( NullPointerException e ) {
log . error ( "相机{}未连接无法拍照" , cameraId ) ;
}
checkLog . setPic ( path ) ;
checkLogMapper . insert ( checkLog ) ;
//托盘码
String trayCode = null ;
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 , true ) ;
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 ;
trayCheck = scan ( configProperties . getScanCodeMode ( ) . getTray ( ) , street , plcCmdInfo , checkLog , trayCode ) ;
} else {
trayCode = trayCode + "扫码枪识别异常" ;
trayCheck = Boolean . FALSE ;
log . warn ( "rfid error:{}" , trayCode ) ;
}
}
Boolean trayGoodCheck = Boolean. TRUE ;
String trayGoodCode = null ;
Boolean trayGoodCheck = scan ( configProperties . getScanCodeMode ( ) . getGoods ( ) , street , plcCmdInfo , checkLog , trayGoodCode ) ;
OrderInfo orderInfo = new OrderInfo ( street , plcCmdInfo , 1 , cmdCode ) ;
//扫货物
@ -782,7 +757,8 @@ public class PlcService {
}
}
}
} else if ( configProperties . getScanCodeMode ( ) . getGoods ( ) = = 3 ) {
} else
if ( configProperties . getScanCodeMode ( ) . getGoods ( ) = = 3 ) {
Set < String > tags = new HashSet < > ( ) ;
try {
RFIDCheck ( plcCmdInfo , true ) ;
@ -805,31 +781,49 @@ public class PlcService {
log . warn ( "rfid error:{}" , trayCode ) ;
}
} else if ( configProperties . getScanCodeMode ( ) . getGoods ( ) = = 4 ) {
//开始盘点
String goodLocation = orderInfo . getStreetId ( ) . toString ( ) + "_" + plcCmdInfo . getLeftRight1 ( ) . toString ( ) + "_" + orderInfo . getSeparation ( ) . toString ( ) + "_" + orderInfo . getRow ( ) . toString ( ) + "_" + orderInfo . getColumn ( ) ;
SCTransmission scTransmission = new SCTransmission ( street . getPlcId ( ) , plcCmdInfo . getTaskId ( ) , goodLocation , plcCmdInfo . getTypeNum ( ) , plcCmdInfo . getQuantity ( ) , "N" ) ;
String scTransmissionStr = scTransmission . toString ( ) ;
ClientChanel . write ( scTransmissionStr , street . getPlcId ( ) ) ;
} else
if ( configProperties . getScanCodeMode ( ) . getGoods ( ) = = 4 ) {
TransmissionPojo transmissionPojo = new TransmissionPojo ( checkLog , street ) ;
if ( ClientChanel . get ( plcCmdInfo . getPlcId ( ) ) ! = null ) {
ClientChanel . get ( plcCmdInfo . getPlcId ( ) ) . writeAndFlush ( transmissionPojo . toString ( TransmissionType . ST ) ) ;
} else {
log . error ( "未找到对应plc" + transmissionPojo . toString ( ) ) ;
}
//取货完成进行拍照
try {
Thread . sleep ( 500 ) ;
Thread . sleep ( 50L ) ;
//不为其他状态进入队列
if ( lock . tryLock ( ) ) {
//队列中没有任务,发送取图指令
//只采用队列,队列中有数据则自动发送
//模拟随行
if ( configProperties . isInventorySimulationFollow ( ) ) {
TransmissionPojo transmissionPojoFollow = new TransmissionPojo ( street , transmissionPojo . getRow ( ) , transmissionPojo . getColumn ( ) , transmissionPojo . getDirection ( ) , "" ) ;
String s = ( transmissionPojoFollow ) . toString ( TransmissionType . GPS ) ;
//放置到队列中,等待取图返回后删除
GetPhotoDelayExecutor . addCameraDelayTask ( street . getPlcId ( ) , s , configProperties . getQueueSpanTime ( ) , transmissionPojoFollow ) ;
}
//放置到队列中,等待取图返回后删除
GetPhotoDelayExecutor . addCameraDelayTask ( street . getPlcId ( ) , transmissionPojo . toString ( TransmissionType . GPS ) , configProperties . getQueueSpanTime ( ) , transmissionPojo ) ;
}
} catch ( InterruptedException e ) {
throw new RuntimeException ( e ) ;
log . error ( "取图命令 error" , e ) ;
} finally {
lock . unlock ( ) ;
log . info ( "盘点完成" ) ;
}
//滁州开始盘点即取货到位
SCTransmission scTransmission2 = new SCTransmission ( street . getPlcId ( ) , plcCmdInfo . getTaskId ( ) ) ;
String scTransmissionStr2 = scTransmission2 . toSC02String ( ) ;
ClientChanel . write ( scTransmissionStr2 , street . getPlcId ( ) ) ;
}
Stock stock = stockMapper . getByStreetAndDirectionAndSideAndRowColumn ( orderInfo . getStreetId ( ) , plcCmdInfo . getLeftRight1 ( ) , orderInfo . getSeparation ( ) , orderInfo . getRow ( ) , orderInfo . getColumn ( ) ) ;
String scanCode = null ;
//货物使用球机扫码
checkLog . setTrayCode ( trayCode ) ;
log . info ( "code:{}" , scanCode ) ;
//核对异常
Integer status = 1 ;
@ -837,6 +831,8 @@ public class PlcService {
if ( trayCheck & & trayGoodCheck ) {
status = 2 ;
}
checkLog . setStatus ( status ) ;
checkLogMapper . updateById ( checkLog ) ;
if ( stock = = null ) {
stock = Stock . builder ( )
. checkNum ( plcCmdInfo . getOrderNum ( ) )
@ -870,14 +866,138 @@ 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 ) ;
long timeLong = end - startTime ;
log . info ( "time:{}millisecond" , timeLong ) ;
return true ;
}
Boolean scan ( int type , Street street , PlcCmdInfo plcCmdInfo , CheckLog checkLog , String trayCode ) {
Boolean checkBoolean = true ;
if ( type = = 2 ) {
checkBoolean = Boolean . FALSE ;
log . info ( "扫码类型:" + configProperties . getScanCodeMode ( ) . getTray ( ) ) ;
//托盘使用sick扫码枪
SensorGun sensorGun = sensorService . getSensorByPlc ( street . getId ( ) , plcCmdInfo . getLeftRight1 ( ) ) ;
if ( sensorGun = = null ) {
trayCode = "扫码枪识别异常" ;
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 ( plcCmdInfo . getCode ( ) ) ) {
//托盘码为空,无货物
//只要扫码枪未识别出条码,即认为盘点正确
if ( StringUtils . isEmpty ( trayCode ) | | trayCode . equals ( "NoRead" ) ) {
trayCode = "" ;
checkBoolean = Boolean . TRUE ;
} else {
trayCode = "扫码枪识别异常" ;
checkBoolean = Boolean . FALSE ;
log . warn ( "sick ocr error:{}" , trayCode ) ;
}
} else {
if ( StringUtils . isEmpty ( trayCode ) | | trayCode . equals ( "NoRead" ) ) {
trayCode = "扫码枪识别异常" ;
checkBoolean = Boolean . FALSE ;
log . warn ( "sick ocr error:{}" , trayCode ) ;
} else {
//扫到就认为正常
checkBoolean = Boolean . TRUE ;
}
}
}
} else
if ( type = = 3 ) {
Set < String > tags = new HashSet < > ( ) ;
try {
RFIDCheck ( plcCmdInfo , true ) ;
Thread . sleep ( 1000 * configProperties . getRfid ( ) . getScanTime ( ) ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
} finally {
tags = RFIDStop ( plcCmdInfo ) ;
log . info ( "盘点rfid扫描结果: " + tags ) ;
}
if ( tags ! = null & & tags . contains ( plcCmdInfo . getCode ( ) ) ) {
//托盘码为空,无货物
//只要扫码枪未识别出条码,即认为盘点正确
trayCode = plcCmdInfo . getCode ( ) ;
checkBoolean = Boolean . TRUE ;
} else {
trayCode = trayCode + "扫码枪识别异常" ;
checkBoolean = Boolean . FALSE ;
log . warn ( "rfid error:{}" , trayCode ) ;
}
} else
if ( type = = 4 ) {
TransmissionPojo transmissionPojo = new TransmissionPojo ( checkLog , street ) ;
if ( ClientChanel . get ( plcCmdInfo . getPlcId ( ) ) ! = null ) {
ClientChanel . get ( plcCmdInfo . getPlcId ( ) ) . writeAndFlush ( transmissionPojo . toString ( TransmissionType . ST ) ) ;
} else {
log . error ( "未找到对应plc" + transmissionPojo . toString ( ) ) ;
}
//取货完成进行拍照
try {
Thread . sleep ( 50L ) ;
//不为其他状态进入队列
if ( lock . tryLock ( ) ) {
//队列中没有任务,发送取图指令
//只采用队列,队列中有数据则自动发送
//模拟随行
if ( configProperties . isInventorySimulationFollow ( ) ) {
TransmissionPojo transmissionPojoFollow = new TransmissionPojo ( street , transmissionPojo . getRow ( ) , transmissionPojo . getColumn ( ) , transmissionPojo . getDirection ( ) , "" ) ;
String s = ( transmissionPojoFollow ) . toString ( TransmissionType . GPS ) ;
//放置到队列中,等待取图返回后删除
GetPhotoDelayExecutor . addCameraDelayTask ( street . getPlcId ( ) , s , configProperties . getQueueSpanTime ( ) , transmissionPojoFollow ) ;
}
//放置到队列中,等待取图返回后删除
GetPhotoDelayExecutor . addCameraDelayTask ( street . getPlcId ( ) , transmissionPojo . toString ( TransmissionType . GPS ) , configProperties . getQueueSpanTime ( ) , transmissionPojo ) ;
}
} catch ( InterruptedException e ) {
log . error ( "取图命令 error" , e ) ;
} finally {
lock . unlock ( ) ;
log . info ( "盘点完成" ) ;
}
}
return checkBoolean ;
}
public KsecInfo getKsecDataInfo ( TransmissionPojo transmissionPojo , String type ) {
KsecDataInfo ksecDataInfo = new KsecDataInfo ( ) ;
CheckLog checkLog = checkLogMapper . selectById ( transmissionPojo . getCheckId ( ) ) ;
if ( checkLog ! = null ) {
ksecDataInfo . setLotnum ( checkLog . getLotnum ( ) ) ;
ksecDataInfo . setSRMNumber ( transmissionPojo . getStreetNumber ( ) ) ;
ksecDataInfo . setCmdName ( type ) ;
ksecDataInfo . setTaskId ( checkLog . getTaskId ( ) . toString ( ) ) ;
ksecDataInfo . setFromDirection ( checkLog . getDirection ( ) ) ;
ksecDataInfo . setFromColumn ( checkLog . getColumn ( ) ) ;
ksecDataInfo . setFromRow ( checkLog . getRow ( ) ) ;
ksecDataInfo . setFromSide ( checkLog . getSide ( ) ) ;
ksecDataInfo . setCode ( checkLog . getCode ( ) ) ;
ksecDataInfo . setTrayCode ( checkLog . getTrayCode ( ) ) ;
ksecDataInfo . setLotnum ( checkLog . getLotnum ( ) ) ;
}
KsecInfo ksecInfo = new KsecInfo ( "KC" , "E" , ksecDataInfo ) ;
return ksecInfo ;
}
public void checkLog ( Stock stock ) {
CheckLog checkLog = new CheckLog ( ) ;
checkLog . setCheckNum ( stock . getCheckNum ( ) ) ;
@ -984,4 +1104,37 @@ public class PlcService {
}
checkLog ( stock ) ;
}
public void visualCalculationResults ( TransmissionPojo transmissionPojo ) {
CheckLog checkLog = checkLogMapper . selectById ( transmissionPojo . getCheckId ( ) ) ;
Stock stock = stockMapper . selectOne ( new QueryWrapper < Stock > ( ) . eq ( "check_Num" , checkLog . getId ( ) ) ) ;
Street street = streetService . getStreetByPlcId ( transmissionPojo . getStreetNumber ( ) ) ;
if ( transmissionPojo . getResult ( ) ! = null & & transmissionPojo . getResult ( ) = = 1 ) {
checkLog . setStatusVision ( StockStatus . SUCCESS . getStatus ( ) ) ;
stock . setStatusVision ( StockStatus . SUCCESS . getStatus ( ) ) ;
} else {
checkLog . setStatusVision ( StockStatus . ERROR . getStatus ( ) ) ;
stock . setStatusVision ( StockStatus . ERROR . getStatus ( ) ) ;
stock . setCount ( transmissionPojo . getCount ( ) ) ;
stock . setCategory ( transmissionPojo . getCategory ( ) ) ;
}
if ( transmissionPojo . getPcd ( ) ! = null & & ! "" . equals ( transmissionPojo . getPcd ( ) ) ) {
stock . setPcd ( "http://" + street . getPlcIp ( ) + ":8007" + transmissionPojo . getPcd ( ) ) ;
}
if ( transmissionPojo . getPicsPath ( ) ! = null & & transmissionPojo . getPicsPath ( ) . size ( ) > 0 ) {
String pics = transmissionPojo . getPicsPath ( ) . stream ( ) . map ( v - > {
return "http://" + street . getPlcIp ( ) + ":8007" + v ;
} ) . collect ( Collectors . joining ( ";" ) ) ;
checkLog . setPic ( pics ) ;
stock . setCheckPic ( pics ) ;
}
checkLogMapper . updateById ( checkLog ) ;
stockMapper . updateById ( stock ) ;
}
public void saveFollowPhoto ( TransmissionPojo transmissionPojo ) {
}
}