|
|
@@ -1,12 +1,15 @@
|
|
|
package com.xunmei.core.reportForms.monitor.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.xunmei.common.core.constant.CacheConstants;
|
|
|
import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
import com.xunmei.common.core.enums.OrgTypeEnum;
|
|
|
import com.xunmei.common.core.utils.DateHelper;
|
|
|
import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
+import com.xunmei.common.redis.utils.RedisUtils;
|
|
|
import com.xunmei.common.security.utils.SecurityUtils;
|
|
|
import com.xunmei.core.edu.service.impl.ValueCellWriteHandler;
|
|
|
import com.xunmei.core.reportForms.monitor.dto.MonitoringAccessDTO;
|
|
|
@@ -15,6 +18,7 @@ import com.xunmei.core.reportForms.monitor.service.MonitorAccessReportService;
|
|
|
import com.xunmei.core.reportForms.monitor.vo.MonitoringAccessVO;
|
|
|
import com.xunmei.system.api.RemoteOrgService;
|
|
|
import com.xunmei.system.api.domain.SysOrg;
|
|
|
+import com.xunmei.system.api.vo.SysOrgVO;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -25,6 +29,8 @@ import java.net.URLEncoder;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
|
import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author :LuoWei
|
|
|
@@ -90,31 +96,40 @@ public class MonitorAccessReportServiceImpl implements MonitorAccessReportServic
|
|
|
|
|
|
@Override
|
|
|
public List<MonitoringAccessVO> selectAll(MonitoringAccessDTO monitoringAccessDTO) {
|
|
|
- if (monitoringAccessDTO.getStartDate().endsWith("32")){
|
|
|
+ if (monitoringAccessDTO.getStartDate().endsWith("32")) {
|
|
|
String[] split = monitoringAccessDTO.getEndDate().split("-");
|
|
|
- monitoringAccessDTO.setStartDate(split[0]+"-"+split[1] + "-01 00:00:00");
|
|
|
+ monitoringAccessDTO.setStartDate(split[0] + "-" + split[1] + "-01 00:00:00");
|
|
|
}
|
|
|
monitoringAccessDTO.setStartDate(monitoringAccessDTO.getStartDate() + " 00:00:00");
|
|
|
monitoringAccessDTO.setEndDate(monitoringAccessDTO.getEndDate() + " 23:59:59");
|
|
|
if (null == monitoringAccessDTO.getOrgId()) {
|
|
|
monitoringAccessDTO.setOrgId(SecurityUtils.getLoginUser().getOrgId());
|
|
|
}
|
|
|
- Long orgId=monitoringAccessDTO.getOrgId();
|
|
|
+ Long orgId = monitoringAccessDTO.getOrgId();
|
|
|
+ List<SysOrgVO> cacheList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
|
|
|
+ // 创建一个Map来存储SysOrgVO的ID和对象
|
|
|
+ Map<Long, SysOrgVO> sysOrgMap = cacheList.stream()
|
|
|
+ .collect(Collectors.toMap(SysOrgVO::getId, Function.identity()));
|
|
|
//判断机构类型,如果机构类型大于行社,都展示行社数据
|
|
|
- SysOrg sysOrg = remoteOrgService.selectSysOrgById(monitoringAccessDTO.getOrgId(), SecurityConstants.INNER);
|
|
|
- List<SysOrg> sysOrgs;
|
|
|
- if (null==sysOrg.getType()){
|
|
|
+ Optional<SysOrgVO> first = cacheList.stream().filter(s -> ObjectUtil.equal(s.getId(), monitoringAccessDTO.getOrgId())).findFirst();
|
|
|
+ if (!first.isPresent()){
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ SysOrgVO sysOrg=first.get();
|
|
|
+ List<SysOrgVO> sysOrgs;
|
|
|
+ if (null == sysOrg.getType()) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
if (sysOrg.getType() < 3 || sysOrg.getShortName().endsWith("地区行社") || sysOrg.getType() == 9) {
|
|
|
- sysOrgs = remoteOrgService.selectSysOrgByPathAndType(sysOrg.getPath(), 3, SecurityConstants.INNER);
|
|
|
+ sysOrgs = cacheList.stream().filter(r->ObjectUtil.equal(r.getType(),3)).filter(r->r.getPath().startsWith(sysOrg.getPath())).collect(Collectors.toList());
|
|
|
} else if (sysOrg.getType() == 3) {
|
|
|
- sysOrgs = remoteOrgService.selectSysOrgByPathAndType(sysOrg.getPath(), 4, SecurityConstants.INNER);
|
|
|
+ sysOrgs = cacheList.stream().filter(r->ObjectUtil.equal(r.getType(),4)).filter(r->r.getPath().startsWith(sysOrg.getPath())).collect(Collectors.toList());
|
|
|
} else {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
- List<MonitoringAccessVO> monitoringAccessVOList = new ArrayList<>();
|
|
|
- sysOrgs.forEach(s -> {
|
|
|
+
|
|
|
+ /* sysOrgs.forEach(s -> {
|
|
|
+ Long condOrgId=monitoringAccessDTO.getOrgId();
|
|
|
MonitoringAccessVO monitoringAccessVO = new MonitoringAccessVO();
|
|
|
SysOrg sysOrg1;
|
|
|
if (sysOrg.getType() < 3 || sysOrg.getShortName().endsWith("地区行社") || sysOrg.getType() == 9) {
|
|
|
@@ -148,8 +163,78 @@ public class MonitorAccessReportServiceImpl implements MonitorAccessReportServic
|
|
|
monitoringAccessVOList.add(monitoringAccessVO);
|
|
|
|
|
|
monitoringAccessDTO.setOrgId(condOrgId);
|
|
|
- });
|
|
|
- return monitoringAccessVOList;
|
|
|
+ });*/
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 使用流式处理来遍历sysOrgs
|
|
|
+ return sysOrgs.stream()
|
|
|
+ .map(s -> {
|
|
|
+ MonitoringAccessVO monitoringAccessVO = new MonitoringAccessVO();
|
|
|
+ // 从缓存中获取SysOrg对象
|
|
|
+ //SysOrgVO sysOrg1 = getSysOrgFromCache(s.getParentId(), sysOrgMap);
|
|
|
+ SysOrgVO sysOrg1;
|
|
|
+ if (sysOrg.getType() < 3 || sysOrg.getShortName().endsWith("地区行社") || sysOrg.getType() == 9) {
|
|
|
+ sysOrg1 = getOrgFromCache(s.getParentId(), sysOrgMap);
|
|
|
+ } else {
|
|
|
+ Long parentId = getOrgFromCache(s.getParentId(), sysOrgMap).getParentId();
|
|
|
+ sysOrg1 = getOrgFromCache(parentId, sysOrgMap);
|
|
|
+ if (!sysOrg1.getShortName().contains("地区行社")) {
|
|
|
+ SysOrgVO org1 = getOrgFromCache(s.getParentId(), sysOrgMap);
|
|
|
+ SysOrgVO org2 = getOrgFromCache(org1.getParentId(), sysOrgMap);
|
|
|
+ sysOrg1 = getOrgFromCache(org2.getParentId(), sysOrgMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ monitoringAccessVO.setCity(getCityName(sysOrg1));
|
|
|
+ int orgNum = (int) cacheList.stream()
|
|
|
+ .filter(r -> ObjectUtil.equal(OrgTypeEnum.YINGYE_WANGDIAN.getCode(), r.getType()))
|
|
|
+ .filter(r -> r.getPath().startsWith(s.getPath()))
|
|
|
+ .count();
|
|
|
+ monitoringAccessDTO.setOrgPath(s.getPath());
|
|
|
+ MonitoringAccessVO monitoringAccessVO1;
|
|
|
+ String avg;
|
|
|
+ if (s.getType() != 4) {
|
|
|
+ monitoringAccessDTO.setOrgId(null);
|
|
|
+ monitoringAccessVO1 = monitorAccessReportMapper.selectAll(monitoringAccessDTO);
|
|
|
+ avg = monitorAccessReportMapper.avg(monitoringAccessDTO);
|
|
|
+ monitoringAccessDTO.setOrgId(orgId);
|
|
|
+ } else {
|
|
|
+ orgNum = 1;
|
|
|
+ monitoringAccessDTO.setOrgId(s.getId());
|
|
|
+ monitoringAccessVO1 = monitorAccessReportMapper.selectAll(monitoringAccessDTO);
|
|
|
+ avg = monitorAccessReportMapper.avg(monitoringAccessDTO);
|
|
|
+ }
|
|
|
+ // 设置其他属性
|
|
|
+ monitoringAccessVO.setDuration(avg);
|
|
|
+ monitoringAccessVO.setNetworkNumber(orgNum);
|
|
|
+ monitoringAccessVO.setAccessRate(monitoringAccessVO1.getAccessRate());
|
|
|
+ monitoringAccessVO.setOrgName(s.getShortName());
|
|
|
+ monitoringAccessVO.setPlanAccessNumber(monitoringAccessVO1.getPlanAccessNumber());
|
|
|
+ monitoringAccessVO.setRealityAccessNumber(monitoringAccessVO1.getRealityAccessNumber());
|
|
|
+ // 重置orgId
|
|
|
+ monitoringAccessDTO.setOrgId(orgId);
|
|
|
+
|
|
|
+ return monitoringAccessVO;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 方法引用:从缓存中获取SysOrg对象
|
|
|
+ private SysOrgVO getOrgFromCache(Long parentId, Map<Long, SysOrgVO> sysOrgMap) {
|
|
|
+ return sysOrgMap.computeIfAbsent(parentId, this::getOrgFromCache);
|
|
|
+ }
|
|
|
+
|
|
|
+ private SysOrgVO getOrgFromCache(Long parentId) {
|
|
|
+ SysOrg sysOrg = remoteOrgService.selectOrgById(parentId, SecurityConstants.INNER);
|
|
|
+ return BeanUtil.copyProperties(sysOrg, SysOrgVO.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 方法引用:获取城市名称
|
|
|
+ private String getCityName(SysOrgVO sysOrg1) {
|
|
|
+ String shortName = sysOrg1.getShortName();
|
|
|
+ return shortName.endsWith("地区行社") ? shortName.split("地区行社")[0] : shortName.substring(0, 2);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -171,11 +256,11 @@ public class MonitorAccessReportServiceImpl implements MonitorAccessReportServic
|
|
|
if (monitoringAccessVOS.size() > 10000) {
|
|
|
throw new RuntimeException("导出数据量过大(单次导出限量10000条数据),请填写条件分批导出");
|
|
|
}
|
|
|
- String baseHeaderName="监控调阅情况表";
|
|
|
- String header=getTitle(monitoringAccessDTO);
|
|
|
+ String baseHeaderName = "监控调阅情况表";
|
|
|
+ String header = getTitle(monitoringAccessDTO);
|
|
|
response.setContentType("application/vnd.ms-excel");
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
- String fileName = URLEncoder.encode("【" + orgName + "】-"+baseHeaderName + DateHelper.getDateString(new Date()), "UTF-8");
|
|
|
+ String fileName = URLEncoder.encode("【" + orgName + "】-" + baseHeaderName + DateHelper.getDateString(new Date()), "UTF-8");
|
|
|
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
|
|
// 调用EasyExcel的导出方法
|
|
|
EasyExcel.write(response.getOutputStream(), MonitoringAccessVO.class)
|
|
|
@@ -201,7 +286,7 @@ public class MonitorAccessReportServiceImpl implements MonitorAccessReportServic
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
// String title = sysOrg.getShortName() + "监控调阅情况表" + "(" + st + "~" + en + ")";
|
|
|
- String title = "监控调阅情况表" + "(" + st + "~" + en + ")";
|
|
|
+ String title = "监控调阅情况表" + "(" + st + "~" + en + ")";
|
|
|
return title;
|
|
|
}
|
|
|
|