コード例 #1
0
        public async Task <IActionResult> GetHealthInformationAsync(string userGuid)
        {
            if (string.IsNullOrEmpty(userGuid))
            {
                return(Failed(ErrorCode.Empty, "请指定会员"));
            }

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

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

            var informationBiz = new HealthInformationBiz();
            var informations   = await informationBiz.GetHealthInformationList(userGuid);

            GetUserHealthInformationResponseDto result = new GetUserHealthInformationResponseDto
            {
                UserName              = model.UserName,
                Birthday              = model.Birthday,
                Gender                = model.Gender,
                IdentityNumber        = model.IdentityNumber,
                HealthInformationList = informations
            };

            return(Success(result));
        }
コード例 #2
0
        public async Task <IActionResult> UpdateHealthReport([FromBody] CreateOrUpdateHealthReportRequestDto request)
        {
            var healthBiz = new HealthBiz();

            if (string.IsNullOrEmpty(request.UserGuid))
            {
                return(Failed(ErrorCode.Empty, "请指定检验报告所属会员"));
            }

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

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

            if (string.IsNullOrEmpty(request.ReportGuid))
            {
                return(Failed(ErrorCode.Empty, "请指定编辑报告"));
            }

            if (string.IsNullOrEmpty(request.Suggestion) && request.Suggestion.Length > 1000)
            {
                return(Failed(ErrorCode.Empty, "报告建议超过最大长度限制"));
            }

            if (request.Attachments is null || request.Attachments.Count <= 0)
            {
                return(Failed(ErrorCode.Empty, "请上传报告附件"));
            }

            if (await healthBiz.CheckReportName(request.ReportName, request.ReportGuid))
            {
                return(Failed(ErrorCode.Empty, $"报告名称“{request.ReportName}”已存在"));
            }

            var model = await healthBiz.GetConsumerHealthReport(request.ReportGuid);

            model.ReportName      = request.ReportName;
            model.Suggestion      = request.Suggestion;
            model.LastUpdatedBy   = UserID;
            model.LastUpdatedDate = DateTime.Now;

            (List <ConsumerHealthReportDetailModel> detailModels, string errorMsg) = FilterReportAttachments(request.Attachments, model.ReportGuid);

            if (detailModels is null && !string.IsNullOrEmpty(errorMsg))
            {
                return(Failed(ErrorCode.Empty, errorMsg));
            }

            var result = await healthBiz.UpdateHealthReport(model, detailModels.ToList());

            return(result ? Success() : Failed(ErrorCode.DataBaseError, "编辑检验报告失败"));
        }
コード例 #3
0
        public async Task <IActionResult> GetConsumerBasicInfo(string userGuid)
        {
            if (string.IsNullOrEmpty(userGuid))
            {
                return(Failed(ErrorCode.Empty, "请指定上传会员"));
            }

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

            return(Success(model == null ? (null) : new { model.NickName, model.Phone }));
        }
コード例 #4
0
        public async Task <IActionResult> GetMemberInfoAsync(string userGuid)
        {
            if (string.IsNullOrWhiteSpace(userGuid))
            {
                return(Failed(ErrorCode.UserData));
            }
            UserBiz userBiz = new UserBiz();
            var     ressult = await userBiz.GetAsync(userGuid);

            if (ressult == null)
            {
                return(Failed(ErrorCode.UserData, "userGuid错误"));
            }
            var response = ressult.ToDto <GetMemberInfoResponseDto>();
            //获取用户消费信息
            var consumer = await userBiz.GetConsumerAsync(userGuid);

            if (consumer != null)
            {
                response.LastBuyDate      = (DateTime?)consumer?.LastBuyDate;
                response.OrderAverage     = (decimal)consumer?.OrderAverage;
                response.OrderQty         = (int)consumer?.OrderQty;
                response.OrderTotalAmount = (decimal)consumer?.OrderTotalAmount;
            }
            //消费者
            var consumer2 = await new ConsumerBiz().GetAsync(userGuid);

            if (consumer2 != null)
            {
                response.Recommended = (await userBiz.GetAsync(consumer2.RecommendGuid))?.UserName;
            }
            var address = new AddressBiz().GetUserDefaultAddress(userGuid);

            response.Address = $"{address?.Province}{address?.City}{address?.Area}{address?.DetailAddress}";
            return(Success(response));
        }
コード例 #5
0
        public async Task <IActionResult> ResetPasswordAsync([FromBody] ResetPasswordResponseDto request)
        {
            UserBiz userBiz   = new UserBiz();
            var     userModel = await userBiz.GetAsync(request.DoctorGuid);

            if (userModel == null)
            {
                return(Failed(ErrorCode.DataBaseError));
            }
            var password = "******";//默认密码

            userModel.Password        = Common.Helper.CryptoHelper.AddSalt(userModel.UserGuid, GD.Common.Helper.CryptoHelper.Md5(password));
            userModel.LastUpdatedBy   = UserID;
            userModel.LastUpdatedDate = DateTime.Now;
            await userBiz.UpdateAsync(userModel);

            return(Success());
        }
