ReSetMeterAllParamService.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 ReSetMeterAllParamService
  15. {
  16. SqlHelper sqlHelper = new SqlHelper("NBDB");
  17. 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)
  18. {
  19. string Metesta_value = "";
  20. try
  21. {
  22. Up_time = Up_time.Replace(":", "");
  23. if (Metesta == "02")
  24. {
  25. Metesta_value = timeStart.Replace(":", "") + timeEnd.Replace(":", "");
  26. }
  27. else
  28. {
  29. Metesta_value = "00000000";
  30. }
  31. Up_interval = Convert.ToString(Convert.ToInt32(Up_interval), 16).PadLeft(4, '0');
  32. Self_Checking = Convert.ToString(Convert.ToInt32(Self_Checking), 16).PadLeft(4, '0');
  33. //发送指令
  34. string strParams = "{\"deviceId\": \"" + IOT_Code + "\",\"command\": {\"method\": \"Set_Meter_All\",\"paras\": {\"Metesta\": \""
  35. + 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\"}";
  36. JObject jObj = NBCommon.SendCommand(strParams);
  37. if (jObj["error_code"] != null)
  38. {
  39. return "";
  40. }
  41. string commandId = jObj["commandId"].ToString();//命令ID
  42. string status = jObj["status"].ToString();//命令状态
  43. string userId = OperatorProvider.Provider.Current().UserId;//命令操作者
  44. //命令保存
  45. string insertCommandSql = "INSERT INTO RMRS_SendCmdRecord (MeterId, CmdType, CmdID, Operator,CmdResult,SendText) VALUES(" + id + ",1013,'" + commandId + "','" + userId + "','" + status + "','" + strParams + "')";
  46. sqlHelper.ExecuteNoParams(insertCommandSql, CommandType.Text);
  47. string reJson = "{\"commandId\":\"" + commandId + "\",\"status\":\"" + status + "\"}";
  48. return reJson;
  49. }
  50. catch (Exception ex)
  51. {
  52. throw ex;
  53. }
  54. }
  55. }
  56. }