| | |
| | | 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.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | 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; |
| | | |
| | | /** |
| | |
| | | * @since 2022-09-16 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/sccg-region") |
| | | @RequestMapping("/sccg_region") |
| | | @Api(tags = "行政区域") |
| | | public class SccgRegionController extends BaseController { |
| | | |
| | | @Resource |
| | | private RedisService redisService; |
| | | |
| | | @Resource |
| | | private ISccgRegionService iSccgRegionService; |
| | |
| | | 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); |
| | | } |
| | | } |