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

import com.alibaba.fastjson.JSON;
import com.trs.cms.CMSConstants;
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.util.Log_Exception;
import net.sf.json.JSONObject;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;

public class ServiceImplKp2 {
    private String sqlType = ConfigConstant.SQLTYPE;

    /**
     * 从开普系统当中查询对应的资讯信息
     * @param channelId
     * @return
     */
    public List<Map<String,Object>> GetAllDocInfoFromKPDB(String channelId){
        List<Map<String, Object>> oldMaps = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        ResultSet set = null;
        try {
            StringBuilder sb=new StringBuilder(
               "SELECT " +
                       " cm.MANUSCRIPT_ID manuscriptId,  " +
                       " cm.WEBSITE_ID websiteId,  " +
                       " cm.TITLE title,  " +
                       " cm.SHORT_TITLE shortTitle,  " +
                       " cm.KEYWORD KEYWORD,  " +
                       " cm.MEMO memo,  " +
                       " cm.SUB_TITLE subTitle,  " +
                       " cm.PUBLISHED_TIME publishedTime,  " +
                       " cm.MODIFIED_TIME modifiedTime,  " +
                       " cm.CREATED_TIME CREATED_TIME,  " +
                       " cm.URL url,  " +
                       " cm.STATUS CMSTATUS,  " +
                       " cm.TYPE type,  " +
                       " cm.IS_AUTORECALL isAutorecall,  " +
                       " cm.HAS_IMG hasImg,  " +
                       " cm.HAS_VIDEO hasVideo,  " +
                       " cm.HAS_DOC hasDoc,  " +
                       " cm.HAS_RADIO hasRadio,  " +
                       " cm.REDIRECT_URL REDIRECT_URL,  " +
                       " sfn.FS_NAMES_ID fsNamesId,  " +
                       " sfn.CURRENT_FILE_PATH currentFilePath,  " +
                       " concat( sfn.CURRENT_FILE_PATH, \"/\", substring( sfn.FS_NAMES_ID, 5, 29 ), \".html\" ) currentFilePathHtmlUrl,  " +
                       " cw.NAME cwName,  " +
                       " cc.CHANNEL_ID ChannelId,  " +
                       " cc.CHANNEL_NAME channelName,  " +
                       " cw.URL site_url,  " +
                       " cc.URL channel_url,  " +
                       " cc.PARENT_ID channelParentId,  " +
                       " cc.IS_NAVIGATION IS_NAVIGATION,  " +
                       " cc.STATUS ccSTATUS,  " +
                       " cmmc.C_GKSX C_GKSX,  " +
                       " cmmc.C_FWRQ C_FWRQ,  " +
                       " cmmc.C_FBJG C_FBJG,  " +
                       " cmmc.C_SYH C_SYH,  " +
                       " cmmc.C_WJBH C_WJBH,  " +
                       " cmmc.C_ZTC C_ZTC,  " +
                       " cmmc.C_ZHUTI C_ZHUTI," +
                       " cms_c.CN_NAME CN_NAME," +
                       " cb.b_source as b_source" +
                       " FROM  " +
                       " CMS_MANUSCRIPT cm  " +
                       " LEFT JOIN cms_fs_names sfn ON sfn.RES_ID = cm.MANUSCRIPT_ID  " +
                       " LEFT JOIN CMS_CHANNEL cc ON cm.CHANNEL_ID = cc.CHANNEL_ID  " +
                       " LEFT JOIN CMS_WEBSITE cw ON cm.WEBSITE_ID = cw.WEBSITE_ID  " +
                       " LEFT JOIN CMS_MANUSCRIPT_METADATA_B CB   ON CB.MANUSCRIPT_METADATA_ID=cm.MANUSCRIPT_ID" +
                       " LEFT JOIN cms_manuscript_metadata_c cmmc ON cm.MANUSCRIPT_ID = cmmc.MANUSCRIPT_METADATA_ID  " +
                       " LEFT JOIN cms_code cms_c ON cms_c.CODE_ID = substring_index( cmmc.C_ZHUTI, \";\", 1 )   " +
               " where " +
                       " cm.CHANNEL_ID ='"+channelId+"'" +
                       " and  cm.STATUS = 4" +
                       " order by cm.SEQ_NUM asc  "

            );
            System.out.println(sb);
            connection = ConnectionUtil.getConnection("mysql");
            statement = connection.createStatement();
            set = statement.executeQuery(sb.toString());
            while (set.next()){
                System.out.println(set);
                Map<String, Object> map = new HashMap<>();
                map.put("manuscriptId", set.getString("manuscriptId"));
                map.put("websiteId", set.getString("websiteId"));
                map.put("title", set.getString("title"));
                map.put("shortTitle", set.getString("shortTitle"));
                map.put("KEYWORD", set.getString("KEYWORD"));
                map.put("memo", set.getString("memo"));
                map.put("subTitle", set.getString("subTitle"));
                map.put("publishedTime", set.getString("publishedTime"));
                map.put("modifiedTime", set.getString("modifiedTime"));
                map.put("CREATED_TIME", set.getString("CREATED_TIME"));
                map.put("url", set.getString("url"));
                map.put("CMSTATUS", set.getString("CMSTATUS"));
                map.put("type", set.getString("type"));
                map.put("isAutorecall", set.getString("isAutorecall"));
                map.put("hasImg", set.getString("hasImg"));
                map.put("hasVideo", set.getString("hasVideo"));
                map.put("hasDoc", set.getString("hasDoc"));
                map.put("hasRadio", set.getString("hasRadio"));
                map.put("REDIRECT_URL", set.getString("REDIRECT_URL"));
                map.put("fsNamesId", set.getString("fsNamesId"));
                map.put("currentFilePath", set.getString("currentFilePath"));
                map.put("currentFilePathHtmlUrl", set.getString("currentFilePathHtmlUrl"));
                map.put("cwName", set.getString("cwName"));
                map.put("ChannelId", set.getString("ChannelId"));
                map.put("channelName", set.getString("channelName"));
                map.put("site_url", set.getString("site_url"));
                map.put("channel_url", set.getString("channel_url"));
                map.put("channelParentId", set.getString("channelParentId"));
                map.put("IS_NAVIGATION", set.getString("IS_NAVIGATION"));
                map.put("ccSTATUS", set.getString("ccSTATUS"));
                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"));
                map.put("CN_NAME", set.getString("CN_NAME"));
                map.put("b_source", set.getString("b_source"));
                oldMaps.add(map);
            }
            return oldMaps;
        } catch (Exception e) {
            Log_Exception.Error_txt("GetAllDocInfoFromOldDB() error"+e.getMessage());
            return null;
        } finally {
            ConnectionUtil.closeConnection(set, statement, connection);
        }
    }
    public List<Map<String,Object>> GetAllDocInfoFromKPDBOne(String manuscriptIdStr){
        List<Map<String, Object>> oldMaps = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        ResultSet set = null;
        try {
            StringBuilder sb=new StringBuilder(
                    "SELECT " +
                            " cm.MANUSCRIPT_ID manuscriptId,  " +
                            " cm.WEBSITE_ID websiteId,  " +
                            " cm.TITLE title,  " +
                            " cm.SHORT_TITLE shortTitle,  " +
                            " cm.KEYWORD KEYWORD,  " +
                            " cm.MEMO memo,  " +
                            " cm.SUB_TITLE subTitle,  " +
                            " cm.PUBLISHED_TIME publishedTime,  " +
                            " cm.MODIFIED_TIME modifiedTime,  " +
                            " cm.CREATED_TIME CREATED_TIME,  " +
                            " cm.URL url,  " +
                            " cm.STATUS CMSTATUS,  " +
                            " cm.TYPE type,  " +
                            " cm.IS_AUTORECALL isAutorecall,  " +
                            " cm.HAS_IMG hasImg,  " +
                            " cm.HAS_VIDEO hasVideo,  " +
                            " cm.HAS_DOC hasDoc,  " +
                            " cm.HAS_RADIO hasRadio,  " +
                            " cm.REDIRECT_URL REDIRECT_URL,  " +
                            " sfn.FS_NAMES_ID fsNamesId,  " +
                            " sfn.CURRENT_FILE_PATH currentFilePath,  " +
                            " concat( sfn.CURRENT_FILE_PATH, \"/\", substring( sfn.FS_NAMES_ID, 5, 29 ), \".html\" ) currentFilePathHtmlUrl,  " +
                            " cw.NAME cwName,  " +
                            " cc.CHANNEL_ID ChannelId,  " +
                            " cc.CHANNEL_NAME channelName,  " +
                            " cw.URL site_url,  " +
                            " cc.URL channel_url,  " +
                            " cc.PARENT_ID channelParentId,  " +
                            " cc.IS_NAVIGATION IS_NAVIGATION,  " +
                            " cc.STATUS ccSTATUS,  " +
                            " cmmc.C_GKSX C_GKSX,  " +
                            " cmmc.C_FWRQ C_FWRQ,  " +
                            " cmmc.C_FBJG C_FBJG,  " +
                            " cmmc.C_SYH C_SYH,  " +
                            " cmmc.C_WJBH C_WJBH,  " +
                            " cmmc.C_ZTC C_ZTC,  " +
                            " cmmc.C_ZHUTI C_ZHUTI," +
                            " cms_c.CN_NAME CN_NAME," +
                            " cb.b_source as b_source" +
                            " FROM  " +
                            " CMS_MANUSCRIPT cm  " +
                            " LEFT JOIN cms_fs_names sfn ON sfn.RES_ID = cm.MANUSCRIPT_ID  " +
                            " LEFT JOIN CMS_CHANNEL cc ON cm.CHANNEL_ID = cc.CHANNEL_ID  " +
                            " LEFT JOIN CMS_WEBSITE cw ON cm.WEBSITE_ID = cw.WEBSITE_ID  " +
                            " LEFT JOIN CMS_MANUSCRIPT_METADATA_B CB   ON CB.MANUSCRIPT_METADATA_ID=cm.MANUSCRIPT_ID" +
                            " LEFT JOIN cms_manuscript_metadata_c cmmc ON cm.MANUSCRIPT_ID = cmmc.MANUSCRIPT_METADATA_ID  " +
                            " LEFT JOIN cms_code cms_c ON cms_c.CODE_ID = substring_index( cmmc.C_ZHUTI, \";\", 1 )   " +
                            " where " +
                            " cm.MANUSCRIPT_ID = '"+manuscriptIdStr+"'" +
                            " and  cm.STATUS = 4" +
                            " order by cm.SEQ_NUM asc  "

            );
            System.out.println(sb);
            connection = ConnectionUtil.getConnection("mysql");
            statement = connection.createStatement();
            set = statement.executeQuery(sb.toString());
            while (set.next()){
                System.out.println(set);
                Map<String, Object> map = new HashMap<>();
                map.put("manuscriptId", set.getString("manuscriptId"));
                map.put("websiteId", set.getString("websiteId"));
                map.put("title", set.getString("title"));
                map.put("shortTitle", set.getString("shortTitle"));
                map.put("KEYWORD", set.getString("KEYWORD"));
                map.put("memo", set.getString("memo"));
                map.put("subTitle", set.getString("subTitle"));
                map.put("publishedTime", set.getString("publishedTime"));
                map.put("modifiedTime", set.getString("modifiedTime"));
                map.put("CREATED_TIME", set.getString("CREATED_TIME"));
                map.put("url", set.getString("url"));
                map.put("CMSTATUS", set.getString("CMSTATUS"));
                map.put("type", set.getString("type"));
                map.put("isAutorecall", set.getString("isAutorecall"));
                map.put("hasImg", set.getString("hasImg"));
                map.put("hasVideo", set.getString("hasVideo"));
                map.put("hasDoc", set.getString("hasDoc"));
                map.put("hasRadio", set.getString("hasRadio"));
                map.put("REDIRECT_URL", set.getString("REDIRECT_URL"));
                map.put("fsNamesId", set.getString("fsNamesId"));
                map.put("currentFilePath", set.getString("currentFilePath"));
                map.put("currentFilePathHtmlUrl", set.getString("currentFilePathHtmlUrl"));
                map.put("cwName", set.getString("cwName"));
                map.put("ChannelId", set.getString("ChannelId"));
                map.put("channelName", set.getString("channelName"));
                map.put("site_url", set.getString("site_url"));
                map.put("channel_url", set.getString("channel_url"));
                map.put("channelParentId", set.getString("channelParentId"));
                map.put("IS_NAVIGATION", set.getString("IS_NAVIGATION"));
                map.put("ccSTATUS", set.getString("ccSTATUS"));
                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"));
                map.put("CN_NAME", set.getString("CN_NAME"));
                map.put("b_source", set.getString("b_source"));
                oldMaps.add(map);
            }
            return oldMaps;
        } catch (Exception e) {
            Log_Exception.Error_txt("GetAllDocInfoFromOldDB() error"+e.getMessage());
            return null;
        } finally {
            ConnectionUtil.closeConnection(set, statement, connection);
        }
    }

