mitao
2024-04-30 ab4ea7b8f10c9b66aed9c2ea161a08b25c3851a7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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;
    }
}