浏览代码

履职登记簿布撤防数据样式修改

jingyuanchao 1 年之前
父节点
当前提交
b18a90db0e

+ 29 - 31
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/service/impl/ProtectionServiceImpl.java

@@ -12,7 +12,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.xunmei.common.core.constant.Constants;
 import com.xunmei.common.core.constant.SecurityConstants;
 import com.xunmei.common.core.domain.iot.domain.IotAlarmSubsystem;
 import com.xunmei.common.core.domain.iot.domain.IotAlarmSubsystemLog;
@@ -129,7 +128,6 @@ public class ProtectionServiceImpl extends ServiceImpl<ProtectionMapper, IotAlar
             throw new RuntimeException("防区名称重复");
         }
         IotAlarmSubsystem protection = new IotAlarmSubsystem();
-        Long id=dto.getId();
         if (dto.getId() != null) {
             protection = getById(dto.getId());
             BeanUtil.copyProperties(dto, protection);
@@ -138,12 +136,11 @@ public class ProtectionServiceImpl extends ServiceImpl<ProtectionMapper, IotAlar
             BeanUtil.copyProperties(dto, protection);
             protection.setStatus(ProtectionStatus.UNKNOWN.ordinal());
             save(protection);
-            id=protection.getId();
         }
-        //一个机构下仅允许存在一个子系统关联登记簿
+        /*//一个机构下仅允许存在一个子系统关联登记簿
         if (ObjectUtil.equal(dto.getInBook(),1)){
             baseMapper.updateInBookStatus(dto.getOrgId(),id);
-        }
+        }*/
 
         return protection.getId();
 
@@ -264,15 +261,12 @@ public class ProtectionServiceImpl extends ServiceImpl<ProtectionMapper, IotAlar
 
     @Override
     public List<Map<String, List<Map<String, Object>>>> selectDataByOrgId(Long orgId, Date date) {
+
+
         // 一个防区对应 布撤防历史(我知道这这个结构写的很烂,但是时间有限,先这样吧)
         List<Map<String, List<Map<String, Object>>>> resultList = new ArrayList<>();
 
-        List<IotAlarmSubsystem> list = lambdaQuery()
-                .eq(IotAlarmSubsystem::getOrgId, orgId)
-                .eq(IotAlarmSubsystem::getDeleted, 0)
-                .eq(IotAlarmSubsystem::getInBook, 1)
-                .last(Constants.LIMIT1)//一个机构只会有一个子系统关联登记簿
-                .list();
+        List<IotAlarmSubsystem> list = getIotAlarmSubsystems(orgId);
         if (ObjectUtil.isEmpty(list)) {
             return resultList;
         }
@@ -282,14 +276,11 @@ public class ProtectionServiceImpl extends ServiceImpl<ProtectionMapper, IotAlar
             resultList.add(map);
         }
         List<Long> protectionIdList = list.stream().map(IotAlarmSubsystem::getId).collect(Collectors.toList());
-        LambdaQueryWrapper<IotAlarmSubsystemLog> wrapper = new LambdaQueryWrapper<IotAlarmSubsystemLog>();
-        wrapper.eq(IotAlarmSubsystemLog::getOrgId, orgId)
-                .in(IotAlarmSubsystemLog::getProtectionId, protectionIdList)
-                .between(IotAlarmSubsystemLog::getStatusChangeTime, DateUtil.beginOfDay(date), DateUtil.endOfDay(date));
-        List<IotAlarmSubsystemLog> logList = protectionLogMapper.selectList(wrapper);
+        List<IotAlarmSubsystemLog> logList = getIotAlarmSubsystemLogs(orgId, date, protectionIdList);
         if (ObjectUtil.isEmpty(logList)) {
             return resultList;
         }
