Administrator
6 hours ago 33fb9a2fdb0e6cd68a987bbdcbe22ef587fa5813
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package cc.mrbird.febs.ai.service.impl;
 
import cc.mrbird.febs.ai.entity.AiProduct;
import cc.mrbird.febs.ai.entity.AiProductCategory;
import cc.mrbird.febs.ai.entity.AiProductPoint;
import cc.mrbird.febs.ai.mapper.AiProductPointMapper;
import cc.mrbird.febs.ai.service.AiProductCategoryService;
import cc.mrbird.febs.ai.service.AiProductPointLinkService;
import cc.mrbird.febs.ai.service.AiProductPointService;
import cc.mrbird.febs.ai.util.UUID;
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.common.entity.QueryRequest;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
 
/**
 * AI产品知识点 Service实现类
 *
 * @author yourname
 * @date 2025-07-29
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class AiProductPointServiceImpl extends ServiceImpl<AiProductPointMapper, AiProductPoint> implements AiProductPointService {
 
    private final AiProductPointMapper aiProductPointMapper;
    private final AiProductPointLinkService aiProductPointLinkService;
    private final AiProductCategoryService aiProductCategoryService;
 
    @Override
    public AiProductPoint getById(String id) {
        return aiProductPointMapper.selectById(id);
    }
 
    @Override
    public IPage<AiProductPoint> listInPage(AiProductPoint dto, QueryRequest request) {
        Page<AiProductPoint> page = new Page<>(request.getPageNum(), request.getPageSize());
        LambdaQueryWrapper<AiProductPoint> query = Wrappers.lambdaQuery(AiProductPoint.class);
        if (StrUtil.isNotEmpty(dto.getCompanyId())){
            query.eq(AiProductPoint::getCompanyId, dto.getCompanyId());
        }
        Page<AiProductPoint> pages = aiProductPointMapper.selectPage(page, query);
        List<AiProductPoint> records = pages.getRecords();
        if (CollUtil.isNotEmpty( records)){
            Set<String> collect = records.stream().map(AiProductPoint::getProductCategoryId).collect(Collectors.toSet());
 
            if(CollUtil.isNotEmpty( collect)){
                Map<String, AiProductCategory> map = aiProductCategoryService.selectMapByIds(collect);
                for (AiProductPoint record : records){
                    AiProductCategory orDefault = map.getOrDefault(record.getProductCategoryId(), null);
                    if(ObjectUtil.isNotNull(orDefault)){
                        record.setProductCategoryName(orDefault.getName());
                    }
                }
            }
        }
        return pages;
    }
 
    @Override
    public FebsResponse add(AiProductPoint dto) {
        AiProductPoint entity = new AiProductPoint();
        entity.setId(UUID.getSimpleUUIDString());
        entity.setProductCategoryId(dto.getProductCategoryId());
        entity.setCompanyId(dto.getCompanyId());
        entity.setIsNormal(dto.getIsNormal() );
        entity.setFinderUserName(dto.getFinderUserName());
        entity.setFeedId(dto.getFeedId());
        entity.setFeedImg(dto.getFeedImg());
        entity.setTitle(dto.getTitle());
        entity.setDescription(dto.getDescription());
        entity.setCreatedTime(new Date());
        this.save(entity);
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse update(AiProductPoint dto) {
        String id = dto.getId();
        AiProductPoint entity = this.getById(id);
        if (ObjectUtil.isNotNull( entity)){
            this.update(null,
                    Wrappers.lambdaUpdate(AiProductPoint.class)
                            .set(AiProductPoint::getIsNormal, dto.getIsNormal())
                            .set(AiProductPoint::getProductCategoryId, dto.getProductCategoryId())
                            .set(AiProductPoint::getFinderUserName, dto.getFinderUserName())
                            .set(AiProductPoint::getFeedId, dto.getFeedId())
                            .set(AiProductPoint::getTitle, dto.getTitle())
                            .set(AiProductPoint::getFeedImg, dto.getFeedImg())
                            .set(AiProductPoint::getDescription, dto.getDescription())
                            .set(AiProductPoint::getUpdatedTime, new Date())
                            .eq(AiProductPoint::getId, id)
            );
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse delete(String id) {
        AiProductPoint entity = this.getById(id);
        if(ObjectUtil.isNotNull( entity)){
            // 删除
            aiProductPointMapper.deleteById( id);
            aiProductPointLinkService.deleteByProductPointId(id);
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public List<AiProductPoint> pointTree(String companyId) {
        LambdaQueryWrapper<AiProductPoint> query = Wrappers.lambdaQuery(AiProductPoint.class);
        if (StrUtil.isNotEmpty(companyId)){
            query.eq(AiProductPoint::getCompanyId, companyId);
        }
        return aiProductPointMapper.selectList(query);
    }
 
    @Override
    public List<AiProductPoint> selectList(String companyId) {
        LambdaQueryWrapper<AiProductPoint> query = Wrappers.lambdaQuery(AiProductPoint.class);
        if (StrUtil.isNotEmpty(companyId)){
            query.eq(AiProductPoint::getCompanyId, companyId);
        }
        return aiProductPointMapper.selectList(query);
    }
 
 
}