package com.zy.core.operation.handler; import com.core.common.Cools; import com.zy.asrs.controller.vo.ApplyInDto; import com.zy.asrs.controller.vo.ApplyInRepsonseDto; import com.zy.asrs.entity.Job; import com.zy.asrs.enums.WorkNoTypeType; import com.zy.asrs.service.JobService; import com.zy.asrs.service.WmsMainService; import com.zy.asrs.service.WrkLastnoService; import com.zy.core.cache.SlaveConnection; import com.zy.core.enums.ConveyorStateType; import com.zy.core.enums.SlaveType; import com.zy.core.model.DevpSlave; import com.zy.core.model.protocol.StaProtocol; import com.zy.core.operation.OperationHandler; import com.zy.core.properties.CtuOperationConfig; import com.zy.core.properties.SlaveProperties; import com.zy.core.thread.BarcodeThread; import com.zy.core.thread.SiemensDevpThread; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.interceptor.TransactionAspectSupport; import java.util.Date; /** * 入库 */ @Slf4j @Component public class AppleLocOperationHandler implements OperationHandler { @Autowired private SlaveProperties slaveProperties; @Autowired private WrkLastnoService wrkLastnoService; @Autowired private WmsMainService wmsMainService; @Autowired private JobService jobService; @Override public ConveyorStateType getType() { return ConveyorStateType.APPLYLOC; } @Override @Transactional(rollbackFor = Exception.class) public synchronized void execute(CtuOperationConfig config) { try { // 根据输送线plc遍历 for (DevpSlave devp : slaveProperties.getDevp()) { // 遍历入库口 for (DevpSlave.Sta inSta : devp.getInSta()) { // 根据输送线plc遍历 SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo()); BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, devp.getId()); if (staProtocol == null) { return; } else { staProtocol = staProtocol.clone(); } // 判断是否满足条件 if (!staProtocol.isLoading()) { return; } if (staProtocol.getWorkNo() > 0 && staProtocol.isAutoing()) { String barcode = barcodeThread.getBarcode(); if (Cools.isEmpty(barcode)) { log.info("未扫到码值:{}", barcode); return; } if (staProtocol.getWorkNo() >= 9991 && staProtocol.getWorkNo() <= 9992) { Job job = jobService.getJobByBarcode(barcode); if (job == null || (job != null && job.getJobSts() == 8)) { ApplyInDto applyInDto = new ApplyInDto(); applyInDto.setStaNo(inSta.getStaNo() + ""); applyInDto.setBarcode(barcode); applyInDto.setFull(staProtocol.getWorkNo() == 9992); ApplyInRepsonseDto locOfWms = wmsMainService.getLocOfWms(applyInDto); if (locOfWms != null) { job = new Job(); job.setLoc(locOfWms.getLocNo()); job.setTaskNo(locOfWms.getTaskNo()); job.setBatchNo(locOfWms.getBatchNo()); job.setBarcode(barcode); job.setStaNo(inSta.getTargetSta() + ""); job.setJobNo(wrkLastnoService.nextWorkNo(WorkNoTypeType.WORK_NO_TYPE.type)); job.setJobSts(4); job.setWmsTime(new Date()); jobService.insert(job); } else { log.info("WMS未返回库位信息,{}", applyInDto); } } } } } } } catch (Exception e) { e.printStackTrace(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } } }