Files
17168ERP/web/App_Code/api/guadanStatisticsTableController.cs

81 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
/// <summary>
/// guadanStatisticsTable 的摘要描述
/// </summary>
///
[ezAuthorize]
public class guadanStatisticsTableController: ApiController
{
private Model.ezEntities _db = new Model.ezEntities();
public guadanStatisticsTableController()
{
//
// TODO: 在這裡新增建構函式邏輯
//
}
[HttpGet]
[Route("api/guadan/guadanstatisticstable/list")]
public IHttpActionResult Get([FromUri] DateTime? start, [FromUri] DateTime? end)
{
// 如果兩個都為空,設定 start = 今天end = 一個月後
if (!start.HasValue && !end.HasValue)
{
start = DateTime.Today;
end = DateTime.Today.AddMonths(1);
}
// 如果有 start 沒有 end就給 end 預設一個月後
if (start.HasValue && !end.HasValue)
{
end = start.Value.Date.AddMonths(1);
}
// 如果有 end 沒有 start就給 start 預設 end 的前一個月
if (!start.HasValue && end.HasValue)
{
start = end.Value.Date.AddMonths(-1);
}
// 最後確保只取 date 部分
var startDate = start.Value.Date;
var endDate = end.Value.Date;
// 查詢資料庫時就用 date 型別對應
var statistics = _db.RegionAndRoomAndBedSchedule
.Where(s => s.IsCancel == false)
.Where(s => s.ScheduleDate >= startDate && s.ScheduleDate <= endDate)
.GroupBy(s => s.ScheduleDate)
.Select(g => new
{
date = g.Key,
todaytotalbookers = g.Count(), // 该日期的总记录数
checkin = g.Key <= DateTime.Today
? g.Count(x => x.GuaDanOrderGuest.RegionRoomBedStatus.Code == "402"
|| x.GuaDanOrderGuest.RegionRoomBedStatus.Code == "403")
: 0,
})
.OrderBy(x => x.date)
.ToList();
var todayDate = DateTime.Today;
var bedcount = _db.RegionRoomBed
.Where(a => a.IsDeleted == false)
.Count();
var roomcount = _db.Room.Count();
var result = new
{
bedcount,
roomcount,
statistics,
};
return Ok(result);
}
}