Ejemplo n.º 1
0
        public async Task <BaseResponse> GetTypeUpdateFile(int TypeId)
        {
            var ret = await _tu.Find(a => a.TypeId == TypeId).ToListAsync();

            var dtos = _mapper.Map <List <TypeUpdateFileData> >(ret);
            var rm   = new BResponse <List <TypeUpdateFileData> > {
                Success = true, Message = "获取数据成功", Data = dtos
            };

            return(rm);
        }
Ejemplo n.º 2
0
        public async Task <BaseResponse> GetUserRole(int UserId)
        {
            var ur = await _userrole.FindWithRole(UserId);

            var          urDto = _mapper.Map <List <UserRoleData> >(ur);
            BaseResponse br    = new BResponse <List <UserRoleData> > {
                Success = true, Message = "获取数据成功", Data = urDto
            };

            return(br);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取设备的最新一条历史数据
        /// </summary>
        /// <param name="DeviceSn">设备序列号</param>
        /// <returns>返回设备最新一条历史数据</returns>
        public async Task <BaseResponse> GetDeviceLatestHisDataAsync(string DeviceSn)
        {
            var data = await _dhr.FindWithDevice(a => a.DeviceSn == DeviceSn).OrderByDescending(a => a.Dt).FirstOrDefaultAsync();

            var dto = _mapper.Map <DeviceHisDataDto>(data);
            var br  = new BResponse <DeviceHisDataDto>()
            {
                Success = true,
                Message = "获取数据成功",
                Data    = dto
            };

            return(br);
        }
Ejemplo n.º 4
0
        public async Task <BaseResponse> GetAppVersionAsync()
        {
            var ret = await _avr.Find(a => true).OrderByDescending(a => a.CreateTime).FirstOrDefaultAsync();

            if (ret == null)
            {
                return(new BaseResponse {
                    Success = false, Message = "没有升级文件"
                });
            }
            var dto = _mapper.Map <AppVersionDto>(ret);
            var rm  = new BResponse <AppVersionDto> {
                Success = true, Message = "获取数据成功", Data = dto
            };

            return(rm);
        }
Ejemplo n.º 5
0
        public async Task <BaseResponse> GetFile(int Id)
        {
            var ret = await _tu.FindAsync(Id);

            if (ret == null)
            {
                return(new BaseResponse {
                    Success = false, Message = "输入的升级文件标示不存在"
                });
            }
            var dto = _mapper.Map <TypeUpdateFileData>(ret);
            var rm  = new BResponse <TypeUpdateFileData> {
                Success = true, Message = "获取数据成功", Data = dto
            };

            return(rm);
        }
Ejemplo n.º 6
0
        public async Task <BaseResponse> GetGroupAsync(string Id)
        {
            var gm = await _group.Find(a => a.Id == Id).FirstOrDefaultAsync();

            if (gm != null)
            {
                var br = new BResponse <GroupData>();
                br.Success = true;
                br.Message = "获取数据成功";

                br.Data = _mapper.Map <GroupData>(gm);
                return(br);
            }
            else
            {
                return(new BaseResponse()
                {
                    Success = false, Message = "该组织数据不存在"
                });
            }
        }
Ejemplo n.º 7
0
        public async Task <BaseResponse> GetUserAsync(int id)
        {
            var userInfo = await Task.Run(() =>
            {
                var user = _user.Find(id);
                if (user == null)
                {
                    return(new BaseResponse {
                        Success = false, Message = "该用户不存在"
                    });
                }
                var UserDto = _mapper.Map <UserData>(user);
                var br      = new BResponse <UserData>();
                br.Data     = UserDto;
                br.Success  = true;
                br.Message  = "获取用户数据成功";
                return(br);
            });

            return(userInfo);
        }
Ejemplo n.º 8
0
        public async Task <BaseResponse> GetRole(int RoleId)
        {
            BaseResponse br = new BaseResponse();

            br = await Task.Run(() =>
            {
                var ret = _role.Find(RoleId);
                if (ret == null)
                {
                    br.Success = false;
                    br.Message = "输入的角色编号不存在";
                    return(br);
                }
                var d = _mapper.Map <RoleDataDto>(ret);
                br    = new BResponse <RoleDataDto>()
                {
                    Success = true, Message = "获取数据成功", Data = d
                };
                return(br);
            });

            return(br);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 添加部门,已验证是否重名,调用端只需验证权限
        /// </summary>
        /// <param name="req">部门信息</param>
        /// <param name="groupId">组织编号</param>
        /// <returns>返回添加部门是否成功</returns>
        public async Task <BaseResponse> AddDepartmentAsync(DepartmentAddViewModel req, string account)
        {
            int          level = 1;
            string       pathId = null, pathName = null;
            BaseResponse rm = new BaseResponse();

            //查看是否存在多个顶级部门
            if (req.ParentId == null || req.ParentId.Value == 0)
            {
                if (req.DepartmentType == 1)
                {
                    return(new BaseResponse {
                        Success = false, Message = "不能直接添加岗位"
                    });
                }
                var dep = await _department.FindAsync(a => a.GroupId == req.GroupId && (a.ParentId.Value == 0 || a.ParentId == null));

                if (dep != null)
                {
                    return(new BaseResponse {
                        Success = false, Message = "一个组织只能添加一个顶级部门"
                    });
                }
            }
            else
            {
                var parent = await _department.FindAsync(req.ParentId.Value);

                if (parent == null)
                {
                    return(new BaseResponse {
                        Success = false, Message = "输入的父部门不存在"
                    });
                }
                level = parent.Level + 1;
                if (parent.ParentId == null)
                {
                    pathId   = parent.Id.ToString();
                    pathName = parent.DepartmentName;
                }
                else
                {
                    pathId   = $"{ parent.PathId}/{parent.Id}";
                    pathName = $"{parent.PathName}/{parent.DepartmentName}";
                }
                if (parent.DepartmentType == DepartmentType.Station)
                {
                    return(new BaseResponse {
                        Success = false, Message = "岗位下不能再添加部门或者岗位"
                    });
                }
            }

            //同一部门下的子部门不能重名
            var d = _department.Find(a => a.ParentId == req.ParentId && a.DepartmentName == req.Name && a.GroupId == req.GroupId).FirstOrDefault();

            if (d != null)
            {
                rm.Success = false;
                rm.Message = "该组织下存在相同的部门名称";
                return(rm);
            }
            try
            {
                var data = _map.Map <DepartmentModel>(req);
                data.Create   = account;
                data.GroupId  = req.GroupId;
                data.Level    = level;
                data.PathId   = pathId;
                data.PathName = pathName;
                await _department.AddAsync(data);

                rm = new BResponse <int>()
                {
                    Success = true,
                    Message = "添加数据成功",
                    Data    = data.Id
                };
                _log.LogInformation($"{account}添加id为{data.Id},名称为:{req.Name}的部门成功");
            }
            catch (Exception ex)
            {
                rm.Success = false;
                rm.Message = "添加数据失败";
                _log.LogError($"{account}添加名称为{req.Name}的部门失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}");
            }
            return(rm);
        }
Ejemplo n.º 10
0
        public async Task <BaseResponse> AddDeviceAsync(DeviceAddDto req, string account, string GroupId)
        {
            BaseResponse br = new BaseResponse();
            //查找是否存在相同的设备序号
            var device = _dr.Find(a => a.DeviceNo == req.DeviceNo);

            if (await device.FirstOrDefaultAsync() != null)
            {
                br.Success = false;
                br.Message = "该设备已存在,请确认";
                return(br);
            }
            //获取设备所属项目路径
            string pathId, PathName;

            if (req.ProjectId.HasValue && req.ProjectId.Value != 0)
            {
                var p = await _ps.GetProjectAsync(req.ProjectId.Value);

                if (p != null)
                {
                    //设备增加所属场站编号和名称
                    pathId   = $"{p.PathId}/{p.Id}";
                    PathName = $"{p.PathName}/{p.Name}";
                }
                else
                {
                    br.Success = false;
                    br.Message = "输入的场站不存在";
                    return(br);
                }
            }
            else
            {
                pathId   = null;
                PathName = null;
            }

            try
            {
                var entity = _mapper.Map <DeviceModel>(req);
                entity.DeviceSn = Guid.NewGuid().ToString("N");
                entity.Create   = account;
                entity.FullId   = pathId;
                entity.FullName = PathName;
                entity.GroupId  = GroupId;
                //获取类型硬件配置数据
                var data = await _th.GetTypeHardwareConfigAsync(req.TypeId);

                var dtos = _mapper.Map <List <TypeHardwareConfigModel>, List <DeviceHardwareConfigModel> >(data);
                foreach (var item in dtos)
                {
                    item.Device = entity;
                    item.Create = account;
                }
                await _dr.AddAsync(entity, dtos);

                br = new BResponse <string> {
                    Data = entity.DeviceSn, Success = true, Message = "添加设备成功"
                };
                _log.LogInformation($"{account}删除类型标示为{entity.DeviceSn}的设备数据成功");
            }
            catch (Exception ex)
            {
                _log.LogError($"{account}添加设备失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}");
                br.Success = false;
                br.Message = "添加设备失败,请联系管理员";
            }
            return(br);
        }