ReSetMeterAddressService.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 ReSetMeterAddressService
  15. {
  16. SqlHelper sqlHelper = new SqlHelper("NBDB");
  17. public string SendCommand(string id, string addr, string metesta, string IOT_Code, string timeStart, string timeEnd)
  18. {
  19. //限制时间的指令
  20. string metesta_value = "";
  21. //要发送的指令字符串
  22. string strParams = "";
  23. try
  24. {
  25. //发送指令
  26. //判断指令的类型
  27. if (metesta == "01")
  28. {
  29. strParams = "{\"deviceId\": \"" + IOT_Code + "\",\"command\": {\"method\": \"Set_Meter_WorkSta\",\"paras\": {\"Address\": \"" + addr + "\",\"Metesta\": \"" + metesta + "\",\"Metesta_value\": \"" + metesta_value + "\"},\"serviceId\": \"WaterMeter\"},\"callbackUrl\":\"http://47.105.45.253:" + NBCommon.NB_ServerPort + "/NBManage/NBSubscribeListener/CallBackReSetAddr\"}";//,\"expireTime\":\"0\"
  30. }
  31. if (metesta == "02" || metesta == "03")
  32. {
  33. //拼接时间指令参数
  34. metesta_value = timeStart.Replace(":", "") + timeEnd.Replace(":", "");
  35. strParams = "{\"deviceId\": \"" + IOT_Code + "\",\"command\": {\"method\": \"Set_Meter_WorkSta\",\"paras\": {\"Address\": \"" + addr + "\",\"Metesta\": \"" + metesta + "\",\"Metesta_value\": \"" + metesta_value + "\"},\"serviceId\": \"WaterMeter\"},\"callbackUrl\":\"http://47.105.45.253:" + NBCommon.NB_ServerPort + "/NBManage/NBSubscribeListener/CallBackReSetAddr\"}";//,\"expireTime\":\"0\"
  36. }
  37. //增肌strParams为空判断
  38. JObject jObj = NBCommon.SendCommand(strParams);
  39. if (jObj["error_code"] != null)
  40. {
  41. return "";
  42. }
  43. string commandId = jObj["commandId"].ToString();//命令ID
  44. string status = jObj["status"].ToString();//命令状态
  45. string userId = OperatorProvider.Provider.Current().UserId;//命令操作者
  46. //命令保存
  47. string insertCommandSql = "INSERT INTO RMRS_SendCmdRecord (MeterId, CmdType, CmdID, Operator,CmdResult,SendText) VALUES(" + id + ",1004,'" + commandId + "','" + userId + "','" + status + "','" + strParams + "')";
  48. sqlHelper.ExecuteNoParams(insertCommandSql, CommandType.Text);
  49. string reJson = "{\"commandId\":\"" + commandId + "\",\"status\":\"" + status + "\"}";
  50. return reJson;
  51. }
  52. catch (Exception ex)
  53. {
  54. throw ex;
  55. }
  56. }
  57. }
  58. }