/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package i2client;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.TreeMap;
import javax.swing.JOptionPane;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import java.util.Date;
import java.text.ParsePosition;
import java.util.Calendar;
import java.util.TimeZone;
 
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;

import javax.xml.namespace.QName;  
import javax.xml.rpc.ParameterMode;  
  
import org.apache.axis.client.Call;  
import org.apache.axis.client.Service;  
import org.apache.axis.encoding.XMLType;  
import org.apache.axis.message.MessageElement;  
import org.apache.axis.types.Schema;   
 
/**
 *
 * @author LENOVO
 */
public class Index extends javax.swing.JFrame {

    /**
     * Creates new form Index
     */
    
    private Timer Timereqm = new Timer();
    public Index() {
        // try{
            // DBHelper help=new DBHelper();
            // Connection conn=null;
            // conn=help.getConnection();
            // PreparedStatement pstmt = null;
            // ResultSet rs=null;
            // String checksql = "select * from sys_rg";
            // pstmt=conn.prepareStatement(checksql);//装载sql语句
            // ResultSet checkrt=null;
            // checkrt=pstmt.executeQuery(); 
            // int checknum;
            // while(checkrt.next()){
                // String mc = checkrt.getString("mc");
                // String ac5 = checkrt.getString("ac5");
                // String ck5 = checkrt.getString("ck5");
                // String encrypt = getResult(mc+key);
                // if(!ac5.equals(encrypt)){
                    // checknum = 0;
                // }else{
                    // checknum = 1;
                // }
                // String checkupsql = "UPDATE sys_rg SET  ck5= '"+checknum+"' WHERE mc='"+checkrt.getString("mc")+"'";
                // help.getConnection();
                // int num = help.excuteUpdate(checkupsql);
                // help.getConnection().close();
            // }
            // pstmt=conn.prepareStatement(checksql);//装载sql语句
            // checkrt=null;
            // checkrt=pstmt.executeQuery();
            // while(checkrt.next()){
                // int ck ;
                // for(int i=0;i<9;i++){
                   // ck = checkrt.getInt("ck"+(i+1));
                   // if(ck!=1){
                        // JOptionPane.showMessageDialog(null, "该软件未注册");
                        // System.exit(0);
                        // return;
                   // }
                // }
            // }
            // conn.close();
            // }catch (Exception e) {e.printStackTrace();}
        initComponents();
         Timereqm.schedule(new TimerTask() {
            @Override
            public void run() {
                try{
                        loadFunction();
                } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        writeFile("slog/"+getCurrentYYYYMM()+".log", e.getMessage());
                    }
                }
        }, 0, 120000);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("I2通道数据显示");

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 785, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 344, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Index.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Index.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Index.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Index.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Index().setVisible(true);
            }
        });
    }
    public String  getResult(String inputStr)
    {
        BigInteger bigInteger=null;

        try {
         MessageDigest md = MessageDigest.getInstance("MD5");
         byte[] inputData = inputStr.getBytes(); 
         md.update(inputData);   
         bigInteger = new BigInteger(md.digest());   
        } catch (Exception e) {e.printStackTrace();}
        return bigInteger.toString(16);
    }
    String key = "295122708900494DAE5701DB80A1C3A5";
    String xml = "";    
    public void loadFunction(){
        try{
            XydlServiceImplService ucd  = new XydlServiceImplService();
            DBHelper help=new DBHelper();
            Connection conn=null;
            conn=help.getConnection();
            PreparedStatement pstmt = null;
            ResultSet rs=null;
            
            String sql ="select * from vw_sb where 1";
            pstmt=conn.prepareStatement(sql);//装载sql语句
            rs=pstmt.executeQuery();
            //System.out.println(rs);
            //把查询出来的记录封装成对应的实体类对象
            ResultSetMetaData rsd=rs.getMetaData();//获得列对象,通过此对象可以得到表的结构，包括，列名，列的个数，列的数据类型
            while(rs.next()){
                 if(rs.getInt("mtid")==20){                  //电缆环流
                 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                 Calendar beforeTime = Calendar.getInstance();
                 beforeTime.add(Calendar.MINUTE, -15);// 15分钟之前的时间
                 Date beforeD = beforeTime.getTime();
                 String time = sdf.format(beforeD);
                 String sql1 = "select * from data_scur_h where  (isupload is null or isupload=0)    and  eqmid ="+rs.getString("id")+" and d_time<\""+time+"\" order by d_time asc";
                 pstmt=conn.prepareStatement(sql1);//装载sql语句
                 ResultSet rs1=null;
                 rs1=pstmt.executeQuery();
                 while(rs1.next()){
                     try{
                        String sql2 = "select * from warn_cfg where eqmid ="+rs1.getString("eqmid")+"";
                        pstmt=conn.prepareStatement(sql2);//装载sql语句
                        ResultSet rs2=null;
                        rs2=pstmt.executeQuery();
                        String sql3 = "select * from i2relation where eqmid ="+rs1.getString("eqmid");
                        //System.out.println(sql3);
                        pstmt=conn.prepareStatement(sql3);//装载sql语句
                        ResultSet rs3=null;
                        rs3=pstmt.executeQuery();
                        String data[][] = new String[2][2];
                        while(rs3.next()){
                            if(!rs3.getString("cacid").equals("")){
                               String timestamp = rs1.getString("d_time");
                                data[0][0] =  rs1.getString("current_val");
                                data[0][1] =  rs1.getString("alarm_level");
                                  if(rs1.getInt("alarm_level")>5){
                                      data[0][1] = "TRUE" ;
                                  }else{
                                      data[0][1] = "FALSE" ;
                                  }
                                /*if(rs2.next()){
                                    if(rs1.getInt("Cur")>rs2.getInt("warnmin5") && rs1.getInt("Cur")<rs2.getInt("warnmax5")){
                                        data[0][1] =  "SAFE";
                                    }else if(rs1.getInt("Cur")>rs2.getInt("warnmin4") && rs1.getInt("Cur")<rs2.getInt("warnmax4")){
                                        data[0][1] =  "Lev1_Low";   
                                    }else if(rs1.getInt("Cur")>rs2.getInt("warnmin3") && rs1.getInt("Cur")<rs2.getInt("warnmax3")){
                                        data[0][1] =  "Lev2_Low";
                                    }else if(rs1.getInt("Cur")>rs2.getInt("warnmin2") && rs1.getInt("Cur")<rs2.getInt("warnmax2")){
                                        data[0][1] =  "Lev3_Low";
                                    }else if(rs1.getInt("Cur")>rs2.getInt("warnmin1") && rs1.getInt("Cur")<rs2.getInt("warnmax1")){
                                        data[0][1] =  "Lev4_Low";
                                    }else if(rs1.getInt("Cur")>rs2.getInt("warnmin6") && rs1.getInt("Cur")<rs2.getInt("warnmax6")){
                                        data[0][1] =  "Lev1_High";
                                    }else if(rs1.getInt("Cur")>rs2.getInt("warnmin7") && rs1.getInt("Cur")<rs2.getInt("warnmax7")){
                                        data[0][1] =  "Lev2_High";
                                    }else if(rs1.getInt("Cur")>rs2.getInt("warnmin8") && rs1.getInt("Cur")<rs2.getInt("warnmax8")){
                                        data[0][1] =  "Lev3_High";
                                    }else if(rs1.getInt("Cur")>rs2.getInt("warnmin9") && rs1.getInt("Cur")<rs2.getInt("warnmax9")){
                                        data[0][1] =  "Lev4_High";
                                    }else if(rs1.getInt("Cur")>rs2.getInt("warnmin10") && rs1.getInt("Cur")<rs2.getInt("warnmax10")){
                                        data[0][1] =  "Lev5_High";
                                    }else if(rs1.getInt("Cur")>rs2.getInt("warnmin11") && rs1.getInt("Cur")<rs2.getInt("warnmax11")){
                                        data[0][1] =  "Lev6_High";
                                    }else if(rs1.getInt("Cur")>rs2.getInt("warnmin12") && rs1.getInt("Cur")<rs2.getInt("warnmax12")){
                                        data[0][1] =  "Lev7_High";
                                    }else if(rs1.getInt("Cur")>rs2.getInt("warnmin13") && rs1.getInt("Cur")<rs2.getInt("warnmax13")){
                                        data[0][1] =  "Lev8_High";
                                    }else if(rs1.getInt("Cur")>rs2.getInt("warnmin14") && rs1.getInt("Cur")<rs2.getInt("warnmax14")){
                                        data[0][1] =  "Lev9_High";
                                    }else if(rs1.getInt("Cur")>rs2.getInt("warnmin15") && rs1.getInt("Cur")<rs2.getInt("warnmax15")){
                                        data[0][1] =  "Lev10_High";
                                    }else if(rs1.getInt("Cur")>rs2.getInt("warnmin16") && rs1.getInt("Cur")<rs2.getInt("warnmax16")){
                                        data[0][1] =  "Lev11_High";
                                    }else if(rs1.getInt("Cur")>rs2.getInt("warnmin17") && rs1.getInt("Cur")<rs2.getInt("warnmax17")){
                                        data[0][1] =  "Lev12_High";
                                    }else if(rs1.getInt("Cur")>rs2.getInt("warnmin18") && rs1.getInt("Cur")<rs2.getInt("warnmax18")){
                                        data[0][1] =  "Lev13_High";
                                    }else if(rs1.getInt("Cur")>rs2.getInt("warnmin19") && rs1.getInt("Cur")<rs2.getInt("warnmax19")){
                                        data[0][1] =  "Lev14_High";
                                    }else if(rs1.getInt("Cur")>rs2.getInt("warnmin20") && rs1.getInt("Cur")<rs2.getInt("warnmax20")){
                                        data[0][1] =  "Lev15_High";
                                    }    
                                }else{
                                     data[0][1] =  "Danger!";
                                }
                                */
                                String cacid = rs3.getString("cacid");
                                String sensorid = rs3.getString("sensorid");
                                String equipmentid = rs3.getString("equipmentid");
                                String code = rs3.getString("monitortype");
                                String phase = rs3.getString("phase"); 
                                xml = GenerateXml.createCACData_scur(cacid,sensorid,equipmentid,timestamp,phase,data,code);
//</editor-fold>
                                String str = ucd.getXydlServiceImplPort().uploadCACData(xml);
                                System.out.println("客户端接受："+str); 
                                TreeMap ret = GenerateXml.xmlElements(str);
                                System.out.println("客户端接受："+ret);
                                if( Integer.parseInt(ret.get("response.result.code").toString())==0){
                                    String sql4 = "UPDATE data_scur_h SET isupload = 1 WHERE d_time ='"+rs1.getString("d_time")+"' and eqmid='"+rs1.getString("eqmid")+"' ";
                                    System.out.println(sql4);
                                    help.getConnection();
                                    int num = help.excuteUpdate(sql4);
                                    help.getConnection().close();
                                    if(num>0){
                                        String old=jTextArea1.getText();
                                        jTextArea1.append("\n"); 
                                        jTextArea1.setText(old+"传输成功！"+xml+"\n");
                                        System.out.println("Send XML: " + xml );
                                    }
                                }
                            }
                        }
                     }catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                writeFile("slog/"+getCurrentYYYYMM()+".log", e.getMessage());
        }
                    }
                }
                       
                if(rs.getInt("mtid")==4){//避雷器
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    Calendar beforeTime = Calendar.getInstance();
                    beforeTime.add(Calendar.MINUTE, -15);// 15分钟之前的时间
                    Date beforeD = beforeTime.getTime();
                    String time = sdf.format(beforeD);
                    String sql1 = "select eqmid,d_time,pt1,lc1,rc1,ligcnt1,lastligtm1,pt2,lc2,rc2,ligcnt2,lastligtm2,pt3,lc3,rc3,ligcnt3,lastligtm3 from data_moa_h where  (isupload is null or isupload=0) and eqmid ="+rs.getString("id")+" and d_time<\""+time+"\" order by d_time asc";
                    //System.out.println(sql1);
                    pstmt=conn.prepareStatement(sql1);//装载sql语句
                    ResultSet rs1=null;
                    rs1=pstmt.executeQuery();
                    //System.out.println(sql1);
                    while(rs1.next()){
                        try{
                    //System.out.println(rs1.getString("eqmid"));
                        String sql2 = "select * from warn_cfg where eqmid ="+rs1.getString("eqmid")+"";
                        pstmt=conn.prepareStatement(sql2);//装载sql语句
                        ResultSet rs2=null;
                        rs2=pstmt.executeQuery();
                        
                        String sql3 = "select * from i2relation where eqmid ="+rs1.getString("eqmid");
                        //System.out.println(sql3);
                        pstmt=conn.prepareStatement(sql3);//装载sql语句
                        ResultSet rs3=null;
                        rs3=pstmt.executeQuery();
                        int okstatus = 3;
                        while(rs3.next()){
                            String data[][] = new String[5][2];
                            String timestamp = rs1.getString("d_time");
                            //System.out.println(rs2);
                            if(!rs3.getString("cacid").equals("")){
                                if(rs3.getString("phase").equals("A相")){
                                    data[0][0] =  rs1.getString("pt1");
                                    if(rs1.getString("pt1")==null)
                                    {
                                        data[0][0]="0";
                                    }
                                    data[1][0] =  rs1.getString("lc1");
                                    if(rs1.getString("lc1")==null)
                                    {
                                        data[1][0]="0";
                                    }
                                    data[2][0] =  rs1.getString("rc1");
                                    if(rs1.getString("rc1")==null)
                                    {
                                        data[2][0]="0";
                                    }
                                    data[3][0] =  rs1.getString("ligcnt1");
                                    if( rs1.getInt("ligcnt1")==-1 || rs1.getInt("ligcnt1")==0){
                                        data[3][0] = "0";
                                    }
                                    data[3][1] =  "FALSE";
                                    if(rs1.getString("lastligtm1")==null || rs1.getString("lastligtm1").equals("0000-0-0 00:00:00"))
                                    {
                                        data[4][0] =  "1970-01-01 00:00:00"; 
                                    }
                                    else
                                    {
                                        data[4][0] =  rs1.getString("lastligtm1");
                                    }
                                    data[4][1] =  "FALSE";
                                    if(rs2.next()){
                                        if(rs1.getInt("pt1")>rs2.getInt("warnmin1") && rs1.getInt("pt1")<rs2.getInt("warnmax1")){
                                            data[0][1] =  "FALSE";
                                        }else{
                                            data[0][1] =  "TRUE";  
                                        }
                                        if(rs1.getInt("lc1")>rs2.getInt("warnmin4") && rs1.getInt("lc1")<rs2.getInt("warnmax4")){
                                            data[1][1] =  "FALSE";
                                        }else{
                                            data[1][1] =  "TRUE";   
                                        }
                                        if(rs1.getInt("rc1")>rs2.getInt("warnmin7") && rs1.getInt("rc1")<rs2.getInt("warnmax7")){
                                            data[2][1] =  "FALSE";
                                        }else{
                                            data[2][1] =  "TRUE";   
                                        }
                                    }else{
                                        data[0][1] =  "FALSE";
                                        data[1][1] =  "FALSE";
                                        data[2][1] =  "FALSE";
                                    }
                                }else if(rs3.getString("phase").equals("B相")){
                                    data[0][0] =  rs1.getString("pt2");
                                    if(rs1.getString("pt2")==null)
                                    {
                                        data[0][0]="0";
                                    }
                                    data[1][0] =  rs1.getString("lc2");
                                    if(rs1.getString("lc2")==null)
                                    {
                                        data[1][0]="0";
                                    }
                                    data[2][0] =  rs1.getString("rc2");
                                    if(rs1.getString("rc2")==null)
                                    {
                                        data[2][0]="0";
                                    }
                                    data[3][0] =  rs1.getString("ligcnt2");
                                    if( rs1.getInt("ligcnt2")==-1 || rs1.getInt("ligcnt2")==0){
                                        data[3][0] = "0";
                                    }
                                    data[3][1] =  "FALSE";
                                    if(rs1.getString("lastligtm2")==null || rs1.getString("lastligtm2").equals("0000-0-0 00:00:00"))
                                    {
                                        data[4][0] =  "1970-01-01 00:00:00"; 
                                    }
                                    else
                                    {
                                        data[4][0] =  rs1.getString("lastligtm2");
                                    }
                                    data[4][1] =  "FALSE";
                                    if(rs2.next()){
                                        if(rs1.getInt("pt2")>rs2.getInt("warnmin2") && rs1.getInt("pt1")<rs2.getInt("warnmax2")){
                                            data[0][1] =  "FALSE";
                                        }else{
                                            data[0][1] =  "TRUE";   
                                        }
                                        if(rs1.getInt("lc2")>rs2.getInt("warnmin5") && rs1.getInt("lc1")<rs2.getInt("warnmax5")){
                                            data[1][1] =  "FALSE";
                                        }else{
                                            data[1][1] =  "TRUE";   
                                        }
                                        if(rs1.getInt("rc2")>rs2.getInt("warnmin8") && rs1.getInt("rc1")<rs2.getInt("warnmax8")){
                                            data[2][1] =  "FALSE";
                                        }else{
                                            data[2][1] =  "TRUE";   
                                        }
                                    }else{
                                        data[0][1] =  "FALSE";
                                        data[1][1] =  "FALSE";
                                        data[2][1] =  "FALSE";
                                    }
                                }else if(rs3.getString("phase").equals("C相")){
                                    data[0][0] =  rs1.getString("pt3");
                                    if(rs1.getString("pt3")==null)
                                    {
                                        data[0][0]="0";
                                    }
                                    data[1][0] =  rs1.getString("lc3");
                                    if(rs1.getString("lc3")==null)
                                    {
                                        data[1][0]="0";
                                    }
                                    data[2][0] =  rs1.getString("rc3");
                                    if(rs1.getString("rc3")==null)
                                    {
                                        data[2][0]="0";
                                    }
                                    data[3][0] =  rs1.getString("ligcnt3");
                                    if( rs1.getInt("ligcnt3")==-1 || rs1.getInt("ligcnt3")==0){
                                        data[3][0] = "0";
                                    }
                                    data[3][1] =  "FALSE";
                                    if(rs1.getString("lastligtm3")==null || rs1.getString("lastligtm3").equals("0000-0-0 00:00:00"))
                                    {
                                        data[4][0] =  "1970-01-01 00:00:00"; 
                                    }
                                    else
                                    {
                                        data[4][0] =  rs1.getString("lastligtm3");
                                    }
                                    data[4][1] =  "FALSE";
                                    if(rs2.next()){
                                        if(rs1.getInt("pt3")>rs2.getInt("warnmin3") && rs1.getInt("pt1")<rs2.getInt("warnmax3")){
                                            data[0][1] =  "FALSE";
                                        }else{
                                            data[0][1] =  "TRUE";   
                                        }
                                        if(rs1.getInt("lc3")>rs2.getInt("warnmin6") && rs1.getInt("lc1")<rs2.getInt("warnmax6")){
                                            data[1][1] =  "FALSE";
                                        }else{
                                            data[1][1] =  "TRUE";   
                                        }
                                        if(rs1.getInt("rc3")>rs2.getInt("warnmin9") && rs1.getInt("rc1")<rs2.getInt("warnmax9")){
                                            data[2][1] =  "FALSE";
                                        }else{
                                            data[2][1] =  "TRUE";   
                                        }
                                    }else{
                                        data[0][1] =  "FALSE";
                                        data[1][1] =  "FALSE";
                                        data[2][1] =  "FALSE";
                                    }
                                };
                            }
                            String cacid = rs3.getString("cacid");
                            String sensorid = rs3.getString("sensorid");
                            String equipmentid = rs3.getString("equipmentid");
                            String phase = rs3.getString("phase");
                            xml = GenerateXml.createCACData_moa(cacid,sensorid,equipmentid,timestamp,phase,data);
                            writeFile("slog/"+getCurrentYYYYMM()+".log", xml);
                            String str = ucd.getXydlServiceImplPort().uploadCACData(xml);
                             
                            System.out.println("客户端接受："+xml); 
                            TreeMap ret = GenerateXml.xmlElements(str);
                            System.out.println("客户端接受："+ret);
                            if( Integer.parseInt(ret.get("response.result.code").toString())==0){
                                okstatus--;
                            }
                        }
                        if(okstatus==0){
                            String sql4 = "UPDATE data_moa_h SET isupload = 1 WHERE d_time='"+rs1.getString("d_time")+"' and eqmid='"+rs1.getString("eqmid")+"'";
                            System.out.println(sql4);
                            help.getConnection();
                            int num = help.excuteUpdate(sql4);
                            help.getConnection().close();
                            if(num>0){
                                String old=jTextArea1.getText();
                                jTextArea1.append("\n"); 
                                jTextArea1.setText(old+"传输成功！"+xml+"\n");
                            }
                        }
                       }catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                writeFile("slog/"+getCurrentYYYYMM()+".log", e.getMessage());
        }
                    }
                }
                if(rs.getInt("mtid")==1){
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    Calendar beforeTime = Calendar.getInstance();
                    beforeTime.add(Calendar.MINUTE, -90);// 30分钟之前的时间
                    Date beforeD = beforeTime.getTime();
                    String time = sdf.format(beforeD);
                    String sql1 = "select * from data_epa_h where  (isupload is null or isupload=0)    and  eqmid ="+rs.getString("id")+" and d_time<\""+time+"\" order by d_time asc";
                    pstmt=conn.prepareStatement(sql1);//装载sql语句
                    ResultSet rs1=null;
                    rs1=pstmt.executeQuery();
                    while(rs1.next()){
                    try{
                        String sql2 = "select * from warn_cfg where eqmid ="+rs1.getString("eqmid")+"";
                        pstmt=conn.prepareStatement(sql2);//装载sql语句
                        ResultSet rs2=null;
                        rs2=pstmt.executeQuery();
                        String sql3 = "select * from i2relation where eqmid ="+rs1.getString("eqmid");
                        //System.out.println(sql3);
                        pstmt=conn.prepareStatement(sql3);//装载sql语句
                        ResultSet rs3=null;
                        rs3=pstmt.executeQuery();
                        String data[][] = new String[12][2];
                        //System.out.println(rs2);
                        while(rs3.next()){
                            if(!rs3.getString("cacid").equals("")){
                                String timestamp = rs1.getString("d_time");
                                data[0][0] =  rs1.getString("h2ppm");
                                if(rs1.getString("h2ppm")==null)
                                {
                                    data[0][0]="0";
                                }
                                data[1][0] =  rs1.getString("ch4ppm");
                                if(rs1.getString("ch4ppm")==null)
                                {
                                    data[1][0]="0";
                                }
                                data[2][0] =  rs1.getString("c2h6ppm");
                                if(rs1.getString("c2h6ppm")==null)
                                {
                                    data[2][0]="0";
                                }
                                data[3][0] =  rs1.getString("c2h4ppm");
                                if(rs1.getString("c2h4ppm")==null)
                                {
                                    data[3][0]="0";
                                }
                                data[4][0] =  rs1.getString("c2h2ppm");
                                if(rs1.getString("c2h2ppm")==null)
                                {
                                    data[4][0]="0";
                                }
                                data[5][0] =  rs1.getString("coppm");
                                if(rs1.getString("coppm")==null)
                                {
                                    data[5][0]="0";
                                }
                                data[6][0] =  rs1.getString("co2ppm");
                                if(rs1.getString("co2ppm")==null)
                                {
                                    data[6][0]="34";
                                }
                                data[7][0] =  rs1.getString("o2ppm");
                                if(rs1.getString("o2ppm")==null)
                                {
                                    data[7][0]="0";
                                }
                                data[8][0] =  rs1.getString("n2ppm");
                                if(rs1.getString("n2ppm")==null)
                                {
                                    data[8][0]="0";
                                }
                                data[9][0] =  rs1.getString("totalhydrocarbon");
                                if(rs1.getString("totalhydrocarbon")==null)
                                {
                                    data[9][0]="0";
                                }
//                                data[10][0] =  rs1.getString("gaspress");
//                                if(data[10][0]==null){
//                                    data[10][0]="0";
//                                }
//                                if(rs1.getFloat("gaspress")==0)
//                                {
//                                    data[10][0]="0";
//                                }
                                data[10][0]="1";
                                data[11][0] =  rs1.getString("h2oppm");
                                if(rs1.getString("h2oppm")==null)
                                {
                                    data[11][0]="0";
                                }
                                if(rs2.next()){
                                    if(rs1.getInt("h2ppm")>rs2.getInt("warnmin5") && rs1.getInt("h2ppm")<rs2.getInt("warnmax5")){
                                        data[0][1] =  "FALSE";
                                    }else{
                                        data[0][1] =  "TRUE";   
                                    }
                                    if(rs1.getInt("ch4ppm")>rs2.getInt("warnmin1") && rs1.getInt("ch4ppm")<rs2.getInt("warnmax1")){
                                        data[1][1] =  "FALSE";
                                    }else{
                                        data[1][1] =  "TRUE";   
                                    }
                                    if(rs1.getInt("c2h6ppm")>rs2.getInt("warnmin3") && rs1.getInt("c2h6ppm")<rs2.getInt("warnmax3")){
                                        data[2][1] =  "FALSE";
                                    }else{
                                        data[2][1] =  "TRUE";   
                                    }
                                    if(rs1.getInt("c2h4ppm")>rs2.getInt("warnmin2") && rs1.getInt("c2h4ppm")<rs2.getInt("warnmax2")){
                                        data[3][1] =  "FALSE";
                                    }else{
                                        data[3][1] =  "TRUE";   
                                    }if(rs1.getInt("c2h2ppm")>rs2.getInt("warnmin4") && rs1.getInt("c2h2ppm")<rs2.getInt("warnmax4")){
                                        data[4][1] =  "FALSE";
                                    }else{
                                        data[4][1] =  "TRUE";
                                    }
                                    if(rs1.getInt("coppm")>rs2.getInt("warnmin6") && rs1.getInt("coppm")<rs2.getInt("warnmax6")){
                                        data[5][1] =  "FALSE";
                                    }else{
                                        data[5][1] =  "TRUE";
                                    }
                                    if(rs1.getInt("co2ppm")>rs2.getInt("warnmin7") && rs1.getInt("co2ppm")<rs2.getInt("warnmax7")){
                                        data[6][1] =  "FALSE";
                                    }else{
                                        data[6][1] =  "TRUE";
                                    }
                                    if(rs1.getInt("o2ppm")>rs2.getInt("warnmin10") && rs1.getInt("o2ppm")<rs2.getInt("warnmax10")){
                                        data[7][1] =  "FALSE";
                                    }else{
                                        data[7][1] =  "TRUE";
                                    }
                                    if(rs1.getInt("n2ppm")>rs2.getInt("warnmin11") && rs1.getInt("n2ppm")<rs2.getInt("warnmax11")){
                                        data[8][1] =  "FALSE";
                                    }else{
                                        data[8][1] =  "TRUE";
                                    }
                                    if(rs1.getInt("totalhydrocarbon")>rs2.getInt("warnmin8") && rs1.getInt("totalhydrocarbon")<rs2.getInt("warnmax8")){
                                        data[9][1] =  "FALSE";
                                    }else{
                                        data[9][1] =  "TRUE";   
                                    }
                                    if(rs1.getInt("gaspress")>rs2.getInt("warnmin12") && rs1.getInt("gaspress")<rs2.getInt("warnmax12")){
                                        data[10][1] =  "FALSE";
                                    }else{
                                        data[10][1] =  "TRUE";
                                    }
                                      if(rs1.getInt("h2oppm")>rs2.getInt("warnmin13") && rs1.getInt("h2oppm")<rs2.getInt("warnmax13")){
                                        data[11][1] =  "FALSE";
                                    }else{
                                        data[11][1] =  "TRUE";   
                                    }
                                }else{
                                    data[0][1] =  "FALSE";
                                    data[1][1] =  "FALSE";
                                    data[2][1] =  "FALSE";
                                    data[3][1] =  "FALSE";
                                    data[4][1] =  "FALSE";
                                    data[5][1] =  "FALSE";
                                    data[6][1] =  "FALSE";
                                    data[7][1] =  "FALSE";
                                    data[8][1] =  "FALSE";
                                    data[9][1] =  "FALSE";
                                    data[10][1] =  "FALSE";
                                    data[11][1] =  "FALSE";
                                }
                                String cacid = rs3.getString("cacid");
                                String sensorid = rs3.getString("sensorid");
                                String equipmentid = rs3.getString("equipmentid");
                                String phase = rs3.getString("phase");
                                xml = GenerateXml.createCACData_YSP(cacid,sensorid,equipmentid,timestamp,phase,data);
                                String str = ucd.getXydlServiceImplPort().uploadCACData(xml);
                                System.out.println("客户端发送："+xml);
                                TreeMap ret = GenerateXml.xmlElements(str);
                                System.out.println("客户端接受："+ret);
                                if( Integer.parseInt(ret.get("response.result.code").toString())==0){
                                    String sql4 = "UPDATE data_epa_h SET isupload = 1 WHERE d_time ='"+rs1.getString("d_time")+"' and eqmid='"+rs1.getString("eqmid")+"'";
                                    //System.out.println(sql4);
                                    help.getConnection();
                                    int num = help.excuteUpdate(sql4);
                                    help.getConnection().close();
                                    if(num>0){
                                        String old=jTextArea1.getText();
                                        jTextArea1.append("\n");
                                        jTextArea1.setText(old+"传输成功！"+xml+"\n");
                                    }
                                }  
                            }
                        }
						        }catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                writeFile("slog/"+getCurrentYYYYMM()+".log", e.getMessage());
        }
                    }
                }
                if(rs.getInt("mtid")==9){
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    Calendar beforeTime = Calendar.getInstance();
                    beforeTime.add(Calendar.MINUTE, -15);// 15分钟之前的时间
                    Date beforeD = beforeTime.getTime();
                    String time = sdf.format(beforeD);
                    String sql1 = "select * from data_eaif_h where  (isupload is null or isupload=0) and  eqmid ="+rs.getString("id")+" and capturetime<\""+time+"\" order by capturetime asc";
                    //System.out.println(sql1);
                    pstmt=conn.prepareStatement(sql1);//装载sql语句
                    ResultSet rs1=null;
                    rs1=pstmt.executeQuery(); 
                    while(rs1.next()){
						try{
                        String sql2 = "select * from warn_cfg where eqmid ="+rs1.getString("eqmid")+"";
                        pstmt=conn.prepareStatement(sql2);//装载sql语句
                        ResultSet rs2=null;
                        rs2=pstmt.executeQuery();
                        
                        String sql3 = "select * from i2relation where eqmid ="+rs1.getString("eqmid");
                        //System.out.println(sql3);
                        pstmt=conn.prepareStatement(sql3);//装载sql语句
                        ResultSet rs3=null;
                        rs3=pstmt.executeQuery();
                        String data[][] = new String[6][2];
                        //System.out.println(rs2);
                        while(rs3.next()){
                            if(!rs3.getString("cacid").equals("")){
                                String timestamp = rs1.getString("capturetime");
                                String phase = rs3.getString("phase");
                                String cacid = rs3.getString("cacid");
                                data[0][0] =  rs1.getString("maxtemp");
                                data[1][0] =  rs1.getString("mintemp");
                                data[2][0] =  rs1.getString("avgtemp");
                                if(rs2.next()){
                                    if(rs1.getInt("maxtemp")>rs2.getInt("warnmin1") && rs1.getInt("maxtemp")<rs2.getInt("warnmax1")){
                                        data[0][1] =  "FALSE";
                                    }else{
                                        data[0][1] =  "TRUE";
                                    }
                                    if(rs1.getInt("mintemp")>rs2.getInt("warnmin2") && rs1.getInt("mintemp")<rs2.getInt("warnmax2")){
                                        data[1][1] =  "FALSE";
                                    }else{
                                        data[1][1] =  "TRUE";   
                                    }
                                    if(rs1.getInt("avgtemp")>rs2.getInt("warnmin3") && rs1.getInt("avgtemp")<rs2.getInt("warnmax3")){
                                        data[2][1] =  "FALSE";
                                    }else{
                                        data[2][1] =  "TRUE";   
                                    }
                                }else{
                                    data[0][1] =  "FALSE";
                                    data[1][1] =  "FALSE";
                                    data[2][1] =  "FALSE";
                                }
                                String sensorid = rs3.getString("sensorid");
                                String equipmentid = rs3.getString("equipmentid");
                                String code=rs3.getString("monitortype");
                                xml = GenerateXml.createCACData_eaif(cacid,sensorid,equipmentid,timestamp,phase,data,code);
                                String str = ucd.getXydlServiceImplPort().uploadCACData(xml);
                                //System.out.println("客户端接受："+str); 
                                TreeMap ret = GenerateXml.xmlElements(str);
                                //System.out.println("客户端接受："+ret);
                                if( Integer.parseInt(ret.get("response.result.code").toString())==0){
                                    String sql4 = "UPDATE data_eaif_h SET isupload = 1 WHERE capturetime ='"+rs1.getString("capturetime")+"' and eqmid='"+rs1.getString("eqmid")+"'";
                                    //System.out.println(sql4);
                                    help.getConnection();
                                    int num = help.excuteUpdate(sql4);
                                    help.getConnection().close();
                                    if(num>0){
                                        String old=jTextArea1.getText();
                                        jTextArea1.append("\n"); 
                                        jTextArea1.setText(old+"传输成功！\n");
                                    }
                                }
                            }
                        }
						        }catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                writeFile("slog/"+getCurrentYYYYMM()+".log", e.getMessage());
        }
                    }
                }
                if(rs.getInt("mtid")==2){
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    Calendar beforeTime = Calendar.getInstance();
                    beforeTime.add(Calendar.MINUTE, -15);// 15分钟之前的时间
                    Date beforeD = beforeTime.getTime();
                    String time = sdf.format(beforeD);
                    String sql1 = "select * from data_eia_h where  (isupload is null or isupload=0)    and  eqmid ="+rs.getString("id")+" and d_time<\""+time+"\" order by d_time asc";
                    pstmt=conn.prepareStatement(sql1);//装载sql语句
                    ResultSet rs1=null;
                    rs1=pstmt.executeQuery();
                    while(rs1.next()){
						try{
                        String sql2 = "select * from warn_cfg where eqmid ="+rs1.getString("eqmid")+"";
                        pstmt=conn.prepareStatement(sql2);//装载sql语句
                        ResultSet rs2=null;
                        rs2=pstmt.executeQuery();
                        String sql3 = "select * from i2relation where eqmid ="+rs1.getString("eqmid");
                        //System.out.println(sql3);
                        pstmt=conn.prepareStatement(sql3);//装载sql语句
                        ResultSet rs3=null;
                        rs3=pstmt.executeQuery();
                        String data[][] = new String[2][2];
                        while(rs3.next()){
                            if(!rs3.getString("cacid").equals("")){
                               String timestamp = rs1.getString("d_time");
                                data[0][0] =  rs1.getString("d_ct_1");
                                if(rs2.next()){
                                    if(rs1.getInt("d_ct_1")>rs2.getInt("warnmin5") && rs1.getInt("d_ct_1")<rs2.getInt("warnmax5")){
                                        data[0][1] =  "FALSE";
                                    }else{
                                        data[0][1] =  "TRUE";   
                                    }
                                }else{
                                     data[0][1] =  "FALSE";
                                }
                                
                                String cacid = rs3.getString("cacid");
                                String sensorid = rs3.getString("sensorid");
                                String equipmentid = rs3.getString("equipmentid");
                                String phase = rs3.getString("phase");
                                xml = GenerateXml.createCACData_tx(cacid,sensorid,equipmentid,timestamp,phase,data);
                                String str = ucd.getXydlServiceImplPort().uploadCACData(xml);
                                //System.out.println("客户端接受："+str); 
                                TreeMap ret = GenerateXml.xmlElements(str);
                                //System.out.println("客户端接受："+ret);
                                if( Integer.parseInt(ret.get("response.result.code").toString())==0){
                                    String sql4 = "UPDATE data_eia_h SET isupload = 1 WHERE d_time ='"+rs1.getString("d_time")+"' and eqmid='"+rs1.getString("eqmid")+"'";
                                    //System.out.println(sql4);
                                    help.getConnection();
                                    int num = help.excuteUpdate(sql4);
                                    help.getConnection().close();
                                    if(num>0){
                                        String old=jTextArea1.getText();
                                        jTextArea1.append("\n"); 
                                        jTextArea1.setText(old+"传输成功！"+xml+"\n");
                                    }
                                }
                            }
                        }
						        }catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                writeFile("slog/"+getCurrentYYYYMM()+".log", e.getMessage());
        }
                    }
                }
                if(rs.getInt("mtid")==13||rs.getInt("mtid")==14||rs.getInt("mtid")==15){
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    Calendar beforeTime = Calendar.getInstance();
                    beforeTime.add(Calendar.MINUTE, -15);// 15分钟之前的时间
                    Date beforeD = beforeTime.getTime();
                    String time = sdf.format(beforeD);
                    String sql1 = "select * from data_eia_h where  (isupload is null or isupload=0) and  eqmid ="+rs.getString("id")+" and d_time<\""+time+"\" order by d_time asc";
                    pstmt=conn.prepareStatement(sql1);//装载sql语句
                    ResultSet rs1=null;
                    rs1=pstmt.executeQuery(); 
                    while(rs1.next()){
						try{
                        String sql2 = "select * from warn_cfg where eqmid ="+rs1.getString("eqmid")+"";
                        pstmt=conn.prepareStatement(sql2);//装载sql语句
                        ResultSet rs2=null;
                        rs2=pstmt.executeQuery();
                        String sql3 = "select * from i2relation where eqmid ="+rs1.getString("eqmid");
                        //System.out.println(sql3);
                        pstmt=conn.prepareStatement(sql3);//装载sql语句
                        ResultSet rs3=null;
                        rs3=pstmt.executeQuery();
                        String data[][] = new String[6][2];
                        //System.out.println(rs2);
                        int okstatus = 3;
                        while(rs3.next()){
                            if(!rs3.getString("cacid").equals("")){
                                String timestamp = rs1.getString("d_time");
                                String d_ct_1 = rs1.getString("d_ct_1");
                                String d_ct_2 = rs1.getString("d_ct_2");
                                String d_ct_3 = rs1.getString("d_ct_3");
                                String d_pt_1 =  rs1.getString("d_pt_1");
                                String d_pt_2 =  rs1.getString("d_pt_2");
                                String d_pt_3 =  rs1.getString("d_pt_3");
                                String maxd_ct = d_ct_1;
                                String mind_ct = d_ct_1;
                                String maxd_pt = d_pt_1;
                                String mind_pt = d_pt_1;
                                if(Float.parseFloat(d_ct_2)>Float.parseFloat(maxd_ct)){
                                    maxd_ct = d_ct_2;
                                }
                                if(Float.parseFloat(d_ct_3)>Float.parseFloat(maxd_ct)){
                                    maxd_ct = d_ct_3;
                                }
                                if(Float.parseFloat(d_ct_2)>Float.parseFloat(maxd_ct)){
                                    maxd_ct = d_ct_2;
                                }
                                if(Float.parseFloat(d_ct_2)<Float.parseFloat(mind_ct)){
                                    mind_ct = d_ct_2;
                                }
                                if(Float.parseFloat(d_ct_3)<Float.parseFloat(mind_ct)){
                                    mind_ct = d_ct_3;
                                }
                                //获取三相不平衡电流(最大差值)
                                String current = (Float.parseFloat(maxd_ct)-Float.parseFloat(mind_ct))+"";
                                
                                if(Float.parseFloat(d_pt_2)>Float.parseFloat(maxd_pt)){
                                    maxd_pt = d_pt_2;
                                }
                                if(Float.parseFloat(d_pt_3)>Float.parseFloat(maxd_pt)){
                                    maxd_pt = d_pt_3;
                                }
                                if(Float.parseFloat(d_pt_2)>Float.parseFloat(maxd_pt)){
                                    maxd_pt = d_pt_2;
                                }
                                if(Float.parseFloat(d_pt_2)<Float.parseFloat(mind_pt)){
                                    mind_pt = d_pt_2;
                                }
                                if(Float.parseFloat(d_pt_3)<Float.parseFloat(mind_pt)){
                                    mind_pt = d_pt_3;
                                }
                                String voltage = (Float.parseFloat(maxd_pt)-Float.parseFloat(mind_pt))+"";
                                String sn = rs3.getString("sensorindex");
                                if(rs3.getString("sensorindex").equals("1")){
                                    data[0][0] =  rs1.getString("d_pf_1");
                                    data[1][0] =  rs1.getString("d_jx_1");
                                    data[2][0] =  current;
                                    data[3][0] =  voltage;
                                    data[4][0] =  d_ct_1;
                                    data[5][0] =  d_pt_1;
                                    if(rs2.next()){
                                        if(rs1.getInt("d_pf_1")>rs2.getInt("warnmin10") && rs1.getInt("d_pf_1")<rs2.getInt("warnmax10")){
                                            data[0][1] =  "FALSE";
                                        }else{
                                            data[0][1] =  "TRUE";  
                                        }
                                        if(rs1.getInt("d_jx_1")>rs2.getInt("warnmin14") && rs1.getInt("d_jx_1")<rs2.getInt("warnmax14")){
                                            data[1][1] =  "FALSE";
                                        }else{
                                            data[1][1] =  "TRUE";   
                                        }
                                        data[2][1] =  "FALSE";
                                        data[3][1] =  "FALSE";
                                        if (rs1.getInt("d_ct_1") > rs2.getInt("warnmin5") && rs1.getInt("d_ct_1") < rs2.getInt("warnmax5")) {
                                            data[4][1] = "FALSE";
                                        } else {
                                            data[4][1] = "TRUE";
                                        }
                                        if (rs1.getInt("d_pt_1") > rs2.getInt("warnmin1") && rs1.getInt("d_ct_1") < rs2.getInt("warnmax1")) {
                                            data[5][1] = "FALSE";
                                        } else {
                                            data[5][1] = "TRUE";
                                        }
                                    }else{
                                         data[0][1] =  "FALSE";
                                         data[1][1] =  "FALSE";
                                         data[2][1] =  "FALSE";
                                         data[3][1] =  "FALSE";
                                         data[4][1] =  "FALSE";
                                         data[5][1] =  "FALSE";
                                    }
                                }else if(rs3.getString("sensorindex").equals("2")){
                                    data[0][0] =  rs1.getString("d_pf_2");
                                    data[1][0] =  rs1.getString("d_jx_2");
                                    data[2][0] =  current;
                                    data[3][0] =  voltage;
                                    data[4][0] =  d_ct_2;
                                    data[5][0] =  d_pt_2;
                                    if(rs2.next()){
                                        if(rs1.getInt("d_pf_2")>rs2.getInt("warnmin11") && rs1.getInt("d_pf_2")<rs2.getInt("warnmax11")){
                                            data[0][1] =  "FALSE";
                                        }else{
                                            data[0][1] =  "TRUE";  
                                        }
                                        if(rs1.getInt("d_jx_2")>rs2.getInt("warnmin15") && rs1.getInt("d_jx_2")<rs2.getInt("warnmax15")){
                                            data[1][1] =  "FALSE";
                                        }else{
                                            data[1][1] =  "TRUE";   
                                        }
                                        data[2][1] =  "FALSE";
                                        data[3][1] =  "FALSE";
                                        if (rs1.getInt("d_ct_2") > rs2.getInt("warnmin6") && rs1.getInt("d_ct_2") < rs2.getInt("warnmax6")) {
                                            data[4][1] = "FALSE";
                                        } else {
                                            data[4][1] = "TRUE";
                                        }
                                        if (rs1.getInt("d_pt_2") > rs2.getInt("warnmin2") && rs1.getInt("d_ct_2") < rs2.getInt("warnmax2")) {
                                            data[5][1] = "FALSE";
                                        } else {
                                            data[5][1] = "TRUE";
                                        }
                                    }else{
                                         data[0][1] =  "FALSE";
                                         data[1][1] =  "FALSE";
                                         data[2][1] =  "FALSE";
                                         data[3][1] =  "FALSE";
                                         data[4][1] =  "FALSE";
                                         data[5][1] =  "FALSE";
                                    }
                                }else if(rs3.getString("sensorindex").equals("3")){
                                    data[0][0] =  rs1.getString("d_pf_3");
                                    data[1][0] =  rs1.getString("d_jx_3");
                                    data[2][0] =  current;
                                    data[3][0] =  voltage;
                                    data[4][0] =  d_ct_3;
                                    data[5][0] =  d_pt_3;
                                    if(rs2.next()){
                                        if(rs1.getInt("d_pf_3")>rs2.getInt("warnmin12") && rs1.getInt("d_pf_3")<rs2.getInt("warnmax12")){
                                            data[0][1] =  "FALSE";
                                        }else{
                                            data[0][1] =  "TRUE";  
                                        }
                                        if(rs1.getInt("d_jx_3")>rs2.getInt("warnmin16") && rs1.getInt("d_jx_3")<rs2.getInt("warnmax16")){
                                            data[1][1] =  "FALSE";
                                        }else{
                                            data[1][1] =  "TRUE";   
                                        }
                                        data[2][1] =  "FALSE";
                                        data[3][1] =  "FALSE";
                                        if (rs1.getInt("d_ct_3") > rs2.getInt("warnmin7") && rs1.getInt("d_ct_3") < rs2.getInt("warnmax7")) {
                                            data[4][1] = "FALSE";
                                        } else {
                                            data[4][1] = "TRUE";
                                        }
                                        if (rs1.getInt("d_pt_3") > rs2.getInt("warnmin3") && rs1.getInt("d_ct_3") < rs2.getInt("warnmax3")) {
                                            data[5][1] = "FALSE";
                                        } else {
                                            data[5][1] = "TRUE";
                                        }
                                    }else{
                                         data[0][1] =  "FALSE";
                                         data[1][1] =  "FALSE";
                                         data[2][1] =  "FALSE";
                                         data[3][1] =  "FALSE";
                                         data[4][1] =  "FALSE";
                                         data[5][1] =  "FALSE";
                                    }
                                }
                                
                                
                                String cacid = rs3.getString("cacid");
                                String sensorid = rs3.getString("sensorid");                               
                                String equipmentid = rs3.getString("equipmentid");
                                String phase = rs3.getString("phase");
                                xml = GenerateXml.createCACData_eia(cacid,sensorid,equipmentid,timestamp,phase,data);
                                String str = ucd.getXydlServiceImplPort().uploadCACData(xml);
                                System.out.println("客户端接受："+xml); 
                                TreeMap ret = GenerateXml.xmlElements(str);
                                System.out.println("客户端接受："+ret);
                                if( Integer.parseInt(ret.get("response.result.code").toString())==0){
                                    okstatus--;
                                }
                            }
                        }
                        if(okstatus==0){
                            String sql4 = "UPDATE data_eia_h SET isupload = 1 WHERE d_time ='"+rs1.getString("d_time")+"' and eqmid='"+rs1.getString("eqmid")+"'";
                            //System.out.println(sql4);
                            help.getConnection();
                            int num = help.excuteUpdate(sql4);
                            help.getConnection().close();
                            if(num>0){
                                String old=jTextArea1.getText();
                                jTextArea1.append("\n"); 
                                jTextArea1.setText(old+"传输成功！\n");
                            }
                        }
						        }catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                writeFile("slog/"+getCurrentYYYYMM()+".log", e.getMessage());
        }
                    }
                }
                if(rs.getInt("mtid")==8){
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    Calendar beforeTime = Calendar.getInstance();
                    beforeTime.add(Calendar.MINUTE, -15);// 15分钟之前的时间
                    Date beforeD = beforeTime.getTime();
                    String time = sdf.format(beforeD);
                    String sql1 = "select * from data_sf6_h where   (isupload is null or isupload=0)    and eqmid ="+rs.getString("id")+"  and d_time<\""+time+"\"  order by d_time asc";
                    //System.out.println(sql1);
                    pstmt=conn.prepareStatement(sql1);//装载sql语句
                    ResultSet rs1=null;
                    rs1=pstmt.executeQuery(); 
                    //System.out.println(sql1);
                    while(rs1.next()){
						try{
                        //System.out.println(rs1.getString("eqmid"));
                        String sql2 = "select * from warn_cfg where eqmid ="+rs1.getString("eqmid")+"";
                        pstmt=conn.prepareStatement(sql2);//装载sql语句
                        ResultSet rs2=null;
                        rs2=pstmt.executeQuery();
                        String sql3 = "select * from i2relation where eqmid ="+rs1.getString("eqmid");
                        //System.out.println(sql3);
                        pstmt=conn.prepareStatement(sql3);//装载sql语句
                        ResultSet rs3=null;
                        rs3=pstmt.executeQuery();
                        String data[][] = new String[4][2];
                        String timestamp = rs1.getString("d_time");;
                        //System.out.println(rs2);
                        int okstatus = 3;
                        int idnumbers = 3;
                        while(rs3.next()){
                            if(!rs3.getString("cacid").equals("")){
                                String cacid = rs3.getString("cacid");
                                String sensorid = rs3.getString("sensorid");
                                String equipmentid = rs3.getString("equipmentid");
                                String phase = rs3.getString("phase");
                                if(rs3.getString("phase").equals("A相")){
                                    if(rs3.getString("monitortype").equals("024004")){
                                        data[0][0] =  rs1.getString("temp1");
                                        if(rs1.getString("temp1")==null)
                                        {
                                            data[0][0]="0";
                                        }
                                        data[1][0] =  rs1.getString("pressure1");
                                        if(rs1.getString("pressure1")==null)
                                        {
                                            data[1][0]="0";
                                        }
                                        data[2][0] =  rs1.getString("md1");
                                        if(rs1.getString("md1")==null)
                                        {
                                            data[2][0]="0";
                                        }
                                        data[3][0] =  rs1.getString("pm1");
                                        if(rs1.getString("pm1")==null)
                                        {
                                            data[3][0]="0";
                                        }
                                        if(rs2.next()){
                                            if(rs1.getInt("temp1")>rs2.getInt("warnmin1") && rs1.getInt("temp1")<rs2.getInt("warnmax1")){
                                                data[0][1] =  "FALSE";
                                            }else{
                                                data[0][1] =  "TRUE";  
                                            }
                                            if(rs1.getInt("pressure1")>rs2.getInt("warnmin2") && rs1.getInt("pressure1")<rs2.getInt("warnmax2")){
                                                data[1][1] =  "FALSE";
                                            }else{
                                                data[1][1] =  "TRUE";   
                                            }
                                            if(rs1.getInt("md1")>rs2.getInt("warnmin3") && rs1.getInt("md1")<rs2.getInt("warnmin3")){
                                                data[2][1] =  "FALSE";
                                            }else{
                                                data[2][1] =  "TRUE";   
                                            }
                                            if (rs1.getInt("pm1") > rs2.getInt("warnmin4") && rs1.getInt("pm1") < rs2.getInt("warnmax4")) {
                                                data[3][1] = "FALSE";
                                            } else {
                                                data[3][1] = "TRUE";
                                            }
                                        }else{
                                            data[0][1] =  "FALSE";
                                            data[1][1] =  "FALSE";
                                            data[2][1] =  "FALSE";
                                            data[3][1] =  "FALSE";
                                        }
                                        xml = GenerateXml.createCACData_sf6pressure(cacid,sensorid,equipmentid,timestamp,phase,data);
                                    }
                                }else if(rs3.getString("phase").equals("B相")){
                                    if(rs3.getString("monitortype").equals("024004")){
                                        data[0][0] =  rs1.getString("temp2");
                                        if(rs1.getString("temp2")==null)
                                        {
                                            data[0][0]="0";
                                        }
                                        data[1][0] =  rs1.getString("pressure2");
                                        if(rs1.getString("pressure2")==null)
                                        {
                                            data[1][0]="0";
                                        }
                                        data[2][0] =  rs1.getString("md2");
                                        if(rs1.getString("md2")==null)
                                        {
                                            data[2][0]="0";
                                        }
                                        data[3][0] =  rs1.getString("pm2");
                                        if(rs1.getString("pm2")==null)
                                        {
                                            data[3][0]="0";
                                        }
                                        if(rs2.next()){
                                            if(rs1.getInt("temp2")>rs2.getInt("warnmin6") && rs1.getInt("temp2")<rs2.getInt("warnmax6")){
                                                data[0][1] =  "FALSE";
                                            }else{
                                                data[0][1] =  "TRUE";   
                                            }
                                            if(rs1.getInt("pressure2")>rs2.getInt("warnmin7") && rs1.getInt("pressure2")<rs2.getInt("warnmax7")){
                                                data[1][1] =  "FALSE";
                                            }else{
                                                data[1][1] =  "TRUE";   
                                            }
                                            if(rs1.getInt("md2")>rs2.getInt("warnmin8") && rs1.getInt("md2")<rs2.getInt("warnmax8")){
                                                data[2][1] =  "FALSE";
                                            }else{
                                                data[2][1] =  "TRUE";   
                                            }
                                            if(rs1.getInt("pm2")>rs2.getInt("warnmin9") && rs1.getInt("pm2")<rs2.getInt("warnmax9")){
                                                data[3][1] =  "FALSE";
                                            }else{
                                                data[3][1] =  "TRUE";   
                                            }
                                        }else{
                                            data[0][1] =  "FALSE";
                                            data[1][1] =  "FALSE";
                                            data[2][1] =  "FALSE";
                                            data[3][1] =  "FALSE";
                                        }
                                        xml = GenerateXml.createCACData_sf6pressure(cacid,sensorid,equipmentid,timestamp,phase,data);
                                    }
                                }else if(rs3.getString("phase").equals("C相")){
                                    if(rs3.getString("monitortype").equals("024004")){
                                        data[0][0] =  rs1.getString("temp3");
                                        if(rs1.getString("temp3")==null)
                                        {
                                            data[0][0]="0";
                                        }
                                        data[1][0] =  rs1.getString("pressure3");
                                        if(rs1.getString("pressure3")==null)
                                        {
                                            data[1][0]="0";
                                        }
                                        data[2][0] =  rs1.getString("md3");
                                        if(rs1.getString("md3")==null)
                                        {
                                            data[2][0]="0";
                                        }
                                        data[3][0] =  rs1.getString("pm3");
                                        if(rs1.getString("pm3")==null)
                                        {
                                            data[3][0]="0";
                                        }
                                        if(rs2.next()){
                                            if(rs1.getInt("temp3")>rs2.getInt("warnmin11") && rs1.getInt("temp3")<rs2.getInt("warnmax11")){
                                                data[0][1] =  "FALSE";
                                            }else{
                                                data[0][1] =  "TRUE";   
                                            }
                                            if(rs1.getInt("pressure3")>rs2.getInt("warnmin12") && rs1.getInt("pressure3")<rs2.getInt("warnmax12")){
                                                data[1][1] =  "FALSE";
                                            }else{
                                                data[1][1] =  "TRUE";   
                                            }
                                            if(rs1.getInt("md3")>rs2.getInt("warnmin13") && rs1.getInt("md3")<rs2.getInt("warnmax13")){
                                                data[2][1] =  "FALSE";
                                            }else{
                                                data[2][1] =  "TRUE";   
                                            }
                                             if(rs1.getInt("pm3")>rs2.getInt("warnmin14") && rs1.getInt("pm3")<rs2.getInt("warnmax14")){
                                                data[3][1] =  "FALSE";
                                            }else{
                                                data[3][1] =  "TRUE";   
                                            }
                                        }else{
                                            data[0][1] =  "FALSE";
                                            data[1][1] =  "FALSE";
                                            data[2][1] =  "FALSE";
                                            data[3][1] =  "FALSE";
                                        }
                                        xml = GenerateXml.createCACData_sf6pressure(cacid,sensorid,equipmentid,timestamp,phase,data);
                                    }
                                }
                                System.out.println("xml is " + xml);
                                String str = ucd.getXydlServiceImplPort().uploadCACData(xml);
                                System.out.println("客户端接受："+str); 
                                TreeMap ret = GenerateXml.xmlElements(str);
                                System.out.println("客户端接受："+ret);
                                idnumbers--;
                                if( Integer.parseInt(ret.get("response.result.code").toString())==0){
                                    okstatus--;
                                }
                            }
                        }
                        if(okstatus==idnumbers){
                            String sql4 = "UPDATE data_sf6_h SET isupload = 1 WHERE d_time ='"+rs1.getString("d_time")+"' and eqmid='"+rs1.getString("eqmid")+"'";
                            //System.out.println(sql4);
                            help.getConnection();
                            int num = help.excuteUpdate(sql4);
                            help.getConnection().close();
                            if(num>0){
                                String old=jTextArea1.getText();
                                jTextArea1.append("\n"); 
                                jTextArea1.setText(old+"传输成功！\n");
                            }
                        }
						
						        }catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                writeFile("slog/"+getCurrentYYYYMM()+".log", e.getMessage());
        }
                    }
                }
                if(rs.getInt("mtid")==11){
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    Calendar beforeTime = Calendar.getInstance();
                    beforeTime.add(Calendar.MINUTE, -15);// 15分钟之前的时间
                    Date beforeD = beforeTime.getTime();
                    String time = sdf.format(beforeD);
                    String sql1 = "select * from data_otp_h where   (isupload is null or isupload=0)    and eqmid ="+rs.getString("id")+" and d_time<\""+time+"\"  order by d_time asc";
                    pstmt=conn.prepareStatement(sql1);//装载sql语句
                    ResultSet rs1=null;
                    rs1=pstmt.executeQuery(); 
                    while(rs1.next()){
						try{
                        String sql2 = "select * from warn_cfg where eqmid ="+rs1.getString("eqmid")+"";
                        pstmt=conn.prepareStatement(sql2);//装载sql语句
                        ResultSet rs2=null;
                        rs2=pstmt.executeQuery();
                        
                        String sql3 = "select * from i2relation where eqmid ="+rs1.getString("eqmid");
                        //System.out.println(sql3);
                        pstmt=conn.prepareStatement(sql3);//装载sql语句
                        ResultSet rs3=null;
                        rs3=pstmt.executeQuery();
                        String data[][] = new String[1][2];
                        String timestamp = rs1.getString("d_time");
                        //System.out.println(rs2);
                        while(rs3.next()){
                            if(!rs3.getString("cacid").equals("")){
                                data[0][0] =  rs1.getString("timestamp");
                                if(rs2.next()){
                                    if(rs1.getInt("oiltemperature")>rs2.getInt("warnmin1") && rs1.getInt("oiltemperature")<rs2.getInt("warnmax1")){
                                        data[0][1] =  "FALSE";
                                    }else{
                                        data[0][1] =  "TRUE";   
                                    }
                                }else{
                                    data[0][1] =  "FALSE";
                                }
                                
                                String cacid = rs3.getString("cacid");
                                String sensorid = rs3.getString("sensorid");
                                String equipmentid = rs3.getString("equipmentid");
                                String phase = rs3.getString("phase");
                                xml = GenerateXml.createCACData_yw(cacid,sensorid,equipmentid,timestamp,phase,data);
                                String str = ucd.getXydlServiceImplPort().uploadCACData(xml);
                                //System.out.println("客户端接受："+str); 
                            TreeMap ret = GenerateXml.xmlElements(str);
                            //System.out.println("客户端接受："+ret);
                            if( Integer.parseInt(ret.get("response.result.code").toString())==0){
                                String sql4 = "UPDATE data_otp_h SET isupload = 1 WHERE d_time ='"+rs1.getString("d_time")+"' and eqmid='"+rs1.getString("eqmid")+"'";
                                //System.out.println(sql4);
                                help.getConnection();
                                int num = help.excuteUpdate(sql4);
                                help.getConnection().close();
                                if(num>0){
                                    String old=jTextArea1.getText();
                                    jTextArea1.append("\n"); 
                                    jTextArea1.setText(old+"传输成功！\n");
                                }
                            }
                            }
                        }
						        }catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                writeFile("slog/"+getCurrentYYYYMM()+".log", e.getMessage());
        }
                    }
                }
                if(rs.getInt("mtid")==10){
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    Calendar beforeTime = Calendar.getInstance();
                    beforeTime.add(Calendar.MINUTE, -15);// 15分钟之前的时间
                    Date beforeD = beforeTime.getTime();
                    String time = sdf.format(beforeD);
                    String sql1 = "select * from data_pd_h where   (isupload is null or isupload=0)    and  eqmid ="+rs.getString("id")+" and (d_time<\""+time+"\" or padschalm > 0)  order by d_time asc";
                    pstmt=conn.prepareStatement(sql1);//装载sql语句
                    ResultSet rs1=null;
                    rs1=pstmt.executeQuery();
                    while(rs1.next()){
						try{
                        String sql2 = "select * from warn_cfg where eqmid ="+rs1.getString("eqmid")+"";
                        pstmt=conn.prepareStatement(sql2);//装载sql语句
                        ResultSet rs2=null;
                        rs2=pstmt.executeQuery();
                        String sql3 = "select * from i2relation where eqmid ="+rs1.getString("eqmid");
                        //System.out.println(sql3);
                        pstmt=conn.prepareStatement(sql3);//装载sql语句
                        ResultSet rs3=null;
                        rs3=pstmt.executeQuery();
                        String data[][] = new String[6][2];
                        String timestamp = rs1.getString("d_time");
                        //System.out.println(rs2);
                        while(rs3.next()){
                            if(!rs3.getString("cacid").equals("")){
                                data[0][0] =  rs1.getString("apppadsch");
                                if(rs1.getString("apppadsch")==null)
                                {
                                    data[0][0]="0";
                                }
                                data[1][0] =  rs1.getString("phase");
                                if(rs1.getString("phase")==null)
                                {
                                    data[1][0]="0";
                                }
                                data[2][0] =  rs1.getString("plsnum");
                                if(rs1.getString("plsnum")==null)
                                {
                                    data[2][0]="0";
                                }
                                data[3][0] =  rs1.getString("waveform");
                                if(rs1.getString("waveform")==null)
                                {
                                    data[3][0]="";
                                }
                                data[4][0] =  rs1.getString("padschalm");
                                if(rs1.getString("padschalm")==null)
                                {
                                    data[4][0]="";
                                }
                                data[5][0] =  rs1.getString("padschtype");
                                if(rs1.getString("padschtype")==null)
                                {
                                    data[5][0]="";
                                }
                                if(rs2.next()){
                                    if(rs1.getInt("apppadsch")>rs2.getInt("warnmin2") && rs1.getInt("apppadsch")<rs2.getInt("warnmax2")){
                                        data[0][1] =  "FALSE";
                                    }else{
                                        data[0][1] =  "TRUE";   
                                    }
                                    if(rs1.getInt("phase")>rs2.getInt("warnmin5") && rs1.getInt("phase")<rs2.getInt("warnmax5")){
                                        data[1][1] =  "FALSE";
                                    }else{
                                        data[1][1] =  "TRUE";   
                                    }
                                }else{
                                    data[0][1] =  "FALSE";
                                    data[1][1] =  "FALSE";
                                }
                                data[2][1] =  "FALSE";
                                data[3][1] =  "FALSE";
                                data[4][1] =  "FALSE";
                                data[5][1] =  "FALSE";
                                String cacid = rs3.getString("cacid");
                                String sensorid = rs3.getString("sensorid");
                                String equipmentid = rs3.getString("equipmentid");
                                String phase = rs3.getString("phase");
                                String code=rs3.getString("monitortype");
//                                if(rs1.getString("lmc")=="变压器"||rs1.getString("lmc")=="电抗器"){
//                                    code = "021001";
//                                }else{
//                                    code = "021004";
//                                }
                                xml = GenerateXml.createCACData_pd_h(cacid,sensorid,equipmentid,timestamp,phase,data,code);
                                String str = ucd.getXydlServiceImplPort().uploadCACData(xml);
                                //System.out.println("客户端接受："+str); 
                                TreeMap ret = GenerateXml.xmlElements(str);
                                //System.out.println("客户端接受："+ret);
                                if( Integer.parseInt(ret.get("response.result.code").toString())==0){
                                    String sql4 = "UPDATE data_pd_h SET isupload = 1 WHERE d_time ='"+rs1.getString("d_time")+"' and eqmid='"+rs1.getString("eqmid")+"'";
                                    //System.out.println(sql4);
                                    help.getConnection();
                                    int num = help.excuteUpdate(sql4);
                                    help.getConnection().close();
                                    if(num>0){
                                        String old=jTextArea1.getText();
                                        jTextArea1.append("\n"); 
                                        jTextArea1.setText(old+"传输成功！\n");
                                    }
                                }
                            }
                        }
						        }catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                writeFile("slog/"+getCurrentYYYYMM()+".log", e.getMessage());
        }
                    }
                }
                if(rs.getInt("mtid")==16){//siteqixiang
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    Calendar beforeTime = Calendar.getInstance();
                    beforeTime.add(Calendar.MINUTE, -15);// 15分钟之前的时间
                    Date beforeD = beforeTime.getTime();
                    String time = sdf.format(beforeD);
                    String sql1 = "select * from data_microclimate_h where   (isupload is null or isupload=0) and eqmid ="+rs.getString("id")+" and d_time<\""+time+"\"  order by d_time asc";
                    pstmt=conn.prepareStatement(sql1);//装载sql语句
                    ResultSet rs1=null;
                    rs1=pstmt.executeQuery();
                    while(rs1.next()){
						try{
                        String sql2 = "select * from warn_cfg where eqmid ="+rs1.getString("eqmid")+"";
                        pstmt=conn.prepareStatement(sql2);//装载sql语句
                        ResultSet rs2=null;
                        rs2=pstmt.executeQuery();
                        
                        String sql3 = "select * from i2relation where eqmid ="+rs1.getString("eqmid");
                        //System.out.println(sql3);
                        pstmt=conn.prepareStatement(sql3);//装载sql语句
                        ResultSet rs3=null;
                        rs3=pstmt.executeQuery();
                        String data[][] = new String[8][2];
                        String timestamp = rs1.getString("d_time");
                        //System.out.println(rs2);
                        String okstatus = "";//特殊对应多个sid
                        while(rs3.next()){
                            if(!rs3.getString("cacid").equals("")){
                                data[0][0] =  rs1.getString("envtmp");
                                if(rs1.getString("envtmp")==null)
                                {
                                    data[0][0]="0";
                                }
                                data[1][0] =  String.valueOf(rs1.getFloat("envhum")/100);
                                if(rs1.getString("envhum")==null)
                                {
                                    data[1][0]="0";
                                }
                                data[6][0] =  rs1.getString("wdgustspd");
                                if(rs1.getString("wdgustspd")==null)
                                {
                                    data[6][0]="0";
                                }
                                data[3][0] =  String.valueOf(rs1.getFloat("envpres")/10);
                                if(rs1.getString("envpres")==null)
                                {
                                    data[3][0]="0";
                                }
                                data[7][0] =  rs1.getString("wddir");
                                if(rs1.getString("wddir")==null)
                                {
                                    data[7][0]="0";
                                }
                                data[5][0] =  rs1.getString("rnfll");
                                if(rs1.getString("rnfll")==null)
                                {
                                    data[5][0]="0";
                                }
                                if(rs2.next()){
                                    if(rs1.getInt("envtmp")>rs2.getInt("warnmin1") && rs1.getInt("envtmp")<rs2.getInt("warnmax1")){
                                        data[0][1] =  "FALSE";
                                    }else{
                                        data[0][1] =  "TRUE";   
                                    }
                                    if(rs1.getInt("envhum")>rs2.getInt("warnmin2") && rs1.getInt("envhum")<rs2.getInt("warnmax2")){
                                        data[1][1] =  "FALSE";
                                    }else{
                                        data[1][1] =  "TRUE";   
                                    }
                                    if(rs1.getInt("wdgustspd")>rs2.getInt("warnmin7") && rs1.getInt("wdgustspd")<rs2.getInt("warnmax7")){
                                        data[6][1] =  "FALSE";
                                    }else{
                                        data[6][1] =  "TRUE";   
                                    }
                                    if(rs1.getInt("envpres")>rs2.getInt("warnmin4") && rs1.getInt("envhum")<rs2.getInt("warnmax4")){
                                        data[3][1] =  "FALSE";
                                    }else{
                                        data[3][1] =  "TRUE";   
                                    }
                                    if(rs1.getInt("wddir")>rs2.getInt("warnmin8") && rs1.getInt("wddir")<rs2.getInt("warnmax8")){
                                        data[7][1] =  "FALSE";
                                    }else{
                                        data[7][1] =  "TRUE";   
                                    }
                                    if(rs1.getInt("rnfll")>rs2.getInt("warnmin6") && rs1.getInt("wddir")<rs2.getInt("warnmax6")){
                                        data[5][1] =  "FALSE";
                                    }else{
                                        data[5][1] =  "TRUE";
                                    }
                                }else{
                                    data[0][1] =  "FALSE";
                                    data[1][1] =  "FALSE";
                                    data[2][1] =  "FALSE";
                                    data[3][1] =  "FALSE";
                                    data[4][1] =  "FALSE";
                                    data[5][1] =  "FALSE";
                                    data[6][1] =  "FALSE";
                                    data[7][1] =  "FALSE";
                                }
                                data[4][0]="0";
                                data[2][0]="0";
                                data[2][1] =  "FALSE";
                                data[4][1] =  "FALSE";
                                String cacid = rs3.getString("cacid");
                                String sensorid = rs3.getString("sensorid");
                                String equipmentid = rs3.getString("equipmentid");
                                String phase = rs3.getString("phase");
                                String code=rs3.getString("monitortype");
                                xml = GenerateXml.createCACData_mlh(cacid,sensorid,equipmentid,timestamp,phase,data,code);
                                String str = ucd.getXydlServiceImplPort().uploadCACData(xml);
                                System.out.println("客户端接受："+xml); 
                                TreeMap ret = GenerateXml.xmlElements(str);
                                System.out.println("客户端接受："+ret);
                                if( Integer.parseInt(ret.get("response.result.code").toString())==0){
                                    okstatus="0";
                                }
                            }
                        }
                        if( Integer.parseInt(okstatus)==0){
                            String sql4 = "UPDATE data_microclimate_h SET isupload = 1 WHERE d_time ='"+rs1.getString("d_time")+"' and eqmid='"+rs1.getString("eqmid")+"'";
                            //System.out.println(sql4);
                            help.getConnection();
                            int num = help.excuteUpdate(sql4);
                            help.getConnection().close();
                            if(num>0){
                                String old=jTextArea1.getText();
                                jTextArea1.append("\n"); 
                                jTextArea1.setText(old+"传输成功！\n");
                            }
                        }
						        }catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                writeFile("slog/"+getCurrentYYYYMM()+".log", e.getMessage());
        }
                    }
                }
                if(rs.getInt("mtid")==5){
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    Calendar beforeTime = Calendar.getInstance();
                    beforeTime.add(Calendar.MINUTE, -5);// 5分钟之前的时间
                    Date beforeD = beforeTime.getTime();
                    String time = sdf.format(beforeD);
                    String sql1 = "select * from data_etp_h where   (isupload is null or isupload=0)    and  eqmid ="+rs.getString("id")+"  and d_time<\""+time+"\"  order by d_time asc";
                    pstmt=conn.prepareStatement(sql1);//装载sql语句
                    ResultSet rs1=null;
                    rs1=pstmt.executeQuery();
                    while(rs1.next()){
						try{
                        String sql2 = "select * from warn_cfg where eqmid ="+rs1.getString("eqmid")+"";
                        pstmt=conn.prepareStatement(sql2);//装载sql语句
                        ResultSet rs2=null;
                        rs2=pstmt.executeQuery();
                        String sql3 = "select * from i2relation where eqmid ="+rs1.getString("eqmid");
                        //System.out.println(sql3);
                        pstmt=conn.prepareStatement(sql3);//装载sql语句
                        ResultSet rs3=null;
                        rs3=pstmt.executeQuery();
                        String data[][] = new String[1][2];
                        String timestamp = rs1.getString("d_time");
                        //System.out.println(rs2);
                        Boolean isupload=true;
                        while(rs3.next()){
                            if(!rs3.getString("cacid").equals("")){                                
                                data[0][0] =  rs1.getString("t"+rs3.getString("sensorindex"));
                                /*if(rs1.getFloat("t"+rs3.getString("sensorindex"))==0)
                                {
                                    data[0][0]="0";
                                }*/
                                if(rs1.getString("t"+rs3.getString("sensorindex"))== null)
                                {
                                    data[0][0]="-999";
                                }
                                if(rs2.next()){
                                    if(rs1.getFloat("t"+rs3.getString("sensorindex"))<rs2.getInt("warnmin"+rs3.getString("sensorindex")) || rs1.getFloat("t"+rs3.getString("sensorindex"))>rs2.getInt("warnmax"+rs3.getString("sensorindex"))){
                                        data[0][1] =  "TRUE";
                                    }else{
                                        data[0][1] =  "FALSE";   
                                    }
                                }else{
                                    data[0][1] =  "FALSE";
                                }
                                String cacid = rs3.getString("cacid");
                                String sensorid = rs3.getString("sensorid");
                                String equipmentid = rs3.getString("equipmentid");
                                String phase = rs3.getString("phase");
                                xml = GenerateXml.createCACData_TMT(cacid,sensorid,equipmentid,timestamp,phase,data);
                                System.out.println("xml："+xml);
                                String str = ucd.getXydlServiceImplPort().uploadCACData(xml);
                                System.out.println("客户端接受："+str+xml);
                                TreeMap ret = GenerateXml.xmlElements(str);
                                System.out.println("客户端返回："+ret+xml);
                                if( Integer.parseInt(ret.get("response.result.code").toString())!=0){
                                   isupload=false;
                                }
                            }
                        }
                        
                        if(isupload)
                        {
                            String sql4 = "UPDATE data_etp_h SET isupload = 1 WHERE d_time ='"+rs1.getString("d_time")+"' and eqmid='"+rs1.getString("eqmid")+"'";
                            //System.out.println(sql4);
                            help.getConnection();
                            int num = help.excuteUpdate(sql4);
                            help.getConnection().close();
                            if(num>0){
                                String old=jTextArea1.getText();
                                jTextArea1.append("\n"); 
                                jTextArea1.setText(old+"传输成功！\n"+xml);
                            }
                        }
                               }catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                writeFile("slog/"+getCurrentYYYYMM()+".log", e.getMessage());
        } 
                    }
                }                
