From 139f7015c2373a5bba03a7d66045cf40faa1728c Mon Sep 17 00:00:00 2001 From: whyclxw <810412026@qq.com> Date: 星期六, 08 二月 2025 11:16:02 +0800 Subject: [PATCH] 实时界面点击查看历史信息 --- src/main/java/com/whyc/service/LockHisService.java | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 47 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/whyc/service/LockHisService.java b/src/main/java/com/whyc/service/LockHisService.java index 4101a24..549401a 100644 --- a/src/main/java/com/whyc/service/LockHisService.java +++ b/src/main/java/com/whyc/service/LockHisService.java @@ -2,6 +2,7 @@ import com.github.pagehelper.PageInfo; import com.whyc.dto.Response; +import com.whyc.pojo.db_area.LockInf; import com.whyc.pojo.db_lock_his.LockHis; import com.whyc.util.SubTablePageInfoUtil; import com.whyc.util.ThreadLocalUtil; @@ -9,6 +10,12 @@ import org.springframework.stereotype.Service; import java.text.ParseException; +import java.time.LocalDateTime; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; @Service public class LockHisService { @@ -22,4 +29,44 @@ ,"db_lock_his","tb_lock_his_"+lockId,his); return new Response().setII(1,pageInfo.getList()!=null,pageInfo,"鏌ヨ閿佺殑鍘嗗彶鐘舵��"); } + + //瀹炴椂鐣岄潰鐐瑰嚮鏌ョ湅鍘嗗彶淇℃伅 + public Response getLockHisWithReal(int lockId, String startTime, String endTime) throws ParseException { + LockHis his=new LockHis(); + his.setLockId(lockId); + List<LockHis> list=util.getLockHisWithReal(ThreadLocalUtil.parse(startTime,1),ThreadLocalUtil.parse(endTime,1) + ,"db_lock_his","tb_lock_his_"+lockId,his); + Map<String, Object> map = new HashMap<>(); + map.put("openNum", 0); + map.put("closeNum", 0); + map.put("nowopenNum", 0); + map.put("nowcloseNum", 0); + map.put("hisList", list); + Map<Integer, List<LockHis>> statemap = list.stream().collect(Collectors.groupingBy(LockHis::getLockState)); + for (Integer state : statemap.keySet()) { + if (state == 0) { + map.put("closeNum", statemap.get(0).size());//鍏抽攣 + } + if (state == 1) { + map.put("openNum", statemap.get(1).size());//寮�閿� + } + } + Date date = new Date(); + //鑾峰彇褰撳ぉ寰楀紑濮嬫椂闂� + Date nowstartTime = new Date(date.getYear(), date.getMonth(), date.getDate(), 0, 0, 0); + //鑾峰彇褰撳ぉ鐨勭粨鏉熸椂闂� + Date nowendTime = new Date(date.getYear(), date.getMonth(), date.getDate(), 23, 59, 59); + List<LockHis> nowList =util.getLockHisWithReal(nowstartTime,nowendTime + ,"db_lock_his","tb_lock_his_"+lockId,his); + Map<Integer, List<LockHis>> nowstatemap = nowList.stream().collect(Collectors.groupingBy(LockHis::getLockState)); + for (Integer state : nowstatemap.keySet()) { + if (state == 0) { + map.put("nowcloseNum", nowstatemap.get(0).size());//鍏抽攣 + } + if (state == 1) { + map.put("nowopenNum", nowstatemap.get(1).size());//寮�閿� + } + } + return new Response().setII(1,list!=null,map,"瀹炴椂鐣岄潰鐐瑰嚮鏌ョ湅鍘嗗彶淇℃伅"); + } } \ No newline at end of file -- Gitblit v1.9.1