2021与蓝度共同重构项目,服务端
liuhaonan
2022-10-25 d495f9b8cdc83663e4189bc3cc72ac9543ff5555
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
package com.sandu.ximon.admin.service;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.object.BaseConditionVO;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.ximon.admin.param.GroupParam;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.dao.domain.LedNovaGroup;
import com.sandu.ximon.dao.domain.LedNovaGroupRelation;
import com.sandu.ximon.dao.mapper.LedNovaGroupMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
/**
 * @author LiuHaoNan
 * @date 2022/9/19
 */
@Service
@AllArgsConstructor
public class LedNovaGroupService extends BaseServiceImpl<LedNovaGroupMapper, LedNovaGroup> {
 
    private final ClientService clientService;
    private final LedNovaGroupRelationService relationService;
 
    /**
     * 新增分组
     *
     * @param param
     * @return
     */
    public boolean addGroup(GroupParam param) {
        LedNovaGroup group = new LedNovaGroup();
 
        group.setUserId(SecurityUtils.getUserId());
        group.setClientId(clientService.getClientId(SecurityUtils.getUserId()));
 
        group.setGroupName(param.getGroupName());
        return save(group);
    }
 
    /**
     * 编辑分组
     *
     * @param
     * @param param
     * @return
     */
    public boolean updateGroup(GroupParam param) {
        LedNovaGroup poleGroup = getById(param.getGroupId());
        if (poleGroup == null) {
            throw new BusinessException("未找到该分组");
        }
 
        poleGroup.setGroupName(param.getGroupName());
        return updateById(poleGroup);
    }
 
    /**
     * 删除分组
     *
     * @param groupIds
     * @return
     */
    public boolean deleteGroup(List<Long> groupIds) {
        List<LedNovaGroup> ledNovaGroups = listByIds(groupIds);
        if (ledNovaGroups == null) {
            throw new BusinessException("未找到该分组");
        }
 
        /**
         * 刪除关系
         */
        relationService.remove(Wrappers.lambdaQuery(LedNovaGroupRelation.class).in(LedNovaGroupRelation::getNovaGroupId, groupIds));
        return removeByIds(groupIds);
    }
 
    /**
     * 分组列表
     *
     * @param baseConditionVO
     * @param keyword
     * @return
     */
    public Object groupList(BaseConditionVO baseConditionVO, String keyword) {
        if (keyword == null) {
            throw new BusinessException("关键字不能为null,不需要模糊查询请传空字符串");
        }
 
        if (SecurityUtils.getClientId() == null) {
            //超管
            PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
            return list(Wrappers.lambdaQuery(LedNovaGroup.class).like(LedNovaGroup::getGroupName, keyword));
        } else {
            if (clientService.findClientId()) {
                //二级客户
                PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
                return list(Wrappers.lambdaQuery(LedNovaGroup.class).eq(LedNovaGroup::getUserId, SecurityUtils.getUserId()).like(LedNovaGroup::getGroupName, keyword));
            } else {
                //一级客户
                PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
                return list(Wrappers.lambdaQuery(LedNovaGroup.class).eq(LedNovaGroup::getClientId, SecurityUtils.getUserId()).or(
                        user -> {
                            user.eq(LedNovaGroup::getUserId, SecurityUtils.getUserId());
                        }
                ).like(LedNovaGroup::getGroupName, keyword));
            }
        }
    }
 
    /**
     * 绑定
     *
     * @param groupId
     * @param ledIdList
     * @return
     */
    public boolean bindLed(Long groupId, List<Long> ledIdList) {
        LedNovaGroup ledNovaGroup = getById(groupId);
        if (ledNovaGroup == null) {
            throw new BusinessException("未找到该分组");
        }
        return relationService.saveBinding(groupId, ledIdList);
    }
}