package com.kidgrow.usercenter.controller;
|
|
import com.kidgrow.common.controller.BaseController;
|
import com.kidgrow.common.model.PageResult;
|
import com.kidgrow.common.model.ResultBody;
|
import com.kidgrow.usercenter.model.SysArea;
|
import com.kidgrow.usercenter.service.ISysAreaService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.validation.BindingResult;
|
import org.springframework.validation.ObjectError;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.validation.Valid;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
|
|
/**
|
* 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
|
* @Description: 省市区数据表
|
* @Project: 用户中心
|
* @CreateDate: Created in 2020-04-02 18:32:36 <br>
|
* @Author: <a href="4345453@kidgrow.com">liuke</a>
|
* @version: 1.0
|
*/
|
@Slf4j
|
@RestController
|
@RequestMapping("/sysarea")
|
@Api(tags = "省市区数据表")
|
public class SysAreaController extends BaseController{
|
@Autowired
|
private ISysAreaService sysAreaService;
|
|
/**
|
* 列表
|
*/
|
@ApiOperation(value = "查询列表")
|
@GetMapping("/findAlls")
|
public PageResult<SysArea> findAlls(@RequestParam Map<String, Object> params) {
|
return sysAreaService.findList(params);
|
}
|
@ApiOperation(value = "查询列表")
|
@GetMapping("/getListByMap")
|
public ResultBody getListByMap(@RequestParam Map<String, Object> params) {
|
return sysAreaService.getListByMap(params);
|
}
|
|
/**
|
* 查询
|
*/
|
@ApiOperation(value = "查询")
|
@GetMapping("/{id}")
|
public ResultBody findById(@PathVariable Long id) {
|
SysArea model = sysAreaService.getById(id);
|
return ResultBody.ok().data(model).msg("查询成功");
|
}
|
|
/**
|
* 根据SysArea当做查询条件进行查询
|
*/
|
@ApiOperation(value = "根据SysArea当做查询条件进行查询")
|
@PostMapping("/query")
|
public ResultBody findByObject(@RequestBody SysArea sysArea) {
|
SysArea model = sysAreaService.findByObject(sysArea);
|
return ResultBody.ok().data(model).msg("查询成功");
|
}
|
|
/**
|
* 新增or更新
|
*/
|
@ApiOperation(value = "保存")
|
@PostMapping
|
public ResultBody save(@Valid @RequestBody SysArea sysArea, BindingResult bindingResult) {
|
List<String> errMsg= new ArrayList<>();
|
if (bindingResult.hasErrors()) {
|
for (ObjectError error : bindingResult.getAllErrors()) {
|
errMsg.add(error.getDefaultMessage());
|
}
|
return ResultBody.failed().msg(errMsg.toString());
|
} else {
|
//如果父级id是空的,默认填-1
|
if (sysArea.getAreaParentId()==null) {
|
sysArea.setAreaParentId(-1L);
|
}
|
//添加的时候得判断主键唯一
|
if (sysArea.getIsDel()==null) {
|
SysArea model =sysAreaService.getById(sysArea.getId());
|
if (model!=null)
|
{
|
return ResultBody.failed().msg("区域编号已存在!");
|
}
|
}
|
boolean v= sysAreaService.saveOrUpdate(sysArea);
|
if(v) {
|
return ResultBody.ok().data(sysArea).msg("保存成功");
|
}
|
else {
|
return ResultBody.failed().msg("保存失败");
|
}
|
}
|
}
|
|
/**
|
* 删除
|
*/
|
@ApiOperation(value = "删除")
|
@DeleteMapping("/{id}")
|
public ResultBody delete(@PathVariable Long id) {
|
boolean v= sysAreaService.removeById(id);
|
if(v) {
|
return ResultBody.ok().msg("删除成功");
|
}
|
else {
|
return ResultBody.failed().msg("删除失败");
|
}
|
}
|
/**
|
* 修改状态
|
*
|
* @param params
|
* @return
|
*/
|
@ApiOperation(value = "修改反馈数据状态")
|
@GetMapping("/updateEnabled")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Integer"),
|
@ApiImplicitParam(name = "enabled", value = "是否启用", required = true, dataType = "Boolean")
|
})
|
public ResultBody updateEnabled(@RequestParam Map<String, Object> params) {
|
if (params.size()==0)
|
{
|
return ResultBody.failed().msg("参数异常!");
|
}
|
return sysAreaService.updateEnabled(params);
|
}
|
}
|