package com.trs.web2frame.tool.tyjyh.wcmhy02.si;

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

import com.mysql.fabric.xmlrpc.base.Array;
import com.mysql.jdbc.log.Log;
import com.trs.web2frame.WCMServiceCaller;
import com.trs.web2frame.dispatch.Dispatch;
import com.trs.web2frame.tool.tyjyh.FujianUtil;
import com.trs.web2frame.tool.tyjyh.wcmhy02.ServiceImplWcm02;
import com.trs.web2frame.util.Log_Exception;

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

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

public class WCMUtilInterface02 {
    public static long timeSpan=0;
    //static Log_Exception logger = new Log_Exception();//日志
    //public static WCMUtilInterface wcm=new WCMUtilInterface();
    public static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");// 设置日期格式
    /**
     * 将文档引用到目标栏目并获取返回的recId
     * @param quetoType 引用类型
     * @param RecIDs 被引用文档RecId
     * @param DestChannelIds 目标栏目
     * @param WCM_DOCTITLE 原数据库中的标题（从返回的引用信息中获取标题不准确，例如标题中存在<br>换行符会丢失）
     * @return
     */
    public String quoteToAndGetRecId(String quetoType,String RecIDs,String DestChannelIds,String WCM_DOCTITLE){
        String ret_RecId="";
        
        try {
            if(RecIDs!=null&&!RecIDs.equals("")&&DestChannelIds!=null&&!DestChannelIds.equals("")){
                String rData=quoteTo(quetoType, RecIDs, DestChannelIds);
                if(rData!=null&&!rData.equals("")){
                    JSONArray rArray=JSONArray.fromObject(rData);
                    String rTitle=JSONObject.fromObject(rArray.get(0)).get("TITLE").toString();
                    String rDocTitle=rTitle.substring(rTitle.indexOf("[")+1, rTitle.indexOf("]"));//标题
                    rTitle=rTitle.substring(rTitle.indexOf("]")+1, rTitle.length());
                    String rDocId=rTitle.substring(rTitle.indexOf("[")+4, rTitle.indexOf("]"));//文档ID
                    rTitle=rTitle.substring(rTitle.indexOf("]")+1, rTitle.length());
                    String rChannelName=rTitle.substring(rTitle.indexOf("[")+1, rTitle.indexOf("]"));//栏目名称
                    rTitle=rTitle.substring(rTitle.indexOf("]")+1, rTitle.length());
                    String rChannelId=rTitle.substring(rTitle.indexOf("[")+4, rTitle.indexOf("]"));//栏目ID

                    Map<String,Object> map=GetDocumentRecIdInChannelTest(rChannelId);
                    if(map!=null&&map.size()>0&&!map.get("RECID").toString().equals("")&&map.get("DOCID").toString().equals(rDocId)){
                        ret_RecId=map.get("RECID").toString();
                    }else{
                        if(WCM_DOCTITLE==null||WCM_DOCTITLE.equals("")){
                            WCM_DOCTITLE=rDocTitle;
                        }
                        ret_RecId=GetDocumentRecIdInChannel(rChannelId, WCM_DOCTITLE, rDocId);
                    }
                    
                }
            }
            
            return ret_RecId;
        } catch (Exception e) {
            //TODO: handle exception
            Log_Exception.Error_txt("quoteToAndGetRecId()方法异常"+e.getMessage());
            return null;
        }
    }

