From 28e148e28986a08414a4c690a5e5e7ecdc87f9a7 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期四, 21 八月 2025 18:56:06 +0800
Subject: [PATCH] 修改bug

---
 ManagementQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/specialTrain/TSiteController.java |  105 +++++++++++++++++++++++++++++++---------------------
 1 files changed, 62 insertions(+), 43 deletions(-)

diff --git a/ManagementQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/specialTrain/TSiteController.java b/ManagementQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/specialTrain/TSiteController.java
index 567ab08..4f11545 100644
--- a/ManagementQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/specialTrain/TSiteController.java
+++ b/ManagementQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/specialTrain/TSiteController.java
@@ -8,28 +8,32 @@
 import com.stylefeng.guns.core.base.controller.BaseController;
 import com.stylefeng.guns.core.beetl.ShiroExtUtil;
 import com.stylefeng.guns.core.common.constant.factory.PageFactory;
-import com.stylefeng.guns.core.shiro.ShiroKit;
-import com.stylefeng.guns.core.util.DateUtil;
+import com.stylefeng.guns.core.log.LogObjectHolder;
+import com.stylefeng.guns.core.util.IdGenerator;
 import com.stylefeng.guns.core.util.SinataUtil;
-import com.stylefeng.guns.core.util.ToolUtil;
-import com.stylefeng.guns.modular.system.model.TDriverLine;
 import com.stylefeng.guns.modular.system.model.TLocation;
 import com.stylefeng.guns.modular.system.model.TRegion;
+import com.stylefeng.guns.modular.system.model.TSite;
 import com.stylefeng.guns.modular.system.service.ITLocationService;
 import com.stylefeng.guns.modular.system.service.ITRegionService;
+import com.stylefeng.guns.modular.system.service.ITSiteService;
 import com.stylefeng.guns.modular.system.util.GDMapElectricFenceUtil;
 import com.stylefeng.guns.modular.system.util.ResultUtil;
+import com.stylefeng.guns.modular.system.util.model.GeoFencingPolygon;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.geo.Point;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.geo.GeoJsonPolygon;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.beans.factory.annotation.Autowired;
-import com.stylefeng.guns.core.log.LogObjectHolder;
+import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
-import com.stylefeng.guns.modular.system.model.TSite;
-import com.stylefeng.guns.modular.system.service.ITSiteService;
+import org.springframework.web.bind.annotation.ResponseBody;
 
+import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -49,18 +53,22 @@
 
     @Autowired
     private ITSiteService tSiteService;
-
+    
     @Autowired
     private ITRegionService tRegionService;
-
+    
     @Autowired
     private ITLocationService itLocationService;
-
+    
     @Autowired
     private GDMapElectricFenceUtil gdMapElectricFenceUtil;
+    @Autowired
+    private ShiroExtUtil shiroExtUtil;
 
-
-
+    @Autowired
+    private MongoTemplate mongoTemplate;
+    
+    
     /**
      * 跳转到跨城站点管理首页
      */
@@ -104,7 +112,7 @@
             List<TRegion> areaList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", city.getId()));
             model.addAttribute("areaList",areaList);
         }else{
-            model.addAttribute("areaList",null);
+            model.addAttribute("areaList",new ArrayList<>());
         }
 
         //查询所有的站点区域
