puzhibing
2026-09-28 d4bde58ab669a434bb0c96f391153ec66eedd5b7
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
package com.ruoyi.other.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.other.api.domain.TGroup;
import com.ruoyi.other.api.domain.TGroupCompany;
import com.ruoyi.other.mapper.TGroupMapper;
import com.ruoyi.other.service.TGroupCompanyService;
import com.ruoyi.other.service.TGroupService;
import com.ruoyi.other.vo.GroupCompanyVo;
import com.ruoyi.other.vo.GroupTreeVo;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 集团管理 服务实现类
 * </p>
 *
 * @author mxcd
 * @since 2026-09-22
 */
@Service
public class TGroupServiceImpl extends ServiceImpl<TGroupMapper, TGroup> implements TGroupService {
 
    @Resource
    private TGroupCompanyService groupCompanyService;
 
    @Override
    public List<GroupTreeVo> groupTree() {
        List<TGroup> groups = lambdaQuery().orderByAsc(TGroup::getId).list();
        if (groups.isEmpty()) {
            return Collections.emptyList();
        }
        List<TGroupCompany> companies = groupCompanyService.lambdaQuery().orderByAsc(TGroupCompany::getId).list();
        return groups.stream().map(group -> {
            GroupTreeVo vo = new GroupTreeVo();
            vo.setId(group.getId());
            vo.setGroupName(group.getGroupName());
            vo.setContactName(group.getContactName());
            vo.setContactPhone(group.getContactPhone());
            vo.setChildren(companies.stream()
                    .filter(company -> company.getGroupId() != null && company.getGroupId().equals(group.getId()))
                    .map(company -> new GroupCompanyVo(company.getId(), company.getName(), company.getGroupId()))
                    .collect(Collectors.toList()));
            return vo;
        }).collect(Collectors.toList());
    }
 
}