zhitong.yu
2024-12-27 8abbee975353926e51a426a75c67119337fbdae4
src/main/java/com/hxzk/controller/FenceController.java
@@ -3,24 +3,23 @@
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.pojo.TbSetting;
import com.hxzk.pojo.TbUser;
import com.hxzk.service.DiTuService;
import com.hxzk.service.FenceService;
import com.hxzk.service.SettingService;
import com.hxzk.service.SystemLogService;
import com.hxzk.service.TagService;
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.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@@ -31,6 +30,9 @@
@RestController
@RequestMapping("/")
public class FenceController {
    private String layers = "";
    @Autowired
    FenceService fenceService;
@@ -39,6 +41,11 @@
    @Autowired
    SystemLogService systemLogService;
    @Autowired
    SessionManager sessionManager;
    @Autowired
    SettingService settingService;
    //查询所有围栏设备信息
@@ -47,7 +54,18 @@
        PageInfo<TbFence> cz= fenceService.findAll(page, limit);
        return resultutil.returnSuccess(cz.getTotal(), cz.getList());
    }
    @GetMapping("findAllFence")//获取所有考勤区域,和区域统计类型围栏
    public List<TbFence> findAllFence(){
        return fenceService.findAllFence();
    }
    @GetMapping("findAllFence1")
    public List<TbFence> findAllFence1(){
        return fenceService.findAllFence1();
    }
    @PostMapping("findShiPinFence")
    public List<TbFence> findShiPinFence(){
        return fenceService.findShiPinFence();
    }
    @GetMapping("findfenceSearch")
    result<List<TbFence>>  findfenceSearch(Integer page, Integer limit,TbFence fence){
        PageInfo<TbFence> cz= fenceService.findfenceSearch(page, limit,fence);
@@ -55,18 +73,19 @@
    }
    //删除围栏
    @GetMapping("deletewl")
    public void deletewl(String name){
    public void deletewl(String name,HttpServletRequest request){
        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);
        TbUser user = sessionManager.getCurrentUser(request);
        String content = "删除了一个围栏,该围栏为:"+name;
        byte[] utf8Bytes = xieyi.getBytes(StandardCharsets.UTF_8);
        Udp_Out.udp_to_cs(new String(utf8Bytes, StandardCharsets.UTF_8));
        String ipAddress = request.getRemoteAddr();
        SystemLogController.InsertSystemLog(user.getUsername(),gettime(),content,"删除",ipAddress);
    }
    //新增围栏
    @PostMapping("addbaidufence")
    public String addbaidufence(HttpServletRequest request){
    public Integer 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);
@@ -77,21 +96,105 @@
        String xingzhuang = request.getParameter("xingzhuang");
        String yanse = request.getParameter("yanse");
        String zuobiao = request.getParameter("zuobiao");
        String s = zuobiao.replaceAll("\\,", "\\:");
        String gao = request.getParameter("fencegao");
//        String sd = "";
//        String s= "";
//        String apo = "";
//        String[] parts = new String[0];
//        if (layer.equals("Карта") || 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+= bd09towgs84(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]+";";
//                        }
//                    }
//
//                }
//            }
//        }
        String shengxiao = "00:00:00";
        String shixiao = "23:59:59";
        String xieyi = "BSTOCS1,ADDFENCE," + layer + ","+weilanleixing+","+guanlianduixiang+","+quyumingcheng+","+s+","+xingzhuang+","+shengxiao+","+shixiao+","+formattedDateTime+","+yanse+",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";
        String xieyi = "";
        if (layer.equals(layer)){
             xieyi = "BSTOCS1,ADDFENCE," + layer + ","+weilanleixing+","+guanlianduixiang+","+quyumingcheng+","+zuobiao+","+xingzhuang+","+shengxiao+","+shixiao+","+formattedDateTime+","+yanse+","+gao+",END";
        }else{
             xieyi = "BSTOCS1,ADDFENCE," + layer + ","+weilanleixing+","+guanlianduixiang+","+quyumingcheng+","+zuobiao+","+xingzhuang+","+shengxiao+","+shixiao+","+formattedDateTime+","+yanse+","+gao+",END";
        }
        byte[] utf8Bytes = xieyi.getBytes(StandardCharsets.UTF_8);
        Udp_Out.udp_to_cs(new String(utf8Bytes, StandardCharsets.UTF_8));
        //String xieyi1 = "BSTOCS1,ADDTJAREA,"+quyumingcheng+","+yanse+","+s+",系统默认,END";
        //Udp_Out.udp_to_cs(xieyi1);
        String content= "添加了一个围栏,该围栏为:"+quyumingcheng;
        String ipAddress = request.getRemoteAddr();
        SystemLogController.InsertSystemLog(user.getUsername(),gettime(),content,"新增",ipAddress);
        return 200;
    }
    @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";
        }
        byte[] utf8Bytes = xieyi.getBytes(StandardCharsets.UTF_8);
        Udp_Out.udp_to_cs(new String(utf8Bytes, StandardCharsets.UTF_8));
        //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")