    public List<Map<String,Object>> GetAllDocInfoFromKPDBOne(String channelId,String manuscriptIdStr){
        List<Map<String, Object>> oldMaps = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        ResultSet set = null;
        try {
            StringBuilder sb=new StringBuilder(
                    "SELECT " +
                            " cm.MANUSCRIPT_ID manuscriptId,  " +
                            " cm.WEBSITE_ID websiteId,  " +
                            " cm.TITLE title,  " +
                            " cm.SHORT_TITLE shortTitle,  " +
                            " cm.KEYWORD KEYWORD,  " +
                            " cm.MEMO memo,  " +
                            " cm.SUB_TITLE subTitle,  " +
                            " cm.PUBLISHED_TIME publishedTime,  " +
                            " cm.MODIFIED_TIME modifiedTime,  " +
                            " cm.CREATED_TIME CREATED_TIME,  " +
                            " cm.URL url,  " +
                            " cm.STATUS CMSTATUS,  " +
                            " cm.TYPE type,  " +
                            " cm.IS_AUTORECALL isAutorecall,  " +
                            " cm.HAS_IMG hasImg,  " +
                            " cm.HAS_VIDEO hasVideo,  " +
                            " cm.HAS_DOC hasDoc,  " +
                            " cm.HAS_RADIO hasRadio,  " +
                            " cm.REDIRECT_URL REDIRECT_URL,  " +
                            " sfn.FS_NAMES_ID fsNamesId,  " +
                            " sfn.CURRENT_FILE_PATH currentFilePath,  " +
                            " concat( sfn.CURRENT_FILE_PATH, \"/\", substring( sfn.FS_NAMES_ID, 5, 29 ), \".html\" ) currentFilePathHtmlUrl,  " +
                            " cw.NAME cwName,  " +
                            " cc.CHANNEL_ID ChannelId,  " +
                            " cc.CHANNEL_NAME channelName,  " +
                            " cw.URL site_url,  " +
                            " cc.URL channel_url,  " +
                            " cc.PARENT_ID channelParentId,  " +
                            " cc.IS_NAVIGATION IS_NAVIGATION,  " +
                            " cc.STATUS ccSTATUS,  " +
                            " cmmc.C_GKSX C_GKSX,  " +
                            " cmmc.C_FWRQ C_FWRQ,  " +
                            " cmmc.C_FBJG C_FBJG,  " +
                            " cmmc.C_SYH C_SYH,  " +
                            " cmmc.C_WJBH C_WJBH,  " +
                            " cmmc.C_ZTC C_ZTC,  " +
                            " cmmc.C_ZHUTI C_ZHUTI," +
                            " cms_c.CN_NAME CN_NAME," +
                            " cb.b_source as b_source" +
                            " FROM  " +
                            " CMS_MANUSCRIPT cm  " +
                            " LEFT JOIN cms_fs_names sfn ON sfn.RES_ID = cm.MANUSCRIPT_ID  " +
                            " LEFT JOIN CMS_CHANNEL cc ON cm.CHANNEL_ID = cc.CHANNEL_ID  " +
                            " LEFT JOIN CMS_WEBSITE cw ON cm.WEBSITE_ID = cw.WEBSITE_ID  " +
                            " LEFT JOIN CMS_MANUSCRIPT_METADATA_B CB   ON CB.MANUSCRIPT_METADATA_ID=cm.MANUSCRIPT_ID" +
                            " LEFT JOIN cms_manuscript_metadata_c cmmc ON cm.MANUSCRIPT_ID = cmmc.MANUSCRIPT_METADATA_ID  " +
                            " LEFT JOIN cms_code cms_c ON cms_c.CODE_ID = substring_index( cmmc.C_ZHUTI, \";\", 1 )   " +
                            " where " +
                            " cm.CHANNEL_ID = '"+channelId+"'" +
                            " and  cm.MANUSCRIPT_ID = '"+manuscriptIdStr+"'" +
                            " and  cm.STATUS = 4" +
                            " order by cm.SEQ_NUM asc  "

            );
            System.out.println(sb);
            connection = ConnectionUtil.getConnection("mysql");
            statement = connection.createStatement();
            set = statement.executeQuery(sb.toString());
            while (set.next()){
                System.out.println(set);
                Map<String, Object> map = new HashMap<>();
                map.put("manuscriptId", set.getString("manuscriptId"));
                map.put("websiteId", set.getString("websiteId"));
                map.put("title", set.getString("title"));
                map.put("shortTitle", set.getString("shortTitle"));
                map.put("KEYWORD", set.getString("KEYWORD"));
                map.put("memo", set.getString("memo"));
                map.put("subTitle", set.getString("subTitle"));
                map.put("publishedTime", set.getString("publishedTime"));
                map.put("modifiedTime", set.getString("modifiedTime"));
                map.put("CREATED_TIME", set.getString("CREATED_TIME"));
                map.put("url", set.getString("url"));
                map.put("CMSTATUS", set.getString("CMSTATUS"));
                map.put("type", set.getString("type"));
                map.put("isAutorecall", set.getString("isAutorecall"));
                map.put("hasImg", set.getString("hasImg"));
                map.put("hasVideo", set.getString("hasVideo"));
                map.put("hasDoc", set.getString("hasDoc"));
                map.put("hasRadio", set.getString("hasRadio"));
                map.put("REDIRECT_URL", set.getString("REDIRECT_URL"));
                map.put("fsNamesId", set.getString("fsNamesId"));
                map.put("currentFilePath", set.getString("currentFilePath"));
                map.put("currentFilePathHtmlUrl", set.getString("currentFilePathHtmlUrl"));
                map.put("cwName", set.getString("cwName"));
                map.put("ChannelId", set.getString("ChannelId"));
                map.put("channelName", set.getString("channelName"));
                map.put("site_url", set.getString("site_url"));
                map.put("channel_url", set.getString("channel_url"));
                map.put("channelParentId", set.getString("channelParentId"));
                map.put("IS_NAVIGATION", set.getString("IS_NAVIGATION"));
                map.put("ccSTATUS", set.getString("ccSTATUS"));
                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"));
                map.put("CN_NAME", set.getString("CN_NAME"));
                map.put("b_source", set.getString("b_source"));
                oldMaps.add(map);
            }
            return oldMaps;
        } catch (Exception e) {
            Log_Exception.Error_txt("GetAllDocInfoFromOldDB() error"+e.getMessage());
            return null;
        } finally {
            ConnectionUtil.closeConnection(set, statement, connection);
        }
    }

