update from old git

This commit is contained in:
2025-09-04 18:30:54 +08:00
parent af2c152ef6
commit 61502cb3bd
46 changed files with 6420 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// GuaDanOrder 的摘要描述
/// </summary>
namespace Model
{
public partial class GuaDanOrder
{
public static string GenerateStatusCode()
{
string prefix = "GD";
string datePart = DateTime.Now.ToString("yyyyMMdd");
string randomPart = Guid.NewGuid().ToString("N").Substring(0, 4).ToUpper();
return $"{prefix}{datePart}-{randomPart}";
}
}
}

View File

@@ -0,0 +1,49 @@
using DocumentFormat.OpenXml.Wordprocessing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Region 的摘要描述
/// </summary>
namespace Model
{
public partial class Region
{
public bool IsAvailable()
{
//判断当前区域是否可用,需要判断父区域是否可用,如果父区域不可用,则所有字区域都不可用
if (!this.IsActive)
{
return false;
}
Region region = this.Region2;
while (region != null) {
if (!region.IsActive) {
return false;
}
region = region.Region2;
}
return true;
//这里增加根据区域排程判定在指定时间段内区域是否可用
}
public bool? IsMaleOrFemale()
{
if (this.Gender.HasValue)
return this.Gender.Value;
Region currentRegion = this.Region2;
while (currentRegion != null)
{
if (currentRegion.Gender.HasValue)
return currentRegion.Gender.Value;
currentRegion = currentRegion.Region2; // 上级区域
}
// 都没有定义性别
return null;
}
}
}

View File

@@ -0,0 +1,144 @@
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
/// <summary>
/// RegionAndRoomAndBedSchedule 的摘要描述
/// </summary>
namespace Model
{
public partial class RegionAndRoomAndBedSchedule
{
public enum SchedulePurpose
{
None = -1, // 無特定用途
// 區域相關
Region_Repair = 10, // 區域修繕
Region_Cleaning = 11, // 區域清潔
// 客房相關
Room_Reservation = 20, // 客房預訂
Room_Cleaning = 21, // 客房清潔
Room_Disinfection = 22, // 客房消毒
Room_Repair = 23, // 客房維修
// 床位相關
Bed_Reservation = 30, // 床位預訂
Bed_Cleaning = 31, // 床位清潔
Bed_Repair = 32, // 床位維修
Bed_Disinfection = 33, // 床位消毒
// 其他用途
Event_Use = 90, // 活動使用
Other = 99 // 其他
}
public enum StatusEnum
{
None = 0,
Normal = 1,
Cancel = 2,
}
/// <summary>
/// 查找指定时间段内可用床位(无排程占用)
/// </summary>
/// <param name="db">数据库上下文</param>
/// <param name="start">查询开始时间</param>
/// <param name="end">查询结束时间</param>
/// <returns>可用床位列表</returns>
public static async Task<List<RegionRoomBed>> GetAvailableBedsAsync(ezEntities db, DateTime start, DateTime? end)
{
start = start.Date;
end = end?.Date;
// 找出在日期範圍內被占用的床位 Uuid包括長期占用 ScheduleDate = null
var busyBedUuidsQuery = db.RegionAndRoomAndBedSchedule
.Where(s => s.IsDeleted == false && s.IsActive
&& (s.ScheduleDate == null
|| (end.HasValue
&& s.ScheduleDate >= start
&& s.ScheduleDate <= end.Value)));
var busyBedUuids = await busyBedUuidsQuery
.Select(s => s.TargetUuid)
.Distinct()
.ToListAsync();
// 空閒床位 = 所有床位 - 忙碌床位
var availableBeds = await db.RegionRoomBed
.Where(b => !busyBedUuids.Contains(b.Uuid))
.ToListAsync();
return availableBeds;
}
public static async Task<bool> IsBedAvailableAsync(ezEntities db, Guid targetUuid, DateTime start, DateTime? end)
{
// 如果 end 為 null表示長期占用直接判斷是否已有長期占用
if (end == null)
{
var hasLongTerm = await db.RegionAndRoomAndBedSchedule
.AnyAsync(s => s.IsDeleted == false
&& s.IsActive
&& s.TargetUuid == targetUuid
&& s.ScheduleDate == null);
return !hasLongTerm;
}
// 短期占用,查詢每日排程中有無衝突
var totalDays = (end.Value.Date - start.Date).Days + 1;
for (int i = 0; i < totalDays; i++)
{
var date = start.Date.AddDays(i);
var conflict = await db.RegionAndRoomAndBedSchedule
.AnyAsync(s => s.IsDeleted == false
&& s.IsActive
&& s.TargetUuid == targetUuid
&& s.ScheduleDate == date);
if (conflict)
return false;
}
return true;
}
public static async Task<object> GetAvailableBedCountsAsync(ezEntities db, DateTime start, DateTime end)
{
start = start.Date;
end = end.Date;
// 找出所有在日期範圍內被占用的床位
var busyBedUuids = await db.RegionAndRoomAndBedSchedule
.Where(s => s.IsDeleted == false && s.IsActive
&& (s.ScheduleDate == null // 長期占用
|| (s.ScheduleDate >= start && s.ScheduleDate <= end)))
.Select(s => s.TargetUuid)
.Distinct()
.ToListAsync();
// 可用床位 = 所有床位 - 忙碌床位
var availableBeds = db.RegionRoomBed
.Where(b => !busyBedUuids.Contains(b.Uuid));
var result = await availableBeds
.GroupBy(b => b.Gender)
.Select(g => new
{
Gender = g.Key,
Count = g.Count()
})
.ToListAsync();
var male = result.Where(r => r.Gender == true).Select(r => r.Count).FirstOrDefault();
var female = result.Where(r => r.Gender == false).Select(r => r.Count).FirstOrDefault();
return new { male, female };
}
}
}

