ProductGoodsController.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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.base.vo.PageListVO;
  11. import jnpf.base.vo.PaginationVO;
  12. import jnpf.constant.MsgCode;
  13. import jnpf.entity.ProductGoodsEntity;
  14. import jnpf.model.productgoods.*;
  15. import jnpf.service.ProductGoodsService;
  16. import jnpf.util.JsonUtil;
  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 15:57:50
  29. */
  30. @Slf4j
  31. @RestController
  32. @Tag(name = "产品商品", description = "Goods")
  33. @RequestMapping("/api/extend/saleOrder/Goods")
  34. public class ProductGoodsController extends SuperController<ProductGoodsService, ProductGoodsEntity> {
  35. @Autowired
  36. private ProductGoodsService productgoodsService;
  37. /**
  38. * 列表
  39. *
  40. * @param type 类型
  41. * @return
  42. */
  43. @GetMapping("/getGoodList")
  44. @Operation(summary = "列表")
  45. @Parameters({
  46. @Parameter(name = "type", description = "类型"),
  47. })
  48. @SaCheckPermission("extend.orderDemo")
  49. public ActionResult<ListVO<ProductGoodsListVO>> list(@RequestParam("type")String type) {
  50. List<ProductGoodsEntity> list = productgoodsService.getGoodList(type);
  51. List<ProductGoodsListVO> listVO = JsonUtil.getJsonToList(list, ProductGoodsListVO.class);
  52. ListVO vo = new ListVO();
  53. vo.setList(listVO);
  54. return ActionResult.success(vo);
  55. }
  56. /**
  57. * 列表
  58. *
  59. * @param goodsPagination 分页模型
  60. * @return
  61. */
  62. @GetMapping
  63. @Operation(summary = "列表")
  64. @SaCheckPermission("extend.orderDemo")
  65. public ActionResult<PageListVO<ProductGoodsListVO>> list(ProductGoodsPagination goodsPagination) {
  66. List<ProductGoodsEntity> list = productgoodsService.getList(goodsPagination);
  67. List<ProductGoodsListVO> listVO = JsonUtil.getJsonToList(list, ProductGoodsListVO.class);
  68. PageListVO vo = new PageListVO();
  69. vo.setList(listVO);
  70. PaginationVO page = JsonUtil.getJsonToBean(goodsPagination, PaginationVO.class);
  71. vo.setPagination(page);
  72. return ActionResult.success(vo);
  73. }
  74. /**
  75. * 创建
  76. *
  77. * @param goodsCrForm 商品模型
  78. * @return
  79. */
  80. @PostMapping
  81. @Operation(summary = "创建")
  82. @Parameters({
  83. @Parameter(name = "goodsCrForm", description = "商品模型",required = true),
  84. })
  85. @SaCheckPermission("extend.orderDemo")
  86. public ActionResult create(@RequestBody @Valid ProductGoodsCrForm goodsCrForm) {
  87. ProductGoodsEntity entity = JsonUtil.getJsonToBean(goodsCrForm, ProductGoodsEntity.class);
  88. productgoodsService.create(entity);
  89. return ActionResult.success(MsgCode.SU001.get());
  90. }
  91. /**
  92. * 信息
  93. *
  94. * @param id 主键
  95. * @return
  96. */
  97. @Operation(summary = "信息")
  98. @GetMapping("/{id}")
  99. @Parameters({
  100. @Parameter(name = "id", description = "主键", required = true),
  101. })
  102. @SaCheckPermission("extend.orderDemo")
  103. public ActionResult<ProductGoodsInfoVO> info(@PathVariable("id") String id) {
  104. ProductGoodsEntity entity = productgoodsService.getInfo(id);
  105. ProductGoodsInfoVO vo = JsonUtil.getJsonToBean(entity, ProductGoodsInfoVO.class);
  106. return ActionResult.success(vo);
  107. }
  108. /**
  109. * 更新
  110. *
  111. * @param id 主键
  112. * @param goodsCrFormUpForm 商品模型
  113. * @return
  114. */
  115. @PutMapping("/{id}")
  116. @Operation(summary = "更新")
  117. @Parameters({
  118. @Parameter(name = "id", description = "主键", required = true),
  119. @Parameter(name = "goodsCrFormUpForm", description = "商品模型",required = true),
  120. })
  121. @SaCheckPermission("extend.orderDemo")
  122. public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid ProductGoodsUpForm goodsCrFormUpForm) {
  123. ProductGoodsEntity entity = JsonUtil.getJsonToBean(goodsCrFormUpForm, ProductGoodsEntity.class);
  124. boolean ok = productgoodsService.update(id, entity);
  125. if (ok) {
  126. return ActionResult.success(MsgCode.SU004.get());
  127. }
  128. return ActionResult.fail(MsgCode.FA002.get());
  129. }
  130. /**
  131. * 删除
  132. *
  133. * @param id 主键
  134. * @return
  135. */
  136. @DeleteMapping("/{id}")
  137. @Operation(summary = "删除")
  138. @Parameters({
  139. @Parameter(name = "id", description = "主键", required = true),
  140. })
  141. @SaCheckPermission("extend.orderDemo")
  142. public ActionResult delete(@PathVariable("id") String id) {
  143. ProductGoodsEntity entity = productgoodsService.getInfo(id);
  144. if (entity != null) {
  145. productgoodsService.delete(entity);
  146. }
  147. return ActionResult.success(MsgCode.SU003.get());
  148. }
  149. /**
  150. * 下拉
  151. *
  152. * @param goodsPagination 下拉模型
  153. * @return
  154. */
  155. @GetMapping("/Selector")
  156. @Operation(summary = "下拉")
  157. @SaCheckPermission("extend.orderDemo")
  158. public ActionResult<ListVO<ProductGoodsListVO>> listSelect(ProductGoodsPagination goodsPagination) {
  159. goodsPagination.setCurrentPage(1);
  160. goodsPagination.setPageSize(50);
  161. List<ProductGoodsEntity> list = productgoodsService.getList(goodsPagination);
  162. List<ProductGoodsListVO> listVO = JsonUtil.getJsonToList(list, ProductGoodsListVO.class);
  163. ListVO vo = new ListVO();
  164. vo.setList(listVO);
  165. return ActionResult.success(vo);
  166. }
  167. }