    public List<Map<String,String>> GetAllDocVIEW(String hyChannelId){
        List<Map<String, String>> oldMaps = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        ResultSet set = null;
        try {
            StringBuilder sb = new StringBuilder(
                    "select xwcc.VIEWDESC VIEWDESC from xwcmmetaviewemployer xwmcp \n" +
                            "left join xwcmviewinfo xwcc on xwcc.VIEWINFOID = xwmcp.VIEWID\n" +
                            "where xwmcp.CHANNELID = "+hyChannelId
            );
            connection = ConnectionUtil.getConnectionHy("mysql");
            statement = connection.createStatement();
            set = statement.executeQuery(sb.toString());
            while (set.next()){
                Map<String, String> map = new HashMap<>();
                map.put("VIEWDESC", set.getString("VIEWDESC"));
                oldMaps.add(map);
            }
            return oldMaps;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        } finally {
            ConnectionUtil.closeConnection(set, statement, connection);
        }
    }

    public List<Map<String,String>> GetAllDocCmsCarbonCopy(String ccTargetChannelId){
        List<Map<String, String>> oldMaps = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        ResultSet set = null;
        try {
            StringBuilder sb = new StringBuilder(
                    "select MANUSCRIPT_ID from CMS_CARBON_COPY\n" +
                            " where CC_TARGET_CHANNEL_ID = \""+ccTargetChannelId+"\""
            );
            connection = ConnectionUtil.getConnection("mysql");
            statement = connection.createStatement();
            System.out.println(sb.toString());
            set = statement.executeQuery(sb.toString());
            while (set.next()){
                Map<String, String> map = new HashMap<>();
                map.put("MANUSCRIPT_ID", set.getString("MANUSCRIPT_ID"));
                oldMaps.add(map);
            }
            return oldMaps;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        } finally {
            ConnectionUtil.closeConnection(set, statement, connection);
        }
    }

