Пример #1
0
        /// <summary>
        /// 城市
        /// </summary>
        /// <param name="code"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Sys_AreaInfoModel AddCityCode(string code, string name)
        {
            var city      = new Sys_AreaInfoModel();
            var oldList   = new Sys_AreaInfoAccess2().Query().Where(x => x.type == 3).ToList();
            var modellist = new List <Sys_AreaMatchModel>();
            var matchDb   = new Sys_AreaMatchAccess();
            var cityMatch = matchDb.Query().Where(x => x.OutType == 2 && x.OutCityCode == code).FirstOrDefault();

            if (cityMatch == null || cityMatch.Id <= 0)
            {
                city      = oldList.FirstOrDefault(x => x.name == name);
                cityMatch = new Sys_AreaMatchModel
                {
                    OutCityCode = code,
                    OutCityName = name,
                    OutType     = 2,
                    HbId        = city?.id ?? 0
                };
                matchDb.Add(cityMatch);
            }
            else
            {
                city = oldList.FirstOrDefault(x => x.id == cityMatch.HbId);
            }
            return(city);
        }
Пример #2
0
        //库存 baoku/hotel/getRoomInventoryList、

        #region 城市匹配


        /// <summary>
        /// 获取城市列表
        /// </summary>
        /// <returns></returns>

        public static DataResult GetCityList()
        {
            var result = new DataResult();
            var url    = AtourSignUtil.AtourAuth_URL + "city/getCityList";
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("appId", AtourSignUtil.AtourAuth_APPID);
            var sign     = AtourSignUtil.GetSignUtil(dic);
            var citylist = ApiHelper.HttpGet(url + "?appId=" + AtourSignUtil.AtourAuth_APPID + "&sign=" + sign);

            if (string.IsNullOrWhiteSpace(citylist))
            {
                result = new DataResult {
                    Code = DataResultType.Fail, Message = "系统异常"
                };
            }

            var oldList   = new Sys_AreaInfoAccess2().Query().Where(x => x.type == 3).ToList();
            var modellist = new List <Sys_AreaMatchModel>();
            var data      = citylist.ToObject <AtourCityResponse>();

            data?.result?.ForEach(n =>
            {
                var old   = oldList.FirstOrDefault(x => x.name == n.cityName.Replace("市", ""));
                var model = new Sys_AreaMatchModel
                {
                    OutProvId   = 0,
                    OutProvName = n.provinceName,
                    OutCityId   = n.cityId,
                    OutCityName = n.cityName,
                    HbId        = old?.id ?? 0,
                    OutType     = 1
                };
                var db = new Sys_AreaMatchAccess();
                var m  = db.Query().Where(x => x.OutType == 1 && x.OutCityId == n.cityId).FirstOrDefault();
                if (m == null || m.Id <= 0)
                {
                    db.Add(model);
                    result.Data += $"{old?.id}:{n.cityName};";
                }
                else
                {
                }
            });

            return(result);
        }
Пример #3
0
        /// <summary>
        /// 酒店详情
        /// </summary>
        /// <param name="maxId"></param>
        /// <param name="top"></param>
        /// <returns></returns>
        public static DataResult GetHotelDetail(int maxId, int top)
        {
            var result = new DataResult();

            var hDb       = new H_HotelInfoAccess();
            var hotelList = hDb.Query().Where(h => h.Id >= maxId && h.HIOutType == 2).Top(top).OrderBy(h => h.HIOutId)?.ToList();

            if (hotelList == null || hotelList.Count == 0)
            {
                result.Message = "无数据";
                return(result);
            }
            var provList = new Sys_AreaInfoAccess2().Query().Where(x => x.type == 2).ToList();
            var msgList  = new List <string>();

            Parallel.ForEach(hotelList, new ParallelOptions()
            {
                MaxDegreeOfParallelism = 3
            }, (x, loopstate) =>
            {
                try
                {
                    var request = new XiWanHotelDetailRequest {
                        HotelId = x.HIOutId
                    };
                    var rtn   = XiWanAPI.XiWanPost <XiWanHotelDetail, XiWanHotelDetailRequest>(request, HotelDetailUrl);
                    var hotel = rtn?.Result;
                    if (hotel?.HotelId > 0)
                    {
                        var city = AddCityCode(hotel.CityCode, hotel.CityName) ?? new Sys_AreaInfoModel();
                        var prov = new Sys_AreaInfoModel();
                        if (city.pid > 0)
                        {
                            prov = provList.FirstOrDefault(p => p.id == city.pid) ?? new Sys_AreaInfoModel();
                        }
                        hDb.Update().Set(h =>
                                         h.HIGdLonLat == hotel.Position &&
                                         h.HIName == hotel.HotelName &&
                                         h.HIHotelIntroduction == hotel.Intro &&
                                         h.HIAddress == hotel.Address &&
                                         h.HILinkPhone == hotel.Tel &&
                                         h.HICityId == city.id &&
                                         h.HICity == (city.name ?? string.Empty) &&
                                         h.HIProvinceId == prov.id &&
                                         h.HIProvince == (prov.name ?? string.Empty) &&
                                         h.HIUpdateName == "喜玩详情接口更新" &&
                                         h.HIUpdateTime == DateTime.Now
                                         ).Where(h => h.Id == x.Id).Execute();
                        //会员 暂时未开发
                        logDb.AddLog(x.Id, $"喜玩详情接口更新:{hotel.HotelId}:{hotel.HotelName}", ResourceLogType.HotelUpdate);
                    }
                    else
                    {
                        msgList.Add(rtn?.Msg ?? "系统异常");
                    }

                    //房型等
                    var d1 = Xw_HotelPrice(x.Id);
                    msgList.Add($"||{x.Id}:{d1.Message}");
                    Thread.Sleep(10);
                }
                catch (Exception ex)
                {
                    var log = $"{ex.Message}--{x.Id}---{ex.ToString()}";
                    LogHelper.Error(log);
                }
            });
            result.Data = msgList;
            return(result);
        }