Beispiel #1
0
        public void SynchroDataTo(Context ctx, SynchroDataType dataType, SynchroDirection direction)
        {
            HttpResponseResult result = null;

            try
            {
                if (direction == SynchroDirection.ToK3)
                {
                    result = SynchroDataHelper.SynchroDataToK3(ctx, dataType);
                }
                if (direction == SynchroDirection.ToHC)
                {
                    result = SynchroDataHelper.SynchroDataToHC(ctx, dataType);
                }
                if (result != null)
                {
                    if (result.Success)
                    {
                        this.View.ShowErrMessage("", string.Format("同步{0}至{1}成功!", LogUtils.GetDataSourceTypeDesc(dataType), direction.ToString()) + result.Message, Kingdee.BOS.Core.DynamicForm.MessageBoxType.Error);
                    }
                    else
                    {
                        this.View.ShowErrMessage("", string.Format("同步{0}至{1}失败!", LogUtils.GetDataSourceTypeDesc(dataType), direction.ToString()) + result.Message, Kingdee.BOS.Core.DynamicForm.MessageBoxType.Error);
                    }
                }
                else
                {
                    this.View.ShowErrMessage("", string.Format("同步{0}至{1}失败!", LogUtils.GetDataSourceTypeDesc(dataType), direction.ToString()), Kingdee.BOS.Core.DynamicForm.MessageBoxType.Error);
                }
            }
            catch (Exception ex)
            {
                this.View.ShowErrMessage(ex.ToString(), string.Format("同步{0}至{1}失败!", LogUtils.GetDataSourceTypeDesc(dataType), direction.ToString()), Kingdee.BOS.Core.DynamicForm.MessageBoxType.Error);
            }
        }
 private static HttpResponseResult DoSychro(AbstractSynchro absSyn, SynchroDirection direciton, Dictionary <SynOperationType, IEnumerable <AbsSynchroDataInfo> > dict = null, IEnumerable <AbsSynchroDataInfo> datas = null, IEnumerable <string> numbers = null, bool flag = true)
 {
     if (direciton == SynchroDirection.ToK3)
     {
         AbstractSynchroToK3 k3 = absSyn as AbstractSynchroToK3;
         return(k3.DoSynchroData(numbers, dict));
     }
     else
     {
         AbstractSynchroToHC hc = absSyn as AbstractSynchroToHC;
         return(hc.SynK3DataToWebSite(datas, numbers, flag));
     }
 }
        private static List <T> GetInstances <T>(List <Type> types, SynchroDirection direction)
        {
            if (types != null && types.Count > 0)
            {
                object proVal = null;

                foreach (var type in types)
                {
                    if (type != null)
                    {
                        proVal = GetPropertyValue <object>(type, "Direction");

                        if (proVal != null)
                        {
                            if (proVal.ToString().CompareTo(SynchroDirection.ToHC) == 0)
                            {
                                clsSynchroToHCType.Add(type);
                            }
                            else
                            {
                                clsSynchroToK3Type.Add(type);
                            }
                        }
                    }

                    if (proVal.ToString().CompareTo(SynchroDirection.ToHC) == 0)
                    {
                        return(clsSynchroToHCType as List <T>);
                    }
                    else
                    {
                        return(clsSynchroToK3Type as List <T>);
                    }
                }
            }

            return(null);
        }
