whyclxw
2025-04-17 92efd8906a1af014079e9a11b45d99df91ffd72d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.whyc.service;
 
import com.github.pagehelper.PageInfo;
import com.whyc.dto.LockHisDto;
import com.whyc.dto.Response;
import com.whyc.pojo.plus_lock_his.LockHis;
import com.whyc.util.SubTablePageInfoUtil;
import com.whyc.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.text.ParseException;
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 {
    @Autowired
    private SubTablePageInfoUtil util;
    //查询锁的历史状态
    public Response getLockHis( LockHisDto dto) throws ParseException {
        PageInfo pageInfo=util.getPageInfoWithOutDefault(dto.getPageNum(),dto.getPageSize(),dto.getStartTime(),dto.getEndTime()
                ,"plus_lock_his","tb_lock_his_"+dto.getLockId(),dto);
        return new Response().setII(1,pageInfo.getList()!=null,pageInfo,"查询锁的历史状态");
    }
 
    //实时界面点击查看历史信息
    public Response getLockHisWithReal(int lockId, String startTime, String endTime) throws ParseException {
        LockHisDto his=new LockHisDto();
        his.setLockId(lockId);
        List<LockHis> list=util.getLockHisWithReal(ThreadLocalUtil.parse(startTime,1),ThreadLocalUtil.parse(endTime,1)
                ,"plus_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,"实时界面点击查看历史信息");
    }
}