package com.zy.asrs.service.impl;
|
|
import com.alibaba.fastjson.JSON;
|
import com.zy.asrs.entity.*;
|
import com.zy.asrs.mapper.*;
|
import com.zy.asrs.service.*;
|
import com.zy.asrs.utils.Utils;
|
import com.zy.common.model.*;
|
import com.zy.common.model.enums.NavigationMapType;
|
import com.zy.common.service.CommonService;
|
import com.zy.common.utils.*;
|
import com.zy.core.News;
|
import com.zy.core.action.ForkLiftAction;
|
import com.zy.core.action.ShuttleAction;
|
import com.zy.core.cache.SlaveConnection;
|
import com.zy.core.dispatcher.ShuttleDispatchUtils;
|
import com.zy.core.enums.*;
|
import com.zy.core.model.*;
|
import com.zy.core.model.command.*;
|
import com.zy.core.model.protocol.*;
|
import com.zy.core.properties.SlaveProperties;
|
import com.zy.core.thread.*;
|
import com.zy.system.service.ConfigService;
|
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 java.util.*;
|
|
/**
|
* 立体仓库WCS系统主流程业务
|
* Created by vincent on 2020/8/6
|
*/
|
@Slf4j
|
@Service("mainService")
|
public class MainServiceImpl {
|
|
@Value("${wms.url}")
|
private String wmsUrl;
|
@Autowired
|
private SlaveProperties slaveProperties;
|
@Autowired
|
private WrkMastService wrkMastService;
|
@Autowired
|
private WrkMastLogMapper wrkMastLogMapper;
|
@Autowired
|
private LocMastService locMastService;
|
@Autowired
|
private BasDevpService basDevpService;
|
@Autowired
|
private BasShuttleErrLogService basShuttleErrLogService;
|
@Autowired
|
private BasLiftErrLogService basLiftErrLogService;
|
@Autowired
|
private BasShuttleErrService basShuttleErrService;
|
@Autowired
|
private BasLiftErrService basLiftErrService;
|
@Autowired
|
private CommonService commonService;
|
@Autowired
|
private BasMapService basMapService;
|
@Autowired
|
private BasLiftService basLiftService;
|
@Autowired
|
private ShuttleDispatchUtils shuttleDispatchUtils;
|
@Autowired
|
private RedisUtil redisUtil;
|
@Autowired
|
private BasLiftOptService basLiftOptService;
|
@Autowired
|
private ConfigService configService;
|
@Autowired
|
private NavigateMapUtils navigateMapUtils;
|
@Autowired
|
private NavigateMapData navigateMapData;
|
@Autowired
|
private NavigateUtils navigateUtils;
|
@Autowired
|
private ShuttleOperaUtils shuttleOperaUtils;
|
@Autowired
|
private ShuttleAction shuttleAction;
|
@Autowired
|
private ForkLiftAction forkLiftAction;
|
|
|
// /**
|
// * 组托
|
// * 入库站,根据条码扫描生成入库工作档,工作状态 2
|
// */
|
// public void generateStoreWrkFile() {
|
// try {
|
// // 根据输送线plc遍历
|
// for (DevpSlave devp : slaveProperties.getDevp()) {
|
// // 遍历入库口
|
// for (DevpSlave.Sta inSta : devp.getInSta()) {
|
// // 获取入库站信息
|
// DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
|
// StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo());
|
// if (staProtocol == null) {
|
// continue;
|
// } else {
|
// staProtocol = staProtocol.clone();
|
// }
|
// Short workNo = staProtocol.getWorkNo();
|
// // 尺寸检测异常
|
// boolean back = false;
|
// String errMsg = "异常:";
|
// if (staProtocol.isFrontErr()) {
|
// errMsg = errMsg + "前超限;";
|
// back = true;
|
// }
|
// if (staProtocol.isBackErr()) {
|
// errMsg = errMsg + "后超限";
|
// back = true;
|
// }
|
// if (staProtocol.isHighErr()) {
|
// errMsg = errMsg + "高超限";
|
// back = true;
|
// }
|
// if (staProtocol.isLeftErr()) {
|
// errMsg = errMsg + "左超限";
|
// back = true;
|
// }
|
// if (staProtocol.isRightErr()) {
|
// errMsg = errMsg + "右超限";
|
// back = true;
|
// }
|
// if (staProtocol.isWeightErr()) {
|
// errMsg = errMsg + "超重";
|
// back = true;
|
// }
|
// if (staProtocol.isBarcodeErr()) {
|
// errMsg = errMsg + "扫码失败";
|
// back = true;
|
// }
|
// // 退回
|
// if (back) {
|
// // led 异常显示
|
// LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
|
// if (ledThread != null) {
|
// MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errMsg));
|
// }
|
// continue;
|
// }
|
//
|
// // 判断是否满足入库条件
|
// if (staProtocol.isAutoing() && staProtocol.isLoading()
|
// && staProtocol.isInEnable()
|
// && !staProtocol.isEmptyMk() && (workNo == 0 || (workNo >= 9990 && workNo <= 9999))
|
// ) {
|
//
|
// // 获取条码扫描仪信息
|
// BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode());
|
// if (barcodeThread == null) {
|
// continue;
|
// }
|
// String barcode = barcodeThread.getBarcode();
|
// if (!Cools.isEmpty(barcode)) {
|
//// News.info("{}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode);
|
// if ("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode) || "00000000".equals(barcode)) {
|
//// staProtocol.setWorkNo((short) 32002);
|
//// staProtocol.setStaNo(inSta.getBackSta().shortValue());
|
//// devpThread.setPakMk(staProtocol.getSiteId(), false);
|
//// MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
|
//
|
// // led 异常显示
|
// LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
|
// if (ledThread != null) {
|
// String errorMsg = "扫码失败,请重试";
|
// MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
|
// }
|
// continue;
|
// }
|
// } else {
|
//// staProtocol.setWorkNo((short) 32002);
|
//// staProtocol.setStaNo(inSta.getBackSta().shortValue());
|
//// devpThread.setPakMk(staProtocol.getSiteId(), false);
|
//// MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
|
//
|
//// // led 异常显示
|
//// LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
|
//// if (ledThread != null) {
|
//// String errorMsg = "扫码失败,请重试";
|
//// MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
|
//// }
|
// continue;
|
// }
|
//
|
// // 过滤盘点/拣料/并板任务
|
// WrkMast wrkMast1 = wrkMastMapper.selectPickStepByBarcode(barcode);
|
// if (null != wrkMast1) {
|
// continue;
|
// }
|
//
|
// // 判断重复工作档
|
// WrkMast wrkMast2 = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode);
|
// if (wrkMast2 != null) {
|
// News.error("工作档中已存在该站状态为( 2.设备上走 )的数据,工作号={}", wrkMast2.getWrkNo());
|
// 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/v2")
|
// .setJson(JSON.toJSONString(param))
|
// .build()
|
// .doPost();
|
// JSONObject jsonObject = JSON.parseObject(response);
|
// LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
|
// Integer code = jsonObject.getInteger("code");
|
// if (code.equals(200)) {
|
// StartupDto dto = jsonObject.getObject("data", StartupDto.class);
|
// // plc 处理
|
// barcodeThread.setBarcode("");
|
//// 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站点信息失败");
|
//// }
|
//
|
// // 判断重复工作档
|
// WrkMast wrkMast = wrkMastMapper.selectPakInStep11(inSta.getStaNo());
|
// if (wrkMast == null) {
|
// continue;
|
// }
|
//
|
// // 更新工作主档
|
// wrkMast.setWrkSts(2L); // 工作状态:2.设备上走
|
// wrkMast.setModiTime(new Date());
|
// if (wrkMastMapper.updateById(wrkMast) == 0) {
|
// News.error("更新工作档失败!!! [工作号:{}]", wrkMast.getWrkNo());
|
// }
|
//
|
// } else if (code == 500) {
|
// if (ledThread != null) {
|
// String errorMsg = jsonObject.getString("msg");
|
// if (!Cools.isEmpty(errorMsg)) {
|
// MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
|
// ledThread.setLedMk(false);
|
// }
|
// }
|
// News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v2", JSON.toJSONString(param), response);
|
// } else if (code == 700) {
|
//// staProtocol.setWorkNo((short) 32002);
|
//// staProtocol.setRollback102(1);//102站回退信号
|
//// devpThread.setPakMk(staProtocol.getSiteId(), false);
|
//// MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(5, staProtocol));
|
//
|
// // led 异常显示
|
// if (ledThread != null) {
|
// String errorMsg = barcode + "托盘识别异常,请先进行组托!";
|
// MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
|
// ledThread.setLedMk(false);
|
// }
|
// }
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
// }
|
// }
|
// }
|
// }
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// }
|
// }
|
|
// /**
|
// * 拣料、并板再入库
|
// */
|
// @Transactional
|
// public synchronized void stnToCrnStnPick(){
|
// try {
|
// for (DevpSlave devp : slaveProperties.getDevp()) {
|
// // 遍历拣料入库口
|
// for (DevpSlave.Sta pickSta : devp.getPickInSta()) {
|
// // 获取拣料入库站信息
|
// DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
|
// StaProtocol staProtocol = devpThread.getStation().get(pickSta.getStaNo());
|
// if (staProtocol == null) {
|
// continue;
|
// } else {
|
// staProtocol = staProtocol.clone();
|
// }
|
// if (staProtocol.isAutoing()
|
// && staProtocol.isLoading()
|
// && staProtocol.isInEnable()
|
//// && (staProtocol.getWorkNo() > 0)
|
// && staProtocol.isPakMk()) {
|
//
|
// // 获取条码扫描仪信息
|
// BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
|
// if (barcodeThread == null) {
|
// continue;
|
// }
|
// String barcode = barcodeThread.getBarcode();
|
// if (Cools.isEmpty(barcode)) {
|
// continue;
|
// }
|
// if ("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) {
|
// continue;
|
// }
|
//
|
// WrkMast wrkMast = wrkMastMapper.selectPickStepByBarcode(barcode);
|
// if (wrkMast == null) {//找不到工作档
|
// continue;
|
// }
|
//
|
// if ((wrkMast.getIoType() != 103 && wrkMast.getIoType() != 104)
|
// || Cools.isEmpty(wrkMast.getStaNo()) || Cools.isEmpty(wrkMast.getSourceStaNo())) {
|
// continue;
|
// }
|
//
|
//// //*********************同库位组校验*********************
|
//// boolean flag = false;
|
//// String th = "";
|
//// List<String> innerLoc = Utils.getGroupInnerLoc(wrkMast.getSourceLocNo());
|
//// for (String loc : innerLoc) {
|
//// LocMast locMast = locMastService.selectById(loc);
|
//// if (locMast == null) {
|
//// continue;
|
//// }
|
////
|
//// if (!locMast.getLocSts().equals("F")) {
|
//// flag = true;
|
//// th = loc + "库位存在未回库任务";
|
//// break;
|
//// }
|
//// }
|
//// if (flag) {
|
//// News.info(th);
|
//// continue;
|
//// }
|
//// //*********************同库位组校验*********************
|
//
|
//// // 保存工作主档历史档
|
//// if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) {
|
//// News.info(wrkMast.getWrkNo() + "保存工作主档历史档失败");
|
//// continue;
|
//// }
|
//
|
// try {
|
// LocMast locMast = locMastService.selectById(wrkMast.getSourceLocNo());//源库位
|
// SearchLocParam param = new SearchLocParam();
|
// param.setWrkNo(wrkMast.getWrkNo());
|
// param.setBarcode(wrkMast.getBarcode());
|
// param.setIoType(wrkMast.getIoType());
|
// param.setSourceStaNo(pickSta.getStaNo());
|
// param.setLiftNo(pickSta.getLiftNo());
|
// param.setLocType1(locMast.getLocType1());
|
// String response = new HttpHandler.Builder()
|
// .setUri(wmsUrl)
|
// .setPath("/rpc/pakin/loc/v2")
|
// .setJson(JSON.toJSONString(param))
|
// .build()
|
// .doPost();
|
// JSONObject jsonObject = JSON.parseObject(response);
|
// Integer code = jsonObject.getInteger("code");
|
// if (code.equals(200)) {
|
// StartupDto dto = jsonObject.getObject("data", StartupDto.class);
|
//
|
//// //获取回库提升机目标站
|
//// LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(pickSta.getLiftNo(), Utils.getLev(dto.getLocNo()));
|
//// if (liftStaProtocol == null) {
|
//// News.info(wrkMast.getWrkNo() + "获取回库提升机目标站失败");
|
//// continue;
|
//// }
|
////
|
//// // 更新工作档数据状态
|
//// wrkMast.setIoType(wrkMast.getIoType() - 50); // 入出库类型: 103->53,104->54
|
//// wrkMast.setWrkSts(2L); // 工作状态: 2.设备上走
|
//// wrkMast.setSourceStaNo(dto.getSourceStaNo()); // 源站
|
//// wrkMast.setStaNo(liftStaProtocol.getStaNo());//目标站
|
//// wrkMast.setLocNo(dto.getLocNo()); // 目标库位
|
//// wrkMast.setShuttleNo(null); // 穿梭车清空
|
//// wrkMast.setLiftNo(null);// 提升机清空
|
//// wrkMast.setModiTime(new Date());
|
//// if (wrkMastMapper.updateById(wrkMast) == 0) {
|
//// News.info(wrkMast.getWrkNo() + "更新工作档数据状态失败");
|
//// continue;
|
//// }
|
// } else if (code == 500) {
|
// News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v2", JSON.toJSONString(param), response);
|
// }
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
// }
|
// }
|
// }
|
//
|
// }
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// }
|
// }
|
|
// /**
|
// * 盘点再入库
|
// */
|
// @Transactional
|
// public synchronized void stnToCrnStnPlate(){
|
// try {
|
// for (DevpSlave devp : slaveProperties.getDevp()) {
|
// // 遍历拣料入库口
|
// for (DevpSlave.Sta pickSta : devp.getPickInSta()) {
|
// // 获取拣料入库站信息
|
// DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
|
// StaProtocol staProtocol = devpThread.getStation().get(pickSta.getStaNo());
|
// if (staProtocol == null) {
|
// continue;
|
// } else {
|
// staProtocol = staProtocol.clone();
|
// }
|
// if (staProtocol.isAutoing()
|
// && staProtocol.isLoading()
|
// && staProtocol.isInEnable()
|
//// && (staProtocol.getWorkNo() > 0)
|
// && staProtocol.isPakMk()) {
|
//
|
// // 获取条码扫描仪信息
|
// BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
|
// if (barcodeThread == null) {
|
// continue;
|
// }
|
// String barcode = barcodeThread.getBarcode();
|
// if (Cools.isEmpty(barcode)) {
|
// continue;
|
// }
|
// if ("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) {
|
// continue;
|
// }
|
// WrkMast wrkMast = wrkMastMapper.selectByBarcode(barcode);
|
// if (wrkMast == null) {//找不到工作档
|
// continue;
|
// }
|
//
|
// if ((wrkMast.getIoType() != 107)
|
// || Cools.isEmpty(wrkMast.getStaNo()) || Cools.isEmpty(wrkMast.getSourceStaNo())) {
|
// continue;
|
// }
|
//
|
//// // 保存工作主档历史档
|
//// if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) {
|
//// News.info(wrkMast.getWrkNo() + "保存工作主档历史档失败");
|
//// continue;
|
//// }
|
//
|
// //盘点找新库位
|
// try {
|
// LocMast locMast = locMastService.selectById(wrkMast.getSourceLocNo());//源库位
|
// SearchLocParam param = new SearchLocParam();
|
// param.setWrkNo(wrkMast.getWrkNo());
|
// param.setBarcode(wrkMast.getBarcode());
|
// param.setIoType(107);//盘点
|
// param.setSourceStaNo(pickSta.getStaNo());
|
// param.setLiftNo(pickSta.getLiftNo());
|
// param.setLocType1(locMast.getLocType1());
|
// String response = new HttpHandler.Builder()
|
// .setUri(wmsUrl)
|
// .setPath("/rpc/pakin/loc/v2")
|
// .setJson(JSON.toJSONString(param))
|
// .build()
|
// .doPost();
|
// JSONObject jsonObject = JSON.parseObject(response);
|
// Integer code = jsonObject.getInteger("code");
|
// if (code.equals(200)) {
|
// StartupDto dto = jsonObject.getObject("data", StartupDto.class);
|
//
|
//// //获取回库提升机目标站
|
//// LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(pickSta.getLiftNo(), Utils.getLev(dto.getLocNo()));
|
//// if (liftStaProtocol == null) {
|
//// News.info(wrkMast.getWrkNo() + "获取回库提升机目标站失败");
|
//// continue;
|
//// }
|
////
|
//// // 更新工作档数据状态
|
//// wrkMast.setIoType(wrkMast.getIoType() - 50); // 入出库类型: 107->57
|
//// wrkMast.setWrkSts(2L); // 工作状态: 2.设备上走
|
//// wrkMast.setSourceStaNo(dto.getSourceStaNo()); // 源站
|
//// wrkMast.setStaNo(liftStaProtocol.getStaNo());//目标站
|
//// wrkMast.setLocNo(dto.getLocNo()); // 目标库位
|
//// wrkMast.setShuttleNo(null); // 穿梭车清空
|
//// wrkMast.setLiftNo(null);// 提升机清空
|
//// wrkMast.setModiTime(new Date());
|
//// if (wrkMastMapper.updateById(wrkMast) == 0) {
|
//// News.info(wrkMast.getWrkNo() + "更新工作档数据状态失败");
|
//// continue;
|
//// }
|
//
|
//// staProtocol.setStaNo(dto.getSourceStaNo().shortValue());//写入目标站
|
//// MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
|
//
|
// } else if (code == 500) {
|
// News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v2", JSON.toJSONString(param), response);
|
// }
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
// }
|
//
|
// }
|
// }
|
// }
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// }
|
// }
|
|
/**
|
* 初始化实时地图
|
*/
|
public synchronized void initRealtimeBasMap() {
|
try {
|
for (int i = 1; i <= 4; i++) {//总共四层楼
|
Object data = redisUtil.get(RedisKeyType.MAP.key + i);
|
if (data == null) {//redis地图数据为空,从数据库中获取
|
BasMap basMap = basMapService.selectLatestMap(i);
|
if (basMap == null) {
|
//数据库中也不存在地图数据,从地图文件中获取
|
//载入地图
|
List<List<MapNode>> lists = navigateMapData.getJsonData(i, -1, null, null);//获取完整地图(包括入库出库)
|
|
//存入数据库
|
basMap = new BasMap();
|
basMap.setData(JSON.toJSONString(lists));
|
basMap.setCreateTime(new Date());
|
basMap.setUpdateTime(new Date());
|
basMap.setLev(i);
|
|
if (!basMapService.insert(basMap)) {
|
log.info("地图数据存储失败");
|
}
|
}
|
|
//将数据库地图数据存入redis
|
redisUtil.set(RedisKeyType.MAP.key + i, JSON.toJSONString(basMap));
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
// /**
|
// * 入库 ===>> 四向穿梭车入库作业下发
|
// */
|
// public synchronized void shuttleInExecute() {
|
// try {
|
// List<WrkMast> wrkMasts = wrkMastMapper.selectInStep4();
|
// for (WrkMast wrkMast : wrkMasts) {
|
// //获取源站
|
// BasDevp sourceBasDevp = basDevpService.selectById(wrkMast.getSourceStaNo());
|
// if (sourceBasDevp == null) {
|
// continue;//站点不存在
|
// }
|
//
|
// //获取目标站
|
// LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(sourceBasDevp.getLiftNo(), Utils.getLev(wrkMast.getLocNo()));
|
// if (liftStaProtocol == null) {
|
// continue;//站点不存在
|
// }
|
//
|
// // 判断是否满足入库条件,自动、空闲、有物
|
// if (!(liftStaProtocol.getModel() && !liftStaProtocol.getBusy() && liftStaProtocol.getHasTray())) {
|
// News.info("{}任务,输送站点状态不满足入库。输送站点:{}", wrkMast.getWrkNo(), JSON.toJSONString(liftStaProtocol));
|
// continue;
|
// }
|
//
|
// boolean step1 = this.shuttleInExecuteStep1(wrkMast, liftStaProtocol);//小车搬入库中
|
// if (!step1) {
|
// continue;
|
// }
|
// }
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// }
|
// }
|
|
// /**
|
// * 入库-小车搬入库中
|
// * 如需主方法执行continue,请返回false
|
// * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
|
// */
|
// public boolean shuttleInExecuteStep1(WrkMast wrkMast, LiftStaProtocol liftStaProtocol) {
|
// if (wrkMast.getWrkSts() == 4) {
|
// if (wrkMast.getShuttleNo() == null) {//没有绑定小车,进行调度
|
// boolean result = shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), liftStaProtocol.getLocNo());//调度小车到货物所在输送站点进行取货
|
// News.info("{}任务,调度小车{}系统等待中", wrkMast.getWrkNo(), result ? "成功" : "失败");
|
// return false;
|
// }
|
//
|
// //获取四向穿梭车线程
|
// ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
|
// if (shuttleThread == null) {
|
// return false;
|
// }
|
// ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
|
// if (shuttleProtocol == null) {
|
// return false;
|
// }
|
// if (!shuttleThread.isIdle()) {
|
// News.info("{}任务,{}小车忙碌中", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
|
// return false;
|
// }
|
//// //判断小车令牌是否未被占领
|
//// if (shuttleProtocol.getToken() != 0) {
|
//// News.info("{}任务,{}小车,令牌已被独占,禁止派发任务", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
|
//// return false;//小车已被独占,禁止再派发任务
|
//// }
|
//
|
// //判断小车是否存在移动任务
|
// WrkMast hasMoveWorking = wrkMastMapper.selectShuttleHasMoveWorking(wrkMast.getShuttleNo());
|
// if (hasMoveWorking != null) {
|
// News.info("{}任务,{}小车,存在移动任务,禁止派发任务", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
|
// return false;//存在移动任务,禁止执行入库任务
|
// }
|
//
|
// //判断小车是否到达输送站点库位
|
// if (!shuttleProtocol.getCurrentLocNo().equals(liftStaProtocol.getLocNo())) {
|
// //小车不在输送站点位置
|
// shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), liftStaProtocol.getLocNo(), wrkMast.getShuttleNo());//调度小车到货物所在输送站点进行取货
|
// News.info("{}任务,{}小车,未到达输送站点,系统等待中", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
|
// return false;
|
// }
|
//
|
// //小车已抵达输送站点位置,进行搬运货物
|
// ShuttleOperaResult result = ShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getLocNo());
|
// if (result == null) {//路径计算失败
|
// News.info("{}任务,{}小车,路径计算失败,系统等待中", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
|
// return false;
|
// }
|
//
|
// //创建分配命令
|
// ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
|
// assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号
|
// assignCommand.setTaskNo(wrkMast.getWrkNo());//任务号
|
// assignCommand.setTaskMode(ShuttleTaskModeType.PAK_IN.id);//入库模式
|
// assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//源库位(小车当前位置)
|
// assignCommand.setCommands(result.getCommands());//运行命令
|
// assignCommand.setNodes(result.getNodes());//路径节点
|
//
|
// wrkMast.setWrkSts(5L);//4.提升机搬运完成 => 5.小车搬运中
|
// wrkMast.setModiTime(new Date());
|
//// shuttleProtocol.setToken(wrkMast.getWrkNo());//独占小车令牌
|
// if (wrkMastMapper.updateById(wrkMast) > 0) {
|
// //下发任务
|
// MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
|
// }
|
//
|
// return false;
|
// }
|
// return true;
|
// }
|
|
// /**
|
// * 出库 ===>> 四向穿梭车出库作业下发
|
// */
|
// public synchronized void shuttleOutExecute() {
|
// try {
|
// for (WrkMast wrkMast : wrkMastMapper.selectBy2125()) {
|
// boolean step1 = this.shuttleOutExecuteStep1(wrkMast);//小车搬出库中
|
// if (!step1) {
|
// continue;
|
// }
|
// }
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// }
|
// }
|
//
|
// /**
|
// * 出库-小车搬出库中
|
// * 如需主方法执行continue,请返回false
|
// * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
|
// */
|
// public boolean shuttleOutExecuteStep1(WrkMast wrkMast) {
|
// //21.生成出库任务 => 22.小车搬运中
|
// if (wrkMast.getWrkSts() == 21) {
|
// EntityWrapper<StaDesc> wrapper = new EntityWrapper<>();
|
// wrapper.eq("type_no", wrkMast.getIoType());//路径类型
|
// wrapper.eq("stn_no", wrkMast.getStaNo());//出库站点编号
|
// StaDesc staDesc = staDescService.selectOne(wrapper);
|
// if (staDesc == null) {
|
// News.info("{}任务,出库路径不存在", wrkMast.getWrkNo());
|
// return false;//出库路径不存在
|
// }
|
//
|
// //获取出库站点
|
// BasDevp basDevp = basDevpService.selectById(wrkMast.getStaNo());
|
// if (basDevp == null) {
|
// return false;//出库站点不存在
|
// }
|
//
|
//// if (!basDevp.getAutoing().equals("Y")) {
|
//// News.info("{}任务,{}站点,不是自动状态",wrkMast.getWrkNo(),basDevp.getDevNo());
|
//// return false;//不是自动状态
|
//// }
|
////
|
//// if (!basDevp.getOutEnable().equals("Y")) {
|
//// News.info("{}任务,{}站点,没有可出信号", wrkMast.getWrkNo(), basDevp.getDevNo());
|
//// return false;//出库站点不可出
|
//// }
|
//
|
// Integer liftNo = basDevp.getLiftNo();//搜索出库提升机是否存在入库任务,如存在禁止出库
|
// List<WrkMast> liftWrkMasts = wrkMastMapper.selectInWrkMastByLiftNo(liftNo);
|
// if (!liftWrkMasts.isEmpty()) {
|
// News.info("{}任务,{}号提升机,存在入库任务,系统禁止出库", wrkMast.getWrkNo(), liftNo);
|
// return false;//存在入库任务,禁止出库
|
// }
|
//
|
// //同库位组校验
|
// List<String> outerLoc = Utils.getGroupOuterLoc(wrkMast.getSourceLocNo());
|
// List<LocMast> outerLocMasts = locMastService.selectNotEmptyLocNos(outerLoc);
|
// if (!outerLocMasts.isEmpty()) {
|
// News.info("{}任务,浅库位存在货物,系统等待中", wrkMast.getWrkNo());
|
// return false;//浅库位存在未执行任务
|
// }
|
//
|
// //获取源站
|
// LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(basDevp.getLiftNo(), Utils.getLev(wrkMast.getSourceLocNo()));
|
// if (liftStaProtocol == null) {
|
// return false;//找不到站点
|
// }
|
//
|
// if (!(liftStaProtocol.getModel() && !liftStaProtocol.getBusy() && !liftStaProtocol.getHasTray())) {
|
// News.info("{}任务,{}内部输送站,不满足自动、空闲、无托盘状态", wrkMast.getWrkNo(), liftStaProtocol.getStaNo());
|
// return false;//站点必须自动、空闲、没有托盘
|
// }
|
//
|
// if (wrkMast.getShuttleNo() == null) {//没有绑定小车,进行调度
|
// //强制预留一台小车给入库任务
|
// int lev = Utils.getLev(wrkMast.getSourceLocNo());
|
// //获取当前楼层有几台可用小车
|
// int shuttleCount = shuttleDispatchUtils.getShuttleCountByLev(lev);
|
// if (shuttleCount >= 2) {//只有可用小车数量大于2,才进行入库任务预留小车
|
// int shuttleWrkInObligateCount = 1;//预留小车数量
|
// Config config = configService.selectOne(new EntityWrapper<Config>().eq("code", "shuttleWrkInObligateCount").eq("status", 1));
|
// if (config != null) {
|
// shuttleWrkInObligateCount = Integer.parseInt(config.getValue());
|
// }
|
// //可用出库小车数量(给入库任务预留一台车)
|
// int useShuttleCount = shuttleCount - shuttleWrkInObligateCount;
|
// //查询楼层已分配车辆的出库任务数量
|
// List<WrkMast> wrkMasts = wrkMastService.selectShuttleOutWrkByLev(lev);
|
// if (wrkMasts.size() >= useShuttleCount) {
|
// News.info("{}任务,当前楼层可用小车{}台,出库任务已分配{}台,系统等待中。", wrkMast.getWrkNo(), useShuttleCount, wrkMasts.size());
|
// return false;
|
// }
|
// }
|
// boolean result = shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo());//调度小车到货物所在库位进行取货
|
// News.info("{}任务,调度小车{}系统等待中。", wrkMast.getWrkNo(), result ? "成功" : "失败");
|
// return false;
|
// }
|
//
|
// //获取四向穿梭车线程
|
// NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
|
// if (shuttleThread == null) {
|
// return false;
|
// }
|
// NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
|
// if (shuttleProtocol == null) {
|
// return false;
|
// }
|
// if (!shuttleProtocol.isIdle()) {
|
// News.info("{}任务,{}小车,忙碌中", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
|
// return false;
|
// }
|
// //判断小车令牌是否未被占领
|
// if (shuttleProtocol.getToken() != 0) {
|
// News.info("{}任务,{}小车,令牌已被独占,禁止派发任务", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
|
// return false;//小车已被独占,禁止再派发任务
|
// }
|
//
|
// //判断小车是否到达货物库位
|
// if (!shuttleProtocol.getCurrentLocNo().equals(wrkMast.getSourceLocNo())) {
|
// //小车不在输送站点位置
|
// shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getShuttleNo());//调度小车到货物所在库位进行取货
|
// News.info("{}任务,{}小车,未到达输送站点,系统等待中", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
|
// return false;
|
// }
|
//
|
// //小车已抵达货物位置,进行搬运货物
|
// ShuttleOperaResult result = ShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), liftStaProtocol.getLocNo());//将货物搬运至提升机输送站点
|
// if (result == null) {//出库路径计算失败
|
// News.info("{}任务,{}小车,路径计算失败,系统等待中", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
|
// return false;
|
// }
|
//
|
// //创建分配命令
|
// ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
|
// assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号
|
// assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//任务号
|
// assignCommand.setTaskMode(ShuttleTaskModeType.PAK_OUT.id.shortValue());//出库模式
|
// assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//源库位(小车当前位置)
|
// assignCommand.setCommands(result.getCommands());//运行命令
|
// assignCommand.setNodes(result.getNodes());//路径节点
|
//
|
// wrkMast.setWrkSts(22L);//21.生成出库任务 => 22.小车搬运中
|
// wrkMast.setModiTime(new Date());
|
// shuttleProtocol.setToken(wrkMast.getWrkNo());//独占小车令牌
|
// if (wrkMastMapper.updateById(wrkMast) > 0) {
|
// //下发任务
|
// MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
|
// }
|
// return false;
|
// }
|
// return true;
|
// }
|
|
/**
|
* 四向穿梭车任务完成
|
*/
|
public synchronized void shuttleFinished() {
|
try {
|
for (ShuttleSlave shuttle : slaveProperties.getShuttle()) {
|
//获取四向穿梭车信息
|
ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId());
|
ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
|
if (shuttleProtocol == null) {
|
continue;
|
}
|
|
//四向穿梭车状态为等待确认、小车处于空闲状态
|
if (shuttleProtocol.getProtocolStatus() == ShuttleProtocolStatusType.WAITING.id //任务完成等待确认
|
&& shuttleProtocol.getTaskNo() != 0
|
) {
|
//将任务档标记为完成
|
WrkMast wrkMast = wrkMastService.selectByWorkNo(shuttleProtocol.getTaskNo());
|
if (wrkMast != null) {
|
switch (wrkMast.getWrkSts().intValue()) {
|
// case 5://5.小车搬运中 ==> 9.入库完成
|
// wrkMast.setWrkSts(9L);
|
// shuttleProtocol.setTaskNo(0);
|
// if (shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) {
|
// //释放小车令牌
|
// shuttleProtocol.setToken(0);
|
// }
|
// break;
|
// case 22://22.小车搬运中 ==> 23.小车搬运完成
|
// wrkMast.setWrkSts(23L);
|
// shuttleProtocol.setTaskNo(0);
|
// if (shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) {
|
// //释放小车令牌
|
// shuttleProtocol.setToken(0);
|
// }
|
// break;
|
case 302://302.小车移动至站点 ==> 303.小车移动至站点完成
|
wrkMast.setWrkSts(WrkStsType.MOVE_SITE_COMPLETE.sts);
|
break;
|
case 110://310.小车移动中 ==> 311.小车移动完成
|
wrkMast.setWrkSts(WrkStsType.COMPLETE_MOVE.sts);
|
shuttleThread.setTaskNo(0);
|
break;
|
default:
|
}
|
|
if (wrkMastService.updateById(wrkMast)) {
|
if (wrkMast.getWrkSts() == 111) {
|
// 保存工作主档历史档
|
if (wrkMastLogMapper.save(wrkMast.getWrkNo()) <= 0) {
|
log.info("保存工作历史档[workNo={0}]失败", wrkMast.getWrkNo());
|
}
|
// 删除工作主档
|
if (!wrkMastService.deleteById(wrkMast)) {
|
log.info("删除工作主档[workNo={0}]失败", wrkMast.getWrkNo());
|
}
|
}
|
|
//设置四向穿梭车为空闲状态
|
shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
|
News.info("四向穿梭车已确认且任务完成状态,复位。四向穿梭车号={}", shuttleProtocol.getShuttleNo());
|
} else {
|
News.error("四向穿梭车已确认且任务完成状态,复位失败,但未找到工作档。四向穿梭车号={},工作号={}", shuttleProtocol.getShuttleNo(), shuttleProtocol.getTaskNo());
|
}
|
} else {
|
Object object = redisUtil.get(RedisKeyType.SHUTTLE_WORK_FLAG.key + shuttleProtocol.getTaskNo());
|
if(object != null){
|
ShuttleAssignCommand assignCommand = JSON.parseObject(object.toString(), ShuttleAssignCommand.class);
|
if (!assignCommand.getAuto()) {
|
//手动模式
|
//工作号清零
|
shuttleThread.setTaskNo(0);
|
//设置四向穿梭车为空闲状态
|
shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
|
News.info("四向穿梭车已确认且任务完成状态,复位。四向穿梭车号={}", shuttleProtocol.getShuttleNo());
|
}
|
}
|
}
|
}
|
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
// /**
|
// * 提升机任务
|
// */
|
// public synchronized void liftIoExecute() {
|
// try {
|
// for (LiftSlave liftSlave : slaveProperties.getLift()) {
|
// LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftSlave.getId());
|
// if (liftThread == null) {
|
// continue;
|
// }
|
// LiftProtocol liftProtocol = liftThread.getLiftProtocol();
|
// if (liftProtocol == null) {
|
// continue;
|
// }
|
//
|
// if (!liftProtocol.isIdle()) {
|
// News.info("{}号提升机,忙碌中", liftSlave.getId());
|
// continue;
|
// }
|
//
|
// //判断提升机令牌是否被占用
|
// if (liftProtocol.getToken() != 0) {
|
// News.info("{}号提升机,令牌已被独占", liftSlave.getId());
|
// continue;
|
// }
|
//
|
// //搜索是否有待处理的任务
|
// List<WrkMast> wrkMasts = wrkMastMapper.selectLiftStep223103();
|
// if (wrkMasts.isEmpty()) {
|
// continue;
|
// }
|
//
|
// for (WrkMast wrkMast : wrkMasts) {
|
// //搜索是否有其他任务占用了提升机,如果占用提升机的任务和当前任务相同,则运行执行
|
// WrkMast wrkMast1 = wrkMastMapper.selectLiftWrkMast(liftProtocol.getLiftNo().intValue());
|
// if (wrkMast1 != null && wrkMast1.getWrkNo().intValue() != wrkMast.getWrkNo().intValue()) {
|
// News.info("{}号提升机,被其他任务{}占用且和当前任务{}不相同,禁止派发", liftSlave.getId(), wrkMast1.getWrkNo(), wrkMast.getWrkNo());
|
// continue;
|
// }
|
//
|
// boolean stepIn = this.liftIoExecuteStepIn(wrkMast);//提升机入库
|
// if (!stepIn) {
|
// continue;
|
// }
|
//
|
// boolean stepOut = this.liftIoExecuteStepOut(wrkMast);//提升机出库
|
// if (!stepOut) {
|
// continue;
|
// }
|
// }
|
//
|
// }
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// }
|
// }
|
//
|
// /**
|
// * 提升机入库
|
// * 如需主方法执行continue,请返回false
|
// * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
|
// */
|
// private boolean liftIoExecuteStepIn(WrkMast wrkMast) {
|
// //--------------------------------------提升机入库-----------------------------------------//
|
// Date now = new Date();
|
//
|
// //2.设备上走 ==> 3.提升机搬运中
|
// if (wrkMast.getWrkSts() == 2) {
|
// //获取源站
|
// BasDevp sourceBasDevp = basDevpService.selectById(wrkMast.getSourceStaNo());
|
// if (sourceBasDevp == null) {
|
// return false;//找不到站点
|
// }
|
//
|
// if (!sourceBasDevp.getInEnable().equals("Y")) {
|
// News.info("{}任务,{}源站,没有可入信号", wrkMast.getWrkNo(), sourceBasDevp.getDevNo());
|
// return false;//站点不可入
|
// }
|
//
|
// Integer barcodeId = Utils.getBarcodeIdByStaNo(wrkMast.getSourceStaNo());
|
// if (barcodeId == null) {
|
// News.info("{}任务,{}源站,找不到可用条码器ID", wrkMast.getWrkNo(), sourceBasDevp.getDevNo());
|
// return false;//站点不可入
|
// }
|
//
|
// BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId);
|
// if (barcodeThread == null) {
|
// News.info("{}任务,{}源站,条码器{}线程为空", wrkMast.getWrkNo(), sourceBasDevp.getDevNo(), barcodeId);
|
// return false;//站点不可入
|
// }
|
// String barcode = barcodeThread.getBarcode();
|
// if(!Cools.isEmpty(barcode)) {
|
// if(!("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode))) {
|
// //存在条码值,判断是否和当前工作档一致
|
// if (!barcode.equals(wrkMast.getBarcode())) {
|
// News.info("{}任务,{}站点,条码器{}值{}与工作档条码值{}不一致,系统跳过执行", wrkMast.getWrkNo(), sourceBasDevp.getDevNo(), barcodeId, barcode,wrkMast.getBarcode());
|
// return false;//站点不可入
|
// }
|
// }
|
// }else {
|
// return false;
|
// }
|
//
|
// //判断提升机整个三楼是否都处于入库模式
|
// Integer outInModel1 = Utils.getOutInModelByLift(sourceBasDevp.getLiftNo(), 1);
|
// Integer outInModel2 = Utils.getOutInModelByLift(sourceBasDevp.getLiftNo(), 5);
|
// Integer outInModel3 = Utils.getOutInModelByLift(sourceBasDevp.getLiftNo(), 8);
|
// if (outInModel1 == null || outInModel2 == null || outInModel3 == null) {
|
// News.info("{}任务,没有出入库模式", wrkMast.getWrkNo());
|
// return false;//不存在出入库模式
|
// }
|
//
|
// if (outInModel1 == 2 || outInModel2 == 2 && outInModel3 == 2) {
|
// News.info("{}任务,有站点处于出库模式,禁止入库", wrkMast.getWrkNo());
|
// return false;//只要有一个处于出库模式,禁止入库
|
// }
|
//
|
// LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, sourceBasDevp.getLiftNo());
|
// if (liftThread == null) {
|
// return false;
|
// }
|
// LiftProtocol liftProtocol = liftThread.getLiftProtocol();
|
// if (liftProtocol == null) {
|
// return false;
|
// }
|
// if (!liftProtocol.isIdle()) {
|
// News.info("{}任务,{}号提升机,忙碌中", wrkMast.getWrkNo(), liftProtocol.getLiftNo());
|
// return false;
|
// }
|
// //判断提升机令牌是否未被占领
|
// if (liftProtocol.getToken() != 0) {
|
// News.info("{}任务,{}号提升机,令牌已被独占,禁止派发", wrkMast.getWrkNo(), liftProtocol.getLiftNo());
|
// return false;//提升机已被独占,禁止再派发任务
|
// }
|
//
|
// //判断提升机内是否有小车
|
// if (liftProtocol.getHasCar()) {
|
// News.info("{}任务,{}号提升机,提升机内部有小车,禁止派发", wrkMast.getWrkNo(), liftProtocol.getLiftNo());
|
// return false;//有小车,禁止派发
|
// }
|
//
|
// //判断提升机内是否有托盘
|
// if (liftProtocol.getHasTray()) {
|
// News.info("{}任务,{}号提升机,提升机内部有托盘,禁止派发", wrkMast.getWrkNo(), liftProtocol.getLiftNo());
|
// return false;//有托盘,禁止派发
|
// }
|
//
|
// //判断提升机是否有其他任务
|
// WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(liftThread.getSlave().getId());
|
// if (liftWrkMast != null) {
|
// News.info("{}任务,{}号提升机,当前提升机存在未完成任务,禁止派发", wrkMast.getWrkNo(), liftProtocol.getLiftNo());
|
// return false;//当前提升机存在未完成任务,等待下一次轮询
|
// }
|
//
|
// //获取源站对应的牛眼提升机站点编号(起点编号)
|
// Integer startSta = Integer.parseInt(sourceBasDevp.getQrCodeValue());
|
// //获取提升机站点
|
// LiftStaProtocol targetStaProtocol = NyLiftUtils.getLiftStaByLev(liftThread.getSlave().getId(), Utils.getLev(wrkMast.getLocNo()));
|
// if (targetStaProtocol == null) {
|
// return false;//站点不存在
|
// }
|
//
|
// if (targetStaProtocol.getHasTray()) {
|
// News.info("{}任务,{}号提升机,{}站点,提升机站点有托盘,禁止派发", wrkMast.getWrkNo(), liftProtocol.getLiftNo(), targetStaProtocol.getStaNo());
|
// return false;//提升机站点有托盘,禁止派发
|
// }
|
//
|
// Integer targetSta = targetStaProtocol.getStaNo();
|
//
|
// //获取提升机命令
|
// NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_TRAY.id, startSta, targetSta, wrkMast.getWrkNo());
|
// if (wrkMast.getIoType() == 53 || wrkMast.getIoType() == 57) {
|
// //拣料再回库,重新分配设备工作号
|
// int deviceWrk = commonService.getWorkNo(8);//生成提升机设备工作号
|
// BasLiftOpt basLiftOpt = basLiftOptService.selectByDeviceWrk(String.valueOf(deviceWrk), liftThread.getSlave().getId());
|
// if (basLiftOpt != null) {
|
// News.info("{}任务,{}号提升机,设备工作号出现重复情况,请联系技术人员支持。", wrkMast.getWrkNo(), liftProtocol.getLiftNo());
|
// return false;
|
// }
|
// liftCommand.setTaskNo((short) deviceWrk);
|
// }
|
// ArrayList<NyLiftCommand> commands = new ArrayList<>();
|
// commands.add(liftCommand);
|
//
|
// //提交到线程去工作
|
// LiftAssignCommand assignCommand = new LiftAssignCommand();
|
// assignCommand.setCommands(commands);
|
// assignCommand.setLiftNo(liftProtocol.getLiftNo());
|
// assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());
|
// assignCommand.setTaskMode(NyLiftTaskModelType.MOVE_TRAY.id.shortValue());
|
//
|
// wrkMast.setWrkSts(3L);//2.设备上走 ==> 3.提升机搬运中
|
// wrkMast.setLiftNo(liftThread.getSlave().getId());//任务档绑定提升机号
|
// wrkMast.setModiTime(now);
|
// liftProtocol.setToken(wrkMast.getWrkNo());//独占提升机令牌
|
// if (wrkMastMapper.updateById(wrkMast) > 0) {
|
// //下发任务
|
// MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand));
|
// }
|
//
|
// return false;
|
// }
|
// return true;
|
// }
|
//
|
// /**
|
// * 提升机出库
|
// * 如需主方法执行continue,请返回false
|
// * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
|
// */
|
// private boolean liftIoExecuteStepOut(WrkMast wrkMast) {
|
// //--------------------------------------提升机出库-----------------------------------------//
|
// Date now = new Date();
|
//
|
// //23.小车搬运完成 ==> 24.提升机搬运中
|
// if (wrkMast.getWrkSts() == 23) {
|
// NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
|
// if (shuttleThread == null) {
|
// return false;
|
// }
|
//
|
// //获取出库站点(目标站)
|
// BasDevp basDevp = basDevpService.selectById(wrkMast.getStaNo());
|
// if (basDevp == null) {
|
// News.info("{}任务,出库站点不存在,禁止派发", wrkMast.getWrkNo());
|
// return false;//出库站点不存在
|
// }
|
//
|
// //获取源站对应的牛眼提升机站点编号(起点编号)
|
// LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(basDevp.getLiftNo(), Utils.getLev(wrkMast.getSourceLocNo()));
|
// if (liftStaProtocol == null) {
|
// News.info("{}任务,找不到站点,禁止派发", wrkMast.getWrkNo());
|
// return false;//找不到站点
|
// }
|
// Integer startSta = liftStaProtocol.getStaNo();
|
//
|
// NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
|
// if (shuttleProtocol.getCurrentLocNo().equals(liftStaProtocol.getLocNo())) {
|
// //小车还在输送站点
|
// //调度小车避让
|
// boolean result = Utils.searchEmptyGroupToMoveShuttle(Utils.getLev(wrkMast.getSourceLocNo()), wrkMast.getShuttleNo(), shuttleThread);
|
// if (!result) {
|
// News.info("{}任务,{}小车,小车在输送站点调度小车避让失败", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
|
// return false;
|
// }
|
// }
|
//
|
// if (!basDevp.getAutoing().equals("Y")) {
|
// News.info("{}任务,{}站点,没有自动信号,禁止派发", wrkMast.getWrkNo(), basDevp.getDevNo());
|
// return false;//出库站点不可出
|
// }
|
//
|
// if (basDevp.getLoading().equals("Y")) {
|
// News.info("{}任务,{}站点,存在有物信号,禁止派发", wrkMast.getWrkNo(), basDevp.getDevNo());
|
// return false;//出库站点不可出
|
// }
|
//
|
// if (!basDevp.getOutEnable().equals("Y")) {
|
// News.info("{}任务,{}站点,没有可出信号,禁止派发", wrkMast.getWrkNo(), basDevp.getDevNo());
|
// return false;//出库站点不可出
|
// }
|
//
|
// LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, basDevp.getLiftNo());
|
// if (liftThread == null) {
|
// return false;
|
// }
|
// LiftProtocol liftProtocol = liftThread.getLiftProtocol();
|
// if (liftProtocol == null) {
|
// return false;
|
// }
|
//
|
// if (!liftProtocol.isIdle()) {
|
// News.info("{}任务,{}号提升机,忙碌中", wrkMast.getWrkNo(), liftProtocol.getLiftNo());
|
// return false;
|
// }
|
// //判断提升机令牌是否未被占领
|
// if (liftProtocol.getToken() != 0) {
|
// News.info("{}任务,{}号提升机,令牌已被独占,禁止派发", wrkMast.getWrkNo(), liftProtocol.getLiftNo());
|
// return false;//提升机已被独占,禁止再派发任务
|
// }
|
// //判断提升机是否有其他任务
|
// WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(liftThread.getSlave().getId());
|
// if (liftWrkMast != null) {
|
// News.info("{}任务,{}号提升机,当前提升机存在未完成任务,禁止派发", wrkMast.getWrkNo(), liftProtocol.getLiftNo());
|
// return false;//当前提升机存在未完成任务,等待下一次轮询
|
// }
|
//
|
// //获目标站源站对应的输送站点
|
// BasDevp targetBasDevp = basDevpService.selectById(wrkMast.getStaNo());
|
// if (targetBasDevp == null) {
|
// News.info("{}任务,{}站点,站点不存在,禁止派发", wrkMast.getWrkNo(), wrkMast.getStaNo());
|
// return false;//站点不存在
|
// }
|
// //获取牛眼提升机站点编号(目标编号)
|
// Integer targetSta = Integer.parseInt(targetBasDevp.getQrCodeValue());
|
//
|
// //获取提升机命令
|
// NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftThread.getSlave().getId(), NyLiftTaskModelType.MOVE_TRAY.id, startSta, targetSta, wrkMast.getWrkNo());
|
//
|
// ArrayList<NyLiftCommand> commands = new ArrayList<>();
|
// commands.add(liftCommand);
|
//
|
// //提交到线程去工作
|
// LiftAssignCommand assignCommand = new LiftAssignCommand();
|
// assignCommand.setCommands(commands);
|
// assignCommand.setLiftNo(liftProtocol.getLiftNo());
|
// assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());
|
// assignCommand.setTaskMode(NyLiftTaskModelType.MOVE_TRAY.id.shortValue());
|
//
|
// wrkMast.setWrkSts(24L);//23.小车搬运完成 ==> 24.提升机搬运中
|
// wrkMast.setLiftNo(liftThread.getSlave().getId());//任务档绑定提升机号
|
// wrkMast.setModiTime(now);
|
// liftProtocol.setToken(wrkMast.getWrkNo());//独占提升机令牌
|
// if (wrkMastMapper.updateById(wrkMast) > 0) {
|
// //下发任务
|
// MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand));
|
// }
|
//
|
// return false;
|
// }
|
// return true;
|
// }
|
//
|
/**
|
* 货叉提升机任务完成
|
*/
|
public synchronized void forkLiftFinished() {
|
try {
|
for (ForkLiftSlave forkLiftSlave : slaveProperties.getForkLift()) {
|
//获取提升机信息
|
ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, forkLiftSlave.getId());
|
ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus();
|
if (forkLiftProtocol == null) {
|
continue;
|
}
|
|
//提升机为等待确认且空闲
|
if (forkLiftProtocol.getProtocolStatus() == ForkLiftProtocolStatusType.WAITING.id
|
&& forkLiftProtocol.getWrkNo() != 0
|
) {
|
//将任务档标记为完成
|
WrkMast wrkMast = wrkMastService.selectByWorkNo(forkLiftProtocol.getWrkNo());
|
if (wrkMast != null) {
|
switch (wrkMast.getWrkSts().intValue()) {
|
// case 3://3.提升机搬运中 ==> 4.提升机搬运完成
|
// wrkMast.setWrkSts(4L);
|
// wrkMast.setLiftNo(null);//释放提升机
|
// if (liftProtocol.getToken().equals(wrkMast.getWrkNo())) {
|
// //释放提升机令牌
|
// liftProtocol.setToken(0);
|
// }
|
// break;
|
// case 24://24.提升机搬运中 ==> 25.提升机搬运完成
|
// wrkMast.setWrkSts(25L);
|
// if (wrkMast.getIoType() == 11) {//库位移转
|
// wrkMast.setWrkSts(4L);//4.提升机搬运完成
|
// } else {
|
// if (wrkMast.getMk() == null || !wrkMast.getMk().equals("Y")) {
|
// //不需要用到机械臂,直接转29.出库完成
|
// wrkMast.setWrkSts(29L);
|
// wrkMast.setShuttleNo(null);//释放小车
|
// wrkMast.setLiftNo(null);//释放提升机
|
// wrkMast.setModiTime(new Date());
|
// }
|
// }
|
// break;
|
case 306://306.提升机搬运中 ==> 307.提升机搬运完成
|
wrkMast.setWrkSts(WrkStsType.MOVE_LIFT_RUN_COMPLETE.sts);
|
//货叉提升机需要跳过迁出提升机流程
|
wrkMast.setWrkSts(WrkStsType.MOVE_OUT_LIFT_COMPLETE.sts);
|
break;
|
default:
|
}
|
|
wrkMast.setModiTime(new Date());
|
if (wrkMastService.updateById(wrkMast)) {
|
forkLiftThread.reset();
|
News.info("提升机已确认且任务完成状态。提升机号={}", forkLiftProtocol.getLiftNo());
|
} else {
|
News.error("提升机已确认且任务完成状态,复位失败,但未找到工作档。提升机号={},工作号={}", forkLiftProtocol.getLiftNo(), forkLiftProtocol.getWrkNo());
|
}
|
}
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 异常信息记录
|
*/
|
public void recErr() {
|
try {
|
this.recShuttleErr();
|
this.recLiftErr();
|
} catch (Exception e) {
|
News.error("recErr fail", e);
|
}
|
}
|
|
/**
|
* 四向穿梭车异常信息记录
|
*/
|
private void recShuttleErr() {
|
Date now = new Date();
|
for (ShuttleSlave shuttleSlave : slaveProperties.getShuttle()) {
|
// 获取四向穿梭车信息
|
ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleSlave.getId());
|
if (shuttleThread == null) {
|
continue;
|
}
|
ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
|
if (shuttleProtocol == null) {
|
continue;
|
}
|
|
if (shuttleProtocol.getTaskNo() != 0) {
|
//有任务
|
BasShuttleErrLog latest = basShuttleErrLogService.findLatestByTaskNo(shuttleSlave.getId(), shuttleProtocol.getTaskNo());
|
// 有异常
|
if (latest == null) {
|
if (shuttleProtocol.getErrorCode() != null && Integer.parseInt(shuttleProtocol.getErrorCode()) != 0) {
|
WrkMast wrkMast = wrkMastService.selectByWorkNo(shuttleProtocol.getTaskNo());
|
if (wrkMast == null) {
|
continue;
|
}
|
int errorCode = Integer.parseInt(shuttleProtocol.getErrorCode());
|
BasShuttleErr basShuttleErr = basShuttleErrService.queryByCode(errorCode);
|
String errName = basShuttleErr==null? "未知异常":basShuttleErr.getErrName();
|
BasShuttleErrLog basShuttleErrLog = new BasShuttleErrLog(
|
null, // 编号
|
wrkMast.getWrkNo(), // 工作号
|
now, // 发生时间
|
null, // 结束时间
|
wrkMast.getWrkSts(), // 工作状态
|
wrkMast.getIoType(), // 入出库类型
|
shuttleSlave.getId(), // 四向穿梭车
|
null, // plc
|
wrkMast.getLocNo(), // 目标库位
|
wrkMast.getStaNo(), // 目标站
|
wrkMast.getSourceStaNo(), // 源站
|
wrkMast.getSourceLocNo(), // 源库位
|
wrkMast.getBarcode(), // 条码
|
errorCode, // 异常码
|
errName, // 异常
|
1, // 异常情况
|
now, // 添加时间
|
null, // 添加人员
|
now, // 修改时间
|
null, // 修改人员
|
"任务中异常", // 备注
|
JSON.toJSONString(shuttleProtocol) // 系统状态数据
|
);
|
if (!basShuttleErrLogService.insert(basShuttleErrLog)) {
|
News.error("四向穿梭车plc异常记录失败 ===>> [id:{}] [error:{}]", shuttleSlave.getId(), errName);
|
}
|
}
|
} else {
|
// 异常修复
|
if (shuttleProtocol.getErrorCode() == null || Integer.parseInt(shuttleProtocol.getErrorCode()) == 0) {
|
latest.setEndTime(now);
|
latest.setUpdateTime(now);
|
latest.setStatus(2);
|
if (!basShuttleErrLogService.updateById(latest)) {
|
News.error("四向穿梭车plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", shuttleSlave.getId(), latest.getId());
|
}
|
}
|
}
|
}
|
}
|
}
|
|
/**
|
* 提升机异常信息记录
|
*/
|
private void recLiftErr() {
|
Date now = new Date();
|
for (ForkLiftSlave forkLiftSlave : slaveProperties.getForkLift()) {
|
// 获取提升机信息
|
ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, forkLiftSlave.getId());
|
if (forkLiftThread == null) {
|
continue;
|
}
|
ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus();
|
if (forkLiftProtocol == null) {
|
continue;
|
}
|
|
if (forkLiftProtocol.getTaskNo() != 0) {
|
//有任务
|
BasLiftErrLog latest = basLiftErrLogService.findLatestByTaskNo(forkLiftSlave.getId(), forkLiftProtocol.getTaskNo());
|
// 有异常
|
if (latest == null) {
|
if (forkLiftProtocol.getErrorCode() != null && forkLiftProtocol.getErrorCode() != 0) {
|
WrkMast wrkMast = wrkMastService.selectByWorkNo(forkLiftProtocol.getWrkNo());
|
if (wrkMast == null) {
|
continue;
|
}
|
|
BasLiftErr basLiftErr = basLiftErrService.queryByCode(forkLiftProtocol.getErrorCode());
|
String errName = basLiftErr==null? "未知异常":basLiftErr.getErrName();
|
|
BasLiftErrLog basLiftErrLog = new BasLiftErrLog(
|
null, // 编号
|
wrkMast.getWrkNo(), // 工作号
|
now, // 发生时间
|
null, // 结束时间
|
wrkMast.getWrkSts(), // 工作状态
|
wrkMast.getIoType(), // 入出库类型
|
forkLiftSlave.getId(), // 提升机
|
null, // plc
|
wrkMast.getLocNo(), // 目标库位
|
wrkMast.getStaNo(), // 目标站
|
wrkMast.getSourceStaNo(), // 源站
|
wrkMast.getSourceLocNo(), // 源库位
|
wrkMast.getBarcode(), // 条码
|
null, // 异常码
|
errName, // 异常
|
1, // 异常情况
|
now, // 添加时间
|
null, // 添加人员
|
now, // 修改时间
|
null, // 修改人员
|
"任务中异常", // 备注
|
JSON.toJSONString(forkLiftProtocol) // 系统状态数据
|
);
|
if (!basLiftErrLogService.insert(basLiftErrLog)) {
|
News.error("提升机plc异常记录失败 ===>> [id:{}] [error:{}]", forkLiftSlave.getId(), errName);
|
}
|
}
|
} else {
|
// 异常修复
|
if (forkLiftProtocol.getErrorCode() == null || forkLiftProtocol.getErrorCode() == 0) {
|
latest.setEndTime(now);
|
latest.setUpdateTime(now);
|
latest.setStatus(2);
|
if (!basLiftErrLogService.updateById(latest)) {
|
News.error("提升机plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", forkLiftSlave.getId(), latest.getId());
|
}
|
}
|
}
|
}
|
}
|
}
|
|
// -------------------------------------------------------------------------------
|
|
// /**
|
// * 空栈板初始化入库,叉车入库站放货
|
// */
|
// public void storeEmptyPlt(){
|
// try {
|
// for (DevpSlave devp : slaveProperties.getDevp()) {
|
// // 遍历空板入库口
|
// for (DevpSlave.Sta emptyInSta : devp.getEmptyInSta()) {
|
// // 获取空板入库站信息
|
// DevpThread devpThread = (DevpThread) 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() == 0 || (staProtocol.getWorkNo() >= 9990 || staProtocol.getWorkNo() <= 9999))
|
// && staProtocol.isPakMk()) {
|
//
|
// // 获取条码扫描仪信息
|
// String barcode = null;
|
// BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, emptyInSta.getBarcode());
|
// if (barcodeThread != null) {
|
// String barcode0 = barcodeThread.getBarcode();
|
// if (!Cools.isEmpty(barcode0)) {
|
//// News.info("{}号条码扫描器检测条码信息:{}", emptyInSta.getBarcode(), barcode0);
|
// if (!"NG".endsWith(barcode0) && !"NoRead".equals(barcode0) && !"empty".equals(barcode0)) {
|
// barcode = barcode0;
|
// }
|
// }
|
// }
|
//
|
// if (!Cools.isEmpty(barcode)) {
|
// WrkMast wrkMast = wrkMastMapper.selectByBarcode(barcode);//条码存在工作档
|
// if (wrkMast != null) {
|
// continue;
|
// }
|
// }
|
//
|
// LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, emptyInSta.getLed());
|
//
|
// try {
|
// LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
|
//
|
// SearchLocParam param = new SearchLocParam();
|
// param.setIoType(10);
|
// if (!Cools.isEmpty(barcode)) {
|
// param.setBarcode(barcode);
|
// }
|
// param.setSourceStaNo(emptyInSta.getStaNo());
|
//// param.setLocType1(locTypeDto.getLocType1());
|
// String response = new HttpHandler.Builder()
|
// .setUri(wmsUrl)
|
// .setPath("/rpc/pakin/loc/v2")
|
// .setJson(JSON.toJSONString(param))
|
// .build()
|
// .doPost();
|
// JSONObject jsonObject = JSON.parseObject(response);
|
// Integer code = jsonObject.getInteger("code");
|
// if (code.equals(200)) {
|
// StartupDto dto = jsonObject.getObject("data", StartupDto.class);
|
// barcodeThread.setBarcode("");
|
//// // 更新站点信息 且 下发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 {
|
// if (ledThread != null) {
|
// String errorMsg = jsonObject.getString("msg");
|
// if (!Cools.isEmpty(errorMsg)) {
|
// MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(3, errorMsg));
|
// }
|
// }
|
// News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v2", JSON.toJSONString(param), response);
|
// }
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
// }
|
//
|
// }
|
//
|
//
|
// }
|
// }
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// }
|
// }
|
|
/**
|
* 出库 ===>> 工作档信息写入led显示器
|
*/
|
public void ledExecute() {
|
// try {
|
// 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<>();
|
// List<WrkMastLog> wrkMastLogs = 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());
|
// Integer wrkNo = staProtocol.getWorkNo().intValue();
|
// Integer ioType = null;
|
// String sourceLocNo = null;
|
// String locNo = null;
|
// Integer wrkStaNo = null;
|
// String barcode = null;
|
// if (wrkMast == null) {
|
// //查询历史档
|
// WrkMastLog wrkMastLog = wrkMastLogMapper.selectLatestByWorkNo(staProtocol.getWorkNo().intValue());
|
// if (wrkMastLog == null) {
|
// continue;
|
// }
|
// ioType = wrkMastLog.getIoType();
|
// sourceLocNo = wrkMastLog.getSourceLocNo();
|
// locNo = wrkMastLog.getLocNo();
|
// wrkStaNo = wrkMastLog.getStaNo();
|
// barcode = wrkMastLog.getBarcode();
|
// wrkMastLogs.add(wrkMastLog);
|
// }else {
|
// if (wrkMast.getWrkSts() < 14 || wrkMast.getIoType() < 100) {
|
// continue;
|
// }
|
// ioType = wrkMast.getIoType();
|
// sourceLocNo = wrkMast.getSourceLocNo();
|
// locNo = wrkMast.getLocNo();
|
// wrkStaNo = wrkMast.getStaNo();
|
// barcode = wrkMast.getBarcode();
|
// wrkMasts.add(wrkMast);
|
// }
|
// // 组装命令
|
// LedCommand ledCommand = new LedCommand();
|
// ledCommand.setWorkNo(wrkNo);
|
// ledCommand.setIoType(ioType);
|
// // 出库模式
|
// switch (ioType) {
|
// 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:
|
// News.error("任务入出库类型错误!!![工作号:{}] [入出库类型:{}]", wrkNo, ioType);
|
// break;
|
// }
|
// ledCommand.setSourceLocNo(sourceLocNo);
|
// ledCommand.setLocNo(locNo);
|
// ledCommand.setStaNo(wrkStaNo);
|
// ledCommand.setBarcode(barcode);
|
// if (ioType != 110 && ioType != 10) {
|
// List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo));
|
// if (!wrkDetls.isEmpty()) {
|
// wrkDetls.forEach(wrkDetl -> {
|
// double remainNum = wrkDetl.getStock() - wrkDetl.getAnfme();//剩余数量
|
// if (remainNum < 0) {
|
// remainNum = 0;
|
// }
|
// String matnr = wrkDetl.getMatnr();
|
// Mat mat = matService.selectByMatnr(wrkDetl.getMatnr());
|
// if (mat != null) {
|
// if (!mat.getMatnr().equals(mat.getMatnr2())) {
|
// matnr += " - " + mat.getMatnr2();
|
// }
|
// }
|
// ledCommand.getMatDtos().add(new MatDto(matnr, wrkDetl.getMaktx(), wrkDetl.getAnfme(), remainNum, wrkDetl.getSpecs(), wrkDetl.getSuppCode(), wrkDetl.getOrderNo()));
|
// });
|
// }else {
|
// List<WrkDetlLog> wrkDetlLogs = wrkDetlLogService.selectLatestByWorkNo(wrkNo, barcode);
|
// for (WrkDetlLog wrkDetlLog : wrkDetlLogs) {
|
// double remainNum = wrkDetlLog.getStock() - wrkDetlLog.getAnfme();//剩余数量
|
// if (remainNum < 0) {
|
// remainNum = 0;
|
// }
|
// String matnr = wrkDetlLog.getMatnr();
|
// Mat mat = matService.selectByMatnr(wrkDetlLog.getMatnr());
|
// if (mat != null) {
|
// if (!mat.getMatnr().equals(mat.getMatnr2())) {
|
// matnr += " - " + mat.getMatnr2();
|
// }
|
// }
|
// ledCommand.getMatDtos().add(new MatDto(matnr, wrkDetlLog.getMaktx(), wrkDetlLog.getAnfme(), remainNum, wrkDetlLog.getSpecs(), wrkDetlLog.getSuppCode()));
|
// }
|
// }
|
// commands.add(ledCommand);
|
// }
|
// Set<Integer> workNos = null;
|
// if (!wrkMasts.isEmpty()) {
|
// workNos = wrkMasts.stream().map(WrkMast::getWrkNo).collect(Collectors.toSet());
|
// }else {
|
// workNos = wrkMastLogs.stream().map(WrkMastLog::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 (!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();
|
// }
|
//
|
// }
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// }
|
}
|
|
/**
|
* 其他 ===>> LED显示器复位,显示默认信息
|
*/
|
public void ledReset() {
|
// try {
|
// 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.isLoading()) {
|
// reset = false;
|
// break;
|
// }
|
// }
|
// // 获取led线程
|
// LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
|
// // led显示默认内容
|
// if (reset) {
|
// 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());
|
// }
|
// }
|
// }
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// }
|
}
|
|
/**
|
* 四向穿梭车电量检测 ===>> 发起充电
|
*/
|
public synchronized void loopShuttleCharge() {
|
try {
|
for (ShuttleSlave shuttle : slaveProperties.getShuttle()) {
|
//获取四向穿梭车线程
|
ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId());
|
ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
|
if (shuttleProtocol == null) {
|
continue;
|
}
|
|
//判断当前小车是否满足需要充电要求
|
if (!shuttleThread.isRequireCharge()) {
|
continue;
|
}
|
|
WrkMast wrkMast = wrkMastService.selectChargeWorking(shuttleProtocol.getShuttleNo());
|
if (wrkMast != null) {//已有充电任务
|
continue;
|
}
|
|
//小车所在楼层
|
int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());
|
ShuttleChargeType shuttleCharge = null;
|
|
//搜索小车所在楼层有没有充电桩
|
for (ShuttleChargeType chargeType : ShuttleChargeType.values()) {
|
if (lev != Utils.getLev(chargeType.locNo)) {
|
continue;//小车和充电桩不在同一层
|
}
|
|
//小车和充电桩在同一层
|
if (wrkMastService.selectChargeWorkingByChargeSta(chargeType.id) == null) {
|
shuttleCharge = chargeType;
|
break;
|
}
|
}
|
|
if (shuttleCharge == null) {
|
//同楼层没有找到充电桩,找可用充电桩
|
//小车同楼层没有充电桩,只要充电桩可用就生成充电任务
|
for (ShuttleChargeType chargeType : ShuttleChargeType.values()) {
|
if (wrkMastService.selectChargeWorkingByChargeSta(chargeType.id) == null) {
|
//判断当前充电桩楼层是否有小车,如有小车,不分配该充电桩
|
int chargeLev = Utils.getLev(chargeType.locNo);//充电桩楼层
|
boolean checkLevHasShuttle = Utils.checkLevHasShuttle(chargeLev);//检测楼层是否有穿梭车
|
if (checkLevHasShuttle) {
|
//当前充电桩楼层有穿梭车,不分配该充电桩
|
continue;
|
}
|
|
shuttleCharge = chargeType;
|
break;
|
}
|
}
|
}
|
|
if (shuttleCharge == null) {
|
continue;
|
}
|
|
String chargeLocNo = shuttleCharge.locNo;
|
wrkMast = new WrkMast();
|
wrkMast.setMk(String.valueOf(shuttleCharge.id));
|
wrkMast.setWrkNo(commonService.getWorkNo(WrkIoType.SHUTTLE_CHARGE.id));
|
wrkMast.setWrkSts(WrkStsType.NEW_CHARGE.sts);
|
wrkMast.setIoType(WrkIoType.SHUTTLE_CHARGE.id);//300.充电
|
wrkMast.setIoPri((double) 999);
|
wrkMast.setLocNo(chargeLocNo);
|
wrkMast.setShuttleNo(shuttle.getId());
|
wrkMast.setMemo("charge");
|
wrkMast.setAppeTime(new Date());
|
if (!wrkMastService.insert(wrkMast)) {
|
News.error("保存{}号四向穿梭车充电任务失败!!!", shuttle.getId());
|
continue;
|
}
|
|
News.info("保存{}号四向穿梭车充电任务成功!!!", shuttle.getId());
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 执行四向穿梭车充电任务
|
*/
|
public synchronized void executeShuttleCharge() {
|
try {
|
//查询小车移库任务
|
for (ShuttleSlave shuttle : slaveProperties.getShuttle()) {
|
WrkMast wrkMast = wrkMastService.selectChargeWorking(shuttle.getId());
|
if(wrkMast == null) {
|
continue;
|
}
|
|
boolean result1 = this.executeShuttleChargeStepGoToChargeSta(wrkMast);//小车等待充电桩
|
if (!result1) {
|
continue;
|
}
|
|
boolean result2 = this.executeShuttleChargeStepArrivalChargeSta(wrkMast);//小车到达充电桩
|
if (!result2) {
|
continue;
|
}
|
|
boolean result3 = this.executeShuttleChargeStepStartCharge(wrkMast);//小车开始充电
|
if (!result3) {
|
continue;
|
}
|
|
boolean result4 = this.executeShuttleChargeStepStopCharge(wrkMast);//小车停止充电
|
if (!result4) {
|
continue;
|
}
|
|
boolean result5 = this.executeShuttleChargeStepLeaveCharge(wrkMast);//小车离开充电桩
|
if (!result5) {
|
continue;
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 小车前往充电桩
|
*/
|
private synchronized boolean executeShuttleChargeStepGoToChargeSta(WrkMast wrkMast) {
|
if (wrkMast.getWrkSts() == WrkStsType.NEW_CHARGE.sts) {
|
ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
|
if (shuttleThread == null) {
|
return false;
|
}
|
ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
|
if (shuttleProtocol == null) {
|
return false;
|
}
|
|
if (shuttleProtocol.getCurrentLocNo().equals(wrkMast.getLocNo())) {
|
//小车在充电桩位置
|
wrkMast.setWrkSts(WrkStsType.CHARGE_SHUTTLE_RUN_COMPLETE.sts);
|
wrkMast.setModiTime(new Date());
|
wrkMastService.updateById(wrkMast);
|
return false;
|
}
|
|
//调度小车去充电桩
|
boolean dispatched = shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getLocNo(), wrkMast.getShuttleNo());
|
if (!dispatched) {
|
return false;
|
}
|
|
wrkMast.setWrkSts(WrkStsType.CHARGE_SHUTTLE_RUN.sts);//小车前往充电桩
|
wrkMast.setModiTime(new Date());
|
wrkMastService.updateById(wrkMast);
|
return false;
|
}
|
return true;
|
}
|
|
/**
|
* 小车到达充电桩
|
*/
|
private synchronized boolean executeShuttleChargeStepArrivalChargeSta(WrkMast wrkMast) {
|
if (wrkMast.getWrkSts() == WrkStsType.CHARGE_SHUTTLE_RUN.sts) {
|
ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
|
if (shuttleThread == null) {
|
return false;
|
}
|
ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
|
if (shuttleProtocol == null) {
|
return false;
|
}
|
|
//判断是否存在未完成的移动任务
|
WrkMast moveWrk = wrkMastService.selectShuttleHasMoveWorking(wrkMast.getShuttleNo());
|
if(moveWrk != null) {
|
return false;
|
}
|
|
if (!shuttleProtocol.getCurrentLocNo().equals(wrkMast.getLocNo())) {
|
return false;
|
}
|
|
//小车在充电桩位置
|
wrkMast.setWrkSts(WrkStsType.CHARGE_SHUTTLE_RUN_COMPLETE.sts);//小车到达充电桩
|
wrkMast.setModiTime(new Date());
|
wrkMastService.updateById(wrkMast);
|
|
return false;
|
}
|
return true;
|
}
|
|
//小车开始充电
|
private synchronized boolean executeShuttleChargeStepStartCharge(WrkMast wrkMast) {
|
if (wrkMast.getWrkSts() == WrkStsType.CHARGE_SHUTTLE_RUN_COMPLETE.sts) {
|
ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
|
if (shuttleThread == null) {
|
return false;
|
}
|
ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
|
if (shuttleProtocol == null) {
|
return false;
|
}
|
|
//小车已经在充电桩位置,下发充电命令
|
ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
|
assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号
|
assignCommand.setTaskNo(wrkMast.getWrkNo());//任务号
|
assignCommand.setTaskMode(ShuttleTaskModeType.CHARGE.id);//出库模式
|
assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//源库位(小车当前位置)
|
|
List<ShuttleCommand> commands = shuttleOperaUtils.getShuttleChargeCommand(assignCommand, shuttleThread, true);
|
assignCommand.setCommands(commands);//运行命令
|
|
wrkMast.setWrkSts(WrkStsType.CHARGE_SHUTTLE_WORKING.sts);
|
wrkMast.setModiTime(new Date());
|
if (!wrkMastService.updateById(wrkMast)) {
|
return false;
|
}
|
|
//下发任务
|
shuttleAction.assignWork(shuttleProtocol.getShuttleNo(), assignCommand);
|
return false;
|
}
|
return true;
|
}
|
|
//小车停止充电
|
private synchronized boolean executeShuttleChargeStepStopCharge(WrkMast wrkMast) {
|
if (wrkMast.getWrkSts() == WrkStsType.CHARGE_SHUTTLE_WORKING.sts) {
|
ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
|
if (shuttleThread == null) {
|
return false;
|
}
|
ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
|
if (shuttleProtocol == null) {
|
return false;
|
}
|
|
if (!shuttleThread.isChargingCompleted()) {
|
return false;
|
}
|
|
//小车已经在充电桩位置,下发停止充电命令
|
ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
|
assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号
|
assignCommand.setTaskNo(wrkMast.getWrkNo());//任务号
|
assignCommand.setTaskMode(ShuttleTaskModeType.CHARGE.id);//出库模式
|
assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//源库位(小车当前位置)
|
|
List<ShuttleCommand> commands = shuttleOperaUtils.getShuttleChargeCommand(assignCommand, shuttleThread, false);
|
assignCommand.setCommands(commands);//运行命令
|
|
wrkMast.setWrkSts(WrkStsType.CHARGE_SHUTTLE_COMPLETE.sts);
|
wrkMast.setModiTime(new Date());
|
if (!wrkMastService.updateById(wrkMast)) {
|
return false;
|
}
|
|
//下发任务
|
shuttleAction.assignWork(shuttleProtocol.getShuttleNo(), assignCommand);
|
return false;
|
}
|
return true;
|
}
|
|
//小车离开充电桩
|
private synchronized boolean executeShuttleChargeStepLeaveCharge(WrkMast wrkMast) {
|
if (wrkMast.getWrkSts() == WrkStsType.CHARGE_SHUTTLE_COMPLETE.sts) {
|
ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
|
if (shuttleThread == null) {
|
return false;
|
}
|
ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
|
if (shuttleProtocol == null) {
|
return false;
|
}
|
|
ShuttleChargeType chargeType = ShuttleChargeType.get(wrkMast.getMk());
|
if(chargeType == null) {
|
return false;
|
}
|
|
wrkMast.setWrkSts(WrkStsType.CHARGE_SHUTTLE_COMPLETE.sts);
|
wrkMast.setModiTime(new Date());
|
if (wrkMastService.updateById(wrkMast)) {
|
//调度小车去待机位
|
boolean dispatched = shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), chargeType.waitLocNo, wrkMast.getShuttleNo());
|
if (!dispatched) {
|
return false;
|
}
|
return false;
|
}
|
|
return false;
|
}
|
return true;
|
}
|
|
/**
|
* 执行小车移库任务
|
*/
|
public synchronized void shuttleMoveExecute() {
|
try {
|
//查询小车移库任务
|
List<WrkMast> wrkMasts = wrkMastService.selectShuttleMoveWrk();
|
for (WrkMast wrkMast : wrkMasts) {
|
boolean stepMoveSta = this.shuttleMoveExecuteStepMoveSta(wrkMast);//小车移动到站点
|
if (!stepMoveSta) {
|
continue;
|
}
|
|
boolean stepLiftMove = this.shuttleMoveExecuteStepLiftMove(wrkMast);//提升机搬运中
|
if (!stepLiftMove) {
|
continue;
|
}
|
|
boolean stepMoveLoc = this.shuttleMoveExecuteStepMoveLoc(wrkMast);//小车移动到目标库位中
|
if (!stepMoveLoc) {
|
continue;
|
}
|
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 小车迁移-小车移动到站点
|
* 如需主方法执行continue,请返回false
|
* ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
|
*/
|
private boolean shuttleMoveExecuteStepMoveSta(WrkMast wrkMast) {
|
//--------------------------------------小车移动至站点-----------------------------------------//
|
Date now = new Date();
|
|
//小车移动至站点 301.生成小车移库任务 ==> 302.小车移动至站点中
|
if (wrkMast.getWrkSts() == WrkStsType.NEW_MOVE.sts) {
|
//获取四向穿梭车线程
|
ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
|
if (shuttleThread == null) {
|
return false;
|
}
|
ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
|
if (shuttleProtocol == null) {
|
return false;
|
}
|
|
//小车处于空闲状态
|
if (!shuttleThread.isIdle()) {
|
News.info("{}任务,{}小车,小车忙碌中", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
|
return false;
|
}
|
|
if (Utils.getLev(wrkMast.getLocNo()) == Utils.getLev(shuttleProtocol.getCurrentLocNo())) {
|
//目标库位和小车库位处于同一楼层,不需要通过提升机调度
|
wrkMast.setWrkSts(WrkStsType.MOVE_OUT_LIFT_COMPLETE.sts);// 309.小车迁出提升机完成 ==> 310.小车移动中
|
wrkMast.setModiTime(now);
|
if (wrkMastService.updateById(wrkMast)) {
|
//下发任务
|
return true;//直接进入309.小车迁出提升机完成 ==> 310.小车移动中
|
}
|
return false;
|
}
|
|
//获取源输送站
|
ForkLiftStaProtocol liftSta = ForkLiftUtils.getLiftStaByStaNo(wrkMast.getSourceStaNo());
|
if (liftSta == null) {
|
return false;//找不到站点
|
}
|
|
//判断提升机是否有其他任务(该任务需要换层必须提前独占提升机)
|
WrkMast liftWrkMast = wrkMastService.selectLiftWrkMast(liftSta.getLiftNo());
|
if (liftWrkMast != null) {
|
News.info("{}任务,{}号提升机,提升机存在未完成任务,禁止派发", wrkMast.getWrkNo(), liftSta.getLiftNo());
|
return false;//当前提升机存在未完成任务,等待下一次轮询
|
}
|
|
ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
|
assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); // 四向穿梭车编号
|
assignCommand.setTaskMode(ShuttleTaskModeType.MOVE_LOC_NO.id);//小车移库任务
|
assignCommand.setTaskNo(wrkMast.getWrkNo());//任务号
|
assignCommand.setAuto(true);//自动模式
|
|
//获取小车到输送站点行走命令
|
List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getCurrentLocNo(), liftSta.getLocNo(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
|
if (commands == null) {
|
News.info("{}任务,{}小车,路径计算失败", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
|
return false;//路径解锁失败
|
}
|
|
assignCommand.setCommands(commands);
|
|
//*************尝试锁定目标站路径***************
|
List<NavigateNode> targetNodes = ForkLiftUtils.getLiftStaNodes(wrkMast.getStaNo());
|
if (targetNodes == null) {
|
return false;//未获取到节点
|
}
|
boolean checkPathIsAvailable = navigateUtils.checkPathIsAvailable(targetNodes, shuttleProtocol.getShuttleNo(), Utils.getLev(wrkMast.getLocNo()));
|
if (!checkPathIsAvailable) {
|
News.info("{}任务,{}小车,目标站点路径被占用,禁止派发", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
|
return false;//检测目标站点路径是否未被占用
|
}
|
//尝试锁定目标站路径
|
boolean result2 = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(wrkMast.getLocNo()), shuttleProtocol.getShuttleNo(), targetNodes, true);//所使用的路径进行锁定禁用
|
if (!result2) {
|
News.info("{}任务,{}小车,路径锁定失败,禁止派发", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
|
return false;//路径锁定失败
|
}
|
//*************尝试锁定目标站路径***************
|
|
wrkMast.setWrkSts(WrkStsType.MOVE_SITE.sts);//小车移动到提升机中 301.生成小车移库任务 ==> 302.小车移动至站点
|
wrkMast.setModiTime(now);
|
wrkMast.setLiftNo(liftSta.getLiftNo());//提前锁定提升机
|
// shuttleProtocol.setToken(wrkMast.getWrkNo());//独占该小车令牌
|
if (wrkMastService.updateById(wrkMast)) {
|
//下发任务
|
shuttleAction.assignWork(shuttleProtocol.getShuttleNo(), assignCommand);
|
return false;
|
}
|
return false;
|
}
|
return true;
|
}
|
|
/**
|
* 小车迁移-提升机搬运中
|
* 如需主方法执行continue,请返回false
|
* ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
|
*/
|
private boolean shuttleMoveExecuteStepLiftMove(WrkMast wrkMast) {
|
//--------------------------------------提升机搬运中-----------------------------------------//
|
Date now = new Date();
|
|
//提升机搬运中 303.小车移动至站点完成 ==> 306.提升机搬运中
|
if (wrkMast.getWrkSts() == WrkStsType.MOVE_SITE_COMPLETE.sts) {
|
ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, wrkMast.getLiftNo());
|
if (forkLiftThread == null) {
|
return false;
|
}
|
ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus();
|
if (forkLiftProtocol == null) {
|
return false;
|
}
|
if (!forkLiftThread.isIdle()) {
|
News.info("{}任务,{}号提升机,提升机忙碌中,禁止派发", wrkMast.getWrkNo(), wrkMast.getLiftNo());
|
return false;
|
}
|
//判断提升机是否有其他任务
|
WrkMast liftWrkMast = wrkMastService.selectLiftWrkMast(wrkMast.getLiftNo());
|
if (liftWrkMast != null) {
|
if (!liftWrkMast.getWrkNo().equals(wrkMast.getWrkNo())) {//提升机任务和当前任务不相同
|
News.info("{}任务,{}号提升机,提升机存在未完成任务,禁止派发", wrkMast.getWrkNo(), wrkMast.getLiftNo());
|
return false;//当前提升机存在未完成任务,等待下一次轮询
|
}
|
}
|
|
//获取源站
|
ForkLiftStaProtocol sourceLiftSta = ForkLiftUtils.getLiftStaByStaNo(wrkMast.getSourceStaNo());
|
//获取目标站
|
ForkLiftStaProtocol liftSta = ForkLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
|
if (sourceLiftSta == null || liftSta == null) {
|
News.info("{}任务,缺少站点信息,禁止派发", wrkMast.getWrkNo());
|
return false;//缺少站点信息
|
}
|
|
|
//获取提升机命令
|
List<ForkLiftCommand> liftCommands = forkLiftThread.getShuttleSwitchCommand(wrkMast.getWrkNo(), sourceLiftSta.getLev(), liftSta.getLev());
|
ArrayList<ForkLiftCommand> commands = new ArrayList<>();
|
commands.addAll(liftCommands);
|
|
//提交到线程去工作
|
LiftAssignCommand assignCommand = new LiftAssignCommand();
|
assignCommand.setCommands(commands);
|
assignCommand.setLiftNo(wrkMast.getLiftNo().shortValue());
|
assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());
|
assignCommand.setTaskMode(ForkLiftTaskModeType.SHUTTLE_SWITCH.id.shortValue());
|
|
wrkMast.setWrkSts(WrkStsType.MOVE_LIFT_RUN.sts);//提升机搬运中 303.小车移动至站点完成 ==> 306.提升机搬运中
|
wrkMast.setModiTime(now);
|
if (wrkMastService.updateById(wrkMast)) {
|
//下发任务
|
forkLiftAction.assignWork(wrkMast.getLiftNo(), assignCommand);
|
}
|
}
|
return true;
|
}
|
|
/**
|
* 小车迁移-小车移动到目标库位中
|
* 如需主方法执行continue,请返回false
|
* ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
|
*/
|
private boolean shuttleMoveExecuteStepMoveLoc(WrkMast wrkMast) {
|
//--------------------------------------小车移动到目标库位中-----------------------------------------//
|
Date now = new Date();
|
|
//小车移动到目标库位中 309.小车迁出提升机完成 ==> 310.小车移动中
|
if (wrkMast.getWrkSts() == WrkStsType.MOVE_OUT_LIFT_COMPLETE.sts) {
|
|
//获取四向穿梭车线程
|
ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
|
if (shuttleThread == null) {
|
return false;
|
}
|
ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
|
if (shuttleProtocol == null) {
|
return false;
|
}
|
|
//小车处于空闲状态
|
if (!shuttleThread.isIdle()) {
|
News.info("{}任务,{}小车,小车忙碌中,禁止派发", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
|
return false;
|
}
|
|
//小车已经在目标库位,直接认定小车移动任务完成
|
if (shuttleProtocol.getCurrentLocNo().equals(wrkMast.getLocNo())) {
|
wrkMast.setWrkSts(WrkStsType.COMPLETE_MOVE.sts);//311.小车移动完成
|
wrkMast.setLiftNo(null);//释放提升机
|
wrkMast.setModiTime(now);
|
wrkMastService.updateById(wrkMast);
|
|
if (wrkMast.getWrkSts() == WrkStsType.COMPLETE_MOVE.sts) {
|
// 保存工作主档历史档
|
if (wrkMastLogMapper.save(wrkMast.getWrkNo()) <= 0) {
|
log.info("保存工作历史档[workNo={}]失败", wrkMast.getWrkNo());
|
}
|
// 删除工作主档
|
if (!wrkMastService.deleteById(wrkMast)) {
|
log.info("删除工作主档[workNo={}]失败", wrkMast.getWrkNo());
|
}
|
}
|
return false;
|
}
|
|
ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
|
assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); // 四向穿梭车编号
|
assignCommand.setTaskMode(ShuttleTaskModeType.MOVE_LOC_NO.id);//小车移库任务
|
assignCommand.setTaskNo(wrkMast.getWrkNo());//任务号
|
assignCommand.setAuto(true);//自动模式
|
assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//源库位
|
assignCommand.setLocNo(wrkMast.getLocNo());//目标库位
|
|
List<ShuttleCommand> commands = null;
|
//跨楼层移动任务
|
if (Utils.getLev(wrkMast.getSourceLocNo()) != Utils.getLev(wrkMast.getLocNo())) {
|
// //需要将前两个节点作为白名单节点传入
|
// //获取目标站
|
// LiftStaProtocol liftSta = NyLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
|
// if (liftSta == null) {
|
// return false;//找不到站点
|
// }
|
//
|
// List<NavigateNode> targetNodes = NyLiftUtils.getLiftStaNodes(liftSta.getStaNo());
|
// if (targetNodes == null) {
|
// return false;//未获取到节点
|
// }
|
//
|
// //设置计算节点的白名单
|
// ArrayList<int[]> whiteList = new ArrayList<>();//设置计算节点的白名单
|
// for (NavigateNode node : targetNodes) {
|
// whiteList.add(new int[]{node.getX(), node.getY()});
|
// }
|
// commands = shuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getCurrentLocNo(), wrkMast.getLocNo(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread, whiteList);
|
}else {
|
//获取小车到目标库位命令
|
commands = shuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getCurrentLocNo(), wrkMast.getLocNo(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
|
}
|
|
if (commands == null) {
|
return false;//路径计算失败
|
}
|
|
assignCommand.setCommands(commands);
|
|
// if (wrkMast.getLiftNo() != null) {
|
// LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo());
|
// if (liftThread == null) {
|
// return false;
|
// }
|
// LiftProtocol liftProtocol = liftThread.getLiftProtocol();
|
// if (liftProtocol == null) {
|
// return false;
|
// }
|
// if (liftProtocol.getToken().equals(shuttleProtocol.getShuttleNo())) {
|
// liftProtocol.setToken(0);//释放提升机令牌
|
// }
|
// }
|
|
wrkMast.setWrkSts(WrkStsType.MOVE_SHUTTLE.sts);//小车移动到目标库位中 309.小车迁出提升机完成 ==> 310.小车移动中
|
wrkMast.setLiftNo(null);//释放提升机
|
wrkMast.setModiTime(now);
|
|
if (wrkMastService.updateById(wrkMast)) {
|
//下发任务
|
shuttleAction.assignWork(shuttleProtocol.getShuttleNo(), assignCommand);
|
}
|
}
|
return true;
|
}
|
|
// //扫描设备PakMk标记是否超时
|
// public synchronized void scanDevicePakMk() {
|
// try {
|
// //扫描小车
|
// for (ShuttleSlave slave : slaveProperties.getShuttle()) {
|
// NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId());
|
// NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
|
// if (shuttleProtocol == null) {
|
// continue;
|
// }
|
//
|
// if ((System.currentTimeMillis() - shuttleProtocol.getSendTime() > (1000 * 60 * 5)) && shuttleProtocol.getPakMk()) {
|
// //设备超过5分钟还没复位标记
|
// shuttleProtocol.setPakMk(false);//复位标记
|
// }
|
// }
|
//
|
// //扫描提升机
|
// for (LiftSlave slave : slaveProperties.getLift()) {
|
// LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, slave.getId());
|
// LiftProtocol liftProtocol = liftThread.getLiftProtocol();
|
// if (liftProtocol == null) {
|
// continue;
|
// }
|
//
|
// if ((System.currentTimeMillis() - liftProtocol.getSendTime() > (1000 * 60 * 5)) && liftProtocol.getPakMk()) {
|
// //设备超过5分钟还没复位标记
|
// liftProtocol.setPakMk(false);//复位标记
|
// }
|
// }
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// }
|
//
|
// }
|
|
}
|