public async Task <IActionResult> GetTherapistListAsync([FromQuery] GetTherapistListRequestDto requestDto) { requestDto.MerchantGuid = string.IsNullOrWhiteSpace(requestDto.MerchantGuid) ? (UserID ?? "") : requestDto.MerchantGuid; if (string.IsNullOrWhiteSpace(requestDto.MerchantGuid)) { return(Failed(ErrorCode.Empty, "商铺guid必填")); } var response = await new TherapistBiz().GetTherapistListAsync(requestDto); return(Success(response)); }
/// <summary> /// 分页获取服务人员列表 /// </summary> /// <param name="requestDto"></param> /// <returns></returns> public async Task <GetTherapistListResponseDto> GetTherapistListAsync(GetTherapistListRequestDto requestDto) { var parameters = new DynamicParameters(); parameters.Add("@MerchantGuid", requestDto.MerchantGuid); var sql = $@"SELECT a.therapist_guid as TherapistGuid, a.therapist_name AS TherapistName, a.therapist_phone AS TherapistPhone, a.creation_date AS CreationDate FROM t_merchant_therapist a WHERE a.merchant_guid = @MerchantGuid AND a.`enable`= 1"; if (!string.IsNullOrEmpty(requestDto.KeyWord)) { sql += $" and a.therapist_name like '%{requestDto.KeyWord}%' OR a.therapist_phone like '%{requestDto.KeyWord}%'"; } sql += " order by a.creation_date desc"; var rows = (List <GetTherapistListItemDto>)null; var classifyItems = (List <TherapistClassifyItem>)null; using (var conn = MySqlHelper.GetConnection()) { rows = (await conn.QueryAsync <GetTherapistListItemDto>(sql, commandType: CommandType.Text, param: parameters)).ToList(); if (rows?.Count() <= 0) { return(null); } var ids = string.Join(",", rows.Select(x => "'" + x.TherapistGuid + "'").ToArray()); sql = $@" SELECT DISTINCT a.therapist_guid AS TherapistGuid, b.classify_guid AS ClassifyGuid, b.classify_name AS ClassifyName FROM t_merchant_therapist_classify as a INNER JOIN t_merchant_category_extension as b ON a.classify_guid = b.classify_guid WHERE a.therapist_guid in ({ids}) AND b.merchant_guid = '{requestDto.MerchantGuid}'"; classifyItems = (await conn.QueryAsync <TherapistClassifyItem>(sql, commandType: CommandType.Text)).ToList(); } foreach (var row in rows.ToList()) { row.Items = classifyItems.Where(d => d.TherapistGuid == row.TherapistGuid)?.ToList(); if (!string.IsNullOrEmpty(requestDto.ClassifyGuid)) { //通过平台分类Id过滤数据 row.Items = row.Items.Where(d => d.ClassifyGuid.Equals(requestDto.ClassifyGuid))?.ToList(); //若查询分类不存在,则将基础数据行给移除 if (row.Items?.Count <= 0) { rows.Remove(row); } } } var total = rows.Count(); var offset = (requestDto.PageIndex - 1) * requestDto.PageSize; rows = rows.Skip(offset).Take(requestDto.PageSize).ToList(); return(new GetTherapistListResponseDto() { CurrentPage = rows, Total = total }); }