package com.stylefeng.guns.modular.system.controller.specialTrain;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.plugins.Page;
|
import com.stylefeng.guns.core.base.controller.BaseController;
|
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;
|
import com.stylefeng.guns.modular.system.model.TLocation;
|
import com.stylefeng.guns.modular.system.model.TRegion;
|
import com.stylefeng.guns.modular.system.service.ITLocationService;
|
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 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;
|
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.RequestParam;
|
import com.stylefeng.guns.modular.system.model.TSite;
|
import com.stylefeng.guns.modular.system.service.ITSiteService;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 跨城站点管理控制器
|
*
|
* @author fengshuonan
|
* @Date 2020-09-04 10:35:51
|
*/
|
@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;
|
|
/**
|
* 跳转到跨城站点管理首页
|
*/
|
@RequestMapping("")
|
public String index() {
|
return PREFIX + "tSite.html";
|
}
|
|
/**
|
* 跳转到添加跨城站点管理
|
*/
|
@RequestMapping("/tSite_add")
|
public String tSiteAdd(Model model) {
|
//省
|
List<TRegion> provinceList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
|
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);
|
LogObjectHolder.me().set(tSite);
|
|
//省
|
List<TRegion> provinceList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
|
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())) {
|
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", 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");
|
|
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) {
|
String beginTime = null;
|
String endTime = null;
|
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) {
|
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) {
|
tSite.setInsertTime(new Date());
|
tSite.setInsertUserId(ShiroKit.getUser().getId());
|
tSite.setState(1);
|
tSiteService.insert(tSite);
|
|
//添加站点区域
|
addLocation(subArr, tSite.getId());
|
return ResultUtil.success();
|
}
|
|
/**
|
* 添加站点区域
|
*
|
* @param subArr
|
* @param id
|
*/
|
public void addLocation(String subArr, Integer id) {
|
JSONArray jsonArray = JSON.parseArray(subArr);
|
int size = jsonArray.size();
|
for (int i = 0; i < size; i++) {
|
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
TLocation location = new TLocation();
|
location.setSiteId(id);
|
location.setName(jsonObject.getString("name"));
|
location.setInsertTime(new Date());
|
location.setAddTime(jsonObject.getString("time"));
|
location.setState(1);
|
location.setUpdateTime(new Date());
|
Integer type = jsonObject.getInteger("areaType");
|
location.setType(type);
|
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"))) {
|
location.setCity(jsonObject.getString("city"));
|
location.setCityCode(jsonObject.getString("cityCode"));
|
}
|
if (SinataUtil.isNotEmpty(jsonObject.getString("districtCode"))) {
|
location.setDistrict(jsonObject.getString("district"));
|
location.setDistrictCode(jsonObject.getString("districtCode"));
|
}
|
} 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);
|
}
|
}
|
|
/**
|
* 操作跨城站点管理
|
* optType 1=删除 2=冻结 3=解冻
|
*/
|
@RequestMapping(value = "/opt")
|
@ResponseBody
|
public Object opt(@RequestParam Integer tSiteId, @RequestParam Integer optType) {
|
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) {
|
tSite.setState(1);
|
}
|
tSiteService.updateById(tSite);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改跨城站点管理
|
*/
|
@RequestMapping(value = "/update")
|
@ResponseBody
|
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) {
|
boolean b = true;
|
for(int i = 0; i < jsonArray.size(); i++){
|
if(jsonArray.getJSONObject(i).getIntValue("id") == location.getId()){
|
b = false;
|
}
|
}
|
if (b) {
|
del.add(location);
|
continue;
|
}
|
}
|
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) {
|
//删除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());
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 跨城站点管理详情
|
*/
|
@RequestMapping(value = "/detail/{tSiteId}")
|
@ResponseBody
|
public Object detail(@PathVariable("tSiteId") Integer tSiteId) {
|
return tSiteService.selectById(tSiteId);
|
}
|
}
|