rk
2025-09-28 081b2afc94c32a1c5e735e2f6b971d9fe1ff9b4f
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
package com.doumee.service.business.impl;
 
import com.doumee.service.business.third.model.PageData;
import com.doumee.service.business.third.model.PageWrap;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.WarningRuleMapper;
import com.doumee.dao.business.model.WarningRule;
import com.doumee.service.business.WarningRuleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.List;
 
/**
 * 报警规则配置表Service实现
 * @author 江蹄蹄
 * @date 2025/09/28 09:01
 */
@Service
public class WarningRuleServiceImpl implements WarningRuleService {
 
    @Autowired
    private WarningRuleMapper warningRuleMapper;
 
    @Override
    public Integer create(WarningRule warningRule) {
        warningRuleMapper.insert(warningRule);
        return warningRule.getId();
    }
 
    @Override
    public void deleteById(Integer id) {
        warningRuleMapper.deleteById(id);
    }
 
    @Override
    public void delete(WarningRule warningRule) {
        UpdateWrapper<WarningRule> deleteWrapper = new UpdateWrapper<>(warningRule);
        warningRuleMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        warningRuleMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(WarningRule warningRule) {
        warningRuleMapper.updateById(warningRule);
    }
 
    @Override
    public void updateByIdInBatch(List<WarningRule> warningRules) {
        if (CollectionUtils.isEmpty(warningRules)) {
            return;
        }
        for (WarningRule warningRule: warningRules) {
            this.updateById(warningRule);
        }
    }
 
    @Override
    public WarningRule findById(Integer id) {
        return warningRuleMapper.selectById(id);
    }
 
    @Override
    public WarningRule findOne(WarningRule warningRule) {
        QueryWrapper<WarningRule> wrapper = new QueryWrapper<>(warningRule);
        return warningRuleMapper.selectOne(wrapper);
    }
 
    @Override
    public List<WarningRule> findList(WarningRule warningRule) {
        QueryWrapper<WarningRule> wrapper = new QueryWrapper<>(warningRule);
        return warningRuleMapper.selectList(wrapper);
    }
  
    @Override
    public PageData<WarningRule> findPage(PageWrap<WarningRule> pageWrap) {
        IPage<WarningRule> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        QueryWrapper<WarningRule> queryWrapper = new QueryWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        if (pageWrap.getModel().getId() != null) {
            queryWrapper.lambda().eq(WarningRule::getId, pageWrap.getModel().getId());
        }
        if (pageWrap.getModel().getCreator() != null) {
            queryWrapper.lambda().eq(WarningRule::getCreator, pageWrap.getModel().getCreator());
        }
        if (pageWrap.getModel().getCreateDate() != null) {
            queryWrapper.lambda().ge(WarningRule::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate()));
            queryWrapper.lambda().le(WarningRule::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate()));
        }
        if (pageWrap.getModel().getEditor() != null) {
            queryWrapper.lambda().eq(WarningRule::getEditor, pageWrap.getModel().getEditor());
        }
        if (pageWrap.getModel().getEditDate() != null) {
            queryWrapper.lambda().ge(WarningRule::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate()));
            queryWrapper.lambda().le(WarningRule::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate()));
        }
        if (pageWrap.getModel().getIsdeleted() != null) {
            queryWrapper.lambda().eq(WarningRule::getIsdeleted, pageWrap.getModel().getIsdeleted());
        }
        if (pageWrap.getModel().getInfo() != null) {
            queryWrapper.lambda().eq(WarningRule::getInfo, pageWrap.getModel().getInfo());
        }
        if (pageWrap.getModel().getMemberId() != null) {
            queryWrapper.lambda().eq(WarningRule::getMemberId, pageWrap.getModel().getMemberId());
        }
        if (pageWrap.getModel().getIntervalSec() != null) {
            queryWrapper.lambda().eq(WarningRule::getIntervalSec, pageWrap.getModel().getIntervalSec());
        }
        if (pageWrap.getModel().getSortnum() != null) {
            queryWrapper.lambda().eq(WarningRule::getSortnum, pageWrap.getModel().getSortnum());
        }
        if (pageWrap.getModel().getStatus() != null) {
            queryWrapper.lambda().eq(WarningRule::getStatus, pageWrap.getModel().getStatus());
        }
        if (pageWrap.getModel().getWarningId() != null) {
            queryWrapper.lambda().eq(WarningRule::getWarningId, pageWrap.getModel().getWarningId());
        }
        for(PageWrap.SortData sortData: pageWrap.getSorts()) {
            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
                queryWrapper.orderByDesc(sortData.getProperty());
            } else {
                queryWrapper.orderByAsc(sortData.getProperty());
            }
        }
        return PageData.from(warningRuleMapper.selectPage(page, queryWrapper));
    }
 
    @Override
    public long count(WarningRule warningRule) {
        QueryWrapper<WarningRule> wrapper = new QueryWrapper<>(warningRule);
        return warningRuleMapper.selectCount(wrapper);
    }
}