日照智慧社区接口服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

102 lines
2.7 KiB

/**
* Copyright (c) 2018 人人开源 All rights reserved.
*
* https://www.renren.io
*
* 版权所有,侵权必究!
*/
package com.epmet.controller;
import com.epmet.commons.tools.exception.ErrorCode;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.AssertUtils;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.commons.tools.validator.group.AddGroup;
import com.epmet.commons.tools.validator.group.DefaultGroup;
import com.epmet.commons.tools.validator.group.UpdateGroup;
import com.epmet.dto.SysRegionDTO;
import com.epmet.dto.region.RegionProvince;
import com.epmet.service.SysRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* 行政区域
*
* @author Mark sunlightcs@gmail.com
*/
@RestController
@RequestMapping("region")
public class SysRegionController {
@Autowired
private SysRegionService sysRegionService;
@GetMapping("list")
public Result<List<SysRegionDTO>> list(@RequestParam Map<String, Object> params){
List<SysRegionDTO> list = sysRegionService.list(params);
return new Result<List<SysRegionDTO>>().ok(list);
}
@GetMapping("tree")
public Result<List<Map<String, Object>>> tree(){
List<Map<String, Object>> list = sysRegionService.getTreeList();
return new Result<List<Map<String, Object>>>().ok(list);
}
@GetMapping("{id}")
public Result<SysRegionDTO> get(@PathVariable("id") Long id){
SysRegionDTO data = sysRegionService.get(id);
return new Result<SysRegionDTO>().ok(data);
}
@PostMapping
public Result save(@RequestBody SysRegionDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
sysRegionService.save(dto);
return new Result();
}
@PutMapping
public Result update(@RequestBody SysRegionDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
sysRegionService.update(dto);
return new Result();
}
@DeleteMapping("{id}")
public Result delete(@PathVariable("id") Long id){
//效验数据
AssertUtils.isNull(id, "id");
int count = sysRegionService.getCountByPid(id);
if(count > 0){
throw new RenException(ErrorCode.REGION_SUB_DELETE_ERROR);
}
sysRegionService.delete(id);
return new Result();
}
@GetMapping("region")
public Result<List<RegionProvince>> region(@RequestParam(value = "threeLevel", defaultValue = "true") boolean threeLevel){
List<RegionProvince> list = sysRegionService.getRegion(threeLevel);
return new Result<List<RegionProvince>>().ok(list);
}
}