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 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; } }