package com.qianwen.smartman.modules.fms.service.impl; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Lists; import com.qianwen.core.log.exception.ServiceException; import com.qianwen.core.tool.utils.Func; import com.qianwen.smartman.common.cache.ParamCache; import com.qianwen.smartman.common.constant.CommonConstant; import com.qianwen.smartman.common.constant.FmsConstant; import com.qianwen.smartman.common.utils.MessageUtils; import com.qianwen.smartman.modules.cps.entity.Tray; import com.qianwen.smartman.modules.cps.entity.Workstation; import com.qianwen.smartman.modules.cps.entity.WorkstationWorkbench; import com.qianwen.smartman.modules.cps.enums.TrayEnum; import com.qianwen.smartman.modules.cps.enums.WorkTypeEnum; import com.qianwen.smartman.modules.cps.service.ITrayService; import com.qianwen.smartman.modules.cps.service.IWorkstationService; import com.qianwen.smartman.modules.cps.service.IWorkstationWorkbenchService; import com.qianwen.smartman.modules.fms.dto.ManualTrayDmpDTO; import com.qianwen.smartman.modules.fms.entity.FmsRealTimeTray; import com.qianwen.smartman.modules.fms.enums.PositionTypeEnum; import com.qianwen.smartman.modules.fms.enums.RealTimePartTypeEnum; import com.qianwen.smartman.modules.fms.enums.ScheStateEnum; import com.qianwen.smartman.modules.fms.forestClient.FmsForestClient; import com.qianwen.smartman.modules.fms.service.IFmsOrderService; import com.qianwen.smartman.modules.fms.service.IFmsRealTimeTrayService; import com.qianwen.smartman.modules.fms.service.IFmsScheduleService; import com.qianwen.smartman.modules.fms.util.FmsForestUtil; import com.qianwen.smartman.modules.fms.vo.ManualTrayVO; @Service /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/fms/service/impl/FmsScheduleServiceImpl.class */ public class FmsScheduleServiceImpl implements IFmsScheduleService { private final ITrayService trayService; private final IFmsRealTimeTrayService fmsRealTimeTrayService; private final IWorkstationWorkbenchService workstationWorkbenchService; private final IWorkstationService workstationService; private final IFmsOrderService fmsOrderService; private final FmsForestClient fmsForestClient; public FmsScheduleServiceImpl(final ITrayService trayService, final IFmsRealTimeTrayService fmsRealTimeTrayService, final IWorkstationWorkbenchService workstationWorkbenchService, final IWorkstationService workstationService, final IFmsOrderService fmsOrderService, final FmsForestClient fmsForestClient) { this.trayService = trayService; this.fmsRealTimeTrayService = fmsRealTimeTrayService; this.workstationWorkbenchService = workstationWorkbenchService; this.workstationService = workstationService; this.fmsOrderService = fmsOrderService; this.fmsForestClient = fmsForestClient; } @Override // org.springblade.modules.fms.service.IFmsScheduleService public Boolean check(ManualTrayVO manualTrayVO) { checkManual(); checkTrayStatus(manualTrayVO.getTrayCode()); FmsRealTimeTray fmsRealTimeTray = this.fmsRealTimeTrayService.getOne(Wrappers.lambdaQuery().eq(FmsRealTimeTray::getTrayCode, manualTrayVO.getTrayCode())); /* FmsRealTimeTray fmsRealTimeTray = (FmsRealTimeTray) this.fmsRealTimeTrayService.getOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getTrayCode(); }, manualTrayVO.getTrayCode()));*/ checkScheState(fmsRealTimeTray.getScheState()); checkTargetHasTray(manualTrayVO); if (PositionTypeEnum.DEVICE.getType().equals(manualTrayVO.getEndType())) { checkPartStatus(fmsRealTimeTray.getPartType(), manualTrayVO.getEndPosition()); } checkDeviceStatus(manualTrayVO.getStartType(), manualTrayVO.getStartPosition()); checkBoundWorkstation(manualTrayVO, fmsRealTimeTray); return true; } private void checkScheState(Integer scheState) { if (ScheStateEnum.WILL_GO.getType().equals(scheState)) { throw new ServiceException(MessageUtils.message("fms.schedule.sche.state.is.will.go", new Object[0])); } } private void checkManual() { String isAuto = ParamCache.getValue(FmsConstant.PARAM_KEY); if (Boolean.TRUE.toString().equals(isAuto)) { throw new ServiceException(MessageUtils.message("fms.schedule.only.manual.mode.can.drag", new Object[0])); } } private void checkTrayStatus(String trayCode) { Tray tray = this.trayService.getOne(Wrappers.lambdaQuery().eq(Tray::getCode, trayCode)); if (TrayEnum.StatusEnum.FREEZE.getStatus().equals(tray.getAvailability())) { throw new ServiceException(MessageUtils.message("fms.schedule.tray.is.freeze", new Object[0])); } } private void checkBoundWorkstation(ManualTrayVO manualTrayVO, FmsRealTimeTray fmsRealTimeTray) { if (PositionTypeEnum.LOCATION.getType().equals(manualTrayVO.getEndType()) || Func.isEmpty(fmsRealTimeTray.getOrderId())) { return; } List workstationIdList = this.fmsOrderService.listWorkstationByTrayCode(manualTrayVO.getTrayCode()); Set workstationIdSet = new HashSet<>(); workstationIdList.forEach(workstationIds -> { List strings = Func.toLongList(workstationIds); workstationIdSet.addAll(strings); }); List workstationCodeList = this.workstationService.listByIds(workstationIdSet).stream().map(Workstation::getCode).collect(Collectors.toList()); /* List workstationCodeList = (List) this.workstationService.listByIds(workstationIdSet).stream().map((v0) -> { return v0.getCode(); }).collect(Collectors.toList());*/ if (!workstationCodeList.contains(manualTrayVO.getEndPosition())) { throw new ServiceException(MessageUtils.message("fms.schedule.order.not.assign.to.this.position", new Object[0])); } } private void checkPartStatus(Integer partType, String endPosition) { if (Func.isEmpty(partType)) { return; } Workstation workstation = getWorkstation(endPosition); List canNotDragPartTypeList = Lists.newArrayList(new Integer[]{Integer.valueOf(RealTimePartTypeEnum.PROCESS_FINISH.getType()), Integer.valueOf(RealTimePartTypeEnum.NONCONFORMING_PRODUCTS.getType())}); if (canNotDragPartTypeList.contains(partType) && WorkTypeEnum.PROCESS.getCode().equals(workstation.getDeviceType())) { throw new ServiceException(MessageUtils.message("fms.schedule.part.type.status.is.process.finish", new Object[0])); } } private void checkTargetHasTray(ManualTrayVO manualTrayVO) { long count = this.fmsRealTimeTrayService.count(Wrappers.lambdaQuery() .eq(PositionTypeEnum.DEVICE.getType().equals(manualTrayVO.getEndType()), FmsRealTimeTray::getCurrentPosition, manualTrayVO.getEndPosition()) .eq(FmsRealTimeTray::getCurrentStation, manualTrayVO.getEndStation()) .eq(FmsRealTimeTray::getCurrentType, manualTrayVO.getEndType())); /* long count = this.fmsRealTimeTrayService.count((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq(PositionTypeEnum.DEVICE.getType().equals(manualTrayVO.getEndType()), (v0) -> { return v0.getCurrentPosition(); }, manualTrayVO.getEndPosition()).eq((v0) -> { return v0.getCurrentStation(); }, manualTrayVO.getEndStation())).eq((v0) -> { return v0.getCurrentType(); }, manualTrayVO.getEndType()));*/ if (count > CommonConstant.ZERO.intValue()) { throw new ServiceException(MessageUtils.message("fms.schedule.target.position.has.already.exists.tray", new Object[0])); } } private void checkDeviceStatus(Integer type, String position) { if (!PositionTypeEnum.DEVICE.getType().equals(type)) { return; } Workstation startPosition = getWorkstation(position); if (WorkTypeEnum.PROCESS.getCode().equals(startPosition.getDeviceType()) && isSingleWorkBench(startPosition.getId()).booleanValue()) { deviceIsInProcess(position); } } private Workstation getWorkstation(String workstationCode) { return this.workstationService.getOne(Wrappers.lambdaQuery().eq(Workstation::getCode, workstationCode)); } private Boolean isSingleWorkBench(Long workstationId) { long count = this.workstationWorkbenchService.count(Wrappers.lambdaQuery().eq(WorkstationWorkbench::getWorkstationId, workstationId)); /* long count = this.workstationWorkbenchService.count((Wrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getWorkstationId(); }, workstationId));*/ return Boolean.valueOf(count <= ((long) CommonConstant.ONE.intValue())); } private void deviceIsInProcess(String position) { long count = this.fmsRealTimeTrayService.count(Wrappers.lambdaQuery() .eq(FmsRealTimeTray::getCurrentPosition, position) .eq(FmsRealTimeTray::getCurrentType, PositionTypeEnum.DEVICE.getType()) .eq(FmsRealTimeTray::getPartType, Integer.valueOf(RealTimePartTypeEnum.IN_PROCESS.getType()))); /* long count = this.fmsRealTimeTrayService.count((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getCurrentPosition(); }, position)).eq((v0) -> { return v0.getCurrentType(); }, PositionTypeEnum.DEVICE.getType())).eq((v0) -> { return v0.getPartType(); }, Integer.valueOf(RealTimePartTypeEnum.IN_PROCESS.getType()))); */ if (count > CommonConstant.ZERO.intValue()) { throw new ServiceException(MessageUtils.message("fms.schedule.device.status.is.in.process.can.not.drag.in.or.out", new Object[0])); } } @Override // org.springblade.modules.fms.service.IFmsScheduleService public Boolean manualDrag(ManualTrayVO manualTrayVO) { check(manualTrayVO); ManualTrayDmpDTO manualTrayDmpDTO = ManualTrayDmpDTO.builder().TrayCode(manualTrayVO.getTrayCode()).StartPosition(manualTrayVO.getStartPosition()).StartStation(manualTrayVO.getStartStation()).EndPosition(manualTrayVO.getEndPosition()).EndStation(manualTrayVO.getEndStation()).ActionType(manualTrayVO.getActionType()).CurrentType(manualTrayVO.getEndType()).build(); try { String returnMessage = this.fmsForestClient.manual(manualTrayDmpDTO); FmsForestUtil.checkMessage(returnMessage, "手动拖拽"); return true; } catch (Exception e) { throw new ServiceException("手动拖拽异常"); } } }