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

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 java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.trs.cms.CMSConstants;
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.JDBCUtils;
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.tool.tyjyh.wcmhy06_szf.StartZipDoc;
import com.trs.web2frame.util.Log_Exception;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class StartZipDoc {
    private String sqlType = ConfigConstant.SQLTYPE;
    
	private static Map<String, String> classInfoMap ;
	private static Map<String, String> channelInfoMap ;
	private static ServiceImplWcm wcm=new ServiceImplWcm(); ;
	static {
		try {
			classInfoMap = wcm.queryClassinfoMapping();
			channelInfoMap = wcm.queryChanelRelationErrorSzf();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
    
    
	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 temp_new_chnl_copy t on t.chnlname=wc.chnlname \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 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;
	}
    
    /**
     * 向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 docRelFileJson = new JSONArray();
			JSONArray picRelFileJson = new JSONArray();
			StartZipDoc sit=new StartZipDoc();
            try {
                List<Map<String,Object>> fileList=sit.GetFilesInfoByDocId(docId);
                if (fileList!= null) {
                   JSONArray jsonArray = JSONArray.fromObject(fileList);
                   for (int f = 0; f < jsonArray.size(); f++) {
                       JSONObject jsonObject = JSONObject.fromObject(jsonArray.get(f));
                       String pathfile = jsonObject.get("APPFILE").toString();
                       String appFlag = jsonObject.get("APPFLAG").toString();//附件类型
                       String sUploadFile = "";
                       if(!appFlag.equals("40")){
                           Map<String,Object> oPostData=new HashMap<>();
                           oPostData.put("path", ConfigConstant.REMOTFILEEURL);
                           oPostData.put("from", pathfile);
                           oPostData.put("CurrUserName", "dev");
                           Dispatch result = WCMServiceCaller.Call("sxgov_dataexchange", "movePic", oPostData, true);
                           sUploadFile = result.getResponseText();
                           if(CMyString.isEmpty(sUploadFile))continue;
                       }
                       String srcFile = jsonObject.get("SRCFILE").toString();
                       String appDesc = jsonObject.get("APPDESC").toString();
                       
                       JSONObject docRelObj = new JSONObject();
                       docRelObj.put("SrcFile", srcFile);
                       docRelObj.put("AppFile", sUploadFile);
                       docRelObj.put("AppDesc", appDesc);
                       docRelObj.put("AppendixId", 0);
                       
                       // 判断如果是文件
                       if (appFlag.equals("10")||appFlag.equals("70")||appFlag.equals("130")) {
                    	   docRelFileJson.add(docRelObj);
                       }
                       // 判断如果是图片
                       if (appFlag.equals("20")) {
                    	   picRelFileJson.add(docRelObj);
                       }
                   }
               }
                //默认视图
                map.put("docRelFile", docRelFileJson.toString());
                map.put("docRelPic", picRelFileJson.toString());
                return map;
            } catch (Exception e) {
                Log_Exception.Error_txt("GetRelFileInfoByDocId()方法异常！"+e.getMessage());
                return null;
            }
    }
    
    
    /**
     * 处理内容中的附件
     * @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.startsWith("W0")||temp.startsWith("P0")) {
                        	Node.attr("src", FujianUtil.getLocalFullPath(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.startsWith("W0")||temp.startsWith("P0")) {
	                        boolean isfile= IsContainFile(temp);
	                        if(isfile){
	                        	Node.attr("href", FujianUtil.getLocalFullPath(temp));
	                            Node.attr("appendix", "true");
	                        }
                        }
                    }
                }

            }
            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 
     * @param object3 
     * 
     * @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
     * @param zwrecid
     * @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(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) {
            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 
     * @param siteId 
     * @return
     */
    public List<Map<String,Object>> GetAllDocInfoFromOldDB(String channelId,String oldDocid){
        List<Map<String, Object>> oldMaps = new ArrayList<>();
        String conditions=ConfigConstant.SQLCONDITION;
        Connection connection = null;
        Statement statement = null;
        ResultSet set = null;
        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.DOCSTATUS=10 and wc.modal=1  and wc.CHNLID="+channelId+ conditions + oldDocid +"  order by wc.DOCORDER");//and wc.recid not in(select wcmrecid from nw_result)
            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("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("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("DOCCONTENT",set.getString("DOCCONTENT"));
                map.put("DOCORDER",set.getString("DOCORDER"));
                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 * from channel_mapping where id>731 order by ID");
		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;
    }
    
    
    /**
     * 获取结果信息
     * @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();
            }
        }
        
    }
    
    
    //----------------------------此处是公开的方法--------------------------------//
    /**
     * 从老库查出该栏目下所有信息
     * @param channelId 
     * @param siteId 
     * @return
     */
    public static List<Map<String,Object>> GetAllGKDocInfoFromOldDB(){
        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=585 "+ 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 
     * @param siteId 
     * @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
    /**
     * 从老库查出该栏目下所有信息
     * @param channelId 
     * @param siteId 
     * @return
     */
    public static void main(String[] args) {
    	StartZipDoc sz = new StartZipDoc();
    	sz.GetErrorDocInfoFromOldDB();
	}
    public void GetErrorDocInfoFromOldDB(){
        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.docid in(879678,841571,337573,386888,797679,841576)  and w.siteid=7 and wcd.chnlid>0  "+ ConfigConstant.SQLCONDITIONGK+" ORDER BY wcd.DOCORDER ");
        	
            Connection connection = ConnectionUtil.getConnection(sqlType);
            Statement statement = connection.createStatement();
            ResultSet set = statement.executeQuery(sb.toString());
            int count = 0;
            while (set.next()){
            	Map<String, Object> map = new HashMap<>();
                map.put("DOCORDER",set.getString("DOCORDER"));
                map.put("DOCID", set.getString("DOCID"));
                map.put("RECID", set.getString("RECID"));
              
                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"));
                
                
                Map<String,Object> oPostData=new HashMap<>();
                String wcmDocId=map.get("DOCID").toString();//文档ID
                String docTitle=map.get("Title").toString();
                String RECID=map.get("RECID").toString();
                oPostData.put("RECID", RECID);
                oPostData.put("DOCTYPE",CMSConstants.CONTENT_BODY_HTML);
                
                if (map.get("placekey") != null) {
                	oPostData.put("placekey", map.get("placekey"));
                }
                if (map.get("efectdate") != null) {
                	oPostData.put("efectdate", map.get("efectdate"));
                }
                if (map.get("Description") != null) {
                	oPostData.put("Description", map.get("Description"));
                }
                if (map.get("RidxId") != null) {
                	oPostData.put("RidxId", map.get("RidxId"));
                }
                if (map.get("acesmthd") != null) {
                	oPostData.put("acesmthd", map.get("acesmthd"));
                }
                if (map.get("Rtitle") != null) {
                	oPostData.put("Rtitle", map.get("Rtitle"));
                }
                if (map.get("fileNum") != null) {
                	oPostData.put("fileNum", map.get("fileNum"));
                }
                //关键词
                if (map.get("Keywords") != null) {
                    String Keywords = (String) map.get("Keywords");
                    Keywords = Keywords.replaceAll("<br/>", "");//
                    Keywords = Keywords.replaceAll("<br>", "");//
                    oPostData.put("Keywords", Keywords);
                }
                //idxID-必填
                if (map.get("idxID") != null) {
                	oPostData.put("oldidxid", map.get("idxID"));//旧索引号
                    oPostData.put("IDXID", map.get("idxID"));
                }
                if (map.get("Abolidate") != null) {
                    oPostData.put("Abolidate", map.get("Abolidate"));
                }
                if (map.get("mdUpdTime") != null) {
                    oPostData.put("mdUpdTime", map.get("mdUpdTime"));
                }
                if (map.get("PubDate") != null) {
                    oPostData.put("PubDate", map.get("PubDate"));
                }
                if (map.get("Publisher") != null) {
                    oPostData.put("Publisher", map.get("Publisher"));
                }
                if (map.get("BGXZ") != null) {
                    oPostData.put("BGXZ", map.get("BGXZ"));
                }
                if (map.get("ZXZX") != null) {
                    oPostData.put("ZXZX", map.get("ZXZX"));
                }
                if (map.get("ZXTS") != null) {
                    oPostData.put("ZXTS", map.get("ZXTS"));
                }
                if (map.get("ZXSB") != null) {
                    oPostData.put("ZXSB", map.get("ZXSB"));
                }
                if (map.get("ZXCX") != null) {
                    oPostData.put("ZXCX", map.get("ZXCX"));
                }
                if (map.get("JGGS") != null) {
                    oPostData.put("JGGS", map.get("JGGS"));
                }
                if (map.get("MZ") != null) {
                    oPostData.put("MZ", map.get("MZ"));
                }
                if (map.get("ZW") != null) {
                    oPostData.put("ZW", map.get("ZW"));
                }
                if (map.get("FGGZ") != null) {
                    oPostData.put("FGGZ", map.get("FGGZ"));
                }
                if (map.get("XSDWLJ") != null) {
                    oPostData.put("XSDWLJ", map.get("XSDWLJ"));
                }
                if (map.get("XSDWLJ") != null) {
                    oPostData.put("XSDWLJ", map.get("XSDWLJ"));
                }
                if (map.get("Rreports") != null) {
                    oPostData.put("Rreports", map.get("Rreports"));
                }
                
                //主题分类-必填
                if (map.get("subcat") != null&&!map.get("subcat").toString().equals("")) {
                	String[] split = map.get("subcat").toString().split(",");
                	String newsubcat = "";
                	for(String oldthe:split) {
                		String newthe = classInfoMap.get(oldthe);
                		if(CMyString.isEmpty(newthe))continue;
                		newsubcat += newthe+",";
                	}
                	if(!CMyString.isEmpty(newsubcat)) {
                		newsubcat = newsubcat.substring(0,newsubcat.length()-1);
                		oPostData.put("SUBCAT", newsubcat);
                	}
                	
                }
                
                //所属体裁-必填
                if (map.get("themecat") != null&&!map.get("themecat").toString().equals("")) {
                	String[] split = map.get("themecat").toString().split(",");
                	String newthemecat = "";
                	for(String oldthe:split) {
                		String newthe = classInfoMap.get(oldthe);
                		if(CMyString.isEmpty(newthe))continue;
                		newthemecat += newthe+",";
                	}
                	if(!CMyString.isEmpty(newthemecat)) {
                		newthemecat = newthemecat.substring(0,newthemecat.length()-1);
                		oPostData.put("themecat", newthemecat);
                	}
                }
                
                //机构分类
                if (map.get("organcat") != null&&!map.get("organcat").toString().equals("")) {
                	String[] split = map.get("organcat").toString().split(",");
                	String neworg = "";
                	for(String oldthe:split) {
                		String newthe = classInfoMap.get(oldthe);
                		if(CMyString.isEmpty(newthe))continue;
                		neworg += newthe+",";
                	}
                	if(!CMyString.isEmpty(neworg)) {
                		neworg = neworg.substring(0,neworg.length()-1);
                		oPostData.put("organcat", neworg);
                	}
                }
                
                //机构分类
                if (map.get("newthemecat") != null&&!map.get("newthemecat").toString().equals("")) {
                	String[] split = map.get("newthemecat").toString().split(",");
                	String neworg = "";
                	for(String oldthe:split) {
                		String newthe = classInfoMap.get(oldthe);
                		if(CMyString.isEmpty(newthe))continue;
                		neworg += newthe+",";
                	}
                	if(!CMyString.isEmpty(neworg)) {
                		neworg = neworg.substring(0,neworg.length()-1);
                		oPostData.put("newthemecat", neworg);
                	}
                }
                
                
                if (map.get("ispdffile") != null) {
                	if("是".equals(map.get("ispdffile").toString())) {
                		oPostData.put("ispdffile", "1");
                	}else if("否".equals(map.get("ispdffile").toString())){
                		oPostData.put("ispdffile", "2");
                	}else {
                		oPostData.put("ispdffile", map.get("ispdffile"));
                	}
                }
                
                //标题-必填
                if (docTitle != null) {
                    oPostData.put("TITLE", docTitle);
                }
                
				if (map.get("Content") != null) {
					String htmlContent = map.get("Content").toString();
					// 处理内容中附件
					String ret_htmlContent = wcm.GetRetHtmlContent(htmlContent);
					if (ret_htmlContent != null && !ret_htmlContent.equals("")) {
						htmlContent = ret_htmlContent;
					}
					oPostData.put("Content", htmlContent);
				} else {
					oPostData.put("Content", "");
				}
                
				String docOrder = "";
				if (map.get("DOCORDER") != null) {
					docOrder = map.get("DOCORDER").toString();
					oPostData.put("docOrder", docOrder);
				}
                
                oPostData.put("olddocid", wcmDocId);
            	
            	//System.out.println("1111");
            	ArticleInfo arIf = new ArticleInfo();
            	arIf.setID(set.getString("DOCID"));
            	String channelIdFor = channelInfoMap.get(set.getString("CHNLID"));
            	arIf.setColumnID(channelIdFor);
            	String sTitle = set.getString("DOCTITLE");
				arIf.setTitle(CMyString.showEmpty(sTitle, "无标题"));
				
				arIf.setProperties(oPostData);
            	
            	//类型
				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("Content").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.writeXmlSzf(arIf, count);	
				
				
				//System.out.println("已搞定:"+count+ "[ID:" + arIf.getID() + "]");
            	
            }
            ConnectionUtil.closeConnection(set, statement, connection);
        } catch (Exception e) {
            Log_Exception.Error_txt("GetErrorDocInfoFromOldDB()方法异常"+e.getMessage());
        }
    }
    
    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;
		}
	}


}