Commit e59d956f authored by zhuxiang's avatar zhuxiang
Browse files

团体画布接口

parent 9c02f656
...@@ -43,4 +43,9 @@ public class GroupController extends BaseController { ...@@ -43,4 +43,9 @@ public class GroupController extends BaseController {
return Result.data(groupDetailService.queryMacDetail(mac)); return Result.data(groupDetailService.queryMacDetail(mac));
} }
@GetMapping("/draw/{groupId}")
public Result draw(@PathVariable String groupId) {
return Result.data(groupDetailService.draw(groupId));
}
} }
...@@ -5,6 +5,7 @@ import com.platform.model.dto.CaseDTO; ...@@ -5,6 +5,7 @@ import com.platform.model.dto.CaseDTO;
import com.platform.model.entity.ExcelDataEntity; import com.platform.model.entity.ExcelDataEntity;
import com.platform.model.vo.ExcelDataVO; import com.platform.model.vo.ExcelDataVO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
...@@ -19,4 +20,7 @@ public interface ExcelDataMapper extends BaseMapper<ExcelDataEntity> { ...@@ -19,4 +20,7 @@ public interface ExcelDataMapper extends BaseMapper<ExcelDataEntity> {
List<ExcelDataVO> queryByCaseId(String id); List<ExcelDataVO> queryByCaseId(String id);
List<ExcelDataEntity> queryList(CaseDTO caseDTO); List<ExcelDataEntity> queryList(CaseDTO caseDTO);
List<ExcelDataEntity> queryListByPayUserList(@Param("userList") List<String> userList,
@Param("caseId") int caseId);
} }
...@@ -2,6 +2,7 @@ package com.platform.mapper; ...@@ -2,6 +2,7 @@ package com.platform.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.platform.model.dto.GroupDetailDTO; import com.platform.model.dto.GroupDetailDTO;
import com.platform.model.entity.ExcelDataEntity;
import com.platform.model.entity.GroupDetailEntity; import com.platform.model.entity.GroupDetailEntity;
import com.platform.model.vo.GroupDetailVO; import com.platform.model.vo.GroupDetailVO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
...@@ -15,4 +16,11 @@ public interface GroupDetailMapper extends BaseMapper<GroupDetailEntity> { ...@@ -15,4 +16,11 @@ public interface GroupDetailMapper extends BaseMapper<GroupDetailEntity> {
List<GroupDetailVO> queryIp(GroupDetailDTO groupDetailDTO); List<GroupDetailVO> queryIp(GroupDetailDTO groupDetailDTO);
List<GroupDetailVO> queryMac(GroupDetailDTO groupDetailDTO); List<GroupDetailVO> queryMac(GroupDetailDTO groupDetailDTO);
/**
* 根据团体id查看团体明细
* @param groupId
* @return
*/
List<String> queryUserList(String groupId);
} }
...@@ -39,4 +39,12 @@ public class EdgeVO { ...@@ -39,4 +39,12 @@ public class EdgeVO {
this.account = account; this.account = account;
} }
public EdgeVO(String id, String source, String target, int totalTransactions, double totalAmount) {
this.id = id;
this.source = source;
this.target = target;
this.totalTransactions = totalTransactions;
this.totalAmount = totalAmount;
}
} }
...@@ -46,4 +46,6 @@ public interface ExcelDataService extends IService<ExcelDataEntity> { ...@@ -46,4 +46,6 @@ public interface ExcelDataService extends IService<ExcelDataEntity> {
List<ExcelDataEntity> queryListByCaseId(String id); List<ExcelDataEntity> queryListByCaseId(String id);
List<ExcelDataEntity> queryList(CaseDTO caseDTO); List<ExcelDataEntity> queryList(CaseDTO caseDTO);
List<ExcelDataEntity> queryListByPayUserList(List<String> userList,int caseId);
} }
...@@ -3,6 +3,7 @@ package com.platform.service; ...@@ -3,6 +3,7 @@ package com.platform.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.platform.model.dto.GroupDetailDTO; import com.platform.model.dto.GroupDetailDTO;
import com.platform.model.entity.GroupDetailEntity; import com.platform.model.entity.GroupDetailEntity;
import com.platform.model.vo.GraphVO;
import com.platform.model.vo.GroupDetailVO; import com.platform.model.vo.GroupDetailVO;
import java.util.List; import java.util.List;
...@@ -17,4 +18,6 @@ public interface GroupDetailService extends IService<GroupDetailEntity> { ...@@ -17,4 +18,6 @@ public interface GroupDetailService extends IService<GroupDetailEntity> {
List<GroupDetailVO> queryMac(GroupDetailDTO groupDetailDTO); List<GroupDetailVO> queryMac(GroupDetailDTO groupDetailDTO);
List<GroupDetailEntity> queryMacDetail(String mac); List<GroupDetailEntity> queryMacDetail(String mac);
GraphVO draw(String groupId);
} }
...@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ...@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.mapper.ExcelDataMapper; import com.platform.mapper.ExcelDataMapper;
import com.platform.model.dto.CaseDTO; import com.platform.model.dto.CaseDTO;
import com.platform.model.dto.ExcelDataDTO;
import com.platform.model.entity.ExcelDataEntity; import com.platform.model.entity.ExcelDataEntity;
import com.platform.model.vo.ExcelDataVO; import com.platform.model.vo.ExcelDataVO;
import com.platform.service.ExcelDataService; import com.platform.service.ExcelDataService;
...@@ -60,4 +59,9 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData ...@@ -60,4 +59,9 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData
public List<ExcelDataEntity> queryList(CaseDTO caseDTO) { public List<ExcelDataEntity> queryList(CaseDTO caseDTO) {
return baseMapper.queryList(caseDTO); return baseMapper.queryList(caseDTO);
} }
@Override
public List<ExcelDataEntity> queryListByPayUserList(List<String> userList, int caseId) {
return baseMapper.queryListByPayUserList(userList, caseId);
}
} }
package com.platform.service.impl; package com.platform.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.mapper.GroupDetailMapper; import com.platform.mapper.GroupDetailMapper;
import com.platform.model.dto.GroupDetailDTO; import com.platform.model.dto.GroupDetailDTO;
import com.platform.model.entity.ExcelDataEntity; import com.platform.model.entity.ExcelDataEntity;
import com.platform.model.entity.GroupDetailEntity; import com.platform.model.entity.GroupDetailEntity;
import com.platform.model.entity.GroupEntity;
import com.platform.model.vo.EdgeVO;
import com.platform.model.vo.GraphVO;
import com.platform.model.vo.GroupDetailVO; import com.platform.model.vo.GroupDetailVO;
import com.platform.model.vo.NodeVO;
import com.platform.service.ExcelDataService;
import com.platform.service.GroupDetailService; import com.platform.service.GroupDetailService;
import com.platform.service.GroupService;
import com.platform.utils.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import javax.annotation.Resource;
import java.util.*;
@Service @Service
public class GroupDetailServiceImpl extends ServiceImpl<GroupDetailMapper, GroupDetailEntity> implements GroupDetailService { public class GroupDetailServiceImpl extends ServiceImpl<GroupDetailMapper, GroupDetailEntity> implements GroupDetailService {
@Resource
private GroupService groupService;
@Resource
private ExcelDataService excelDataService;
@Override @Override
public List<GroupDetailEntity> queryList(GroupDetailDTO groupDetailDTO) { public List<GroupDetailEntity> queryList(GroupDetailDTO groupDetailDTO) {
return baseMapper.selectList(new LambdaQueryWrapper<GroupDetailEntity>() return baseMapper.selectList(new LambdaQueryWrapper<GroupDetailEntity>()
...@@ -41,4 +56,70 @@ public class GroupDetailServiceImpl extends ServiceImpl<GroupDetailMapper, Group ...@@ -41,4 +56,70 @@ public class GroupDetailServiceImpl extends ServiceImpl<GroupDetailMapper, Group
return baseMapper.selectList(new LambdaQueryWrapper<GroupDetailEntity>() return baseMapper.selectList(new LambdaQueryWrapper<GroupDetailEntity>()
.eq(GroupDetailEntity::getMac, mac)); .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<String, EdgeVO> edgeMap = new HashMap<>();
// 使用Set去重
Set<String> uniqueNodes = new HashSet<>();
//根据团体id查看团体明细
List<String> userList = baseMapper.queryUserList(groupId);
if (CollUtil.isNotEmpty(userList)) {
List<ExcelDataEntity> excelDataEntityList = excelDataService.queryListByPayUserList(userList, groupEntity.getCaseId());
// 遍历结果集
for (ExcelDataEntity excelDataEntity : excelDataEntityList) {
String payer = excelDataEntity.getPayUserName();
String payee = excelDataEntity.getPayeeName();
double amount = excelDataEntity.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;
}
} }
...@@ -38,4 +38,22 @@ ...@@ -38,4 +38,22 @@
and time betwenn #{startTime} and #{endTime} and time betwenn #{startTime} and #{endTime}
</if> </if>
</select> </select>
<select id="queryListByPayUserList" resultType="com.platform.model.entity.ExcelDataEntity">
select
pay_user_name payUserName,
payee_name payeeName,
amount amount
from
excel_data
where
use_flag = 1
and
case_id = #{caseId}
and
pay_user_name in
<foreach collection="userList" item="userName" open="(" separator="," close=")">
#{userName}
</foreach>
</select>
</mapper> </mapper>
...@@ -30,4 +30,13 @@ ...@@ -30,4 +30,13 @@
GROUP BY GROUP BY
mac mac
</select> </select>
<select id="queryUserList" resultType="java.lang.String">
select
user_name
from
group_detail
where
group_id = #{groupId}
</select>
</mapper> </mapper>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment