elkers
2025-04-07 2dba8dbb14af4616eec876fd9af744651e8beeda
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/**
#                                                    __----~~~~~~~~~~~------___
#                                   .  .   ~~//====......          __--~ ~~
#                   -.            \_|//     |||\\  ~~~~~~::::... /~
#                ___-==_       _-~o~  \/    |||  \\            _/~~-
#        __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
#    _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
#  .~       .~       |   \\ -_    /  /-   /   ||      \   /
# /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
# |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
#          '         ~-|      /|    |-~\~~       __--~~
#                      |-~~-_/ |    |   ~\_   _-~            /\
#                           /  \     \__   \/~                \__
#                       _--~ _/ | .-~~____--~-/                  ~~==.
#                      ((->/~   '.|||' -_|    ~~-/ ,              . _||
#                                 -_     ~\      ~~---l__i__i__i--~~_/
#                                 _-~-__   ~)  \--______________--~~
#                               //.-~~~-~_--~- |-------~~~~~~~~
#                                      //.-~~~--\
#                  神兽保佑
#                  永无BUG!
*/
package com.nanjing.water.repository.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nanjing.water.common.PagerResult;
import com.nanjing.water.common.enums.EYesOrNo;
import com.nanjing.water.common.util.*;
import com.nanjing.water.entity.dto.*;
import com.nanjing.water.entity.enums.*;
import com.nanjing.water.entity.search.SearchAlarmHistory;
import com.nanjing.water.repository.BasicMapperImpl;
import com.nanjing.water.repository.mapper.AlarmHistoryMapper;
import com.nanjing.water.repository.po.AlarmHistoryPO;
import org.springframework.stereotype.Repository;
 
import java.util.List;
 
/**
 * 报警信息
 * @author lin.liu
 */
@Repository
public class AlarmHistoryMapperImpl extends BasicMapperImpl<AlarmHistoryPO, AlarmHistoryMapper> {
    AlarmHistoryMapperImpl(AlarmHistoryMapper mapper) {
        super(mapper);
    }
 
    @Override
    public PagerResult<AlarmHistoryPO> search(SearchBasicDTO request) {
        // 还原查询条件真实类型
        SearchAlarmHistory search = (SearchAlarmHistory)request;
        // 查询条件
        LambdaQueryWrapper<AlarmHistoryPO> queryWrapper = this.query();
        // 非逻辑删除
        queryWrapper.eq(AlarmHistoryPO::getIsDelete, EYesOrNo.NO.getValue());
        // 状态
        //queryWrapper.eq(NumericUtil.tryParseInt(search.getStatus()).compareTo(0) > 0, AlarmHistoryPO::getStatus, search.getStatus());
        // 状态列表
        //queryWrapper.in(ListUtil.isNotNullOrEmpty(search.getListStatus()), AlarmHistoryPO::getStatus, search.getListStatus());
 
        // 数据创建时间-起始
        queryWrapper.ge(NumericUtil.tryParseLong(search.getCreateTimeStart()).compareTo(0L) > 0, AlarmHistoryPO::getCreateTime, search.getCreateTimeStart());
        // 数据创建时间-截止
        queryWrapper.le(NumericUtil.tryParseLong(search.getCreateTimeEnd()).compareTo(0L) > 0, AlarmHistoryPO::getCreateTime, search.getCreateTimeEnd());
        // 关键字
        //if (StringUtil.isNotNullOrEmpty(search.getKeywords())) {
        //    queryWrapper.and(q ->
        //        q.like(AlarmHistoryPO::getName, search.getKeywords())
        //        .or().like(AlarmHistoryPO::getPhone, search.getKeywords())
        //    );
        //}
 
        // 排序处理
        if (ListUtil.isNotNullOrEmpty(search.getOrderBy())) {
            for (OrderByDTO item : search.getOrderBy()) {
                EOrderBy orderBy = EOrderBy.getByValue(item.getOrderBy());
                // 顺序排序
                if (item.getIsAsc()) {
                    switch (orderBy) {
                        // 主键
                        case ID:
                            queryWrapper.orderByAsc(AlarmHistoryPO::getId);
                            break;
                        // 数据创建时间
                        case CREATE_TIME:
                            queryWrapper.orderByAsc(AlarmHistoryPO::getCreateTime);
                            break;
                        // 最后更新时间
                        case UPDATE_TIME:
                            queryWrapper.orderByAsc(AlarmHistoryPO::getUpdateTime);
                            break;
                    }
                } else {
                    // 倒叙排序
                    switch (orderBy) {
                        // 主键
                        case ID:
                            queryWrapper.orderByDesc(AlarmHistoryPO::getId);
                            break;
                        // 数据创建时间
                        case CREATE_TIME:
                            queryWrapper.orderByDesc(AlarmHistoryPO::getCreateTime);
                            break;
                        // 最后更新时间
                        case UPDATE_TIME:
                            queryWrapper.orderByDesc(AlarmHistoryPO::getUpdateTime);
                            break;
                    }
                }
            }
        } else {
            queryWrapper.orderByDesc(AlarmHistoryPO::getId);
        }
        Page<AlarmHistoryPO> pageResult = super.selectPage(new Page<>(search.getPage(), search.getLimit()), queryWrapper);
        return new PagerResult<>(pageResult.getSize(), pageResult.getCurrent(), pageResult.getTotal(), pageResult.getRecords());
    }
 
    public Boolean add(AlarmHistoryPO item) {
        int rowCount = super.insert(item);
        return rowCount == 1;
    }
 
    public Boolean addNotIncrement(AlarmHistoryPO item) {
        int rowCount = super.insert(item);
        return rowCount == 1;
    }
 
    public AlarmHistoryPO getById(Long id) {
        return super.get(id);
    }
 
    public List<AlarmHistoryPO> getListById(List<Long> listId) {
        return super.getList(listId);
    }
 
 
    public List<AlarmHistoryPO> getListByTime(Long  beginTime,Long  endTime) {
        LambdaQueryWrapper<AlarmHistoryPO> queryWrapper = this.query();
        queryWrapper.between(AlarmHistoryPO::getLastTime,beginTime,endTime);
        return super.selectList(queryWrapper);
    }
    public AlarmHistoryPO getListByFacilityId(Long  facilityId,Integer  code) {
        LambdaQueryWrapper<AlarmHistoryPO> queryWrapper = this.query();
        queryWrapper.eq(AlarmHistoryPO::getFacilityId,facilityId);
        queryWrapper.eq(AlarmHistoryPO::getCode,code);
        queryWrapper.ne(AlarmHistoryPO::getIsConfirm,30);
        queryWrapper.ne(AlarmHistoryPO::getIsConfirm,200);
        return super.selectOne(queryWrapper);
    }
}