Пример #1
0
        public void ShouldParsePageInfoSuccess(int pageIndex, int pageSize, int offset, int limit)
        {
            var limitInfo = LimitInfo.FromPageInfo(pageIndex, pageSize);

            Assert.AreEqual(offset, limitInfo.Offset);
            Assert.AreEqual(limit, limitInfo.Limit);
        }
Пример #2
0
        private LimitInfo CalculateLimitInfo(IEnumerable <Operation> filteredOperations, DateTime date, double limit, string limitName, CurrencyName currency)
        {
            var totalExpense          = filteredOperations.Sum(x => x.Amount);
            var actualSpeed           = Normalize(filteredOperations).GroupBy(x => x.Date.Day).Average(group => group.Sum(operation => operation.Amount));
            var prognosedTotalExpense = actualSpeed * DateTime.DaysInMonth(date.Year, date.Month);
            var prognosedPercentage   = prognosedTotalExpense * 100 / limit;

            var limitInfo = new LimitInfo();

            limitInfo.Limit       = limit;
            limitInfo.AmountSpent = Math.Round(totalExpense, 2);
            limitInfo.Speed       = Math.Round(actualSpeed, 2);
            limitInfo.Percentage  = Math.Round(totalExpense * 100 / limit, 2);
            limitInfo.Currency    = currency;
            limitInfo.Name        = limitName;
            limitInfo.RunOutDays  = Math.Round((limit - totalExpense) / actualSpeed, 0);

            if (prognosedPercentage <= 70)
            {
                limitInfo.SpeedDanger = SpeedDangerLevel.Green;
            }
            else if (prognosedPercentage > 70 && prognosedPercentage <= 90)
            {
                limitInfo.SpeedDanger = SpeedDangerLevel.Orange;
            }
            else
            {
                limitInfo.SpeedDanger = SpeedDangerLevel.Red;
            }

            return(limitInfo);
        }
        public async Task <LimitInfo> Save(SimpleUser user, LimitInfo li)
        {
            var old = await Context.LimitInfos.Where(x => x.UserId == li.UserId).FirstOrDefaultAsync();

            if (old != null)
            {
                old.IsDeleted  = li.IsDeleted;
                old.Amount     = li.Amount;
                old.Memo       = li.Memo;
                old.LimitType  = li.LimitType;
                old.UpdateTime = DateTime.Now;
                old.UpdateUser = user.Id;
            }
            else
            {
                //新增
                li.CreateTime = DateTime.Now;
                li.CreateUser = user.Id;
                Context.LimitInfos.Add(li);
            }

            await Context.SaveChangesAsync();

            return(li);
        }
Пример #4
0
        public void ShouldParseSuccess(string limitStr, int offset, int limit)
        {
            var limitInfo = LimitInfo.Parse(limitStr);

            Assert.AreEqual(offset, limitInfo.Offset);
            Assert.AreEqual(limit, limitInfo.Limit);
        }
Пример #5
0
        public async Task <ResponseMessage <LimitInfoResponse> > Save(UserInfo user, LimitInfoRequest request)
        {
            ResponseMessage <LimitInfoResponse> r = new ResponseMessage <LimitInfoResponse>();

            HumanInfo ui = await _Store.GetUserInfo(request.UserId);

            if (ui == null)
            {
                r.Code    = "404";
                r.Message = "人员不存在";
                return(r);
            }

            await checkPermission(r, user.Id, PERMISSION_BXXE, ui.DepartmentId);

            if (!r.IsSuccess())
            {
                return(r);
            }

            LimitInfo li = await _Store.Save(_mapper.Map <SimpleUser>(user), _mapper.Map <LimitInfo>(request));

            r.Extension = _mapper.Map <LimitInfoResponse>(li);

            return(r);
        }
Пример #6
0
        /// <summary>
        /// 根据参数查询权限信息
        /// </summary>
        /// <param name="info">权限信息对象</param>
        /// <returns>权限信息集合</returns>
        public List <LimitInfo> SelectWithParameter(LimitInfo info)
        {
            project data = new project();

            data.Type        = "1";
            data.Search_type = "6";
            return(getData(data));
        }
