package com.sinata.modular.system.controller;
|
|
import cn.hutool.core.util.StrUtil;
|
import com.baomidou.mybatisplus.enums.SqlLike;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
import com.baomidou.mybatisplus.plugins.Page;
|
import com.sinata.common.enums.EnumIsDelete;
|
import com.sinata.core.base.controller.BaseController;
|
import com.sinata.core.base.tips.ErrorTip;
|
import com.sinata.core.common.annotion.BussinessLog;
|
import com.sinata.core.common.annotion.Permission;
|
import com.sinata.core.common.constant.factory.PageFactory;
|
import com.sinata.core.log.LogObjectHolder;
|
import com.sinata.modular.system.model.AreaCity;
|
import com.sinata.modular.system.model.TCityRegion;
|
import com.sinata.modular.system.service.IAreaCityService;
|
import com.sinata.modular.system.service.ITCityRegionService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.ui.Model;
|
import org.springframework.util.StringUtils;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 区域城市控制器
|
* @author goku
|
*/
|
@Controller
|
@RequestMapping("/areaCity")
|
public class AreaCityController extends BaseController {
|
|
private String PREFIX = "/system/areaCity/";
|
|
@Autowired
|
private IAreaCityService areaCityService;
|
|
@Autowired
|
private ITCityRegionService cityRegionService;
|
|
/**
|
* 跳转到区域城市首页
|
*/
|
@RequestMapping("")
|
public String index() {
|
return PREFIX + "areaCity.html";
|
}
|
|
/**
|
* 跳转到添加区域城市
|
*/
|
@RequestMapping("/areaCity_add")
|
public String areaCityAdd(Model model) {
|
// 省市区三级联动
|
List<TCityRegion> cityList = cityRegionService.selectList(
|
new EntityWrapper<TCityRegion>()
|
.setSqlSelect("code, name")
|
.eq("parent_id", 0)
|
);
|
model.addAttribute("cityList", cityList);
|
return PREFIX + "areaCity_add.html";
|
}
|
|
/**
|
* 跳转到修改区域城市
|
*/
|
@RequestMapping("/areaCity_update/{areaCityId}")
|
public String areaCityUpdate(@PathVariable Integer areaCityId, Model model) {
|
// 省市区三级联动
|
List<TCityRegion> cityList = cityRegionService.selectList(
|
new EntityWrapper<TCityRegion>()
|
.setSqlSelect("code, name")
|
.eq("parent_id", 0)
|
);
|
model.addAttribute("cityList", cityList);
|
|
AreaCity areaCity = areaCityService.selectById(areaCityId);
|
model.addAttribute("item",areaCity);
|
LogObjectHolder.me().set(areaCity);
|
return PREFIX + "areaCity_edit.html";
|
}
|
|
/**
|
* 获取区域城市列表
|
*/
|
@ResponseBody
|
@RequestMapping(value = "/list")
|
public Object list(String beginTime, String endTime, String condition) {
|
Page<Map<String, Object>> page = new PageFactory().defaultPage();
|
Wrapper wrapper = new EntityWrapper<AreaCity>().eq("is_delete", 0).orderBy("id", false);
|
|
// 时间搜索
|
if(!StringUtils.isEmpty(beginTime)) {
|
wrapper.ge("create_time", beginTime + " 00:00:00");
|
}
|
if(!StringUtils.isEmpty(endTime)) {
|
wrapper.le("create_time", endTime + " 23:59:59");
|
}
|
if (StrUtil.isNotBlank(condition)) {
|
wrapper.like("province_name", condition)
|
.or().like("city_name", condition)
|
.or().like("county_name", condition);
|
}
|
|
// 查询数据列表
|
List<Map<String, Object>> list = areaCityService.selectMapsPage(page, wrapper).getRecords();
|
|
page.setRecords(list);
|
return super.packForBT(page);
|
}
|
|
/**
|
* 新增区域城市
|
*/
|
@Permission
|
@ResponseBody
|
@BussinessLog(value = "新增区域城市")
|
@RequestMapping(value = "/add")
|
public Object add(AreaCity areaCity) {
|
// 获取城市有效信息
|
int count = areaCityService.selectCount(
|
new EntityWrapper<AreaCity>()
|
.eq("is_delete", 0)
|
.eq("county_code", areaCity.getCountyCode())
|
);
|
if (count > 0) {
|
return new ErrorTip(500, "城市已存在!");
|
}
|
|
// 获取城市信息
|
String[] city = cityRegionService.getProvinceCityCountyName(areaCity.getCountyCode());
|
// 省市区赋值
|
areaCity.setProvinceName(city[0]);
|
areaCity.setCityName(city[1]);
|
areaCity.setCountyName(city[2]);
|
|
areaCityService.insert(areaCity);
|
return SUCCESS_TIP;
|
}
|
/**
|
* 删除/批量删除
|
*/
|
@Permission
|
@ResponseBody
|
@BussinessLog(value = "删除/批量删除区域城市")
|
@RequestMapping(value = "/delete")
|
public Object delete(@RequestParam String ids) {
|
// 逻辑删除
|
areaCityService.updateForSet("is_delete = 1", new EntityWrapper<AreaCity>().in("id", ids.split(",")));
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改区域城市
|
*/
|
@Permission
|
@ResponseBody
|
@BussinessLog(value = "修改区域城市")
|
@RequestMapping(value = "/update")
|
public Object update(AreaCity areaCity) {
|
// 获取城市有效信息
|
int count = areaCityService.selectCount(
|
new EntityWrapper<AreaCity>()
|
.eq("is_delete", 0)
|
.eq("county_code", areaCity.getCountyCode())
|
.ne("id", areaCity.getId())
|
);
|
if (count > 0) {
|
return new ErrorTip(500, "城市已存在!");
|
}
|
|
// 获取城市信息
|
String[] city = cityRegionService.getProvinceCityCountyName(areaCity.getCountyCode());
|
// 省市区赋值
|
areaCity.setProvinceName(city[0]);
|
areaCity.setCityName(city[1]);
|
areaCity.setCountyName(city[2]);
|
|
areaCityService.updateById(areaCity);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改区域城市状态
|
*/
|
@ResponseBody
|
@BussinessLog(value = "修改区域城市状态")
|
@RequestMapping(value = "/updateState")
|
public Object updateState(Integer areaCityId, Integer state) {
|
areaCityService.updateForSet("is_open = " + state, new EntityWrapper<AreaCity>().eq("id", areaCityId));
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 跳转区域城市详情
|
*/
|
@RequestMapping(value = "/detail/{areaCityId}")
|
public Object detail(@PathVariable("areaCityId") Integer areaCityId, Model model) {
|
AreaCity areaCity = areaCityService.selectById(areaCityId);
|
model.addAttribute("item",areaCity);
|
return PREFIX + "areaCity_detail.html";
|
}
|
|
/**
|
* 查询开通城市
|
*/
|
@ResponseBody
|
@GetMapping("/getListByCode")
|
public Object getListByParentId(String code1, String code2) {
|
Wrapper<AreaCity> wrapper = new EntityWrapper<AreaCity>()
|
.eq("is_open", 1)
|
.eq("is_delete", EnumIsDelete.EXISTED.index);
|
if (StrUtil.isNotBlank(code1) && !code1.equals("-1")) {
|
wrapper.eq("province_code", code1)
|
.like("city_code", code1.substring(0, 2) + "%" + "00", SqlLike.CUSTOM)
|
.groupBy("city_code");
|
return areaCityService.selectList(wrapper);
|
} else if (StrUtil.isNotBlank(code2) && !code2.equals("-1")) {
|
wrapper.eq("city_code", code2)
|
.like("county_code", code2.substring(0, 4), SqlLike.RIGHT)
|
.groupBy("county_code");
|
return areaCityService.selectList(wrapper);
|
}
|
return null;
|
}
|
}
|