|
@@ -5,6 +5,10 @@ using SCADA_DAQ.Plugin.Tailg;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.ComponentModel;
|
|
|
+using System.Windows.Forms;
|
|
|
+using System.Text.RegularExpressions;
|
|
|
+using System.Data;
|
|
|
+using SCADA.CommonLib.Data.DIL;
|
|
|
|
|
|
namespace SCADA_DAQ.Plugin.Tailg.Service
|
|
|
{
|
|
@@ -12,24 +16,23 @@ namespace SCADA_DAQ.Plugin.Tailg.Service
|
|
|
/// 看板API服务
|
|
|
/// </summary>
|
|
|
[DisplayName("看板API服务")]
|
|
|
- public class CustomerService : BaseService
|
|
|
+ public class WebApiService : BaseService
|
|
|
{
|
|
|
- // 数据库对象
|
|
|
- private static SqlSchema.DIL.DILDB DAL = Env.SgIDAL;
|
|
|
|
|
|
// 静态缓存时长/s
|
|
|
- private static int staticCacheDuration = 2;
|
|
|
+ private static int staticCacheDuration = 5;
|
|
|
// 静态缓存
|
|
|
private Dictionary<string, Dictionary<string, object>> StaticCache =
|
|
|
new Dictionary<string, Dictionary<string, object>>()
|
|
|
{
|
|
|
- { "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} } }
|
|
|
+ { "GetExceptionData", new Dictionary<string, object>(){ {"Time",DateTime.Now}, { "Cache", null} } },
|
|
|
+ { "GetTodayOutput", new Dictionary<string, object>(){ { "Time", DateTime.Now }, { "Cache", null} } },
|
|
|
+ { "GetMonthOutput", new Dictionary<string, object>(){ { "Time", DateTime.Now }, { "Cache", null} } },
|
|
|
+ { "GetPerCapitaOutputPerHour", new Dictionary<string, object>(){ { "Time", DateTime.Now }, { "Cache", null} } }
|
|
|
};
|
|
|
|
|
|
|
|
|
- private static CustomerService _instance;
|
|
|
+ private static WebApiService _instance;
|
|
|
private CustomerServiceConfig _customerServiceConfig;
|
|
|
/// <summary>
|
|
|
///
|
|
@@ -44,7 +47,7 @@ namespace SCADA_DAQ.Plugin.Tailg.Service
|
|
|
/// <summary>
|
|
|
///
|
|
|
/// </summary>
|
|
|
- public static CustomerService Instance { get => _instance ?? (_instance = new CustomerService()); }
|
|
|
+ public static WebApiService Instance { get => _instance ?? (_instance = new WebApiService()); }
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
@@ -53,7 +56,7 @@ namespace SCADA_DAQ.Plugin.Tailg.Service
|
|
|
public override Type ConfigType => typeof(CustomerServiceConfig);
|
|
|
|
|
|
|
|
|
- private CustomerService()
|
|
|
+ private WebApiService()
|
|
|
{
|
|
|
if (_instance == null)
|
|
|
{
|
|
@@ -125,6 +128,44 @@ namespace SCADA_DAQ.Plugin.Tailg.Service
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 获取当日异常数据
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ public RpcResponse<object> GetExceptionData()
|
|
|
+ {
|
|
|
+ // 返回静态缓存
|
|
|
+ var timespan = (DateTime.Now - (DateTime)StaticCache["GetExceptionData"]["Time"]).TotalSeconds;
|
|
|
+ if (timespan < staticCacheDuration)
|
|
|
+ return new RpcResponse<object>() { Data = StaticCache["GetExceptionData"]["Cache"], Message = null };
|
|
|
+
|
|
|
+ Dictionary<string, string> workShopMap = new Dictionary<string, string>()
|
|
|
+ {
|
|
|
+ { "一车间","W01"}, {"二车间","W02"}, {"三车间","W03"}, {"四车间","W04"},
|
|
|
+ { "五车间","W05"}, {"六车间","W06"}, {"七车间","W07"}, {"八车间","W08"},
|
|
|
+ };
|
|
|
+ Dictionary<string, string> productionLineMap = new Dictionary<string, string>()
|
|
|
+ {
|
|
|
+ { "产线1号","P01"}, {"产线2号","P02"}, {"产线3号","P03"}, {"产线4号","P04"},
|
|
|
+ { "产线5号","P05"}, {"产线6号","P06"}, {"产线7号","P07"}, {"产线8号","P08"},
|
|
|
+ };
|
|
|
+
|
|
|
+ var sql = $"SELECT LEFT(Device_Str, 3) 车间号, SUBSTRING(Device_Str,4,4) 产线号, " +
|
|
|
+ $"AlarmType_Str AS 异常类型, COUNT(*) AS 次数, SUM(Duration_Int) 时长 " +
|
|
|
+ $"FROM V_Base_AlarmLog WHERE DATEDIFF(dd, CreateTime_Dt, GETDATE())= 0 " +
|
|
|
+ $"AND LEN(AlarmType_Str)>0 GROUP BY Device_Str, AlarmType_Str";
|
|
|
+ var dt = Env.SgIDAL.ReadDataTable(sql);
|
|
|
+ foreach (DataRow dr in dt.Rows)
|
|
|
+ {
|
|
|
+ dr["车间号"] = workShopMap[dr["车间号"].ToString()];
|
|
|
+ dr["产线号"] = productionLineMap[dr["产线号"].ToString()];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置静态缓存
|
|
|
+ StaticCache["GetExceptionData"] = new Dictionary<string, object>()
|
|
|
+ { { "Time", DateTime.Now}, { "Cache", dt} };
|
|
|
+ return new RpcResponse<object>() { Data = dt, Message = null };
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
@@ -133,11 +174,20 @@ namespace SCADA_DAQ.Plugin.Tailg.Service
|
|
|
/// <returns></returns>
|
|
|
public RpcResponse<object> GetTodayOutput()
|
|
|
{
|
|
|
+ // 返回静态缓存
|
|
|
+ var timespan = (DateTime.Now - (DateTime)StaticCache["GetTodayOutput"]["Time"]).TotalSeconds;
|
|
|
+ if (timespan < staticCacheDuration)
|
|
|
+ return new RpcResponse<object>() { Data = StaticCache["GetTodayOutput"]["Cache"], Message = null };
|
|
|
+
|
|
|
var sql = $"SELECT WorkShopId_Str AS 车间号, ProductionLineId_Str AS 产线号, COUNT(*) AS 产量 " +
|
|
|
$"FROM APP_TaiLing_ProductionRecord WHERE DATEDIFF(dd, EndTime_Dt, GETDATE())= 0 " +
|
|
|
$"GROUP BY WorkShopId_Str, ProductionLineId_Str";
|
|
|
- var res = DAL.ReadDataTable(sql);
|
|
|
- return new RpcResponse<object>() { Data = res, Message = null };
|
|
|
+ var dt = Env.SgIDAL.ReadDataTable(sql);
|
|
|
+
|
|
|
+ // 设置静态缓存
|
|
|
+ StaticCache["GetTodayOutput"] = new Dictionary<string, object>()
|
|
|
+ { { "Time", DateTime.Now}, { "Cache", dt} };
|
|
|
+ return new RpcResponse<object>() { Data = dt, Message = null };
|
|
|
}
|
|
|
|
|
|
|
|
@@ -147,12 +197,21 @@ namespace SCADA_DAQ.Plugin.Tailg.Service
|
|
|
/// <returns></returns>
|
|
|
public RpcResponse<object> GetMonthOutput()
|
|
|
{
|
|
|
+ // 返回静态缓存
|
|
|
+ var timespan = (DateTime.Now - (DateTime)StaticCache["GetMonthOutput"]["Time"]).TotalSeconds;
|
|
|
+ if (timespan < staticCacheDuration)
|
|
|
+ return new RpcResponse<object>() { Data = StaticCache["GetMonthOutput"]["Cache"], Message = null };
|
|
|
+
|
|
|
var sql = $"SELECT YEAR(StartTime_Dt) AS 年份, MONTH(StartTime_Dt) AS 月份, " +
|
|
|
$"WorkShopId_Str AS 车间号, ProductionLineId_Str AS 产线号, COUNT(*) AS 产量 " +
|
|
|
$"FROM APP_TaiLing_ProductionRecord " +
|
|
|
$"GROUP BY YEAR(StartTime_Dt), MONTH(StartTime_Dt), WorkShopId_Str, ProductionLineId_Str";
|
|
|
- var res = DAL.ReadDataTable(sql);
|
|
|
- return new RpcResponse<object>() { Data = res, Message = null };
|
|
|
+ var dt = Env.SgIDAL.ReadDataTable(sql);
|
|
|
+
|
|
|
+ // 设置静态缓存
|
|
|
+ StaticCache["GetMonthOutput"] = new Dictionary<string, object>()
|
|
|
+ { { "Time", DateTime.Now}, { "Cache", dt} };
|
|
|
+ return new RpcResponse<object>() { Data = dt, Message = null };
|
|
|
}
|
|
|
|
|
|
|
|
@@ -162,6 +221,10 @@ namespace SCADA_DAQ.Plugin.Tailg.Service
|
|
|
/// <returns></returns>
|
|
|
public RpcResponse<object> GetPerCapitaOutputPerHour()
|
|
|
{
|
|
|
+ // 返回静态缓存
|
|
|
+ var timespan = (DateTime.Now - (DateTime)StaticCache["GetPerCapitaOutputPerHour"]["Time"]).TotalSeconds;
|
|
|
+ if (timespan < staticCacheDuration)
|
|
|
+ return new RpcResponse<object>() { Data = StaticCache["GetPerCapitaOutputPerHour"]["Cache"], Message = null };
|
|
|
|
|
|
// 三表联查,人均小时产出率直接用sql算出来
|
|
|
var sql = "SELECT tb1.年份, tb1.月份, tb1.车间号, tb1.产线号, tb1.时长, tb2.产量, tb3.NumberOfPeople_Int AS 人数, " +
|
|
@@ -178,10 +241,12 @@ namespace SCADA_DAQ.Plugin.Tailg.Service
|
|
|
"ON tb1.年份 = tb2.年份 AND tb1.月份 = tb2.月份 AND tb1.车间号 = tb2.车间号 AND tb1.产线号 = tb2.产线号) " +
|
|
|
"LEFT JOIN APP_TaiLing_ProductionLineManagement AS tb3 " +
|
|
|
"ON tb1.车间号 = tb3.WorkShopId_Str AND tb1.产线号 = tb3.ProductionLineId_Str";
|
|
|
- var res = DAL.ReadDataTable(sql);
|
|
|
-
|
|
|
+ var dt = Env.SgIDAL.ReadDataTable(sql);
|
|
|
|
|
|
- return new RpcResponse<object>() { Data = res, Message = null };
|
|
|
+ // 设置静态缓存
|
|
|
+ StaticCache["GetPerCapitaOutputPerHour"] = new Dictionary<string, object>()
|
|
|
+ { { "Time", DateTime.Now}, { "Cache", dt} };
|
|
|
+ return new RpcResponse<object>() { Data = dt, Message = null };
|
|
|
}
|
|
|
|
|
|
|