CustomerController.java 4.3 KB

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