public override void Sync()
        {
            LogOperation.WriteTitle(sbLog, "-------------------------------------同步流程信息开始-------------------------------------");

            string        companyCodeConditionString = "ccode = '" + targetCode + "'";
            List <string> workflowId = new List <string>();

            LogOperation.WriteSyncTableTitle(sbLog, "wf_workflow", SyncType.AddAfterDelete, companyCodeConditionString);
            SyncByAddAfterDelete("wf_workflow", companyCodeConditionString, deleteAction,
                                 (dr) =>
            {
                LogOperation.Append(sbLog, "流程ID:" + dr["FLOWID"] + "。");
                workflowId.Add("'" + dr["FLOWID"] + "'");
            }, totalAction);

            string workflowConditionString = "flowid in (" + string.Join(",", workflowId.ToArray()) + ")";

            LogOperation.WriteSyncTableTitle(sbLog, "wf_node", SyncType.AddAfterDelete, workflowConditionString);
            SyncByAddAfterDelete("wf_node", workflowConditionString, deleteAction,
                                 (dr) =>
            {
                LogOperation.Append(sbLog, "流程ID:" + dr["FLOWID"] + "," + "环节ID" + dr["NODEID"] + "。");
            }, totalAction);

            LogOperation.WriteSyncTableTitle(sbLog, "wf_file", SyncType.Comparer, string.Empty);
            SyncByComparer("wf_file", string.Empty, new List <string>()
            {
                "FILECODE"
            }, false,
                           (dr) =>
            {
                LogOperation.Append(sbLog, "添加 文档编码:" + dr["FILECODE"]);
            }, (dr) =>
            {
                LogOperation.Append(sbLog, "删除 文档编码:" + dr["FILECODE"]);
            }, (drTarget, drLocal) =>
            {
                LogOperation.Append(sbLog, "更新 文档编码:" + drTarget["FILECODE"]);
            });

            LogOperation.WriteTitle(sbLog, "-------------------------------------同步流程信息结束-------------------------------------");
        }
        private void SyncXxbh(OracleDbOperation sourceDbOperation, OracleDbOperation targetDbOperation, string targetCode,
                              Action <DataRow> actionAddTargetMessageFile, Action <DataRow> actionDeleteSourceMessageFile, Action <DataRow> actionDeleteTargetMessageFile)
        {
            string sql;
            List <OracleParameter> parameters = new List <OracleParameter>();
            DataTable dt;

            //用指定的行政区代码去系统信息接收表中查询所有与接收人行政区代码相等的记录,即需要同步的信息编号。
            sql = "select distinct(jsxxbh) from xtxxjs where jsrxzdm = :jsrxzdm";
            parameters.Clear();
            parameters.Add(new OracleParameter("jsrxzdm", targetCode));
            dt = sourceDbOperation.ExecuteDataTable(sql, "temp", parameters);
            var xxbhs = (from DataRow dr in dt.Rows
                         select "'" + dr[0] + "'").ToArray();

            if (xxbhs.Length > 0)
            {
                //分别取源系统和目标系统取出需要同步的信息接收数据。
                string xxbhsCondition = string.Join(",", xxbhs);
                sql = "select * from xtxxjs where jsxxbh in (" + xxbhsCondition + ")";
                DataTable dtSourceXtxxjs = sourceDbOperation.ExecuteDataTable(sql, "xtxxjs", null);
                DataTable dtTargetXtxxjs = targetDbOperation.ExecuteDataTable(sql, "xtxxjs", null);

                string xtxxCondition = "xxbh in (" + xxbhsCondition + ")";

                //进行比对同步。
                LogOperation.WriteSyncTableTitle(sbLog, "xtxx", SyncType.Comparer, xtxxCondition);
                SyncByComparer(sourceDbOperation, targetDbOperation, "xtxx", xtxxCondition, new List <string>()
                {
                    "xxbh"
                }, true,
                               (dr) =>
                {
                    string xxbh = dr["xxbh"].ToString();
                    LogOperation.Append(sbLog, "添加目标系统信息!信息编号:" + xxbh);
                    foreach (var needAddXtxxjs in dtSourceXtxxjs.Select("jsxxbh = '" + xxbh + "' and jsrxzdm = '" + targetCode + "'"))
                    {
                        DataRow newXtxxjs = dtTargetXtxxjs.NewRow();
                        Copy(needAddXtxxjs, newXtxxjs);
                        dtTargetXtxxjs.Rows.Add(newXtxxjs);
                    }
                    if (actionAddTargetMessageFile != null)
                    {
                        actionAddTargetMessageFile(dr);
                    }
                },
                               (dr) =>
                {
                    LogOperation.Append(sbLog, "删除垃圾系统信息!信息编号:" + dr["XXBH"]);
                },
                               (drSource, drTarget) =>
                {
                    string xxbh = drSource["XXBH"].ToString();
                    LogOperation.Append(sbLog, "更新系统信息!信息编号:" + xxbh);

                    if (actionAddTargetMessageFile != null)
                    {
                        actionAddTargetMessageFile(drSource);
                    }

                    //判断是否需要删除邮件。
                    if (drSource["FSRSC"].ToString() == "1")
                    {
                        var querySource = from DataRow dr in dtSourceXtxxjs.Rows
                                          where dr["JSXXBH"].ToString() == xxbh
                                          select dr;
                        var queryTarget = from DataRow dr in dtTargetXtxxjs.Rows
                                          where dr["JSXXBH"].ToString() == xxbh
                                          select dr;
                        bool needDelete = true;
                        foreach (var itemSource in querySource)
                        {
                            string jsr         = itemSource["JSR"].ToString();
                            var queryTargetJsr = (from dr in queryTarget
                                                  where dr["JSR"].ToString() == jsr
                                                  select dr).FirstOrDefault();
                            if (queryTargetJsr == null)
                            {
                                if (itemSource["JSRSC"].ToString() == "0")
                                {
                                    needDelete = false;
                                    break;
                                }
                            }
                            else
                            {
                                if (queryTargetJsr["JSRSC"].ToString() == "0")
                                {
                                    needDelete = false;
                                    break;
                                }
                            }
                        }

                        //删除邮件。
                        if (needDelete)
                        {
                            dtOperation.DeleteDbDataRow(drSource, (dr) =>
                            {
                                dtOperation.DeleteDbDataRows(querySource, null);
                                LogOperation.Append(sbLog, "删除源系统信息,因为收发双方都已删除此信息!信息编号:" + xxbh);
                                actionDeleteSourceMessageFile(drSource);
                            });
                            dtOperation.DeleteDbDataRow(drTarget, (dr) =>
                            {
                                dtOperation.DeleteDbDataRows(queryTarget, null);
                                LogOperation.Append(sbLog, "删除目标系统信息,因为收发双方都已删除此信息!信息编号:" + xxbh);
                                actionDeleteSourceMessageFile(drTarget);
                            });
                        }
                    }
                });

                //保存信息接收信息。
                sourceDbOperation.UpdateDataTable(dtSourceXtxxjs);
                targetDbOperation.UpdateDataTable(dtTargetXtxxjs);
            }
        }
