DictController.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
  3. * <p>
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. * <p>
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. * <p>
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springblade.modules.system.controller;
  17. import io.swagger.annotations.*;
  18. import lombok.AllArgsConstructor;
  19. import org.springblade.core.boot.ctrl.BladeController;
  20. import org.springblade.core.mp.support.Condition;
  21. import org.springblade.core.tool.api.R;
  22. import org.springblade.core.tool.node.INode;
  23. import org.springblade.core.tool.utils.Func;
  24. import org.springblade.modules.system.entity.Dict;
  25. import org.springblade.modules.system.service.IDictService;
  26. import org.springblade.modules.system.vo.DictVO;
  27. import org.springblade.modules.system.wrapper.DictWrapper;
  28. import org.springframework.web.bind.annotation.*;
  29. import springfox.documentation.annotations.ApiIgnore;
  30. import javax.validation.Valid;
  31. import java.util.List;
  32. import java.util.Map;
  33. /**
  34. * 控制器
  35. *
  36. * @author Chill
  37. * @since 2018-12-24
  38. */
  39. @ApiIgnore
  40. @RestController
  41. @AllArgsConstructor
  42. @RequestMapping("/blade-system/dict")
  43. @Api(value = "字典", tags = "字典")
  44. public class DictController extends BladeController {
  45. private IDictService dictService;
  46. /**
  47. * 详情
  48. */
  49. @GetMapping("/detail")
  50. @ApiOperation(value = "详情", notes = "传入dict", position = 1)
  51. public R<DictVO> detail(Dict dict) {
  52. Dict detail = dictService.getOne(Condition.getQueryWrapper(dict));
  53. DictWrapper dictWrapper = new DictWrapper(dictService);
  54. return R.data(dictWrapper.entityVO(detail));
  55. }
  56. /**
  57. * 列表
  58. */
  59. @GetMapping("/list")
  60. @ApiImplicitParams({
  61. @ApiImplicitParam(name = "code", value = "字典编号", paramType = "query", dataType = "string"),
  62. @ApiImplicitParam(name = "dictValue", value = "字典名称", paramType = "query", dataType = "string")
  63. })
  64. @ApiOperation(value = "列表", notes = "传入dict", position = 2)
  65. public R<List<INode>> list(@ApiIgnore @RequestParam Map<String, Object> dict) {
  66. @SuppressWarnings("unchecked")
  67. List<Dict> list = dictService.list(Condition.getQueryWrapper(dict, Dict.class).lambda().orderByAsc(Dict::getSort));
  68. DictWrapper dictWrapper = new DictWrapper();
  69. return R.data(dictWrapper.listNodeVO(list));
  70. }
  71. /**
  72. * 获取字典树形结构
  73. *
  74. * @return
  75. */
  76. @GetMapping("/tree")
  77. @ApiOperation(value = "树形结构", notes = "树形结构", position = 3)
  78. public R<List<DictVO>> tree() {
  79. List<DictVO> tree = dictService.tree();
  80. return R.data(tree);
  81. }
  82. /**
  83. * 新增或修改
  84. */
  85. @PostMapping("/submit")
  86. @ApiOperation(value = "新增或修改", notes = "传入dict", position = 6)
  87. public R submit(@Valid @RequestBody Dict dict) {
  88. return R.status(dictService.saveOrUpdate(dict));
  89. }
  90. /**
  91. * 删除
  92. */
  93. @PostMapping("/remove")
  94. @ApiOperation(value = "物理删除", notes = "传入ids", position = 7)
  95. public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
  96. return R.status(dictService.removeByIds(Func.toIntList(ids)));
  97. }
  98. /**
  99. * 获取字典
  100. *
  101. * @return
  102. */
  103. @GetMapping("/dictionary")
  104. @ApiOperation(value = "获取字典", notes = "获取字典", position = 8)
  105. public R<List<Dict>> dictionary(String code) {
  106. List<Dict> tree = dictService.getList(code);
  107. return R.data(tree);
  108. }
  109. }