package com.trs.web2frame.tool.tyjyh.wcmhy01_lcj.add;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.trs.web2frame.tool.tyjyh.ConnectionUtil;
import com.trs.web2frame.util.Log_Exception;

public class ServiceImpl {
    private String sqlType = "oracle";

    /**
     * 插入结果
     * @param object2 
     * @param object 
     * @param object3 
     * 
     * @throws SQLException
     */
    public Boolean InsertResult(Integer wcmrecid, Integer hyrecid, Integer zwrecid, String object, String object2, String object3) throws SQLException {
        Connection connection=null;
        Statement statement =null;
        try {
            if (wcmrecid == null) {
                return false;
            }
            StringBuilder sb = new StringBuilder(
                    "INSERT INTO NW_RESULT(WCMRECID,HYRECID,ZWRECID,TITLE,PUBDATE,CRTIME) VALUES(" + wcmrecid + "," + hyrecid + "," + zwrecid + ",'" + object + "','" + object2 +"','" + object3 +"'  )");
            connection = ConnectionUtil.getConnection(sqlType);
            statement = connection.createStatement();
            int count = statement.executeUpdate(sb.toString());
            // ResultSet rs = statement.getResultSet();
            // ConnectionUtil.closeConnection(rs, statement, connection);
            
            if (count != 1) {
                return false;
            } else {
                return true;
            }
        } catch (Exception e) {
            // TODO: handle exception
            Log_Exception.Error_txt("InsertResult 方法异常！" + e.getMessage());
            return false;
        }
        finally{
            if (statement != null) {
                statement.close();
            }
            if (connection != null) {
                connection.close();
            }
        }

    }

    /**
     * 更新结果
     * 
     * @param wcmrecid
     * @param hyrecid
     * @param zwrecid
     * @return
     * @throws SQLException
     */
    public Boolean UpdateResult(Integer wcmrecid, Integer hyrecid, Integer zwrecid) throws SQLException {
        Connection connection=null;
        Statement statement =null;
        try {
            if(wcmrecid==null){
                return false;
            }
            StringBuilder sb=new StringBuilder("UPDATE NW_RESULT SET HYRECID="+hyrecid+",ZWRECID="+zwrecid+" WHERE WCMRECID="+wcmrecid);
            connection = ConnectionUtil.getConnection(sqlType);
            statement = connection.createStatement();
            int count = statement.executeUpdate(sb.toString());
           
            if(count!=1){
                return false;
            }else{
                return true;
            }
        } catch (Exception e) {
            //TODO: handle exception
            Log_Exception.Error_txt("UpdateResult 方法异常！"+e.getMessage());
            return false;
        }
        finally{
            if(statement!=null){
                statement.close();
            }
            if(connection!=null){
                connection.close();
            }
        }
        
    }
    public Boolean Updatehyrecid(Integer wcmrecid,Integer hyrecid) throws SQLException {
        Connection connection=null;
        Statement statement =null;
        try {
            if(wcmrecid==null){
                return false;
            }
            StringBuilder sb=new StringBuilder("UPDATE NW_RESULT SET HYRECID="+hyrecid+" WHERE WCMRECID="+wcmrecid);
            connection = ConnectionUtil.getConnection(sqlType);
            statement = connection.createStatement();
            int count = statement.executeUpdate(sb.toString());
           
            if(count!=1){
                return false;
            }else{
                return true;
            }
        } catch (Exception e) {
            //TODO: handle exception
            Log_Exception.Error_txt("Updatehyrecid 方法异常！"+e.getMessage());
            return false;
        }
        finally{
            if(statement!=null){
                statement.close();
            }
            if(connection!=null){
                connection.close();
            }
        }
        
    }
    /**
     * 获取结果信息
     * @param wcmrecid
     * @return
     */
    public Map<String,Object> GetResultInfo(Integer wcmrecid){
        Map<String,Object> map=new HashMap<>();
        try {
            if(wcmrecid!=null){
                StringBuilder sb=new StringBuilder("SELECT * FROM NW_RESULT WHERE WCMRECID="+wcmrecid);
                Connection connection = ConnectionUtil.getConnection(sqlType);
                Statement statement = connection.createStatement();
                ResultSet set = statement.executeQuery(sb.toString());
                while (set.next()){
                    map.put("wcmrecid", set.getString("WCMRECID"));//文档记录ID
                    map.put("hyrecid", set.getString("HYRECID"));//文档记录ID
                    map.put("zwrecid", set.getString("ZWRECID"));//文档记录ID
                }
                ConnectionUtil.closeConnection(set, statement, connection);
                return map;
            }else{
                return null;
            }
        } catch (Exception e) {
            //TODO: handle exception
            Log_Exception.Error_txt("GetResultInfo方法异常！"+e.getMessage());
            return null;
        }
        
    }
    /**
     * 插入错误信息
     * 
     * @throws SQLException
     */
    public Boolean InsertLogMessageInfo(Integer wcmrecid, String docTitle, String logMessage) throws SQLException {
        Connection connection=null;
        Statement statement =null;
        try {
            if (wcmrecid == null) {
                return false;
            }
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式
            String timeNow = df.format(new Date()).toString();
            StringBuilder sb = new StringBuilder(
                    "INSERT INTO LOGMESSAGEINFO(WCMRECID,DOCTITLEINFO,MESSAGEINFO,RETIME) VALUES(" + wcmrecid + ",'" + docTitle + "','" + logMessage + "','"+timeNow+"')");
            connection = ConnectionUtil.getConnection(sqlType);
            statement = connection.createStatement();
            int count = statement.executeUpdate(sb.toString());
            // ResultSet rs = statement.getResultSet();
            // ConnectionUtil.closeConnection(rs, statement, connection);
            
            if (count != 1) {
                return false;
            } else {
                return true;
            }
        } catch (Exception e) {
            // TODO: handle exception
            Log_Exception.Error_txt("InsertLogMessageInfo 方法异常！" + e.getMessage());
            return false;
        }
        finally{
            if (statement != null) {
                statement.close();
            }
            if (connection != null) {
                connection.close();
            }
        }

    }

