public BasicResponse <ConfigInfo> GetConfigCacheByKey(ConfigCacheGetByKeyRequest configCacheRequest) { var configCache = ConfigCache.ConfigCacheInstance.Query(config => config.Name == configCacheRequest.Name).FirstOrDefault(); var configCacheResponse = new BasicResponse <ConfigInfo>(); configCacheResponse.Data = configCache; return(configCacheResponse); }
public BasicResponse SaveInspectionIn(SaveInspectionInRequest saveInspectionInRequest) { var saveTime = saveInspectionInRequest.SaveTime; //保存定义更新时间 if (Basic.Framework.Data.PlatRuntime.Items.ContainsKey("_DefUpdateTime")) { Basic.Framework.Data.PlatRuntime.Items["_DefUpdateTime"] = saveTime; } else { Basic.Framework.Data.PlatRuntime.Items.Add("_DefUpdateTime", saveTime); } //保存数据库 ConfigInfo tempConfig = new ConfigInfo(); tempConfig.Name = "defdatetime"; tempConfig.Text = saveTime.ToString("yyyy-MM-dd HH:mm:ss"); tempConfig.Upflag = "0"; ConfigCacheGetByKeyRequest configCacheRequest = new ConfigCacheGetByKeyRequest(); configCacheRequest.Name = "defdatetime"; var result = _ConfigCacheService.GetConfigCacheByKey(configCacheRequest); ConfigInfo tempConfigCache = result.Data; if (tempConfig != null) { tempConfig.ID = tempConfigCache.ID; tempConfig.InfoState = InfoState.Modified; //更新数据库 var request = ObjectConverter.Copy <ConfigInfo, ConfigModel>(tempConfig); _Repository.UpdateConfig(request); //更新缓存 ConfigCacheUpdateRequest UpdateConfigCacheRequest = new ConfigCacheUpdateRequest(); UpdateConfigCacheRequest.ConfigInfo = tempConfig; _ConfigCacheService.UpdateConfigCahce(UpdateConfigCacheRequest); } return(new BasicResponse()); }
/// <summary> /// 同步老广播系统测点定义 /// </summary> /// <returns></returns> public BasicResponse <bool> SynchronousPoint(SynchronousPointRequest PointDefineRequest) { BasicResponse <bool> response = new BasicResponse <bool>(); try { bool isupdate = false; if (PointDefineRequest.Points != null) { var points = _b_DefCacheService.Get(new B_DefCacheGetByConditionRequest { predicate = b => b.Sysid == (int)SystemEnum.Broadcast }).Data; bool isupdatedb = false;//是否更新数据库,如果只有状态发生改变,则只更新缓存数据;反之需要更新数据库 foreach (DataRow row in PointDefineRequest.Points.Rows) { var point = row["AddNum"].ToString(); //如果存在则比较更新测点信息;如果不存在则插入测点信息 if (points.FirstOrDefault(p => p.Point == point) != null) { Dictionary <string, object> paramater = new Dictionary <string, object>(); var definfo = points.FirstOrDefault(p => p.Point == point); //比较位置是否一致 if (definfo.Wz != row["Wz"].ToString()) { isupdatedb = true; definfo.Wzid = GetPositionId(row["Wz"].ToString()); definfo.Wz = row["Wz"].ToString(); paramater.Add("Wzid", GetPositionId(row["Wz"].ToString())); paramater.Add("Wz", row["Wz"].ToString()); } //比较区域是否一致 // 20180606 //var zoneId = row["ZoneId"]; if (row.Table.Columns.Contains("ZoneId") && row["ZoneId"] != null && row["ZoneId"].ToString() != "") { var req = new AreaCacheGetByConditionRequest(); req.Predicate = a => a.Areaid == definfo.Areaid; var res = _areaCacheService.GetAreaCache(req); var areaInfo = res.Data[0]; if (areaInfo.Areaname != row["Groupname"].ToString() || areaInfo.Areadescribe != row["ZoneId"].ToString()) { isupdatedb = true; definfo.Areaid = GetAreaId(row["Groupname"].ToString(), row["ZoneId"].ToString()); definfo.AreaName = row["Groupname"].ToString(); paramater.Add("Areaid", GetAreaId(row["Groupname"].ToString(), row["ZoneId"].ToString())); paramater.Add("AreaName", row["Groupname"].ToString()); paramater.Add("Areadescribe", row["ZoneId"].ToString()); } } else { if (definfo.AreaName != row["Groupname"].ToString()) { isupdatedb = true; definfo.Areaid = GetAreaId(row["Groupname"].ToString()); definfo.AreaName = row["Groupname"].ToString(); paramater.Add("Areaid", GetAreaId(row["Groupname"].ToString())); paramater.Add("AreaName", row["Groupname"].ToString()); } } //数据状态与设备状态不做比较,直接更新 var state = row["State"].ToString(); if (state == "0") { definfo.DataState = 3; definfo.State = 3; paramater.Add("DataState", 3); paramater.Add("State", 3); paramater.Add("Ssz", EnumHelper.GetEnumDescription(DeviceDataState.EquipmentAC)); } else if (state == "1") { definfo.DataState = 49; definfo.State = 3; paramater.Add("DataState", 49); paramater.Add("State", 3); paramater.Add("Ssz", EnumHelper.GetEnumDescription(DeviceDataState.BroadCastInCall)); } else if (state == "2") { definfo.DataState = 0; definfo.State = 0; paramater.Add("DataState", 0); paramater.Add("State", 0); paramater.Add("Ssz", EnumHelper.GetEnumDescription(DeviceDataState.EquipmentInterrupted)); } //比较Mac是否一致 if (definfo.Jckz1 != row["Mac"].ToString()) { isupdatedb = true; definfo.Jckz1 = row["Mac"].ToString(); paramater.Add("Jckz1", row["Mac"].ToString()); } //比较IP是否一致 if (definfo.Jckz2 != row["IP"].ToString()) { isupdatedb = true; definfo.Jckz2 = row["IP"].ToString(); paramater.Add("Jckz2", row["IP"].ToString()); } //比较设备类型是否一致 if (definfo.Bz6 != row["Type"].ToString()) { isupdatedb = true; definfo.Bz6 = row["Type"].ToString(); paramater.Add("Bz6", row["Type"].ToString()); } //更新数据库 if (isupdatedb) { isupdate = true; var _jc_Def = ObjectConverter.Copy <Jc_DefInfo, B_DefModel>(definfo); _repository.UpdateDef(_jc_Def); } //更新数据更新时间,每次调用都更新时间 20180422 paramater.Add("DttStateTime", DateTime.Now); //更新缓存 if (paramater.Count > 0) { UpdatePropertiesRequest updaterequest = new UpdatePropertiesRequest(); updaterequest.PointID = definfo.PointID; updaterequest.UpdateItems = paramater; _b_DefCacheService.UpdateInfo(updaterequest); } } else { var bdev = _devCacheService.GetPointDefineCache(new DeviceDefineCacheGetByConditonRequest { Predicate = dev => dev.Name == "广播主机" }).Data.FirstOrDefault(); if (bdev != null) { Jc_DefInfo bdefinfo = new Jc_DefInfo(); bdefinfo.ID = bdefinfo.PointID = IdHelper.CreateLongId().ToString(); bdefinfo.Wzid = GetPositionId(row["Wz"].ToString()); bdefinfo.Wz = row["Wz"].ToString(); // 20180606 //var zoneId = row["ZoneId"]; if (row.Table.Columns.Contains("ZoneId") && row["ZoneId"] != null && row["ZoneId"].ToString() != "") { bdefinfo.Areaid = GetAreaId(row["Groupname"].ToString(), row["ZoneId"].ToString()); bdefinfo.AreaName = row["Groupname"].ToString(); } else { bdefinfo.Areaid = GetAreaId(row["Groupname"].ToString()); bdefinfo.AreaName = row["Groupname"].ToString(); } bdefinfo.Point = point; bdefinfo.Upflag = "1";//子系统同步测点 bdefinfo.Jckz1 = row["Mac"].ToString(); bdefinfo.Jckz2 = row["IP"].ToString(); bdefinfo.Bz6 = row["Type"].ToString(); bdefinfo.CreateUpdateTime = DateTime.Now; bdefinfo.DeleteTime = DateTime.Parse("1900-01-01 00:00:00"); bdefinfo.Activity = "1"; bdefinfo.InfoState = InfoState.AddNew; bdefinfo.DevPropertyID = 0; bdefinfo.DevProperty = bdev.DevProperty; bdefinfo.Devid = bdev.Devid; bdefinfo.DevName = bdev.Name; bdefinfo.Sysid = (int)SystemEnum.Broadcast; bdefinfo.DttStateTime = DateTime.Now; var bdefinfos = _b_DefCacheService.Get(new B_DefCacheGetByConditionRequest { predicate = b => b.Sysid == (int)SystemEnum.Broadcast }).Data; //if (bdefinfos.Count == 0) //{ // bdefinfo.Fzh = 256; //} //else //{ // int maxstationnum = bdefinfos.Max(o => o.Fzh); // bdefinfo.Fzh = (short)(maxstationnum + 1); //} // 20180605 //生成分站号 var req = new B_DefCacheGetAllRequest(); var res = _b_DefCacheService.GetAll(req); var broadcastPoints = res.Data; short fzh = 0; for (int i = 257; i < 513; i++) { var exist = broadcastPoints.Any(a => a.Fzh == i); if (!exist) { fzh = (short)i; break; } } //var fzh = Convert.ToInt32(point) + 256; if (fzh == 0) { var ret = new BasicResponse <bool>(); ret.Code = 101; ret.Data = false; ret.Message = "广播设备对应分站号已满。"; return(ret); } bdefinfo.Fzh = fzh; isupdate = true; //添加数据库 var _jc_Def = ObjectConverter.Copy <Jc_DefInfo, B_DefModel>(bdefinfo); var resultjc_Def = _repository.AddDef(_jc_Def); //更新缓存 B_DefCacheInsertRequest addbDefCacheRequest = new B_DefCacheInsertRequest(); addbDefCacheRequest.B_DefInfo = bdefinfo; _b_DefCacheService.Insert(addbDefCacheRequest); } } } //判断同步数据是否有删除的测点信息,如果有则同步删除 for (int i = points.Count - 1; i >= 0; i--) { var pointrow = PointDefineRequest.Points.Select("AddNum = '" + points[i].Point + "'"); if (pointrow.Length == 0) { isupdate = true; //删除数据库 _repository.Delete(points[i].ID); //删除缓存 _b_DefCacheService.Delete(new B_DefCacheDeleteRequest { B_DefInfo = points[i] }); } } } if (isupdate) { var saveTime = DateTime.Now; //保存定义更新时间 if (Basic.Framework.Data.PlatRuntime.Items.ContainsKey("_DefUpdateTime")) { Basic.Framework.Data.PlatRuntime.Items["_DefUpdateTime"] = saveTime; } else { Basic.Framework.Data.PlatRuntime.Items.Add("_DefUpdateTime", saveTime); } //保存数据库 ConfigInfo tempConfig = new ConfigInfo(); tempConfig.Name = "defdatetime"; tempConfig.Text = saveTime.ToString("yyyy-MM-dd HH:mm:ss"); tempConfig.Upflag = "0"; ConfigCacheGetByKeyRequest configCacheRequest = new ConfigCacheGetByKeyRequest(); configCacheRequest.Name = "defdatetime"; var result = _configCacheService.GetConfigCacheByKey(configCacheRequest); ConfigInfo tempConfigCache = result.Data; if (tempConfig != null) { tempConfig.ID = tempConfigCache.ID; tempConfig.InfoState = InfoState.Modified; //更新数据库 var req2 = ObjectConverter.Copy <ConfigInfo, ConfigModel>(tempConfig); _configRepository.UpdateConfig(req2); //更新缓存 ConfigCacheUpdateRequest UpdateConfigCacheRequest = new ConfigCacheUpdateRequest(); UpdateConfigCacheRequest.ConfigInfo = tempConfig; _configCacheService.UpdateConfigCahce(UpdateConfigCacheRequest); } } response.Data = true; return(response); } catch (Exception ex) { LogHelper.Error("广播同步定义信息出错!" + ex.Message); response.Data = true; return(response); } }