コード例 #6
0
        public async Task <IActionResult> UpdateHealthInformationAsync([FromBody] UpdateHealthInformationRequestDto request)
        {
            var userBiz = new UserBiz();
            var model   = await userBiz.GetAsync(request.UserGuid);

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

            if (request.Items.Count == 0)
            {
                return(Failed(ErrorCode.Empty, "会员基础信息为空,请检查"));
            }

            var informationBiz = new HealthInformationBiz();

            var consumerHealthInfoBiz = new ConsumerHealthInfoBiz();

            var insertModels = new List <ConsumerHealthInfoModel>();
            var updateModels = new List <ConsumerHealthInfoModel>();

            var filterHealthInfos = new List <string>();

            foreach (var item in request.Items)
            {
                if (string.IsNullOrEmpty(item.InformationGuid))
                {
                    return(Failed(ErrorCode.Empty, "健康基础信息项数据为空,请检查"));
                }

                if (filterHealthInfos.Contains(item.InformationGuid))
                {
                    return(Failed(ErrorCode.Empty, "健康基础信息存在重复项,请检查"));
                }

                var healthInfoModel = await informationBiz.GetAsync(item.InformationGuid);

                if (healthInfoModel == null)
                {
                    return(Failed(ErrorCode.DataBaseError, "健康基础信息不存在,请检查"));
                }

                filterHealthInfos.Add(healthInfoModel.InformationGuid);

                var consumerHealthInfoModel = new ConsumerHealthInfoModel()
                {
                    InfoRecordGuid  = Guid.NewGuid().ToString("N"),
                    InformationGuid = item.InformationGuid,
                    UserGuid        = request.UserGuid,
                    CreatedBy       = UserID,
                    LastUpdatedBy   = UserID,
                    ResultValue     = item.ResultValue
                };

                var selectedOptionGuids = item.OptionGuids;

                if (healthInfoModel.InformationType == HealthInformationEnum.Decimal.ToString())
                {
                    if (!string.IsNullOrEmpty(item.ResultValue))
                    {
                        if (!decimal.TryParse(item.ResultValue, out var value))
                        {
                            return(Failed(ErrorCode.Empty, "数据类型不正确"));
                        }
                    }
                }
                else if (healthInfoModel.InformationType == HealthInformationEnum.Enum.ToString() ||
                         healthInfoModel.InformationType == HealthInformationEnum.Array.ToString())
                {
                    if (selectedOptionGuids.Count <= 0)
                    {
                        continue;
                    }

                    if (healthInfoModel.InformationType == HealthInformationEnum.Enum.ToString())
                    {
                        if (selectedOptionGuids.Count > 1)
                        {
                            return(Failed(ErrorCode.Empty, $"题目【{healthInfoModel.SubjectName}】答案存在多个"));
                        }
                    }

                    var options = await informationBiz.GetHealthInformationOptionAsync(item.InformationGuid);

                    var infoResult = selectedOptionGuids.Except(options.Select(s => s.OptionGuid));

                    if (infoResult != null && infoResult.Count() > 0)
                    {
                        return(Failed(ErrorCode.Empty, $"题目【{healthInfoModel.SubjectName}】答案选项不存在"));
                    }

                    consumerHealthInfoModel.OptionGuids = JsonConvert.SerializeObject(selectedOptionGuids);
                    consumerHealthInfoModel.ResultValue = null;
                }

                //用户没有填写任何信息,既不更新也不添加
                if (string.IsNullOrEmpty(consumerHealthInfoModel.OptionGuids) &&
                    string.IsNullOrEmpty(consumerHealthInfoModel.ResultValue?.Trim()))
                {
                    continue;
                }

                var consumerHealthInfo = await consumerHealthInfoBiz.GetConsumerHealthInfoAsync(item.InformationGuid, request.UserGuid);

                if (consumerHealthInfo != null)
                {
                    consumerHealthInfoModel.InfoRecordGuid  = consumerHealthInfo.InfoRecordGuid;
                    consumerHealthInfoModel.InformationGuid = consumerHealthInfo.InformationGuid;
                    consumerHealthInfoModel.LastUpdatedBy   = UserID;
                    consumerHealthInfoModel.LastUpdatedDate = DateTime.Now;

                    updateModels.Add(consumerHealthInfoModel);
                }
                else
                {
                    insertModels.Add(consumerHealthInfoModel);
                }
            }

            var result = await consumerHealthInfoBiz.CreateOrUpdateConsumerHealthInfo(insertModels, updateModels);

            return(result ? Success() : Failed(ErrorCode.DataBaseError, "更新健康基础信息失败"));
        }
コード例 #7
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, "创建健康指标失败"));
        }