Administrator
11 hours ago 490bceb5d9e911a5c4f687dd6570b6699ca11915
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package cc.mrbird.febs.ai.service.impl;
 
import cc.mrbird.febs.ai.entity.AiMemberRole;
import cc.mrbird.febs.ai.entity.AiMemberRolePoint;
import cc.mrbird.febs.ai.entity.AiMemberRoleProduct;
import cc.mrbird.febs.ai.mapper.AiMemberRoleMapper;
import cc.mrbird.febs.ai.req.AdminMoveChooseInfoDto;
import cc.mrbird.febs.ai.service.AiMemberRolePointService;
import cc.mrbird.febs.ai.service.AiMemberRoleProductService;
import cc.mrbird.febs.ai.service.AiMemberRoleService;
import cc.mrbird.febs.ai.service.AiProductService;
import cc.mrbird.febs.ai.util.UUID;
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.common.entity.QueryRequest;
import cc.mrbird.febs.system.service.IUserService;
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;
 
/**
 * AI用户选择角色表 Service实现类
 *
 * @author yourname
 * @date 2025-07-29
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class AiMemberRoleServiceImpl extends ServiceImpl<AiMemberRoleMapper, AiMemberRole> implements AiMemberRoleService {
 
    private final AiMemberRoleMapper aiMemberRoleMapper;
    private final AiProductService aiProductService;
    private final AiMemberRoleProductService aiMemberRoleProductService;
    private final AiMemberRolePointService aiMemberRolePointService;
    private final IUserService iUserService;
 
    @Override
    public AiMemberRole getById(String id) {
        return aiMemberRoleMapper.selectById(id);
    }
 
    @Override
    public IPage<AiMemberRole> listInPage(AiMemberRole dto, QueryRequest request) {
        Page<AiMemberRole> page = new Page<>(request.getPageNum(), request.getPageSize());
        LambdaQueryWrapper<AiMemberRole> query = Wrappers.lambdaQuery(AiMemberRole.class);
        if (StrUtil.isNotEmpty(dto.getCompanyId())){
            query.eq(AiMemberRole::getCompanyId, dto.getCompanyId());
        }
        query.ne(AiMemberRole::getState, 2);
        query.orderByAsc(AiMemberRole::getSort);
        Page<AiMemberRole> pages = aiMemberRoleMapper.selectPage(page, query);
        return pages;
    }
 
    @Override
    public FebsResponse changeState(String id, Integer state) {
        AiMemberRole entity = this.getById(id);
        if(ObjectUtil.isNotEmpty(entity)){
            this.update(null,
                    Wrappers.lambdaUpdate(AiMemberRole.class)
                            .set(AiMemberRole::getState, state)
                            .set(AiMemberRole::getUpdatedTime, new Date())
                            .eq(AiMemberRole::getId, id));
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse memberRoleAdd(AiMemberRole dto) {
        AiMemberRole entity = new AiMemberRole();
        entity.setId(UUID.getSimpleUUIDString());
        entity.setName(dto.getName());
        entity.setCode(dto.getCode());
        entity.setIconImg(dto.getIconImg());
        entity.setSort(dto.getSort());
        entity.setState(dto.getState());
        entity.setCompanyId(dto.getCompanyId());
        entity.setCreatedTime(new Date());
        this.save( entity);
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse updateMemberRole(AiMemberRole dto) {
 
        String id = dto.getId();
        AiMemberRole entity = this.getById(id);
        if(ObjectUtil.isNotNull( entity)){
            this.update(null,
                    Wrappers.lambdaUpdate(AiMemberRole.class)
                            .set(AiMemberRole::getCode, dto.getCode())
                            .set(AiMemberRole::getName, dto.getName())
                            .set(AiMemberRole::getIconImg, dto.getIconImg())
                            .set(AiMemberRole::getSort, dto.getSort())
                            .set(AiMemberRole::getUpdatedTime, new Date())
                            .eq(AiMemberRole::getId, id));
 
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse delete(String id) {
        AiMemberRole entity = this.getById(id);
        if(ObjectUtil.isNotNull( entity)){
            this.update(null,
                    Wrappers.lambdaUpdate(AiMemberRole.class)
                            .set(AiMemberRole::getState, 2)
                            .set(AiMemberRole::getUpdatedTime, new Date())
                            .eq(AiMemberRole::getId, id));
 
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse productSet(AdminMoveChooseInfoDto dto) {
        String chooseId = dto.getChooseId();
        List<String> chooseIds = dto.getChooseIds();
        AiMemberRole aiMemberRole = this.getById(chooseId);
        if (ObjectUtil.isNotNull(aiMemberRole)) {
            String companyId = aiMemberRole.getCompanyId();
            aiMemberRoleProductService.deleteByQuery(
                    Wrappers.lambdaQuery(AiMemberRoleProduct.class)
                            .eq(AiMemberRoleProduct::getRoleId,chooseId)
                            .eq(AiMemberRoleProduct::getCompanyId,companyId)
            );
            if(CollUtil.isNotEmpty(chooseIds)){
                Date createdTime = new Date();
                for (String item : chooseIds){
                    AiMemberRoleProduct entity = new AiMemberRoleProduct();
                    entity.setId(UUID.getSimpleUUIDString());
                    entity.setRoleId(chooseId);
                    entity.setProductId(item);
                    entity.setCompanyId(companyId);
                    entity.setCreatedTime(createdTime);
                    aiMemberRoleProductService.getBaseMapper().insert(entity);
                }
            }
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse productPointSet(AdminMoveChooseInfoDto dto) {
 
        String chooseId = dto.getChooseId();
        List<String> chooseIds = dto.getChooseIds();
        AiMemberRole aiMemberRole = this.getById(chooseId);
        if (ObjectUtil.isNotNull(aiMemberRole)) {
            String companyId = aiMemberRole.getCompanyId();
            aiMemberRolePointService.deleteByQuery(
                    Wrappers.lambdaQuery(AiMemberRolePoint.class)
                            .eq(AiMemberRolePoint::getRoleId,chooseId)
                            .eq(AiMemberRolePoint::getCompanyId,companyId)
            );
            if(CollUtil.isNotEmpty(chooseIds)){
                Date createdTime = new Date();
                for (String item : chooseIds){
                    AiMemberRolePoint entity = new AiMemberRolePoint();
                    entity.setId(UUID.getSimpleUUIDString());
                    entity.setRoleId(chooseId);
                    entity.setProductPointId(item);
                    entity.setCompanyId(companyId);
                    entity.setCreatedTime(createdTime);
                    aiMemberRolePointService.getBaseMapper().insert(entity);
                }
            }
        }
        return new FebsResponse().success().message("操作成功");
    }
}