Ejemplo n.º 1
0
        public async Task <IActionResult> GetTherapistsScheduleByProjectIdOneDayAsync([FromBody] GetTherapistsScheduleByProjectIdOneDayRequestDto requestDto)
        {
            requestDto.ScheduleDate = DateTime.Now;
            requestDto.MerchantGuid = UserID;

            var result = await new TherapistBiz().GetTherapistsScheduleByProjectIdOneDayAsync(requestDto);

            if (result == null)
            {
                return(Success());
            }

            var scheduleTemplateModel = await new ScheduleTemplateBiz().GetModelByDateAsync(requestDto.MerchantGuid, requestDto.ScheduleDate);

            if (scheduleTemplateModel == null)
            {
                return(Failed(ErrorCode.Empty, "店铺当天未进行排班!"));
            }

            var times = await GetMerchantMaxDurationTimeButtonsAsync(requestDto.MerchantGuid, scheduleTemplateModel.TemplateGuid);

            if (!times.Any())
            {
                return(Failed(ErrorCode.Empty, "店铺未配置班次,请先配置班次!"));
            }

            var(currentDay, minAppointTime) = CheckCurrentDayGetMinAppointTime(requestDto.ScheduleDate);

            var groupDetails = result.ScheduleDetails.GroupBy(a => a.TherapistGuid);

            var response = new List <GetTherapistsScheduleByProjectIdOneDayResponseDto>();

            foreach (var therapist in result.Therapists)
            {
                var therapistDetails = (groupDetails.FirstOrDefault(a => a.Key == therapist.TherapistGuid))?.ToList();

                var responseItem = new GetTherapistsScheduleByProjectIdOneDayResponseDto
                {
                    TherapistGuid   = therapist.TherapistGuid,
                    TherapistName   = therapist.TherapistName,
                    PortraitUrl     = therapist.PortraitUrl,
                    ScheduleGuid    = therapistDetails?.FirstOrDefault()?.ScheduleGuid,
                    ScheduleDetails = new List <ScheduleTimeDetailDto>()
                };

                if (therapistDetails != null)
                {
                    foreach (var time in times)
                    {
                        var res = therapistDetails?.FirstOrDefault(a => a.StartTime != null && a.StartTime.CompareTo(time.StartTime) <= 0 && a.EndTime.CompareTo(time.StartTime) > 0);

                        var scheduleTimeDetail = new ScheduleTimeDetailDto
                        {
                            ScheduleDetailGuid = res?.ScheduleDetailGuid,
                            StartTime          = time.StartTime,
                            EndTime            = time.EndTime,
                            ConsumptionGuid    = res?.ConsumptionGuid,
                            Occupy             = res != null
                        };

                        if (currentDay && time.StartTime.CompareTo(minAppointTime) < 0)
                        {
                            scheduleTimeDetail.Occupy = true;
                        }

                        responseItem.ScheduleDetails.Add(scheduleTimeDetail);
                    }
                    response.Add(responseItem);
                }
            }
            return(Success(response));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取商户某天某项目的服务人员和排班详情
        /// </summary>
        /// <param name="requestDto"></param>
        /// <returns></returns>
        public async Task <TherapistsScheduleByProjectIdOneDayResponseDto> GetTherapistsScheduleByProjectIdOneDayAsync(GetTherapistsScheduleByProjectIdOneDayRequestDto requestDto)
        {
            using (var conn = MySqlHelper.GetConnection())
            {
                var sql = @"DROP TEMPORARY TABLE
                            IF
	                            EXISTS tmp_merchant_therapist;
                            DROP TEMPORARY TABLE
                            IF
	                            EXISTS tmp_merchant_therapist_1;
                            CREATE TEMPORARY TABLE tmp_merchant_therapist AS SELECT distinct
                            b.therapist_guid,
                            b.therapist_name,
                            CONCAT( c.base_path, c.relative_path ) AS PortraitUrl 
                            FROM
	                            t_merchant_therapist_project a
	                            INNER JOIN t_merchant_therapist b ON a.therapist_guid = b.therapist_guid 
	                            AND a.`enable` = b.`enable`
	                            LEFT JOIN t_utility_accessory c ON b.portrait_guid = c.accessory_guid 
                            WHERE
	                            a.project_guid = @projectGuid 
	                            and b.merchant_guid=@merchantGuid
	                            AND a.`enable` = 1;
                            CREATE TEMPORARY TABLE tmp_merchant_therapist_1 SELECT
                            * 
                            FROM
	                            tmp_merchant_therapist;

                            SELECT
	                            * 
                            FROM
	                            tmp_merchant_therapist;
	
                            SELECT
                              t.therapist_guid,
                                sche.schedule_guid,
	                            detail.schedule_detail_guid,
	                            detail.consumption_guid,
	                            detail.start_time,
	                            detail.end_time
                            FROM
	                            tmp_merchant_therapist_1 t
	                            INNER JOIN t_merchant_schedule sche ON t.therapist_guid = sche.target_guid
	                            left JOIN t_merchant_schedule_detail detail ON sche.schedule_guid = detail.schedule_guid and sche.`enable`=detail.`enable`
                            WHERE
	                            sche.schedule_date = @scheduleDate 
	                            AND sche.`enable` = 1 ;
                            DROP TEMPORARY TABLE tmp_merchant_therapist;
                            DROP TEMPORARY TABLE tmp_merchant_therapist_1;";

                var reader = await conn.QueryMultipleAsync(sql, new { projectGuid = requestDto.ProjectGuid, merchantGuid = requestDto.MerchantGuid, scheduleDate = requestDto.ScheduleDate.Date });

                var therapists = (await reader.ReadAsync <TherapistsByProjectIdOneDayDto>())?.ToList();

                var scheduleDetails = (await reader.ReadAsync <TherapistsScheduleByProjectIdOneDayDto>())?.ToList();

                if (!therapists.Any())
                {
                    return(null);
                }

                return(new TherapistsScheduleByProjectIdOneDayResponseDto
                {
                    Therapists = therapists,
                    ScheduleDetails = scheduleDetails
                });
            }
        }