package com.zy.asrs.service.impl;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.zy.asrs.entity.WrkMast;
|
import com.zy.asrs.mapper.*;
|
import com.zy.asrs.service.*;
|
import com.zy.common.service.CommonService;
|
import com.zy.common.utils.News;
|
import com.zy.core.cache.MessageQueue;
|
import com.zy.core.cache.SlaveConnection;
|
import com.zy.core.enums.SlaveType;
|
import com.zy.core.model.DevpSlave;
|
import com.zy.core.model.Task;
|
import com.zy.core.model.protocol.StaProtocol;
|
import com.zy.core.properties.SlaveProperties;
|
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 java.util.Date;
|
|
/**
|
* 立体仓库WCS系统主流程业务
|
* Created by vincent on 2020/8/6
|
*/
|
@Slf4j
|
@Service("mainService")
|
@Transactional
|
public class CtuMainServiceImpl {
|
|
public static final long COMMAND_TIMEOUT = 5 * 1000;
|
|
|
@Autowired
|
private SlaveProperties slaveProperties;
|
@Autowired
|
private WrkMastMapper wrkMastMapper;
|
|
@Autowired
|
private WrkMastService wrkMastService;
|
|
|
public Integer wrkNo = 10000;
|
|
/**
|
* 入库,从拣料站到入库站(CTU取货站)
|
*/
|
public synchronized void generateStoreWrkFile(Integer mark) {
|
// 根据输送线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 (!staProtocol.isLoading()) {
|
continue;
|
}
|
if (staProtocol.isAutoing() && staProtocol.isInEnable()
|
&& !staProtocol.isEmptyMk() && (staProtocol.getWorkNo() == 0 || staProtocol.getWorkNo() == 9999)
|
&& staProtocol.isPakMk()) {
|
WrkMast wrkMast = wrkMastMapper.selectByWrkNo(staProtocol.getWorkNo());
|
if (wrkMast.getWrkSts() == 106) {
|
//下发移动任务,并生成入库工作档
|
|
} else {
|
log.info("" + mark + " - " + staProtocol.getWorkNo() + " - 找不到对应的工作档");
|
}
|
}
|
}
|
}
|
}
|
|
/**
|
* 出库站到拣料站
|
*/
|
public synchronized void generateStoreWrkFile0(Integer mark) {
|
// 根据输送线plc遍历
|
for (DevpSlave devp : slaveProperties.getDevp()) {
|
// 遍历入库口
|
for (DevpSlave.Sta inSta : devp.getOutSta()) {
|
// 获取入库站信息
|
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 (!staProtocol.isLoading()) {
|
continue;
|
}
|
|
if (staProtocol.isAutoing() && staProtocol.isOutEnable()
|
&& !staProtocol.isEmptyMk() && (staProtocol.getWorkNo() == 0 || staProtocol.getWorkNo() == 9999)
|
&& staProtocol.isPakMk()) {
|
News.warnNoLog("" + mark + " - 0" + " - 开始执行");
|
// 判断重复工作档
|
WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("source_sta_no", staProtocol.getSiteId()).eq("wrk_sts", 105));
|
if (wrkMast == null) {
|
continue;
|
}
|
|
// 命令下发区 --------------------------------------------------------------------------
|
|
// 更新站点信息 且 下发plc命令
|
staProtocol.setWorkNo(wrkMast.getWrkNo());
|
staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
|
devpThread.setPakMk(staProtocol.getSiteId(), false);
|
boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
|
log.info("输送线下发3:{},{}", wrkMast.getWrkNo(), wrkMast.getStaNo());
|
if (result) {
|
// 更新工作主档
|
wrkMast.setWrkSts(106L);
|
wrkMast.setModiTime(new Date());
|
if (wrkMastMapper.updateById(wrkMast) == 0) {
|
News.error("" + mark + " - 1" + " - 更新工作档失败!!! [工作号:{}]", wrkMast.getWrkNo());
|
}
|
} else {
|
News.error("" + mark + " - 2" + " - 发布命令至输送线队列失败!!! [plc编号:{}]", devp.getId());
|
}
|
|
} else {
|
News.errorNoLog("" + mark + " - 6" + " - 站点信息不符合入库条件!!!" + " 自动信号:" + staProtocol.isLoading() + "、可入信号:" + staProtocol.isInEnable()
|
+ "、空板信号:" + staProtocol.isEmptyMk() + "、工作号:" + staProtocol.getWorkNo()
|
+ "、锁定标记" + staProtocol.isPakMk() + "、入库印记:" + staProtocol.getStamp());
|
}
|
}
|
}
|
}
|
|
}
|