예제 #1
0
        public async Task <IActionResult> GetHealthIndicatorList(string userGuid)
        {
            if (string.IsNullOrEmpty(userGuid))
            {
                return(Failed(ErrorCode.Empty, "会员参数为空"));
            }

            var health = new HealthIndicatorBiz();

            return(Success(await health.GetHealthIndicatorList(userGuid)));
        }
예제 #2
0
        public async Task <IActionResult> GetHealthIndicatorOptions(string indicatorGuid,
                                                                    string userGuid)
        {
            if (string.IsNullOrEmpty(userGuid))
            {
                return(Failed(ErrorCode.Empty, "会员参数为空"));
            }

            if (string.IsNullOrEmpty(indicatorGuid))
            {
                return(Failed(ErrorCode.Empty, "指标id不能为空"));
            }

            var health = new HealthIndicatorBiz();

            var options = await health.GetHealthIndicatorOptionList(indicatorGuid, userGuid);

            return(Success(options));
        }
        public async Task <IActionResult> GeHealthIndicatorListtAsync(string userId)
        {
            if (string.IsNullOrWhiteSpace(userId))
            {
                userId = UserID;
            }
            HealthIndicatorBiz health = new HealthIndicatorBiz();
            var healthIndicatorList   = await health.GetHealthIndicatorList();

            if (healthIndicatorList == null)
            {
                return(Success(healthIndicatorList));
            }
            healthIndicatorList = healthIndicatorList.GroupBy(s => s.IndicatorGuid).Select(s => new GetHealthIndicatorResponseDto
            {
                IndicatorGuid = s.Key,
                IndicatorName = s.FirstOrDefault().IndicatorName,
                IndicatorType = s.FirstOrDefault().IndicatorType,
                MaxValue      = s.FirstOrDefault()?.MaxValue,
                MinValue      = s.FirstOrDefault()?.MinValue,
                OptionName    = s.FirstOrDefault().OptionName,
                OptionUnit    = s.FirstOrDefault().OptionUnit,
                OptionGuid    = s.FirstOrDefault().OptionGuid
            }).ToList();
            foreach (var item in healthIndicatorList)
            {
                //单个值
                if (!item.IndicatorType)
                {
                    item.IndicatorName = item.OptionName;
                    //查找用户的最近数据
                    item.ResultVale = await health.GetHealthIndicatorValue(userId, item.IndicatorGuid, item.OptionGuid);
                }
            }
            //给第一条数据添加建议
            if (healthIndicatorList.Count > 0)
            {
                healthIndicatorList.FirstOrDefault().Suggestion = await health.GetHealthIndicatorSuggestion(userId);
            }
            return(Success(healthIndicatorList));
        }
예제 #4
0
        public async Task <IActionResult> CreateConsumerHealthIndicatorOptions([FromBody]
                                                                               CreateHealthIndicatorRequestDto request)
        {
            if (request is null)
            {
                return(Failed(ErrorCode.Empty, "参数为空,请检查!"));
            }

            var options = request.Options;

            if (options.Count == 0)
            {
                return(Failed(ErrorCode.Empty, "对应健康指标项为空,请检查!"));
            }

            var userBiz = new UserBiz();
            var model   = await userBiz.GetAsync(request.UserGuid);

            if (model is null || !model.Enable)
            {
                return(Failed(ErrorCode.Empty, "指定会员不存在"));
            }

            var healthInDicatorBiz = new HealthIndicatorBiz();

            var healthIndicator = await healthInDicatorBiz.GetAsync(request.IndicatorGuid);

            if (healthIndicator == null)
            {
                return(Failed(ErrorCode.Empty, "对应健康指标未找到,参数错误!"));
            }

            if (!healthIndicator.IndicatorType && request.Options.All(d => !d.IndicatorValue.HasValue))
            {
                return(Failed(ErrorCode.Empty, "单指标必须提供值,请检查!"));
            }

            var groupOptions = options.GroupBy(s => s.OptionGuid);

            foreach (var groupOption in groupOptions.Select((x, i) => new { Index = i + 1, Value = x }))
            {
                if (groupOption.Value.Count() > 1)
                {
                    return(Failed(ErrorCode.Empty, $"第【{groupOption.Index}】个指标项有重复,请检查!"));
                }
            }

            var optionGuids = options.Select(s => s.OptionGuid).Distinct();

            //判断是否存在必填的选项
            var healthIndicatorOptions = await healthInDicatorBiz.GetHealthIndicatorOptionAsync(request.IndicatorGuid);

            if (healthIndicatorOptions is null || healthIndicatorOptions.Count <= 0)
            {
                return(Failed(ErrorCode.DataBaseError, "健康指标选项不存在"));
            }

            var dbOptionGuids = healthIndicatorOptions.Select(s => s.OptionGuid);

            //全局匹配差集
            var infoCheckResult = optionGuids.Except(dbOptionGuids).ToList();

            if (infoCheckResult != null && infoCheckResult.Count() > 0)
            {
                return(Failed(ErrorCode.DataBaseError, "提交有不存在的健康指标项,请检查!"));
            }

            //必须有的选项值
            var dbRequiredOptionGuids = healthIndicatorOptions.Where(s => s.Required)
                                        .Select(s => s.OptionGuid);

            //差集
            var infoResult = dbRequiredOptionGuids.Except(optionGuids).ToList();

            if (infoResult != null && infoResult.Count > 0)
            {
                return(Failed(ErrorCode.Empty, "健康指标选项必填项不能为空"));
            }

            var recordGuid = Guid.NewGuid().ToString("N");

            var indicatorModel = new ConsumerIndicatorModel()
            {
                IndicatorRecordGuid = recordGuid,
                IndicatorGuid       = request.IndicatorGuid,
                UserGuid            = request.UserGuid,
                CreatedBy           = UserID,
                LastUpdatedBy       = UserID
            };

            var indicatorDetailModels = request.Options.Select(s => new ConsumerIndicatorDetailModel
            {
                RecordDetailGuid    = Guid.NewGuid().ToString("N"),
                IndicatorRecordGuid = recordGuid,
                IndicatorOptionGuid = s.OptionGuid,
                IndicatorValue      = s.IndicatorValue,
                CreatedBy           = UserID,
                CreationDate        = DateTime.Now,
                LastUpdatedDate     = DateTime.Now
            }).ToList();

            var result = await healthInDicatorBiz.CreateConsumerHealthIndicatorAsync(indicatorModel, indicatorDetailModels);

            return(result ? Success() : Failed(ErrorCode.DataBaseError, "创建健康指标失败"));
        }