View File

@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
/// <summary>
/// RegionRoomBed 的摘要描述
/// </summary>
namespace Model
{
public partial class RegionRoomBed
{
public bool IsAvailable()
{
//判断床位是否可用:自身是否启用
//床位使用排程是否可用
//是否需要传入时间?指定时间间隔内
if (!this.IsActive)
{
return false;
}
return this.Room.IsAvailable();
//根据床位排程判定床位是否可用
}
public bool IsAvailableDuring(DateTime checkInAt, DateTime? checkOutAt, ezEntities _db)
{
// 床位本身不可用,直接返回 false
if (!this.IsActive || !this.Room.IsAvailable())
{
return false;
}
// 如果資料庫 ScheduleDate 是 date 型別,本身沒有時間部分,可以直接比較
var conflict = _db.RegionAndRoomAndBedSchedule.Any(s =>
s.TargetUuid == this.Uuid &&
s.IsActive &&
!s.IsDeleted &&
(
s.ScheduleDate == null || // 長期占用
(checkOutAt.HasValue
? (s.ScheduleDate >= checkInAt && s.ScheduleDate <= checkOutAt.Value)
: s.ScheduleDate >= checkInAt)
)
);
return !conflict;
}
}
}

View File

@@ -0,0 +1,55 @@
using Model;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Model
{
[MetadataType(typeof(RegionRoomBedStatusMetadata))]
public partial class RegionRoomBedStatus
{
private class RegionRoomBedStatusMetadata
{
//[JsonIgnore]
//public virtual ICollection<RegionRoomBed> RegionRoomBed { get; set; }
//[JsonIgnore]
//public virtual ICollection<GuaDanOrder> GuaDanOrder { get; set; }
}
public enum CategoryEnum
{
Unknown = 0,
BedStatus = 1,
GuaDanStatus = 2,
RoomStatus = 3,
GuadanLianyouStatus = 4,
}
[JsonProperty("CategoryName")]
public string CategoryName => GetCategoryName(this.Category);
public static string GetCategoryName(int? category)
{
if (category == null) return "";
switch ((CategoryEnum)category)
{
case CategoryEnum.BedStatus: return "床位狀態";
case CategoryEnum.GuaDanStatus: return "掛單狀態";
case CategoryEnum.RoomStatus: return "房間狀態";
case CategoryEnum.GuadanLianyouStatus: return "個人掛單狀態";
default: return "";
}
}
public static IEnumerable GetCategoryList()
{
var list = new ArrayList();
list.Add(new { Value = (int)CategoryEnum.BedStatus, Text = "床位狀態" });
list.Add(new { Value = (int)CategoryEnum.GuaDanStatus, Text = "掛單狀態" });
list.Add(new { Value = (int)CategoryEnum.RoomStatus, Text = "房間狀態" });
list.Add(new { Value = (int)CategoryEnum.GuadanLianyouStatus, Text = "個人掛單狀態" });
return list;
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Model
{
public partial class Room
{
public bool IsAvailable()
{
//判断当前房间是否可用,需要判断父区域是否可用,如果父区域不可用,则所有子区域都不可用
// 有值且是 false表示不可用
if (this.IsActive.HasValue && this.IsActive.Value == false)
return false;
return this.Region.IsAvailable();
//这里增加根据房间排程判定在指定时间段内房间是否可用
}
}
}
/// <summary>
/// Room 的摘要描述
/// </summary>

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
/// <summary>
/// GuaDanGuestView 的摘要描述
/// </summary>
public class GuaDanGuestView
{
public GuaDanGuestView()
{
//
// TODO: 在這裡新增建構函式邏輯
//
}
public int? Id { get; set; }
[Required]
[StringLength(100, MinimumLength = 1)]
public string FullName { get; set; }
public Nullable<int> Gender { get; set; }
public string Phone { get; set; }
public string IDNumber { get; set; }
public Nullable<System.DateTime> Birthday { get; set; }
public string Email { get; set; }
public string Address { get; set; }
public string EmergencyContact { get; set; }
public string EmergencyPhone { get; set; }
public Nullable<int> Status { get; set; }
public string Notes { get; set; }
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// GuaDanOrderView 的摘要描述
/// </summary>
public class GuaDanOrderView
{
public Guid? Uuid { get; set; } = null;
public System.DateTime startdate { get; set; }
public Nullable<System.DateTime> enddate { get; set; }
public Guid? statusUuid { get; set; } = null;
public Nullable<int> createuser { get; set; }
public System.DateTime createdat { get; set; }
public System.DateTime updatedat { get; set; }
public string note { get; set; }
public string bookerName { get; set; }
public string bookerPhone { get; set; }
public int? bookerFollowerNum { get; set; }
}