[merge] rename function
This commit is contained in:
commit
db0a29dd9c
|
@ -43,17 +43,23 @@ namespace SiteManagementSystem_SoftwareEngineering_.Service
|
||||||
}
|
}
|
||||||
public void AddField(string name, string value)
|
public void AddField(string name, string value)
|
||||||
{
|
{
|
||||||
var t = (bool)
|
try
|
||||||
_service.RemoveField(
|
|
||||||
new Field
|
|
||||||
{
|
{
|
||||||
Id = Guid.Parse("99b472f1-9912-49df-bb1f-3db0fc5bee11"),
|
var t = (bool)
|
||||||
Name = "t1",
|
_service.AddAppointment(
|
||||||
Position = "t2",
|
new FieldRecord
|
||||||
Opentime = "t3"
|
{
|
||||||
|
Fid = Guid.NewGuid(),
|
||||||
|
Uid = Guid.NewGuid(),
|
||||||
|
StartTime = DateTime.Now,
|
||||||
|
EndTime = DateTime.Now + TimeSpan.FromMinutes(30)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
Console.WriteLine(t);
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{ }
|
||||||
|
Console.WriteLine(_layer.RecordDb.FindAll("Uid",Guid.Parse("bd422092-7f2b-4f53-ad08-47a75aa089ea")).First().StartTime);
|
||||||
|
Console.WriteLine(DateTime.Now);
|
||||||
//Console.WriteLine(_service.AddField());
|
//Console.WriteLine(_service.AddField());
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
import clr
|
||||||
|
|
||||||
|
clr.AddReference('System')
|
||||||
|
from System import DateTime, TimeSpan, Convert
|
||||||
|
|
||||||
|
|
||||||
|
class Duration:
|
||||||
|
time_span: TimeSpan
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
if len(args) == 1:
|
||||||
|
if args[0] is Duration:
|
||||||
|
self.time_span = args[0]
|
||||||
|
else:
|
||||||
|
raise ValueError("Invalid arguments for Duration initialization")
|
||||||
|
else:
|
||||||
|
raise ValueError("Invalid arguments for Duration initialization")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_seconds(second: int):
|
||||||
|
return Duration(TimeSpan.FromSeconds(second))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_minutes(minute: int):
|
||||||
|
return Duration(TimeSpan.FromMinutes(minute))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_hours(hour: int):
|
||||||
|
return Duration(TimeSpan.FromHours(hour))
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
|
return self.time_span < other.time_span
|
||||||
|
|
||||||
|
def __le__(self, other):
|
||||||
|
return self.time_span <= other.time_span
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return self.time_span == other.time_span
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
return self.time_span != other.time_span
|
||||||
|
|
||||||
|
def __gt__(self, other):
|
||||||
|
return self.time_span > other.time_span
|
||||||
|
|
||||||
|
def __ge__(self, other):
|
||||||
|
return self.time_span >= other.time_span
|
||||||
|
|
||||||
|
|
||||||
|
class Time:
|
||||||
|
struct_time: DateTime
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
if len(args) == 0:
|
||||||
|
self.struct_time = DateTime.Now
|
||||||
|
elif len(args) == 1:
|
||||||
|
print(type(args[0]))
|
||||||
|
if args[0] is str:
|
||||||
|
self.struct_time = Convert.ToDateTime(args[0])
|
||||||
|
else:
|
||||||
|
self.struct_time = args[0]
|
||||||
|
else:
|
||||||
|
raise ValueError("Invalid arguments for Time initialization")
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
|
return self.struct_time < other.struct_time
|
||||||
|
|
||||||
|
def __le__(self, other):
|
||||||
|
return self.struct_time <= other.struct_time
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return self.struct_time == other.struct_time
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
return self.struct_time != other.struct_time
|
||||||
|
|
||||||
|
def __gt__(self, other):
|
||||||
|
return self.struct_time > other.struct_time
|
||||||
|
|
||||||
|
def __ge__(self, other):
|
||||||
|
return self.struct_time >= other.struct_time
|
||||||
|
|
||||||
|
def __add__(self, other: Duration):
|
||||||
|
return Time(self.struct_time + other.time_span)
|
||||||
|
|
||||||
|
def __sub__(self, other: 'Time'):
|
||||||
|
return TimeSpan(self.struct_time - other.struct_time)
|
|
@ -1,18 +1,13 @@
|
||||||
import time
|
from cstime import *
|
||||||
|
|
||||||
from layer import Layer
|
from layer import Layer
|
||||||
from field import Field
|
from field import Field
|
||||||
from user import User
|
from user import User
|
||||||
from field_record import FieldRecord
|
from field_record import FieldRecord
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Service:
|
class Service:
|
||||||
layer = Layer(LAYER) # 初始化数据库数据并启动增删查功能
|
layer = Layer(LAYER) # 初始化数据库数据并启动增删查功能
|
||||||
|
|
||||||
|
|
||||||
# 普通用户操作:
|
# 普通用户操作:
|
||||||
# 请求一条场地使用信息(普通用户自动传入自己的用户id,管理员用户手动选择传入用户id) #redis
|
# 请求一条场地使用信息(普通用户自动传入自己的用户id,管理员用户手动选择传入用户id) #redis
|
||||||
# 参数:cs_fieldRecord(用户id,场地id,开始时间,结束时间) 返回:bool 是否预约成功
|
# 参数:cs_fieldRecord(用户id,场地id,开始时间,结束时间) 返回:bool 是否预约成功
|
||||||
|
@ -31,12 +26,11 @@ class Service:
|
||||||
self.layer.add_record(fieldRecord)
|
self.layer.add_record(fieldRecord)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
# 提前结束场地的使用 正在使用时提前结束 #finished
|
# 提前结束场地的使用 正在使用时提前结束 #finished
|
||||||
# 参数:cs_user //cs_fieldRecord 返回:bool 是否结束成功
|
# 参数:cs_user //cs_fieldRecord 返回:bool 是否结束成功
|
||||||
def end_appointment(self, cs_user) -> bool:
|
def end_appointment(self, cs_user) -> bool:
|
||||||
user = User(cs_user)
|
user = User(cs_user)
|
||||||
records=self.layer.find_record("Uid",user.uid)
|
records = self.layer.find_record("Uid", user.id)
|
||||||
if len(records) == 0:
|
if len(records) == 0:
|
||||||
raise ValueError("No appointment")
|
raise ValueError("No appointment")
|
||||||
elif len(records) != 1:
|
elif len(records) != 1:
|
||||||
|
@ -46,7 +40,7 @@ class Service:
|
||||||
uid = user.id
|
uid = user.id
|
||||||
start_time = records[0].start_time
|
start_time = records[0].start_time
|
||||||
# 获取当前时间
|
# 获取当前时间
|
||||||
curtime=time.localtime()
|
curtime = Time()
|
||||||
# 正在使用时可以提前结束,修改结束时间
|
# 正在使用时可以提前结束,修改结束时间
|
||||||
if curtime >= start_time and curtime < records[0].end_time:
|
if curtime >= start_time and curtime < records[0].end_time:
|
||||||
fieldRecord = FieldRecord(fid, uid, start_time, curtime)
|
fieldRecord = FieldRecord(fid, uid, start_time, curtime)
|
||||||
|
@ -56,8 +50,6 @@ class Service:
|
||||||
else:
|
else:
|
||||||
raise ValueError("No ongoing appointment")
|
raise ValueError("No ongoing appointment")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 取消预约
|
# 取消预约
|
||||||
# 参数:cs_user //cs_fieldRecord(用户id,场地id,开始时间,结束时间) 返回:bool 是否取消成功
|
# 参数:cs_user //cs_fieldRecord(用户id,场地id,开始时间,结束时间) 返回:bool 是否取消成功
|
||||||
def cancel_appointment(self, cs_user) -> bool:
|
def cancel_appointment(self, cs_user) -> bool:
|
||||||
|
@ -68,14 +60,13 @@ class Service:
|
||||||
elif len(records) != 1:
|
elif len(records) != 1:
|
||||||
raise ValueError("Appointment nums error")
|
raise ValueError("Appointment nums error")
|
||||||
else:
|
else:
|
||||||
curtime=time.localtime()
|
curtime = Time()
|
||||||
if curtime < records[0].start_time:
|
if curtime < records[0].start_time:
|
||||||
fieldRecord = FieldRecord(records[0])
|
fieldRecord = FieldRecord(records[0])
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
raise ValueError("Appointment has started")
|
raise ValueError("Appointment has started")
|
||||||
|
|
||||||
|
|
||||||
# 延长场地的使用时间 #redis
|
# 延长场地的使用时间 #redis
|
||||||
# 参数:cs_fieldRecord(用户id,场地id(null),开始时间(null),结束时间) 返回:bool 是否延长成功
|
# 参数:cs_fieldRecord(用户id,场地id(null),开始时间(null),结束时间) 返回:bool 是否延长成功
|
||||||
def extend_appointment(self, cs_fieldRecord) -> bool:
|
def extend_appointment(self, cs_fieldRecord) -> bool:
|
||||||
|
@ -86,7 +77,7 @@ class Service:
|
||||||
elif len(records) != 1:
|
elif len(records) != 1:
|
||||||
raise ValueError("Appointment nums error")
|
raise ValueError("Appointment nums error")
|
||||||
else:
|
else:
|
||||||
curtime=time.localtime()
|
curtime = Time()
|
||||||
start_time = records[0].start_time
|
start_time = records[0].start_time
|
||||||
end_time = records[0].end_time
|
end_time = records[0].end_time
|
||||||
if curtime >= start_time and curtime < end_time:
|
if curtime >= start_time and curtime < end_time:
|
||||||
|
@ -96,15 +87,14 @@ class Service:
|
||||||
else:
|
else:
|
||||||
raise ValueError("Appointment is finished or not started")
|
raise ValueError("Appointment is finished or not started")
|
||||||
|
|
||||||
|
|
||||||
# 查询场地占用
|
# 查询场地占用
|
||||||
# 参数:cs_fieldRecord(用户id(null),场地id,开始时间(null),结束时间(null)) 返回:list_time [(start_time,end_time),(...),(...),...]
|
# 参数:cs_fieldRecord(用户id(null),场地id,开始时间(null),结束时间(null)) 返回:list_time [(start_time,end_time),(...),(...),...]
|
||||||
def query_fieldUsage(self, cs_fieldRecord) -> []:
|
def query_fieldUsage(self, cs_fieldRecord) -> []:
|
||||||
fid = FieldRecord(cs_fieldRecord).fid
|
fid = FieldRecord(cs_fieldRecord).fid
|
||||||
records = self.layer.find_record("Fid", fid)
|
records = self.layer.find_record("Fid", fid)
|
||||||
list_time=[]
|
list_time: List[(Time, Time)] = []
|
||||||
for x in records:
|
for x in records:
|
||||||
tup=(time.strftime("%Y-%m-%d %H:%M:%S",x.start_time),time.strftime("%Y-%m-%d %H:%M:%S",x.end_time))
|
tup = (x.start_time.struct_time, x.end_time.struct_time)
|
||||||
list_time.append(tup)
|
list_time.append(tup)
|
||||||
# 使用 sorted() 函数进行排序,key 参数指定用于排序的键函数
|
# 使用 sorted() 函数进行排序,key 参数指定用于排序的键函数
|
||||||
sorted_time_list = sorted(list_time, key=lambda x: x[0])
|
sorted_time_list = sorted(list_time, key=lambda x: x[0])
|
||||||
|
@ -112,15 +102,12 @@ class Service:
|
||||||
for x in range(len(sorted_time_list) - 1, 0, -1):
|
for x in range(len(sorted_time_list) - 1, 0, -1):
|
||||||
strtm2 = sorted_time_list[x][0]
|
strtm2 = sorted_time_list[x][0]
|
||||||
strtm1 = sorted_time_list[x - 1][1]
|
strtm1 = sorted_time_list[x - 1][1]
|
||||||
timestamp1 = time.mktime(time.strptime(strtm1, "%Y-%m-%d %H:%M:%S"))
|
if Time(strtm2) - Time(strtm1) <= Duration.from_minutes(10):
|
||||||
timestamp2 = time.mktime(time.strptime(strtm2, "%Y-%m-%d %H:%M:%S"))
|
|
||||||
if (timestamp2 - timestamp1) / 60 <= 10:
|
|
||||||
tup = (sorted_time_list[x - 1][0], sorted_time_list[x][1])
|
tup = (sorted_time_list[x - 1][0], sorted_time_list[x][1])
|
||||||
sorted_time_list.pop(x)
|
sorted_time_list.pop(x)
|
||||||
sorted_time_list[x - 1] = tup
|
sorted_time_list[x - 1] = tup
|
||||||
return sorted_time_list
|
return sorted_time_list
|
||||||
|
|
||||||
|
|
||||||
# 查询用户的预约记录
|
# 查询用户的预约记录
|
||||||
# 参数:cs_user(id) 返回:array_cs_fieldRecord
|
# 参数:cs_user(id) 返回:array_cs_fieldRecord
|
||||||
def query_appointment_record(self, cs_user) -> []:
|
def query_appointment_record(self, cs_user) -> []:
|
||||||
|
@ -137,8 +124,6 @@ class Service:
|
||||||
cs_fieldRecords.append(FieldRecord.parse_to_csharp_object(FieldRecord(x)))
|
cs_fieldRecords.append(FieldRecord.parse_to_csharp_object(FieldRecord(x)))
|
||||||
return cs_fieldRecords
|
return cs_fieldRecords
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 管理员操作:(包含普通用户操作以及一下特殊操作)
|
# 管理员操作:(包含普通用户操作以及一下特殊操作)
|
||||||
|
|
||||||
# 添加一个场地
|
# 添加一个场地
|
||||||
|
@ -162,10 +147,3 @@ class Service:
|
||||||
raise ValueError("Field id duplication")
|
raise ValueError("Field id duplication")
|
||||||
self.layer.remove_field(field)
|
self.layer.remove_field(field)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
from field import *
|
from field import *
|
||||||
from user import *
|
from user import *
|
||||||
import time
|
from cstime import Time
|
||||||
import clr
|
import clr
|
||||||
|
|
||||||
clr.AddReference('System')
|
clr.AddReference('System')
|
||||||
from System import Guid, Convert
|
from System import Guid
|
||||||
|
|
||||||
|
|
||||||
class FieldRecord:
|
class FieldRecord:
|
||||||
fid = ""
|
fid = ""
|
||||||
uid = ""
|
uid = ""
|
||||||
start_time: time.struct_time
|
start_time: Time
|
||||||
end_time: time.struct_time
|
end_time: Time
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
if len(args) == 0:
|
if len(args) == 0:
|
||||||
|
@ -20,11 +20,12 @@ class FieldRecord:
|
||||||
field_record = args[0]
|
field_record = args[0]
|
||||||
self.fid = field_record.Fid.ToString()
|
self.fid = field_record.Fid.ToString()
|
||||||
self.uid = field_record.Uid.ToString()
|
self.uid = field_record.Uid.ToString()
|
||||||
self.start_time = time.strptime(field_record.StartTime.ToString(), "%Y-%m-%d %H:%M:%S")
|
print(type(field_record.StartTime))
|
||||||
self.end_time = time.strptime(field_record.EndTime.ToString(), "%Y-%m-%d %H:%M:%S")
|
self.start_time = Time(field_record.StartTime)
|
||||||
|
self.end_time = Time(field_record.EndTime)
|
||||||
elif len(args) == 4 and isinstance(args[0], User) and isinstance(args[1], Field) and isinstance(args[2],
|
elif len(args) == 4 and isinstance(args[0], User) and isinstance(args[1], Field) and isinstance(args[2],
|
||||||
time.struct_time) and isinstance(
|
Time.struct_time) and isinstance(
|
||||||
args[3], time.struct_time):
|
args[3], Time.struct_time):
|
||||||
user, field, start_time, end_time = args
|
user, field, start_time, end_time = args
|
||||||
self.fid = field.id
|
self.fid = field.id
|
||||||
self.uid = user.id
|
self.uid = user.id
|
||||||
|
@ -36,6 +37,6 @@ class FieldRecord:
|
||||||
def parse_to_csharp_object(self, empty_field_record):
|
def parse_to_csharp_object(self, empty_field_record):
|
||||||
empty_field_record.Fid = Guid.Parse(self.fid)
|
empty_field_record.Fid = Guid.Parse(self.fid)
|
||||||
empty_field_record.Uid = Guid.Parse(self.uid)
|
empty_field_record.Uid = Guid.Parse(self.uid)
|
||||||
empty_field_record.StartTime = Convert.ToDateTime(time.strftime("%Y-%m-%d %H:%M:%S", self.start_time))
|
empty_field_record.StartTime = self.start_time.struct_time
|
||||||
empty_field_record.EndTime = Convert.ToDateTime(time.strftime("%Y-%m-%d %H:%M:%S", self.end_time))
|
empty_field_record.EndTime = self.end_time.struct_time
|
||||||
return empty_field_record
|
return empty_field_record
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
from user import User
|
from user import User
|
||||||
from field import Field
|
from field import Field
|
||||||
from field_record import FieldRecord
|
from field_record import FieldRecord
|
||||||
|
|
||||||
clr.AddReference('System')
|
clr.AddReference('System')
|
||||||
from System import Guid, DateTime
|
from System import Guid, DateTime
|
||||||
|
|
||||||
|
@ -34,7 +33,7 @@ class Layer:
|
||||||
def find_record(self, key: str, value: str) -> [FieldRecord]:
|
def find_record(self, key: str, value: str) -> [FieldRecord]:
|
||||||
return [FieldRecord(t) for t in self._record_db.FindAll(key, Guid.Parse(value))]
|
return [FieldRecord(t) for t in self._record_db.FindAll(key, Guid.Parse(value))]
|
||||||
|
|
||||||
# One User only allowed to book one field at a time
|
# One User only allowed to book one field at a Time
|
||||||
def remove_record(self, record: FieldRecord) -> 'Layer':
|
def remove_record(self, record: FieldRecord) -> 'Layer':
|
||||||
self._record_db.TryDelete("Uid", record.parse_to_csharp_object(self._record_db.GetDefaultEntity()).Uid)
|
self._record_db.TryDelete("Uid", record.parse_to_csharp_object(self._record_db.GetDefaultEntity()).Uid)
|
||||||
return self
|
return self
|
||||||
|
@ -46,7 +45,7 @@ class Layer:
|
||||||
def find_finished_record(self, key: str, value: str) -> [FieldRecord]:
|
def find_finished_record(self, key: str, value: str) -> [FieldRecord]:
|
||||||
return [FieldRecord(t) for t in self._finished_field_recoed_db.FindAll(key, Guid.Parse(value))]
|
return [FieldRecord(t) for t in self._finished_field_recoed_db.FindAll(key, Guid.Parse(value))]
|
||||||
|
|
||||||
# One User only allowed to book one field at a time
|
# One User only allowed to book one field at a Time
|
||||||
def remove_finished_record(self, record: FieldRecord) -> 'Layer':
|
def remove_finished_record(self, record: FieldRecord) -> 'Layer':
|
||||||
self._finished_field_recoed_db.TryDelete("Uid", record.parse_to_csharp_object(self._finished_field_recoed_db.GetDefaultEntity()).Uid)
|
self._finished_field_recoed_db.TryDelete("Uid", record.parse_to_csharp_object(self._finished_field_recoed_db.GetDefaultEntity()).Uid)
|
||||||
return self
|
return self
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"Redis": "127.0.0.1:6379,abortConnect=false",
|
"Redis": "host.docker.internal:6379,abortConnect=false",
|
||||||
"SQL": "Server=127.0.0.1;Port=3306;Database=SiteManagementSystem;Uid=SiteManagementSystem;Pwd=SiteManagementSystem;"
|
"SQL": "Server=host.docker.internal;Port=3306;Database=SiteManagementSystem;Uid=SiteManagementSystem;Pwd=SiteManagementSystem;"
|
||||||
},
|
},
|
||||||
"RedisDB": 0,
|
"RedisDB": 0,
|
||||||
"Jwt": {
|
"Jwt": {
|
||||||
|
|
Loading…
Reference in New Issue