zhitong.yu
2024-06-19 890cb68586fe79d95b37ee0ad78df0d9f7dce796
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
package com.hxzk.controller;
 
import cn.hutool.json.JSONObject;
import com.github.pagehelper.PageInfo;
import com.hxzk.pojo.TbFence;
import com.hxzk.pojo.TbMap;
import com.hxzk.pojo.TbSystemOperationLog;
import com.hxzk.pojo.TbTag;
import com.hxzk.service.DiTuService;
import com.hxzk.service.FenceService;
import com.hxzk.service.SystemLogService;
import com.hxzk.service.TagService;
import com.hxzk.udp.Udp_Out;
import com.hxzk.util.result;
import com.hxzk.util.resultutil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
 
import javax.print.DocFlavor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
@RestController
@RequestMapping("/")
public class FenceController {
    @Autowired
    FenceService fenceService;
 
    @Autowired
    DiTuService diTuService;
 
    @Autowired
    SystemLogService systemLogService;
 
 
    //查询所有围栏设备信息
    @GetMapping("findfence")
    result<List<TbFence>> findfence(Integer page, Integer limit){
        PageInfo<TbFence> cz= fenceService.findAll(page, limit);
        return resultutil.returnSuccess(cz.getTotal(), cz.getList());
    }
 
    @GetMapping("findfenceSearch")
    result<List<TbFence>>  findfenceSearch(Integer page, Integer limit,TbFence fence){
        PageInfo<TbFence> cz= fenceService.findfenceSearch(page, limit,fence);
        return resultutil.returnSuccess(cz.getTotal(), cz.getList());
    }
    //删除围栏
    @GetMapping("deletewl")
    public void deletewl(String name){
        String xieyi = "BSTOCS1,DELETEFENCE," + name + ",END";
        TbSystemOperationLog systemOperationLog = new TbSystemOperationLog();
        systemOperationLog.setName(UserController.username);
        systemOperationLog.setTime(gettime());
        systemOperationLog.setContent("删除了一个围栏,该围栏为:"+name);
        systemLogService.insertSystem(systemOperationLog);
        Udp_Out.udp_to_cs(xieyi);
    }
    //新增围栏
    @PostMapping("addbaidufence")
    public String addbaidufence(HttpServletRequest request){
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String formattedDateTime = now.format(formatter);
        String layer = request.getParameter("layer");
        String weilanleixing = request.getParameter("weilanleixing");
        String guanlianduixiang = request.getParameter("guanlianduixiang");
        String quyumingcheng = request.getParameter("quyumingcheng");
        String xingzhuang = request.getParameter("xingzhuang");
        String yanse = request.getParameter("yanse");
        String zuobiao = request.getParameter("zuobiao");
        String sd = "";
        String s= "";
        String apo = "";
        String[] parts = new String[0];
        if (layer.equals("百度地图")){
            s = zuobiao.replaceAll("\\,", "\\:");
            String[] pos = s.split(";");
            for (int p = 0; p < pos.length;p++){
                String[] pos1 = pos[p].split(":");
                for (int h = 0 ; h < pos1.length;h++){
                    if (h==1){
                        sd+= bd09ToWGS841(Double.parseDouble(pos1[0]),Double.parseDouble(pos1[1]))+";";
                    }
                }
            }
        }else{
             parts = zuobiao.split(",");
            if (xingzhuang.equals("矩形")){
                for (int i = 0 ; i < parts.length-2; i++){
 
                    if (i == 0){
                        apo += parts[i]+":"+parts[i+1]+";";
                    }else{
                        apo += parts[i+1]+":"+parts[i+2]+";";
                    }
 
                }
            }else{
                for (int i = 0 ; i < parts.length; i++){
                    if (i == 0){
                        apo+=parts[i]+":";
                    }else if (i == 1){
                        apo+=parts[i]+";";
                    }else{
                        if (i%2 == 0){
                            apo+=parts[i]+":";
                        }else{
                            apo+= parts[i]+";";
                        }
                    }
 
                }
            }
        }
//        for (int i = 0 ; i < parts.length;i++){
//            String[] parts1 = parts[i].split(":");
//            String ac = bd09ToWGS84(Double.parseDouble(parts1[0]),Double.parseDouble(parts1[1]));
//            String ac1 = ac+";";
//            sd = sd+ac1;
//        }
 
 
        String shengxiao = "00:00:00";
        String shixiao = "23:59:59";
        String xieyi = "";
        if (layer.equals("百度地图")){
             xieyi = "BSTOCS1,ADDFENCE," + layer + ","+weilanleixing+","+guanlianduixiang+","+quyumingcheng+","+s+","+xingzhuang+","+shengxiao+","+shixiao+","+formattedDateTime+","+yanse+",-1,END";
 
        }else{
             xieyi = "BSTOCS1,ADDFENCE," + layer + ","+weilanleixing+","+guanlianduixiang+","+quyumingcheng+","+apo+","+xingzhuang+","+shengxiao+","+shixiao+","+formattedDateTime+","+yanse+",-1,END";
        }
        Udp_Out.udp_to_cs(xieyi);
        String xieyi1 = "BSTOCS1,ADDTJAREA,"+quyumingcheng+","+yanse+","+s+",系统默认,END";
        Udp_Out.udp_to_cs(xieyi1);
        TbSystemOperationLog systemOperationLog = new TbSystemOperationLog();
        systemOperationLog.setName(UserController.username);
        systemOperationLog.setTime(gettime());
        systemOperationLog.setContent("添加了一个围栏,该围栏为:"+quyumingcheng);
        systemLogService.insertSystem(systemOperationLog);
        return "success";
    }
 
 
    //修改围栏
//    @PostMapping("upWeiLan")
//    public void upWeiLan(TbFence fence, HttpServletResponse response) throws IOException {
//        LocalDateTime now = LocalDateTime.now();
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//        String formattedDateTime = now.format(formatter);
//        String yanse = "红色";
//        String xingzhuang = "多边形";
//        String shengxiao = "00:00:00";
//        String shixiao = "23:59:59";
//        String xieyi = "BSTOCS1,DELETEWL," + fence.getFloor() + ","+fence.getType()+","+fence.getBumen()+","+fence.getName()+","+fence.getZuobiao()+","+xingzhuang+","+shengxiao+","+shixiao+","+formattedDateTime+","+yanse+",END";
//        Udp_Out.udp_to_cs(xieyi);
//        TbSystemOperationLog systemOperationLog = new TbSystemOperationLog();
//        systemOperationLog.setName(UserController.username);
//        systemOperationLog.setTime(gettime());
//        systemOperationLog.setContent("修改了一个围栏,该围栏为:"+fence.getName());
//        response.sendRedirect("/hxzkuwb/HouTai/WeiLanList/WeiLanList.jsp");
//    }
 
 
    //旧
    @PostMapping("getFloorFence")
    List<TbFence> getFloorFence(HttpServletRequest request){
        String floor_number = request.getParameter("value");
        List<TbFence> fenceList = this.fenceService.getFence(floor_number);
        List<TbFence> fenceList2 = new ArrayList();
        for(int i = 0; i < fenceList.size(); ++i) {
            if (!((TbFence)fenceList.get(i)).getType().equals("变电站")) {
                fenceList2.add(fenceList.get(i));
            }
        }
        return fenceList;
    }
 
