Exemplo n.º 1
0
        public async Task <ActionResult <BaseResponse> > Add(int typeId, TypeStatisticsAddViewModel req)
        {
            string Account = User.Claims.FirstOrDefault(a => a.Type == "Account").Value;
            //string user = User.Identity.Name;
            //if (string.IsNullOrWhiteSpace(user))
            //{
            //    return Unauthorized("用户凭证缺失");
            //}
            //UserMessage um = JsonConvert.DeserializeObject<UserMessage>(user);
            //string GroupId;
            //int status;
            //var ret = _ts.IsExist(typeId, out GroupId, out status);
            //if (!ret)
            //{
            //    return new BaseResponse { Success = false, Message = "输入的类型不存在" };
            //}
            //if (status == 0)
            //{
            //    return new BaseResponse { Success = false, Message = "目录节点类型不能添加具体数据" };
            //}
            //if (!(um.IsAdmin && (um.GroupId == GroupId || um.Code == _config["Group"])))
            //{
            //    return Unauthorized("用户没有权限");
            //}
            var rm = await _tss.AddStatistics(typeId, req, Account);

            return(rm);
        }
Exemplo n.º 2
0
        public async Task <BaseResponse> AddStatistics(int typeId, TypeStatisticsAddViewModel req, string account)
        {
            //验证类型是否可以添加
            var t = await _tr.FindAsync(typeId);

            if (t.Status == TypeStatus.Root)
            {
                return(new BaseResponse {
                    Success = false, Message = "目录节点类型不能添加具体数据"
                });
            }
            //验证数据定义是否存在
            var data = await _tdd.FindAsync(req.DataDefineId);

            if (data == null)
            {
                return(new BaseResponse {
                    Success = false, Message = "输入类型的数据定义不存在"
                });
            }
            //验证统计名称和数据定义key是否存在
            var count = _tsr.Find(a => a.TypeId == typeId && (a.Name == req.Name || a.DataKey == data.DataKey)).Count();

            if (count > 0)
            {
                return(new BaseResponse {
                    Success = false, Message = "此类型下已存在相同名称的统计数据或者相同的key值"
                });
            }
            try
            {
                var entity = _mapper.Map <TypeStatisticsInfoModel>(req);
                entity.TypeId  = typeId;
                entity.Create  = account;
                entity.DataKey = data.DataKey;
                entity.SUnit   = data.Unit;
                await _tsr.AddAsync(entity);

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