掛單
This commit is contained in:
1 parent
1cb2a7a35e
commit
8db6019ba3
10 files changed
+1120
-703
No files matched your search
@@ -109,6 +109,14 @@ public class guadanGuestQueryController: ApiController
|
||||
.ToListAsync();
|
||||
return Ok(data);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("api/guadan/getGuadanLimit")]
|
||||
public async Task<IHttpActionResult> GetGuadanLimit([FromUri] dynamic req)
|
||||
{
|
||||
var data=_db.GuaDanLimits.ToList();
|
||||
return Ok(data);
|
||||
}
|
||||
public string GetRoomAndBedString(RegionRoomBed bed)
|
||||
{
|
||||
if (bed == null || bed.Room == null) return "";
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Model;
|
||||
using DocumentFormat.OpenXml.EMMA;
|
||||
using Model;
|
||||
using Org.BouncyCastle.Asn1.Ocsp;
|
||||
using PagedList;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -7,6 +9,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using static Model.admin_log;
|
||||
/// <summary>
|
||||
/// guadanOderController 的摘要描述
|
||||
/// </summary>
|
||||
@@ -184,6 +187,156 @@ public class guadanOrderController : ApiController
|
||||
return Ok(guadanorder);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("api/guadan/saveGandan")]
|
||||
public async Task<IHttpActionResult> SaveGandan([FromBody] dynamic req)
|
||||
{
|
||||
var json = req;
|
||||
if (json != null&&json.order!=null) {
|
||||
var order = json.order;
|
||||
if (string.IsNullOrEmpty(order.GuaDanOrderNo))
|
||||
{//表示新增掛單
|
||||
// 生成新的掛單編號跟uuid
|
||||
var guadanorder = new GuaDanOrder
|
||||
{
|
||||
StartDate = order.startdate,
|
||||
EndDate = order.enddate,
|
||||
CreateUser = order.createuser,
|
||||
CreatedAt = DateTime.Now,
|
||||
UpdatedAt = DateTime.Now,
|
||||
Notes = order.note,
|
||||
GuaDanOrderNo = GuaDanOrder.GenerateStatusCode(),
|
||||
BookerName = order.bookerName,
|
||||
BookerPhone = order.bookerPhone,
|
||||
Uuid = Guid.NewGuid(),
|
||||
ActivityNum = order.activityNum,
|
||||
};
|
||||
//掛單明細
|
||||
var list = new List<GuaDanOrderGuest>();
|
||||
var guest = new GuaDanOrderGuest();
|
||||
var bedList = new List<RegionAndRoomAndBedSchedule>();
|
||||
if (json.detail!=null)
|
||||
{
|
||||
var details = json.detail;
|
||||
foreach (var detail in details)
|
||||
{
|
||||
guest=new GuaDanOrderGuest
|
||||
{
|
||||
GuaDanOrderNo = guadanorder.GuaDanOrderNo,
|
||||
Uuid = Guid.NewGuid(),
|
||||
StatusCode = GuaDanOrderGuest.STATUS_BOOKED, // 預約狀態
|
||||
RoomUuid = detail.roomUuid,
|
||||
BedUuid = detail.bedUuid,
|
||||
CheckInAt = detail.checkInAt,
|
||||
CheckOutAt = detail.checkOutAt,
|
||||
Sex = detail.gender,
|
||||
Handi = detail.handi,
|
||||
IsDeleted = false,
|
||||
Name = detail.name,
|
||||
};
|
||||
list.Add(guest);
|
||||
if (!Guid.TryParse((string)detail.bedUuid, out Guid targetGuid))
|
||||
{
|
||||
return BadRequest("無效的 GUID 格式");
|
||||
}
|
||||
|
||||
if (detail.bedUuid!=null&&!string.IsNullOrEmpty((string)detail.bedUuid))
|
||||
{
|
||||
var bed = _db.RegionRoomBed.Where(r => r.Uuid == targetGuid);
|
||||
if (bed == null)
|
||||
return BadRequest("床位不存在");
|
||||
// 檢查床位可用性
|
||||
var bedIsCanUse = await RegionAndRoomAndBedSchedule.IsBedAvailableAsync(
|
||||
_db,
|
||||
targetGuid,
|
||||
guest.CheckInAt.Value,
|
||||
guest.CheckOutAt.Value
|
||||
);
|
||||
if (!bedIsCanUse)
|
||||
return BadRequest("床位在該時間段內已被占用");
|
||||
}
|
||||
else {
|
||||
return BadRequest("未設定床位");
|
||||
}
|
||||
|
||||
int totalDays = (guest.CheckOutAt.Value - guest.CheckInAt.Value).Days;
|
||||
for (int i = 0; i < totalDays; i++)
|
||||
{
|
||||
var scheduleDate = guest.CheckOutAt.Value.AddDays(i);
|
||||
|
||||
var schedul = new RegionAndRoomAndBedSchedule
|
||||
{
|
||||
Title = "掛單",
|
||||
Description = "床位掛單",
|
||||
ScheduleDate = scheduleDate,
|
||||
IsDeleted = false,
|
||||
IsCancel = false,
|
||||
TargetUuid = guest.BedUuid,
|
||||
UseType = (int)RegionAndRoomAndBedSchedule.SchedulePurpose.Bed_Reservation,
|
||||
CreatedAt = DateTime.Now,
|
||||
GuaDanOrderNo = guest.GuaDanOrderNo,
|
||||
Uuid = Guid.NewGuid(),
|
||||
GuaDanOrderGuestUuid = guest.Uuid,
|
||||
};
|
||||
//_db.RegionAndRoomAndBedSchedule.Add(schedul);
|
||||
bedList.Add(schedul);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_db.GuaDanOrder.Add(guadanorder);
|
||||
_db.GuaDanOrderGuest.AddRange(list);
|
||||
_db.RegionAndRoomAndBedSchedule.AddRange(bedList);
|
||||
_db.SaveChanges();
|
||||
}
|
||||
else
|
||||
{//表示更新掛單
|
||||
var model =await _db.GuaDanOrder.FindAsync((string)order.Uuid);
|
||||
if (model == null)
|
||||
{
|
||||
return BadRequest("未找到對應掛單資料");
|
||||
}
|
||||
model.StartDate = order.startdate;
|
||||
model.EndDate = order.enddate;
|
||||
model.Notes = order.note;
|
||||
model.BookerName = order.bookerName;
|
||||
model.BookerPhone = order.bookerPhone;
|
||||
model.ActivityNum = order.activityNum;
|
||||
|
||||
//更新掛單明細...還要處理RegionAndRoomAndBedSchedule
|
||||
}
|
||||
//if (json.detail != null)
|
||||
//{
|
||||
// var details = json.detail;
|
||||
// foreach (var detail in details)
|
||||
// {
|
||||
// var guadanDetail = new GuaDanOrderGuest
|
||||
// {
|
||||
// GuaDanOrderNo = order.GuaDanOrderNo,
|
||||
// //FollowerNum = detail.guestName,
|
||||
// Uuid = detail.uuid,
|
||||
// StatusCode = "401", // 預約狀態
|
||||
// RoomUuid = detail.roomUuid,
|
||||
// BedUuid = detail.bedUuid,
|
||||
// CheckInAt = detail.checkInAt,
|
||||
// CheckOutAt = detail.checkOutAt,
|
||||
// Sex = detail.gender,
|
||||
// Handi = detail.handi,
|
||||
// IsDeleted = false,
|
||||
// Name = detail.name,
|
||||
// };
|
||||
// _db.GuaDanOrderGuest.Add(guadanDetail);
|
||||
// }
|
||||
|
||||
|
||||
// //return BadRequest("掛單資料不可為空");
|
||||
//}
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
[Route("api/guadan/update")]
|
||||
public async Task<IHttpActionResult> updateGuadanOrder(GuaDanOrderView model)
|
||||
|
||||
@@ -7,6 +7,7 @@ using Org.BouncyCastle.Asn1.Ocsp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
@@ -273,6 +274,42 @@ public class regionRoomBedController : ApiController
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("api/region/bed/getAvailableBeds")]
|
||||
public async Task<IHttpActionResult> GetAvailableBeds([FromBody] dynamic request)
|
||||
{
|
||||
var f = new System.Globalization.CultureInfo("zh-TW",true);
|
||||
//f. = "yyyy-MM-dd";
|
||||
var json = request;
|
||||
DateTime allocationStart = Convert.ToDateTime((string)json.startTime,f);
|
||||
DateTime? allocationEnd = Convert.ToDateTime( (string)json.endTime,f);
|
||||
//bool isAllallocation = true; //是否全部分配完毕
|
||||
// 获取可用床位列表
|
||||
var busyBedUuidsQuery = _db.RegionAndRoomAndBedSchedule
|
||||
.Where(s => s.IsDeleted == false && !s.IsCancel
|
||||
&& ( s.ScheduleDate >= allocationStart
|
||||
&& s.ScheduleDate <= allocationEnd));
|
||||
|
||||
var busyBedUuids = busyBedUuidsQuery
|
||||
.Select(s => s.TargetUuid)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
// 空閒床位 = 所有床位 - 忙碌床位
|
||||
var availableBeds = _db.RegionRoomBed.Select(b=>new {
|
||||
b.Name ,b.Uuid,b.StatusCode,b.IsActive,
|
||||
b.RoomUuid,
|
||||
Room=_db.Room.Where(r=>r.Uuid==b.RoomUuid).
|
||||
Select(r=>new { r.Name,r.RegionUuid,
|
||||
RegionName=_db.Region.Where(g=>g.Uuid==r.RegionUuid).Select(g=>g.Name).FirstOrDefault()}).FirstOrDefault(),
|
||||
})
|
||||
.Where(b => !busyBedUuids.Contains(b.Uuid))
|
||||
.ToList();
|
||||
|
||||
|
||||
return Ok(new { availableBeds });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("api/region/bed/preallocation")]
|
||||
public async Task<IHttpActionResult> PreAutoAllocationBed([FromBody] ConfirmAllocationRequest request)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user