    //引用方法
    /**
     * 将指定文档引用到指定栏目
     * @param quetoType 引用类型 1：本身 2:链接  3：镜像 4：复制
     * @param RecIDs
     * @param DestChannelIds
     * @return
     */
    public static long quetoTotalTime=0;
    public static int quetoTotalCount=0;
    public static String quoteTo(String quetoType,String RecIDs,String DestChannelIds){
        String sServiceId = "gov_webdocument";
        String sMethodName = "";
        if(quetoType.equals("2")){
            sMethodName = "quoteTo";
        }else if(quetoType.equals("3")){
            sMethodName = "mirrorTo";
        }else if(quetoType.equals("4")){
            sMethodName = "copyTo";
        }else{
            return null;
        }
        
        Map<String,Object> oPostData = new HashMap<>();
        oPostData.put("CurrUserName", "test1");
        String ret_Data="";
        try {
            if(RecIDs!=null&&!RecIDs.equals("")&&DestChannelIds!=null&&!DestChannelIds.equals("")){
                oPostData.put("RecIDs", RecIDs);
                oPostData.put("DestChannelIds", DestChannelIds);
                oPostData.put("isImmediatelyPublish", 0);
               
                // String timeNow1 = df.format(new Date()).toString();
                // System.out.println("接口开始调用"+timeNow1);
                long startTime = Util.fromDateStringToLong(df.format(new Date()));
                Dispatch result=WCMServiceCaller.Call(sServiceId, sMethodName, oPostData, true);
                long stopTime = Util.fromDateStringToLong(df.format(new Date()));
                // String timeNow2 = df.format(new Date()).toString();
                // System.out.println("接口调用结束"+timeNow2);
                if(result!=null){
                    JSONObject rObject=JSONObject.fromObject(result.getResponseText().toString());
                    if(rObject.get("ISSUCCESS").toString().equals("true")){
                        
                        quetoTotalCount++;
                        long timeSpan_temp = stopTime - startTime;
                        quetoTotalTime=quetoTotalTime+timeSpan_temp;
                        if(quetoTotalCount==1000){
//                            Log_Exception.Run_txt("引用接口处理1000条数据共花时间（毫秒）为："+quetoTotalTime);
                        }
                        ret_Data=rObject.get("DATA").toString();
                        System.out.println(ret_Data);//输出成功后结果
                        // String timeNow3 = df.format(new Date()).toString();
                        // System.out.println("完成引用时间"+timeNow3);
                        
                    }else{
                        String rMsg=rObject.get("MSG").toString();
                        System.out.println("引用失败！失败信息："+rMsg);
                        
                    }
                }
            }
            return ret_Data;
           
        } catch (Exception e) {
            //TODO: handle exception
            Log_Exception.Error_txt("quoteTo()方法异常"+e.getMessage());
            return null;
        }
    }



    //调序方法
    /**
     * 排序：将文档指定到目标文档的前/后
     * @param ChannelID
     * @param RECID
     * @param ToRecId
     * @return
     */
    public Boolean changeOrder(String ChannelID,String RECID,String ToRecId){
        String sServiceId = "gov_webdocument";
        String sMethodName = "changeOrder";
        Map<String,Object> oPostData = new HashMap<>();
        oPostData.put("CurrUserName", "test1");
        boolean ret=false;
        try {
            if(ChannelID!=null&&!ChannelID.equals("")&&RECID!=null&&!RECID.equals("")&&ToRecId!=null&&!ToRecId.equals("")){
                oPostData.put("ChannelID", ChannelID);
                oPostData.put("RECID", RECID);
                oPostData.put("ToRecId", ToRecId);
                oPostData.put("BeforeOrAfter", "After");
                Dispatch result=WCMServiceCaller.Call(sServiceId, sMethodName, oPostData, true);
                if(result!=null){
                    JSONObject rObject=JSONObject.fromObject(result.getResponseText().toString());
                    if(rObject.get("ISSUCCESS").toString().equals("true")){
                        String rData=rObject.get("DATA").toString();
                        System.out.println("成功"+rData);//输出成功后结果
                        ret=true;
                    }else{
                        String rMsg=rObject.get("MSG").toString();
                        System.out.println("失败:"+rMsg);
                        ret=false;
                    }
                }
            }
            return ret;
        } catch (Exception e) {
            //TODO: handle exception
            Log_Exception.Error_txt("changeOrder()方法异常"+e.getMessage());
            return false;
        }
    }

