DictController.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * Neither the name of the dreamlu.net developer nor the names of its
  13. * contributors may be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. * Author: Chill 庄骞 (smallchill@163.com)
  16. */
  17. package org.springblade.modules.system.controller;
  18. import io.swagger.annotations.*;
  19. import lombok.AllArgsConstructor;
  20. import org.springblade.core.boot.ctrl.BladeController;
  21. import org.springblade.core.mp.support.Condition;
  22. import org.springblade.core.tool.api.R;
  23. import org.springblade.core.tool.node.INode;
  24. import org.springblade.core.tool.utils.Func;
  25. import org.springblade.modules.system.entity.Dict;
  26. import org.springblade.modules.system.service.IDictService;
  27. import org.springblade.modules.system.vo.DictVO;
  28. import org.springblade.modules.system.wrapper.DictWrapper;
  29. import org.springframework.web.bind.annotation.*;
  30. import springfox.documentation.annotations.ApiIgnore;
  31. import javax.validation.Valid;
  32. import java.util.List;
  33. import java.util.Map;
  34. /**
  35. * 控制器
  36. *
  37. * @author Chill
  38. * @since 2018-12-24
  39. */
  40. @ApiIgnore
  41. @RestController
  42. @AllArgsConstructor
  43. @RequestMapping("/blade-system/dict")
  44. @Api(value = "字典", tags = "字典")
  45. public class DictController extends BladeController {
  46. private IDictService dictService;
  47. /**
  48. * 详情
  49. */
  50. @GetMapping("/detail")
  51. @ApiOperation(value = "详情", notes = "传入dict", position = 1)
  52. public R<DictVO> detail(Dict dict) {
  53. Dict detail = dictService.getOne(Condition.getQueryWrapper(dict));
  54. DictWrapper dictWrapper = new DictWrapper(dictService);
  55. return R.data(dictWrapper.entityVO(detail));
  56. }
  57. /**
  58. * 列表
  59. */
  60. @GetMapping("/list")
  61. @ApiImplicitParams({
  62. @ApiImplicitParam(name = "code", value = "字典编号", paramType = "query", dataType = "string"),
  63. @ApiImplicitParam(name = "dictValue", value = "字典名称", paramType = "query", dataType = "string")
  64. })
  65. @ApiOperation(value = "列表", notes = "传入dict", position = 2)
  66. public R<List<INode>> list(@ApiIgnore @RequestParam Map<String, Object> dict) {
  67. @SuppressWarnings("unchecked")
  68. List<Dict> list = dictService.list(Condition.getQueryWrapper(dict, Dict.class).lambda().orderByAsc(Dict::getSort));
  69. DictWrapper dictWrapper = new DictWrapper();
  70. return R.data(dictWrapper.listNodeVO(list));
  71. }
  72. /**
  73. * 获取字典树形结构
  74. *
  75. * @return
  76. */
  77. @GetMapping("/tree")
  78. @ApiOperation(value = "树形结构", notes = "树形结构", position = 3)
  79. public R<List<DictVO>> tree() {
  80. List<DictVO> tree = dictService.tree();
  81. return R.data(tree);
  82. }
  83. /**
  84. * 新增或修改
  85. */
  86. @PostMapping("/submit")
  87. @ApiOperation(value = "新增或修改", notes = "传入dict", position = 6)
  88. public R submit(@Valid @RequestBody Dict dict) {
  89. return R.status(dictService.saveOrUpdate(dict));
  90. }
  91. /**
  92. * 删除
  93. */
  94. @PostMapping("/remove")
  95. @ApiOperation(value = "物理删除", notes = "传入ids", position = 7)
  96. public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
  97. return R.status(dictService.removeByIds(Func.toIntList(ids)));
  98. }
  99. /**
  100. * 获取字典
  101. *
  102. * @return
  103. */
  104. @GetMapping("/dictionary")
  105. @ApiOperation(value = "获取字典", notes = "获取字典", position = 8)
  106. public R<List<Dict>> dictionary(String code) {
  107. List<Dict> tree = dictService.getList(code);
  108. return R.data(tree);
  109. }
  110. }