/// <summary> /// 设备组同步 /// </summary> /// <param name="obj"></param> public void DeviceGroupSynchronize(object obj) { try { string sql = @"select S_groupID,S_groupN,S_groupDes,S_groupToken,S_groupRoles,N_OrderBy from T_RTIOT_devicegroups where S_ISUSE='1' and S_UpdateFlag='1' and S_TenantID_FK='" + tenantid + "'"; DataTable dt = DbHelperSQL.Query(sql).Tables[0]; for (int i = 0; i < dt.Rows.Count; i++) { string ret = sm.getDeviceGroupByToken(dt.Rows[i]["S_groupToken"].ToString().Trim()); List <string> role = dt.Rows[i]["S_groupRoles"].ToString().Trim().Split('|').ToList(); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("TabPage", dt.Rows[i]["S_groupID"].ToString().Trim()); dic.Add("N_OrderBy", dt.Rows[i]["N_OrderBy"].ToString().Trim()); if (!string.IsNullOrEmpty(ret)) { sm.updateDeviceGroup(dt.Rows[i]["S_groupToken"].ToString().Trim(), dt.Rows[i]["S_groupN"].ToString().Trim(), dt.Rows[i]["S_groupDes"].ToString().Trim(), role, dic); } else { Group2 g = JsonConvert.DeserializeObject <Group2>(sm.createDeviceGroup(dt.Rows[i]["S_groupID"].ToString().Trim(), dt.Rows[i]["S_groupN"].ToString().Trim(), dt.Rows[i]["S_groupDes"].ToString().Trim(), role, dic)); sm.UpdateToken("T_RTIOT_devicegroups", "S_groupToken='" + g.token + "'", "S_groupID='" + dt.Rows[i]["S_groupID"].ToString().Trim() + "'"); } sm.UpdateFlag("T_RTIOT_devicegroups", "S_groupID='" + dt.Rows[i]["S_groupID"].ToString().Trim() + "'"); } } catch (Exception e) { logger.Error("DeviceGroupSynchronize异常:" + e.Message); } }
public string updateDeviceGroup(string groupToken, string name, string description, List <string> itemrole, Dictionary <string, string> dic) { Group2 g = new Group2(); g.groupToken = groupToken; g.name = name; g.description = description; g.roles = itemrole; g.metadata = dic; string data = JsonConvert.SerializeObject(g); string ret = gp.HttpPut("http://" + httpurl + "/sitewhere/api/devicegroups/" + groupToken, data, tenanttoken); return(ret); }
public string createDeviceGroup(string S_groupID, string name, string description, List <string> itemrole, Dictionary <string, string> dic) { Group2 g = new Group2(); g.groupToken = Guid.NewGuid().ToString("N"); g.name = name; g.description = description; g.roles = itemrole; g.metadata = dic; string data = JsonConvert.SerializeObject(g); string ret = gp.HttpPost("http://" + httpurl + "/sitewhere/api/devicegroups", data, tenanttoken); return(ret); }