    /**
     * 更新错误信息
     * 
     */
    public Boolean UpdateLogMessageInfo(Integer wcmrecid, String logMessage) throws SQLException {
        Connection connection=null;
        Statement statement =null;
        try {
            if(wcmrecid==null){
                return false;
            }
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式
            String timeNow = df.format(new Date()).toString();
            StringBuilder sb=new StringBuilder("UPDATE LOGMESSAGEINFO SET MESSAGEINFO='"+logMessage+"',RETIME='"+timeNow+"' WHERE WCMRECID="+wcmrecid);
            connection = ConnectionUtil.getConnection(sqlType);
            statement = connection.createStatement();
            int count = statement.executeUpdate(sb.toString());
           
            if(count!=1){
                return false;
            }else{
                return true;
            }
        } catch (Exception e) {
            //TODO: handle exception
            Log_Exception.Error_txt("UpdateLogMessageInfo 方法异常！"+e.getMessage());
            return false;
        }
        finally{
            if(statement!=null){
                statement.close();
            }
            if(connection!=null){
                connection.close();
            }
        }
        
    }

    /**
     * 根据原文档记录id获取迁移错误信息
     * @param wcmrecid
     * @return
     */
    public Map<String,Object> GetLogMessageInfo(Integer wcmrecid){
        Map<String,Object> map=new HashMap<>();
        try {
            if(wcmrecid!=null){
                StringBuilder sb=new StringBuilder("SELECT WCMRECID,DOCTITLEINFO,MESSAGEINFO,RETIME from LOGMESSAGEINFO WHERE WCMRECID="+wcmrecid);
                Connection connection = ConnectionUtil.getConnection(sqlType);
                Statement statement = connection.createStatement();
                ResultSet set = statement.executeQuery(sb.toString());
                while (set.next()){
                    map.put("wcmrecid", set.getString("WCMRECID"));//文档记录ID
                    //map.put("DOCTITLEINFO", set.getString("DOCTITLEINFO"));//
                    //map.put("MESSAGEINFO", set.getString("MESSAGEINFO"));//
                    //map.put("RETIME", set.getString("RETIME"));
                }
                ConnectionUtil.closeConnection(set, statement, connection);
                return map;
            }else{
                return null;
            }
        } catch (Exception e) {
            //TODO: handle exception
            Log_Exception.Error_txt("GetLogMessageInfo方法异常！"+e.getMessage());
            return null;
        }
        
    }

    
    
