Administrator
12 hours ago 45391bbd1117ddac9dd91d8b2223381176713c37
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
package cc.mrbird.febs.ai.service.impl;
 
import cc.mrbird.febs.ai.entity.AiProductPrompt;
import cc.mrbird.febs.ai.entity.AiProductQuestionLabel;
import cc.mrbird.febs.ai.mapper.AiProductQuestionLabelMapper;
import cc.mrbird.febs.ai.service.AiProductQuestionLabelService;
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.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;
 
@Slf4j
@Service
@RequiredArgsConstructor
public class AiProductQuestionLabelServiceImpl extends ServiceImpl<AiProductQuestionLabelMapper, AiProductQuestionLabel> implements AiProductQuestionLabelService {
 
    private final AiProductQuestionLabelMapper aiProductQuestionLabelMapper;
 
    @Override
    public AiProductQuestionLabel getById(String id) {
        return aiProductQuestionLabelMapper.selectById( id);
    }
 
    @Override
    public IPage<AiProductQuestionLabel> listInPage(AiProductQuestionLabel dto, QueryRequest request) {
        Page<AiProductQuestionLabel> page = new Page<>(request.getPageNum(), request.getPageSize());
        LambdaQueryWrapper<AiProductQuestionLabel> query = Wrappers.lambdaQuery(AiProductQuestionLabel.class);
        if (StrUtil.isNotEmpty(dto.getCompanyId())){
            query.eq(AiProductQuestionLabel::getCompanyId, dto.getCompanyId());
        }
        query.orderByDesc(AiProductQuestionLabel::getCreatedTime);
        Page<AiProductQuestionLabel> pages = aiProductQuestionLabelMapper.selectPage(page, query);
        return pages;
    }
 
    @Override
    public FebsResponse add(AiProductQuestionLabel dto) {
        Date createTime = new Date();
        AiProductQuestionLabel entity = new AiProductQuestionLabel();
        entity.setId(UUID.getSimpleUUIDString());
        entity.setName(dto.getName());
        if (StrUtil.isNotEmpty(dto.getCompanyId())){
            entity.setCompanyId(dto.getCompanyId());
        }
        entity.setCreatedTime(createTime);
        aiProductQuestionLabelMapper.insert( entity);
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse update(AiProductQuestionLabel dto) {
        String id = dto.getId();
        AiProductQuestionLabel entity = this.getById(id);
        if(ObjectUtil.isNotNull( entity)){
            this.update(null,
                    Wrappers.lambdaUpdate(AiProductQuestionLabel.class)
                            .set(AiProductQuestionLabel::getName, dto.getName())
                            .set(AiProductQuestionLabel::getUpdatedTime, new Date())
                            .eq(AiProductQuestionLabel::getId, id));
 
        }
        return new FebsResponse().success().message("操作成功");
    }
}