//                if(rs.getInt("mtid")==5){
//                    String sql1 = "select * from data_etp_h where   (isupload is null or isupload=0)    and  eqmid ="+rs.getString("id")+" order by d_time asc";
//                    pstmt=conn.prepareStatement(sql1);//装载sql语句
//                    ResultSet rs1=null;
//                    rs1=pstmt.executeQuery();
//                    while(rs1.next()){
//                        String sql2 = "select * from warn_cfg where eqmid ="+rs1.getString("eqmid")+"";
//                        pstmt=conn.prepareStatement(sql2);//装载sql语句
//                        ResultSet rs2=null;
//                        rs2=pstmt.executeQuery();
//                        String sql3 = "select * from i2relation where eqmid ="+rs1.getString("eqmid");
//                        //System.out.println(sql3);
//                        pstmt=conn.prepareStatement(sql3);//装载sql语句
//                        ResultSet rs3=null;
//                        rs3=pstmt.executeQuery();
//                        String data[][] = new String[7][2];
//                        String timestamp = rs1.getString("d_time");
//                        //System.out.println(rs2);
//                        while(rs3.next()){
//                            if(!rs3.getString("cacid").equals("")){
//                                data[0][0] =  rs1.getString("t1");
//                                data[1][0] =  rs1.getString("t2");
//                                data[2][0] =  rs1.getString("t3");
//                                data[3][0] =  rs1.getString("t4");
//                                data[4][0] =  rs1.getString("t5");
//                                data[5][0] =  rs1.getString("t6");
//                                data[6][0] =  rs1.getString("t7");
//                                if(rs2.next()){
//                                    if(rs1.getInt("t1")>rs2.getInt("warnmin1") && rs1.getInt("t1")<rs2.getInt("warnmax1")){
//                                        data[0][1] =  "FALSE";
//                                    }else{
//                                        data[0][1] =  "TRUE";   
//                                    }
//                                    if(rs1.getInt("t2")>rs2.getInt("warnmin2") && rs1.getInt("t2")<rs2.getInt("warnmax2")){
//                                        data[1][1] =  "FALSE";
//                                    }else{
//                                        data[1][1] =  "TRUE";   
//                                    }
//                                    if(rs1.getInt("t3")>rs2.getInt("warnmin3") && rs1.getInt("t3")<rs2.getInt("warnmax3")){
//                                        data[2][1] =  "FALSE";
//                                    }else{
//                                        data[2][1] =  "TRUE";   
//                                    }
//                                    if(rs1.getInt("t4")>rs2.getInt("warnmin4") && rs1.getInt("t4")<rs2.getInt("warnmax4")){
//                                        data[3][1] =  "FALSE";
//                                    }else{
//                                        data[3][1] =  "TRUE";   
//                                    }
//                                     if(rs1.getInt("t5")>rs2.getInt("warnmin5") && rs1.getInt("t5")<rs2.getInt("warnmax5")){
//                                        data[4][1] =  "FALSE";
//                                    }else{
//                                        data[4][1] =  "TRUE";   
//                                    }
//                                    if(rs1.getInt("t6")>rs2.getInt("warnmin6") && rs1.getInt("t6")<rs2.getInt("warnmax6")){
//                                        data[5][1] =  "FALSE";
//                                    }else{
//                                        data[5][1] =  "TRUE";   
//                                    }
//                                     if(rs1.getInt("t7")>rs2.getInt("warnmin7") && rs1.getInt("t7")<rs2.getInt("warnmax7")){
//                                        data[6][1] =  "FALSE";
//                                    }else{
//                                        data[6][1] =  "TRUE";   
//                                    }
//                                }else{
//                                    data[0][1] =  "FALSE";
//                                    data[1][1] =  "FALSE";
//                                    data[2][1] =  "FALSE";
//                                    data[3][1] =  "FALSE";
//                                    data[4][1] =  "FALSE";
//                                    data[5][1] =  "FALSE";
//                                    data[6][1] =  "FALSE";
//                                }
//                                String cacid = rs3.getString("cacid");
//                                String sensorid = rs3.getString("sensorid");
//                                String equipmentid = rs3.getString("equipmentid");
//                                String phase = rs3.getString("phase");
//                                xml = GenerateXml.createCACData_KGG(cacid,sensorid,equipmentid,timestamp,phase,data);
//                                String str = ucd.getXydlServiceImplPort().uploadCACData(xml);
//                                //System.out.println("客户端接受："+str); 
//                                TreeMap ret = GenerateXml.xmlElements(str);
//                                //System.out.println("客户端接受："+ret);
//                                if( Integer.parseInt(ret.get("response.result.code").toString())==0){
//                                    String sql4 = "UPDATE data_etp_h SET isupload = 1 WHERE d_time ='"+rs1.getString("d_time")+"' and eqmid='"+rs1.getString("eqmid")+"'";
//                                    //System.out.println(sql4);
//                                    help.getConnection();
//                                    int num = help.excuteUpdate(sql4);
//                                    if(num>0){
//                                        String old=jTextArea1.getText();
//                                        jTextArea1.append("\n"); 
//                                        jTextArea1.setText(old+"传输成功！\n");
//                                    }
//                                }
//                            }
//                        }
//                    }
//                }
            }
            conn.close();
        }catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                writeFile("slog/"+getCurrentYYYYMM()+".log", e.getMessage());
        }
    }
    /**
     * 
     * @param path
     * path:保存日志文件路径
     * @param content
     * content：日志内容
     */
    public static void writeFile(String path, String content) {
        File writefile;
        try {
        // 通过这个对象来判断是否向文本文件中追加内容
        // boolean addStr = append;
        writefile = new File(path);
        // 如果文本文件不存在则创建它
        if (!writefile.exists()) {
        writefile.createNewFile();
        writefile = new File(path); // 重新实例化
        }

        FileOutputStream fw = new FileOutputStream(writefile,true);
        Writer out = new OutputStreamWriter(fw, "utf-8");
        out.write(content);
        String newline = System.getProperty("line.separator");
        //写入换行  
        out.write(newline);
        out.close();
        fw.flush();
        fw.close();
        } catch (Exception ex) {
        System.out.println(ex.getMessage());
        }
    }

    // 获取当前时间
    public static String getCurrentYYYYMM() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        Calendar beforeTime = Calendar.getInstance();
        Date beforeD = beforeTime.getTime();
        String time = sdf.format(beforeD);
        return time;
    }  
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration//GEN-END:variables
}
