xc
2020-12-07 fa06bd64705ccc0e95eaf8818e583ba931118503
src/main/java/com/hbbh/adapter/manager/impl/DataSourceImpl.java
@@ -8,6 +8,7 @@
import com.hbbh.adapter.manager.DataSource;
import com.hbbh.adapter.pojo.Point;
import com.hbbh.adapter.pojo.golden.*;
import com.hbbh.adapter.utils.EmptyUtils;
import com.hbbh.adapter.utils.SearchConditionUtil;
import com.rtdb.enums.DataSort;
import com.rtdb.model.Entity;
@@ -24,8 +25,7 @@
import java.util.TreeMap;
@Service
public class DataSourceImpl implements DataSource
{
public class DataSourceImpl implements DataSource {
    private static final Logger log = LoggerFactory.getLogger(Class.class);
@@ -49,11 +49,12 @@
    /**
     * 获取表与标签数量关系
     *
     * @return
     * @throws Exception
     */
    public Map<Table,Integer> getCount() throws Exception {
        Map<Table,Integer> map = Maps.newHashMap();
    public Map<Table, Integer> getCount() throws Exception {
        Map<Table, Integer> map = Maps.newHashMap();
        BaseImpl base = new BaseImpl(goldenConfig.getServer());
@@ -62,7 +63,7 @@
        for (int tableId : tableIds) {
            int i = base.getTableRealSizeById(tableId);
            Table table = base.getTablePropertiesById(tableId);
            map.put(table,i);
            map.put(table, i);
        }
        return map;
    }
@@ -84,10 +85,11 @@
    /**
     * k - tableName
     * v - point
     *
     * @return
     * @throws Exception
     */
    public Map<String,List<Point>> selectAllEntity() throws Exception {
    public Map<String, List<Point>> selectAllEntity() throws Exception {
        Map<String, List<Point>> result = Maps.newTreeMap();
        //Map<Table,List<Point>> result=Maps.newHashMap();
@@ -95,15 +97,15 @@
        BaseImpl base = new BaseImpl(goldenConfig.getServer());
        map.forEach((k,v)->{
        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){
                result.put(k.getName(), points);
            } catch (Exception e) {
                throw new RuntimeException("取数据失败");
            }
        });
@@ -116,7 +118,7 @@
        for (Map.Entry<String, List<Point>> entry : tableListMap.entrySet()) {
            String k = entry.getKey();
            List<Point> v = entry.getValue();
            insert(k,v);
            insert(k, v);
        }
    }
@@ -133,41 +135,60 @@
    KTNZ2C_PLCDao ktnz2CPlcDao;
    public void insert(String flag,List<Point> point){
        System.out.println(flag);
    public void insert(String flag, List<Point> point) {
        if (EmptyUtils.isEmpty(flag)) {
            log.info("golden 中 未获取到表信息 -->{}", flag);
            return;
        }
        if (point.size()==0) {
            log.info("golden 中 表 ----> {}  没有数据", flag);
            return;
        }
        switch (flag) {
            case "SMS":
                point.forEach(p->{
                    SMS data=PointConvert.pointToSMS(p);
        log.info("golden 中 表 ----> {}  正在构建数据...",flag);
        TableEnum byType = TableEnum.getByType(flag);
        //TODO:部分表未介入
        if (EmptyUtils.isEmpty(byType)){
            log.info("golden 中 表 ----> {}  暂未介入adapter程序中", flag);
            return;
        }
        switch (byType) {
            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);
            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);
            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;
        }
        log.info("golden 中 表 ----> {}  构建数据成功",flag);
    }
}