自动化立体仓库 - WMS系统
zwl
2 天以前 909cc78ba290cefc3c4623eff234e85ca0140e6d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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<IotPublishRecordMapper, IotPublishRecord> implements IotPublishRecordService {
 
    @Override
    public IotPublishRecord findByInstructionId(String instructionId) {
        if (Cools.isEmpty(instructionId)) {
            return null;
        }
        return selectOne(new EntityWrapper<IotPublishRecord>().eq("instruction_id", instructionId));
    }
 
    @Override
    public IotPublishRecord findLatestInboundInstruction(String containerId, String messageType) {
        if (Cools.isEmpty(containerId) || Cools.isEmpty(messageType)) {
            return null;
        }
        Wrapper<IotPublishRecord> wrapper = new EntityWrapper<IotPublishRecord>()
                .eq("direction", IotConstants.DIRECTION_INBOUND)
                .eq("message_type", messageType)
                .eq("container_id", containerId)
                .orderBy("message_creation_time", false)
                .orderBy("create_time", false);
        Page<IotPublishRecord> page = selectPage(new Page<IotPublishRecord>(1, 1), wrapper);
        if (page == null || page.getRecords() == null || page.getRecords().isEmpty()) {
            return null;
        }
        return page.getRecords().get(0);
    }
 
    @Override
    public List<IotPublishRecord> selectPendingPublishes(int limit) {
        if (limit <= 0) {
            return Collections.emptyList();
        }
        Wrapper<IotPublishRecord> wrapper = new EntityWrapper<IotPublishRecord>()
                .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<IotPublishRecord> page = selectPage(new Page<IotPublishRecord>(1, limit), wrapper);
        if (page == null || page.getRecords() == null) {
            return Collections.emptyList();
        }
        return page.getRecords();
    }
}