瀏覽代碼

更新API

zhangliwen 1 年之前
父節點
當前提交
2cf80f74d8
共有 1 個文件被更改,包括 20 次插入126 次删除
  1. 20 126
      SCADA_DAQ/Customer/Service/CustomerService.cs

+ 20 - 126
SCADA_DAQ/Customer/Service/CustomerService.cs

@@ -53,7 +53,9 @@ namespace SCADA_DAQ.Customer.Service
         {
             { "GetTaskInfo", new Dictionary<string, object>(){ {"Time",DateTime.Now}, { "Cache", null} } },
             { "GetOutputAndOrder", new Dictionary<string, object>(){ { "Time", DateTime.Now }, { "Cache", null} } },
-            { "GetNoticeInfo", new Dictionary<string, object>(){ { "Time", DateTime.Now }, { "Cache", null} } }
+            { "GetNoticeInfo", new Dictionary<string, object>(){ { "Time", DateTime.Now }, { "Cache", null} } },
+            { "GetLineOutput", new Dictionary<string, object>(){ { "Time", DateTime.Now }, { "Cache", null} } },
+            { "GetLineExceptionData", new Dictionary<string, object>(){ { "Time", DateTime.Now }, { "Cache", null} } }
         };
 
 
@@ -236,131 +238,6 @@ namespace SCADA_DAQ.Customer.Service
             return new RpcResponse<object>() { Data = result, Message = null };
         }
 
-        ///// <summary>
-        ///// 获取产量和工单数
-        ///// </summary>
-        ///// <param name="workShopId">车间号</param>
-        ///// <param name="productionLineId">产线号</param>
-        ///// <param name="year">年份</param>
-        ///// <param name="month">月份</param>
-        ///// <returns></returns>
-        //public RpcResponse<object> GetOutputAndOrder(List<string> workShopId, List<string> productionLineId, int year, int month)
-        //{
-        //    // 判断参数合理性
-        //    if (workShopId == null || productionLineId == null)
-        //        return new RpcResponse<object>() { Data = null, Message = "paras is empty." };
-
-        //    // 返回静态缓存
-        //    if (outputAndOrderStaticCacheDuration > 0)
-        //        return new RpcResponse<object>() { Data = OutputAndOrderStaticCache, Message = null };
-
-        //    bool isAllShop = false;  // 是否查询所有车间
-        //    bool isAllLine = false;  // 是否查询所有产线
-        //    bool isAllYear = false;  // 是否查询所有年份
-        //    bool isAllMonth = false;  // 是否查询所有月份
-
-        //    if (workShopId.Count <= 0)
-        //        isAllShop = true;
-        //    if (productionLineId.Count <= 0)
-        //        isAllLine = true;
-        //    if (year <= 0)
-        //        isAllYear = true;
-        //    if (month <= 0)
-        //        isAllMonth = true;
-
-        //    // 查询数据库
-        //    List<TaskManagementModel> tableInfo = DAL.APP_TaiLing_TaskManagement.GetData<TaskManagementModel>();
-        //    //  tableInfo = DAL.APP_TaiLing_TaskManagement.GetData<TaskManagementModel>(t => t.OrderId == "1");
-        //    if (tableInfo == null)
-        //    {
-        //        return new RpcResponse<object>() { Data = null, Message = null };
-        //    }
-
-        //    List<int> yearList = new List<int>(); // 年份列表
-        //    List<object> resList = new List<object>(); // 结果列表
-
-
-        //    if (!isAllShop)
-        //    {
-        //        var workShopIdDic = workShopId.ToLookup(t => t); 
-        //        // workShopId 不为空就查询指定车
-        //        tableInfo = tableInfo.Where(t => workShopIdDic.Contains(t.WorkShopId)).ToList();
-        //    }
-
-        //    if (!isAllLine)
-        //    {
-        //        // productionLineId 不为空就查询指定产线号
-        //        tableInfo = tableInfo.Where(t => productionLineId.IndexOf(t.ProductionLineId) >= 0).ToList();
-        //    }
-
-        //    if (!isAllYear)
-        //    {
-        //        // year>0 就查询指定年份
-        //        tableInfo = tableInfo.Where(t => t.OrderDatetime.Year == year).ToList();
-        //        yearList.Add(year);
-        //    }
-        //    else
-        //    {
-        //        // year<=0 就把记录时间等于year的放到yearList
-        //        yearList = tableInfo.ToLookup(t => t.OrderDatetime.Year).Select(t => t.Key).ToList();
-        //    }
-
-        //    if (!isAllMonth)
-        //    {
-        //        // month>0 就查询指定月份
-        //        var monthgroup = tableInfo.Where(t => t.OrderDatetime.Month == month).
-        //            ToLookup(t => t.OrderDatetime.Year).Select(t => new
-        //            {
-        //                Year = t.Key,
-        //                Month = month,
-        //                Output = t.Sum(p => p.CurrentProduction),
-        //                OrderQuantity = t.Count(),
-        //                TotalDurationSec = t.Sum(p => p.DurationSec)
-        //            });
-        //        // 启用静态缓存
-        //        outputAndOrderStaticCacheDuration = staticCacheDuration;
-        //        OutputAndOrderStaticCache = monthgroup;
-        //        return new RpcResponse<object>() { Data = monthgroup, Message = null };
-        //    }
-
-        //    tableInfo.ToLookup(t => t.OrderDatetime.Year).ForEach(yearData =>
-        //    {
-        //        Dictionary<int, int> yearOutput = new Dictionary<int, int>{
-        //            { 1, 0 },{ 2, 0 },{ 3, 0 },{ 4, 0 },{ 5, 0 },{ 6, 0 },
-        //            { 7, 0 },{ 8, 0 },{ 9, 0 },{ 10, 0 },{ 11, 0 },{ 12, 0 }
-        //        };
-        //        Dictionary<int, int> yearOrderQuantity = new Dictionary<int, int>{
-        //            { 1, 0 },{ 2, 0 },{ 3, 0 },{ 4, 0 },{ 5, 0 },{ 6, 0 },
-        //            { 7, 0 },{ 8, 0 },{ 9, 0 },{ 10, 0 },{ 11, 0 },{ 12, 0 }
-        //        };
-        //        Dictionary<int, int> yearDurationSec = new Dictionary<int, int>{
-        //            { 1, 0 },{ 2, 0 },{ 3, 0 },{ 4, 0 },{ 5, 0 },{ 6, 0 },
-        //            { 7, 0 },{ 8, 0 },{ 9, 0 },{ 10, 0 },{ 11, 0 },{ 12, 0 }
-        //        };
-        //        foreach (var item in yearData.ToLookup(t => t.OrderDatetime.Month))
-        //        {
-        //            yearOutput[item.Key] = item.Sum(t => t.CurrentProduction);
-        //            yearOrderQuantity[item.Key] = item.Count();
-        //            yearDurationSec[item.Key] = item.Sum(t => t.DurationSec);
-        //        }
-        //        resList.Add(new
-        //        {
-        //            Year = yearData.Key,
-        //            Month = 0,
-        //            Output = yearOutput,
-        //            OrderQuantity = yearOrderQuantity,
-        //            TotalDurationSec = yearDurationSec
-        //        });
-
-        //    });
-
-        //    // 启用静态缓存
-        //    outputAndOrderStaticCacheDuration = staticCacheDuration;
-        //    OutputAndOrderStaticCache = resList;
-        //    return new RpcResponse<object>() { Data = resList, Message = null };
-
-        //}
-
 
         /// <summary>
         /// 获取产量和工单数