Beispiel #4
0
        public static Dictionary <string, string> GetRedisSetKey(SynchroDataType dataType, SynchroDirection direct = default(SynchroDirection))
        {
            Dictionary <string, string> dict = new Dictionary <string, string>();

            switch (dataType)
            {
            case SynchroDataType.Customer:
                switch (direct)
                {
                case SynchroDirection.ToK3:
                    dict.Add(UnreadKey, "customers_unread");
                    dict.Add(InfoKey, "customers_info:");
                    dict.Add(AllKey, "customers_all");
                    return(dict);

                case SynchroDirection.ToHC:
                    dict.Add(UnreadKey, "K3Customers_unread");
                    dict.Add(InfoKey, "K3Customers_info:");
                    dict.Add(AllKey, "K3Customers_all");
                    return(dict);

                default:
                    return(null);
                }

            case SynchroDataType.CustomerAddress:
                dict.Add(UnreadKey, "b2b_address_unread");
                dict.Add(InfoKey, "b2b_address_info:");
                dict.Add(AllKey, "b2b_address_all");
                return(dict);

            case SynchroDataType.DelCustomerAddress:
                dict.Add(UnreadKey, "b2b_address_delete_unread");
                dict.Add(InfoKey, "b2b_address_delete_info:");
                dict.Add(AllKey, "b2b_address_delete_all");
                return(dict);

            case SynchroDataType.SaleOrder:
            case SynchroDataType.DropShippingSalOrder:
                switch (direct)
                {
                case SynchroDirection.ToK3:
                case SynchroDirection.ToB2B:
                    dict.Add(UnreadKey, "unread_orders");
                    dict.Add(InfoKey, "orders_info:");
                    dict.Add(AllKey, "all_orders");
                    return(dict);

                case SynchroDirection.ToHC:
                    dict.Add(UnreadKey, "Credit_unread");
                    dict.Add(InfoKey, "Credit_info:");
                    dict.Add(AllKey, "Credit_all");
                    return(dict);

                default:
                    return(null);
                }

            case SynchroDataType.SalesOrderPayStatus:
                dict.Add(UnreadKey, "orders_status_unread");
                dict.Add(InfoKey, "orders_status_info:");
                dict.Add(AllKey, "orders_status_all");
                return(dict);

            case SynchroDataType.DownLoadListInfo:
                dict.Add(UnreadKey, "unread_material_listid");
                dict.Add(InfoKey, "material_info:");
                dict.Add(AllKey, "all_material_listid");
                return(dict);

            case SynchroDataType.SynchroListInfo:
                dict.Add(UnreadKey, "MaterialListInfo_unread");
                dict.Add(InfoKey, "MaterialListInfo_info:");
                dict.Add(AllKey, "MaterialListInfo_all");
                return(dict);

            case SynchroDataType.ReceiveBill:
                dict.Add(UnreadKey, "Credit_unread");
                dict.Add(InfoKey, "Credit_info:");
                dict.Add(AllKey, "Credit_all");
                return(dict);

            case SynchroDataType.ReFundBill:
                dict.Add(UnreadKey, "Credit_unread");
                dict.Add(InfoKey, "Credit_info:");
                dict.Add(AllKey, "Credit_all");
                return(dict);

            case SynchroDataType.ImportLogis:
                dict.Add(UnreadKey, "CarriageNO_unread");
                dict.Add(InfoKey, "CarriageNO_info:");
                dict.Add(AllKey, "CarriageNO_all");
                return(dict);

            case SynchroDataType.Material:
                dict.Add(UnreadKey, "material_unread");
                dict.Add(InfoKey, "material_info:");
                dict.Add(AllKey, "material_all");
                return(dict);

            case SynchroDataType.Inventroy:
                dict.Add(UnreadKey, "inventories_Unread");
                dict.Add(InfoKey, "inventories_info:");
                dict.Add(AllKey, "inventories_All");
                return(dict);

            case SynchroDataType.SaleOrderOffline:
                switch (direct)
                {
                case SynchroDirection.Default:
                    dict.Add(UnreadKey, "Credit_unread");
                    dict.Add(InfoKey, "Credit_info:");
                    dict.Add(AllKey, "Credit_all");
                    return(dict);

                case SynchroDirection.ToHC:
                    dict.Add(UnreadKey, "offlineOrder_unread");
                    dict.Add(InfoKey, "offlineOrder_info:");
                    dict.Add(AllKey, "offlineOrder_all");
                    return(dict);

                default:
                    return(null);
                }

            case SynchroDataType.SaleOrderStatus:
                dict.Add(UnreadKey, "orderStatus_unread");
                dict.Add(InfoKey, "orderStatus_info:");
                dict.Add(AllKey, "orderStatus_all");
                return(dict);

            case SynchroDataType.BatchAdjust:
                dict.Add(UnreadKey, "BatchAdjust_unread");
                dict.Add(InfoKey, "BatchAdjust_info:");
                dict.Add(AllKey, "BatchAdjust_all");
                return(dict);

            case SynchroDataType.OnTheWay:
                switch (direct)
                {
                case SynchroDirection.ToHC:
                case SynchroDirection.ToB2B:
                    dict.Add(UnreadKey, "TransportationInventory_unread");
                    dict.Add(InfoKey, "TransportationInventory_info:");
                    dict.Add(AllKey, "TransportationInventory_all");
                    return(dict);

                default:
                    return(null);
                }

            case SynchroDataType.DeliveryNoticeBill:
                dict.Add(UnreadKey, "LogisticsTrajectory_unread");
                dict.Add(InfoKey, "LogisticsTrajectory_info:");
                dict.Add(AllKey, "LogisticsTrajectory_all");
                return(dict);

            case SynchroDataType.InStock:
                dict.Add(UnreadKey, "HomemarkReached_unread");
                dict.Add(InfoKey, "HomemarkReached_info:");
                dict.Add(AllKey, "HomemarkReached_all");
                return(dict);
            }
            return(null);
        }
