| New file |
| | |
| | | package com.zy.acs.conveyor.core.operation.handler; |
| | | |
| | | import com.zy.acs.common.utils.RedisSupport; |
| | | import com.zy.acs.conveyor.controller.vo.ApplyInDto; |
| | | import com.zy.acs.conveyor.controller.vo.ApplyInRepsonseDto; |
| | | import com.zy.acs.conveyor.core.constant.RedisConveyorConstant; |
| | | import com.zy.acs.conveyor.core.enums.ConveyorStateType; |
| | | 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.service.StationService; |
| | | import com.zy.acs.conveyor.entity.Job; |
| | | import com.zy.acs.conveyor.enums.WorkNoTypeType; |
| | | import com.zy.acs.conveyor.service.JobService; |
| | | import com.zy.acs.conveyor.service.WmsMainService; |
| | | import com.zy.acs.conveyor.service.WrkLastnoService; |
| | | import com.zy.acs.framework.common.Cools; |
| | | 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; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 入库 |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | public class AppleLocOperationHandler implements OperationHandler { |
| | | |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | |
| | | |
| | | @Autowired |
| | | private WrkLastnoService wrkLastnoService; |
| | | |
| | | @Autowired |
| | | private WmsMainService wmsMainService; |
| | | |
| | | @Autowired |
| | | private JobService jobService; |
| | | |
| | | |
| | | @Autowired |
| | | private StationService stationService; |
| | | |
| | | |
| | | private final RedisSupport redis = RedisSupport.defaultRedisSupport; |
| | | |
| | | |
| | | @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遍历 |
| | | Map<Integer, StaProtocol> stationMap = stationService.getStationMap(devp.getId()); |
| | | StaProtocol staProtocol = stationMap.get(inSta.getStaNo()); |
| | | if (staProtocol == null) { |
| | | continue; |
| | | } else { |
| | | staProtocol = staProtocol.clone(); |
| | | } |
| | | // 判断是否满足条件 |
| | | if (!staProtocol.isLoading()) { |
| | | continue; |
| | | } |
| | | if (staProtocol.getWorkNo() > 0 && staProtocol.isAutoing()) { |
| | | String barcode = staProtocol.getBarcode(); |
| | | if (Cools.isEmpty(barcode)) { |
| | | log.error("站点:{},未扫到码值:{}", staProtocol.getSiteId(), barcode); |
| | | return; |
| | | } |
| | | // 9991是空板,9992是满板 |
| | | if (staProtocol.getWorkNo() >= 9991 && staProtocol.getWorkNo() <= 9992) { |
| | | Job job = jobService.getJobByBarcode(barcode, ConveyorStateType.INBOUND.getStatus()); |
| | | // 申请入库 |
| | | if (job == null || (job != null && job.getJobSts() == ConveyorStateType.CLEARSIGNAL.getStatus())) { |
| | | ApplyInRepsonseDto locOfWms = wmsMainService.getLocOfWms(applyIn(barcode, inSta.getStaNo() + "", staProtocol)); |
| | | if (locOfWms != null) { |
| | | Integer workNo = getWorkNo(); |
| | | staProtocol.setWorkNo(workNo); |
| | | staProtocol.setStaNo(inSta.getTargetSta()); |
| | | redis.push(RedisConveyorConstant.CONVEYOR_TASK_FLAG, staProtocol); |
| | | if (jobService.insert(initJob(locOfWms, barcode, workNo, inSta.getTargetSta() + ""))) { |
| | | log.info("申请入库成功,条码:{},站点:{}", barcode, inSta.getStaNo()); |
| | | } |
| | | } else { |
| | | log.info("WMS未返回库位信息,条码:{},站点:{}", barcode, inSta.getStaNo()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } |
| | | } |
| | | |
| | | |
| | | private Job initJob(ApplyInRepsonseDto locOfWms, String barcode, Integer workNo, String staNo) { |
| | | Job job = new Job(); |
| | | job.setLoc(locOfWms.getLocNo()); |
| | | job.setTaskNo(locOfWms.getTaskNo()); |
| | | job.setBatchNo(locOfWms.getBatchNo()); |
| | | job.setBarcode(barcode); |
| | | job.setStaNo(staNo); |
| | | job.setJobNo(workNo); |
| | | job.setJobSts(ConveyorStateType.INBOUND.getStatus()); |
| | | job.setWmsTime(new Date()); |
| | | return job; |
| | | } |
| | | |
| | | private Integer getWorkNo() { |
| | | return wrkLastnoService.nextWorkNo(WorkNoTypeType.WORK_NO_TYPE.type); |
| | | } |
| | | |
| | | private ApplyInDto applyIn(String barcode, String staNo, StaProtocol staProtocol) { |
| | | ApplyInDto applyInDto = new ApplyInDto(); |
| | | applyInDto.setStaNo(staNo); |
| | | applyInDto.setBarcode(barcode); |
| | | applyInDto.setFull(staProtocol.getWorkNo() == 9992); |
| | | return applyInDto; |
| | | } |
| | | } |