103 lines
3.6 KiB
Java
103 lines
3.6 KiB
Java
package com.cnbm.admin.controller;
|
||
|
||
import com.cnbm.admin.annotation.LogOperation;
|
||
import com.cnbm.admin.dto.SysDictDataDTO;
|
||
import com.cnbm.admin.service.SysDictDataService;
|
||
import com.cnbm.common.constant.Constant;
|
||
import com.cnbm.common.page.PageData;
|
||
import com.cnbm.common.utils.Result;
|
||
import com.cnbm.common.validator.AssertUtils;
|
||
import com.cnbm.common.validator.ValidatorUtils;
|
||
import com.cnbm.common.validator.group.DefaultGroup;
|
||
import com.cnbm.common.validator.group.UpdateGroup;
|
||
import io.swagger.annotations.Api;
|
||
import io.swagger.annotations.ApiImplicitParam;
|
||
import io.swagger.annotations.ApiImplicitParams;
|
||
import io.swagger.annotations.ApiOperation;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.security.access.prepost.PreAuthorize;
|
||
import org.springframework.web.bind.annotation.*;
|
||
import springfox.documentation.annotations.ApiIgnore;
|
||
|
||
import java.util.Map;
|
||
|
||
/**
|
||
* @Author weihongyang
|
||
* @Date 2022/6/12 10:55 AM
|
||
* @Version 1.0
|
||
*/
|
||
@RestController
|
||
@RequestMapping("sys/dict/data")
|
||
@Api(tags="字典数据")
|
||
public class SysDictDataController {
|
||
@Autowired
|
||
private SysDictDataService sysDictDataService;
|
||
|
||
@GetMapping("page")
|
||
@ApiOperation("字典数据")
|
||
@ApiImplicitParams({
|
||
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") ,
|
||
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
|
||
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
|
||
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String") ,
|
||
@ApiImplicitParam(name = "dictLabel", value = "字典标签", paramType = "query", dataType="String"),
|
||
@ApiImplicitParam(name = "dictValue", value = "字典值", paramType = "query", dataType="String")
|
||
})
|
||
@PreAuthorize("@ex.hasAuthority('sys:dept:page')")
|
||
public Result<PageData<SysDictDataDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
|
||
//字典类型
|
||
PageData<SysDictDataDTO> page = sysDictDataService.page(params);
|
||
|
||
return new Result<PageData<SysDictDataDTO>>().ok(page);
|
||
}
|
||
|
||
@GetMapping("{id}")
|
||
@ApiOperation("信息")
|
||
@PreAuthorize("@ex.hasAuthority('sys:dict:info')")
|
||
public Result<SysDictDataDTO> get(@PathVariable("id") Long id){
|
||
SysDictDataDTO data = sysDictDataService.get(id);
|
||
|
||
return new Result<SysDictDataDTO>().ok(data);
|
||
}
|
||
|
||
@PostMapping
|
||
@ApiOperation("保存")
|
||
@LogOperation("保存")
|
||
@PreAuthorize("@ex.hasAuthority('sys:dict:save')")
|
||
public Result save(@RequestBody SysDictDataDTO dto){
|
||
//效验数据
|
||
ValidatorUtils.validateEntity(dto, DefaultGroup.class);
|
||
|
||
sysDictDataService.save(dto);
|
||
|
||
return new Result();
|
||
}
|
||
|
||
@PutMapping
|
||
@ApiOperation("修改")
|
||
@LogOperation("修改")
|
||
@PreAuthorize("@ex.hasAuthority('sys:dict:update')")
|
||
public Result update(@RequestBody SysDictDataDTO dto){
|
||
//效验数据
|
||
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
|
||
|
||
sysDictDataService.update(dto);
|
||
|
||
return new Result();
|
||
}
|
||
|
||
@DeleteMapping
|
||
@ApiOperation("删除")
|
||
@LogOperation("删除")
|
||
@PreAuthorize("@ex.hasAuthority('sys:dict:delete')")
|
||
public Result delete(@RequestBody Long[] ids){
|
||
//效验数据
|
||
AssertUtils.isArrayEmpty(ids, "id");
|
||
|
||
sysDictDataService.delete(ids);
|
||
|
||
return new Result();
|
||
}
|
||
|
||
}
|