瀏覽代碼

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

jingyuanchao 1 年之前
父節點
當前提交
a828a5bd3b

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

@@ -271,7 +271,7 @@ public class ProtectionServiceImpl extends ServiceImpl<ProtectionMapper, IotAlar
             return resultList;
         }
         for (IotAlarmSubsystem subsystem : list) {
-            Map<String, List<Map<String, Object>>> map = new HashMap<>();
+            Map<String, List<Map<String, Object>>> map = new LinkedHashMap<>();
             map.put(JSON.toJSONString(subsystem), new ArrayList<>());
             resultList.add(map);
         }
@@ -284,7 +284,11 @@ public class ProtectionServiceImpl extends ServiceImpl<ProtectionMapper, IotAlar
         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);
-                List<IotAlarmSubsystemLog> subsystemLogList = logList.stream().filter(r -> ObjectUtil.equal(r.getProtectionId(), subsystem.getId())).collect(Collectors.toList());
+                List<IotAlarmSubsystemLog> subsystemLogList = logList
+                        .stream()
+                        .filter(r -> ObjectUtil.equal(r.getProtectionId(), subsystem.getId()))
+                        .sorted(Comparator.comparing(IotAlarmSubsystemLog::getStatusChangeTime))
+                        .collect(Collectors.toList());
                 if (subsystemLogList.isEmpty()) {
                     continue;
                 }

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

@@ -15,6 +15,7 @@ import com.xunmei.system.api.domain.AccessDataVo;
 import com.xunmei.system.api.domain.CheckDataVo;
 import com.xunmei.system.api.domain.SafeCheckTaskRegisterBookVo;
 import com.xunmei.system.api.domain.SysDictData;
+import com.xunmei.system.api.enums.ProtectionStatus;
 import io.netty.util.internal.StringUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FileUtils;
@@ -241,46 +242,8 @@ public class PdfUtil {
         }
 
         // ------------------------------------------------------------------------------------------------------------
-
-        List<Map<String, List<Map<String, Object>>>> protectionList = (List<Map<String, List<Map<String, Object>>>>) data.get("protection");
-        if (ObjectUtil.isNotEmpty(protectionList)) {
-            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);
-                    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, 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);
-                    } else {
-                        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 {
-            //子系统名称
-            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, StringUtil.EMPTY_STRING, Element.ALIGN_MIDDLE, 2, 1);
-        }
-
+        //日常登记簿-布撤防数据
+        resumptionProtectionData(document, table, tableFont, data);
 
         // ------------------------------------------------------------------------------------------------------------
 
@@ -321,17 +284,70 @@ 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;
+    private static void resumptionProtectionData(Document document, PdfPTable table, Font tableFont, Map<String, Object> data) throws DocumentException {
+        PdfUtil.createPDFCell(tableFont, table, "布撤防情况", Element.ALIGN_MIDDLE, 10, 1);
+        PdfUtil.createPDFCell(tableFont, table, "控制器", Element.ALIGN_MIDDLE, 4, 1);
+        PdfUtil.createPDFCell(tableFont, table, "状态", Element.ALIGN_MIDDLE, 3, 1);
+        PdfUtil.createPDFCell(tableFont, table, "时间", Element.ALIGN_MIDDLE, 3, 1);
+
+        List<Map<String, List<Map<String, Object>>>> protectionList = (List<Map<String, List<Map<String, Object>>>>) data.get("protection");
+        if (ObjectUtil.isEmpty(protectionList)) {
+            PdfUtil.createPDFCell(tableFont, table, "/", Element.ALIGN_MIDDLE, 4, 1);
+            PdfUtil.createPDFCell(tableFont, table, "/", Element.ALIGN_MIDDLE, 3, 1);
+            PdfUtil.createPDFCell(tableFont, table, "/", Element.ALIGN_MIDDLE, 3, 1);
+            document.add(table);
+        } else {
+            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);
+                    List<Map<String, Object>> value = listEntry.getValue();
+                    //布防状态,0:撤防,1:布防
+                    if (value.isEmpty()) {
+                        //子系统名称
+                        PdfUtil.createPDFCell(tableFont, table, subsystem.getName(), Element.ALIGN_MIDDLE, 4, 1);
+                        //状态
+                        PdfUtil.createPDFCell(tableFont, table, StringUtil.EMPTY_STRING, Element.ALIGN_MIDDLE, 3, 1);
+                        // 时间
+                        PdfUtil.createPDFCell(tableFont, table, StringUtil.EMPTY_STRING, Element.ALIGN_MIDDLE, 3, 1);
+                    } else {
+                        //子系统名称
+                        PdfUtil.createPDFCell(tableFont, table, subsystem.getName(), Element.ALIGN_MIDDLE, 4, value.size());
+                        for (Map<String, Object> map : value) {
+                            //状态
+                            PdfUtil.createPDFCell(tableFont, table, getStatusText(map), Element.ALIGN_MIDDLE, 3, 1);
+                            //时间
+                            PdfUtil.createPDFCell(tableFont, table, getStatusTime(map), Element.ALIGN_MIDDLE, 3, 1);
+                        }
+
+                    }
+                }
+            }
+        }
+    }
+
+    private static String getStatusTime(Map<String, Object> value) {
+        if (value == null) {
+            return StringUtil.EMPTY_STRING;
         }
-        return num;
+        Object status = value.get("date");
+        return status == null ? StringUtil.EMPTY_STRING : status.toString();
     }
 
+    private static String getStatusText(Map<String, Object> value) {
+        if (value == null) {
+            return StringUtil.EMPTY_STRING;
+        }
+        Object status = value.get("status");
+        if (status == null) {
+            return StringUtil.EMPTY_STRING;
+        }
+        for (ProtectionStatus protectionStatus : ProtectionStatus.values()) {
+            if (ObjectUtil.equal(protectionStatus.ordinal(), Integer.parseInt(status.toString()))) {
+                return protectionStatus.getText();
+            }
+        }
+        return StringUtil.EMPTY_STRING;
+    }
     public static String getLineStr(String str) {
         StringBuilder result = new StringBuilder();
         for (int i = 0; i < str.length(); i++) {