huliguo
3 天以前 e7c5c8c6768e018b17a766d7481f13300b7cd5a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package com.linghu.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linghu.model.common.ResponseResult;
import com.linghu.model.entity.Keyword;
import com.linghu.model.vo.*;
import com.linghu.model.vo.KeywordStaticsListVO;
import com.linghu.service.KeywordService;
import com.linghu.mapper.KeywordMapper;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
/**
 * @author xy
 * @description 针对表【keyword】的数据库操作Service实现
 * @createDate 2025-07-04 20:17:33
 */
@Service
public class KeywordServiceImpl extends ServiceImpl<KeywordMapper, Keyword> implements KeywordService {
    @Autowired
    private KeywordMapper keywordMapper;
 
    @Override
    public ResponseResult<KeywordStaticsListVO> statics(Integer keywordId, Integer questionId) {
        KeywordStaticsListVO vo = new KeywordStaticsListVO();
        // 1.关键词是否存在
        Keyword keyword = this.getById(keywordId);
        if (keyword == null) {
            return ResponseResult.error("关键词不存在");
        }
        if (!"completed".equals(keyword.getStatus())) {
            return ResponseResult.error("关键词采集未完成");
        }
        List<KeywordStaticsVO> statics = this.getBaseMapper().statics(keywordId, questionId, keyword.getNum());
        vo.setNowRecord(statics);
        if (keyword.getNum() > 1) {
            statics = this.getBaseMapper().statics(keywordId, questionId, keyword.getNum() - 1);
            vo.setBeforeRecord(statics);
        }
        return ResponseResult.success(vo);
    }
 
    @Override
    public ResponseResult<List<PlatformProportionVO>> getResultByTypeId(Integer keywordId, Integer questionId,
            Integer typeId) {
        // 1.关键词是否存在
        Keyword keyword = this.getById(keywordId);
        if (keyword == null) {
            return ResponseResult.error("关键词不存在");
        }
        if (!"completed".equals(keyword.getStatus())) {
            return ResponseResult.error("关键词采集未完成");
        }
        List<PlatformProportionVO> result = this.getBaseMapper().getResultByTypeId(keywordId, questionId,
                keyword.getNum(), typeId);
        return ResponseResult.success(result);
    }
 
    @Override
    public ResponseResult<List<ResultListVO>> getResultByPlatformId(Integer keywordId, Integer questionId,
            Integer platformId) {
        // 1.关键词是否存在
        Keyword keyword = this.getById(keywordId);
        if (keyword == null) {
            return ResponseResult.error("关键词不存在");
        }
        if (!"completed".equals(keyword.getStatus())) {
            return ResponseResult.error("关键词采集未完成");
        }
 
        List<ResultListVO> result = this.getBaseMapper().getResultByPlatformId(keywordId, questionId, keyword.getNum(),
                platformId);
        return ResponseResult.success(result);
    }
 
    @Override
    public List<Keyword> getKeywordsByOrderId(String orderId) {
        LambdaQueryWrapper<Keyword> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Keyword::getOrder_id, orderId);
        return keywordMapper.selectList(queryWrapper);
    }
 
    @Override
    public Boolean saveKeywords(String keywords, String order_id) {
        if (StringUtils.hasText(keywords)) {
            List<Keyword> keywordList = new ArrayList<>();
            String[] keywordArray = keywords.split("\\n");
            for (String keyword : keywordArray) {
                Keyword newKeyword = new Keyword();
                newKeyword.setKeyword_name(keyword);
                newKeyword.setOrder_id(order_id);
                newKeyword.setStatus("notSubmitted");
                keywordList.add(newKeyword);
            }
            return this.saveBatch(keywordList);
        }else {
            return false;
        }
    }
 
}