xuhy
2024-05-28 5470d21a35286abe41fafc25a7deaabefd7c55da
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
package com.stylefeng.guns.modular.system.service.impl;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.modular.system.dao.LocationMapper;
import com.stylefeng.guns.modular.system.dao.SiteMapper;
import com.stylefeng.guns.modular.system.model.Dispatch;
import com.stylefeng.guns.modular.system.model.Site;
import com.stylefeng.guns.modular.system.service.IDispatchService;
import com.stylefeng.guns.modular.system.service.ISiteService;
import com.stylefeng.guns.modular.system.util.GDMapElectricFenceUtil;
import com.stylefeng.guns.modular.system.warpper.SiteWarpper;
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;
 
    @Autowired
    private IDispatchService dispatchService;
 
 
 
 
 
 
    /**
     * 获取站点
     * @return
     * @throws Exception
     */
    @Override
    public List<SiteWarpper> querySite(Integer startSiteId, Integer uid) throws Exception {
        List<Map<String, Object>> sites = null;
        Integer companyId = null;
        Dispatch dispatch = dispatchService.selectById(uid);
        if(dispatch.getFranchiseeId() == null || dispatch.getFranchiseeId().compareTo(0) == 0){
            companyId = dispatch.getCompanyId();
        }else{
            companyId = dispatch.getFranchiseeId();
        }
        if(null == startSiteId){
            sites = siteMapper.querySite(null, companyId);
        }else{
            sites = siteMapper.querySite(startSiteId, companyId);
        }
        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;
    }
 
 
    /**
     * 根据站点id获取地点区域
     * @param siteId
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> queryLocation(Integer siteId) throws Exception {
        return locationMapper.queryLocation(siteId);
    }
 
 
 
    /**
     * 判断点是都在区域范围内
     * @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){//电子围栏
                List<String> list1 = gdMapElectricFenceUtil.monitorElectricFenc("", lonLat);
                return list1.size() > 0 ? true : false;
            }
        }
        return false;
    }
}