whyclxw
2025-02-17 1244252b672f0ef0e83ad0671c1150f538572f0b
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.mapper.LockAlarmMapper;
import com.whyc.mapper.LockInfMapper;
import com.whyc.pojo.db_area.LockInf;
import com.whyc.pojo.db_lock_alarm.LockAlarm;
import com.whyc.util.ActionUtil;
import com.whyc.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
 
@Service
public class LockAlarmService {
    @Autowired(required = false)
    private LockAlarmMapper mapper;
 
    @Autowired(required = false)
    private LockInfMapper linfMapper;
 
    @Autowired
    private AreaInfService areaInfService;
    //查询锁实时告警信息
    public Response getLockAlm(Integer areaId, String almIds,Integer confirmFlag,int pageNum,  int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper wrapper=new QueryWrapper();
        if(areaId!=null){
            List<Integer> areaList=new ArrayList();
            areaList.add(areaId);
            areaInfService.getAllAreaId(areaId,areaList);
            if(areaList!=null){
                QueryWrapper wrapper1=new QueryWrapper();
                wrapper1.in("area_id",areaList);
                List<LockInf> lockInfList=linfMapper.selectList(wrapper1);
                List<Integer> lockIdList = lockInfList.stream()
                        .map(LockInf::getLockId) // 提取id值
                        .collect(Collectors.toList()); // 转换为列表*/
                wrapper.in("lock_id",lockIdList);
            }
        }
        if(almIds!=null){
            String[] almId=almIds.split(",");
            wrapper.in("alm_id",almId);
        }
        if(confirmFlag!=null){
            wrapper.eq("alm_is_confirmed",confirmFlag);
        }
        List<LockAlarm> list=mapper.selectList(wrapper);
        for (LockAlarm alm:list) {
            LockInf linf=linfMapper.getlinfBylockId(alm.getLockId());
            alm.setLinf(linf);
        }
        PageInfo pageInfo=new PageInfo(list);
        return new Response().setII(1,list!=null,pageInfo,"查询锁实时告警信息");
    }
    //确认告警
    public Response confirmAlm(Integer num) {
        UpdateWrapper wrapper= new UpdateWrapper<LockAlarm>();
        wrapper.eq("num",num);
        wrapper.set("alm_is_confirmed",1);
        wrapper.set("alm_confirmed_time",new Date());
        mapper.update((LockAlarm) ActionUtil.objeNull,wrapper);
        return new Response().set(1,true,"确认告警成功!");
    }
    //取消告警
    public Response cancleAlm(Integer num) {
        UpdateWrapper wrapper= new UpdateWrapper<LockAlarm>();
        wrapper.eq("num",num);
        wrapper.set("alm_is_confirmed",0);
        wrapper.set("alm_confirmed_time", ThreadLocalUtil.parse("2000-01-01 00:00:00",1));
        mapper.update((LockAlarm) ActionUtil.objeNull,wrapper);
        return new Response().set(1,true,"取消告警成功!");
    }
 
    //删除告警
    public Response delAlm(Integer num) {
        UpdateWrapper wrapper= new UpdateWrapper<LockAlarm>();
        wrapper.eq("num",num);
        mapper.delete(wrapper);
        return new Response().set(1,true,"删除告警成功!");
    }
}