package com.zy.asrs.service.impl;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
import com.core.common.Cools;
|
import com.core.common.DateUtils;
|
import com.core.exception.CoolException;
|
import com.zy.asrs.entity.*;
|
import com.zy.asrs.mapper.BasCrnErrorMapper;
|
import com.zy.asrs.mapper.BasRgvErrMapper;
|
import com.zy.asrs.mapper.WrkMastMapper;
|
import com.zy.asrs.service.*;
|
import com.zy.asrs.utils.Utils;
|
import com.zy.asrs.utils.VersionUtils;
|
import com.zy.common.model.LocTypeDto;
|
import com.zy.common.model.MatDto;
|
import com.zy.common.model.SearchLocParam;
|
import com.zy.common.model.StartupDto;
|
import com.zy.common.service.CommonService;
|
import com.zy.common.utils.CollectionUtils;
|
import com.zy.common.utils.HttpHandler;
|
import com.zy.common.utils.RedisUtil;
|
import com.zy.common.utils.RgvUtils;
|
import com.zy.core.CrnThread;
|
import com.zy.core.DevpThread;
|
import com.zy.core.cache.MessageQueue;
|
import com.zy.core.cache.SlaveConnection;
|
import com.zy.core.enums.*;
|
import com.zy.core.model.*;
|
import com.zy.core.model.command.CrnCommand;
|
import com.zy.core.model.command.LedCommand;
|
import com.zy.core.model.command.RgvCommand;
|
import com.zy.core.model.protocol.CrnProtocol;
|
import com.zy.core.model.protocol.RgvProtocol;
|
import com.zy.core.model.protocol.StaProtocol;
|
import com.zy.core.properties.SlaveProperties;
|
import com.zy.core.thread.BarcodeThread;
|
import com.zy.core.thread.LedThread;
|
import com.zy.core.thread.RgvThread;
|
import com.zy.core.thread.SiemensDevpThread;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* 立体仓库WCS系统主流程业务
|
* Created by vincent on 2020/8/6
|
*/
|
@Slf4j
|
@Service("mainService")
|
@Transactional
|
public class MainServiceImpl {
|
|
public static final long COMMAND_TIMEOUT = 5 * 1000;
|
|
@Autowired
|
private CommonService commonService;
|
@Autowired
|
private SlaveProperties slaveProperties;
|
@Autowired
|
private WrkMastMapper wrkMastMapper;
|
@Autowired
|
private WrkDetlService wrkDetlService;
|
@Autowired
|
private LocMastService locMastService;
|
@Autowired
|
private StaDescService staDescService;
|
@Autowired
|
private BasCrnpService basCrnpService;
|
@Autowired
|
private BasRgvService basRgvService;
|
@Autowired
|
private BasDevpService basDevpService;
|
@Autowired
|
private LocDetlService locDetlService;
|
@Autowired
|
private BasErrLogService basErrLogService;
|
@Autowired
|
private BasCrnErrorMapper basCrnErrorMapper;
|
@Autowired
|
private BasRgvErrMapper basRgvErrMapper;
|
@Autowired
|
private BasRgvErrLogService basRgvErrLogService;
|
@Autowired
|
private BasRgvPathService basRgvPathService;
|
@Autowired
|
private RedisUtil redisUtil;
|
|
@Value("${wms.url}")
|
private String wmsUrl;
|
|
/**
|
* 组托
|
* 入库站,根据条码扫描生成入库工作档,工作状态 2
|
*/
|
public synchronized void generateStoreWrkFile() {
|
// 根据输送线plc遍历
|
for (DevpSlave devp : slaveProperties.getDevp()) {
|
// 遍历入库口
|
for (DevpSlave.Sta inSta : devp.getInSta()) {
|
// 获取条码扫描仪信息
|
BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode());
|
if (barcodeThread == null) {
|
continue;
|
}
|
String barcode = barcodeThread.getBarcode();
|
|
if (!Cools.isEmpty(barcode)) {
|
log.info("{}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode);
|
if ("NG".endsWith(barcode) || "NoRead".equals(barcode)) {
|
continue;
|
}
|
} else {
|
continue;
|
}
|
|
// 获取入库站信息
|
// SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
|
SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
|
StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo());
|
if (staProtocol == null) {
|
continue;
|
} else {
|
staProtocol = staProtocol.clone();
|
}
|
|
// 入出库模式判断
|
// if ( inSta.getStaNo()==203 && devpThread.ioModeOf2F != IoModeType.PAKIN_MODE) { continue; }
|
// if (inSta.getStaNo() == 203 && devpThread.ioModeOf2F == IoModeType.PAKOUT_MODE) {
|
// continue;
|
// }
|
|
// 判断是否满足入库条件
|
if (staProtocol.isAutoing()
|
&& staProtocol.isLoading()
|
&& staProtocol.isInEnable()
|
&& !staProtocol.isEmptyMk()
|
&& (staProtocol.getWorkNo() == 0 || staProtocol.getWorkNo() > 9990)
|
&& staProtocol.isPakMk()) {// && !Cools.isEmpty(barcode)) {
|
|
// if(Cools.isEmpty(barcode) || "NG".endsWith(barcode) || "NoRead".equals(barcode)) {
|
// log.info("{}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode);
|
// //条码为空或者不符合,退库到172站点
|
// staProtocol.setWorkNo((short)9999);
|
// staProtocol.setStaNo((short)172);
|
// devpThread.setPakMk(staProtocol.getSiteId(), false);
|
// boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
|
// if (!result) {
|
// throw new CoolException("更新plc站点信息失败");
|
// }
|
// continue;
|
// }
|
|
// 判断重复工作档
|
WrkMast wrkMast = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode);
|
if (wrkMast != null) {
|
log.error("工作档中已存在该站状态为( 2.设备上走 )的数据,工作号={}", wrkMast.getWrkNo());
|
continue;
|
}
|
// // 获取入库通知档
|
// List<WaitPakin> waitPakins = waitPakinMapper.selectList(new EntityWrapper<WaitPakin>().eq("zpallet", barcode).eq("io_status", "N"));
|
// if (waitPakins.isEmpty()) {
|
// log.error("无此入库条码数据。条码号={}", barcode);
|
// continue;
|
// }
|
|
try {
|
|
LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
|
|
SearchLocParam param = new SearchLocParam();
|
param.setBarcode(barcode);
|
param.setIoType(1);
|
param.setSourceStaNo(inSta.getStaNo());
|
param.setLocType1(locTypeDto.getLocType1());
|
String response = new HttpHandler.Builder()
|
.setUri(wmsUrl)
|
.setPath("/rpc/pakin/loc/v1")
|
.setJson(JSON.toJSONString(param))
|
.build()
|
.doPost();
|
JSONObject jsonObject = JSON.parseObject(response);
|
if (jsonObject.getInteger("code").equals(200)) {
|
StartupDto dto = jsonObject.getObject("data", StartupDto.class);
|
|
barcodeThread.setBarcode("");
|
staProtocol.setWorkNo(dto.getWorkNo().shortValue());
|
|
if(Cools.isEmpty(dto.getRgvNo()) || dto.getRgvNo() <= 0) {
|
staProtocol.setStaNo(dto.getStaNo().shortValue());
|
} else {//如果存在RGV编号,说明需要RGV接驳,先下发任务到RGV源站
|
staProtocol.setStaNo(dto.getRgvSstaNo().shortValue());
|
}
|
|
devpThread.setPakMk(staProtocol.getSiteId(), false);
|
boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
|
if (!result) {
|
throw new CoolException("更新plc站点信息失败");
|
}
|
} else {
|
log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
|
}
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
}
|
|
}
|
|
|
}
|
}
|
|
}
|
|
/**
|
* wms入库
|
* 入库站,根据条码扫描生成入库工作档,工作状态 1 ==>> 2
|
*/
|
public synchronized void generateStoreWrkFile0() {
|
// 根据输送线plc遍历
|
for (DevpSlave devp : slaveProperties.getDevp()) {
|
// 遍历入库口
|
for (DevpSlave.Sta inSta : devp.getInSta()) {
|
// 获取入库站信息
|
SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
|
StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo());
|
if (staProtocol == null) {
|
continue;
|
} else {
|
staProtocol = staProtocol.clone();
|
}
|
|
// // 入出库模式判断
|
if (inSta.getStaNo() == 203 && devpThread.ioModeOf2F != IoModeType.PAKIN_MODE) {
|
continue;
|
}
|
|
// 判断是否满足入库条件
|
if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable()
|
&& !staProtocol.isEmptyMk() && (staProtocol.getWorkNo() == 0 || staProtocol.getWorkNo() == 9999)
|
&& staProtocol.isPakMk()) {
|
// 判断重复工作档
|
WrkMast wrkMast = wrkMastMapper.selectPakInStep11(inSta.getStaNo());
|
if (wrkMast == null) {
|
continue;
|
}
|
|
// 命令下发区 --------------------------------------------------------------------------
|
|
// 更新站点信息 且 下发plc命令
|
staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
|
staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
|
devpThread.setPakMk(staProtocol.getSiteId(), false);
|
boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
|
if (result) {
|
// 更新工作主档
|
wrkMast.setWrkSts(2L); // 工作状态:2.设备上走
|
wrkMast.setModiTime(new Date());
|
if (wrkMastMapper.updateById(wrkMast) == 0) {
|
log.error("更新工作档失败!!! [工作号:{}]", wrkMast.getWrkNo());
|
}
|
} else {
|
log.error("发布命令至输送线队列失败!!! [plc编号:{}]", devp.getId());
|
}
|
|
}
|
|
|
}
|
}
|
|
}
|
|
/**
|
* 拣料、并板、盘点再入库
|
*/
|
public synchronized void stnToCrnStnPick() {
|
for (DevpSlave devp : slaveProperties.getDevp()) {
|
// 遍历拣料入库口
|
for (DevpSlave.Sta pickSta : devp.getPickSta()) {
|
// // 获取条码扫描仪信息
|
// BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
|
// if (barcodeThread == null) {
|
// continue;
|
// }
|
// String barcode = barcodeThread.getBarcode();
|
// if(!Cools.isEmpty(barcode)) {
|
// log.info("{}号条码扫描器检测条码信息:{}", pickSta.getBarcode(), barcode);
|
// if("NG".endsWith(barcode) || "NoRead".equals(barcode)) {
|
// continue;
|
// }
|
// } else {
|
// continue;
|
// }
|
|
// 获取拣料入库站信息
|
SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
|
StaProtocol staProtocol = devpThread.getStation().get(pickSta.getStaNo());
|
if (staProtocol == null) {
|
continue;
|
} else {
|
staProtocol = staProtocol.clone();
|
}
|
|
// // 入出库模式判断
|
// if (devpThread.ioMode != IoModeType.PAKIN_MODE) { continue; }
|
|
if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable() && staProtocol.isPakMk()) {
|
// WrkMast wrkMast = wrkMastMapper.selectPickStep(barcode);
|
WrkMast wrkMast = wrkMastMapper.selectPakInStep3(staProtocol.getWorkNo().intValue());
|
if (wrkMast == null) {
|
// 无拣料数据
|
continue;
|
}
|
if ((wrkMast.getIoType() != 103 && wrkMast.getIoType() != 104 && wrkMast.getIoType() != 107)
|
|| Cools.isEmpty(wrkMast.getStaNo()) || Cools.isEmpty(wrkMast.getSourceStaNo())) {
|
continue;
|
}
|
|
// 拣、盘、并 作业站转换
|
// int stnNo = 0;
|
// if (wrkMast.getStaNo() == 109) {
|
// stnNo = 127;
|
// } else if (wrkMast.getStaNo() == 113) {
|
// stnNo = 128;
|
// } else {
|
// log.error("{}号任务数据异常!", wrkMast.getWrkNo());
|
// }
|
// 获取目标站
|
Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
|
.eq("type_no", wrkMast.getIoType() - 50)
|
.eq("stn_no", pickSta.getStaNo()) // 作业站点 = 拣料出库的目标站
|
.eq("crn_no", wrkMast.getCrnNo()); // 堆垛机号
|
StaDesc staDesc = staDescService.selectOne(wrapper);
|
if (Cools.isEmpty(staDesc)) {
|
log.error("入库路径不存在!type_no={},stn_no={},crn_no={}", wrkMast.getIoType(), pickSta.getStaNo(), wrkMast.getCrnNo());
|
continue;
|
}
|
|
try {
|
// 保存工作明细档历史档
|
if (wrkMastMapper.saveWrkDetlLog(wrkMast.getWrkNo()) == 0) {
|
throw new CoolException("保存工作明细档历史档失败");
|
}
|
// 保存工作主档历史档
|
if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) {
|
throw new CoolException("保存工作主档历史档失败");
|
}
|
|
Date now = new Date();
|
// 堆垛机站点(目标站)
|
Integer staNo = staDesc.getCrnStn();
|
// 更新工作档数据状态
|
wrkMast.setIoTime(now);
|
wrkMast.setIoType(wrkMast.getIoType() - 50); // 入出库类型: 103->53,104->54,107->57
|
wrkMast.setWrkSts(2L); // 工作状态: 2.设备上走
|
wrkMast.setSourceStaNo(wrkMast.getStaNo()); // 源站
|
wrkMast.setStaNo(staNo); // 目标站
|
wrkMast.setLocNo(wrkMast.getSourceLocNo()); // 目标库位 = 出库时的源库位
|
wrkMast.setSourceLocNo(""); // 源库位清空
|
wrkMast.setModiTime(now);
|
if (wrkMastMapper.updateById(wrkMast) == 0) {
|
throw new CoolException("更新工作档数据状态失败");
|
}
|
// 更新明细档io_time (历史档关联使用)
|
wrkDetlService.updateIoTime(wrkMast.getWrkNo(), now);
|
// 修改库位状态 Q.拣料/盘点/并板再入库
|
LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
|
locMast.setLocSts("Q");
|
locMast.setModiTime(new Date());
|
if (!locMastService.updateById(locMast)) {
|
throw new CoolException("修改库位状态失败");
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
continue;
|
}
|
|
// 更新站点信息 且 下发plc命令
|
staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
|
staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
|
devpThread.setPakMk(staProtocol.getSiteId(), false);
|
boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
|
if (!result) {
|
log.error("发布命令至输送线队列失败!!! [plc编号:{}]", devp.getId());
|
}
|
|
}
|
|
}
|
|
}
|
}
|
|
/**
|
* 堆垛机站出库到出库站
|
*/
|
public synchronized void crnStnToOutStn() {
|
for (CrnSlave crnSlave : slaveProperties.getCrn()) {
|
// 遍历堆垛机出库站
|
for (CrnSlave.CrnStn crnStn : crnSlave.getCrnOutStn()) {
|
// 获取堆垛机出库站信息
|
DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
|
StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
|
if (staProtocol == null) {
|
continue;
|
} else {
|
staProtocol = staProtocol.clone();
|
}
|
if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) {
|
// 查询工作档
|
WrkMast wrkMast = wrkMastMapper.selectPakOutStep2(staProtocol.getSiteId());
|
if (wrkMast == null) {
|
continue;
|
}
|
// 判断工作档条件
|
if (wrkMast.getIoType() < 100 || wrkMast.getStaNo() == null || wrkMast.getSourceStaNo() == null) {
|
continue;
|
}
|
// 判断吊车是否实际已完成,且电脑状态在move中,以备电脑进行更新工作档
|
CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, wrkMast.getCrnNo());
|
CrnProtocol crnProtocol = crnThread.getCrnProtocol();
|
if (crnProtocol.statusType == CrnStatusType.FETCHING || crnProtocol.statusType == CrnStatusType.PUTTING) {
|
// 移动中
|
continue;
|
}
|
// 判断堆垛机状态等待确认
|
if (crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.getTaskNo().equals(wrkMast.getWrkNo().shortValue())
|
&& crnProtocol.statusType == CrnStatusType.WAITING
|
&& crnProtocol.forkPosType == CrnForkPosType.HOME) {
|
|
// 命令下发区 --------------------------------------------------------------------------
|
|
// 下发站点信息
|
staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
|
staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
|
if (!MessageQueue.offer(SlaveType.Devp, crnStn.getDevpPlcId(), new Task(2, staProtocol))) {
|
continue;
|
}
|
|
// 更新工作档状态为14失败
|
wrkMast.setWrkSts(14L);
|
wrkMast.setCrnEndTime(new Date());
|
if (wrkMastMapper.updateById(wrkMast) != 0) {
|
// 复位堆垛机
|
crnThread.setResetFlag(true);
|
} else {
|
log.error("更新工作档的工作状态为14失败!!! [工作号:{}]", wrkMast.getWrkNo());
|
}
|
|
}
|
|
}
|
}
|
}
|
}
|
|
/**
|
* 入出库 ===>> 堆垛机入出库作业下发
|
*/
|
public synchronized void crnIoExecute() {
|
for (CrnSlave crn : slaveProperties.getCrn()) {
|
// 获取堆垛机信息
|
CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
|
CrnProtocol crnProtocol = crnThread.getCrnProtocol();
|
if (crnProtocol == null) {
|
continue;
|
}
|
BasCrnp basCrnp = basCrnpService.selectById(crn.getId());
|
if (basCrnp == null) {
|
log.error("{}号堆垛机尚未在数据库进行维护!", crn.getId());
|
continue;
|
}
|
|
// 只有当堆垛机空闲 并且 无任务时才继续执行
|
if (crnProtocol.getStatusType() == CrnStatusType.IDLE
|
&& crnProtocol.getTaskNo() == 0
|
&& crnProtocol.getModeType() == CrnModeType.AUTO
|
&& crnProtocol.getLoaded() == 0
|
&& crnProtocol.getForkPos() == 0) {
|
// 如果最近一次是入库模式
|
if (crnProtocol.getLastIo().equals("I")) {
|
if (basCrnp.getInEnable().equals("Y")) {
|
this.crnStnToLoc1(crn, crnProtocol); // 入库
|
crnProtocol.setLastIo("O");
|
} else if (basCrnp.getOutEnable().equals("Y")) {
|
this.locToCrnStn1(crn, crnProtocol); // 出库
|
crnProtocol.setLastIo("I");
|
}
|
}
|
// 如果最近一次是出库模式
|
else if (crnProtocol.getLastIo().equals("O")) {
|
if (basCrnp.getOutEnable().equals("Y")) {
|
this.locToCrnStn1(crn, crnProtocol); // 出库
|
crnProtocol.setLastIo("I");
|
} else if (basCrnp.getInEnable().equals("Y")) {
|
this.crnStnToLoc1(crn, crnProtocol); // 入库
|
crnProtocol.setLastIo("O");
|
}
|
}
|
}
|
// 库位移转
|
this.locToLoc(crn, crnProtocol);
|
// this.crnRebackHp(crnProtocol, crnThread);
|
|
}
|
}
|
|
/**
|
* 搜索RGV车。通过目标站搜索哪台车可用
|
*/
|
public synchronized Integer searchRgvNo(Integer staNo) {
|
BasDevp basDevp = basDevpService.selectById(staNo);
|
if (basDevp == null) {
|
return null;//目标站不存在
|
}
|
//路径值
|
int path = basDevp.getLocType3().intValue();
|
|
ArrayList<RgvThread> list = new ArrayList<>();
|
for (RgvSlave rgv : slaveProperties.getRgv()) {
|
// 获取RGV信息
|
RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgv.getId());
|
RgvProtocol rgvProtocol = rgvThread.getRgvProtocol();
|
if (rgvProtocol == null) {
|
continue;
|
}
|
BasRgv basRgv = basRgvService.selectById(rgv.getId());
|
if (basRgv == null) {
|
log.error("{}号RGV尚未在数据库进行维护!", rgv.getId());
|
continue;
|
}
|
|
list.add(rgvThread);
|
}
|
|
if (list.size() > 1) {
|
//超过两台车,按照配置的规则进行分配
|
for (RgvThread rgvThread : list) {
|
//获取车辆配置的路径规则
|
BasRgvPath basRgvPath = basRgvPathService.selectByRgvNo(rgvThread.getSlave().getId());
|
if (basRgvPath == null) {
|
continue;
|
}
|
//目标站是否包含当前路径中
|
List<Integer> rgvPath = JSON.parseArray(basRgvPath.getPath(), Integer.class);
|
if (rgvPath.contains(path)) {
|
//当前路径中包含目标站,则选定这台车
|
return rgvThread.getSlave().getId();
|
}
|
}
|
}else {
|
//小于或等于1台车,分配全路径
|
BasRgvPath basRgvPath = basRgvPathService.selectByRgvNo(0);//获取默认路径
|
if (basRgvPath == null) {
|
return null;
|
}
|
List<Integer> rgvPath = JSON.parseArray(basRgvPath.getPath(), Integer.class);
|
if (rgvPath.contains(path)) {
|
//当前路径中包含目标站,则选定这台车
|
return list.get(0).getSlave().getId();
|
}
|
}
|
|
return null;
|
}
|
|
/**
|
* 绑定小车方法
|
*/
|
public synchronized void rgvBindSte() {
|
//获取等待绑定RGV的任务
|
List<WrkMast> wrkMasts = wrkMastMapper.selectWaitBindRGV();
|
for (WrkMast wrkMast : wrkMasts) {
|
//目标站
|
Integer staNo = wrkMast.getStaNo();
|
//通过目标站搜索rgv号
|
Integer rgvNo = this.searchRgvNo(staNo);
|
if (rgvNo == null) {//未找到可用的rgv
|
continue;
|
}
|
|
wrkMast.setRgvNo(rgvNo);//绑定rgv号
|
wrkMast.setRgvDstaNo(wrkMast.getSourceStaNo());//设置RGV前往工作档源站取货
|
if (wrkMastMapper.updateById(wrkMast)==0){
|
log.error("绑定小车更新工作档失败!!! [工作号:{}]", wrkMast.getWrkNo());
|
}
|
}
|
}
|
|
/**
|
* 入出库 ===>> RGV入出库作业下发
|
*/
|
public synchronized void rgvIoExecute() {
|
for (RgvSlave rgv : slaveProperties.getRgv()) {
|
// 获取RGV信息
|
RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgv.getId());
|
RgvProtocol rgvProtocol = rgvThread.getRgvProtocol();
|
if (rgvProtocol == null) {
|
continue;
|
}
|
BasRgv basRgv = basRgvService.selectById(rgv.getId());
|
if (basRgv == null) {
|
log.error("{}号RGV尚未在数据库进行维护!", rgv.getId());
|
continue;
|
}
|
|
// 只有当RGV空闲、自动,
|
if (rgvProtocol.getStatusType() == RgvStatusType.IDLE
|
&& rgvProtocol.getModeType() == RgvModeType.AUTO
|
// && rgvProtocol.getTaskNo1() == 0 && rgvProtocol.getTaskNo2() == 0
|
// && rgvProtocol.getLoaded1() == 0 && rgvProtocol.getLoaded2() == 0
|
) {
|
|
//查找是否存在入出库工作中等待RGV搬运的任务
|
List<WrkMast> wrkMasts = wrkMastMapper.selectIoRgvNo(rgv.getId());
|
for (WrkMast wrkMast : wrkMasts) {
|
if (wrkMast.getWrkSts() == 2) {//2.设备上走1 => 3.RGV取货中
|
if (rgvProtocol.getTaskNo1() != 0 || rgvProtocol.getLoaded1() != 0) {//RGV是否无任务、RGV是否无货
|
continue;
|
}
|
|
//判断行走路径是否被占用
|
Integer staNo = wrkMast.getSourceStaNo();
|
BasDevp basDevp = basDevpService.selectById(staNo);
|
if (basDevp == null) {
|
continue;//目标站不存在
|
}
|
//起始路径
|
int startPath = rgvProtocol.getRgvPos().intValue();
|
//目标路径值
|
int endPath = basDevp.getLocType3().intValue();
|
boolean pathUsed = RgvUtils.isPathUsed(startPath, endPath);//判断行走路径是否被占用
|
if (pathUsed) {
|
//行走路径被占用,禁止下发命令
|
continue;
|
}
|
//行走路径空闲,锁定路径
|
RgvUtils.lockPath(startPath, endPath, rgvProtocol.getRgvNo(), true);
|
|
// 命令下发区 --------------------------------------------------------------------------
|
RgvCommand rgvCommand = new RgvCommand();
|
rgvCommand.setRgvNo(wrkMast.getRgvNo()); // RGV编号
|
rgvCommand.setAckFinish1((short) 0); // 工位1任务完成确认位
|
rgvCommand.setTaskNo1(wrkMast.getWrkNo().shortValue()); // 工位1工作号
|
rgvCommand.setTaskMode1(RgvTaskModeType.FETCH); // 工位1任务模式: 取货
|
rgvCommand.setDestinationStaNo1(wrkMast.getRgvDstaNo().shortValue()); //工位1目标站点
|
rgvCommand.setCommand((short) 1); //工位1任务确认
|
if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getRgvNo(), new Task(4, rgvCommand))) {
|
//step=2,工位1、2写任务; step=4,工位1写任务; step=5,工位2写任务
|
log.error("RGV命令下发失败,RGV号={},任务数据={}", wrkMast.getRgvNo(), JSON.toJSON(rgvCommand));
|
} else {
|
// 修改工作档状态 2.设备上走1 => 3.RGV取货中
|
Date now = new Date();
|
wrkMast.setWrkSts(3L);
|
wrkMast.setModiTime(now);
|
if (wrkMastMapper.updateById(wrkMast) == 0) {
|
log.error("修改工作档状态 2.设备上走1 => 3.RGV取货中 失败!!,工作号={}", wrkMast.getWrkNo());
|
}
|
}
|
} else if (wrkMast.getWrkSts() == 4) {//4.RGV取货完成 => 5.RGV放货中
|
if (rgvProtocol.getTaskNo1() == 0 || !rgvProtocol.getTaskNo1().equals(wrkMast.getWrkNo().shortValue())) {//RGV必须有任务且任务和当前工作档一致
|
continue;
|
}
|
if (rgvProtocol.getLoaded1() == 0) {//RGV必须有物
|
continue;
|
}
|
|
//判断行走路径是否被占用
|
Integer staNo = wrkMast.getStaNo();
|
BasDevp basDevp = basDevpService.selectById(staNo);
|
if (basDevp == null) {
|
continue;//目标站不存在
|
}
|
//起始路径
|
int startPath = rgvProtocol.getRgvPos().intValue();
|
//目标路径值
|
int endPath = basDevp.getLocType3().intValue();
|
boolean pathUsed = RgvUtils.isPathUsed(startPath, endPath);//判断行走路径是否被占用
|
if (pathUsed) {
|
//行走路径被占用,禁止下发命令
|
continue;
|
}
|
//行走路径空闲,锁定路径
|
RgvUtils.lockPath(startPath, endPath, rgvProtocol.getRgvNo(), true);
|
|
// 命令下发区 --------------------------------------------------------------------------
|
RgvCommand rgvCommand = new RgvCommand();
|
rgvCommand.setRgvNo(wrkMast.getRgvNo()); // RGV编号
|
rgvCommand.setAckFinish1((short) 0); // 工位1任务完成确认位
|
rgvCommand.setTaskNo1(wrkMast.getWrkNo().shortValue()); // 工位1工作号
|
rgvCommand.setTaskMode1(RgvTaskModeType.PUT); // 工位1任务模式: 放货
|
rgvCommand.setDestinationStaNo1(wrkMast.getRgvDstaNo().shortValue()); //工位1目标站点
|
rgvCommand.setCommand((short) 1); //工位1任务确认
|
if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getRgvNo(), new Task(4, rgvCommand))) {
|
//step=2,工位1、2写任务; step=4,工位1写任务; step=5,工位2写任务
|
log.error("RGV命令下发失败,RGV号={},任务数据={}", wrkMast.getRgvNo(), JSON.toJSON(rgvCommand));
|
} else {
|
// 修改工作档状态 4.RGV取货完成 => 5.RGV放货中
|
Date now = new Date();
|
wrkMast.setWrkSts(5L);
|
wrkMast.setModiTime(now);
|
if (wrkMastMapper.updateById(wrkMast) == 0) {
|
log.error("修改工作档状态 4.RGV取货完成 => 5.RGV放货中 失败!!,工作号={}", wrkMast.getWrkNo());
|
}
|
}
|
} else if (wrkMast.getWrkSts() == 23) {//23.设备上走1 => 24.RGV取货中
|
if (rgvProtocol.getTaskNo1() != 0 || rgvProtocol.getLoaded1() != 0) {//RGV是否无任务、RGV是否无货
|
continue;
|
}
|
|
//判断行走路径是否被占用
|
Integer staNo = wrkMast.getSourceStaNo();
|
BasDevp basDevp = basDevpService.selectById(staNo);
|
if (basDevp == null) {
|
continue;//目标站不存在
|
}
|
//起始路径
|
int startPath = rgvProtocol.getRgvPos().intValue();
|
//目标路径值
|
int endPath = basDevp.getLocType3().intValue();
|
boolean pathUsed = RgvUtils.isPathUsed(startPath, endPath);//判断行走路径是否被占用
|
if (pathUsed) {
|
//行走路径被占用,禁止下发命令
|
continue;
|
}
|
//行走路径空闲,锁定路径
|
RgvUtils.lockPath(startPath, endPath, rgvProtocol.getRgvNo(), true);
|
|
// 命令下发区 --------------------------------------------------------------------------
|
RgvCommand rgvCommand = new RgvCommand();
|
rgvCommand.setRgvNo(wrkMast.getRgvNo()); // RGV编号
|
rgvCommand.setAckFinish1((short) 0); // 工位1任务完成确认位
|
rgvCommand.setTaskNo1(wrkMast.getWrkNo().shortValue()); // 工位1工作号
|
rgvCommand.setTaskMode1(RgvTaskModeType.FETCH); // 工位1任务模式: 取货
|
rgvCommand.setDestinationStaNo1(wrkMast.getRgvDstaNo().shortValue()); //工位1目标站点
|
rgvCommand.setCommand((short) 1); //工位1任务确认
|
if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getRgvNo(), new Task(4, rgvCommand))) {
|
//step=2,工位1、2写任务; step=4,工位1写任务; step=5,工位2写任务
|
log.error("RGV命令下发失败,RGV号={},任务数据={}", wrkMast.getRgvNo(), JSON.toJSON(rgvCommand));
|
} else {
|
// 修改工作档状态 23.设备上走1 => 24.RGV取货中
|
Date now = new Date();
|
wrkMast.setWrkSts(24L);
|
wrkMast.setModiTime(now);
|
if (wrkMastMapper.updateById(wrkMast) == 0) {
|
log.error("修改工作档状态 23.设备上走1 => 24.RGV取货中 失败!!,工作号={}", wrkMast.getWrkNo());
|
}
|
}
|
} else if (wrkMast.getWrkSts() == 25) {//25.RGV取货完成 => 26.RGV放货中
|
if (rgvProtocol.getTaskNo1() == 0 || !rgvProtocol.getTaskNo1().equals(wrkMast.getWrkNo().shortValue())) {//RGV必须有任务且任务和当前工作档一致
|
continue;
|
}
|
if (rgvProtocol.getLoaded1() == 0) {//RGV必须有物
|
continue;
|
}
|
|
//判断行走路径是否被占用
|
Integer staNo = wrkMast.getStaNo();
|
BasDevp basDevp = basDevpService.selectById(staNo);
|
if (basDevp == null) {
|
continue;//目标站不存在
|
}
|
//起始路径
|
int startPath = rgvProtocol.getRgvPos().intValue();
|
//目标路径值
|
int endPath = basDevp.getLocType3().intValue();
|
boolean pathUsed = RgvUtils.isPathUsed(startPath, endPath);//判断行走路径是否被占用
|
if (pathUsed) {
|
//行走路径被占用,禁止下发命令
|
continue;
|
}
|
//行走路径空闲,锁定路径
|
RgvUtils.lockPath(startPath, endPath, rgvProtocol.getRgvNo(), true);
|
|
// 命令下发区 --------------------------------------------------------------------------
|
RgvCommand rgvCommand = new RgvCommand();
|
rgvCommand.setRgvNo(wrkMast.getRgvNo()); // RGV编号
|
rgvCommand.setAckFinish1((short) 0); // 工位1任务完成确认位
|
rgvCommand.setTaskNo1(wrkMast.getWrkNo().shortValue()); // 工位1工作号
|
rgvCommand.setTaskMode1(RgvTaskModeType.PUT); // 工位1任务模式: 放货
|
rgvCommand.setDestinationStaNo1(wrkMast.getRgvDstaNo().shortValue()); //工位1目标站点
|
rgvCommand.setCommand((short) 1); //工位1任务确认
|
if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getRgvNo(), new Task(4, rgvCommand))) {
|
//step=2,工位1、2写任务; step=4,工位1写任务; step=5,工位2写任务
|
log.error("RGV命令下发失败,RGV号={},任务数据={}", wrkMast.getRgvNo(), JSON.toJSON(rgvCommand));
|
} else {
|
// 修改工作档状态 25.RGV取货完成 => 26.RGV放货中
|
Date now = new Date();
|
wrkMast.setWrkSts(26L);
|
wrkMast.setModiTime(now);
|
if (wrkMastMapper.updateById(wrkMast) == 0) {
|
log.error("修改工作档状态 25.RGV取货完成 => 26.RGV放货中 失败!!,工作号={}", wrkMast.getWrkNo());
|
}
|
}
|
}
|
}
|
|
}
|
}
|
}
|
|
/**
|
* 回原点,堆垛机没有执行中任务,设备存在入库任务时叫回原点
|
*/
|
public synchronized void crnRebackHp(CrnProtocol crnProtocol, CrnThread crnThread) {
|
// for (CrnSlave crn : slaveProperties.getCrn()) {
|
// // 获取堆垛机信息
|
// CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
|
// CrnProtocol crnProtocol = crnThread.getCrnProtocol();
|
// if (crnProtocol == null) {
|
// continue;
|
// }
|
// BasCrnp basCrnp = basCrnpService.selectById(crn.getId());
|
// if (basCrnp == null) {
|
// log.error("{}号堆垛机尚未在数据库进行维护!", crn.getId());
|
// continue;
|
// }
|
if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO) {
|
if (crnProtocol.getBay() == 1 && crnProtocol.getLevel() == 1) {
|
return;
|
}
|
|
// 已经存在吊车执行任务时,则过滤3,12
|
if (wrkMastMapper.selectWorking(crnProtocol.getCrnNo()) != null) {
|
return;
|
}
|
|
//堆垛机有执行中任务,过滤3,4,11,12
|
if (wrkMastMapper.selectCrnWorking(crnProtocol.getCrnNo()) != null) {
|
return;
|
}
|
|
//输送线没有入库任务,过滤2
|
if (wrkMastMapper.selectDevWorking(crnProtocol.getCrnNo()) == null) {
|
return;
|
}
|
log.info("堆垛机召回原点==>>" + crnProtocol.getCrnNo() + "号堆垛机有入库任务,召回原点");
|
// 命令下发区 --------------------------------------------------------------------------
|
CrnCommand crnCommand = new CrnCommand();
|
crnCommand.setCrnNo(crnProtocol.getCrnNo()); // 堆垛机编号
|
crnCommand.setTaskNo((short) 9999); // 工作号
|
crnCommand.setAckFinish((short) 0); // 任务完成确认位
|
crnCommand.setTaskMode(CrnTaskModeType.GO_ORIGIN); // 任务模式: 回原点
|
crnCommand.setSourcePosX((short) 0); // 源库位排
|
crnCommand.setSourcePosY((short) 0); // 源库位列
|
crnCommand.setSourcePosZ((short) 0); // 源库位层
|
crnCommand.setDestinationPosX((short) 0); // 目标库位排
|
crnCommand.setDestinationPosY((short) 0); // 目标库位列
|
crnCommand.setDestinationPosZ((short) 0); // 目标库位层
|
if (!MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(2, crnCommand))) {
|
log.error("堆垛机回原点命令下发失败,堆垛机号={},任务数据={}", crnProtocol.getCrnNo(), JSON.toJSON(crnCommand));
|
}
|
crnThread.setBackHpFlag(true);
|
}
|
// }
|
}
|
|
/**
|
* 入库 ===>> 堆垛机站到库位
|
*/
|
public synchronized void crnStnToLoc(CrnSlave slave, CrnProtocol crnProtocol) {
|
for (CrnSlave.CrnStn crnStn : slave.getCrnInStn()) {
|
boolean flag = false;
|
// 获取堆垛机入库站信息
|
DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
|
StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
|
if (staProtocol == null) {
|
continue;
|
} else {
|
staProtocol = staProtocol.clone();
|
}
|
// 查询站点详细信息
|
BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
|
if (staDetl == null) {
|
log.error("入库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo());
|
continue;
|
}
|
if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() > 0 && staProtocol.isInEnable()
|
&& staDetl.getCanining() != null && staDetl.getCanining().equals("Y")) {
|
flag = true;
|
}
|
if (!flag) {
|
continue;
|
}
|
// 获取工作状态为2(设备上走)的入库工作档
|
WrkMast wrkMast = wrkMastMapper.selectPakInStep2(slave.getId(), staProtocol.getWorkNo().intValue(), crnStn.getStaNo());
|
if (null == wrkMast) {
|
// log.error("查询无待入库数据--wrk_sts=2, 工作号={}", staProtocol.getWorkNo());
|
continue;
|
}
|
// 获取库位信息
|
LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
|
if (locMast == null) {
|
log.error("查询库存无数据--库位号{}", wrkMast.getLocNo());
|
continue;
|
}
|
if (!locMast.getLocSts().equals("S") && !locMast.getLocSts().equals("Q")) {
|
log.error("入库操作库位状态不符合--状态, 库位号={},库位状态={}", wrkMast.getLocNo(), locMast.getLocSts());
|
continue;
|
}
|
|
// 堆垛机控制过滤
|
if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
|
continue;
|
}
|
|
// 已经存在吊车执行任务时,则过滤
|
if (wrkMastMapper.selectWorking(slave.getId()) != null) {
|
continue;
|
}
|
|
// 双深库位且浅库位有货,则需先对浅库位进行库位移转
|
if (Utils.isDeepLoc(slaveProperties, wrkMast.getLocNo())) {
|
String shallowLocNo = Utils.getShallowLoc(slaveProperties, wrkMast.getLocNo());
|
LocMast shallowLoc = locMastService.selectById(shallowLocNo);
|
// O.空库位、Q.拣料/盘点/并板再入库、S.入库预约、X.禁用 直接搬!
|
if (shallowLoc.getLocSts().equals("P") || shallowLoc.getLocSts().equals("R")) {
|
WrkMast waitWrkMast = wrkMastMapper.selectByLocNo(shallowLocNo);
|
if (null == waitWrkMast) {
|
log.error("{}库位异常,未检索到相应工作档!", shallowLocNo);
|
} else {
|
waitWrkMast.setIoPri(15D);
|
waitWrkMast.setModiTime(new Date());
|
if (wrkMastMapper.updateById(waitWrkMast) == 0) {
|
log.error("调整工作档优先级失败!工作号={}", waitWrkMast.getWrkNo());
|
}
|
continue;
|
}
|
|
} else if (shallowLoc.getLocSts().equals("F") || shallowLoc.getLocSts().equals("D")) {
|
// 此标记避免多次执行移库任务
|
if (Cools.isEmpty(wrkMast.getUpdMk()) || "N".equals(wrkMast.getUpdMk())) {
|
wrkMast.setUpdMk("Y");
|
wrkMast.setIoPri(14D);
|
wrkMastMapper.updateById(wrkMast);
|
// 生成工作档,将浅库位移转到新的库位中
|
moveLocForDeepLoc(slave, shallowLoc);
|
// 生成工作档、改变浅库位的源库/目标库 库位状态、下发堆垛机命令(立马执行)
|
// moveLocForDeepLocPakin(slave, shallowLoc, wrkMast);
|
}
|
continue;
|
} else if (shallowLoc.getLocSts().equals("Q")) {
|
WrkMast waitWrkMast = wrkMastMapper.selectByLocNo1(shallowLocNo);
|
if (null != waitWrkMast && waitWrkMast.getWrkSts() == 4) {
|
continue;
|
}
|
}
|
}
|
|
// 命令下发区 --------------------------------------------------------------------------
|
CrnCommand crnCommand = new CrnCommand();
|
crnCommand.setCrnNo(slave.getId()); // 堆垛机编号
|
crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 工作号
|
crnCommand.setAckFinish((short) 0); // 任务完成确认位
|
crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式: 库位移转
|
crnCommand.setSourcePosX(crnStn.getRow().shortValue()); // 源库位排
|
crnCommand.setSourcePosY(crnStn.getBay().shortValue()); // 源库位列
|
crnCommand.setSourcePosZ(crnStn.getLev().shortValue()); // 源库位层
|
crnCommand.setDestinationPosX(locMast.getRow1().shortValue()); // 目标库位排
|
crnCommand.setDestinationPosY(locMast.getBay1().shortValue()); // 目标库位列
|
crnCommand.setDestinationPosZ(locMast.getLev1().shortValue()); // 目标库位层
|
if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
|
log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
|
} else {
|
|
// long startTime = System.currentTimeMillis();
|
// while ((System.currentTimeMillis() - startTime) < COMMAND_TIMEOUT) {
|
//
|
// if (true) {
|
// break;
|
// }
|
//
|
// try{
|
// Thread.sleep(500);
|
// }catch(Exception ignore){}
|
// }
|
|
// 修改工作档状态 2.设备上走 => 3.吊车入库中
|
Date now = new Date();
|
wrkMast.setWrkSts(3L);
|
wrkMast.setCrnStrTime(now);
|
wrkMast.setModiTime(now);
|
if (wrkMastMapper.updateById(wrkMast) == 0) {
|
log.error("修改工作档状态 2.设备上走 => 3.吊车入库中 失败!!,工作号={}", wrkMast.getWrkNo());
|
}
|
}
|
}
|
}
|
|
/**
|
* 入库 ===>> 堆垛机站到库位
|
* 2022-12-03 TQS修改,先遍历查询同台堆垛机工作档所有站点入库任务LIST,根据工作档任务排序优先级高于 根据堆垛机入库站点排序
|
*/
|
public synchronized void crnStnToLoc1(CrnSlave slave, CrnProtocol crnProtocol) {
|
List<WrkMast> wrkMasts = wrkMastMapper.selectPakInStep12(slave.getId());
|
for(WrkMast wrkMast : wrkMasts){
|
if (wrkMast == null) {
|
continue;
|
}
|
|
CrnSlave.CrnStn crnStn = null;
|
for (CrnSlave.CrnStn crnStn1 : slave.getCrnInStn()){
|
if(crnStn1.getStaNo() == wrkMast.getStaNo()){
|
crnStn = crnStn1;
|
break;
|
} else {
|
continue;
|
}
|
}
|
if(Cools.isEmpty(crnStn)){
|
continue;
|
}
|
|
boolean flag = false;
|
// 获取堆垛机入库站信息
|
DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
|
StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
|
if (staProtocol == null) {
|
continue;
|
} else {
|
staProtocol = staProtocol.clone();
|
}
|
// 查询站点详细信息
|
BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
|
if (staDetl == null) {
|
log.error("入库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo());
|
continue;
|
}
|
if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() > 0 && staProtocol.isInEnable()
|
&& staDetl.getCanining() != null && staDetl.getCanining().equals("Y")) {
|
flag = true;
|
}
|
if (!flag) {
|
continue;
|
}
|
|
// 获取库位信息
|
LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
|
if (locMast == null) {
|
log.error("查询库存无数据--库位号{}", wrkMast.getLocNo());
|
continue;
|
}
|
if (!locMast.getLocSts().equals("S") && !locMast.getLocSts().equals("Q")) {
|
log.error("入库操作库位状态不符合--状态, 库位号={},库位状态={}", wrkMast.getLocNo(), locMast.getLocSts());
|
continue;
|
}
|
|
// 堆垛机控制过滤
|
if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
|
continue;
|
}
|
|
// 已经存在吊车执行任务时,则过滤
|
if (wrkMastMapper.selectWorking(slave.getId()) != null) {
|
continue;
|
}
|
|
// 双深库位且浅库位有货,则需先对浅库位进行库位移转
|
if (Utils.isDeepLoc(slaveProperties, wrkMast.getLocNo())) {
|
String shallowLocNo = Utils.getShallowLoc(slaveProperties, wrkMast.getLocNo());
|
LocMast shallowLoc = locMastService.selectById(shallowLocNo);
|
// O.空库位、Q.拣料/盘点/并板再入库、S.入库预约、X.禁用 直接搬!
|
if (shallowLoc.getLocSts().equals("P") || shallowLoc.getLocSts().equals("R")) {
|
WrkMast waitWrkMast = wrkMastMapper.selectByLocNo(shallowLocNo);
|
if (null == waitWrkMast) {
|
log.error("{}库位异常,未检索到相应工作档!", shallowLocNo);
|
} else {
|
waitWrkMast.setIoPri(15D);
|
waitWrkMast.setModiTime(new Date());
|
if (wrkMastMapper.updateById(waitWrkMast) == 0) {
|
log.error("调整工作档优先级失败!工作号={}", waitWrkMast.getWrkNo());
|
}
|
continue;
|
}
|
|
} else if (shallowLoc.getLocSts().equals("F") || shallowLoc.getLocSts().equals("D")) {
|
// 此标记避免多次执行移库任务
|
if (Cools.isEmpty(wrkMast.getUpdMk()) || "N".equals(wrkMast.getUpdMk())) {
|
wrkMast.setUpdMk("Y");
|
wrkMast.setIoPri(14D);
|
wrkMastMapper.updateById(wrkMast);
|
// 生成工作档,将浅库位移转到新的库位中
|
moveLocForDeepLoc(slave, shallowLoc);
|
// 生成工作档、改变浅库位的源库/目标库 库位状态、下发堆垛机命令(立马执行)
|
// moveLocForDeepLocPakin(slave, shallowLoc, wrkMast);
|
}
|
continue;
|
} else if (shallowLoc.getLocSts().equals("Q")) {
|
WrkMast waitWrkMast = wrkMastMapper.selectByLocNo1(shallowLocNo);
|
if (null != waitWrkMast && waitWrkMast.getWrkSts() == 4) {
|
continue;
|
}
|
}
|
}
|
|
// 命令下发区 --------------------------------------------------------------------------
|
CrnCommand crnCommand = new CrnCommand();
|
crnCommand.setCrnNo(slave.getId()); // 堆垛机编号
|
crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 工作号
|
crnCommand.setAckFinish((short) 0); // 任务完成确认位
|
crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式: 库位移转
|
crnCommand.setSourcePosX(crnStn.getRow().shortValue()); // 源库位排
|
crnCommand.setSourcePosY(crnStn.getBay().shortValue()); // 源库位列
|
crnCommand.setSourcePosZ(crnStn.getLev().shortValue()); // 源库位层
|
crnCommand.setDestinationPosX(locMast.getRow1().shortValue()); // 目标库位排
|
crnCommand.setDestinationPosY(locMast.getBay1().shortValue()); // 目标库位列
|
crnCommand.setDestinationPosZ(locMast.getLev1().shortValue()); // 目标库位层
|
if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
|
log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
|
} else {
|
// 修改工作档状态 2.设备上走 => 3.吊车入库中
|
Date now = new Date();
|
wrkMast.setWrkSts(3L);
|
wrkMast.setCrnStrTime(now);
|
wrkMast.setModiTime(now);
|
if (wrkMastMapper.updateById(wrkMast) == 0) {
|
log.error("修改工作档状态 2.设备上走 => 3.吊车入库中 失败!!,工作号={}", wrkMast.getWrkNo());
|
}
|
}
|
}
|
|
}
|
|
/**
|
* 出库 ===>> 库位到堆垛机站
|
* 2022-06-09 TQS修改,查询工作档LIST,遍历下发,防止第一个任务堵塞出库
|
*/
|
public synchronized void locToCrnStn(CrnSlave slave, CrnProtocol crnProtocol) {
|
for (CrnSlave.CrnStn crnStn : slave.getCrnOutStn()) {
|
// 获取工作状态为11(生成出库ID)的出库工作档
|
// WrkMast wrkMast = wrkMastMapper.selectPakOutStep1(slave.getId(), crnStn.getStaNo());
|
List<WrkMast> wrkMasts = wrkMastMapper.selectPakOutStep11(slave.getId(), crnStn.getStaNo());
|
for (WrkMast wrkMast : wrkMasts) {
|
if (wrkMast == null) {
|
continue;
|
}
|
// 工作档状态判断
|
if (wrkMast.getIoType() < 100 || wrkMast.getSourceStaNo() == null) {
|
log.error("查询工作档数据不符合条件--入出类型/站点, 工作号={},源库位={},入出类型={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getIoType());
|
continue;
|
}
|
// 获取源库位信息
|
LocMast sourceSta = locMastService.selectById(wrkMast.getSourceLocNo());
|
if (!sourceSta.getLocSts().equals("R") && !sourceSta.getLocSts().equals("P")) {
|
log.error("出库操作库位状态不符合--状态, 库位号={},库位状态={}", wrkMast.getLocNo(), sourceSta.getLocSts());
|
continue;
|
}
|
// 获取堆垛机出库站信息
|
SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
|
StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
|
if (staProtocol == null) {
|
break;
|
// continue;
|
} else {
|
staProtocol = staProtocol.clone();
|
}
|
|
// // 入出库模式判断
|
// if (devpThread.ioMode != IoModeType.PAKOUT_MODE) { continue; }
|
if (wrkMast.getStaNo() == 204 && devpThread.ioModeOf2F != IoModeType.PAKOUT_MODE) {
|
continue;
|
}
|
|
// 查询站点详细信息
|
BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
|
if (staDetl == null) {
|
log.error("出库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo());
|
break;
|
// continue;
|
}
|
// 判断堆垛机出库站状态
|
if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y")
|
&& staProtocol.getWorkNo() == 0 && staProtocol.isOutEnable()) {
|
// 命令下发区 --------------------------------------------------------------------------
|
|
// 堆垛机控制过滤
|
if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
|
// continue;
|
break;
|
}
|
|
// 双深库位且浅库位有货,则需先对浅库位进行库位移转
|
if (Utils.isDeepLoc(slaveProperties, wrkMast.getSourceLocNo())) {
|
String shallowLocNo = Utils.getShallowLoc(slaveProperties, wrkMast.getSourceLocNo());
|
LocMast shallowLoc = locMastService.selectById(shallowLocNo);
|
// O.空库位、Q.拣料/盘点/并板再入库、S.入库预约、X.禁用 直接搬!
|
if (shallowLoc.getLocSts().equals("P") || shallowLoc.getLocSts().equals("R")) {
|
WrkMast waitWrkMast = wrkMastMapper.selectByLocNo(shallowLocNo);
|
if (null == waitWrkMast) {
|
log.error("{}库位异常,未检索到相应工作档!", shallowLocNo);
|
} else {
|
if (waitWrkMast.getWrkSts() == 11) {
|
waitWrkMast.setIoPri(15D);
|
waitWrkMast.setModiTime(new Date());
|
if (wrkMastMapper.updateById(waitWrkMast) == 0) {
|
log.error("调整工作档优先级失败!工作号={}", waitWrkMast.getWrkNo());
|
}
|
continue;
|
} else {
|
|
}
|
}
|
} else if (shallowLoc.getLocSts().equals("F") || shallowLoc.getLocSts().equals("D")) {
|
// WrkMast waitWrkMast = wrkMastMapper.selectByLocNo(shallowLocNo);
|
//2022-08-16 modify,不根据updmk标记移库任务(容易被取消导致堵塞),查询工作档是否存在任务
|
WrkMast waitWrkMast = wrkMastMapper.selectByLocNo1(shallowLocNo);
|
// 此标记避免多次执行移库任务
|
// if (Cools.isEmpty(wrkMast.getUpdMk()) || "N".equals(wrkMast.getUpdMk())
|
// || Cools.isEmpty(waitWrkMast)) {
|
if (Cools.isEmpty(waitWrkMast)) {
|
wrkMast.setUpdMk("Y");
|
wrkMastMapper.updateById(wrkMast);
|
// 生成工作档,将浅库位移转到新的库位中
|
moveLocForDeepLoc(slave, shallowLoc);
|
}
|
log.error("{}任务出库失败,浅库位堵塞!浅库位号:{}", wrkMast.getWrkNo(), shallowLocNo);
|
continue;
|
} else if (shallowLoc.getLocSts().equals("Q") || shallowLoc.getLocSts().equals("S")) {
|
WrkMast waitWrkMast = wrkMastMapper.selectByLocNo1(shallowLocNo);
|
if (null != waitWrkMast && waitWrkMast.getWrkSts() == 4) {
|
continue;
|
}
|
}
|
}
|
|
// 已经存在吊车执行任务时,则过滤
|
if (wrkMastMapper.selectWorking(slave.getId()) != null) {
|
break;
|
// return;
|
}
|
|
// 1.堆垛机开始移动
|
CrnCommand crnCommand = new CrnCommand();
|
crnCommand.setCrnNo(slave.getId()); // 堆垛机编号
|
crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 工作号
|
crnCommand.setAckFinish((short) 0); // 任务完成确认位
|
crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式: 库位移转
|
crnCommand.setSourcePosX(sourceSta.getRow1().shortValue()); // 源库位排
|
crnCommand.setSourcePosY(sourceSta.getBay1().shortValue()); // 源库位列
|
crnCommand.setSourcePosZ(sourceSta.getLev1().shortValue()); // 源库位层
|
crnCommand.setDestinationPosX(crnStn.getRow().shortValue()); // 目标库位排
|
crnCommand.setDestinationPosY(crnStn.getBay().shortValue()); // 目标库位列
|
crnCommand.setDestinationPosZ(crnStn.getLev().shortValue()); // 目标库位层
|
if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
|
log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
|
} else {
|
// 修改工作档状态 11.生成出库ID => 12.吊车出库中
|
Date now = new Date();
|
wrkMast.setWrkSts(12L);
|
wrkMast.setCrnStrTime(now);
|
wrkMast.setModiTime(now);
|
if (wrkMastMapper.updateById(wrkMast) == 0) {
|
log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", wrkMast.getWrkNo());
|
}
|
break;
|
}
|
}
|
}
|
}
|
}
|
|
/**
|
* 出库 ===>> 库位到堆垛机站
|
* 2022-12-03 TQS修改,先遍历查询工作档所有站点出库任务LIST,根据工作档任务排序优先级高于 根据堆垛机入库站点排序
|
*/
|
public synchronized void locToCrnStn1(CrnSlave slave, CrnProtocol crnProtocol) {
|
List<WrkMast> wrkMasts = wrkMastMapper.selectPakOutStep12(slave.getId());
|
for (WrkMast wrkMast : wrkMasts) {
|
if (wrkMast == null) {
|
continue;
|
}
|
|
CrnSlave.CrnStn crnStn = null;
|
for (CrnSlave.CrnStn crnStn1 : slave.getCrnOutStn()){
|
if(crnStn1.getStaNo() == wrkMast.getSourceStaNo()){
|
crnStn = crnStn1;
|
break;
|
} else {
|
continue;
|
}
|
}
|
if(Cools.isEmpty(crnStn)){
|
continue;
|
}
|
|
// 工作档状态判断
|
if (wrkMast.getIoType() < 100 || wrkMast.getSourceStaNo() == null) {
|
log.error("查询工作档数据不符合条件--入出类型/站点, 工作号={},源库位={},入出类型={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getIoType());
|
continue;
|
}
|
// 获取源库位信息
|
LocMast sourceSta = locMastService.selectById(wrkMast.getSourceLocNo());
|
if (!sourceSta.getLocSts().equals("R") && !sourceSta.getLocSts().equals("P")) {
|
log.error("出库操作库位状态不符合--状态, 库位号={},库位状态={}", wrkMast.getLocNo(), sourceSta.getLocSts());
|
continue;
|
}
|
// 获取堆垛机出库站信息
|
SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
|
StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
|
if (staProtocol == null) {
|
break;
|
// continue;
|
} else {
|
staProtocol = staProtocol.clone();
|
}
|
|
// // 入出库模式判断
|
// if (devpThread.ioMode != IoModeType.PAKOUT_MODE) { continue; }
|
if (wrkMast.getStaNo() == 204 && devpThread.ioModeOf2F != IoModeType.PAKOUT_MODE) {
|
continue;
|
}
|
|
// 查询站点详细信息
|
BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
|
if (staDetl == null) {
|
log.error("出库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo());
|
break;
|
// continue;
|
}
|
// 判断堆垛机出库站状态
|
if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y")
|
&& staProtocol.getWorkNo() == 0 && staProtocol.isOutEnable()) {
|
// 命令下发区 --------------------------------------------------------------------------
|
|
// 堆垛机控制过滤
|
if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
|
// continue;
|
break;
|
}
|
|
// 双深库位且浅库位有货,则需先对浅库位进行库位移转
|
if (Utils.isDeepLoc(slaveProperties, wrkMast.getSourceLocNo())) {
|
String shallowLocNo = Utils.getShallowLoc(slaveProperties, wrkMast.getSourceLocNo());
|
LocMast shallowLoc = locMastService.selectById(shallowLocNo);
|
// O.空库位、Q.拣料/盘点/并板再入库、S.入库预约、X.禁用 直接搬!
|
if (shallowLoc.getLocSts().equals("P") || shallowLoc.getLocSts().equals("R")) {
|
WrkMast waitWrkMast = wrkMastMapper.selectByLocNo(shallowLocNo);
|
if (null == waitWrkMast) {
|
log.error("{}库位异常,未检索到相应工作档!", shallowLocNo);
|
} else {
|
if (waitWrkMast.getWrkSts() == 11) {
|
waitWrkMast.setIoPri(15D);
|
waitWrkMast.setModiTime(new Date());
|
if (wrkMastMapper.updateById(waitWrkMast) == 0) {
|
log.error("调整工作档优先级失败!工作号={}", waitWrkMast.getWrkNo());
|
}
|
continue;
|
} else {
|
|
}
|
}
|
} else if (shallowLoc.getLocSts().equals("F") || shallowLoc.getLocSts().equals("D")) {
|
// WrkMast waitWrkMast = wrkMastMapper.selectByLocNo(shallowLocNo);
|
//2022-08-16 modify,不根据updmk标记移库任务(容易被取消导致堵塞),查询工作档是否存在任务
|
WrkMast waitWrkMast = wrkMastMapper.selectByLocNo1(shallowLocNo);
|
// 此标记避免多次执行移库任务
|
// if (Cools.isEmpty(wrkMast.getUpdMk()) || "N".equals(wrkMast.getUpdMk())
|
// || Cools.isEmpty(waitWrkMast)) {
|
if (Cools.isEmpty(waitWrkMast)) {
|
wrkMast.setUpdMk("Y");
|
wrkMastMapper.updateById(wrkMast);
|
// 生成工作档,将浅库位移转到新的库位中
|
moveLocForDeepLoc(slave, shallowLoc);
|
}
|
log.error("{}任务出库失败,浅库位堵塞!浅库位号:{}", wrkMast.getWrkNo(), shallowLocNo);
|
continue;
|
} else if (shallowLoc.getLocSts().equals("Q") || shallowLoc.getLocSts().equals("S")) {
|
WrkMast waitWrkMast = wrkMastMapper.selectByLocNo1(shallowLocNo);
|
if (null != waitWrkMast && waitWrkMast.getWrkSts() == 4) {
|
continue;
|
}
|
}
|
}
|
|
// 已经存在吊车执行任务时,则过滤
|
if (wrkMastMapper.selectWorking(slave.getId()) != null) {
|
break;
|
// return;
|
}
|
|
// 1.堆垛机开始移动
|
CrnCommand crnCommand = new CrnCommand();
|
crnCommand.setCrnNo(slave.getId()); // 堆垛机编号
|
crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 工作号
|
crnCommand.setAckFinish((short) 0); // 任务完成确认位
|
crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式: 库位移转
|
crnCommand.setSourcePosX(sourceSta.getRow1().shortValue()); // 源库位排
|
crnCommand.setSourcePosY(sourceSta.getBay1().shortValue()); // 源库位列
|
crnCommand.setSourcePosZ(sourceSta.getLev1().shortValue()); // 源库位层
|
crnCommand.setDestinationPosX(crnStn.getRow().shortValue()); // 目标库位排
|
crnCommand.setDestinationPosY(crnStn.getBay().shortValue()); // 目标库位列
|
crnCommand.setDestinationPosZ(crnStn.getLev().shortValue()); // 目标库位层
|
if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
|
log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
|
} else {
|
// 修改工作档状态 11.生成出库ID => 12.吊车出库中
|
Date now = new Date();
|
wrkMast.setWrkSts(12L);
|
wrkMast.setCrnStrTime(now);
|
wrkMast.setModiTime(now);
|
if (wrkMastMapper.updateById(wrkMast) == 0) {
|
log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", wrkMast.getWrkNo());
|
}
|
break;
|
}
|
}
|
}
|
|
}
|
|
/**
|
* 查找工作状态为2(设备上走),且RGV入库接驳站符合的的入库工作档,提取出最多2笔
|
* @param slave
|
* @return
|
*/
|
public synchronized List<WrkMast> getRgvInTask(RgvSlave slave){
|
List<WrkMast> wrkMastTask = new ArrayList<>();
|
List<Integer> staNos = new ArrayList<>();
|
for (RgvSlave.RgvStn rgvStn : slave.getRgvInSStn()) {
|
staNos.add(rgvStn.getStaNo());
|
}
|
if(staNos.size() < 1){
|
return null;
|
}
|
List<WrkMast> wrkMasts = wrkMastMapper.selectRgvInStep1(slave.getId(), staNos);
|
for(WrkMast wrkMast : wrkMasts){
|
Integer plcId = 0;
|
for (RgvSlave.RgvStn rgvStn : slave.getRgvInSStn()) {
|
if(rgvStn.getStaNo() == wrkMast.getRgvSstaNo()){
|
plcId = rgvStn.getDevpPlcId();
|
break;
|
}
|
}
|
|
DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, plcId);
|
//判断RGV入库源站点,自动、有物,有任务号,可出
|
boolean flag1 = false;
|
StaProtocol staProtocol1 = devpThread.getStation().get(wrkMast.getRgvSstaNo());
|
if (staProtocol1 == null) {
|
continue;
|
} else {
|
staProtocol1 = staProtocol1.clone();
|
}
|
// 查询站点详细信息
|
BasDevp staDetl1 = basDevpService.selectById(wrkMast.getRgvSstaNo());
|
if (staDetl1 == null) {
|
log.error("RGV入库 ===>> 输送机源站点在数据库不存在, 站点编号={}", wrkMast.getRgvSstaNo());
|
continue;
|
}
|
if (staProtocol1.isAutoing() && staProtocol1.isLoading() && staProtocol1.getWorkNo().intValue() == wrkMast.getWrkNo()
|
&& staProtocol1.isOutEnable() && staDetl1.getOutEnable() != null && staDetl1.getOutEnable().equals("Y")) {
|
flag1 = true;
|
}
|
|
//判断RGV入库目标站点,自动、无物,没有任务号,可入
|
boolean flag2 = false;
|
StaProtocol staProtocol2 = devpThread.getStation().get(wrkMast.getRgvDstaNo());
|
if (staProtocol2 == null) {
|
continue;
|
} else {
|
staProtocol2 = staProtocol2.clone();
|
}
|
// 查询站点详细信息
|
BasDevp staDetl2 = basDevpService.selectById(wrkMast.getRgvSstaNo());
|
if (staDetl2 == null) {
|
log.error("RGV入库 ===>> 输送机源站点在数据库不存在, 站点编号={}", wrkMast.getRgvSstaNo());
|
continue;
|
}
|
if (staProtocol2.isAutoing() && staProtocol2.isLoading() && staProtocol2.getWorkNo().intValue() == wrkMast.getWrkNo()
|
&& staProtocol2.isInEnable() && staDetl2.getCanining() != null && staDetl2.getCanining().equals("Y")) {
|
flag2 = true;
|
}
|
|
if(flag1 && flag2){
|
wrkMastTask.add(wrkMast);
|
if(wrkMastTask.size() >= 2) break;
|
}
|
}
|
return wrkMastTask;
|
}
|
|
/**
|
* 入库 ===>> RGV入库站到站
|
*/
|
public synchronized void rgvInStn(RgvSlave slave, RgvProtocol rgvProtocol) {
|
WrkMast wrkMast = wrkMastMapper.selectRgvInSteNo(slave.getId());
|
|
|
//查找工作状态为2(设备上走),且RGV入库接驳站符合的的入库工作档,提取出最多2笔
|
List<WrkMast> wrkMastTask = getRgvInTask(slave);
|
if(wrkMastTask.size() <= 0){
|
return;
|
}
|
|
// RGV控制过滤, 必须满足自动、空闲,没有任务号
|
if (!rgvProtocol.getStatusType().equals(CrnStatusType.IDLE)
|
|| rgvProtocol.getModeType() != RgvModeType.AUTO
|
|| rgvProtocol.getTaskNo1() != 0 || rgvProtocol.getTaskNo2() != 0) {
|
return;
|
}
|
|
// 已经存在RGV执行任务时,则过滤
|
if(wrkMastMapper.selectRgvInWorking(slave.getId()).size() > 0){
|
return;
|
}
|
|
if(wrkMastTask.size() == 2){
|
//有2笔RGV待入库任务,2个工位,取货、放货任务同时下发
|
WrkMast wrkMast1 = wrkMastTask.get(0);
|
WrkMast wrkMast2 = wrkMastTask.get(1);
|
if(Cools.isEmpty(wrkMast1) || Cools.isEmpty(wrkMast2)){
|
log.error("工作档RGV入库数据为空");
|
return;
|
}
|
// 命令下发区 --------------------------------------------------------------------------
|
RgvCommand rgvCommand = new RgvCommand();
|
rgvCommand.setRgvNo(slave.getId()); // RGV编号
|
rgvCommand.setAckFinish1((short) 0); // 工位1任务完成确认位
|
rgvCommand.setTaskNo1(wrkMast1.getWrkNo().shortValue()); // 工位1工作号
|
rgvCommand.setTaskMode1(RgvTaskModeType.FETCH_PUT); // 工位1任务模式: 取放货
|
rgvCommand.setSourceStaNo1(wrkMast1.getRgvSstaNo().shortValue()); //工位1源站点
|
rgvCommand.setDestinationStaNo1(wrkMast1.getRgvDstaNo().shortValue()); //工位1目标站点
|
rgvCommand.setAckFinish2((short) 0); // 工位2任务完成确认位
|
rgvCommand.setTaskNo2(wrkMast2.getWrkNo().shortValue()); // 工位2工作号
|
rgvCommand.setTaskMode2(RgvTaskModeType.FETCH_PUT); // 工位2任务模式: 取放货
|
rgvCommand.setSourceStaNo2(wrkMast2.getRgvSstaNo().shortValue()); //工位2源站点
|
rgvCommand.setDestinationStaNo2(wrkMast2.getRgvDstaNo().shortValue()); //工位2目标站点
|
rgvCommand.setCommand((short) 0); //工位1、2任务确认
|
if (!MessageQueue.offer(SlaveType.Crn, wrkMast1.getRgvNo(), new Task(2, rgvCommand))) {
|
//step=2,工位1、2写任务; step=4,工位1写任务; step=5,工位2写任务
|
log.error("RGV命令下发失败,RGV号={},任务数据={}", slave.getId(), JSON.toJSON(rgvCommand));
|
} else {
|
// 修改工作档状态 2.设备上走 => 6.RGV入库取货中
|
Date now = new Date();
|
wrkMast1.setWrkSts(6L);
|
wrkMast1.setCrnStrTime(now);
|
wrkMast1.setModiTime(now);
|
if (wrkMastMapper.updateById(wrkMast1) == 0) {
|
log.error("修改工作档状态 2.设备上走 => 6.RGV入库取货中 失败!!,工作号={}", wrkMast1.getWrkNo());
|
}
|
|
wrkMast2.setWrkSts(6L);
|
wrkMast2.setCrnStrTime(now);
|
wrkMast2.setModiTime(now);
|
if (wrkMastMapper.updateById(wrkMast2) == 0) {
|
log.error("修改工作档状态 2.设备上走 => 6.RGV入库取货中 失败!!,工作号={}", wrkMast2.getWrkNo());
|
}
|
}
|
} else if(wrkMastTask.size() == 1){
|
//只有1笔RGV待入库任务,先下发取货任务,取货后再判断是否有下一笔待入库任务
|
WrkMast wrkMast1 = wrkMastTask.get(0);
|
if(Cools.isEmpty(wrkMast1)){
|
log.error("工作档RGV入库数据为空");
|
return;
|
}
|
// 命令下发区 --------------------------------------------------------------------------
|
RgvCommand rgvCommand = new RgvCommand();
|
rgvCommand.setRgvNo(slave.getId()); // RGV编号
|
rgvCommand.setAckFinish1((short) 0); // 工位1任务完成确认位
|
rgvCommand.setTaskNo1(wrkMast1.getWrkNo().shortValue()); // 工位1工作号
|
rgvCommand.setTaskMode1(RgvTaskModeType.FETCH); // 工位1任务模式: 取货
|
rgvCommand.setSourceStaNo1(wrkMast1.getRgvSstaNo().shortValue()); //工位1源站点
|
rgvCommand.setDestinationStaNo1(wrkMast1.getRgvDstaNo().shortValue()); //工位1目标站点
|
rgvCommand.setCommand((short) 0); //工位1、2任务确认
|
if (!MessageQueue.offer(SlaveType.Crn, wrkMast1.getRgvNo(), new Task(4, rgvCommand))) {
|
//step=2,工位1、2任务确认; step=4,工位1确认; step=5,工位2任务确认
|
log.error("RGV命令下发失败,RGV号={},任务数据={}", slave.getId(), JSON.toJSON(rgvCommand));
|
} else {
|
// 修改工作档状态 2.设备上走 => 6.RGV入库取货中
|
Date now = new Date();
|
wrkMast1.setWrkSts(6L);
|
wrkMast1.setCrnStrTime(now);
|
wrkMast1.setModiTime(now);
|
if (wrkMastMapper.updateById(wrkMast1) == 0) {
|
log.error("修改工作档状态 2.设备上走 => 6.RGV入库取货中 失败!!,工作号={}", wrkMast1.getWrkNo());
|
}
|
}
|
}
|
}
|
|
/**
|
* 出库 ===>> RGV出库站到站
|
*/
|
public synchronized void rgvOutStn(RgvSlave slave, RgvProtocol rgvProtocol) {
|
//查找工作状态为14(出库完成),且RGV出库接驳站符合的的出库工作档,提取出最多2笔
|
List<WrkMast> wrkMastTask = getRgvOutTask(slave);
|
if(wrkMastTask.size() <= 0){
|
return;
|
}
|
|
// RGV控制过滤, 必须满足自动、空闲,没有任务号
|
if (!rgvProtocol.getStatusType().equals(CrnStatusType.IDLE)
|
|| rgvProtocol.getModeType() != RgvModeType.AUTO
|
|| rgvProtocol.getTaskNo1() != 0 || rgvProtocol.getTaskNo2() != 0) {
|
return;
|
}
|
|
// 已经存在RGV执行任务时,则过滤
|
if(wrkMastMapper.selectRgvOutWorking(slave.getId()).size() > 0){
|
return;
|
}
|
|
if(wrkMastTask.size() == 2){
|
//有2笔RGV待入库任务,2个工位,取货、放货任务同时下发
|
WrkMast wrkMast1 = wrkMastTask.get(0);
|
WrkMast wrkMast2 = wrkMastTask.get(1);
|
if(Cools.isEmpty(wrkMast1) || Cools.isEmpty(wrkMast2)){
|
log.error("工作档RGV入库数据为空");
|
return;
|
}
|
// 命令下发区 --------------------------------------------------------------------------
|
RgvCommand rgvCommand = new RgvCommand();
|
rgvCommand.setRgvNo(slave.getId()); // RGV编号
|
rgvCommand.setAckFinish1((short) 0); // 工位1任务完成确认位
|
rgvCommand.setTaskNo1(wrkMast1.getWrkNo().shortValue()); // 工位1工作号
|
rgvCommand.setTaskMode1(RgvTaskModeType.FETCH_PUT); // 工位1任务模式: 取放货
|
rgvCommand.setSourceStaNo1(wrkMast1.getRgvSstaNo().shortValue()); //工位1源站点
|
rgvCommand.setDestinationStaNo1(wrkMast1.getRgvDstaNo().shortValue()); //工位1目标站点
|
rgvCommand.setAckFinish2((short) 0); // 工位2任务完成确认位
|
rgvCommand.setTaskNo2(wrkMast2.getWrkNo().shortValue()); // 工位2工作号
|
rgvCommand.setTaskMode2(RgvTaskModeType.FETCH_PUT); // 工位2任务模式: 取放货
|
rgvCommand.setSourceStaNo2(wrkMast2.getRgvSstaNo().shortValue()); //工位2源站点
|
rgvCommand.setDestinationStaNo2(wrkMast2.getRgvDstaNo().shortValue()); //工位2目标站点
|
rgvCommand.setCommand((short) 0); //工位1、2任务确认
|
if (!MessageQueue.offer(SlaveType.Crn, wrkMast1.getRgvNo(), new Task(2, rgvCommand))) {
|
//step=2,工位1、2写任务; step=4,工位1写任务; step=5,工位2写任务
|
log.error("RGV命令下发失败,RGV号={},任务数据={}", slave.getId(), JSON.toJSON(rgvCommand));
|
} else {
|
// 修改工作档状态 14.出库完成 => 16.RGV出库取货中
|
Date now = new Date();
|
wrkMast1.setWrkSts(16L);
|
wrkMast1.setCrnStrTime(now);
|
wrkMast1.setModiTime(now);
|
if (wrkMastMapper.updateById(wrkMast1) == 0) {
|
log.error("修改工作档状态 14.出库完成 => 16.RGV出库取货中 失败!!,工作号={}", wrkMast1.getWrkNo());
|
}
|
|
wrkMast2.setWrkSts(16L);
|
wrkMast2.setCrnStrTime(now);
|
wrkMast2.setModiTime(now);
|
if (wrkMastMapper.updateById(wrkMast2) == 0) {
|
log.error("修改工作档状态 14.出库完成 => 16.RGV出库取货中 失败!!,工作号={}", wrkMast2.getWrkNo());
|
}
|
}
|
} else if(wrkMastTask.size() == 1){
|
//只有1笔RGV待入库任务,先下发取货任务,取货后再判断是否有下一笔待入库任务
|
WrkMast wrkMast1 = wrkMastTask.get(0);
|
if(Cools.isEmpty(wrkMast1)){
|
log.error("工作档RGV入库数据为空");
|
return;
|
}
|
// 命令下发区 --------------------------------------------------------------------------
|
RgvCommand rgvCommand = new RgvCommand();
|
rgvCommand.setRgvNo(slave.getId()); // RGV编号
|
rgvCommand.setAckFinish1((short) 0); // 工位1任务完成确认位
|
rgvCommand.setTaskNo1(wrkMast1.getWrkNo().shortValue()); // 工位1工作号
|
rgvCommand.setTaskMode1(RgvTaskModeType.FETCH); // 工位1任务模式: 取货
|
rgvCommand.setSourceStaNo1(wrkMast1.getRgvSstaNo().shortValue()); //工位1源站点
|
rgvCommand.setDestinationStaNo1(wrkMast1.getRgvDstaNo().shortValue()); //工位1目标站点
|
rgvCommand.setCommand((short) 0); //工位1、2任务确认
|
if (!MessageQueue.offer(SlaveType.Crn, wrkMast1.getRgvNo(), new Task(4, rgvCommand))) {
|
//step=2,工位1、2任务确认; step=4,工位1确认; step=5,工位2任务确认
|
log.error("RGV命令下发失败,RGV号={},任务数据={}", slave.getId(), JSON.toJSON(rgvCommand));
|
} else {
|
// 修改工作档状态 14.出库完成 => 16.RGV出库取货中
|
Date now = new Date();
|
wrkMast1.setWrkSts(16L);
|
wrkMast1.setCrnStrTime(now);
|
wrkMast1.setModiTime(now);
|
if (wrkMastMapper.updateById(wrkMast1) == 0) {
|
log.error("修改工作档状态 14.出库完成 => 16.RGV出库取货中 失败!!,工作号={}", wrkMast1.getWrkNo());
|
}
|
}
|
}
|
}
|
|
/**
|
* 查找工作状态为14(出库完成),且RGV出库接驳站符合的的出库工作档,提取出最多2笔
|
* @param slave
|
* @return
|
*/
|
public synchronized List<WrkMast> getRgvOutTask(RgvSlave slave){
|
List<WrkMast> wrkMastTask = new ArrayList<>();
|
List<Integer> staNos = new ArrayList<>();
|
for (RgvSlave.RgvStn rgvStn : slave.getRgvOutSStn()) {
|
staNos.add(rgvStn.getStaNo());
|
}
|
if(staNos.size() < 1){
|
return null;
|
}
|
List<WrkMast> wrkMasts = wrkMastMapper.selectRgvOutStep1(slave.getId(), staNos);
|
for(WrkMast wrkMast : wrkMasts){
|
Integer plcId = 0;
|
for (RgvSlave.RgvStn rgvStn : slave.getRgvOutSStn()) {
|
if(rgvStn.getStaNo() == wrkMast.getRgvSstaNo()){
|
plcId = rgvStn.getDevpPlcId();
|
break;
|
}
|
}
|
|
DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, plcId);
|
//判断RGV出库源站点,自动、有物,有任务号,可出
|
boolean flag1 = false;
|
StaProtocol staProtocol1 = devpThread.getStation().get(wrkMast.getRgvSstaNo());
|
if (staProtocol1 == null) {
|
continue;
|
} else {
|
staProtocol1 = staProtocol1.clone();
|
}
|
// 查询站点详细信息
|
BasDevp staDetl1 = basDevpService.selectById(wrkMast.getRgvSstaNo());
|
if (staDetl1 == null) {
|
log.error("RGV出库 ===>> 输送机源站点在数据库不存在, 站点编号={}", wrkMast.getRgvSstaNo());
|
continue;
|
}
|
if (staProtocol1.isAutoing() && staProtocol1.isLoading() && staProtocol1.getWorkNo().intValue() == wrkMast.getWrkNo()
|
&& staProtocol1.isOutEnable() && staDetl1.getOutEnable() != null && staDetl1.getOutEnable().equals("Y")) {
|
flag1 = true;
|
}
|
|
//判断RGV出库目标站点,自动、无物,没有任务号,可入
|
boolean flag2 = false;
|
StaProtocol staProtocol2 = devpThread.getStation().get(wrkMast.getRgvDstaNo());
|
if (staProtocol2 == null) {
|
continue;
|
} else {
|
staProtocol2 = staProtocol2.clone();
|
}
|
// 查询站点详细信息
|
BasDevp staDetl2 = basDevpService.selectById(wrkMast.getRgvSstaNo());
|
if (staDetl2 == null) {
|
log.error("RGV出库 ===>> 输送机源站点在数据库不存在, 站点编号={}", wrkMast.getRgvSstaNo());
|
continue;
|
}
|
if (staProtocol2.isAutoing() && staProtocol2.isLoading() && staProtocol2.getWorkNo().intValue() == wrkMast.getWrkNo()
|
&& staProtocol2.isInEnable() && staDetl2.getCanining() != null && staDetl2.getCanining().equals("Y")) {
|
flag2 = true;
|
}
|
|
if(flag1 && flag2){
|
wrkMastTask.add(wrkMast);
|
if(wrkMastTask.size() >= 2) break;
|
}
|
}
|
return wrkMastTask;
|
}
|
|
/**
|
* 根据RGV完成信号,执行对工作档的完成操作,和RGV的任务下发
|
*/
|
public synchronized void rgvFinished() {
|
Date now = new Date();
|
for (RgvSlave rgv : slaveProperties.getRgv()) {
|
// 获取RGV信息
|
RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgv.getId());
|
RgvProtocol rgvProtocol = rgvThread.getRgvProtocol();
|
if (rgvProtocol == null) {
|
continue;
|
}
|
//判断RGV是否空闲,工位1是否空闲,工位1是否有物,是否为电脑模式,工位1是否有工作号
|
if (rgvProtocol.statusType1 == RgvStatusType.FETCHWAITING
|
&& rgvProtocol.getModeType() == RgvModeType.AUTO
|
&& rgvProtocol.getTaskNo1() != 0
|
&& rgvProtocol.getStatus() != 0
|
&& rgvProtocol.getStatus1() != 0
|
) {
|
WrkMast wrkMast1 = wrkMastMapper.selectPakInStep3(rgvProtocol.getTaskNo1().intValue());
|
if (wrkMast1 == null) {
|
log.error("RGV工位1处于等待确认且取货任务完成状态,但未找到工作档。RGV号={},工作号={}", rgv.getId(), rgvProtocol.getTaskNo1());
|
continue;
|
}
|
|
if (wrkMast1.getWrkSts() == 3) {//3.RGV取货中 => 4.RGV取货完成
|
wrkMast1.setWrkSts(4L);
|
}else if(wrkMast1.getWrkSts() == 5){//5.RGV放货中 => 6.RGV放货完成
|
rgvProtocol.setTaskNo1((short) 0);//入库任务完成,清空任务号
|
wrkMast1.setWrkSts(6L);
|
} else if (wrkMast1.getWrkSts() == 24) {//24.RGV取货中 => 25.RGV取货完成
|
wrkMast1.setWrkSts(25L);//
|
} else if (wrkMast1.getWrkSts() == 26) {//26.RGV放货中 => 27.RGV放货完成
|
rgvProtocol.setTaskNo1((short) 0);//出库任务完成,清空任务号
|
wrkMast1.setWrkSts(27L);//27.RGV放货完成
|
}
|
|
wrkMast1.setModiTime(now);
|
if (wrkMastMapper.updateById(wrkMast1) == 0) {
|
log.error("工位1修改工作档状态失败!!,工作号={}", wrkMast1.getWrkNo());
|
}
|
|
// //工位1取货完成后,工位2是无货空闲状态时,准备给工位2发任务,确认是否有待执行RGV任务
|
// if (rgvProtocol.getModeType() == RgvModeType.AUTO
|
// && rgvProtocol.getTaskNo1() > 0 && rgvProtocol.getTaskNo2() == 0
|
// && rgvProtocol.getLoaded1() > 0 && rgvProtocol.getLoaded2() == 0
|
// && rgvProtocol.getStatusType2() == RgvStatusType.IDLE
|
// ) {
|
// WrkMast wrkMast1 = wrkMastMapper.selectPakInStep3(rgvProtocol.getTaskNo1().intValue());
|
// if (wrkMast1 == null) {
|
// log.error("RGV工位1处于等待确认且取货任务完成状态,但未找到工作档。RGV号={},工作号={}", rgv.getId(), rgvProtocol.getTaskNo1());
|
// continue;
|
// }
|
// List<WrkMast> wrkMastTask = new ArrayList<>();
|
// List<WrkMast> list = new ArrayList<>();
|
// Integer type = 0;//1入库,2出库
|
// if(wrkMast1.getWrkSts()==6L){
|
// wrkMastTask = getRgvInTask(rgv);
|
// list = wrkMastMapper.selectRgvInWorking(rgv.getId());
|
// type = 1;
|
// } else if(wrkMast1.getWrkSts()==16L){
|
// wrkMastTask = getRgvOutTask(rgv);
|
// list = wrkMastMapper.selectRgvOutWorking(rgv.getId());
|
// type = 2;
|
// }
|
// if(wrkMastTask.size() > 0){//有继续执行任务,下发取货任务给工位2
|
// // 已经存在RGV执行任务时,则过滤
|
// if (list.size() > 1) {
|
// continue;
|
// }
|
// WrkMast wrkMast2 = wrkMastTask.get(0);
|
// // 命令下发区 --------------------------------------------------------------------------
|
// RgvCommand rgvCommand = new RgvCommand();
|
// rgvCommand.setRgvNo(rgv.getId()); // RGV编号
|
// rgvCommand.setAckFinish2((short) 0); // 工位2任务完成确认位
|
// rgvCommand.setTaskNo2(wrkMast2.getWrkNo().shortValue()); // 工位2工作号
|
// rgvCommand.setTaskMode2(RgvTaskModeType.FETCH); // 工位2任务模式: 取货
|
// rgvCommand.setSourceStaNo2(wrkMast2.getRgvSstaNo().shortValue()); //工位2源站点
|
// rgvCommand.setDestinationStaNo2(wrkMast2.getRgvDstaNo().shortValue()); //工位2目标站点
|
// rgvCommand.setCommand((short) 0); //工位1、2任务确认
|
// if (!MessageQueue.offer(SlaveType.Crn, wrkMast2.getRgvNo(), new Task(5, rgvCommand))) {
|
// //step=2,工位1、2写任务; step=4,工位1写任务; step=5,工位2写任务
|
// log.error("RGV命令下发失败,RGV号={},任务数据={}", rgv.getId(), JSON.toJSON(rgvCommand));
|
// } else {
|
// // 修改工作档状态 2.设备上走 => 6.RGV入库取货中
|
// Date now = new Date();
|
// wrkMast2.setWrkSts(type==1 ? 6L : 16L);
|
// wrkMast2.setCrnStrTime(now);
|
// wrkMast2.setModiTime(now);
|
// if (wrkMastMapper.updateById(wrkMast2) == 0) {
|
// log.error("工位2修改工作档状态 2/14.设备上走 => 6/16.RGV入库取货中 失败!!,工作号={}", wrkMast2.getWrkNo());
|
// }
|
// }
|
// } else {//没有继续执行任务,下发放货任务给工位1
|
// if(type == 1 && wrkMast1.getWrkSts() != 6L){//RGV入库取货中
|
// continue;
|
// }
|
// if(type == 2 && wrkMast1.getWrkSts() != 16L){//RGV出库取货中
|
// continue;
|
// }
|
//
|
// // 命令下发区 --------------------------------------------------------------------------
|
// RgvCommand rgvCommand = new RgvCommand();
|
// rgvCommand.setRgvNo(rgv.getId()); // RGV编号
|
// rgvCommand.setAckFinish1((short) 0); // 工位1任务完成确认位
|
// rgvCommand.setTaskNo1(wrkMast1.getWrkNo().shortValue()); // 工位1工作号
|
// rgvCommand.setTaskMode1(RgvTaskModeType.PUT); // 工位1任务模式: 放货
|
// rgvCommand.setSourceStaNo1(wrkMast1.getRgvSstaNo().shortValue()); //工位1源站点
|
// rgvCommand.setDestinationStaNo1(wrkMast1.getRgvDstaNo().shortValue()); //工位1目标站点
|
// rgvCommand.setCommand((short) 0); //工位1、2任务确认
|
// if (!MessageQueue.offer(SlaveType.Crn, wrkMast1.getRgvNo(), new Task(4, rgvCommand))) {
|
// //step=2,工位1、2任务确认; step=4,工位1确认; step=5,工位2任务确认
|
// log.error("RGV命令下发失败,RGV号={},任务数据={}", rgv.getId(), JSON.toJSON(rgvCommand));
|
// } else {
|
// // 修改工作档状态 6.RGV入库取货中 => 7.RGV入库放货中
|
// Date now = new Date();
|
// wrkMast1.setWrkSts(type==1 ? 7L : 17L);
|
// wrkMast1.setCrnEndTime(now);
|
// wrkMast1.setModiTime(now);
|
// if (wrkMastMapper.updateById(wrkMast1) == 0) {
|
// log.error("修改工作档状态 6/16.RGV入库取货中 => 7/17.RGV入库放货中 失败!!,工作号={}", wrkMast1.getWrkNo());
|
// }
|
// log.error("RGV命令下发成功,RGV号={},任务数据={}", rgv.getId(), JSON.toJSON(rgvCommand));
|
// }
|
// }
|
// } else if (rgvProtocol.getModeType() == RgvModeType.AUTO
|
// && rgvProtocol.getTaskNo1() > 0 && rgvProtocol.getTaskNo2() > 0
|
// && rgvProtocol.getLoaded1() > 0 && rgvProtocol.getLoaded2() > 0
|
// && rgvProtocol.statusType2 == RgvStatusType.FETCHWAITING){
|
// // 工位2状态:也是取货完成等待确认91 并且 任务完成位 = 1, 工位1、2同时下发放货任务
|
// WrkMast wrkMast1 = wrkMastMapper.selectPakInStep3(rgvProtocol.getTaskNo1().intValue());
|
// WrkMast wrkMast2 = wrkMastMapper.selectPakInStep3(rgvProtocol.getTaskNo2().intValue());
|
// // 命令下发区 --------------------------------------------------------------------------
|
// RgvCommand rgvCommand = new RgvCommand();
|
// rgvCommand.setRgvNo(rgv.getId()); // RGV编号
|
// rgvCommand.setAckFinish1((short) 0); // 工位1任务完成确认位
|
// rgvCommand.setTaskNo1(wrkMast1.getWrkNo().shortValue()); // 工位1工作号
|
// rgvCommand.setTaskMode1(RgvTaskModeType.PUT); // 工位1任务模式: 放货
|
// rgvCommand.setSourceStaNo1(wrkMast1.getRgvSstaNo().shortValue()); //工位1源站点
|
// rgvCommand.setDestinationStaNo1(wrkMast1.getRgvDstaNo().shortValue()); //工位1目标站点
|
// rgvCommand.setAckFinish2((short) 0); // 工位2任务完成确认位
|
// rgvCommand.setTaskNo2(wrkMast2.getWrkNo().shortValue()); // 工位2工作号
|
// rgvCommand.setTaskMode2(RgvTaskModeType.PUT); // 工位2任务模式: 放货
|
// rgvCommand.setSourceStaNo2(wrkMast2.getRgvSstaNo().shortValue()); //工位2源站点
|
// rgvCommand.setDestinationStaNo2(wrkMast2.getRgvDstaNo().shortValue()); //工位2目标站点
|
// rgvCommand.setCommand((short) 0); //工位1、2任务确认
|
// if (!MessageQueue.offer(SlaveType.Crn, wrkMast1.getRgvNo(), new Task(2, rgvCommand))) {
|
// //step=2,工位1、2任务确认; step=4,工位1确认; step=5,工位2任务确认
|
// log.error("RGV命令下发失败,RGV号={},任务数据={}", rgv.getId(), JSON.toJSON(rgvCommand));
|
// } else {
|
// // 修改工作档状态 2.设备上走 => 6.RGV入库取货中
|
// Date now = new Date();
|
// wrkMast1.setWrkSts(wrkMast1.getWrkSts()==6L ? 7L : 17L);
|
// wrkMast1.setCrnStrTime(now);
|
// wrkMast1.setModiTime(now);
|
// if (wrkMastMapper.updateById(wrkMast1) == 0) {
|
// log.error("修改工作档状态 6/16.RGV入库取货中 => 7/17.RGV入库放货中 失败!!,工作号={}", wrkMast1.getWrkNo());
|
// }
|
//
|
// wrkMast2.setWrkSts(wrkMast2.getWrkSts()==6L ? 7L : 17L);
|
// wrkMast2.setCrnStrTime(now);
|
// wrkMast2.setModiTime(now);
|
// if (wrkMastMapper.updateById(wrkMast2) == 0) {
|
// log.error("修改工作档状态 6/16.RGV入库取货中 => 7/17.RGV入库放货中 失败!!,工作号={}", wrkMast2.getWrkNo());
|
// }
|
// }
|
// }
|
}
|
|
}
|
}
|
|
/**
|
* 入出库 ===>> RGV出库站到堆垛机入库站/系统入库站
|
* rgvInDStnToCrnStn
|
*/
|
public synchronized void rgvDestStnToCrnStn() {
|
for (RgvSlave rgvSlave : slaveProperties.getRgv()) {
|
// 遍历入库任务的RGV出库站
|
for (RgvSlave.RgvStn rgvStn : rgvSlave.getRgvDestStn()) {
|
// 获取RGV出库站信息
|
DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, rgvStn.getDevpPlcId());
|
StaProtocol staProtocol = devpThread.getStation().get(rgvStn.getStaNo());
|
if (staProtocol == null) {
|
continue;
|
} else {
|
staProtocol = staProtocol.clone();
|
}
|
if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) {
|
// 查询工作档List
|
// List<WrkMast> wrkMasts = wrkMastMapper.selectRgvInStep2(staProtocol.getSiteId());
|
List<WrkMast> wrkMasts = wrkMastMapper.selectRgvDestStep2(staProtocol.getSiteId());
|
for(WrkMast wrkMast : wrkMasts){
|
// 判断工作档条件
|
if (wrkMast.getStaNo() == null || wrkMast.getSourceStaNo() == null
|
|| wrkMast.getRgvSstaNo() == null || wrkMast.getRgvDstaNo() == null) {
|
continue;
|
}
|
|
RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, wrkMast.getRgvNo());
|
RgvProtocol rgvProtocol = rgvThread.getRgvProtocol();
|
// 判断RGV状态等待确认,工位1
|
if (rgvProtocol.modeType == RgvModeType.AUTO && rgvProtocol.getTaskNo1().equals(wrkMast.getWrkNo().shortValue())
|
&& rgvProtocol.statusType1 == RgvStatusType.WAITING) {
|
// 命令下发区 --------------------------------------------------------------------------
|
// 下发站点信息
|
staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
|
staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
|
if (!MessageQueue.offer(SlaveType.Devp, rgvStn.getDevpPlcId(), new Task(2, staProtocol))) {
|
continue;
|
}
|
// 更新工作档状态为2,14
|
wrkMast.setWrkSts(wrkMast.getWrkSts()==7L ? 2L : 14L);
|
wrkMast.setOnlineYn("Y");
|
wrkMast.setCrnEndTime(new Date());
|
if (wrkMastMapper.updateById(wrkMast) != 0) {
|
// 复位RGV工位1
|
rgvThread.setResetFlag1(true);
|
} else {
|
log.error("RGV工位1接驳,更新工作档的工作状态为{}失败!!! [工作号:{}]", wrkMast.getWrkSts()==7L ? 2L : 14L, wrkMast.getWrkNo());
|
}
|
}
|
// 判断RGV状态等待确认,工位2
|
if (rgvProtocol.modeType == RgvModeType.AUTO && rgvProtocol.getTaskNo2().equals(wrkMast.getWrkNo().shortValue())
|
&& rgvProtocol.statusType2 == RgvStatusType.WAITING) {
|
// 命令下发区 --------------------------------------------------------------------------
|
// 下发站点信息
|
staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
|
staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
|
if (!MessageQueue.offer(SlaveType.Devp, rgvStn.getDevpPlcId(), new Task(2, staProtocol))) {
|
continue;
|
}
|
// 更新工作档状态为2,14
|
wrkMast.setWrkSts(wrkMast.getWrkSts()==7L ? 2L : 14L);
|
wrkMast.setOnlineYn("Y");
|
wrkMast.setCrnEndTime(new Date());
|
if (wrkMastMapper.updateById(wrkMast) != 0) {
|
// 复位RGV工位2
|
rgvThread.setResetFlag2(true);
|
} else {
|
log.error("RGV工位2接驳,更新工作档的工作状态为{}失败!!! [工作号:{}]", wrkMast.getWrkSts()==7L ? 2L : 14L, wrkMast.getWrkNo());
|
}
|
}
|
}
|
|
}
|
}
|
}
|
}
|
|
/**
|
* 出库 ===>> RGV出库站到系统出库站
|
*/
|
public synchronized void rgvOutDStnToOutStn() {
|
for (RgvSlave rgvSlave : slaveProperties.getRgv()) {
|
// 遍历出库任务的RGV出库站
|
for (RgvSlave.RgvStn rgvStn : rgvSlave.getRgvDestStn()) {
|
// 获取RGV出库站信息
|
DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, rgvStn.getDevpPlcId());
|
StaProtocol staProtocol = devpThread.getStation().get(rgvStn.getStaNo());
|
if (staProtocol == null) {
|
continue;
|
} else {
|
staProtocol = staProtocol.clone();
|
}
|
if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) {
|
// 查询工作档List
|
List<WrkMast> wrkMasts = wrkMastMapper.selectRgvOutStep2(staProtocol.getSiteId());
|
for(WrkMast wrkMast : wrkMasts){
|
// 判断工作档条件
|
if (wrkMast.getIoType() < 100 || wrkMast.getStaNo() == null || wrkMast.getSourceStaNo() == null
|
|| wrkMast.getRgvSstaNo() == null || wrkMast.getRgvDstaNo() == null) {
|
continue;
|
}
|
|
RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, wrkMast.getRgvNo());
|
RgvProtocol rgvProtocol = rgvThread.getRgvProtocol();
|
// 判断RGV状态等待确认,工位1
|
if (rgvProtocol.modeType == RgvModeType.AUTO && rgvProtocol.getTaskNo1().equals(wrkMast.getWrkNo().shortValue())
|
&& rgvProtocol.statusType1 == RgvStatusType.WAITING) {
|
// 命令下发区 --------------------------------------------------------------------------
|
// 下发站点信息
|
staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
|
staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
|
if (!MessageQueue.offer(SlaveType.Devp, rgvStn.getDevpPlcId(), new Task(2, staProtocol))) {
|
continue;
|
}
|
// 更新工作档状态为14
|
wrkMast.setWrkSts(14L);
|
wrkMast.setOnlineYn("Y"); //控制WMS将工作状态14转15的时机,只有RGV运搬完成后才可以转
|
wrkMast.setCrnEndTime(new Date());
|
if (wrkMastMapper.updateById(wrkMast) != 0) {
|
// 复位RGV工位1
|
rgvThread.setResetFlag1(true);
|
} else {
|
log.error("RGV工位1接驳,更新工作档的工作状态为2失败!!! [工作号:{}]", wrkMast.getWrkNo());
|
}
|
}
|
// 判断RGV状态等待确认,工位2
|
if (rgvProtocol.modeType == RgvModeType.AUTO && rgvProtocol.getTaskNo2().equals(wrkMast.getWrkNo().shortValue())
|
&& rgvProtocol.statusType2 == RgvStatusType.WAITING) {
|
// 命令下发区 --------------------------------------------------------------------------
|
// 下发站点信息
|
staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
|
staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
|
if (!MessageQueue.offer(SlaveType.Devp, rgvStn.getDevpPlcId(), new Task(2, staProtocol))) {
|
continue;
|
}
|
// 更新工作档状态为14
|
wrkMast.setWrkSts(14L);
|
wrkMast.setOnlineYn("Y"); //控制WMS将工作状态14转15的时机,只有RGV运搬完成后才可以转
|
wrkMast.setCrnEndTime(new Date());
|
if (wrkMastMapper.updateById(wrkMast) != 0) {
|
// 复位RGV工位2
|
rgvThread.setResetFlag2(true);
|
} else {
|
log.error("RGV工位2接驳,更新工作档的工作状态为2失败!!! [工作号:{}]", wrkMast.getWrkNo());
|
}
|
}
|
}
|
|
}
|
}
|
}
|
}
|
|
/**
|
* 库位移转
|
*/
|
public synchronized void locToLoc(CrnSlave slave, CrnProtocol crnProtocol) {
|
// 获取工作档信息
|
WrkMast wrkMast = wrkMastMapper.selectLocMove(slave.getId());
|
if (null == wrkMast) {
|
return;
|
}
|
// 获取源库位信息
|
LocMast sourceSta = locMastService.selectById(wrkMast.getSourceLocNo());
|
if (null == sourceSta) {
|
log.error("工作档库位移转失败,原因:检索源库位失败!工作号={},源库位={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
|
return;
|
}
|
// 源库位 库位状态判断
|
if (!sourceSta.getLocSts().equals("R") && !sourceSta.getLocSts().equals("S")) {
|
return;
|
}
|
// 获取目标库位信息
|
LocMast sta = locMastService.selectById(wrkMast.getLocNo());
|
if (null == sta) {
|
log.error("工作档库位移转失败,原因:检索目标库位失败!工作号={},源库位={}", wrkMast.getWrkNo(), wrkMast.getLocNo());
|
return;
|
}
|
// 获取堆垛机信息 并 判断是否可入出
|
BasCrnp basCrnp = basCrnpService.selectById(slave.getId());
|
if (!basCrnp.getInEnable().equals("Y") && !basCrnp.getOutEnable().equals("Y")) {
|
return;
|
}
|
|
// 堆垛机控制过滤
|
if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
|
return;
|
}
|
|
// 已经存在吊车执行任务时,则过滤
|
if (wrkMastMapper.selectWorking(slave.getId()) != null) {
|
return;
|
}
|
|
// 命令下发区 --------------------------------------------------------------------------
|
CrnCommand crnCommand = new CrnCommand();
|
crnCommand.setCrnNo(slave.getId()); // 堆垛机编号
|
crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 工作号
|
crnCommand.setAckFinish((short) 0); // 任务完成确认位
|
crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式: 库位移转
|
crnCommand.setSourcePosX(sourceSta.getRow1().shortValue()); // 源库位排
|
crnCommand.setSourcePosY(sourceSta.getBay1().shortValue()); // 源库位列
|
crnCommand.setSourcePosZ(sourceSta.getLev1().shortValue()); // 源库位层
|
crnCommand.setDestinationPosX(sta.getRow1().shortValue()); // 目标库位排
|
crnCommand.setDestinationPosY(sta.getBay1().shortValue()); // 目标库位列
|
crnCommand.setDestinationPosZ(sta.getLev1().shortValue()); // 目标库位层
|
if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
|
log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
|
} else {
|
// 修改工作档状态 11.生成出库ID => 12.吊车出库中
|
Date now = new Date();
|
wrkMast.setWrkSts(12L);
|
wrkMast.setCrnStrTime(now);
|
wrkMast.setModiTime(now);
|
if (wrkMastMapper.updateById(wrkMast) == 0) {
|
log.error("【库位移转】 修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", wrkMast.getWrkNo());
|
}
|
}
|
|
}
|
|
/**
|
* 执行对工作档的完成操作
|
*/
|
public synchronized void storeFinished() {
|
for (CrnSlave crn : slaveProperties.getCrn()) {
|
// 获取堆垛机信息
|
CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
|
CrnProtocol crnProtocol = crnThread.getCrnProtocol();
|
if (crnProtocol == null) {
|
continue;
|
}
|
// 状态:等待确认 并且 任务完成位 = 1
|
if (crnProtocol.statusType == CrnStatusType.WAITING && crnProtocol.getTaskNo() != 0) {
|
if (crnProtocol.getTaskNo() == 9999) {
|
// 堆垛机复位
|
crnThread.setResetFlag(true);
|
} else {
|
// 获取入库待确认工作档
|
WrkMast wrkMast = wrkMastMapper.selectPakInStep3(crnProtocol.getTaskNo().intValue());
|
if (wrkMast == null) {
|
log.error("堆垛机处于等待确认且任务完成状态,但未找到工作档。堆垛机号={},工作号={}", crn.getId(), crnProtocol.getTaskNo());
|
continue;
|
}
|
// 入库 + 库位转移 ==> 4.入库完成
|
if (wrkMast.getWrkSts() == 3 || (wrkMast.getWrkSts() == 12 && wrkMast.getIoType() == 11)) {
|
wrkMast.setWrkSts(4L);
|
} else {
|
continue;
|
}
|
Date now = new Date();
|
wrkMast.setCrnEndTime(now);
|
wrkMast.setModiTime(now);
|
// 修改成功后复位堆垛机
|
if (wrkMastMapper.updateById(wrkMast) > 0) {
|
// 堆垛机复位
|
crnThread.setResetFlag(true);
|
}
|
}
|
|
}
|
}
|
}
|
|
/**
|
* 异常信息记录
|
*/
|
public synchronized void recErr() {
|
try {
|
this.recCrnErr();
|
this.recRgvErr();
|
} catch (Exception e) {
|
log.error("recErr fail", e);
|
}
|
}
|
|
/**
|
* RGV异常信息记录
|
*/
|
public synchronized void recRgvErr() {
|
Date now = new Date();
|
for (RgvSlave rgv : slaveProperties.getRgv()) {
|
// 获取RGV信息
|
RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgv.getId());
|
RgvProtocol rgvProtocol = rgvThread.getRgvProtocol();
|
if (rgvProtocol == null) {
|
continue;
|
}
|
if (true) {
|
// 有任务
|
if (rgvProtocol.getTaskNo1() != 0 || rgvProtocol.getTaskNo2() != 0) {
|
Integer taskNo = rgvProtocol.getTaskNo1() > 0 ? rgvProtocol.getTaskNo1().intValue() : rgvProtocol.getTaskNo2().intValue();
|
BasRgvErrLog latest = basRgvErrLogService.findLatestByTaskNo(rgv.getId(), taskNo);
|
// 有异常
|
if (latest == null) {
|
if (rgvProtocol.getAlarm() != null && rgvProtocol.getAlarm() > 0) {
|
WrkMast wrkMast = wrkMastMapper.selectById(taskNo);
|
if (wrkMast == null) {
|
continue;
|
}
|
BasRgvErr rgvErr = basRgvErrMapper.selectById(rgvProtocol.getAlarm());
|
String errName = rgvErr == null ? String.valueOf(rgvProtocol.getAlarm()) : rgvErr.getErrName();
|
BasRgvErrLog basRgvErrLog = new BasRgvErrLog(
|
null, // 编号
|
wrkMast.getWrkNo(), // 工作号
|
now, // 发生时间
|
null, // 结束时间
|
wrkMast.getWrkSts(), // 工作状态
|
wrkMast.getIoType(), // 入出库类型
|
rgv.getId(), // 堆垛机
|
null, // plc
|
wrkMast.getLocNo(), // 目标库位
|
wrkMast.getStaNo(), // 目标站
|
wrkMast.getSourceStaNo(), // 源站
|
wrkMast.getSourceLocNo(), // 源库位
|
wrkMast.getBarcode(), // 条码
|
(int) rgvProtocol.getAlarm(), // 异常码
|
errName, // 异常
|
1, // 异常情况
|
now, // 添加时间
|
null, // 添加人员
|
now, // 修改时间
|
null, // 修改人员
|
"任务中异常" // 备注
|
);
|
|
if (!basRgvErrLogService.insert(basRgvErrLog)) {
|
log.error("RGV异常记录失败 ===>> [id:{}] [error:{}]", rgv.getId(), errName);
|
}
|
}
|
} else {
|
// 异常修复
|
if (rgvProtocol.getAlarm() == null || rgvProtocol.getAlarm() == 0) {
|
latest.setEndTime(now);
|
latest.setUpdateTime(now);
|
latest.setStatus(2);
|
if (!basRgvErrLogService.updateById(latest)) {
|
log.error("堆垛机plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", rgv.getId(), latest.getId());
|
}
|
}
|
}
|
// 无任务
|
} else {
|
BasRgvErrLog latest = basRgvErrLogService.findLatest(rgv.getId());
|
// 有异常
|
if (rgvProtocol.getAlarm() != null && rgvProtocol.getAlarm() > 0) {
|
// 记录新异常
|
if (latest == null || (latest.getErrCode() != rgvProtocol.getAlarm().intValue())) {
|
BasRgvErr rgvErr = basRgvErrMapper.selectById(rgvProtocol.getAlarm());
|
String errName = rgvErr == null ? String.valueOf(rgvProtocol.getAlarm()) : rgvErr.getErrName();
|
BasRgvErrLog basRgvErrLog = new BasRgvErrLog(
|
null, // 编号
|
null, // 工作号
|
now, // 发生时间
|
null, // 结束时间
|
null, // 工作状态
|
null, // 入出库类型
|
rgv.getId(), // 堆垛机
|
null, // plc
|
null, // 目标库位
|
null, // 目标站
|
null, // 源站
|
null, // 源库位
|
null, // 条码
|
(int) rgvProtocol.getAlarm(), // 异常码
|
errName, // 异常
|
1, // 异常情况
|
now, // 添加时间
|
null, // 添加人员
|
now, // 修改时间
|
null, // 修改人员
|
"无任务异常" // 备注
|
);
|
|
if (!basRgvErrLogService.insert(basRgvErrLog)) {
|
log.error("RGV异常记录失败 ===>> [id:{}] [error:{}]", rgv.getId(), errName);
|
}
|
}
|
// 无异常
|
} else {
|
// 异常修复
|
if (latest != null && latest.getStatus() == 1) {
|
latest.setEndTime(now);
|
latest.setUpdateTime(now);
|
latest.setStatus(2);
|
if (!basRgvErrLogService.updateById(latest)) {
|
log.error("RGV异常记录修复失败 ===>> [id:{}] [errLogId:{}]", rgv.getId(), latest.getId());
|
}
|
}
|
}
|
}
|
}
|
|
}
|
}
|
|
/**
|
* 堆垛机异常信息记录
|
*/
|
public synchronized void recCrnErr() {
|
Date now = new Date();
|
for (CrnSlave crn : slaveProperties.getCrn()) {
|
// 获取堆垛机信息
|
CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
|
CrnProtocol crnProtocol = crnThread.getCrnProtocol();
|
if (crnProtocol == null) {
|
continue;
|
}
|
if (true) {
|
// if (crnProtocol.getModeType() != CrnModeType.STOP) {
|
// 有任务
|
if (crnProtocol.getTaskNo() != 0) {
|
BasErrLog latest = basErrLogService.findLatestByTaskNo(crn.getId(), crnProtocol.getTaskNo().intValue());
|
// 有异常
|
if (latest == null) {
|
if (crnProtocol.getAlarm() != null && crnProtocol.getAlarm() > 0) {
|
WrkMast wrkMast = wrkMastMapper.selectById(crnProtocol.getTaskNo());
|
if (wrkMast == null) {
|
continue;
|
}
|
BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm());
|
String errName = crnError == null ? String.valueOf(crnProtocol.getAlarm()) : crnError.getErrName();
|
BasErrLog basErrLog = new BasErrLog(
|
null, // 编号
|
wrkMast.getWrkNo(), // 工作号
|
now, // 发生时间
|
null, // 结束时间
|
wrkMast.getWrkSts(), // 工作状态
|
wrkMast.getIoType(), // 入出库类型
|
crn.getId(), // 堆垛机
|
null, // plc
|
wrkMast.getLocNo(), // 目标库位
|
wrkMast.getStaNo(), // 目标站
|
wrkMast.getSourceStaNo(), // 源站
|
wrkMast.getSourceLocNo(), // 源库位
|
wrkMast.getBarcode(), // 条码
|
(int) crnProtocol.getAlarm(), // 异常码
|
errName, // 异常
|
1, // 异常情况
|
now, // 添加时间
|
null, // 添加人员
|
now, // 修改时间
|
null, // 修改人员
|
"任务中异常" // 备注
|
);
|
if (!basErrLogService.insert(basErrLog)) {
|
log.error("堆垛机plc异常记录失败 ===>> [id:{}] [error:{}]", crn.getId(), errName);
|
}
|
}
|
} else {
|
// 异常修复
|
if (crnProtocol.getAlarm() == null || crnProtocol.getAlarm() == 0) {
|
latest.setEndTime(now);
|
latest.setUpdateTime(now);
|
latest.setStatus(2);
|
if (!basErrLogService.updateById(latest)) {
|
log.error("堆垛机plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", crn.getId(), latest.getId());
|
}
|
}
|
}
|
// 无任务
|
} else {
|
BasErrLog latest = basErrLogService.findLatest(crn.getId());
|
// 有异常
|
if (crnProtocol.getAlarm() != null && crnProtocol.getAlarm() > 0) {
|
// 记录新异常
|
if (latest == null || (latest.getErrCode() != crnProtocol.getAlarm().intValue())) {
|
BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm());
|
String errName = crnError == null ? String.valueOf(crnProtocol.getAlarm()) : crnError.getErrName();
|
BasErrLog basErrLog = new BasErrLog(
|
null, // 编号
|
null, // 工作号
|
now, // 发生时间
|
null, // 结束时间
|
null, // 工作状态
|
null, // 入出库类型
|
crn.getId(), // 堆垛机
|
null, // plc
|
null, // 目标库位
|
null, // 目标站
|
null, // 源站
|
null, // 源库位
|
null, // 条码
|
(int) crnProtocol.getAlarm(), // 异常码
|
errName, // 异常
|
1, // 异常情况
|
now, // 添加时间
|
null, // 添加人员
|
now, // 修改时间
|
null, // 修改人员
|
"无任务异常" // 备注
|
);
|
if (!basErrLogService.insert(basErrLog)) {
|
log.error("堆垛机plc异常记录失败 ===>> [id:{}] [error:{}]", crn.getId(), errName);
|
}
|
}
|
// 无异常
|
} else {
|
// 异常修复
|
if (latest != null && latest.getStatus() == 1) {
|
latest.setEndTime(now);
|
latest.setUpdateTime(now);
|
latest.setStatus(2);
|
if (!basErrLogService.updateById(latest)) {
|
log.error("堆垛机plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", crn.getId(), latest.getId());
|
}
|
}
|
}
|
}
|
}
|
|
}
|
}
|
|
// -------------------------------------------------------------------------------
|
|
/**
|
* 空栈板初始化入库,叉车入库站放货
|
*/
|
public synchronized void storeEmptyPlt() {
|
for (DevpSlave devp : slaveProperties.getDevp()) {
|
// 遍历空板入库口
|
for (DevpSlave.Sta emptyInSta : devp.getEmptyInSta()) {
|
// 获取空板入库站信息
|
SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
|
StaProtocol staProtocol = devpThread.getStation().get(emptyInSta.getStaNo());
|
if (staProtocol == null) {
|
continue;
|
} else {
|
staProtocol = staProtocol.clone();
|
}
|
|
// 站点条件判断
|
if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable()
|
&& staProtocol.isEmptyMk() && (staProtocol.getWorkNo() > 9990 && staProtocol.getWorkNo() <= 9999) && staProtocol.isPakMk()) {
|
|
try {
|
LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
|
|
SearchLocParam param = new SearchLocParam();
|
param.setIoType(10);
|
param.setSourceStaNo(emptyInSta.getStaNo());
|
param.setLocType1(locTypeDto.getLocType1());
|
String response = new HttpHandler.Builder()
|
.setUri(wmsUrl)
|
.setPath("/rpc/pakin/loc/v1")
|
.setJson(JSON.toJSONString(param))
|
.build()
|
.doPost();
|
JSONObject jsonObject = JSON.parseObject(response);
|
if (jsonObject.getInteger("code").equals(200)) {
|
StartupDto dto = jsonObject.getObject("data", StartupDto.class);
|
|
// 更新站点信息 且 下发plc命令
|
staProtocol.setWorkNo(dto.getWorkNo().shortValue());
|
staProtocol.setStaNo(dto.getStaNo().shortValue());
|
devpThread.setPakMk(staProtocol.getSiteId(), false);
|
boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
|
if (!result) {
|
throw new CoolException("更新plc站点信息失败");
|
}
|
} else {
|
log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
}
|
|
|
// // 检索库位
|
// LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
|
// StartupDto startupDto = commonService.getLocNo(1, 10, emptyInSta.getStaNo(), null, locTypeDto, 0);
|
// // 工作号
|
// int workNo = startupDto.getWorkNo();
|
//
|
// try {
|
// // 插入工作主档
|
// WrkMast wrkMast = new WrkMast();
|
// wrkMast.setWrkNo(workNo);
|
// wrkMast.setIoTime(new Date());
|
// wrkMast.setWrkSts(2L); // 工作状态:2.设备上走
|
// wrkMast.setIoType(10); // 入出库状态:10.空板入库
|
// wrkMast.setIoPri(10D); // 优先级:10
|
// wrkMast.setCrnNo(startupDto.getCrnNo());
|
// wrkMast.setSourceStaNo(startupDto.getSourceStaNo());
|
// wrkMast.setStaNo(startupDto.getStaNo());
|
// wrkMast.setLocNo(startupDto.getLocNo());
|
// wrkMast.setFullPlt("N"); // 满板
|
// wrkMast.setPicking("N"); // 拣料
|
// wrkMast.setExitMk("N"); // 退出
|
// wrkMast.setEmptyMk("Y"); // 空板
|
// wrkMast.setLinkMis("N");
|
//// wrkMast.setCtnType(sourceStaNo.getCtnType()); // 容器类型
|
// // 操作人员数据
|
// wrkMast.setAppeTime(new Date());
|
// wrkMast.setModiTime(new Date());
|
// Integer insert = wrkMastMapper.insert(wrkMast);
|
// if (insert == 0) {
|
// throw new CoolException("保存工作档失败");
|
// }
|
// // 更新目标库位状态
|
// LocMast locMast = locMastService.selectById(startupDto.getLocNo());
|
// locMast.setLocSts("S"); // S.入库预约
|
// locMast.setModiTime(new Date());
|
// if (!locMastService.updateById(locMast)){
|
// throw new CoolException("改变库位状态失败");
|
// }
|
// // 命令下发区 --------------------------------------------------------------------------
|
//
|
// // 更新站点信息 且 下发plc命令
|
// staProtocol.setWorkNo((short) workNo);
|
// staProtocol.setStaNo(startupDto.getStaNo().shortValue());
|
// devpThread.setPakMk(staProtocol.getSiteId(), false);
|
// boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
|
// if (!result) {
|
// throw new CoolException("更新plc站点信息失败");
|
// }
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
// }
|
|
}
|
|
|
}
|
}
|
}
|
|
/**
|
* 出库 ===>> 工作档信息写入led显示器
|
*/
|
public synchronized void ledExecute() {
|
for (LedSlave led : slaveProperties.getLed()) {
|
// 获取输送线plc线程
|
DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
|
// 命令集合
|
List<LedCommand> commands = new ArrayList<>();
|
// 工作档集合
|
List<WrkMast> wrkMasts = new ArrayList<>();
|
for (Integer staNo : led.getStaArr()) {
|
// 获取叉车站点
|
StaProtocol staProtocol = devpThread.getStation().get(staNo);
|
if (null == staProtocol || null == staProtocol.getWorkNo() || 0 == staProtocol.getWorkNo() || !staProtocol.isLoading()) {
|
continue;
|
} else {
|
staProtocol = staProtocol.clone();
|
}
|
// 获取工作档数据
|
WrkMast wrkMast = wrkMastMapper.selectById(staProtocol.getWorkNo());
|
// if (null == wrkMast || wrkMast.getWrkSts() < 14 || wrkMast.getIoType() < 100) { continue; }
|
if (null == wrkMast) {
|
continue;
|
}
|
wrkMasts.add(wrkMast);
|
// 组装命令
|
LedCommand ledCommand = new LedCommand();
|
ledCommand.setWorkNo(wrkMast.getWrkNo());
|
ledCommand.setIoType(wrkMast.getIoType());
|
// 出库模式
|
switch (wrkMast.getIoType()) {
|
case 1:
|
ledCommand.setTitle("全板入库");
|
break;
|
case 10:
|
ledCommand.setTitle("空板入库");
|
break;
|
case 101:
|
ledCommand.setTitle("全板出库");
|
break;
|
case 103:
|
ledCommand.setTitle("拣料出库");
|
break;
|
case 104:
|
ledCommand.setTitle("并板出库");
|
break;
|
case 107:
|
ledCommand.setTitle("盘点出库");
|
break;
|
case 110:
|
ledCommand.setTitle("空板出库");
|
ledCommand.setEmptyMk(true);
|
break;
|
default:
|
log.error("任务入出库类型错误!!![工作号:{}] [入出库类型:{}]", wrkMast.getWrkNo(), wrkMast.getIoType());
|
break;
|
}
|
ledCommand.setSourceLocNo(wrkMast.getSourceLocNo());
|
ledCommand.setLocNo(wrkMast.getLocNo());
|
ledCommand.setStaNo(wrkMast.getStaNo());
|
// ledCommand.setSourceStaNo(wrkMast.getSourceStaNo());
|
if (wrkMast.getIoType() != 110 && wrkMast.getIoType() != 10) {
|
List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo());
|
wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme())));
|
}
|
commands.add(ledCommand);
|
}
|
Set<Integer> workNos = wrkMasts.stream().map(WrkMast::getWrkNo).collect(Collectors.toSet());
|
// 获取LED线程
|
LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
|
// 相同工作号集合则过滤
|
if (CollectionUtils.equals(ledThread.getWorkNos(), workNos)) {
|
continue;
|
}
|
// 命令下发 -------------------------------------------------------------------------------
|
if (!commands.isEmpty()) {
|
if (led.getId() == 7) {
|
if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(3, commands))) {
|
log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
|
continue;
|
} else {
|
ledThread.setLedMk(false);
|
}
|
} else {
|
if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(1, commands))) {
|
log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
|
continue;
|
} else {
|
ledThread.setLedMk(false);
|
}
|
}
|
|
}
|
|
try {
|
// 修改主档led标记
|
for (WrkMast wrkMast : wrkMasts) {
|
wrkMast.setOveMk("Y");
|
wrkMast.setModiTime(new Date());
|
if (wrkMastMapper.updateById(wrkMast) == 0) {
|
throw new CoolException("更新工作档失败");
|
}
|
}
|
|
// 更新线程当前工作号集合
|
ledThread.setWorkNos(workNos);
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
}
|
|
}
|
}
|
|
/**
|
* 其他 ===>> LED显示器复位,显示默认信息
|
*/
|
public synchronized void ledReset() {
|
for (LedSlave led : slaveProperties.getLed()) {
|
// 获取输送线plc线程
|
DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
|
// 命令集合
|
boolean reset = true;
|
for (Integer staNo : led.getStaArr()) {
|
// 获取叉车站点
|
StaProtocol staProtocol = devpThread.getStation().get(staNo);
|
if (staProtocol == null) {
|
continue;
|
}
|
if (staProtocol.getWorkNo() != 0 && staProtocol.isLoading()) {
|
reset = false;
|
break;
|
}
|
}
|
// 获取led线程
|
LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
|
// led显示默认内容
|
if (reset && !ledThread.isLedMk()) {
|
if (led.getId() == 7) {
|
ledThread.setLedMk(true);
|
if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(4, new ArrayList<>()))) {
|
log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
|
} else {
|
|
}
|
} else {
|
ledThread.setLedMk(true);
|
if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(2, new ArrayList<>()))) {
|
log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
|
} else {
|
|
}
|
}
|
}
|
}
|
}
|
|
/**
|
* 因双深库位阻塞,对浅库位进行移转(入库版)
|
* tip:同步
|
*/
|
@Transactional
|
public synchronized void moveLocForDeepLocPakin(CrnSlave crn, LocMast shallowLoc, WrkMast pakinWrkMast) {
|
LocMast loc = locMastService.selectById(pakinWrkMast.getLocNo());
|
|
// 获取工作号
|
int workNo = commonService.getWorkNo(0);
|
Date now = new Date();
|
// 保存工作档
|
WrkMast wrkMast = new WrkMast();
|
wrkMast.setWrkNo(workNo);
|
wrkMast.setIoTime(now);
|
wrkMast.setWrkSts(11L); // 工作状态:11.生成出库ID
|
wrkMast.setIoType(11); // 入出库状态: 11.库格移载
|
wrkMast.setIoPri(15D);
|
wrkMast.setCrnNo(crn.getId());
|
wrkMast.setSourceLocNo(shallowLoc.getLocNo()); // 源库位
|
wrkMast.setLocNo(loc.getLocNo()); // 目标库位
|
wrkMast.setFullPlt(shallowLoc.getFullPlt()); // 满板
|
wrkMast.setPicking("N"); // 拣料
|
wrkMast.setExitMk("N"); // 退出
|
wrkMast.setEmptyMk(shallowLoc.getLocSts().equals("D") ? "Y" : "N"); // 空板
|
wrkMast.setBarcode(shallowLoc.getBarcode()); // 托盘码
|
wrkMast.setLinkMis("N");
|
wrkMast.setCtnNo("Y"); // 入库阻塞库位移转标记
|
wrkMast.setAppeTime(now);
|
wrkMast.setModiTime(now);
|
int res = wrkMastMapper.insert(wrkMast);
|
if (res == 0) {
|
throw new CoolException("保存工作档失败");
|
}
|
// 工作档明细保存
|
if (shallowLoc.getLocSts().equals("F")) {
|
List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", shallowLoc.getLocNo()));
|
for (LocDetl locDetl : locDetls) {
|
WrkDetl wrkDetl = new WrkDetl();
|
wrkDetl.setWrkNo(workNo);
|
wrkDetl.setIoTime(now);
|
wrkDetl.setAnfme(locDetl.getAnfme());
|
VersionUtils.setWrkDetl(wrkDetl, locDetl); // 版本控制
|
wrkDetl.setAppeTime(now);
|
wrkDetl.setModiTime(now);
|
if (!wrkDetlService.insert(wrkDetl)) {
|
throw new CoolException("保存工作档明细失败");
|
}
|
}
|
}
|
// 修改源库位状态
|
if (shallowLoc.getLocSts().equals("D") || shallowLoc.getLocSts().equals("F")) {
|
shallowLoc.setLocSts("S"); // S.入库预约,入库阻塞库位移转
|
shallowLoc.setModiTime(now);
|
if (!locMastService.updateById(shallowLoc)) {
|
throw new CoolException("更新源库位状态失败");
|
}
|
} else {
|
throw new CoolException("源库位出库失败");
|
}
|
// // 修改目标库位状态
|
// if (loc.getLocSts().equals("O")) {
|
// loc.setLocSts("S"); // S.入库预约
|
// loc.setModiTime(new Date());
|
// if (!locMastService.updateById(loc)) {
|
// throw new CoolException("更新目标库位状态失败");
|
// }
|
// } else {
|
// throw new CoolException("移转失败");
|
// }
|
wrkMast.setLocNo(shallowLoc.getLocNo());
|
if (wrkMastMapper.updateById(wrkMast) == 0) {
|
throw new CoolException("修改阻塞入库任务失败");
|
}
|
}
|
|
/**
|
* 因双深库位阻塞,对浅库位进行移转(立即执行版)
|
* tip:同步
|
*/
|
private synchronized void moveLocForDeepLoc(CrnSlave crn, LocMast shallowLoc) {
|
try {
|
List<Integer> rows = locMastService.queryDistinctRow(crn.getId());
|
LocMast loc = null;
|
for (Integer row : rows) {
|
if (Utils.isDeepLoc(slaveProperties, row)) {
|
loc = locMastService.queryFreeLocMast(row, shallowLoc.getLocType1());
|
|
if (loc != null) {
|
if (Utils.isDeepLoc(slaveProperties, loc.getLocNo())) {
|
String shallowLocNo = Utils.getShallowLoc(slaveProperties, loc.getLocNo());
|
LocMast shallowLoc1 = locMastService.selectById(shallowLocNo);
|
if (!shallowLoc1.getLocSts().equals("O")) {
|
loc = null;
|
}
|
}
|
}
|
if (null != loc) {
|
break;
|
}
|
}
|
}
|
if (null == loc) {
|
for (Integer row : rows) {
|
if (Utils.isShallowLoc(slaveProperties, row)) {
|
loc = locMastService.queryFreeLocMast(row, shallowLoc.getLocType1());
|
|
if (null != loc) {//对应深库位非在库状态,不能移库
|
String deepLoc = Utils.getDeepLoc(slaveProperties, loc.getLocNo());
|
LocMast deepLoc1 = locMastService.selectById(deepLoc);
|
if (!deepLoc1.getLocSts().equals("F") && !deepLoc1.getLocSts().equals("D")) {
|
loc = null;
|
}
|
}
|
|
if (null != loc) {
|
break;
|
}
|
}
|
}
|
}
|
|
if (null == loc) {
|
log.error("双深库位 --- 浅库位阻塞异常! 待移转浅库位:" + shallowLoc.getLocNo());
|
throw new CoolException("双深库位 --- 浅库位阻塞异常! 待移转浅库位:" + shallowLoc.getLocNo());
|
}
|
|
// 获取工作号
|
int workNo = commonService.getWorkNo(0);
|
// 保存工作档
|
WrkMast wrkMast = new WrkMast();
|
wrkMast.setWrkNo(workNo);
|
wrkMast.setIoTime(new Date());
|
wrkMast.setWrkSts(11L); // 工作状态:11.生成出库ID
|
wrkMast.setIoType(11); // 入出库状态: 11.库格移载
|
wrkMast.setIoPri(13D);
|
wrkMast.setCrnNo(crn.getId());
|
wrkMast.setSourceLocNo(shallowLoc.getLocNo()); // 源库位
|
wrkMast.setLocNo(loc.getLocNo()); // 目标库位
|
wrkMast.setFullPlt(shallowLoc.getFullPlt()); // 满板
|
wrkMast.setPicking("N"); // 拣料
|
wrkMast.setExitMk("N"); // 退出
|
wrkMast.setEmptyMk(shallowLoc.getLocSts().equals("D") ? "Y" : "N"); // 空板
|
wrkMast.setBarcode(shallowLoc.getBarcode()); // 托盘码
|
wrkMast.setLinkMis("N");
|
wrkMast.setAppeTime(new Date());
|
wrkMast.setModiTime(new Date());
|
int res = wrkMastMapper.insert(wrkMast);
|
if (res == 0) {
|
throw new CoolException("保存工作档失败");
|
}
|
// 工作档明细保存
|
if (shallowLoc.getLocSts().equals("F")) {
|
List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", shallowLoc.getLocNo()));
|
for (LocDetl locDetl : locDetls) {
|
WrkDetl wrkDetl = new WrkDetl();
|
wrkDetl.setWrkNo(workNo);
|
wrkDetl.setIoTime(new Date());
|
wrkDetl.setAnfme(locDetl.getAnfme());
|
VersionUtils.setWrkDetl(wrkDetl, locDetl); // 版本控制
|
wrkDetl.setAppeTime(new Date());
|
wrkDetl.setModiTime(new Date());
|
if (!wrkDetlService.insert(wrkDetl)) {
|
throw new CoolException("保存工作档明细失败");
|
}
|
}
|
}
|
// 修改源库位状态
|
if (shallowLoc.getLocSts().equals("D") || shallowLoc.getLocSts().equals("F")) {
|
shallowLoc.setLocSts("R"); // R.出库预约
|
shallowLoc.setModiTime(new Date());
|
if (!locMastService.updateById(shallowLoc)) {
|
throw new CoolException("更新源库位状态失败");
|
}
|
} else {
|
throw new CoolException("源库位出库失败");
|
}
|
// 修改目标库位状态
|
if (loc.getLocSts().equals("O")) {
|
loc.setLocSts("S"); // S.入库预约
|
loc.setModiTime(new Date());
|
if (!locMastService.updateById(loc)) {
|
throw new CoolException("更新目标库位状态失败");
|
}
|
} else {
|
throw new CoolException("移转失败");
|
}
|
} catch (Exception e) {
|
log.error("双深库位阻塞,对浅库位进行移转失败", e);
|
e.printStackTrace();
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
}
|
}
|
|
/**
|
* 初始化RGV地图
|
*/
|
public synchronized void initRgvMap() {
|
Object data = redisUtil.get("rgv_map");
|
if (data == null) {
|
//重新获取全路径地图
|
BasRgvPath basRgvPath = basRgvPathService.selectByRgvNo(0);//获取默认路径
|
if (basRgvPath != null) {
|
ArrayList<RgvNode> rgvNodes = new ArrayList<>();
|
List<Integer> rgvPath = JSON.parseArray(basRgvPath.getPath(), Integer.class);
|
for (Integer integer : rgvPath) {
|
RgvNode rgvNode = new RgvNode(integer);
|
rgvNodes.add(rgvNode);
|
}
|
//将数据库地图数据存入redis
|
redisUtil.set("rgv_map", JSON.toJSONString(rgvNodes));
|
}
|
}
|
}
|
|
/**
|
* 堆垛机演示 ===>> 库位移转
|
*/
|
public synchronized void crnDemoOfLocMove1() {
|
try {
|
for (CrnSlave crn : slaveProperties.getCrn()) {
|
if (!crn.getDemo()) {
|
continue;
|
} // 必须为演示状态
|
|
CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
|
CrnProtocol crnProtocol = crnThread.getCrnProtocol();
|
if (crnProtocol == null) {
|
continue;
|
}
|
|
// 只有当堆垛机空闲 并且 无任务时才继续执行
|
if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO) {
|
// 获取移库工作档信息
|
WrkMast wrkMast = wrkMastMapper.selectLocMove(crn.getId());
|
if (null != wrkMast) {
|
continue;
|
}
|
|
LocMast sourceLoc = locMastService.queryDemoSourceLoc(crn.getId());
|
LocMast loc = locMastService.queryDemoLoc(crn.getId());
|
if (null == sourceLoc || null == loc) {
|
continue;
|
}
|
|
String sourceLocNo = sourceLoc.getLocNo();
|
String locNo = loc.getLocNo();
|
|
// 获取工作号
|
int workNo = commonService.getWorkNo(0);
|
// 保存工作档
|
wrkMast = new WrkMast();
|
wrkMast.setWrkNo(workNo);
|
wrkMast.setIoTime(new Date());
|
wrkMast.setWrkSts(11L); // 工作状态:11.生成出库ID
|
wrkMast.setIoType(11); // 入出库状态: 11.库格移载
|
wrkMast.setIoPri(13D);
|
wrkMast.setCrnNo(crn.getId());
|
wrkMast.setSourceLocNo(sourceLocNo); // 源库位
|
wrkMast.setLocNo(locNo); // 目标库位
|
wrkMast.setFullPlt("N"); // 满板:Y
|
wrkMast.setPicking("N"); // 拣料
|
wrkMast.setExitMk("N"); // 退出
|
wrkMast.setEmptyMk(sourceLoc.getLocSts().equals("D") ? "Y" : "N"); // 空板
|
wrkMast.setBarcode(sourceLoc.getBarcode()); // 托盘码
|
wrkMast.setLinkMis("N");
|
wrkMast.setAppeTime(new Date());
|
wrkMast.setModiTime(new Date());
|
int res = wrkMastMapper.insert(wrkMast);
|
if (res == 0) {
|
throw new CoolException("保存工作档失败");
|
}
|
// 工作档明细保存
|
// List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", sourceLocNo));
|
// for (LocDetl locDetl : locDetls) {
|
// WrkDetl wrkDetl = new WrkDetl();
|
// wrkDetl.setWrkNo(workNo);
|
// wrkDetl.setIoTime(new Date());
|
// wrkDetl.setAnfme(locDetl.getAnfme());
|
// VersionUtils.setWrkDetl(wrkDetl, locDetl); // 版本控制
|
// wrkDetl.setAppeTime(new Date());
|
// wrkDetl.setModiTime(new Date());
|
// if (!wrkDetlService.insert(wrkDetl)) {
|
// throw new CoolException("保存工作档明细失败");
|
// }
|
// }
|
// 修改源库位状态
|
if (sourceLoc.getLocSts().equals("D")) {
|
sourceLoc.setLocSts("R"); // R.出库预约
|
sourceLoc.setModiTime(new Date());
|
if (!locMastService.updateById(sourceLoc)) {
|
throw new CoolException("更新源库位状态失败");
|
}
|
} else {
|
throw new CoolException("源库位出库失败");
|
}
|
// 修改目标库位状态
|
if (loc.getLocSts().equals("O")) {
|
loc.setLocSts("S"); // S.入库预约
|
loc.setModiTime(new Date());
|
if (!locMastService.updateById(loc)) {
|
throw new CoolException("更新目标库位状态失败");
|
}
|
} else {
|
throw new CoolException("移转失败");
|
}
|
|
}
|
}
|
} catch (Exception e) {
|
log.error("堆垛机演示 ===>> 库位移转失败", e);
|
e.printStackTrace();
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
}
|
}
|
|
/**
|
* 堆垛机命令下发后,异步修改工作档状态
|
*/
|
public synchronized void crnIoWrkMast() {
|
for (CrnSlave crn : slaveProperties.getCrn()) {
|
// 获取堆垛机信息
|
CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
|
CrnProtocol crnProtocol = crnThread.getCrnProtocol();
|
if (crnProtocol == null) {
|
continue;
|
}
|
Date now = new Date();
|
// 堆垛机正在运行
|
if (crnProtocol.getStatusType() != CrnStatusType.IDLE && crnProtocol.getTaskNo() != 0 && crnProtocol.getModeType() == CrnModeType.AUTO) {
|
// 获取工作档
|
WrkMast wrkMast = wrkMastMapper.selectById(crnProtocol.getTaskNo());
|
if (wrkMast == null) {
|
continue;
|
}
|
// 入库
|
if (wrkMast.getWrkSts() == 1 || wrkMast.getWrkSts() == 2) {
|
log.warn("堆垛机非空闲情况下,开始修改工作档状态。[id:{},时间:{}] >>>>> 堆垛机当前状态为:{}。任务号:{}", crn.getId(), DateUtils.convert(now, DateUtils.yyyyMMddHHmmsssss_F), crnProtocol.getStatusType().desc, crnProtocol.getTaskNo());
|
// 修改工作档状态 2.设备上走 => 3.吊车入库中
|
wrkMast.setWrkSts(3L);
|
wrkMast.setCrnStrTime(now);
|
wrkMast.setModiTime(now);
|
if (wrkMastMapper.updateById(wrkMast) == 0) {
|
log.error("修改工作档状态 2.设备上走 => 3.吊车入库中 失败!!,工作号={}", wrkMast.getWrkNo());
|
}
|
log.warn("修改工作档状态成功。[时间:{}] >>>>> 任务号:{}", DateUtils.convert(now, DateUtils.yyyyMMddHHmmsssss_F), wrkMast.getWrkNo());
|
}
|
// 出库、移库
|
if (wrkMast.getWrkSts() == 11) {
|
log.warn("堆垛机非空闲情况下,开始修改工作档状态。[id:{},时间:{}] >>>>> 堆垛机当前状态为:{}。任务号:{}", crn.getId(), DateUtils.convert(now, DateUtils.yyyyMMddHHmmsssss_F), crnProtocol.getStatusType().desc, crnProtocol.getTaskNo());
|
// 修改工作档状态 11.生成出库ID => 12.吊车出库中
|
wrkMast.setWrkSts(12L);
|
wrkMast.setCrnStrTime(now);
|
wrkMast.setModiTime(now);
|
if (wrkMastMapper.updateById(wrkMast) == 0) {
|
log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", wrkMast.getWrkNo());
|
}
|
log.warn("修改工作档状态成功。[时间:{}] >>>>> 任务号:{}", DateUtils.convert(now, DateUtils.yyyyMMddHHmmsssss_F), wrkMast.getWrkNo());
|
}
|
|
|
}
|
|
}
|
}
|
|
/**
|
* 入出库模式切换函数
|
*/
|
public synchronized void ioConvert() {
|
try {
|
// 根据输送线plc遍历
|
for (DevpSlave devp : slaveProperties.getDevp()) {
|
SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
|
|
for (DevpSlave.Sta inSta : devp.getInSta()) {
|
if (inSta.getStaNo() == 2) {
|
continue;
|
}
|
WrkMast pakout = wrkMastMapper.selectWorkingPakout(inSta.getStaNo());
|
switch (inSta.getStaNo()) {
|
case 203://1F
|
if (pakout != null) {
|
if (devpThread.ioModeOf2F != IoModeType.PAKOUT_MODE) {
|
// 出库切换中
|
devpThread.ioModeOf2F = IoModeType.PAKOUT_BOOTING;
|
WrkMast pakin = wrkMastMapper.selectWorkingPakin(inSta.getStaNo());
|
if (pakin == null && !devpThread.getStation().get(inSta.getStaNo()).isLoading()
|
&& !devpThread.getStation().get(inSta.getStaNo() + 1).isLoading()
|
&& devpThread.getStation().get(inSta.getStaNo() + 1).getWorkNo() == 0) {
|
// 出库模式
|
devpThread.ioModeOf2F = IoModeType.PAKOUT_MODE;
|
}
|
}
|
} else {
|
// 入库模式
|
devpThread.ioModeOf2F = IoModeType.PAKIN_MODE;
|
}
|
break;
|
case 401://1F
|
if (pakout != null) {
|
if (devpThread.ioModeOf4F != IoModeType.PAKOUT_MODE) {
|
// 出库切换中
|
devpThread.ioModeOf4F = IoModeType.PAKOUT_BOOTING;
|
WrkMast pakin = wrkMastMapper.selectWorkingPakin(inSta.getStaNo());
|
if (pakin == null && !devpThread.getStation().get(inSta.getStaNo()).isLoading()
|
&& !devpThread.getStation().get(inSta.getStaNo() + 1).isLoading()
|
&& devpThread.getStation().get(inSta.getStaNo() + 1).getWorkNo() == 0) {
|
// 出库模式
|
devpThread.ioModeOf4F = IoModeType.PAKOUT_MODE;
|
}
|
}
|
} else {
|
// 入库模式
|
devpThread.ioModeOf4F = IoModeType.PAKIN_MODE;
|
}
|
break;
|
}
|
}
|
|
}
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
|
}
|
|
public synchronized void outOfDevp() {
|
List<WrkMast> wrkMasts = wrkMastMapper.selectPick();
|
for (WrkMast wrkMast : wrkMasts) {
|
if (basDevpService.selectCount(new EntityWrapper<BasDevp>().eq("wrk_no", wrkMast.getWrkNo())) == 0) {
|
wrkMast.setCtnNo("Y");
|
if (wrkMastMapper.updateById(wrkMast) == 0) {
|
log.error("修改{}工作档失败,ctn_no", wrkMast.getWrkNo());
|
}
|
}
|
|
}
|
}
|
|
|
public synchronized void autoEmptyOut() {
|
DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, 1);
|
Integer autoOutSite = 12;
|
//如果站点可出禁用,则不生成空盘出库任务
|
StaProtocol staProtocol = devpThread.getStation().get(autoOutSite);
|
if (staProtocol == null) {
|
return;
|
} else {
|
staProtocol = staProtocol.clone();
|
}
|
if (staProtocol.isAutoing() //自动
|
&& !staProtocol.isLoading() //无物
|
&& staProtocol.isOutEnable() //可出信号
|
&& staProtocol.getWorkNo() == 0
|
) {
|
WrkMast pakoutEmpty = wrkMastMapper.selectPakoutEmpty(autoOutSite);
|
if (null != pakoutEmpty) {
|
return;
|
}
|
try {
|
String response = new HttpHandler.Builder()
|
.setUri(wmsUrl)
|
.setPath("/rpc/auto/emptyOut/v1")
|
.build()
|
.doPost();
|
JSONObject jsonObject = JSON.parseObject(response);
|
if (jsonObject.getInteger("code").equals(200)) {
|
JSONObject data = (JSONObject) jsonObject.get("data");
|
log.info((String) data.get("msg"));
|
} else {
|
log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/auto/emptyOut/v1","", response);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
}
|
}
|
}
|
|
public synchronized void autoEmptyIn() {
|
DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, 1);
|
Integer autoInSite = 12;
|
StaProtocol staProtocol = devpThread.getStation().get(autoInSite);
|
if (staProtocol == null) {
|
return;
|
} else {
|
staProtocol = staProtocol.clone();
|
}
|
if (staProtocol.isAutoing() //自动
|
&& staProtocol.isLoading() //有物
|
&& staProtocol.isInEnable() //可入信号
|
&& (staProtocol.getWorkNo() == 0 || staProtocol.getWorkNo() > 9990) //工作号为0或者工作号是9991~9999(输送机留用)
|
) {
|
|
try {
|
LocTypeDto locTypeDto = new LocTypeDto((short) 1, (short) 1, (short) 1);
|
|
|
String response = new HttpHandler.Builder()
|
.setUri(wmsUrl)
|
.setPath("/rpc/auto/emptyIn/v1")
|
.setJson(JSON.toJSONString(locTypeDto))
|
.build()
|
.doPost();
|
JSONObject jsonObject = JSON.parseObject(response);
|
if (jsonObject.getInteger("code").equals(200)) {
|
log.info((String) jsonObject.get("msg"));
|
} else {
|
log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/auto/emptyIn/v1", JSON.toJSONString(locTypeDto), response);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
}
|
}
|
}
|
}
|