Beispiel #5
0
        private const int ORGID = 100035;//使用组织

        /// <summary>
        /// 从Redis获取同步数据
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="dataType"></param>
        /// <param name="dbId"></param>
        /// <param name="numbers"></param>
        /// <returns></returns>
        public static List <AbsSynchroDataInfo> GetSynchroDatas(Context ctx, SynchroDataType dataType, long dbId, IEnumerable <string> numbers = null, SynchroDirection direction = SynchroDirection.ToK3)
        {
            List <AbsSynchroDataInfo> datas = null;
            RedisManager manager            = new RedisManager(ctx);
            IRedisClient redis = manager.GetClientEx(ctx, dbId);

            IEnumerable <string>        keys  = null;
            HashSet <string>            infos = null;
            Dictionary <string, string> dict  = null;

            if (redis != null)
            {
                dict = RedisKeyUtils.GetRedisSetKey(dataType, SynchroDirection.ToK3);

                if (numbers != null && numbers.Count() > 0)
                {
                    keys = numbers;
                }
                else
                {
                    if (dict != null && dict.Count > 0)
                    {
                        if (!string.IsNullOrEmpty(dict["unreadKey"]))
                        {
                            keys = manager.GetAllItemsFromSet(dict["unreadKey"], ctx, dbId);
                        }
                    }
                }

                if (keys != default(HashSet <string>) && keys.Count() > 0)
                {
                    infos = new HashSet <string>();

                    if (!string.IsNullOrEmpty(dict["infoKey"]))
                    {
                        foreach (var item in keys)
                        {
                            if (!string.IsNullOrWhiteSpace(item))
                            {
                                string info = dict["infoKey"] + item;

                                if (!string.IsNullOrEmpty(info))
                                {
                                    infos.Add(info.Trim());
                                }
                            }
                        }
                    }
                }

                datas = GetSynchroObjects(ctx, dataType, redis, infos, direction);

                redis.Dispose();
                redis = null;
            }

            return(datas);
        }
