package com.stylefeng.guns.modular.system.controller.general;
|
|
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.SinataUtil;
|
import com.stylefeng.guns.modular.system.dao.TOpenCitySiteMapper;
|
import com.stylefeng.guns.modular.system.model.TOpenCityBusiness;
|
import com.stylefeng.guns.modular.system.model.TOpenCitySite;
|
import com.stylefeng.guns.modular.system.model.TRegion;
|
import com.stylefeng.guns.modular.system.service.ITOpenCityBusinessService;
|
import com.stylefeng.guns.modular.system.service.ITRegionService;
|
import com.stylefeng.guns.modular.system.util.GaoDeMapUtil;
|
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.TOpenCity;
|
import com.stylefeng.guns.modular.system.service.ITOpenCityService;
|
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.regex.Matcher;
|
import java.util.regex.Pattern;
|
|
/**
|
* 城市管理控制器
|
*
|
* @author fengshuonan
|
* @Date 2020-06-02 11:40:31
|
*/
|
@Controller
|
@RequestMapping("/tOpenCity")
|
public class TOpenCityController extends BaseController {
|
|
private String PREFIX = "/system/tOpenCity/";
|
|
@Autowired
|
private ITOpenCityService tOpenCityService;
|
|
@Autowired
|
private ITRegionService tRegionService;
|
|
@Autowired
|
private ITOpenCityBusinessService tOpenCityBusinessService;
|
@Autowired
|
private TOpenCitySiteMapper tOpenCitySiteMapper;
|
/**
|
* 跳转到城市管理首页
|
*/
|
@RequestMapping("")
|
public String index() {
|
return PREFIX + "tOpenCity.html";
|
}
|
|
/**
|
* 跳转到添加城市管理
|
*/
|
@RequestMapping("/tOpenCity_add")
|
public String tOpenCityAdd(Model model) {
|
List<TRegion> provinceList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
|
model.addAttribute("provinceList",provinceList);
|
return PREFIX + "tOpenCity_add.html";
|
}
|
|
/**
|
* 跳转到修改城市管理
|
*/
|
@RequestMapping("/tOpenCity_update/{tOpenCityId}")
|
public String tOpenCityUpdate(@PathVariable Integer tOpenCityId, Model model) {
|
TOpenCity tOpenCity = tOpenCityService.selectById(tOpenCityId);
|
model.addAttribute("item",tOpenCity);
|
LogObjectHolder.me().set(tOpenCity);
|
//省
|
List<TRegion> provinceList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
|
model.addAttribute("provinceList",provinceList);
|
//市
|
List<TRegion> cityList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", tOpenCity.getAreaId()));
|
model.addAttribute("cityList",cityList);
|
//区
|
List<TRegion> areaList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", tOpenCity.getCityId()));
|
model.addAttribute("areaList",areaList);
|
//经营业务
|
List<Map<String,Object>> businessList = tOpenCityService.getBusinessByCityId(tOpenCityId);
|
model.addAttribute("businessList",businessList);
|
// 机场/动车站点
|
List<TOpenCitySite> siteList = tOpenCitySiteMapper.selectList(new EntityWrapper<TOpenCitySite>()
|
.eq("openCityId", tOpenCityId)
|
.ne("flag",3));
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd");
|
for (TOpenCitySite openCitySite : siteList) {
|
String format = simpleDateFormat.format(openCitySite.getInsertTime());
|
openCitySite.setInsertTime1(format);
|
}
|
model.addAttribute("siteList",siteList);
|
return PREFIX + "tOpenCity_edit.html";
|
}
|
|
@RequestMapping(value = "/change")
|
@ResponseBody
|
public Object change(@RequestParam Integer id) {
|
List<TRegion> list = new ArrayList<>();
|
if (SinataUtil.isNotEmpty(id)){
|
list = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", id));
|
}
|
return list;
|
}
|
|
/**
|
* 获取城市管理列表
|
*/
|
@RequestMapping(value = "/list")
|
@ResponseBody
|
public Object list(String insertTime,String condition) {
|
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();
|
page.setRecords(tOpenCityService.getOpenCityList(page,beginTime,endTime,condition));
|
return super.packForBT(page);
|
}
|
|
/**
|
* 新增城市管理
|
*/
|
@RequestMapping(value = "/add")
|
@ResponseBody
|
public Object add(TOpenCity tOpenCity,@RequestParam String businessTypeStr,
|
String sites,
|
Integer areaId,Integer cityId,
|
Integer provinceId) {
|
//获取code
|
if (SinataUtil.isNotEmpty(areaId)){
|
TRegion area = tRegionService.selectById(areaId);
|
tOpenCity.setCode(area.getCode());
|
}
|
if (SinataUtil.isNotEmpty(cityId)){
|
TRegion city = tRegionService.selectById(cityId);
|
tOpenCity.setCode(city.getCode());
|
}
|
if (SinataUtil.isNotEmpty(provinceId)){
|
TRegion province = tRegionService.selectById(provinceId);
|
tOpenCity.setCode(province.getCode());
|
}
|
tOpenCity.setAreaId(areaId);
|
tOpenCity.setCityId(cityId);
|
tOpenCity.setProvinceId(provinceId);
|
//获取经纬度
|
String address = tOpenCity.getAreaName();
|
if (SinataUtil.isNotEmpty(tOpenCity.getCityName())){
|
address+=tOpenCity.getCityName();
|
}
|
if (SinataUtil.isNotEmpty(tOpenCity.getProvinceName())){
|
address+=tOpenCity.getProvinceName();
|
}
|
JSONObject positionObj = GaoDeMapUtil.getLngAndLat(address);
|
String longitude = positionObj.getString("longitude");
|
String latitude = positionObj.getString("latitude");
|
tOpenCity.setLon(Double.valueOf(longitude));
|
tOpenCity.setLat(Double.valueOf(latitude));
|
tOpenCity.setInsertTime(new Date());
|
tOpenCity.setInsertUser(ShiroKit.getUser().getId());
|
tOpenCityService.insert(tOpenCity);
|
|
//添加经营业务
|
testJSONStrToJSONArray(businessTypeStr,tOpenCity.getId());
|
// 添加机场/动车站点
|
JSONArray jsonArray = JSON.parseArray(sites);
|
int size = jsonArray.size();
|
for (int i = 0; i < size; i++){
|
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
TOpenCitySite openCitySite = new TOpenCitySite();
|
openCitySite.setOpenCityId(tOpenCity.getId());
|
String string = jsonObject.getString("lonAndLat");
|
// 去除转义符
|
String unescaped = string.replaceAll("& #40;", "(").replaceAll("& #41;", ")");
|
// 提取括号中的内容
|
Pattern pattern = Pattern.compile("\\(([^)]+)\\)");
|
Matcher matcher = pattern.matcher(unescaped);
|
if (matcher.find()) {
|
String lonAndLat = matcher.group(1);
|
System.out.println("括号中的内容: " + lonAndLat);
|
// 使用逗号分割字符串
|
String[] parts = lonAndLat.split(",");
|
// 提取需要的部分
|
String lon = parts[0];
|
String lat = parts[1];
|
openCitySite.setLon(lon);
|
openCitySite.setLat(lat);
|
}
|
openCitySite.setFlag(1);
|
openCitySite.setName(jsonObject.getString("name"));
|
openCitySite.setInsertTime(DateUtil.parse(jsonObject.getString("time")+" 00:00:00","yyyy-MM-dd HH:mm:ss"));
|
tOpenCitySiteMapper.insert(openCitySite);
|
}
|
return SUCCESS_TIP;
|
}
|
|
public void testJSONStrToJSONArray(String subArr,Integer tOpenCityId){
|
JSONArray jsonArray = JSON.parseArray(subArr);
|
int size = jsonArray.size();
|
for (int i = 0; i < size; i++){
|
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
TOpenCityBusiness business = new TOpenCityBusiness();
|
if (SinataUtil.isNotEmpty(jsonObject.getInteger("busId")) && jsonObject.getInteger("busId") != 0){
|
business = tOpenCityBusinessService.selectById(jsonObject.getInteger("busId"));
|
business.setUpdateTime(new Date());
|
business.setUpdateUser(ShiroKit.getUser().getId());
|
business.setFlag("2");
|
}else{
|
business.setInsertTime(DateUtil.parse(jsonObject.getString("time")+" 00:00:00","yyyy-MM-dd HH:mm:ss"));
|
business.setInsertUser(ShiroKit.getUser().getId());
|
}
|
business.setOpenCityId(tOpenCityId);
|
String type = jsonObject.getString("type");
|
Integer businessType = 0;
|
if ("专车".equals(type)){
|
businessType = 1;
|
}else if ("出租车".equals(type)){
|
businessType = 2;
|
}else if ("跨城".equals(type)){
|
businessType = 3;
|
}else if ("跨城小件物流".equals(type)){
|
businessType = 4;
|
}else if ("同城小件物流".equals(type)){
|
businessType = 5;
|
}else if ("包车".equals(type)){
|
businessType = 6;
|
}else if ("接送机".equals(type)){
|
businessType = 7;
|
}
|
business.setBusinessType(businessType);
|
business.setSort(jsonObject.getInteger("sort"));
|
if (SinataUtil.isNotEmpty(jsonObject.getInteger("busId")) && jsonObject.getInteger("busId") != 0){
|
tOpenCityBusinessService.updateById(business);
|
}else{
|
tOpenCityBusinessService.insert(business);
|
}
|
}
|
}
|
|
/**
|
* 删除城市管理
|
*/
|
@RequestMapping(value = "/delete")
|
@ResponseBody
|
public Object delete(@RequestParam Integer tOpenCityId) {
|
TOpenCity tOpenCity = tOpenCityService.selectById(tOpenCityId);
|
tOpenCity.setFlag("3");
|
tOpenCityService.updateById(tOpenCity);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改城市管理
|
*/
|
@RequestMapping(value = "/update")
|
@ResponseBody
|
public Object update(TOpenCity tOpenCity,@RequestParam String businessTypeStr,Integer areaId,Integer cityId,Integer provinceId,String sites) {
|
if (SinataUtil.isNotEmpty(areaId)){
|
TRegion area = tRegionService.selectById(areaId);
|
tOpenCity.setCode(area.getCode());
|
}
|
if (SinataUtil.isNotEmpty(cityId)){
|
TRegion city = tRegionService.selectById(cityId);
|
tOpenCity.setCode(city.getCode());
|
}
|
if (SinataUtil.isNotEmpty(provinceId)){
|
TRegion province = tRegionService.selectById(provinceId);
|
tOpenCity.setCode(province.getCode());
|
}
|
if (SinataUtil.isEmpty(areaId)){
|
tOpenCity.setAreaId(0);
|
tOpenCity.setAreaName("");
|
}else{
|
tOpenCity.setAreaId(areaId);
|
}
|
if (SinataUtil.isEmpty(cityId)){
|
tOpenCity.setCityId(0);
|
tOpenCity.setCityName("");
|
}else{
|
tOpenCity.setCityId(cityId);
|
}
|
if (SinataUtil.isEmpty(provinceId)){
|
tOpenCity.setProvinceId(0);
|
tOpenCity.setProvinceName("");
|
}else{
|
tOpenCity.setProvinceId(provinceId);
|
}
|
|
//获取经纬度
|
String address = tOpenCity.getAreaName();
|
if (SinataUtil.isNotEmpty(tOpenCity.getCityName())){
|
address+=tOpenCity.getCityName();
|
}
|
if (SinataUtil.isNotEmpty(tOpenCity.getProvinceName())){
|
address+=tOpenCity.getProvinceName();
|
}
|
JSONObject positionObj = GaoDeMapUtil.getLngAndLat(address);
|
String longitude = positionObj.getString("longitude");
|
String latitude = positionObj.getString("latitude");
|
tOpenCity.setLon(Double.valueOf(longitude));
|
tOpenCity.setLat(Double.valueOf(latitude));
|
tOpenCity.setUpdateTime(new Date());
|
tOpenCity.setUpdateUser(ShiroKit.getUser().getId());
|
tOpenCityService.updateById(tOpenCity);
|
|
//删除经营业务
|
TOpenCityBusiness business = new TOpenCityBusiness();
|
business.setFlag("3");
|
tOpenCityBusinessService.update(business,new EntityWrapper<TOpenCityBusiness>().eq("openCityId",tOpenCity.getId()));
|
//添加经营业务
|
testJSONStrToJSONArray(businessTypeStr,tOpenCity.getId());
|
// TOpenCitySite openCitySite = new TOpenCitySite();
|
// // 删除站点
|
// tOpenCitySiteMapper.update(openCitySite,new EntityWrapper<TOpenCitySite>().eq("openCityId",tOpenCity.getId()));
|
List<TOpenCitySite> openCityId = tOpenCitySiteMapper.selectList(new EntityWrapper<TOpenCitySite>()
|
.eq("openCityId", tOpenCity.getId()));
|
for (TOpenCitySite openCitySite : openCityId) {
|
openCitySite.setFlag(3);
|
tOpenCitySiteMapper.updateById(openCitySite);
|
}
|
// 添加站点
|
// 添加机场/动车站点
|
JSONArray jsonArray = JSON.parseArray(sites);
|
int size = jsonArray.size();
|
for (int i = 0; i < size; i++){
|
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
String string = jsonObject.getString("lonAndLat");
|
// 去除转义符
|
String unescaped = string.replaceAll("& #40;", "(").replaceAll("& #41;", ")");
|
// 提取括号中的内容
|
Pattern pattern = Pattern.compile("\\(([^)]+)\\)");
|
Matcher matcher = pattern.matcher(unescaped);
|
String lon = "";
|
String lat = "";
|
if (matcher.find()) {
|
String lonAndLat = matcher.group(1);
|
System.out.println("括号中的内容: " + lonAndLat);
|
// 使用逗号分割字符串
|
String[] parts = lonAndLat.split(",");
|
// 提取需要的部分
|
lon = parts[0];
|
lat = parts[1];
|
}
|
if (SinataUtil.isNotEmpty(jsonObject.getInteger("busId")) && jsonObject.getInteger("busId") != 0){
|
// 修改
|
TOpenCitySite openCitySite1 = tOpenCitySiteMapper.selectById(jsonObject.getInteger("busId"));
|
openCitySite1.setLon(lon);
|
openCitySite1.setLat(lat);
|
openCitySite1.setName(jsonObject.getString("name"));
|
openCitySite1.setFlag(2);
|
openCitySite1.setType(jsonObject.getInteger("siteType"));
|
tOpenCitySiteMapper.updateById(openCitySite1);
|
}else{
|
// 新增
|
TOpenCitySite openCitySite3 = new TOpenCitySite();
|
openCitySite3.setOpenCityId(tOpenCity.getId());
|
openCitySite3.setLon(lon);
|
openCitySite3.setLat(lat);
|
openCitySite3.setFlag(1);
|
openCitySite3.setName(jsonObject.getString("name"));
|
openCitySite3.setType(jsonObject.getInteger("siteType"));
|
openCitySite3.setInsertTime(DateUtil.parse(jsonObject.getString("time")+" 00:00:00","yyyy-MM-dd HH:mm:ss"));
|
tOpenCitySiteMapper.insert(openCitySite3);
|
}
|
|
}
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 城市管理详情
|
*/
|
@RequestMapping(value = "/detail/{tOpenCityId}")
|
@ResponseBody
|
public Object detail(@PathVariable("tOpenCityId") Integer tOpenCityId) {
|
return tOpenCityService.selectById(tOpenCityId);
|
}
|
}
|