コード例 #1
0
ファイル: AssetApi.cs プロジェクト: mirrortom/asset
        public async Task History()
        {
            var           para = this.ParaForm <AssetM>();
            List <AssetM> data = AssetBll.HistoryList(para);

            if (data.Count == 0)
            {
                await this.Json(new { errmsg = para.ErrorMsg, errcode = para.ErrorCode });

                return;
            }
            // 返回字段按需设定
            var redata = AllFieldList(data);

            // 按需字段列表
            if (!string.IsNullOrWhiteSpace(para.Fields) && para.Fields.Split(',').Length > 0)
            {
                var list = SerializeHelp.ObjectsToDicts(redata, para.Fields.Split(','));
                await this.Json(new { list, errcode = ErrCode.Success });

                return;
            }
            // 所有字段
            await this.Json(new { list = redata, errcode = ErrCode.Success });
        }
コード例 #2
0
ファイル: AssetApi.cs プロジェクト: mirrortom/asset
        public async Task Statistic()
        {
            AssetM data = AssetBll.ValueTotal();

            if (data.ErrorCode != 200)
            {
                await this.Json(new { errcode = 301, errmsg = data.ErrorMsg });

                return;
            }
            // 风险等级
            Dictionary <string, object>[] byRisk = AssetBll.ValueTotalByRisk();
            // 机构
            List <AssetM> byExcOrg = AssetBll.ValueTotalByExcOrg();
            // 资产类型
            List <AssetM> byKind = AssetBll.ValueTotalByKind();
            // 近30更新日总值
            List <AssetM> lasttotal30 = AssetBll.Last30TotalVal();

            // 历史最高/低
            AssetM[] maxmin = AssetBll.ValueMaxMinOfHis();
            var      redata = new
            {
                data.Value,
                byRisk   = data.Value == 0 ? null : byRisk,
                byExcOrg = byExcOrg == null ? null :
                           SerializeHelp.ObjectsToDicts(byExcOrg, nameof(AssetM.ExcOrg), nameof(AssetM.Value)),
                byKind = byKind == null ? null :
                         SerializeHelp.ObjectsToDicts(byKind, nameof(AssetM.Kind), nameof(AssetM.Value)),
                lasttotal30 = lasttotal30 == null ? null :
                              SerializeHelp.ObjectsToDicts(lasttotal30, nameof(AssetM.Value), nameof(AssetM.TotalDate)),
                max     = maxmin[0] == null ? null : new { maxmin[0].Value, maxmin[0].TotalDate },
                min     = maxmin[1] == null ? null : new { maxmin[1].Value, maxmin[1].TotalDate },
                errcode = data.ErrorCode
            };

            await this.Json(redata);
        }
コード例 #3
0
        public async Task List()
        {
            // 支持传多个分组
            KeyvalM para = this.ParaForm <KeyvalM>();
            // get KVdata
            Dictionary <string, List <KeyvalM> > datadict = KeyValBll.AllByCategory(para);

            if (datadict == null)
            {
                await this.Json(new { errmsg = para.ErrorMsg });

                return;
            }
            // 返回字段按需设定
            Dictionary <string, IEnumerable <object> > redict = new Dictionary <string, IEnumerable <object> >();

            string[] fields = null;
            if (!string.IsNullOrWhiteSpace(para.Fields))
            {
                fields = para.Fields.Split(',');
            }
            foreach (var key in datadict.Keys)
            {
                // 按需字段列表
                if (fields != null && fields.Length > 0)
                {
                    redict[key] = SerializeHelp.ObjectsToDicts(datadict[key], fields);
                }
                else
                {
                    redict[key] = AllFieldList(datadict[key]);
                }
            }
            //
            await this.Json(new { list = redict, errcode = 200 });
        }