lxw
2022-12-21 108da8c66924e7fc4015a0598f79b606f7436ad5
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.AlarmDaoFactory;
import com.whyc.dto.Response;
import com.whyc.mapper.PwrdevAlarmHistoryMapper;
import com.whyc.mapper.PwrdevAlarmParamMapper;
import com.whyc.pojo.PwrdevAlarm;
import com.whyc.pojo.PwrdevAlarmHistory;
import com.whyc.pojo.PwrdevAlarmParam;
import com.whyc.util.ActionUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
 
@Service
public class PwrdevAlarmHistoryService {
    @Resource
    private PwrdevAlarmHistoryMapper mapper;
 
    @Resource
    private PwrdevAlarmParamMapper paramMapper;
 
    //查询所有的电源历史告警信息
    public Response getHistoryAllPage(PwrdevAlarmHistory pwrH){
        PageHelper.startPage(pwrH.getPage().getPageCurr(),pwrH.getPage().getPageSize());
        pwrH.setUsrId(ActionUtil.getUser().getUId().intValue());
        List<PwrdevAlarmHistory> list= mapper.getHistoryAllPage(pwrH);
        for (PwrdevAlarmHistory p:list) {
            p.setAlarmName(AlarmDaoFactory.getAllAlarmName(p.getAlmType()));
        }
        PageInfo pageInfo=new PageInfo(list);
        return  new Response<>().set(1,pageInfo);
    }
    //电源历史告警删除
    public Response delete(int num) {
        int flag=mapper.deleteById(num);
        return new Response().set(flag);
    }
    //电源历史告警删除批量
    @Transactional
    public Response deletepro(List<Integer> list) {
        int flag=0;
        for (Integer num:list) {
            flag=mapper.deleteById(num);
        }
        return  new Response().set(flag);
    }
    //查询所有的通讯电源历史告警信息
    public Response getHistoryAllPage2(PwrdevAlarmHistory pwrH) {
        PageHelper.startPage(pwrH.getPage().getPageCurr(),pwrH.getPage().getPageSize());
        pwrH.setUsrId(ActionUtil.getUser().getUId().intValue());
        List<PwrdevAlarmHistory> list= mapper.getHistoryAllPage2(pwrH);
        List<String> tableList = paramMapper.getParamList();
        //取第一条记录,即param表
        String alarmParamTableName = tableList.get(0);
        List<PwrdevAlarmParam>  paramList=paramMapper.searchAll(alarmParamTableName);
        for (PwrdevAlarmHistory p:list) {
            int almType = p.getAlmType();
            AtomicBoolean matchFlag = new AtomicBoolean(false);
            paramList.stream().forEach(param->{
                if(param.getAlarmId()  == almType ){
                    p.setAlarmName(param.getAlarmName());
                    matchFlag.set(true);
                    return;
                }
            });
            if(!matchFlag.get()){
                p.setAlarmName("未知告警类型");
            }
 
        }
        PageInfo pageInfo=new PageInfo(list);
        return  new Response<>().set(1,pageInfo);
    }
 
}