Exemplo n.º 1
0
        public BasicResponse <AreaInfo> UpdateArea(AreaUpdateRequest arearequest)
        {
            var arearesponse = new BasicResponse <AreaInfo>();
            //判断缓存中是否存在
            AreaInfo oldArea = null;
            AreaCacheGetByKeyRequest AreaCacheRequest = new AreaCacheGetByKeyRequest();

            AreaCacheRequest.Areaid = arearequest.AreaInfo.Areaid;
            oldArea = _AreaCacheService.GetByKeyAreaCache(AreaCacheRequest).Data;
            if (oldArea == null)
            {
                //缓存中存在此测点
                arearesponse.Code    = 1;
                arearesponse.Message = "当前更新的区域不存在!";
                return(arearesponse);
            }

            //向网关同步数据  20180103
            if (!string.IsNullOrEmpty(arearequest.AreaInfo.Bz3) && arearequest.AreaInfo.Bz3 == "1")//如果是广播分区,则需要向网关同步数据
            {
                List <AreaInfo> SendItemList = new List <AreaInfo>();
                SendItemList.Add(arearequest.AreaInfo);
                var resultSync = SynchronousDataToGateway(SendItemList);
                if (!resultSync)
                {
                    arearesponse.Code    = 1;
                    arearesponse.Message = "向网关同步数据失败!";
                    return(arearesponse);
                }
            }

            var _area = ObjectConverter.Copy <AreaInfo, AreaModel>(arearequest.AreaInfo);

            _Repository.UpdateArea(_area);
            //更新区域限制、禁止进入人员信息
            SaveRestrictedperson(arearequest.AreaInfo.Areaid, arearequest.AreaInfo.RestrictedpersonInfoList);
            //更新区域识别器定义限制信息
            SaveAreaRule(arearequest.AreaInfo.Areaid, arearequest.AreaInfo.AreaRuleInfoList);
            //更新区域缓存  20171128
            AreaCacheUpdateRequest AreaCacheUpdateRequest = new AreaCacheUpdateRequest();

            AreaCacheUpdateRequest.AreaInfo = arearequest.AreaInfo;
            _AreaCacheService.UpdateAreaCache(AreaCacheUpdateRequest);

            arearesponse.Data = ObjectConverter.Copy <AreaModel, AreaInfo>(_area);
            return(arearesponse);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 向网关同步数据
        /// </summary>
        /// <param name="SendItemList"></param>
        /// <returns></returns>
        private bool SynchronousDataToGateway(List <AreaInfo> SendItemList)
        {
            foreach (AreaInfo areaInfo in SendItemList)
            {
                PartitionControlRequest partitionControlRequest = new PartitionControlRequest();

                if (string.IsNullOrEmpty(areaInfo.Areadescribe))
                {
                    partitionControlRequest.zoneId = "";//分区标识
                }
                else
                {
                    partitionControlRequest.zoneId = areaInfo.Areadescribe; //分区标识
                }
                partitionControlRequest.paTaskDN    = "";                   //分区广播接入号码[暂未使用]
                partitionControlRequest.zoneName    = areaInfo.Areaname;    //分区名称
                partitionControlRequest.almLinkUdn1 = "";                   //分区报警联动用户号码列表[暂未使用]
                partitionControlRequest.almLinkUdn2 = "";                   //分区报警联动用户号码列表[暂未使用]
                partitionControlRequest.almLinkUdn3 = "";                   //分区报警联动用户号码列表[暂未使用]

                partitionControlRequest.InfoState = areaInfo.InfoState;
                //调用RPC发送
                MasProtocol masProtocol = new MasProtocol(SystemType.Broadcast, DirectionType.Down, ProtocolType.PartitionControlRequest);
                masProtocol.Protocol = partitionControlRequest;
                PartitionControlResponse result = RpcService.Send <PartitionControlResponse>(masProtocol, RequestType.BusinessRequest);

                if (result == null && result.retCode != "0")
                {
                    Basic.Framework.Logging.LogHelper.Error("向网关同步广播分区信息失败!,分区名称:" + areaInfo.Areaname);
                    return(false);
                }
                else
                {
                    //将返回的分区标识更新到缓存及数据库  20180103
                    areaInfo.Areadescribe = result.zoneId;
                    //更新数据库
                    var _area = ObjectConverter.Copy <AreaInfo, AreaModel>(areaInfo);
                    _Repository.UpdateArea(_area);
                    //更新区域缓存  20171128
                    AreaCacheUpdateRequest AreaCacheUpdateRequest = new AreaCacheUpdateRequest();
                    AreaCacheUpdateRequest.AreaInfo = areaInfo;
                    _AreaCacheService.UpdateAreaCache(AreaCacheUpdateRequest);
                }
            }
            return(true);
        }