Pu Zhibing
2 天以前 949bf4798368d0fce115993427e03758d4b3c897
ManagementOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/specialTrain/TSiteController.java
@@ -9,6 +9,7 @@
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.util.IdGenerator;
import com.stylefeng.guns.core.util.SinataUtil;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.model.TDriverLine;
@@ -18,7 +19,11 @@
import com.stylefeng.guns.modular.system.service.ITRegionService;
import com.stylefeng.guns.modular.system.util.GDMapElectricFenceUtil;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import org.springframework.stereotype.Controller;
import com.stylefeng.guns.modular.system.util.model.GeoFencingPolygon;
import org.apache.commons.collections.CollectionUtils;
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;
@@ -58,7 +63,8 @@
    @Autowired
    private GDMapElectricFenceUtil gdMapElectricFenceUtil;
    @Autowired
    private MongoTemplate mongoTemplate;
    /**
     * 跳转到跨城站点管理首页
@@ -103,19 +109,29 @@
            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<>());
        }
        if (SinataUtil.isNotEmpty(tSite.getDistrictCode())) {
            TRegion area = tRegionService.selectOne(new EntityWrapper<TRegion>().eq("code", tSite.getDistrictCode()));
            //乡镇街道
            List<TRegion> townList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", area.getId()));
            model.addAttribute("townList", townList);
        } else {
            model.addAttribute("townList", new ArrayList<>());
        }
        //查询所有的站点区域
        List<TLocation> locationList = itLocationService.selectList(new EntityWrapper<TLocation>().eq("siteId", tSite.getId()).ne("state", 3));
        model.addAttribute("locationList",locationList);
        model.addAttribute("locationList1", JSON.toJSONString(locationList));
        model.addAttribute("disabled","disabled");
        Integer type = itLocationService.selectList(new EntityWrapper<TLocation>().eq("siteId", tSite.getId())).get(0).getType();
        if (CollectionUtils.isNotEmpty(locationList)) {
            Integer type = locationList.get(0).getType();
        model.addAttribute("type1", type == 1 ? "block" : "none");
        model.addAttribute("type2", type == 1 ? "none" : "block");
        model.addAttribute("checked1", type == 1 ? "checked" : "");
        model.addAttribute("checked2", type == 1 ? "" : "checked");
        }
        return PREFIX + "tSite_edit.html";
    }
@@ -134,7 +150,9 @@
        }
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        if (ShiroKit.getUser().getRoleType() != 1){
            page.setRecords(null);
            if (ShiroKit.getUser().getRoleType() == 2){
                page.setRecords(tSiteService.getCompanySiteList(page, beginTime, endTime, name, insertUser, city, state,ShiroKit.getUser().getId()));
            }
        }else{
            page.setRecords(tSiteService.getSiteList(page,beginTime,endTime,name,insertUser,city,state));
        }
@@ -159,6 +177,7 @@
    /**
     * 添加站点区域
     *
     * @param subArr
     * @param id
     */
@@ -193,20 +212,24 @@
                String coordinate = jsonObject.getString("coordinate");
                coordinate = coordinate.substring(0, coordinate.length() - 1);
                location.setCoordinate(coordinate);
                //将电子围栏坐标信息存储到MongoDB
                GeoFencingPolygon gfp = new GeoFencingPolygon();
                gfp.setId(IdGenerator.getId());
                gfp.setSiteId(id);
                gfp.setName(jsonObject.getString("name"));
                String[] split = coordinate.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);
            }
        }
    }
@@ -220,6 +243,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){
@@ -239,9 +266,11 @@
        //删除站点区域
        JSONArray jsonArray = JSON.parseArray(subArr);
        //查询站点对应区域数据
        List<TLocation> siteId = itLocationService.selectList(new EntityWrapper<TLocation>().eq("siteId", tSite.getId()));
        List<TLocation> del = new ArrayList<>();
        List<Object> add = new ArrayList<>();
        //遍历区域数据
        for(TLocation location : siteId){
            boolean b = true;
            for(int i = 0; i < jsonArray.size(); i++){
@@ -261,10 +290,10 @@
        }
        for(TLocation location : del){
            if(location.getType() == 2){
                String[] s = location.getGid().split("_");
                for(String gid : s){
                    gdMapElectricFenceUtil.deleteElectricFenc(gid);
                }
                //删除mongoDB的区域信息
                Criteria criteria =Criteria.where("siteId").is(tSite.getId());
                Query query = new Query(criteria);
                mongoTemplate.remove(query,GeoFencingPolygon.class);
            }
            itLocationService.deleteById(location.getId());
        }