guyue
2025-09-05 e4451cbe7eea81c397353e8d5649e52dcbd3b7d1
src/main/java/com/linghu/controller/KeywordController.java
@@ -1,6 +1,8 @@
package com.linghu.controller;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linghu.config.FinalStatus;
import com.linghu.listener.KeywordExcelListener;
import com.linghu.model.common.ResponseResult;
import com.linghu.model.dto.ExportFeedDTO;
@@ -10,12 +12,14 @@
import com.linghu.model.dto.ExportStaticsDTO;
import com.linghu.model.entity.*;
import com.linghu.model.excel.*;
import com.linghu.model.validator.UpdateGroup;
import com.linghu.model.vo.*;
import com.linghu.model.vo.KeywordStaticsListVO;
import com.linghu.model.vo.PlatformProportionVO;
import com.linghu.model.vo.ResultListVO;
import com.linghu.service.KeywordService;
import com.linghu.service.OrderService;
import com.linghu.service.ReferenceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -24,6 +28,7 @@
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -44,6 +49,9 @@
    @Autowired
    private ReferenceService referenceService;
    @Autowired
    private OrderService orderService;
    /**
     * 关键词统计 EChart图
@@ -66,7 +74,7 @@
    @PostMapping(value = "/exportStatics")
    @ApiOperation(value = "EChart图导出")
    public ResponseEntity<byte[]> exportStatics(@RequestBody ExportStaticsDTO exportStaticsDTO) {
    public ResponseEntity<byte[]> exportStatics(@Valid @RequestBody ExportStaticsDTO exportStaticsDTO) {
        return keywordService.exportEChart(exportStaticsDTO);
    }
@@ -92,7 +100,7 @@
     */
    @PostMapping(value = "/exportGetResultByTypeId")
    @ApiOperation(value = "导出:根据类别查看")
    public ResponseEntity<byte[]> exportGetResultByTypeId(@RequestBody ExportGetResultDTO dto) {
    public ResponseEntity<byte[]> exportGetResultByTypeId(@Valid @RequestBody ExportGetResultDTO dto) {
        return keywordService.exportResult(dto);
    }
@@ -190,8 +198,8 @@
     */
    @PostMapping("/updateKeyword")
    @ApiOperation(value = "修改关键词")
    public ResponseResult<String> updateKeyword(@RequestBody Keyword keyword) {
        if("submitted".equals(keyword.getStatus())){
    public ResponseResult<String> updateKeyword(@Validated(UpdateGroup.class) @RequestBody Keyword keyword) {
        if(FinalStatus.SUBMITTED.getValue().equals(keyword.getStatus())){
            return ResponseResult.error("关键词已开始采集不允许修改!");
        }
        keywordService.updateById(keyword);
@@ -205,10 +213,20 @@
    @ApiOperation(value = "删除关键词")
    public ResponseResult<String> deleteKeyword(@RequestParam("keywordId") Integer keywordId) {
        Keyword keyword = keywordService.getById(keywordId);
        if("submitted".equals(keyword.getStatus())){
        if(FinalStatus.SUBMITTED.getValue().equals(keyword.getStatus())){
            return ResponseResult.error("关键词已开始采集或不允许删除!");
        }
        keywordService.removeById(keywordId);
        //找到订单
        Orders order = orderService.getById(keyword.getOrder_id());
        //更新关键词数量
        LambdaQueryWrapper<Keyword> queryKeywordsQueryWrapper =  new LambdaQueryWrapper<>();
        queryKeywordsQueryWrapper.eq(Keyword::getOrder_id, keyword.getOrder_id());
        int count1 = (int) keywordService.count(queryKeywordsQueryWrapper);
        order.setKeyword_num(count1);
        orderService.updateById(order);
        return ResponseResult.success("删除成功");
    }