xuhy
20 小时以前 df7b409920210fa920f99516450001827db92ddc
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
package com.stylefeng.guns.modular.crossCity.server.impl;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.modular.crossCity.dao.LocationMapper;
import com.stylefeng.guns.modular.crossCity.dao.SiteMapper;
import com.stylefeng.guns.modular.crossCity.model.Site;
import com.stylefeng.guns.modular.crossCity.server.ISiteService;
import com.stylefeng.guns.modular.crossCity.warpper.SiteWarpper;
import com.stylefeng.guns.modular.system.util.ElectricFenceUtil;
import com.stylefeng.guns.modular.system.util.GDMapElectricFenceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.*;
 
 
@Service
public class SiteServiceImpl extends ServiceImpl<SiteMapper, Site> implements ISiteService {
 
    @Resource
    private SiteMapper siteMapper;
 
    @Resource
    private LocationMapper locationMapper;
 
    @Autowired
    private GDMapElectricFenceUtil gdMapElectricFenceUtil;
 
 
    /**
     * 获取站点
     * @return
     * @throws Exception
     */
    @Override
    public List<SiteWarpper> querySite(Integer startSiteId) throws Exception {
        List<Map<String, Object>> sites = null;
        if(null == startSiteId){
            sites = siteMapper.querySite(null);
        }else{
            sites = siteMapper.querySite(startSiteId);
        }
        Set<String> set = new HashSet<>();
        for(Map<String, Object> site : sites) {
            set.add(site.get("cityCode").toString());
        }
 
        List<SiteWarpper> list = new ArrayList<>();
        for(String c : set){
            SiteWarpper siteWarpper = new SiteWarpper();
            List<Object> data = new ArrayList<>();
            String name = "";
            String code = "";
            for(Map<String, Object> s : sites){
                if(c.equals(s.get("cityCode").toString())){
                    Map<String, Object> map = new HashMap<>();
                    map.put("id", s.get("id"));
                    map.put("name", s.get("name").toString());
                    name = s.get("cityName").toString();
                    code = s.get("cityCode").toString();
                    data.add(map);
                }
            }
            siteWarpper.setName(name);
            siteWarpper.setCode(code);
            siteWarpper.setSites(data);
            list.add(siteWarpper);
        }
        return list;
    }
 
 
    /**
     * 判断点是都在区域范围内
     * @param siteId
     * @param code
     * @param lonLat
     * @return
     * @throws Exception
     */
    @Override
    public boolean areaMonitoring(Integer siteId, Integer code, String lonLat) throws Exception {
        List<Map<String, Object>> list = this.queryLocation(siteId);
        String province = code.toString().substring(0, 2) + "0000";
        String city = code.toString().substring(0, 4) + "00";
        for(Map<String, Object> map : list){
            if(Integer.valueOf(map.get("type").toString()) == 1){//行政区域
                if(null != map.get("districtCode")){
                    if(code.toString().equals(map.get("districtCode").toString())){
                        return true;
                    }
                    continue;
                }
                if(null != map.get("cityCode")){
                    if(city.equals(map.get("cityCode").toString())){
                        return true;
                    }
                    continue;
                }
                if(null != map.get("provinceCode")){
                    if(province.equals(map.get("provinceCode").toString())){
                        return true;
                    }
                    continue;
                }
            }
            if(Integer.valueOf(map.get("type").toString()) == 2){//电子围栏
                String coordinate = map.get("coordinate").toString();
                return ElectricFenceUtil.monitorElectricFenc(coordinate, lonLat);
            }
        }
        return false;
    }
 
    /**
     * 根据站点id获取地点区域
     * @param siteId
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> queryLocation(Integer siteId) throws Exception {
        return locationMapper.queryLocation(siteId);
    }
}