    /**
     * 根据条件获取栏目下文档的RecID
     * @param ChannelId 栏目id
     * @param DocTitle 文档标题
     * @param DocId 文档id
     * @return
     */
    public static String  GetDocumentRecIdInChannel(String ChannelId,String DocTitle,String DocId) {
        String sServiceId = "gov_webdocument";
        String sMethodName = "queryDocumentsInQuanbu";
        HashMap<String, Object> hParameters = new HashMap<>();
        hParameters.put("CurrUserName", "test1"); // 当前操作的用户
        hParameters.put("OnlyMy", "1");
        //hParameters.put("DocType", "20");
        hParameters.put("SearchFields", "DocTitle");
       
        //hParameters.put("pageSize", "200");
        //hParameters.put("pageIndex", index);
        String ret_RecId="";
        try {
            if(ChannelId!=null&&!ChannelId.equals("")&&DocTitle!=null&&!DocTitle.equals("")&&DocId!=null&&!DocId.equals("")){
                hParameters.put("ChannelId", ChannelId);
                hParameters.put("SearchValue", DocTitle);
                Dispatch result = WCMServiceCaller.Call(sServiceId, sMethodName, hParameters, true);
                if(result!=null){
                    JSONObject rObject=JSONObject.fromObject(result.getResponseText().toString());
                    if(rObject.get("ISSUCCESS").toString().equals("true")){
                        String rData=rObject.get("DATA").toString();
                        String rDataData=JSONObject.fromObject(rData).get("DATA").toString();
                        JSONArray rArray=JSONArray.fromObject(rDataData);
                        for (int i = 0; i < rArray.size(); i++) {
                            String DOCID=JSONObject.fromObject(rArray.get(i).toString()).get("DOCID").toString();//获取每条结果的文档id
                            if(DocId.equals(DOCID)){
                                ret_RecId=JSONObject.fromObject(rArray.get(i).toString()).get("RECID").toString();
                            }
                        }
                    }else{
                        String rMsg=rObject.get("MSG").toString();
                        System.out.println("失败:"+rMsg);
                    }
                }
            }
            return ret_RecId;
        } catch (Exception e) {
            Log_Exception.Error_txt("GetAllDocumentInChannel()方法异常" + e.getMessage());
            return null;
        }
    }

    /**根据recId返回文档信息
     * 
     * @param recId
     * @return  {"DOCID":"1542690","CHNLID":"32829","DEFAULTVIEW":"1","STATUSOPRKEY":"yifa","DOCSTATUS":"10","RECID":"2076971","ADDEDITHTML":"/app/application/42/metaviewdata_addedit.html?2020-01-1517:05:13.874","SITEID":"91","DOCTYPE":"20"}
     */
    public String  GetDocByRecId(int recId){
        String sServiceId = "gov_webdocument";
        String sMethodName = "obtainInfoByRecId";
        Map<String,Object> oPostData = new HashMap<>();
        oPostData.put("CurrUserName", "test1");
        String rData="";
        try {
            if(recId>0){
                oPostData.put("recid", recId);
                Dispatch result = WCMServiceCaller.Call(sServiceId, sMethodName, oPostData, true);
                if(result!=null){
                    JSONObject rObject=JSONObject.fromObject(result.getResponseText().toString());
                    if(rObject.get("ISSUCCESS").toString().equals("true")){
                        rData=rObject.get("DATA").toString();
                        //System.out.print(rData);
                    }
                }
            }
            return rData;
        } catch (Exception e) {
            //TODO: handle exception
            Log_Exception.Error_txt("GetDocByRecId()方法异常" + e.getMessage());
            return null;
        }
    }

