zhanghua
2023-11-21 bbe76086f95dfb34e942d9f2801e17db38391c68
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
package com.ycl.controller.region;
 
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ycl.api.CommonPage;
import com.ycl.api.CommonResult;
import com.ycl.controller.BaseController;
import com.ycl.entity.region.SccgRegion;
import com.ycl.service.redis.RedisService;
import com.ycl.service.region.ISccgRegionService;
import com.ycl.utils.redis.RedisKey;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
 
/**
 * <p>
 * 遂昌行政区域 前端控制器
 * </p>
 *
 * @author lyq
 * @since 2022-09-16
 */
@RestController
@RequestMapping("/sccg_region")
@Api(tags = "行政区域")
public class SccgRegionController extends BaseController {
 
    @Resource
    private RedisService redisService;
 
    @Resource
    private ISccgRegionService iSccgRegionService;
 
    @ApiOperation("树结构")
    @GetMapping("/getTree")
    public CommonResult<List<SccgRegion>> getTree() {
        List<SccgRegion> treeList = iSccgRegionService.getTree();
        return CommonResult.success(treeList);
    }
 
    @ApiOperation(value = "添加行政区域")
    @RequestMapping(value = "/addRegion", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult addRegion(@Validated @RequestBody SccgRegion sccgRegion) {
        redisService.del(RedisKey.SCCG_REGION);
        return CommonResult.success(iSccgRegionService.save(sccgRegion));
    }
 
    @ApiOperation(value = "获取行政区域分页查询")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<SccgRegion>> list(@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                     @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        Page<SccgRegion> list = iSccgRegionService.list(pageSize, pageNum);
        return CommonResult.success(CommonPage.restPage(list));
    }
 
 
    @ApiOperation("获取指定行政区域")
    @RequestMapping(value = "/getRegion/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<SccgRegion> getMessage(@PathVariable Long id) {
        SccgRegion sccgRegion = iSccgRegionService.getById(id);
        return CommonResult.success(sccgRegion);
    }
 
    @ApiOperation("修改指定行政区域")
    @RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult update(@PathVariable Long id, @RequestBody SccgRegion sccgRegion) {
        redisService.del(RedisKey.SCCG_REGION);
        sccgRegion.setId(id);
        boolean success = iSccgRegionService.updateById(sccgRegion);
        if (success) {
            return CommonResult.success(null);
        }
        return CommonResult.failed();
    }
 
    @ApiOperation("批量删除行政区域")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult delete(@RequestParam("ids") List<Long> ids) {
        redisService.del(RedisKey.SCCG_REGION);
        boolean success = iSccgRegionService.removeBatchByIds(ids);
        if (success) {
            return CommonResult.success(null);
        }
        return CommonResult.failed();
    }
 
    @ApiOperation("获取子类")
    @GetMapping("/getChildren/{parentId}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId", value = "顶级parentId=0")
    })
    public CommonResult<List<SccgRegion>> getChildren(@PathVariable Long parentId) {
        List<SccgRegion> treeList = iSccgRegionService.getChildren(parentId);
        return CommonResult.success(treeList);
    }
}