package com.platform.service.impl; import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.platform.mapper.GroupDetailMapper; import com.platform.model.dto.GroupDetailDTO; import com.platform.model.entity.GroupDetailEntity; import com.platform.model.entity.GroupEntity; import com.platform.model.vo.*; import com.platform.service.ExcelDataService; import com.platform.service.GroupDetailService; import com.platform.service.GroupService; import com.platform.utils.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.*; @Service public class GroupDetailServiceImpl extends ServiceImpl implements GroupDetailService { @Resource private GroupService groupService; @Resource private ExcelDataService excelDataService; @Override public List queryList(GroupDetailDTO groupDetailDTO) { List groupDetailEntityList = baseMapper.selectList(new LambdaQueryWrapper() .eq(GroupDetailEntity::getGroupId, groupDetailDTO.getGroupId())); // 安全移除元素 groupDetailEntityList.removeIf(groupDetailEntity -> groupDetailEntity.getUserName().contains("商户")); return groupDetailEntityList; } @Override public List queryIp(GroupDetailDTO groupDetailDTO) { return baseMapper.queryIp(groupDetailDTO); } @Override public List queryIpDetail(String ip) { return baseMapper.selectList(new LambdaQueryWrapper() .eq(GroupDetailEntity::getIp, ip)); } @Override public List queryMac(GroupDetailDTO groupDetailDTO) { return baseMapper.queryMac(groupDetailDTO); } @Override public List queryMacDetail(String mac) { return baseMapper.selectList(new LambdaQueryWrapper() .eq(GroupDetailEntity::getMac, mac)); } @Override public GraphVO draw(String groupId) { //查看group信息 GroupEntity groupEntity = groupService.getById(groupId); if (groupEntity == null) { return null; } // 创建图 GraphVO graph = new GraphVO(); // 使用Map来存储边的信息,键为payer-payee组合,值为Edge对象 Map edgeMap = new HashMap<>(); // 使用Set去重 Set uniqueNodes = new HashSet<>(); //根据团体id查看团体明细 List userList = baseMapper.queryUserList(groupId); if (CollUtil.isNotEmpty(userList)) { List excelDataEntityList = excelDataService.queryListByPayUserList(userList, groupEntity.getCaseId()); // 遍历结果集 for (ExcelDataVO excelDataVO : excelDataEntityList) { String payer = excelDataVO.getPayUserName(); String payee = excelDataVO.getPayeeName(); double amount = excelDataVO.getAmount(); if (StringUtils.isEmpty(payee) || StringUtils.isEmpty(payer)) { continue; } // 添加节点 uniqueNodes.add(payer); uniqueNodes.add(payee); // 生成边的唯一标识 String edgeKey = payer + "-" + payee; // 检查是否已经存在这条边 if (edgeMap.containsKey(edgeKey)) { // 如果存在,更新总笔数和总金额 EdgeVO existingEdge = edgeMap.get(edgeKey); existingEdge.setTotalTransactions(existingEdge.getTotalTransactions() + 1); existingEdge.setTotalAmount(existingEdge.getTotalAmount() + amount); } else { // 如果不存在,创建新的边 String edgeId = "line-" + payer + "-" + payee; EdgeVO newEdge = new EdgeVO(edgeId, payer, payee, 1, amount); edgeMap.put(edgeKey, newEdge); } } // 添加去重后的节点 for (String node : uniqueNodes) { graph.addNode(new NodeVO(node)); } // 添加边 for (EdgeVO edge : edgeMap.values()) { graph.addEdge(edge); } return graph; } return null; } }