    /**
     * 从老库查出该栏目下所有信息
     * @param channelId 
     * @return
     */
    public List<Map<String,Object>> GetAllDocInfoFromOldDB(String channelId){
        List<Map<String, Object>> oldMaps = new ArrayList<>();
        String conditions=" AND  wcd.crtime>'2021-07-21 00:00:00.000' ";
//      conditions=" AND  wm.crtime>'2020/5/15 23:12:04'  ";
        try {
            StringBuilder sb=new StringBuilder("SELECT wcd.RECID,wcd.CHNLID,wcd.DOCCHANNEL,wcd.POSCHNLID,wcd.DOCID,wcd.MODAL, w.DOCTYPE,w.DOCTITLE,w.DOCCONTENT,w.DOCHTMLCON,"
            +"w.DOCABSTRACT,w.DOCKEYWORDS,w.DOCPEOPLE,w.DOCAUTHOR,w.DOCAUDITOR,w.DOCPLACE,"
            +"w.DOCPUBTIME,w.DOCRELTIME,w.CRTIME,w.DOCWORDSCOUNT,w.SUBDOCTITLE,"
            +" w.DOCSOURCENAME,w.DOCPUBURL,w.DOCFILENAME,w.DOCLINK,w.DOCLINKTO,w.TITLECOLOR,"
            +" WM.IDXID,WM.ABOLIDATE,WM.ACESMTHD,WM.\"CONTENT\",WM.DESCRIPTION,WM.EFECTDATE,WM.FILENUM,WM.KEYWORDS,WM.MDUPDTIME,WM.ORGANCAT,WM.PLACEKEY"
            +",WM.PUBDATE,WM.PUBLISHER,WM.RIDXID,WM.RTITLE,WM.SEARCHCONTENT,WM.SUBCAT,WM.SVOBJCAT,WM.THEMECAT,WM.TITLE"
            +" FROM WCMCHNLDOC wcd LEFT JOIN WCMDOCUMENT w ON WCD.DOCID=w.DOCID"
            +" LEFT JOIN WCMMETATABLEGOVINFO WM ON W.DOCID = WM.METADATAID WHERE  WCD.SITEID=6 AND wcd.CHNLID="+channelId+ conditions+" ORDER BY wcd.DOCORDER ");//WCD.DOCSTATUS=10 AND
            //,wd.TOPLINE,wd.ZCFGHY,wd.ZCFGJB,wd.JZSJ,wd.DDBS,wd.YT,wd.VIDEO_FILE AND wcd.SITEID=4
            Connection connection = ConnectionUtil.getConnection("sqlserver");
            Statement statement = connection.createStatement();
            ResultSet set = statement.executeQuery(sb.toString());
            int i = 1;
            while (set.next()){
                Map<String, Object> map = new HashMap<>();
                map.put("RECID", set.getString("RECID"));//文档记录ID
                map.put("MODAL", set.getString("MODAL"));//引用类型

                

                map.put("DOCID", set.getString("DOCID"));
                map.put("DOCTYPE",set.getString("DOCTYPE"));
                map.put("DOCTITLE",set.getString("DOCTITLE"));
                map.put("DOCCONTENT",set.getString("DOCCONTENT"));
                map.put("DOCHTMLCON",set.getString("DOCHTMLCON"));
                map.put("DOCABSTRACT",set.getString("DOCABSTRACT"));
                map.put("DOCAUDITOR",set.getString("DOCAUDITOR"));
                map.put("DOCKEYWORDS",set.getString("DOCKEYWORDS"));
                map.put("DOCPEOPLE",set.getString("DOCPEOPLE"));
                map.put("DOCPLACE",set.getString("DOCPLACE"));
                map.put("DOCAUTHOR",set.getString("DOCAUTHOR"));
                map.put("DOCRELTIME",set.getString("DOCRELTIME"));
                map.put("CRTIME",set.getString("CRTIME"));
                map.put("SUBDOCTITLE",set.getString("SUBDOCTITLE"));
                map.put("DOCSOURCENAME",set.getString("DOCSOURCENAME"));
                map.put("DOCFILENAME",set.getString("DOCFILENAME"));
                map.put("DOCLINK",set.getString("DOCLINK"));
                map.put("DOCLINKTO",set.getString("DOCLINKTO"));
               // map.put("EDITOR",set.getString("EDITOR"));
                map.put("TITLECOLOR",set.getString("TITLECOLOR"));
                
                map.put("IDXID", set.getString("IDXID"));
                map.put("CONTENT", set.getString("CONTENT"));
                map.put("DESCRIPTION", set.getString("DESCRIPTION"));
                map.put("TITLE", set.getString("TITLE"));
                map.put("FILENUM", set.getString("FILENUM"));
                map.put("PUBDATE", set.getString("PUBDATE"));
                map.put("PUBLISHER", set.getString("PUBLISHER"));
                map.put("ORGANCAT", set.getString("ORGANCAT"));
                map.put("MDUPDTIME", set.getString("MDUPDTIME"));
                map.put("ACESMTHD", set.getString("ACESMTHD"));
                map.put("SUBCAT", set.getString("SUBCAT"));
                map.put("ABOLIDATE", set.getString("ABOLIDATE"));
                map.put("EFECTDATE", set.getString("EFECTDATE"));
                map.put("KEYWORDS", set.getString("KEYWORDS"));
                map.put("PLACEKEY", set.getString("PLACEKEY"));
                map.put("RIDXID", set.getString("RIDXID"));
                map.put("RTITLE", set.getString("RTITLE"));
                map.put("SEARCHCONTENT", set.getString("SEARCHCONTENT"));
                map.put("SVOBJCAT", set.getString("SVOBJCAT"));
                map.put("THEMECAT", set.getString("THEMECAT"));
                System.out.println("第"+i+++"篇");
                                            
                oldMaps.add(map);

            }
            ConnectionUtil.closeConnection(set, statement, connection);
            return oldMaps;
        } catch (Exception e) {
            //TODO: handle exception
            Log_Exception.Error_txt("GetAllDocInfoFromOldDB()方法异常"+e.getMessage());
            return null;
        }
    }

