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);
|
}
|
|
}
|
|
|
}
|