@@ -146,21 +249,35 @@
    }
    @GetMapping("FenceKaiQi")
    public void fenceKai(TbFence fence){
    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);
        byte[] utf8Bytes = xieyi.getBytes(StandardCharsets.UTF_8);
        Udp_Out.udp_to_cs(new String(utf8Bytes, StandardCharsets.UTF_8));
        String content = "开启了一个围栏该围栏名称为:"+fence.getName();
        String ipAddress = request.getRemoteAddr();
        SystemLogController.InsertSystemLog(user.getUsername(),gettime(),content,"修改",ipAddress);
    }
    @GetMapping("FenceGuanBi")
    public void fenceGuan(TbFence fence){
    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);
        byte[] utf8Bytes = xieyi.getBytes(StandardCharsets.UTF_8);
        Udp_Out.udp_to_cs(new String(utf8Bytes, StandardCharsets.UTF_8));
        String content = "关闭了一个围栏该围栏名称为:"+fence.getName();
        String ipAddress = request.getRemoteAddr();
        SystemLogController.InsertSystemLog(user.getUsername(),gettime(),content,"修改",ipAddress);
    }
    @PostMapping("upWeiLanTiShiYu")
    public void upWeiLanTiShiYu(TbFence fence,HttpServletResponse response) throws IOException {
    public void upWeiLanTiShiYu(TbFence fence,HttpServletResponse response,HttpServletRequest request) throws IOException {
        TbUser user = sessionManager.getCurrentUser(request);
        fenceService.upWeiLanTiShiYu(fence);
        String content = "修改了围栏提示语该围栏提示语为:"+fence.getBaoliu9();
        String ipAddress = request.getRemoteAddr();
        SystemLogController.InsertSystemLog(user.getUsername(),gettime(),content,"修改",ipAddress);
        response.sendRedirect("/hxzkuwb/HouTai/WeiLanList/WeiLanList.jsp");
    }
@@ -179,20 +296,185 @@
        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)).getBaoliu8());
        }
        }
        json.put("fences", fences2);
        return json.toString();
     }
    @GetMapping("baidufenceName.do")
    public List baidufenceName(HttpServletRequest request) {
        List<TbFence> fences = this.fenceService.getFenceList();
        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";
            byte[] utf8Bytes = xieyi.getBytes(StandardCharsets.UTF_8);
            Udp_Out.udp_to_cs(new String(utf8Bytes, StandardCharsets.UTF_8));
        }
        if (types.equals("限高")){
            String xieyi = "BSTOCS1,ADDFENCESS,0" + ",限高围栏,"+bumen+","+name+","+zuobiao+","+"多边形"+","+"00:00:00"+","+"23:59:59"+","+formattedDateTime+","+"红色,"+xiangao+",END";
            byte[] utf8Bytes = xieyi.getBytes(StandardCharsets.UTF_8);
            Udp_Out.udp_to_cs(new String(utf8Bytes, StandardCharsets.UTF_8));
        }
        if (types.equals("多边形")){
            String xieyi = "BSTOCS1,ADDFENCESS,0" + ","+type+","+bumen+","+name+","+zuobiao+","+"多边形"+","+"00:00:00"+","+"23:59:59"+","+formattedDateTime+","+"红色"+",-1,END";
            byte[] utf8Bytes = xieyi.getBytes(StandardCharsets.UTF_8);
            Udp_Out.udp_to_cs(new String(utf8Bytes, StandardCharsets.UTF_8));
        }
        if (types.equals("矩形")){
            String xieyi = "BSTOCS1,ADDFENCEPS,0," +type+ ",限高围栏,"+bumen+","+name+","+zuobiao+","+"电线"+","+"00:00:00"+","+"23:59:59"+","+formattedDateTime+","+"红色"+",-1,END";
            byte[] utf8Bytes = xieyi.getBytes(StandardCharsets.UTF_8);
            Udp_Out.udp_to_cs(new String(utf8Bytes, StandardCharsets.UTF_8));
        }
        String content= "手动录入了一个围栏,该围栏为:"+name;
        String ipAddress = request.getRemoteAddr();
        SystemLogController.InsertSystemLog(user.getUsername(),gettime(),content,"新增",ipAddress);
    }
     //三维根据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;
    }
