ProductController.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package com.example.xiaoshiweixinback.controller;
  2. import com.example.xiaoshiweixinback.business.common.Constants;
  3. import com.example.xiaoshiweixinback.business.common.Response;
  4. import com.example.xiaoshiweixinback.business.common.base.Records;
  5. import com.example.xiaoshiweixinback.business.exception.BusinessException;
  6. import com.example.xiaoshiweixinback.business.utils.FileUtils;
  7. import com.example.xiaoshiweixinback.checkLogin.checkLogin;
  8. import com.example.xiaoshiweixinback.domain.AssoPersonProduct;
  9. import com.example.xiaoshiweixinback.domain.ImportTask;
  10. import com.example.xiaoshiweixinback.entity.dto.AssoPersonProductDTO;
  11. import com.example.xiaoshiweixinback.entity.product.*;
  12. import com.example.xiaoshiweixinback.entity.vo.ProductVO;
  13. import com.example.xiaoshiweixinback.service.AssoPersonProductService;
  14. import com.example.xiaoshiweixinback.service.ImportTaskService;
  15. import com.example.xiaoshiweixinback.service.ProductService;
  16. import com.example.xiaoshiweixinback.service.importPatent.excel.ImportProductService;
  17. import io.swagger.v3.oas.annotations.Operation;
  18. import io.swagger.v3.oas.models.security.SecurityScheme;
  19. import lombok.RequiredArgsConstructor;
  20. import lombok.extern.slf4j.Slf4j;
  21. import org.springframework.web.bind.annotation.*;
  22. import org.springframework.web.multipart.MultipartFile;
  23. import java.io.File;
  24. import java.util.List;
  25. @Slf4j
  26. @RequestMapping(Constants.XIAOSHI_WEIXINBACK + "/product")
  27. @RestController
  28. @RequiredArgsConstructor
  29. public class ProductController {
  30. private final ProductService productService;
  31. private final AssoPersonProductService assoPersonProductService;
  32. private final ImportProductService importProductService;
  33. private final ImportTaskService importTaskService;
  34. @Operation(summary = "查询爆款产品")
  35. @PostMapping("/queryHotProduct")
  36. public Response queryHotProduct(@RequestBody ProductDTO productDTO) {
  37. Records records = productService.queryHotProduct(productDTO);
  38. return Response.success(records);
  39. }
  40. @Operation(summary = "添加或更新产品")
  41. @PostMapping("/addOrUpdateProduct")
  42. public Response addOrUpdateProduct(@RequestBody ProductAddDTO productAddDTO) {
  43. Records records = new Records();
  44. try {
  45. Integer id = productService.addOrUpdateProduct(productAddDTO);
  46. records.setData(id);
  47. } catch (BusinessException e) {
  48. return Response.error(e.getErrorCode(), e.getMessage());
  49. }
  50. return Response.success(records);
  51. }
  52. @checkLogin
  53. @Operation(summary = "关注产品")
  54. @PostMapping("/follow")
  55. public Response follow(@RequestBody AssoPersonProductDTO assoPersonProductDTO) {
  56. Records records = new Records();
  57. Integer id =null;
  58. try {
  59. id = assoPersonProductService.add(assoPersonProductDTO);
  60. if (id == null) {
  61. return Response.noPermissions("已超过可关注数量");
  62. }
  63. if (id.equals(-2)) {
  64. return Response.noPermissions("无关注产品的权益");
  65. }
  66. }
  67. catch (BusinessException e){
  68. return Response.error(e.getErrorCode(),e.getMessage());
  69. }
  70. records.setData(id);
  71. return Response.success(records);
  72. }
  73. @Operation(summary = "取消关注产品")
  74. @GetMapping("/unFollow")
  75. public Response unFollow(Integer productId) {
  76. Records records = new Records();
  77. Integer id = assoPersonProductService.cancel(productId);
  78. if (id.equals(-1)) {
  79. return Response.error("取消失败");
  80. } else if (id.equals(0)) {
  81. return Response.error("没有权限");
  82. }
  83. records.setData(id);
  84. return Response.success(records);
  85. }
  86. @checkLogin
  87. @Operation(summary = "查询关注的产品")
  88. @PostMapping("/queryConcernProduct")
  89. public Response queryConcernProduct(@RequestBody ProductDTO productDTO) {
  90. Records records = productService.queryConcernProduct(productDTO);
  91. return Response.success(records);
  92. }
  93. @checkLogin
  94. @Operation(summary = "添加或更新爆款产品")
  95. @PostMapping("/addOrUpdateHotProduct")
  96. public Response addOrUpdateHotProduct(@RequestBody HotProductAddDTO hotProductAddDTO) {
  97. Integer id =null;
  98. try {
  99. id = productService.addOrUpdateHotProduct(hotProductAddDTO,null);
  100. } catch (BusinessException e) {
  101. return Response.error(e.getErrorCode(),e.getMessage());
  102. }
  103. return Response.success(id);
  104. }
  105. @checkLogin
  106. @Operation(summary = "查看单个产品详情")
  107. @PostMapping("/queryHotProductDetail")
  108. public Response queryHotProductDetail(Integer id) {
  109. ProductVO productVO = productService.queryHotProductDetail(id);
  110. Records records = new Records();
  111. records.setData(productVO);
  112. return Response.success(records);
  113. }
  114. @checkLogin
  115. @Operation(summary = "上下架产品")
  116. @PostMapping("/updateProductIfShow")
  117. public Response updateProductIfShow(@RequestBody UpdateProductShowDTO updateProductShowDTO) {
  118. List<Integer> ids = productService.updateProductIfShow(updateProductShowDTO);
  119. return Response.success(ids);
  120. }
  121. @checkLogin
  122. @Operation(summary = "删除产品")
  123. @PostMapping("/deleteHotProduct")
  124. public Response deleteHotProduct(@RequestBody HotProductDeleteDTO hotProductDeleteDTO) {
  125. List<Integer> ids = productService.deleteHotProduct(hotProductDeleteDTO);
  126. return Response.success(ids);
  127. }
  128. @Operation(summary = "导入产品")
  129. @PostMapping("/ImportProductBatch")
  130. public Response importProduct(@RequestBody MultipartFile file) throws Exception {
  131. File newFile= FileUtils.multipartFileToFile(file);
  132. ImportTask importTask =importTaskService.addImportTask(newFile,2);
  133. importProductService.importProject(newFile,importTask);
  134. Records records =new Records();
  135. records.setData(importTask);
  136. return Response.success(records);
  137. }
  138. }