package com.trs.web2frame.tool.tyjyh.tongliao;

import com.trs.infra.util.CMyFile;
import com.trs.infra.util.CMyString;
import com.trs.web2frame.WCMServiceCaller;
import com.trs.web2frame.dispatch.Dispatch;
import com.trs.web2frame.tool.tyjyh.ConfigConstant;
import com.trs.web2frame.tool.tyjyh.ConnectionUtil;
import com.trs.web2frame.tool.tyjyh.ConnectionUtil2;
import com.trs.web2frame.tool.tyjyh.FujianUtil;
import com.trs.web2frame.tool.tyjyh.common.Appendix;
import com.trs.web2frame.tool.tyjyh.common.ArticleInfo;
import com.trs.web2frame.tool.tyjyh.common.Common;
import com.trs.web2frame.tool.tyjyh.common.WriteWcmXML;
import com.trs.web2frame.util.Log_Exception;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ServiceImplWcm {
    private String sqlType = ConfigConstant.SQLTYPE;
    
    
	public List<Map<String, Object>> GetDocFromLogmsg() {
		StringBuilder sb = new StringBuilder("select docid,chnlid from WCMCHNLDOC where recid in(\r\n" + 
				" select wcmrecid from LOGMESSAGEINFO where MESSAGEINFO like '栏目没有设置视图！%')");
		List<Map<String,Object>> list = new ArrayList<>();
		Connection connection = null;
		Statement statement = null;
		ResultSet set = null;
		try {
			connection = ConnectionUtil.getConnection(sqlType);
			statement = connection.createStatement();
			set = statement.executeQuery(sb.toString());
			while (set.next()) {
				Map<String,Object> map=new HashMap<>();
				map.put("docid", set.getString("docid"));
				map.put("chnlid", set.getString("chnlid"));
				list.add(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			ConnectionUtil.closeConnection(set, statement, connection);
		}
		return list;
	}
    
    
    
	public String GetHyRecidFromNewDb(String docid,String chnlid) {
		StringBuilder sb = new StringBuilder("select recid from wcmchnldoc where docid="+docid+" and chnlid="+chnlid );
		Connection connection = null;
		Statement statement = null;
		ResultSet set = null;
		String recid = "";
		try {
			connection = ConnectionUtil2.getConnection();
			statement = connection.createStatement();
			set = statement.executeQuery(sb.toString());
			while (set.next()) {
				recid = set.getString("recid");
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			ConnectionUtil2.closeConnection(set, statement, connection);
		}
		return recid;
	}
    
	public List<Map<String, Object>> GetQuoteDocFromOldDB(String channelId) {
		StringBuilder sb = new StringBuilder(" select t.NEWCHANELID,n.HYRECID,n.HYDOCID,wcd.DOCORDER from wcmchnldoc wcd \r\n" + 
				" left join wcmchannel wc on wcd.chnlid=wc.channelid \r\n" + 
				" left join CHANNEL_MAPPING t on t.OLDCHANELID=wc.channelid \r\n" +
				" left join nw_result n on n.WCMDOCID=wcd.DOCID\r\n" + 
				" where chnlid="+channelId+" and modal>1 and n.HYRECID is not null  and docstatus=10 order by docorder");
		List<Map<String,Object>> list = new ArrayList<>();
		Connection connection = null;
		Statement statement = null;
		ResultSet set = null;
		try {
			connection = ConnectionUtil.getConnection(sqlType);
			statement = connection.createStatement();
			set = statement.executeQuery(sb.toString());
			while (set.next()) {
				Map<String,Object> map=new HashMap<>();
				map.put("recid", set.getString("HYRECID"));
				map.put("chnlid", set.getString("NEWCHANELID"));
				
				map.put("hydocid", set.getString("HYDOCID"));
				map.put("docorder", set.getString("DOCORDER"));
				list.add(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			ConnectionUtil.closeConnection(set, statement, connection);
		}
		return list;
	}
    public Map<String,Object> GetRelFileInfoByDocIdJIEDU(String docId) {
        // 获取文档相关的附件信息
        Map<String,Object> map=new HashMap<>();
        JSONArray picRelFileJson = new JSONArray();
        JSONArray docRelFileJson = new JSONArray();
        try {
            List<Map<String, Object>> oldMaps = new ArrayList<>();
            Connection connection = null;
            Statement statement = null;
            ResultSet set = null;
            try {
                StringBuilder sb=new StringBuilder("select cn.extension,cr.TYPE as filetype,FS_NAMES_ID,cr.title,concat(cn.CURRENT_FILE_PATH,\"/\",substring(cn.FS_NAMES_ID,5,29),concat(\".\",cn.extension)) as fileurl from CMS_MANUSCRIPT_RELATED_RES cr\n" +
                        "left join CMS_FS_NAMES cn on cr.RES_RELATED_ID=cn.RES_ID\n" +
                        "where cr.MANUSCRIPT_ID='"+docId+"'");
                connection = ConnectionUtil.getConnection("mysql");
                statement = connection.createStatement();
                set = statement.executeQuery(sb.toString());

                while (set.next()){
                    String extension = set.getString("extension");
                    String file_type = set.getString("filetype");
                    String pic_name = set.getString("title");
                    String file_url = "http://10.21.245.114:81/" + set.getString("fileurl");
                    if(pic_name==null)continue;
                    JsoupUtils jsoupUtils = new JsoupUtils();
                    String name = null;
                    try {
                        name = set.getString("fileurl").substring(set.getString("fileurl").lastIndexOf("/")+1);
                    }catch (Exception e){
                        name = Math.random()+"";
                    }
                    String sUploadFile = jsoupUtils.updateFileUrl( file_url,name);

                    if(!CMyString.isEmpty(sUploadFile)) {
                        if("PICTURE".equals(file_type)){
                            JSONObject picRelObj = new JSONObject();
                            picRelObj.put("SrcFile", pic_name);
                            picRelObj.put("AppFile", sUploadFile);
                            picRelObj.put("AppDesc", pic_name);
                            picRelObj.put("AppendixId", 0);
                            picRelFileJson.add(picRelObj);
                        }else{
                            JSONObject docRelObj = new JSONObject();
                            docRelObj.put("SrcFile", pic_name);
                            docRelObj.put("AppFile", sUploadFile);
                            docRelObj.put("AppDesc", pic_name);
                            docRelObj.put("AppendixId", 0);
                            docRelFileJson.add(docRelObj);
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                return new HashMap<>();
            } finally {
                ConnectionUtil.closeConnection(set, statement, connection);
            }
            //默认视图
            map.put("FJ",docRelFileJson.toString());
            return map;
        } catch (Exception e) {
            e.printStackTrace();
            return new HashMap<>();
        }
    }
    /**
     * 向wcmchnldoc插入排序字段
     */
	public int updateChnldoc(String hyRecId, String docOrder) {
		Connection connection = null;
		Statement statement = null;
		int result = 0;
		String sql = "update wcmchnldoc set olddocOrder="+docOrder+" where recid="+hyRecId;
		try {
			connection = ConnectionUtil2.getConnection();
			statement = connection.createStatement();
			result = statement.executeUpdate(sql);
		} catch(Exception e) {
			e.printStackTrace();
			Log_Exception.Error_txt("updateChnldoc()方法异常！"+e.getMessage());
		} finally {
			ConnectionUtil2.closeConnection(statement,connection);
		}
		return result;
		
	}

    /**
     * 根据DOcID获取文档相关的附件信息
     * @param docId
     * @return
     */
    public Map<String,Object> GetRelFileInfoByDocId(String docId){
        // 获取文档相关的附件信息
        Map<String,Object> map=new HashMap<>();
        JSONArray picRelFileJson = new JSONArray();
        JSONArray docRelFileJson = new JSONArray();
        try {
            List<Map<String, Object>> oldMaps = new ArrayList<>();
            Connection connection = null;
            Statement statement = null;
            ResultSet set = null;
            try {
                StringBuilder sb=new StringBuilder("select cn.extension,cr.TYPE as filetype,FS_NAMES_ID,cr.title,concat(cn.CURRENT_FILE_PATH,\"/\",substring(cn.FS_NAMES_ID,5,29),concat(\".\",cn.extension)) as fileurl from CMS_MANUSCRIPT_RELATED_RES cr\n" +
                        "left join CMS_FS_NAMES cn on cr.RES_RELATED_ID=cn.RES_ID\n" +
                        "where cr.MANUSCRIPT_ID='"+docId+"'");
                connection = ConnectionUtil.getConnection("mysql");
                statement = connection.createStatement();
                set = statement.executeQuery(sb.toString());

                while (set.next()){
                    String extension = set.getString("extension");
                    String file_type = set.getString("filetype");
                    String pic_name = set.getString("title");
                    String file_url = "http://10.21.245.114:81/" + set.getString("fileurl");
                    if(pic_name==null)continue;
                    JsoupUtils jsoupUtils = new JsoupUtils();
                    String name = null;
                    try {
                        name = set.getString("fileurl").substring(set.getString("fileurl").lastIndexOf("/")+1);
                    }catch (Exception e){
                        name = Math.random()+"";
                    }
                    String sUploadFile = jsoupUtils.updateFileUrl( file_url,name);

                    if(!CMyString.isEmpty(sUploadFile)) {
                        if("PICTURE".equals(file_type)){
                            JSONObject picRelObj = new JSONObject();
                            picRelObj.put("SrcFile", pic_name);
                            picRelObj.put("AppFile", sUploadFile);
                            picRelObj.put("AppDesc", pic_name);
                            picRelObj.put("AppendixId", 0);
                            picRelFileJson.add(picRelObj);
                        }else{
                            JSONObject docRelObj = new JSONObject();
                            docRelObj.put("SrcFile", pic_name);
                            docRelObj.put("AppFile", sUploadFile);
                            docRelObj.put("AppDesc", pic_name);
                            docRelObj.put("AppendixId", 0);
                            docRelFileJson.add(docRelObj);
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                return new HashMap<>();
            } finally {
                ConnectionUtil.closeConnection(set, statement, connection);
            }
            //默认视图
            map.put("docRelFile",docRelFileJson.toString());
            map.put("docRelPic",picRelFileJson.toString());
            return map;
        } catch (Exception e) {
            e.printStackTrace();
            return new HashMap<>();
        }
    }

    public Map<String,Object> GetRelFileInfoByDocIdGG(String docId){
        // 获取文档相关的附件信息
        Map<String,Object> map=new HashMap<>();
        JSONArray picRelFileJson = new JSONArray();
        JSONArray docRelFileJson = new JSONArray();
        try {
            List<Map<String, Object>> oldMaps = new ArrayList<>();
            Connection connection = null;
            Statement statement = null;
            ResultSet set = null;
            try {
                StringBuilder sb=new StringBuilder("select cn.extension,cr.TYPE as filetype,FS_NAMES_ID,cr.title,concat(cn.CURRENT_FILE_PATH,\"/\",substring(cn.FS_NAMES_ID,5,29),concat(\".\",cn.extension)) as fileurl from CMS_MANUSCRIPT_RELATED_RES cr\n" +
                        "left join CMS_FS_NAMES cn on cr.RES_RELATED_ID=cn.RES_ID\n" +
                        "where cr.MANUSCRIPT_ID='"+docId+"'");
                connection = ConnectionUtil.getConnection("mysql");
                statement = connection.createStatement();
                set = statement.executeQuery(sb.toString());

                while (set.next()){
                    String extension = set.getString("extension");
                    String file_type = set.getString("filetype");
                    String pic_name = set.getString("title");
                    String file_url = "http://10.21.245.114:81/" + set.getString("fileurl");
                    if(pic_name==null)continue;
                    JsoupUtils jsoupUtils = new JsoupUtils();
                    String name = null;
                    try {
                        name = set.getString("fileurl").substring(set.getString("fileurl").lastIndexOf("/")+1);
                    }catch (Exception e){
                        name = Math.random()+"";
                    }
                    String sUploadFile = jsoupUtils.updateFileUrl( file_url,name);

                    if(!CMyString.isEmpty(sUploadFile)) {
                        if("PICTURE".equals(file_type)){
                            JSONObject picRelObj = new JSONObject();
                            picRelObj.put("SrcFile", pic_name);
                            picRelObj.put("AppFile", sUploadFile);
                            picRelObj.put("AppDesc", pic_name);
                            picRelObj.put("AppendixId", 0);
                            picRelFileJson.add(picRelObj);
                        }else{
                            JSONObject docRelObj = new JSONObject();
                            docRelObj.put("SrcFile", pic_name);
                            docRelObj.put("AppFile", sUploadFile);
                            docRelObj.put("AppDesc", pic_name);
                            docRelObj.put("AppendixId", 0);
                            docRelFileJson.add(docRelObj);
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                return new HashMap<>();
            } finally {
                ConnectionUtil.closeConnection(set, statement, connection);
            }
            //默认视图
            map.put("GBFL",docRelFileJson.toString());
            return map;
        } catch (Exception e) {
            e.printStackTrace();
            return new HashMap<>();
        }
    }

    public Map<String,Object> GetRelFileInfoByDocIdGK(String docId){
        // 获取文档相关的附件信息
        Map<String,Object> map=new HashMap<>();
        JSONArray picRelFileJson = new JSONArray();
        JSONArray docRelFileJson = new JSONArray();
        try {
            List<Map<String, Object>> oldMaps = new ArrayList<>();
            Connection connection = null;
            Statement statement = null;
            ResultSet set = null;
            try {
                StringBuilder sb=new StringBuilder("select cn.extension,cr.TYPE as filetype,FS_NAMES_ID,cr.title,concat(cn.CURRENT_FILE_PATH,\"/\",substring(cn.FS_NAMES_ID,5,29),concat(\".\",cn.extension)) as fileurl from CMS_MANUSCRIPT_RELATED_RES cr\n" +
                        "left join CMS_FS_NAMES cn on cr.RES_RELATED_ID=cn.RES_ID\n" +
                        "where cr.MANUSCRIPT_ID='"+docId+"'");
                connection = ConnectionUtil.getConnection("mysql");
                statement = connection.createStatement();
                set = statement.executeQuery(sb.toString());

                while (set.next()){
                    String extension = set.getString("extension");
                    String file_type = set.getString("filetype");
                    String pic_name = set.getString("title");
                    String file_url = "http://10.21.245.114:81/" + set.getString("fileurl");
                    if(pic_name==null)continue;
                    JsoupUtils jsoupUtils = new JsoupUtils();
                    String name = null;
                    try {
                        name = set.getString("fileurl").substring(set.getString("fileurl").lastIndexOf("/")+1);
                    }catch (Exception e){
                        name = Math.random()+"";
                    }
                    String sUploadFile = jsoupUtils.updateFileUrl( file_url,name);

                    if(!CMyString.isEmpty(sUploadFile)) {
                        if("PICTURE".equals(file_type)){
                            JSONObject picRelObj = new JSONObject();
                            picRelObj.put("SrcFile", pic_name);
                            picRelObj.put("AppFile", sUploadFile);
                            picRelObj.put("AppDesc", pic_name);
                            picRelObj.put("AppendixId", 0);
                            picRelFileJson.add(picRelObj);
                        }else{
                            JSONObject docRelObj = new JSONObject();
                            docRelObj.put("SrcFile", pic_name);
                            docRelObj.put("AppFile", sUploadFile);
                            docRelObj.put("AppDesc", pic_name);
                            docRelObj.put("AppendixId", 0);
                            docRelFileJson.add(docRelObj);
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                return new HashMap<>();
            } finally {
                ConnectionUtil.closeConnection(set, statement, connection);
            }
            //默认视图
            map.put("DOCATTACHPICFIELD",docRelFileJson.toString());
            return map;
        } catch (Exception e) {
            e.printStackTrace();
            return new HashMap<>();
        }
    }

    /**
     * 处理内容中的附件
     * @param htmlContent
     * @return
     */
    public String GetRetHtmlContent(String htmlContent){
        //1.找出内容中的所有图片 2.找出内容中的附件 3.调接口上传图片/附件并记录返回的信息 4.替换正文中的对应图片/附件信息
        try {
            Document doc = Jsoup.parse(htmlContent);
            Elements sectionNodes = doc.getAllElements();
            for (int i = 0; i < sectionNodes.size(); i++){
                Element Node = sectionNodes.get(i);
                //找图片
                if ("img".equalsIgnoreCase(Node.nodeName())) {
                    //如果是相对路径
                    if (Node.attr("src") != null) {
                        String temp = Node.attr("src");
                        if(temp.contains("website-webapp")) {
                        	Node.attr("src", temp);
                        }
                    }
                    if (Node.attr("oldsrc") != null && !Node.attr("OLDSRC").equals("")){
                    	Node.removeAttr("oldsrc");
                    }
                }
                //找文件
                if("a".equals(Node.nodeName())){
                    if (Node.attr("href") != null && !Node.attr("href").equals("")&&Node.hasText()){
                        //判断该链接是否是文件
                        String temp=Node.attr("href");
                        if(temp.contains("website-webapp")) {
	                        boolean isfile= IsContainFile(temp);
	                        if(isfile){
                                Dispatch oDispatch = WCMServiceCaller.UploadFile("D:/TRS/soft/nginx/nginx-1.12.2/html/files/filedownload/"+temp);
                                String sUploadFile = oDispatch.getUploadShowName();
	                        }
                        }
                    }
                }

            }
            Elements bodies = doc.getElementsByTag("body");
            if (bodies.size() > 0) {
            	Element body = bodies.get(0);
            	return body.html();
            }
           
            return doc.html();
        } catch (Exception e) {
            Log_Exception.Error_txt("GetAllFileInfoInContent()方法异常" + e.getMessage());
            return null;
        }
    }
    
  //判断字符串中是否包含附件
    public static Boolean IsContainFile(String content){
        if(content!=null&&!content.equals("")) {
            String regExImg = "(.txt|.doc|.xls|.zip|.rar|.pdf|.ppt|.TXT|.DOC|.XLS|.ZIP|.RAR|.PDF|.PPT|.mp3|.swf)";//正文中图片--------------add by miyanzhao20190111
            Pattern patternImg = Pattern.compile(regExImg);
            Matcher matcherImg = patternImg.matcher(content);

            if(matcherImg.find()) {
                return true;
            }else{
                return false;
            }
        }else{
            return false;
        }
    } 
    
    
    
    

    /**
     * 插入结果
     * @param object2 
     * @param object 
     *
     * @throws SQLException
     */
    public Boolean InsertResult(Integer wcmrecid, Integer hyrecid, Integer wcmdocid, Integer hydocid, String object, String object2) 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 NW_RESULT(WCMRECID,HYRECID,WCMDOCID,HYDOCID,TITLE,CRTIME) VALUES(" + wcmrecid + "," + hyrecid + "," + wcmdocid +","+ hydocid + ",'" + object + "','" + 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("InsertResult 方法异常！" + e.getMessage());
            return false;
        }
        finally{
            if (statement != null) {
                statement.close();
            }
            if (connection != null) {
                connection.close();
            }
        }

    }

    /**
     * 更新结果
     * 
     * @param wcmrecid
     * @param hyrecid
     * @return
     * @throws SQLException
     */
    public Boolean UpdateResult(Integer wcmrecid, Integer hyrecid, Integer wcmdocid, Integer hydocid) 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="+wcmdocid+",HYDOCID="+hydocid+" 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) {
            Log_Exception.Error_txt("UpdateResult 方法异常！"+e.getMessage());
            return false;
        }
        finally{
            if(statement!=null){
                statement.close();
            }
            if(connection!=null){
                connection.close();
            }
        }
        
    }
    /**
     * 获取结果信息
     * @param wcmRecId
     * @return
     */
    public Map<String,Object> GetResultInfo(String 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) {
            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());
            if (count != 1) {
                return false;
            } else {
                return true;
            }
        } catch (Exception e) {
            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
                }
                ConnectionUtil.closeConnection(set, statement, connection);
                return map;
            }else{
                return null;
            }
        } catch (Exception e) {
            Log_Exception.Error_txt("GetLogMessageInfo方法异常！"+e.getMessage());
            return null;
        }
        
    }

    
    /**
     * 从老库查出该栏目下所有信息
     * @param channelId 
     * @return
     */
    public List<Map<String,Object>> GetAllDocInfoFromOldDB(String channelId,String oldDocid){
        List<Map<String, Object>> oldMaps = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        ResultSet set = null;
        try {
	            StringBuilder sb=new StringBuilder("select \n" +
                        " c.MANUSCRIPT_ID,c.TITLE,c.SUB_TITLE,c.SHORT_TITLE,c.KEYWORD,c.PUBLISHED_TIME,c.MEMO,c.TYPE,c.CREATED_TIME,c.HAS_IMG,c.HAS_VIDEO,c.HAS_DOC,c.HAS_RADIO,concat(sfn.CURRENT_FILE_PATH,\"/\",substring(sfn.FS_NAMES_ID,5,29),\".html\")  currentFilePathHtmlUrl,\n" +
                        "cb.B_SOURCE as B_SOURCE\n" +
                        " from CMS_MANUSCRIPT c\n" +
                        " left join CMS_FS_NAMES sfn on sfn.RES_ID=c.MANUSCRIPT_ID\n" +
                        " left join cms_manuscript_metadata_b cb on cb.MANUSCRIPT_METADATA_ID=c.MANUSCRIPT_ID\n" +
                        " where STATUS=4\n" +
                        " and CHANNEL_ID='"+channelId+"' \n" +
                        " order by c.SEQ_NUM asc"

                );
            connection = ConnectionUtil.getConnection("mysql");
            statement = connection.createStatement();
            set = statement.executeQuery(sb.toString());
            while (set.next()){
                Map<String, Object> map = new HashMap<>();
                map.put("MANUSCRIPT_ID", set.getString("MANUSCRIPT_ID"));
                map.put("TITLE", set.getString("TITLE"));
                map.put("SUB_TITLE", set.getString("SUB_TITLE"));
                map.put("SHORT_TITLE", set.getString("SHORT_TITLE"));
                map.put("KEYWORD",set.getString("KEYWORD"));
                map.put("PUBLISHED_TIME",set.getString("PUBLISHED_TIME"));
                map.put("MEMO",set.getString("MEMO"));
                map.put("TYPE",set.getString("TYPE"));
                map.put("CREATED_TIME",set.getString("CREATED_TIME"));
                map.put("HAS_IMG",set.getString("HAS_IMG"));
                map.put("HAS_VIDEO",set.getString("HAS_VIDEO"));
                map.put("HAS_DOC",set.getString("HAS_DOC"));
                map.put("HAS_RADIO",set.getString("HAS_RADIO"));
                map.put("B_SOURCE", set.getString("B_SOURCE"));
                map.put("currentFilePathHtmlUrl",set.getString("currentFilePathHtmlUrl"));
                oldMaps.add(map);
            }
            return oldMaps;
        } catch (Exception e) {
            Log_Exception.Error_txt("GetAllDocInfoFromOldDB()方法异常"+e.getMessage());
            return null;
        } finally {
        	ConnectionUtil.closeConnection(set, statement, connection);
        }
    }

    public List<Map<String,Object>> GetAllDocInfoFromOldDBAll(String channelId){
        List<Map<String, Object>> oldMaps = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        ResultSet set = null;
        try {
            StringBuilder sb=new StringBuilder("select \n" +
                    " c.MANUSCRIPT_ID,c.TITLE,c.SUB_TITLE,c.SHORT_TITLE,c.KEYWORD,c.PUBLISHED_TIME,c.MEMO,c.TYPE,c.CREATED_TIME,c.HAS_IMG,c.HAS_VIDEO,c.HAS_DOC,c.HAS_RADIO,concat(sfn.CURRENT_FILE_PATH,\"/\",substring(sfn.FS_NAMES_ID,5,29),\".html\")  currentFilePathHtmlUrl,\n" +
                    "cb.B_SOURCE as B_SOURCE,\n" +
                    " cmmc.C_GKSX C_GKSX,\n" +
                    " cmmc.C_FWRQ C_FWRQ,\n" +
                    " cmmc.C_FBJG C_FBJG,\n" +
                    " cmmc.C_SYH C_SYH,\n" +
                    " cmmc.C_WJBH C_WJBH,\n" +
                    " cmmc.C_ZTC C_ZTC,\n" +
                    " cmmc.C_ZHUTI C_ZHUTI,"+
                    " cms_c.CN_NAME CN_NAME"+
                    " from CMS_MANUSCRIPT c\n" +
                    " left join CMS_FS_NAMES sfn on sfn.RES_ID=c.MANUSCRIPT_ID\n" +
                    " left join cms_manuscript_metadata_b cb   on cb.MANUSCRIPT_METADATA_ID=c.MANUSCRIPT_ID\n" +
                    " left join cms_manuscript_metadata_c cmmc on c.manuscript_id = cmmc.manuscript_metadata_id"+
                    " left join cms_code cms_c on cms_c.code_id = substring_index(cmmc.c_zhuti,\";\",1)"+
                    " where STATUS=4\n" +
                    " and CHANNEL_ID='"+channelId+"' \n" +
                    " order by c.SEQ_NUM asc"
            );
            connection = ConnectionUtil.getConnection("mysql");
            statement = connection.createStatement();
            set = statement.executeQuery(sb.toString());
            while (set.next()){
                Map<String, Object> map = new HashMap<>();
                map.put("MANUSCRIPT_ID", set.getString("MANUSCRIPT_ID"));
                map.put("TITLE", set.getString("TITLE"));
                map.put("SUB_TITLE", set.getString("SUB_TITLE"));
                map.put("SHORT_TITLE", set.getString("SHORT_TITLE"));
                map.put("KEYWORD",set.getString("KEYWORD"));
                map.put("PUBLISHED_TIME",set.getString("PUBLISHED_TIME"));
                map.put("MEMO",set.getString("MEMO"));
                map.put("TYPE",set.getString("TYPE"));
                map.put("CREATED_TIME",set.getString("CREATED_TIME"));
                map.put("HAS_IMG",set.getString("HAS_IMG"));
                map.put("HAS_VIDEO",set.getString("HAS_VIDEO"));
                map.put("HAS_DOC",set.getString("HAS_DOC"));
                map.put("HAS_RADIO",set.getString("HAS_RADIO"));
                map.put("B_SOURCE", set.getString("B_SOURCE"));
                map.put("currentFilePathHtmlUrl",set.getString("currentFilePathHtmlUrl"));
                map.put("C_GKSX",set.getString("C_GKSX"));
                map.put("C_FWRQ",set.getString("C_FWRQ"));
                map.put("C_FBJG",set.getString("C_FBJG"));
                map.put("C_SYH",set.getString("C_SYH"));
                map.put("C_WJBH",set.getString("C_WJBH"));
                map.put("C_ZTC",set.getString("C_ZTC"));
                map.put("C_ZHUTI",set.getString("C_ZHUTI"));
                oldMaps.add(map);
            }
            return oldMaps;
        } catch (Exception e) {
            Log_Exception.Error_txt("GetAllDocInfoFromOldDB()方法异常"+e.getMessage());
            return null;
        } finally {
            ConnectionUtil.closeConnection(set, statement, connection);
        }
    }
    /**
     * 找出当前栏目下所有需要被引用的文档信息
     * @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) {
            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 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 = null;
		Statement statement = null;
		ResultSet set = null;
		try {
			connection = ConnectionUtil.getConnection(sqlType);
			statement = connection.createStatement();
			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);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			ConnectionUtil.closeConnection(set, statement, connection);
		}
		return list;
    }
    
    /**
	 * 获取新旧栏目关系
	 */
	public List<Map<String,Object>> queryChanelRelation(){
		List<Map<String,Object>> list = new ArrayList();
		String condition = ConfigConstant.SQLCONDITIONCHNL;
		StringBuilder sb = new StringBuilder("select docchannel as oldchanelid,t.channelid as newchanelid from wcmdocument w \r\n" + 
		" left join wcmchannel wc on wc.channelid=w.docchannel\r\n" + 
		" left join temp_new_chnl_gd t on wc.chnlname=t.chnlname\r\n" + 
		" where w.siteid=38 \r\n" + 
		" and w.dockind=0 and docstatus=10 and w.docchannel>0 ");
		
//        StringBuilder sb = new StringBuilder("select * FROM CHANNEL_MAPPING where oldchanelid>280 order by oldchanelid");
//		StringBuilder sb = new StringBuilder("select t.channelid as newchanelid,t.chnlname,wc.CHANNELID as oldchanelid,wc.CHNLNAME from temp_new_chnl_szfgk t\r\n" + 
//				" left join WCMCHANNEL wc on t.chnlname=wc.CHNLNAME\r\n" + 
//				" where wc.SITEID="+ConfigConstant.SITEIDGK+" "+condition+"  \r\n" + 
//				" ORDER BY wc.CHANNELID");
//		StringBuilder sb = new StringBuilder("select docchannel as oldchanelid,t.channelid as newchanelid from wcmdocument w \r\n" + 
//				" left join wcmchannel wc on wc.channelid=w.docchannel\r\n" + 
//				" left join temp_new_chnl_szfgk t on wc.chnlname=t.chnlname\r\n" + 
//				" where w.siteid=7 \r\n" + 
//				" and w.dockind=0 and docstatus=10 and w.docchannel>0 group by docchannel,t.channelid");
		Connection connection = null;
		Statement statement = null;
		ResultSet set = null;
		try {
//			connection = JDBCUtils.getConnection();
			connection = ConnectionUtil.getConnection(sqlType);
			statement = connection.createStatement();
			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);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
//			JDBCUtils.close(connection, statement, set);
			ConnectionUtil.closeConnection(set, statement, connection);
		}
		return list;
    }
    /**
     * 获取栏目关系
     * @param channelId
     * @return
     * @throws Exception
     */
    public String GetNewChannelId(String channelId){
        String NEWCHANNELID="";
        String sb = "select t.channelid as newchanelid,t.chnlname,wc.CHANNELID as oldchanelid,wc.CHNLNAME from temp_new_chnl_copy t left join WCMCHANNEL wc on t.chnlname=wc.CHNLNAME where wc.channelid="+channelId;
		Connection connection = null;
		Statement statement = null;
		ResultSet set = null;
		try {
			connection = ConnectionUtil.getConnection(sqlType);
			statement = connection.createStatement();
			set = statement.executeQuery(sb.toString());
			while (set.next()) {
				NEWCHANNELID=set.getString("newchanelid");
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			ConnectionUtil.closeConnection(set, statement, connection);
		}
		return NEWCHANNELID;
    }
    
    
	public Map<String,String> queryChanelRelationErrorSzf(){
		String condition = ConfigConstant.SQLCONDITIONCHNL;
		StringBuilder sb = new StringBuilder("select t.channelid as newchanelid,t.chnlname,wc.CHANNELID as oldchanelid,wc.CHNLNAME from temp_new_chnl_szfgk t\r\n" + 
				" left join WCMCHANNEL wc on t.chnlname=wc.CHNLNAME\r\n" + 
				" where wc.SITEID="+ConfigConstant.SITEIDGK+" "+condition+"  \r\n" + 
				" ORDER BY wc.CHANNELID");
		Connection connection = null;
		Statement statement = null;
		ResultSet set = null;
		Map<String,String> map=new HashMap<>();
		try {
			connection = ConnectionUtil.getConnection(sqlType);
			statement = connection.createStatement();
			set = statement.executeQuery(sb.toString());
			while (set.next()) {
				map.put(set.getString("OLDCHANELID"), set.getString("NEWCHANELID"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			ConnectionUtil.closeConnection(set, statement, connection);
		}
		return map;
    }
    
    
    /**
     * 获取结果信息
     * @param object 
     * @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();
            }
        }
        
    }
    
    
    //----------------------------此处是公开的方法--------------------------------//
    /**
     * 从老库查出该栏目下所有信息
     * @param channelId 
     * @return
     */
    public List<Map<String,Object>> GetAllGKDocInfoFromOldDB(String channelId,String oldDocid){
        List<Map<String, Object>> oldMaps = new ArrayList<>();
        String conditions= ConfigConstant.SQLCONDITIONGK;
        try {
            StringBuilder sb=new StringBuilder("SELECT wcd.RECID,wcd.CHNLID,wcd.DOCCHANNEL,wcd.DOCORDER,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.DOCSTATUS=10 and wcd.modal=1 and w.dockind!=0 AND wcd.CHNLID="+channelId+ conditions+" ORDER BY wcd.DOCORDER ");
            //,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("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"));
                map.put("DOCORDER", set.getString("DOCORDER"));
                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;
        }
    }
    
	public Map<String,String> queryClassinfoMapping(){
        StringBuilder sb = new StringBuilder("select * from CLASSINFOMAPPING");
		Connection connection = null;
		Statement statement = null;
		ResultSet set = null;
		Map<String,String> map = new HashMap<String,String>();
        try {
    		connection = ConnectionUtil.getConnection(sqlType);
    		statement = connection.createStatement();
    		set = statement.executeQuery(sb.toString());
    		while (set.next()) {
    			map.put(set.getString("OLDCLASSID"), set.getString("NEWCLASSID"));
    		}
        }catch(Exception e){
        	e.printStackTrace();
        } finally {
        	ConnectionUtil.closeConnection(set, statement, connection);
        }
		return map;
    }
	
	
	/**
     * 市政府信息公开
     * @param channelId 
     * @return
     */
    public List<Map<String,Object>> GetAllSZFGKDocInfoFromOldDB(String channelId,String oldDocid){
        List<Map<String, Object>> oldMaps = new ArrayList<>();
        String conditions= ConfigConstant.SQLCONDITIONGK;
        try {
            StringBuilder sb=new StringBuilder("SELECT wcd.RECID,wcd.CHNLID,wcd.DOCCHANNEL,wcd.DOCORDER,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.Title,WM.placekey,WM.subcat,WM.themecat,WM.organcat,WM.efectdate,WM.Description,WM.Content,WM.RidxId, "
            +" WM.acesmthd,WM.Rtitle,WM.fileNum,WM.Keywords,WM.idxID,WM.Abolidate,WM.mdUpdTime,WM.PubDate,WM.Publisher, "
            +" WM.BGXZ,WM.ZXZX,WM.ZXTS,WM.ZXSB,WM.ZXCX,WM.JGGS,WM.olddocid,WM.MZ,WM.ZW, "
            +" WM.FGGZ,WM.XSDWLJ,WM.newthemecat,WM.ispdffile,WM.Rreports "
            +" FROM WCMCHNLDOC wcd LEFT JOIN WCMDOCUMENT w ON WCD.DOCID=w.DOCID"
            +" LEFT JOIN WCMMETATABLEGOVINFO WM ON W.DOCID = WM.METADATAID WHERE WCD.DOCSTATUS=10 and wcd.modal=1 and w.dockind!=0 AND wcd.CHNLID="+channelId+ conditions+" ORDER BY wcd.DOCORDER ");
            Connection connection = ConnectionUtil.getConnection(sqlType);
            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("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("DOCORDER",set.getString("DOCORDER"));
              
                map.put("Title", set.getString("Title"));
                map.put("placekey", set.getString("placekey"));
                map.put("subcat", set.getString("subcat"));
                map.put("themecat", set.getString("themecat"));
                map.put("organcat", set.getString("organcat"));
                map.put("efectdate", set.getString("efectdate"));
                map.put("Description", set.getString("Description"));
                map.put("Content", set.getString("Content"));
                map.put("RidxId", set.getString("RidxId"));
                map.put("acesmthd", set.getString("acesmthd"));
                map.put("Rtitle", set.getString("Rtitle"));
                map.put("fileNum", set.getString("fileNum"));
                map.put("Keywords", set.getString("Keywords"));
                map.put("idxID", set.getString("idxID"));
                map.put("Abolidate", set.getString("Abolidate"));
                map.put("mdUpdTime", set.getString("mdUpdTime"));
                map.put("PubDate", set.getString("PubDate"));
                map.put("Publisher", set.getString("Publisher"));
                map.put("BGXZ", set.getString("BGXZ"));
                map.put("ZXZX", set.getString("ZXZX"));
                map.put("ZXTS", set.getString("ZXTS"));
                map.put("ZXSB", set.getString("ZXSB"));
                map.put("ZXCX", set.getString("ZXCX"));
                map.put("JGGS", set.getString("JGGS"));
                map.put("MZ", set.getString("MZ"));
                map.put("ZW", set.getString("ZW"));
                map.put("FGGZ", set.getString("FGGZ"));
                map.put("XSDWLJ", set.getString("XSDWLJ"));
                map.put("newthemecat", set.getString("newthemecat"));
                map.put("ispdffile", set.getString("ispdffile"));
                map.put("Rreports", set.getString("Rreports"));
//                System.out.println("第"+i+++"篇");
                oldMaps.add(map);
            }
            ConnectionUtil.closeConnection(set, statement, connection);
            return oldMaps;
        } catch (Exception e) {
            Log_Exception.Error_txt("公开GetAllDocInfoFromOldDB()方法异常"+e.getMessage());
            return null;
        }
    }
    
    
    //zip
    /**
     * 从老库查出该栏目下所有信息
     * @return
     */
    public List<Map<String,Object>> GetErrorDocInfoFromOldDB(){
        List<Map<String, Object>> oldMaps = new ArrayList<>();
        try {
        	StringBuilder sb=new StringBuilder("select wc.RECID,wc.CHNLID,wc.DOCCHANNEL,wc.DOCID,wc.MODAL,wc.DOCORDER,wd.DOCTYPE,wd.DOCHTMLCON,wd.DOCCONTENT,wd.DOCTITLE,\r\n" + 
            		" wd.DOCABSTRACT,wd.DOCKEYWORDS,wd.DOCPEOPLE,wd.DOCAUTHOR,wd.DOCPLACE, wd.DOCRELTIME,wd.CRTIME,\r\n" + 
            		" wd.SUBDOCTITLE,wd.DOCSOURCENAME,wd.DOCFILENAME,wd.DOCLINK\r\n" + 
            		" from wcmchnldoc wc\r\n" + 
            		" left join wcmdocument wd on wd.docid=wc.docid\r\n" + 
            		" where  wd.dockind=0 and wc.chnlid>0 and wc.DOCSTATUS=10 and wc.modal=1 and wc.SITEID="+ConfigConstant.SITEID + ConfigConstant.SQLCONDITION + "  order by wc.DOCORDER");
        	
        	
        	System.out.println(sb.toString());
            Connection connection = ConnectionUtil.getConnection(sqlType);
            Statement statement = connection.createStatement();
            ResultSet set = statement.executeQuery(sb.toString());
            int count = 0;
            while (set.next()){
            	//System.out.println("1111");
            	ArticleInfo arIf = new ArticleInfo();
            	arIf.setID(set.getString("DOCID"));
            	String channelIdFor = GetNewChannelId(set.getString("CHNLID"));
            	arIf.setColumnID(channelIdFor);
            	String sTitle = set.getString("DOCTITLE");
				arIf.setTitle(CMyString.showEmpty(sTitle, "无标题"));
				
            	arIf.setDocPeople(set.getString("DOCPEOPLE"));
            	arIf.setDocSource(set.getString("DOCSOURCENAME"));
            	arIf.setKeyWords(set.getString("DOCKEYWORDS"));
            	arIf.setSubTitle(set.getString("SUBDOCTITLE"));
            	arIf.setAbscract(set.getString("DOCABSTRACT"));
            	arIf.setAuthor(set.getString("DOCAUTHOR"));
            	arIf.setCreateDate(set.getTimestamp("DOCRELTIME"));
            	arIf.setProperty("RECID", set.getString("RECID"));
            	arIf.setProperty("OLDDOCORDER", set.getString("DOCORDER"));
            	
            	//类型
				String sType = CMyString.showEmpty(set.getString("DOCTYPE"));
				if (sType.equals("40")) { //文件型
					String sDocFileName = getDocFile(CMyString.showNull(set.getString("DOCFILENAME")));
					arIf.setDocFileName(sDocFileName);
					arIf.setDocFilePath(Common.TEMP_PATH);
					Appendix app = new Appendix();
					app.setAPPDESC(sDocFileName);
					app.setAPPLINKALT("");
					app.setAPPFILE(sDocFileName);
					app.setAPPPATH(Common.TEMP_PATH);
					app.setAPPTYPE("100");
					app.setFILEEXT(CMyFile.extractFileExt(sDocFileName));
					app.setSRCFILE(sDocFileName);
					Vector vApp = new Vector();
					vApp.add(app);
					arIf.setApp(vApp);
				}
				if (sType.equals("30")) {
					String sLink = CMyString.showEmpty(set.getString("DOCLINK"), "#");
					arIf.setDocLink(sLink);
				}
				if (sType.equals("20")) {
					//正文
					String htmlContent = set.getString("DOCHTMLCON").toString();
					// 处理内容中附件
					String ret_htmlContent = GetRetHtmlContent(htmlContent);
					if (!CMyString.isEmpty(ret_htmlContent)) {
						htmlContent = ret_htmlContent;
					}
					
					arIf.setContent(htmlContent);
				}
				if (sType.equals("10")) {
					arIf.setContent(set.getString("DOCCONTENT").toString());
					sType = "20";
				}
				arIf.setDocType(sType);
				
				//附件
				if (!sType.equals("40")) {
					List<Map<String,Object>> fileList=GetFilesInfoByDocId(set.getString("DOCID"));
					if (fileList.size() > 0) {
						Vector vApp = new Vector();
						for (int i=0; i<fileList.size(); i++) {
							Map file = (Map) fileList.get(i);
							vApp.add(getAppendix(file));
						}
						arIf.setApp(vApp);
					}
				}
				
				count++;
				WriteWcmXML.writeXml(arIf, count);	
				
				
				//System.out.println("已搞定:"+count+ "[ID:" + arIf.getID() + "]");
            	
            }
            ConnectionUtil.closeConnection(set, statement, connection);
            return oldMaps;
        } catch (Exception e) {
            Log_Exception.Error_txt("GetErrorDocInfoFromOldDB()方法异常"+e.getMessage());
            return null;
        }
    }
    
    private static String getDocFile(String sFileName) {
		try {
			Map<String,Object> fileData=new HashMap<>();
            fileData.put("path", ConfigConstant.REMOTFILEEURL);
            fileData.put("from", sFileName);
            fileData.put("CurrUserName", "dev");
            Dispatch result = WCMServiceCaller.Call("sxgov_dataexchange", "movePic", fileData, true);
            String sUploadFile = result.getResponseText();
            
            String sFilePath = FujianUtil.getHttpFilePath(sFileName);
            Common.downLoadFile(sFilePath, Common.TEMP_PATH + sUploadFile);

			return sUploadFile;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
    
    private static Appendix getAppendix(Map file) {
		try {
			String sFileName = (String)file.get("APPFILE");
			Map<String,Object> fileData=new HashMap<>();
            fileData.put("path", ConfigConstant.REMOTFILEEURL);
            fileData.put("from", sFileName);
            fileData.put("CurrUserName", "dev");
            Dispatch result = WCMServiceCaller.Call("sxgov_dataexchange", "movePic", fileData, true);
            String sUploadFile = result.getResponseText();
            
            String sFilePath = FujianUtil.getHttpFilePath(sFileName);
            Common.downLoadFile(sFilePath, Common.TEMP_PATH + sUploadFile);
			
			Appendix app = new Appendix();
			app.setAPPDESC(CMyString.showEmpty((String)file.get("APPDESC"), sFileName));
			app.setAPPLINKALT("");
			app.setAPPFILE(sUploadFile);
			app.setAPPPATH(Common.TEMP_PATH);
			app.setAPPTYPE((String)file.get("APPFLAG"));
			app.setFILEEXT(sFileName);
			app.setSRCFILE(CMyString.showEmpty((String)file.get("SRCFILE"), sFileName));
			return app;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}



}