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)); }
public async Task <IActionResult> ChangeInfomationSortAsync([FromBody] ChangeInfomationSortRequestDto requestDto) { var biz = new HealthInformationBiz(); var model = await biz.GetAsync(requestDto.InformationGuid); if (model == null) { return(Failed(ErrorCode.UserData, "未找到此健康信息")); } var newSort = requestDto.Sort; if (model.Sort == newSort) { return(Failed(ErrorCode.UserData, "健康信息序号未产生变化,请核对")); } // 一.其他健康信息为待变化健康信息顺次移动位置 // 1.若向前移动,则原序号和新序号之间所有健康信息序号+1 (不包括待变化健康信息) // 2.若向后移动,则原序号和新序号之间所有健康信息序号-1 (不包括待变化健康信息) // 二.将待变化健康信息序号变为新序号 var result = await biz.ChangeSortAsync(model, newSort, UserID); return(result ? Success() : Failed(ErrorCode.DataBaseError, "健康信息变化序号失败")); }
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, "更新健康基础信息失败")); }