using LeaRun.Application.Code; using LeaRun.Application.Entity.NBManage; using LeaRun.Data; using LeaRun.Util; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LeaRun.Application.Service.NBManage { public class ReSetMeterAllParamService { SqlHelper sqlHelper = new SqlHelper("NBDB"); public string SendCommand(string id, string addr, string IOT_Code, string Metesta, string Up_time, string Up_interval, string Self_Checking,string timeStart,string timeEnd) { string Metesta_value = ""; try { Up_time = Up_time.Replace(":", ""); if (Metesta == "02") { Metesta_value = timeStart.Replace(":", "") + timeEnd.Replace(":", ""); } else { Metesta_value = "00000000"; } Up_interval = Convert.ToString(Convert.ToInt32(Up_interval), 16).PadLeft(4, '0'); Self_Checking = Convert.ToString(Convert.ToInt32(Self_Checking), 16).PadLeft(4, '0'); //发送指令 string strParams = "{\"deviceId\": \"" + IOT_Code + "\",\"command\": {\"method\": \"Set_Meter_All\",\"paras\": {\"Metesta\": \"" + Metesta + "\",\"Metesta_value\":\"" + Metesta_value + "\",\"Up_time\":\"" + Up_time + "\",\"Up_interval\":\"" + Up_interval + "\",\"Self_Checking\":\"" + Self_Checking + "\"},\"serviceId\": \"WaterMeter\"},\"callbackUrl\":\"https://47.105.45.253:" + NBCommon.NB_ServerPort + "/NBManage/NBSubscribeListener/CallBackSetAllParam\"}"; JObject jObj = NBCommon.SendCommand(strParams); if (jObj["error_code"] != null) { return ""; } string commandId = jObj["commandId"].ToString();//命令ID string status = jObj["status"].ToString();//命令状态 string userId = OperatorProvider.Provider.Current().UserId;//命令操作者 //命令保存 string insertCommandSql = "INSERT INTO RMRS_SendCmdRecord (MeterId, CmdType, CmdID, Operator,CmdResult,SendText) VALUES(" + id + ",1013,'" + commandId + "','" + userId + "','" + status + "','" + strParams + "')"; sqlHelper.ExecuteNoParams(insertCommandSql, CommandType.Text); string reJson = "{\"commandId\":\"" + commandId + "\",\"status\":\"" + status + "\"}"; return reJson; } catch (Exception ex) { throw ex; } } } }