Example #3
0
        public override void Sync()
        {
            LogOperation.WriteTitle(sbLog, "-------------------------------------同步系统信息开始-------------------------------------");

            Action <DataRow> companyDetailAction = (dr) =>
            {
                LogOperation.Append(sbLog, "单位编码:" + dr["CCODE"]);
            };
            Action <DataRow> departmentDetailAction = (dr) =>
            {
                LogOperation.Append(sbLog, "部门编码:" + dr["DEPTCODE"]);
            };
            Action <DataRow> userDetailAction = (dr) =>
            {
                LogOperation.Append(sbLog, "用户ID:" + dr["USERID"]);
            };

            string targetCompanyCodeConditionString = "ccode like '" + targetCode.Substring(0, 4) + "%'";

            LogOperation.Append(sbLog, "同步系统信息(从" + targetCode + "到" + localCode + ")。");

            LogOperation.WriteSyncTableTitle(sbLog, "company", SyncType.Comparer, targetCompanyCodeConditionString);
            SyncByComparer(targetDb, localDb, "company", targetCompanyCodeConditionString, new List <string>()
            {
                "CCODE"
            }, true,
                           (dr) =>
            {
                LogOperation.Append(sbLog, "添加行政区单位!单位编码:" + dr["CCODE"]);
            },
                           (dr) =>
            {
                LogOperation.Append(sbLog, "删除行政区单位!单位编码:" + dr["CCODE"]);
            },
                           (drTarget, drLocal) =>
            {
                LogOperation.Append(sbLog, "更新行政区单位!单位编码:" + drTarget["CCODE"]);
            });

            LogOperation.WriteSyncTableTitle(sbLog, "department", SyncType.AddAfterDelete, targetCompanyCodeConditionString);
            SyncByAddAfterDelete(targetDb, localDb, "department", targetCompanyCodeConditionString, deleteAction, departmentDetailAction, totalAction);

            LogOperation.WriteSyncTableTitle(sbLog, "users", SyncType.AddAfterDelete, targetCompanyCodeConditionString);
            SyncByAddAfterDelete(targetDb, localDb, "users", targetCompanyCodeConditionString, deleteAction, userDetailAction, totalAction);

            //string localCompanyCodeConditionString = "ccode like '" + localCode.Substring(0, 4) + "%'";

            //LogOperation.Append(sbLog, "同步系统信息(从" + localCode + "到" + targetCode + ")。");

            //LogOperation.WriteSyncTableTitle(sbLog, "company", SyncType.AddAfterDelete, localCompanyCodeConditionString);
            //SyncByComparer(localDb, targetDb, "company", localCompanyCodeConditionString, new List<string>() { "CCODE" }, true,
            //     (dr) =>
            //     {
            //         LogOperation.Append(sbLog, "添加行政区单位!单位编码:" + dr["CCODE"]);
            //     },
            //     (dr) =>
            //     {
            //         LogOperation.Append(sbLog, "删除行政区单位!单位编码:" + dr["CCODE"]);
            //     },
            //     (drTarget, drLocal) =>
            //     {
            //         LogOperation.Append(sbLog, "更新行政区单位!单位编码:" + drTarget["CCODE"]);
            //     });

            //LogOperation.WriteSyncTableTitle(sbLog, "department", SyncType.AddAfterDelete, localCompanyCodeConditionString);
            //SyncByAddAfterDelete(localDb, targetDb, "department", localCompanyCodeConditionString, deleteAction, departmentDetailAction, totalAction);

            //LogOperation.WriteSyncTableTitle(sbLog, "users", SyncType.AddAfterDelete, localCompanyCodeConditionString);
            //SyncByAddAfterDelete(localDb, targetDb, "users", localCompanyCodeConditionString, deleteAction, userDetailAction, totalAction);

            LogOperation.WriteTitle(sbLog, "-------------------------------------同步系统信息结束-------------------------------------");
        }