    /**
     * 根据栏目id和docid获取文档信息
     * @param docId 文档id
     * @param channelId 栏目id
     * @return {"DOCRELFILE":[],"CRTIME":"2019-12-13 21:32:09","DOCPUBTIME":"2020-03-07 16:56:57","ENDTIME":"","CHANNELID":"32829","DOCSTATUS":"10","DOCRELTIME":"2009-07-17 14:18:00","DOCSOURCENAME":"和
平区政府","ATTACHPIC":"0","DOCCONTENT":"　　日前，随着崇仁里、新河里小区提升改造工程的竣工...。","DOCID":"1542690","ISINDEXCONTENTTYPE":"0","CHNLID":"32829","ISINDEXTITLE":"0"
,"DOCTITLE":"和平区完成50余万平方米旧楼区综合整修","DATASENDMODE":"0","DOCFILE":[],"DOCRELVIDEO":[],"CHANNELNAME":"各区动态","THUMBFILES":"","DOCTYPE":"20","DOCRELZC":[],"DOCRELPIC":[]
,"CANEDIT":"true","ISCOMMENT":"0","OTHERPUBLISH":[{"OPERUSER":"陆亨钧","CRTIME":"2019-12-23 20:40:41","TIMEDSTATUS":"0","OTHERVIEWMODE":"0","DOCFLAG":"0","OPERTIME":"2020-03-06 23:01:49"
,"DOCPUBTIME":"2020-03-07 01:02:42","MEDIATYPE":"1","POSCHNLID":"0","DOCSTATUS":"10","SRCSITEID":"91","CRDEPT":"","DOCRELTIME":"2009-07-17 14:18:00","DELETED":"0","NODEID":"0"
,"ATTACHPIC":"0","DOCSOURCENAME":"和平区政府","REFUSESTATUS":"0","ORIGINRECID":"1549128","DOCID":"1542690","CHNLID":"36619","GDORDER":"0","DATASENDMODE":"0"
,"DOCPUBURL":"http://ceshi.tj.gov.cn:11121/qtmb_19564/zwdt/201912/t20191213_1542690.html","ISTIMINGPUBLISH":"0","ACTIONUSER":"test1","DOCFORM":"0","DOCTYPE":"20","DOCFIRSTPUBTIME":"2019-12-23 22:32:07"
,"DOCOUTUPID":"0","SITENAME":"天津市政府_91","CANEDIT":"true","DOCKIND":"42","DOCORDER":"42416","RECID":"2076971","ACTIONTYPE":"0","SITEID":"91","CHNLDESC":"天津政务网 > 首页 > 政务动态"
,"PUBSTATUS":"1","DOCCHANNEL":"32829","PUSHUIRBSTATUS":"1","MODAL":"3","CANCELPUBTIME":"","CHNLNAME":"政务动态","INVALIDTIME":"","CRUSER":"test1","DOCORDERPRI":"0"}],"RECID":"1549128","CHNLIDNAME":"各区动态"
,"DOCRELNEWS":[],"ORIGINMETADATAID":"1542690","SITEID":"91","ISBOLD":"0","DOCCHANNEL":"32829","PUBSTATUS":"1","METADATAID":"1542690","CANCELPUBTIME":"","ATTACHVIDEO":"0","STARTTIME":""
,"DOCHTMLCON":" ","DOCRELATION":[],"CRUSER":"test1","WCMMETATABLEGOVDOC_SZFID":"96387"}
     */
    public String GetDocInfoByDocID(String channelId,String docId){
        String sServiceId = "gov_webdocument";
		String sMethodName = "findDynamicDocumentById";
		//String sMethodName = "findOpenDataDocumentById";
		HashMap<String, Object> oPostData = new HashMap<>();
        oPostData.put("CurrUserName", "test1"); // 当前操作的用户
        String rData="";
        try {
            if(docId!=null&&!docId.equals("")&&channelId!=null&&!channelId.equals("")){
                oPostData.put("ChannelId", channelId);
                oPostData.put("DocId", docId);
                Dispatch result = WCMServiceCaller.Call(sServiceId, sMethodName, oPostData, true);
                if(result!=null){
                    JSONObject rObject=JSONObject.fromObject(result.getResponseText().toString());
                    if(rObject.get("ISSUCCESS").toString().equals("true")){
                        rData=rObject.get("DATA").toString();
                        //System.out.print(rData);
                    }
                }
            }
            return rData;
        } catch (Exception e) {
            //TODO: handle exception
            Log_Exception.Error_txt("GetDocInfoByDocID()方法异常" + e.getMessage());
            return null;
        }
        
    }

    //提取编辑器中图片（附件）到相关图片（相关附件中）
    /**
     * 
     * @param fileUrl 
     * 
     * F:\\住建委\\WCMData\\webpic\\W0202001\\W020200115\\W020200115361703263706.jpg  不可以
     * G:\\农委\\WCMData\\webpic\\W0201804\\W020180428\\W020180428456557898110.jpg 不可以
     * F:\住建委\WCMData\webpic\W0202001\W020200108\W020200108438222984462.xls 不可以
     * http://192.156.41.118:8081/nongwei/WCMData/webpic/W0202003/W020200305/W020200305583725939117.jpg 可以
     * http://60.28.163.184/index/dbtklj/201803/W020180428421951524497.png 可以
     * http://zfcxjs.tj.gov.cn/xxgk_70/wfwj/202002/P020200211484299241261.docx 可以
     * 
     * @param type 0:图片  1（0以外）：附件
     * @return  http://10.99.255.1/gov/openapi/readimg?ScaleWidth=600&FileName=W020200313430873150675.jpg  图片返回结果
     * @return  W020200108438222984462.xls  P020200211484299241261.docx 附件返回结果
     */
    public String extractAppendix(String type,String fileUrl){
        String sServiceId = "gov_appendix";
		String sMethodName = "extractAppendix";
		//String sMethodName = "findOpenDataDocumentById";
		HashMap<String, Object> oPostData = new HashMap<>();
        oPostData.put("CurrUserName", "test1"); // 当前操作的用户
        String rData="";
        try {
            if(fileUrl!=null&&!fileUrl.equals("")){
                oPostData.put("fileUrl", fileUrl);
                oPostData.put("type", type);
                Dispatch result = WCMServiceCaller.Call(sServiceId, sMethodName, oPostData, true);
                if(result!=null){
                    JSONObject rObject=JSONObject.fromObject(result.getResponseText().toString());
                    if(rObject.get("ISSUCCESS").toString().equals("true")){
                        rData=rObject.get("DATA").toString();
                        System.out.print(rData);
                    }else{
                        Log_Exception.Logger_txt("内容中附件提取失败："+fileUrl);
                    }
                }
            }
            return rData;
        } catch (Exception e) {
            Log_Exception.Error_txt("extractAppendix()方法异常" + e.getMessage());
            //TODO: handle exception
            return null;
        }
    }

