| | |
| | | package com.zy.asrs.wcs.core.service.impl; |
| | | |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.wcs.core.entity.Task; |
| | | import com.zy.asrs.wcs.core.kernel.AnalyzeService; |
| | | import com.zy.asrs.wcs.core.model.enums.TaskStsType; |
| | | import com.zy.asrs.wcs.core.service.TaskService; |
| | | import com.zy.asrs.wcs.rcs.News; |
| | | import com.zy.asrs.wcs.core.entity.Motion; |
| | | import com.zy.asrs.wcs.core.service.MotionService; |
| | | import com.zy.asrs.wcs.rcs.cache.SlaveConnection; |
| | | import com.zy.asrs.wcs.rcs.model.enums.SlaveType; |
| | | import com.zy.asrs.wcs.rcs.model.protocol.StaProtocol; |
| | | import com.zy.asrs.wcs.rcs.thread.DevpThread; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 立体仓库WCS系统主流程业务 |
| | |
| | | @Transactional |
| | | public class MainServiceImpl { |
| | | |
| | | @Autowired |
| | | private TaskService taskService; |
| | | @Autowired |
| | | private AnalyzeService analyzeService; |
| | | @Autowired |
| | | private MotionService motionService; |
| | | |
| | | /** |
| | | * 组托 |
| | | * 入库站,根据条码扫描生成入库工作档,工作状态 2 |
| | | */ |
| | | public synchronized void generateInboundWrk() { |
| | | |
| | | } |
| | | |
| | | // 解析入库工作档 |
| | | public synchronized void analyzeInBoundTask() { |
| | | for (Task task : taskService.selectWaitAnalyzeInBoundTask()) { |
| | | // generate motion list |
| | | List<Motion> motionList = analyzeService.generateMotion(task); |
| | | if (motionList.isEmpty()) { |
| | | continue; |
| | | } |
| | | motionService.batchInsert(motionList, task.getUuid(), Integer.valueOf(task.getTaskNo())); |
| | | |
| | | // 更新工作主档 |
| | | task.setTaskSts(TaskStsType.ANALYZE_INBOUND.sts); // 工作状态 |
| | | task.setUpdateTime(new Date()); |
| | | if (!taskService.updateById(task)) { |
| | | News.error("更新工作档失败!!! [工作号:{}]", task.getTaskNo()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 出库 ====>> 同一时间一台穿梭车只能有一个出库任务 |
| | | */ |
| | | public synchronized void generateOutboundWrkMast() { |
| | | List<Task> tasks = taskService.selectPakOut(); |
| | | if (tasks.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | for (Task task : tasks) { |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, 1); |
| | | StaProtocol staProtocol = devpThread.getStation().get(Integer.parseInt(task.getOriginSite()));//源站 |
| | | StaProtocol staProtocol1 = devpThread.getStation().get(Integer.parseInt(task.getDestSite()));//目标站 |
| | | if (staProtocol == null || staProtocol1 == null) { |
| | | continue; |
| | | } else { |
| | | staProtocol = staProtocol.clone(); |
| | | staProtocol1 = staProtocol1.clone(); |
| | | } |
| | | |
| | | // // 查询站点详细信息 |
| | | // BasDevp staDetl = basDevpService.selectById(outSta.getStaNo()); |
| | | // if (staDetl == null) { |
| | | // log.error("出库 ===>> 站点在数据库不存在, 站点编号={}", outSta.getStaNo()); |
| | | // continue; |
| | | // } |
| | | // 判断堆垛机出库站状态 |
| | | if (staProtocol.isAutoing() && !staProtocol.isLoading() && staProtocol.getWorkNo() == 0 && staProtocol.isOutEnable()) { |
| | | |
| | | if (!(staProtocol1.isAutoing() && !staProtocol1.isLoading() && staProtocol1.getWorkNo() == 0 && staProtocol1.isOutEnable())) { |
| | | continue; |
| | | } |
| | | |
| | | // //同库位组校验 |
| | | // List<String> outerLoc = Utils.getGroupOuterLoc(wrkMast.getSourceLocNo()); |
| | | // List<LocMast> outerLocMasts = locMastService.selectNotEmptyLocNos(outerLoc); |
| | | // if (!outerLocMasts.isEmpty()) { |
| | | // News.info("{}任务,浅库位存在货物,系统等待中", wrkMast.getWrkNo()); |
| | | // continue;//浅库位存在未执行任务 |
| | | // } |
| | | |
| | | // generate motion list |
| | | List<Motion> motionList = analyzeService.generateMotion(task); |
| | | if (Cools.isEmpty(motionList)) { |
| | | log.error("出库 ===>> 暂时没有空闲小车, 任务号={}", task.getTaskNo()); |
| | | continue; |
| | | } |
| | | motionService.batchInsert(motionList, task.getUuid(), Integer.valueOf(task.getTaskNo())); |
| | | |
| | | // 更新工作主档 |
| | | task.setTaskSts(TaskStsType.ANALYZE_OUTBOUND.sts); // 工作状态 |
| | | task.setUpdateTime(new Date()); |
| | | if (!taskService.updateById(task)) { |
| | | News.error("更新工作档失败!!! [工作号:{}]", task.getTaskNo()); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 四向穿梭车电量检测 ===>> 发起充电 |
| | | */ |
| | | public synchronized void loopShuttleCharge() { |
| | | // ShuttleChargeType shuttleCharge = ShuttleChargeType.CHARGE_1; |
| | | // for (ShuttleSlave shuttle : slaveProperties.getShuttle()) { |
| | | // // 判断充电位是否被占用 |
| | | // if (wrkChargeService.hasShuttleInChargeLoc(shuttleCharge.locNo, shuttle.getId())) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // //获取四向穿梭车线程 |
| | | // ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId()); |
| | | // ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); |
| | | // if (shuttleProtocol == null) { |
| | | // continue; |
| | | // } |
| | | // if (motionService.selectCount(new EntityWrapper<Motion>() |
| | | // .eq("device_ctg", DeviceCtgType.SHUTTLE.val()) |
| | | // .eq("device", shuttle.getId()) |
| | | // .eq("motion_sts", MotionStsType.EXECUTING.val())) > 0) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // //判断当前小车是否满足需要充电要求 |
| | | // if (!shuttleProtocol.isRequireCharge()) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // WrkCharge wrkCharge = wrkChargeService.selectWorking(null); |
| | | // if (wrkCharge != null) {//已有充电任务 |
| | | // continue; |
| | | // } |
| | | // |
| | | // String chargeLocNo = shuttleCharge.locNo; |
| | | // wrkCharge = new WrkCharge(); |
| | | // wrkCharge.setShuttleNo(shuttle.getId()); |
| | | // wrkCharge.setCharge(shuttleCharge.id); |
| | | // wrkCharge.setWrkNo(commonService.getChargeWorkNo(4)); |
| | | // wrkCharge.setUuid(String.valueOf(snowflakeIdWorker.nextId())); |
| | | // wrkCharge.setWrkSts(WrkMastStsType.NEW_CHARGE.sts); // 充电任务 |
| | | // wrkCharge.setIoType(WrkIoTypeType.CHARGE.sts); |
| | | // wrkCharge.setIoPri((double) 10); |
| | | // wrkCharge.setLocNo(chargeLocNo); |
| | | // wrkCharge.setMemo("charge"); |
| | | // wrkCharge.setAppeTime(new Date()); |
| | | // |
| | | // // generate motion list |
| | | // List<Motion> motionList = analyzeService.generateChargeMotion(wrkCharge); |
| | | // if (Cools.isEmpty(motionList)) { |
| | | // News.error("保存{}号四向穿梭车充电任务失败!!!", shuttle.getId()); |
| | | // continue; |
| | | // } |
| | | // motionService.batchInsert(motionList, wrkCharge.getUuid(), wrkCharge.getWrkNo()); |
| | | // |
| | | // wrkCharge.setWrkSts(WrkMastStsType.ANALYZE_CHARGE.sts); |
| | | // |
| | | // if (!wrkChargeService.insert(wrkCharge)) { |
| | | // News.error("保存{}号四向穿梭车充电任务失败!!!", shuttle.getId()); |
| | | // continue; |
| | | // } |
| | | // |
| | | // News.info("保存{}号四向穿梭车充电任务成功!!!", shuttle.getId()); |
| | | // } |
| | | } |
| | | |
| | | /** |
| | | * 四向穿梭车电量检测 ===>> 满电后回到待机位 |
| | | */ |
| | | public synchronized void loopShuttleToStandbyCauseCharge() { |
| | | // ShuttleChargeType shuttleCharge = ShuttleChargeType.CHARGE_1; |
| | | // Integer enoughPower = 90; |
| | | // Config config = configService.selectOne(new EntityWrapper<Config>() |
| | | // .eq("code", "chargeMaxValue") |
| | | // .eq("status", 1)); |
| | | // if (config != null) { |
| | | // enoughPower = Integer.parseInt(config.getValue()); |
| | | // } |
| | | // |
| | | // for (ShuttleSlave shuttle : slaveProperties.getShuttle()) { |
| | | // //获取四向穿梭车线程 |
| | | // ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId()); |
| | | // ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); |
| | | // if (shuttleProtocol == null) { |
| | | // continue; |
| | | // } |
| | | // // 是否存在充电任务 |
| | | // WrkCharge wrkCharge = wrkChargeService.selectWorking(shuttle.getId()); |
| | | // if (wrkCharge == null) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // if (motionService.selectCount(new EntityWrapper<Motion>() |
| | | // .eq("device_ctg", DeviceCtgType.SHUTTLE.val()) |
| | | // .eq("device", shuttle.getId()) |
| | | // .eq("motion_sts", MotionStsType.EXECUTING.val())) > 0) { |
| | | // continue; |
| | | // } |
| | | // // 不处于充电中 |
| | | // if (!shuttleProtocol.getPlcOutputCharge()) { |
| | | // continue; |
| | | // } |
| | | // // 在充电位 |
| | | // if (!shuttleProtocol.getCurrentLocNo().equals(shuttleCharge.locNo)) { |
| | | // continue; |
| | | // } |
| | | // // 电量是否达到满电要求 |
| | | // if (shuttleProtocol.getBatteryPower$().intValue() < enoughPower) { |
| | | // continue; |
| | | // } |
| | | // // 已有迁移任务 |
| | | // if (wrkChargeService.selectMoveWorking(shuttle.getId()) != null) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // // 待机位 |
| | | // String standByLocNo = ShuttleTempLocType.query(shuttleProtocol.getShuttleNo().intValue(), 2, Utils.getLev(shuttleCharge.locNo)).locNo; |
| | | // |
| | | // shuttleDispatcher.generateShuttleChargeWrkComplete(shuttleProtocol.getShuttleNo().intValue(), standByLocNo); |
| | | // |
| | | // wrkCharge.setWrkSts(WrkMastStsType.COMPLETE_CHARGE.sts); |
| | | // wrkCharge.setIoTime(new Date()); |
| | | // wrkChargeMapper.updateById(wrkCharge); |
| | | // } |
| | | } |
| | | |
| | | } |