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;
@@ -43,23 +48,24 @@
@Controller
@RequestMapping("/tSite")
public class TSiteController extends BaseController {
    private String PREFIX = "/system/tSite/";
    @Autowired
    private ITSiteService tSiteService;
    @Autowired
    private ITRegionService tRegionService;
    @Autowired
    private ITLocationService itLocationService;
    @Autowired
    private GDMapElectricFenceUtil gdMapElectricFenceUtil;
    @Autowired
    private MongoTemplate mongoTemplate;
    /**
     * 跳转到跨城站点管理首页
     */
@@ -67,7 +73,7 @@
    public String index() {
        return PREFIX + "tSite.html";
    }
    /**
     * 跳转到添加跨城站点管理
     */
@@ -75,97 +81,110 @@
    public String tSiteAdd(Model model) {
        //省
        List<TRegion> provinceList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
        model.addAttribute("provinceList",provinceList);
        model.addAttribute("provinceList", provinceList);
        return PREFIX + "tSite_add.html";
    }
    /**
     * 跳转到修改跨城站点管理
     */
    @RequestMapping("/tSite_update/{tSiteId}")
    public String tSiteUpdate(@PathVariable Integer tSiteId, Model model) {
        TSite tSite = tSiteService.selectById(tSiteId);
        model.addAttribute("item",tSite);
        model.addAttribute("item", tSite);
        LogObjectHolder.me().set(tSite);
        //省
        List<TRegion> provinceList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
        model.addAttribute("provinceList",provinceList);
        model.addAttribute("provinceList", provinceList);
        TRegion province = tRegionService.selectOne(new EntityWrapper<TRegion>().eq("code", tSite.getProvinceCode()));
        //市
        List<TRegion> cityList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", province.getId()));
        model.addAttribute("cityList",cityList);
        if (SinataUtil.isNotEmpty(tSite.getCityCode())){
        model.addAttribute("cityList", cityList);
        if (SinataUtil.isNotEmpty(tSite.getCityCode())) {
            TRegion city = tRegionService.selectOne(new EntityWrapper<TRegion>().eq("code", tSite.getCityCode()));
            //区
            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", areaList);
        } else {
            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("disabled","disabled");
        Integer type = itLocationService.selectList(new EntityWrapper<TLocation>().eq("siteId", tSite.getId())).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");
        model.addAttribute("locationList", locationList);
        model.addAttribute("locationList1", JSON.toJSONString(locationList));
        model.addAttribute("disabled", "disabled");
        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";
    }
    /**
     * 获取跨城站点管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String insertTime,String name,String insertUser,String city,Integer state) {
    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 (ShiroKit.getUser().getRoleType() != 1){
            page.setRecords(null);
        }else{
            page.setRecords(tSiteService.getSiteList(page,beginTime,endTime,name,insertUser,city,state));
        if (ShiroKit.getUser().getRoleType() != 1) {
            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));
        }
        return super.packForBT(page);
    }
    /**
     * 新增跨城站点管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TSite tSite,@RequestParam String subArr) {
    public Object add(TSite tSite, @RequestParam String subArr) {
        tSite.setInsertTime(new Date());
        tSite.setInsertUserId(ShiroKit.getUser().getId());
        tSite.setState(1);
        tSiteService.insert(tSite);
        //添加站点区域
        addLocation(subArr,tSite.getId());
        addLocation(subArr, tSite.getId());
        return ResultUtil.success();
    }
    /**
     * 添加站点区域
     *
     * @param subArr
     * @param id
     */
    public void addLocation(String subArr,Integer id){
    public void addLocation(String subArr, Integer id) {
        JSONArray jsonArray = JSON.parseArray(subArr);
        int size = jsonArray.size();
        for (int i = 0; i < size; i++){
        for (int i = 0; i < size; i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            TLocation location = new TLocation();
            location.setSiteId(id);
@@ -176,104 +195,114 @@
            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
                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);
            }
        }
    }
    /**
     * 操作跨城站点管理
     * optType 1=删除 2=冻结 3=解冻
     */
    @RequestMapping(value = "/opt")
    @ResponseBody
    public Object opt(@RequestParam Integer tSiteId,@RequestParam Integer optType) {
    public Object opt(@RequestParam Integer tSiteId, @RequestParam Integer optType) {
        TSite tSite = tSiteService.selectById(tSiteId);
        if (1 == optType){
        if (1 == optType) {
            tSite.setState(3);
        }else if (2 == optType){
            //删除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){
        } else if (3 == optType) {
            tSite.setState(1);
        }
        tSiteService.updateById(tSite);
        return SUCCESS_TIP;
    }
    /**
     * 修改跨城站点管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TSite tSite,@RequestParam String subArr) {
    public Object update(TSite tSite, @RequestParam String subArr) {
        tSiteService.updateById(tSite);
        //删除站点区域
        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){
        //遍历区域数据
        for (TLocation location : siteId) {
            boolean b = true;
            for(int i = 0; i < jsonArray.size(); i++){
                if(jsonArray.getJSONObject(i).getIntValue("id") == location.getId()){
                    b = false;
                }
            }
            if(b){
            if (b) {
                del.add(location);
                continue;
            }
        }
        for(int i = 0; i < jsonArray.size(); i++){
            if(jsonArray.getJSONObject(i).getInteger("id") == null){
        for (int i = 0; i < jsonArray.size(); i++) {
            if (jsonArray.getJSONObject(i).getInteger("id") == null) {
                add.add(jsonArray.get(i));
            }
        }
        for(TLocation location : del){
            if(location.getType() == 2){
                String[] s = location.getGid().split("_");
                for(String gid : s){
                    gdMapElectricFenceUtil.deleteElectricFenc(gid);
                }
        for (TLocation location : del) {
            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());
        }
        //添加站点区域
        addLocation(JSON.toJSONString(add),tSite.getId());
        addLocation(JSON.toJSONString(add), tSite.getId());
        return SUCCESS_TIP;
    }
    /**
     * 跨城站点管理详情
     */