    /**
     * 找出当前栏目下所有需要被引用的文档信息
     * @param channelId
     * @return
     */
    public List<Map<String,Object>> GetAllDocNeedQueto(String channelId){
        List<Map<String,Object>> listMap=new ArrayList<>();
        try {
            StringBuilder sb=new StringBuilder("SELECT wcd.RECID,wcd.DOCID,W.DOCTITLE,wcd.MODAL,nc.NEWCHANELID FROM wcmchnldoc wcd LEFT JOIN WCMDOCUMENT W ON W.DOCID=WCD.DOCID "+
            " LEFT JOIN CHANELRELATION_TEST nc ON wcd.CHNLID=nc.OLDCHANELID WHERE MODAL!=1 AND wcd.DOCSTATUS=10 AND wcd.SITEID=8 AND wcd.CHNLID="+channelId+" ORDER BY wcd.DOCORDER");
            Connection connection = ConnectionUtil.getConnection(sqlType);
            Statement statement = connection.createStatement();
            ResultSet set = statement.executeQuery(sb.toString());
            while (set.next()){
                Map<String,Object> map=new HashMap<>();
                map.put("WCM_RECID", set.getString("RECID"));
                map.put("WCM_DOCID", set.getString("DOCID"));
                map.put("HY_newchanelid", set.getString("NEWCHANELID"));
                map.put("WCM_MODAL", set.getString("MODAL"));
                map.put("WCM_DOCTITLE", set.getString("DOCTITLE"));
                listMap.add(map);
            }
            ConnectionUtil.closeConnection(set, statement, connection);
            return listMap;
        } catch (Exception e) {
            //TODO: handle exception
            Log_Exception.Error_txt("GetAllNeedQueto()方法异常"+e.getMessage());
            return null;
        }
       
    }
    /**
     * 根据文档DocID获取最新的海云中的recID
     * @param wcmDocId
     * @return
     */
    public String GetHyRecId(String wcmDocId){
        String HyRecId="";
        try {
            StringBuilder sb=new StringBuilder("SELECT nr.HYRECID FROM NW_RESULT nr LEFT JOIN wcmchnldoc wcd ON nr.WCMRECID=wcd.RECID WHERE wcd.MODAL=1 AND wcd.DOCID="+wcmDocId);
            Connection connection = ConnectionUtil.getConnection(sqlType);
            Statement statement = connection.createStatement();
            ResultSet set = statement.executeQuery(sb.toString());
            while (set.next()){
                HyRecId=set.getString("HYRECID");
            }
            ConnectionUtil.closeConnection(set, statement, connection);
            return HyRecId;
        } catch (Exception e) {
            //TODO: handle exception
            Log_Exception.Error_txt("GetAllNeedQueto()方法异常"+e.getMessage());
            return null;
        }
    }

