whyclxw
2025-05-15 96510a549bfb313920bf297b28089c4cf57f0146
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.whyc.dto.Response;
import com.whyc.mapper.BaojigroupLockMapper;
import com.whyc.mapper.LockInfMapper;
import com.whyc.pojo.plus_inf.LockInf;
import com.whyc.pojo.plus_lock_ram.LockCtlLog;
import com.whyc.pojo.plus_lock_ram.LockReport;
import com.whyc.pojo.plus_user.BaojigroupLock;
import com.whyc.util.ActionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
@Service
public class HomeService {
    @Autowired(required = false)
    private LockInfMapper linfMapper;
 
    @Autowired(required = false)
    private LockReportService reportService;
 
    @Autowired(required = false)
    private LockCtlLogService ctlLogService;
 
    @Autowired(required = false)
    private BaojigroupLockMapper bjLockMapper;
 
    //锁的工作状态
    public Response getLockState(int uid) {
        try {
            //查询用户管理的锁id集合
            List<Integer> lockidList = bjLockMapper.getLockIdByUid(uid);
            QueryWrapper wrapper = new QueryWrapper();
            wrapper.in("lock_id", lockidList);
            wrapper.eq("del_flag", 0);
            wrapper.orderByAsc("num");
            List<LockInf> list = linfMapper.selectList(wrapper);
            Map<String, Object> map = new HashMap<>();
            map.put("sumLinf", 0);
            map.put("onlineNum", 0);
            map.put("offLineNum", 0);
            map.put("openNum", 0);
            map.put("closeNum", 0);
            map.put("unLoadNum", 0);
            //查看区域下所有的锁
            map.put("sumLinf", list.size());
            Map<Integer, List<LockInf>> onlinemap = list.stream().collect(Collectors.groupingBy(LockInf::getLockOnline));
            for (Integer state : onlinemap.keySet()) {
                if (state == 0) {
                    map.put("offLineNum", onlinemap.get(0).size());//离线
                }
                if (state == 1) {
                    map.put("onlineNum", onlinemap.get(1).size());//在线
                }
            }
            Map<Integer, List<LockInf>> openmap = list.stream().collect(Collectors.groupingBy(LockInf::getLockState));
            for (Integer open : openmap.keySet()) {
                if (open == 0) {
                    map.put("closeNum", openmap.get(0).size());//闭锁
                }
                if (open == 1) {
                    map.put("openNum", openmap.get(1).size());//开锁
                }
                if (open == -1) {
                    map.put("unLoadNum", openmap.get(-1).size());//未安装
                }
                map.put("allLinfs", list);
            }
            return new Response().setII(1, true, map, "锁的工作状态");
        } catch(Exception e){
            return new Response().set(1, false, "锁的工作状态");
        }
    }
 
    //首页统计屏柜类型
    public Response getScreenBoxType(int uid) {
        try {
            //查询用户管理的锁id集合
            List<Integer> lockidList = bjLockMapper.getLockIdByUid(uid);
            QueryWrapper wrapper = new QueryWrapper();
            wrapper.in("lock_id", lockidList);
            wrapper.eq("screen_flag",1);//只取屏柜
            wrapper.eq("del_flag", 0);
            wrapper.orderByAsc("num");
            List<LockInf> list=linfMapper.selectList(wrapper);
            Map<String, List<LockInf>>  boxType = list.stream().collect(Collectors.groupingBy(LockInf::getScreenBoxType));
            Map<String, Object> map = new HashMap<>();
            Map<String, Object> typeMap = new HashMap<>();
            for (String type : boxType.keySet()) {
                typeMap.put(type, boxType.get(type).size());
            }
            map.put("type",typeMap);
            Map<String, List<LockInf>>  productType = list.stream().collect(Collectors.groupingBy(LockInf::getScreenBoxProduct));
            Map<String, Object> productMap = new HashMap<>();
            for (String product : productType.keySet()) {
                productMap.put(product, productType.get(product).size());
            }
            map.put("product",productMap);
            return new Response().setII(1,true,map,"首页统计屏柜类型");
        } catch (Exception e) {
            return new Response().set(1,false,"首页统计屏柜类型");
        }
    }
 
    //lock的使用频次
    public Response getReport(int uid) {
        //查询用户管理的锁id集合
        List<Integer> lockidList = bjLockMapper.getLockIdByUid(uid);
        if(lockidList.size()>0){
            //获取锁的频次
            List<LockReport> reportList=reportService.getReport(lockidList);
            return new Response().setII(1,true,reportList,"lock的使用频次");
        }
        return new Response().set(1,false,"lock的使用频次");
    }
 
    //实时开锁信息(失败)
    public Response getErrorCtlog(int uid) {
        //查询用户管理的锁id集合
        List<Integer> lockidList = bjLockMapper.getLockIdByUid(uid);
        if(lockidList.size()>0){
            //获取锁的日志
            List<LockCtlLog> logList=ctlLogService.getAllErrorLog(lockidList);
            return new Response().setII(1,true,logList,"实时开锁信息(失败)");
        }
        return new Response().set(1,false,"实时开锁信息(失败)");
    }
 
    //实时开锁信息(全部)
    public Response getAllCtlLog(int uid) {
        //查询用户管理的锁id集合
        List<Integer> lockidList = bjLockMapper.getLockIdByUid(uid);
        if(lockidList.size()>0){
            //获取锁的日志
            List<LockCtlLog> logList=ctlLogService.getAllLog(lockidList);
            return new Response().setII(1,true,logList,"实时开锁信息(全部)");
        }
        return new Response().set(1,false,"实时开锁信息(全部)");
    }
 
    //地图顶部的管理的站点和设备(锁)
    public Response getHomeStationAndLock(int uid) {
        Map<String, Object> map = new HashMap<>();
        map.put("stationNum",0);
        map.put("lockNum",0);
        List<BaojigroupLock> list=bjLockMapper.getHomeStationAndLock(uid);
        Map<Integer, List<BaojigroupLock>> stationmap = list.stream().collect(Collectors.groupingBy(BaojigroupLock::getStationId));
        map.put("stationNum",stationmap.size());
        Map<Integer, List<BaojigroupLock>> lockmap = list.stream().collect(Collectors.groupingBy(BaojigroupLock::getLockId));
        map.put("lockNum",lockmap.size());
        if (list!=null){
            return new Response().setII(1,true,map,"地图顶部的管理的站点和设备");
        }else{
            return new Response().setII(1,false,0,"地图顶部的管理的站点和设备");
        }
 
    }
}