|
|
@@ -7,28 +7,26 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.google.common.collect.Lists;
|
|
|
-import com.xunmei.common.core.constant.CacheConstants;
|
|
|
import com.xunmei.common.core.constant.Constants;
|
|
|
import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
import com.xunmei.common.core.domain.iot.domain.IotDailyCheckData;
|
|
|
+import com.xunmei.common.core.domain.iot.domain.IotServerInfo;
|
|
|
import com.xunmei.common.core.domain.iot.vo.DailyCheckReq;
|
|
|
import com.xunmei.common.core.utils.NumberUtils;
|
|
|
import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
-import com.xunmei.common.redis.utils.RedisUtils;
|
|
|
import com.xunmei.iot.dto.dailycheck.DailyCheckDataPageDto;
|
|
|
import com.xunmei.iot.mapper.IotDailyCheckDataMapper;
|
|
|
import com.xunmei.iot.service.IotDailyCheckDataService;
|
|
|
+import com.xunmei.iot.service.IotServerInfoService;
|
|
|
import com.xunmei.iot.vo.dayilcheck.DailyCheckDataPageVo;
|
|
|
import com.xunmei.iot.vo.dayilcheck.DailyCheckDataRateData;
|
|
|
import com.xunmei.iot.vo.dayilcheck.DailyCheckDataStatisticsData;
|
|
|
import com.xunmei.iot.vo.dayilcheck.DailyCheckItemExportVo;
|
|
|
import com.xunmei.system.api.RemoteOrgService;
|
|
|
import com.xunmei.system.api.domain.SysOrg;
|
|
|
-import com.xunmei.system.api.vo.SysOrgVO;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
@@ -39,8 +37,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
|
import java.net.URLEncoder;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -56,6 +53,8 @@ public class IotDailyCheckDataServiceImpl extends ServiceImpl<IotDailyCheckDataM
|
|
|
|
|
|
@Resource
|
|
|
private RemoteOrgService remoteOrgService;
|
|
|
+ @Resource
|
|
|
+ private IotServerInfoService serverInfoService;
|
|
|
|
|
|
@Override
|
|
|
public TableDataInfo selectPage(DailyCheckDataPageDto req) {
|
|
|
@@ -84,77 +83,105 @@ public class IotDailyCheckDataServiceImpl extends ServiceImpl<IotDailyCheckDataM
|
|
|
@Override
|
|
|
public DailyCheckDataStatisticsData statistics(DailyCheckDataPageDto req) {
|
|
|
this.dealReqParam(req);
|
|
|
- LambdaQueryWrapper<IotDailyCheckData> wrapper = new LambdaQueryWrapper<IotDailyCheckData>();
|
|
|
- if (req.getCheckSub()) {
|
|
|
- wrapper.likeRight(IotDailyCheckData::getOrgPath, req.getOrgPath());
|
|
|
- } else {
|
|
|
- wrapper.eq(IotDailyCheckData::getOrgId, req.getOrgId());
|
|
|
- }
|
|
|
- wrapper.between(IotDailyCheckData::getRecordDate, req.getRange()[0], req.getRange()[1]);
|
|
|
- wrapper.select(IotDailyCheckData::getOrgId, IotDailyCheckData::getOrgName, IotDailyCheckData::getRecordDate);
|
|
|
- List<IotDailyCheckData> list = baseMapper.selectList(wrapper);
|
|
|
+ //查询某段时间内执行了检查的主机
|
|
|
+ final List<IotDailyCheckData> dataList = baseMapper.selectCheckData(req);
|
|
|
+ //查询范围内的所有主机,因为只统计接入了的主机的自检情况
|
|
|
+ final List<IotServerInfo> connectHost = serverInfoService.selectConnectOrg(req.getCheckSub(), req.getOrgId(), req.getOrgPath());
|
|
|
+ //将日期范围分组
|
|
|
List<String> dateStrList = DateUtil.rangeToList(DateUtil.parse(req.getRange()[0]), DateUtil.parse(req.getRange()[1]), DateField.DAY_OF_YEAR)
|
|
|
.stream()
|
|
|
.map(d -> DateUtil.format(d, Constants.DAILY_FORMAT))
|
|
|
.collect(Collectors.toList());
|
|
|
+ //如果范围内没有主机执行过自建,那么,已检/半检都为空,未检即范围内的每天都是检查
|
|
|
DailyCheckDataStatisticsData statisticsData = new DailyCheckDataStatisticsData();
|
|
|
- if (ObjectUtil.isEmpty(list)) {
|
|
|
+ if (ObjectUtil.isEmpty(dataList)) {
|
|
|
List<String> doDateList = Lists.newArrayList();
|
|
|
statisticsData.setDoDates(doDateList);
|
|
|
+ statisticsData.setHalfDoDates(doDateList);
|
|
|
statisticsData.setUnDoDates(dateStrList);
|
|
|
return statisticsData;
|
|
|
}
|
|
|
- List<String> doDateList = list.stream().map(IotDailyCheckData::getRecordDate).map(d -> DateUtil.format(d, Constants.DAILY_FORMAT)).collect(Collectors.toList());
|
|
|
- List<String> undoDateList = dateStrList.stream().filter(r -> !doDateList.contains(r)).distinct().collect(Collectors.toList());
|
|
|
- statisticsData.setDoDates(doDateList);
|
|
|
- statisticsData.setUnDoDates(undoDateList);
|
|
|
+ //将执行过检查的主机按日期分组
|
|
|
+ final Map<String, List<IotDailyCheckData>> listMap = dataList.stream().collect(Collectors.groupingBy(r -> DateUtil.format(r.getRecordDate(), Constants.DAILY_FORMAT)));
|
|
|
+ //遍历日期范围,如果某天没有执行过检查,那么,未检日期列表中添加该日期
|
|
|
+ Set<String> doDateSet = new HashSet<>();
|
|
|
+ Set<String> undoDateSet = new HashSet<>();
|
|
|
+ Set<String> halfDoDateSet = new HashSet<>();
|
|
|
+ //将接入的主机按机构分组,用于判断机构内的所有主机是否全部都执行了自检的,如果有一台没有自检,那么当天就是半检
|
|
|
+ final Map<Long, List<IotServerInfo>> orgHostMap = connectHost.stream().collect(Collectors.groupingBy(IotServerInfo::getOrgId));
|
|
|
+ item1:
|
|
|
+ for (String dateStr : dateStrList) {
|
|
|
+ //获取当天自检情况
|
|
|
+ final List<IotDailyCheckData> checkDataList = listMap.get(dateStr);
|
|
|
+ //如果当天没有执行过检查,那么,未检日期列表中添加该日期
|
|
|
+ if (ObjectUtil.isEmpty(checkDataList)) {
|
|
|
+ undoDateSet.add(dateStr);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //随后将检查过的主机按机构分组
|
|
|
+ final Map<Long, List<IotDailyCheckData>> orgCheckDataMap = checkDataList.stream().collect(Collectors.groupingBy(IotDailyCheckData::getOrgId));
|
|
|
+ //遍历机构,如果机构内的所有主机都执行了自检,那么,已检日期列表中添加该日期
|
|
|
+ int doNums = 0;
|
|
|
+ for (Long orgId : orgHostMap.keySet()) {
|
|
|
+ final List<IotServerInfo> hostList = orgHostMap.get(orgId);
|
|
|
+ final List<IotDailyCheckData> checkDataList1 = orgCheckDataMap.get(orgId);
|
|
|
+ if (ObjectUtil.isAllNotEmpty(hostList, checkDataList1) && hostList.size() == checkDataList1.size()) {
|
|
|
+ doNums++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (doNums == orgHostMap.size()) {//全部执行了自检
|
|
|
+ doDateSet.add(dateStr);
|
|
|
+ } else if (doNums > 0) {
|
|
|
+ halfDoDateSet.add(dateStr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ statisticsData.setDoDates(new ArrayList<>(doDateSet));
|
|
|
+ statisticsData.setUnDoDates(new ArrayList<>(undoDateSet));
|
|
|
+ statisticsData.setHalfDoDates(new ArrayList<>(halfDoDateSet));
|
|
|
return statisticsData;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public DailyCheckDataRateData rate(DailyCheckDataPageDto req) {
|
|
|
- int orgNum = 1;
|
|
|
- if (req.getCheckSub()) {
|
|
|
- //List<SysOrg> cacheList = remoteOrgService.selectOrgByPath(req.getOrgId());
|
|
|
- List<SysOrgVO> cacheList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
|
|
|
- SysOrgVO sysOrgVO1 = cacheList.stream().filter(r -> ObjectUtil.equal(r.getId(), req.getOrgId())).findFirst().get();
|
|
|
- req.setOrgPath(sysOrgVO1.getPath());
|
|
|
- int i = 0;
|
|
|
- for (SysOrgVO sysOrgVO : cacheList) {
|
|
|
- try {
|
|
|
- if (sysOrgVO.getPath().startsWith(req.getOrgPath())) {
|
|
|
- i++;
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println(sysOrgVO);
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
+ this.dealReqParam(req);
|
|
|
+ //查询某段时间内执行了检查的主机
|
|
|
+ final List<IotDailyCheckData> dataList = baseMapper.selectCheckData(req);
|
|
|
+ //查询范围内的所有主机,因为只统计接入了的主机的自检情况
|
|
|
+ final List<IotServerInfo> connectHost = serverInfoService.selectConnectOrg(req.getCheckSub(), req.getOrgId(), req.getOrgPath());
|
|
|
+ //将日期范围分组
|
|
|
+ List<String> dateStrList = DateUtil.rangeToList(DateUtil.parse(req.getRange()[0]), DateUtil.parse(req.getRange()[1]), DateField.DAY_OF_YEAR)
|
|
|
+ .stream()
|
|
|
+ .map(d -> DateUtil.format(d, Constants.DAILY_FORMAT))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ final Map<String, List<IotDailyCheckData>> listMap = dataList.stream().collect(Collectors.groupingBy(IotDailyCheckData::getIotCode));
|
|
|
+ int hostNums = connectHost.size() * dateStrList.size();
|
|
|
+ int doNums = 0;
|
|
|
+ int unDoNums = 0;
|
|
|
+ int halfDoNums = 0;
|
|
|
+ //循环每台主机
|
|
|
+ for (IotServerInfo serverInfo : connectHost) {
|
|
|
+ //从检查数据中找到当前主机的检查数据
|
|
|
+ final List<IotDailyCheckData> checkDataList = listMap.get(serverInfo.getIotCode());
|
|
|
+ //如果为空,当前主机每一天都是0,即当天主机日期范围内都没执行过自检
|
|
|
+ if (ObjectUtil.isEmpty(checkDataList)) {
|
|
|
+ unDoNums += dateStrList.size();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //如果有执行过检查
|
|
|
+ for (String dateStr : dateStrList) {
|
|
|
+ if (checkDataList.stream().anyMatch(d -> ObjectUtil.equal(DateUtil.format(d.getRecordDate(), Constants.DAILY_FORMAT), dateStr))) {
|
|
|
+ doNums++;
|
|
|
+ } else
|
|
|
+ unDoNums++;
|
|
|
}
|
|
|
- orgNum = (int) cacheList.stream().filter(r -> ObjectUtil.isNotNull(r) && ObjectUtil.isNotNull(r.getPath()) && r.getPath().startsWith(req.getOrgPath())).count();
|
|
|
}
|
|
|
DailyCheckDataRateData rateData = new DailyCheckDataRateData();
|
|
|
- LambdaQueryWrapper<IotDailyCheckData> wrapper = new LambdaQueryWrapper<>();
|
|
|
- if (req.getCheckSub()) {
|
|
|
- wrapper.likeRight(IotDailyCheckData::getOrgPath, req.getOrgPath());
|
|
|
- } else {
|
|
|
- wrapper.eq(IotDailyCheckData::getOrgId, req.getOrgId());
|
|
|
- }
|
|
|
- wrapper.between(IotDailyCheckData::getRecordDate, req.getRange()[0], req.getRange()[1]);
|
|
|
- wrapper.select(IotDailyCheckData::getOrgId, IotDailyCheckData::getOrgName, IotDailyCheckData::getRecordDate);
|
|
|
- List<IotDailyCheckData> list = baseMapper.selectList(wrapper);
|
|
|
- if (ObjectUtil.isEmpty(list)) {
|
|
|
- rateData.setDoNums(0);
|
|
|
- rateData.setUnDoNums(orgNum);
|
|
|
- rateData.setDoRate(NumberUtils.computeRate(orgNum, 0));
|
|
|
- rateData.setUnDoRate(NumberUtils.computeRate(orgNum, orgNum));
|
|
|
- return rateData;
|
|
|
- }
|
|
|
- int count = (int) list.stream().map(IotDailyCheckData::getOrgId).distinct().count();
|
|
|
- int unDoNums = orgNum - count;
|
|
|
- rateData.setDoNums(count);
|
|
|
+ rateData.setDoNums(doNums);
|
|
|
rateData.setUnDoNums(unDoNums);
|
|
|
- rateData.setDoRate(NumberUtils.computeRate(orgNum, count));
|
|
|
- rateData.setUnDoRate(NumberUtils.computeRate(orgNum, unDoNums));
|
|
|
+ rateData.setHalfDoNums(halfDoNums);
|
|
|
+ rateData.setDoRate(NumberUtils.computeRate(hostNums, doNums));
|
|
|
+ rateData.setUnDoRate(NumberUtils.computeRate(hostNums, unDoNums));
|
|
|
+ rateData.setHalfDoRate(NumberUtils.computeRate(hostNums, halfDoNums));
|
|
|
return rateData;
|
|
|
}
|
|
|
|
|
|
@@ -189,7 +216,8 @@ public class IotDailyCheckDataServiceImpl extends ServiceImpl<IotDailyCheckDataM
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void exportToExcel(List<DailyCheckItemExportVo> exportDataList, HttpServletResponse response) throws IOException {
|
|
|
+ public static void exportToExcel(List<DailyCheckItemExportVo> exportDataList, HttpServletResponse response) throws
|
|
|
+ IOException {
|
|
|
// 创建一个新的Excel 工作簿
|
|
|
Workbook workbook = new XSSFWorkbook();
|
|
|
// 创建一个工作表sheet
|
|
|
@@ -274,7 +302,8 @@ public class IotDailyCheckDataServiceImpl extends ServiceImpl<IotDailyCheckDataM
|
|
|
}
|
|
|
|
|
|
|
|
|
- private static CellStyle createHeaderCellStyle(Workbook workbook, int fontSize, HorizontalAlignment alignment, boolean bgColor) {
|
|
|
+ private static CellStyle createHeaderCellStyle(Workbook workbook, int fontSize, HorizontalAlignment alignment,
|
|
|
+ boolean bgColor) {
|
|
|
CellStyle headerStyle = workbook.createCellStyle();
|
|
|
if (bgColor) {
|
|
|
headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
|
|
|
@@ -299,7 +328,7 @@ public class IotDailyCheckDataServiceImpl extends ServiceImpl<IotDailyCheckDataM
|
|
|
req.setPageSize(Integer.MAX_VALUE);
|
|
|
TableDataInfo page = this.selectPage(req);
|
|
|
List<DailyCheckDataPageVo> rows = page.getRows();
|
|
|
- if (ObjectUtil.isEmpty(rows)){
|
|
|
+ if (ObjectUtil.isEmpty(rows)) {
|
|
|
throw new RuntimeException("暂无可用数据导出");
|
|
|
}
|
|
|
List<DailyCheckDataPageVo> collect = rows.stream().peek(r -> r.setId((long) rows.indexOf(r) + 1)).collect(Collectors.toList());
|