    /**
     * 处理内容中的附件
     * @param htmlContent
     * @return
     */
    public String GetRetHtmlContent(String htmlContent){
        WCMUtilInterface02 wcm=new WCMUtilInterface02();
        String ret_htmlContent=htmlContent;
        //1.找出内容中的所有图片 2.找出内容中的附件 3.调接口上传图片/附件并记录返回的信息 4.替换正文中的对应图片/附件信息
        try {
            Document doc = Jsoup.parse(htmlContent);
            Elements sectionNodes = doc.getAllElements();
            String imgStr="";
            String fileStr="";
            String oldsrc="";
            for (int i = 0; i < sectionNodes.size(); i++){
                Element Node = sectionNodes.get(i);
                //找图片
                if ("img".equals(Node.nodeName())||Node.nodeName().equals("IMG")) {
                    //如果是相对路径
                    if (Node.attr("src") != null) {
                        String temp = Node.attr("src");
                        if(imgStr.equals("")){
                            imgStr+=temp;
                        }else if(!imgStr.contains(temp)){
                            imgStr+=","+temp;
                        }
                    }
                }
                //找文件
                if("a".equals(Node.nodeName())){
                    if (Node.attr("href") != null && !Node.attr("href").equals("")&&Node.hasText()){
                        //判断该链接是否是文件
                        String temp=Node.attr("href");
                        boolean isfile= IsContainFile(temp);
                        if(isfile){
                            if(fileStr.equals("")){
                                fileStr+=temp;
                            }else if(!fileStr.contains(temp)){
                                fileStr+=","+temp;
                            }
                        }
                    }
                }
                //找oldsrc
                if("img".equals(Node.nodeName())){
                    if (Node.attr("OLDSRC") != null && !Node.attr("OLDSRC").equals("")){
                        //判断该链接是否是文件
                        String temp=Node.attr("OLDSRC");
                            if(oldsrc.equals("")){
                            	oldsrc+=temp;
                            }else if(!oldsrc.contains(temp)){
                            	oldsrc+=","+temp;
                        }
                    }
                }
            }
            if(!imgStr.equals("")){
            	System.out.println("zheng wen tu pian"+imgStr);
                String[] imagArray=imgStr.split(",");
                for (int i = 0; i < imagArray.length; i++) {
                    String filePath=FujianUtil.getFullPathUpload(imagArray[i]);
                    //String hyfilePath=wcm.extractAppendix("0", filePath);
                    if(filePath!=null&&!filePath.equals("")){
                        ret_htmlContent=ret_htmlContent.replace(imagArray[i], filePath);
                    }
                }
            }
            
            if(!oldsrc.equals("")){
                String[] oldsrcArray=oldsrc.split(",");
                for (int i = 0; i < oldsrcArray.length; i++) {
                    //String hyfilePath=wcm.extractAppendix("0", filePath);
                	String string = oldsrcArray[i];
                	String ord = "OLDSRC=\""+string+"\"";
                	ret_htmlContent=ret_htmlContent.replace(ord, "");
                }
            }
            
            if(!fileStr.equals("")){
                String[] fileArray=fileStr.split(",");
                for (int i = 0; i < fileArray.length; i++) {
                	String filePath=FujianUtil.getFullPathUpload(fileArray[i]);
//                    String filePath=FujianUtil.getFullPath(fileArray[i]);
//                    String hyfilePath=wcm.extractAppendix("3", filePath);
                    if(filePath!=null&&!filePath.equals("")){
                        ret_htmlContent=ret_htmlContent.replace(fileArray[i], filePath);
                    }
                }
            }
            
            return ret_htmlContent;
        } catch (Exception e) {
            //TODO: handle exception
            Log_Exception.Error_txt("GetAllFileInfoInContent()方法异常" + e.getMessage());
            return null;
        }
    }



