guyue
2025-09-05 e4451cbe7eea81c397353e8d5649e52dcbd3b7d1
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
package com.linghu.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linghu.mapper.KeywordMapper;
import com.linghu.mapper.ReferenceMapper;
import com.linghu.model.common.ResponseResult;
import com.linghu.model.entity.Keyword;
import com.linghu.model.entity.Type;
import com.linghu.service.TypeService;
import com.linghu.mapper.TypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * @author xy
 * @description 针对表【type】的数据库操作Service实现
 * @createDate 2025-07-04 20:10:31
 */
@Service
public class TypeServiceImpl extends ServiceImpl<TypeMapper, Type>
        implements TypeService {
    @Resource
    private TypeMapper typeMapper;
    @Autowired
    private KeywordMapper keywordMapper;
    @Override
    public Type getTypeByName(String typeName) {
        // 查询
        LambdaQueryWrapper<Type> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Type::getType_name, typeName);
        return typeMapper.selectOne(queryWrapper);
 
    }
 
    @Override
    public ResponseResult<Type> addType(Type type) {
        boolean success = this.save(type);
        if (success) {
            return ResponseResult.success(type);
        }
        return ResponseResult.error("添加类型失败");
    }
 
    @Override
    public ResponseResult<Void> batchDeleteTypes(List<Integer> typeIds) {
        if (typeIds.isEmpty()) {
            return ResponseResult.error("请选择要删除的类型");
        }
        List<Type> types = typeIds.stream().map(id -> {
            Type type = new Type();
            type.setType_id(id);
            return type;
        }).collect(Collectors.toList());
        boolean success = this.updateBatchById(types);
        if (success) {
            return ResponseResult.success();
        }
        return ResponseResult.error("批量删除类型失败");
    }
 
    @Override
    public ResponseResult<List<Type>> pageList(Integer keywordId, Integer questionId, Integer isNow) {
        List<Integer> typeIds=new ArrayList<>();
        Keyword keyword=new Keyword();
        //先查找当前关键词下,所有的回答 的 所有的平台名称
        if (keywordId != null) {
            keyword = keywordMapper.selectById(keywordId);
        }
 
 
        typeIds= keywordMapper.getTypeIds(keywordId, questionId, isNow,keyword);
        LambdaQueryWrapper<Type> queryWrapper = new LambdaQueryWrapper<>();
        if (!typeIds.isEmpty()) {
            queryWrapper.in(Type::getType_id, typeIds);
        }else {
            if (keywordId != null) {
                return ResponseResult.success(new ArrayList<>());
 
            }else {
                List<Type> list = this.list(queryWrapper);
                return ResponseResult.success(list);
            }
 
        }
        List<Type> list = this.list(queryWrapper);
        return ResponseResult.success(list);
    }
 
}