/// <summary>
        /// 导出用户签到数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool ExportUserSign(int id, string guid)
        {
            //time.Marke("46.执行 select distinct  openid  from   SignRecords where  ActivityID=@actID ", id.ToString());
            IEnumerable <string> openIdList = _signRecordsRepository
                                              .Query <string>("select distinct  openid  from   SignRecords where  ActivityID=@actID ", new { actID = id });

            //time.Marke("47.执行结束 select distinct  openid  from   SignRecords where  ActivityID=@actID ", id.ToString());
            if (openIdList == null || !openIdList.Any())
            {
                return(true);                                        //无人参加
            }
            int index = 0;
            List <UserSignActivity> userSignList = new List <UserSignActivity>();

            //time.Marke("48.判断是否包含这条用户签到数据", id.ToString());
            if (_userSignActRepositoryMongo.FirstOrDefault(UserSignActivity.GetId(openIdList.FirstOrDefault(), guid)) == null)
            {
                //time.Marke("49.结束判断是否包含这条用户签到数据", id.ToString());
                int cindex = 0;
                foreach (var openid in openIdList)
                {
                    cindex++;
                    #region  MultipQuery
                    ////time.Marke("50." + cindex + ".循环查询用户数据", id.ToString());
                    //List<IEnumerable<object>> queryList = _signPointActivityRepository.QueryMultiple(
                    //    "select  *   from   SignRecords where  ActivityID=@actID and Openid=@openId order by ID desc; " +
                    //    "select  *   from   SignSpecialRecords where  ActivityID=@actID and Openid=@openId; " +
                    //    "select  *   from   MemberSignatureCard where  ActivityID=@actID and Openid=@openId; " +
                    //    //"select  *   from   EventAwardRecords where  ActivityID=@actID and Openid=@openId and (ActivityType=@actType or ActivityType=@actSpecialType ",
                    //    "select  *   from   EventAwardRecords where  ActivityID=@actID and Openid=@openId and ActivityType=@actType union  select  *   from   EventAwardRecords where  ActivityID=@actID and Openid=@openId and ActivityType=@actSpecialType ",
                    //    new { actID = id, openId = openid, actType = 2, actSpecialType = 3 }, new Type[] { typeof(SignRecordsDto), typeof(SignSpecialRecordsDto), typeof(MemberSignatureCardDto), typeof(EventAwardRecordsDto) });
                    ////time.Marke("51." + cindex + ".循环查询用户数据", id.ToString());
                    ////time.Marke("52." + cindex + ".数据赋值", id.ToString());
                    //List<SignRecordsEntity> recordEntityList = GetUserRecords(queryList[0], guid);//时间先后倒叙排序,最新的在最前面
                    //List<SignSpecialRecordsEntity> specialRecordEntityList = GetUserSpecialRecords(queryList[1], guid);
                    //List<MemberSignatureCardEntity> cardEntityList = GetUserCardList(queryList[2], guid, id);
                    //List<EventAwardRecordsEntity> eventAwardEntityList = GetEventAwardList(guid, queryList[3]);
                    #endregion

                    #region SingleQuery
                    IEnumerable <SignRecordsDto> recordTempList = _signRecordsRepository
                                                                  .Query <SignRecordsDto>("select  *   from   SignRecords where  ActivityID=@actID and Openid=@openId order by ID desc", new { actID = id, openId = openid });
                    IEnumerable <SignSpecialRecordsDto> specialTempList = _signRecordsRepository
                                                                          .Query <SignSpecialRecordsDto>("select  *   from   SignSpecialRecords where  ActivityID=@actID and Openid=@openId", new { actID = id, openId = openid });
                    IEnumerable <MemberSignatureCardDto> cardTempList = _signRecordsRepository
                                                                        .Query <MemberSignatureCardDto>("select  *   from   MemberSignatureCard where  ActivityID=@actID and Openid=@openId", new { actID = id, openId = openid });
                    IEnumerable <EventAwardRecordsDto> awardTempList = _signRecordsRepository
                                                                       .Query <EventAwardRecordsDto>("select  *   from   EventAwardRecords where  ActivityID=@actID and Openid=@openId and ActivityType=@actType union  select  *   from   EventAwardRecords where  ActivityID=@actID and Openid=@openId and ActivityType=@actSpecialType ",
                                                                                                     new { actID = id, openId = openid, actType = 2, actSpecialType = 3 });
                    List <SignRecordsEntity>         recordEntityList        = GetUserRecords(recordTempList, guid);//时间先后倒叙排序,最新的在最前面
                    List <SignSpecialRecordsEntity>  specialRecordEntityList = GetUserSpecialRecords(specialTempList, guid);
                    List <MemberSignatureCardEntity> cardEntityList          = GetUserCardList(cardTempList, guid, id);
                    List <EventAwardRecordsEntity>   eventAwardEntityList    = GetEventAwardList(guid, awardTempList);
                    #endregion
                    UserSignActivity userSign = new UserSignActivity(openid, guid)
                    {
                        LastSignTime        = getLastSignTime(recordEntityList),
                        MaxTotalNumber      = recordEntityList.Max(t => t.TotalNumber),
                        SignRecords         = recordEntityList,
                        SignSpecialRecords  = specialRecordEntityList,
                        MemberSignatureCard = cardEntityList,
                        EventAwardRecords   = eventAwardEntityList
                    };
                    userSignList.Add(userSign);
                    //time.Marke("53." + cindex + ".数据赋值结束", id.ToString());
                    index++;
                    if (index >= 1000)
                    {
                        //time.Marke("54." + cindex + ".1000条插入mongodb开始", id.ToString());
                        _userSignActRepositoryMongo.InsertList(userSignList);
                        //time.Marke("55." + cindex + ".1000条插入mongodb结束", id.ToString());
                        index = 0;
                        //time.Marke("56." + cindex + ".清理列表开始", id.ToString());
                        userSignList.Clear();
                        //time.Marke("57." + cindex + ".清理列表结束", id.ToString());
                    }
                }
                //time.Marke("58.剩余的数据插入mongodb开始." + userSignList.Count, id.ToString());
                _userSignActRepositoryMongo.InsertList(userSignList);
                //time.Marke("59.剩余的数据插入mongodb结束." + userSignList.Count, id.ToString());
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#2
0
        public void IsSuccessfullyInsertData()
        {
            var actIdList = _signPointActivityRepository.Query <int>("select distinct top 1 id  from  SignPointActivity");
            var watch     = new Stopwatch();

            watch.Start();
            //数据库应该有数据
            actIdList.ShouldNotBeNull();
            //条目不为空
            actIdList.Any().ShouldBe(true);

            var node = actIdList.FirstOrDefault();
            var boo  = _actuatorAppService.ExportAct(node);

            boo.ShouldBe(true);
            //检测mongodb的字段
            List <IEnumerable <object> > queryList = _signPointActivityRepository.QueryMultiple(
                "select top 1 * from SignPointActivity where  ID=@id;select  * from   SignPointSet where  ActivityID=@id",
                new { id = node }, typeof(SignPointActivityDto), typeof(SignPointSetDto));
            SignPointActivityDto signAct = (SignPointActivityDto)queryList[0].FirstOrDefault();

            signAct.ShouldNotBeNull();
            List <SignPointSetDto> actSetList = new List <SignPointSetDto>();

            foreach (var item in queryList[1])
            {
                actSetList.Add((SignPointSetDto)item);
            }
            actSetList.Any().ShouldBe(true);

            SignActivity signMongo = _signActivityRepository.FirstOrDefault(x => x.Id == signAct.ActID.ToString());

            signMongo.ShouldNotBeNull();
            signMongo.Title.ShouldBe(signAct.Title);
            signMongo.BackGroundImg.ShouldBe(signAct.BackGroundImg);
            signMongo.BtnName.ShouldBe(signAct.BtnName);
            signMongo.BtnUrl.ShouldBe(signAct.BtnUrl);
            signMongo.BtnUrlName.ShouldBe(signAct.BtnUrlName);
            signMongo.CssStyle.ShouldBe(signAct.CssStyle);
            signMongo.FreeChance.ShouldBe(signAct.FreeChance);
            signMongo.RegistrationRemark.ShouldBe(signAct.RegistrationRemark);
            signMongo.Memberlogin.ShouldBe(signAct.Memberlogin);
            signMongo.SignPointSet.Count().ShouldBe(actSetList.Count());
            string timePattern = "yyyyMMdd";

            signMongo.BeginTime.ToString(timePattern).ShouldBe(signAct.BeginTime.ToString(timePattern));
            signMongo.EndTime.ToString(timePattern).ShouldBe(signAct.EndTime.ToString(timePattern));

            //检查奖项库存
            foreach (var item in signMongo.SignPointSet)
            {
                if (item.WxHbID > 0)//红包
                {
                    int    prizeType       = 0;
                    int    activityType    = item.IsSpecial == 0 ? 2 : 3;
                    string hbStockCountKey = string.Format(SignKeys.signactprizegrantnum_key, item.ID, prizeType);
                    hbStockCountKey = "B200016:" + hbStockCountKey;
                    int hbGrantCount = _eventAwardRecordsRepository.Count(" where MemberLogin=@Memberlogin and ActivityID=@ActID  and ActivityType=@ActivityType and (PrizeType=@PrizeType or  PrizeType=@PrizeType2 )  and AwardSetId = @AwardSetId",
                                                                          new { Memberlogin = item.Memberlogin, ActID = node, ActivityType = activityType, PrizeType = 5, PrizeType2 = 6, AwardSetId = item.ID });
                    int count = Convert.ToInt32(_redisHelper.StringGet(hbStockCountKey));
                    count.ShouldBe(hbGrantCount);
                }
                if (item.ProductID > 0)//产品
                {
                    int    prizeType            = 1;
                    int    activityType         = item.IsSpecial == 0 ? 2 : 3;
                    string productStockCountKey = string.Format(SignKeys.signactprizegrantnum_key, item.ID, prizeType);
                    productStockCountKey = "B200016:" + productStockCountKey;
                    int prizeTypeDB       = 0;
                    int productStockCount = _eventAwardRecordsRepository.Count("where MemberLogin=@Memberlogin and ActivityID=@ActID  and ActivityType=@ActivityType and PrizeType=@PrizeType  and AwardSetId = @AwardSetId",
                                                                               new { Memberlogin = item.Memberlogin, ActID = node, ActivityType = activityType, PrizeType = prizeTypeDB, AwardSetId = item.ID });
                    int count = Convert.ToInt32(_redisHelper.StringGet(productStockCountKey));
                    count.ShouldBe(productStockCount);
                }
            }


            //检查用户数据
            IEnumerable <string> openIdList = _signRecordsRepository
                                              .Query <string>("select distinct  openid  from   SignRecords where  ActivityID=@actID ",
                                                              new { actID = node });

            if (openIdList == null || !openIdList.Any())
            {
                return;                                         //无人参加
            }
            string openid = openIdList.FirstOrDefault();
            List <IEnumerable <object> > queryList2 = _signPointActivityRepository.QueryMultiple(
                "select  *   from   SignRecords where  ActivityID=@actID and Openid=@openId order by ID desc; " +
                "select  *   from   SignSpecialRecords where  ActivityID=@actID and Openid=@openId; " +
                "select  *   from   MemberSignatureCard where  ActivityID=@actID and Openid=@openId; " +
                //"select  *   from   EventAwardRecords where  ActivityID=@actID and Openid=@openId and (ActivityType=@actType or ActivityType=@actSpecialType ",
                "select  *   from   EventAwardRecords where  ActivityID=@actID and Openid=@openId and ActivityType=@actType union  select  *   from   EventAwardRecords where  ActivityID=@actID and Openid=@openId and ActivityType=@actSpecialType ",
                new { actID = node, openId = openid, actType = 2, actSpecialType = 3 }, new Type[] { typeof(SignRecordsDto), typeof(SignSpecialRecordsDto), typeof(MemberSignatureCardDto), typeof(EventAwardRecordsDto) });

            //签到记录
            UserSignActivity userSignMongo = _userSignActRepositoryMongo.FirstOrDefault(UserSignActivity.GetId(openid, signMongo.Id));

            userSignMongo.ShouldNotBeNull();
            if (queryList2[0].Any())
            {
                List <SignRecordsDto> records = new List <SignRecordsDto>();
                foreach (var item in queryList2[0])
                {
                    records.Add((SignRecordsDto)item);
                }
                userSignMongo.SignRecords.Count().ShouldBe(records.Count());
                var recordDB    = records.OrderBy(m => m.Addtime).FirstOrDefault();
                var recordMongo = userSignMongo.SignRecords.OrderBy(t => t.Addtime).FirstOrDefault();
                userSignMongo.Id.ShouldBe(UserSignActivity.GetId(openid, signMongo.Id));
                recordMongo.CustomerID.ShouldBe(recordDB.CustomerID);
                recordMongo.Day.ShouldBe(recordDB.Day);
                recordMongo.IsContinue.ShouldBe(recordDB.IsContinue);
                recordMongo.IsSignature.ShouldBe(recordDB.IsSignature);
                recordMongo.memberlogin.ShouldBe(recordDB.memberlogin);
            }
            //特殊
            if (queryList2[1].Any())
            {
                List <SignSpecialRecordsDto> specials = new List <SignSpecialRecordsDto>();
                foreach (var item in queryList2[1])
                {
                    specials.Add((SignSpecialRecordsDto)item);
                }
                userSignMongo.SignSpecialRecords.Count().ShouldBe(specials.Count);
                var recordDB    = specials.OrderBy(m => m.Addtime).FirstOrDefault();
                var recordMongo = userSignMongo.SignSpecialRecords.OrderBy(t => t.Addtime).FirstOrDefault();
                recordMongo.SpecialSDate.ShouldBe(recordDB.SpecialSDate);
                recordMongo.CustomerID.ShouldBe(recordDB.CustomerID);
            }
            //补签卡
            if (queryList2[2].Any())
            {
                List <MemberSignatureCardDto> cards = new List <MemberSignatureCardDto>();
                foreach (var item in queryList2[2])
                {
                    cards.Add((MemberSignatureCardDto)item);
                }
                userSignMongo.MemberSignatureCard.Count().ShouldBe(cards.Count());
                userSignMongo.MemberSignatureCard.Count(m => m.IsUse == 1).ShouldBe(cards.Count(m => m.IsUse == 1));
            }
            //奖项
            if (queryList2[3].Any())
            {
                List <EventAwardRecordsDto> awards = new List <EventAwardRecordsDto>();
                foreach (var item in queryList2[3])
                {
                    awards.Add((EventAwardRecordsDto)item);
                }
                userSignMongo.EventAwardRecords.Count().ShouldBe(awards.Count());
            }

            //检测完删掉mongodb的测试数据
            //   _signActivityRepository.Delete

            foreach (var user in openIdList)
            {
                _userSignActRepositoryMongo.Delete(UserSignActivity.GetId(user, signMongo.Id));
            }

            _signActivityRepository.Delete(signMongo.Id);


            watch.Stop();
            watch.ElapsedMilliseconds.ShouldBeLessThan(10000);
        }