|
@@ -2,6 +2,8 @@ package com.qizhen.healsphere.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.qizhen.healsphere.repository.mapper.KgCountInfoMapper;
|
|
|
import com.qizhen.healsphere.repository.mapper.KgCountTotalInfoMapper;
|
|
|
import com.qizhen.healsphere.repository.mapper.entity.KgCountInfo;
|
|
@@ -10,14 +12,14 @@ import com.qizhen.healsphere.service.KgCountService;
|
|
|
import com.qizhen.healsphere.web.param.KgCountListPageQuery;
|
|
|
import com.qizhen.healsphere.web.vo.CountInfoVO;
|
|
|
import com.qizhen.healsphere.web.vo.CountListVO;
|
|
|
-import com.qizhen.healsphere.web.vo.Page;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -36,63 +38,87 @@ public class KgCountServiceImpl implements KgCountService {
|
|
|
|
|
|
@Override
|
|
|
public CountInfoVO getCountTotalInfo() {
|
|
|
-
|
|
|
CountInfoVO countInfoVO = new CountInfoVO();
|
|
|
List<CountInfoVO.InfoVO> infoVOS = new ArrayList<>();
|
|
|
- CountInfoVO.InfoVO nodeTypeInfoVO = new CountInfoVO.InfoVO();
|
|
|
- nodeTypeInfoVO.setName("实体类型");
|
|
|
- nodeTypeInfoVO.setNum(0);
|
|
|
-
|
|
|
- CountInfoVO.InfoVO nodeInfoVO = new CountInfoVO.InfoVO();
|
|
|
- nodeInfoVO.setName("实体");
|
|
|
- nodeInfoVO.setNum(0);
|
|
|
-
|
|
|
- CountInfoVO.InfoVO nodePropInfoVO = new CountInfoVO.InfoVO();
|
|
|
- nodePropInfoVO.setName("实体属性");
|
|
|
- nodePropInfoVO.setNum(0);
|
|
|
-
|
|
|
- CountInfoVO.InfoVO relationTypeInfoVO = new CountInfoVO.InfoVO();
|
|
|
- relationTypeInfoVO.setName("关系类型");
|
|
|
- relationTypeInfoVO.setNum(0);
|
|
|
-
|
|
|
- CountInfoVO.InfoVO relationInfoVO = new CountInfoVO.InfoVO();
|
|
|
- relationInfoVO.setName("关系");
|
|
|
- relationInfoVO.setNum(0);
|
|
|
-
|
|
|
+
|
|
|
+ // 初始化各个统计项
|
|
|
+ infoVOS.add(createInfoVO("实体类型", 0));
|
|
|
+ infoVOS.add(createInfoVO("实体", 0));
|
|
|
+ infoVOS.add(createInfoVO("实体属性", 0));
|
|
|
+ infoVOS.add(createInfoVO("关系类型", 0));
|
|
|
+ infoVOS.add(createInfoVO("关系", 0));
|
|
|
+
|
|
|
+ // 查询统计数据 - 使用原来的方法
|
|
|
KgCountTotalInfo countTotalInfo = kgCountTotalInfoMapper.getCountTotalInfo();
|
|
|
+
|
|
|
+ // 更新统计数据
|
|
|
if (countTotalInfo != null) {
|
|
|
- nodeTypeInfoVO.setNum(countTotalInfo.getNodeTypeNum());
|
|
|
- nodeInfoVO.setNum(countTotalInfo.getNodeNum());
|
|
|
- nodePropInfoVO.setNum(countTotalInfo.getNodePropNum());
|
|
|
- relationTypeInfoVO.setNum(countTotalInfo.getRelationTypeNum());
|
|
|
- relationInfoVO.setNum(countTotalInfo.getRelationNum());
|
|
|
+ infoVOS.get(0).setNum(countTotalInfo.getNodeTypeNum());
|
|
|
+ infoVOS.get(1).setNum(countTotalInfo.getNodeNum());
|
|
|
+ infoVOS.get(2).setNum(countTotalInfo.getNodePropNum());
|
|
|
+ infoVOS.get(3).setNum(countTotalInfo.getRelationTypeNum());
|
|
|
+ infoVOS.get(4).setNum(countTotalInfo.getRelationNum());
|
|
|
}
|
|
|
- infoVOS.add(nodeTypeInfoVO);
|
|
|
- infoVOS.add(nodeInfoVO);
|
|
|
- infoVOS.add(nodePropInfoVO);
|
|
|
- infoVOS.add(relationTypeInfoVO);
|
|
|
- infoVOS.add(relationInfoVO);
|
|
|
+
|
|
|
countInfoVO.setInfos(infoVOS);
|
|
|
return countInfoVO;
|
|
|
}
|
|
|
|
|
|
+ private CountInfoVO.InfoVO createInfoVO(String name, Integer num) {
|
|
|
+ CountInfoVO.InfoVO infoVO = new CountInfoVO.InfoVO();
|
|
|
+ infoVO.setName(name);
|
|
|
+ infoVO.setNum(num);
|
|
|
+ return infoVO;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
- public Page<CountListVO> getCountListInfo(KgCountListPageQuery query) {
|
|
|
- Integer pageNo = query.getPageNo();
|
|
|
- Integer pageSize = query.getPageSize();
|
|
|
-
|
|
|
- Integer count = kgCountInfoMapper.count();
|
|
|
- List<CountListVO> listVOS = new ArrayList<>();
|
|
|
- if (count > 0){
|
|
|
- List<KgCountInfo> countList = kgCountInfoMapper.getCountList(pageSize, (pageNo - 1) * pageSize);
|
|
|
- if (CollUtil.isNotEmpty(countList)){
|
|
|
- countList.forEach(kgCountInfo -> {
|
|
|
- CountListVO countListVO = BeanUtil.copyProperties(kgCountInfo, CountListVO.class);
|
|
|
- listVOS.add(countListVO);
|
|
|
- });
|
|
|
+ public com.qizhen.healsphere.web.vo.Page<CountListVO> getCountListInfo(KgCountListPageQuery query) {
|
|
|
+ try {
|
|
|
+ // 在这里设置断点
|
|
|
+ Page<KgCountInfo> page = new Page<>(query.getPageNo(), query.getPageSize());
|
|
|
+
|
|
|
+ // 在这里设置断点
|
|
|
+ QueryWrapper<KgCountInfo> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.orderByDesc("node_num");
|
|
|
+
|
|
|
+ // 在这里设置断点
|
|
|
+ Page<KgCountInfo> result = kgCountInfoMapper.selectPage(page, queryWrapper);
|
|
|
+
|
|
|
+ if (result == null || result.getRecords() == null) {
|
|
|
+ log.warn("查询结果为null");
|
|
|
+ return new com.qizhen.healsphere.web.vo.Page<>(query.getPageNo(), query.getPageSize(), 0, 0, new ArrayList<>());
|
|
|
}
|
|
|
+
|
|
|
+ log.info("查询到 {} 条记录", result.getRecords().size());
|
|
|
+ result.getRecords().forEach(record -> {
|
|
|
+ log.info("记录详情: {}", record);
|
|
|
+ log.info("SQL查询结果字段值: id={}, nodeType={}, nodeNum={}, nodePropNum={}, relationType={}, relationNum={}",
|
|
|
+ record.getId(), record.getNodeType(), record.getNodeNum(),
|
|
|
+ record.getNodePropNum(), record.getRelationType(), record.getRelationNum());
|
|
|
+ });
|
|
|
+
|
|
|
+ // 转换为 VO 对象
|
|
|
+ List<CountListVO> listVOS = result.getRecords().stream()
|
|
|
+ .map(info -> {
|
|
|
+ CountListVO vo = new CountListVO();
|
|
|
+ log.info("转换前的实体对象: {}", info);
|
|
|
+ BeanUtil.copyProperties(info, vo);
|
|
|
+ log.info("转换后的VO对象: {}", vo);
|
|
|
+ return vo;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ return new com.qizhen.healsphere.web.vo.Page<>(
|
|
|
+ query.getPageNo(),
|
|
|
+ query.getPageSize(),
|
|
|
+ listVOS.size(),
|
|
|
+ (int)result.getTotal(),
|
|
|
+ listVOS
|
|
|
+ );
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("获取统计列表失败", e);
|
|
|
+ throw new RuntimeException("获取统计列表失败", e);
|
|
|
}
|
|
|
- return new Page<>(pageNo,pageSize,listVOS.size(),count,listVOS);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -100,13 +126,8 @@ public class KgCountServiceImpl implements KgCountService {
|
|
|
public Boolean updateStatisticsData() {
|
|
|
try {
|
|
|
log.info("开始更新统计数据...");
|
|
|
-
|
|
|
- // 1. 更新总体统计信息
|
|
|
updateTotalInfo();
|
|
|
-
|
|
|
- // 2. 更新分类统计信息
|
|
|
updateDetailInfo();
|
|
|
-
|
|
|
log.info("统计数据更新完成");
|
|
|
return true;
|
|
|
} catch (Exception e) {
|
|
@@ -116,42 +137,42 @@ public class KgCountServiceImpl implements KgCountService {
|
|
|
}
|
|
|
|
|
|
private void updateTotalInfo() {
|
|
|
- // 1. 获取新的统计数据
|
|
|
KgCountTotalInfo totalInfo = kgCountTotalInfoMapper.calculateTotalInfo();
|
|
|
+ log.info("计算得到的统计数据: {}", totalInfo);
|
|
|
if (totalInfo == null) {
|
|
|
throw new RuntimeException("计算总体统计数据失败");
|
|
|
}
|
|
|
|
|
|
- // 2. 查询现有数据
|
|
|
KgCountTotalInfo existingInfo = kgCountTotalInfoMapper.getCountTotalInfo();
|
|
|
-
|
|
|
- // 3. 更新或插入数据
|
|
|
+ log.info("查询到的现有数据: {}", existingInfo);
|
|
|
+
|
|
|
if (existingInfo != null) {
|
|
|
totalInfo.setId(existingInfo.getId());
|
|
|
- kgCountTotalInfoMapper.update(totalInfo);
|
|
|
+ kgCountTotalInfoMapper.updateById(totalInfo);
|
|
|
log.info("更新总体统计数据成功");
|
|
|
} else {
|
|
|
totalInfo.setId(1L);
|
|
|
- kgCountTotalInfoMapper.save(totalInfo);
|
|
|
+ kgCountTotalInfoMapper.insert(totalInfo);
|
|
|
log.info("插入总体统计数据成功");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void updateDetailInfo() {
|
|
|
try {
|
|
|
- // 1. 获取新的分类统计数据
|
|
|
List<KgCountInfo> detailInfoList = kgCountInfoMapper.calculateDetailInfo();
|
|
|
if (CollUtil.isEmpty(detailInfoList)) {
|
|
|
log.warn("没有获取到分类统计数据");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 2. 清空现有数据
|
|
|
- kgCountInfoMapper.clearTable();
|
|
|
+ // 清空现有数据
|
|
|
+ kgCountInfoMapper.delete(null);
|
|
|
log.info("清空分类统计表成功");
|
|
|
|
|
|
- // 3. 批量插入新数据
|
|
|
- kgCountInfoMapper.batchInsert(detailInfoList);
|
|
|
+ // 批量插入新数据
|
|
|
+ for (KgCountInfo info : detailInfoList) {
|
|
|
+ kgCountInfoMapper.insert(info);
|
|
|
+ }
|
|
|
log.info("插入分类统计数据成功,共 {} 条记录", detailInfoList.size());
|
|
|
} catch (Exception e) {
|
|
|
log.error("更新分类统计数据失败", e);
|