示例#1
0
        public async Task <CumulativeByRcc> MonthlyCumulateByRcc(ResolveFieldContext context, int rcc)
        {
            if (context.ThrowIfInvalidAuthorization() == false)
            {
                return(null);
            }
            var rcckeys = context.GetSiteKeysByRcc();

            if (rcckeys.ContainsKey(rcc) == false)
            {
                context.Errors.Add(new GraphQL.ExecutionError("대상 RCC의 지역 사이트는 소유하지 않았습니다"));
                return(null);
            }
            using (IStatelessSession session = mysqlDataAccessor.SessionFactory.OpenStatelessSession())
            {
                var result = await MonthlyQuery(session, DateTime.Now.Year, DateTime.Now.Month, rcckeys[rcc]);

                CumulativeByRcc row = new CumulativeByRcc();
                row.rcc               = rcc;
                row.sumofcharge       = result.Sum(x => x.Sumofcharge);
                row.sumofdischarge    = result.Sum(x => x.Sumofdischarge);
                row.sumofpvgeneration = result.Sum(x => x.Sumofpvgeneration);
                row.sites             = result.Select(x => new CumulativeBySite()
                {
                    siteid = x.Siteid, sumofcharge = x.Sumofcharge, sumofdischarge = x.Sumofdischarge, sumofpvgeneration = x.Sumofpvgeneration
                });
                return(row);
            }
        }
示例#2
0
        public async Task <IEnumerable <CumulativeByRcc> > MonthlyCumulateByAll(ResolveFieldContext context)
        {
            if (context.ThrowIfInvalidAuthorization() == false)
            {
                return(null);
            }
            var rcckeys = context.GetSiteKeysByRcc();
            List <CumulativeByRcc> results = new List <CumulativeByRcc>();

            using (IStatelessSession session = mysqlDataAccessor.SessionFactory.OpenStatelessSession())
            {
                foreach (int rcc in rcckeys.Keys)
                {
                    var result = await MonthlyQuery(session, DateTime.Now.Year, DateTime.Now.Month, rcckeys[rcc]);

                    CumulativeByRcc row = new CumulativeByRcc();
                    row.rcc               = rcc;
                    row.sumofcharge       = result.Sum(x => x.Sumofcharge);
                    row.sumofdischarge    = result.Sum(x => x.Sumofdischarge);
                    row.sumofpvgeneration = result.Sum(x => x.Sumofpvgeneration);
                    row.sites             = result.Select(x => new CumulativeBySite()
                    {
                        siteid = x.Siteid, sumofcharge = x.Sumofcharge, sumofdischarge = x.Sumofdischarge, sumofpvgeneration = x.Sumofpvgeneration
                    });
                    results.Add(row);
                }
            }
            return(results);
        }