Exemple #1
0
        //只获取项目,包含项目下设备数据
        public async Task <BaseResponse> GetProjectByIdAsync(int Id)
        {
            var data = await _pr.FindWithImageAndChildAsync(a => a.Id == Id).FirstOrDefaultAsync();

            if (data == null)
            {
                return(new BaseResponse {
                    Success = false, Message = "输入的项目或者场站不存在"
                });
            }
            var dto = _mapper.Map <ProjectDto>(data);
            //获取项目下所有的场站
            var sites = await GetProjectSitesIdAsync(Id);

            //获取项目下设备的数量
            var count = await _dr.Find(a => sites.Contains(a.ProjectId.Value)).CountAsync();

            dto.DeviceCount = count;
            //获取项目的区域名称
            if (data.RegionId != null && "" != data.RegionId)
            {
                var r = await _rr.FindAsync(data.RegionId, data.GroupId);

                if (r != null)
                {
                    dto.RegionName = r.Name;
                }
            }
            return(new BResponse <ProjectDto> {
                Success = true, Message = "获取数据成功", Data = dto
            });
        }
Exemple #2
0
 public Task <Regions> Get(decimal id, CancellationToken cancellationToken)
 {
     return(_regionRepository.FindAsync(cancellationToken, id));
 }
Exemple #3
0
        public async Task <BaseResponse> AddRegionAsync(string account, string groupId, RegionAddDto req)
        {
            //检测parentId是否合法,不合法置为null
            if (req.ParentId != null && "" == req.ParentId.Trim())
            {
                req.ParentId = null;
            }
            //统一组织的,统一层级区域名称不能重复
            var data = await _rr.Find(a => a.GroupId == groupId && a.ParentId == req.ParentId && a.Name == req.Name).FirstOrDefaultAsync();

            if (data != null)
            {
                return(new BaseResponse {
                    Success = false, Message = "该区域下已存在相同的区域名称"
                });
            }
            RegionModel parent = null;

            try
            {
                bool   bP       = false;
                string fullPath = null;
                string regionId = "101";
                //生成区域标示
                if (req.ParentId != null)     //有父区域标示
                {
                    //获取父节点
                    parent = await _rr.FindAsync(req.ParentId, groupId);

                    if (parent == null)
                    {
                        return(new BaseResponse {
                            Success = false, Message = "输入的父节点不存在"
                        });
                    }
                    if (parent.DeleteId == null || "" == parent.DeleteId)//没有删除节点
                    {
                        //获取Id最大的节点
                        var bro = await _rr.Find(a => a.GroupId == groupId && a.ParentId == req.ParentId).OrderByDescending(a => a.Id).FirstOrDefaultAsync();

                        if (bro == null)
                        {
                            regionId = req.ParentId + "001";
                        }
                        else
                        {
                            string r  = bro.Id;
                            int    ir = Convert.ToInt32(r.Substring(r.Length - 3)) + 1;
                            regionId = r.Substring(0, r.Length - 3) + ir.ToString().PadLeft(3, '0');
                        }
                    }    //父节点没有删除节点
                    else //父节点有删除节点
                    {
                        bP = true;
                        string[] strDelete = parent.DeleteId.Split(',');
                        regionId = strDelete[0];
                        string[] arr = new string[strDelete.Length - 1];
                        //删除数组第一个元素
                        Array.Copy(strDelete, 1, arr, 0, arr.Length);
                        parent.DeleteId = string.Join(",", arr);
                    }
                    fullPath = parent.FullPath + "/" + regionId;
                }    //有父节点
                else //没有父节点
                {
                    req.ParentId = null;
                    if (req.RegionCode.Length != 3)
                    {
                        return(new BaseResponse {
                            Success = false, Message = "添加区域失败,区域的区域码必须为3位"
                        });
                    }
                    regionId = req.RegionCode;
                    fullPath = regionId;
                    //检测是否添加过
                    var top = await _rr.FindAsync(regionId, groupId);

                    if (top != null)
                    {
                        return(new BaseResponse {
                            Success = false, Message = "此区域已存在,添加失败"
                        });
                    }
                }
                var entity = _mapper.Map <RegionModel>(req);
                entity.GroupId  = groupId;
                entity.Id       = regionId;
                entity.Create   = account;
                entity.FullPath = fullPath;
                await _rr.AddAsync(entity, parent, bP);

                _log.LogInformation($"{account}添加标示为{new { entity.Id, entity.GroupId }}的区域成功");
                return new HandleResponse<object> { Success = true, Message = "添加区域成功", Key = new { Id = regionId, GroupId = groupId } };
            }
            catch (Exception ex)
            {
                _log.LogError($"{account}添加区域失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}");
                return(new BaseResponse {
                    Success = false, Message = "添加区域失败,请联系管理员"
                });
            }
        }