예제 #1
0
        public async Task <ActionResult <BaseResponse> > GetTypeHardwareConfig(int typeId, [FromQuery] BasePageRequest req)
        {
            //string user = User.Identity.Name;
            //if (string.IsNullOrWhiteSpace(user))
            //{
            //    return Unauthorized("用户凭证缺失");
            //}
            //UserMessage um = JsonConvert.DeserializeObject<UserMessage>(user);
            //string GroupId;
            //var ret = _ts.IsExist(a => a.Id == typeId, out GroupId);
            //if (!ret)
            //{
            //    return new BaseResponse { Success = false, Message = "输入的类型不存在" };
            //}
            ////用户所在的组和超级管理员可以查看
            //if (um.GroupId != GroupId || (!um.IsAdmin && um.Code != _config["Group"]))
            //{
            //    return Unauthorized("用户没有权限");
            //}
            var rm = await _ths.GetTypeHardwareConfigAsync(typeId, req);

            return(rm);
        }
예제 #2
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);
        }