package com.hxzk.controller; import cn.hutool.json.JSONObject; import com.github.pagehelper.PageInfo; import com.hxzk.pojo.*; import com.hxzk.service.*; import com.hxzk.udp.Udp_Out; import com.hxzk.util.SessionManager; 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 { private String layers = ""; @Autowired FenceService fenceService; @Autowired DiTuService diTuService; @Autowired SystemLogService systemLogService; @Autowired SessionManager sessionManager; @Autowired SettingService settingService; //查询所有围栏设备信息 @GetMapping("findfence") result> findfence(Integer page, Integer limit){ PageInfo cz= fenceService.findAll(page, limit); return resultutil.returnSuccess(cz.getTotal(), cz.getList()); } @GetMapping("findAllFence") public List findAllFence(){ return fenceService.findAllFence(); } @GetMapping("findAllFence1") public List findAllFence1(){ return fenceService.findAllFence1(); } @GetMapping("findfenceSearch") result> findfenceSearch(Integer page, Integer limit,TbFence fence){ PageInfo cz= fenceService.findfenceSearch(page, limit,fence); return resultutil.returnSuccess(cz.getTotal(), cz.getList()); } //删除围栏 @GetMapping("deletewl") public void deletewl(String name,HttpServletRequest request){ String xieyi = "BSTOCS1,DELETEFENCE," + name + ",END"; TbUser user = sessionManager.getCurrentUser(request); String content = "删除了一个围栏,该围栏为:"+name; String contentew = "Удалено ограждение, которое является:"+name; Udp_Out.udp_to_cs(xieyi); SystemLogController.InsertSystemLog(user.getUsername(),gettime(),content,contentew); } //新增围栏 @PostMapping("addbaidufence") public String addbaidufence(HttpServletRequest request){ TbUser user = sessionManager.getCurrentUser(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 gao = request.getParameter("fencegao"); String sd = ""; String s= ""; String apo = ""; String[] parts = new String[0]; if (layer.equals("Карта") || 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+= bd09ToWGS842(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 = String.valueOf(bd09ToWGS842(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(layer)){ xieyi = "BSTOCS1,ADDFENCE," + layer + ","+weilanleixing+","+guanlianduixiang+","+quyumingcheng+","+sd+","+xingzhuang+","+shengxiao+","+shixiao+","+formattedDateTime+","+yanse+","+gao+",END"; }else{ xieyi = "BSTOCS1,ADDFENCE," + layer + ","+weilanleixing+","+guanlianduixiang+","+quyumingcheng+","+apo+","+xingzhuang+","+shengxiao+","+shixiao+","+formattedDateTime+","+yanse+","+gao+",END"; } Udp_Out.udp_to_cs(xieyi); //String xieyi1 = "BSTOCS1,ADDTJAREA,"+quyumingcheng+","+yanse+","+s+",系统默认,END"; //Udp_Out.udp_to_cs(xieyi1); String content= "添加了一个围栏,该围栏为:"+quyumingcheng; String contentew= "Добавлен забор, который является:"+quyumingcheng; SystemLogController.InsertSystemLog(user.getUsername(),gettime(),content,contentew); return content; } @PostMapping("addfenceTianDiMap") public String addfenceTianDiMap(HttpServletRequest request,String fencetype,String bumen,String name,String zuobiao,String fencegao,String xingzhuang,String yuanradius){ TbUser user = sessionManager.getCurrentUser(request); LocalDateTime now = LocalDateTime.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); String formattedDateTime = now.format(formatter); String layers = "百度地图"; String yanse = "红色"; String[] parts = new String[0]; String shengxiao = "00:00:00"; String shixiao = "23:59:59"; String xieyi = ""; if (xingzhuang.equals("圆形")){ String[] zuobiao1 = zuobiao.split(";"); double jingdu = ublox_d2dm(Double.parseDouble(zuobiao1[0])); double weidu = ublox_d2dm(Double.parseDouble(zuobiao1[1])); zuobiao = jingdu+";"+weidu; xieyi = "BSTOCS1,ADDFENCEYUAN,0" + ","+fencetype+","+bumen+","+yuanradius+","+name+","+zuobiao+","+"圆形"+","+"00:00:00"+","+"23:59:59"+","+formattedDateTime+","+"红色"+",END"; }else{ xieyi = "BSTOCS1,ADDFENCE," + layers + ","+fencetype+","+bumen+","+name+","+zuobiao+","+xingzhuang+","+shengxiao+","+shixiao+","+formattedDateTime+","+yanse+","+fencegao+",END"; } Udp_Out.udp_to_cs(xieyi); //String xieyi1 = "BSTOCS1,ADDTJAREA,"+quyumingcheng+","+yanse+","+s+",系统默认,END"; //Udp_Out.udp_to_cs(xieyi1); // String content= "添加了一个围栏,该围栏为:"+name; // SystemLogController.InsertSystemLog(user.getUsername(),gettime(),content); 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 getFloorFence(HttpServletRequest request){ String floor_number = request.getParameter("value"); List fenceList = this.fenceService.getFence(floor_number); List 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 getFloorFence_all(HttpServletRequest request) { List fenceList = fenceService.getFence_all(); for (int i = 0 ; i findFenceType(){ return fenceService.findFenceType(); } @GetMapping("FenceKaiQi") public void fenceKai(TbFence fence,HttpServletRequest request){ TbUser user = sessionManager.getCurrentUser(request); String xieyi = "BSTOCS1,FENCE,OPEN," +fence.getName()+",END"; Udp_Out.udp_to_cs(xieyi); String content = "开启了一个围栏该围栏名称为:"+fence.getName(); String contentew = "Открывается забор, который называется:"+fence.getName(); SystemLogController.InsertSystemLog(user.getUsername(),gettime(),content,contentew); } @GetMapping("FenceGuanBi") public void fenceGuan(TbFence fence,HttpServletRequest request){ TbUser user = sessionManager.getCurrentUser(request); String xieyi = "BSTOCS1,FENCE,CLOSE," +fence.getName()+",END"; System.out.println(); Udp_Out.udp_to_cs(xieyi); String content = "关闭了一个围栏该围栏名称为:"+fence.getName(); String contentew= "Закрыли забор, который называется:"+fence.getName(); SystemLogController.InsertSystemLog(user.getUsername(),gettime(),content,contentew); } @PostMapping("upWeiLanTiShiYu") public void upWeiLanTiShiYu(TbFence fence,HttpServletResponse response,HttpServletRequest request) throws IOException { TbUser user = sessionManager.getCurrentUser(request); fenceService.upWeiLanTiShiYu(fence); String content = "修改了围栏提示语该围栏提示语为:"+fence.getBaoliu9(); String contentew = "Изменить подсказку ограждения, которая гласит::"+fence.getBaoliu9(); SystemLogController.InsertSystemLog(user.getUsername(),gettime(),content,contentew); 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 fences = this.fenceService.getFenceList(); List fences2 = new ArrayList(); for(int i = 0; i < fences.size(); ++i) { fences2.add(((TbFence)fences.get(i)).getBaoliu8()); } json.put("fences", fences2); return json.toString(); } @GetMapping("baidufenceName.do") public List baidufenceName(HttpServletRequest request) { List fences = this.fenceService.getFenceList(); return fences; } @GetMapping("baidufenceTian.do") public String baidufenceTian(HttpServletRequest request) { JSONObject json = new JSONObject(); List fences = this.fenceService.getFenceListTian(); List fences2 = new ArrayList(); for(int i = 0; i < fences.size(); ++i) { fences2.add(((TbFence)fences.get(i)).getBaoliu8()); fences2.add(((TbFence)fences.get(i)).getName()); } json.put("fences", fences2); return json.toString(); } @GetMapping("baidufenceTianYuan.do") public List baidufenceTianYuan(HttpServletRequest request) { List fences = this.fenceService.getFenceListTianYuan(); return fences; } @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,HttpServletRequest request){ TbUser user = sessionManager.getCurrentUser(request); 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); } String content= "手动录入了一个围栏,该围栏为:"+name; String contentew= "Введите вручную забор, который является:"+name; SystemLogController.InsertSystemLog(user.getUsername(),gettime(),content,contentew); } //三维根据Fid查询是否有这个围栏 @GetMapping("FindSanWeiIFID") public int FindSanWeiIFID(String Fid){ return fenceService.FindSanWeiIFID(Fid); } //URT绘制围栏 @GetMapping("UrtHuiZhi") public int UrtHuiZhi(String tagid,String type,String infoes){ if (tagid == null || type == null){ return 0; } if (infoes.equals("开始绘制")){ String msg = "BSTOCS1,URTADDFENCE,"+type+",Start,"+tagid+",END"; Udp_Out.udp_to_cs(msg); }else{ String msg = "BSTOCS1,URTADDFENCE,"+type+",Stop,"+tagid+",END"; Udp_Out.udp_to_cs(msg); } return 1; } 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 String 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_lon+":"+wgs84_lat; } public static double ublox_d2dm(double deg) { double deg0 =Math.floor(deg); double ddeg = deg-deg0; double m = ddeg*60; double ddmm = deg0*100+m; return ddmm; } public void Languages(){ List setting = settingService.FindSetting(); if (setting.get(0).getLanguages().equals("0")){ layers = "百度地图"; } if (setting.get(0).getLanguages().equals("2")){ layers = "Карта Baidu"; } } }