//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.tohi.common.pwdutil;

import com.tohi.app.rest.JdbcUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

public class CustThread extends Thread {
    private Connection con;
    private String strContent;

    public static Connection getDB2Conn() {
        Connection conn = null;

        try {
            conn = JdbcUtil.getConn();
        } catch (Exception var2) {
            var2.printStackTrace();
        }

        return conn;
    }

    public CustThread(String strContent) {
        this.strContent = strContent;
        this.con = getDB2Conn();
    }

    public void run() {
        ResultSet rst = null;
        PreparedStatement pst = null;
        ResultSet rst1 = null;
        PreparedStatement pst1 = null;
        ResultSet rst2 = null;
        PreparedStatement pst2 = null;
        ResultSet rst3 = null;
        PreparedStatement pst3 = null;
        ResultSet rst4 = null;
        PreparedStatement pst4 = null;

        try {
            System.out.println("========================44");
            int beg = this.strContent.indexOf("&US_CODE");
//            int end = this.strContent.indexOf("&UpdateDate");
            int end = this.strContent.indexOf("&callback");
            String userid = this.strContent.substring(beg, end);
            List<String[]> list = new ArrayList();
            Integer result = 0;
            int endIndex = 0;
             endIndex = this.strContent.lastIndexOf("&Company_ID");
            this.strContent = this.strContent.substring(0, endIndex);
            String[] strs = this.strContent.split(";");
            if (strs != null) {
                String[] var21 = strs;
                int var20 = strs.length;

                for(int var19 = 0; var19 < var20; ++var19) {
                    String str = var21[var19];
                    String[] test = str.split("\\^");
                    list.add(test);
                }

                List<String> listsql = new ArrayList();
                List<String> upqy = new ArrayList();
                int d = 0;
                int i = 1;
                int m = 0;
                String id = "";
                String US_CODE = userid.substring(9, userid.length());
                List<String> listqy = new ArrayList();
                String qyid = null;
                new SimpleDateFormat("yyyy-MM-dd");
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(new Date());
                calendar.add(5, -1);
                Date datej = calendar.getTime();
                String imid = null;
                String imsql = null;
                String zt = null;
                String itemsql = null;
                String qfsql = null;
                String qfsql1 = null;

                String sql;
                String sqlx;
                for(Iterator var37 = list.iterator(); var37.hasNext(); ++i) {
                    String[] str = (String[])var37.next();
                    if (i == 1) {
                        id = str[0].replaceAll("strContent=", "");
                        str[0] = id;
                    }

                    if ("9008081".equalsIgnoreCase(str[0])) {
                        d = 0;
                        result = 1;
                    }

                    System.out.println("str[6]================" + str[6]);
                    if ("点检".equalsIgnoreCase(str[6])) {
                        qfsql = " PI_TASK_ITEMID='" + str[0] + "'";
                        qfsql1 = " b.PI_TASK_ITEMID='" + str[0] + "'";
                    } else {
                        qfsql = " NUM='" + str[0] + "' and BEGIN_TIME<=to_date('" + str[3] + "','yyyy-mm-dd hh24:mi:ss')" + " and END_TIME >=to_date('" + str[3] + "','yyyy-mm-dd hh24:mi:ss')";
                        qfsql1 = " b.NUM='" + str[0] + "' and b.BEGIN_TIME<=to_date('" + str[3] + "','yyyy-mm-dd hh24:mi:ss')" + " and b.END_TIME >=to_date('" + str[3] + "','yyyy-mm-dd hh24:mi:ss')";
                    }

                    sql = "update PI_TASK_ITEM  set XJPERSONID='" + str[8] + "', PI_TASK_ITEM_RESULT='" + str[2] + "', PI_TASK_TIME=to_date('" + str[3] + "','yyyy-mm-dd hh24:mi:ss'), REMARK='" + str[4] + "' where " + " " + qfsql;
                    if (!"".equalsIgnoreCase(str[0]) && str[0] != null) {
                        itemsql = "select PI_TASK_ITEM_RESULT,PI_TASK_ITEMID ,pi_task_no,(select PI_TASK_AREAid from  PI_TASK_AREA where num in(select PI_TASK_area_no from PI_TASK_DEVICE where  pi_task_no=PI_TASK_ITEM.pi_task_no  and num=PI_TASK_ITEM.PI_TASK_device_no and pi_task_area_no=PI_TASK_ITEM.pi_task_area_no) and pi_task_no=PI_TASK_ITEM.pi_task_no  ) qyid  from PI_TASK_ITEM where " + qfsql;
                        System.out.println("139:" + itemsql);
                        pst4 = this.con.prepareStatement(itemsql);
                        rst4 = pst4.executeQuery();
                        if (rst4.next()) {
                            if (!"正常".equalsIgnoreCase(str[2])) {
                                if (imid == null) {
                                    imid = "'" + rst4.getString("PI_TASK_ITEMID") + "'";
                                } else {
                                    imid = imid + ",'" + rst4.getString("PI_TASK_ITEMID") + "'";
                                }
                            }

                            listqy.add(rst4.getString("qyid"));
                        }

                        if (rst4 != null) {
                            rst4.close();
                        }

                        if (pst4 != null) {
                            pst4.close();
                        }
                    }

                    System.out.println("sql556:" + sql);
                    if (str[0] != null && str[0] != "") {
                        m = 0;
                    }

                    System.out.println(str[4] + "============581============" + str[7]);
                    sqlx = " update PI_TASK_AREA a set UDSFSM=" + str[7] + " where exists (select 1 from PI_TASK_ITEM b where a.pi_task_no=b.pi_task_no " + " and a.num=b.PI_TASK_AREA_no and " + qfsql1 + " )";
                    System.out.println("584:" + sqlx);
                    listsql.add(sql);
                    if ("1".equals(str[5])) {
                        zt = "运行";
                    } else if ("2".equals(str[5])) {
                        zt = "检修";
                    } else if ("3".equals(str[5])) {
                        zt = "备用(巡检)";
                    } else if ("4".equals(str[5])) {
                        zt = "备用";
                    } else if ("5".equals(str[5])) {
                        zt = "停运";
                    }

                    sql = "  update PI_TASK_DEVICE a set ON_OFF_POTIN='" + zt + "' where exists (select 1 from PI_TASK_ITEM b where a.pi_task_no=b.pi_task_no " + " and a.num=b.PI_TASK_device_no  and a.PI_area_no=b.PI_TASK_area_no and " + qfsql1 + " ) ";
                    listsql.add(sql);
                    listsql.add(sqlx);
                }

                String ctj;
                if (i > 1 && d==0) {
                    HashSet<String> h = new HashSet(listqy);
                    listqy.clear();
                    listqy.addAll(h);

                    for(int j = 0; j < listqy.size(); ++j) {
                        if (j == 0) {
                            qyid = "'" + (String)listqy.get(j) + "'";
                        } else {
                            qyid = qyid + ",'" + (String)listqy.get(j) + "'";
                        }
                    }

                    ctj = "update  PI_TASK_AREA set IS_UPLOAD=1,SCPERSON='" + US_CODE + "',SCDATE= CURRENT_DATE," + " SCANTIME=(select to_date(to_char(min(PI_TASK_TIME),'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss') sj  from PI_TASK_ITEM where " + "  PI_TASK_TIME is not null and pi_task_no=PI_TASK_AREA.pi_task_no and PI_TASK_DEVICE_no in(" + "  select NUM from PI_TASK_DEVICE where  ON_OFF_POTIN in('运行','检修','备用(巡检)') and pi_task_no=PI_TASK_AREA.pi_task_no  ))" + "  where PI_TASK_AREAID in(" + qyid + ")";
                    listsql.add(ctj);
                }

                if (d==0) {
                    System.out.println("207---" + listsql.size());
                    this.executeUpdateqy(listsql);
                }

                if (i > 1 && d==0) {
                    try {
                         sql = " select PI_TASK_NO,(select IGNORE_POINT from PI_TASK where num=PI_TASK_AREA.PI_TASK_NO) xjs from  PI_TASK_AREA where IS_UPLOAD=1 and  PI_TASK_AREAID in(" + qyid + ") group by PI_TASK_NO";
                        System.out.println("561sql:----" + sql);
                        pst1 = this.con.prepareStatement(sql);
                        rst1 = pst1.executeQuery();
                        ctj = "";

                        label773:
                        while(true) {
                            do {
                                do {
                                    if (!rst1.next()) {
                                        break label773;
                                    }
                                } while(rst1.getString("PI_TASK_NO") == null);
                            } while("".equalsIgnoreCase(rst1.getString("PI_TASK_NO")));

                            sql = " select a.qyz,b.yjd,c.kjd,(select count(*) tj from PI_TASK_DEVICE where pi_task_no = a.PI_TASK_NO  and ON_OFF_POTIN in('备用','停运')) tj, (select count(*) from PI_TASK_ITEM where PI_TASK_DEVICE_no in(  select num from PI_TASK_DEVICE where pi_task_no = a.PI_TASK_NO  and ON_OFF_POTIN in('备用','停运')) and pi_task_no =a.PI_TASK_NO ) tjx,  (select count(t.pi_task_no) lj from  PI_TASK_ITEM  t where t.pi_task_no='" + rst1.getString("PI_TASK_NO") + "' and " + "  PI_TASK_DEVICE_no in(select NUM from  PI_TASK_DEVICE  t where t.pi_task_no='" + rst1.getString("PI_TASK_NO") + "'" + " and ON_OFF_POTIN in('运行','检修','备用(巡检)'))  and PI_TASK_ITEM_RESULT is null) lj," + "  (select count(*) yj from ( select t.PI_TASK_ITEMid  from  PI_TASK_ITEM  t " + "    where t.pi_task_no='" + rst1.getString("PI_TASK_NO") + "' " + " and  PI_TASK_DEVICE_no in(select NUM from  PI_TASK_DEVICE  t where t.pi_task_no='" + rst1.getString("PI_TASK_NO") + "' and ON_OFF_POTIN in('运行','检修','备用(巡检)'))  " + " and (PI_TASK_ITEM_RESULT like '%异常%' or PI_TASK_ITEM_RESULT like '%轻微%'   or PI_TASK_ITEM_RESULT like '%严重%' )" + "  union all" + " select t.PI_TASK_ITEMid  from PI_TASK_ITEM   t " + "  where t.pi_task_no='" + rst1.getString("PI_TASK_NO") + "' and  POINT_TYPE='JS' and PI_TASK_ITEM_RESULT is not null " + " and  PI_TASK_ITEM_RESULT!='正常'  and  PI_TASK_DEVICE_no in(select NUM from  PI_TASK_DEVICE  t where t.pi_task_no='" + rst1.getString("PI_TASK_NO") + "' and ON_OFF_POTIN in('运行','检修','备用(巡检)')) " + " and (nvl(PI_TASK_ITEM_RESULT,0)>nvl(HIGHER_LIMIT,0) or nvl(PI_TASK_ITEM_RESULT,0)<nvl(LOWER_LIMIT,0))) a) yc" + " from  (select count(*) qyz,max(PI_TASK_NO) PI_TASK_NO   from PI_TASK_AREA " + "  where PI_TASK_NO='" + rst1.getString("PI_TASK_NO") + "'  and IS_UPLOAD=1) a left join " + " (select count(*) yjd ,max(PI_TASK_NO) PI_TASK_NO from PI_TASK_DEVICE where NUM in(" + " select pi_AREA_DEVICE_NO from PI_TASK_ITEM where pi_task_no = '" + rst1.getString("PI_TASK_NO") + "' " + " and PI_TASK_ITEM_RESULT is not null  group by pi_AREA_DEVICE_NO) and PI_TASK_NO='" + rst1.getString("PI_TASK_NO") + "'" + "  and  NUM in(select NUM from  PI_TASK_DEVICE  t where t.pi_task_no='" + rst1.getString("PI_TASK_NO") + "' and ON_OFF_POTIN in('运行','检修','备用(巡检)')) " + ") b on a.PI_TASK_NO=b.PI_TASK_NO" + "  left join  (select count(*) kjd,max(PI_TASK_NO) pi_task_no  from PI_TASK_DEVICE where PI_TASK_NO='" + rst1.getString("PI_TASK_NO") + "'" + " and NUM not in(select pi_AREA_DEVICE_NO from PI_TASK_ITEM where pi_task_no = '" + rst1.getString("PI_TASK_NO") + "' " + "  group by pi_AREA_DEVICE_NO)) c on a.PI_TASK_NO=c.PI_TASK_NO";
                            System.out.println("233====" + sql);
                            pst2 = this.con.prepareStatement(sql);
                            rst2 = pst2.executeQuery();

                            while(rst2.next()) {
                                ctj = ",MISSED_RATE=trunc(to_number(cast(" + rst2.getInt("lj") + " as float)/(IGNORE_POINT-" + rst2.getInt("tjx") + ")*100),0) " + " ,PI_RATE =trunc(to_number(cast(" + (rst2.getInt("yjd") + rst2.getInt("kjd")) + " as float)/(NORM_POINT-" + rst2.getInt("tj") + ")*100),0)";
                                if (rst1.getInt("xjs") == rst2.getInt("tjx")) {
                                    ctj = " ,MISSED_RATE=0,PI_RATE =100 ";
                                }

                                sqlx = "update PI_TASK set status='已上传结果' ,REAL_AREA=" + rst2.getInt("qyz") + ",IN_PLACE_RATE =trunc(to_number(cast(" + rst2.getInt("qyz") + " as float)/NORM_AREA*100),0),CHANGEBY='" + US_CODE + "' " + " ,REAL_POINT=" + (rst2.getInt("yjd") + rst2.getInt("kjd")) + " ,TJ_POINT='" + rst2.getInt("tj") + "'," + " TJX='" + rst2.getInt("tjx") + "'," + " YCD='" + rst2.getString("yc") + "',MISSED_POINT='" + rst2.getString("lj") + "' " + " " + ctj + "  where num='" + rst1.getString("PI_TASK_NO") + "'";
                                System.out.println("632===" + sqlx);
                                upqy.add(sqlx);
                                sqlx = "  update PI_TASK_DEVICE set SCANTIME=(select to_date(to_char(min(PI_TASK_TIME),'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss') sj  from PI_TASK_ITEM where   PI_TASK_TIME is not null and pi_task_no=PI_TASK_DEVICE.pi_task_no and PI_TASK_DEVICE_no=PI_TASK_DEVICE.num)  where   ON_OFF_POTIN in('运行','检修','备用(巡检)')  and pi_task_no='" + rst1.getString("PI_TASK_NO") + "'" + "   and num in(select pi_task_device_no from PI_TASK_ITEM where   PI_TASK_TIME is not null and pi_task_no='" + rst1.getString("PI_TASK_NO") + "')";
                                upqy.add(sqlx);
                                System.out.println("664===" + sqlx);
                                this.executeUpdate(upqy);
                                upqy.clear();
                            }

                            if (rst2 != null) {
                                rst2.close();
                            }

                            if (pst2 != null) {
                                pst2.close();
                            }
                        }
                    } catch (Exception var62) {
                        this.closeAll(this.con, (PreparedStatement)pst, (ResultSet)rst);
                        this.closeAll((Connection)null, pst1, rst1);
                        this.closeAll((Connection)null, pst2, rst2);
                        this.closeAll((Connection)null, pst4, rst4);
                        var62.printStackTrace();
                    } finally {
                        this.closeAll(this.con, (PreparedStatement)pst, (ResultSet)rst);
                        this.closeAll((Connection)null, pst1, rst1);
                        this.closeAll((Connection)null, pst2, rst2);
                        this.closeAll((Connection)null, pst4, rst4);
                    }

                    imsql = " select t.PI_TASK_ITEMid,t.PI_TASK_no,'部件名称:'||t.DEVICE_PART_NAME ||',巡检描述:'||t.PI_ITEM_DESCRIPTION||',巡检结果：'||t.PI_TASK_ITEM_RESULT as ms, t.PI_TASK_DEVICE_no,(select LOCATION from PI_TASK_DEVICE where NUM=t.PI_TASK_DEVICE_no and rownum=1) location  from  PI_TASK_ITEM  t   where t.PI_TASK_ITEMID in(" + imid + ") " + " and PI_TASK_DEVICE_no in(select NUM from  PI_TASK_DEVICE  t where t.pi_task_no in(select pi_task_no from PI_TASK_ITEM where PI_TASK_ITEMID in(" + imid + "))  and ON_OFF_POTIN in('运行','检修','备用(巡检)'))" + " and (PI_TASK_ITEM_RESULT like '%异常%' or PI_TASK_ITEM_RESULT like '%轻微%' " + "  or PI_TASK_ITEM_RESULT like '%严重%' ) " + " union all" + "  select t.PI_TASK_ITEMid,t.PI_TASK_no,'部件名称:'||t.DEVICE_PART_NAME ||',巡检描述:'||t.PI_ITEM_DESCRIPTION||',上限值:'||t.HIGHER_LIMIT||',下限值:'||t.LOWER_LIMIT||',巡检结果：'||t.PI_TASK_ITEM_RESULT as ms," + "  t.PI_TASK_DEVICE_no,(select LOCATION from PI_TASK_DEVICE where NUM=t.PI_TASK_DEVICE_no and rownum=1) location  from PI_TASK_ITEM   t " + "  where t.PI_TASK_ITEMID in(" + imid + ") and  POINT_TYPE='JS' and  PI_TASK_ITEM_RESULT!='正常' and PI_TASK_ITEM_RESULT is not null and " + "  PI_TASK_DEVICE_no in(select NUM from  PI_TASK_DEVICE  t where t.pi_task_no in(select pi_task_no from PI_TASK_ITEM where PI_TASK_ITEMID in(" + imid + "))  and ON_OFF_POTIN in('运行','检修','备用(巡检)'))" + " and HIGHER_LIMIT is not null and LOWER_LIMIT  is not null   and (nvl(PI_TASK_ITEM_RESULT,0)>nvl(HIGHER_LIMIT,0) or nvl(PI_TASK_ITEM_RESULT,0)<nvl(LOWER_LIMIT,0))";
                    System.out.println("634====" + imsql);

                    try {
                        this.con = JdbcUtil.getConn();
                        pst3 = this.con.prepareStatement(imsql);
                        rst3 = pst3.executeQuery();
                        int mm = 0;

                        for(ctj = ""; rst3.next(); mm = 1) {
                            ctj = " insert into udbug (UDBUGID, DESCRIPTION, ORGID, SITEID, HASLD, APPTYPE, ASSETNUM, BUGLEVEL, BUGMEMO, BUGNUM, BUGTYPE, CHANGEBY, CHANGEDATE, COMPDATE, FINBZ, FINDBY, FINDDEPT, FINDTIME, HISTORYFLAG, LEAD, LOCATION, LONGDESC, PLANYSTIME, PROCESSMEMO, PROCESSMODE, REPORTBY, REPORTDEPT, REPORTTIME, STATUS, STATUSDATE, STATUSDESC, UDBUGNUM, WONUM, UDTASKNUM) values (UDBUGIDSEQ.NEXTVAL, null, 'YXHBDC', 'YXDC', 0, 'SBUG', null, null, null, null, null, '" + US_CODE + "'," + " sysdate, null, null, null, null, null, 0, null, '" + rst3.getString("location") + "', '" + rst3.getString("ms") + "'," + " null, null, null, '" + US_CODE + "', (select DEPARTMENT from PERSON where PERSONID='" + US_CODE + "'), sysdate," + " 'DRAFT',sysdate, '草稿', (select seed+1 sd from AUTOKEY where AUTOKEYNAME='UDBUGNUMS' and orgid='YXHBDC'), null, '" + rst3.getString("PI_TASK_ITEMid") + "')";
                            System.out.println("==============648==" + ctj);
                            upqy.add(ctj);
                            ctj = " update AUTOKEY set seed=seed+1 where AUTOKEYNAME='UDBUGNUMS' and orgid='YXHBDC'";
                            System.out.println("==============648==" + ctj);
                            upqy.add(ctj);
                        }

                        if (mm > 0) {
                            this.executeUpdate(upqy);
                        }
                    } catch (SQLException var60) {
                        this.closeAll(this.con, pst3, rst3);
                        var60.printStackTrace();
                    } finally {
                        this.closeAll(this.con, pst3, rst3);
                    }
                }

                System.out.println(result + "===============result==========291Thread=======");
            }
        } catch (Exception var64) {
            this.closeAll(this.con, (PreparedStatement)null, (ResultSet)null);
            this.closeAll((Connection)null, pst1, rst1);
            this.closeAll((Connection)null, pst2, rst2);
            this.closeAll((Connection)null, pst3, rst3);
            this.closeAll((Connection)null, pst4, rst4);
            var64.printStackTrace();
        } finally {
            this.closeAll(this.con, (PreparedStatement)null, (ResultSet)null);
            this.closeAll((Connection)null, pst1, rst1);
            this.closeAll((Connection)null, pst2, rst2);
            this.closeAll((Connection)null, pst3, rst3);
            this.closeAll((Connection)null, pst4, rst4);
        }

    }

