ReSetMeterIntervalService.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using LeaRun.Application.Code;
  2. using LeaRun.Application.Entity.NBManage;
  3. using LeaRun.Data;
  4. using LeaRun.Util;
  5. using Newtonsoft.Json.Linq;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace LeaRun.Application.Service.NBManage
  13. {
  14. public class ReSetMeterIntervalService
  15. {
  16. SqlHelper sqlHelper = new SqlHelper("NBDB");
  17. public string SendCommand(string id, string addr, string IOT_Code, string timeUp, string timeUpInterval)
  18. {
  19. try
  20. {
  21. //发送指令
  22. string strParams = "{\"deviceId\": \"" + IOT_Code + "\",\"command\": {\"method\": \"SET_METER_INTERVAL\",\"paras\": {\"addr\": \"" + addr + "\",\"time\":\"" + timeUp + "\",\"interval\":\"" + timeUpInterval + "\"},\"serviceId\": \"WaterMeterX\"},\"callbackUrl\":\"https://60.205.104.179:" + NBCommon.NB_ServerPort + "/NBManage/NBSubscribeListener/CallBackSetMeterInterval\"}";
  23. JObject jObj = NBCommon.SendCommand(strParams);
  24. if (jObj["error_code"] != null)
  25. {
  26. return "";
  27. }
  28. string commandId = jObj["commandId"].ToString();//命令ID
  29. string status = jObj["status"].ToString();//命令状态
  30. string userId = OperatorProvider.Provider.Current().UserId;//命令操作者
  31. //命令保存
  32. string insertCommandSql = "INSERT INTO RMRS_SendCmdRecord (MeterId, CmdType, CmdID, Operator,CmdResult,SendText) VALUES(" + id + ",1016,'" + commandId + "','" + userId + "','" + status + "','" + strParams + "')";
  33. sqlHelper.ExecuteNoParams(insertCommandSql, CommandType.Text);
  34. string reJson = "{\"commandId\":\"" + commandId + "\",\"status\":\"" + status + "\"}";
  35. return reJson;
  36. }
  37. catch (Exception ex)
  38. {
  39. throw ex;
  40. }
  41. }
  42. }
  43. }