Monica视频监控处理程序
xc
2020-12-07 16806eadf0dff9123ec09ea708078f223d155d7c
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
166
167
168
169
170
171
172
173
174
175
176
177
package com.hbbh.adapter.manager.impl;
 
import com.google.common.collect.Maps;
import com.hbbh.adapter.config.GoldenConfig;
import com.hbbh.adapter.covert.PointConvert;
import com.hbbh.adapter.dao.golden.*;
import com.hbbh.adapter.enums.TableEnum;
import com.hbbh.adapter.manager.DataSource;
import com.hbbh.adapter.pojo.Point;
import com.hbbh.adapter.pojo.golden.*;
import com.hbbh.adapter.utils.SearchConditionUtil;
import com.rtdb.enums.DataSort;
import com.rtdb.model.Entity;
import com.rtdb.model.FullPoint;
import com.rtdb.model.Table;
import com.rtdb.service.impl.BaseImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
 
@Service
public class DataSourceImpl implements DataSource {
    private static final Logger log = LoggerFactory.getLogger(Class.class);
 
 
    @Autowired
    GoldenConfig goldenConfig;
 
 
    /**
     * @param pointIds 标签点id数组
     * @return
     * @throws Exception
     */
    public List<FullPoint> selectFullPoint(int[] pointIds) throws Exception {
        BaseImpl base = new BaseImpl(goldenConfig.getServer());
 
        Entity<FullPoint> pointsProperties = base.getPointsProperties(pointIds);
        List<FullPoint> list = pointsProperties.getList();
        return list;
    }
 
 
    /**
     * 获取表与标签数量关系
     *
     * @return
     * @throws Exception
     */
    public Map<Table, Integer> getCount() throws Exception {
        Map<Table, Integer> map = Maps.newHashMap();
 
        BaseImpl base = new BaseImpl(goldenConfig.getServer());
 
        int[] tableIds = base.getTableIds();
 
        for (int tableId : tableIds) {
            int i = base.getTableRealSizeById(tableId);
            Table table = base.getTablePropertiesById(tableId);
            map.put(table, i);
        }
        return map;
    }
 
/*
    public List<Point> selectEntity() throws Exception {
        int count = 0;
        BaseImpl base = new BaseImpl(goldenConfig.getServer());
 
        int[] pointIds = base.search(SearchConditionUtil.getSearchCondition(),
                count,
                DataSort.SORT_BY_ID);
        List<FullPoint> fullPoints = selectFullPoint(pointIds);
 
        List<Point> results = PointConvert.fullpointsToPointEntity(fullPoints);
        return results;
    }*/
 
    /**
     * k - tableName
     * v - point
     *
     * @return
     * @throws Exception
     */
    public Map<String, List<Point>> selectAllEntity() throws Exception {
        Map<String, List<Point>> result = Maps.newTreeMap();
        //Map<Table,List<Point>> result=Maps.newHashMap();
 
        Map<Table, Integer> map = getCount();
 
        BaseImpl base = new BaseImpl(goldenConfig.getServer());
 
        map.forEach((k, v) -> {
            try {
                int[] pointIds = base.search(SearchConditionUtil.getSearchCondition(),
                        v,
                        DataSort.SORT_BY_ID);
                List<FullPoint> fullPoints = selectFullPoint(pointIds);
                List<Point> points = PointConvert.fullpointsToPointEntity(fullPoints);
                result.put(k.getName(), points);
            } catch (Exception e) {
                throw new RuntimeException("取数据失败");
            }
        });
        return result;
    }
 
    public void execute() throws Exception {
        Map<String, List<Point>> tableListMap = selectAllEntity();
 
        for (Map.Entry<String, List<Point>> entry : tableListMap.entrySet()) {
            String k = entry.getKey();
            List<Point> v = entry.getValue();
            insert(k, v);
 
        }
    }
 
    @Autowired
    SMSDao smsDao;
    @Autowired
    DLZ_PLCDao dlzPlcDao;
    @Autowired
    DJW_PLCDao djwPlcDao;
    @Autowired
    BDS_PLCDao bdsPlcDao;
    @Autowired
    KTNZ2C_PLCDao ktnz2CPlcDao;
 
 
    public void insert(String flag, List<Point> point) {
        log.info("golden 中 表 ----> {}  正在构建数据...");
        TableEnum byType = TableEnum.getByType(flag);
 
        switch (byType) {
            case SMS:
                point.forEach(p -> {
                    SMS data = PointConvert.pointToSMS(p);
                    smsDao.saveAndFlush(data);
                });
                break;
            case BDS_PLC:
                point.forEach(p -> {
                    BDS_PLC data = PointConvert.pointToBDSPLC(p);
                    bdsPlcDao.saveAndFlush(data);
                });
                break;
            case DJW_PLC:
                point.forEach(p -> {
                    DJW_PLC data = PointConvert.pointToDJWPLC(p);
                    djwPlcDao.saveAndFlush(data);
                });
                break;
            case DLZ_PLC:
                point.forEach(p -> {
                    DLZ_PLC data = PointConvert.pointToDLZPLC(p);
                    dlzPlcDao.saveAndFlush(data);
                });
                break;
            case KTNZ2C_PLC:
                point.forEach(p -> {
                    KTNZ2C_PLC data = PointConvert.pointToKTNZ2CPLC(p);
                    ktnz2CPlcDao.saveAndFlush(data);
                });
                break;
            default:
                //TODO:剩下表构建
        }
 
    }
}