123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- package com.example.xiaoshiweixinback.controller;
- import com.example.xiaoshiweixinback.business.common.Constants;
- import com.example.xiaoshiweixinback.business.common.Response;
- import com.example.xiaoshiweixinback.business.common.base.Records;
- import com.example.xiaoshiweixinback.business.exception.BusinessException;
- import com.example.xiaoshiweixinback.business.utils.FileUtils;
- import com.example.xiaoshiweixinback.checkLogin.checkLogin;
- import com.example.xiaoshiweixinback.domain.AssoPersonProduct;
- import com.example.xiaoshiweixinback.domain.ImportTask;
- import com.example.xiaoshiweixinback.entity.dto.AssoPersonProductDTO;
- import com.example.xiaoshiweixinback.entity.product.*;
- import com.example.xiaoshiweixinback.entity.vo.ProductVO;
- import com.example.xiaoshiweixinback.service.AssoPersonProductService;
- import com.example.xiaoshiweixinback.service.ImportTaskService;
- import com.example.xiaoshiweixinback.service.ProductService;
- import com.example.xiaoshiweixinback.service.importPatent.excel.ImportProductService;
- import io.swagger.v3.oas.annotations.Operation;
- import io.swagger.v3.oas.models.security.SecurityScheme;
- import lombok.RequiredArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import java.io.File;
- import java.util.List;
- @Slf4j
- @RequestMapping(Constants.XIAOSHI_WEIXINBACK + "/product")
- @RestController
- @RequiredArgsConstructor
- public class ProductController {
- private final ProductService productService;
- private final AssoPersonProductService assoPersonProductService;
- private final ImportProductService importProductService;
- private final ImportTaskService importTaskService;
- @Operation(summary = "查询爆款产品")
- @PostMapping("/queryHotProduct")
- public Response queryHotProduct(@RequestBody ProductDTO productDTO) {
- Records records = productService.queryHotProduct(productDTO);
- return Response.success(records);
- }
- @Operation(summary = "添加或更新产品")
- @PostMapping("/addOrUpdateProduct")
- public Response addOrUpdateProduct(@RequestBody ProductAddDTO productAddDTO) {
- Records records = new Records();
- try {
- Integer id = productService.addOrUpdateProduct(productAddDTO);
- records.setData(id);
- } catch (BusinessException e) {
- return Response.error(e.getErrorCode(), e.getMessage());
- }
- return Response.success(records);
- }
- @checkLogin
- @Operation(summary = "关注产品")
- @PostMapping("/follow")
- public Response follow(@RequestBody AssoPersonProductDTO assoPersonProductDTO) {
- Records records = new Records();
- Integer id =null;
- try {
- id = assoPersonProductService.add(assoPersonProductDTO);
- if (id == null) {
- return Response.noPermissions("已超过可关注数量");
- }
- if (id.equals(-2)) {
- return Response.noPermissions("无关注产品的权益");
- }
- }
- catch (BusinessException e){
- return Response.error(e.getErrorCode(),e.getMessage());
- }
- records.setData(id);
- return Response.success(records);
- }
- @Operation(summary = "取消关注产品")
- @GetMapping("/unFollow")
- public Response unFollow(Integer productId) {
- Records records = new Records();
- Integer id = assoPersonProductService.cancel(productId);
- if (id.equals(-1)) {
- return Response.error("取消失败");
- } else if (id.equals(0)) {
- return Response.error("没有权限");
- }
- records.setData(id);
- return Response.success(records);
- }
- @checkLogin
- @Operation(summary = "查询关注的产品")
- @PostMapping("/queryConcernProduct")
- public Response queryConcernProduct(@RequestBody ProductDTO productDTO) {
- Records records = productService.queryConcernProduct(productDTO);
- return Response.success(records);
- }
- @checkLogin
- @Operation(summary = "添加或更新爆款产品")
- @PostMapping("/addOrUpdateHotProduct")
- public Response addOrUpdateHotProduct(@RequestBody HotProductAddDTO hotProductAddDTO) {
- Integer id =null;
- try {
- id = productService.addOrUpdateHotProduct(hotProductAddDTO,null);
- } catch (BusinessException e) {
- return Response.error(e.getErrorCode(),e.getMessage());
- }
- return Response.success(id);
- }
- @checkLogin
- @Operation(summary = "查看单个产品详情")
- @PostMapping("/queryHotProductDetail")
- public Response queryHotProductDetail(Integer id) {
- ProductVO productVO = productService.queryHotProductDetail(id);
- Records records = new Records();
- records.setData(productVO);
- return Response.success(records);
- }
- @checkLogin
- @Operation(summary = "上下架产品")
- @PostMapping("/updateProductIfShow")
- public Response updateProductIfShow(@RequestBody UpdateProductShowDTO updateProductShowDTO) {
- List<Integer> ids = productService.updateProductIfShow(updateProductShowDTO);
- return Response.success(ids);
- }
- @checkLogin
- @Operation(summary = "删除产品")
- @PostMapping("/deleteHotProduct")
- public Response deleteHotProduct(@RequestBody HotProductDeleteDTO hotProductDeleteDTO) {
- List<Integer> ids = productService.deleteHotProduct(hotProductDeleteDTO);
- return Response.success(ids);
- }
- @Operation(summary = "导入产品")
- @PostMapping("/ImportProductBatch")
- public Response importProduct(@RequestBody MultipartFile file) throws Exception {
- File newFile= FileUtils.multipartFileToFile(file);
- ImportTask importTask =importTaskService.addImportTask(newFile,2);
- importProductService.importProject(newFile,importTask);
- Records records =new Records();
- records.setData(importTask);
- return Response.success(records);
- }
- }
|