    /**
     * 获取该栏目下所有需要重新排序的引用文档
     * @param channelId
     * @return
     */
    public List<Map<String,Object>> GetDocsNeedChangeOrder(String channelId){
        List<Map<String,Object>> listMap=new ArrayList<>();
        try {
            StringBuilder sb=new StringBuilder("SELECT wcd.RECID,wcd.DOCID,nc.NEWCHANELID,nr.HYRECID,nr.ZWRECID FROM wcmchnldoc wcd  LEFT JOIN CHANELRELATION_TEST nc "
            +" ON wcd.CHNLID=nc.OLDCHANELID LEFT JOIN NW_RESULT nr ON wcd.RECID=nr.WCMRECID WHERE  wcd.MODAL!=1 AND wcd.DOCSTATUS=10 AND wcd.SITEID=8 AND wcd.CHNLID="+channelId+" ORDER BY wcd.DOCORDER");
            Connection connection = ConnectionUtil.getConnection(sqlType);
            Statement statement = connection.createStatement();
            ResultSet set = statement.executeQuery(sb.toString());
            while (set.next()){
                Map<String,Object> map=new HashMap<>();
                map.put("WCM_RECID", set.getString("RECID"));
                map.put("WCM_DOCID", set.getString("DOCID"));
                map.put("HY_newchanelid", set.getString("NEWCHANELID"));
                map.put("hyrecid", set.getString("HYRECID"));
                map.put("zwrecid", set.getString("ZWRECID"));
                listMap.add(map);
            }
            ConnectionUtil.closeConnection(set, statement, connection);
            return listMap;
        } catch (Exception e) {
            //TODO: handle exception
            Log_Exception.Error_txt("GetNeedChangeOrder()方法异常"+e.getMessage());
            return null;
        }

        
    }
    	/**
	 * 根据文档获取附件信息集合
	 * @param docId
	 * @return
	 * @throws Exception
	 */
	public List<Map<String,Object>> GetFilesInfoByDocId (String docId) throws Exception{
		StringBuilder sb = new StringBuilder("SELECT w.SRCFILE,w.APPFILE,w.APPDESC,w.APPFLAG FROM wcmappendix w where w.APPDOCID="+docId);
		List<Map<String,Object>> list = new ArrayList();
		Connection connection = ConnectionUtil.getConnection(sqlType);
		//Connection connection = ConnectionUtil.getConnection("mysql");
		Statement statement = connection.createStatement();
		ResultSet set = statement.executeQuery(sb.toString());
		
		while (set.next()) {
			Map<String,Object> map=new HashMap<>();
			map.put("SRCFILE", set.getString("SRCFILE"));
			map.put("APPFILE", set.getString("APPFILE"));
			map.put("APPDESC", set.getString("APPDESC"));
			map.put("APPFLAG", set.getString("APPFLAG"));
			list.add(map);
		}
		ConnectionUtil.closeConnection(set, statement, connection);
		return list;
    }
    
