package com.zy.asrs.wcs.rcs.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.zy.asrs.framework.common.R; import com.zy.asrs.framework.exception.CoolException; import com.zy.asrs.wcs.rcs.cache.SlaveConnection; import com.zy.asrs.wcs.rcs.entity.Device; import com.zy.asrs.wcs.rcs.entity.DeviceType; import com.zy.asrs.wcs.rcs.model.enums.SlaveType; import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol; import com.zy.asrs.wcs.rcs.service.DeviceService; import com.zy.asrs.wcs.rcs.service.DeviceTypeService; import com.zy.asrs.wcs.rcs.service.ShuttleService; import com.zy.asrs.wcs.rcs.thread.ShuttleThread; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; @Service("ShuttleService") public class ShuttleServiceImpl implements ShuttleService { @Autowired private DeviceService deviceService; @Autowired private DeviceTypeService deviceTypeService; @Override public List getShuttleStatusList(Long hostId) { DeviceType deviceType = deviceTypeService.getOne(new LambdaQueryWrapper() .eq(DeviceType::getHostId, hostId) .eq(DeviceType::getStatus, 1) .eq(DeviceType::getFlag, String.valueOf(SlaveType.Shuttle))); if (deviceType == null) { throw new CoolException("设备类型不存在"); } ArrayList data = new ArrayList<>(); List list = deviceService.list(new LambdaQueryWrapper() .eq(Device::getHostId, hostId) .eq(Device::getStatus, 1) .eq(Device::getDeviceType, deviceType.getId())); for (Device device : list) { ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue()); ShuttleProtocol status = shuttleThread.getStatus(); data.add(status); } return data; } }