whyclxw
2024-08-29 e849305278bdb46b287a7821b0f4c68e543e0b66
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Page;
import com.whyc.dto.Response;
import com.whyc.mapper.A200RealstateMapper;
import com.whyc.mapper.ActmRealstateMapper;
import com.whyc.mapper.DevInfMapper;
import com.whyc.pojo.db_lithium_ram_db.A200Realstate;
import com.whyc.pojo.db_lithium_ram_db.ActmRealstate;
import com.whyc.pojo.db_lithium_ram_db.DevInf;
import com.whyc.util.RSAUtil;
import org.simpleframework.xml.Order;
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 DevInfService {
    @Autowired(required = false)
    private DevInfMapper mapper;
 
    @Autowired(required = false)
    private A200RealstateMapper a200Mapper;
 
    @Autowired(required = false)
    private ActmRealstateMapper actmMapper;
 
    //添加设备
    public Response addDev(DevInf devInf) {
        QueryWrapper wrapper=new QueryWrapper();
        //判断设备类型生成devId
        int devId=getDevId(devInf.getDevType());
        devInf.setDevId(devId);
        int bl=mapper.insert(devInf);
        return new Response().set(1,bl>0);
    }
   //判断设备类型生成devId
    private int getDevId(Integer devType) {
        //查询该类型最大设备编号
        Integer devId=mapper.getMaxDevId(devType);
        if(devId==null){
            switch (devType){
                case 1:devId=100000000;break;
                case 2:devId=200000000;break;
            }
        }
        return devId+1;
    }
 
    //获取所有的设备信息
    public Response getAllInf(Integer uid, Page page) {
        Map<String, Object> allMap = new HashMap<>();
        PageHelper.startPage(page.getPageNum(),page.getPageSize());
        List<DevInf> list=mapper.getAllInf(uid);
 
        Map<Integer, List<DevInf>> typeDevMap = list.stream().collect(Collectors.groupingBy(DevInf::getDevType));
        Map<Integer, List<DevInf>> onlineDevMap = list.stream().collect(Collectors.groupingBy(DevInf::getDevOnline));
        Map<Integer, Object> typeMap = new HashMap<>();
        typeMap.put(1,0);
        typeMap.put(2,0);
        Map<Integer, Object> onlineMap = new HashMap<>();
        onlineMap.put(0,0);
        onlineMap.put(1,0);
        int devSum = list.size();
        for (Integer type : typeDevMap.keySet()) {
            typeMap.put(type, typeDevMap.get(type).size());
        }
        for (Integer online : onlineDevMap.keySet()) {
            onlineMap.put(online, onlineDevMap.get(online).size());
        }
        PageInfo pageInfo=new PageInfo(list);
        allMap.put("type",typeMap);
        allMap.put("onlineMap",onlineMap);
        allMap.put("devSum",devSum);
        allMap.put("pageInfo",pageInfo);
 
        return new Response().setII(1,list!=null,allMap,"获取所有的设备信息");
    }
 
    //获取左侧列表
    public Response getDevBytype(Integer devType) {
        QueryWrapper wrapper=new QueryWrapper();
        if (devType!=null){
            wrapper.eq("dev_type",devType);
        }
        wrapper.orderByAsc("dev_id");
        List<DevInf> list=mapper.selectList(wrapper);
        return new Response().setII(1,list!=null,list,"获取左侧列表");
    }
   //获取左侧泪飙
    public Response getLine(int uid) {
        Map<String, Object> allMap = new HashMap<>();
        List<DevInf> a200List=mapper.getLine(uid);
        for (DevInf a200:a200List) {
            QueryWrapper a200wrapper= Wrappers.query();
            a200wrapper.eq("dev_id",a200.getDevId());
            a200wrapper.last("limit 1");
            A200Realstate a200state=a200Mapper.selectOne(a200wrapper);
            a200.setA200sTate(a200state);
        }
        List<DevInf> actmList=mapper.getLine(uid);
        for (DevInf actm:actmList) {
            QueryWrapper actmwrapper= Wrappers.query();
            actmwrapper.eq("dev_id",actm.getDevId());
            actmwrapper.last("limit 1");
            ActmRealstate actmstate=actmMapper.selectOne(actmwrapper);
            actm.setActmsTate(actmstate);
        }
        allMap.put("a200List",a200List);
        allMap.put("actmList",actmList);
        return new Response().setII(1,allMap.size()>0,allMap,"获取左侧列表");
    }
}