    /**
	 * 根据文档id获取关联文档信息
	 * @param docId
	 * @return
	 * @throws Exception
	 */
	public List<Map<String,Object>> queryRelations(String docId) throws Exception{
		List<Map<String,Object>> list=new ArrayList<>();
		StringBuilder sb = new StringBuilder("SELECT WR.CHANNELID,WR.RELDOCID,(SELECT CR.NEWCHANELID FROM CHANELRELATION_TEST cr WHERE CR.OLDCHANELID=WR.CHANNELID ) AS NEWCHANNELID,w.DOCTITLE,w.DOCRELTIME FROM WCMRELATION WR LEFT JOIN WCMDOCUMENT w ON WR.RELDOCID=w.DOCID WHERE 1=1 AND WR.DOCID="+docId+" ORDER BY w.CRTIME DESC");
		Connection connection = ConnectionUtil.getConnection(sqlType);
		//Connection connection = ConnectionUtil.getConnection("mysql");
		Statement statement = connection.createStatement();
		ResultSet set = statement.executeQuery(sb.toString());
		while (set.next()) {
			Map<String,Object> map=new HashMap<>();
			map.put("RELDOCID",set.getString("RELDOCID"));
			map.put("DOCTITLE", set.getString("DOCTITLE"));
			map.put("CHANNELID", set.getString("CHANNELID"));
			map.put("NEWCHANNELID", set.getString("NEWCHANNELID"));
			map.put("DOCRELTIME", set.getString("DOCRELTIME"));

			list.add(map);
		}
		ConnectionUtil.closeConnection(set, statement, connection);
		return list;
	}



    	/**
	 * 获取新旧栏目关系
	 */
	public List<Map<String,Object>> queryChanelRelation() throws Exception{
		List<Map<String,Object>> list = new ArrayList();
		StringBuilder sb = new StringBuilder("select t.channelid as newchanelid,t.chnlname,wc.CHANNELID as oldchanelid,wc.CHNLNAME from temp_new_chnl t\r\n" + 
				"left join WCMCHANNEL wc on t.chnlname=wc.CHNLNAME\r\n" + 
				"where wc.SITEID=6  and wc.CHANNELID in(\r\n" + 
				"1234,\r\n" + 
				"1263,\r\n" + 
				"1549,\r\n" + 
				"1555,\r\n" + 
				"1291,\r\n" + 
				"1240,\r\n" + 
				"1277,\r\n" + 
				"1563,\r\n" + 
				"1346,\r\n" + 
				"1294,\r\n" + 
				"1243,\r\n" + 
				"1274,\r\n" + 
				"1558,\r\n" + 
				"1249,\r\n" + 
				"1246,\r\n" + 
				"1338,\r\n" + 
				"1295,\r\n" + 
				"1238,\r\n" + 
				"1232,\r\n" + 
				"1352,\r\n" + 
				"1235,\r\n" + 
				"1358,\r\n" + 
				"1252,\r\n" + 
				"1550,\r\n" + 
				"1272,\r\n" + 
				"1266,\r\n" + 
				"1278,\r\n" + 
				"1253,\r\n" + 
				"1293,\r\n" + 
				"1244,\r\n" + 
				"1287,\r\n" + 
				"1233,\r\n" + 
				"1264,\r\n" + 
				"1559,\r\n" + 
				"1310,\r\n" + 
				"1270,\r\n" + 
				"1556,\r\n" + 
				"1290,\r\n" + 
				"1236,\r\n" + 
				"1359,\r\n" + 
				"1222,\r\n" + 
				"1248,\r\n" + 
				"1242,\r\n" + 
				"1548,\r\n" + 
				"1348,\r\n" + 
				"1554,\r\n" + 
				"1219,\r\n" + 
				"1268,\r\n" + 
				"1276,\r\n" + 
				"1239\r\n" + 
				") ORDER BY wc.CHANNELID\r\n" + 
				"");
		Connection connection = ConnectionUtil.getConnection("sqlserver");
		//Connection connection = ConnectionUtil.getConnection("mysql");
		Statement statement = connection.createStatement();
		ResultSet set = statement.executeQuery(sb.toString());
		while (set.next()) {
			Map<String,Object> map=new HashMap<>();
			map.put("oldchanelid", set.getString("OLDCHANELID"));
			map.put("newchanelid", set.getString("NEWCHANELID"));
			list.add(map);
		}
		ConnectionUtil.closeConnection(set, statement, connection);
		return list;
    }
    /**
     * 获取栏目关系
     * @param channelId
     * @return
     * @throws Exception
     */
    public String GetNewChannelId(String channelId)throws Exception{
        String NEWCHANNELID="";
        StringBuilder sb = new StringBuilder("SELECT NEWCHANNELID FROM OLDNEWCHANNEL WHERE OLDCHANNELID="+channelId);
		Connection connection = ConnectionUtil.getConnection(sqlType);
		//Connection connection = ConnectionUtil.getConnection("mysql");
		Statement statement = connection.createStatement();
		ResultSet set = statement.executeQuery(sb.toString());
		while (set.next()) {
			NEWCHANNELID=set.getString("NEWCHANNELID");
		}
		ConnectionUtil.closeConnection(set, statement, connection);
		return NEWCHANNELID;
    }
	/**
	 * 替换分类
	 */
	public String queryClassRelation(String classoldId) throws Exception{
		String classnewId="";
		if(classoldId!=null&&!classoldId.equals("")){
			StringBuilder sb = new StringBuilder("SELECT CLASSNEWID FROM SZF_CLASSRELATION WHERE CLASSOLDID="+classoldId);
			//StringBuilder sb = new StringBuilder("select * from zjw_chanelRelation_yw where ishad ='0' order by id");
			Connection connection = ConnectionUtil.getConnection(sqlType);
			//Connection connection = ConnectionUtil.getConnection("mysql");
			Statement statement = connection.createStatement();
			ResultSet set = statement.executeQuery(sb.toString());
			while (set.next()) {
				
				classnewId=set.getString("CLASSNEWID");
				
			}
			ConnectionUtil.closeConnection(set, statement, connection);
			return classnewId;
		}else{
			return classnewId;
		}
		
	}
    	/**
	 * 替换分类
	 */
	public Map<String,Object> queryZhuTiClassRelation(String classoldId) throws Exception{
		Map<String,Object> classInfoMap=new HashMap<>();
		if(classoldId!=null&&!classoldId.equals("")){
			StringBuilder sb = new StringBuilder("SELECT CLASSNEWID,CLASSOLDID FROM SZF_CLASSRELATIONNEWOLD WHERE CLASSID="+classoldId);
			//StringBuilder sb = new StringBuilder("select * from zjw_chanelRelation_yw where ishad ='0' order by id");
			Connection connection = ConnectionUtil.getConnection(sqlType);
			//Connection connection = ConnectionUtil.getConnection("mysql");
			Statement statement = connection.createStatement();
			ResultSet set = statement.executeQuery(sb.toString());
			while (set.next()) {
				
				//classnewId=set.getString("CLASSNEWID");
				classInfoMap.put("CLASSNEWID", set.getString("CLASSNEWID"));
				classInfoMap.put("CLASSOLDID", set.getString("CLASSOLDID"));
				
			}
			ConnectionUtil.closeConnection(set, statement, connection);
			return classInfoMap;
		}else{
			return null;
		}
		
    }
    