    @RequestMapping(value = {"/getFloorFence_all.do"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public List<TbFence> getFloorFence_all(HttpServletRequest request) {
        List<TbFence> fenceList = fenceService.getFence_all();
        for (int i = 0 ; i <fenceList.size();i++){
            String str = fenceList.get(i).getZuobiao();
            String replacedStr = str.replace(";", ",");
            fenceList.get(i).setZuobiao(replacedStr);
 
        }
        return fenceList;
    }
 
    @GetMapping("findFenceType")
    public List<TbFence> findFenceType(){
        return fenceService.findFenceType();
    }
 
    @GetMapping("FenceKaiQi")
    public void fenceKai(TbFence fence){
        String xieyi = "BSTOCS1,FENCE,OPEN," +fence.getName()+",END";
 
        Udp_Out.udp_to_cs(xieyi);
    }
    @GetMapping("FenceGuanBi")
    public void fenceGuan(TbFence fence){
        String xieyi = "BSTOCS1,FENCE,CLOSE," +fence.getName()+",END";
        System.out.println();
        Udp_Out.udp_to_cs(xieyi);
    }
 
    @PostMapping("upWeiLanTiShiYu")
    public void upWeiLanTiShiYu(TbFence fence,HttpServletResponse response) throws IOException {
        fenceService.upWeiLanTiShiYu(fence);
        response.sendRedirect("/hxzkuwb/HouTai/WeiLanList/WeiLanList.jsp");
    }
 
 
    public String gettime(){
        Date now = new Date();
        // 创建日期格式化对象,设置格式为 "yyyy-MM-dd HH:mm"
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        // 格式化日期对象,输出字符串结果
        String formattedDate = sdf.format(now);
        return formattedDate;
    }
 
    @GetMapping("baidufence.do")
    public String baidufence(HttpServletRequest request) {
        JSONObject json = new JSONObject();
        List<TbFence> fences = this.fenceService.getFenceList();
        List<String> fences2 = new ArrayList();
 
        for(int i = 0; i < fences.size(); ++i) {
                fences2.add(((TbFence)fences.get(i)).getZuobiao());
                fences2.add(((TbFence)fences.get(i)).getName());
        }
 
        json.put("fences", fences2);
        return json.toString();
     }
 
    @PostMapping("ShouDongWeiLan")
    public void ShouDongWeiLan(String name,String bumen,String lng,String lat,String banjing,String zuobiao,String xiangao,String type,String types,String kuandu){
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String formattedDateTime = now.format(formatter);
        if (types.equals("圆形")){
            String xieyi = "BSTOCS1,ADDFENCEYUAN,0" + ","+type+","+bumen+","+banjing+","+name+","+lng +";"+lat+","+"圆形"+","+"00:00:00"+","+"23:59:59"+","+formattedDateTime+","+"红色"+",END";
            Udp_Out.udp_to_cs(xieyi);
        }
        if (types.equals("限高")){
            String xieyi = "BSTOCS1,ADDFENCESS,0" + ",限高围栏,"+bumen+","+name+","+zuobiao+","+"多边形"+","+"00:00:00"+","+"23:59:59"+","+formattedDateTime+","+"红色,"+xiangao+",END";
            Udp_Out.udp_to_cs(xieyi);
        }
        if (types.equals("多边形")){
            String xieyi = "BSTOCS1,ADDFENCESS,0" + ","+type+","+bumen+","+name+","+zuobiao+","+"多边形"+","+"00:00:00"+","+"23:59:59"+","+formattedDateTime+","+"红色"+",-1,END";
            Udp_Out.udp_to_cs(xieyi);
        }
        if (types.equals("矩形")){
            String xieyi = "BSTOCS1,ADDFENCEPS,0," +type+ ",限高围栏,"+bumen+","+name+","+zuobiao+","+"电线"+","+"00:00:00"+","+"23:59:59"+","+formattedDateTime+","+"红色"+",-1,END";
            Udp_Out.udp_to_cs(xieyi);
        }
    }
 
     //三维根据Fid查询是否有这个围栏
    @GetMapping("FindSanWeiIFID")
    public int FindSanWeiIFID(String Fid){
        return fenceService.FindSanWeiIFID(Fid);
    }
 
 
    public String bd09ToWGS841(double bd_lon, double bd_lat) {
        double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
        double x = bd_lon;
        double y = bd_lat;
        double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
        double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
        double wgs84_lon = z * Math.cos(theta)+0.0065;
        double wgs84_lat = z * Math.sin(theta)+0.006;
        return wgs84_lon+":"+wgs84_lat;
    }
    public double bd09ToWGS842(double bd_lon, double bd_lat) {
        double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
        double x = bd_lon - 0.0065;
        double y = bd_lat - 0.006;
        double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
        double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
        double wgs84_lon = z * Math.cos(theta);
        double wgs84_lat = z * Math.sin(theta);
        return wgs84_lat;
    }
 
}