1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- 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 ReSetMeterAddressService
- {
- SqlHelper sqlHelper = new SqlHelper("NBDB");
- public string SendCommand(string id, string addr, string metesta, string IOT_Code, string timeStart, string timeEnd)
- {
- //限制时间的指令
- string metesta_value = "";
- //要发送的指令字符串
- string strParams = "";
- try
- {
- //发送指令
- //判断指令的类型
- if (metesta == "01")
- {
- 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\"
- }
- if (metesta == "02" || metesta == "03")
- {
- //拼接时间指令参数
- metesta_value = timeStart.Replace(":", "") + timeEnd.Replace(":", "");
- 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\"
- }
- //增肌strParams为空判断
- 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 + ",1004,'" + commandId + "','" + userId + "','" + status + "','" + strParams + "')";
- sqlHelper.ExecuteNoParams(insertCommandSql, CommandType.Text);
- string reJson = "{\"commandId\":\"" + commandId + "\",\"status\":\"" + status + "\"}";
- return reJson;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- }
- }
|