Administrator
2025-08-01 dc1b9b02fe6dfc3fa76eaa29be0d66a4542e6fba
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
package cc.mrbird.febs.ai.service.impl;
 
import cc.mrbird.febs.ai.entity.AiProductRole;
import cc.mrbird.febs.ai.mapper.AiProductRoleMapper;
import cc.mrbird.febs.ai.service.AiProductRoleService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
/**
 * AI产品陪练角色 Service实现类
 *
 * @author yourname
 * @date 2025-07-29
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class AiProductRoleServiceImpl extends ServiceImpl<AiProductRoleMapper, AiProductRole> implements AiProductRoleService {
 
    private final AiProductRoleMapper aiProductRoleMapper;
 
    @Override
    public AiProductRole getById(String id) {
        return this.getById(id);
    }
 
    @Override
    public List<AiProductRole> getByCompanyId(String companyId) {
        LambdaQueryWrapper<AiProductRole> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AiProductRole::getCompanyId, companyId);
        queryWrapper.orderByDesc(AiProductRole::getCreatedTime);
        return this.list(queryWrapper);
    }
 
    @Override
    public List<AiProductRole> getByProductId(String productId) {
        LambdaQueryWrapper<AiProductRole> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AiProductRole::getProductId, productId);
        queryWrapper.orderByDesc(AiProductRole::getCreatedTime);
        return this.list(queryWrapper);
    }
 
    @Override
    public List<AiProductRole> getByName(String name) {
        LambdaQueryWrapper<AiProductRole> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(AiProductRole::getName, name);
        queryWrapper.orderByDesc(AiProductRole::getCreatedTime);
        return this.list(queryWrapper);
    }
 
    @Override
    public List<AiProductRole> getByCompanyIdAndProductId(String companyId, String productId) {
        LambdaQueryWrapper<AiProductRole> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AiProductRole::getCompanyId, companyId);
        queryWrapper.eq(AiProductRole::getProductId, productId);
        queryWrapper.orderByDesc(AiProductRole::getCreatedTime);
        return this.list(queryWrapper);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveProductRole(AiProductRole aiProductRole) {
        try {
            return this.save(aiProductRole);
        } catch (Exception e) {
            log.error("保存AI产品角色失败: ", e);
            return false;
        }
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveBatchProductRoles(List<AiProductRole> productRoles) {
        try {
            return this.saveBatch(productRoles);
        } catch (Exception e) {
            log.error("批量保存AI产品角色失败: ", e);
            return false;
        }
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateProductRole(AiProductRole aiProductRole) {
        try {
            return this.updateById(aiProductRole);
        } catch (Exception e) {
            log.error("更新AI产品角色失败: ", e);
            return false;
        }
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteById(String id) {
        try {
            return this.removeById(id);
        } catch (Exception e) {
            log.error("删除AI产品角色失败: ", e);
            return false;
        }
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteByProductId(String productId) {
        try {
            LambdaQueryWrapper<AiProductRole> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(AiProductRole::getProductId, productId);
            return this.remove(queryWrapper);
        } catch (Exception e) {
            log.error("根据AI产品ID删除AI产品角色失败: ", e);
            return false;
        }
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteByCompanyId(String companyId) {
        try {
            LambdaQueryWrapper<AiProductRole> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(AiProductRole::getCompanyId, companyId);
            return this.remove(queryWrapper);
        } catch (Exception e) {
            log.error("根据公司ID删除AI产品角色失败: ", e);
            return false;
        }
    }
}