    /**
     * 根据DOcID获取文档相关的附件信息
     * @param docId
     * @return
     */
    public Map<String,Object> GetRelFileInfoByDocId(String docId){
        // 获取文档相关的附件信息
        Map<String,Object> map=new HashMap<>();
			StringBuilder docRelFile = new StringBuilder();// 相关文件
			StringBuilder picRelFile = new StringBuilder();// 相关图片
			ServiceImplWcm02 sit=new ServiceImplWcm02();
            try {
                List<Map<String,Object>> fileList=sit.GetFilesInfoByDocId(docId);
                docRelFile.append("[");
                picRelFile.append("[");
                if (fileList!= null) {
                     System.out.println("fu jian"+fileList.size());
                    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 final_file = FujianUtil.getLocalFullPathDownload(pathfile);// 拼接后的数据
                        //开始下载附件///
                        
                        String appFile = "";
                        // System.out.println(final_file);
                        String appFlag = jsonObject.get("APPFLAG").toString();//附件类型
                            if(!appFlag.equals("40")){
                                Dispatch oDispatch = WCMServiceCaller.UploadFile(final_file);
                                if (oDispatch == null) {
                                    Log_Exception.Logger_txt("docId:"+docId+ "————文件上传失败："+pathfile );
                                } else {
                                    appFile = oDispatch.getUploadShowName();
                                    if(!appFile.equals("")){

                                    }else{
                                        Log_Exception.Logger_txt("docId:"+docId+ "————文件上传失败："+pathfile );
                                    }
                                    
                                }
                            }else {
                            	map.put("appflag40", jsonObject.get("APPDESC").toString());
                            	map.put("appflag41", jsonObject.get("SRCFILE").toString());
                            }
                        String srcFile = jsonObject.get("SRCFILE").toString();
    
                        String appDesc = jsonObject.get("APPDESC").toString();
                        
                        // 判断如果是文件
                        if (appFlag.equals("20")||appFlag.equals("10")||appFlag.equals("70")||appFlag.equals("130")) {
                            docRelFile.append("{\"SrcFile\":\"" + srcFile + "\",\"AppFile\":\"" + appFile
                                    + "\",\"AppDesc\":\"" + appDesc + "\", \"AppendixId\":\"0\" }");
                            if (f < jsonArray.size() - 1) {
                                docRelFile.append(",");
                            }
                        }
                        // 判断如果是图片
                        if (appFlag.equals("20")) {
                            picRelFile.append("{\"SrcFile\":\"" + srcFile + "\",\"AppFile\":\"" + appFile
                                    + "\",\"AppDesc\":\"" + appDesc + "\", \"AppendixId\":\"0\" }");
                            if (f < jsonArray.size() - 1) {
                                picRelFile.append(",");
                            }
                        }
    
                    }
                }
                docRelFile.append("]");
                picRelFile.append("]");
                //默认视图
                map.put("docRelFile", docRelFile);
                map.put("DocRelPic", picRelFile);
                //自定义视图
                map.put("DOCATTACHFILEFIELD", docRelFile);
                map.put("DOCATTACHPICFIELD", picRelFile);
                
                map.put("fj", docRelFile);
                //map.put("fj", picRelFile);
//                map.put("fj", picRelFile);
                return map;
    
                
            } catch (Exception e) {
                //TODO: handle exception
                Log_Exception.Error_txt("GetRelFileInfoByDocId()方法异常！"+e.getMessage());
                return null;
            }
			
    }

    public static void main(String[] args) {
        WCMUtilInterface02 wcm=new WCMUtilInterface02();
        //String recid=wcm.quoteToAndGetRecId("2","2307487","43457");
       // System.out.println(recid);
        wcm.quoteTo("3","2693218", "44064");//43275
        //wcm.GetDocumentRecIdInChannel("43457","深化京津冀协同发展<br>精准务实承接北京非首都功能","2115638");//715586 //种植业污染防治工作协调推动会
        //wcm.changeOrder("13562", "2252500", "2253197");
        //wcm.GetDocByRecId(2076971);
        //wcm.GetDocInfoByDocID("32829", "1542690");
       // wcm.extractAppendix("0","F:\\nw\\WCMData\\webpic\\W0201806\\W020180608\\W020180608370131192504.jpg");
        //wcm.extractAppendix("0", "http://117.78.17.106:8121/h5/static/logo.png");

        //GetDocumentRecIdInChannelTest("42345");
    }

   
    //判断字符串中是否包含图片
    public static Boolean IsContainImg(String content){
        if(content!=null&&!content.equals("")) {
            String regExImg = "(.jpg|.gif|.png|.jpeg|.bmp|.JPG|.GIF|.PNG|.JPEG|.BMP)";//正文中图片--------------add by miyanzhao20190111
            Pattern patternImg = Pattern.compile(regExImg);
            Matcher matcherImg = patternImg.matcher(content);

            if(matcherImg.find()) {
                return true;
            }else{
                return false;
            }
        }else{
            return false;
        }
    }