    public List<Map<String,Object>> GetAllDocInfoFromByMANUSCRIPT_ID(String manuscript_id){
        List<Map<String, Object>> oldMaps = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        ResultSet set = null;
        try {
            StringBuilder sb=new StringBuilder(
                    "SELECT " +
                            " cm.MANUSCRIPT_ID manuscriptId,  " +
                            " cm.WEBSITE_ID websiteId,  " +
                            " cm.TITLE title,  " +
                            " cm.SHORT_TITLE shortTitle,  " +
                            " cm.KEYWORD KEYWORD,  " +
                            " cm.MEMO memo,  " +
                            " cm.SUB_TITLE subTitle,  " +
                            " cm.PUBLISHED_TIME publishedTime,  " +
                            " cm.MODIFIED_TIME modifiedTime,  " +
                            " cm.CREATED_TIME CREATED_TIME,  " +
                            " cm.URL url,  " +
                            " cm.STATUS CMSTATUS,  " +
                            " cm.TYPE type,  " +
                            " cm.IS_AUTORECALL isAutorecall,  " +
                            " cm.HAS_IMG hasImg,  " +
                            " cm.HAS_VIDEO hasVideo,  " +
                            " cm.HAS_DOC hasDoc,  " +
                            " cm.HAS_RADIO hasRadio,  " +
                            " cm.REDIRECT_URL REDIRECT_URL,  " +
                            " sfn.FS_NAMES_ID fsNamesId,  " +
                            " sfn.CURRENT_FILE_PATH currentFilePath,  " +
                            " concat( sfn.CURRENT_FILE_PATH, \"/\", substring( sfn.FS_NAMES_ID, 5, 29 ), \".html\" ) currentFilePathHtmlUrl,  " +
                            " cw.NAME cwName,  " +
                            " cc.CHANNEL_ID ChannelId,  " +
                            " cc.CHANNEL_NAME channelName,  " +
                            " cw.URL site_url,  " +
                            " cc.URL channel_url,  " +
                            " cc.PARENT_ID channelParentId,  " +
                            " cc.IS_NAVIGATION IS_NAVIGATION,  " +
                            " cc.STATUS ccSTATUS,  " +
                            " cmmc.C_GKSX C_GKSX,  " +
                            " cmmc.C_FWRQ C_FWRQ,  " +
                            " cmmc.C_FBJG C_FBJG,  " +
                            " cmmc.C_SYH C_SYH,  " +
                            " cmmc.C_WJBH C_WJBH,  " +
                            " cmmc.C_ZTC C_ZTC,  " +
                            " cmmc.C_ZHUTI C_ZHUTI," +
                            " cms_c.CN_NAME CN_NAME," +
                            " cb.b_source as b_source" +
                            " FROM  " +
                            " CMS_MANUSCRIPT cm  " +
                            " LEFT JOIN cms_fs_names sfn ON sfn.RES_ID = cm.MANUSCRIPT_ID  " +
                            " LEFT JOIN CMS_CHANNEL cc ON cm.CHANNEL_ID = cc.CHANNEL_ID  " +
                            " LEFT JOIN CMS_WEBSITE cw ON cm.WEBSITE_ID = cw.WEBSITE_ID  " +
                            " LEFT JOIN CMS_MANUSCRIPT_METADATA_B CB   ON CB.MANUSCRIPT_METADATA_ID=cm.MANUSCRIPT_ID" +
                            " LEFT JOIN cms_manuscript_metadata_c cmmc ON cm.MANUSCRIPT_ID = cmmc.MANUSCRIPT_METADATA_ID  " +
                            " LEFT JOIN cms_code cms_c ON cms_c.CODE_ID = substring_index( cmmc.C_ZHUTI, \";\", 1 )   " +
                            " where " +
                            " cm.MANUSCRIPT_ID='"+manuscript_id+"'" +
                            " and  cm.STATUS = 4" +
                            " order by cm.SEQ_NUM asc  "

            );
            System.out.println(sb);
            connection = ConnectionUtil.getConnection("mysql");
            statement = connection.createStatement();
            set = statement.executeQuery(sb.toString());
            while (set.next()){
                System.out.println(set);
                Map<String, Object> map = new HashMap<>();
                map.put("manuscriptId", set.getString("manuscriptId"));
                map.put("websiteId", set.getString("websiteId"));
                map.put("title", set.getString("title"));
                map.put("shortTitle", set.getString("shortTitle"));
                map.put("KEYWORD", set.getString("KEYWORD"));
                map.put("memo", set.getString("memo"));
                map.put("subTitle", set.getString("subTitle"));
                map.put("publishedTime", set.getString("publishedTime"));
                map.put("modifiedTime", set.getString("modifiedTime"));
                map.put("CREATED_TIME", set.getString("CREATED_TIME"));
                map.put("url", set.getString("url"));
                map.put("CMSTATUS", set.getString("CMSTATUS"));
                map.put("type", set.getString("type"));
                map.put("isAutorecall", set.getString("isAutorecall"));
                map.put("hasImg", set.getString("hasImg"));
                map.put("hasVideo", set.getString("hasVideo"));
                map.put("hasDoc", set.getString("hasDoc"));
                map.put("hasRadio", set.getString("hasRadio"));
                map.put("REDIRECT_URL", set.getString("REDIRECT_URL"));
                map.put("fsNamesId", set.getString("fsNamesId"));
                map.put("currentFilePath", set.getString("currentFilePath"));
                map.put("currentFilePathHtmlUrl", set.getString("currentFilePathHtmlUrl"));
                map.put("cwName", set.getString("cwName"));
                map.put("ChannelId", set.getString("ChannelId"));
                map.put("channelName", set.getString("channelName"));
                map.put("site_url", set.getString("site_url"));
                map.put("channel_url", set.getString("channel_url"));
                map.put("channelParentId", set.getString("channelParentId"));
                map.put("IS_NAVIGATION", set.getString("IS_NAVIGATION"));
                map.put("ccSTATUS", set.getString("ccSTATUS"));
                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"));
                map.put("CN_NAME", set.getString("CN_NAME"));
                map.put("b_source", set.getString("b_source"));
                oldMaps.add(map);
            }
            return oldMaps;
        } catch (Exception e) {
            Log_Exception.Error_txt("GetAllDocInfoFromOldDB() error"+e.getMessage());
            return null;
        } finally {
            ConnectionUtil.closeConnection(set, statement, connection);
        }
    }


