public ActionResult SearchLocation() { OTSClient _oTSClient = OTSHelper.GetOTSClientLocation(_tableStoreModel); PrimaryKey pk = new PrimaryKey(); pk.Add("d", new ColumnValue(Convert.ToInt64(Request.Form["d"]))); pk.Add("t", new ColumnValue(TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(Request.Form["t"])))); GetRowRequest getRowRequest = new GetRowRequest("L_100000000", pk); GetRowResponse response = _oTSClient.GetRow(getRowRequest); StringBuilder sbAttributeColumns = new StringBuilder(); foreach (var item in response.Attribute) { if (item.Key == "l") { byte[] lbyte = item.Value.BinaryValue; Dictionary <string, int> dictionary = ByteIntHelper.GetLocationByByte(lbyte); foreach (var dic in dictionary) { sbAttributeColumns.Append(dic.Key + ":" + dic.Value + "; "); } } } ViewData["pk"] = "设备:" + Request.Form["d"] + " 时间:" + Request.Form["t"]; ViewData["att"] = sbAttributeColumns.ToString(); return(View("Search", ViewBag)); }
public string LocationBeatQuery(string DataTime, string stationname, int lineid = 1) { string strJsonString = string.Empty; try { long begintime = 0; long endtime = 0; string datestr = DateTime.Now.ToLongDateString(); if (DataTime == null) { begintime = TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(datestr)); endtime = TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(datestr).AddDays(1)); } else { DateTimeFormatInfo dtFormat = new DateTimeFormatInfo(); dtFormat.ShortDatePattern = "yyyy-MM-dd"; datestr = DataTime; begintime = TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(datestr, dtFormat)); endtime = TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(datestr, dtFormat).AddDays(1)); } double avgrun = 0.0; double avgfree = 0.0; double avgwarn = 0.0; //获取七日平均 string strSql = " select round(sum(runt) / sum(if (runc > 0,runc,1)))as run,round(sum(freet) / sum(if (freec > 0,freec,1))) as free," + " round(sum(warnt) / sum(if (warnc > 0,warnc,1)))as warn from(select a.* from rptlocationday a left " + " join locationcfg b on a.ProductLineId = b.ProductLineId and a.locationid = b.locationid where a.ProductLineId = " + lineid + " and b.StationName = '" + stationname + "' order by a.ProductionT desc limit 7) tt1"; DataTable newTb = MySqlHelper.ExecuteQuery(strSql); if (newTb.Rows.Count > 0) { avgrun = Convert.ToDouble(newTb.Rows[0]["run"].ToString()); avgfree = Convert.ToDouble(newTb.Rows[0]["free"].ToString()); avgwarn = Convert.ToDouble(newTb.Rows[0]["warn"].ToString()); } string strSql1 = " select stationstate, FROM_UNIXTIME(starttime / 1000, '%H:%i:%s' ) as tm , if (currtime > 299,299,currtime) as timelen from( " + " select stationstate, starttime, (TIMESTAMPDIFF(SECOND, '1970-1-1 08:00:00', NOW()) - round(starttime / 1000)) as currtime from locationstatecache where ProductLineId =" + lineid + " and StationName = '" + stationname + "' " + " union all select stationstate, starttime, round((endtime - starttime) / 1000) as currtime from locationstate where ProductLineId = " + lineid + " and StationName = '" + stationname + "' and starttime > '" + begintime + "' and stationstate!='报警' order by starttime desc limit 200 " + " ) a order by starttime asc "; DataTable Tb = MySqlHelper.ExecuteQuery(strSql1); string recds = JsonConvert.SerializeObject(Tb); string strjson = "{ \"avgrun\":" + avgrun + ", \"avgfree\":" + avgfree + ", \"avgwarn \": " + avgwarn + " ,\"records\":" + recds + " }"; return(strjson); } catch (Exception ex) { logger.Error("查询生产节拍失败" + ex.Message); return(Global.RETURN_ERROR(ex.Message)); } }
public string FluctChangeTime(string DataTime, int dura, int lineid = 1) { DateTime time = Convert.ToDateTime(DataTime); long lTime = TimeHelper.ConvertDateTimeToInt(time); DateTime timeend = Convert.ToDateTime(DataTime).AddDays(1); long lTimeend = TimeHelper.ConvertDateTimeToInt(timeend); DosageInfoServer dServer = new DosageInfoServer(); DataTable tb = dServer.GetYieldFluctuation(lTime, lTimeend, dura, lineid); return(JsonHelper.DataTableToJson(tb)); }
public string ChangeTime(string DataTime, int duramins, int lineid = 1) { DateTime time = Convert.ToDateTime(DataTime); long lTime = TimeHelper.ConvertDateTimeToInt(time); DateTime timeend = time.AddDays(1); long lTimeend = TimeHelper.ConvertDateTimeToInt(timeend); DosageInfoServer dServer = new DosageInfoServer(); DataTable tb = dServer.GetCurrentProduction(lTime, lTimeend, duramins, lineid); return(JsonHelper.DataTableToJson(tb)); }
public ActionResult SearchRoute() { OTSClient _oTSClient = OTSHelper.GetOTSClientRoute(_tableStoreModel); PrimaryKey pk = new PrimaryKey(); pk.Add("d", new ColumnValue(Convert.ToInt64(Request.Form["d"]))); pk.Add("s", new ColumnValue(TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(Request.Form["s"])))); GetRowRequest getRowRequest = new GetRowRequest("Route", pk); GetRowResponse response = _oTSClient.GetRow(getRowRequest); StringBuilder sbAttributeColumns = new StringBuilder(); foreach (var item in response.Attribute) { switch (item.Key) { case "e": sbAttributeColumns.Append(item.Key + ":" + item.Value.IntegerValue + "【" + TimeHelper.ConvertStringToDateTime(item.Value.IntegerValue.ToString()).ToString("yyyy-MM-dd HH:mm:ss fff") + "】;"); break; case "r": byte[] lbyte = item.Value.BinaryValue; Dictionary <string, int> dictionary = ByteIntHelper.GetRouteByByte(lbyte); foreach (var dic in dictionary) { sbAttributeColumns.Append(dic.Key + ":" + dic.Value + "; "); } break; case "ds": byte[] ds = item.Value.BinaryValue; Dictionary <string, int> dsDic = ByteIntHelper.GetDurationstatsByByte(ds); foreach (var dic in dsDic) { sbAttributeColumns.Append(dic.Key + ":" + dic.Value + "; "); } break; case "es": byte[] es = item.Value.BinaryValue; Dictionary <string, int> esDic = ByteIntHelper.GetEventStatsByByte(es); foreach (var dic in esDic) { sbAttributeColumns.Append(dic.Key + ":" + dic.Value + "; "); } break; } } ViewData["pk"] = "设备:" + Request.Form["d"] + " 开始时间:" + Request.Form["s"]; ViewData["att"] = sbAttributeColumns.ToString(); return(View("Search", ViewBag)); }
public string GetUsage( ) { string strJsonString = string.Empty; try { ProductionLinesServer pServer = new ProductionLinesServer(); DataTable linedt = pServer.GetLinesList(); if (linedt.Rows.Count < 0) { return(strJsonString = "{\"ErrorType\":1,\"ErrorMessage\":\"生产线数量为0!\"}"); } List <Hashtable> list = new List <Hashtable> (); for (int x = 0; x < linedt.Rows.Count - 1; x++) { Hashtable dic = new Hashtable(); int lineid = 0; string linename = string.Empty;; int.TryParse(linedt.Rows[x][0].ToString(), out lineid); linename = linedt.Rows[x][1].ToString(); dic.Add("ProductLineId", lineid.ToString()); dic.Add("ProductLineName", linename); Dictionary <string, DataTable> dString = new Dictionary <string, DataTable>(); DateTime time = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")); long lTime = TimeHelper.ConvertDateTimeToInt(time); //string strSql = string.Format("SELECT * FROM `usage` a LEFT JOIN `line` b ON a.id_usage=b.id_usage WHERE UpData_Time>{0} ORDER BY ct DESC LIMIT 0,1", lTime); string strSql = string.Format("SELECT a.ID_Usage, a.ChildID, a.OrderID, a.ChildN, a.ProductionT, a.ProductionBeat, round(a.NowN/2) as NowN, round(a.OldN/2) as OldN ,round(a.AllN/2) as AllN , a.WeiTiaoConsumption, a.HuChiConsumption, a.BiaoQianConsumption, a.DaDiConsumption, a.ProductLineId ,b.* FROM `usage` a LEFT JOIN `line` b ON a.id_usage=b.id_usage where a.ProductLineId={0} ORDER BY ct DESC LIMIT 0,1", lineid); DataTable tb = MySqlHelper.ExecuteQuery(strSql); if (tb.Rows.Count > 0) { dic.Add("Data", JsonHelper.DataRowToDic(tb.Columns, tb.Rows[0])); } else { dic.Add("Data", ""); } list.Add(dic); } return(JsonConvert.SerializeObject(list)); } catch (Exception ex) { return(Global.RETURN_ERROR(ex.Message)); } }
public ActionResult SearchEvent() { OTSClient _oTSClient = OTSHelper.GetOTSClientEvent(_tableStoreModel); PrimaryKey pk = new PrimaryKey(); pk.Add("d", new ColumnValue(Convert.ToInt64(Request.Form["d"]))); pk.Add("et", new ColumnValue(TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(Request.Form["et"])))); pk.Add("ei", new ColumnValue(ByteIntHelper.intToBytes2(Convert.ToInt64(Request.Form["ei"]), 1))); GetRowRequest getRowRequest = new GetRowRequest("E_100000000", pk); GetRowResponse response = _oTSClient.GetRow(getRowRequest); StringBuilder sbAttributeColumns = new StringBuilder(); foreach (var item in response.Attribute) { switch (item.Key) { case "ep": //事件参数字段暂不做处理 //byte[] ep = item.Value.BinaryValue; break; case "t": sbAttributeColumns.Append(item.Key + ":" + item.Value.IntegerValue + "【" + TimeHelper.ConvertStringToDateTime(item.Value.IntegerValue.ToString()).ToString("yyyy-MM-dd HH:mm:ss fff") + "】;"); break; case "l": byte[] lbyte = item.Value.BinaryValue; Dictionary <string, int> dictionary = ByteIntHelper.GetLocationByByte(lbyte); foreach (var dic in dictionary) { sbAttributeColumns.Append(dic.Key + ":" + dic.Value + "; "); } break; } } ViewData["pk"] = "设备:" + Request.Form["d"] + " 事件时间:" + Request.Form["et"] + " 事件ID:" + Request.Form["ei"]; ViewData["att"] = sbAttributeColumns.ToString(); return(View("Search", ViewBag)); }
public GameResponesViewModel(SysCode sysCode, T data, ISystems sys, string appkey, string requestId, string nonce) { _sys = sys; string appSecret = _sys.GetAppConfig(appkey).Secret; code = (int)sysCode; message = EnumExtention.GetDescription(sysCode); timestamp = TimeHelper.ConvertDateTimeToInt(DateTime.Now.ToLocalTime()).ToString(); if (data != null) { this.data = _sys.Base64Encode(Encoding.UTF8, JsonHelper.SerializeObject(data)); sign = _sys.Sha512Encode($"{appkey}{appSecret}{this.data}{nonce}{timestamp}"); } else { sign = _sys.Sha512Encode($"{appkey}{appSecret}{nonce}{timestamp}"); } this.requestId = requestId; this.appKey = appkey; this.nonce = nonce; page = null; //用不上 signType = "sha_512"; }
protected readonly ISystems _sys; /**/ /// <summary> /// 返回值构造函数 /// author:陶林辉 /// </summary> /// <param name="sysCode">错误枚举</param> /// <param name="data">返回业务参数</param> /// <param name="encrypt">加密方式</param> public ResponseViewModel(SysCode sysCode, T data, string encrypt, ISystems sys, string secret) { _sys = sys; Code = (int)sysCode; Message = EnumExtention.GetDescription(sysCode); Datetime = DateTime.Now.ToLocalTime().ToString(); Timestamp = TimeHelper.ConvertDateTimeToInt(DateTime.Now.ToLocalTime()); if (encrypt == "0") { if (data != null) { this.Data = _sys.Base64Encode(Encoding.UTF8, JsonHelper.SerializeObject(data)); } } else if (encrypt == "1") { if (data != null) { this.Data = _sys.AesEncrypt(secret, JsonHelper.SerializeObject(data)); } } this.Encrypt = encrypt; }
static async void Query() { while (true) { try { Thread.Sleep(10000); Decimal begintime = 0; string qrysql = " select (TIMESTAMPDIFF(SECOND, '1970-1-1 08:00:00', NOW())-300) * 1000 as begintime"; DataTable datedt = MySqlHelper.ExecuteQuery(qrysql); if (datedt.Rows.Count > 0) { begintime = Convert.ToDecimal(datedt.Rows[0]["begintime"].ToString()); } else { DateTime dtm = DateTime.Now.AddMinutes(-5); begintime = TimeHelper.ConvertDateTimeToInt(dtm); } foreach (int key in datakeys) { string sql = "select tt2.locationid, tt2.stationname, if( runc>0,runc,0) as runc from locationcfg tt2 left join ( select t.productlineid, " + " t.stationname, sum(if (t.stationstate = '运行',1 ,0)) as runc from(select stationname, stationstate, starttime, productlineid " + " from locationstate where starttime > " + begintime + " and productlineid = " + key + " union select stationname, stationstate, starttime, productlineid " + " from locationstatecache where productlineid = 1 ) t where stationname in (select stationname from locationcfg where productlineid = " + key + " and state = 1) " + " group by productlineid ,stationname ) tt1 " + " on tt1.productlineid = tt2.productlineid and tt1.stationname = tt2.stationname where tt2.state = 1 order by tt2.locationid"; Dictionary <string, int> dic2 = new Dictionary <string, int>(); Dictionary <string, int> dic = new Dictionary <string, int>(); DataTable dt = MySqlHelper.ExecuteQuery(sql); for (int i = 0; i < dt.Rows.Count; i++) { int locationid = Convert.ToInt32(dt.Rows[i]["locationid"].ToString()); string stationname = dt.Rows[i]["stationname"].ToString(); int runc = Convert.ToInt32(dt.Rows[i]["runc"].ToString()); if (locationid <= 11) { dic.Add(stationname, runc); } } for (int i = dt.Rows.Count - 1; i > 0; i--) { int locationid = Convert.ToInt32(dt.Rows[i]["locationid"].ToString()); string stationname = dt.Rows[i]["stationname"].ToString(); int runc = Convert.ToInt32(dt.Rows[i]["runc"].ToString()); if (locationid > 11) { dic2.Add(stationname, runc); } } LocationBusyState1[key] = dic; LocationBusyState2[key] = dic2; // DealData(key, dic); } } catch (Exception e) { logger.Info(e.Message); } } }
/// <summary> /// Ons the action executing. /// </summary> /// <param name="context">Filter context.</param> public override void OnActionExecuting(ActionExecutingContext context) { GameRequestViweModel request = null; var _sys = context.HttpContext.RequestServices.GetService <ISystems>(); string sign = string.Empty; //本地签名信息 var route = context.RouteData.Values; var controller = route["controller"]; var action = route["action"]; try { context.HttpContext.Request.Body.Seek(0, SeekOrigin.Begin); using (var sr = new StreamReader(context.HttpContext.Request.Body)) { request = JsonHelper.DeserializeJsonToObject <GameRequestViweModel>(sr.ReadToEnd()); } } catch (Exception ex) { //缺少公共参数 GameResponesViewModel <Object> response = new GameResponesViewModel <object>(SysCode.LackParameter, null, _sys, "", "", ""); context.Result = new JsonResult(response); return; } if (string.IsNullOrEmpty(request.appKey) || string.IsNullOrEmpty(request.sign) || string.IsNullOrEmpty(request.requestId) || string.IsNullOrEmpty(request.timestamp) || string.IsNullOrEmpty(request.nonce) || string.IsNullOrEmpty(request.signType) ) { //公共参数必填项为空 GameResponesViewModel <Object> response = new GameResponesViewModel <object>(SysCode.EmptyParameter, null, _sys, "", "", ""); context.Result = new JsonResult(response); return; } long time = 0; try { time = long.Parse(request.timestamp); time = TimeHelper.ConvertDateTimeToInt(DateTime.Now) - time; if (time > 1200) { //非法时间戳 GameResponesViewModel <Object> response = new GameResponesViewModel <object>(SysCode.TimestampErr, null, _sys, "", "", ""); context.Result = new JsonResult(response); return; } } catch (Exception) { //非法时间戳 GameResponesViewModel <Object> response = new GameResponesViewModel <object>(SysCode.TimestampErr, null, _sys, request.appKey, request.requestId, request.nonce); context.Result = new JsonResult(response); return; } var appConfigDto = _sys.GetAppConfig(request.appKey); if (appConfigDto == null) { //无效appkey GameResponesViewModel <Object> response = new GameResponesViewModel <object>(SysCode.AppKey, null, _sys, request.appKey, request.requestId, request.nonce); context.Result = new JsonResult(response); return; } sign = _sys.Sha512Encode($"{appConfigDto.Keys}{appConfigDto.Secret}{request.data}{request.nonce}{request.timestamp}"); if (!request.sign.Equals(sign)) { //签名验证失败 GameResponesViewModel <Object> response = new GameResponesViewModel <object>(SysCode.SignCheckErr, null, _sys, request.appKey, request.requestId, request.nonce); context.Result = new JsonResult(response); return; } if (!string.IsNullOrEmpty((string)request.data) && request.data != null) { (string json, var code) = _sys.Base64Decode(Encoding.UTF8, (string)request.data); if (code != SysCode.Ok) { //base64解码失败 GameResponesViewModel <Object> response = new GameResponesViewModel <object>(SysCode.Base64DecodeErr, null, _sys, request.appKey, request.requestId, request.nonce); context.Result = new JsonResult(response); return; } else { request.data = JsonHelper.DeserializeJsonToObject <dynamic>(json); } } var claimsIdentity = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, JsonHelper.SerializeObject(request)), }, "Basic"); var claimsPrincipal = new ClaimsPrincipal(claimsIdentity); context.HttpContext.User = claimsPrincipal; if (true) { GameResponesViewModel <Object> response = new GameResponesViewModel <object> (_sys.CheckParameters(request.data, action.ToString()), null, _sys, request.appKey, request.requestId, request.nonce); if (response.code != 0) { context.Result = new JsonResult(response); return; } } }
/// <summary> /// Ons the action executing. /// </summary> /// <param name="context">Filter context.</param> public override void OnActionExecuting(ActionExecutingContext context) { ExternalRequesViewModel RequestObj = null; var errCode = SysCode.Ok; var _sys = context.HttpContext.RequestServices.GetService <ISystems>(); ExternalResponesViewModel <object> Response = null; var route = context.RouteData.Values; var action = route["action"]; string md5 = string.Empty; try { context.HttpContext.Request.Body.Seek(0, SeekOrigin.Begin);//FromBody 不加读取不到参数 using (var sr = new StreamReader(context.HttpContext.Request.Body)) { RequestObj = JsonHelper.DeserializeJsonToObject <ExternalRequesViewModel>(sr.ReadToEnd()); //业务参数,加密方式 } } catch (Exception) { errCode = SysCode.LackParameter; Response = new ExternalResponesViewModel <object>(errCode, _sys, null); context.Result = new JsonResult(Response); //缺少参数 return; } /*appkey校验*/ var appConfigDto = _sys.GetAppConfig(RequestObj.AppKey); if (appConfigDto == null) { errCode = SysCode.AppKey; Response = new ExternalResponesViewModel <object>(errCode, _sys, null); context.Result = new JsonResult(Response); return; } ; /*时间戳校验 */ long ltime = TimeHelper.ConvertDateTimeToInt(DateTime.Now) - long.Parse(RequestObj.Stimestamp); if (ltime > 120000) { errCode = SysCode.TimestampErr; Response = new ExternalResponesViewModel <object>(errCode, _sys, null); context.Result = new JsonResult(Response); return; } /*签名验证 appKey+appSecret+data+uuId+timestamp*/ md5 = _sys.Md5Encode($"{appConfigDto.Keys}{appConfigDto.Secret}{RequestObj.Data}{RequestObj.Stimestamp}"); if (!RequestObj.Sign.Equals(md5)) { errCode = SysCode.SignCheckErr; Response = new ExternalResponesViewModel <object>(errCode, _sys, null); context.Result = new JsonResult(Response); return; } string strTemp = RequestObj.Data.ToString(); (string strJson, var code) = _sys.Base64Decode(Encoding.UTF8, strTemp); if (code != SysCode.Ok) { //64解码失败 errCode = SysCode.Base64DecodeErr; Response = new ExternalResponesViewModel <object>(errCode, _sys, null); context.Result = new JsonResult(Response); return; } RequestObj.Data = JsonHelper.DeserializeJsonToObject <dynamic>(strJson); //这里需要增加strJson是否是json格式的判断 var claimsIdentity = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, JsonHelper.SerializeObject(RequestObj)), }, "Basic"); var claimsPrincipal = new ClaimsPrincipal(claimsIdentity); context.HttpContext.User = claimsPrincipal; /*业务参数校验*/ if (true) { ExternalResponesViewModel <object> response = new ExternalResponesViewModel <object>(_sys.CheckParameters(RequestObj.Data, action.ToString()), _sys, null); if (response.Code != 0) { context.Result = new JsonResult(response); return; } } }
/// <summary> /// OnActionExecuting 重写,用于验证参数 /// author:陶林辉 /// </summary> /// <param name="context"></param> public override void OnActionExecuting(ActionExecutingContext context) { //Attribute 只能这样获取注入接口对象 var _sys = context.HttpContext.RequestServices.GetService <ISystems>(); var _routine = context.HttpContext.RequestServices.GetService <IRoutine>(); RequestViewModel request = null; string sign = string.Empty;//本地签名信息 var route = context.RouteData.Values; var controller = route["controller"]; var action = route["action"]; #region 请求头参数认证 try { context.HttpContext.Request.Body.Seek(0, SeekOrigin.Begin);//FromBody 不加读取不到参数 using (var sr = new StreamReader(context.HttpContext.Request.Body)) { request = JsonHelper.DeserializeJsonToObject <RequestViewModel>(sr.ReadToEnd()); //业务参数,加密方式 } request.HendInfo = JsonHelper.DeserializeJsonToObject <HeadConten>(context.HttpContext.Request.Headers["HeadConten"]); //请求头 request.Client = JsonHelper.DeserializeJsonToObject <ClientInfo>(context.HttpContext.Request.Headers["Client"]); //客户端信息 } catch (Exception) { //缺少参数 ResponseViewModel <object> response = new ResponseViewModel <object>(SysCode.LackParameter, null, request.Encrypt, _sys, ""); context.Result = new JsonResult(response); return; } /*请求头校验*/ if (string.IsNullOrEmpty(request.HendInfo.Sign) || string.IsNullOrEmpty(request.HendInfo.Timestamp) || string.IsNullOrEmpty(request.HendInfo.UuId) || string.IsNullOrEmpty(request.HendInfo.AppKey) || string.IsNullOrEmpty(request.Client.Channel) || string.IsNullOrEmpty(request.Client.DeviceCode) || string.IsNullOrEmpty(request.Client.Gps) || string.IsNullOrEmpty(request.Client.OsType) || string.IsNullOrEmpty(request.Client.OsVersion) || string.IsNullOrEmpty(request.Client.Platform) || string.IsNullOrEmpty(request.Client.UserAgent) || string.IsNullOrEmpty(request.Client.Version) || string.IsNullOrEmpty(request.Client.VersionCode) ) { ResponseViewModel <object> response = new ResponseViewModel <object>(SysCode.EmptyParameter, null, request.Encrypt, _sys, ""); context.Result = new JsonResult(response); return; } if (!_routine.JudgeVersionStatus(request.Client.Version)) { ResponseViewModel <object> response = new ResponseViewModel <object>(SysCode.VersionIsNo, null, request.Encrypt, _sys, ""); context.Result = new JsonResult(response); return; } /*appkey校验*/ var appConfigDto = _sys.GetAppConfig(request.HendInfo.AppKey); if (appConfigDto == null) { ResponseViewModel <object> response = new ResponseViewModel <object>(SysCode.AppKey, null, request.Encrypt, _sys, ""); context.Result = new JsonResult(response); return; } ; request.Secret = appConfigDto.Secret; /*时间戳校验*/ long ltime = TimeHelper.ConvertDateTimeToInt(DateTime.Now) - long.Parse(request.HendInfo.Timestamp); if (ltime > 120000) { ResponseViewModel <object> response = new ResponseViewModel <object>(SysCode.TimestampErr, null, request.Encrypt, _sys, ""); context.Result = new JsonResult(response); } /*主参数校验*/ if (request == null || request.Encrypt == null || request.Data == null) { //缺少参数 ResponseViewModel <object> response = new ResponseViewModel <object>(SysCode.LackParameter, null, request.Encrypt, _sys, ""); context.Result = new JsonResult(response); return; } /*签名验证 appKey+appSecret+data+uuId+timestamp*/ sign = _sys.Md5Encode($"{appConfigDto.Keys}{appConfigDto.Secret}{request.Data}{request.HendInfo.UuId}{request.HendInfo.Timestamp}"); if (!request.HendInfo.Sign.Equals(sign)) { ResponseViewModel <object> response = new ResponseViewModel <object>(SysCode.SignCheckErr, null, request.Encrypt, _sys, ""); context.Result = new JsonResult(response); return; } /*业务参数解密*/ if (request.Encrypt == "0" || request.Encrypt == "")//base编码 { string strTemp = request.Data.ToString(); (string strJson, var vCode) = _sys.Base64Decode(Encoding.UTF8, strTemp); if (vCode != SysCode.Ok) { //64解码失败 ResponseViewModel <object> response = new ResponseViewModel <object>(SysCode.Base64DecodeErr, null, request.Encrypt, _sys, ""); context.Result = new JsonResult(response); return; } //这里需要增加strJson是否是json格式的判断 request.Data = JsonHelper.DeserializeJsonToObject <dynamic>(strJson); } else { request.Data = JsonHelper.DeserializeJsonToObject <dynamic>(_sys.AesDecrypt(request.Data.ToString(), appConfigDto.Secret)); } var claimsIdentity = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, JsonHelper.SerializeObject(request)), }, "Basic"); var claimsPrincipal = new ClaimsPrincipal(claimsIdentity); context.HttpContext.User = claimsPrincipal; #endregion /*业务参数校验*/ if (true) { ResponseViewModel <object> response = new ResponseViewModel <object>(_sys.CheckParameters(request.Data, action.ToString()), null, request.Encrypt, _sys, ""); if (response.Code != 0) { context.Result = new JsonResult(response); return; } } }
//获取各工位的末次生产时间 public string ChartBeatQuery(string DataTime, int lineid = 1) { string strJsonString = string.Empty; try { long begintime = 0; long endtime = 0; string datestr = DateTime.Now.ToLongDateString(); if (DataTime == null) { begintime = TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(datestr)); endtime = TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(datestr).AddDays(1)); } else { DateTimeFormatInfo dtFormat = new DateTimeFormatInfo(); dtFormat.ShortDatePattern = "yyyy-MM-dd"; datestr = DataTime; begintime = TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(datestr, dtFormat)); endtime = TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(datestr, dtFormat).AddDays(1)); } //获取生产线的最新id_usage string strSql = " select b1.JobType,b1.StationName,b1.LocationSeq, if (stationstate is null ,'停止',stationstate) as stationstate , if (currtime is null || currtime < 1,1,currtime) as currtime ," + " if (run is null ,0,run) as run ,if (free is null ,0,free) as free ,if (warn is null ,0,warn) as warn from(select t3.*, t2.LocationSeq, t2.JobType from(select stationNAME, stationstate, (TIMESTAMPDIFF(SECOND, '1970-1-1 08:00:00', NOW()) - round(starttime / 1000)) as currtime " + " from huabao.LocationStatecache where ProductLineId = " + lineid + ") t3 " + " left join(SELECT * from huabao.locationcfg where ProductLineId = " + lineid + ") t2 " + " on t3.stationNAME = t2.StationName and t2.state=1) as b1 left join(select stationNAME, " + " round( run_t /if (run_c > 0,run_c,1))as run,round(free_t /if (free_c > 0,free_c,1)) as free,round(warn_t /if (warn_c > 0,warn_c,1))as warn " + " from(select sum( if (stationstate = '运行',if( (endtime - startTime)<300000,endtime - startTime,300000), 0))/ 1000 AS run_t, sum( if (stationstate = '运行',1, 0)) AS run_c, sum( if " + " (stationstate = '空闲', endtime - startTime, 0))/ 1000 AS free_t, sum( if (stationstate = '空闲',1, 0)) AS free_c, " + " sum( if (stationstate = '报警', endtime - startTime, 0))/ 1000 AS warn_t, sum( if (stationstate = '报警',1, 0)) " + " AS warn_c, stationNAME from huabao.LocationState where starttime > " + begintime + " and starttime< " + endtime + " and ProductLineId = " + lineid + " " + " group by stationNAME ) a2 )a1 on a1.stationNAME = b1.stationNAME where JobType is not null order by b1.LocationSeq"; DataTable newTb = MySqlHelper.ExecuteQuery(strSql); if (newTb.Rows.Count > 0) { for (int i = 0; i < newTb.Rows.Count; i++) { if (Convert.ToUInt32(newTb.Rows[i][6]) > 299) { newTb.Rows[i][6] = 299; } if (Convert.ToUInt32(newTb.Rows[i][4]) > 299) { newTb.Rows[i][4] = 299; } if (Convert.ToUInt32(newTb.Rows[i][5]) > 299) { newTb.Rows[i][5] = 299; } if (Convert.ToUInt32(newTb.Rows[i][7]) > 299) { newTb.Rows[i][7] = 299; } } } strJsonString = JsonHelper.DataTableToJson(newTb); } catch (Exception ex) { logger.Error("查询生产节拍失败" + ex.Message); return(Global.RETURN_ERROR(ex.Message)); } logger.Info("查询生产节拍结束"); return(strJsonString); }