多氟多http协议
parent
63a1b65081
commit
7bddfd004c
@ -0,0 +1,153 @@
|
|||||||
|
package com.zhehekeji.web.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.zhehekeji.common.util.FileUtil;
|
||||||
|
import com.zhehekeji.core.pojo.Result;
|
||||||
|
import com.zhehekeji.web.entity.Stock;
|
||||||
|
import com.zhehekeji.web.pojo.Cmd;
|
||||||
|
import com.zhehekeji.web.service.GoodsActionTimes;
|
||||||
|
import com.zhehekeji.web.service.PlcCmdInfo;
|
||||||
|
import com.zhehekeji.web.service.PlcService;
|
||||||
|
import com.zhehekeji.web.service.ksec.KsecDataInfo;
|
||||||
|
import com.zhehekeji.web.service.ksec.KsecInfo;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
|
||||||
|
@Api(value = "monitor",tags = "监控接口")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/monitor")
|
||||||
|
@Slf4j
|
||||||
|
public class MonitorController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PlcService plcService;
|
||||||
|
private static final Logger tcpLogger = LoggerFactory.getLogger("tcp");
|
||||||
|
|
||||||
|
private static String lastLotnum;
|
||||||
|
|
||||||
|
private static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(7,21,30, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<>(20000));
|
||||||
|
|
||||||
|
@PostMapping("/task")
|
||||||
|
public Result monitorTask(@RequestBody KsecInfo ksecInfo){
|
||||||
|
KescRunnable kescRunnable = new KescRunnable(ksecInfo,plcService);
|
||||||
|
threadPoolExecutor.execute(kescRunnable);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class KescRunnable implements Runnable{
|
||||||
|
|
||||||
|
private KsecInfo ksecInfo;
|
||||||
|
|
||||||
|
private PlcService plcService;
|
||||||
|
|
||||||
|
public KescRunnable(KsecInfo ksecInfo,PlcService plcService){
|
||||||
|
this.ksecInfo = ksecInfo;
|
||||||
|
this.plcService = plcService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
tcpLogger.info("{}",JSONObject.toJSONString(ksecInfo));
|
||||||
|
KsecDataInfo dataInfo = ksecInfo.getData();
|
||||||
|
String lotnum = dataInfo.getLotnum();
|
||||||
|
PlcCmdInfo plcCmdInfo = null;
|
||||||
|
String srmNumber = dataInfo.getSRMNumber();
|
||||||
|
String cmdName = dataInfo.getCmdName();;
|
||||||
|
if(dataInfo != null){
|
||||||
|
|
||||||
|
plcCmdInfo = new PlcCmdInfo(dataInfo.getSRMNumber(), dataInfo.getTaskId(), dataInfo.getFromSide(), dataInfo.getFromDirection(), dataInfo.getFromColumn(), dataInfo.getFromRow(), dataInfo.getFromSeparation(),dataInfo.getToSide(), dataInfo.getToDirection(), dataInfo.getToColumn(), dataInfo.getToRow(),dataInfo.getToSeparation(),lotnum);
|
||||||
|
}
|
||||||
|
if (Cmd.A.name().equals(ksecInfo.getType())) {
|
||||||
|
//心跳
|
||||||
|
log.debug("receieve heart ");
|
||||||
|
} else if (Cmd.B.name().equals(ksecInfo.getType())) {
|
||||||
|
|
||||||
|
//任务
|
||||||
|
if (Cmd.B1.name().equals(cmdName)) {
|
||||||
|
//任务开始 旋转到原点位
|
||||||
|
plcService.gyrateCamera(plcCmdInfo,Cmd.C5.name());
|
||||||
|
plcService.orderStart(plcCmdInfo);
|
||||||
|
|
||||||
|
} else if (Cmd.B2.name().equals(cmdName)) {
|
||||||
|
plcService.gyrateCamera(plcCmdInfo,Cmd.C5.name());
|
||||||
|
plcService.orderStop(plcCmdInfo);
|
||||||
|
}
|
||||||
|
} else if (Cmd.C.name().equals(ksecInfo.getType())) {
|
||||||
|
|
||||||
|
//动作
|
||||||
|
String code = dataInfo.getCmdName();
|
||||||
|
log.info("action code,{},orderInfo:{}", code, plcCmdInfo.toString());
|
||||||
|
if (Cmd.isBaseAction(code)) {
|
||||||
|
//执行动作,需要保存执行到第几步了
|
||||||
|
Integer times = GoodsActionTimes.put(plcCmdInfo.getOrderNum());
|
||||||
|
plcCmdInfo.setTimes(times);
|
||||||
|
code = code + "-" + plcCmdInfo.getLeftRightStr(times) + plcCmdInfo.getInOutStr(times);
|
||||||
|
//执行动作
|
||||||
|
try {
|
||||||
|
plcService.action(plcCmdInfo, times, code);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
log.info("other C code :{}",code);
|
||||||
|
}
|
||||||
|
} else if (Cmd.D.name().equals(ksecInfo.getType())) {
|
||||||
|
|
||||||
|
String code = dataInfo.getCmdName();
|
||||||
|
if(code.equals(Cmd.D1.name())){
|
||||||
|
log.info("plcId:{},warn start",plcCmdInfo.getPlcId());
|
||||||
|
//根据告警code转动camera
|
||||||
|
String warnCode = dataInfo.getWarnCode();
|
||||||
|
if(!StringUtils.isEmpty(warnCode)){
|
||||||
|
String warnCode0 = Cmd.D1.name()+"-"+warnCode.split(",")[0];
|
||||||
|
plcService.warnAction(plcCmdInfo,warnCode0);
|
||||||
|
}
|
||||||
|
plcService.warnStart(plcCmdInfo.getPlcId(),dataInfo.getWarnCode());
|
||||||
|
}else if(code.equals(Cmd.D2.name())){
|
||||||
|
log.info("plcId:{},warn stop",plcCmdInfo.getPlcId());
|
||||||
|
plcService.warnStop(plcCmdInfo.getPlcId());
|
||||||
|
}else {
|
||||||
|
log.info("other D code :{}",code);
|
||||||
|
}
|
||||||
|
} else if (Cmd.E.name().equals(ksecInfo.getType())) {
|
||||||
|
|
||||||
|
//盘点
|
||||||
|
//转球机到盘点位 然后拍照
|
||||||
|
|
||||||
|
if(!StringUtils.isEmpty(lotnum) && !lotnum.equals(lastLotnum)){
|
||||||
|
//需要把stock表truncate
|
||||||
|
FileUtil.save(lotnum,"lastLotnum");
|
||||||
|
|
||||||
|
plcService.truncateStock();
|
||||||
|
lastLotnum = lotnum;
|
||||||
|
}
|
||||||
|
plcCmdInfo.setTimes(1);
|
||||||
|
Stock stock = plcService.check(plcCmdInfo,ksecInfo.getData().getCmdName(), dataInfo.getCode(), dataInfo.getWmsCode());
|
||||||
|
if(stock.getStatus() == 2){
|
||||||
|
ksecInfo.getData().setStatus(1);
|
||||||
|
ksecInfo.getData().setCode(stock.getTrayCode());
|
||||||
|
}else {
|
||||||
|
ksecInfo.getData().setStatus(0);
|
||||||
|
ksecInfo.getData().setCode(stock.getTrayCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue