/// <summary> /// 生成token /// </summary> /// <typeparam name="T">承载信息类型</typeparam> /// <param name="payloadInfo">承载信息</param> /// <param name="secret">秘钥</param> /// <param name="timeoutSeconds">超时时间(单位:秒)</param> /// <returns></returns> public static string Encode <T>(T payloadInfo, string secret, int timeoutSeconds) { IJwtAlgorithm algorithm = new HMACSHA256Algorithm(); IJsonSerializer serializer = new JsonNetSerializer(); IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder(); IJwtEncoder encoder = new JwtEncoder(algorithm, serializer, urlEncoder); //用户信息转字段 var dic = CvtHelper.ToDictionary(payloadInfo, false); //超时时间 var timeOut = CvtHelper.ToTimeStamp(DateTime.Now) + timeoutSeconds; dic["exp"] = timeOut; var token = encoder.Encode(dic, secret); return(token); }
/// <summary> /// 按年度统计 /// </summary> /// <param name="familyID">家庭ID</param> /// <param name="req">条件</param> /// <returns></returns> public async Task <List <SumListInfo <string> > > SumOutPutYearAsync(int familyID, OutSumReq req) { using (IOSysContext db = new IOSysContext()) { //条件 var q = this.GetSumOutPutWhere(db, familyID, req.StartDate, req.EndDate); //统计 var list = await(from m in q group m by m.OutDate.Year into g select new SumListInfo <string>() { name = CvtHelper.ToStr(g.Key), value = g.Sum(m => m.Amount) }).ToListAsync(); return(list); } }
/// <summary> /// 按年度统计 /// </summary> /// <param name="familyID">家庭ID</param> /// <param name="req">条件</param> /// <returns></returns> public async Task <List <BorrowRepaySumListInfo <string> > > SumBorrowRepayYearAsync(int familyID, BorrowRepaySumReq req) { using (IOSysContext db = new IOSysContext()) { //条件 var q = this.GetSumBorrowRepayWhere(db, familyID, req.StartDate, req.EndDate, req.LstBRType); //统计 var list = await(from m in q group m by new { m.BRDate.Year, m.BRType } into g select new BorrowRepaySumListInfo <string>() { name = CvtHelper.ToStr(g.Key.Year), BRType = g.Key.BRType, value = g.Sum(m => m.Amount) }).ToListAsync(); return(list); } }
/// <summary> /// 把值转成字节数组 /// </summary> /// <typeparam name="T">值类型</typeparam> /// <param name="value">值</param> /// <returns></returns> private byte[] ToBytes <T>(T value) { //转字符串值 string strValue = ""; if (value is DateTime) { strValue = Convert.ToDateTime(value).ToString("yyyy/MM/dd HH:mm:ss.fff"); } else if (value is string) { strValue = CvtHelper.ToStr(value); } else { strValue = JsonConvert.SerializeObject(value, Formatting.Indented); } return(Encoding.UTF8.GetBytes(strValue)); }
/// <summary> /// 查询支出明细列表 /// </summary> /// <param name="familyID">家庭ID</param> /// <param name="req">条件</param> /// <returns></returns> public async Task <PageAmountList <OutPut> > QueryOutRecordAsync(int familyID, OutRecordReq req) { using (IOSysContext db = new IOSysContext()) { #region 条件 //家庭ID var q = db.OutPuts.AsNoTracking().Where(m => m.FamilyID == familyID); //开始日期 if (req.StartDate.HasValue) { q = q.Where(m => m.OutDate >= req.StartDate.Value); } //截止日期 if (req.EndDate.HasValue) { q = q.Where(m => m.OutDate <= req.EndDate.Value); } //类型 if (req.LstOutTypeID != null && req.LstOutTypeID.Count > 0) { q = q.Where(m => req.LstOutTypeID.Contains(m.OutTypeID)); } //账户 if (req.LstAmountAccountID != null && req.LstAmountAccountID.Count > 0) { q = q.Where(m => req.LstAmountAccountID.Contains(m.AmountAccountID)); } //备注(模糊匹配) if (string.IsNullOrWhiteSpace(req.Remark) == false) { q = q.Where(m => m.Remark.Contains(req.Remark)); } #endregion var totalRecord = 0; //总条数 var totalAmount = 0M; //总金额 //是否需要分页 if (req.IsSetPage()) { totalAmount = await q.SumAsync(m => m.Amount); totalRecord = await q.CountAsync(); } //设置排序和分页 if (CvtHelper.ToStr(req.Sort).StartsWith("OutCategoryID")) { if (CvtHelper.ToStr(req.Sort).EndsWith("asc")) { q = from op in q join otTemp in db.OutTypes on op.OutTypeID equals otTemp.ID into otJoin from ot in otJoin.DefaultIfEmpty() orderby ot.OutCategoryID ascending select op; } else { q = from op in q join otTemp in db.OutTypes on op.OutTypeID equals otTemp.ID into otJoin from ot in otJoin.DefaultIfEmpty() orderby ot.OutCategoryID descending select op; } req.Sort = string.Empty; this.SetSortPage(ref q, req); } else { this.SetSortPage(ref q, req); } //查询列表 var list = await q.ToListAsync(); //是否需要分页 if (req.IsSetPage() == false) { totalRecord = list.Count; totalAmount = list.Sum(m => m.Amount); } return(new PageAmountList <OutPut>(list, totalRecord, totalAmount)); } }
/// <summary> /// 构造函数 /// </summary> /// <param name="consulIP">consul服务IP</param> /// <param name="consulPort">consul服务端口</param> /// <param name="prefixKey">key前缀,一般用来区分不同服务</param> public ConsulKV(string consulIP, int consulPort, string prefixKey) { this.consulClient = new ConsulClient(p => { p.Address = new Uri($"http://{consulIP}:{consulPort}"); }); this.prefixKey = CvtHelper.ToStr(prefixKey); }