xc
2020-12-04 6566968d727f3739926c401b39925c6f55dff4ec
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
package com.hbbh.adapter.manager.impl;
 
 
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.hbbh.adapter.covert.PointConvert;
import com.hbbh.adapter.pojo.Point;
import com.hbbh.adapter.utils.SearchConditionUtil;
import com.rtdb.enums.DataSort;
import com.rtdb.model.*;
import com.rtdb.service.impl.BaseImpl;
import com.rtdb.service.impl.ServerImpl;
import com.rtdb.service.impl.ServerImplPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
 
import java.util.List;
 
@Deprecated
public class DataSourceManager
        //implements DataSource
{
    private static final Logger log = LoggerFactory.getLogger(Class.class);
 
 
    @Value("${golden.ip}")
    private String _ip;
    @Value("${golden.port}")
    private int _port;
    @Value("${golden.username}")
    private String _username;
    @Value("${golden.password}")
    private String _password;
 
    @Value("${golden.poolSize}")
    private int _poolSize;
    @Value("${golden.maxSize}")
    private int _maxSize;
 
 
    private static ServerImplPool pool;
    private static ServerImpl server;
 
 
    static {
        pool = new ServerImplPool("47.92.145.232",
                6327,
                "sa",
                "golden",
                5,
                10);
        try {
            server = pool.getServerImpl();
        } catch (Exception e) {
            log.error("实时数据库,建立单连接失败!");
            e.printStackTrace();
        }
    }
 
/*    public ServerImpl server {
        try {
            ServerImpl serverImpl = server.server;
            return serverImpl;
        } catch (Exception e) {
            log.error("实时数据库,建立单连接失败!");
            e.printStackTrace();
        }
        return null;
    }*/
 
    /**
     * 格式批量获取标签点最小信息
     *
     * @return
     * @throws Exception
     */
    public List<MinPoint> findPoints(String target) throws Exception {
        String[] tableTags = new String[1];
        tableTags[0] = target;
        BaseImpl base = new BaseImpl(server);
        List<MinPoint> points = base.findPoints(tableTags);
 
        log.info(JSON.toJSONString(points));
        return points;
    }
 
    /**
     * @param pointIds 标签点id数组
     * @return
     * @throws Exception
     */
    public List<FullPoint> selectFullPoint(int[] pointIds) throws Exception {
        BaseImpl base = new BaseImpl(server);
 
        Entity<FullPoint> pointsProperties = base.getPointsProperties(pointIds);
        List<FullPoint> list = pointsProperties.getList();
        return list;
    }
 
 
    public FullPoint findFullPoint(int id) throws Exception {
        BaseImpl base = new BaseImpl(server);
        int[] pointIds = new int[1];
        pointIds[0] = id;
        Entity<FullPoint> pointsProperties = base.getPointsProperties(pointIds);
        List<FullPoint> list = pointsProperties.getList();
        return list.get(0);
    }
 
 
    /**
     * TODO:
     * 获取表信息
     *
     * @return
     * @throws Exception
     */
    public List<Table> findTableInfo() throws Exception {
        List<Table> results = Lists.newArrayList();
 
        BaseImpl base = new BaseImpl(server);
        int[] tableIds = base.getTableIds();
        int tableId = tableIds[0];
 
        return results;
    }
 
 
    public int getCount() throws Exception {
        BaseImpl base = new BaseImpl(server);
 
        //TODO:写死 暂时第一个
        int[] tableIds = base.getTableIds();
        int tableId = tableIds[0];
        int pointSize = base.getTableRealSizeById(tableId);
        return pointSize;
    }
 
    /**
     * 获取单个表的所有测量点信息
     *
     * @return
     * @throws Exception
     */
    public List<Point> selectEntity() throws Exception {
        int count = getCount();
        BaseImpl base = new BaseImpl(server);
 
        int[] pointIds = base.search(SearchConditionUtil.getSearchCondition(),
                count,
                DataSort.SORT_BY_ID);
        List<FullPoint> fullPoints = selectFullPoint(pointIds);
 
        List<Point> results = PointConvert.fullpointsToPointEntity(fullPoints);
        return results;
    }
 
 
    public void execute() throws Exception {
        List<Point> points = selectEntity();
        for (Point point : points) {
            //goldenDao.saveAndFlush(point);
        }
 
    }
 
 
}