@ -9,12 +9,17 @@ import com.zhehekeji.web.lib.*;
import com.zhehekeji.web.mapper.* ;
import com.zhehekeji.web.mapper.* ;
import com.zhehekeji.web.pojo.OrderVO ;
import com.zhehekeji.web.pojo.OrderVO ;
import com.zhehekeji.web.pojo.camera.CameraPtzPojo ;
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.RFIDMap ;
import com.zhehekeji.web.service.RFID.RFIDSocket ;
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.entity.EmptyCheckPic ;
import com.zhehekeji.web.service.client.ClientChanel ;
import com.zhehekeji.web.service.client.GetPhotoDelayExecutor ;
import com.zhehekeji.web.service.client.TransmissionPojo ;
import com.zhehekeji.web.service.client.TransmissionType ;
import com.zhehekeji.web.service.ksec.KsecDataInfo ;
import com.zhehekeji.web.service.ksec.KsecInfo ;
import io.swagger.models.auth.In ;
import lombok.extern.slf4j.Slf4j ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.beans.BeanUtils ;
import org.springframework.beans.BeanUtils ;
import org.springframework.stereotype.Service ;
import org.springframework.stereotype.Service ;
@ -28,6 +33,7 @@ import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor ;
import java.util.concurrent.ThreadPoolExecutor ;
import java.util.concurrent.TimeUnit ;
import java.util.concurrent.TimeUnit ;
/ * *
/ * *
* @Description plc 信 号 指 令 处 理 类
* @Description plc 信 号 指 令 处 理 类
* 对 plcId 做 同 步 处 理 , 防 止 内 存 中 保 存 的 正 在 运 行 的 订 单 信 息 错 乱
* 对 plcId 做 同 步 处 理 , 防 止 内 存 中 保 存 的 正 在 运 行 的 订 单 信 息 错 乱
@ -470,100 +476,6 @@ public class PlcService {
@Resource
@Resource
private LightSourceMapper lightSourceMapper ;
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 ( ) ;
long end = System . currentTimeMillis ( ) ;
long s = end - startTime ;
log . info ( "time:{}millisecond" , s ) ;
return true ;
}
/ * *
* 保 存 盘 点 记 录
* @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 . setCategory ( scTransmission . getRstCategory ( ) ) ;
stock . setCode ( scTransmission . getGoodsLocation ( ) ) ;
stock . setWmsCategory ( scTransmission . getCategory ( ) ) ;
//盘点正确 : 2
//盘点异常 : 1
Integer status = scTransmission . getRstCount ( ) . equals ( stock . getWmsCount ( ) ) & & scTransmission . getRstCategory ( ) . equals ( stock . getWmsCategory ( ) ) ? 2 : 1 ;
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 ) {
public void checkLog ( Stock stock ) {
CheckLog checkLog = new CheckLog ( ) ;
CheckLog checkLog = new CheckLog ( ) ;
@ -660,84 +572,8 @@ public class PlcService {
}
}
/ * *
* 相 机 转 动 , 拍 照 , 并 返 回 两 张 照 片 地 址
* 顶 部 拍 照 C1
* @param SRMNumber
* @return
* /
public String IntoStockSave ( String SRMNumber , String taskId , String goodsLocation , String picName ) {
String ip = "http://" + ClientChanel . getIpFromId ( SRMNumber ) + ":9009/pic/" ;
String [ ] pics = picName . split ( ";" ) ;
String picNameDataBase = ip + pics [ 0 ] + ";" + ip + pics [ 1 ] ;
Order oldOrder = orderMapper . getOneByOrderNum ( taskId ) ;
oldOrder . setIntoStockPic ( picNameDataBase ) ;
orderMapper . updateById ( oldOrder ) ;
return ip + pics [ 0 ] + "*" + ip + pics [ 1 ] ;
}
/ * *
* 相 机 转 动 , 拍 照 , 并 返 回 图 片 地 址
* 顶 部 拍 照 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 ;
}
public String getWebPicPath ( ) {
return configProperties . getIP ( ) + ":9007/api/pic/" ;
}
/ * *
/ * *
* 相 机 转 动 , 拍 照 , 并 返 回 图 片 地 址
* 相 机 转 动 , 拍 照 , 并 返 回 图 片 地 址
* @param SRMNumber
* @param SRMNumber
@ -776,4 +612,117 @@ public class PlcService {
cameraCapture ( cameraId , false , 0 l , path ) ;
cameraCapture ( cameraId , false , 0 l , path ) ;
return configProperties . getIP ( ) + ":9007/api/pic/" + path ;
return configProperties . getIP ( ) + ":9007/api/pic/" + path ;
}
}
public void check ( PlcCmdInfo plcCmdInfo , KsecDataInfo dataInfo ) {
Street street = streetService . getStreetByPlcId ( dataInfo . getSRMNumber ( ) ) ;
//开始盘点具体货位
if ( dataInfo . getCmdName ( ) . equals ( "SC01" ) ) {
CheckLog checkLog = new CheckLog ( ) ;
checkLog . setStreetId ( street . getId ( ) ) ;
checkLog . setLotnum ( dataInfo . getLotnum ( ) ) ;
checkLog . setDirection ( dataInfo . getFromDirection ( ) ) ;
checkLog . setSide ( dataInfo . getFromSide ( ) ) ;
checkLog . setRow ( dataInfo . getFromRow ( ) ) ;
checkLog . setColumn ( dataInfo . getFromColumn ( ) ) ;
checkLog . setTaskId ( ( dataInfo . getTaskId ( ) ) ) ;
//默认未盘点
checkLog . setStatus ( StockStatus . PENDING . getStatus ( ) ) ;
checkLog . setCreateTime ( LocalDateTime . now ( ) ) ;
checkLog . setCategory ( dataInfo . getTypeNum ( ) ) ;
checkLog . setCount ( dataInfo . getQuantity ( ) ) ;
checkLogMapper . insert ( checkLog ) ;
Stock stock = stockMapper . getByStreetAndDirectionAndSideAndRowColumn ( street . getId ( ) , dataInfo . getFromDirection ( ) , dataInfo . getFromSide ( ) , dataInfo . getFromRow ( ) , dataInfo . getFromColumn ( ) ) ;
if ( stock = = null ) {
stock = new Stock ( ) ;
}
stock . setStreetId ( street . getId ( ) ) ;
stock . setCheckNum ( checkLog . getId ( ) . toString ( ) ) ;
stock . setLotnum ( dataInfo . getLotnum ( ) ) ;
stock . setDirection ( dataInfo . getFromDirection ( ) ) ;
stock . setSide ( dataInfo . getFromSide ( ) ) ;
stock . setRow ( dataInfo . getFromRow ( ) ) ;
stock . setColumn ( dataInfo . getFromColumn ( ) ) ;
stock . setCategory ( dataInfo . getTypeNum ( ) ) ;
stock . setCount ( dataInfo . getQuantity ( ) ) ;
stock . setTaskId ( ( dataInfo . getTaskId ( ) ) ) ;
//默认未盘点
stock . setStatus ( StockStatus . PENDING . getStatus ( ) ) ;
stock . setExportTime ( LocalDateTime . now ( ) ) ;
if ( stock . getId ( ) = = null ) {
stockMapper . insert ( stock ) ;
} else stockMapper . updateById ( stock ) ;
TransmissionPojo transmissionPojo = new TransmissionPojo ( checkLog , street ) ;
ClientChanel . get ( dataInfo . getSRMNumber ( ) ) . writeAndFlush ( transmissionPojo . toString ( TransmissionType . ST ) ) ;
}
//取货完成进行拍照
else if ( dataInfo . getCmdName ( ) . equals ( "SC02" ) ) {
CheckLog checkLog = checkLogMapper . selectOne ( new QueryWrapper < CheckLog > ( )
. eq ( "direction" , dataInfo . getFromDirection ( ) )
. eq ( "street_id" , street . getId ( ) )
. orderByDesc ( "id" ) . last ( "limit 1" ) ) ;
TransmissionPojo transmissionPojo = new TransmissionPojo ( checkLog , street ) ;
if ( GetPhotoDelayExecutor . cameraDelayTasks . size ( ) = = 0 ) {
//队列中没有任务,发送取图指令
ClientChanel . get ( dataInfo . getSRMNumber ( ) ) . writeAndFlush ( transmissionPojo . toString ( TransmissionType . GPS ) ) ;
}
//将取图指令放入队列等待上条取图结束,或队列超时调用
GetPhotoDelayExecutor . addCameraDelayTask ( street . getPlcId ( ) , transmissionPojo . toString ( TransmissionType . GPS ) , 2000L ) ;
// ClientChanel.get(dataInfo.getSRMNumber()).writeAndFlush();
}
}
public void visualCalculationResults ( TransmissionPojo transmissionPojo ) {
CheckLog checkLog = checkLogMapper . selectById ( transmissionPojo . getCheckId ( ) ) ;
Stock stock = stockMapper . selectOne ( new QueryWrapper < Stock > ( ) . eq ( "check_Num" , checkLog . getId ( ) ) ) ;
if ( transmissionPojo . getResult ( ) ! = null & & transmissionPojo . getResult ( ) = = 1 ) {
checkLog . setStatus ( StockStatus . SUCCESS . getStatus ( ) ) ;
stock . setStatus ( StockStatus . SUCCESS . getStatus ( ) ) ;
} else {
checkLog . setStatus ( StockStatus . ERROR . getStatus ( ) ) ;
stock . setStatus ( StockStatus . ERROR . getStatus ( ) ) ;
}
if ( transmissionPojo . getPicsPath ( ) ! = null & & transmissionPojo . getPicsPath ( ) . length > 0 ) {
String pics = join ( transmissionPojo . getPicsPath ( ) , ";" ) ;
checkLog . setPic ( pics ) ;
stock . setCheckPic ( pics ) ;
}
checkLogMapper . updateById ( checkLog ) ;
stockMapper . updateById ( stock ) ;
}
public static String join ( String [ ] array , String separator ) {
StringBuilder sb = new StringBuilder ( ) ;
for ( int i = 0 ; i < array . length ; i + + ) {
sb . append ( array [ i ] ) ;
if ( i < array . length - 1 ) {
sb . append ( separator ) ;
}
}
return sb . toString ( ) ;
}
public KsecInfo getKsecDataInfo ( TransmissionPojo transmissionPojo , String type ) {
KsecDataInfo ksecDataInfo = new KsecDataInfo ( ) ;
CheckLog checkLog = checkLogMapper . selectById ( transmissionPojo . getCheckId ( ) ) ;
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" , "SC" , ksecDataInfo ) ;
return ksecInfo ;
}
}
}