    public Integer executeUpdate(List<String> Listsql) {
        Integer result = -1;
        Statement pst = null;

        try {
            pst = this.con.createStatement();

            String sql;
            for(Iterator var5 = Listsql.iterator(); var5.hasNext(); result = pst.executeUpdate(sql)) {
                sql = (String)var5.next();
            }
        } catch (SQLException var16) {
            result = -1;

            try {
                if (pst != null) {
                    pst.close();
                }

                if (this.con != null) {
                    this.con.close();
                }
            } catch (SQLException var15) {
                var15.printStackTrace();
            }

            var16.printStackTrace();
        } finally {
            try {
                if (pst != null) {
                    pst.close();
                }
            } catch (SQLException var14) {
                var14.printStackTrace();
            }

        }

        return result;
    }

    public Integer executeUpdateqy(List<String> Listsql) {
        Integer result = -1;
        Statement pst = null;

        try {
            pst = this.con.createStatement();

            String sql;
            for(Iterator var5 = Listsql.iterator(); var5.hasNext(); result = pst.executeUpdate(sql)) {
                sql = (String)var5.next();
            }
        } catch (SQLException var16) {
            result = -1;
            var16.printStackTrace();

            try {
                if (pst != null) {
                    pst.close();
                }

                if (this.con != null) {
                    this.con.close();
                }
            } catch (SQLException var15) {
                var15.printStackTrace();
            }
        } finally {
            try {
                if (pst != null) {
                    pst.close();
                }
            } catch (SQLException var14) {
                var14.printStackTrace();
            }

        }

        return result;
    }

    private void closeAll(Connection con, PreparedStatement pst, ResultSet rst) {
        try {
            if (rst != null) {
                rst.close();
            }

            if (pst != null) {
                pst.close();
            }

            if (con != null) {
                con.close();
            }
        } catch (SQLException var5) {
            var5.printStackTrace();
        }

    }
}
