Пример #1
0
        public void Test()
        {
            string          fileUrl        = Path.Combine("E:\\Main\\gk2823_files\\json", "table0.json");
            JsonFileHelper  jsonFileHelper = new JsonFileHelper(fileUrl);
            var             data           = jsonFileHelper.ReadList <Table0>("RECORDS");
            List <JosnTab0> jsonTabs       = new List <JosnTab0>();

            foreach (var a in data.GroupBy(p => p.REP_OFFICE).ToList())
            {
                JosnTab0 jsonTab = new JosnTab0();
                jsonTab.officeName = a.Key.ToString();
                jsonTab.details    = new List <JosnTab0.Details>();
                foreach (var b in a.ToList().GroupBy(p => p.AGENTLEVEL).ToList())
                {
                    var detail = new JosnTab0.Details();
                    detail.agentName        = b.Key.ToString();
                    detail.bindThridAgenNum = b.Sum(p => p.BINDTHIRDCOUNT);
                    detail.cloudGoodNum     = b.Sum(p => p.BINDSECONDCOUNT);
                    detail.goodsDetails     = new List <JosnTab0.Details.GoodsDetails>();
                    foreach (var c in b.ToList().GroupBy(p => p.CATALOGNAME).ToList())
                    {
                        var goodsDetail = new JosnTab0.Details.GoodsDetails();
                        goodsDetail.allLightCount = c.FirstOrDefault().ALLLIGHTUPNUM;
                        goodsDetail.goodNum       = $"{c.Key.ToString()}:" + c.FirstOrDefault().LOCALLIGHTUPNUM.ToString();
                        var present = c.FirstOrDefault().LOCALLIGHTUPNUM / c.FirstOrDefault().ALLLIGHTUPNUM;
                        goodsDetail.goodPresent   = $"{c.Key.ToString()}:" + (present > 0 ? present.ToString("0%") : "0%");
                        goodsDetail.provinceMoney = c.FirstOrDefault().MONEY;
                        goodsDetail.provinceNum   = c.FirstOrDefault().SELLNUM;
                        detail.goodsDetails.Add(goodsDetail);
                    }
                    jsonTab.details.Add(detail);
                }
                Console.WriteLine(JsonConvert.SerializeObject(jsonTab));
                Console.WriteLine("-----------------------------------");
                jsonTabs.Add(jsonTab);
            }
        }