    //查询对应开普名称对应的海云发布机构ID
    public String GetKpMEMO(String manuscriptId){
        String MEMO = null;
        List<Map<String, String>> oldMaps = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        ResultSet set = null;
        try {
            StringBuilder sb = new StringBuilder(
                    "select * from cms_manuscript where MANUSCRIPT_ID = \""+manuscriptId+"\" limit 1"
            );
            System.out.println(sb);
            connection = ConnectionUtil.getConnection("mysql");
            statement = connection.createStatement();
            set = statement.executeQuery(sb.toString());
            while (set.next()){
                Map<String, String> map = new HashMap<>();
                map.put("MEMO", set.getString("MEMO"));
                oldMaps.add(map);
            }
            if(oldMaps != null && oldMaps.size() >= 1){
                MEMO = oldMaps.get(0).get("MEMO");
            }
        } catch (Exception e) {
            e.printStackTrace();
            MEMO = null;
        } finally {
            ConnectionUtil.closeConnection(set, statement, connection);
        }
        return MEMO;
    }


    //查询对应开普名称对应的海云发布机构ID
    public String GetKpFPJG(String kpFBJG){
        String id = null;
        List<Map<String, String>> oldMaps = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        ResultSet set = null;
        try {
            String newName=new String(kpFBJG.getBytes(),"UTF-8");
            StringBuilder sb = new StringBuilder(
                    "select * from testfbjg where testfbjg.kpfbjg = \""+kpFBJG+"\" limit 1"
            );
            System.out.println(sb);
            connection = ConnectionUtil.getConnectionHyTest("mysql");
            statement = connection.createStatement();
            set = statement.executeQuery(sb.toString());
            while (set.next()){
                Map<String, String> map = new HashMap<>();
                map.put("id", set.getString("id"));
                map.put("site", set.getString("site"));
                map.put("hycloudid", set.getString("hycloudid"));
                map.put("hyfbjg", set.getString("hyfbjg"));
                map.put("kpfbjg", set.getString("kpfbjg"));
                oldMaps.add(map);
            }
            if(oldMaps != null && oldMaps.size() >= 1){
                id = oldMaps.get(0).get("hycloudid");
            }
        } catch (Exception e) {
            e.printStackTrace();
            id = null;
        } finally {
            ConnectionUtil.closeConnection(set, statement, connection);
        }
        return id;
    }

    public String GetWcmMetaTableGovDocNewsMetaDataIdByOldDocId(String oldDocId){
        String id = null;
        List<Map<String, String>> oldMaps = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        ResultSet set = null;
        try {
            StringBuilder sb = new StringBuilder(
                    "SELECT MetaDataId FROM wcmmetatablegovdocnews where oldDocid = \""+oldDocId+"\" limit 1"
            );
            System.out.println(sb);
            connection = ConnectionUtil.getConnectionHy("mysql");
            statement = connection.createStatement();
            set = statement.executeQuery(sb.toString());
            while (set.next()){
                Map<String, String> map = new HashMap<>();
                map.put("MetaDataId", set.getString("MetaDataId"));
                oldMaps.add(map);
            }
            if(oldMaps != null && oldMaps.size() >= 1){
                id = oldMaps.get(0).get("MetaDataId");
            }
        } catch (Exception e) {
            e.printStackTrace();
            id = null;
        } finally {
            ConnectionUtil.closeConnection(set, statement, connection);
        }
        return id;
    }


    public List<Map<String, Object>> GetAllDocInfoFromKPDBByDate(String channelId, String date) {
        List<Map<String, Object>> oldMaps = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        ResultSet set = null;
        try {
            StringBuilder sb=new StringBuilder(
                    "SELECT " +
                            " cm.MANUSCRIPT_ID manuscriptId,  " +
                            " cm.WEBSITE_ID websiteId,  " +
                            " cm.TITLE title,  " +
                            " cm.SHORT_TITLE shortTitle,  " +
                            " cm.KEYWORD KEYWORD,  " +
                            " cm.MEMO memo,  " +
                            " cm.SUB_TITLE subTitle,  " +
                            " cm.PUBLISHED_TIME publishedTime,  " +
                            " cm.MODIFIED_TIME modifiedTime,  " +
                            " cm.CREATED_TIME CREATED_TIME,  " +
                            " cm.URL url,  " +
                            " cm.STATUS CMSTATUS,  " +
                            " cm.TYPE type,  " +
                            " cm.IS_AUTORECALL isAutorecall,  " +
                            " cm.HAS_IMG hasImg,  " +
                            " cm.HAS_VIDEO hasVideo,  " +
                            " cm.HAS_DOC hasDoc,  " +
                            " cm.HAS_RADIO hasRadio,  " +
                            " cm.REDIRECT_URL REDIRECT_URL,  " +
                            " sfn.FS_NAMES_ID fsNamesId,  " +
                            " sfn.CURRENT_FILE_PATH currentFilePath,  " +
                            " concat( sfn.CURRENT_FILE_PATH, \"/\", substring( sfn.FS_NAMES_ID, 5, 29 ), \".html\" ) currentFilePathHtmlUrl,  " +
                            " cw.NAME cwName,  " +
                            " cc.CHANNEL_ID ChannelId,  " +
                            " cc.CHANNEL_NAME channelName,  " +
                            " cw.URL site_url,  " +
                            " cc.URL channel_url,  " +
                            " cc.PARENT_ID channelParentId,  " +
                            " cc.IS_NAVIGATION IS_NAVIGATION,  " +
                            " cc.STATUS ccSTATUS,  " +
                            " cmmc.C_GKSX C_GKSX,  " +
                            " cmmc.C_FWRQ C_FWRQ,  " +
                            " cmmc.C_FBJG C_FBJG,  " +
                            " cmmc.C_SYH C_SYH,  " +
                            " cmmc.C_WJBH C_WJBH,  " +
                            " cmmc.C_ZTC C_ZTC,  " +
                            " cmmc.C_ZHUTI C_ZHUTI," +
                            " cms_c.CN_NAME CN_NAME," +
                            " cb.b_source as b_source" +
                            " FROM  " +
                            " CMS_MANUSCRIPT cm  " +
                            " LEFT JOIN cms_fs_names sfn ON sfn.RES_ID = cm.MANUSCRIPT_ID  " +
                            " LEFT JOIN CMS_CHANNEL cc ON cm.CHANNEL_ID = cc.CHANNEL_ID  " +
                            " LEFT JOIN CMS_WEBSITE cw ON cm.WEBSITE_ID = cw.WEBSITE_ID  " +
                            " LEFT JOIN CMS_MANUSCRIPT_METADATA_B CB   ON CB.MANUSCRIPT_METADATA_ID=cm.MANUSCRIPT_ID" +
                            " LEFT JOIN cms_manuscript_metadata_c cmmc ON cm.MANUSCRIPT_ID = cmmc.MANUSCRIPT_METADATA_ID  " +
                            " LEFT JOIN cms_code cms_c ON cms_c.CODE_ID = substring_index( cmmc.C_ZHUTI, \";\", 1 )   " +
                            " where " +
                            " cm.CHANNEL_ID='"+channelId+"'" +
                            " and  cm.STATUS = 4" +
                            " and  cm.PUBLISHED_TIME >= " + date +
                            " order by cm.SEQ_NUM asc  "
            );
            System.out.println(sb);
            connection = ConnectionUtil.getConnection("mysql");
            statement = connection.createStatement();
            set = statement.executeQuery(sb.toString());
            while (set.next()){
                System.out.println(set);
                Map<String, Object> map = new HashMap<>();
                map.put("manuscriptId", set.getString("manuscriptId"));
                map.put("websiteId", set.getString("websiteId"));
                map.put("title", set.getString("title"));
                map.put("shortTitle", set.getString("shortTitle"));
                map.put("KEYWORD", set.getString("KEYWORD"));
                map.put("memo", set.getString("memo"));
                map.put("subTitle", set.getString("subTitle"));
                map.put("publishedTime", set.getString("publishedTime"));
                map.put("modifiedTime", set.getString("modifiedTime"));
                map.put("CREATED_TIME", set.getString("CREATED_TIME"));
                map.put("url", set.getString("url"));
                map.put("CMSTATUS", set.getString("CMSTATUS"));
                map.put("type", set.getString("type"));
                map.put("isAutorecall", set.getString("isAutorecall"));
                map.put("hasImg", set.getString("hasImg"));
                map.put("hasVideo", set.getString("hasVideo"));
                map.put("hasDoc", set.getString("hasDoc"));
                map.put("hasRadio", set.getString("hasRadio"));
                map.put("REDIRECT_URL", set.getString("REDIRECT_URL"));
                map.put("fsNamesId", set.getString("fsNamesId"));
                map.put("currentFilePath", set.getString("currentFilePath"));
                map.put("currentFilePathHtmlUrl", set.getString("currentFilePathHtmlUrl"));
                map.put("cwName", set.getString("cwName"));
                map.put("ChannelId", set.getString("ChannelId"));
                map.put("channelName", set.getString("channelName"));
                map.put("site_url", set.getString("site_url"));
                map.put("channel_url", set.getString("channel_url"));
                map.put("channelParentId", set.getString("channelParentId"));
                map.put("IS_NAVIGATION", set.getString("IS_NAVIGATION"));
                map.put("ccSTATUS", set.getString("ccSTATUS"));
                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"));
                map.put("CN_NAME", set.getString("CN_NAME"));
                map.put("b_source", set.getString("b_source"));
                oldMaps.add(map);
            }
            return oldMaps;
        } catch (Exception e) {
            Log_Exception.Error_txt("GetAllDocInfoFromOldDB() error"+e.getMessage());
            return null;
        } finally {
            ConnectionUtil.closeConnection(set, statement, connection);
        }

    }