+        //布防状态,0:撤防,1:布防
         for (Map<String, List<Map<String, Object>>> subsystemListMap : resultList) {
             for (Map.Entry<String, List<Map<String, Object>>> listEntry : subsystemListMap.entrySet()) {
                 IotAlarmSubsystem subsystem = JSON.parseObject(listEntry.getKey(), IotAlarmSubsystem.class);
@@ -297,21 +288,11 @@ public class ProtectionServiceImpl extends ServiceImpl<ProtectionMapper, IotAlar
                 if (subsystemLogList.isEmpty()) {
                     continue;
                 }
-                //布防状态,0:撤防,1:布防
-                Optional<IotAlarmSubsystemLog> optional = subsystemLogList.stream().filter(r -> ObjectUtil.equal(r.getStatus(), 1)).max(Comparator.comparing(IotAlarmSubsystemLog::getStatusChangeTime));
-                if (optional.isPresent()){
-                    IotAlarmSubsystemLog log = optional.get();
-                    Map<String, Object> map = new HashMap<>();
-                    map.put("status", log.getStatus());
-                    map.put("date", DateUtil.format(log.getStatusChangeTime(), "HH:mm"));
-                    listEntry.getValue().add(map);
-                }
-                optional = subsystemLogList.stream().filter(r -> ObjectUtil.equal(r.getStatus(), 0)).min(Comparator.comparing(IotAlarmSubsystemLog::getStatusChangeTime));
-                if (optional.isPresent()){
-                    IotAlarmSubsystemLog log = optional.get();
-                    Map<String, Object> map = new HashMap<>();
-                    map.put("status", log.getStatus());
-                    map.put("date", DateUtil.format(log.getStatusChangeTime(), "HH:mm"));
+                for (IotAlarmSubsystemLog subsystemLog : subsystemLogList) {
+                    Map<String, Object> map = new LinkedHashMap<>();
+                    map.put("id", subsystemLog.getId());
+                    map.put("status", subsystemLog.getStatus());
+                    map.put("date", DateUtil.format(subsystemLog.getStatusChangeTime(), "HH:mm"));
                     listEntry.getValue().add(map);
                 }
             }
@@ -320,5 +301,22 @@ public class ProtectionServiceImpl extends ServiceImpl<ProtectionMapper, IotAlar
 
         return resultList;
     }
+
+    private List<IotAlarmSubsystem> getIotAlarmSubsystems(Long orgId) {
+        return lambdaQuery()
+                .eq(IotAlarmSubsystem::getOrgId, orgId)
+                .eq(IotAlarmSubsystem::getDeleted, 0)
+                .eq(IotAlarmSubsystem::getInBook, 1)
+                .list();
+    }
+
+    private List<IotAlarmSubsystemLog> getIotAlarmSubsystemLogs(Long orgId, Date date, List<Long> protectionIdList) {
+        LambdaQueryWrapper<IotAlarmSubsystemLog> wrapper = new LambdaQueryWrapper<IotAlarmSubsystemLog>();
+        wrapper.eq(IotAlarmSubsystemLog::getOrgId, orgId)
+                .in(IotAlarmSubsystemLog::getProtectionId, protectionIdList)
+                .between(IotAlarmSubsystemLog::getStatusChangeTime, DateUtil.beginOfDay(date), DateUtil.endOfDay(date))
+                .orderByAsc(IotAlarmSubsystemLog::getStatusChangeTime);
+        return protectionLogMapper.selectList(wrapper);
+    }
 }
 

+ 43 - 48
soc-modules/soc-modules-file/src/main/java/com/xunmei/file/utils/PdfUtil.java

@@ -191,6 +191,18 @@ public class PdfUtil {
         }
     }
 
