//
// 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 com.tohi.common.dto.*;

import java.io.*;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.activation.DataHandler;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.MediaType;

import net.sf.json.JSONObject;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.json.JSONArray;


public class dbhelpers {
    private Connection con = getDB2Conn();
    private SimpleDateFormat ymd = new SimpleDateFormat("yyyy-MM-dd");
    private SimpleDateFormat hms = new SimpleDateFormat("HH:mm:ss");
    private Date today = new Date();
    private int sl = 0;
    private int xt = 0;
    private String pzbh = null;
    private String zqbh = null;
    private String rwbh = null;
    private String qybh = null;
    private List<String> bhlist = new ArrayList();

    public void setCon(Connection con) {
        this.con = con;
    }

    public dbhelpers() {
    }

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

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

        return conn;
    }

    public List<Map<String,String>>  selectItemPicture(String taskNum,String itemNum){

        ResultSet rst = null;
        PreparedStatement pst = null;
        ArrayList list = new ArrayList();
        String sql = "SELECT df.DOCUMENT as FILENUM,df.DESCRIPTION as FILENAME FROM (SELECT * FROM DOCLINKS " +
                "WHERE OWNERTABLE = 'PI_TASK_ITEM' AND OWNERID IN (SELECT PI_TASK_ITEMID FROM PI_TASK_ITEM where " +
                "PI_TASK_NO ='"+taskNum+"' and NUM = '"+itemNum+"'))dl LEFT JOIN DOCINFO df on dl.DOCINFOID = df.DOCINFOID";
        try {
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }
            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();
            while (rst.next()){
               Map<String,String> map =  new HashMap();
               map.put("FILENUM",rst.getString("FILENUM"));
               map.put("FILENAME",rst.getString("FILENAME"));
               list.add(map);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            this.closeAll(this.con, pst, rst);
        }
        return list;
    }

    //根据任务编号和巡检项编号查询
    public PI_TASK_ITEM selectItemDetail(String taskNum,String itemNum){
        PI_TASK_ITEM pi_task_item = new PI_TASK_ITEM();
        ResultSet rst = null;
        PreparedStatement pst = null;
        String sql ="SELECT p.NUM,p.DEVICE_PART_NAME,p.PI_ITEM_DESCRIPTION,p.POINT_NORM,p.CHECK_METHOD,p.HIGHER_LIMIT,p.LOWER_LIMIT," +
                "p.POINT_TYPE,p.PI_TASK_ITEM_RESULT,p.DOUBLERET,p.XJPERSONID,p.PI_TASK_TIME,p.PI_TASK_NO,p.STATUS,p.REMARK,q.TASK_NAME, " +
                "a.DESCRIPTION as ASSETNAME FROM (SELECT * FROM PI_TASK_ITEM where PI_TASK_NO ='"+taskNum+"' and NUM = '"+itemNum+"')p " +
                "LEFT JOIN PI_TASK q on p.PI_TASK_NO = q.NUM "+
                "LEFT JOIN PI_TASK_DEVICE d on p.PI_TASK_NO = d.PI_TASK_NO and d.NUM = p.PI_AREA_DEVICE_NO and d.PI_TASK_AREA_NO = p.PI_TASK_AREA_NO "+
                "LEFT JOIN ASSET a on d.ASSETNUM = a.ASSETNUM and a.SITEID = d.SITEID ";
            try {
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }
            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();
            while (rst.next()){
                pi_task_item.setNUM(rst.getString("NUM"));
                pi_task_item.setDEVICE_PART_NAME(rst.getString("DEVICE_PART_NAME"));
                pi_task_item.setPI_ITEM_DESCRIPTION(rst.getString("PI_ITEM_DESCRIPTION"));
                pi_task_item.setPOINT_NORM(rst.getString("POINT_NORM"));
                pi_task_item.setCHECK_METHOD(rst.getString("CHECK_METHOD"));
                pi_task_item.setPOINT_TYPE(rst.getString("POINT_TYPE"));
                pi_task_item.setPI_TASK_ITEM_RESULT(rst.getString("PI_TASK_ITEM_RESULT"));
                pi_task_item.setDOUBLERET(rst.getString("DOUBLERET"));
                pi_task_item.setXJPERSONID(rst.getString("XJPERSONID"));
                pi_task_item.setSTATUS(rst.getString("STATUS"));
                pi_task_item.setHIGHER_LIMIT(rst.getString("HIGHER_LIMIT"));
                pi_task_item.setLOWER_LIMIT(rst.getString("LOWER_LIMIT"));
                pi_task_item.setPI_TASK_NO(rst.getString("PI_TASK_NO"));
                pi_task_item.setPI_TASK_TIME(rst.getString("PI_TASK_TIME")==null?null :rst.getString("PI_TASK_TIME").replace(":00.0",":00"));
                pi_task_item.setREMARK(rst.getString("REMARK"));
                pi_task_item.setTASK_NAME(rst.getString("TASK_NAME"));
                pi_task_item.setASSETNAME(rst.getString("ASSETNAME"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            this.closeAll(this.con, pst, rst);
        }
        return pi_task_item;
    }

    //上传打卡图片
    public String uploadPunchCardImg(String useCode,String taskNum,String cardId,String IsiOS,Attachment img){
        String r = "成功";
        ArrayList sqls = new ArrayList();
        if(IsiOS==null || "".equals(IsiOS)){
            return "失败";
        }
        if(cardId==null || "".equals(cardId)){
            return "失败";
        }
        if(taskNum==null || "".equals(taskNum)){
            return "失败";
        }

        //IsiOS为0，手机为安卓系统，cardId为nfcId;   IsiOS为1，手机为iOS系统，cardId为区域编号;
       String  areaNum = this.getAreaNumByCardId(cardId,IsiOS);
        if (areaNum == null || "".equals(areaNum)) {
            return "失败:找不到区域号";
        }

        if(img!=null){
            //上传图片
            DataHandler dh = img.getDataHandler();
            MediaType ct = img.getContentType();//文件类型
            //D:\DOCLINKS\ATTACHMENTS\
            String filepath = JdbcUtil.doc;//文件路径
            Date date = new Date();
            SimpleDateFormat fileDate = new SimpleDateFormat("yyyyMMddHHmmss");
            String filename = areaNum+fileDate.format(date)+"."+ct.toString().split("/")[1];//文件名
            String fileURL = filepath+"\\"+filename;//文件链接

            try {
                this.writeFile(dh,filepath,filename);
            } catch (IOException e) {
                e.printStackTrace();
            }
            //把图片存进附件表
            String rowCount = this.selectDOCINFOSEQ();
            String DOCUMENT = "XJ" + rowCount;

            //更新区域的状态并保存打卡图片路径
        String updateAreaStatus = "update pi_task_area set URLNAME = '"+filename+"' " +
                "where num =  '"+areaNum+"' and pi_task_no = '"+taskNum+"'" ;
        sqls.add(updateAreaStatus);

            String insertToDoc = " insert into DOCINFO (DOCUMENT, DESCRIPTION, APPLICATION, STATUS, STATUSDATE, CREATEDATE, " +
                    "REVISION, CHANGEBY, CHANGEDATE, DOCLOCATION, DOCTYPE, CREATEBY, URLTYPE, DMSNAME, URLNAME, URLPARAM1, " +
                    "URLPARAM2, URLPARAM3, URLPARAM4, URLPARAM5, PRINTTHRULINKDFLT, USEDEFAULTFILEPATH, SHOW,  DOCINFOID, " +
                    "LANGCODE, HASLD, CONTENTUID) values ('" + DOCUMENT + "', '" +filename+ "', null, null, null, sysdate, " +
                    "null, '" + useCode + "',sysdate, null, 'Attachments', '" + useCode + "', '文件', null," + " '" + fileURL + "'," +
                    " null, null, null, null, null, 1, 0, 0, " + rowCount + ", 'ZH', 0, '" + rowCount + "')";
            sqls.add(insertToDoc);//插入数据到DOCINFO

            String insertToDocs = " insert into DOCLINKS (DOCUMENT, OWNERTABLE, OWNERID, REFERENCE, DOCTYPE, DOCVERSION, " +
                    "GETLATESTVERSION,  CREATEBY, CREATEDATE, CHANGEBY, CHANGEDATE, PRINTTHRULINK, COPYLINKTOWO, DOCLINKSID," +
                    " DOCINFOID) values ('" + DOCUMENT + "', 'PI_TASK_AREA', (select PI_TASK_AREAID from PI_TASK_AREA " +
                    "where PI_TASK_NO = '"+taskNum+"' and NUM = '"+areaNum+"'), null, 'Attachments', null, 1, '" + useCode + "', " +
                    "sysdate, '" + useCode + "', sysdate, 1, 0, DOCLINKSSEQ.NEXTVAL, " + rowCount + ")";
            sqls.add(insertToDocs);//插入数据到DOCLINKS
        }
        try {
            JdbcUtil.executeBatch(sqls);
        } catch (RemoteException e) {
            e.printStackTrace();
            return "失败";
        } catch (SQLException e) {
            e.printStackTrace();
            return "失败";
        }
        return r;
    }

    //上传巡检项图片
    public String uploadItemImg(String useCode,String taskNum,String itemNum,Attachment img){
        String r = "成功";
        ArrayList sqls = new ArrayList();
        if(itemNum==null || "".equals(itemNum)){
            return "失败";
        }
        if(taskNum==null || "".equals(taskNum)){
            return "失败";
        }
        if(img!=null){
            //上传图片
            DataHandler dh = img.getDataHandler();
            MediaType ct = img.getContentType();//文件类型
            //D:\DOCLINKS\ATTACHMENTS\
            String filepath = JdbcUtil.doc;//文件路径
            Date date = new Date();
            SimpleDateFormat fileDate = new SimpleDateFormat("yyyyMMddHHmmss");
            String filename = itemNum+fileDate.format(date)+"."+ct.toString().split("/")[1];//文件名
            String fileURL = filepath+"\\"+filename;//文件链接

            try {
                this.writeFile(dh,filepath,filename);
            } catch (IOException e) {
                e.printStackTrace();
            }
            //把图片存进附件表
            String rowCount = this.selectDOCINFOSEQ();
            String DOCUMENT = "XJ" + rowCount;
            String insertToDoc = " insert into DOCINFO (DOCUMENT, DESCRIPTION, APPLICATION, STATUS, STATUSDATE, CREATEDATE, " +
                    "REVISION, CHANGEBY, CHANGEDATE, DOCLOCATION, DOCTYPE, CREATEBY, URLTYPE, DMSNAME, URLNAME, URLPARAM1, " +
                    "URLPARAM2, URLPARAM3, URLPARAM4, URLPARAM5, PRINTTHRULINKDFLT, USEDEFAULTFILEPATH, SHOW,  DOCINFOID, " +
                    "LANGCODE, HASLD, CONTENTUID) values ('" + DOCUMENT + "', '" +filename+ "', null, null, null, sysdate, " +
                    "null, '" + useCode + "',sysdate, null, 'Attachments', '" + useCode + "', '文件', null," + " '" + fileURL + "'," +
                    " null, null, null, null, null, 1, 0, 0, " + rowCount + ", 'ZH', 0, '" + rowCount + "')";

            String insertToDocs = " insert into DOCLINKS (DOCUMENT, OWNERTABLE, OWNERID, REFERENCE, DOCTYPE, DOCVERSION, " +
                    "GETLATESTVERSION,  CREATEBY, CREATEDATE, CHANGEBY, CHANGEDATE, PRINTTHRULINK, COPYLINKTOWO, DOCLINKSID," +
                    " DOCINFOID) values ('" + DOCUMENT + "', 'PI_TASK_ITEM', (select PI_TASK_ITEMID from PI_TASK_ITEM " +
                    "where PI_TASK_NO = '"+taskNum+"' and NUM = '"+itemNum+"'), null, 'Attachments', null, 1, '" + useCode + "', " +
                    "sysdate, '" + useCode + "', sysdate, 1, 0, DOCLINKSSEQ.NEXTVAL, " + rowCount + ")";
            sqls.add(insertToDoc);//插入数据到DOCINFO
            sqls.add(insertToDocs);//插入数据到DOCLINKS
        }
        try {
            JdbcUtil.executeBatch(sqls);
        } catch (RemoteException e) {
            e.printStackTrace();
            return "失败";
        } catch (SQLException e) {
            e.printStackTrace();
            return "失败";
        }
        return r;
    }
    //巡检结果保存，需要进入巡检项详情，保存检测结果
    public String updateItem(String useCode,String taskNum,String itemNum,String result,String valueResult,String remark){
        String r = "成功";
        ArrayList sqls = new ArrayList();
        if(itemNum==null || "".equals(itemNum)){
            return "失败";
        }
        if(taskNum==null || "".equals(taskNum)){
            return "失败";
        }
        //上传巡检结果
        HashMap<String,String> itemMap = new HashMap();
        if(result==null || "".equals(result)){
            return "失败";
        }
        itemMap.put("XJPERSONID",useCode);
        itemMap.put("PI_TASK_TIME","isSentence:sysdate");
        itemMap.put("PI_TASK_ITEM_RESULT",result);
        if(valueResult!=null && !"".equals(valueResult)){
            itemMap.put("DOUBLERET",valueResult);
        }
        if(remark!=null && !"".equals(remark)){
            itemMap.put("REMARK",remark);
        }
        String updateItemWhere = " where pi_task_no='"+taskNum+"' and num='"+itemNum+"'";
        String updateItem = JdbcUtil.updateSentence(itemMap,"PI_TASK_ITEM",updateItemWhere);
        sqls.add(updateItem);
        try {
            JdbcUtil.executeBatch(sqls);
        } catch (RemoteException e) {
            e.printStackTrace();
            return "失败";
        } catch (SQLException e) {
            e.printStackTrace();
            return "失败";
        }
        return r;
    }
    //保存：如果巡检项需要抄表的内容都不为空，保存成功;否则返回未抄表的巡检项列表
    public List<PI_TASK_ITEM> saveRecord(String taskNum){
        List<PI_TASK_ITEM> list = new ArrayList();

        String ISEX = this.IsSaveRecord(taskNum);//检验是否已经保存记录
        if ("已检".equals(ISEX)){
            return list;
        }else if("未检".equals(ISEX)){
            PI_TASK_ITEM pi_task_item = new PI_TASK_ITEM();
            pi_task_item.setNUM("1");
            list.add(pi_task_item);
            return list;
        }
        list = this.selectNotFinishItemList(taskNum,null);
        if (list.size()!=0){
            return list;
        }
        ArrayList sqls = new ArrayList();

        //更新区域的状态
        String updateAreaStatus = "update pi_task_area set status = '已检' where   pi_task_no = '"+taskNum+"'" ;
        sqls.add(updateAreaStatus);

        //更新区域下所有的设备状态
        String updateDeviceStatus = "update pi_task_device set status = '已检' where  pi_task_no = '"+taskNum+"'";
        sqls.add(updateDeviceStatus);

        //更新区域下所有的巡检项状态
        String updateItemStatus= "update pi_task_item set status = '已检'  where   pi_task_no = '"+taskNum+"'";
        sqls.add(updateItemStatus);
        //查询巡检异常项数量
        String abnormalItem = this.getAbnormalItem(taskNum);
        //更新巡检任务状态
        String updateTaskStatus= "update pi_task set status = '已检',REAL_POINT=NORM_POINT," +
                "IN_PLACE_RATE='100',PI_RATE='100',MISSED_RATE='0',YCD='"+abnormalItem+"' where num = '"+taskNum+"'";
        sqls.add(updateTaskStatus);

        try {
            JdbcUtil.executeBatch(sqls);
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }

    //设置设备免检
    public String exemptFromInspection(String taskNum, String areaNum,String deviceNum) {
        ArrayList sqls = new ArrayList();
        //更新区域下所有的设备状态
        String updateDeviceStatus = "update pi_task_device set status = '免检' where pi_task_area_no= '"+areaNum+"' " +
                "and pi_task_no = '"+taskNum+"' and num = '"+deviceNum+"'";
        sqls.add(updateDeviceStatus);

        //更新区域下所有的巡检项状态
        String exemptFromInspectionItem= "update pi_task_item set status = '免检',PI_TASK_ITEM_RESULT = '免检'" +
                " where pi_task_area_no= '"+areaNum+"' and pi_task_no = '"+taskNum+"' and pi_task_device_no ='"+deviceNum+"'";
        sqls.add(exemptFromInspectionItem);
        //如果区域下设备都已经为免检或者为草稿状态，更新区域状态
        if(IsexemptFromInspection(taskNum,areaNum,"未检")==1){
            String updateAreaStatus = "update pi_task_area set status = '草稿' where pi_task_no = '"+taskNum+"' AND " +
                    "num = '"+areaNum+"'";
            sqls.add(updateAreaStatus);
            //如果任务下区域都已经为草稿状态，更新任务状态
            if(IsFinishPunchCard(taskNum,"未检")==1){
                String updateTaskStatus = "update pi_task set status = '草稿' where num = '"+taskNum+"'";
                sqls.add(updateTaskStatus);
            }
        }
        try {
            JdbcUtil.executeBatch(sqls);
        } catch (RemoteException e) {
            e.printStackTrace();
            return "失败";
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return "成功";
    }

    //查询区域下异常的巡检项列表
    public List<PI_TASK_ITEM> selectExpItemList(String taskNum,String result) {
        ResultSet rst = null;
        PreparedStatement pst = null;
        ArrayList list = new ArrayList();
        String sql ="SELECT p.NUM,p.DEVICE_PART_NAME,p.PI_ITEM_DESCRIPTION,p.POINT_NORM,p.CHECK_METHOD,p.HIGHER_LIMIT,p.LOWER_LIMIT," +
                "p.POINT_TYPE,p.PI_TASK_ITEM_RESULT,p.DOUBLERET,p.XJPERSONID,p.PI_TASK_TIME,p.PI_TASK_NO,p.STATUS,p.REMARK," +
                "q.TASK_NAME FROM PI_TASK_ITEM p LEFT JOIN PI_TASK q on p.PI_TASK_NO = q.NUM " +
                "WHERE p.PI_TASK_NO ='"+taskNum+"' and  p.PI_TASK_ITEM_RESULT = '"+result+"' ";
        try {
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }
            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();
            while (rst.next()){
                PI_TASK_ITEM obj = new PI_TASK_ITEM();
                obj.setNUM(rst.getString("NUM"));
                obj.setDEVICE_PART_NAME(rst.getString("DEVICE_PART_NAME"));
                obj.setPI_ITEM_DESCRIPTION(rst.getString("PI_ITEM_DESCRIPTION"));
                obj.setPOINT_NORM(rst.getString("POINT_NORM"));
                obj.setCHECK_METHOD(rst.getString("CHECK_METHOD"));
                obj.setPOINT_TYPE(rst.getString("POINT_TYPE"));
                obj.setPI_TASK_ITEM_RESULT(rst.getString("PI_TASK_ITEM_RESULT"));
                obj.setDOUBLERET(rst.getString("DOUBLERET"));
                obj.setXJPERSONID(rst.getString("XJPERSONID"));
                obj.setSTATUS(rst.getString("STATUS"));
                obj.setHIGHER_LIMIT(rst.getString("HIGHER_LIMIT"));
                obj.setLOWER_LIMIT(rst.getString("LOWER_LIMIT"));
                obj.setPI_TASK_NO(rst.getString("PI_TASK_NO"));
                obj.setTASK_NAME(rst.getString("TASK_NAME"));
                list.add(obj);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            this.closeAll(this.con, pst, rst);
        }
        return list;
    }
    //查询区域下未填值的巡检项列表
    public List<PI_TASK_ITEM> selectNotFinishItemList(String taskNum,String status){
        ResultSet rst = null;
        PreparedStatement pst = null;
        ArrayList list = new ArrayList();
        StringBuilder sql= new StringBuilder();
        String sql2 ="SELECT p.NUM,p.DEVICE_PART_NAME,p.PI_ITEM_DESCRIPTION,p.POINT_NORM,p.CHECK_METHOD,p.HIGHER_LIMIT,p.LOWER_LIMIT," +
                "p.POINT_TYPE,p.PI_TASK_ITEM_RESULT,p.DOUBLERET,p.XJPERSONID,p.PI_TASK_TIME,p.PI_TASK_NO,p.STATUS,p.REMARK,q.TASK_NAME " +
                "FROM (SELECT * FROM PI_TASK_ITEM where PI_TASK_NO ='"+taskNum+"' and POINT_TYPE in ('CB','CL','CW','JS','JL') and DOUBLERET is null  )p " +
                "LEFT JOIN PI_TASK q on p.PI_TASK_NO = q.NUM  where p.status != '免检' ";
        StringBuilder where = new StringBuilder("and p.status='"+status+"'");
        sql.append(sql2);
        if(status!=null){
            sql.append(where);
        }

        try {
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }
            pst = this.con.prepareStatement(sql.toString());
            rst = pst.executeQuery();
            while (rst.next()){
                PI_TASK_ITEM obj = new PI_TASK_ITEM();
                obj.setNUM(rst.getString("NUM"));
                obj.setDEVICE_PART_NAME(rst.getString("DEVICE_PART_NAME"));
                obj.setPI_ITEM_DESCRIPTION(rst.getString("PI_ITEM_DESCRIPTION"));
                obj.setPOINT_NORM(rst.getString("POINT_NORM"));
                obj.setCHECK_METHOD(rst.getString("CHECK_METHOD"));
                obj.setPOINT_TYPE(rst.getString("POINT_TYPE"));
                obj.setPI_TASK_ITEM_RESULT(rst.getString("PI_TASK_ITEM_RESULT"));
                obj.setDOUBLERET(rst.getString("DOUBLERET"));
                obj.setXJPERSONID(rst.getString("XJPERSONID"));
                obj.setSTATUS(rst.getString("STATUS"));
                obj.setHIGHER_LIMIT(rst.getString("HIGHER_LIMIT"));
                obj.setLOWER_LIMIT(rst.getString("LOWER_LIMIT"));
                obj.setPI_TASK_NO(rst.getString("PI_TASK_NO"));
                obj.setTASK_NAME(rst.getString("TASK_NAME"));
                list.add(obj);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            this.closeAll(this.con, pst, rst);
        }
        return list;
    }
    //打卡：前端传递打卡编号和图片进行打卡，打卡后巡检任务、区域、设备、巡检项状态都变为草稿
    public synchronized String  punchCard(String useCode,String taskNum,String cardId,String IsiOS){
        String result = "成功";
        String areaNum = null;

        if(cardId==null||"".equals(cardId)){
            return  "失败:cardId为空";
        }
        if(taskNum==null||"".equals(taskNum)){
            return "失败:taskNum为空";
        }
        if(IsiOS==null||"".equals(IsiOS)){
            return "失败:IsiOS为空";
        }
        //IsiOS为0，手机为安卓系统，cardId为nfcId;   IsiOS为1，手机为iOS系统，cardId为区域编号;
        areaNum = this.getAreaNumByCardId(cardId,IsiOS);
        if (areaNum == null || "".equals(areaNum)) {
            return "失败:找不到区域号";
        }

        //判断该区域是否已经打过卡了
        String urlname = this.IsPunchCard(areaNum, taskNum);
        if(urlname==null||"".equals(urlname)){
            return "区域号或任务号错误";
        }
        if(!urlname.equals("1")){
            return "已经打过卡了";
        }
//        //上传图片
//        DataHandler dh = img.getDataHandler();
//        MediaType ct = img.getContentType();//文件类型
////        String classpath = this.getClass().getResource("/").getPath().replaceFirst("/", "");
////        String webappRoot = classpath.replace("WEB-INF/classes/","");
//        //D:\DOCLINKS\ATTACHMENTS\
//        String filepath = JdbcUtil.doc; //文件路径
//        Date date = new Date();
//        SimpleDateFormat fileDate = new SimpleDateFormat("yyyyMMddHHmmss");
//        String filename = areaNum+fileDate.format(date)+"."+ct.toString().split("/")[1];//文件名
//        String fileURL = filepath+"\\"+filename;//文件链接
//
//        try {
//            this.writeFile(dh,filepath,filename);
//        } catch (IOException e) {
//            e.printStackTrace();
//            return "失败";
//        }
        ArrayList sqls = new ArrayList();

        //更新区域的状态
        String updateAreaStatus = "update pi_task_area set status = '草稿',UDSFSM = 1 " +
                "where num =  '"+areaNum+"' and pi_task_no = '"+taskNum+"'" ;
        sqls.add(updateAreaStatus);

        //更新区域下所有的设备状态
        //20250627更新
//        String updateDeviceStatus = "update pi_task_device set status = '草稿' where pi_task_area_no= '"+areaNum+"' " +
//                "and pi_task_no = '"+taskNum+"'";
        String updateDeviceStatus = "update pi_task_device set status = '草稿' where pi_task_area_no= '"+areaNum+"' " +
                "and pi_task_no = '"+taskNum+"' and num not in (select pi_task_device_no from pi_task_item where   pi_task_area_no= '"+areaNum+"' and pi_task_no = '"+taskNum+"' and POINT_TYPE in ('CB','CL','CW','JS','JL') ) ";

        sqls.add(updateDeviceStatus);

        //更新区域下所有的巡检项状态
        String updateItemStatus= "update pi_task_item set status = '草稿',PI_TASK_ITEM_RESULT = '正常'," +
                "XJPERSONID='"+useCode+"',PI_TASK_TIME= sysdate " +
                " where pi_task_area_no= '"+areaNum+"' and pi_task_no = '"+taskNum+"'";
        sqls.add(updateItemStatus);
        //实到区域加一
        String updateTaskRealArea= "update pi_task set REAL_AREA = REAL_AREA+1  where num = '"+taskNum+"'";
        sqls.add(updateTaskRealArea);

        //更新巡检任务状态
        String updateTaskStatus= "update pi_task set status = '草稿' where num = '"+taskNum+"'";
        if(IsFinishPunchCard(taskNum,"未检")==1){
            sqls.add(updateTaskStatus);
        }
        //把图片存进附件表
//        String rowCount = this.selectDOCINFOSEQ();
//        String DOCUMENT = "XJ" + rowCount;
//        String insertToDoc = " insert into DOCINFO (DOCUMENT, DESCRIPTION, APPLICATION, STATUS, STATUSDATE, CREATEDATE, " +
//        "REVISION, CHANGEBY, CHANGEDATE, DOCLOCATION, DOCTYPE, CREATEBY, URLTYPE, DMSNAME, URLNAME, URLPARAM1, " +
//                "URLPARAM2, URLPARAM3, URLPARAM4, URLPARAM5, PRINTTHRULINKDFLT, USEDEFAULTFILEPATH, SHOW,  DOCINFOID, " +
//                "LANGCODE, HASLD, CONTENTUID) values ('" + DOCUMENT + "', '" +filename+ "', null, null, null, sysdate, " +
//                "null, '" + useCode + "',sysdate, null, 'Attachments', '" + useCode + "', '文件', null," + " '" + fileURL + "'," +
//                " null, null, null, null, null, 1, 0, 0, " + rowCount + ", 'ZH', 0, '" + rowCount + "')";
//        sqls.add(insertToDoc);//插入数据到DOCINFO
//
//        String insertToDocs = " insert into DOCLINKS (DOCUMENT, OWNERTABLE, OWNERID, REFERENCE, DOCTYPE, DOCVERSION, " +
//                "GETLATESTVERSION,  CREATEBY, CREATEDATE, CHANGEBY, CHANGEDATE, PRINTTHRULINK, COPYLINKTOWO, DOCLINKSID," +
//                " DOCINFOID) values ('" + DOCUMENT + "', 'PI_TASK_AREA', (select PI_TASK_AREAID from PI_TASK_AREA " +
//                "where PI_TASK_NO = '"+taskNum+"' and NUM = '"+areaNum+"'), null, 'Attachments', null, 1, '" + useCode + "', " +
//                "sysdate, '" + useCode + "', sysdate, 1, 0, DOCLINKSSEQ.NEXTVAL, " + rowCount + ")";
//        sqls.add(insertToDocs);//插入数据到DOCLINKS
        try {
            JdbcUtil.executeBatch(sqls);
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return result;
    }
    //根据巡检设备编号获取巡检项列表
    public List getItemList(String taskNum,String areaNum,String deviceNum,String page){
        StringBuilder newSql = new StringBuilder();
        newSql.append("select * from(select m.*,ROWNUM rn from (SELECT NUM,DEVICE_PART_NAME,PI_ITEM_DESCRIPTION,POINT_NORM,CHECK_METHOD,HIGHER_LIMIT,LOWER_LIMIT," +
                "POINT_TYPE,PI_TASK_ITEM_RESULT,DOUBLERET,XJPERSONID,PI_TASK_TIME,PI_TASK_NO,STATUS FROM PI_TASK_ITEM");
        StringBuilder where = new StringBuilder();
        where.append(" where 1=1");
        if (taskNum!=null&& !"".equals(taskNum)){
            where.append("and PI_TASK_NO = '"+taskNum+"'");
        }
        if (taskNum!=null&& !"".equals(areaNum)){
            where.append("and PI_TASK_AREA_NO = '"+areaNum+"'");
        }
        if(deviceNum!=null&&!"".equals(deviceNum)){
            where.append(" and PI_TASK_DEVICE_NO = '"+deviceNum+"'" );
        }
        if(where.length()>10){
            newSql.append(where.toString());
            newSql.append(" order by NUM )m) where 1 = 1 ");
        }
        if(page!=null&& !"".equals(page)){
            Integer begin = (Integer.parseInt(page)-1)* 15;
            Integer end = Integer.parseInt(page) * 15;
            String pageWhere = "and rn> "+begin+" and rn<="+end;
            newSql.append(pageWhere);
        }
        ResultSet rst = null;
        PreparedStatement pst = null;
        ArrayList list = new ArrayList();
        try {
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }
            pst = this.con.prepareStatement(newSql.toString());
            rst = pst.executeQuery();
            while (rst.next()){
                PI_TASK_ITEM obj = new PI_TASK_ITEM();
                obj.setNUM(rst.getString("NUM"));
                obj.setDEVICE_PART_NAME(rst.getString("DEVICE_PART_NAME"));
                obj.setPI_ITEM_DESCRIPTION(rst.getString("PI_ITEM_DESCRIPTION"));
                obj.setPOINT_NORM(rst.getString("POINT_NORM"));
                obj.setCHECK_METHOD(rst.getString("CHECK_METHOD"));
                obj.setPOINT_TYPE(rst.getString("POINT_TYPE"));
                obj.setPI_TASK_ITEM_RESULT(rst.getString("PI_TASK_ITEM_RESULT"));
                obj.setDOUBLERET(rst.getString("DOUBLERET"));
                obj.setXJPERSONID(rst.getString("XJPERSONID"));
                obj.setSTATUS(rst.getString("STATUS"));
                obj.setHIGHER_LIMIT(rst.getString("HIGHER_LIMIT"));
                obj.setLOWER_LIMIT(rst.getString("LOWER_LIMIT"));
                obj.setPI_TASK_NO(rst.getString("PI_TASK_NO"));
                list.add(obj);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            this.closeAll(this.con, pst, rst);
        }
        return list;

    }
    //根据巡检区域编号获取设备列表
    public List getDeviceList(String taskNum,String areaNum,String page){
        StringBuilder sql = new StringBuilder();
        StringBuilder where  = new StringBuilder();
        sql.append("select * from(select m.*,ROWNUM rn from (SELECT p.NUM,p.ON_OFF_POTIN,p.SCANTIME,p.TASK_DEVICE_NAME,p.LOCATION,p.STATUS,p.ASSETNUM,a.DESCRIPTION" +
                " FROM PI_TASK_DEVICE p LEFT JOIN ASSET a ON p.ASSETNUM = a.ASSETNUM");
        where.append(" where 1=1 ");
        if (taskNum!=null&& !"".equals(taskNum)){
            where.append("and p.PI_TASK_NO = '"+taskNum+"'");
        }
        if (areaNum!=null&& !"".equals(areaNum)){
            where.append("and p.PI_TASK_AREA_NO = '"+areaNum+"'");
        }
        if(where.length()>10){
            sql.append(where.toString());
            sql.append(" order by p.NUM )m) where 1 = 1 ");
        }
        if(page!=null&& !"".equals(page)){
            Integer begin = (Integer.parseInt(page)-1)* 15;
            Integer end = Integer.parseInt(page) * 15;
            String pageWhere = "and rn> "+begin+" and rn<="+end;
            sql.append(pageWhere);
        }
        ResultSet rst = null;
        PreparedStatement pst = null;
        ArrayList list = new ArrayList();
        try {
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }
            pst = this.con.prepareStatement(sql.toString());
            rst = pst.executeQuery();
            while (rst.next()){
                PI_TASK_DEVICE obj = new PI_TASK_DEVICE();
                obj.setNUM(rst.getString("NUM"));
                obj.setON_OFF_POTIN(rst.getString("ON_OFF_POTIN"));
                obj.setSCANTIME(rst.getString("SCANTIME"));
                obj.setTASK_DEVICE_NAME(rst.getString("TASK_DEVICE_NAME"));
                obj.setLOCATION(rst.getString("LOCATION"));
                obj.setSTATUS(rst.getString("STATUS"));
                obj.setASSETNUM(rst.getString("ASSETNUM"));
                obj.setASSETNAME(rst.getString("DESCRIPTION"));
                list.add(obj);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            this.closeAll(this.con, pst, rst);
        }
        return list;

    }
    //根据巡检任务编号获取区域列表
    public List getAreaList(String taskNum,String status,String page){
        StringBuilder sql = new StringBuilder();
        StringBuilder where  = new StringBuilder();
        sql.append("select * from(select m.*,ROWNUM rn from (SELECT p.PI_TASK_NO,q.LC_XP_ID,p.NUM,p.TASK_AREA_NAME,p.PROFESSIONAL,p.UDSFSM,q.LC_IN_NO_P AS NFCID," +
                " p.URLNAME,p.SCPERSON,p.SCANTIME,p.STATUS FROM PI_TASK_AREA p left join PI_AREA q on p.NUM = q.NUM");
        where.append(" where 1=1 ");
        if (taskNum!=null&& !"".equals(taskNum)){
            where.append("and p.PI_TASK_NO = '"+taskNum+"'");
        }  if (status!=null&& !"".equals(status)){
            where.append("and p.status = '"+status+"'");
        }
        if(where.length()>10){
            sql.append(where.toString());
            sql.append(" order by p.NUM )m) where 1 = 1 ");
        }

        if(page!=null&& !"".equals(page)){
            Integer begin = (Integer.parseInt(page)-1)* 15;
            Integer end = Integer.parseInt(page) * 15;
            String pageWhere = "and rn> "+begin+" and rn<="+end;
            sql.append(pageWhere);
        }
        ResultSet rst = null;
        PreparedStatement pst = null;
        ArrayList list = new ArrayList();
        try {
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }
            pst = this.con.prepareStatement(sql.toString());
            rst = pst.executeQuery();
            for (;rst.next();){
                PI_TASK_AREA obj = new PI_TASK_AREA();
                obj.setPI_TASK_NO(rst.getString("PI_TASK_NO"));
                obj.setLC_XP_ID(rst.getString("LC_XP_ID"));
                obj.setNUM(rst.getString("NUM"));
                obj.setTASK_AREA_NAME(rst.getString("TASK_AREA_NAME"));
                obj.setPROFESSIONAL(rst.getString("PROFESSIONAL"));
                obj.setUDSFSM(rst.getString("UDSFSM"));
                obj.setSCANTIME(rst.getString("SCANTIME"));
                obj.setSTATUS(rst.getString("STATUS"));
                obj.setURLNAME(rst.getString("URLNAME"));
                obj.setNFCID(rst.getString("NFCID"));
                list.add(obj);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            this.closeAll(this.con, pst, rst);
        }
        return list;

    }
    //统计区域数量
    public int getAreaListTotal(String taskNum,String status){
        int result = 0;
        StringBuilder sql = new StringBuilder();
        StringBuilder where  = new StringBuilder();
        sql.append("SELECT count(*) as total FROM PI_TASK_AREA p ");
        where.append(" where 1=1 ");
        where.append("and p.PI_TASK_NO = '"+taskNum+"'");
        if (status!=null&& !"".equals(status)){
            where.append("and p.status = '"+status+"'");
        }
        if(where.length()>10){
            sql.append(where.toString());
        }
        ResultSet rst = null;
        PreparedStatement pst = null;
        try {
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }
            pst = this.con.prepareStatement(sql.toString());
            rst = pst.executeQuery();
            for (;rst.next();){
                result = Integer.parseInt(rst.getString("total"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            this.closeAll(this.con, pst, rst);
        }
        return result;

    }

    //根据巡检状态和岗位获取巡检任务列表
    public List<PI_TASK> getTaskList(Map<String,String> routeMap){
        StringBuilder sql = new StringBuilder();
        StringBuilder where  = new StringBuilder();
        sql.append("select * from(select m.*,ROWNUM rn from (select NUM,TASK_NAME,PI_TASKCFG_NO,TASK_TYPE,PROFESSIONAL,PI_POST_NO,STATUS,BEGIN_TIME,END_TIME," +
                "NORM_AREA,REAL_AREA FROM PI_TASK");
        where.append(" where 1=1 ");
        if (routeMap.get("status")!=null&& !"".equals(routeMap.get("status"))){
            where.append("and status = '"+routeMap.get("status")+"' ");
        }
        if (routeMap.get("postId")!=null&& !"".equals(routeMap.get("postId"))){
            where.append("and pi_post_no in (SELECT PI_POST_NO FROM PI_USER WHERE PERSONID IN " +
                    "(SELECT PERSONGROUP FROM PERSONGROUPTEAM WHERE RESPPARTYGROUP = '"+routeMap.get("postId")+"'))");
        }
        if(routeMap.get("PI_TASKCFG_NO")!=null&& !"".equals(routeMap.get("PI_TASKCFG_NO"))){
            where.append("and PI_TASKCFG_NO = '"+routeMap.get("PI_TASKCFG_NO")+"' ");
        }
        if(routeMap.get("routeDate")!=null&& !"".equals(routeMap.get("routeDate"))){
            where.append("and to_char(BEGIN_TIME,'YYYY-MM-DD HH24:MI:SS') <= '"+routeMap.get("routeDate")+"' and to_char(END_TIME,'YYYY-MM-DD HH24:MI:SS') >= '"+routeMap.get("routeDate")+"' " );
        }
        if(where.length()>10){
            sql.append(where.toString());
            sql.append(" order by BEGIN_TIME desc)m) where 1 = 1 ");
        }
        if(routeMap.get("page")!=null&& !"".equals(routeMap.get("page"))){
            Integer page = Integer.parseInt(routeMap.get("page"));
            Integer begin = (page-1)* 20;
            Integer end = page * 20;
            String pageWhere = " and rn> "+begin+" and rn<="+end;
            sql.append(pageWhere);
        }
        ResultSet rst = null;
        ArrayList list = new ArrayList();
        PreparedStatement pst = null;
        System.out.println("SQL====="+sql.toString());
        try {
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }
            pst = this.con.prepareStatement(sql.toString());
            rst = pst.executeQuery();
            while (rst.next()){
                PI_TASK obj = new PI_TASK();
                obj.setNUM(rst.getString("NUM"));
                obj.setTASK_NAME(rst.getString("TASK_NAME"));
                obj.setPI_TASKCFG_NO(rst.getString("PI_TASKCFG_NO"));
                obj.setTASK_TYPE(rst.getString("TASK_TYPE"));
                obj.setPROFESSIONAL(rst.getString("PROFESSIONAL"));
                obj.setPI_POST_NO(rst.getString("PI_POST_NO"));
                obj.setSTATUS(rst.getString("STATUS"));
                obj.setBEGIN_TIME(rst.getString("BEGIN_TIME").replace(":00.0",":00"));
                obj.setEND_TIME(rst.getString("END_TIME").replace(":00.0",":00"));
                obj.setNORM_AREA(rst.getString("NORM_AREA"));
                obj.setREAL_AREA(rst.getString("REAL_AREA"));
                list.add(obj);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            this.closeAll(this.con, pst, rst);
        }
        return list;
    }

    //根据巡检状态和岗位获取巡检任务列表
    public List<PI_TASK> getTaskList(String postId,String status){
        StringBuilder sql = new StringBuilder();
        StringBuilder where  = new StringBuilder();
        sql.append("select distinct TASK_NAME,PI_TASKCFG_NO FROM PI_TASK ");
        where.append(" where 1=1 and to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') <= to_char(END_TIME,'YYYY-MM-DD HH24:MI:SS') ");
        if (status!=null&& !"".equals(status)){
            where.append("and status = '"+status+"'");
        }
        if (postId!=null&& !"".equals(postId)){
            where.append("and pi_post_no in (SELECT PI_POST_NO FROM PI_USER WHERE PERSONID IN " +
                    "(SELECT PERSONGROUP FROM PERSONGROUPTEAM WHERE RESPPARTYGROUP = '"+postId+"'))");
        }
        if(where.length()>10){
            sql.append(where.toString());
        }

        ResultSet rst = null;
        ArrayList list = new ArrayList();
        PreparedStatement pst = null;
        System.out.println("SQL====="+sql.toString());
        try {
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }
            pst = this.con.prepareStatement(sql.toString());
            rst = pst.executeQuery();
            while (rst.next()){
                PI_TASK obj = new PI_TASK();
                obj.setTASK_NAME(rst.getString("TASK_NAME"));
                obj.setPI_TASKCFG_NO(rst.getString("PI_TASKCFG_NO"));
                list.add(obj);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            this.closeAll(this.con, pst, rst);
        }
        return list;
    }
    //查询DOCINFO的序列号
    public String selectDOCINFOSEQ(){
        String ID = "";
        String sql = " select DOCINFOSEQ.NEXTVAL ID from dual";
        ResultSet rst = null;
        PreparedStatement pst = null;
        try {
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }
            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();
            while (rst.next()) {
                ID = rst.getString("ID");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            this.closeAll(this.con, pst, rst);
        }
        return ID;
    }

    //判断任务下所有的区域状态已更新
    public int IsexemptFromInspection(String taskId,String areaNum,String status){
        int result = -1;
        String sql = "select COUNT(*) AS RESULT from pi_task_device where pi_task_no ='"+ taskId +"' AND " +
                "pi_task_area_no ='"+areaNum+"' AND STATUS = '"+status+"'";
        ResultSet rst = null;
        PreparedStatement pst = null;
        try {
            this.setCon(getDB2Conn());
            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();
            while (rst.next()) {
                result = rst.getInt("RESULT");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            this.closeAll(this.con, pst, rst);
        }
        return result;
    }

    //判断任务下所有的区域状态已更新
    public int IsFinishPunchCard(String taskId,String status){
        int result = -1;
        String sql = "select COUNT(*) AS RESULT from pi_task_area where pi_task_no ='"+ taskId +"' AND STATUS = '"+status+"'";
        ResultSet rst = null;
        PreparedStatement pst = null;
        try {
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }
            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();
            while (rst.next()) {
                result = rst.getInt("RESULT");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            this.closeAll(this.con, pst, rst);
        }
        return result;
    }
    //查询指定任务下巡检项异常条数
    public String getAbnormalItem(String taskId){
        String result = "0";
        ResultSet rst = null;
        PreparedStatement pst = null;
        String sql = "select count(*) as RESULT from PI_TASK_ITEM where PI_TASK_NO ='"+taskId+"' and PI_TASK_ITEM_RESULT ='异常'";
        try {
            if(this.con.isClosed()){
                this.setCon(getDB2Conn());
            }
            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();
            while(rst.next()){
                result = rst.getString("RESULT");
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            this.closeAll(this.con,pst,rst);
        }
        return result;
    }
    //根据NFC编号查询区域编号
    public String getAreaNumByCardId(String cardId,String isIOS){
        //查询区域编号
        String areaNum = "";
        String sql = "";
        if(isIOS.equals("1")){
             sql = "select NUM from pi_area where LC_XP_ID = '"+cardId+"'";
        }else {
             sql = "select NUM from pi_area where LC_IN_NO_P = '"+cardId+"'";
        }
        ResultSet rst = null;
        PreparedStatement pst = null;
        try {
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }
            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();
            while (rst.next()){
                areaNum = rst.getString("NUM");
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            this.closeAll(this.con, pst, rst);
        }
        return areaNum;
    }
    //检验是否该任务已经保存
    public String IsSaveRecord(String taskNum) {
        String ISEX = "";
        ResultSet rst = null;
        PreparedStatement pst = null;
        String sql = "select status as ISEX from pi_task where num = '"+taskNum+"' ";
        try {
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }
            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();
            while (rst.next()){
              ISEX = rst.getString("ISEX");
            }

        } catch (Exception var12) {
            var12.printStackTrace();
        }
        return ISEX;
    }
    //检验是否已经有人打卡
    public String IsPunchCard(String areaNum, String taskNum) {
            String UDSFSM = "";
        String ISEX = "";
        ResultSet rst = null;
        PreparedStatement pst = null;
        String sql = "select UDSFSM,1 as ISEX from pi_task_area where num =  '"+areaNum+"' and pi_task_no = '"+taskNum+"'";
        try {
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }
            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();
            while (rst.next()){
                UDSFSM = rst.getString("UDSFSM");
                ISEX = rst.getString("ISEX");
            }

        } catch (Exception var12) {
            var12.printStackTrace();
        }
        if(ISEX.equals("1")){
            if(UDSFSM.equals("0")){
                return ISEX;
            }else {
                return "已打卡";
            }
        }
        return UDSFSM;
    }

    public String login(String loginid, String password) {
        String result = "";

        try {
            String sql = "select personid,password from maxuser where loginid = '" + loginid + "'";
            String jsonObj = this.executeQuery(sql);
            JSONObject o = JSONObject.fromObject(jsonObj);
            JSONObject o1 = (JSONObject)o.get("0");
            if (o1 != null) {
                String o2 = (String)o1.get("PASSWORD");
                PropertiesUtil pu = new PropertiesUtil();
                MXCipherX mx = new MXCipherX(true, pu);
                String spwd = mx.encData(password);
                if (!spwd.equalsIgnoreCase(o2)) {
                    result = "用户名或密码错误";
                }
            } else {
                result = "用户名或密码错误";
            }
        } catch (Exception var12) {
            result = var12.getMessage();
        }

        return result;
    }

    public String GetPhoneAPP(String paramString, String paramString1) {
        String bm = "";
        ResultSet rst = null;
        PreparedStatement pst = null;
        String sql = "select udurl,UDBB from UDAPP where sfyx=1 and cust_app='FB' and UDBB in(select max(UDBB) from UDAPP where sfyx=1 and cust_app='FB') ";

        try {
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }

            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();
            String m = null;
            int UDBB = 0;
            if (rst.next()) {
                m = rst.getString("udurl");
                UDBB = rst.getInt("UDBB");
            }

            if (!"".equalsIgnoreCase(m) && m != null) {
                int bb = Integer.parseInt(paramString);
                if (bb < UDBB) {
                    bm = "{\"UpdateNow\":true,\"url\":\"" + m + "\"}";
                }
            } else {
                bm = "{\"UpdateNow\":false,\"url\":}";
            }
        } catch (SQLException var13) {
            this.closeAll(this.con, pst, rst);
            var13.printStackTrace();
        } finally {
            this.closeAll(this.con, pst, rst);
        }

        return bm;
    }

    public String GetPItask(String paramString1) {
        String bm = "";
        ResultSet rst = null;
        PreparedStatement pst = null;
        String lx = this.selebm(paramString1, (String)null);
      String where = " and  to_char(BEGIN_TIME,'yyyy-MM-dd')>=to_char(sysdate,'yyyy-MM')||'-01' and  END_TIME <=to_date(''||to_char(sysdate,'yyyy-MM-dd')||' 01:00:00','yyyy-MM-dd HH24:mi:ss') ";
//        String where = " and  to_char(BEGIN_TIME,'yyyy-MM-dd')>=concat(to_char(sysdate,'yyyy-MM'),'-01') and  END_TIME <=to_date(concat('',concat(to_char(sysdate,'yyyy-MM-dd'),' 01:00:00')),'yyyy-MM-dd HH24:mi:ss') ";
        if ("点检".equalsIgnoreCase(lx)) {
            where = " and  to_char(BEGIN_TIME,'yyyy-MM-dd')>=to_char(sysdate,'yyyy-MM')||'-01'";
        }

        String sql = " select k.zs,k.tjx,ROUND(((k.ljxa+k.ljxb))/(k.zs-k.tjx),4)*100 ljl, 100-(ROUND(((k.ljxa+k.ljxb))/(k.zs-k.tjx),4)*100) dwl   from ( select sum(IGNORE_POINT) zs, sum(TJX) tjx, sum(nvl((select IGNORE_POINT from PI_TASK p where p.NUM=PI_TASK.num and status ='未上传结果' ),0))ljxa, sum(nvl((select MISSED_POINT from PI_TASK p where p.NUM=PI_TASK.num and status ='已上传结果' ),0))ljxb, sum(NORM_POINT) yjd,sum(TJ_POINT) tjd,sum(REAL_POINT) sjd  from PI_TASK   where status!='已停检' and PI_POST_NO ='" + paramString1 + "' " + " " + where + " ) k";
//        String sql = " select k.zs,k.tjx,0 ljl, 100 dwl   from ( select sum(IGNORE_POINT) zs, sum(TJX) tjx, sum(nvl((select IGNORE_POINT from PI_TASK p where p.NUM=PI_TASK.num and status ='未上传结果' ),0))ljxa, sum(nvl((select MISSED_POINT from PI_TASK p where p.NUM=PI_TASK.num and status ='已上传结果' ),0))ljxb, sum(NORM_POINT) yjd,sum(TJ_POINT) tjd,sum(REAL_POINT) sjd  from PI_TASK   where status!='已停检' and PI_POST_NO ='" + paramString1 + "' " + " " + where + " ) k";

        try {
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }

            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();
            if (rst.next()) {
                bm = "{\"zs\":" + rst.getString("zs") + ",\"tjx\":" + rst.getString("tjx") + ",\"ljl\":" + rst.getString("ljl") + ",\"dwl\":" + rst.getString("dwl") + "}";
            }
        } catch (SQLException var12) {
            this.closeAll(this.con, pst, rst);
            var12.printStackTrace();
        } finally {
            System.out.println(sql);
            this.closeAll(this.con, pst, rst);
        }

        return bm;
    }

    public List<PA_GG> GetNotice(String PostID) {

        ResultSet rst = null;
        PreparedStatement pst = null;
        ArrayList li = new ArrayList();

        try {
            String sql = "select UDAPPID,to_char(KSDATE,'yyyy-MM-dd') as KSDATE,to_char(JSDATE,'yyyy-MM-dd') as JSDATE," +
                    "PI_POST_NO,CREATEBY,to_char(CREATEDATE,'yyyy-MM-dd HH:mm:ss') as CREATEDATE,DESCRIPTION from UDAPP " +
                    "where sfyx=1 and to_date(to_char(sysdate,'yyyy/MM/dd'),'yyyy/MM/dd')>=ksdate  " +
                    "and to_date(to_char(sysdate,'yyyy/MM/dd'),'yyyy/MM/dd')<=jsdate and cust_app='GG'  " +
                    "and (PI_POST_NO in (SELECT PI_POST_NO FROM PI_USER WHERE PERSONID IN " +
                    "(SELECT PERSONGROUP FROM PERSONGROUPTEAM WHERE RESPPARTYGROUP = '"+PostID+"')))   order by KSDATE desc";
            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();

            while(rst.next()) {
                PA_GG pa = new PA_GG();
                pa.setCREATEBY(rst.getString("CREATEBY"));
                pa.setUDAPPID(rst.getString("UDAPPID"));
                pa.setKSDATE(rst.getString("KSDATE"));
                pa.setJSDATE(rst.getString("JSDATE"));
                pa.setPI_POST_NO(rst.getString("PI_POST_NO"));
                pa.setCREATEDATE(rst.getString("CREATEDATE"));
                pa.setDESCRIPTION(rst.getString("DESCRIPTION"));
                li.add(pa);
            }
        } catch (SQLException var10) {
            this.closeAll(this.con, pst, rst);
            var10.printStackTrace();
        } finally {
            this.closeAll(this.con, pst, rst);
        }

        return li;
    }

    public String executeQuery(String sql) {
        ResultSet rst = null;
        PreparedStatement pst = null;
        JSONObject jsonobj = null;
        Integer flag = 0;

        String var11;
        try {
            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();
            Map<String, Map<String, String>> mp = new HashMap();
            ResultSetMetaData rsmd = rst.getMetaData();

            while(rst.next()) {
                Map<String, String> op = new HashMap();

                for(int i = 1; i <= rsmd.getColumnCount(); ++i) {
                    op.put(rsmd.getColumnLabel(i), rst.getString(rsmd.getColumnLabel(i)));
                }

                Integer var10001 = flag;
                flag = flag + 1;
                mp.put(var10001.toString(), op);
            }

            jsonobj = JSONObject.fromObject(mp);
            String var12 = jsonobj.toString();
            return var12;
        } catch (SQLException var15) {
            this.closeAll(this.con, pst, rst);
            var15.printStackTrace();
            var11 = var15.getMessage();
        } finally {
            this.closeAll(this.con, pst, rst);
        }

        return var11;
    }

    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;

            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();
                }

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

        }

        return result;
    }

    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();
                }

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

        }

        return result;
    }

    public int executeUpdate(String sql) {
        int result = -1;
        PreparedStatement pst = null;

        try {
            pst = this.con.prepareStatement(sql);
            result = pst.executeUpdate();
        } catch (SQLException var8) {
            this.closeAll(this.con, pst, (ResultSet)null);
            var8.printStackTrace();
        } finally {
            this.closeAll(this.con, pst, (ResultSet)null);
        }

        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();
        }

    }

    public String downloadPerson(String personid) {
        ResultSet rst = null;
        PreparedStatement pst = null;
        String jg = null;

        try {
//            String sql = " select count(*) cz from PERSONGROUPTEAM where RESPPARTYGROUP='" + personid + "' and  PERSONGROUP " + " in(select PERSONGROUP from PERSONGROUP where DESCRIPTION like '%临时巡检任务%') ";
           String sql = " select count(*) cz from PERSONGROUPTEAM where RESPPARTYGROUP='" + personid + "' and  PERSONGROUP " + " in(select PERSONGROUP from PERSONGROUP where DESCRIPTION ='标准操作票修编组电气')";
            System.out.println("下载人员组sql:" + sql);
            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();
            if (rst.next()) {
                jg = rst.getString("cz");
            }
        } catch (SQLException var9) {
            this.closeAll(this.con, pst, rst);
            var9.printStackTrace();
        } finally {
            this.closeAll(this.con, pst, rst);
        }

        return jg;
    }

    public String bindNFC(String nfcId,String signId){
        List<String> list = new ArrayList();
        String updateSignboard = "update SA_LC_IN set LC_IN_NO_P = '"+nfcId+"' where LC_XP_ID = '"+signId+"'";
        list.add(updateSignboard);
        String updateArea = "update PI_AREA set LC_IN_NO_P = '"+nfcId+"' where LC_XP_ID = '"+signId+"'";
        list.add(updateArea);
        try {
            JdbcUtil.executeBatch(list);
        } catch (RemoteException e) {
            e.printStackTrace();
            return "失败";
        } catch (SQLException e) {
            e.printStackTrace();
            return "失败";
        }
        return "成功";
    }

    public List<UdGeneral> downloadPA_BSP(String areaName,String areaNum) {
        ResultSet rst = null;
        PreparedStatement pst = null;
        ArrayList li = new ArrayList();
        StringBuilder sql = new StringBuilder();
        sql.append("select DISTINCT LC_XP_ID,LC_IN_NO_P,DESCRIPTION ms from SA_LC_IN where 1 = 1 and LC_IN_NO_P is null ");
        StringBuilder where = new StringBuilder();
        if(areaName!=null&&!"".equals(areaName)){
            String areaNameWhere = "and DESCRIPTION like '%"+areaName+"%' ";
            where.append(areaNameWhere);
        }
        if(areaNum!=null&&!"".equals(areaNum)){
            String areaNumWhere = "and LC_XP_ID = '"+areaNum+"' ";
            where.append(areaNumWhere);
        }
        sql.append(where);
        try {
            pst = this.con.prepareStatement(sql.toString());
            rst = pst.executeQuery();

            while(rst.next()) {
                UdGeneral pa = new UdGeneral();
                pa.setAreaNum(rst.getString("LC_XP_ID"));
                pa.setNFCID(rst.getString("LC_IN_NO_P"));
                pa.setAreaName(rst.getString("ms"));
                li.add(pa);
            }
        } catch (SQLException var10) {
            this.closeAll(this.con, pst, rst);
            var10.printStackTrace();
        } finally {
            this.closeAll(this.con, pst, rst);
        }

        return li;
    }

    public List<PA_Group_TempModel> downloadPA_ROLE(String orgid) {
        ResultSet rst = null;
        PreparedStatement pst = null;
        ArrayList li = new ArrayList();

        try {
            String sql = " select p.NUM,p.POST_NAME ,p.GWTYPE from PI_POST p where  p.type='巡检' and p.orgid='" + orgid + "' ";
            System.out.println("下载角色sql:" + sql);
            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();

            while(rst.next()) {
                PA_Group_TempModel pa = new PA_Group_TempModel();
                pa.setID(rst.getString("NUM"));
                pa.setName(rst.getString("POST_NAME"));
                pa.setType(rst.getString("GWTYPE"));
                li.add(pa);
            }
        } catch (SQLException var10) {
            this.closeAll(this.con, pst, rst);
            var10.printStackTrace();
        } finally {
            this.closeAll(this.con, pst, rst);
        }

        return li;
    }

    public List<Phone_C_USER> downloadPA_User(String orgid, String RoleID) {
        ResultSet rst = null;
        PreparedStatement pst = null;
        ArrayList li = new ArrayList();

        try {
            String sql = " select m.USERID,m.password,(select DISPLAYNAME from PERSON where personid=m.PERSONID) as xm from MAXUSER m   where m.personid in(select RESPPARTYGROUP from  PERSONGROUPTEAM where PERSONGROUP in( select personid from PI_USER  where PI_POST_NO="+ RoleID+"))";
            System.out.println("sql:" + sql);
            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();
            String dec = null;
            PropertiesUtil pu = new PropertiesUtil();
            while(rst.next()) {
                Phone_C_USER pa = new Phone_C_USER();
                pa.setUS_CODE(rst.getString("USERID"));
                pa.setAccount_Alias(rst.getString("USERID"));
                dec = rst.getString("password");
                MXCipherX dmx = new MXCipherX(false, pu);
                pa.setUS_PWD(dmx.decData(dec));
                pa.setAccount_Alias(rst.getString("USERID"));
                pa.setUS_NAME(rst.getString("xm"));
                pa.setUS_PHONE_NUMBER("");
                pa.setUS_COMPANY_ID(orgid);
                pa.setROLEID(RoleID);
                li.add(pa);
            }
        } catch (SQLException var14) {
            this.closeAll(this.con, pst, rst);
            var14.printStackTrace();
        } finally {
            this.closeAll(this.con, pst, rst);
        }

        return li;
    }

    public String selebm(String gw, String orgid) {
        String bm = "";
        ResultSet rst = null;
        PreparedStatement pst = null;
        String sql = " select gwtype DEPARTMENT from PI_POST where NUM='" + gw + "' ";

        try {
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }

            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();
            if (rst.next()) {
                bm = rst.getString("DEPARTMENT");
            }
        } catch (SQLException var11) {
            this.closeAll(this.con, pst, rst);
            var11.printStackTrace();
        } finally {
            this.closeAll(this.con, pst, rst);
        }

        return bm;
    }

    public int selebsp(String bsp, String sj) {
        int bm = 0;
        ResultSet rst = null;
        PreparedStatement pst = null;
        String sql = " select count(*) ts from UDBUG where LC_XP_ID='" + bsp + "' and REPORTTIME>=" + " add_months(to_date(to_char(to_date('" + sj + "','yyyy/MM/dd hh24:mi:ss')," + "'yyyy/MM/dd hh24:mi:ss'),'yyyy/MM/dd hh24:mi:ss'),-1)" + " and status not in('CAN','CLOSE')";
        System.out.println("445===" + sql);

        try {
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }

            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();
            if (rst.next()) {
                bm = rst.getInt("ts");
            }
        } catch (SQLException var11) {
            this.closeAll(this.con, pst, rst);
            var11.printStackTrace();
        } finally {
            this.closeAll(this.con, pst, rst);
        }

        return bm;
    }

    public synchronized List<Phone_PA_ROUTINE_GROUP> downloadPA_ROUTINE_GROUP(String personid, String orgid) {
        ResultSet rst = null;
        PreparedStatement pst = null;
        List<Phone_PA_ROUTINE_GROUP> runtimeGroup = new ArrayList();
        String sql = null;

        try {
            String bm = this.selebm(personid, orgid);
            String where = " and  p.BEGIN_TIME <= CURRENT_DATE  and p.END_TIME >= CURRENT_DATE ";
            System.out.println("==========nbm=====" + bm);
            if ("巡检".equalsIgnoreCase(bm)) {
                where = " and  p.BEGIN_TIME>=to_date(''||to_char(sysdate,'yyyy-MM-dd')||' 00:00:00','yyyy-MM-dd HH24:mi:ss')  and  p.END_TIME <=to_date(''||to_char(sysdate+1,'yyyy-MM-dd')||' 01:00:00','yyyy-MM-dd HH24:mi:ss')";
                sql = " select ROWNUM as GROUP_SEQ,k.* from (select BARCODE,TWOCODE,GROUP_ID,GROUP_NAME,NFCID,QRCODE,PAPOINTID,UDXL,PAPOINTNAME,zs from ( select '' as BARCODE ,'' TWOCODE ,p.TASK_TYPE as GROUP_ID , p.professional as GROUP_NAME ,   i.lc_in_no_p as NFCID , i.LC_XP_ID QRCODE,  a.NUM as PAPOINTID ,  p.TASK_NAME UDXL,a.TASK_AREA_NAME as PAPOINTNAME , (select count(*) from PI_TASK_ITEM where pi_task_no=p.num  and   pi_task_area_no=a.num  and BEGIN_TIME=p.BEGIN_TIME and  END_TIME=p.END_TIME) zs            FROM pi_task p , pi_task_area a ,PI_AREA i where  p.NUM =a.PI_TASK_NO and a.NUM=i.NUM   and p.status!='已停检' and p.PI_POST_NO = '" + personid + "'" + " " + where + " " + " )group by BARCODE,TWOCODE,GROUP_ID,GROUP_NAME,NFCID,QRCODE,PAPOINTID,UDXL,PAPOINTNAME,zs) k";
            } else if ("点检".equalsIgnoreCase(bm)) {
                where = " and to_char(p.END_TIME,'yyyy-MM-dd')>=to_char(sysdate,'yyyy-MM-dd') ) a ";
                sql = " select a.*,DownloadNUM.nextval as GROUP_SEQ from ( select '' as BARCODE ,'' TWOCODE ,p.TASK_TYPE as GROUP_ID , p.professional as GROUP_NAME ,   i.lc_in_no_p as NFCID , i.LC_XP_ID QRCODE,  a.PI_TASK_AREAid as PAPOINTID , p.TASK_NAME  UDXL,a.TASK_AREA_NAME as PAPOINTNAME ,  (select count(*) from PI_TASK_ITEM where  pi_task_no=p.num  and   pi_task_area_no=a.num  and BEGIN_TIME=p.BEGIN_TIME  and  END_TIME=p.END_TIME and PI_TASK_ITEM_RESULT is null) zs          FROM pi_task p , pi_task_area a ,PI_AREA i  where  p.NUM =a.PI_TASK_NO and a.NUM=i.NUM   and p.status!='已停检' and p.PI_POST_NO = '" + personid + "'" + " " + where;
            }

            System.out.println("personid:==" + personid + "--downloadPA_ROUTINE_GROUP-----orgid:" + orgid);
            System.out.println("downloadPA_ROUTINE_GROUP:" + sql);
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }
            if(sql==null){
                return runtimeGroup;
            }
            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();

            while(rst.next()) {
                Phone_PA_ROUTINE_GROUP obj = new Phone_PA_ROUTINE_GROUP();
                if ("点检".equalsIgnoreCase(bm)) {
                    obj.setGROUP_ID("点检");
                } else {
                    obj.setGROUP_ID(rst.getString("GROUP_ID"));
                }

                obj.setGROUP_NAME(rst.getString("UDXL"));
                obj.setGROUP_SEQ(rst.getString("GROUP_SEQ"));
                obj.setPAPOINTID(rst.getString("PAPOINTID"));
                obj.setPAPOINTNAME(rst.getString("PAPOINTNAME"));
                obj.setNFCID(rst.getString("NFCID"));
                obj.setTWOCODE(rst.getString("TWOCODE"));
                obj.setBARCODE(rst.getString("BARCODE"));
                obj.setQRCODE(rst.getString("QRCODE"));
                obj.setZs(rst.getString("zs"));
                runtimeGroup.add(obj);
            }
        } catch (SQLException var13) {
            this.closeAll(this.con, pst, rst);
            var13.printStackTrace();
        } finally {
            this.closeAll(this.con, pst, rst);
        }

        return runtimeGroup;
    }

    public String queryrw(String personid, String orgid) {
        String num = "'00'";
        ResultSet rst = null;
        PreparedStatement pst = null;
        String bm = this.selebm(personid, orgid);
        String where = " and  q.BEGIN_TIME <= CURRENT_DATE  and q.END_TIME >= CURRENT_DATE ";
        if ("巡检".equalsIgnoreCase(bm)) {
            where = " and  q.BEGIN_TIME>=to_date(''||to_char(sysdate,'yyyy-MM-dd')||' 00:00:00','yyyy-MM-dd HH24:mi:ss')  and  q.END_TIME <=to_date(''||to_char(sysdate+1,'yyyy-MM-dd')||' 01:00:00','yyyy-MM-dd HH24:mi:ss')";
        } else if ("点检".equalsIgnoreCase(bm)) {
            where = " and to_char(q.END_TIME,'yyyy-MM-dd')>=to_char(sysdate,'yyyy-MM-dd') ";
        }

        String sql = " select num,PI_POST_NO js from PI_TASK q where  q.orgid='" + orgid + "' and q.status!='已停检' and q.PI_POST_NO = '" + personid + "' " + where + " ";

        try {
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }

            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();
            int i = 1;

            while(rst.next()) {
                if (rst.getString("num") != null && !"".equalsIgnoreCase(rst.getString("num"))) {
                    if (i == 1) {
                        num = "'" + rst.getString("num") + "'";
                    } else {
                        num = num + ",'" + rst.getString("num") + "'";
                    }

                    ++i;
                }
            }
        } catch (SQLException var21) {
            var21.printStackTrace();

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

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

                if (pst != null) {
                    pst.close();
                }
            } catch (SQLException var19) {
                var19.printStackTrace();
            }

        }

        System.out.println("num:" + num + "----------");
        return num;
    }

    public synchronized List<Phone_PA_ROUTINE> downloadPA_ROUTINE(String personid, String orgid) {
        String num = this.queryrw(personid, orgid);
        ResultSet rst = null;
        PreparedStatement pst = null;
        String PAPOINTID = "PI_TASK_AREAID";
        String EQUIPID = "PI_TASK_DEVICEid";
        String ITEM_ID = "PI_TASK_ITEMID";
        String tjsql = " and I.PI_TASK_ITEM_RESULT is null";
        String wk = "";
        ArrayList runtime = new ArrayList();

        try {
            System.out.println("personid:==" + personid + "--downloadPA_ROUTINE-----orgid:" + orgid);
            String bm = this.selebm(personid, orgid);
            String where = " and  p.BEGIN_TIME <= CURRENT_DATE  and p.END_TIME >= CURRENT_DATE ";
            if ("巡检".equalsIgnoreCase(bm)) {
                where = " and  I.BEGIN_TIME>=to_date(''||to_char(sysdate,'yyyy-MM-dd')||' 00:00:00','yyyy-MM-dd HH24:mi:ss')  and  I.END_TIME <=to_date(''||to_char(sysdate+1,'yyyy-MM-dd')||' 01:00:00','yyyy-MM-dd HH24:mi:ss')";
                PAPOINTID = "num";
                EQUIPID = "num";
                ITEM_ID = "num";
                tjsql = "";
            } else if ("点检".equalsIgnoreCase(bm)) {
                where = " and to_char(I.END_TIME,'yyyy-MM-dd')>=to_char(sysdate,'yyyy-MM-dd') and I.PI_TASK_ITEM_RESULT is null ";
                tjsql = "";
                wk = " and PI_TASK_ITEM_RESULT is null";
            }

            String sql = "SELECT   (select u.RATE_DAY||(select DESCRIPTION ms from ALNDOMAIN where DOMAINID='TASK_RATETYPE' and value=u.RATE_TYPE)||'='||u.UDPL||'次'    from  PI_AREA_DEVICE p,UDPITASKZQ u  where p.UDPITASKNUM=u.UDPITASKNUM and  pi_area_no=D.pi_task_area_no  and num=D.num  and rownum=1)zq, (select count(*) from PI_TASK_ITEM where pi_task_no=p.num  and   pi_task_device_no=D.NUM and  pi_task_area_no=ar.num  and BEGIN_TIME=p.BEGIN_TIME and  END_TIME=p.END_TIME " + wk + ") sbsl," + " ar.LC_XP_ID QRCODE,I.SEQ AS ITEMSEQ,p.BEGIN_TIME,p.END_TIME,p.TASK_TYPE as GROUP_ID ,  p.professional as GROUP_NAME , a." + PAPOINTID + " AS PAPOINTID," + " ar.LC_IN_NO_P nfcid,D.ON_OFF_POTIN, p.TASK_NAME UDXL,a.TASK_AREA_NAME TASK_AREA_NAME, D." + EQUIPID + " AS EQUIPID, " + " I.HIGHER_LIMIT AS UPPERLIMIT,  I.LOWER_LIMIT AS LOWERLIMIT,  '' AS MAXINPUT,    '' AS MININPUT, I.POINT_UNIT AS UNIT,'' AS PROMPT, " + "d.TASK_DEVICE_NAME EQUIPNAME, I." + ITEM_ID + " AS ITEM_ID, I.DEVICE_PART_NAME AS ITEM_NAME,  '' AS TIMES, I.CHECK_METHOD AS ITEM_CHECK, 'BC' AS CYCLE_TYPE, " + "  I.POINT_TYPE AS ITEMTYPE, I.POINT_NORM AS ITEMGUIDE, I.PI_ITEM_DESCRIPTION AS ITEMDESC,   '' AS LASTTIME,  '' AS  NEXTTIME, '' AS EQRUNSTATU," + " '' as EQSTOPSTATU, '1' as EQSTATU,  i.num as EQSEQ, I.UDDJXM   FROM PI_TASK  P, PI_TASK_DEVICE   D,  PI_TASK_ITEM   I , PI_TASK_AREA   A" + " ,PI_AREA   ar WHERE  p.NUM =I.pi_task_no  and p.PI_POST_NO ='" + personid + "' " + " and p.status!='已停检' and  " + " P.NUM=A.PI_TASK_NO " + " and D.pi_task_no = P.NUM   and I.pi_task_no = P.NUM and D.NUM = I.PI_TASK_device_NO" + "  and A.NUM = D.PI_TASK_AREA_no  and D.PI_TASK_area_NO=I.PI_TASK_AREA_NO and a.NUM =ar.NUM and  p.orgid='" + orgid + "' " + " " + where + " and  D.pi_task_no =I.pi_task_no and I.pi_task_no in(" + num + ") " + tjsql;
            System.out.println(sql + "--------------------sql");
            if (this.con.isClosed()) {
                this.setCon(getDB2Conn());
            }

            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();
            String zq = null;
            String zhouqi = null;
            String cishu = null;

            while(rst.next()) {
                Phone_PA_ROUTINE obj = new Phone_PA_ROUTINE();
                obj.setITEMSEQ(rst.getString("ITEMSEQ"));
                obj.setPAPOINTID(rst.getString("PAPOINTID"));
                obj.setPAPOINTNAME(rst.getString("TASK_AREA_NAME"));
                obj.setSbsl(rst.getString("sbsl"));
                zq = rst.getString("zq");
                if (!"".equalsIgnoreCase(zq) && zq != null) {
                    zhouqi = zq.substring(0, zq.indexOf("="));
                    cishu = zq.substring(zq.indexOf("=") + 1);
                    obj.setZhouqi(zhouqi);
                    obj.setCishu(cishu);
                } else {
                    obj.setZhouqi("");
                    obj.setCishu("");
                }

                if ("点检".equalsIgnoreCase(bm)) {
                    obj.setGROUP_ID("点检");
                } else {
                    obj.setGROUP_ID(rst.getString("GROUP_ID"));
                }

                obj.setGROUP_NAME(rst.getString("UDXL"));
                obj.setNFCID(rst.getString("nfcid"));
                obj.setQRCODE(rst.getString("QRCODE"));
                obj.setEQUIPID(rst.getString("EQUIPID"));
                obj.setQTD_NUMBER("运行");
                obj.setUPPERLIMIT(rst.getString("UPPERLIMIT"));
                obj.setLOWERLIMIT(rst.getString("LOWERLIMIT"));
                obj.setMAXINPUT(rst.getString("MAXINPUT"));
                obj.setMININPUT(rst.getString("MININPUT"));
                obj.setUNIT(rst.getString("UNIT"));
                obj.setPROMPT(rst.getString("PROMPT"));
                obj.setEQUIPNAME(rst.getString("EQUIPNAME"));
                obj.setITEM_ID(rst.getString("ITEM_ID"));
                obj.setITEM_NAME(rst.getString("ITEM_NAME"));
                obj.setTIMES(rst.getString("TIMES"));
                obj.setITEM_CHECK(rst.getString("ITEM_CHECK"));
                obj.setCYCLE_TYPE(rst.getString("CYCLE_TYPE"));
                if ("点检".equalsIgnoreCase(bm)) {
                    obj.setCYCLE_TYPE("AC");
                    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                    obj.setEFFECTIVE_BEGINDATE(format.format(rst.getDate("BEGIN_TIME")));
                    obj.setEFFECTIVE_ENDDATE(format.format(rst.getDate("END_TIME")));
                } else {
                    obj.setCYCLE_TYPE(rst.getString("CYCLE_TYPE"));
                    obj.setEFFECTIVE_BEGINDATE(rst.getString("BEGIN_TIME"));
                    obj.setEFFECTIVE_ENDDATE(rst.getString("END_TIME"));
                }

                if ("GC,GZ".indexOf(rst.getString("ITEMTYPE")) <= -1 && !"".equalsIgnoreCase(rst.getString("ITEMTYPE"))) {
                    if ("JS".indexOf(rst.getString("ITEMTYPE")) > -1) {
                        obj.setITEMTYPE("1");
                        obj.setMANDATORY("1");
                        obj.setLeixi("记录类");
                    } else if ("PZ".indexOf(rst.getString("ITEMTYPE")) > -1) {
                        obj.setITEMTYPE("8");
                        obj.setMANDATORY("1");
                        obj.setLeixi("拍照类");
                    } else if ("CW".indexOf(rst.getString("ITEMTYPE")) > -1) {
                        obj.setITEMTYPE("5");
                        obj.setMANDATORY("1");
                        obj.setLeixi("测温类");
                    } else if ("CZ".indexOf(rst.getString("ITEMTYPE")) > -1) {
                        obj.setITEMTYPE("6");
                        obj.setMANDATORY("1");
                        obj.setLeixi("测振类");
                    } else {
                        obj.setITEMTYPE("1");
                        obj.setMANDATORY("1");
                        obj.setLeixi("其它类");
                    }
                } else {
                    obj.setITEMTYPE("7");
                    obj.setMANDATORY("");
                    obj.setLeixi("观察类");
                }

                obj.setITEMGUIDE(rst.getString("ITEMGUIDE"));
                obj.setITEMDESC(rst.getString("ITEMDESC"));
                obj.setLASTTIME(rst.getString("LASTTIME"));
                obj.setNEXTTIME(rst.getString("NEXTTIME"));
                obj.setEQSTATU(rst.getString("EQSTATU"));
                obj.setEQSEQ(rst.getString("EQSEQ"));
                obj.setFLAG("");
                runtime.add(obj);
            }

            System.out.println("num:" + num);
            if (!"00".equals(num)) {
                String sqlUpdate = "update  PI_TASK_AREA set STATUS='已到位' where pi_task_no in(" + num + ")";
                int result = this.executeUpdate(sqlUpdate);
                System.out.println("result:" + result);
            }
        } catch (SQLException var23) {
            this.closeAll(this.con, pst, rst);
            var23.printStackTrace();
        } finally {
            this.closeAll(this.con, pst, rst);
        }

        return runtime;
    }

    public synchronized Integer methodB(String strContent) {
        String doc = PropertiesConfigurerUtil.getProperty("docdata");
        int beg = strContent.indexOf("&US_CODE");
        int end = strContent.indexOf("&callback");
        String userid = strContent.substring(beg, end);
        String US_CODE = userid.substring(9, userid.length());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HHmmss");
        File file = new File(doc + sdf.format(new Date()) + "-" + US_CODE + ".txt");
        System.out.println(doc + sdf.format(new Date()) + "-" + US_CODE + ".txt===================");

        try {
            FileOutputStream outputStream = new FileOutputStream(file);
            outputStream.write(strContent.getBytes());
            outputStream.close();
        } catch (Exception var10) {
            var10.printStackTrace();
        }

        Thread a = new CustThread(strContent);
        a.start();
        System.out.println("this is class B method");
        return 1;
    }

    public synchronized Integer methodBls(String strContent) {
        String doc = PropertiesConfigurerUtil.getProperty("docdata");
        String sint = "insert into UDLSXJ(UDLSXJID,orgid,siteid,hasld,CHANGEBY,CHANGEDATE,CREATEBY,CREATEDATE,UDXJR,UDXJDATE,UDBSPID,UDBSPNAME,UDBZ,UDSFSM,UDXJGW) values(UDLSXJIDSEQ.NEXTVAL,'YXHBDC','YXDC')";
        int beg = strContent.indexOf("Submitter:");
        int end = strContent.indexOf(";submissionTime");
        System.out.println("strContent==" + strContent);
        String userid = strContent.substring(beg, end);
        String US_CODE = userid.substring(10, userid.length());
        String tjdate = strContent.substring(end + 16, strContent.length() - 1);
        System.out.println(userid + "====929=====" + US_CODE + "===" + tjdate);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        File file = new File(doc + sdf.format(new Date()) + "-" + US_CODE + "-ls.txt");
        System.out.println(doc + sdf.format(new Date()) + "-" + US_CODE + "-ls.txt===================");
        ArrayList list = new ArrayList();

        try {
            FileOutputStream outputStream = new FileOutputStream(file);
            outputStream.write(strContent.getBytes());
            outputStream.close();
            int endIndex = 0;
             endIndex = strContent.lastIndexOf(";Submitter:");
            strContent = strContent.substring(0, endIndex);
            String[] strs = strContent.split(";");
            String UDBZ = "";
            if (strs != null) {
                List<String> listsql = new ArrayList();
                int i = 1;
                String id = "";
                String[] var22 = strs;
                int var21 = strs.length;

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

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

                    if (str.length > 8) {
                        UDBZ = "'" + str[8] + "'";
                    } else {
                        UDBZ = "null";
                    }

                    sint = "insert into UDLSXJ(UDLSXJID,orgid,siteid,hasld,CHANGEBY,CHANGEDATE,CREATEBY,CREATEDATE,UDXJR,UDXJDATE,UDBSPID, UDBSPNAME,UDBZ,UDSFSM,UDXJGW) values (UDLSXJIDSEQ.NEXTVAL,'YXHBDC','YXDC',0,'" + US_CODE + "',sysdate,'" + US_CODE + "'," + " to_date('" + tjdate + "','yyyy-MM-dd hh24:mi:ss'),'" + str[0] + "'," + " to_date('" + str[7] + "','yyyy-MM-dd hh24:mi:ss'),'" + str[4] + "','" + str[5] + "'," + UDBZ + "," + str[6] + ",'" + str[2] + "')";
                    listsql.add(sint);
                }

                this.executeUpdateqy(listsql);
            }
        } catch (Exception var24) {
            var24.printStackTrace();
        }

        return 1;
    }

    public synchronized Integer UploadingPA_DATA(String strContent) {
        int beg = strContent.indexOf("&US_CODE");
        int end = strContent.indexOf("&UpdateDate");
        String userid = strContent.substring(beg, end);
        System.out.println("strContent======"+strContent);
        System.out.println("userid======"+userid);
        ResultSet rst = null;
        PreparedStatement pst = null;
        ResultSet rst1 = null;
        PreparedStatement pst1 = null;
        ResultSet rst2 = null;
        PreparedStatement pst2 = null;
        ResultSet rst3 = null;
        PreparedStatement pst3 = null;
        List<String[]> list = new ArrayList();
        Integer result = 0;
        int endIndex = 0;
         endIndex = strContent.lastIndexOf("&Company_ID");
        strContent = strContent.substring(0, endIndex);
        int k = 0;
        String[] strs = 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 = "0";
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(new Date());
            calendar.add(5, -1);
            Date datej = calendar.getTime();
            String ddate = format.format(new Date());
            String qdate = format.format(datej);
            String imid = null;
            String imsql = null;
            String zt = null;

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

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

                if (str[3].indexOf(ddate) <= -1 && str[3].indexOf(qdate) <= -1) {
                    d = 1;
                    result = 1;
                }

                sqlx = "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 NUM='" + str[0] + "' and BEGIN_TIME<=to_date('" + str[3] + "','yyyy-mm-dd hh24:mi:ss')" + " END_TIME>=to_date('" + str[3] + "','yyyy-mm-dd hh24:mi:ss')";
                if (!"".equalsIgnoreCase(str[0]) && str[0] != null) {
                    if (imid == null) {
                        imid = "'" + str[0] + "'";
                    } else {
                        imid = imid + ",'" + str[0] + "'";
                    }
                }

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

                System.out.println(str[4] + "============581============" + str[7]);
                String sql1 = " 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 b.NUM='" + str[0] + "' and b.BEGIN_TIME<=to_date('" + str[3] + "','yyyy-mm-dd hh24:mi:ss')" + " b.END_TIME>=to_date('" + str[3] + "','yyyy-mm-dd hh24:mi:ss') )";
                System.out.println("584:" + sql1);
                listqy.add(str[1]);
                listsql.add(sqlx);
                if ("0".equals(str[5])) {
                    zt = "运行";
                } else 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 = "停运";
                }

                sqlx = "  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 b.NUM='" + str[0] + "' and b.BEGIN_TIME<=to_date('" + str[3] + "','yyyy-mm-dd hh24:mi:ss')" + " b.END_TIME>=to_date('" + str[3] + "','yyyy-mm-dd hh24:mi:ss') ) ";
                listsql.add(sqlx);
                listsql.add(sql1);
            }

            String sql3;
            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 (!"".equalsIgnoreCase((String)listqy.get(j)) && listqy.get(j) != null) {
                        if ("0".equals(qyid)) {
                            qyid = "'" + (String)listqy.get(j) + "'";
                        } else {
                            qyid = qyid + ",'" + (String)listqy.get(j) + "'";
                        }
                    }
                }

                sql3 = "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(sql3);
            }

            if (d > 0) {
                this.executeUpdateqy(listsql);
            }

            if (i > 1 && d > 0) {
                try {
                    String sql = " select PI_TASK_NO from  PI_TASK_AREA where IS_UPLOAD=1 and  PI_TASK_AREAID in(" + qyid + ") group by PI_TASK_NO";
                    System.out.println("561sql:----" + sql);
                    if (this.con.isClosed()) {
                        this.setCon(getDB2Conn());
                    }

                    pst1 = this.con.prepareStatement(sql);
                    rst1 = pst1.executeQuery();

                    label501:
                    while(true) {
                        do {
                            do {
                                if (!rst1.next()) {
                                    this.executeUpdate((List)upqy);
                                    result = 1;
                                    break label501;
                                }
                            } while(rst1.getString("PI_TASK_NO") == null);
                        } while("".equalsIgnoreCase(rst1.getString("PI_TASK_NO")));

                        sql3 = " 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";
                        pst2 = this.con.prepareStatement(sql3);
                        rst2 = pst2.executeQuery();

                        while(rst2.next()) {
                            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+0.005),2)*100,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") + "' " + ",MISSED_RATE=trunc(to_number(cast(" + rst2.getInt("lj") + " as float)/(IGNORE_POINT-" + rst2.getInt("tjx") + ")+0.005),2)*100 " + " ,PI_RATE =trunc(to_number(cast(" + (rst2.getInt("yjd") + rst2.getInt("kjd")) + " as float)/(NORM_POINT-" + rst2.getInt("tj") + ")+0.005),2)*100" + " 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);
                        }
                    }
                } catch (Exception var51) {
                    this.closeAll(this.con, (PreparedStatement)pst, (ResultSet)rst);
                    this.closeAll((Connection)null, pst1, rst1);
                    this.closeAll((Connection)null, pst2, rst2);
                    var51.printStackTrace();
                } finally {
                    this.closeAll(this.con, (PreparedStatement)pst, (ResultSet)rst);
                    this.closeAll((Connection)null, pst1, rst1);
                    this.closeAll((Connection)null, pst2, rst2);
                }

                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 (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(sql3 = ""; rst3.next(); mm = 1) {
                        sql3 = " 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==" + sql3);
                        upqy.add(sql3);
                        sql3 = " update AUTOKEY set seed=seed+1 where AUTOKEYNAME='UDBUGNUMS' and orgid='YXHBDC'";
                        System.out.println("==============648==" + sql3);
                        upqy.add(sql3);
                    }

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

            System.out.println(result + "===============result=================");
        }

        return result;
    }

    public List<Phone_PA_ITEM_STATU> downloadPA_ITEM_STATU(String personid) {
        ResultSet rst = null;
        PreparedStatement pst = null;
        ArrayList runtimestatus = new ArrayList();

        try {
            String sql = "  select  i.NUM as ITEMID ,'' as FALUTID ,i.ON_OFF_POTIN as FALUTID_NAME  from   PI_TASK_ITEM i,PI_TASK_USER u where  i.pi_task_no=u.pi_task_no and u.personid= '" + personid + "'";
            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();
            System.out.println(sql);

            while(rst.next()) {
                Phone_PA_ITEM_STATU obj = new Phone_PA_ITEM_STATU();
                obj.setITEMID(rst.getString("ITEMID"));
                obj.setFALUTID(rst.getString("FALUTID"));
                obj.setFALUTID_NAME(rst.getString("FALUTID_NAME"));
                runtimestatus.add(obj);
            }
        } catch (SQLException var10) {
            this.closeAll(this.con, pst, rst);
            var10.printStackTrace();
        } finally {
            this.closeAll(this.con, pst, rst);
        }

        return runtimestatus;
    }

    public Phone_C_USER getUserinfo(String personid, String password) {
        ResultSet rst = null;
        PreparedStatement pst = null;
        Phone_C_USER ouser = new Phone_C_USER();

        try {
            String sql = "  select  personid US_CODE ,displayname US_NAME, locationorg US_COMPANY_ID from person where upper(personid) = upper('" + personid + "')";
            pst = this.con.prepareStatement(sql);
            rst = pst.executeQuery();

            while(rst.next()) {
                ouser.setROLEID((String)null);
                ouser.setUS_CODE(rst.getString("US_CODE"));
                ouser.setUS_NAME(rst.getString("US_NAME"));
                ouser.setUS_COMPANY_ID(rst.getString("US_COMPANY_ID"));
                ouser.setUS_PHONE_NUMBER((String)null);
//                ouser.setUS_PWD(password);
                ouser.setUS_PWD(null);
            }
        } catch (SQLException var10) {
            this.closeAll(this.con, pst, rst);
            var10.printStackTrace();
        } finally {
            this.closeAll(this.con, pst, rst);
        }

        return ouser;
    }

    public String uploadFileList(List<Attachment> attachments, HttpServletRequest request) {
        System.out.println("===="+attachments);
        String jg = "";
        String docu = PropertiesConfigurerUtil.getProperty("docu");
        String doc = PropertiesConfigurerUtil.getProperty("doc");
        List<String> listsql = new ArrayList();
        List<String> listtp = new ArrayList();
        String yh = null;
        String sjid = null;
        Map<String, String> danMaps = new HashMap();
        System.out.println(docu + "========================868" + doc);
        String value;
        String[] a;
        if (attachments.size() > 0) {
            Iterator var12 = attachments.iterator();

            label220:
            while(true) {
                while(true) {
                    if (!var12.hasNext()) {
                        break label220;
                    }

                    Attachment attach = (Attachment)var12.next();
                    DataHandler dh = attach.getDataHandler();
                    value = null;
                    String tpname = "";
                    System.out.println("1085---" + attach.getContentType().toString());
                    if (attach.getContentType().toString().contains("image")) {
                        try {
                            this.writeToFile(dh.getInputStream(), doc + dh.getName());
                            jg = "ok";
                            tpname = dh.getName();
                            listtp.add(tpname);
                            System.out.println("879===" + tpname);
                        } catch (IOException var28) {
                            var28.printStackTrace();
                        }
                    } else if (attach.getContentType().toString().contains("text/")) {
                        try {
                            value = this.writeToString(dh.getInputStream());
                            System.out.println(dh.getName() + " = " + value + "--------------------");
                            if ("UserCode".equalsIgnoreCase(dh.getName())) {
                                yh = value;
                            }

                            if ("Phone_PA_IMGDATA_Json".equalsIgnoreCase(dh.getName())) {
                                JSONArray resultArray = new JSONArray(value);
                                String tpjq = "";

                                for(int i = 0; i < resultArray.length(); ++i) {
                                    org.json.JSONObject resultObj = resultArray.optJSONObject(i);
                                    tpjq = resultObj.getString("IMGSRC");
                                    int kl = 0;
                                    if (tpjq.indexOf("~file") > -1) {
                                        a = tpjq.split("~");

                                        for(int j = 0; j < a.length; ++j) {
                                            kl = a[j].indexOf("/doc/");
                                            tpjq = a[j].substring(kl + 5);
                                            System.out.println("1062===============" + tpjq);
                                            danMaps.put(tpjq, resultObj.getString("iteminfoid") + "==" + resultObj.getString("SAVEDATE"));
                                        }
                                    } else {
                                        kl = tpjq.indexOf("/doc/");
                                        tpjq = tpjq.substring(kl + 5);
                                        danMaps.put(tpjq, resultObj.getString("iteminfoid") + "==" + resultObj.getString("SAVEDATE"));
                                    }

                                    System.out.println(tpjq + "======" + kl + "========" + resultObj.getString("iteminfoid") + "==" + resultObj.getString("SAVEDATE"));
                                }
                            }
                        } catch (Exception var30) {
                            var30.printStackTrace();
                        }
                    }
                }
            }
        }

        if ("ok".equalsIgnoreCase(jg)) {
            String inpsql = "";
            ResultSet rst = null;
            PreparedStatement pst = null;
            value = null;
            int k = 0;
            String sqlqf = "";
            for(int i = 0; i < listtp.size(); ++i) {
                try {
                    String sql = " select DOCINFOSEQ.NEXTVAL id,to_char(sysdate,'yyyyMMddhh24miss') sj from dual";
                    pst = this.con.prepareStatement(sql);
                    rst = pst.executeQuery();
                    int rowCount = 0;
                    String sj = "";
                    if (rst.next()) {
                        rowCount = rst.getInt("id");
                        sj = "XJ" + rst.getInt("id");
                    }

                    sjid = (String)danMaps.get(listtp.get(i));
                    System.out.println("======="+sjid);
                    a = sjid.split("==");
                    if (a[0].indexOf("JXM") > -1) {
                        sqlqf = " NUM='" + a[0] + "' and BEGIN_TIME<=to_date('" + a[1] + "','yyyy-mm-dd hh24:mi:ss')" + " and END_TIME >=to_date('" + a[1] + "','yyyy-mm-dd hh24:mi:ss')";
                    } else {
                        sqlqf = " PI_TASK_ITEMID=" + a[0];
                    }

                    inpsql = " insert into DOCINFO (DOCUMENT, DESCRIPTION, APPLICATION, STATUS, STATUSDATE, CREATEDATE, REVISION, CHANGEBY, CHANGEDATE, DOCLOCATION, DOCTYPE, CREATEBY, URLTYPE, DMSNAME, URLNAME, URLPARAM1, URLPARAM2, URLPARAM3, URLPARAM4, URLPARAM5, PRINTTHRULINKDFLT, USEDEFAULTFILEPATH, SHOW,  DOCINFOID, LANGCODE, HASLD, CONTENTUID) values ('" + sj + "', '" + (String)listtp.get(i) + "', null, null, null, sysdate, null, '" + yh + "'," + "  sysdate, null, 'Attachments', '" + yh + "', 'FILE', null," + " '" + docu + (String)listtp.get(i) + "', null, null, null, null, null, 1, 0, 0, " + rowCount + ", 'ZH', 0, '" + rowCount + "')";
                    listsql.add(inpsql);
                    System.out.println("6264==" + inpsql);
                    inpsql = " insert into DOCLINKS (DOCUMENT, OWNERTABLE, OWNERID, REFERENCE, DOCTYPE, DOCVERSION, GETLATESTVERSION,  CREATEBY, CREATEDATE, CHANGEBY, CHANGEDATE, PRINTTHRULINK, COPYLINKTOWO, DOCLINKSID, DOCINFOID) values ('" + sj + "', 'PI_TASK_ITEM', (select PI_TASK_ITEMID from PI_TASK_ITEM where " + sqlqf + "), null, 'Attachments', null, 1, '" + yh + "', sysdate, '" + yh + "', sysdate, 1, 0, DOCLINKSSEQ.NEXTVAL, " + rowCount + ")";
                    listsql.add(inpsql);
                    System.out.println("1182==" + inpsql);
                    k = 1;
                } catch (Exception var27) {
                    this.closeAll(this.con, pst, rst);
                    var27.getMessage();
                } finally {
                    if (i + 1 == listtp.size()) {
                        if (k > 0) {
                            this.executeUpdate((List)listsql);
                        }

                        this.closeAll(this.con, (PreparedStatement)null, (ResultSet)null);
                    } else {
                        this.closeAll((Connection)null, pst, rst);
                    }

                }
            }
        }

        return jg;
    }

    public String CreaUdbug(List<Attachment> attachments, HttpServletRequest request) {
        String jg = "";
        String cz = "";
        String docu = PropertiesConfigurerUtil.getProperty("docu");
        String doc = PropertiesConfigurerUtil.getProperty("doc");
        List<String> listsql = new ArrayList();
        List<String> listtp = new ArrayList();
        String yh = null;
        JSONArray resultArray = null;
        String pj = null;
        if (attachments.size() > 0) {
            Iterator var13 = attachments.iterator();

            while(var13.hasNext()) {
                Attachment attach = (Attachment)var13.next();
                DataHandler dh = attach.getDataHandler();
                String value = null;
                String tpname = "";
                if (attach.getContentType().toString().contains("image")) {
                    try {
                        this.writeToFile(dh.getInputStream(), doc + dh.getName());
                        jg = "ok";
                        tpname = dh.getName();
                        listtp.add(tpname);
                        System.out.println("1038===" + tpname);
                    } catch (IOException var53) {
                        var53.printStackTrace();
                    }
                } else if (attach.getContentType().toString().contains("text/")) {
                    try {
                        value = this.writeToString(dh.getInputStream());
                        System.out.println(dh.getName() + " = " + value + "--------------------");
                        if ("US_CODE".equalsIgnoreCase(dh.getName())) {
                            yh = value;
                        }

                        if ("Phone_CM_PL_PJO_Json".equalsIgnoreCase(dh.getName())) {
                            resultArray = new JSONArray(value);
                            cz = "CZ";
                        }

                        if ("strContent,Company_ID,strGroup,US_CODE,UpdateDate,PhoneID,RoleID".indexOf(dh.getName()) > -1) {
                            if ("strContent".indexOf(dh.getName()) > -1) {
                                pj = dh.getName() + "=" + value;
                            } else {
                                pj = pj + "&" + dh.getName() + "=" + value;
                            }
                        }
                    } catch (Exception var52) {
                        var52.printStackTrace();
                    }
                }
            }
        }

        System.out.println("====================1107======" + jg);
        if ("ok".equalsIgnoreCase(jg) || "CZ".equalsIgnoreCase(cz)) {
            String inpsql = "";
            ResultSet rst = null;
            PreparedStatement pst = null;
            ResultSet rs = null;
            Statement stmt = null;
            Connection conn = null;
            int k = 0;
            String tpjq = "";
            String tp = null;
            String lx = "SBUG";
            String kks = null;
            String bsp = null;
            String nfcid = null;
            int sl = 0;

            for(int i = 0; i < resultArray.length(); ++i) {
                try {
                    org.json.JSONObject resultObj = resultArray.optJSONObject(i);
                    if (!"".equalsIgnoreCase(resultObj.getString("CODEID")) && resultObj.getString("CODEID") != null) {
                        if ("2".equalsIgnoreCase(resultObj.getString("TYPE"))) {
                            lx = "BSP";
                            kks = "null";
                            bsp = "'" + resultObj.getString("EQUIPID") + "'";
                            nfcid = "(select LC_IN_NO_P from SA_LC_IN where LC_XP_ID=" + bsp + ")";
                            sl = this.selebsp(resultObj.getString("EQUIPID"), resultObj.getString("CREATEDATE"));
                        } else {
                            sl = 0;
                            lx = "SBUG";
                            bsp = "null";
                            nfcid = "null";
                            kks = "(select LOCATION from PI_TASK_DEVICE where num='" + resultObj.getString("EQUIPID") + "' and rownum=1)";
                        }

                        if (sl <= 0) {
                            String sql = " select UDBUGIDSEQ.NEXTVAL qxid from dual";
                            pst = this.con.prepareStatement(sql);
                            rst = pst.executeQuery();
                            int rowCount = 0;
                            String sj = "";
                            String qxid = "";
                            if (rst.next()) {
                                qxid = rst.getString("qxid");
                            }

                            inpsql = " insert into udbug (LC_IN_NO_P,LC_XP_ID,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 (" + nfcid + "," + bsp + "," + qxid + ", null, 'YXHBDC', 'YXDC', 0, '" + lx + "', null, null, null, null, null, '" + yh + "'," + " sysdate, null, null, null, null, null, 0, null, " + " " + kks + "," + " '" + resultObj.getString("XJ_CONTENT") + "'," + " null, null, null, '" + yh + "', (select DEPARTMENT from PERSON where PERSONID='" + yh + "'), " + "  to_date(to_char(to_date('" + resultObj.getString("CREATEDATE") + "','yyyy/MM/dd hh24:mi:ss'),'yyyy/MM/dd hh24:mi:ss'),'yyyy/MM/dd hh24:mi:ss')," + " 'DRAFT',sysdate, '草稿', (select seed+1 sd from AUTOKEY where AUTOKEYNAME='UDBUGNUMS' and orgid='YXHBDC'), null, null)";
                            System.out.println("1279===" + inpsql);
                            listsql.add(inpsql);
                            inpsql = " update AUTOKEY set seed=seed+1 where AUTOKEYNAME='UDBUGNUMS' and orgid='YXHBDC'";
                            listsql.add(inpsql);
                            if ("ok".equalsIgnoreCase(jg)) {
                                tpjq = resultObj.getString("PJOIMG");
                                String[] b = tpjq.split("~");
                                int kl = 0;

                                for(int j = 0; j < b.length; ++j) {
                                     kl = b[j].indexOf("/doc/");
                                    tp = b[j].substring(kl + 5);
                                    conn = JdbcUtil.getConn();
                                    stmt = conn.createStatement();
                                    String sql1 = " select DOCINFOSEQ.NEXTVAL id from dual";
                                    rs = stmt.executeQuery(sql1);
                                    if (rs.next()) {
                                        rowCount = rs.getInt("id");
                                        if ("2".equalsIgnoreCase(resultObj.getString("TYPE"))) {
                                            sj = "BSP" + rs.getInt("id");
                                        } else {
                                            sj = "QX" + rs.getInt("id");
                                        }
                                    }

                                    inpsql = " insert into DOCINFO (DOCUMENT, DESCRIPTION, APPLICATION, STATUS, STATUSDATE, CREATEDATE, REVISION, CHANGEBY, CHANGEDATE, DOCLOCATION, DOCTYPE, CREATEBY, URLTYPE, DMSNAME, URLNAME, URLPARAM1, URLPARAM2, URLPARAM3, URLPARAM4, URLPARAM5, PRINTTHRULINKDFLT, USEDEFAULTFILEPATH, SHOW,  DOCINFOID, LANGCODE, HASLD, CONTENTUID) values ('" + sj + "', '" + tp + "', null, null, null, sysdate, null, '" + yh + "'," + "  sysdate, null, 'Attachments', '" + yh + "', 'FILE', null," + " '" + docu + tp + "', null, null, null, null, null, 1, 0, 0, " + rowCount + ", 'ZH', 0, '" + rowCount + "')";
                                    listsql.add(inpsql);
                                    inpsql = " insert into DOCLINKS (DOCUMENT, OWNERTABLE, OWNERID, REFERENCE, DOCTYPE, DOCVERSION, GETLATESTVERSION,  CREATEBY, CREATEDATE, CHANGEBY, CHANGEDATE, PRINTTHRULINK, COPYLINKTOWO, DOCLINKSID, DOCINFOID) values ('" + sj + "', 'UDBUG', " + qxid + ", null, 'Attachments', null, 1, '" + yh + "', sysdate, '" + yh + "', sysdate, 1, 0, DOCLINKSSEQ.NEXTVAL, " + rowCount + ")";
                                    listsql.add(inpsql);
                                }
                            }

                            k = 1;
                        }
                    }
                } catch (Exception var54) {
                    this.closeAll(this.con, pst, rst);

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

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

                        if (conn != null) {
                            conn.close();
                        }
                    } catch (SQLException var51) {
                        var51.printStackTrace();
                    }

                    var54.printStackTrace();
                } finally {
                    System.out.println(i + 1 + "======1549======" + resultArray.length() + "===" + k);
                    if (i + 1 == resultArray.length()) {
                        if (k > 0) {
                            this.executeUpdate((List)listsql);
                            this.closeAll(this.con, (PreparedStatement)null, (ResultSet)null);
                        }

                        try {
                            if (conn != null) {
                                conn.close();
                            }
                        } catch (SQLException var50) {
                            var50.printStackTrace();
                        }
                    } else {
                        this.closeAll((Connection)null, pst, rst);

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

                            if (rs != null) {
                                rs.close();
                            }
                        } catch (SQLException var49) {
                            var49.printStackTrace();
                        }
                    }

                }
            }
        }

        if (!"".equalsIgnoreCase(pj) && pj != null) {
            System.out.println("1230==" + pj);
            this.con = getDB2Conn();
            Integer upload = this.methodB(pj);
            if (upload == 1) {
                jg = "ok";
            } else {
                jg = "no";
            }
        }

        return jg;
    }

    private String writeToString(InputStream ins) throws Exception {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] b = new byte[1024];
        boolean var4 = true;

        int i;
        while((i = ins.read(b)) != -1) {
            out.write(b, 0, i);
        }

        ins.close();
        return new String(out.toByteArray(), "UTF-8");
    }

    //写入文件
    private String  writeFile(DataHandler dh,String filepath,String filename) throws IOException {
        File uploadFile = new File(filepath);
        if (!uploadFile.exists()) {
            uploadFile.mkdir();//创建这个目录
        }
        String msg = null;
        File uploadFilename = new File(filepath + "\\" + filename);
        if(!uploadFilename.exists()){
            uploadFilename.createNewFile();
        }
        //=======================文件传输=====================
        //获得输入的流
        InputStream inputStream = dh.getInputStream();

        //创建一个文件输出流
        //realPath = 真实的文件夹
        //差了一个文件；加上输出文件的名字+"/"+uuidFileName
        FileOutputStream fos = new FileOutputStream(filepath + "/" + filename);

        //创建缓冲区
        byte[] buffer = new byte[1024 * 1024];

        //判断是否读取完毕
        int len = 0;
        //如果大于0说明还存在数据
        while ((len = inputStream.read(buffer)) > 0) {
            fos.write(buffer, 0, len);
        }

        //关闭流
        fos.close();
        inputStream.close();
        msg = "文件上传成功";
        return msg;
    }
    private void writeToFile(InputStream ins, String path) {
        FileOutputStream out = null;

        try {
            out = new FileOutputStream(new File(path));
            int read = 0;
            byte[] bytes = new byte[1024];


            while((read = ins.read(bytes)) != -1) {
                out.write(bytes, 0, read);
            }

            out.flush();
            out.close();
        } catch (FileNotFoundException var16) {
            var16.printStackTrace();
        } catch (IOException var17) {
            var17.printStackTrace();
        } finally {
            if (out != null) {
                try {
                    out.flush();
                    out.close();
                } catch (IOException var15) {
                    var15.printStackTrace();
                }
            }

        }

    }

    public synchronized void downloadPA_Createpitask(String personid, String orgid) {
        String sql = "select p.UDPITASKNUM,max(p.pi_area_no) pi_area_no, max(g.PI_TASKCFGID) PI_TASKCFGID,g.NUM,max(u.RATE_TYPE)RATE_TYPE ,max(u.RATE_DAY)RATE_DAY, max(p.RATE_EXECUTETIME)RATE_EXECUTETIME,max(u.MONDAY)MONDAY, max(u.TUESDAY)TUESDAY, max(u.WEDNESDAY)WEDNESDAY, max(u.THURSDAY)THURSDAY, max(u.FRIDAY)FRIDAY, max(u.SATURDAY)SATURDAY, max(u.SUNDAY)SUNDAY, max(g.PROFESSIONAL)PROFESSIONAL,max(g.TASK_TYPE)TASK_TYPE, max(g.TASK_NAME)TASK_NAME,max(g.ORGID)ORGID, max(g.SITEID)SITEID,max(p.NEXTDATE)NEXTDATE,max(g.PI_POST_NO)PI_POST_NO,max(u.UDPL)UDPL  from PI_AREA_DEVICE p,PI_TASKCFG_AREA a,PI_TASKCFG g,UDPITASKZQ u  where  p.udtj=0 and p.pi_area_no=a.num and a.pi_taskcfg_no=g.num and  p.UDPITASKNUM=u.UDPITASKNUM and g.PI_POST_NO='" + personid + "' and  p.UDPITASKNUM is not null and g.IS_ACTIVITY = 1 " + " and g.UDSFSD=0 and g.TASK_TYPE = '巡检' and (p.PRE_EXECUTE_DATE is null or p.PRE_EXECUTE_DATE <> '" + this.ymd.format(this.today) + "')" + "  group by  p.UDPITASKNUM ,g.NUM order by g.NUM,p.UDPITASKNUM";
        String[] columns = new String[]{"UDPITASKNUM", "pi_area_no", "PI_TASKCFGID", "NUM", "RATE_TYPE", "RATE_DAY", "RATE_EXECUTETIME", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY", "PROFESSIONAL", "TASK_TYPE", "TASK_NAME", "ORGID", "SITEID", "NEXTDATE", "PI_POST_NO", "UDPL"};
        List tasks = null;

        try {
            System.out.println("findActionTask:sql:" + sql);
            tasks = JdbcUtil.find(sql, columns);
            if (tasks == null || tasks.isEmpty()) {
                return;
            }

            boolean kk = false;

            Map task;
            for(Iterator var8 = tasks.iterator(); var8.hasNext(); this.rateTypeExecute(task)) {
                task = (Map)var8.next();
                if (kk) {
                    this.pzbh = (String)task.get("NUM");
                    this.zqbh = (String)task.get("UDPITASKNUM");
                    this.qybh = (String)task.get("pi_area_no");
                    this.xt = 0;
                } else if (task.get("NUM").equals(this.pzbh)&& task.get("UDPITASKNUM").equals(this.zqbh)) {
                    this.pzbh = (String)task.get("NUM");
                    this.zqbh = (String)task.get("UDPITASKNUM");
                    this.qybh = (String)task.get("pi_area_no");
                    this.xt = 1;
                } else {
                    this.pzbh = (String)task.get("NUM");
                    this.zqbh = (String)task.get("UDPITASKNUM");
                    this.qybh = (String)task.get("pi_area_no");
                    this.xt = 0;
                }
            }

            List<String> sqls = new ArrayList();
            Iterator rwpz = tasks.iterator();

            String rwpz1;
            while(rwpz.hasNext()) {
                Map<String, String> task1 = (Map)rwpz.next();
                System.out.println("进for");
                Integer execTimes = Integer.valueOf((String)task1.get("RATE_EXECUTETIME"));
                task1.put("RATE_EXECUTETIME", String.valueOf(execTimes + 1));
                task1.put("PRE_EXECUTE_DATE", this.ymd.format(this.today));
                System.out.println((String)task1.get("RATE_TYPE") + "-----------00000");
                task1.put("NEXTDATE", "null");
                System.out.println("today1:" + this.ymd.parse(this.ymd.format(this.today)));
                rwpz1 = " where UDPITASKNUM ='" + (String)task1.get("UDPITASKNUM") + "' and pi_area_no in(select num from PI_TASKCFG_AREA where pi_taskcfg_no='" + (String)task1.get("NUM") + "')";
                String nxdate = " ,NEXTDATE=null";
                String updateSql = "update PI_AREA_DEVICE set RATE_EXECUTETIME = (RATE_EXECUTETIME)+1,PRE_EXECUTE_DATE = '" + this.ymd.format(this.today) + "'" + " " + nxdate + " " + rwpz1;
                System.out.println("updateSql:" + updateSql);
                sqls.add(updateSql);
            }

            System.out.println("设置上一次执行时间" + sqls.size());
            JdbcUtil.executeBatch(sqls);
            List<String> sqlsbg = new ArrayList();
            if (this.bhlist.size() > 0) {
                rwpz = null;

                for(int i = 0; i < this.bhlist.size(); ++i) {
                    rwpz1 = " update PI_TASK set NORM_AREA=(select count(num) from PI_TASK_AREA where pi_task_no='" + (String)this.bhlist.get(i) + "')," + " NORM_POINT=(select count(num)  from PI_TASK_DEVICE where pi_task_no='" + (String)this.bhlist.get(i) + "') ," + " IGNORE_POINT=(select count(num) from PI_TASK_ITEM where pi_task_no='" + (String)this.bhlist.get(i) + "')  where num='" + (String)this.bhlist.get(i) + "'";;
                    sqlsbg.add(rwpz1);
                }

                JdbcUtil.executeBatch(sqlsbg);
            }
        } catch (Exception var15) {
            var15.printStackTrace();
        }

    }

    private void rateTypeExecute(Map<String, String> task) {
        System.out.println("rateTypeExecute---------------------");
        List<Map<String, String>> piTask = this.getTask(task);
        if (piTask != null) {
            this.insertTask(piTask);
        }

    }

    private List<Map<String, String>> getTask(Map<String, String> taskCfg) {
        System.out.println("getTask---------------------");
        String[] weekDays = new String[]{"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(new Date());
        cal1.add(5, 1);
        int w = cal1.get(7) - 1;
        if (w < 0) {
            w = 0;
        }

        Map<String, String> days = new HashMap();
        days.put("星期一", "MONDAY");
        days.put("星期二", "TUESDAY");
        days.put("星期三", "WEDNESDAY");
        days.put("星期四", "THURSDAY");
        days.put("星期五", "FRIDAY");
        days.put("星期六", "SATURDAY");
        days.put("星期日", "SUNDAY");
        String rateType = (String)taskCfg.get("RATE_TYPE");
        if ("day".equalsIgnoreCase(rateType)) {
            Integer executeTime = Integer.valueOf((String)taskCfg.get("RATE_EXECUTETIME"));
            Integer rateDay = Integer.valueOf((String)taskCfg.get("RATE_DAY"));
            if (executeTime % rateDay != 0) {
                return null;
            }
        }

        if ("zdzq".equalsIgnoreCase(rateType) && ((String)taskCfg.get(days.get(weekDays[w]))).equalsIgnoreCase("0")) {
            return null;
        } else {
            if ("month".equalsIgnoreCase(rateType) || "week".equalsIgnoreCase(rateType)) {
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                Date currentDate = new Date();
                Calendar cal = Calendar.getInstance();
                cal.setTime(currentDate);
                cal.add(5, 1);
                String dq = format.format(cal.getTime());
                if ("".equalsIgnoreCase((String)taskCfg.get("NEXTDATE")) || (String)taskCfg.get("NEXTDATE") == null) {
                    return null;
                }

                String nd = ((String)taskCfg.get("NEXTDATE")).substring(0, 10);
                if (!dq.equalsIgnoreCase(nd)) {
                    return null;
                }
            }

            List<Map<String, String>> result = new ArrayList();
            String sql = " select to_char(BEGIN_TIME,'hh24:mi:ss') BEGIN_TIME, to_char(END_TIME,'hh24:mi:ss') END_TIME from PI_DUTYTIME where UDPITASKNUM = '" + (String)taskCfg.get("UDPITASKNUM") + "' order by LINENUM ";

            try {
                List<Map<String, String>> duties = JdbcUtil.find(sql, new String[]{"BEGIN_TIME", "END_TIME"});
                Iterator var24 = duties.iterator();

                while(var24.hasNext()) {
                    Map<String, String> duty = (Map)var24.next();
                    Map<String, String> task = new HashMap();
                    Long begin = this.hms.parse((String)duty.get("BEGIN_TIME")).getTime();
                    Long end = this.hms.parse((String)duty.get("END_TIME")).getTime();
                    System.out.println("-------------------------------196");
                    if (begin != end) {
                        String beginStr;
                        String endStr;
                        if (begin > end) {
                            System.out.println((String)taskCfg.get("RATE_TYPE") + "========================201");
                            System.out.println("============================264");
                            beginStr = this.ymd.format(new Date(this.today.getTime() + 86400000L));
                            endStr = this.ymd.format(new Date(this.today.getTime() + 172800000L));
                            task.put("BEGIN_TIME", beginStr + " " + (String)duty.get("BEGIN_TIME"));
                            task.put("END_TIME", endStr + " " + (String)duty.get("END_TIME"));
                        } else {
                            beginStr = this.ymd.format(new Date(this.today.getTime() + 86400000L));
                            endStr = this.ymd.format(new Date(this.today.getTime() + 86400000L));
                            task.put("BEGIN_TIME", beginStr + " " + (String)duty.get("BEGIN_TIME"));
                            task.put("END_TIME", endStr + " " + (String)duty.get("END_TIME"));
                        }

                        task.put("UDPITASKNUM", (String)taskCfg.get("UDPITASKNUM"));
                        task.put("NUM", (String)taskCfg.get("NUM"));
                        task.put("RATE_TYPE", (String)taskCfg.get("RATE_TYPE"));
                        task.put("RATE_DAY", (String)taskCfg.get("RATE_DAY"));
                        task.put("RATE_EXECUTETIME", (String)taskCfg.get("RATE_EXECUTETIME"));
                        task.put("MONDAY", (String)taskCfg.get("MONDAY"));
                        task.put("TUESDAY", (String)taskCfg.get("TUESDAY"));
                        task.put("WEDNESDAY", (String)taskCfg.get("WEDNESDAY"));
                        task.put("THURSDAY", (String)taskCfg.get("THURSDAY"));
                        task.put("FRIDAY", (String)taskCfg.get("FRIDAY"));
                        task.put("SATURDAY", (String)taskCfg.get("SATURDAY"));
                        task.put("SATURDAY", (String)taskCfg.get("SATURDAY"));
                        task.put("PROFESSIONAL", (String)taskCfg.get("PROFESSIONAL"));
                        task.put("TASK_TYPE", (String)taskCfg.get("TASK_TYPE"));
                        task.put("TASK_NAME", (String)taskCfg.get("TASK_NAME"));
                        task.put("SITEID", (String)taskCfg.get("SITEID"));
                        task.put("ORGID", (String)taskCfg.get("ORGID"));
                        task.put("NEXTDATE", (String)taskCfg.get("NEXTDATE"));
                        task.put("PI_POST_NO", (String)taskCfg.get("PI_POST_NO"));
                        task.put("UDPL", (String)taskCfg.get("UDPL"));
                        System.out.println("siteid_map:" + (String)taskCfg.get("SITEID"));
                        System.out.println("orgid_map:" + (String)taskCfg.get("ORGID"));
                        result.add(task);
                    }
                }
            } catch (Exception var17) {
                var17.printStackTrace();
            }

            System.out.println("return-----------------:" + result.isEmpty());
            return result.isEmpty() ? null : result;
        }
    }

    private void insertTask(List<Map<String, String>> taskcfgs) {
        Iterator var3 = taskcfgs.iterator();

        while(var3.hasNext()) {
            Map<String, String> taskcfg = (Map)var3.next();
            Map<String, String> task = new HashMap();
            task.put("PI_TASKID", "PI_TASKIDSEQ.NEXTVAL");
            task.put("HASLD", "0");
            task.put("TASK_NAME", (String)taskcfg.get("TASK_NAME"));
            String sqla;
            String kssj;
            String zbsja;
            String zzdate;
            String rqdate;
            List duties2;
            Map duty;
            Iterator var15;
            if (!"month".equalsIgnoreCase((String)taskcfg.get("RATE_TYPE")) && !"week".equalsIgnoreCase((String)taskcfg.get("RATE_TYPE"))) {
                task.put("BEGIN_TIME", "isSentence:to_date('" + (String)taskcfg.get("BEGIN_TIME") + "','yyyy-MM-dd HH24:mi:ss')");
                task.put("END_TIME", "isSentence:to_date('" + (String)taskcfg.get("END_TIME") + "','yyyy-MM-dd HH24:mi:ss')");
            } else {
                sqla = " ";
                int zts = 7;
                int RATE_DAY = Integer.parseInt((String)taskcfg.get("RATE_DAY"));
                int UDPL = Integer.parseInt((String)taskcfg.get("UDPL"));
                kssj = ((String)taskcfg.get("NEXTDATE")).substring(0, 10);
                zbsja = ((String)taskcfg.get("NEXTDATE")).substring(0, 7);
                zzdate = "";
                rqdate = "";
                if ("week".equalsIgnoreCase((String)taskcfg.get("RATE_TYPE"))) {
                    int zts1 = zts * RATE_DAY - 1;
                    if (this.sl == 0) {
                        sqla = " select to_char(to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss'),'yyyy-MM-dd HH24:mi:ss') rq, " + " to_char((to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss')) +" + zts1 + ",'yyyy-MM-dd HH24:mi:ss') zz ," + " to_char(to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss'),'yyyy-MM-dd HH24:mi:ss')  ks," + " to_char(((to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss')+(" + zts1 + "*1)/" + UDPL + ")),'yyyy-MM-dd HH24:mi:ss') js " + "  from dual  ";
                    } else {
                        sqla = " select to_char(to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss'),'yyyy-MM-dd HH24:mi:ss') rq," + " to_char((to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss')) +" + zts1 + ",'yyyy-MM-dd HH24:mi:ss') zz ," + " to_char(((to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss')+(" + zts1 + "*" + this.sl + ")/" + UDPL + ")),'yyyy-MM-dd HH24:mi:ss') ks," + " to_char(((to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss')+(" + zts1 + "*(" + this.sl + "+1))/" + UDPL + ")),'yyyy-MM-dd HH24:mi:ss') js" + "  from dual ";
                    }
                } else if (this.sl == 0) {
                    sqla = " select to_char(to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss'),'yyyy-MM-dd HH24:mi:ss') rq, " + " to_char((to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss')) +((add_months(to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss')," + RATE_DAY + ")-1)-to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss')),'yyyy-MM-dd HH24:mi:ss') zz ," + " to_char(to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss'),'yyyy-MM-dd HH24:mi:ss')  ks," + " to_char(((to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss')+(((add_months(to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss')," + RATE_DAY + ")-1)-to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss'))*1)/" + UDPL + ")),'yyyy-MM-dd HH24:mi:ss') js " + "  from dual  ";
                } else {
                    sqla = " select to_char(to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss'),'yyyy-MM-dd HH24:mi:ss') rq," + " to_char((to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss')) +((add_months(to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss')," + RATE_DAY + ")-1)-to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss')),'yyyy-MM-dd HH24:mi:ss') zz ," + " to_char(((to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss')+(((add_months(to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss')," + RATE_DAY + ")-1)-to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss'))*" + this.sl + ")/" + UDPL + ")),'yyyy-MM-dd HH24:mi:ss') ks," + " to_char(((to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss')+(((add_months(to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss')," + RATE_DAY + ")-1)-to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss'))*(" + this.sl + "+1))/" + UDPL + ")),'yyyy-MM-dd HH24:mi:ss') js" + "  from dual ";
                }

                System.out.println("241=========" + sqla);

                try {
                    duties2 = JdbcUtil.find(sqla, new String[]{"rq", "zz", "ks", "js"});
                    var15 = duties2.iterator();

                    while(var15.hasNext()) {
                        duty = (Map)var15.next();
                        kssj = (String)duty.get("ks");
                        zbsja = (String)duty.get("js");
                        zzdate = (String)duty.get("zz");
                        rqdate = (String)duty.get("rq");
                        if (zzdate.equalsIgnoreCase(zbsja)) {
                            zbsja = zbsja.substring(0, 10);
                            zbsja = zbsja + " 23:59:59";
                        }

                        if (kssj.equalsIgnoreCase(rqdate)) {
                            kssj = kssj.substring(0, 10);
                            kssj = kssj + " 00:00:00";
                        }
                    }

                    System.out.println(kssj + "============260==============" + zbsja);
                    task.put("BEGIN_TIME", "isSentence:to_date('" + kssj + "','yyyy-MM-dd HH24:mi:ss')");
                    task.put("END_TIME", "isSentence:to_date('" + zbsja + "','yyyy-MM-dd HH24:mi:ss')");
                } catch (Exception var27) {
                    var27.printStackTrace();
                }
            }

            task.put("PROFESSIONAL", (String)taskcfg.get("PROFESSIONAL"));
            task.put("TASK_TYPE", (String)taskcfg.get("TASK_TYPE"));
            task.put("STATUS", "未上传结果");
            sqla = "  select to_char(to_date(ks,'HH24:mi'),'HH24:mi:ss') ks,to_char(to_date(js,'HH24:mi'),'HH24:mi:ss') js,bc,DEPARTMENT from ( select substr(value,0,instr(value,'-')-1) ks,substr(value,instr(value,'-')+1) js,value ,description bc, (select GWTYPE DEPARTMENT from PI_POST where NUM='" + (String)taskcfg.get("PI_POST_NO") + "') DEPARTMENT from " + " ALNDOMAIN where domainid='HDCYCSHIFT' and  value like '%:%' ) h";
            String ybsja = "";
            String ybsjb = "";
            String bbsja = "";
            kssj = "";
            zbsja = "";
            zzdate = "";
            rqdate = null;

            try {
                duties2 = JdbcUtil.find(sqla, new String[]{"ks", "js", "bc", "DEPARTMENT"});

                for(var15 = duties2.iterator(); var15.hasNext(); rqdate = (String)duty.get("DEPARTMENT")) {
                    duty = (Map)var15.next();
                    if ("夜班".equalsIgnoreCase((String)duty.get("bc"))) {
                        ybsja = (String)duty.get("ks");
                        ybsjb = (String)duty.get("js");
                    } else if ("白班".equalsIgnoreCase((String)duty.get("bc"))) {
                        bbsja = (String)duty.get("ks");
                        kssj = (String)duty.get("js");
                    } else if ("中班".equalsIgnoreCase((String)duty.get("bc"))) {
                        zbsja = (String)duty.get("ks");
                        zzdate = (String)duty.get("js");
                    }
                }
            } catch (Exception var28) {
                var28.printStackTrace();
            }

            String insertTask;
            if (!"".equalsIgnoreCase(rqdate) && rqdate != null && "巡检".equalsIgnoreCase(rqdate)) {
                insertTask = " select (select count(*) ye from dual where to_date('" + (String)taskcfg.get("BEGIN_TIME") + "','yyyy-MM-dd HH24:mi:ss')>=to_date(to_char(to_date('" + (String)taskcfg.get("BEGIN_TIME") + "','yyyy-MM-dd HH24:mi:ss') ,'yyyy-MM-dd')||' " + ybsja + "','yyyy-MM-dd HH24:mi:ss')" + " and to_date('" + (String)taskcfg.get("END_TIME") + "','yyyy-MM-dd HH24:mi:ss')<=to_date(to_char(to_date('" + (String)taskcfg.get("BEGIN_TIME") + "','yyyy-MM-dd HH24:mi:ss') ,'yyyy-MM-dd')||' " + ybsjb + "','yyyy-MM-dd HH24:mi:ss')) y," + " (select count(*) b from dual where to_date('" + (String)taskcfg.get("BEGIN_TIME") + "','yyyy-MM-dd HH24:mi:ss')>=to_date(to_char(to_date('" + (String)taskcfg.get("BEGIN_TIME") + "','yyyy-MM-dd HH24:mi:ss') ,'yyyy-MM-dd')||' " + bbsja + "','yyyy-MM-dd HH24:mi:ss')" + " and to_date('" + (String)taskcfg.get("END_TIME") + "','yyyy-MM-dd HH24:mi:ss')<=to_date(to_char(to_date('" + (String)taskcfg.get("BEGIN_TIME") + "','yyyy-MM-dd HH24:mi:ss') ,'yyyy-MM-dd')||' " + kssj + "','yyyy-MM-dd HH24:mi:ss')) b," + " (select count(*) z from dual where to_date('" + (String)taskcfg.get("BEGIN_TIME") + "','yyyy-MM-dd HH24:mi:ss')>=to_date(to_char(to_date('" + (String)taskcfg.get("BEGIN_TIME") + "','yyyy-MM-dd HH24:mi:ss') ,'yyyy-MM-dd')||' " + zbsja + "','yyyy-MM-dd HH24:mi:ss')" + " and to_date('" + (String)taskcfg.get("END_TIME") + "','yyyy-MM-dd HH24:mi:ss')<=to_date(to_char(to_date('" + (String)taskcfg.get("BEGIN_TIME") + "','yyyy-MM-dd HH24:mi:ss')+1 ,'yyyy-MM-dd')||' " + zzdate + "','yyyy-MM-dd HH24:mi:ss')) z," + " ( select d.SHIFTA||d.SHIFTB||d.SHIFTC from HDRUNCYCRULE h,HDRUNCYCRULELINE d where h.ACTIVE=1 and h.rulenum=d.rulenum and d.RULELINENUM in(" + "  select case when  regexp_like(b.s,'.([.])') then substr(b.s,instr(b.s,'.')+1) else '10' end s from (" + "  select RULELINENUM,RULECYCLE,STARTDATE,SHIFTA,SHIFTB,SHIFTC,to_char((sysdate+1),'yyyy/mm/dd') mt," + " to_date(to_char((sysdate+1),'yyyy/mm/dd'),'yyyy/mm/dd')-to_date(to_char(STARTDATE,'yyyy/mm/dd'),'yyyy/mm/dd') ts," + " ((to_date(to_char((sysdate+1),'yyyy/mm/dd'),'yyyy/mm/dd')-to_date(to_char(STARTDATE,'yyyy/mm/dd'),'yyyy/mm/dd'))+1)/RULECYCLE s" + " from HDRUNCYCRULE h,HDRUNCYCRULELINE d where h.ACTIVE=1 and h.rulenum=d.rulenum order by RULELINENUM asc) b where rownum=1)) m," + " (select DEPARTMENT from PI_POST where NUM='" + (String)taskcfg.get("PI_POST_NO") + "') DEPARTMENT" + " from dual ";
                System.out.println("271===" + insertTask);

                try {
                    List<Map<String, String>> duties = JdbcUtil.find(insertTask, new String[]{"y", "b", "z", "m", "DEPARTMENT"});
                    String y = null;
                    String b = null;
                    String z = null;
                    String udnight = null;
                    String udwhite = null;
                    String udinthe = null;

                    Map duty1;
                    for(Iterator var22 = duties.iterator(); var22.hasNext(); rqdate = (String)duty1.get("DEPARTMENT")) {
                        duty1 = (Map)var22.next();
                        y = (String)duty1.get("y");
                        b = (String)duty1.get("b");
                        z = (String)duty1.get("z");
                        udnight = ((String)duty1.get("m")).substring(0, 1);
                        udwhite = ((String)duty1.get("m")).substring(1, 2);
                        udinthe = ((String)duty1.get("m")).substring(2);
                    }

                    if ("1".equalsIgnoreCase(y)) {
                        task.put("UDZB", udnight);
                    } else if ("1".equalsIgnoreCase(b)) {
                        task.put("UDZB", udwhite);
                    } else if ("1".equalsIgnoreCase(z)) {
                        task.put("UDZB", udinthe);
                    }
                } catch (Exception var29) {
                    var29.printStackTrace();
                }
            }

            System.out.println("siteid_task:" + (String)taskcfg.get("SITEID"));
            System.out.println("orgid_task:" + (String)taskcfg.get("ORGID"));
            task.put("IS_ASSESSMENT", "1");
            task.put("PI_TASKCFG_NO", (String)taskcfg.get("NUM"));
            task.put("ISREPLACE", "0");
            task.put("SITEID", (String)taskcfg.get("SITEID"));
            task.put("ORGID", (String)taskcfg.get("ORGID"));
            task.put("NUM", "isSentence:(select (case when max(num) is null then 1 else max(num) + 1 end) from PI_TASK)");
            task.put("NORM_AREA", "0");
            task.put("REAL_AREA", "0");
            task.put("IN_PLACE_RATE", ".00");
            task.put("NORM_POINT", "0");
            task.put("REAL_POINT", "0");
            task.put("PI_RATE", ".00");
            task.put("MISSED_POINT", "0");
            task.put("MISSED_RATE", ".00");
            task.put("TJ_POINT", "0");
            task.put("YCD", "0");
            task.put("TJX", "0");
            task.put("PI_POST_NO", (String)taskcfg.get("PI_POST_NO"));
            task.put("IGNORE_POINT", "0");
            insertTask = JdbcUtil.insertSentence(task, "PI_TASK");

            try {
                JdbcUtil.execute(insertTask);
                String findTaskMaxNum = "select * from PI_TASK where PI_TASKID = (select max(PI_TASKID) from PI_TASK)";
                Map<String, String> pi_task = JdbcUtil.findOne(findTaskMaxNum, new String[]{"PI_TASKID", "NUM", "UDXL", "BEGIN_TIME", "END_TIME"});
                task.put("PI_TASKID", (String)pi_task.get("PI_TASKID"));
                task.put("NUM", (String)pi_task.get("NUM"));
                task.put("UDXL", (String)pi_task.get("UDXL"));
                task.put("BEGIN_TIME", (String)pi_task.get("BEGIN_TIME"));
                task.put("END_TIME", (String)pi_task.get("END_TIME"));
                this.insertPost(task);
                this.rwbh = (String)pi_task.get("NUM");
                this.bhlist.add((String)pi_task.get("NUM"));
                this.insertArea(task);
            } catch (Exception var26) {
                var26.printStackTrace();
            }
        }

    }

    private void insertPost(Map<String, String> task) {
        String postCfgSql = "select PI_USERID,DESCRIPTION,HASLD,PERSONID,DISPLAYNAME,PI_POST_NO,PI_POST_NO,ORGID,SITEID from PI_USER where PI_POST_NO = '" + (String)task.get("PI_POST_NO") + "'";
        String[] columns = new String[]{"PI_USERID", "DESCRIPTION", "HASLD", "PERSONID", "DISPLAYNAME", "PI_POST_NO", "PI_POST_NO", "ORGID", "SITEID"};

        try {
            List<Map<String, String>> posts = JdbcUtil.find(postCfgSql, columns);
            if (posts != null && !posts.isEmpty()) {
                List<String> insertPosts = new ArrayList();
                Iterator var7 = posts.iterator();

                String updateSql;
                while(var7.hasNext()) {
                    Map<String, String> post = (Map)var7.next();
                    Map<String, String> map = new HashMap();
                    map.put("PI_TASK_USERID", "PI_TASK_USERIDSEQ.NEXTVAL");
                    map.put("HASLD", "0");
                    map.put("PERSONID", (String)post.get("PERSONID"));
                    map.put("DISPLAYNAME", (String)post.get("DISPLAYNAME"));
                    map.put("PI_POST_NO", (String)post.get("PI_POST_NO"));
                    map.put("DOWNLOAD_USER", "0");
                    map.put("PI_TASK_NO", (String)task.get("NUM"));
                    map.put("SITEID", (String)task.get("SITEID"));
                    map.put("ORGID", (String)task.get("ORGID"));
                    updateSql = JdbcUtil.insertSentence(map, "PI_TASK_USER");
                    insertPosts.add(updateSql);
                }

                Map<String, String> updateTask = new HashMap();
                updateTask.put("PI_POST_NO", (String)((Map)posts.get(0)).get("PI_POST_NO"));
                String where = " where PI_TASKID = " + (String)task.get("PI_TASKID");
                updateSql = JdbcUtil.updateSentence(updateTask, "PI_TASK", where);
                insertPosts.add(updateSql);
                JdbcUtil.executeBatch(insertPosts);
            }
        } catch (Exception var10) {
            var10.printStackTrace();
        }

    }

    private void insertArea(Map<String, String> task) {
        String findAreasSql = "select * from PI_TASKCFG_AREA where PI_TASKCFG_NO = '" + (String)task.get("PI_TASKCFG_NO") + "'  and  num in(select a.num from PI_AREA_DEVICE p," + "PI_TASKCFG_AREA a,PI_TASKCFG g,UDPITASKZQ u  where " + " p.udtj=0 and p.pi_area_no=a.num and a.pi_taskcfg_no=g.num and  p.UDPITASKNUM=u.UDPITASKNUM and  p.UDPITASKNUM is not null and g.IS_ACTIVITY = 1 " + " and g.UDSFSD=0 and g.TASK_TYPE = '巡检'  and p.UDPITASKNUM='" + this.zqbh + "' and g.num='" + this.pzbh + "'  group by a.num) ";
        String[] columns = new String[]{"PI_TASKCFG_AREAID", "TASK_AREA_NAME", "IS_BATCH", "PROFESSIONAL", "PI_RFID_NO", "PI_TASKCFG_NO", "SEQ", "RFID_CODE", "RFID_NO", "NUM", "TYPE", "SITEID", "ORGID", "LC_XP_ID", "UDXL"};
        System.out.println("insertArea===="+findAreasSql);
        try {
            List<Map<String, String>> cfgAreas = JdbcUtil.findNullToEmpty(findAreasSql, columns);
            if (cfgAreas != null && !cfgAreas.isEmpty()) {
                Iterator var6 = cfgAreas.iterator();

                while(var6.hasNext()) {
                    Map<String, String> cfgArea = (Map)var6.next();
                    Map<String, String> obj = new HashMap();
                    obj.put("PI_TASK_AREAID", "PI_TASK_AREAIDSEQ.NEXTVAL");
                    obj.put("HASLD", "0");
                    obj.put("TASK_AREA_NAME", (String)cfgArea.get("TASK_AREA_NAME"));
                    obj.put("IS_BATCH", (String)cfgArea.get("IS_BATCH"));
                    obj.put("PROFESSIONAL", (String)cfgArea.get("PROFESSIONAL"));
                    obj.put("PI_RFID_NO", (String)cfgArea.get("PI_RFID_NO"));
                    obj.put("PI_TASK_NO", this.rwbh);
                    obj.put("SEQ", (String)cfgArea.get("SEQ"));
                    obj.put("RFID_CODE", (String)cfgArea.get("RFID_CODE"));
                    obj.put("RFID_NO", (String)cfgArea.get("RFID_NO"));
                    obj.put("NUM", (String)cfgArea.get("NUM"));
                    obj.put("TYPE", (String)cfgArea.get("TYPE"));
                    obj.put("STATUS", "未到位");
                    obj.put("ORGID", (String)cfgArea.get("ORGID"));
                    obj.put("SITEID", (String)cfgArea.get("SITEID"));
                    obj.put("LC_XP_ID", (String)cfgArea.get("LC_XP_ID"));
                    obj.put("IS_UPLOAD", "0");
                    obj.put("UDSFSM", "0");
                    obj.put("UDXL", (String)cfgArea.get("UDXL"));
                    String sql = JdbcUtil.insertSentence(obj, "PI_TASK_AREA");
                    System.out.println(sql);
                    JdbcUtil.execute(sql);
                    this.insertDevice(cfgArea, task);
                }
            }
        } catch (Exception var9) {
            var9.printStackTrace();
        }

    }

    private void insertDevice(Map<String, String> areaCfg, Map<String, String> task) {
        String findDeviceSql = "select p.* from PI_AREA_DEVICE p,PI_TASKCFG_AREA a,PI_TASKCFG g,UDPITASKZQ u  where p.udtj=0 and\t p.pi_area_no=a.num and a.pi_taskcfg_no=g.num and  p.UDPITASKNUM=u.UDPITASKNUM and  p.UDPITASKNUM is not null and g.IS_ACTIVITY = 1   and g.UDSFSD=0 and g.TASK_TYPE = '巡检'  and p.PI_AREA_NO ='" + (String)areaCfg.get("NUM") + "' and p.UDPITASKNUM='" + this.zqbh + "' and g.num='" + this.pzbh + "'" + " and (p.pi_area_no,p.num) not in(select qynum,sbnum from  PI_SBQTDATE  where to_char(sysdate+1,'yyyy/MM/dd')>=to_char(UDKSDATE,'yyyy/MM/dd')" + " and  to_char(sysdate+1,'yyyy/MM/dd')<=to_char(JZDATE,'yyyy/MM/dd') and ON_OFF_POTIN  in('备用','停运'))";
        String[] columns = new String[]{"PI_AREA_DEVICEID", "DEVICE_NAME", "IS_BATCH", "LOCATION", "NO", "NUM", "ORGID", "PI_AREA_NO", "SEQ", "SITEID", "TYPE", "HASLD", "ON_OFF_POTIN", "JZDATE", "UDKSDATE"};

        try {
            List<Map<String, String>> cfgDevices = JdbcUtil.findNullToEmpty(findDeviceSql, columns);
            if (cfgDevices != null) {
                List<String> sqls = new ArrayList();
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                Date currentDate = new Date();
                Calendar cal = Calendar.getInstance();
                cal.setTime(currentDate);
                cal.add(5, 1);
                String dq = format.format(cal.getTime());
                Iterator var12 = cfgDevices.iterator();

                List<Map> cfgDevice = new ArrayList<Map>();
                while(var12.hasNext()) {
                    Map cfgDevice1 = (Map) var12.next();
                    cfgDevice.add(cfgDevice1);
                    Map<String, String> obj = new HashMap();
                    obj.put("PI_TASK_DEVICEID", "PI_TASK_DEVICEIDSEQ.NEXTVAL");
                    obj.put("HASLD", (String)cfgDevice1.get("HASLD"));
                    obj.put("NO", (String)cfgDevice1.get("NO"));
                    obj.put("TASK_DEVICE_NAME", (String)cfgDevice1.get("DEVICE_NAME"));
                    obj.put("LOCATION", (String)cfgDevice1.get("LOCATION"));
                    obj.put("IS_BATCH", (String)cfgDevice1.get("IS_BATCH"));
                    obj.put("PI_AREA_NO", (String)cfgDevice1.get("PI_AREA_NO"));
                    obj.put("SEQ", (String)cfgDevice1.get("SEQ"));
                    obj.put("PI_TASK_AREA_NO", (String)cfgDevice1.get("PI_AREA_NO"));
                    obj.put("NUM", (String)cfgDevice1.get("NUM"));
                    obj.put("TYPE", (String)cfgDevice1.get("TYPE"));
                    obj.put("PI_TASK_NO", this.rwbh);
                    obj.put("SITEID", (String)cfgDevice1.get("SITEID"));
                    obj.put("ORGID", (String)cfgDevice1.get("ORGID"));
                    String sql;
                    if (!"".equalsIgnoreCase((String)cfgDevice1.get("JZDATE")) && (String)cfgDevice1.get("JZDATE") != null && !"".equalsIgnoreCase((String)cfgDevice1.get("UDKSDATE")) && (String)cfgDevice1.get("UDKSDATE") != null) {
                        sql = ((String)cfgDevice1.get("JZDATE")).substring(0, 10);
                        String ks = ((String)cfgDevice1.get("UDKSDATE")).substring(0, 10);
                        int res = dq.compareTo(sql);
                        int kss = dq.compareTo(ks);
                        System.out.println(res + "======" + dq + "===" + sql);
                        if (kss >= 0 && res <= 0) {
                            obj.put("ON_OFF_POTIN", (String)cfgDevice1.get("ON_OFF_POTIN"));
                        } else {
                            obj.put("ON_OFF_POTIN", "运行");
                        }
                    } else {
                        obj.put("ON_OFF_POTIN", "运行");
                    }

                    sql = JdbcUtil.insertSentence(obj, "PI_TASK_DEVICE");
                    sqls.add(sql);

                }

                JdbcUtil.executeBatch(sqls);
                var12 = cfgDevices.iterator();

                while(var12.hasNext()) {
                    this.insertItem((Map)var12.next(), task);
                }
            }
        } catch (Exception var18) {
            var18.printStackTrace();
        }

    }

    private void insertItem(Map<String, String> cfgDevice, Map<String, String> task) {
        String findItemSql = "select * from PI_AREA_ITEM where PI_AREA_DEVICE_NO = '" + (String)cfgDevice.get("NUM") + "' and pi_area_no='" + (String)cfgDevice.get("PI_AREA_NO") + "'";
        String[] columns = new String[]{"PI_AREA_ITEMID", "CHECK_METHOD", "DEVICE_PART_NAME", "HIGHER_LIMIT", "ISPCHECK", "LOWER_LIMIT", "NO", "NUM", "ON_OFF_POTIN", "ORGID", "PI_AREA_DEVICE_NO", "PI_AREA_NO", "PI_ITEM_DESCRIPTION", "POINT_NORM", "POINT_TYPE", "POINT_UNIT", "SEQ", "SHAKE_TYPE", "SITEID", "TYPE", "HASLD", "UDDJXM"};
        try {
            List<Map<String, String>> cfgItems = JdbcUtil.findNullToEmpty(findItemSql, columns);
            String ks = "";
            String js = "";
            if (cfgItems != null) {
                List<String> sqls = new ArrayList();
                Iterator var10 = cfgItems.iterator();

                while(var10.hasNext()) {
                    Map<String, String> cfgItem = (Map)var10.next();
                    Map<String, String> obj = new HashMap();
                    obj.put("PI_TASK_ITEMID", "PI_TASK_ITEMIDSEQ.NEXTVAL");
                    obj.put("HASLD", (String)cfgItem.get("HASLD"));
                    obj.put("POINT_TYPE", (String)cfgItem.get("POINT_TYPE"));
                    obj.put("NO", (String)cfgItem.get("NO"));
                    obj.put("DEVICE_PART_NAME", (String)cfgItem.get("DEVICE_PART_NAME"));
                    obj.put("HIGHER_LIMIT", (String)cfgItem.get("HIGHER_LIMIT"));
                    obj.put("POINT_UNIT", (String)cfgItem.get("POINT_UNIT"));
                    obj.put("LOWER_LIMIT", (String)cfgItem.get("LOWER_LIMIT"));
                    obj.put("ON_OFF_POTIN", (String)cfgItem.get("ON_OFF_POTIN"));
                    obj.put("CHECK_METHOD", (String)cfgItem.get("CHECK_METHOD"));
                    obj.put("SHAKE_TYPE", (String)cfgItem.get("SHAKE_TYPE"));
                    obj.put("PI_AREA_DEVICE_NO", (String)cfgItem.get("PI_AREA_DEVICE_NO"));
                    obj.put("SEQ", (String)cfgItem.get("SEQ"));
                    obj.put("PI_TASK_DEVICE_NO", (String)cfgDevice.get("NUM"));
                    obj.put("POINT_NORM", (String)cfgItem.get("POINT_NORM"));
                    obj.put("IS_EXCESSIVE", "0");
                    obj.put("PI_ITEM_DESCRIPTION", (String)cfgItem.get("PI_ITEM_DESCRIPTION"));
                    obj.put("TYPE", (String)cfgItem.get("TYPE"));
                    obj.put("NUM", (String)cfgItem.get("NUM"));
                    obj.put("PI_TASK_NO", this.rwbh);
                    ks = (String)task.get("BEGIN_TIME");
                    js = (String)task.get("END_TIME");
                    obj.put("BEGIN_TIME", "isSentence:to_date('" + ks + "','yyyy-MM-dd HH24:mi:ss')");
                    obj.put("END_TIME", "isSentence:to_date('" + js + "','yyyy-MM-dd HH24:mi:ss')");
                    obj.put("ISPCHECK", (String)cfgItem.get("ISPCHECK"));
                    obj.put("PI_TASK_AREA_NO", (String)cfgItem.get("PI_AREA_NO"));
                    obj.put("PI_DEVICE_NAME", (String)cfgItem.get("DEVICE_PART_NAME"));
                    obj.put("SITEID", (String)cfgItem.get("SITEID"));
                    obj.put("ORGID", (String)cfgItem.get("ORGID"));
                    obj.put("UDDJXM", (String)cfgItem.get("UDDJXM"));
                    String sql = JdbcUtil.insertSentence(obj, "PI_TASK_ITEM");
                    sql = sql.replace(":00.0", ":00");
                    sqls.add(sql);
                }

                JdbcUtil.executeBatch(sqls);
            }
        } catch (Exception var13) {
            var13.printStackTrace();
        }

    }

}
