93 lines
3.5 KiB
C#
93 lines
3.5 KiB
C#
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,
|
||
checkinfemale = g.Key <= DateTime.Today
|
||
? g.Count(x => (x.GuaDanOrderGuest.RegionRoomBedStatus.Code == "402"
|
||
|| x.GuaDanOrderGuest.RegionRoomBedStatus.Code == "403")
|
||
&& x.GuaDanOrderGuest.followers.sex == "女眾")
|
||
: 0,
|
||
checkinmale = g.Key <= DateTime.Today
|
||
? g.Count(x => (x.GuaDanOrderGuest.RegionRoomBedStatus.Code == "402"
|
||
|| x.GuaDanOrderGuest.RegionRoomBedStatus.Code == "403")
|
||
&& x.GuaDanOrderGuest.followers.sex == "男眾")
|
||
: 0,
|
||
bookfemale = g.Count(x => x.GuaDanOrderGuest.followers.sex == "女眾"),
|
||
bookmale = g.Count(x => x.GuaDanOrderGuest.followers.sex == "男眾")
|
||
})
|
||
.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);
|
||
}
|
||
|
||
} |