/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2020-02-17
 * 描述            ：null
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.tcp.impl;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;

import market.tcp.mapper.RtdPingzhengMapper;
import market.tcp.mapper.RtdSuanxiMapper;
import market.tcp.mapper.RtdTuihuoluMapper;
import market.tcp.service.RtdPingzhengService;
import market.tcp.vo.RtdPingzheng;
import market.tcp.vo.RtdSuanxi;
import market.tcp.vo.RtdTuihuolu;
import net.sf.json.JSONObject;

import org.springframework.stereotype.Service;

import com.hnshituo.basic.service.impl.BaseServiceImpl;
import com.hnshituo.basic.spring.remoting.annotation.RemoteService;

@Service("RtdPingzhengService")
@RemoteService(path="RtdPingzhengService")
public class RtdPingzhengServiceImpl extends BaseServiceImpl<RtdPingzheng,Object> implements RtdPingzhengService {

	@Override
	public void doInsertRtd(String url) {
		try {		
			URLConnection connection = new URL(url).openConnection();
			InputStream is = connection.getInputStream();
			InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String line;
            StringBuilder builder = new StringBuilder();
            while ((line = br.readLine())!= null) {
                builder.append(line);
            }
            br.close();
            isr.close();
            is.close();
            JSONObject js = JSONObject.fromObject(builder.toString());
            RtdPingzheng ttc = new RtdPingzheng();
            ttc.setSystime(new Date());//采集时间
            ttc.setGuolvqi_steam_f(new Double(js.get("GuoLvQi_Steam_F").toString()));
            ttc.setGuolvqi_steam_f_acc(new Double(js.get("GuoLvQi_Steam_F_ACC").toString()));
            ttc.setMogun_air_f(new Double(js.get("MoGun_air_F").toString()));
            ttc.setMogun_air_f_acc(new Double(js.get("MoGun_air_F_ACC").toString()));
            ttc.setPingzheng_air_f(new Double(js.get("PingZheng_air_F").toString()));
            ttc.setPingzheng_air_f_acc(new Double(js.get("PingZheng_air_F_ACC").toString()));
            ttc.setPingzheng_steam_f(new Double(js.get("PingZheng_Steam_F").toString()));
            ttc.setPingzheng_steam_f_acc(new Double(js.get("PingZheng_Steam_F_ACC").toString()));
            ttc.setSet_zero(new Double(js.get("Set_Zero").toString()));
            ttc.setTuoyan_water_f(new Double(js.get("TuoYan_Water_F").toString()));
            ttc.setTuoyan_water_f_acc(new Double(js.get("TuoYan_Water_F_ACC").toString()));
            ttc.setZhaji_air_f(new Double(js.get("ZhaJi_air_F").toString()));
            ttc.setZhaji_air_f_acc(new Double(js.get("ZhaJi_air_F_ACC").toString()));
            ttc.setZhaji_steam_f(new Double(js.get("Zhaji_Steam_F").toString()));
            ttc.setZhaji_steam_f_acc(new Double(js.get("Zhaji_Steam_F_ACC").toString()));
            ttc.setZhajituoyan_water_f(new Double(js.get("ZhaJiTuoYan_Water_F").toString()));
            ttc.setZhajituoyan_water_f_acc(new Double(js.get("ZhaJiTuoYan_Water_F_ACC").toString()));
            this.getMapper(RtdPingzhengMapper.class).insert(ttc);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	
	@Override
	public void doInsertRtdtuihuo(String url) {
		try {			
			URLConnection connection = new URL(url).openConnection();
			InputStream is = connection.getInputStream();
			InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String line;
            StringBuilder builder = new StringBuilder();
            while ((line = br.readLine())!= null) {
                builder.append(line);
            }
            br.close();
            isr.close();
            is.close();
            JSONObject js = JSONObject.fromObject(builder.toString());
            RtdTuihuolu ttc = new RtdTuihuolu();
            ttc.setCreate_time(new Date());//采集时间
            ttc.setBs_h2(new Double(js.get("BS_H2").toString()));
            ttc.setBs_h2_acc(new Double(js.get("BS_H2_ACC").toString()));
            ttc.setBs_n2(new Double(js.get("BS_N2").toString()));
            ttc.setBs_n2_acc(new Double(js.get("BS_N2_ACC").toString()));
            ttc.setCog(new Double(js.get("COG").toString()));
            ttc.setCog_acc(new Double(js.get("COG_ACC").toString()));
            ttc.setEbn_h2(new Double(js.get("EBN_H2").toString()));
            ttc.setEbn_h2_acc(new Double(js.get("EBN_H2_ACC").toString()));
            ttc.setEbn_n2(new Double(js.get("EBN_N2").toString()));
            ttc.setEbn_n2_acc(new Double(js.get("EBN_N2_ACC").toString()));
            ttc.setWater_cyc(new Double(js.get("WATER_CYC").toString()));
            ttc.setWater_new(new Double(js.get("WATER_NEW").toString()));
            
            this.getMapper(RtdTuihuoluMapper.class).insert(ttc);
		} catch (Exception e) {
			e.printStackTrace();
		}		
	}
	
	/**
	 * 新增酸洗实时采集
	 */
	@Override
	public void doInsertRtdSuanxi(String url) {
		try {			
			URLConnection connection = new URL(url).openConnection();
			InputStream is = connection.getInputStream();
			InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String line;
            StringBuilder builder = new StringBuilder();
            while ((line = br.readLine())!= null) {
                builder.append(line);
            }
            br.close();
            isr.close();
            is.close();
            JSONObject js = JSONObject.fromObject(builder.toString());
            System.out.println(js);
            /**{"QDYSKQ_F":"58.72093201","ZSS_A":"120.8324356","XS_F":"0","QDYSKQ_A":"4965.808105","FS_A":"1.877285123",
            	"ZQ_A":"138.5810394","YSKQ_F":"16.21613312","ZQ_F":"0","XS_A":"117.2111206","XFS_F":"236.1110992",
            	"FS_F":"0","YSKQ_A":"1549.065674","TYS_A":"773.2210693","ZSS_F":"0.005787037313","TYS_F":"0","XFS_A":"49781.33984"}**/
            RtdSuanxi rs = new RtdSuanxi();
            rs.setFs_a(new Double(js.get("FS_A").toString()));
            rs.setFs_f(new Double(js.get("FS_F").toString()));
            rs.setQdyskq_a(new Double(js.get("QDYSKQ_A").toString()));
            rs.setQdyskq_f(new Double(js.get("QDYSKQ_F").toString()));
            rs.setTys_a(new Double(js.get("TYS_A").toString()));
            rs.setTys_f(new Double(js.get("TYS_F").toString()));
            rs.setXfs_a(new Double(js.get("XFS_A").toString()));
            rs.setXfs_f(new Double(js.get("XFS_F").toString()));
            rs.setXs_a(new Double(js.get("XS_A").toString()));
            rs.setXs_f(new Double(js.get("XS_F").toString()));
            rs.setYskq_a(new Double(js.get("YSKQ_A").toString()));
            rs.setYskq_f(new Double(js.get("YSKQ_F").toString()));
            rs.setZq_a(new Double(js.get("ZQ_A").toString()));
            rs.setZq_f(new Double(js.get("ZQ_F").toString()));
            rs.setZss_a(new Double(js.get("ZSS_A").toString()));
            rs.setZss_f(new Double(js.get("ZSS_F").toString()));
            //rs.setSxxxfs_a(new Double(js.get("SXXXFS_A").toString()));
            //rs.setSxxxfs_f(new Double(js.get("SXXXFS_F").toString()));
            rs.setSystime(new Date());
            this.getMapper(RtdSuanxiMapper.class).insert(rs);
		} catch (Exception e) {
			e.printStackTrace();
		}		
	}
	
}
