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; /** *

* 集团管理 服务实现类 *

* * @author mxcd * @since 2026-09-22 */ @Service public class TGroupServiceImpl extends ServiceImpl implements TGroupService { @Resource private TGroupCompanyService groupCompanyService; @Override public List groupTree() { List groups = lambdaQuery().orderByAsc(TGroup::getId).list(); if (groups.isEmpty()) { return Collections.emptyList(); } List 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.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()); } }