Beispiel #6
0
        /// <summary>
        /// 复制Redis正式库数据至测试库
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="dict"></param>
        /// <param name="keys"></param>
        /// <param name="dataType"></param>
        public static void BackupDataToRedis(Context ctx, Dictionary <string, string> dict, IEnumerable <string> keys, SynchroDataType dataType, SynchroDirection direction)
        {
            long backupRedisId = 0;

            try
            {
                Dictionary <string, string> redisKey = RedisKeyUtils.GetRedisSetKey(dataType, SynchroDirection.ToK3);

                switch (direction)
                {
                case SynchroDirection.ToK3:
                    backupRedisId = 1;
                    break;

                case SynchroDirection.ToB2B:
                    backupRedisId = 2;
                    break;

                default:
                    break;
                }

                if (DataBaseConst.CurrentRedisServerIp.CompareTo(DataBaseConst.HKRedisIP) == 0)
                {
                    RedisManager manager = new RedisManager(ctx);
                    Thread       subTh   = new Thread(new ThreadStart(() =>
                    {
                        using (IRedisClient redis = manager.GetClientTest(ctx, backupRedisId))
                        {
                            if (redis != null)
                            {
                                if (dict != null && dict.Count > 0)
                                {
                                    redis.SetAll(dict);

                                    if (keys != null && keys.Count() > 0)
                                    {
                                        if (!string.IsNullOrWhiteSpace(redisKey["unreadKey"]) && !string.IsNullOrWhiteSpace(redis["allKey"]))
                                        {
                                            if (GetItems(keys) != null && GetItems(keys).Count > 0)
                                            {
                                                redis.AddRangeToSet(redisKey["unreadKey"], GetItems(keys));
                                                redis.AddRangeToSet(redis["allKey"], GetItems(keys));
                                            }
                                        }
                                    }
                                }

                                redis.Dispose();
                            }
                        }
                    }

                                                                      ));
                    subTh.IsBackground = true;
                    subTh.Start();
                }
            }
            catch (Exception ex)
            {
                LogUtils.WriteSynchroLog(ctx, SynchroDataType.Redis, ex.Message + System.Environment.NewLine + ex.StackTrace);
            }
        }
