|
|
|
|
@ -1,19 +1,22 @@
|
|
|
|
|
package com.zhehekeji.web.service.putian;
|
|
|
|
|
|
|
|
|
|
import com.zhehekeji.web.service.EmptyCheckService;
|
|
|
|
|
import com.zhehekeji.web.service.client.ClientChanel;
|
|
|
|
|
import com.zhehekeji.web.service.client.ECTransmission;
|
|
|
|
|
import com.zhehekeji.web.service.client.EmptyCheckCodeInfo;
|
|
|
|
|
import com.zhehekeji.web.service.PlcService;
|
|
|
|
|
import com.zhehekeji.web.service.client.*;
|
|
|
|
|
import com.zhehekeji.web.service.ksec.KsecDecoder;
|
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
|
|
|
import io.netty.handler.codec.LineBasedFrameDecoder;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.poi.ss.formula.functions.T;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.concurrent.ArrayBlockingQueue;
|
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class PTDecoder extends LineBasedFrameDecoder {
|
|
|
|
|
@ -22,6 +25,10 @@ public class PTDecoder extends LineBasedFrameDecoder {
|
|
|
|
|
|
|
|
|
|
private EmptyCheckService emptyCheckService;
|
|
|
|
|
|
|
|
|
|
private PlcService plcService;
|
|
|
|
|
|
|
|
|
|
private static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(7,21,30, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<>(20000));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* failFast 与 maxLength 需要搭配使用,通过设置 failFast 可以控制抛出 TooLongFrameException 的时机,
|
|
|
|
|
@ -31,14 +38,40 @@ public class PTDecoder extends LineBasedFrameDecoder {
|
|
|
|
|
* @param stripDelimiter true:解析出的数据包不带换行符
|
|
|
|
|
* @param failFast
|
|
|
|
|
*/
|
|
|
|
|
public PTDecoder(int maxLength, boolean stripDelimiter, boolean failFast,EmptyCheckService emptyCheckService) {
|
|
|
|
|
public PTDecoder(int maxLength, boolean stripDelimiter, boolean failFast,EmptyCheckService emptyCheckService,PlcService plcService) {
|
|
|
|
|
super(maxLength, stripDelimiter, failFast);
|
|
|
|
|
this.emptyCheckService = emptyCheckService;
|
|
|
|
|
this.plcService = plcService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
|
|
|
|
|
in = (ByteBuf) super.decode(ctx, in);
|
|
|
|
|
if(in != null){
|
|
|
|
|
if(in == null){
|
|
|
|
|
log.debug("no data");
|
|
|
|
|
}else {
|
|
|
|
|
PTRunnable ptRunnable = new PTRunnable(ctx,in,emptyCheckService,plcService);
|
|
|
|
|
threadPoolExecutor.execute(ptRunnable);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class PTRunnable implements Runnable{
|
|
|
|
|
|
|
|
|
|
private ChannelHandlerContext ctx;
|
|
|
|
|
private ByteBuf in;
|
|
|
|
|
private EmptyCheckService emptyCheckService;
|
|
|
|
|
private PlcService plcService;
|
|
|
|
|
|
|
|
|
|
public PTRunnable(ChannelHandlerContext ctx, ByteBuf in,EmptyCheckService emptyCheckService,PlcService plcService){
|
|
|
|
|
this.ctx = ctx;
|
|
|
|
|
this.in = in;
|
|
|
|
|
this.emptyCheckService = emptyCheckService;
|
|
|
|
|
this.plcService = plcService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
String body = in.toString(Charset.forName("UTF-8"));
|
|
|
|
|
tcpLogger.info("received from PT:{}",body);
|
|
|
|
|
PTData ptData = new PTData(body);
|
|
|
|
|
@ -60,34 +93,64 @@ public class PTDecoder extends LineBasedFrameDecoder {
|
|
|
|
|
String endEmptyCheckStr = ECTransmission.toEmptyCheckEndString(checkContent.getSRMNUmber(),checkContent.getTaskNo(),checkContent.getRow(),checkContent.getStartColumn(),checkContent.getEndColumn());
|
|
|
|
|
//通知客户端结束检测
|
|
|
|
|
ClientChanel.write(endEmptyCheckStr,checkContent.getSRMNUmber());
|
|
|
|
|
//等待3s把空货位盘点的结果发给普天
|
|
|
|
|
//todo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
emptyCheckService.getEmptyStatus(checkContent.getSRMNUmber(),checkContent.getTaskNo(),1,1,checkContent.getRow(),checkContent.getStartColumn(),checkContent.getEndColumn());
|
|
|
|
|
//等待3s把空货位盘点的结果发给普天
|
|
|
|
|
String res = emptyCheckService.getEmptyStatus(checkContent.getSRMNUmber(),checkContent.getTaskNo(),1,1,checkContent.getRow(),checkContent.getStartColumn(),checkContent.getEndColumn());
|
|
|
|
|
//打印空货位的所有条码
|
|
|
|
|
Set<String> codes = EmptyCheckCodeInfo.getAllCode(checkContent.getSRMNUmber(),checkContent.getRow(),checkContent.getStartColumn(),checkContent.getEndColumn());
|
|
|
|
|
log.info("【空货位扫描到的所有条码】,SRMNumber:{},row:{},startColumn:{},endColumn:{},taskId:{},\ncodes:{}",checkContent.getSRMNUmber(),checkContent.getRow(),checkContent.getStartColumn(),checkContent.getEndColumn(),checkContent.getTaskNo(),codes);
|
|
|
|
|
//清空所有的条码
|
|
|
|
|
EmptyCheckCodeInfo.stop(checkContent.getSRMNUmber(),checkContent.getRow(),checkContent.getStartColumn(),checkContent.getEndColumn());
|
|
|
|
|
|
|
|
|
|
//返回普天该行的盘点结果
|
|
|
|
|
checkContent.setEmptyStatus(res);
|
|
|
|
|
PuTianNettyClient.write(PTData.EmptyStatusResponse(checkContent));
|
|
|
|
|
}else if(ptData.getType().equals(PTData.STOCK_CHECK_01)){
|
|
|
|
|
log.info("盘点具体货位");
|
|
|
|
|
|
|
|
|
|
//发送给客户端
|
|
|
|
|
PTCheckContent ptCheckContent = PTCheckContent.CheckContentSC01(ptData.getContent());
|
|
|
|
|
TMTransmission tmTransmission = new TMTransmission(ptCheckContent.getSRMNUmber(),ptCheckContent.getTaskNo(),ptCheckContent.getGoodsLocation(),ptCheckContent.getCode(), ptCheckContent.getCount(), "N");
|
|
|
|
|
plcService.checkStart(tmTransmission);
|
|
|
|
|
String msg = tmTransmission.toString();
|
|
|
|
|
ClientChanel.write(msg,ptCheckContent.getSRMNUmber());
|
|
|
|
|
}else if(ptData.getType().equals(PTData.STOCK_CHECK_02)){
|
|
|
|
|
log.info("盘点具体货位 ,货物已取到载货台");
|
|
|
|
|
|
|
|
|
|
PTCheckContent ptCheckContent = PTCheckContent.CheckContentSC02(ptData.getContent());
|
|
|
|
|
TMTransmission tmTransmission = new TMTransmission(ptCheckContent.getSRMNUmber(),ptCheckContent.getTaskNo());
|
|
|
|
|
String msg = tmTransmission.toSC02String();
|
|
|
|
|
ClientChanel.write(msg,ptCheckContent.getSRMNUmber());
|
|
|
|
|
}else if(ptData.getType().equals(PTData.Into_Stock_01)){
|
|
|
|
|
log.info("入库顶部拍照");
|
|
|
|
|
|
|
|
|
|
//保存order标表
|
|
|
|
|
PTOrderContent ptOrderContent = PTOrderContent.OrderContentIS01And03(ptData.getContent());
|
|
|
|
|
String picPath = plcService.IntoStock(ptOrderContent.getSRMNUmber(), ptOrderContent.getTaskNo(), ptOrderContent.getGoodsLocation());
|
|
|
|
|
//返回普天
|
|
|
|
|
PTData resData = PTData.IntoStock(ptOrderContent.getSRMNUmber(), ptOrderContent.getTaskNo(), ptOrderContent.getGoodsLocation(),picPath);
|
|
|
|
|
PuTianNettyClient.write(resData);
|
|
|
|
|
}else if(ptData.getType().equals(PTData.Into_Stock_02)){
|
|
|
|
|
log.info("入库完成拍照");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PTOrderContent ptOrderContent = PTOrderContent.OrderContentIS01And03(ptData.getContent());
|
|
|
|
|
String picPath = plcService.IntoStockOver(ptOrderContent.getSRMNUmber(), ptOrderContent.getTaskNo(), ptOrderContent.getGoodsLocation());
|
|
|
|
|
|
|
|
|
|
//向客户端发送读码指令,等待客户端返回条码
|
|
|
|
|
ISTransmission isTransmission = new ISTransmission(ptOrderContent.getSRMNUmber(), ptOrderContent.getTaskNo(), ptOrderContent.getGoodsLocation());
|
|
|
|
|
//为防万一,先清除code
|
|
|
|
|
ClientCodeMap.removeCode(ptOrderContent.getSRMNUmber());
|
|
|
|
|
ClientChanel.write(isTransmission.toString(),ptOrderContent.getSRMNUmber());
|
|
|
|
|
//发送结果给普天
|
|
|
|
|
//若1分钟内仍为收到 则放弃
|
|
|
|
|
Long start = System.currentTimeMillis();
|
|
|
|
|
while (ClientCodeMap.getCode(ptOrderContent.getSRMNUmber()) == null && (System.currentTimeMillis()-start)<60000){
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(300l);
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String code = ClientCodeMap.getCode(ptOrderContent.getSRMNUmber());
|
|
|
|
|
PTData resData = PTData.IntoStock04(ptOrderContent.getSRMNUmber(), ptOrderContent.getTaskNo(), ptOrderContent.getGoodsLocation(),picPath,code);
|
|
|
|
|
PuTianNettyClient.write(resData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|