package com.zy.iot.service.impl; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.Wrapper; import com.baomidou.mybatisplus.plugins.Page; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.core.common.Cools; import com.zy.iot.constant.IotConstants; import com.zy.iot.entity.IotPublishRecord; import com.zy.iot.mapper.IotPublishRecordMapper; import com.zy.iot.service.IotPublishRecordService; import org.springframework.stereotype.Service; import java.util.Arrays; import java.util.Collections; import java.util.List; @Service public class IotPublishRecordServiceImpl extends ServiceImpl implements IotPublishRecordService { @Override public IotPublishRecord findByInstructionId(String instructionId) { if (Cools.isEmpty(instructionId)) { return null; } return selectOne(new EntityWrapper().eq("instruction_id", instructionId)); } @Override public IotPublishRecord findLatestInboundInstruction(String containerId, String messageType) { if (Cools.isEmpty(containerId) || Cools.isEmpty(messageType)) { return null; } Wrapper wrapper = new EntityWrapper() .eq("direction", IotConstants.DIRECTION_INBOUND) .eq("message_type", messageType) .eq("container_id", containerId) .orderBy("message_creation_time", false) .orderBy("create_time", false); Page page = selectPage(new Page(1, 1), wrapper); if (page == null || page.getRecords() == null || page.getRecords().isEmpty()) { return null; } return page.getRecords().get(0); } @Override public List selectPendingPublishes(int limit) { if (limit <= 0) { return Collections.emptyList(); } Wrapper wrapper = new EntityWrapper() .in("publish_status", Arrays.asList(IotConstants.PUBLISH_STATUS_PENDING, IotConstants.PUBLISH_STATUS_FAILURE)) .isNotNull("publish_topic") .isNotNull("publish_payload") .orderBy("create_time", true) .orderBy("id", true); Page page = selectPage(new Page(1, limit), wrapper); if (page == null || page.getRecords() == null) { return Collections.emptyList(); } return page.getRecords(); } }