| | |
| | | package com.zy.acs.conveyor.core.operation.handler; |
| | | |
| | | import com.zy.acs.conveyor.core.cache.MessageQueue; |
| | | import com.zy.acs.conveyor.core.cache.SlaveConnection; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.zy.acs.common.utils.News; |
| | | import com.zy.acs.common.utils.RedisSupport; |
| | | import com.zy.acs.conveyor.core.constant.RedisConveyorConstant; |
| | | import com.zy.acs.conveyor.core.enums.ConveyorStateType; |
| | | import com.zy.acs.conveyor.core.enums.SlaveType; |
| | | import com.zy.acs.conveyor.core.enums.TaskType; |
| | | import com.zy.acs.conveyor.core.model.Task; |
| | | import com.zy.acs.conveyor.core.model.protocol.StaProtocol; |
| | | import com.zy.acs.conveyor.core.model.SafeSignal; |
| | | import com.zy.acs.conveyor.core.model.StaProtocol; |
| | | import com.zy.acs.conveyor.core.operation.OperationHandler; |
| | | import com.zy.acs.conveyor.core.properties.CtuOperationConfig; |
| | | import com.zy.acs.conveyor.core.properties.DevpSlave; |
| | | import com.zy.acs.conveyor.core.properties.SlaveProperties; |
| | | import com.zy.acs.conveyor.core.thread.SiemensDevpThread; |
| | | import com.zy.acs.conveyor.core.service.StationService; |
| | | import com.zy.acs.conveyor.entity.Job; |
| | | import com.zy.acs.conveyor.service.CtuMainService; |
| | | import com.zy.acs.conveyor.service.JobService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | |
| | | |
| | | /** |
| | |
| | | private JobService jobService; |
| | | |
| | | |
| | | @Autowired |
| | | private StationService stationService; |
| | | |
| | | @Autowired |
| | | private CtuMainService ctuMainService; |
| | | |
| | | |
| | | private final RedisSupport redis = RedisSupport.defaultRedisSupport; |
| | | |
| | | |
| | | @Override |
| | | public ConveyorStateType getType() { |
| | | return ConveyorStateType.CLEARSIGNAL; |
| | |
| | | // 遍历等待ctu取货站 |
| | | for (DevpSlave.Sta takeSta : devp.getTakeSta()) { |
| | | // 根据输送线plc遍历 |
| | | SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); |
| | | StaProtocol staProtocol = devpThread.getStation().get(takeSta.getStaNo()); |
| | | Map<Integer, StaProtocol> stationMap = stationService.getStationMap(devp.getId()); |
| | | StaProtocol staProtocol = stationMap.get(takeSta.getStaNo()); |
| | | if (staProtocol == null) { |
| | | continue; |
| | | } else { |
| | |
| | | } |
| | | // 判断是否满足条件 |
| | | if (staProtocol.isLoading()) { |
| | | //News.error("{}:站点:{},有物", config.getMark(), staProtocol.getSiteId()); |
| | | continue; |
| | | } |
| | | if (staProtocol.getWorkNo() > 0 && staProtocol.isAutoing()) { |
| | | if (!staProtocol.isAutoing()) { |
| | | //News.error("{}:站点:{},非自动", config.getMark(), staProtocol.getSiteId()); |
| | | continue; |
| | | } |
| | | if (staProtocol.getWorkNo() > 0 && !staProtocol.isLoading()) { |
| | | Job job = jobService.getJobByJobNo(staProtocol.getWorkNo()); |
| | | if (job != null && job.getJobSts() == ConveyorStateType.SENDTASK.getStatus()) { |
| | | //String s = ctuMainService.checkStationStatus(takeSta.getStaNo()); |
| | | staProtocol.setWorkNo(0); |
| | | staProtocol.setStaNo(0); |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, 1, new Task(TaskType.WRITE, staProtocol)); |
| | | if (result) { |
| | | log.info("" + config.getMark() + "站点清空失败:{},{}", takeSta.getStaNo(), staProtocol.getWorkNo()); |
| | | job.setJobSts(ConveyorStateType.CLEARSIGNAL.getStatus()); |
| | | jobService.updateById(job); |
| | | if (job == null) { |
| | | News.error("{}:站点:{},找不到任务", config.getMark(), staProtocol.getSiteId()); |
| | | continue; |
| | | } |
| | | if (job.getJobSts() != ConveyorStateType.SENDTASK.getStatus()) { |
| | | if (job.getJobSts() == ConveyorStateType.CLEARSIGNAL.getStatus()) { |
| | | continue; |
| | | } |
| | | News.error("{}:站点:{},任务状态不对,{}", config.getMark(), staProtocol.getSiteId(), JSON.toJSON(job)); |
| | | continue; |
| | | } |
| | | if (ctuMainService.checkComplete(job.getTaskNo())) { |
| | | staProtocol.setSafeSignal(new SafeSignal(devp.getPutSta().indexOf(takeSta), (short) 1, false)); |
| | | redis.push(RedisConveyorConstant.CONVEYOR_SAFE_FLAG, staProtocol); |
| | | job.setUpdateTime(new Date()); |
| | | job.setJobSts(ConveyorStateType.CLEARSIGNAL.getStatus()); |
| | | if (!jobService.updateById(job)) { |
| | | log.info("" + config.getMark() + "站点清空失败:{},{}", takeSta.getStaNo(), staProtocol.getWorkNo()); |
| | | } else { |
| | | News.info("" + config.getMark() + "站点清空:{},{}", takeSta.getStaNo(), staProtocol.getWorkNo()); |
| | | } |
| | | } else { |
| | | log.info("" + config.getMark() + "站点:{},{}", takeSta.getStaNo(), staProtocol.getWorkNo()); |
| | | } |
| | | } |
| | | } |