+    private static String getStatusTime(List<Map<String, Object>> data, Integer status, List<Long> ingoreIdList) {
+        Optional<Map<String, Object>> optional = data.stream()
+                .filter(r -> r.get("status").equals(status) && !ingoreIdList.contains(Long.valueOf(r.get("id").toString())))
+                .findFirst();
+        if (optional.isPresent()) {
+            Map<String, Object> map = optional.get();
+            ingoreIdList.add(Long.valueOf(map.get("id").toString()));
+            return map.get("date").toString();
+        }
+        return StringUtil.EMPTY_STRING;
+    }
+
 
     public static void dealResumptionBody(Document document, PdfPTable table, Font tableFont, Map<String, Object> data) throws Exception {
         // 第一行
@@ -205,26 +217,12 @@ public class PdfUtil {
         PdfUtil.createPDFCell(tableFont, table, "检查时间", Element.ALIGN_MIDDLE, 2, 0);
         PdfUtil.createPDFCell(tableFont, table, "检查内容", Element.ALIGN_MIDDLE, 6, 0);
         PdfUtil.createPDFCell(tableFont, table, "检查情况", Element.ALIGN_MIDDLE, 2, 0);
-
-
-//        PdfUtil.createPDFCell(tableFont, table, "检查时间", Element.ALIGN_CENTER, 1, 0);
-//        PdfUtil.createPDFCell(tableFont, table, "检查内容", Element.ALIGN_CENTER, 5, 0);
-//        PdfUtil.createPDFCell(tableFont, table, "检查情况", Element.ALIGN_CENTER, 0, 0);
-//        PdfUtil.createPDFCell(tableFont, table, "登记人", Element.ALIGN_CENTER, 0, 0);
-
-        /*List<String> names = new ArrayList<>();
-        names.add(DictUtils.getDictLabel(DictConstants.RESUMPTION_PLAN_EXEC, 2));
-        names.add(DictUtils.getDictLabel(DictConstants.RESUMPTION_PLAN_EXEC, 3));
-        names.add(DictUtils.getDictLabel(DictConstants.RESUMPTION_PLAN_EXEC, 4));*/
         final List<SysDictData> dictCache = DictUtils.getDictCache(DictConstants.RESUMPTION_PLAN_EXEC);
         final List<String> names = dictCache.stream().map(SysDictData::getDictLabel).collect(Collectors.toList());
         for (String s : names) {
             List<LinkedHashMap<String, Object>> lists = (List<LinkedHashMap<String, Object>>) data.get(s);
             if (ObjectUtil.isEmpty(lists)) {
                 //不同的执行时刻
-               /* PdfUtil.createPDFCell(tableFont, table, s, PdfPCell.ALIGN_MIDDLE, 2,1);
-                PdfUtil.createPDFCell(tableFont, table,"/", PdfPCell.ALIGN_MIDDLE, 6, 1);
-                PdfUtil.createPDFCell(tableFont, table, "/", PdfPCell.ALIGN_MIDDLE, 2,1);*/
                 continue;
             }
             //不同的执行时刻
@@ -243,57 +241,43 @@ public class PdfUtil {
         }
 
         // ------------------------------------------------------------------------------------------------------------
-/*
-        PdfUtil.createPDFCell(tableFont, table, "布撤防情况", Element.ALIGN_MIDDLE, 10, 1);
-
-        PdfUtil.createPDFCell(tableFont, table, "控制器名称", Element.ALIGN_MIDDLE, 2, 1);
-        PdfUtil.createPDFCell(tableFont, table, "详情", Element.ALIGN_MIDDLE, 8, 1);*/
-
 
         List<Map<String, List<Map<String, Object>>>> protectionList = (List<Map<String, List<Map<String, Object>>>>) data.get("protection");
         if (ObjectUtil.isNotEmpty(protectionList)) {
-            for (int i = 0; i < protectionList.size(); i++) {
-                Map<String, List<Map<String, Object>>> listMap = protectionList.get(i);
+            for (Map<String, List<Map<String, Object>>> listMap : protectionList) {
                 for (Map.Entry<String, List<Map<String, Object>>> listEntry : listMap.entrySet()) {
-                    IotAlarmSubsystem subsystem = JSON.parseObject(listEntry.getKey(),IotAlarmSubsystem.class);
+                    IotAlarmSubsystem subsystem = JSON.parseObject(listEntry.getKey(), IotAlarmSubsystem.class);
                     List<Map<String, Object>> value = listEntry.getValue();
                     //布防状态,0:撤防,1:布防
                     if (value.isEmpty()) {
                         //子系统名称
                         PdfUtil.createPDFCell(tableFont, table, subsystem.getName(), Element.ALIGN_MIDDLE, 2, 1);
-                        PdfUtil.createPDFCell(tableFont, table,"撤防时间" , Element.ALIGN_MIDDLE, 2, 1);
+                        PdfUtil.createPDFCell(tableFont, table, "撤防时间", Element.ALIGN_MIDDLE, 2, 1);
                         PdfUtil.createPDFCell(tableFont, table, StringUtil.EMPTY_STRING, Element.ALIGN_MIDDLE, 2, 1);
-                        PdfUtil.createPDFCell(tableFont, table,"布防时间" , Element.ALIGN_MIDDLE, 2, 1);
+                        PdfUtil.createPDFCell(tableFont, table, "布防时间", Element.ALIGN_MIDDLE, 2, 1);
                         PdfUtil.createPDFCell(tableFont, table, StringUtil.EMPTY_STRING, Element.ALIGN_MIDDLE, 2, 1);
                     } else {
-                        // 子系统名称
-                        PdfUtil.createPDFCell(tableFont, table, subsystem.getName(), Element.ALIGN_MIDDLE, 2, 1);
-                        Optional<Map<String, Object>> statusOptional1 = value.stream().filter(r -> {
-                            Integer status = (Integer) r.get("status");
-                            return ObjectUtil.equal(0,status);
-                        }).findFirst();
-                        String cfStatus = statusOptional1.isPresent() ? String.valueOf(statusOptional1.get().get("date")) : StringUtil.EMPTY_STRING;
-                        // 撤防时间
-                        PdfUtil.createPDFCell(tableFont, table, "撤防时间", Element.ALIGN_MIDDLE, 2, 1);
-                        PdfUtil.createPDFCell(tableFont, table, cfStatus, Element.ALIGN_MIDDLE, 2, 1);
-
-                        Optional<Map<String, Object>> statusOptional = value.stream().filter(r -> {
-                            Integer status = (Integer) r.get("status");
-                            return ObjectUtil.equal(1,status);
-                        }).findFirst();
-                        String bfStatus = statusOptional.isPresent() ? String.valueOf(statusOptional.get().get("date")) : StringUtil.EMPTY_STRING;
-                        // 布防时间
-                        PdfUtil.createPDFCell(tableFont, table, "布防时间", Element.ALIGN_MIDDLE, 2, 1);
-                        PdfUtil.createPDFCell(tableFont, table, bfStatus, Element.ALIGN_MIDDLE, 3, 1);
+                        long num = getNum(value);//可能出现布防两次,撤防一次的情况,避免登记簿异常,取最大值
+                        List<Long> ingoreIdList = new ArrayList<>();
+                        for (long i = 0; i < num; i++) {
+                            // 子系统名称
+                            PdfUtil.createPDFCell(tableFont, table, subsystem.getName(), Element.ALIGN_MIDDLE, 2, 1);
+                            // 撤防时间
+                            PdfUtil.createPDFCell(tableFont, table, "撤防时间", Element.ALIGN_MIDDLE, 2, 1);
+                            PdfUtil.createPDFCell(tableFont, table, getStatusTime(value, 0, ingoreIdList), Element.ALIGN_MIDDLE, 2, 1);
+                            // 布防时间
+                            PdfUtil.createPDFCell(tableFont, table, "布防时间", Element.ALIGN_MIDDLE, 2, 1);
+                            PdfUtil.createPDFCell(tableFont, table, getStatusTime(value, 1, ingoreIdList), Element.ALIGN_MIDDLE, 3, 1);
+                        }
                     }
                 }
             }
-        }else   {
+        } else {
             //子系统名称
-            PdfUtil.createPDFCell(tableFont, table,StringUtil.EMPTY_STRING, Element.ALIGN_MIDDLE, 2, 1);
-            PdfUtil.createPDFCell(tableFont, table,"撤防时间" , Element.ALIGN_MIDDLE, 2, 1);
             PdfUtil.createPDFCell(tableFont, table, StringUtil.EMPTY_STRING, Element.ALIGN_MIDDLE, 2, 1);
-            PdfUtil.createPDFCell(tableFont, table,"布防时间" , Element.ALIGN_MIDDLE, 2, 1);
+            PdfUtil.createPDFCell(tableFont, table, "撤防时间", Element.ALIGN_MIDDLE, 2, 1);
+            PdfUtil.createPDFCell(tableFont, table, StringUtil.EMPTY_STRING, Element.ALIGN_MIDDLE, 2, 1);
+            PdfUtil.createPDFCell(tableFont, table, "布防时间", Element.ALIGN_MIDDLE, 2, 1);
             PdfUtil.createPDFCell(tableFont, table, StringUtil.EMPTY_STRING, Element.ALIGN_MIDDLE, 2, 1);
         }
 
@@ -337,6 +321,17 @@ public class PdfUtil {
 
     }
 
+    private static long getNum(List<Map<String, Object>> value) {
+        long num;
+        List<Integer> statusList = value.stream().map(m -> (Integer) m.get("status")).collect(Collectors.toList());
+        num = statusList.stream().filter(r -> ObjectUtil.equal(0, r)).count();
+        long bfNums = statusList.stream().filter(r -> ObjectUtil.equal(1, r)).count();
+        if (bfNums > num) {
+            num = bfNums;
+        }
+        return num;
+    }
+
     public static String getLineStr(String str) {
         StringBuilder result = new StringBuilder();
         for (int i = 0; i < str.length(); i++) {