//查重
@GetMapping("FindNameFence")
public Integer FindNameFence(String name) {
    return fenceService.FindNameFence(name);
}
    @GetMapping("FindNameFenceTbFence")
    public TbFence FindNameFenceTbFence(String name){
        return fenceService.FindNameFenceTbFence(name);
    }
    public static double pi = 3.1415926535897932384626;
    public static double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
    public static double a = 6378245.0;
    public static double ee = 0.00669342162296594323;
    public static double transformLat(double x, double y) {
        double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
        ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
        ret += (20.0 * Math.sin(y * pi) + 40.0 * Math.sin(y / 3.0 * pi)) * 2.0 / 3.0;
        ret += (160.0 * Math.sin(y / 12.0 * pi) + 320 * Math.sin(y * pi / 30.0)) * 2.0 / 3.0;
        return ret;
    }
    public static double transformLon(double x, double y) {
        double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
        ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
        ret += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x / 3.0 * pi)) * 2.0 / 3.0;
        ret += (150.0 * Math.sin(x / 12.0 * pi) + 300.0 * Math.sin(x / 30.0 * pi)) * 2.0 / 3.0;
        return ret;
    }
    public static double[] transform(double lat, double lon) {
        if (outOfChina(lat, lon)) {
            return new double[]{lat,lon};
        }
        double dLat = transformLat(lon - 105.0, lat - 35.0);
        double dLon = transformLon(lon - 105.0, lat - 35.0);
        double radLat = lat / 180.0 * pi;
        double magic = Math.sin(radLat);
        magic = 1 - ee * magic * magic;
        double sqrtMagic = Math.sqrt(magic);
        dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);
        dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi);
        double mgLat = lat + dLat;
        double mgLon = lon + dLon;
        return new double[]{mgLat,mgLon};
    }
    public static boolean outOfChina(double lat, double lon) {
        if (lon < 72.004 || lon > 137.8347)
            return true;
        if (lat < 0.8293 || lat > 55.8271)
            return true;
        return false;
    }
    public static double[] bd09_To_Gcj02(double lat, double lon) {
        double x = lon - 0.0065, y = 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 tempLon = z * Math.cos(theta);
        double tempLat = z * Math.sin(theta);
        double[] gps = {tempLat,tempLon};
        return gps;
    }
    public static double[] gcj02_To_Gps84(double lat, double lon) {
        double[] gps = transform(lat, lon);
        double lontitude = lon * 2 - gps[1];
        double latitude = lat * 2 - gps[0];
        return new double[]{latitude, lontitude};
    }
    public static String bd09_To_gps84(double lat,double lon){
        double[] gcj02 = bd09_To_Gcj02(lat, lon);
        double[] gps84 = gcj02_To_Gps84(gcj02[0], gcj02[1]);
        //保留小数点后六位
        gps84[0] = retain6(gps84[0]);
        gps84[1] = retain6(gps84[1]);
        return gps84[0]+","+gps84[1];
    }
    private static double retain6(double num){
        String result = String .format("%.6f", num);
        return Double.valueOf(result);
    }
    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<TbSetting> setting = settingService.FindSetting();
        if (setting.get(0).getLanguages().equals("0")){
            layers = "百度地图";
        }
        if (setting.get(0).getLanguages().equals("2")){
            layers = "Карта Baidu";
        }
    }
}