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){
|
System.out.println(flag);
|
|
switch (flag) {
|
case "SMS":
|
point.forEach(p->{
|
SMS data=PointConvert.pointToSMS(p);
|
smsDao.saveAndFlush(data);
|
});
|
break;
|
case "DLZ_PLC":
|
point.forEach(p->{
|
DLZ_PLC data=PointConvert.pointToDLZPLC(p);
|
dlzPlcDao.saveAndFlush(data);
|
});
|
break;
|
case "DJW_PLC":
|
point.forEach(p->{
|
DJW_PLC data=PointConvert.pointToDJWPLC(p);
|
djwPlcDao.saveAndFlush(data);
|
});
|
break;
|
case "BDS_PLC":
|
point.forEach(p->{
|
BDS_PLC data=PointConvert.pointToBDSPLC(p);
|
bdsPlcDao.saveAndFlush(data);
|
});
|
break;
|
case "KTNZ2C_PLC":
|
point.forEach(p->{
|
KTNZ2C_PLC data=PointConvert.pointToKTNZ2CPLC(p);
|
ktnz2CPlcDao.saveAndFlush(data);
|
});
|
break;
|
}
|
|
}
|
}
|