@@ -531,6 +408,11 @@ namespace SCADA_DAQ.Customer.Service
         /// <returns></returns>
         public RpcResponse<object> GetLineOutput()
         {
+            // 返回静态缓存
+            var timespan = (DateTime.Now - (DateTime)StaticCache["GetLineOutput"]["Time"]).TotalSeconds;
+            if (timespan < staticCacheDuration)
+                return new RpcResponse<object>() { Data = StaticCache["GetLineOutput"]["Cache"], Message = null };
+
             var sql = $"DECLARE @W VARCHAR(10), @P VARCHAR(10);" +
                 $"SET @W = '{CustomerEnv.ProductionLineConfigValue.WorkShopId}'; " + 
                 $"SET @P = '{CustomerEnv.ProductionLineConfigValue.ProductionLineId}';" +
@@ -543,6 +425,10 @@ namespace SCADA_DAQ.Customer.Service
                 $"WHERE DATEDIFF(dd, EndTime_Dt, GETDATE())= 0 AND WorkShopId_Str = @W AND ProductionLineId_Str = @P " +
                 $"GROUP BY WorkShopId_Str, ProductionLineId_Str; ";
             var dt = DAL.ReadDataTable(sql);
+
+            // 设置静态缓存
+            StaticCache["GetLineOutput"] = new Dictionary<string, object>()
+                { { "Time", DateTime.Now}, { "Cache", dt} };
             return new RpcResponse<object>() { Data = dt, Message = null };
         }
 
@@ -552,6 +438,11 @@ namespace SCADA_DAQ.Customer.Service
         /// <returns></returns>
         public RpcResponse<object> GetLineExceptionData()
         {
+            // 返回静态缓存
+            var timespan = (DateTime.Now - (DateTime)StaticCache["GetLineExceptionData"]["Time"]).TotalSeconds;
+            if (timespan < staticCacheDuration)
+                return new RpcResponse<object>() { Data = StaticCache["GetLineExceptionData"]["Cache"], Message = null };
+
             Dictionary<string, string> workShopMap = new Dictionary<string, string>()
             {
                 { "一车间","W01"}, {"二车间","W02"}, {"三车间","W03"}, {"四车间","W04"},
@@ -576,6 +467,9 @@ namespace SCADA_DAQ.Customer.Service
                 dr["产线号"] = productionLineMap[dr["产线号"].ToString()];
             }
 
+            // 设置静态缓存
+            StaticCache["GetLineExceptionData"] = new Dictionary<string, object>()
+                { { "Time", DateTime.Now}, { "Cache", dt} };
             return new RpcResponse<object>() { Data = dt, Message = null };
         }