Пример #7
0
        private GuildPrivateGoods LoadGuildPrivateGoodsFromXml(SecurityElement element)
        {
            GuildPrivateGoods goods = new GuildPrivateGoods {
                GoodsId                = StrParser.ParseHexInt(element.Attribute("Id"), 0),
                GoodsName              = StrParser.ParseStr(element.Attribute("Name"), ""),
                GoodsIconId            = StrParser.ParseHexInt(element.Attribute("IconId"), 0),
                GoodsDesc              = StrParser.ParseStr(element.Attribute("Desc"), ""),
                OpenTime               = StrParser.ParseDateTime(element.Attribute("StartTime")),
                CloseTime              = StrParser.ParseDateTime(element.Attribute("EndTime")),
                ResetType              = TypeNameContainer <_TimeDurationType> .Parse(element.Attribute("ResetType"), 0),
                BuyLimitCountPerCircle = StrParser.ParseDecInt(element.Attribute("BuyLimitCountPerCircle"), 0),
                BatchPurchase          = StrParser.ParseBool(element.Attribute("BatchPurchase"), false),
                ShowIndex              = StrParser.ParseDecInt(element.Attribute("ShowIndex"), 0)
            };

            if (element.Children != null)
            {
                foreach (SecurityElement element2 in element.Children)
                {
                    string tag = element2.Tag;
                    if (tag != null)
                    {
                        if (tag == "CostInfo")
                        {
                            CostInfo item = new CostInfo {
                                BuyCount = StrParser.ParseDecInt(element2.Attribute("BuyCount"), 0)
                            };
                            if (element2.Children != null)
                            {
                                foreach (SecurityElement element3 in element2.Children)
                                {
                                    if (element3.Tag == "Cost")
                                    {
                                        item.Costs.Add(Cost.LoadFromXml(element3));
                                    }
                                }
                            }
                            goods.Costinfos.Add(item);
                        }
                        else if (tag == "Reward")
                        {
                            goods.Rewards.Add(Reward.LoadFromXml(element2));
                        }
                        else if (tag == "Limit")
                        {
                            LimitInfo info2 = new LimitInfo {
                                LimitType  = TypeNameContainer <_LimitType> .Parse(element2.Attribute("Type"), 0),
                                LimitValue = StrParser.ParseDecInt(element2.Attribute("Value"), 0)
                            };
                            goods.LimitInfos.Add(info2);
                        }
                    }
                }
            }
            return(goods);
        }
Пример #8
0
        public static LimitData <T> ToLimitData <T>(this IQueryable <T> source, LimitInfo limitInfo)
        {
            _ = limitInfo ?? throw new ArgumentNullException(nameof(limitInfo));
            var limit         = limitInfo.Limit;
            var offset        = limitInfo.Offset;
            var totalCount    = source.Count();
            var limitListData = source.Skip(offset).Take(limit).ToList();

            return(new LimitData <T>(limitListData, offset, limit, totalCount));
        }
Пример #9
0
        public void ShouldConvertToStringSuccess()
        {
            TypeConverter typeConverter = TypeDescriptor.GetConverter(typeof(LimitInfo));
            var           canToString   = typeConverter.CanConvertTo(typeof(string));

            Assert.AreEqual(true, canToString);
            LimitInfo limitInfo = new LimitInfo(100, 20);

            Assert.AreEqual("100,20", typeConverter.ConvertTo(limitInfo, typeof(string)));
        }
Пример #10
0
        public async Task <ResponseMessage <LimitInfoResponse> > GetDetail(UserInfo user, string userId)
        {
            ResponseMessage <LimitInfoResponse> r = new ResponseMessage <LimitInfoResponse>();
            LimitInfo li = await _Store.Get(_mapper.Map <SimpleUser>(user), userId);

            if (li == null)
            {
                return(r);
            }
            await checkPermission(r, user.Id, PERMISSION_BXXE, li.UserInfo.DepartmentId);

            if (!r.IsSuccess())
            {
                return(r);
            }

            r.Extension = _mapper.Map <LimitInfoResponse>(li);

            return(r);
        }
Пример #11
0
 private void Reset()
 {
     m_LimitInfos = LimitInfo.GetDefaultLimitSetup();
 }
Пример #12
0
 public void ShouldThrowArgumentNullExceptionWhenLimitStrIsNull()
 {
     LimitInfo.Parse(null);
 }
Пример #13
0
 public void ShouldParseFailure(string limitStr)
 {
     LimitInfo.Parse(limitStr);
 }