Prechádzať zdrojové kódy

第三方系统迁移到海云程序调整

lijihong 6 rokov pred
rodič
commit
e3ac65ba26

+ 13 - 0
TRS.WCM.Developer/DB/hycloud_developer.sql

@@ -0,0 +1,13 @@
+DROP TABLE IF EXISTS `HYCLOUDSITERELATION`;
+CREATE TABLE `HYCLOUDSITERELATION` (
+  `SRCSITECODE` varchar(200) NOT NULL,
+  `SITEID` int(11) NOT NULL,
+  PRIMARY KEY (`SRCSITECODE`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+DROP TABLE IF EXISTS `HYCLOUDCHANNELRELATION`;
+CREATE TABLE `HYCLOUDCHANNELRELATION` (
+  `SRCCHANNELCODE` varchar(200) NOT NULL,
+  `CHANNELID` int(11) NOT NULL,
+  PRIMARY KEY (`SRCCHANNELCODE`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;

+ 2 - 2
TRS.WCM.Developer/myconfig/log4j.properties

@@ -33,7 +33,7 @@ log4j.appender.A1.layout.ConversionPattern=[WCMLOG] %5p - %d %m -[%t] %l %n
 ###########WCMStd RollBack File##########
 #########################################
 log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender
-log4j.appender.A2.File=/Users/cao.hui/tmp/TRSWCMLog.txt
+log4j.appender.A2.File=/Users/macro.li/TRS/logs/TRSWCMLog.txt
 log4j.appender.A2.File.Encoding=utf-8
 log4j.appender.A2.DatePattern='_'yyyyMM'.txt'
 log4j.appender.A2.layout=org.apache.log4j.PatternLayout
@@ -62,7 +62,7 @@ log4j.appender.A2.layout.ConversionPattern=[WCMLOG] %d - %-5p %x - %m - %c%l -%-
 log4j.logger.com.trs.eshop.log=info,logstash
 
 log4j.appender.logstash=org.apache.log4j.DailyRollingFileAppender
-log4j.appender.logstash.File=/Users/cao.hui/tmp/TRSWCMLogStash.txt
+log4j.appender.logstash.File=/Users/macro.li/TRS/logs/TRSWCMLogStash.txt
 log4j.appender.logstash.File.Encoding=UTF-8
 log4j.appender.logstash.DatePattern='.'yyyy-MM-dd'.log'
 log4j.appender.logstash.layout=org.apache.log4j.PatternLayout

+ 231 - 0
TRS.WCM.Developer/src/com/trs/dto/ChannelDTO.java

@@ -0,0 +1,231 @@
+package com.trs.dto;
+
+/**
+ * create by li.jihong
+ * 2019/6/20
+ */
+public class ChannelDTO {
+
+    //存放目录 *该参数不能重复
+    private String chnldatapath;
+    //显示名称
+    private String chnldesc;
+    //唯一标识 *该参数不能重复
+    private String chnlname;
+    //数据视图ID
+    private int viewinfoid;
+    //在迁移前的应用系统中的 唯一表示 *该参数不能重复
+    private String srcChannelCode;
+    //栏目所属站点
+    private int siteid;
+    //文档模板 可以通过SQL 获取系统默认的模板: SELECT * FROM wcmtemplate WHERE TEMPNAME = '默认文档模板';
+    private int detailtemplate;
+    //栏目模板 可以通过SQL 获取系统默认的模:SELECT * FROM wcmtemplate WHERE TEMPNAME = '默认栏目模板';
+    private int outlinetemplate;
+    //父栏目ID
+    private int parentid = 0;
+
+    /*
+    ------------------以上的字段必须指定,填写-------------------
+    */
+    //栏目域名
+    private String rootdomain;
+    //连接栏目URL
+    private String linkurl;
+    //站点ID 0-新增
+    private int channelid = 0;
+    //站点顺序 -1:最前
+    private int chnlorder = -1;
+    //允许下达 0-关 1-开
+    private int isdistributable = 0;
+    //允许上报 0-关 1-开
+    private int ispushable = 0;
+    //允许订阅 0-关 1-开
+    private int issubscribe = 0;
+    //是否允许发布 0-关 1-开
+    private int canpub = 1;
+    //栏目类型 0:普通栏目 11:连接栏目
+    private int chnltype = 0;
+    //渠道类型 1:网站
+    private int mediatype = 1;
+
+    private int generatechnlrole = 0;
+    private int isotherplatdistributable = 0;
+    private int isotherplatpushable = 0;
+
+    public String getChnldatapath() {
+        return chnldatapath;
+    }
+
+    public void setChnldatapath(String chnldatapath) {
+        this.chnldatapath = chnldatapath;
+    }
+
+    public String getChnldesc() {
+        return chnldesc;
+    }
+
+    public void setChnldesc(String chnldesc) {
+        this.chnldesc = chnldesc;
+    }
+
+    public String getChnlname() {
+        return chnlname;
+    }
+
+    public void setChnlname(String chnlname) {
+        this.chnlname = chnlname;
+    }
+
+    public int getViewinfoid() {
+        return viewinfoid;
+    }
+
+    public void setViewinfoid(int viewinfoid) {
+        this.viewinfoid = viewinfoid;
+    }
+
+    public String getSrcChannelCode() {
+        return srcChannelCode;
+    }
+
+    public void setSrcChannelCode(String srcChannelCode) {
+        this.srcChannelCode = srcChannelCode;
+    }
+
+    public int getSiteid() {
+        return siteid;
+    }
+
+    public void setSiteid(int siteid) {
+        this.siteid = siteid;
+    }
+
+    public int getDetailtemplate() {
+        return detailtemplate;
+    }
+
+    public void setDetailtemplate(int detailtemplate) {
+        this.detailtemplate = detailtemplate;
+    }
+
+    public int getOutlinetemplate() {
+        return outlinetemplate;
+    }
+
+    public void setOutlinetemplate(int outlinetemplate) {
+        this.outlinetemplate = outlinetemplate;
+    }
+
+    public int getParentid() {
+        return parentid;
+    }
+
+    public void setParentid(int parentid) {
+        this.parentid = parentid;
+    }
+
+    public String getRootdomain() {
+        return rootdomain;
+    }
+
+    public void setRootdomain(String rootdomain) {
+        this.rootdomain = rootdomain;
+    }
+
+    public String getLinkurl() {
+        return linkurl;
+    }
+
+    public void setLinkurl(String linkurl) {
+        this.linkurl = linkurl;
+    }
+
+    public int getChannelid() {
+        return channelid;
+    }
+
+    public void setChannelid(int channelid) {
+        this.channelid = channelid;
+    }
+
+    public int getChnlorder() {
+        return chnlorder;
+    }
+
+    public void setChnlorder(int chnlorder) {
+        this.chnlorder = chnlorder;
+    }
+
+    public int getIsdistributable() {
+        return isdistributable;
+    }
+
+    public void setIsdistributable(int isdistributable) {
+        this.isdistributable = isdistributable;
+    }
+
+    public int getIspushable() {
+        return ispushable;
+    }
+
+    public void setIspushable(int ispushable) {
+        this.ispushable = ispushable;
+    }
+
+    public int getIssubscribe() {
+        return issubscribe;
+    }
+
+    public void setIssubscribe(int issubscribe) {
+        this.issubscribe = issubscribe;
+    }
+
+    public int getCanpub() {
+        return canpub;
+    }
+
+    public void setCanpub(int canpub) {
+        this.canpub = canpub;
+    }
+
+    public int getChnltype() {
+        return chnltype;
+    }
+
+    public void setChnltype(int chnltype) {
+        this.chnltype = chnltype;
+    }
+
+    public int getMediatype() {
+        return mediatype;
+    }
+
+    public void setMediatype(int mediatype) {
+        this.mediatype = mediatype;
+    }
+
+    public int getGeneratechnlrole() {
+        return generatechnlrole;
+    }
+
+    public void setGeneratechnlrole(int generatechnlrole) {
+        this.generatechnlrole = generatechnlrole;
+    }
+
+    public int getIsotherplatdistributable() {
+        return isotherplatdistributable;
+    }
+
+    public void setIsotherplatdistributable(int isotherplatdistributable) {
+        this.isotherplatdistributable = isotherplatdistributable;
+    }
+
+    public int getIsotherplatpushable() {
+        return isotherplatpushable;
+    }
+
+    public void setIsotherplatpushable(int isotherplatpushable) {
+        this.isotherplatpushable = isotherplatpushable;
+    }
+}

+ 202 - 0
TRS.WCM.Developer/src/com/trs/dto/SiteDTO.java

@@ -0,0 +1,202 @@
+package com.trs.dto;
+
+/**
+ * create by li.jihong
+ * 2019/6/19
+ */
+
+public class SiteDTO {
+
+    //站点类别ID
+    private int classificationid;
+    //存放目录 *该参数不能重复
+    private String datapath;
+    //显示名称
+    private String sitedesc;
+    //唯一标识 *该参数不能重复
+    private String sitename;
+    //数据视图
+    private int viewinfoid;
+    //访问域名
+    private String webhttp;
+
+    //在迁移前的应用系统中的 唯一表示
+    private String srcSiteCode;
+
+    //文档模板 可以通过SQL 获取系统默认的模板: SELECT * FROM wcmtemplate WHERE TEMPNAME = '默认文档模板';
+    private int detailtemplate;
+    //站点模板 可以通过SQL 获取系统默认的模:SELECT * FROM wcmtemplate WHERE TEMPNAME = '默认站点模板';
+    private int outlinetemplate;
+    //栏目模板 可以通过SQL 获取系统默认的模:SELECT * FROM wcmtemplate WHERE TEMPNAME = '默认栏目模板';
+    private int chnloutlinetemp;
+/*
+------------------以上的字段必须指定,填写-------------------
+*/
+    //站点ID 0-新增
+    private int siteid = 0;
+    //站点顺序 -1:最前
+    private int siteorder = -1;
+    //允许下达 0-关 1-开
+    private int isdistributable = 0;
+    //允许上报 0-关 1-开
+    private int ispushable = 0;
+    //允许订阅 0-关 1-开
+    private int issubscribe = 0;
+    //渠道类型 1:网站
+    private int mediatype = 1;
+    private int autocheck = 0;
+    private int isotherplatdistributable = 0;
+    private int isotherplatpushable = 0;
+
+    public int getClassificationid() {
+        return classificationid;
+    }
+
+    public void setClassificationid(int classificationid) {
+        this.classificationid = classificationid;
+    }
+
+    public String getDatapath() {
+        return datapath;
+    }
+
+    public void setDatapath(String datapath) {
+        this.datapath = datapath;
+    }
+
+    public String getSitedesc() {
+        return sitedesc;
+    }
+
+    public void setSitedesc(String sitedesc) {
+        this.sitedesc = sitedesc;
+    }
+
+    public String getSitename() {
+        return sitename;
+    }
+
+    public void setSitename(String sitename) {
+        this.sitename = sitename;
+    }
+
+    public int getViewinfoid() {
+        return viewinfoid;
+    }
+
+    public void setViewinfoid(int viewinfoid) {
+        this.viewinfoid = viewinfoid;
+    }
+
+    public String getWebhttp() {
+        return webhttp;
+    }
+
+    public void setWebhttp(String webhttp) {
+        this.webhttp = webhttp;
+    }
+
+    public int getDetailtemplate() {
+        return detailtemplate;
+    }
+
+    public void setDetailtemplate(int detailtemplate) {
+        this.detailtemplate = detailtemplate;
+    }
+
+    public int getOutlinetemplate() {
+        return outlinetemplate;
+    }
+
+    public void setOutlinetemplate(int outlinetemplate) {
+        this.outlinetemplate = outlinetemplate;
+    }
+
+    public int getChnloutlinetemp() {
+        return chnloutlinetemp;
+    }
+
+    public void setChnloutlinetemp(int chnloutlinetemp) {
+        this.chnloutlinetemp = chnloutlinetemp;
+    }
+
+    public int getSiteid() {
+        return siteid;
+    }
+
+    public void setSiteid(int siteid) {
+        this.siteid = siteid;
+    }
+
+    public int getSiteorder() {
+        return siteorder;
+    }
+
+    public void setSiteorder(int siteorder) {
+        this.siteorder = siteorder;
+    }
+
+    public int getIsdistributable() {
+        return isdistributable;
+    }
+
+    public void setIsdistributable(int isdistributable) {
+        this.isdistributable = isdistributable;
+    }
+
+    public int getIspushable() {
+        return ispushable;
+    }
+
+    public void setIspushable(int ispushable) {
+        this.ispushable = ispushable;
+    }
+
+    public int getIssubscribe() {
+        return issubscribe;
+    }
+
+    public void setIssubscribe(int issubscribe) {
+        this.issubscribe = issubscribe;
+    }
+
+    public int getMediatype() {
+        return mediatype;
+    }
+
+    public void setMediatype(int mediatype) {
+        this.mediatype = mediatype;
+    }
+
+    public int getAutocheck() {
+        return autocheck;
+    }
+
+    public void setAutocheck(int autocheck) {
+        this.autocheck = autocheck;
+    }
+
+    public int getIsotherplatdistributable() {
+        return isotherplatdistributable;
+    }
+
+    public void setIsotherplatdistributable(int isotherplatdistributable) {
+        this.isotherplatdistributable = isotherplatdistributable;
+    }
+
+    public int getIsotherplatpushable() {
+        return isotherplatpushable;
+    }
+
+    public void setIsotherplatpushable(int isotherplatpushable) {
+        this.isotherplatpushable = isotherplatpushable;
+    }
+
+    public String getSrcSiteCode() {
+        return srcSiteCode;
+    }
+
+    public void setSrcSiteCode(String srcSiteCode) {
+        this.srcSiteCode = srcSiteCode;
+    }
+}

+ 1 - 2
TRS.WCM.Developer/src/com/trs/exchange/MyScripts.java

@@ -17,8 +17,7 @@ public class MyScripts {
 
     public static void main(String[] args) throws IOException {
         //System.out.println(Pattern.matches("3_sp\\w+.sql","3_sp_data_migration_wcmtemplatequote.sql"));
-        String basedir = //工程下文件夹
-                "E:\\IdeaProject\\TRS.WCM.Developer_cddev\\TRS.WCM.Developer\\贵州项目6个WCM节点迁移到海云\\";
+        String basedir = "E:\\IdeaProject\\TRS.WCM.Developer_cddev\\TRS.WCM.Developer\\贵州项目6个WCM节点迁移到海云";
         String toPath = "E:\\xxy\\mergeSql\\";//生成的merge.sql存放路径
         createMergeSpScript(0,basedir,toPath);
         createMergeSpScript(1,basedir,toPath);

+ 271 - 0
TRS.WCM.Developer/src/com/trs/util/DBUtil.java

@@ -0,0 +1,271 @@
+package com.trs.util;
+
+
+import com.trs.infra.common.BizError;
+import com.trs.infra.common.WCMException;
+
+import java.io.Reader;
+import java.io.StringReader;
+import java.sql.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * create by li.jihong
+ * 2019/6/5
+ */
+public class DBUtil {
+
+    private static final String TABLE_REGEX = "\\d\\/(.*?)\\?";
+
+    public static DBUtil getDBManager() {
+
+        return new DBUtil();
+    }
+
+    public static Connection getConnection(String url, String userName, String psd) throws BizError {
+        Connection conn = null;
+        try {
+            Class.forName("com.mysql.jdbc.Driver");
+            conn = DriverManager.getConnection(url, userName, psd);
+        } catch (Exception e) {
+            throw new BizError("connect mysql db failed!");
+        }
+        return conn;
+    }
+
+    public static String getTableSchema(String connectUrl) {
+
+        Pattern pattern = Pattern.compile(TABLE_REGEX);
+
+        Matcher matcher = pattern.matcher(connectUrl);
+        String tableSchema = "";
+        if (matcher.find()) {
+            tableSchema = matcher.group(1);
+        }
+        return tableSchema;
+    }
+
+    public List<String> sqlExecuteStringsQuery(Connection connection, String sql, List parameters) throws BizError {
+
+        PreparedStatement statement = null;
+        ResultSet resultSet = null;
+        List<String> result = new ArrayList<>();
+        try {
+            statement = connection.prepareStatement(sql);
+            setParameters(statement, parameters);
+            resultSet = statement.executeQuery();
+            while (resultSet.next()) {
+                result.add(resultSet.getString(1));
+            }
+        } catch (SQLException e) {
+            throw new BizError("sql execute failed!");
+        } finally {
+            try {
+                if (resultSet != null) {
+                    resultSet.close();
+                }
+                if (statement != null) {
+                    statement.close();
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        return result;
+    }
+
+    private void setParameters(PreparedStatement statement, List listSearchValues) throws BizError {
+
+        if (statement == null || listSearchValues == null || listSearchValues.size() <= 0) {
+            return;
+        }
+        Object value;
+        try {
+            for (int i = 0; i < listSearchValues.size(); i++) {
+                value = listSearchValues.get(i);
+                if (value == null) {
+                    continue;
+                }
+                if (value instanceof Long) {
+                    statement.setLong(i + 1, (Long) value);
+                } else if (value instanceof Float) {
+                    statement.setFloat(i + 1, (Float) value);
+                } else if (value instanceof Double) {
+                    statement.setDouble(i + 1, (Double) value);
+                } else if (value instanceof Integer) {
+                    statement.setInt(i + 1, (Integer) value);
+                } else if (value instanceof String) {
+                    String sValue = (String) value;
+                    if (sValue.length() <= 300) {
+                        statement.setString(i + 1, sValue);
+                    } else {
+                        StringReader stringReader = new StringReader(sValue);
+                        statement.setCharacterStream(i + 1, stringReader, sValue.length());
+                    }
+                } else if (value instanceof Timestamp) {
+                    statement.setTimestamp(i + 1, (Timestamp) value);
+                }
+            }
+        } catch (SQLException e) {
+            throw new BizError("failed set sql parameters!");
+        }
+    }
+
+    public List<Map<String, Object>> executeStringsQuery(Connection connection, String sql, List parameters) throws BizError {
+        PreparedStatement statement = null;
+        ResultSet resultSet = null;
+        List<Map<String, Object>> result = new ArrayList<>();
+        try {
+            statement = connection.prepareStatement(sql);
+            setParameters(statement, parameters);
+            resultSet = statement.executeQuery();
+            int count = resultSet.getMetaData().getColumnCount();
+            while (resultSet.next()) {
+                Map<String, Object> row = readFromRs(resultSet);
+                result.add(row);
+            }
+        } catch (SQLException e) {
+            throw new BizError("sql execute failed!");
+        } finally {
+            try {
+                if (resultSet != null) {
+                    resultSet.close();
+                }
+                if (statement != null) {
+                    statement.close();
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        return result;
+    }
+
+    private Map<String, Object> readFromRs(ResultSet resultSet) {
+
+        Map<String, Object> result = new HashMap<>();
+        try {
+            if (resultSet == null) {
+                return result;
+            }
+            ResultSetMetaData metaData = resultSet.getMetaData();
+            Object objValue;
+            String sFieldName;
+            int nColCount = metaData.getColumnCount();
+            for (int i = 1; i <= nColCount; i++) {
+                sFieldName = metaData.getColumnLabel(i).toUpperCase();
+                objValue = null;
+                switch (metaData.getColumnType(i)) {
+                    case Types.NUMERIC:
+                    case Types.DECIMAL: {//数值
+                        if (metaData.getScale(i) <= 0) {
+                            long lValue = resultSet.getLong(i);
+                            if (!resultSet.wasNull()) {
+                                objValue = lValue;
+                            }
+                        } else {
+                            Double dValue = resultSet.getDouble(i);
+                            if (!resultSet.wasNull())
+                                objValue = dValue;
+                        }
+                        break;
+                    }
+                    case Types.INTEGER:
+                    case Types.TINYINT:
+                    case Types.SMALLINT:
+                    case Types.BIGINT: { // 整型
+                        long lValue = resultSet.getLong(i);
+                        if (!resultSet.wasNull()) {
+                            objValue = lValue;
+                        }
+                        break;
+                    }
+                    case Types.CHAR:
+                    case Types.VARCHAR: { // 变长字符串
+                        objValue = resultSet.getString(i);
+                        break;
+                    }
+                    case Types.DATE:
+                    case Types.TIME:
+                    case Types.TIMESTAMP: { // 日期时间型
+                        Timestamp tsDateTime = resultSet.getTimestamp(i);
+                        objValue = tsDateTime.getTime();
+                        break;
+                    }
+                    case Types.CLOB:
+                    case Types.LONGVARCHAR: { // 大文本数据
+
+                        Reader reader = resultSet.getCharacterStream(i);
+                        objValue = getClob(reader);
+                        break;
+                    }
+                    case Types.DOUBLE: { // 双精度数据
+                        double dValue = resultSet.getDouble(i);
+                        if (!resultSet.wasNull()) {
+                            objValue = dValue;
+                        }
+                        break;
+                    }
+                    default: { // 其他类型
+                        objValue = resultSet.getObject(i);
+                        break;
+                    }
+                }
+                if (objValue != null) {
+                    result.put(sFieldName, objValue);
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return result;
+    }
+
+    public void sqlExecuteUpdate(Connection conn, String updatesql, List paramerters) throws WCMException {
+        PreparedStatement preStm = null;
+        try {
+            preStm = conn.prepareStatement(updatesql);
+            setParameters(preStm, paramerters);
+            preStm.executeUpdate();
+            preStm.close();
+            preStm = null;
+        } catch (Exception e) {
+            throw new WCMException(e.getMessage(), e);
+        } finally {
+            if (preStm != null) {
+                try {
+                    preStm.close();
+                } catch (Exception e) {
+                   e.printStackTrace();
+                }
+            }
+        }
+    }
+
+    private String getClob(Reader reader) throws Exception {
+        if (reader == null)
+            return null;
+
+        StringBuffer txtBuff = null;
+
+        char[] buff = new char[8192];
+        int nLen = -1;
+        while ((nLen = reader.read(buff)) != -1) {
+            if (txtBuff == null)
+                txtBuff = new StringBuffer(nLen);
+            txtBuff.append(buff, 0, nLen);
+        }
+        buff = null;
+        reader.close();
+
+        if (txtBuff == null) {
+            return "";
+        }
+        return txtBuff.toString();
+    }
+}

+ 6 - 5
TRS.WCM.Developer/src/com/trs/web2frame/ServiceConfig.java

@@ -13,18 +13,19 @@ import java.util.Map;
 import com.trs.infra.util.Loader;
 
 /**
- * Title: TRS 内容协作平台(TRS WCM) <BR>
+ * Title: TRS 锟斤拷锟斤拷协锟斤拷平台锟斤拷TRS WCM锟斤拷 <BR>
  * Description: <BR>
  * TODO <BR>
- * Copyright: Copyright (c) 2004-2005 TRS信息技术有限公司 <BR>
- * Company: TRS信息技术有限公司(www.trs.com.cn) <BR>
+ * Copyright: Copyright (c) 2004-2005 TRS锟斤拷息锟斤拷锟斤拷锟斤拷锟睫癸拷司 <BR>
+ * Company: TRS锟斤拷息锟斤拷锟斤拷锟斤拷锟睫癸拷司(www.trs.com.cn) <BR>
  * 
- * @author TRS信息技术有限公司 LY
+ * @author TRS锟斤拷息锟斤拷锟斤拷锟斤拷锟睫癸拷司 LY
  * @version 1.0
  */
 
 public class ServiceConfig {
-	public static String WCM_HOST_URL = "http://gzdev.devdemo.trs.net.cn/gov";
+//	public static String WCM_HOST_URL = "https://gzdev.devdemo.trs.net.cn/gov";
+	public static String WCM_HOST_URL = "http://192.168.200.124/gov";
 //	public static String WCM_HOST_URL = "http://192.168.0.99:8080/wcm";
 
 	public static String WCM_SERVICE_URL = WCM_HOST_URL + "/opendata.do";

+ 309 - 6
TRS.WCM.Developer/test/com/trs/web2frame/WCMServiceCallerTest.java

@@ -3,19 +3,29 @@
  */
 package com.trs.web2frame;
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.trs.cms.CMSConstants;
+import com.trs.dto.ChannelDTO;
+import com.trs.dto.SiteDTO;
+import com.trs.infra.common.BizError;
+import com.trs.infra.common.WCMException;
+import com.trs.infra.util.CMyString;
+import com.trs.util.DBUtil;
 import com.trs.web2frame.dispatch.Dispatch;
 import com.trs.web2frame.eventhandler.ICallbackCompleteHandler;
 import com.trs.web2frame.eventhandler.ICallbackEventHandler;
 import com.trs.web2frame.eventhandler.ICallbackSuccessHandler;
 import com.trs.web2frame.util.JsonHelper;
-
 import junit.framework.TestCase;
 
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 /**
  * Title: TRS 内容协作平台(TRS WCM) <BR>
  * Description: <BR>
@@ -33,14 +43,39 @@ public class WCMServiceCallerTest extends TestCase {
 	 */
 	// public static final String FILE_1 =
 	// "D:\\Webapps\\TRS_WCM_52\\Tomcat\\webapps\\wcm\\infoview\\infoview.js";
-	public static final String FILE_1 = "/Users/cao.hui/tmp/j01.txt";
+	public static final String FILE_1 = "/Users/macro.li/TRS/logs/j01.txt";
+
+	private static final String connectUrl = "jdbc:mysql://127.0.0.1:3306/liion?characterEncoding=utf-8&amp;zeroDateTimeBehavior=convertToNull";
+	private static final String userName = "root";
+	private static final String pswd = "zxcv1234";
+	private static Connection connection;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        connection = DBUtil.getConnection(connectUrl, userName, pswd);
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+        try {
+            if (connection != null) {
+                connection.close();
+            }
+        } catch (SQLException e) {
+            e.printStackTrace();
+        }
+    }
 
 	public void testCall() {
 		String sServiceId = "gov_site";
 		String sMethodName = "querySites";
 		Map oPostData = new HashMap();
 		oPostData.put("CurrUserName", "admin");
+		oPostData.put("MODULEID", "10");
 		oPostData.put("MediaType", "1");
+		oPostData.put("PAGESIZE", "10");
 		Dispatch oResult = WCMServiceCaller.Call(sServiceId, sMethodName,
 				oPostData, false);
 		System.out.println("Result:" + oResult.getResponseText());
@@ -157,4 +192,272 @@ public class WCMServiceCallerTest extends TestCase {
 
 		WCMServiceCaller.Call(sServiceId, sMethodName, hParameters, true);
 	}
+
+    /**
+     * 站点迁移
+     * @throws WCMException
+     */
+    public void testPostSaveSite() throws WCMException {
+
+        List<SiteDTO> list = new ArrayList<>();
+
+        //start TODO 需要项目组根据第三方项目情况,填写相应数据 具体参数见:SiteDTO
+        SiteDTO siteDTO = new SiteDTO();
+
+	    siteDTO.setSitename("乐至市改1");
+	    siteDTO.setClassificationid(95);
+	    siteDTO.setSitedesc("乐至市");
+	    siteDTO.setDatapath("lezshi1");
+	    siteDTO.setWebhttp("http://192.168.200.124/pub/lezshi");
+        siteDTO.setViewinfoid(36);
+        siteDTO.setDetailtemplate(7086);
+        siteDTO.setOutlinetemplate(7084);
+	    siteDTO.setChnloutlinetemp(7085);
+	    siteDTO.setSrcSiteCode("1");
+
+        list.add(siteDTO);
+        //end TODO 需要项目组根据第三方项目情况,填写相应数据
+        testSaveSite(list);
+    }
+
+    /**
+     * 栏目迁移
+     * @throws WCMException
+     */
+    public void testPostSaveChannel() throws WCMException {
+
+        List<ChannelDTO> list = new ArrayList<>();
+
+        //start TODO 需要项目组根据第三方项目情况,填写相应数据 具体参数见:ChannelDTO
+        ChannelDTO channelDTO = new ChannelDTO();
+
+        channelDTO.setChnlname("视频新闻");
+        channelDTO.setChnldesc("视频新闻");
+        channelDTO.setChnldatapath("spxw");
+        channelDTO.setViewinfoid(36);
+        channelDTO.setDetailtemplate(0);
+        channelDTO.setOutlinetemplate(0);
+        channelDTO.setParentid(0);
+        String srcSiteCode = "1";
+        //通过第三方系统的站点 唯一表示 获取迁移后的站点
+        int siteId = querySiteIdBySrcSiteCode(srcSiteCode);
+        if (siteId == 0){
+            throw new BizError(String.format("该站点[%s]没有迁移",srcSiteCode));
+        }
+        channelDTO.setSiteid(siteId);
+        channelDTO.setSrcChannelCode("13");
+
+        list.add(channelDTO);
+        //end TODO 需要项目组根据第三方项目情况,填写相应数据
+        testSaveChannel(list);
+    }
+
+    private int querySiteIdBySrcSiteCode(String srcSiteCode) throws BizError {
+
+        String sql = "SELECT SITEID FROM HYCLOUDSITERELATION WHERE SRCSITECODE = ?;";
+
+        List<String> list = new ArrayList<>();
+        list.add(srcSiteCode);
+        List<String> result = DBUtil.getDBManager().sqlExecuteStringsQuery(connection, sql, list);
+
+        int siteId = 0;
+        if (result != null && result.size() == 1){
+            siteId = Integer.parseInt(result.get(0));
+        }
+        return siteId;
+    }
+
+    /**
+     * 海云批量保存站点
+     * @param siteDTOList
+     */
+    private void testSaveSite(List<SiteDTO> siteDTOList) throws WCMException {
+
+        String sServiceId = "gov_site";
+
+        String sMethodName = "saveSite";
+
+        for(SiteDTO siteDTO : siteDTOList) {
+
+        	if (CMyString.isEmpty(siteDTO.getSrcSiteCode())){
+        		throw new BizError("第三方站点唯一表示不能为空");
+			}
+
+            HashMap<String, Object> hParameters = new HashMap<>();
+
+            hParameters.put("CurrUserName", "admin"); // 当前操作的用户
+
+            hParameters.put("SITEID", siteDTO.getSiteid()); // 表示新建
+
+            hParameters.put("SITENAME", siteDTO.getSitename());
+
+            hParameters.put("SITEDESC", siteDTO.getSitedesc());
+
+            hParameters.put("CLASSIFICATIONID", siteDTO.getClassificationid());
+
+            hParameters.put("DATAPATH", siteDTO.getDatapath());
+
+            hParameters.put("VIEWINFOID", siteDTO.getViewinfoid());
+
+            hParameters.put("WEBHTTP", siteDTO.getWebhttp());
+
+            hParameters.put("DETAILTEMPLATE", siteDTO.getDetailtemplate());
+
+            hParameters.put("OUTLINETEMPLATE", siteDTO.getOutlinetemplate());
+
+            hParameters.put("CHNLOUTLINETEMP", siteDTO.getChnloutlinetemp());
+
+            hParameters.put("SITEORDER", siteDTO.getSiteorder());
+
+            hParameters.put("ISDISTRIBUTABLE", siteDTO.getIsdistributable());
+
+            hParameters.put("ISPUSHABLE", siteDTO.getIspushable());
+
+            hParameters.put("ISSUBSCRIBE", siteDTO.getIssubscribe());
+
+            hParameters.put("MEDIATYPE", siteDTO.getMediatype());
+
+            hParameters.put("AUTOCHECK", siteDTO.getAutocheck());
+
+            hParameters.put("ISOTHERPLATDISTRIBUTABLE", siteDTO.getIsotherplatdistributable());
+
+            hParameters.put("ISOTHERPLATPUSHABLE", siteDTO.getIsotherplatpushable());
+
+            Dispatch oResult = WCMServiceCaller.Call(sServiceId, sMethodName, hParameters, true);
+
+            //对返回值进行处理
+            dealWithSiteReturn(oResult, siteDTO);
+
+        }
+    }
+
+    private void dealWithSiteReturn(Dispatch oResult, SiteDTO siteDTO) throws WCMException {
+
+        System.out.println("Result:" + oResult.getResponseText());
+
+        JSONObject jsonObject = JSON.parseObject(oResult.getResponseText()).getJSONObject("DATA");
+        if (jsonObject == null) {
+            throw new BizError(String.format("保存站点失败,站点名称[%s],迁移前应用ID[%s]", siteDTO.getSitename(), siteDTO.getSrcSiteCode()));
+        }
+        int siteId = jsonObject.getIntValue("SITEID");
+        if (siteId == 0) {
+            throw new BizError(String.format("保存站点失败,站点名称[%s],迁移前应用ID[%s]", siteDTO.getSitename(), siteDTO.getSrcSiteCode()));
+        }
+        saveSiteMapping(siteId, siteDTO.getSrcSiteCode());
+    }
+
+	public void testPostSaveSiteMapping() throws WCMException{
+
+    	saveSiteMapping(1, "12");
+	}
+
+	private void saveSiteMapping(int siteId, String siteCode) throws WCMException {
+
+		System.out.println(String.format("保存成功,新站点ID[%d]", siteId));
+		String sql = "INSERT INTO HYCLOUDSITERELATION (SRCSITECODE,SITEID) VALUES(?, ?);";
+		List<Object> list = new ArrayList<>();
+		list.add(siteCode);
+		list.add(siteId);
+		DBUtil.getDBManager().sqlExecuteUpdate(connection, sql, list);
+	}
+
+
+    private void testSaveChannel(List<ChannelDTO> channelDTOS) throws WCMException{
+
+        String sServiceId = "gov_channel";
+
+        String sMethodName = "saveChannel";
+
+        for(ChannelDTO channelDTO : channelDTOS) {
+
+            if (CMyString.isEmpty(channelDTO.getSrcChannelCode())){
+                throw new BizError("第三方栏目唯一表示不能为空");
+            }
+
+            HashMap<String, Object> hParameters = new HashMap<>();
+
+            hParameters.put("CurrUserName", "admin"); // 当前操作的用户
+
+            hParameters.put("SITEID", channelDTO.getSiteid());
+
+            hParameters.put("CHANNELID", channelDTO.getChannelid()); // 表示新建
+
+            hParameters.put("CHNLNAME", channelDTO.getChnlname());
+
+            hParameters.put("CHNLDESC", channelDTO.getChnldesc());
+
+            hParameters.put("PARENTID", channelDTO.getParentid());
+
+            hParameters.put("CHNLDATAPATH", channelDTO.getChnldatapath());
+
+            hParameters.put("VIEWINFOID", channelDTO.getViewinfoid());
+
+            if (channelDTO.getRootdomain() != null){
+                hParameters.put("ROOTDOMAIN", channelDTO.getRootdomain());
+            }
+            hParameters.put("DETAILTEMPLATE", channelDTO.getDetailtemplate());
+
+            hParameters.put("OUTLINETEMPLATE", channelDTO.getOutlinetemplate());
+
+            hParameters.put("CHNLORDER", channelDTO.getChnlorder());
+
+            hParameters.put("ISDISTRIBUTABLE", channelDTO.getIsdistributable());
+
+            hParameters.put("ISPUSHABLE", channelDTO.getIspushable());
+
+            hParameters.put("ISSUBSCRIBE", channelDTO.getIssubscribe());
+
+            hParameters.put("MEDIATYPE", channelDTO.getMediatype());
+
+            hParameters.put("CANPUB", channelDTO.getCanpub());
+
+            hParameters.put("ISOTHERPLATDISTRIBUTABLE", channelDTO.getIsotherplatdistributable());
+
+            hParameters.put("ISOTHERPLATPUSHABLE", channelDTO.getIsotherplatpushable());
+
+            hParameters.put("CHNLTYPE", channelDTO.getChnltype());
+
+            if (channelDTO.getLinkurl() != null){
+                hParameters.put("LINKURL", channelDTO.getLinkurl());
+            }
+
+            hParameters.put("GENERATECHNLROLE", channelDTO.getGeneratechnlrole());
+
+            Dispatch oResult = WCMServiceCaller.Call(sServiceId, sMethodName, hParameters, true);
+
+            //对返回值进行处理
+            dealWithChannelReturn(oResult, channelDTO);
+
+        }
+
+    }
+
+    private void dealWithChannelReturn(Dispatch oResult, ChannelDTO channelDTO) throws WCMException {
+        System.out.println("Result:" + oResult.getResponseText());
+
+        JSONObject jsonObject = JSON.parseObject(oResult.getResponseText()).getJSONObject("DATA");
+        if (jsonObject == null) {
+            throw new BizError(String.format("保存栏目失败,栏目名称[%s],迁移前应用ID[%s]", channelDTO.getChnlname(), channelDTO.getSrcChannelCode()));
+        }
+        int channelid = jsonObject.getIntValue("CHANNELID");
+        if (channelid == 0) {
+            throw new BizError(String.format("保存栏目失败,栏目名称[%s],迁移前应用ID[%s]", channelDTO.getChnlname(), channelDTO.getSrcChannelCode()));
+        }
+        saveChannelMapping(channelid, channelDTO.getSrcChannelCode());
+    }
+
+    public void testPostSaveChannelMapping() throws WCMException{
+
+        saveChannelMapping(1, "12");
+    }
+
+    private void saveChannelMapping(int channelid, String srcChannelCode) throws WCMException {
+
+        System.out.println(String.format("保存成功,新栏目ID[%d]", channelid));
+        String sql = "INSERT INTO HYCLOUDCHANNELRELATION (SRCCHANNELCODE, CHANNELID) VALUES(?, ?);";
+        List<Object> list = new ArrayList<>();
+        list.add(srcChannelCode);
+        list.add(channelid);
+        DBUtil.getDBManager().sqlExecuteUpdate(connection, sql, list);
+    }
 }