    public List<Map<String,String>> GetAllDocCmsCarbonCopyAll(String[] kpChannelIdList){
        List<Map<String, String>> oldMapsRe = new ArrayList<>();
        List<Long> longs = new ArrayList<>();
        Map<Long,Map<String, String>> hashMap = new HashMap<>();
        for (String kpChannelId : kpChannelIdList) {
            Connection connection = null;
            Statement statement = null;
            ResultSet set = null;
            try {
                StringBuilder sb=new StringBuilder(
                        "SELECT " +
                                " cm.MANUSCRIPT_ID manuscriptId,  " +
                                " cm.WEBSITE_ID websiteId,  " +
                                " cm.TITLE title,  " +
                                " cm.SHORT_TITLE shortTitle,  " +
                                " cm.KEYWORD KEYWORD,  " +
                                " cm.MEMO memo,  " +
                                " cm.SUB_TITLE subTitle,  " +
                                " cm.PUBLISHED_TIME publishedTime,  " +
                                " cm.MODIFIED_TIME modifiedTime,  " +
                                " cm.CREATED_TIME CREATED_TIME,  " +
                                " cm.URL url,  " +
                                " cm.STATUS CMSTATUS,  " +
                                " cm.TYPE type,  " +
                                " cm.IS_AUTORECALL isAutorecall,  " +
                                " cm.HAS_IMG hasImg,  " +
                                " cm.HAS_VIDEO hasVideo,  " +
                                " cm.HAS_DOC hasDoc,  " +
                                " cm.HAS_RADIO hasRadio,  " +
                                " cm.REDIRECT_URL REDIRECT_URL,  " +
                                " cm.SEQ_NUM SEQ_NUM,  " +
                                " sfn.FS_NAMES_ID fsNamesId,  " +
                                " sfn.CURRENT_FILE_PATH currentFilePath,  " +
                                " concat( sfn.CURRENT_FILE_PATH, \"/\", substring( sfn.FS_NAMES_ID, 5, 29 ), \".html\" ) currentFilePathHtmlUrl,  " +
                                " cw.NAME cwName,  " +
                                " cc.CHANNEL_ID ChannelId,  " +
                                " cc.CHANNEL_NAME channelName,  " +
                                " cw.URL site_url,  " +
                                " cc.URL channel_url,  " +
                                " cc.PARENT_ID channelParentId,  " +
                                " cc.IS_NAVIGATION IS_NAVIGATION,  " +
                                " cc.STATUS ccSTATUS,  " +
                                " cmmc.C_GKSX C_GKSX,  " +
                                " cmmc.C_FWRQ C_FWRQ,  " +
                                " cmmc.C_FBJG C_FBJG,  " +
                                " cmmc.C_SYH C_SYH,  " +
                                " cmmc.C_WJBH C_WJBH,  " +
                                " cmmc.C_ZTC C_ZTC,  " +
                                " cmmc.C_ZHUTI C_ZHUTI," +
                                " cms_c.CN_NAME CN_NAME," +
                                " cb.b_source as b_source" +
                                " FROM  " +
                                " CMS_MANUSCRIPT cm  " +
                                " LEFT JOIN cms_fs_names sfn ON sfn.RES_ID = cm.MANUSCRIPT_ID  " +
                                " LEFT JOIN CMS_CHANNEL cc ON cm.CHANNEL_ID = cc.CHANNEL_ID  " +
                                " LEFT JOIN CMS_WEBSITE cw ON cm.WEBSITE_ID = cw.WEBSITE_ID  " +
                                " LEFT JOIN CMS_MANUSCRIPT_METADATA_B CB   ON CB.MANUSCRIPT_METADATA_ID=cm.MANUSCRIPT_ID" +
                                " LEFT JOIN cms_manuscript_metadata_c cmmc ON cm.MANUSCRIPT_ID = cmmc.MANUSCRIPT_METADATA_ID  " +
                                " LEFT JOIN cms_code cms_c ON cms_c.CODE_ID = substring_index( cmmc.C_ZHUTI, \";\", 1 )   " +
                                " where " +
                                " cm.CHANNEL_ID='"+kpChannelId+"'" +
                                " and  cm.STATUS = 4"

                );
                System.out.println(sb);
                connection = ConnectionUtil.getConnection("mysql");
                statement = connection.createStatement();
                set = statement.executeQuery(sb.toString());
                while (set.next()){
                    System.out.println(set);
                    Map<String, String> map = new HashMap<>();
                    map.put("manuscriptId", set.getString("manuscriptId"));
                    map.put("websiteId", set.getString("websiteId"));
                    map.put("title", set.getString("title"));
                    map.put("shortTitle", set.getString("shortTitle"));
                    map.put("KEYWORD", set.getString("KEYWORD"));
                    map.put("memo", set.getString("memo"));
                    map.put("subTitle", set.getString("subTitle"));
                    map.put("publishedTime", set.getString("publishedTime"));
                    map.put("modifiedTime", set.getString("modifiedTime"));
                    map.put("CREATED_TIME", set.getString("CREATED_TIME"));
                    map.put("url", set.getString("url"));
                    map.put("CMSTATUS", set.getString("CMSTATUS"));
                    map.put("type", set.getString("type"));
                    map.put("isAutorecall", set.getString("isAutorecall"));
                    map.put("hasImg", set.getString("hasImg"));
                    map.put("hasVideo", set.getString("hasVideo"));
                    map.put("hasDoc", set.getString("hasDoc"));
                    map.put("hasRadio", set.getString("hasRadio"));
                    map.put("REDIRECT_URL", set.getString("REDIRECT_URL"));
                    map.put("fsNamesId", set.getString("fsNamesId"));
                    map.put("currentFilePath", set.getString("currentFilePath"));
                    map.put("currentFilePathHtmlUrl", set.getString("currentFilePathHtmlUrl"));
                    map.put("cwName", set.getString("cwName"));
                    map.put("ChannelId", set.getString("ChannelId"));
                    map.put("channelName", set.getString("channelName"));
                    map.put("site_url", set.getString("site_url"));
                    map.put("channel_url", set.getString("channel_url"));
                    map.put("channelParentId", set.getString("channelParentId"));
                    map.put("IS_NAVIGATION", set.getString("IS_NAVIGATION"));
                    map.put("ccSTATUS", set.getString("ccSTATUS"));
                    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"));
                    map.put("CN_NAME", set.getString("CN_NAME"));
                    map.put("b_source", set.getString("b_source"));
                    String seq_num = set.getString("SEQ_NUM");
                    try {
                        Long seqNum = Long.parseLong(seq_num);
                        System.out.println(seqNum);
                        hashMap.put(seqNum,map);
                        longs.add(seqNum);
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
            } catch (Exception e) {
                Log_Exception.Error_txt("GetAllDocInfoFromOldDB() error"+e.getMessage());
                return null;
            } finally {
                ConnectionUtil.closeConnection(set, statement, connection);
            }
        }
        Collections.sort(longs);
        for (Long aLong : longs) {
            Map<String, String> stringStringMap = hashMap.get(aLong);
            oldMapsRe.add(stringStringMap);
        }
        return oldMapsRe;
    }



    public String getHyMetaDataIDByTitle(String viewName,String title, String hyChannelId) {
        String id = null;
        List<Map<String, String>> oldMaps = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        ResultSet set = null;
        try {
            StringBuilder sb = new StringBuilder(
                    "SELECT MetaDataId FROM "+viewName+" where title = \""+title+"\" and  channelid = \""+hyChannelId+"\" limit 1"
            );
            System.out.println(sb);
            connection = ConnectionUtil.getConnectionHy("mysql");
            statement = connection.createStatement();
            set = statement.executeQuery(sb.toString());
            while (set.next()){
                Map<String, String> map = new HashMap<>();
                map.put("MetaDataId", set.getString("MetaDataId"));
                oldMaps.add(map);
            }
            if(oldMaps != null && oldMaps.size() >= 1){
                id = oldMaps.get(0).get("MetaDataId");
            }
        } catch (Exception e) {
            e.printStackTrace();
            id = null;
        } finally {
            ConnectionUtil.closeConnection(set, statement, connection);
        }
        return id;
    }

    public String getWCMMETATABLEGovOpenDataBYTitleAndTime(String title,String format,String hyChannelId) {
        String titleR = null;
        List<Map<String, String>> oldMaps = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        ResultSet set = null;
        try {
            StringBuilder sb = new StringBuilder(
                    "SELECT title FROM WCMMETATABLEGovOpenData where title = \""+title+"\" and  CHANNELID = \""+hyChannelId+"\" and  scrq = \""+format+"\" limit 1"
            );

            System.out.println(sb);
            connection = ConnectionUtil.getConnectionHy("mysql");
            statement = connection.createStatement();
            set = statement.executeQuery(sb.toString());
            while (set.next()){
                Map<String, String> map = new HashMap<>();
                map.put("title", set.getString("title"));
                oldMaps.add(map);
            }
            if(oldMaps != null && oldMaps.size() >= 1){
                titleR = oldMaps.get(0).get("title");
            }
        } catch (Exception e) {
            e.printStackTrace();
            titleR = null;
        } finally {
            ConnectionUtil.closeConnection(set, statement, connection);
        }
        return titleR;
    }

    public String getWCMMETATABLEGovOpenDataBYTitle(String title, String hyChannelId) {
        String titleR = null;
        List<Map<String, String>> oldMaps = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        ResultSet set = null;
        try {
            StringBuilder sb = new StringBuilder(
                    "SELECT title FROM WCMMETATABLEGovOpenData where title = \""+title+"\" and  CHANNELID = \""+hyChannelId+"\" limit 1"
            );

            System.out.println(sb);
            connection = ConnectionUtil.getConnectionHy("mysql");
            statement = connection.createStatement();
            set = statement.executeQuery(sb.toString());
            while (set.next()){
                Map<String, String> map = new HashMap<>();
                map.put("title", set.getString("title"));
                oldMaps.add(map);
            }
            if(oldMaps != null && oldMaps.size() >= 1){
                titleR = oldMaps.get(0).get("title");
            }
        } catch (Exception e) {
            e.printStackTrace();
            titleR = null;
        } finally {
            ConnectionUtil.closeConnection(set, statement, connection);
        }
        return titleR;
    }


    public String getwcmmetatablegovdocnewsTitle(String title,String hyChannelId) {
        String titleR = null;
        List<Map<String, String>> oldMaps = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        ResultSet set = null;
        try {
            StringBuilder sb = new StringBuilder(
                    "SELECT DocTitle FROM wcmmetatablegovdocnews where DocTitle = \""+title+"\" and  CHANNELID = \""+hyChannelId+"\" limit 1"
            );
            System.out.println(sb);
            connection = ConnectionUtil.getConnectionHy("mysql");
            statement = connection.createStatement();
            set = statement.executeQuery(sb.toString());
            while (set.next()){
                Map<String, String> map = new HashMap<>();
                map.put("DocTitle", set.getString("DocTitle"));
                oldMaps.add(map);
            }
            if(oldMaps != null && oldMaps.size() >= 1){
                titleR = oldMaps.get(0).get("DocTitle");
            }
        } catch (Exception e) {
            e.printStackTrace();
            titleR = null;
        } finally {
            ConnectionUtil.closeConnection(set, statement, connection);
        }
        return titleR;
    }


    public void orderBy(String hyChannelId) {

        List<Map<String, String>> oldMapsReUp = new ArrayList<>();
        Connection connectionUp = null;
        Statement statementUp = null;
        ResultSet setUp = null;
        try {
            StringBuilder sbUp=new StringBuilder(
                    "select RECID,DOCORDER from wcmchnldoc where   CHNLID  = "+hyChannelId+"  and DOCSTATUS >=0 ORDER BY DOCRELTIME asc"
            );
            System.out.println(sbUp);
            connectionUp = ConnectionUtil.getConnectionHy("mysql");
            statementUp = connectionUp.createStatement();
            setUp = statementUp.executeQuery(sbUp.toString());
            while (setUp.next()){
                System.out.println(setUp);
                Map<String, String> map = new HashMap<>();
                map.put("RECID", setUp.getString("RECID"));
                map.put("DOCORDER", setUp.getString("DOCORDER"));
                oldMapsReUp.add(map);
            }
        } catch (Exception e) {
            Log_Exception.Error_txt("GetAllDocInfoFromOldDB() error"+e.getMessage());
        } finally {
            ConnectionUtil.closeConnection(setUp, statementUp, connectionUp);
        }

        for (int i = 0; i < oldMapsReUp.size(); i++) {
            Map<String, String> stringStringMap = oldMapsReUp.get(i);
            System.out.println(stringStringMap.get("RECID"));
            System.out.println(stringStringMap.get("DOCORDER"));
            System.out.println("========================");
            String recid = stringStringMap.get("RECID");
            if(recid != null && recid != ""){
                updateHyOrderby(""+(i+1),recid);
            }
        }
    }

    public void updateHyOrderby(String orderNum,String RECID){
        Connection connectionUp = null;
        Statement statementUp = null;
        ResultSet setUp = null;
        try {
            StringBuilder sbUp=new StringBuilder(
                    "UPDATE wcmchnldoc SET DOCORDER = "+orderNum+" WHERE  RECID  = "+RECID
            );
            System.out.println(sbUp);
            connectionUp = ConnectionUtil.getConnectionHy("mysql");
            statementUp = connectionUp.createStatement();
            int i = statementUp.executeUpdate(sbUp.toString());
            System.out.println(i);
        } catch (Exception e) {
            Log_Exception.Error_txt("GetAllDocInfoFromOldDB() error"+e.getMessage());
        } finally {
            ConnectionUtil.closeConnection(setUp, statementUp, connectionUp);
        }
    }

    public void updateDOCRELTIME(String hyChannelId) {

        List<Map<String, String>> oldMapsReUp = new ArrayList<>();
        Connection connectionUp = null;
        Statement statementUp = null;
        ResultSet setUp = null;
        try {
            StringBuilder sbUp=new StringBuilder(
                    "select " +
                            "DOCRELTIME," +
                            "METADATAID, " +
                            "TITLE, " +
                            "UEDITOR, " +
                            "scrq " +
                            "from " +
                            "wcmmetatablegovopendata where   ChannelID  = "+hyChannelId
            );
            System.out.println(sbUp);
            connectionUp = ConnectionUtil.getConnectionHy("mysql");
            statementUp = connectionUp.createStatement();
            setUp = statementUp.executeQuery(sbUp.toString());
            while (setUp.next()){
                System.out.println(setUp);
                Map<String, String> map = new HashMap<>();
                map.put("DOCRELTIME", setUp.getString("DOCRELTIME"));
                map.put("METADATAID", setUp.getString("METADATAID"));
                map.put("TITLE", setUp.getString("TITLE"));
                map.put("UEDITOR", setUp.getString("UEDITOR"));
                map.put("scrq", setUp.getString("scrq"));
                oldMapsReUp.add(map);
            }
        } catch (Exception e) {
            Log_Exception.Error_txt("GetAllDocInfoFromOldDB() error"+e.getMessage());
        } finally {
            ConnectionUtil.closeConnection(setUp, statementUp, connectionUp);
        }

        for (int i = 0; i < oldMapsReUp.size(); i++) {
            Map<String, String> stringStringMap = oldMapsReUp.get(i);
            System.out.println(stringStringMap.get("DOCRELTIME"));
            System.out.println(stringStringMap.get("METADATAID"));
            System.out.println(stringStringMap.get("TITLE"));
            System.out.println(stringStringMap.get("UEDITOR"));
            String docreltime = stringStringMap.get("DOCRELTIME");
            System.out.println("docreltime==="+docreltime);
            String metadataid = stringStringMap.get("METADATAID");
            String title = stringStringMap.get("TITLE");
            String UEDITOR = stringStringMap.get("UEDITOR");
            String scrq = stringStringMap.get("scrq");
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            try {
                Date date1 = simpleDateFormat.parse(docreltime);
                try {
                    Calendar c = Calendar.getInstance();
                    c.setTime(date1);
                    c.add(Calendar.HOUR_OF_DAY, -8);
                    Date newDate = c.getTime();
                    String format = simpleDateFormat.format(newDate);
                    System.out.println(format);
                    if(metadataid != null && metadataid !=""){
                        updateDOCRELTIMEType(title,format,hyChannelId,metadataid,UEDITOR,scrq);
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
            }catch (Exception e){
                e.printStackTrace();
            }

        }
    }

    public void updateDOCRELTIMEType(String title,String time,String hyChannelId,String ObjectId,String UEDITOR,String scrq){
        String sServiceId = "gov_webdocument";
        String sMethodName = "saveDocumentInOpenData";//自定义视图
        try {
                Map<String,Object> oPostData=new HashMap<>();
                oPostData.put("ObjectId", ObjectId);
                oPostData.put("metadataid", ObjectId);
                oPostData.put("ChannelId", Integer.parseInt(hyChannelId));// 目标栏目id
                oPostData.put("CurrUserName", "dev");
                oPostData.put("isShenhe", "1");
                oPostData.put("DOCTYPE", CMSConstants.CONTENT_BODY_HTML);
                //标题-必填
                if (title != null) {
                    oPostData.put("title",title);
                }
                //发布时间
                if (time != null) {
                    oPostData.put("DocRelTime",time);
                }
                if(UEDITOR != null){
                    oPostData.put("UEDITOR",UEDITOR);
                }
                if(scrq != null){
                    oPostData.put("scrq",scrq);
                }
                try {
                    System.out.println("==============="+oPostData);
                    System.out.println("==============="+sMethodName);
                    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")){
                            System.out.println("DOCTITLE:"+time);
                            System.out.println("oldDocid:"+time);
                        }else{
                            String serror = JSON.toJSONString(rObject);
                            System.out.println(serror);
                        }
                    }
                }catch(Exception e) {
                    e.printStackTrace();
                }
        }catch (Exception e){

        }

    }


    public static void main(String[] args) {
        // 5463
        ServiceImplKp2 serviceImplKp = new ServiceImplKp2();
        serviceImplKp.updateDOCRELTIME("11675");

    }



}