package com.cisdi.data.DIClient;

import com.alibaba.fastjson.JSON;
import com.cisdi.data.DIClient.bean.DIClientCnfg;
import com.cisdi.data.DIClient.gateway.DBReader;
import com.cisdi.data.DIClient.gateway.DBTask;
import com.cisdi.data.common.exception.BusinessException;
import com.cisdi.data.sdk.enums.GatewayState;

import java.io.UnsupportedEncodingException;

public class DIClientTest {
    public static void main(String[] args) throws UnsupportedEncodingException {
        char x=0x03;
        String test="20210408195055077MR001     N11001001       yf        R一级焦炭                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Bt          7.000  2                                                                                                                                                                                                                                                                                                                                                                                                                Y99999.0000       0.0000         0.0000         0.0000                             B020      ";
        String value="7.000  ";
        value=value.trim();
        int splitIndex = value.length() - 3;

        String t="{\"cycleTime\":3000,\"dbName\":\"test\",\"driverClassName\":\"com.mysql.jdbc.Driver\",\"pwd\":\"yLNklB0v6Hu&J2T!\",\"url\":\"jdbc:mysql://10.232.12.58:3306/zgerp?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&useSSL=false\",\"user\":\"root\"} ";

        String prev = value.substring(0, splitIndex-1);
        String end = value.substring(splitIndex);

        DIClientCnfg diClientCnfg=new DIClientCnfg();
        diClientCnfg.setCycleTime((long) 3000);
        diClientCnfg.setDbName("test");
        diClientCnfg.setDriverClassName("com.mysql.jdbc.Driver");
        diClientCnfg.setUrl("jdbc:mysql://10.232.12.58:3306/zgerp?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&useSSL=false");
        diClientCnfg.setUser("root");
        diClientCnfg.setPwd("yLNklB0v6Hu&J2T!");

        System.out.println(JSON.toJSONString(diClientCnfg));
        boolean open = false;
        DBReader dbReader=new DBReader(diClientCnfg.getDriverClassName(),diClientCnfg.getUrl(),diClientCnfg.getUser(),diClientCnfg.getPwd());
        open=dbReader.connectionInternal(0);
        if(open == true) {
            DBTask dbTask=new DBTask(null,null,dbReader,diClientCnfg.getCycleTime(),"");
            dbTask.start();


            try {
                Thread.sleep(10000000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("DIClient网关:{}启动成功 参数:{}");
        }else {
            System.out.println("DIClient网关:{}启动失败 参数:{}");
        }
    }
}