Beispiel #7
0
        /// <summary>
        /// 从Redis获取同步数据
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="dataType"></param>
        /// <param name="redis"></param>
        /// <param name="redisKeys"></param>
        /// <returns></returns>
        private static List <AbsSynchroDataInfo> GetSynchroObjects(Context ctx, SynchroDataType dataType, IRedisClient redis, IEnumerable <string> redisKeys, SynchroDirection direction = SynchroDirection.ToK3)
        {
            List <AbsSynchroDataInfo> datas = null;
            List <string>             jsons = null;

            Dictionary <string, string> dict = null;

            if (redis != null)
            {
                if (redisKeys != null && redisKeys.Count() > 0)
                {
                    dict  = new Dictionary <string, string>();
                    jsons = new List <string>();

                    foreach (var item in redisKeys)
                    {
                        if (!string.IsNullOrWhiteSpace(item))
                        {
                            string json = redis.Get <string>(item.ToString());

                            if (!string.IsNullOrWhiteSpace(json))
                            {
                                BackupJson.WriteJsonToLocal(ctx, dataType, json);
                                jsons.Add(json);
                                dict.Add(item.ToString(), JsonUtils.ReplaceDoubleQuotes(json));
                            }
                        }
                    }

                    BackupDataToRedis(ctx, dict, redisKeys, dataType, direction);
                }
            }

            if (jsons != null && jsons.Count > 0)
            {
                datas = new List <AbsSynchroDataInfo>();

                foreach (var json in jsons)
                {
                    if (json.IsNullOrEmptyOrWhiteSpace() || json.EqualsIgnoreCase("None"))
                    {
                        continue;
                    }
                    try
                    {
                        AbsSynchroDataInfo data = SynchroDataHelper.BuildSynchroData(ctx, dataType, json);

                        if (data != null)
                        {
                            datas.Add(data);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogUtils.WriteSynchroLog(ctx, dataType,
                                                 "下载" + dataType + "出现异常" +
                                                 ex.Message + System.Environment.NewLine + ex.StackTrace);
                    }
                }
            }

            return(datas);
        }
        public static HttpResponseResult SynK3DataToWebSite(Context ctx, SynchroDataType DataType, SynchroDirection Direction, long RedisDbId, IEnumerable <AbsSynchroDataInfo> k3Datas = null, IEnumerable <string> billNos = null, bool SQLFilter = true, bool IsSynchroB2B = false)
        {
            HttpResponseResult               result = null;
            Dictionary <string, string>      dict   = null;
            IEnumerable <AbsSynchroDataInfo> datas  = null;
            List <string>     keys      = null;
            bool              IsSuccess = false;
            IRedisTransaction trans     = null;

            lock (oLock)
            {
                RedisManager redis = new RedisManager(ctx);

                try
                {
                    if (datas != null && datas.Count() > 0)
                    {
                        dict = new Dictionary <string, string>();
                        keys = new List <string>();

                        var group = from d in datas
                                    group d by d.SrcNo into g
                                    select g;

                        if (group != null && group.Count() > 0)
                        {
                            foreach (var g in group)
                            {
                                if (g != null && g.ToList().Count > 0)
                                {
                                    keys.Add(g.Key);
                                    string infoKey = RedisUnreadkey(DataType, Direction) + g.Key;
                                    dict.Add(infoKey, JsonUtils.SerializeObject <IEnumerable <AbsSynchroDataInfo> >(ctx, g.ToList()));
                                }
                            }

                            if (dict.Count > 0)
                            {
                                IRedisClient client = redis.GetClientEx(ctx, RedisDbId);

                                if (IsConnectSuccess(client))
                                {
                                    using (trans = redis.GetClientEx(ctx, RedisDbId).CreateTransaction())
                                    {
                                        trans.QueueCommand(r => r.AddRangeToSet(GetRedisAllKey(DataType, Direction), keys));
                                        trans.QueueCommand(r => r.AddRangeToSet(RedisUnreadkey(DataType, Direction), keys));
                                        trans.QueueCommand(r => r.SetAll(dict));

                                        IsSuccess = trans.Commit();
                                    }
                                    if (IsSuccess)
                                    {
                                        foreach (var d in dict)
                                        {
                                            LogHelper.WriteSynchroDataLog(ctx, DataType, redis.GetClient(ctx, RedisDbId), d.Key, d.Value);
                                        }

                                        LogHelper.WriteSynchroLog_Succ(ctx, DataType, "【" + DataType + "】同步,单据编码" + FormatNumber(datas) + "信息成功同步到Redis");
                                        result         = new HttpResponseResult();
                                        result.Success = true;
                                        result.Message = "【" + DataType + "】同步成功!";
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        result         = new HttpResponseResult();
                        result.Success = false;
                        result.Message = "没有需要同步的数据";

                        LogUtils.WriteSynchroLog(ctx, DataType, result.Message);
                    }
                }
                catch (Exception ex)
                {
                    LogUtils.WriteSynchroLog(ctx, DataType, "【" + DataType + "】同步过程中出现异常,异常信息:" + ex.Message + System.Environment.NewLine + ex.StackTrace);

                    result         = new HttpResponseResult();
                    result.Success = false;
                    result.Message = "【" + DataType + "】出现异常,异常信息:" + System.Environment.NewLine + ex.Message;
                }
            }

            return(result);
        }
 /// <summary>
 /// Redis string类型的具体数据
 /// </summary>
 public static string RedisInfoKey(SynchroDataType DataType, SynchroDirection Direction)
 {
     return(RedisKeyUtils.GetRedisSetKey(DataType, Direction)["infoKey"]);
 }
Beispiel #10
0
 /// <summary>
 /// Redis未读的Set类型的key
 /// </summary>taType, SynchroDirection
 public static string RedisUnreadkey(SynchroDataType DataType, SynchroDirection Direction)
 {
     return(RedisKeyUtils.GetRedisSetKey(DataType, Direction)["unreadKey"]);
 }
Beispiel #11
0
        /// <summary>
        /// 删除Redis数据库中的数据
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="numbers"></param>
        /// <param name="dataType"></param>
        public static void RemoveRedisData(Context ctx, IEnumerable <string> numbers, SynchroDirection direction, long RedisDbId, SynchroDataType dataType = SynchroDataType.None)
        {
            if (true /*K3LoginInfo.GetRedisServerIp(ctx).CompareTo(DataBaseConst.RedisServerIP) == 0*/)
            {
                List <string> infoKeys = null;
                RedisManager  manager  = new RedisManager(ctx);

                if (numbers != null && numbers.Count() > 0)
                {
                    infoKeys = new List <string>();

                    foreach (var num in numbers)
                    {
                        if (!string.IsNullOrWhiteSpace(num))
                        {
                            if (dataType.CompareTo(SynchroDataType.None) == 0)
                            {
                                infoKeys.Add(RedisInfoKey(dataType, direction) + num);
                                manager.RemoveItemFromSet(ctx, RedisUnreadkey(dataType, direction), num, RedisDbId);
                            }
                            else
                            {
                                infoKeys.Add(RedisInfoKey(dataType, direction) + num);
                                manager.RemoveItemFromSet(ctx, RedisUnreadkey(dataType, direction), num, RedisDbId);
                            }
                        }
                    }

                    if (DataBaseConst.CurrentRedisServerIp.CompareTo(DataBaseConst.HKRedisIP) == 0)
                    {
                        manager.RemoveAll(ctx, infoKeys, RedisDbId);
                    }

                    manager = null;
                }
            }
        }
        /// <summary>
        /// 动态创建同步至K3或HC的实现类
        /// </summary>
        private static List <T> GetSynchroClsInstance_1 <T>(Assembly assembly, Type type, SynchroDataType dataType, SynchroDirection direction)
        {
            lock (synchroLock)
            {
                List <Type> types = CreateSynchroInstance <Type>(assembly, type, dataType);

                if (direction.ToString().Equals(SynchroDirection.ToHC))
                {
                    if (clsSynchroToHCType.Count > 0)
                    {
                        return(clsSynchroToHCType as List <T>);
                    }
                    else
                    {
                        return(GetInstances <T>(types, SynchroDirection.ToHC));
                    }
                }
                else
                {
                    if (clsSynchroToK3Type.Count > 0)
                    {
                        return(clsSynchroToK3Type as List <T>);
                    }
                    else
                    {
                        return(GetInstances <T>(types, SynchroDirection.ToK3));
                    }
                }
            }
        }
        private static HttpResponseResult SynchroDataTo(Context ctx, AbstractSynchro absSyn, SynchroDataType dataType, SynchroDirection direction, DoSchroData doSchroData, Dictionary <SynOperationType, IEnumerable <AbsSynchroDataInfo> > dict = null, IEnumerable <AbsSynchroDataInfo> datas = null, IEnumerable <string> numbers = null, bool flag = true)
        {
            HttpResponseResult result = null;

            if (absSyn == null)
            {
                result         = new HttpResponseResult();
                result.Success = false;
                result.Message = "没有找到【" + dataType + "】同步类的实例!!!";

                return(result);
            }

            var token = GetSeeedSystemProfile(ctx, "");

            if (token.IsNullOrEmptyOrWhiteSpace())
            {
                token = "";
            }

            string url = GetWebAppRootUrl(ctx);

            absSyn.K3CloudContext = ctx;


            if (absSyn.K3CloudContext != null)
            {
                if (absSyn.K3CloudContext.DBId.CompareTo(DataBaseConst.K3CloudDbId) == 0)
                {
                    absSyn.RedisDbId = DataBaseConst.HKRedisDbId;
                }
                else
                {
                    absSyn.RedisDbId = DataBaseConst.ALRedisDbId;
                }
            }

            return(doSchroData(absSyn, direction, dict, datas, numbers, flag));
        }
        /// <summary>
        /// 同步数据至HC网站
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="dataType"></param>
        /// <param name="datas"></param>
        /// <param name="billNos"></param>
        /// <returns></returns>
        public static HttpResponseResult SynchroDataToHC(Context ctx, SynchroDataType dataType, IEnumerable <AbsSynchroDataInfo> datas = null, IEnumerable <string> billNos = null, bool SQLFilter = true, SynchroDirection direction = SynchroDirection.ToHC)
        {
            List <AbstractSynchroToHC> svc    = new List <AbstractSynchroToHC>();
            HttpResponseResult         result = null;

            lock (HCLock)
            {
                svc = GetSynchroClsInstance <AbstractSynchroToHC>(assembly, typeof(AbstractSynchroToHC), dataType);
            }

            if (svc == null || svc.Count == 0)
            {
                result         = new HttpResponseResult();
                result.Success = false;
                result.Message = "没有找到【" + dataType + "】同步类的实例!!!";
                return(result);
            }

            if (svc != null && svc.Count > 0)
            {
                foreach (var item in svc)
                {
                    item.K3CloudContext          = ctx;
                    DataBaseConst.K3CloudContext = ctx;

                    if (item.K3CloudContext != null)
                    {
                        if (item.K3CloudContext.DBId.CompareTo(DataBaseConst.K3CloudDbId) == 0)
                        {
                            if (direction != SynchroDirection.ToHC)
                            {
                                if (direction == SynchroDirection.ToB2B)
                                {
                                    item.RedisDbId = DataBaseConst.HKRedisDbId_B2B;
                                }
                                else
                                {
                                    item.RedisDbId = DataBaseConst.HKRedisDbId;
                                }
                            }
                            else
                            {
                                if (item.Direction == SynchroDirection.ToB2B)
                                {
                                    item.RedisDbId = DataBaseConst.HKRedisDbId_B2B;
                                }
                                else
                                {
                                    item.RedisDbId = DataBaseConst.HKRedisDbId;
                                }
                            }
                        }
                        else
                        {
                            if (direction != SynchroDirection.ToHC)
                            {
                                if (direction == SynchroDirection.ToB2B)
                                {
                                    item.RedisDbId = DataBaseConst.ALRedisDbId_B2B;
                                }
                                else
                                {
                                    item.RedisDbId = DataBaseConst.ALRedisDbId;
                                }
                            }
                            else
                            {
                                if (item.Direction == SynchroDirection.ToB2B)
                                {
                                    item.RedisDbId = DataBaseConst.ALRedisDbId_B2B;
                                }
                                else
                                {
                                    item.RedisDbId = DataBaseConst.ALRedisDbId;
                                }
                            }
                        }
                    }

                    result = item.SynchroDataToHC(datas, billNos, SQLFilter, direction);
                }
            }

            return(result);

            //List<AbstractSynchroToHC> types = GetSynchroClsInstance_1<AbstractSynchroToHC>(assembly, typeof(AbstractSynchroToHC), dataType, SynchroDirection.ToK3);

            //if (types != null && types.Count > 0)
            //{
            //    DoSchroData doSchro = new DoSchroData(DoSychro);
            //    return SynchroDataTo(ctx, types.FirstOrDefault(), dataType, SynchroDirection.ToHC, doSchro, null, datas, null, true);
            //}
            //return null;
        }
Beispiel #15
0
        /// <summary>
        /// 同步K3数据至HC网站
        /// </summary>
        /// <param name="k3Datas"></param>
        /// <param name="billNos"></param>
        /// <returns></returns>
        public virtual HttpResponseResult SynK3DataToWebSite(IEnumerable <AbsSynchroDataInfo> k3Datas = null, IEnumerable <string> billNos = null, bool SQLFilter = true, SynchroDirection direction = SynchroDirection.Default)
        {
            HttpResponseResult               result = null;
            Dictionary <string, string>      dict   = null;
            IEnumerable <AbsSynchroDataInfo> datas  = null;
            List <string>     SynBillNos            = null;
            bool              IsSuccess             = false;
            IRedisTransaction trans = null;

            lock (oLock)
            {
                if (k3Datas == null)
                {
                    datas = GetK3Datas(billNos, SQLFilter);
                }
                else
                {
                    datas = k3Datas;
                }
                try
                {
                    Dictionary <string, string> redisKeys = RedisKeyUtils.GetRedisSetKey(this.DataType, this.Direction);
                    string allKey    = redisKeys["allKey"];
                    string unreadKey = redisKeys["unreadKey"];

                    Dictionary <string, string> synFailDatas = GetSynchroFailureDatas();
                    List <string> failBillNos  = null;
                    List <string> failInfoKeys = null;

                    trans = RedisClient.CreateTransaction();


                    if (synFailDatas != null && synFailDatas.Count > 0)
                    {
                        failBillNos  = GetSychroFailureBillNos(synFailDatas);
                        failInfoKeys = GetSynchroFailureInfoKeys(synFailDatas);

                        trans.QueueCommand(r => r.AddRangeToSet(allKey, failBillNos));
                        trans.QueueCommand(r => r.AddRangeToSet(unreadKey, failBillNos));
                        trans.QueueCommand(r => r.SetAll(synFailDatas));

                        IsSuccess = trans.Commit();
                        trans.Dispose();

                        if (IsSuccess)
                        {
                            UpdateSynchroDataLog(failInfoKeys);
                        }
                    }
                    if (datas != null && datas.Count() > 0)
                    {
                        dict       = new Dictionary <string, string>();
                        SynBillNos = new List <string>();

                        var group = from d in datas
                                    group d by d.SrcNo into g
                                    select g;

                        if (group != null && group.Count() > 0)
                        {
                            foreach (var g in group)
                            {
                                if (g != null && g.ToList().Count > 0)
                                {
                                    SynBillNos.Add(g.Key);
                                    string infoKey = RedisKeyUtils.GetRedisSetKey(this.DataType, this.Direction)["infoKey"] + g.Key;
                                    dict.Add(infoKey, JsonUtils.SerializeObject <IEnumerable <AbsSynchroDataInfo> >(this.K3CloudContext, g.ToList()));
                                }
                            }

                            if (IsConnectSuccess())
                            {
                                if (dict.Count > 0)
                                {
                                    trans = RedisClient.CreateTransaction();
                                    trans.QueueCommand(r => r.AddRangeToSet(allKey, SynBillNos));
                                    trans.QueueCommand(r => r.AddRangeToSet(unreadKey, SynBillNos));
                                    trans.QueueCommand(r => r.SetAll(dict));

                                    IsSuccess = trans.Commit();
                                    trans.Dispose();

                                    if (IsSuccess)
                                    {
                                        UpdateAfterSynchro(datas, true);
                                        LogHelper.WriteSynchroDataLog(this.K3CloudContext, this.DataType, RedisClient, dict, true);

                                        string msg = "【" + this.DataType + "】同步,单据编码" + FormatNumber(datas) + "信息成功同步到Redis";
                                        LogHelper.WriteSynchroLog_Succ(this.K3CloudContext, this.DataType, msg);

                                        result         = new HttpResponseResult();
                                        result.Success = true;
                                        result.Message = msg;
                                    }
                                    else
                                    {
                                        LogHelper.WriteSynchroDataLog(this.K3CloudContext, this.DataType, RedisClient, dict, false);

                                        string msg = "【" + this.DataType + "】同步,单据编码" + FormatNumber(datas) + "信息同步到Redis失败";
                                        LogUtils.WriteSynchroLog(this.K3CloudContext, this.DataType, msg);

                                        result         = new HttpResponseResult();
                                        result.Success = false;
                                        result.Message = msg;
                                    }
                                }
                            }
                            else
                            {
                                LogHelper.WriteSynchroDataLog(this.K3CloudContext, this.DataType, RedisClient, dict, false);
                            }
                        }
                    }
                    else
                    {
                        result         = new HttpResponseResult();
                        result.Success = false;
                        result.Message = "没有需要同步的数据";

                        LogUtils.WriteSynchroLog(this.K3CloudContext, this.DataType, result.Message);
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteSynchroDataLog(this.K3CloudContext, this.DataType, RedisClient, dict, false);
                    string msg = "【" + this.DataType + "】同步过程中出现异常,异常信息:" + ex.Message + System.Environment.NewLine + ex.StackTrace;
                    LogUtils.WriteSynchroLog(this.K3CloudContext, this.DataType, msg);

                    result         = new HttpResponseResult();
                    result.Success = false;
                    result.Message = msg;
                    UpdateAfterSynchro(datas, false);
                }
                finally
                {
                    if (trans != null)
                    {
                        trans.Dispose();
                    }
                }
            }

            return(result);
        }
Beispiel #16
0
 /// <summary>
 /// 同步K3数据至HC网站(用于定时任务)
 /// </summary>
 /// <param name="k3Datas"></param>
 /// <param name="billNos"></param>
 /// <returns></returns>
 public virtual HttpResponseResult SynchroDataToHC(IEnumerable <AbsSynchroDataInfo> k3Datas = null, IEnumerable <string> billNos = null, bool SQLFilter = true, SynchroDirection direction = SynchroDirection.Default)
 {
     return(SynK3DataToWebSite(k3Datas, billNos, SQLFilter, direction));
 }