Ejemplo n.º 1
0
        public BasicResponse <AreaInfo> AddArea(AreaAddRequest 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);
            var resultarea = _Repository.AddArea(_area);

            //更新区域限制、禁止进入人员信息
            SaveRestrictedperson(arearequest.AreaInfo.Areaid, arearequest.AreaInfo.RestrictedpersonInfoList);
            //更新区域识别器定义限制信息
            SaveAreaRule(arearequest.AreaInfo.Areaid, arearequest.AreaInfo.AreaRuleInfoList);

            //更新区域缓存  20171128
            AreaCacheAddRequest AreaCacheAddRequest = new Sys.Safety.Request.PersonCache.AreaCacheAddRequest();

            AreaCacheAddRequest.AreaInfo = arearequest.AreaInfo;
            _AreaCacheService.AddAreaCache(AreaCacheAddRequest);

            arearesponse.Data = ObjectConverter.Copy <AreaModel, AreaInfo>(resultarea);
            return(arearesponse);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取区域ID,如果不存在则添加区域
        /// </summary>
        /// <param name="areaname"></param>
        /// <param name="areadescribe"></param>
        /// <returns></returns>
        private string GetAreaId(string areaname, string areadescribe = null)
        {
            if (string.IsNullOrEmpty(areaname))
            {
                return("0");
            }

            string areaid = string.Empty;

            // 20180606
            AreaInfo areainfo;

            if (areadescribe == null)
            {
                areainfo = _areaCacheService.GetAreaCache(new AreaCacheGetByConditionRequest {
                    Predicate = a => a.Areaname == areaname
                }).Data.FirstOrDefault();
            }
            else
            {
                areainfo = _areaCacheService.GetAreaCache(new AreaCacheGetByConditionRequest {
                    Predicate = a => a.Areaname == areaname && a.Areadescribe == areadescribe
                }).Data.FirstOrDefault();
            }
            if (areainfo == null)
            {
                AreaInfo area = new AreaInfo();
                areaid                = IdHelper.CreateLongId().ToString();
                area.Areaid           = areaid;
                area.Areaname         = areaname;
                area.Areadescribe     = areadescribe;
                area.Activity         = "1";
                area.CreateUpdateTime = DateTime.Now;
                //更新数据库
                var _area      = ObjectConverter.Copy <AreaInfo, AreaModel>(area);
                var resultarea = _areaRepository.AddArea(_area);
                //更新区域缓存
                AreaCacheAddRequest AreaCacheAddRequest = new AreaCacheAddRequest();
                AreaCacheAddRequest.AreaInfo = ObjectConverter.Copy <AreaModel, AreaInfo>(resultarea);
                _areaCacheService.AddAreaCache(AreaCacheAddRequest);
            }
            else
            {
                areaid = areainfo.Areaid;
            }
            return(areaid);
        }