//判断字符串中是否包含附件
    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)";//正文中图片--------------add by miyanzhao20190111
            Pattern patternImg = Pattern.compile(regExImg);
            Matcher matcherImg = patternImg.matcher(content);

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


    /**
     * 根据条件获取栏目下文档的RecID()
     * @param ChannelId 栏目id
     * @param DocTitle 文档标题
     * @param DocId 文档id
     * @return
     */
    public static int yycount=0;
    public static Map<String,Object>  GetDocumentRecIdInChannelTest(String ChannelId) {
        // SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");// 设置日期格式
       
        Map<String,Object> map=new HashMap<>();
        String sServiceId = "gov_webdocument";

        String sMethodName = "queryDocumentsInQuanbu";
        HashMap<String, Object> hParameters = new HashMap<>();
        hParameters.put("CurrUserName", "test1"); // 当前操作的用户
        hParameters.put("OnlyMy", "1");
        //hParameters.put("DocType", "20");
        //hParameters.put("SearchFields", "DocTitle");
       
        hParameters.put("pageSize", "1");
        hParameters.put("pageIndex", 1);
        String ret_RecId="";
        String DOCID="";
        try {
            if(ChannelId!=null&&!ChannelId.equals("")){
                hParameters.put("ChannelId", ChannelId);
                //hParameters.put("SearchValue", DocTitle);
                //String timeNow1 = df.format(new Date()).toString();
                long startTime = Util.fromDateStringToLong(df.format(new Date()));
                //System.out.println("queryDocumentsInQuanbu接口开始调用"+timeNow1);
                Dispatch result = WCMServiceCaller.Call(sServiceId, sMethodName, hParameters, true);
                long stopTime = Util.fromDateStringToLong(df.format(new Date()));
                //String timeNow2 = df.format(new Date()).toString();
                //System.out.println("queryDocumentsInQuanbu接口调用结束"+timeNow2);
                //计算时间差,单位毫秒
                if(result!=null){
                    JSONObject rObject=JSONObject.fromObject(result.getResponseText().toString());
                    if(rObject.get("ISSUCCESS").toString().equals("true")){
                        long timeSpan_temp = stopTime - startTime;
                        timeSpan=timeSpan+timeSpan_temp;
                        yycount++;
                        if(yycount==1000){
//                            Log_Exception.Run_txt("queryDocumentsInQuanbu接口处理完1000条数据共花费时间为（毫秒）："+timeSpan);
                        }
                        String rData=rObject.get("DATA").toString();
                        String rDataData=JSONObject.fromObject(rData).get("DATA").toString();
                        JSONArray rArray=JSONArray.fromObject(rDataData);
                       
                        DOCID=JSONObject.fromObject(rArray.get(0).toString()).get("DOCID").toString();//获取每条结果的文档id
                        ret_RecId=JSONObject.fromObject(rArray.get(0).toString()).get("RECID").toString();
                        map.put("DOCID", DOCID);
                        map.put("RECID", ret_RecId);
                    //     System.out.println(0+" DOCID:"+DOCID+" RECID:"+ret_RecId);
                   
                        
                    }else{
                        String rMsg=rObject.get("MSG").toString();
                        System.out.println("失败:"+rMsg);
                    }
                }
            }
            return map;
        } catch (Exception e) {
            Log_Exception.Error_txt("GetAllDocumentInChannel()方法异常" + e.getMessage());
            return null;
        }
    }

    

}