Example #4
0
        public override void Sync()
        {
            LogOperation.WriteTitle(sbLog, "-------------------------------------同步项目信息开始-------------------------------------");

            LogOperation.WriteTitle(sbLog, string.Format("同步数据方式:{0}", syncConfig.SyncType.Equals(1) ? "增量同步" : "全部同步"));

            Action <DataRow, DataRow> checkTbzt = (drA, drB) =>
            {
                ChangeTbzt(drA);
                if (ChangeTbzt(drB))
                {
                    LogOperation.Append(sbLog, "标记成已同步项目:" + drB["ITEMCODE"].ToString() + "");
                }
            };

            //在目标数据库中查询需要同步的项目信息。
            string strWhere = string.Empty;

            if (syncConfig.SyncType == 1)
            {
                strWhere = "and TBZT != 1";
            }

            string    queryTargetUnSyncXmxx = string.Format("select * from xm_xmxx where 1=1 {0} order by itemCode", strWhere);
            DataTable dtXmxxTarget          = targetDb.ExecuteDataTable(queryTargetUnSyncXmxx, "xm_xmxx", null);

            int rowCount = dtXmxxTarget.Rows.Count;

            if (rowCount > 0)
            {
                string[] itemCodes         = new string[rowCount];
                string[] conditonItemCodes = new string[rowCount];
                for (int i = 0; i < rowCount; i++)
                {
                    string itemCode = dtXmxxTarget.Rows[i]["ITEMCODE"].ToString();
                    conditonItemCodes[i] = "'" + itemCode + "'";
                    itemCodes[i]         = itemCode;
                }
                string itemCodeConditionString = " itemcode in (" + string.Join(",", conditonItemCodes) + ")";

                #region  步项目信息

                LogOperation.WriteSyncTableTitle(sbLog, "xm_xmxx", SyncType.Comparer, itemCodeConditionString);
                SyncByComparer("xm_xmxx", itemCodeConditionString, new List <string>()
                {
                    "ITEMCODE"
                }, true,
                               (dr) =>
                {
                    LogOperation.Append(sbLog, "添加 项目编号:" + dr["ITEMCODE"]);
                },
                               (dr) =>
                {
                    LogOperation.Append(sbLog, "删除 项目编号:" + dr["ITEMCODE"]);
                },
                               (drTarget, drLocal) =>
                {
                    LogOperation.Append(sbLog, "更新 项目编号:" + drTarget["ITEMCODE"]);
                }, checkTbzt);

                #endregion

                #region  步项目相关信息

                List <string> dkxxIds = new List <string>();
                SyncByAddAfterDelete("gis_data", itemCodeConditionString, deleteAction,
                                     (dr) => { dkxxIds.Add("'" + dr["GisId"] + "'"); }, totalAction);

                if (dkxxIds.Count > 0)
                {
                    string dkjzdConditionString = " GisId in (" + string.Join(",", dkxxIds.ToArray()) + ")";

                    SyncByAddAfterDelete("gis_dk", dkjzdConditionString, deleteAction, null, totalAction);

                    SyncByAddAfterDelete("gis_jzd", dkjzdConditionString, deleteAction, null, totalAction);

                    SyncByAddAfterDelete("gis_dltb", dkjzdConditionString, deleteAction, null, totalAction);

                    SyncByAddAfterDelete("gis_xzdw", dkjzdConditionString, deleteAction, null, totalAction);
                }

                string xzfConditionString = "XZDM = " + targetCode;

                SyncByAddAfterDelete("xm_xzf", xzfConditionString, deleteAction, null, totalAction);

                //SyncByAddAfterDelete("xm_xmxx", itemCodeConditionString, deleteAction, null, totalAction);

                SyncByAddAfterDelete("xm_sb_jbxx", itemCodeConditionString, deleteAction, null, totalAction);

                SyncByAddAfterDelete("xm_ky_jbxx", itemCodeConditionString, deleteAction, null, totalAction);

                SyncByAddAfterDelete("xm_ghsjysxx", itemCodeConditionString, deleteAction, null, totalAction);

                SyncByAddAfterDelete("xm_gcxx", itemCodeConditionString, deleteAction, null, totalAction);

                SyncByAddAfterDelete("xm_gdxx", itemCodeConditionString, deleteAction, null, totalAction);

                SyncByAddAfterDelete("xm_jsxx", itemCodeConditionString, deleteAction, null, totalAction);

                SyncByAddAfterDelete("xm_ss_bgxx", itemCodeConditionString, deleteAction, null, totalAction);

                SyncByAddAfterDelete("xm_ss_gcjl_jlht", itemCodeConditionString, deleteAction, null, totalAction);

                SyncByAddAfterDelete("xm_ss_gcjl_jlry", itemCodeConditionString, deleteAction, null, totalAction);

                SyncByAddAfterDelete("xm_ss_jdgz_xmbb", itemCodeConditionString, deleteAction, null, totalAction);

                SyncByAddAfterDelete("xm_ss_zjbf", itemCodeConditionString, deleteAction, null, totalAction);

                SyncByAddAfterDelete("xm_ss_ztb_jbxx", itemCodeConditionString, deleteAction, null, totalAction);

                SyncByAddAfterDelete("xm_ss_ztb_sght", itemCodeConditionString, deleteAction, null, totalAction);

                SyncByAddAfterDelete("xm_ss_ztb_zbqk", itemCodeConditionString, deleteAction, null, totalAction);

                SyncByAddAfterDelete("xm_xmdw", itemCodeConditionString, deleteAction, null, totalAction);

                SyncByAddAfterDelete("xm_xmzj", itemCodeConditionString, deleteAction, null, totalAction);

                SyncByAddAfterDelete("xm_ysxx", itemCodeConditionString, deleteAction, null, totalAction);

                SyncByAddAfterDelete("wf_instance", itemCodeConditionString, deleteAction, null, totalAction);

                SyncByAddAfterDelete("item_file", itemCodeConditionString, deleteAction, null, totalAction);

                //清除垃圾文件。
                LogOperation.WriteTitle(sbLog, "--------开始检查项目垃圾文件--------");
                foreach (var itemCode in itemCodes)
                {
                    string    filePath          = CommonManage.GetFtpUploadPath(targetCode) + itemCode;
                    string    itemFileTableName = "item_file";
                    string    queryFileSql      = "select * from " + itemFileTableName + " where itemcode = '" + itemCode + "'";
                    DataTable dtItemFile        = targetDb.ExecuteDataTable(queryFileSql, itemFileTableName, null);
                    if (dtItemFile.Rows.Count > 0)
                    {
                        List <string> exceptions = (from DataRow dr in dtItemFile.Rows select dr["FILENAME"].ToString()).ToList();
                        targetFtp.ClearDirectory(itemCode, filePath, exceptions, deleteFileAction);
                    }
                }
                LogOperation.WriteTitle(sbLog, "--------结束检查项目垃圾文件--------");

                //LogOperation.WriteSyncTableTitle(sbLog, "item_file", SyncType.AddAfterDelete, itemCodeConditionString);


                LogOperation.WriteTitle(sbLog, "--------开始同步项目文件(FTP)--------");

                foreach (var itemCode in itemCodes)
                {
                    string filePath = CommonManage.GetFtpUploadPath(targetCode);
                    try
                    {
                        targetFtp.CopyDirectory(filePath, itemCode, localFtp, filePath, itemCode, ftpCopyAction);
                    }
                    catch (Exception ex)
                    {
                        LogOperation.Append(sbLog, string.Format("异常  项目编号:{0}; 原因:{1}", itemCode, ex.Message));
                        continue;
                    }
                    //string gisPath = CommonManage.GetFtpGisQueryPath() + itemCode + ".xml";
                    //targetFtpOperation.CopyFile(gisPath, localFtpOperation, gisPath);
                }

                LogOperation.WriteTitle(sbLog, "--------结束同步项目文件(FTP)--------");

                #endregion
                ////同步GIS数据
                if (this.syncConfig.SyncGisData)
                {
                    LogOperation.WriteTitle(sbLog, "--------开始调用GIS服务--------");

                    foreach (var itemCode in itemCodes)
                    {
                        ////得到连接字符串
                        Gis_Data <Gis_Dk> gisdata = new BusiItemManage_Gis().GetNewGisInfo(itemCode, targetDb.ConnectionStr, false);

                        IGBXM <GBDK> gisEntity = new BusiItemManage_Gis().Conversion(gisdata);
                        gisEntity.Ccode = itemCode.Substring(0, 6);

                        string   wsUrl  = this.syncConfig.ServiceUrl;
                        string   method = this.syncConfig.ServiceMethod;
                        object[] args   = new object[1];
                        args[0] = JsonConvert.SerializeObject(gisEntity);
                        try
                        {
                            bool succ = (bool)WebServiceHelper.InvokeWebService(wsUrl, method, args);
                            if (!succ)
                            {
                                LogOperation.Append(sbLog, "服务返回失败:" + itemCode);
                            }
                        }
                        catch (Exception ex)
                        {
                            LogOperation.Append(sbLog, string.Format("异常  项目编号:{0}; 原因:{1}", itemCode, ex.Message));
                            continue;
                        }
                    }

                    LogOperation.WriteTitle(sbLog, "--------结束调用GIS服务--------");
                }
            }

            LogOperation.WriteTitle(sbLog, "-------------------------------------同步项目信息结束-------------------------------------");
        }