   /**
	 * 根据调整好的分类获取该分类的对应新分类
	 */
	public String queryOldNewClass(String classoldId) throws Exception{
		String classnewId="";
		if(classoldId!=null&&!classoldId.equals("")){
			StringBuilder sb = new StringBuilder("SELECT NEWCLASSID FROM OLDNEWCLASS WHERE OLDCLASSID="+classoldId);
			//StringBuilder sb = new StringBuilder("select * from zjw_chanelRelation_yw where ishad ='0' order by id");
			Connection connection = ConnectionUtil.getConnection(sqlType);
			//Connection connection = ConnectionUtil.getConnection("mysql");
			Statement statement = connection.createStatement();
			ResultSet set = statement.executeQuery(sb.toString());
			while (set.next()) {
				
				classnewId=set.getString("NEWCLASSID");
				
			}
			ConnectionUtil.closeConnection(set, statement, connection);
			return classnewId;
		}else{
			return classnewId;
		}
		
    }
    
    public String queryWZIDByWCMDocID(String DocID)throws Exception{
        String classnewId="";
		if(DocID!=null&&!DocID.equals("")){
            StringBuilder sb = new StringBuilder("SELECT WZINFO FROM DOCCLASSINFOBAK WHERE WCMDOCID="+DocID);
			//StringBuilder sb = new StringBuilder("select * from zjw_chanelRelation_yw where ishad ='0' order by id");
			Connection connection = ConnectionUtil.getConnection(sqlType);
			//Connection connection = ConnectionUtil.getConnection("mysql");
			Statement statement = connection.createStatement();
			ResultSet set = statement.executeQuery(sb.toString());
			while (set.next()) {
				
				classnewId=set.getString("WZINFO");
				
			}
			ConnectionUtil.closeConnection(set, statement, connection);
			return classnewId;
		}else{
			return classnewId;
		}
    }

