Merge remote-tracking branch 'origin/guadan0905'
This commit is contained in:
@@ -74,9 +74,11 @@ public class ShuWenController : ApiController
|
||||
{
|
||||
shuwen.ShuWenList = ProcessDesserts2(_db.pro_order_detail.Where(a => a.pro_order.activity_num == activitynum.Value).ToList());
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
shuwen.IsGenerating = false;
|
||||
_db.SaveChanges();
|
||||
return BadRequest("生成舒文失败:" + ex.Message);
|
||||
}
|
||||
shuwen.IsGenerating = false;
|
||||
shuwen.UpdateTime = DateTime.Now;
|
||||
@@ -222,34 +224,42 @@ public class ShuWenController : ApiController
|
||||
[Route("api/shuwen/download")]
|
||||
public HttpResponseMessage DownloadShuWenWord(int? activitynum)
|
||||
{
|
||||
var data = _db.ShuWen.Where(a => a.ActivityNum == activitynum).FirstOrDefault();
|
||||
if (data == null)
|
||||
try
|
||||
{
|
||||
//return;
|
||||
}
|
||||
string json = data.ShuWenList;
|
||||
string ActivityName = _db.activities.Where(a => a.num == data.ActivityNum).FirstOrDefault().subject;
|
||||
if (json == null)
|
||||
{
|
||||
//return;
|
||||
}
|
||||
string fileName = $"疏文名單_{DateTime.Now:yyyyMMddHHmmss}.docx";
|
||||
|
||||
var stream = new MemoryStream();
|
||||
GenerateShuWenWord_OpenXml(json, stream, ActivityName);
|
||||
stream.Position = 0;
|
||||
var response = new HttpResponseMessage(HttpStatusCode.OK)
|
||||
{
|
||||
Content = new StreamContent(stream)
|
||||
};
|
||||
response.Content.Headers.ContentType =
|
||||
new System.Net.Http.Headers.MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
|
||||
response.Content.Headers.ContentDisposition =
|
||||
new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
|
||||
var data = _db.ShuWen.Where(a => a.ActivityNum == activitynum).FirstOrDefault();
|
||||
if (data == null)
|
||||
{
|
||||
FileName = fileName
|
||||
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "活動編號不能為空");
|
||||
}
|
||||
string json = data.ShuWenList;
|
||||
string ActivityName = _db.activities.Where(a => a.num == data.ActivityNum).FirstOrDefault().subject;
|
||||
if (json == null)
|
||||
{
|
||||
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "疏文列表为空,无法生成 Word");
|
||||
}
|
||||
string fileName = $"疏文名單_{DateTime.Now:yyyyMMddHHmmss}.docx";
|
||||
|
||||
var stream = new MemoryStream();
|
||||
GenerateShuWenWord_OpenXml(json, stream, ActivityName);
|
||||
stream.Position = 0;
|
||||
var response = new HttpResponseMessage(HttpStatusCode.OK)
|
||||
{
|
||||
Content = new StreamContent(stream)
|
||||
};
|
||||
return response;
|
||||
response.Content.Headers.ContentType =
|
||||
new System.Net.Http.Headers.MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
|
||||
response.Content.Headers.ContentDisposition =
|
||||
new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
|
||||
{
|
||||
FileName = fileName
|
||||
};
|
||||
return response;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void GenerateShuWenWord_OpenXml(string json, Stream outputStream, string ActivityName ="")
|
||||
|
||||
139
web/App_Code/api/guadanGuestQueryController.cs
Normal file
139
web/App_Code/api/guadanGuestQueryController.cs
Normal file
@@ -0,0 +1,139 @@
|
||||
using Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
|
||||
/// <summary>
|
||||
/// guadanGuestQueryController 的摘要描述
|
||||
/// </summary>
|
||||
public class guadanGuestQueryController: ApiController
|
||||
{
|
||||
private Model.ezEntities _db = new Model.ezEntities();
|
||||
public guadanGuestQueryController()
|
||||
{
|
||||
//
|
||||
// TODO: 在這裡新增建構函式邏輯
|
||||
//
|
||||
}
|
||||
[HttpPost]
|
||||
[Route("api/guadan/guest/query/list")]
|
||||
public async Task<IHttpActionResult> GetList([FromBody] SearchGuestModel search)
|
||||
{
|
||||
var query = _db.GuaDanOrderGuest
|
||||
.Where(guest => guest.StatusCode != "404");
|
||||
if(search.SearchName != null)
|
||||
{
|
||||
query = query.Where(guest => guest.followers.u_name.Contains(search.SearchName));
|
||||
}
|
||||
if(search.searchCheckInDate != null)
|
||||
{
|
||||
query = query.Where(guest => guest.CheckInAt == search.searchCheckInDate);
|
||||
}
|
||||
if(search.searchCheckOutDate != null)
|
||||
{
|
||||
query = query.Where(guest => guest.CheckOutAt == search.searchCheckOutDate);
|
||||
}
|
||||
if(search.searchCheckInDateStart != null)
|
||||
{
|
||||
query = query.Where(guest => guest.CheckInAt >= search.searchCheckInDateStart);
|
||||
}
|
||||
if (search.searchCheckInDateEnd != null)
|
||||
{
|
||||
query = query.Where(guest => guest.CheckInAt <= search.searchCheckInDateEnd);
|
||||
}
|
||||
if (search.searchCheckOutDateStart != null)
|
||||
{
|
||||
query = query.Where(guest => guest.CheckOutAt >= search.searchCheckOutDateStart);
|
||||
}
|
||||
if (search.searchCheckOutDateEnd != null)
|
||||
{
|
||||
query = query.Where(guest => guest.CheckOutAt <= search.searchCheckOutDateEnd);
|
||||
}
|
||||
var totalCount = await query.CountAsync();
|
||||
var pagedData = await query
|
||||
.OrderByDescending(a => a.CheckInAt) // 可根据需要排序
|
||||
.Skip((search.Page - 1) * search.PageSize)
|
||||
.Take(search.PageSize)
|
||||
.ToListAsync();
|
||||
var data1 = pagedData.Select(a => new
|
||||
{
|
||||
name = a.followers != null ? a.followers.u_name : null,
|
||||
checkindate = a.CheckInAt,
|
||||
checkoutdate = a.CheckOutAt,
|
||||
guadanorderno = a.GuaDanOrderNo,
|
||||
roomName = GetRoomAndBedString(a.RegionRoomBed),
|
||||
}).ToList();
|
||||
return Ok(new
|
||||
{
|
||||
items = data1,
|
||||
total = totalCount,
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("api/guadan/guest/checkin/list")]
|
||||
public async Task<IHttpActionResult> GetCheckInGuest([FromUri] DateTime date)
|
||||
{
|
||||
var today = DateTime.Now.Date;
|
||||
var data = await _db.GuaDanOrderGuest
|
||||
.Where(guest => guest.StatusCode == "402")
|
||||
.Where(guest => guest.RegionAndRoomAndBedSchedule
|
||||
.Any(s => s.ScheduleDate == date.Date && s.ScheduleDate == today) == true)
|
||||
.Select(guest => new
|
||||
{
|
||||
name = guest.followers.u_name,
|
||||
gender = guest.followers.sex,
|
||||
})
|
||||
.ToListAsync();
|
||||
return Ok(data);
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("api/guadan/guest/booking/list")]
|
||||
public async Task<IHttpActionResult> GetBookingGuest([FromUri] DateTime date)
|
||||
{
|
||||
var data = await _db.GuaDanOrderGuest
|
||||
.Where(guest => guest.StatusCode == "402" || guest.StatusCode == "401")
|
||||
.Where(guest => guest.RegionAndRoomAndBedSchedule.Any(s => s.ScheduleDate == date.Date) == true)
|
||||
.Select(guest => new
|
||||
{
|
||||
name = guest.followers.u_name,
|
||||
gender = guest.followers.sex,
|
||||
})
|
||||
.ToListAsync();
|
||||
return Ok(data);
|
||||
}
|
||||
public string GetRoomAndBedString(RegionRoomBed bed)
|
||||
{
|
||||
if (bed == null || bed.Room == null) return "";
|
||||
var room = bed.Room;
|
||||
var region = room.Region;
|
||||
var name = room.Name + "/" + bed.Name;
|
||||
if(region != null)
|
||||
{
|
||||
name = region.Name + "/" + name;
|
||||
}
|
||||
var parentRegion = region.Region2;
|
||||
while (parentRegion != null)
|
||||
{
|
||||
name = parentRegion.Name + "/" + name;
|
||||
parentRegion = parentRegion.Region2;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
public class SearchGuestModel
|
||||
{
|
||||
public string SearchName = null;
|
||||
public int Page = 1;
|
||||
public int PageSize = 10;
|
||||
public DateTime? searchCheckInDateStart = null;//入住日期的开始
|
||||
public DateTime? searchCheckInDateEnd = null;//入住日期的结束
|
||||
public DateTime? searchCheckOutDateStart = null;//退房日期的开始
|
||||
public DateTime? searchCheckOutDateEnd = null;//退房日期的结束
|
||||
public DateTime? searchCheckInDate = null;
|
||||
public DateTime? searchCheckOutDate = null;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Model;
|
||||
using PagedList;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity;
|
||||
@@ -15,12 +16,36 @@ using static regionController;
|
||||
public class guadanOrderController : ApiController
|
||||
{
|
||||
private Model.ezEntities _db = new Model.ezEntities();
|
||||
[HttpGet]
|
||||
[HttpPost]
|
||||
[Route("api/guadan/list")]
|
||||
public async Task<IHttpActionResult> getGuadanList()
|
||||
public async Task<IHttpActionResult> getGuadanList([FromBody] guadan_order_search_dto search)
|
||||
{
|
||||
var data = await _db.GuaDanOrder
|
||||
|
||||
var query = _db.GuaDanOrder
|
||||
.Where(a => a.IsCancel == false)
|
||||
.Where(a => a.IsDeleted == false);
|
||||
if(search.guadanUser != null)
|
||||
{
|
||||
query = query.Where(order => order.BookerName == search.guadanUser);
|
||||
}
|
||||
if (search.startDate != null && search.endDate != null)
|
||||
{
|
||||
query = query.Where(order => order.StartDate >= search.startDate)
|
||||
.Where(order => order.EndDate <= search.endDate);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (search.startDate != null)
|
||||
{
|
||||
query = query.Where(order => order.StartDate == search.startDate);
|
||||
}
|
||||
else if (search.endDate != null)
|
||||
{
|
||||
query = query.Where(order => order.EndDate == search.endDate);
|
||||
}
|
||||
}
|
||||
var total = query.Count();
|
||||
var data = await query
|
||||
.OrderByDescending(b => b.CreatedAt)
|
||||
.Select(a => new
|
||||
{
|
||||
@@ -36,8 +61,15 @@ public class guadanOrderController : ApiController
|
||||
.Where(c => c.GuaDanOrderNo == a.GuaDanOrderNo && c.IsDeleted == false)
|
||||
.Where(c => c.RegionRoomBedStatus.Code != GuaDanOrderGuest.STATUS_CANCELLED)
|
||||
.Count(),
|
||||
}).ToListAsync();
|
||||
return Ok(data);
|
||||
})
|
||||
.Skip((search.page - 1) * search.pageSize)
|
||||
.Take(search.pageSize)
|
||||
.ToListAsync();
|
||||
return Ok(new
|
||||
{
|
||||
total,
|
||||
data
|
||||
});
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("api/guadan/getorderbyid")]
|
||||
@@ -221,4 +253,13 @@ public class guadanOrderController : ApiController
|
||||
public RegionRoomBed bed { get; set; } = null;
|
||||
}
|
||||
|
||||
public class guadan_order_search_dto
|
||||
{
|
||||
public DateTime? startDate { get; set; }
|
||||
public DateTime? endDate { get; set; }
|
||||
public string guadanUser { get; set; }
|
||||
public int page { get; set; } = 1;
|
||||
public int pageSize { get; set; } = 10;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public class guadanOrderGuestController : ApiController
|
||||
return BadRequest("床位在該時間段內已被占用");
|
||||
if (model.followerNum.HasValue)
|
||||
{
|
||||
if (_db.GuaDanOrderGuest.Any(a => a.FollowerNum == model.followerNum
|
||||
if (_db.GuaDanOrderGuest.Any(a => a.FollowerNum == model.followerNum
|
||||
&& a.GuaDanOrderNo == model.orderNo
|
||||
&& a.StatusCode != "404"
|
||||
))
|
||||
@@ -330,31 +330,31 @@ public class guadanOrderGuestController : ApiController
|
||||
[Route("api/guadanorderguest/xuzhu")]
|
||||
public async Task<IHttpActionResult> ExtendStay([FromBody] XuZhuModel model)
|
||||
{
|
||||
//续住方法
|
||||
//續住方法
|
||||
if (model == null)
|
||||
return BadRequest("请求数据为空");
|
||||
return BadRequest("請求數據為空");
|
||||
|
||||
if (model.GuestUuid == Guid.Empty || model.GuestBedUuid == Guid.Empty)
|
||||
return BadRequest("GuestUuid 或 GuestBedUuid 无效");
|
||||
var guest= await _db.GuaDanOrderGuest.FindAsync(model.GuestUuid);
|
||||
return BadRequest("GuestUuid 或 GuestBedUuid 無效");
|
||||
var guest = await _db.GuaDanOrderGuest.FindAsync(model.GuestUuid);
|
||||
if (guest == null)
|
||||
{
|
||||
return BadRequest("挂单不存在");
|
||||
return BadRequest("掛單不存在");
|
||||
}
|
||||
if(guest.BedUuid != model.GuestBedUuid)
|
||||
if (guest.BedUuid != model.GuestBedUuid)
|
||||
{
|
||||
return BadRequest("床位不正确");
|
||||
return BadRequest("床位不正確");
|
||||
}
|
||||
var bedIsCanUse = await RegionAndRoomAndBedSchedule.IsBedAvailableAsync(_db,model.GuestBedUuid, model.CurrentCheckoutDate, model.NewCheckoutDate);
|
||||
if(!bedIsCanUse)
|
||||
var bedIsCanUse = await RegionAndRoomAndBedSchedule.IsBedAvailableAsync(_db, model.GuestBedUuid, model.CurrentCheckoutDate, model.NewCheckoutDate);
|
||||
if (!bedIsCanUse)
|
||||
{
|
||||
return BadRequest("该床位在续住时间段内被预定,无法续住");
|
||||
return BadRequest("該床位在續住時間段內被預定,無法續住");
|
||||
}
|
||||
|
||||
var newStartDate = model.CurrentCheckoutDate.Date;
|
||||
var newEndDate = model.NewCheckoutDate.Date.AddDays(-1);
|
||||
if (newEndDate < newStartDate)
|
||||
return BadRequest("续住日期区间无效");
|
||||
return BadRequest("續住日期區間無效");
|
||||
for (var date = newStartDate; date <= newEndDate; date = date.AddDays(1))
|
||||
{
|
||||
var newSchedule = new RegionAndRoomAndBedSchedule
|
||||
@@ -364,8 +364,8 @@ public class guadanOrderGuestController : ApiController
|
||||
TargetUuid = model.GuestBedUuid,
|
||||
GuaDanOrderGuestUuid = model.GuestUuid,
|
||||
ScheduleDate = date,
|
||||
Title = "续住挂单", // 一天一条,开始和结束是同一天
|
||||
Description = "续住挂单",
|
||||
Title = "續住掛單", // 一天一條,開始和結束是同一天
|
||||
Description = "續住掛單",
|
||||
UseType = 30,
|
||||
CreatedAt = DateTime.UtcNow
|
||||
};
|
||||
@@ -373,8 +373,8 @@ public class guadanOrderGuestController : ApiController
|
||||
_db.RegionAndRoomAndBedSchedule.Add(newSchedule);
|
||||
}
|
||||
guest.CheckOutAt = model.NewCheckoutDate.Date;
|
||||
await _db.SaveChangesAsync(); // 保存数据库操作
|
||||
return Ok(new { message = "续住成功" });
|
||||
await _db.SaveChangesAsync(); // 保存資料庫操作
|
||||
return Ok(new { message = "續住成功" });
|
||||
}
|
||||
[HttpPost]
|
||||
[Route("api/guadanorderguest/cancel")]
|
||||
@@ -495,13 +495,13 @@ public class guadanOrderGuestController : ApiController
|
||||
|
||||
//更新未來排程為取消
|
||||
var latestCheckoutStr = _db.GuadanTimeSetting
|
||||
.Select(a => a.LatestCheckOut) // 字符串 "HH:mm"
|
||||
.Select(a => a.LatestCheckOut) // 字串 "HH:mm"
|
||||
.FirstOrDefault();
|
||||
|
||||
TimeSpan? latestCheckoutTime = null;
|
||||
if (!string.IsNullOrEmpty(latestCheckoutStr))
|
||||
{
|
||||
// 尝试解析字符串
|
||||
// 嘗試解析字串
|
||||
if (TimeSpan.TryParse(latestCheckoutStr, out var ts))
|
||||
{
|
||||
latestCheckoutTime = ts;
|
||||
@@ -588,7 +588,7 @@ public class guadanOrderGuestController : ApiController
|
||||
if (guest.BedUuid != null)
|
||||
{
|
||||
var bed = _db.RegionRoomBed.FirstOrDefault(b => b.Uuid == guest.BedUuid);
|
||||
if(bed == null)
|
||||
if (bed == null)
|
||||
{
|
||||
return BadRequest("入住床位不存在");
|
||||
}
|
||||
@@ -598,10 +598,10 @@ public class guadanOrderGuestController : ApiController
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest($"当前床位状态:{bed.RegionRoomBedStatus.Name} 不能入住");
|
||||
return BadRequest($"當前床位狀態:{bed.RegionRoomBedStatus.Name} 不能入住");
|
||||
}
|
||||
}
|
||||
else if(guest.BedUuid == null)
|
||||
else if (guest.BedUuid == null)
|
||||
{
|
||||
return BadRequest("入住床位不存在");
|
||||
}
|
||||
@@ -653,10 +653,10 @@ public class guadanOrderGuestController : ApiController
|
||||
}
|
||||
public class XuZhuModel
|
||||
{
|
||||
public Guid GuestUuid { get; set; } // 不可为空
|
||||
public Guid GuestBedUuid { get; set; } // 不可为空
|
||||
public DateTime CurrentCheckoutDate { get; set; } // 当前退房时间
|
||||
public DateTime NewCheckoutDate { get; set; } // 新退房时间
|
||||
public Guid GuestUuid { get; set; } // 不可為空
|
||||
public Guid GuestBedUuid { get; set; } // 不可為空
|
||||
public DateTime CurrentCheckoutDate { get; set; } // 當前退房時間
|
||||
public DateTime NewCheckoutDate { get; set; } // 新退房時間
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,39 +21,49 @@ public class guadanStatisticsController: ApiController
|
||||
//挂单统计:房间,床位,挂单笔数,挂单人数的统计
|
||||
|
||||
var now = DateTime.Now;
|
||||
var roomCount = await _db.Room.Where(a => a.IsDeleted == false).CountAsync();
|
||||
var rooms = await _db.Room.Include(r => r.RegionRoomBed).ToListAsync();
|
||||
|
||||
var emptyRoomCount = rooms
|
||||
.Where(r => r.RegionRoomBed.All(b => b.IsAvailableDuring(now, now, _db))) // 這裡就能用方法
|
||||
.Count();
|
||||
var bedCount = await _db.RegionRoomBed.Where(a => a.IsDeleted == false).CountAsync();
|
||||
var maleBedCount = await _db.RegionRoomBed.Where(a => a.IsDeleted == false && a.Gender == true).CountAsync();
|
||||
var femaleBedCount = await _db.RegionRoomBed.Where(a => a.IsDeleted == false && a.Gender == false).CountAsync();
|
||||
|
||||
var guadanTotalCount = await _db.GuaDanOrder.Where(a => a.IsDeleted == false).CountAsync();
|
||||
var guadanPeopleTotal = await _db.GuaDanOrderGuest.Where(a => a.IsDeleted == false).CountAsync();
|
||||
var guadanPeopleMale = await _db.GuaDanOrderGuest.Where(a => a.IsDeleted == false && a.followers.sex == "男眾").CountAsync();
|
||||
var guadanPeopleFemale = await _db.GuaDanOrderGuest.Where(a => a.IsDeleted == false && a.followers.sex == "女眾").CountAsync();
|
||||
dynamic bedCounts = await RegionAndRoomAndBedSchedule.GetAvailableBedCountsAsync(_db, DateTime.Now, DateTime.Now);
|
||||
var guadanCurrentCount = await _db.GuaDanOrder.Where(a => now < a.EndDate).CountAsync();
|
||||
var guadanPeopleCurrent = await _db.GuaDanOrderGuest.Where( a => a.CheckOutAt > now).CountAsync();
|
||||
var guadanPeopleCurrentMale = await _db.GuaDanOrderGuest.Where(a => a.CheckOutAt > now && a.followers.sex == "男眾").CountAsync();
|
||||
var guadanPeopleCurrentFemale = await _db.GuaDanOrderGuest.Where(a => a.CheckOutAt > now && a.followers.sex == "女眾").CountAsync();
|
||||
var guadanTotalCount = await _db.GuaDanOrder
|
||||
.Where(a => a.IsDeleted == false)
|
||||
.Where(a => a.IsCancel == false)
|
||||
.CountAsync();
|
||||
var guadanCurrentCount = await _db.GuaDanOrderGuest
|
||||
.Where(guest => guest.StatusCode != "403")
|
||||
.Where(guest => guest.StatusCode != "404")
|
||||
.Select(guest => guest.GuaDanOrderNo)
|
||||
.Distinct()
|
||||
.CountAsync();
|
||||
var guadanPeopleTotal = await _db.GuaDanOrderGuest
|
||||
.Where(a => a.IsDeleted == false)
|
||||
.Where(guest => guest.StatusCode != "404")
|
||||
.CountAsync();
|
||||
var guadanPeopleMale = await _db.GuaDanOrderGuest
|
||||
.Where(guest => guest.StatusCode != "404")
|
||||
.Where(a => a.IsDeleted == false && a.followers.sex == "男眾")
|
||||
.CountAsync();
|
||||
var guadanPeopleFemale = await _db.GuaDanOrderGuest
|
||||
.Where(guest => guest.StatusCode != "404")
|
||||
.Where(a => a.IsDeleted == false && a.followers.sex == "女眾")
|
||||
.CountAsync();
|
||||
var guadanPeopleCurrent = await _db.GuaDanOrderGuest
|
||||
.Where(a => a.IsDeleted == false)
|
||||
.Where(guest => guest.StatusCode != "404")
|
||||
.Where(guest => guest.StatusCode != "403")
|
||||
.Where( a => a.CheckOutAt >= now.Date)
|
||||
.CountAsync();
|
||||
var guadanPeopleCurrentMale = await _db.GuaDanOrderGuest
|
||||
.Where(a => a.IsDeleted == false)
|
||||
.Where(guest => guest.StatusCode != "404")
|
||||
.Where(guest => guest.StatusCode != "403")
|
||||
.Where(a => a.CheckOutAt >= now.Date && a.followers.sex == "男眾")
|
||||
.CountAsync();
|
||||
var guadanPeopleCurrentFemale = await _db.GuaDanOrderGuest
|
||||
.Where(a => a.IsDeleted == false)
|
||||
.Where(guest => guest.StatusCode != "404")
|
||||
.Where(guest => guest.StatusCode != "403")
|
||||
.Where(a => a.CheckOutAt >= now.Date && a.followers.sex == "女眾")
|
||||
.CountAsync();
|
||||
|
||||
var result = new
|
||||
{
|
||||
roomStatistics = new
|
||||
{
|
||||
roomCount = roomCount,
|
||||
emptyRoomCount = emptyRoomCount,
|
||||
bedCount = bedCount,
|
||||
maleBedCount = maleBedCount,
|
||||
femaleBedCount = femaleBedCount,
|
||||
emptyBedCount = bedCounts.male + bedCounts.female,
|
||||
emptyMaleBedCount = bedCounts.male,
|
||||
emptyFemaleBedCount = bedCounts.female
|
||||
},
|
||||
guadanStatistics = new
|
||||
{
|
||||
guadanTotalCount = guadanTotalCount, // 总挂单次数
|
||||
@@ -61,7 +71,7 @@ public class guadanStatisticsController: ApiController
|
||||
guadanPeopleTotal = guadanPeopleTotal, // 总挂单人数
|
||||
guadanPeopleMale = guadanPeopleMale,
|
||||
guadanPeopleFemale = guadanPeopleFemale,
|
||||
guadanPeopleCurrent = guadanPeopleCurrent, // 当前挂单人数
|
||||
guadanPeopleCurrent = guadanPeopleCurrent, // 已預約掛單人數
|
||||
guadanPeopleCurrentMale = guadanPeopleCurrentMale,
|
||||
guadanPeopleCurrentFemale = guadanPeopleCurrentFemale
|
||||
}
|
||||
|
||||
@@ -59,20 +59,22 @@ public class guadanStatisticsTableController: ApiController
|
||||
? 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;
|
||||
dynamic today = statistics.FirstOrDefault(x => x.date == todayDate);
|
||||
|
||||
if (today == null)
|
||||
{
|
||||
var todayCount = _db.RegionAndRoomAndBedSchedule
|
||||
.Where(s => s.ScheduleDate == todayDate && !s.IsCancel)
|
||||
.Count();
|
||||
|
||||
today = new { date = todayDate, todaytotalbookers = todayCount };
|
||||
}
|
||||
|
||||
var bedcount = _db.RegionRoomBed
|
||||
.Where(a => a.IsDeleted == false)
|
||||
@@ -83,11 +85,6 @@ public class guadanStatisticsTableController: ApiController
|
||||
bedcount,
|
||||
roomcount,
|
||||
statistics,
|
||||
today,
|
||||
totalbookers = _db.RegionAndRoomAndBedSchedule
|
||||
.Where(s => s.IsCancel == false)
|
||||
.Where(s => s.ScheduleDate >= DateTime.Today)
|
||||
.Count(),
|
||||
};
|
||||
|
||||
return Ok(result);
|
||||
|
||||
@@ -22,94 +22,14 @@ public class orderdetailController:ApiController
|
||||
public IHttpActionResult GetList([FromBody] Model.ViewModel.pro_order q, int page, int pageSize = 10, string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
int activity_num = Convert.ToInt32(q.activity_num);
|
||||
|
||||
//現在的牌位預覽只會出現功德主,修改為所有人都會出現
|
||||
//var aIDt = _db.actItems.AsEnumerable().Where(f => f.subject.Contains(q.actItemTxt.Trim())).Select(f => f.num);//品項
|
||||
var OrderList = _db.pro_order.Where(u => u.activity_num == activity_num).Select(j => j.order_no).ToList();
|
||||
var gdzOrderList = _db.pro_order_detail.Where(o => OrderList.Contains(o.order_no) && o.print_id.Contains("主")).Select(o => o.order_no).Distinct().ToList();
|
||||
var qry = _db.pro_order.Where(u => gdzOrderList.Contains(u.order_no)).AsEnumerable();
|
||||
if (!string.IsNullOrEmpty(q.order_no))
|
||||
qry = qry.Where(o => o.order_no.Contains(q.order_no.Trim()));
|
||||
if (!string.IsNullOrEmpty(q.keyin1))
|
||||
qry = qry.Where(o => o.keyin1.Contains(q.keyin1));
|
||||
if (q.f_num.HasValue && q.f_num > 0)
|
||||
qry = qry.Where(o => o.f_num == q.f_num);
|
||||
if (q.activity_num.HasValue && q.activity_num > 0)
|
||||
qry = qry.Where(o => o.activity_num == q.activity_num);
|
||||
if (q.up_time1.HasValue)
|
||||
qry = qry.Where(o => o.up_time >= q.up_time1.Value);
|
||||
if (q.up_time2.HasValue)
|
||||
qry = qry.Where(o => o.up_time < Convert.ToDateTime(q.up_time2.Value).AddDays(1));
|
||||
if (!string.IsNullOrEmpty(q.address))
|
||||
qry = qry.Where(o => o.address.Contains(q.address.Trim()));
|
||||
if (!string.IsNullOrEmpty(q.subject))
|
||||
qry = qry.Where(o => o.activity_num.HasValue && o.activity.subject.Contains(q.subject?.Trim()));
|
||||
if (!string.IsNullOrEmpty(q.u_name))
|
||||
qry = qry.Where(o => o.f_num.HasValue && o.follower.u_name.Contains(q.u_name?.Trim()));
|
||||
if (!string.IsNullOrEmpty(q.introducerTxt))
|
||||
qry = qry.Where(o => o.introducer.HasValue && o.follower1.u_name.Contains(q.introducerTxt?.Trim()));
|
||||
|
||||
if (!string.IsNullOrEmpty(q.actItemTxt))
|
||||
{
|
||||
//qry = qry.Where(o => o.pro_order_detail.Where(f2 => f2.order_no == o.order_no && aIDt.ToArray().Contains(f2.actItem_num?.ToString())).Count() > 0);
|
||||
// qry = qry.Where(o => o.pro_order_detail.Where(f2 => f2.order_no == o.order_no && aIDt.Any(x => x == f2.actItem_num)).Count() > 0);
|
||||
|
||||
qry = qry.Where(o => o.pro_order_detail.Where(f2 => f2.actItem_num.HasValue && f2.actItem.subject.Contains(q.actItemTxt?.Trim())).Count() > 0);
|
||||
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(q.country))
|
||||
qry = qry.Where(o => o.f_num != null && o.follower?.country == q.country);
|
||||
if (!string.IsNullOrEmpty(q.country2))
|
||||
{
|
||||
if (q.country2 == "1")
|
||||
{
|
||||
qry = qry.Where(o => o.f_num != null && o.follower?.country == "158");
|
||||
}
|
||||
else if (q.country2 == "2")
|
||||
{
|
||||
qry = qry.Where(o => o.f_num != null && o.follower?.country != "158");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (sortBy.Equals("order_no"))
|
||||
{
|
||||
if (sortDesc)
|
||||
qry = qry.OrderByDescending(o => o.order_no);
|
||||
else
|
||||
qry = qry.OrderBy(o => o.order_no);
|
||||
}
|
||||
else if (sortBy.Equals("keyin1_txt"))
|
||||
{
|
||||
if (sortDesc)
|
||||
qry = qry.OrderByDescending(o => o.keyin1);
|
||||
else
|
||||
qry = qry.OrderBy(o => o.keyin1);
|
||||
}
|
||||
else if (sortBy.Equals("up_time"))
|
||||
{
|
||||
if (sortDesc)
|
||||
qry = qry.OrderByDescending(o => o.up_time);
|
||||
else
|
||||
qry = qry.OrderBy(o => o.up_time);
|
||||
}
|
||||
else if (sortBy.Equals("u_name"))
|
||||
{
|
||||
if (sortDesc)
|
||||
qry = qry.OrderByDescending(o => o.follower?.u_name);
|
||||
else
|
||||
qry = qry.OrderBy(o => o.follower?.u_name);
|
||||
}
|
||||
else if (sortBy.Equals("subject"))
|
||||
{
|
||||
if (sortDesc)
|
||||
qry = qry.OrderByDescending(o => o.activity?.subject);
|
||||
else
|
||||
qry = qry.OrderBy(o => o.activity?.subject);
|
||||
}
|
||||
else
|
||||
qry = qry.OrderByDescending(o => o.reg_time);
|
||||
//var OrderList = _db.pro_order.Where(u => u.activity_num == activity_num).Select(j => j.order_no).ToList();
|
||||
//var gdzOrderList = _db.pro_order_detail.Where(o => OrderList.Contains(o.order_no) && o.print_id.Contains("主")).Select(o => o.order_no).Distinct().ToList();
|
||||
//var qry = _db.pro_order.Where(u => gdzOrderList.Contains(u.order_no)).AsEnumerable();
|
||||
var qry = _db.pro_order.Where( u => u.activity_num == activity_num).AsEnumerable();
|
||||
|
||||
qry = qry.OrderByDescending(o => o.reg_time);
|
||||
|
||||
var count = qry.Count(); //pageSize = count;//一次取回??
|
||||
var ret = new
|
||||
@@ -125,7 +45,11 @@ public class orderdetailController:ApiController
|
||||
up_time = x.up_time,
|
||||
keyin1_txt = Model.pro_order.keyin1_value_to_text(x.keyin1),
|
||||
//detail = x.pro_order_detail.Where(u => u.printed_files != null)
|
||||
detail = new { count = x.pro_order_detail.Where(u => u.actItem.act_bom.Count() == 0).Count(),
|
||||
detail = new { count = x.pro_order_detail
|
||||
.Where(u => (u.parent_num != null)
|
||||
|| u.actItem.subject.Contains("牌")
|
||||
|| !string.IsNullOrEmpty(u.f_num_tablet))
|
||||
.Count(),
|
||||
actItem = x.pro_order_detail.Where(u => u.printed_files != null).FirstOrDefault()?.print_id }
|
||||
}),
|
||||
count = count
|
||||
|
||||
@@ -39,8 +39,9 @@ public class regionController : ApiController
|
||||
var startDate = filter.StartDate.Date;
|
||||
var endDate = filter.EndDate.Date;
|
||||
|
||||
var query = _db.Region
|
||||
var query = _db.Region//区域状态是否启用这里只设置了过滤了有客房的区域,是否要过滤所有
|
||||
.Where(r => !r.IsDeleted)
|
||||
.Where(r => r.IsActive)
|
||||
.Where(r => r.Room.Any());
|
||||
|
||||
if (filter.Gender != null)
|
||||
@@ -105,8 +106,9 @@ public class regionController : ApiController
|
||||
.Where(s => s.TargetUuid == bed.Uuid
|
||||
&& s.IsDeleted == false
|
||||
&& (s.ScheduleDate == null
|
||||
|| (s.ScheduleDate >= startDate && s.ScheduleDate <= endDate)))
|
||||
|| (s.ScheduleDate >= startDate)))
|
||||
.Where(s => s.GuaDanOrderGuest.StatusCode != "403" && s.GuaDanOrderGuest.StatusCode != "404")
|
||||
.OrderBy(a => a.ScheduleDate)
|
||||
.Select(s => new
|
||||
{
|
||||
s.Uuid,
|
||||
@@ -372,6 +374,10 @@ public class regionController : ApiController
|
||||
var region = _db.Region.FirstOrDefault(r => r.Uuid == dto.Uuid);
|
||||
if (region == null)
|
||||
return NotFound();
|
||||
if(dto.RoomCount < region.Room.Count())
|
||||
{
|
||||
return BadRequest("客房數量小於已存在的客房數量");
|
||||
}
|
||||
region.Name = dto.Name;
|
||||
region.Description = dto.Description;
|
||||
region.SortOrder = dto.SortOrder;
|
||||
|
||||
@@ -379,13 +379,14 @@ public class regionRoomBedController : ApiController
|
||||
RoomUuid = roomUuid,
|
||||
CheckInAt = allocationStart,
|
||||
CheckOutAt = allocationEnd,
|
||||
StatusCode = "401",
|
||||
};
|
||||
_db.GuaDanOrderGuest.Add(guest);
|
||||
|
||||
// 新增每日排程
|
||||
if (allocationEnd.HasValue)
|
||||
{
|
||||
for (var date = allocationStart; date <= allocationEnd.Value; date = date.AddDays(1))
|
||||
for (var date = allocationStart; date < allocationEnd.Value; date = date.AddDays(1))
|
||||
{
|
||||
var newSchedule = new RegionAndRoomAndBedSchedule
|
||||
{
|
||||
@@ -396,7 +397,9 @@ public class regionRoomBedController : ApiController
|
||||
IsDeleted = false,
|
||||
CreatedBy = "系统自动分配",
|
||||
CreatedAt = DateTime.Now,
|
||||
GuaDanOrderNo = guest.GuaDanOrderNo
|
||||
GuaDanOrderNo = guest.GuaDanOrderNo,
|
||||
Title = "掛單",
|
||||
GuaDanOrderGuestUuid = guest.Uuid,
|
||||
};
|
||||
_db.RegionAndRoomAndBedSchedule.Add(newSchedule);
|
||||
}
|
||||
@@ -413,7 +416,9 @@ public class regionRoomBedController : ApiController
|
||||
IsDeleted = false,
|
||||
CreatedBy = "系统自动分配",
|
||||
CreatedAt = DateTime.Now,
|
||||
GuaDanOrderNo = guest.GuaDanOrderNo
|
||||
GuaDanOrderNo = guest.GuaDanOrderNo,
|
||||
Title = "掛單",
|
||||
GuaDanOrderGuestUuid = guest.Uuid,
|
||||
};
|
||||
_db.RegionAndRoomAndBedSchedule.Add(newSchedule);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,15 @@ public class regionRoomController : ApiController
|
||||
{
|
||||
return BadRequest("請輸入床位數量");
|
||||
}
|
||||
var region = _db.Region.Find(room.RegionUuid);
|
||||
if(region == null)
|
||||
{
|
||||
return BadRequest("未找到客房所屬的區域");
|
||||
}
|
||||
if(region.Room.Count() >= region.RoomCount)
|
||||
{
|
||||
return BadRequest("當前區域客房數量已經達到上限");
|
||||
}
|
||||
var newRoom = new Room();
|
||||
newRoom.Name = room.Name;
|
||||
newRoom.RegionUuid = room.RegionUuid;
|
||||
@@ -103,15 +112,43 @@ public class regionRoomController : ApiController
|
||||
[Route("api/region/room/delete")]
|
||||
public async Task<IHttpActionResult> deleteRoom([FromBody] Room rm)
|
||||
{
|
||||
var room = await _db.Room.FindAsync(rm.Uuid);
|
||||
if (room == null) return BadRequest("房間不存在");
|
||||
using (var transaction = _db.Database.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
var room = await _db.Room.FindAsync(rm.Uuid);
|
||||
if (room == null) return BadRequest("房間不存在");
|
||||
|
||||
var beds = _db.RegionRoomBed.Where(b => b.RoomUuid == room.Uuid);
|
||||
_db.RegionRoomBed.RemoveRange(beds);
|
||||
var beds = _db.RegionRoomBed.Where(b => b.RoomUuid == room.Uuid);
|
||||
_db.RegionRoomBed.RemoveRange(beds);
|
||||
|
||||
_db.Room.Remove(room);
|
||||
await _db.SaveChangesAsync();
|
||||
return Ok(new { message = "刪除成功" });
|
||||
_db.Room.Remove(room);
|
||||
|
||||
await _db.SaveChangesAsync();
|
||||
transaction.Commit();
|
||||
|
||||
return Ok(new { message = "刪除成功" });
|
||||
}
|
||||
catch (System.Data.Entity.Infrastructure.DbUpdateException ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
|
||||
// 判断是否为外键约束错误
|
||||
if (ex.InnerException?.InnerException is System.Data.SqlClient.SqlException sqlEx &&
|
||||
sqlEx.Number == 547) // 547 = 外键冲突
|
||||
{
|
||||
return BadRequest("房間或床位正在被使用,不能刪除");
|
||||
}
|
||||
|
||||
return InternalServerError(ex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return InternalServerError(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
using Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
|
||||
/// <summary>
|
||||
/// guadanGuestQueryController 的摘要描述
|
||||
/// </summary>
|
||||
public class guadanGuestQueryController: ApiController
|
||||
{
|
||||
private Model.ezEntities _db = new Model.ezEntities();
|
||||
public guadanGuestQueryController()
|
||||
{
|
||||
//
|
||||
// TODO: 在這裡新增建構函式邏輯
|
||||
//
|
||||
}
|
||||
[HttpPost]
|
||||
[Route("api/guadan/guest/query/list")]
|
||||
public async Task<IHttpActionResult> GetList([FromBody] SearchGuestModel search)
|
||||
{
|
||||
var query = _db.GuaDanOrderGuest
|
||||
.Where(guest => guest.StatusCode != "404");
|
||||
if(search.SearchName != null)
|
||||
{
|
||||
query = query.Where(guest => guest.followers.u_name.Contains(search.SearchName));
|
||||
}
|
||||
var data = await query.ToListAsync();
|
||||
var data1 = data.Select(a => new
|
||||
{
|
||||
name = a.followers != null ? a.followers.u_name : null,
|
||||
checkindate = a.CheckInAt,
|
||||
checkoutdate = a.CheckOutAt,
|
||||
guadanorderno = a.GuaDanOrderNo,
|
||||
roomName = GetRoomAndBedString(a.RegionRoomBed),
|
||||
}).ToList();
|
||||
return Ok(new
|
||||
{
|
||||
items = data1,
|
||||
total = data1.Count(),
|
||||
});
|
||||
|
||||
}
|
||||
public string GetRoomAndBedString(RegionRoomBed bed)
|
||||
{
|
||||
if (bed == null || bed.Room == null) return "";
|
||||
var room = bed.Room;
|
||||
var region = room.Region;
|
||||
var name = room.Name + "/" + bed.Name;
|
||||
if(region != null)
|
||||
{
|
||||
name = region.Name + "/" + name;
|
||||
}
|
||||
var parentRegion = region.Region2;
|
||||
while (parentRegion != null)
|
||||
{
|
||||
name = parentRegion.Name + "/" + name;
|
||||
parentRegion = parentRegion.Region2;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
public class SearchGuestModel
|
||||
{
|
||||
public string SearchName = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user