liusuyi
2026-05-06 99ab0d46d30b095d0e1c9d31349f42e0cefc9881
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package com.ard.qs.controller;
 
import com.ard.common.core.web.controller.BaseController;
import com.ard.common.core.web.domain.AjaxResult;
import com.ard.common.core.web.page.TableDataInfo;
import com.ard.common.log.annotation.Log;
import com.ard.common.log.enums.BusinessType;
import com.ard.qs.api.domain.QsRegion;
import com.ard.qs.domain.QsRegionTree;
import com.ard.qs.service.IQsRegionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * 区域管理
 *
 * @FileName QsRegionController
 * @Description
 * @Author fengcheng
 * @date 2026-04-13
 **/
@Slf4j
@RestController
@RequestMapping("/region")
public class QsRegionController extends BaseController {
 
    @Autowired
    private IQsRegionService qsRegionService;
 
    /**
     * 添加区域
     *
     * @param region 区域信息
     */
    @Log(title = "区域管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody QsRegion region) {
        qsRegionService.add(region);
        return AjaxResult.success();
    }
 
    /**
     * 更新区域
     *
     * @param region
     */
    @Log(title = "区域管理", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult update(@RequestBody QsRegion region) {
        qsRegionService.update(region);
        return AjaxResult.success();
    }
 
    /**
     * 删除区域
     *
     * @param id 区域ID
     */
    @Log(title = "区域管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable Integer id) {
        Assert.notNull(id, "区域ID需要存在");
        boolean result = qsRegionService.deleteByDeviceId(id);
        if (!result) {
            throw new RuntimeException("移除失败");
        }
        return AjaxResult.success();
    }
 
    /**
     * 查询区域节点
     *
     * @param parent    所属行政区划编号
     * @param hasDevice 是否查询设备
     * @return
     */
    @GetMapping("/tree/list")
    public AjaxResult queryForTree(@RequestParam(required = false) Integer parent, @RequestParam(required = false) Boolean hasDevice) {
        List<QsRegionTree> list = qsRegionService.queryForTree(parent, hasDevice);
        return success(list);
    }
 
    /**
     * 查询区域节点设备
     *
     * @return
     */
    @GetMapping("/device/list")
    public AjaxResult queryForDevice() {
        List<QsRegionTree> list = qsRegionService.queryForDevice();
        return success(list);
    }
 
    /**
     * 查询区域
     *
     * @param query 要搜索的内容
     * @return
     */
 
    @GetMapping("/tree/query")
    public TableDataInfo queryTree(Integer pageNum, Integer pageSize, String query) {
        startPage();
        List<QsRegion> list = qsRegionService.queryList(pageNum, pageSize, query);
        return getDataTable(list);
    }
 
    /**
     * 获取所属的行政区划下的行政区划
     *
     * @param parent 所属的行政区划
     * @return
     */
    @GetMapping("/base/child/list")
    public AjaxResult getAllChild(@RequestParam(required = false) String parent) {
        if (ObjectUtils.isEmpty(parent)) {
            parent = null;
        }
        List<QsRegion> list = qsRegionService.getAllChild(parent);
        return success(list);
    }
}