‘liusuyi’
2023-06-08 e5b23b9797083fbbbbe530ce76ffa3723bc3422f
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
package com.ruoyi.alarm.globalAlarm.service;
 
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.alarm.globalAlarm.domain.GlobalAlarmCondition;
import com.ruoyi.alarm.stealAlarm.domain.ArdAlarmStealelec;
import com.ruoyi.alarm.stealAlarm.mapper.ArdAlarmStealelecMapper;
import com.ruoyi.alarm.tubeAlarm.domain.ArdAlarmTube;
import com.ruoyi.alarm.tubeAlarm.mapper.ArdAlarmTubeMapper;
import com.ruoyi.alarm.tubeAlarm.service.IArdAlarmTubeService;
import com.ruoyi.alarmpoints.tube.domain.ArdTubes;
import com.ruoyi.alarmpoints.tube.domain.ArdTubesDetails;
import com.ruoyi.alarmpoints.tube.mapper.ArdTubesDetailsMapper;
import com.ruoyi.alarmpoints.tube.mapper.ArdTubesMapper;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.utils.tube.GeoPoint;
import com.ruoyi.utils.tube.TubeTools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
 
import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;
 
/**
 * @ClassName: globalAlarmServiceImpl
 * @Description:
 * @Author: Administrator
 * @Date: 2023年03月10日 11:03
 * @Version: 1.0
 **/
@Service
@Slf4j(topic = "mqtt")
public class GlobalAlarmServiceImpl implements IGlobalAlarmService {
    @Resource
    ArdAlarmStealelecMapper ardAlarmStealelecMapper;
    @Resource
    IArdAlarmTubeService ardAlarmTubeService;
    @Resource
    ArdTubesMapper ardTubesMapper;
    @Resource
    ArdTubesDetailsMapper ardTubesDetailsMapper;
    @Override
    public List<Object> selectAlarmLogs(GlobalAlarmCondition condition) {
        switch (condition.getCommand()) {
            case 1001:
                List<ArdAlarmStealelec> ardAlarmStealelecs = ardAlarmStealelecMapper.selectHistoryByCondition(condition);
                return new ArrayList<Object>(ardAlarmStealelecs);
            default:
                return null;
        }
    }
 
    @Override
    @Async("alarmExecutor")
    public void receiveAlarm(String topic,String message)
    {
        switch (topic)
        {
            case "tube":
                ArdAlarmTube ardAlarmTube = JSONObject.parseObject(message,ArdAlarmTube.class);
                ardAlarmTube.setId(UUID.randomUUID().toString().replace("-",""));
                ArdTubesDetails atd=new ArdTubesDetails();
                atd.setReelNumber(ardAlarmTube.getTubeId());
                List<ArdTubesDetails> ardTubesDetails = ardTubesDetailsMapper.selectArdTubesDetailsList(atd);
                if(ardTubesDetails.size()>0)
                {
                    String tubeId = ardTubesDetails.get(0).getTubeId();
                    ArdTubes ardTubes = ardTubesMapper.selectArdTubesById(tubeId);
                    ardAlarmTube.setTubeName(ardTubes.getName());
                    ardAlarmTube.setColor(ardTubes.getColor());
                    ardAlarmTube.setPipeDiameter(ardTubes.getPipeDiameter());
                    ardAlarmTube.setTubeType(ardTubes.getType());
                    GeoPoint geoPoint = TubeTools.CalculateCoordinates(ardTubesDetails, ardAlarmTube.getPosition());
                    if(StringUtils.isNotNull(geoPoint))
                    {
                        ardAlarmTube.setLongitude(geoPoint.getLongitude());
                        ardAlarmTube.setLatitude(geoPoint.getLatitude());
                        ardAlarmTube.setAltitude(geoPoint.getAltitude());
                    }
                }
                int i = ardAlarmTubeService.insertArdAlarmTube(ardAlarmTube);
                if(i>0)
                {
                    log.info("入库成功:"+ardAlarmTube.toString());
                }
                break;
        }
    }
}