Просмотр исходного кода

网点自检代码修改提交

jingyuanchao 1 год назад
Родитель
Сommit
27cf28e9e2

+ 4 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/mapper/IotDailyCheckDataMapper.java

@@ -7,6 +7,8 @@ import com.xunmei.iot.dto.dailycheck.DailyCheckDataPageDto;
 import com.xunmei.iot.vo.dayilcheck.DailyCheckDataPageVo;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 /**
  * <p>
  * 网点日常自检日志表 Mapper 接口
@@ -18,4 +20,6 @@ import org.apache.ibatis.annotations.Param;
 public interface IotDailyCheckDataMapper extends BaseMapper<IotDailyCheckData> {
 
     Page<DailyCheckDataPageVo> selectPageData(Page<DailyCheckDataPageVo> pageRequest, @Param("req") DailyCheckDataPageDto req);
+
+    List<IotDailyCheckData> selectCheckData(@Param("req") DailyCheckDataPageDto req);
 }

+ 5 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/mapper/IotServerInfoMapper.java

@@ -7,6 +7,8 @@ import com.xunmei.iot.dto.serverInfo.IotServerInfoPageDto;
 import com.xunmei.iot.vo.serverInfo.IotServerInfoPageVo;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 /**
  * <p>
  * iot客户端信息 Mapper 接口
@@ -18,4 +20,7 @@ import org.apache.ibatis.annotations.Param;
 public interface IotServerInfoMapper extends BaseMapper<IotServerInfo> {
 
     Page<IotServerInfoPageVo> selectServerPage(Page<IotServerInfoPageVo> pageRequest, @Param("req") IotServerInfoPageDto req);
+
+    List<IotServerInfo> selectConnectOrg(@Param("checkSub") Boolean checkSub, @Param("orgId") Long orgId, @Param("orgPath") String orgPath);
+
 }

+ 4 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/IotServerInfoService.java

@@ -8,6 +8,7 @@ import com.xunmei.iot.dto.serverInfo.IotServerInfoPageDto;
 import com.xunmei.iot.vo.serverInfo.IotServerInfoPageVo;
 
 import javax.servlet.http.HttpServletResponse;
+import java.util.List;
 
 /**
  * <p>
@@ -28,4 +29,7 @@ public interface IotServerInfoService extends IService<IotServerInfo> {
     void export(IotServerInfoPageDto req, HttpServletResponse response);
 
     void del(Long id);
+
+
+    List<IotServerInfo> selectConnectOrg(Boolean checkSub, Long orgId, String orgPath);
 }

+ 90 - 61
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotDailyCheckDataServiceImpl.java

@@ -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());

+ 7 - 2
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotServerInfoServiceImpl.java

@@ -21,7 +21,6 @@ import com.xunmei.iot.service.IotAlarmDataService;
 import com.xunmei.iot.service.IotServerInfoService;
 import com.xunmei.iot.vo.serverInfo.IotServerInfoPageVo;
 import com.xunmei.system.api.RemoteHostService;
-import com.xunmei.system.api.RemoteMediatorService;
 import com.xunmei.system.api.RemoteOrgService;
 import com.xunmei.system.api.domain.SysOrg;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -53,6 +52,7 @@ public class IotServerInfoServiceImpl extends ServiceImpl<IotServerInfoMapper, I
     RemoteHostService hostService;
     @Autowired
     IotAlarmDataService alarmDataService;
+
     @Override
     public TableDataInfo<IotServerInfoPageVo> serverPage(IotServerInfoPageDto request) {
         if (request.getCheckSub()) {
@@ -136,7 +136,7 @@ public class IotServerInfoServiceImpl extends ServiceImpl<IotServerInfoMapper, I
 
     }
 
-    private void stopServerAndDelData(IotServerInfo info){
+    private void stopServerAndDelData(IotServerInfo info) {
         final AjaxResult result = hostService.closeSession(info.getIotCode());
         if (result.isSuccess()) {
             info.setIotStatus(IotServerConnectStatus.OFFLINE.getIdx());
@@ -183,4 +183,9 @@ public class IotServerInfoServiceImpl extends ServiceImpl<IotServerInfoMapper, I
         hostService.delData(info.getIotCode());
         alarmDataService.deleteData(info.getOrgId());
     }
+
+    @Override
+    public List<IotServerInfo> selectConnectOrg(Boolean checkSub, Long orgId, String orgPath) {
+        return baseMapper.selectConnectOrg(checkSub, orgId, orgPath);
+    }
 }

+ 6 - 2
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/vo/dayilcheck/DailyCheckDataRateData.java

@@ -6,11 +6,15 @@ import lombok.Data;
 @Data
 public class DailyCheckDataRateData {
 
-    @ApiModelProperty("执行过检查的机数量")
+    @ApiModelProperty("执行过检查的机数量")
     private Integer doNums;
     private float doRate;
 
-    @ApiModelProperty("未执行检查的机构数量")
+    @ApiModelProperty("半检的主机数量")
+    private Integer halfDoNums;
+    private float halfDoRate;
+
+    @ApiModelProperty("未执行检查的主机数量")
     private Integer unDoNums;
     private float unDoRate;
 }

+ 3 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/vo/dayilcheck/DailyCheckDataStatisticsData.java

@@ -13,4 +13,7 @@ public class DailyCheckDataStatisticsData {
 
     @ApiModelProperty("未执行检查的日期")
     private List<String> unDoDates;
+
+    @ApiModelProperty("未全部检查的日期")
+    private List<String> halfDoDates;
 }

+ 20 - 0
soc-modules/soc-modules-iot/src/main/resources/mapper/IotDailyCheckDataMapper.xml

@@ -15,4 +15,24 @@
             </if>
         </where>
     </select>
+
+    <select id="selectCheckData" resultType="com.xunmei.common.core.domain.iot.domain.IotDailyCheckData">
+        select distinct d.org_id,d.iot_code,DATE_FORMAT(d.record_date,'%Y-%m-%d') as recordDate
+        from iot_server_info i
+        inner join sys_org s on i.org_id = s.id
+        inner join iot_daily_check_data d on s.id = d.org_id
+        where s.deleted = 0
+        and s.is_lock = 0
+        and i.enable = 0
+        and i.iot_status != 0
+        <if test="req.checkSub==false">
+            and d.org_id =#{req.orgId}
+        </if>
+        <if test="req.checkSub==true">
+            and d.org_path like concat(#{req.orgPath},'%')
+        </if>
+        <if test="req.range != null">
+            and d.record_date between #{req.range[0]} and #{req.range[1]}
+        </if>
+    </select>
 </mapper>

+ 18 - 1
soc-modules/soc-modules-iot/src/main/resources/mapper/IotServerInfoMapper.xml

@@ -2,7 +2,8 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.xunmei.iot.mapper.IotServerInfoMapper">
     <select id="selectServerPage" resultType="com.xunmei.iot.vo.serverInfo.IotServerInfoPageVo">
-        select o.affiliated_area as firstOrgName,o.affiliated_bank as secondOrgName, i.* from iot_server_info i inner join sys_org o on o.id=i.org_id
+        select o.affiliated_area as firstOrgName,o.affiliated_bank as secondOrgName, i.* from iot_server_info i inner
+        join sys_org o on o.id=i.org_id
         <where>
             <if test="req.iotStatus!=null">
                 and i.iot_status=#{req.iotStatus}
@@ -24,4 +25,20 @@
         </where>
         order by i.last_connect_time desc
     </select>
+
+    <select id="selectConnectOrg" resultType="com.xunmei.common.core.domain.iot.domain.IotServerInfo">
+        select i.org_id, i.iot_code, i.org_path
+        from iot_server_info i
+        inner join sys_org o on i.org_id = o.id
+        where o.deleted = 0
+        and o.is_lock = 0
+        and i.enable = 0
+        and i.iot_status != 0
+        <if test="checkSub==false">
+            and o.id =#{orgId}
+        </if>
+        <if test="checkSub==true">
+            and o.path like concat(#{orgPath},'%')
+        </if>
+    </select>
 </mapper>