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());
|
}
|
|
}
|