ProductclassifyController.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package jnpf.controller;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import io.swagger.v3.oas.annotations.Operation;
  4. import io.swagger.v3.oas.annotations.Parameter;
  5. import io.swagger.v3.oas.annotations.Parameters;
  6. import io.swagger.v3.oas.annotations.tags.Tag;
  7. import jnpf.base.ActionResult;
  8. import jnpf.base.controller.SuperController;
  9. import jnpf.base.vo.ListVO;
  10. import jnpf.constant.MsgCode;
  11. import jnpf.entity.ProductclassifyEntity;
  12. import jnpf.model.productclassify.*;
  13. import jnpf.service.ProductclassifyService;
  14. import jnpf.util.JsonUtil;
  15. import jnpf.util.treeutil.SumTree;
  16. import jnpf.util.treeutil.TreeDotUtils;
  17. import lombok.extern.slf4j.Slf4j;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.web.bind.annotation.*;
  20. import jakarta.validation.Valid;
  21. import java.util.List;
  22. /**
  23. * 产品分类
  24. *
  25. * @版本: V3.1.0
  26. * @版权: 引迈信息技术有限公司(https://www.jnpfsoft.com)
  27. * @作者: JNPF开发平台组
  28. * @日期: 2021-07-10 14:34:04
  29. */
  30. @Slf4j
  31. @RestController
  32. @Tag(name = "产品分类", description = "Classify")
  33. @RequestMapping("/api/extend/saleOrder/Classify")
  34. public class ProductclassifyController extends SuperController<ProductclassifyService, ProductclassifyEntity> {
  35. @Autowired
  36. private ProductclassifyService productclassifyService;
  37. /**
  38. * 列表
  39. *
  40. * @return
  41. */
  42. @GetMapping
  43. @Operation(summary = "列表")
  44. @SaCheckPermission("extend.orderDemo")
  45. public ActionResult<ListVO<ProductclassifyListVO>> list() {
  46. List<ProductclassifyEntity> data = productclassifyService.getList();
  47. List<ProductclassifyModel> modelList = JsonUtil.getJsonToList(data, ProductclassifyModel.class);
  48. List<SumTree<ProductclassifyModel>> sumTrees = TreeDotUtils.convertListToTreeDot(modelList);
  49. List<ProductclassifyListVO> list = JsonUtil.getJsonToList(sumTrees, ProductclassifyListVO.class);
  50. ListVO vo = new ListVO();
  51. vo.setList(list);
  52. return ActionResult.success(vo);
  53. }
  54. /**
  55. * 创建
  56. *
  57. * @param classifyCrForm 分类模型
  58. * @return
  59. */
  60. @PostMapping
  61. @Operation(summary = "创建")
  62. @Parameters({
  63. @Parameter(name = "classifyCrForm", description = "分类模型", required = true),
  64. })
  65. @SaCheckPermission("extend.orderDemo")
  66. public ActionResult create(@RequestBody @Valid ProductclassifyCrForm classifyCrForm) {
  67. ProductclassifyEntity entity = JsonUtil.getJsonToBean(classifyCrForm, ProductclassifyEntity.class);
  68. productclassifyService.create(entity);
  69. return ActionResult.success(MsgCode.SU001.get());
  70. }
  71. /**
  72. * 信息
  73. *
  74. * @param id 主键
  75. * @return
  76. */
  77. @GetMapping("/{id}")
  78. @Operation(summary = "信息")
  79. @Parameters({
  80. @Parameter(name = "id", description = "主键", required = true),
  81. })
  82. @SaCheckPermission("extend.orderDemo")
  83. public ActionResult<ProductclassifyInfoVO> info(@PathVariable("id") String id) {
  84. ProductclassifyEntity entity = productclassifyService.getInfo(id);
  85. ProductclassifyInfoVO vo = JsonUtil.getJsonToBean(entity, ProductclassifyInfoVO.class);
  86. return ActionResult.success(vo);
  87. }
  88. /**
  89. * 更新
  90. *
  91. * @param id 主键
  92. * @param classifyUpForm 分类模型
  93. * @return
  94. */
  95. @PutMapping("/{id}")
  96. @Operation(summary = "更新")
  97. @Parameters({
  98. @Parameter(name = "id", description = "主键", required = true),
  99. @Parameter(name = "classifyUpForm", description = "分类模型", required = true),
  100. })
  101. @SaCheckPermission("extend.orderDemo")
  102. public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid ProductclassifyUpForm classifyUpForm) {
  103. ProductclassifyEntity entity = JsonUtil.getJsonToBean(classifyUpForm, ProductclassifyEntity.class);
  104. boolean ok = productclassifyService.update(id, entity);
  105. if (ok) {
  106. return ActionResult.success(MsgCode.SU004.get());
  107. }
  108. return ActionResult.fail(MsgCode.FA002.get());
  109. }
  110. /**
  111. * 删除
  112. *
  113. * @param id 主键
  114. * @return
  115. */
  116. @DeleteMapping("/{id}")
  117. @Operation(summary = "删除")
  118. @Parameters({
  119. @Parameter(name = "id", description = "主键", required = true),
  120. })
  121. @SaCheckPermission("extend.orderDemo")
  122. public ActionResult delete(@PathVariable("id") String id) {
  123. ProductclassifyEntity entity = productclassifyService.getInfo(id);
  124. if (entity != null) {
  125. productclassifyService.delete(entity);
  126. }
  127. return ActionResult.success(MsgCode.SU003.get());
  128. }
  129. }