@ -2,20 +2,21 @@ package com.zhehekeji.web.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.zhehekeji.common.util.PathUtil ;
import com.zhehekeji.core.pojo.Result ;
import com.zhehekeji.web.config.ConfigProperties ;
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.camera.CameraPtzPojo ;
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.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.client.ClientChanel ;
import com.zhehekeji.web.service.client.TransmissionPojo ;
import com.zhehekeji.web.service.ksec.KsecDataInfo ;
import com.zhehekeji.web.service.ksec.KsecInfo ;
import com.zhehekeji.web.service.lbScanCode.ReentrantLockExample ;
import com.zhehekeji.web.service.sick.SickSocket ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.beans.BeanUtils ;
@ -24,13 +25,13 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils ;
import javax.annotation.Resource ;
import java.net.SocketTimeoutException ;
import java.time.Duration ;
import java.time.LocalDateTime ;
import java.util.* ;
import java.util.concurrent.ArrayBlockingQueue ;
import java.util.concurrent.ThreadPoolExecutor ;
import java.util.concurrent.TimeUnit ;
import java.util.stream.Collectors ;
/ * *
* @Description plc 信 号 指 令 处 理 类
@ -157,6 +158,8 @@ public class PlcService {
}
}
/ * *
* 工 单 结 束 信 息
* 判 断 有 没 有 告 警 , 有 告 警 的 不 做 处 理
@ -341,6 +344,81 @@ public class PlcService {
}
}
}
@Resource
ReentrantLockExample reentrantLockExample ;
String scan ( PlcCmdInfo plcCmdInfo , Street street , String path ) {
Boolean trayCheck = Boolean . FALSE ;
String trayCode = "" ;
log . info ( "扫码类型:" + configProperties . getScanCodeMode ( ) . getTray ( ) ) ;
//使用sick扫码枪
if ( plcCmdInfo . getSeparation1 ( ) = = 1 ) {
//托盘使用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 ( plcCmdInfo . getWmsCode ( ) ) ) {
//托盘码为空,无货物
//只要扫码枪未识别出条码,即认为盘点正确
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 {
//扫到与货码相同
if ( trayCode . equals ( plcCmdInfo . getWmsCode ( ) ) ) {
trayCheck = Boolean . TRUE ;
}
}
}
}
} else {
trayCode = reentrantLockExample . identify ( path , configProperties . getIntelliBink ( ) . getIp ( ) , configProperties . getIntelliBink ( ) . getPort ( ) ) ;
if ( trayCode ! = null & & ! "" . equals ( trayCode ) ) {
if ( "" . equals ( plcCmdInfo . getWmsCode ( ) ) ) {
//托盘码为空,无货物
//只要扫码枪未识别出条码,即认为盘点正确
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 {
//扫到与货码相同
if ( trayCode . equals ( plcCmdInfo . getWmsCode ( ) ) ) {
trayCheck = Boolean . TRUE ;
}
}
}
}
}
plcCmdInfo . setTrayCode ( trayCode ) ;
return trayCode ;
}
public Boolean check ( PlcCmdInfo plcCmdInfo , String cmdCode , String wmsCode , String wmsTrayCode , String wmsCatagary ) {
@ -485,7 +563,8 @@ public class PlcService {
}
}
}
} else if ( configProperties . getScanCodeMode ( ) . getGoods ( ) = = 3 ) {
} else
if ( configProperties . getScanCodeMode ( ) . getGoods ( ) = = 3 ) {
Set < String > tags = new HashSet < > ( ) ;
try {
RFIDCheck ( plcCmdInfo ) ;
@ -858,84 +937,84 @@ public class PlcService {
* @param scTransmission
* @return
* /
public Stock checkStart ( SCTransmission scTransmission ) {
log . info ( "【开始盘点货位】save stock info ,taskId:{},SRMNumber:{}, goodsLocation:{}" , scTransmission . getTaskNo ( ) , scTransmission . getSRMNumber ( ) , scTransmission . getGoodsLocation ( ) ) ;
Street street = streetService . getStreetByPlcId ( scTransmission . getSRMNumber ( ) ) ;
Integer row = Integer . valueOf ( scTransmission . getGoodsLocation ( ) . substring ( 8 , 10 ) ) ;
Integer column = Integer . valueOf ( scTransmission . getGoodsLocation ( ) . substring ( 5 , 8 ) ) ;
Integer leftRight = Integer . valueOf ( scTransmission . getGoodsLocation ( ) . substring ( 4 , 5 ) ) ;
Integer inout = Integer . valueOf ( scTransmission . getGoodsLocation ( ) . substring ( 11 , 12 ) ) ;
Stock old = stockMapper . getByStreetAndDirectionAndSideAndRowColumn ( street . getId ( ) , leftRight , inout , row , column ) ;
if ( old = = null ) {
old = new Stock ( ) ;
old . setCount ( null ) ;
old . setCode ( null ) ;
old . setCategory ( null ) ;
old . setCheckNum ( scTransmission . getTaskNo ( ) ) ;
old . setLotnum ( scTransmission . getTaskNo ( ) ) ;
old . setRow ( row ) ;
old . setColumn ( column ) ;
old . setDirection ( leftRight ) ;
old . setSide ( inout ) ;
old . setWmsCode ( scTransmission . getGoodsLocation ( ) ) ;
old . setWmsCategory ( scTransmission . getCategory ( ) ) ;
old . setWmsCount ( scTransmission . getCount ( ) ) ;
old . setStreetId ( street . getId ( ) ) ;
old . setExportTime ( LocalDateTime . now ( ) ) ;
old . setWmsTrayCode ( "" ) ;
stockMapper . insert ( old ) ;
} else {
old . setLotnum ( scTransmission . getTaskNo ( ) ) ;
old . setExportTime ( LocalDateTime . now ( ) ) ;
old . setWmsCode ( scTransmission . getGoodsLocation ( ) ) ;
old . setWmsCount ( scTransmission . getCount ( ) ) ;
old . setCheckNum ( scTransmission . getTaskNo ( ) ) ;
old . setWmsTrayCode ( "" ) ;
stockMapper . updateById ( old ) ;
}
return old ;
}
/ * *
* 保 存 盘 点 结 果
* @param scTransmission
* @return
* /
public Stock checkEnd ( SCTransmission scTransmission ) {
log . info ( "【盘点货位结果返回】update stock info ,taskId:{},SRMNumber:{},goodsLocation:{}" , scTransmission . getTaskNo ( ) , scTransmission . getSRMNumber ( ) , scTransmission . getGoodsLocation ( ) ) ;
Street street = streetService . getStreetByPlcId ( scTransmission . getSRMNumber ( ) ) ;
Integer row = Integer . valueOf ( scTransmission . getGoodsLocation ( ) . substring ( 8 , 10 ) ) ;
Integer column = Integer . valueOf ( scTransmission . getGoodsLocation ( ) . substring ( 5 , 8 ) ) ;
Integer leftRight = Integer . valueOf ( scTransmission . getGoodsLocation ( ) . substring ( 4 , 5 ) ) ;
Integer inout = Integer . valueOf ( scTransmission . getGoodsLocation ( ) . substring ( 11 , 12 ) ) ;
Stock stock = stockMapper . getByStreetAndDirectionAndSideAndRowColumn ( street . getId ( ) , leftRight , inout , row , column ) ;
if ( stock ! = null ) {
//暂时不盘点数量
//stock.setCount(scTransmission.getRstCount());
stock . setCount ( scTransmission . getRstCategory ( ) . equals ( stock . getWmsCategory ( ) ) ? scTransmission . getCount ( ) : 0 ) ;
stock . setCategory ( scTransmission . getRstCategory ( ) ) ;
stock . setCode ( scTransmission . getGoodsLocation ( ) ) ;
stock . setWmsCategory ( scTransmission . getCategory ( ) ) ;
//盘点正确 : 2
//盘点异常 : 1
//暂时不盘点数量
Integer status = scTransmission . getRstCategory ( ) . equals ( stock . getWmsCategory ( ) ) ? 2 : 1 ;
//Integer status = ;
stock . setStatus ( status ) ;
stock . setTrayCode ( scTransmission . getTrayNo ( ) ) ;
stockMapper . updateById ( stock ) ;
log . info ( "update check info,taskId:{},SRMNumber:{},goodsLocation:{}" , stock . getCheckNum ( ) , scTransmission . getSRMNumber ( ) , scTransmission . getGoodsLocation ( ) ) ;
} else {
log . info ( "check end,but no stock info ,taskId:{},SRMNumber:{},goodsLocation:{}" , scTransmission . getTaskNo ( ) , scTransmission . getSRMNumber ( ) , scTransmission . getGoodsLocation ( ) ) ;
stock = new Stock ( ) ;
stock . setCount ( scTransmission . getCount ( ) ) ;
stock . setCode ( scTransmission . getCode ( ) ) ;
stock . setStatus ( 1 ) ;
}
// checkLog(stock);
return stock ;
}
// public Stock checkStart(SCTransmission scTransmission){
// log.info("【开始盘点货位】save stock info ,taskId:{},SRMNumber:{}, goodsLocation:{}",scTransmission.getTaskNo(),scTransmission.getSRMNumber(),scTransmission.getGoodsLocation());
// Street street = streetService.getStreetByPlcId(scTransmission.getSRMNumber());
// Integer row = Integer.valueOf(scTransmission.getGoodsLocation().substring(8,10));
// Integer column = Integer.valueOf(scTransmission.getGoodsLocation().substring(5,8));
// Integer leftRight = Integer.valueOf(scTransmission.getGoodsLocation().substring(4,5));
// Integer inout = Integer.valueOf(scTransmission.getGoodsLocation().substring(11,12));
// Stock old = stockMapper.getByStreetAndDirectionAndSideAndRowColumn(street.getId(),leftRight,inout,row,column);
// if(old == null){
// old = new Stock();
// old.setCount(null);
// old.setCode(null);
// old.setCategory(null);
// old.setCheckNum(scTransmission.getTaskNo());
// old.setLotnum(scTransmission.getTaskNo());
// old.setRow(row);
// old.setColumn(column);
// old.setDirection(leftRight);
// old.setSide(inout);
// old.setWmsCode(scTransmission.getGoodsLocation());
// old.setWmsCategory(scTransmission.getCategory());
// old.setWmsCount(scTransmission.getCount());
// old.setStreetId(street.getId());
// old.setExportTime(LocalDateTime.now());
// old.setWmsTrayCode("");
// stockMapper.insert(old);
// }else {
// old.setLotnum(scTransmission.getTaskNo());
// old.setExportTime(LocalDateTime.now());
// old.setWmsCode(scTransmission.getGoodsLocation());
// old.setWmsCount(scTransmission.getCount());
// old.setCheckNum(scTransmission.getTaskNo());
// old.setWmsTrayCode("");
// stockMapper.updateById(old);
// }
// return old;
// }
//
// /**
// * 保存盘点结果
// * @param scTransmission
// * @return
// */
// public Stock checkEnd(SCTransmission scTransmission){
// log.info("【盘点货位结果返回】update stock info ,taskId:{},SRMNumber:{},goodsLocation:{}",scTransmission.getTaskNo(),scTransmission.getSRMNumber(),scTransmission.getGoodsLocation());
// Street street = streetService.getStreetByPlcId(scTransmission.getSRMNumber());
// Integer row = Integer.valueOf(scTransmission.getGoodsLocation().substring(8,10));
// Integer column = Integer.valueOf(scTransmission.getGoodsLocation().substring(5,8));
// Integer leftRight = Integer.valueOf(scTransmission.getGoodsLocation().substring(4,5));
// Integer inout = Integer.valueOf(scTransmission.getGoodsLocation().substring(11,12));
// Stock stock = stockMapper.getByStreetAndDirectionAndSideAndRowColumn(street.getId(),leftRight,inout,row,column);
// if(stock != null){
//
// //暂时不盘点数量
// //stock.setCount(scTransmission.getRstCount());
// stock.setCount(scTransmission.getRstCategory().equals(stock.getWmsCategory())?scTransmission.getCount():0);
// stock.setCategory(scTransmission.getRstCategory());
// stock.setCode(scTransmission.getGoodsLocation());
// stock.setWmsCategory(scTransmission.getCategory());
// //盘点正确 : 2
// //盘点异常 : 1
// //暂时不盘点数量
// Integer status = scTransmission.getRstCategory().equals(stock.getWmsCategory()) ? 2: 1;
// //Integer status = ;
// stock.setStatus(status);
// stock.setTrayCode(scTransmission.getTrayNo());
// stockMapper.updateById(stock);
// log.info("update check info,taskId:{},SRMNumber:{},goodsLocation:{}",stock.getCheckNum(),scTransmission.getSRMNumber(),scTransmission.getGoodsLocation());
// }else {
// log.info("check end,but no stock info ,taskId:{},SRMNumber:{},goodsLocation:{}",scTransmission.getTaskNo(),scTransmission.getSRMNumber(),scTransmission.getGoodsLocation());
// stock = new Stock();
// stock.setCount(scTransmission.getCount());
// stock.setCode(scTransmission.getCode());
// stock.setStatus(1);
// }
// // checkLog(stock);
// return stock;
// }
public void checkLog ( Stock stock ) {
CheckLog checkLog = new CheckLog ( ) ;
@ -1052,57 +1131,57 @@ public class PlcService {
* 顶 部 拍 照 C1
* @return
* /
@Transactional
public synchronized List < EmptyCheckPic > emptyCheck04 ( ECResultMessage ecResultMessage ) {
EmptyCheckPic emptyCheckPic = new EmptyCheckPic (
ecResultMessage . getEmptyCheckMsg ( ) . substring ( ecResultMessage . getEmptyCheckMsg ( )
. lastIndexOf ( ";" , ecResultMessage . getEmptyCheckMsg ( ) . lastIndexOf ( ";" ) - 1 ) + 1 ,
ecResultMessage . getEmptyCheckMsg ( ) . lastIndexOf ( "," ) ) , ecResultMessage . getTaskId ( ) , ecResultMessage . getSRMNumber ( ) ) ;
Street street = streetService . getStreetByPlcId ( ecResultMessage . getSRMNumber ( ) ) ;
if ( street = = null ) {
log . error ( "SRMNum: {} 对应的巷道不存在" , ecResultMessage . getSRMNumber ( ) ) ;
}
String leftOrRight = emptyCheckPic . getLeftOrRight ( ) . equals ( "2" ) ? "-R" : "-L" ;
//南京烟草物流只有一个相机
Integer cameraId = street . getCamera1Id ( ) = = null ? street . getCamera2Id ( ) : street . getCamera1Id ( ) ;
//浅相机
//转动拍照
gyrateCameraByCode ( cameraId , "C2-IN" + leftOrRight ) ;
//等待2s再拍照
try {
Thread . sleep ( 3000l ) ;
} catch ( InterruptedException e ) {
e . printStackTrace ( ) ;
}
String path = PathUtil . createFileNameByRowColumn ( "jpg" , cameraId ,
Integer . parseInt ( emptyCheckPic . getRow ( ) ) ,
Integer . parseInt ( emptyCheckPic . getColumn ( ) ) ,
emptyCheckPic . getInputString ( ) + emptyCheckPic . getTaskCode ( ) + "-IN" ) ;
cameraCapture ( cameraId , false , 0 l , path ) ;
emptyCheckPic . setShallowPic ( path ) ;
if ( emptyCheckPic . getLeftOrRight ( ) . equals ( "1" ) ? street . getLeftType ( ) . equals ( 1 ) : street . getRightType ( ) . equals ( 1 ) ) {
//深相机
//转动拍照
gyrateCameraByCode ( cameraId , "C2-OUT" + leftOrRight ) ;
//等待2s再拍照
try {
Thread . sleep ( 3000l ) ;
} catch ( InterruptedException e ) {
e . printStackTrace ( ) ;
}
path = path . replace ( "-IN" , "-OUT" ) ;
cameraCapture ( cameraId , false , 0 l , path ) ;
emptyCheckPic . setDeepPic ( path ) ;
}
emptyCheckPicMapper . insert ( emptyCheckPic ) ;
List < EmptyCheckPic > emptyCheckPics = emptyCheckPicMapper . selectList ( new QueryWrapper < EmptyCheckPic > ( ) . eq ( "task_code" , emptyCheckPic . getTaskCode ( ) ) ) ;
return emptyCheckPics ;
}
// @Transactional
// public synchronized List<EmptyCheckPic> emptyCheck04(ECResultMessage ecResultMessage ){
// EmptyCheckPic emptyCheckPic = new EmptyCheckPic(
// ecResultMessage.getEmptyCheckMsg().substring(ecResultMessage.getEmptyCheckMsg()
// .lastIndexOf(";",ecResultMessage.getEmptyCheckMsg().lastIndexOf(";")-1)+1,
// ecResultMessage.getEmptyCheckMsg().lastIndexOf(",")),ecResultMessage.getTaskId(),ecResultMessage.getSRMNumber());
// Street street = streetService.getStreetByPlcId(ecResultMessage.getSRMNumber());
// if (street == null){
// log.error("SRMNum: {} 对应的巷道不存在", ecResultMessage.getSRMNumber());
// }
// String leftOrRight = emptyCheckPic.getLeftOrRight().equals("2") ? "-R" :"-L";
// //南京烟草物流只有一个相机
// Integer cameraId = street.getCamera1Id() == null ? street.getCamera2Id():street.getCamera1Id();
//
// //浅相机
// //转动拍照
// gyrateCameraByCode(cameraId,"C2-IN"+leftOrRight);
// //等待2s再拍照
// try {
// Thread.sleep(3000l);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
//
// String path = PathUtil.createFileNameByRowColumn("jpg",cameraId,
// Integer.parseInt(emptyCheckPic.getRow()),
// Integer.parseInt(emptyCheckPic.getColumn()),
// emptyCheckPic.getInputString()+emptyCheckPic.getTaskCode()+"-IN");
//
// cameraCapture(cameraId,false,0l,path );
// emptyCheckPic.setShallowPic(path);
// if( emptyCheckPic.getLeftOrRight().equals("1") ?street.getLeftType().equals(1) :street.getRightType().equals(1)){
//
// //深相机
// //转动拍照
// gyrateCameraByCode(cameraId,"C2-OUT"+leftOrRight);
// //等待2s再拍照
// try {
// Thread.sleep(3000l);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
//
// path = path.replace("-IN","-OUT");
// cameraCapture(cameraId,false,0l,path );
// emptyCheckPic.setDeepPic(path );
// }
// emptyCheckPicMapper.insert(emptyCheckPic);
// List<EmptyCheckPic> emptyCheckPics = emptyCheckPicMapper.selectList(new QueryWrapper<EmptyCheckPic>().eq("task_code",emptyCheckPic.getTaskCode()));
// return emptyCheckPics;
// }
public String getWebPicPath ( ) {
@ -1146,4 +1225,30 @@ public class PlcService {
cameraCapture ( cameraId , false , 0 l , path ) ;
return configProperties . getIP ( ) + ":9007/api/pic/" + path ;
}
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 ;
}
}