@@ -128,13 +136,13 @@
     public Object list(String insertTime,String name,String insertUser,String city,Integer state) {
         String beginTime = null;
         String endTime = null;
-        if (SinataUtil.isNotEmpty(insertTime)){
+        if (SinataUtil.isNotEmpty(insertTime)) {
             String[] timeArray = insertTime.split(" - ");
             beginTime = timeArray[0];
             endTime = timeArray[1];
         }
         Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
-        if (ShiroExtUtil.getUser().getRoleType() != 1) {
+        if (shiroExtUtil.getUser().getRoleType() != 1) {
             page.setRecords(null);
         } else {
             page.setRecords(tSiteService.getSiteList(page, beginTime, endTime, name, insertUser, city, state));
@@ -149,12 +157,12 @@
     @ResponseBody
     public Object add(TSite tSite,@RequestParam String subArr) {
         tSite.setInsertTime(new Date());
-        tSite.setInsertUserId(ShiroExtUtil.getUser().getId());
+        tSite.setInsertUserId(shiroExtUtil.getUser().getId());
         tSite.setState(1);
         tSiteService.insert(tSite);
-
+    
         //添加站点区域
-        addLocation(subArr,tSite.getId());
+        addLocation(subArr, tSite.getId());
         return ResultUtil.success();
     }
 
@@ -177,37 +185,44 @@
             location.setUpdateTime(new Date());
             Integer type = jsonObject.getInteger("areaType");
             location.setType(type);
-            if (1 == type){
-                if (SinataUtil.isNotEmpty(jsonObject.getString("provinceCode"))){
+            if (1 == type) {
+                if (SinataUtil.isNotEmpty(jsonObject.getString("provinceCode"))) {
                     location.setProvince(jsonObject.getString("province"));
                     location.setProvinceCode(jsonObject.getString("provinceCode"));
                 }
-                if (SinataUtil.isNotEmpty(jsonObject.getString("cityCode"))){
+                if (SinataUtil.isNotEmpty(jsonObject.getString("cityCode"))) {
                     location.setCity(jsonObject.getString("city"));
                     location.setCityCode(jsonObject.getString("cityCode"));
                 }
-                if (SinataUtil.isNotEmpty(jsonObject.getString("districtCode"))){
+                if (SinataUtil.isNotEmpty(jsonObject.getString("districtCode"))) {
                     location.setDistrict(jsonObject.getString("district"));
                     location.setDistrictCode(jsonObject.getString("districtCode"));
                 }
-            }else if (2 == type){
+            } else if (2 == type) {
                 String coordinate = jsonObject.getString("coordinate");
                 coordinate = coordinate.substring(0, coordinate.length() - 1);
                 location.setCoordinate(coordinate);
+                //将电子围栏坐标信息存储到MongoDB
+                String[] s1 = coordinate.split("_");
+                for (String s2 : s1) {
+                    GeoFencingPolygon gfp = new GeoFencingPolygon();
+                    gfp.setId(IdGenerator.getId());
+                    gfp.setSiteId(id);
+                    gfp.setName(jsonObject.getString("name"));
+                    String[] split = s2.split(";");
+                    List<Point> points = new ArrayList<>();
+                    for (String s : split) {
+                        String[] str = s.split(",");
+                        Point point = new Point(Double.parseDouble(str[0]), Double.parseDouble(str[1]));
+                        points.add(point);
+                    }
+                    //最后一个点要和第一个点相同
+                    points.add(new Point(points.get(0).getX(), points.get(0).getY()));
+                    gfp.setGeoJsonPolygon(new GeoJsonPolygon(points));
+                    mongoTemplate.save(gfp);
+                }
             }
             itLocationService.insert(location);
-
-            if(type == 2){
-                List<String> fence = gdMapElectricFenceUtil.createFence(location.getId().toString(), location.getCoordinate());
-                TLocation location1 = itLocationService.selectById(location.getId());
-                String s = "";
-                for(String gid : fence){
-                    s += gid + "_";
-                }
-                location1.setGid(s.substring(0, s.length() - 1));
-                location1.setUpdateTime(new Date());
-                itLocationService.updateById(location1);
-            }
         }
     }
 
@@ -221,6 +236,10 @@
         TSite tSite = tSiteService.selectById(tSiteId);
         if (1 == optType){
             tSite.setState(3);
+            //删除mongoDB的区域信息
+            Criteria criteria =Criteria.where("siteId").is(tSite.getId());
+            Query query = new Query(criteria);
+            mongoTemplate.remove(query,GeoFencingPolygon.class);
         }else if (2 == optType){
             tSite.setState(2);
         }else if (3 == optType){
@@ -261,11 +280,11 @@
             }
         }
         for(TLocation location : del){
-            if(location.getType() == 2){
-                String[] s = location.getGid().split("_");
-                for(String gid : s){
-                    gdMapElectricFenceUtil.deleteElectricFenc(gid);
-                }
+            if (location.getType() == 2) {
+                //删除mongoDB的区域信息
+                Criteria criteria =Criteria.where("siteId").is(tSite.getId());
+                Query query = new Query(criteria);
+                mongoTemplate.remove(query,GeoFencingPolygon.class);
             }
             itLocationService.deleteById(location.getId());
         }

--
Gitblit v1.7.1