zhitong.yu
2024-03-15 ebd89b9ffa8980ac944a7e79ecc64c01637d4f17
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
package com.hxzk.controller;
 
import cn.hutool.json.JSONObject;
import com.hxzk.pojo.TbSystem;
import com.hxzk.pojo.tb_jingwei;
import com.hxzk.service.SystemService;
import com.sun.org.apache.xpath.internal.operations.Mod;
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 javax.servlet.http.HttpSession;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
 
@RestController
@RequestMapping("/")
public class SystemController {
    static double e2;
    static double e4;
    static double e6;
    static double E0;
    static double N0;
 
    static double a = 6378.137;
    static double e = 0.0818192;
    static double k0 = 0.9996;
    @Autowired
    SystemService systemService;
 
    @GetMapping("findsystem")
    public List<TbSystem> findsystem(){
        return systemService.findsystem();
    }
    //修改大屏默认显示地图
    @PostMapping("updaping")
    public void updaping(String baoliu28){
        systemService.updaping(baoliu28);
    }
 
 
    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;
    }
 
    @RequestMapping(value = {"jingweijuli.do"}, method = {RequestMethod.POST, RequestMethod.GET})
    public ModelAndView tojisuan1(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("jisuan1.jsp");
        return modelAndView;
    }
 
 
    @ResponseBody
    @RequestMapping(
            value = {"jisuanjingwei2.do"},
            method = {RequestMethod.POST, RequestMethod.GET}
    )
    public JSONObject jisuanjingwei2(String str) {
        JSONObject json = new JSONObject();
        String[] split = str.split(";");
        double[] sy = gpstodu(split[1], split[0]);
        String str2 = sy[1] + ";" + sy[0];
        json.put("jieguo", str2);
        return json;
    }
 
    @ResponseBody
    @RequestMapping(
            value = {"jisuanjingwei3.do"},
            method = {RequestMethod.POST, RequestMethod.GET}
    )
    public JSONObject jisuanjingwei3(HttpServletRequest request) {
        JSONObject json = new JSONObject();
        String qidian = request.getParameter("qidian");
        String zhongdian = request.getParameter("zhongdian");
        String[] qidians = qidian.split(",");
        String[] zhongdians = zhongdian.split(",");
        String str = qidians[2] + ";" + qidians[4] + ";" + zhongdians[2] + ";" + zhongdians[4];
        String disab = disab(str);
        String[] split = str.split(";");
        String qishi = split[1] + "/" + split[0];
        String zhongzhi = split[3] + "/" + split[2];
        tb_jingwei jingwei = new tb_jingwei();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(new Date());
        jingwei.setQishi(qishi);
        jingwei.setZhongzhi(zhongzhi);
        jingwei.setJieguo(disab);
        jingwei.setAddtime(format);
        json.put("jieguo", disab);
        return json;
    }
 
 
 
    @ResponseBody
    @RequestMapping(value = {"jisuanjingwei.do"}, method = {RequestMethod.POST, RequestMethod.GET})
    public JSONObject jisuanjingwei(String str) {
        JSONObject json = new JSONObject();
        String disab = disab(str);
        String[] split = str.split(";");
        String qishi = split[1] + "/" + split[0];
        String zhongzhi = split[3] + "/" + split[2];
        tb_jingwei jingwei = new tb_jingwei();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(new Date());
        jingwei.setQishi(qishi);
        jingwei.setZhongzhi(zhongzhi);
        jingwei.setJieguo(disab);
        jingwei.setAddtime(format);
        json.put("jieguo", disab);
        return json;
    }
 
 
 
 
    public static String todufen(String Du, String Fen, String Miao) {
        Float strDu = Float.valueOf(Du);
        Float strFen = Float.valueOf(Fen) / 60.0F;
        Float strMiao = Float.valueOf(Miao) / 60.0F;
        Float dufenmiao = strDu + strFen + strMiao;
        String format = String.format("%.6f", dufenmiao);
        return format;
    }
    public static double[] gpstodu(String gps_weidu, String gps_jingdu) {
        double[] a = new double[]{0.0, 0.0};
        String weidu = todufen(gps_weidu.substring(0, 2), gps_weidu.substring(2, 4), gps_weidu.substring(4));
        String jingdu = todufen(gps_jingdu.substring(0, 3), gps_jingdu.substring(3, 5), gps_jingdu.substring(5));
        a[0] = Double.parseDouble(weidu);
        a[1] = Double.parseDouble(jingdu);
        return a;
    }
 
    public static String disab(String jwd) {
        DecimalFormat df = new DecimalFormat("0.00");
        String[] bb = jwd.split(";");
        double jd0 = Double.parseDouble(bb[1]);
        double wd0 = Double.parseDouble(bb[0]);
        double jd1 = Double.parseDouble(bb[3]);
        double wd1 = Double.parseDouble(bb[2]);
        double[] a = run_gps2xyurt(wd0, jd0, wd1, jd1);
        double disa = a[0] * a[0] + a[1] * a[1];
        double dis = Math.sqrt(Math.abs(disa)) * 100.0;
        String temp = df.format(dis);
        System.out.println(jwd + "的距离是:" + temp);
        return temp;
    }
 
    public static double[] run_gps2xyurt(double lat0, double lon0, double lat, double lon) {
        int[] realxy = new int[2];
        double[] xycs = initiize_ublox_zeropoint(lat0, lon0, 0.0);
        double x0 = xycs[0];
        double y0 = xycs[1];
        double c = xycs[2];
        double s = xycs[3];
        double[] xy = new double[2];
        double x = ubloxraw2xy(lat, lon)[0] - x0;
        double y = ubloxraw2xy(lat, lon)[1] - y0;
        xy[0] = c * x - s * y;
        xy[1] = s * x + c * y;
        return xy;
    }
    public static double[] initiize_ublox_zeropoint(double lat, double lon, double th) {
        double[] xycs = new double[]{ubloxraw2xy(lat, lon)[0], ubloxraw2xy(lat, lon)[1], 0.0, 0.0};
        double th1 = th * Math.PI / 180.0;
        xycs[2] = Math.cos(th1);
        xycs[3] = Math.sin(th1);
        return xycs;
    }
 
    public static double[] ubloxraw2xy(double lat, double lon) {
        double[] xy = new double[3];
        double lond = ublox_dm2d(lon);
        double latd = ublox_dm2d(lat);
        double[] dxy = utm(latd, lond);
        xy[0] = dxy[0] * 1000.0;
        xy[1] = dxy[1] * 1000.0;
        xy[2] = dxy[2];
        return xy;
    }
 
    public static double ublox_dm2d(double ddmm_dot_m) {
        double d0 = Math.floor(ddmm_dot_m / 100.0);
        double d = d0 + (ddmm_dot_m - d0 * 100.0) / 60.0;
        return d;
    }
    public static double[] utm(double lat, double lon) {
        double[] dxy = new double[3];
        double zonenum1 = lon / 6.0;
        if (zonenum1 > 0.0) {
            zonenum1 = Math.floor(zonenum1);
        } else {
            zonenum1 = Math.ceil(zonenum1);
        }
 
        double Zonenum = zonenum1 + 31.0;
        double lambda0 = ((Zonenum - 1.0) * 6.0 - 180.0 + 3.0) * Math.PI / 180.0;
        double phi = lat * Math.PI / 180.0;
        double lambda = lon * Math.PI / 180.0;
        double v = 1.0 / Math.sqrt(1.0 - e2 * Math.pow(Math.sin(phi), 2.0));
        double A = (lambda - lambda0) * Math.cos(phi);
        double A2 = A * A;
        double A3 = A2 * A;
        double A4 = A3 * A;
        double A5 = A4 * A;
        double A6 = A5 * A;
        double T = Math.tan(phi) * Math.tan(phi);
        double T2 = T * T;
        double C = e2 * Math.cos(phi) * Math.cos(phi) / (1.0 - e2);
        double C2 = C * C;
        double s = (1.0 - e2 / 4.0 - 3.0 * e4 / 64.0 - 5.0 * e6 / 256.0) * phi - (3.0 * e2 / 8.0 + 3.0 * e4 / 32.0 + 45.0 * e6 / 1024.0) * Math.sin(2.0 * phi) + (15.0 * e4 / 256.0 + 45.0 * e6 / 1024.0) * Math.sin(4.0 * phi) - 35.0 * e6 / 3072.0 * Math.sin(6.0 * phi);
        dxy[0] = E0 + k0 * a * v * (A + (1.0 - T + C) * A3 / 6.0 + (5.0 - 18.0 * T + T2) * A5 / 120.0);
        dxy[1] = N0 + k0 * a * (s + v * Math.tan(phi) * (A2 / 2.0 + (5.0 - T + 9.0 * C + 4.0 * C2) * A4 / 24.0 + (61.0 - 58.0 * T + T2) * A6 / 720.0));
        dxy[2] = Zonenum;
        return dxy;
    }
 
}