using BPA.MES.Base.Application.Entitys.KepData;
using Furion.ClayObject.Extensions;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.MES.Base.Application.Services.KepServerDataService.Services
{
    [ApiDescriptionSettings("大屏数据", Order = 4, Name = "KepData", Tag = "大屏数据", KeepName = true, SplitCamelCase = true, KeepVerb = true)]
    public class KepDataService: KepServerSqlsugar, IKepDataService,ITransient, IDynamicApiController
    {
        public KepDataService()
        { 

        }
        [HttpPost]
        [AllowAnonymous]
        public async Task<Dictionary<string, object>> GetList()
        {
            var data =await KepDb.Queryable<ch1_device1>().Where(x=> SqlFunc.DateIsSame(x._TIMESTAMP, DateTime.Now)).Take(1000).ToListAsync();
            var dicdatass = KepDb.Queryable<ch1_device1>().GroupBy(x => x._NAME).Where(x => SqlFunc.DateIsSame(x._TIMESTAMP, DateTime.Now)).Select(x => x._NAME).ToArray();
            //var dicdata = KepDb.Queryable<ch1_device1>().GroupBy(x => x._NAME).Where(x => SqlFunc.DateIsSame(x._TIMESTAMP, DateTime.Now)).Select(x=>x._NAME).ToDictionary();
            Dictionary<string, object> dic = new Dictionary<string, object>();
            DataTable table = new DataTable();
            foreach (var item in dicdatass)
            {
                var key = item.ToString();
                var values = data.Where(x => x._NAME == key).Select(x=>x._VALUE).ToList();
                dic.Add(key, values);
            }
            var JsonString = JsonConvert.SerializeObject(dic);
            return dic;
        }
    }
}
