public HttpResponseMessage Logout(string token) { if (string.IsNullOrEmpty(token)) { return(Request.CreateResponse( HttpStatusCode.BadRequest, StringHelper.GetMessageString("token无效,登出失败"))); } this.auth.RemoveVerifyTicket(token); // 删除移动设备令牌 string deviceToken = this.Request.GetQueryString("deviceToken"); if (deviceToken != null) { using (var db = new SecureCloud_Entities()) { var item = db.T_DIM_DEVICETOKEN.Where(d => d.DeviceToken == deviceToken); if (item.Any()) { foreach (var i in item) { i.OnlineUser = null; } } db.SaveChanges(); } } return(Request.CreateResponse( HttpStatusCode.Accepted, StringHelper.GetMessageString("登出成功"))); }
public HttpResponseMessage Remove([FromUri] int userId) { using (var db = new SecureCloud_Entities()) { try { var user = db.T_DIM_USER.FirstOrDefault(u => u.USER_NO == userId); if (user == null || !user.USER_IS_ENABLED) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("用户不存在"))); } user.USER_IS_ENABLED = false; #region 日志信息 this.Request.Properties["ActionParameter"] = "userId:" + userId; this.Request.Properties["ActionParameterShow"] = "用户名:" + user.USER_NAME; #endregion db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("用户删除成功"))); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("用户删除失败"))); } } }
public HttpResponseMessage UpdateStructureAggConfig([FromUri] int configId, [FromBody] AggConfigData model) { using (var db = new SecureCloud_Entities()) { try { var config = (from aggconfig in db.T_DIM_AGG_CONFIG where aggconfig.Id == configId select aggconfig).First(); if (config == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("聚集配置不存在"))); } if (!IsConfigChanged(config, model)) { config.IsEnable = false; config.IsDelete = true; var newConfig = new T_DIM_AGG_CONFIG(); ToT_DIM_AGG_CONFIG(model, ref newConfig); db.Entry(config).State = System.Data.EntityState.Modified; db.Entry(newConfig).State = System.Data.EntityState.Added; db.SaveChanges(); SendAggConfigChangedMsg(); } return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("聚集配置修改成功"))); } catch (Exception) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("聚集配置修改失败"))); } } }
public HttpResponseMessage addProgressConfig([FromUri] int lineId, [FromBody] ProgressConfig config) { using (var db = new SecureCloud_Entities()) { try { IQueryable <T_DIM_STRUCTUER_PROGRESS> ProgressConfig = from q in db.T_DIM_STRUCTUER_PROGRESS where q.Line_Id == config.LineId && q.Construct_Length == config.ConstructLength && q.Unit == config.Unit && q.Up_Datatime == config.dataTime select q; if (ProgressConfig != null && ProgressConfig.Count() != 0) { //判断是否有重复 //#region 日志信息 //this.Request.Properties["ActionParameter"] = JsonConvert.SerializeObject(config); //this.Request.Properties["ActionParameterShow"] // = string.Format("进度编号:{0},线路编号:{1},施工长度:{2},长度单位:{3},配置时间:{4},进度颜色:{5}", // config.Id, // config.LineId, // config.ConstructLength, // config.Unit, // config.dataTime, // config.Color); //#endregion return(Request.CreateResponse(HttpStatusCode.NotAcceptable, StringHelper.GetMessageString("线路配置已存在"))); } var us = new T_DIM_STRUCTUER_PROGRESS { Id = config.Id, Line_Id = config.LineId, Construct_Length = config.ConstructLength, Unit = config.Unit, Up_Datatime = config.dataTime, }; db.T_DIM_STRUCTUER_PROGRESS.Add(us); db.SaveChanges(); //#region 日志信息 //this.Request.Properties["ActionParameter"] = JsonConvert.SerializeObject(us); //this.Request.Properties["ActionParameterShow"] // = string.Format("线路编号:{0},施工长度:{1},长度单位:{2},配置时间:{3},进度颜色:{4}", // us.Line_Id, // us.Construct_Length, // us.Unit, // us.Up_Datatime, // us.Color); //#endregion return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("线路进度添加成功"))); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("线路进度添加失败"))); } } }
// [LogInfo("修改进度信息", true)] public HttpResponseMessage ModifyProgress([FromUri] int progressId, [FromBody] ProgressConfig config) { using (var db = new SecureCloud_Entities()) { var paraShow = new StringBuilder(100); try { var configEntity = db.T_DIM_STRUCTUER_PROGRESS.FirstOrDefault(u => u.Id == progressId); if (configEntity == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("线路进度配置不存在"))); } if (config.LineId != default(int) && config.LineId != configEntity.Line_Id) { configEntity.Line_Id = config.LineId; paraShow.AppendFormat("线路编号改为:{0},", config.LineId); } if (config.ConstructLength != default(decimal) && config.ConstructLength != configEntity.Construct_Length) { configEntity.Construct_Length = config.ConstructLength; paraShow.AppendFormat("施工长度改为:{0},", config.ConstructLength); } if (config.Unit != default(string) && config.Unit != configEntity.Unit) { configEntity.Unit = config.Unit; paraShow.AppendFormat("长度单位改为:{0},", config.Unit); } //if (config.Color != default(string) && config.Color != configEntity.Color) //{ // configEntity.Color = config.Color; // paraShow.AppendFormat("颜色改为:{0},", config.Color); //} if (config.dataTime != default(DateTime) && config.dataTime != configEntity.Up_Datatime) { configEntity.Up_Datatime = config.dataTime; paraShow.AppendFormat("修改时间改为:{0},", config.dataTime); } var entry = db.Entry(configEntity); entry.State = System.Data.EntityState.Modified; //#region 日志信息 //this.Request.Properties["ActionParameter"] = JsonConvert.SerializeObject(config); //this.Request.Properties["ActionParameterShow"] = paraShow.ToString(); //#endregion db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("线路配置信息修改成功"))); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("线路配置信息修改失败"))); } } }
public HttpResponseMessage RemoveOrg(int orgId) { using (var entity = new SecureCloud_Entities()) { var org = entity.T_DIM_ORGANIZATION.FirstOrDefault(o => o.ID == orgId && o.IsDeleted != true); if (org == null) { return(Request.CreateResponse( HttpStatusCode.BadRequest, StringHelper.GetMessageString("组织不存在或已被删除"))); } org.IsDeleted = true; var entry = entity.Entry(org); entry.State = System.Data.EntityState.Modified; /****start*remove 自动删除用户关注组织关系,与该组织相关绑定也一并 删除*****/ var entryUserOrgs = from uo in entity.T_DIM_USER_ORG where uo.ORGANIZATION_ID == orgId select uo; foreach (var userOrg in entryUserOrgs) { var entryUserOrg = entity.Entry(userOrg); entryUserOrg.State = System.Data.EntityState.Deleted; } //用户与该组织下结构物的绑定,一并删除 var userOrgStructs = from us in entity.T_DIM_USER_STRUCTURE from os in entity.T_DIM_ORG_STUCTURE where os.ORGANIZATION_ID == orgId && us.STRUCTURE_ID == os.STRUCTURE_ID select us; foreach (var userOrgstr in userOrgStructs) { var entryUserOrgStr = entity.Entry(userOrgstr); entryUserOrgStr.State = System.Data.EntityState.Deleted; } /****end******/ #region 日志信息 this.Request.Properties["ActionParameterShow"] = "组织名称:" + org.ABB_NAME_CN; #endregion try { entity.SaveChanges(); return(Request.CreateResponse( HttpStatusCode.Accepted, StringHelper.GetMessageString("删除组织成功"))); } catch (Exception) { return(Request.CreateResponse( HttpStatusCode.BadRequest, StringHelper.GetMessageString("删除组织失败"))); } } }
public HttpResponseMessage AddGroupsJinRunXian([FromBody] SensorGroupJinRunXian model) { using (var db = new SecureCloud_Entities()) { try { var group = new T_DIM_GROUP(); group.GROUP_NAME = model.GroupName; group.GROUP_TYPE_ID = 3; var entry = db.Entry(group); entry.State = System.Data.EntityState.Added; var sensorIds = model.SensorList.Select(s => s.SensorId); var sensors = db.T_DIM_SENSOR.Where(s => sensorIds.Contains(s.SENSOR_ID)).ToList(); StringBuilder sb = new StringBuilder(); foreach (var sensor in model.SensorList) { sb.AppendFormat( "位置-{0}_高度-{1};", sensors.Where(s => s.SENSOR_ID == sensor.SensorId) .Select(s => s.SENSOR_LOCATION_DESCRIPTION) .FirstOrDefault(), sensor.Height); var sensorGroupJinRunXian = new T_DIM_SENSOR_GROUP_JINRUNXIAN(); sensorGroupJinRunXian.GROUP_ID = group.GROUP_ID; sensorGroupJinRunXian.SENSOR_ID = sensor.SensorId; sensorGroupJinRunXian.HEIGHT = sensor.Height; var test = db.Entry(sensorGroupJinRunXian); test.State = System.Data.EntityState.Added; } #region 日志 this.Request.Properties["ActionParameter"] = JsonConvert.SerializeObject(model); this.Request.Properties["ActionParameterShow"] = string.Format("组:{0},传感器:{1}", model.GroupName, sb); #endregion db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("测斜传感器组新增成功"))); } catch (NullReferenceException e) { return(Request.CreateResponse( HttpStatusCode.BadRequest, StringHelper.GetMessageString("测斜传感器组新增失败:参数无效"))); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("测斜传感器组新增失败"))); } } }
public HttpResponseMessage AddScheduleConfig([FromUri] int structId, [FromBody] LineConfig config) { using (var db = new SecureCloud_Entities()) { try { IQueryable <T_DIM_STRUCTUER_LINE> ScheduleConfig = from q in db.T_DIM_STRUCTUER_LINE where q.Id == config.LineId && q.Line_Name == config.LineName && q.Line_Length == config.LineLength && q.Start_Id == config.StartId && q.End_Id == config.EndId && q.Structure_Id == config.structureId select q; if (ScheduleConfig != null && ScheduleConfig.Count() != 0) { //判断是否有重复 //#region 日志信息 //this.Request.Properties["ActionParameter"] = JsonConvert.SerializeObject(config); //this.Request.Properties["ActionParameterShow"] // = string.Format("线路编号:{0},线路名称:{1},线路长度:{2},开始位置Id:{3},结束位置Id:{4},结构物Id:{5}", // config.LineId, // config.LineName, // config.LineLength, // config.StartId, // config.EndId, // config.structureId); //#endregion return(Request.CreateResponse(HttpStatusCode.NotAcceptable, StringHelper.GetMessageString("线路配置已存在"))); } var us = new T_DIM_STRUCTUER_LINE { Id = config.LineId, Line_Name = config.LineName, Line_Length = config.LineLength, Start_Id = config.StartId, End_Id = config.EndId, Structure_Id = config.structureId, Color = config.Color ?? null, Unit = config.Unit }; db.T_DIM_STRUCTUER_LINE.Add(us); db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("线路配置添加成功"))); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("线路配置添加失败"))); } } }
public HttpResponseMessage RemoveScheduleConfig([FromUri] int LineId) { using (var db = new SecureCloud_Entities()) { try { var config = db.T_DIM_STRUCTUER_LINE.FirstOrDefault(u => u.Id == LineId); if (config == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("线路配置不存在"))); } IQueryable <T_DIM_STRUCTUER_LINE> Line = from q in db.T_DIM_STRUCTUER_LINE where q.Id == LineId select q; foreach (var LineConfig in Line) { db.T_DIM_STRUCTUER_LINE.Remove(LineConfig); } //表T_DIM_STRUCTUER_PROGRESS的同步变动 IQueryable <T_DIM_STRUCTUER_PROGRESS> Progress = from p in db.T_DIM_STRUCTUER_PROGRESS where p.Line_Id == LineId select p; foreach (var ProgressConfig in Progress) { db.T_DIM_STRUCTUER_PROGRESS.Remove(ProgressConfig); } //#region 日志信息 //this.Request.Properties["ActionParameter"] = "Id:" + LineId; //this.Request.Properties["ActionParameterShow"] = // string.Format("线路编号:{0}, 线路名称: {1},结构物编号:{2}", // config.Id, // config.Line_Name, // config.Structure_Id); //#endregion db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("线路配置删除成功"))); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("线路配置删除失败"))); } } }
public void SaveVibrationData([FromBody] SensorCond form) { using (var db = new SecureCloud_Entities()) { var stringId = int.Parse(form.structId); var vibration = (from m1 in db.T_THEMES_VIBRATION_MICROSEISMIC where m1.struct_Id == stringId && m1.CollectTime == form.collectTime select m1).FirstOrDefault(); if (vibration != null) { var selectPt = from m2 in db.T_THEMES_VIBRATION_MICROSEISMIC_PTSELECT where m2.msId == vibration.Id select m2; foreach (var item in selectPt) { db.T_THEMES_VIBRATION_MICROSEISMIC_PTSELECT.Remove(item); } db.T_THEMES_VIBRATION_MICROSEISMIC.Remove(vibration); } T_THEMES_VIBRATION_MICROSEISMIC MS = new T_THEMES_VIBRATION_MICROSEISMIC(); MS.struct_Id = int.Parse(form.structId); MS.CollectTime = form.collectTime; MS.Coordinate_X = decimal.Parse(form.xyzt[0].ToString()); MS.Coordinate_Y = decimal.Parse(form.xyzt[1].ToString()); MS.Coordinate_Z = decimal.Parse(form.xyzt[2].ToString()); MS.Intensity = 0; long a = (long)form.xyzt[3] * 1000 * 10000; long ticks = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).Ticks + a; DateTime dt = new DateTime(ticks); MS.OccurrenceTime = dt; db.T_THEMES_VIBRATION_MICROSEISMIC.Add(MS); foreach (var item in form.items) { T_THEMES_VIBRATION_MICROSEISMIC_PTSELECT tp = new T_THEMES_VIBRATION_MICROSEISMIC_PTSELECT(); tp.msId = MS.Id; tp.SelectPt = int.Parse(item.sensorid); tp.SelectTime = decimal.Parse(item.t.ToString().Substring(0, 13)) / 1000; tp.WaveSpeed = decimal.Parse(item.speed.ToString()); db.T_THEMES_VIBRATION_MICROSEISMIC_PTSELECT.Add(tp); } db.SaveChanges(); } }
public HttpResponseMessage RemoveSectionHotspotConfig(string hotspots) { int[] arrHotspotId = hotspots.Split(',').Select(s => Convert.ToInt32(s)).ToArray(); StringBuilder sb = new StringBuilder(); sb.AppendFormat("共{0}条: ", arrHotspotId.Length); using (var entity = new SecureCloud_Entities()) { foreach (var hotspotId in arrHotspotId) { var hotspot = entity.T_DIM_HOTSPOT_SECTION.FirstOrDefault(s => s.SpotId == hotspotId); if (hotspot == null) { return(Request.CreateResponse( System.Net.HttpStatusCode.BadRequest, StringHelper.GetMessageString("施工截面热点配置不存在,删除施工截面热点配置失败"))); } #region 日志信息 sb.AppendFormat(" 截面:{0};", hotspot.T_DIM_SECTION.SectionName); #endregion DbEntityEntry <T_DIM_HOTSPOT_SECTION> entry = entity.Entry(hotspot); entry.State = EntityState.Deleted; } #region 日志信息 this.Request.Properties["ActionParameterShow"] = sb.ToString(); #endregion try { entity.SaveChanges(); return(Request.CreateResponse( System.Net.HttpStatusCode.Accepted, StringHelper.GetMessageString("删除施工截面热点配置成功"))); } catch (Exception ex) { return(Request.CreateResponse( System.Net.HttpStatusCode.BadRequest, StringHelper.GetMessageString("删除施工截面热点配置失败"))); } } }
public HttpResponseMessage RemoveReportConfigInfo([FromUri] int id) { using (var db = new SecureCloud_Entities()) { try { var config = db.T_REPORT_CONFIG.FirstOrDefault(u => u.Id == id); if (config == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("报表配置不存在或已被删除"))); } var entry = db.Entry(config); entry.State = System.Data.EntityState.Deleted; IQueryable <T_REPORT_CONFIG_TEMPLATE> congigTemp = from q in db.T_REPORT_CONFIG_TEMPLATE where q.ReportConfigId == id select q; foreach (var item in congigTemp) { var entry2 = db.Entry(item); entry2.State = System.Data.EntityState.Deleted; } #region 日志信息 this.Request.Properties["ActionParameter"] = "Id:" + id; this.Request.Properties["ActionParameterShow"] = string.Format("组织编号:{0}, 结构物编号: {1}, 报表名称:{2}", config.OrgId, config.StructId, config.ReportName ); #endregion db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("报表配置删除成功"))); } catch (Exception) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("报表配置删除失败"))); } } }
public HttpResponseMessage RemoveSection([FromUri] int sectionId) { using (var entity = new SecureCloud_Entities()) { var section = entity.T_DIM_SECTION.FirstOrDefault(s => s.SectionId == sectionId); if (section == null) { return(Request.CreateResponse( System.Net.HttpStatusCode.BadRequest, StringHelper.GetMessageString("施工截面不存在,删除施工截面失败"))); } // 删除传感器热点 var hotspots = entity.T_DIM_HOTSPOT.Where(w => w.SECTION_ID == sectionId); foreach (var hotspot in hotspots) { var entry1 = entity.Entry(hotspot); entry1.State = EntityState.Deleted; } // 删除施工截面热点 var sectionHotspot = entity.T_DIM_HOTSPOT_SECTION.Where(w => w.SectionId == sectionId); foreach (var shs in sectionHotspot) { var entry2 = entity.Entry(shs); entry2.State = EntityState.Deleted; } // 删除施工截面 var entry = entity.Entry(section); entry.State = EntityState.Deleted; try { entity.SaveChanges(); return(Request.CreateResponse( System.Net.HttpStatusCode.Accepted, StringHelper.GetMessageString("删除施工截面成功"))); } catch (Exception ex) { return(Request.CreateResponse( System.Net.HttpStatusCode.BadRequest, StringHelper.GetMessageString("删除施工截面失败"))); } } }
public object AddSection([FromUri] int structId, [FromBody] Section model) { using (var entity = new SecureCloud_Entities()) { var structure = entity.T_DIM_STRUCTURE.FirstOrDefault(s => s.ID == structId); if (structure == null) { return(Request.CreateResponse( System.Net.HttpStatusCode.BadRequest, StringHelper.GetMessageString("结构物不存在,新增截面失败"))); } if (entity.T_DIM_SECTION.Where(w => w.StructId == structId).Any(s => s.SectionName == model.SectionName)) { return(Request.CreateResponse( System.Net.HttpStatusCode.BadRequest, StringHelper.GetMessageString("该结构物已存在此截面名称,新增截面失败"))); } var section = new T_DIM_SECTION { SectionName = model.SectionName, SectionStatus = model.SectionStatus, HeapMapName = model.HeapMapName, StructId = structId }; var entry = entity.Entry(section); entry.State = EntityState.Added; try { entity.SaveChanges(); return (new JObject(new JProperty("sectionId", section.SectionId))); // 200: "OK" (新增施工截面成功) } catch (Exception ex) { return(Request.CreateResponse( System.Net.HttpStatusCode.BadRequest, StringHelper.GetMessageString("新增施工截面失败"))); } } }
public HttpResponseMessage ModifySection([FromUri] int sectionId, [FromBody] Section model) { using (var entity = new SecureCloud_Entities()) { var section = entity.T_DIM_SECTION.FirstOrDefault(s => s.SectionId == sectionId); if (section == null) { return(Request.CreateResponse( System.Net.HttpStatusCode.BadRequest, StringHelper.GetMessageString("结构物不存在,修改施工截面信息失败"))); } if (model.SectionName != default(string)) { section.SectionName = model.SectionName; } if (model.SectionStatus != default(int?)) { section.SectionStatus = model.SectionStatus; } if (model.HeapMapName != default(string)) { section.HeapMapName = model.HeapMapName; } var entry = entity.Entry(section); entry.State = EntityState.Modified; try { entity.SaveChanges(); return(Request.CreateResponse( System.Net.HttpStatusCode.Accepted, StringHelper.GetMessageString("修改施工截面信息成功"))); } catch (Exception ex) { return(Request.CreateResponse( System.Net.HttpStatusCode.BadRequest, StringHelper.GetMessageString("修改施工截面信息失败"))); } } }
public HttpResponseMessage AddMap(int dtuId, int structId) { using (var entity = new SecureCloud_Entities()) { if (entity.T_DIM_STRUCT_DTU.Any(d => d.DtuId == dtuId && d.StructureId == structId)) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("添加DTU失败"))); } // 添加关联关系 var sdEntity = new T_DIM_STRUCT_DTU(); sdEntity.DtuId = dtuId; sdEntity.StructureId = structId; var entry2 = entity.Entry(sdEntity); entry2.State = System.Data.EntityState.Added; #region 日志信息 var stc = entity.T_DIM_STRUCTURE.FirstOrDefault(s => s.ID == structId); var dtu = entity.T_DIM_REMOTE_DTU.FirstOrDefault(d => d.ID == dtuId); this.Request.Properties["ActionParameterShow"] = string.Format( "dtu号:{0},结构物:{1}", dtu == null ? string.Empty : dtu.REMOTE_DTU_NUMBER, stc == null ? string.Empty : stc.STRUCTURE_NAME_CN); #endregion try { entity.SaveChanges(); return(Request.CreateResponse( HttpStatusCode.Accepted, StringHelper.GetMessageString("添加DTU成功"))); } catch (Exception ex) { return(Request.CreateResponse( HttpStatusCode.BadRequest, StringHelper.GetMessageString("添加DTU失败"))); } } }
public HttpResponseMessage AddStructureAggConfig([FromBody] AggConfigData model) { using (var db = new SecureCloud_Entities()) { try { var newConfig = new T_DIM_AGG_CONFIG(); ToT_DIM_AGG_CONFIG(model, ref newConfig); db.Entry(newConfig).State = System.Data.EntityState.Added; db.SaveChanges(); SendAggConfigChangedMsg(); return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("聚集配置修改成功"))); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("聚集配置修改失败"))); } } }
public HttpResponseMessage Add([FromBody] SmsUser smsUser) { using (var db = new SecureCloud_Entities()) { var receiver = new T_WARNING_SMS_RECIEVER { RecieverName = smsUser.ReceiverName, RecieverPhone = smsUser.ReceiverPhone, RecieverMail = smsUser.ReceiverMail, RoleId = smsUser.RoleId, FilterLevel = smsUser.FilterLevel, UserNo = smsUser.UserId, ReceiveMode = smsUser.ReceiveMode, }; var entry = db.Entry(receiver); entry.State = System.Data.EntityState.Added; #region 日志信息 this.Request.Properties["ActionParameter"] = JsonConvert.SerializeObject(smsUser); this.Request.Properties["ActionParameterShow"] = string.Format( "接收人:{0},电话:{1},邮箱:{2},接收人角色:{3},接收等级:{4},接收模式:{5}", smsUser.ReceiverName, smsUser.ReceiverPhone, smsUser.ReceiverMail, smsUser.RoleId == 0 ? "用户" : "技术支持", smsUser.FilterLevel, smsUser.ReceiveMode ? "短信" : "邮箱"); #endregion try { db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("添加成功"))); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("添加失败"))); } } }
public object ModifySectionHotSpotConfig([FromUri] int hotspotId, [FromBody] SectionHotSpotConfig config) { using (var entity = new SecureCloud_Entities()) { var hotspot = entity.T_DIM_HOTSPOT_SECTION.FirstOrDefault(s => s.SpotId == hotspotId); if (hotspot == null) { return(Request.CreateResponse( System.Net.HttpStatusCode.BadRequest, StringHelper.GetMessageString("截面热点不存在,修改失败"))); } if (config.SectionId != default(int)) { hotspot.SectionId = config.SectionId; } if (config.SectionSpotX != default(decimal?)) { hotspot.Spot_X_Axis = config.SectionSpotX; } if (config.SectionSpotY != default(decimal?)) { hotspot.Spot_Y_Axis = config.SectionSpotY; } hotspot.SpotPath = config.SectionSpotPath == string.Empty ? null : config.SectionSpotPath; try { entity.SaveChanges(); return(Request.CreateResponse( System.Net.HttpStatusCode.Accepted, new JObject(new JProperty("hotspotId", hotspotId)).ToString())); } catch (Exception ex) { return(Request.CreateResponse( System.Net.HttpStatusCode.BadRequest, StringHelper.GetMessageString("修改截面热点失败"))); } } }
public HttpResponseMessage RemoveProgress([FromUri] int progressId) { using (var db = new SecureCloud_Entities()) { try { var config = db.T_DIM_STRUCTUER_PROGRESS.FirstOrDefault(u => u.Id == progressId); if (config == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("线路配置不存在"))); } IQueryable <T_DIM_STRUCTUER_PROGRESS> progress = from q in db.T_DIM_STRUCTUER_PROGRESS where q.Id == progressId select q; foreach (var ProgressConfig in progress) { db.T_DIM_STRUCTUER_PROGRESS.Remove(ProgressConfig); } //#region 日志信息 //this.Request.Properties["ActionParameter"] = "Line_Id:" + progressId; //this.Request.Properties["ActionParameterShow"] = // string.Format("线路编号:{0}, 施工长度: {1}", // config.Line_Id, // config.Construct_Length); //#endregion db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("线路进度配置删除成功"))); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("线路进度配置删除失败"))); } } }
public HttpResponseMessage Remove(int receiverId) { using (var db = new SecureCloud_Entities()) { var smsUser = db.T_WARNING_SMS_RECIEVER.FirstOrDefault(r => r.ReceiverId == receiverId); #region 日志信息 string sb = string.Empty; if (smsUser != null) { sb = string.Format( "接收人:{0},电话:{1},邮箱:{2},接收人角色:{3},接收等级:{4},接收模式:{5}", smsUser.RecieverName, smsUser.RecieverPhone, smsUser.RecieverMail, smsUser.RoleId == 0 ? "用户" : "技术支持", smsUser.FilterLevel, smsUser.ReceiveMode == null ? string.Empty : ((bool)smsUser.ReceiveMode ? "短信" : "邮箱")); } this.Request.Properties["ActionParameterShow"] = sb; #endregion var entry = db.Entry(smsUser); entry.State = System.Data.EntityState.Deleted; try { db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("添加成功"))); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("添加失败"))); } } }
public HttpResponseMessage AddSectionHotSpotConfig([FromBody] SectionHotSpotConfig config) { using (var entity = new SecureCloud_Entities()) { var section = entity.T_DIM_SECTION.FirstOrDefault(s => s.SectionId == config.SectionId); if (section == null) { return(Request.CreateResponse( System.Net.HttpStatusCode.BadRequest, StringHelper.GetMessageString("施工截面不存在,新增截面热点失败"))); } var hotspot = new T_DIM_HOTSPOT_SECTION { SectionId = config.SectionId, Spot_X_Axis = config.SectionSpotX, // xAxis Spot_Y_Axis = config.SectionSpotY, // yAxis SpotPath = config.SectionSpotPath }; var entry = entity.Entry(hotspot); entry.State = EntityState.Added; try { entity.SaveChanges(); return(Request.CreateResponse( System.Net.HttpStatusCode.Accepted, new JObject(new JProperty("hotspotId", hotspot.SpotId)).ToString())); } catch (Exception ex) { return(Request.CreateResponse( System.Net.HttpStatusCode.BadRequest, StringHelper.GetMessageString("新增施工截面热点失败"))); } } }
public HttpResponseMessage Modify([FromUri] int dtuId, [FromBody] DtuModel dtu) { using (var entity = new SecureCloud_Entities()) { var dtuEntity = entity.T_DIM_REMOTE_DTU.FirstOrDefault(d => d.ID == dtuId); if (dtuEntity == null || dtuEntity.REMOTE_DTU_STATE == false) { return(Request.CreateResponse( HttpStatusCode.BadRequest, StringHelper.GetMessageString("DTU不存在或已禁用"))); } StringBuilder sb = new StringBuilder(); string dtucode = dtuEntity.REMOTE_DTU_NUMBER; if (dtu.DtuNo != default(string) && dtu.DtuNo != dtuEntity.REMOTE_DTU_NUMBER) { dtuEntity.REMOTE_DTU_NUMBER = dtu.DtuNo; sb.AppendFormat("Dtu编号改为:{0},", dtu.DtuNo); } if (dtu.Granularity != default(int) && dtu.Granularity != dtuEntity.REMOTE_DTU_GRANULARITY) { dtuEntity.REMOTE_DTU_GRANULARITY = (short)dtu.Granularity; sb.AppendFormat("采集间隔改为:{0},", dtu.Granularity); } if (dtu.Sim != dtuEntity.REMOTE_DTU_SUBSCRIBER) { dtuEntity.REMOTE_DTU_SUBSCRIBER = dtu.Sim; sb.AppendFormat("sim卡号改为:{0},", dtu.Sim); } if (dtu.Ip != dtuEntity.DTU_IP) { dtuEntity.DTU_IP = dtu.Ip; sb.AppendFormat("Ip改为:{0},", dtu.Ip); } if (dtu.Port != dtuEntity.DTU_PORT) { dtuEntity.DTU_PORT = dtu.Port; sb.AppendFormat("端口改为:{0},", dtu.Port); } if (dtu.ProductId != default(int) && dtu.ProductId != dtuEntity.ProductDtuId) { dtuEntity.ProductDtuId = dtu.ProductId; var product = entity.T_DIM_DTU_PRODUCT.FirstOrDefault(p => p.ProductId == dtu.ProductId); if (product != null) { sb.AppendFormat("产品厂商改为{0},型号改为:{1}", product.DtuFactory, product.DtuModel); } else { sb.AppendFormat("产品id改为{0}", dtu.ProductId); } } if (dtu.P1 != dtuEntity.P1) { dtuEntity.P1 = dtu.P1; sb.AppendFormat("参数1改为:{0}", dtu.P1); } if (dtu.P2 != dtuEntity.P2) { dtuEntity.P2 = dtu.P2; sb.AppendFormat("参数2改为:{0}", dtu.P1); } if (dtu.P3 != dtuEntity.P3) { dtuEntity.P3 = dtu.P3; sb.AppendFormat("参数3改为:{0}", dtu.P1); } if (dtu.P4 != dtuEntity.P4) { dtuEntity.P4 = dtu.P4; sb.AppendFormat("参数4改为:{0}", dtu.P1); } #region 日志信息 this.Request.Properties["ActionParameter"] = JsonConvert.SerializeObject(dtu); this.Request.Properties["ActionParameterShow"] = string.Format("dtu号:{0}:{1}", dtu.DtuNo ?? string.Empty, sb); #endregion try { entity.SaveChanges(); var dtnod = new DtuNode { DtuId = (uint)dtuEntity.ID, Type = DtuType.Gprs, DtuCode = dtuEntity.REMOTE_DTU_NUMBER, NetworkType = dtuEntity.ProductDtuId == 2 ? NetworkType.hclocal : NetworkType.gprs, Name = dtuEntity.DESCRIPTION, DacInterval = dtuEntity.REMOTE_DTU_GRANULARITY == null ? DtuNode.DefaultDacInterval : (uint)dtuEntity.REMOTE_DTU_GRANULARITY }; if (dtnod.NetworkType == NetworkType.hclocal) { dtnod.AddProperty("param1", dtuEntity.P1); } WebClientService.SendToET(ConfigChangedMsgHelper.GetDtuConfigChangedMsg(ChangedStatus.Modify, dtnod, dtucode)); return(Request.CreateResponse( HttpStatusCode.Accepted, StringHelper.GetMessageString("DTU信息修改成功"))); } catch (Exception ex) { return(Request.CreateResponse( HttpStatusCode.BadRequest, StringHelper.GetMessageString("DTU信息修改失败"))); } } }
public HttpResponseMessage AddSensorWeight([FromBody] SensorWeightModel[] config) { var sb = new StringBuilder(50); using (var entity = new SecureCloud_Entities()) { foreach (SensorWeightModel m in config) { SensorWeightModel model = m; var orgStc = (from os in entity.T_DIM_ORG_STUCTURE where os.ORGANIZATION_ID == model.OrgId && os.STRUCTURE_ID == model.StructId select os).FirstOrDefault(); if (orgStc == null) { return(Request.CreateResponse( HttpStatusCode.BadRequest, StringHelper.GetMessageString("组织下不存在该结构物"))); } // 组织结构物代理键 var orgStcId = orgStc.ORG_STRUC_ID; // 对应权重数据 var wei = (from sw in entity.T_FACT_SENSOR_WEIGHTS where sw.ORG_STRUC_ID == orgStcId && sw.SENSOR_ID == model.SensorId select sw).FirstOrDefault(); if (wei == null) { // 数据不存在,新增 var weight = new T_FACT_SENSOR_WEIGHTS(); weight.SENSOR_ID = model.SensorId; weight.SENSOR_WEIGHTS = (byte)model.Weight; weight.ORG_STRUC_ID = orgStcId; var entry = entity.Entry(weight); entry.State = System.Data.EntityState.Added; } else { // 数据已存在,修改 wei.SENSOR_WEIGHTS = (byte)model.Weight; var entry = entity.Entry(wei); entry.State = System.Data.EntityState.Modified; } #region 日志信息 var org = entity.T_DIM_ORGANIZATION.Where(o => o.ID == m.OrgId) .Select(o => o.ABB_NAME_CN) .FirstOrDefault(); var stc = entity.T_DIM_STRUCTURE.Where(s => s.ID == m.StructId) .Select(s => s.STRUCTURE_NAME_CN) .FirstOrDefault(); var sensor = entity.T_DIM_SENSOR.Where(f => f.SENSOR_ID == m.SensorId) .Select(f => f.SENSOR_LOCATION_DESCRIPTION) .FirstOrDefault(); sb.AppendFormat( "组织:{0},结构物:{1},传感器:{2},权重:{3};", org ?? string.Empty, stc ?? string.Empty, sensor ?? string.Empty, m.Weight); #endregion } #region 日志信息 this.Request.Properties["ActionParameter"] = JsonConvert.SerializeObject(config); this.Request.Properties["ActionParameterShow"] = sb.ToString(); #endregion try { entity.Configuration.AutoDetectChangesEnabled = false; entity.Configuration.ValidateOnSaveEnabled = false; entity.SaveChanges(); return(Request.CreateResponse( HttpStatusCode.Accepted, StringHelper.GetMessageString("配置成功"))); } catch (Exception ex) { return(Request.CreateResponse( HttpStatusCode.BadRequest, StringHelper.GetMessageString("配置失败"))); } finally { entity.Configuration.AutoDetectChangesEnabled = true; entity.Configuration.ValidateOnSaveEnabled = true; } } }
public HttpResponseMessage RemoveSensor([FromUri] int sensorId) { using (var db = new SecureCloud_Entities()) { var sensor = db.T_DIM_SENSOR.FirstOrDefault(s => s.SENSOR_ID == sensorId && !s.IsDeleted); if (sensor == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("传感器不存在"))); } sensor.MODULE_NO *= -1; sensor.DAI_CHANNEL_NUMBER = (byte)(sensor.DAI_CHANNEL_NUMBER * -1); sensor.IsDeleted = true; //表T_DIM_SENSOR_CORRENT的同步变动 IQueryable <T_DIM_SENSOR_CORRENT> Corrent = from p in db.T_DIM_SENSOR_CORRENT where p.SensorId == sensorId || p.CorrentSensorId == sensorId//反向删除 select p; foreach (var CorrentConfig in Corrent) { db.T_DIM_SENSOR_CORRENT.Remove(CorrentConfig); } #region 日志信息 this.Request.Properties["ActionParameterShow"] = "传感器位置:" + sensor.SENSOR_LOCATION_DESCRIPTION; #endregion try { if (sensor.Identification != 2) { var sensorinfo = new Entity.Config.Sensor { DtuID = sensor.DTU_ID == null ? 0 : (uint)sensor.DTU_ID, SensorID = (uint)sensor.SENSOR_ID, StructId = sensor.STRUCT_ID == null ? 0 : (uint)sensor.STRUCT_ID, ModuleNo = sensor.MODULE_NO == null ? 0 : (uint)sensor.MODULE_NO, ChannelNo = sensor.DAI_CHANNEL_NUMBER == null ? 0 : (uint)sensor.DAI_CHANNEL_NUMBER, Name = sensor.SENSOR_LOCATION_DESCRIPTION, UnEnable = sensor.Enable//3-3 }; var senopera = new SensorOperation { Action = Operations.Delete, OldDtuId = sensorinfo.DtuID, OldSensorId = sensorinfo.SensorID, Sensor = sensorinfo }; WebClientService.SendToET(ConfigChangedMsgHelper.GetSensorConfigChangedMsg(senopera)); } db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("传感器删除成功"))); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("传感器删除失败"))); } } }
public HttpResponseMessage ModifySensor([FromUri] int sensorId, [FromBody] Sensor model) { using (var db = new SecureCloud_Entities()) { try { var sensor = db.T_DIM_SENSOR.FirstOrDefault(s => s.SENSOR_ID == sensorId && !s.IsDeleted); if (sensor == null) { return(Request.CreateResponse( HttpStatusCode.BadRequest, StringHelper.GetMessageString("传感器修改失败:传感器不存在或已删除"))); } int dtuid = sensor.DTU_ID.Value; StringBuilder sb = new StringBuilder(); var sensorLoc = sensor.SENSOR_LOCATION_DESCRIPTION; sb.AppendFormat("原传感器:{0}:", sensorLoc); if (model.FactorId != default(int) && model.FactorId != sensor.SAFETY_FACTOR_TYPE_ID) { sensor.SAFETY_FACTOR_TYPE_ID = model.FactorId; var fac = db.T_DIM_SAFETY_FACTOR_TYPE.Where(f => f.SAFETY_FACTOR_TYPE_ID == model.FactorId) .Select(f => f.SAFETY_FACTOR_TYPE_NAME) .FirstOrDefault(); sb.AppendFormat("监测因素改为:{0};", fac); } if (model.DtuId != default(int) && model.DtuId != sensor.DTU_ID) { sensor.DTU_ID = model.DtuId; var dtu = db.T_DIM_REMOTE_DTU.Where(d => d.ID == model.DtuId) .Select(d => d.REMOTE_DTU_NUMBER) .FirstOrDefault(); sb.AppendFormat("dtu号改为:{0};", dtu); } if (model.ModuleNo != default(int) && model.ModuleNo != sensor.MODULE_NO) { sensor.MODULE_NO = model.ModuleNo; sb.AppendFormat("模块号改为:{0};", model.ModuleNo); } if (model.Channel != null && model.Channel != sensor.DAI_CHANNEL_NUMBER) { sensor.DAI_CHANNEL_NUMBER = (byte?)model.Channel; sb.AppendFormat("通道改为:{0};", model.Channel); } //2-26 if (model.Enable != sensor.Enable) { sensor.Enable = model.Enable; sb.AppendFormat("使能改为:{0};", model.Enable); } if (model.ProductId != default(int) && model.ProductId != sensor.PRODUCT_SENSOR_ID) { sensor.PRODUCT_SENSOR_ID = model.ProductId; var pdt = db.T_DIM_SENSOR_PRODUCT.Where(p => p.PRODUCT_ID == model.ProductId) .Select(p => new { p.PRODUCT_NAME, p.PRODUCT_CODE }) .FirstOrDefault(); sb.AppendFormat("设备改为{0}({1});", pdt.PRODUCT_NAME, pdt.PRODUCT_CODE); } if (model.Location != default(string) && model.Location != sensor.SENSOR_LOCATION_DESCRIPTION) { sensor.SENSOR_LOCATION_DESCRIPTION = model.Location; sb.AppendFormat("位置标识改为{0};", model.Location); } if (model.Params != null) { var query = (from p in db.T_DIM_SENSOR_PRODUCT join fn in db.T_DIM_FORMULA_PARA on p.FORMAULAID equals fn.FormulaID into forluma from f in forluma.DefaultIfEmpty() join fname in db.T_DIM_FORMULA_PARA_NAME on f.ParaNameID equals fname.ParaNameID into name from n in name where p.PRODUCT_ID == model.ProductId orderby f.Order select new { f.FormulaParaID, n.ParaAlias }).ToList(); var para = (from q in query from v in model.Params where q.FormulaParaID == v.Id select new { q.FormulaParaID, v.Value }).ToList(); var paramStr = (from q in query from v in model.Params where q.FormulaParaID == v.Id select new { q.ParaAlias, v.Value }).ToList(); sb.AppendFormat( "参数修改为:{0}", string.Join( "-", paramStr.Select(p => string.Format("{0}:{1}", p.ParaAlias, p.Value)).ToArray())); var old = from o in db.T_DIM_FORMULAID_SET where o.SENSOR_ID == sensor.SENSOR_ID select o; foreach (var o in old) { db.Entry(o).State = System.Data.EntityState.Deleted; } var newParam = new T_DIM_FORMULAID_SET(); newParam.SENSOR_ID = sensor.SENSOR_ID; for (int i = 0; i < para.Count(); i++) { newParam.GetType() .GetProperty("FormulaParaID" + (i + 1)) .SetValue(newParam, para[i].FormulaParaID, null); newParam.GetType() .GetProperty("Parameter" + (i + 1)) .SetValue(newParam, (decimal?)para[i].Value, null); } db.Entry(newParam).State = System.Data.EntityState.Added; } //关联传感器 if (model.CorrentId != null) { var correntTable = from cp in db.T_DIM_SENSOR_CORRENT where cp.SensorId == sensorId select cp; foreach (var o in correntTable) { db.T_DIM_SENSOR_CORRENT.Remove(o); } var array = model.CorrentId.Split(','); for (int j = 0; j < array.Length; j++) { var correntSensor = new T_DIM_SENSOR_CORRENT(); correntSensor.SensorId = sensorId; var correntId = array.GetValue(j); correntSensor.CorrentSensorId = Convert.ToInt32(correntId); db.T_DIM_SENSOR_CORRENT.Add(correntSensor); db.SaveChanges(); } } #region 日志信息 this.Request.Properties["ActionParameter"] = JsonConvert.SerializeObject(model); this.Request.Properties["ActionParameterShow"] = sb.ToString(); #endregion db.SaveChanges(); if (sensor.Identification != 2) { Entity.Config.Sensor sensorinfo = GetSensor(sensor); var senopera = new SensorOperation { Sensor = sensorinfo, OldDtuId = (uint)dtuid, OldSensorId = sensorinfo.SensorID, Action = sensor.DTU_ID == dtuid ? Operations.Update : Operations.ChangedDtu }; WebClientService.SendToET(ConfigChangedMsgHelper.GetSensorConfigChangedMsg(senopera)); } return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("传感器修改成功"))); } catch (NullReferenceException e) { return(Request.CreateResponse( HttpStatusCode.BadRequest, StringHelper.GetMessageString("传感器修改失败:参数无效"))); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("传感器修改失败"))); } } }
public HttpResponseMessage AddSensor([FromBody] Sensor model) { using (var db = new SecureCloud_Entities()) { try { var sensor = new T_DIM_SENSOR(); sensor.STRUCT_ID = model.StructId; sensor.SAFETY_FACTOR_TYPE_ID = model.FactorId; sensor.DTU_ID = model.DtuId; sensor.MODULE_NO = model.ModuleNo; sensor.DAI_CHANNEL_NUMBER = (byte?)model.Channel; sensor.PRODUCT_SENSOR_ID = model.ProductId; sensor.SENSOR_LOCATION_DESCRIPTION = model.Location; sensor.IsDeleted = false; sensor.Identification = model.Identify; sensor.Enable = model.Enable; var entry = db.Entry(sensor); entry.State = System.Data.EntityState.Added; var query = (from p in db.T_DIM_SENSOR_PRODUCT join fn in db.T_DIM_FORMULA_PARA on p.FORMAULAID equals fn.FormulaID into forluma from f in forluma.DefaultIfEmpty() join fname in db.T_DIM_FORMULA_PARA_NAME on f.ParaNameID equals fname.ParaNameID into name from n in name where p.PRODUCT_ID == model.ProductId orderby f.Order select f.FormulaParaID).ToList(); var para = (from q in query from v in model.Params where q == v.Id select new { q, v.Value }).ToList(); var old = from o in db.T_DIM_FORMULAID_SET where o.SENSOR_ID == sensor.SENSOR_ID select o; foreach (var o in old) { db.Entry(o).State = System.Data.EntityState.Deleted; } var newParam = new T_DIM_FORMULAID_SET(); newParam.SENSOR_ID = sensor.SENSOR_ID; for (int i = 0; i < para.Count(); i++) { newParam.GetType().GetProperty("FormulaParaID" + (i + 1)).SetValue(newParam, para[i].q, null); newParam.GetType().GetProperty("Parameter" + (i + 1)).SetValue(newParam, (decimal?)para[i].Value, null); } db.Entry(newParam).State = System.Data.EntityState.Added; if (model.CorrentId != null) { var correntSensor = new T_DIM_SENSOR_CORRENT(); var array = model.CorrentId.Split(','); for (int j = 0; j < array.Length; j++) { correntSensor.SensorId = sensor.SENSOR_ID; var correntId = array.GetValue(j); correntSensor.CorrentSensorId = Convert.ToInt32(correntId); db.T_DIM_SENSOR_CORRENT.Add(correntSensor); db.SaveChanges(); } } #region 日志信息 var fac = db.T_DIM_SAFETY_FACTOR_TYPE.Where(f => f.SAFETY_FACTOR_TYPE_ID == model.FactorId) .Select(f => f.SAFETY_FACTOR_TYPE_NAME) .FirstOrDefault(); var dtu = db.T_DIM_REMOTE_DTU.Where(d => d.ID == model.DtuId) .Select(d => d.REMOTE_DTU_NUMBER) .FirstOrDefault(); var pdt = db.T_DIM_SENSOR_PRODUCT.Where(p => p.PRODUCT_ID == model.ProductId) .Select(p => new { p.PRODUCT_NAME, p.PRODUCT_CODE }) .FirstOrDefault(); this.Request.Properties["ActionParameter"] = JsonConvert.SerializeObject(model); this.Request.Properties["ActionParameterShow"] = string.Format( "位置:{0},监测因素:{1},dtu:{2},模块号:{3},通道号:{4},设备类型:{5},参数:{6}", string.IsNullOrEmpty(model.Location) ? string.Empty : model.Location, fac ?? string.Empty, dtu ?? string.Empty, model.ModuleNo, model.Channel, pdt == null ? string.Empty : string.Format("{0}({1})", pdt.PRODUCT_NAME, pdt.PRODUCT_CODE), model.Params == null ? string.Empty : string.Join(",", model.Params.Select(p => p.Value))); #endregion db.SaveChanges(); if (sensor.Identification != 2) { Entity.Config.Sensor sensorinfo = GetSensor(sensor); var senopera = new SensorOperation { Action = Operations.Add, Sensor = sensorinfo, OldDtuId = sensorinfo.DtuID, OldSensorId = sensorinfo.SensorID }; WebClientService.SendToET(ConfigChangedMsgHelper.GetSensorConfigChangedMsg(senopera)); } return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("传感器新增成功"))); } catch (NullReferenceException e) { return(Request.CreateResponse( HttpStatusCode.BadRequest, StringHelper.GetMessageString("传感器新增失败:参数无效"))); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("传感器新增失败"))); } } }
public object ModifyDtuRemoteConfig([FromUri] string messageId, [FromUri] int dtuId, [FromBody] DtuConfig dtuConfig) { // 查询 T_TASK_INSTANT 表获取数据: using (var entity = new SecureCloud_Entities()) { var dtuEntity = entity.T_DIM_REMOTE_DTU.FirstOrDefault(d => d.ID == dtuId); if (dtuEntity == null || dtuEntity.REMOTE_DTU_STATE == false) { return(ConstructJobject(dtuId, "DTU不存在或已禁用", HttpStatusCode.BadRequest)); } var query = from ti in entity.T_TASK_INSTANT where ti.MSG_ID == messageId select new { dtuId = ti.DTU_ID, data = ti.RESULT_JSON, time = ti.FINISHED, status = ti.RESULT_MSG }; var list = query.ToList(); if (list.Count == 0) { return(null); // 200: OK } if (list.Select(s => s.dtuId).FirstOrDefault() != dtuId) { return(ConstructJobject(dtuId, "任务中DTU和当前DTU不匹配", HttpStatusCode.BadRequest)); } var strData = list.Select(s => s.data).FirstOrDefault(); if (strData == null || strData.Trim() == "") { return(list.Select(s => new { result = JsonConvert.DeserializeObject(""), s.time, s.status }).FirstOrDefault()); } JObject jObj = list.Select(s => JObject.Parse(s.data)).FirstOrDefault(); DtuConfig.UpdateDtuConfig(dtuEntity, jObj, dtuConfig); #region 日志信息 this.Request.Properties["ActionParameter"] = JsonConvert.SerializeObject(dtuConfig); var dtuNo = entity.T_DIM_REMOTE_DTU.Where(w => w.ID == dtuId).Select(s => s.REMOTE_DTU_NUMBER).FirstOrDefault(); this.Request.Properties["ActionParameterShow"] = string.Format("DTU编号:{0},主中心ip:{1},主中心端口:{2},副中心2ip:{3},副中心2端口:{4}," + "DTU工作模式:{5},封包间隔时间:{6},重连次数:{7}", dtuNo, dtuConfig.Ip ?? string.Empty, dtuConfig.Port, dtuConfig.Ip2 ?? string.Empty, dtuConfig.Port2, string.IsNullOrEmpty(dtuConfig.DtuMode) ? string.Empty : dtuConfig.DtuMode, dtuConfig.PacketInterval, dtuConfig.ReconnectionCount ); #endregion try { entity.SaveChanges(); return(list.Select(s => new { result = JsonConvert.DeserializeObject(s.data), s.time, s.status }).FirstOrDefault()); } catch (Exception ex) { return(ConstructJobject(dtuId, "DTU信息修改失败", HttpStatusCode.BadRequest)); } } }
public HttpResponseMessage Remove(int dtuId, int structId) { using (var entity = new SecureCloud_Entities()) { var dtuEntity = entity.T_DIM_REMOTE_DTU.FirstOrDefault(d => d.ID == dtuId); if (dtuEntity == null || dtuEntity.REMOTE_DTU_STATE == false) { return(Request.CreateResponse( HttpStatusCode.BadRequest, StringHelper.GetMessageString("DTU不存在或已禁用"))); } // 检查传感器关联 var sens = entity.T_DIM_SENSOR.Where(s => s.DTU_ID == dtuId && !s.IsDeleted); if (sens.Any()) { return(Request.CreateResponse( HttpStatusCode.Conflict, StringHelper.GetMessageString("请先删除该DTU下的传感器"))); } // 删除关联 var sd = entity.T_DIM_STRUCT_DTU.Where(d => d.DtuId == dtuId && d.StructureId == structId); foreach (var m in sd) { entity.T_DIM_STRUCT_DTU.Remove(m); } // 检查关联 if (!entity.T_DIM_STRUCT_DTU.Any(d => d.DtuId == dtuId)) { dtuEntity.REMOTE_DTU_STATE = false; } #region 日志信息 var info = (from d in entity.T_DIM_REMOTE_DTU from s in entity.T_DIM_STRUCT_DTU from st in entity.T_DIM_STRUCTURE where d.ID == s.DtuId && d.ID == dtuId && s.StructureId == st.ID select new { d.REMOTE_DTU_NUMBER, st.STRUCTURE_NAME_CN }).FirstOrDefault(); var dtu = info == null ? string.Empty : info.REMOTE_DTU_NUMBER; var stc = info == null ? string.Empty : info.STRUCTURE_NAME_CN; this.Request.Properties["ActionParameterShow"] = string.Format("dtu号:{0}, 所属结构物:{1}", dtu, stc); #endregion try { var dtnod = new DtuNode { DtuId = (uint)dtuEntity.ID, Type = DtuType.Gprs, DtuCode = dtuEntity.REMOTE_DTU_NUMBER, Name = dtuEntity.DESCRIPTION, DacInterval = dtuEntity.REMOTE_DTU_GRANULARITY == null ? DtuNode.DefaultDacInterval : (uint)(dtuEntity.REMOTE_DTU_GRANULARITY * 60), NetworkType = dtuEntity.ProductDtuId == 2 ? NetworkType.hclocal : NetworkType.gprs }; if (dtnod.NetworkType == NetworkType.hclocal) { dtnod.AddProperty("param1", dtuEntity.P1); } entity.SaveChanges(); WebClientService.SendToET(ConfigChangedMsgHelper.GetDtuConfigChangedMsg(ChangedStatus.Delete, dtnod)); return(Request.CreateResponse( HttpStatusCode.Accepted, StringHelper.GetMessageString("DTU删除成功"))); } catch (Exception ex) { return(Request.CreateResponse( HttpStatusCode.BadRequest, StringHelper.GetMessageString("DTU删除失败"))); } } }
public HttpResponseMessage Add([FromBody] DtuModel dtu) { using (var entity = new SecureCloud_Entities()) { // 新增dtu var dtuEntity = new T_DIM_REMOTE_DTU(); dtuEntity.REMOTE_DTU_NUMBER = dtu.DtuNo; dtuEntity.REMOTE_DTU_SUBSCRIBER = dtu.Sim; dtuEntity.REMOTE_DTU_GRANULARITY = (short)dtu.Granularity; dtuEntity.DTU_IP = dtu.Ip; dtuEntity.DTU_PORT = dtu.Port; dtuEntity.P1 = dtu.P1; dtuEntity.P2 = dtu.P2; dtuEntity.P3 = dtu.P3; dtuEntity.P4 = dtu.P4; dtuEntity.ProductDtuId = dtu.ProductId; dtuEntity.REMOTE_DTU_STATE = true; var entry = entity.Entry(dtuEntity); entry.State = System.Data.EntityState.Added; // 添加关联关系 var sdEntity = new T_DIM_STRUCT_DTU(); sdEntity.DtuId = dtuEntity.ID; sdEntity.StructureId = dtu.StructId; var entry2 = entity.Entry(sdEntity); entry2.State = System.Data.EntityState.Added; #region 日志信息 var stc = entity.T_DIM_STRUCTURE.FirstOrDefault(s => s.ID == dtu.StructId); var product = entity.T_DIM_DTU_PRODUCT.FirstOrDefault(p => p.ProductId == dtu.ProductId); var paramName1 = (product != null && product.NetworkType.ToLower().Contains("local")) ? "文件路径" : "参数1"; this.Request.Properties["ActionParameter"] = JsonConvert.SerializeObject(dtu); this.Request.Properties["ActionParameterShow"] = string.Format( "dtu号:{0},结构物:{1},采集粒度:{3},产品厂商:{6},产品型号:{7},sim卡号:{2},ip地址:{4},端口:{5},[{12}:{8},参数2:{9},参数3:{10},参数4:{11}]", dtu.DtuNo ?? string.Empty, stc == null ? string.Empty : stc.STRUCTURE_NAME_CN, dtu.Sim ?? string.Empty, dtu.Granularity, dtu.Ip, dtu.Port, product != null ? product.DtuFactory : string.Empty, product != null ? product.DtuModel : string.Empty, dtu.P1, dtu.P2, dtu.P3, dtu.P4, paramName1); #endregion try { entity.SaveChanges(); var dtnod = new DtuNode { DtuId = (uint)dtuEntity.ID, Type = DtuType.Gprs, DtuCode = dtuEntity.REMOTE_DTU_NUMBER, Name = dtuEntity.DESCRIPTION, DacInterval = dtuEntity.REMOTE_DTU_GRANULARITY == null ? DtuNode.DefaultDacInterval : (uint)(dtuEntity.REMOTE_DTU_GRANULARITY * 60), NetworkType = dtuEntity.ProductDtuId == 2 ? NetworkType.hclocal : NetworkType.gprs }; if (dtnod.NetworkType == NetworkType.hclocal) { dtnod.AddProperty("param1", dtuEntity.P1); } WebClientService.SendToET(ConfigChangedMsgHelper.GetDtuConfigChangedMsg(ChangedStatus.Add, dtnod)); return(Request.CreateResponse( HttpStatusCode.Accepted, StringHelper.GetMessageString("添加DTU成功"))); } catch (Exception ex) { return(Request.CreateResponse( HttpStatusCode.BadRequest, StringHelper.GetMessageString("添加DTU失败"))); } } }