    public String queryBELONGCLASSByWCMDocID(String DocID)throws Exception{
        String classnewId="";
		if(DocID!=null&&!DocID.equals("")){
            StringBuilder sb = new StringBuilder("SELECT BELONGCLASS FROM DOCCLASSINFOBAK WHERE WCMDOCID="+DocID);
			//StringBuilder sb = new StringBuilder("select * from zjw_chanelRelation_yw where ishad ='0' order by id");
			Connection connection = ConnectionUtil.getConnection(sqlType);
			//Connection connection = ConnectionUtil.getConnection("mysql");
			Statement statement = connection.createStatement();
			ResultSet set = statement.executeQuery(sb.toString());
			while (set.next()) {
				
				classnewId=set.getString("BELONGCLASS");
				
			}
			ConnectionUtil.closeConnection(set, statement, connection);
			return classnewId;
		}else{
			return classnewId;
		}
    }
    
    
    /**
     * 获取结果信息
     * @param object 
     * @param wcmrecid
     * @return
     */
    public Boolean GetNWResultInfo(Object title,Object pubtime, Object object){
        Map<String,Object> map=new HashMap<>();
        try {
        	title = title.toString().replace("\"", "");
        	title = title.toString().replace("\'", "");
        	title = title.toString().replace("\\", "");
        	StringBuilder sb=new StringBuilder("SELECT * FROM NW_RESULT WHERE TITLE='"+title+"' and PUBDATE='"+pubtime+"' and CRTIME='"+object+"' and TYPE IS NULL");
            Connection connection = ConnectionUtil.getConnection(sqlType);
            Statement statement = connection.createStatement();
            ResultSet set = statement.executeQuery(sb.toString());
            
            while (set.next()){
            	ConnectionUtil.closeConnection(set, statement, connection);
            	return true;
            }
            return false;
        } catch (Exception e) {
            //TODO: handle exception
            Log_Exception.Error_txt("GetNWResultInfo方法异常！"+e.getMessage());
            return null;
        }
        
        
    }
    
    public void InsertDubs(Integer wcmrecid, Integer hyrecid, Integer zwrecid, String object, String object2, String object3) throws SQLException {
        Connection connection=null;
        Statement statement =null;
        try {
            StringBuilder sb = new StringBuilder(
                    "INSERT INTO NW_RESULT(WCMRECID,HYRECID,ZWRECID,TITLE,PUBDATE,CRTIME) VALUES(" + wcmrecid + "," + hyrecid + "," + zwrecid + ",'" + object + "','" + object2 +"','" + object3 +"'  )");
            connection = ConnectionUtil.getConnection(sqlType);
            statement = connection.createStatement();
            int count = statement.executeUpdate(sb.toString());
            
        } catch (Exception e) {
            Log_Exception.Error_txt("InsertResult 方法异常！" + e.getMessage());
        }
        finally{
            if (statement != null) {
                statement.close();
            }
            if (connection != null) {
                connection.close();
            }
        }

    }
    
    /**
     * 
     * @return
     * @throws SQLException
     */
    public void UpdateResults(Integer CHNLID) throws SQLException {
        Connection connection=null;
        Statement statement =null;
        try {
            StringBuilder sb=new StringBuilder("UPDATE NW_RESULT SET TYPE="+CHNLID+",TEMP="+0+" WHERE TYPE IS NULL");
            connection = ConnectionUtil.getConnection(sqlType);
            statement = connection.createStatement();
            int count = statement.executeUpdate(sb.toString());
           
        } catch (Exception e) {
            Log_Exception.Error_txt("UpdateResults 方法异常！"+e.getMessage());
        }
        finally{
            if(statement!=null){
                statement.close();
            }
            if(connection!=null){
                connection.close();
            }
        }
        
    }
}