package com.sinata.modular.system.controller;
|
|
import com.baomidou.mybatisplus.enums.SqlLike;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.sinata.core.base.controller.BaseController;
|
import com.sinata.modular.system.model.TCityRegion;
|
import com.sinata.modular.system.service.ITCityRegionService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.util.StringUtils;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
/**
|
* 城市三级联动
|
* @author goku
|
*/
|
@Controller
|
@RequestMapping("/cityRegion")
|
public class CityRegionController extends BaseController {
|
|
@Autowired
|
private ITCityRegionService cityRegionService;
|
|
/**
|
* 根据上级城市ID,查询下级城市
|
*/
|
@ResponseBody
|
@GetMapping("/getListByParentId")
|
public Object getListByParentId(Integer parentId, String code1, String code2) {
|
if(parentId != null && parentId != -1) {
|
return cityRegionService.selectList(
|
new EntityWrapper<TCityRegion>()
|
.setSqlSelect("id, code, name")
|
.eq("parent_id", parentId)
|
);
|
} else if(!StringUtils.isEmpty(code1) && !code1.equals("-1")) {
|
return cityRegionService.selectList(
|
new EntityWrapper<TCityRegion>()
|
.setSqlSelect("id, code, name")
|
.like("code", code1.substring(0,2) + "%" + "00", SqlLike.CUSTOM)
|
.ne("code", code1.substring(0,2) + "0000")
|
);
|
} else if(!StringUtils.isEmpty(code2) && !code2.equals("-1")) {
|
return cityRegionService.selectList(
|
new EntityWrapper<TCityRegion>()
|
.setSqlSelect("id, code, name")
|
.like("code", code2.substring(0,4), SqlLike.RIGHT)
|
.ne("code", code2.substring(0,4)+"00")
|
);
|
}
|
return null;
|
}
|
}
|