2021与蓝度共同重构项目,服务端
liuhaonan
2022-05-27 b34d941094d11e21e21a2ceead8a9fdeee640e2d
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
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.PoleGroupParam;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.dao.domain.PoleGroup;
import com.sandu.ximon.dao.domain.PoleGroupRelation;
import com.sandu.ximon.dao.mapper.PoleGroupMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * 分组操作
 *
 * @author chenjiantian
 */
@Service
@AllArgsConstructor
public class PoleGroupService extends BaseServiceImpl<PoleGroupMapper, PoleGroup> {
 
    private final PoleGroupRelationService poleGroupRelationService;
 
    public boolean addGroup(PoleGroupParam param) {
        PoleGroup group = new PoleGroup();
        if (SecurityUtils.getClientId() != null) {
            group.setClientId(SecurityUtils.getUserId());
        }
        group.setGroupName(param.getGroupName());
        return save(group);
    }
 
    public boolean updateGroup(Long groupId, PoleGroupParam param) {
        PoleGroup poleGroup = getById(groupId);
        if (poleGroup == null) {
            throw new BusinessException("未找到该分组");
        }
        PoleGroup update = new PoleGroup();
        update.setGroupId(groupId);
        update.setGroupName(param.getGroupName());
        return updateById(update);
    }
 
    public boolean deleteGroup(Long groupId) {
        PoleGroup poleGroup = getById(groupId);
        if (poleGroup == null) {
            throw new BusinessException("未找到该分组");
        }
        /**
         * 刪除
         */
        poleGroupRelationService.remove(Wrappers.lambdaQuery(PoleGroupRelation.class).eq(PoleGroupRelation::getPoleGroupId, groupId));
        return removeById(groupId);
    }
 
    public List<PoleGroup> groupList(BaseConditionVO baseConditionVO, String keyword, Long groupid) {
        Long clientId = SecurityUtils.getClientId();
        PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
 
//        LambdaQueryWrapper<PoleGroup> wrapper = new LambdaQueryWrapper<>();
        List<PoleGroup> list = new ArrayList<>();
        if (clientId == null) {
            list = list(Wrappers.lambdaQuery(PoleGroup.class).like(PoleGroup::getGroupName, keyword));
 
        } else {
            list = list(Wrappers.lambdaQuery(PoleGroup.class).eq(PoleGroup::getClientId, clientId).like(PoleGroup::getGroupName, keyword));
        }
        list.forEach(poleGroup -> {
//            int size = poleGroupRelationService.list(Wrappers.lambdaQuery(PoleGroupRelation.class).eq(PoleGroupRelation::getPoleGroupId, poleGroup.getGroupId())).size();
            poleGroup.setPoleCount(poleGroupRelationService.list(Wrappers.lambdaQuery(PoleGroupRelation.class).eq(PoleGroupRelation::getPoleGroupId, poleGroup.getGroupId())).size());
        });
        return list;
    }
 
    /**
     * 绑定灯杆
     */
    public boolean bindPole(Long groupId, List<Long> poleIdList) {
        PoleGroup poleGroup = getById(groupId);
        if (poleGroup == null) {
            throw new BusinessException("未找到该分组");
        }
        return poleGroupRelationService.saveBinding(groupId, poleIdList);
    }
}