[feature]/python completed

This commit is contained in:
IMAXS 2024-11-05 21:04:21 +08:00
parent 92f58a5b6f
commit 2088dbe020
6 changed files with 61 additions and 43 deletions

View File

@ -43,19 +43,17 @@ namespace SiteManagementSystem_SoftwareEngineering_.Service
} }
public void AddField(string name, string value) public void AddField(string name, string value)
{ {
var t = (Field) var t = (bool)
_service.AddField( _service.RemoveField(
new Field new Field
{ {
Id = Guid.Parse("99b472f1-9912-49df-bb1f-3db0fc5bee11"),
Name = "t1", Name = "t1",
Position = "t2", Position = "t2",
Opentime = "t3" Opentime = "t3"
} }
); );
Console.WriteLine( Console.WriteLine(t);
$"{t.Id},{t.Name},{t.Type}"
);
//t();
//Console.WriteLine(_service.AddField()); //Console.WriteLine(_service.AddField());
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -70,7 +68,7 @@ namespace SiteManagementSystem_SoftwareEngineering_.Service
{ {
public readonly SQLHelperService<Field> FieldDb; public readonly SQLHelperService<Field> FieldDb;
public readonly SQLHelperService<FieldRecord> RecordDb; public readonly SQLHelperService<FieldRecord> RecordDb;
public readonly SQLHelperService<Field> FinishedFieldRecordDb; public readonly SQLHelperService<FieldRecord> FinishedFieldRecordDb;
private readonly ICacheService<FieldService> _cacheService; private readonly ICacheService<FieldService> _cacheService;
public EntityFrameworkPythonCompatibilityAndInterpretationLayer(SQLService storageService, ICacheService<FieldService> cacheService) public EntityFrameworkPythonCompatibilityAndInterpretationLayer(SQLService storageService, ICacheService<FieldService> cacheService)
@ -81,7 +79,7 @@ namespace SiteManagementSystem_SoftwareEngineering_.Service
storageService, storageService,
nameof(storageService.UserFieldRecords) nameof(storageService.UserFieldRecords)
); );
FinishedFieldRecordDb = new SQLHelperService<Field>(storageService,nameof(storageService.FinishedFieldRecords)); FinishedFieldRecordDb = new SQLHelperService<FieldRecord>(storageService,nameof(storageService.FinishedFieldRecords));
} }
public void SetTimeOut(DateTime endTime,string info) public void SetTimeOut(DateTime endTime,string info)
{ {

View File

@ -3,8 +3,7 @@
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 user_field import FieldRecord from field_record import FieldRecord
from datetime import datetime
@ -19,9 +18,9 @@ class Service:
#参数cs_fieldRecord(用户id场地id开始时间结束时间) 返回bool 是否预约成功 #参数cs_fieldRecord(用户id场地id开始时间结束时间) 返回bool 是否预约成功
def AddAppointment(self,cs_fieldRecord) -> bool: def AddAppointment(self,cs_fieldRecord) -> bool:
fieldRecord=FieldRecord(cs_fieldRecord) fieldRecord=FieldRecord(cs_fieldRecord)
records=self.layer.find_record("fid",fieldRecord.fid) records=self.layer.find_record("Fid",fieldRecord.fid)
#如果用户已经有预约了,就不能再提交预约 #如果用户已经有预约了,就不能再提交预约
if len(self.layer.find_record("uid",fieldRecord.uid))!=0: if len(self.layer.find_record("Uid",fieldRecord.uid))!=0:
raise ValueError("Already has an appointment") raise ValueError("Already has an appointment")
else: else:
#检查场地此时是否有空 #检查场地此时是否有空
@ -34,10 +33,10 @@ class Service:
#提前结束场地的使用 正在使用时提前结束 #finished #提前结束场地的使用 正在使用时提前结束 #finished
#参数cs_user //cs_fieldRecord(用户id场地id开始时间) 返回bool 是否结束成功 #参数cs_user //cs_fieldRecord 返回bool 是否结束成功
def EndAppointment(self,cs_user) -> bool: def EndAppointment(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.uid)
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,8 +45,8 @@ class Service:
fid = records[0].fid fid = records[0].fid
uid = user.id uid = user.id
start_time = records[0].start_time start_time = records[0].start_time
#获取当前时间并转为%Y-%m-%d %H:%M:%S形式的字符串 #获取当前时间
curtime=datetime.now().strftime("%Y-%m-%d %H:%M:%S") curtime=time.localtime()
#正在使用时可以提前结束,修改结束时间 #正在使用时可以提前结束,修改结束时间
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)
@ -63,13 +62,13 @@ class Service:
# 参数cs_user //cs_fieldRecord(用户id场地id开始时间结束时间) 返回bool 是否取消成功 # 参数cs_user //cs_fieldRecord(用户id场地id开始时间结束时间) 返回bool 是否取消成功
def CancelAppointment(self,cs_user) -> bool: def CancelAppointment(self,cs_user) -> bool:
user=User(cs_user) user=User(cs_user)
records=self.layer.find_record("uid",user.id) records=self.layer.find_record("Uid",user.id)
if len(records)==0: if len(records)==0:
raise ValueError("No appointment or appointment is finished") raise ValueError("No appointment or appointment is finished")
elif len(records)!=1: elif len(records)!=1:
raise ValueError("Appointment nums error") raise ValueError("Appointment nums error")
else: else:
curtime=datetime.now().strftime("%Y-%m-%d %H:%M:%S") curtime=time.localtime()
if curtime<records[0].start_time: if curtime<records[0].start_time:
fieldRecord=FieldRecord(records[0]) fieldRecord=FieldRecord(records[0])
return True return True
@ -81,13 +80,13 @@ class Service:
# 参数cs_fieldRecord(用户id场地id(null),开始时间(null),结束时间) 返回bool 是否延长成功 # 参数cs_fieldRecord(用户id场地id(null),开始时间(null),结束时间) 返回bool 是否延长成功
def ExtendAppointment(self,cs_fieldRecord) -> bool: def ExtendAppointment(self,cs_fieldRecord) -> bool:
field_Record=FieldRecord(cs_fieldRecord) field_Record=FieldRecord(cs_fieldRecord)
records=self.layer.find_record("uid", field_Record.uid) records=self.layer.find_record("Uid", field_Record.uid)
if len(records)==0: if len(records)==0:
raise ValueError("No appointment or appointment is finished") raise ValueError("No appointment or appointment is finished")
elif len(records)!=1: elif len(records)!=1:
raise ValueError("Appointment nums error") raise ValueError("Appointment nums error")
else: else:
curtime=datetime.now().strftime("%Y-%m-%d %H:%M:%S") curtime=time.localtime()
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:
@ -100,18 +99,15 @@ class Service:
#查询场地占用 #查询场地占用
# 参数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 parse_time(time_str):
return datetime.strptime(time_str, "%Y-%m-%d %H:%M:%S").time()
def QueryFieldUsage(self,cs_fieldRecord) -> []: def QueryFieldUsage(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=[]
for x in records: for x in records:
tup=(x.start_time,x.end_time) tup=(time.strftime("%Y-%m-%d %H:%M:%S",x.start_time),time.strftime("%Y-%m-%d %H:%M:%S",x.end_time))
list_time.append(tup) list_time.append(tup)
# 使用 sorted() 函数进行排序key 参数指定用于排序的键函数 # 使用 sorted() 函数进行排序key 参数指定用于排序的键函数
sorted_time_list = sorted(list_time, key=lambda x: self.parse_time(x[0])) sorted_time_list = sorted(list_time, key=lambda x: x[0])
#从后往前遍历 #从后往前遍历
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]
@ -125,26 +121,47 @@ class Service:
return sorted_time_list return sorted_time_list
#查询用户的预约记录 #查询用户的预约记录
# 参数cs_user(id) 返回array_cs_fieldRecord # 参数cs_user(id) 返回array_cs_fieldRecord
def QueryAppointmentRecord(self,cs_user) -> []: def QueryAppointmentRecord(self,cs_user) -> []:
user=User(cs_user) user=User(cs_user)
cs_fieldRecords=[]
fieldRecords=self.layer.find_record("Uid",user.id)
if len(fieldRecords)==1:
cs_fieldRecords.append(FieldRecord(fieldRecords[0]))
elif len(fieldRecords)!=0:
raise ValueError("Appointment nums error")
fieldRecords=self.layer.find_finished_record("Uid",user.id)
if len(fieldRecords)!=0:
for x in fieldRecords:
cs_fieldRecords.append(FieldRecord.parse_to_csharp_object(FieldRecord(x)))
return cs_fieldRecords
#管理员操作:(包含普通用户操作以及一下特殊操作) #管理员操作:(包含普通用户操作以及一下特殊操作)
#添加一个场地 #添加一个场地
#参数cs_field(id,name,position,open_time,type) 返回bool 是否添加成功 #参数cs_field(id,name,position,open_time,type) 返回bool 是否添加成功
def AddField(self, cs_field) -> str: def AddField(self, cs_field) -> bool:
field = Field(cs_field) field = Field(cs_field)
fields = self.layer.find_field("Name", field.name)
if len(fields) > 0:
raise ValueError("Duplicated name")
self.layer.add_field(field) self.layer.add_field(field)
return "" return True
#删除一个场地 #删除一个场地
# 参数cs_field(id,name,position(null),open_time(null),type(null)) 返回bool 是否删除成功 # 参数cs_field(id,name,position(null),open_time(null),type(null)) 返回bool 是否删除成功
def RemoveField(self,cs_field) -> bool:
field=Field(cs_field)
fields=self.layer.find_field("Id",field.id)
if len(fields) == 0:
raise ValueError("No such field")
if len(fields) != 1:
raise ValueError("Field id duplication")
self.layer.remove_field(field)
return True

View File

@ -24,7 +24,7 @@ class Field:
self.id = field.Id.ToString() self.id = field.Id.ToString()
self.name = field.Name self.name = field.Name
self.position = field.Position self.position = field.Position
self.open_time = field.OpenTime self.open_time = field.Opentime
self.type = field.Type self.type = field.Type
elif len(args) == 5: elif len(args) == 5:
self.id, self.name, self.position, self.open_time, self.type = args self.id, self.name, self.position, self.open_time, self.type = args
@ -35,10 +35,11 @@ class Field:
return f"Field: Id: {self.id}, Name: {self.name}, Position: {self.position}, Type: {self.type}" return f"Field: Id: {self.id}, Name: {self.name}, Position: {self.position}, Type: {self.type}"
def parse_to_csharp_object(self, empty_field): def parse_to_csharp_object(self, empty_field):
print(self.id)
empty_field.Id = Guid.Parse(self.id) empty_field.Id = Guid.Parse(self.id)
empty_field.Name = self.name empty_field.Name = self.name
empty_field.Position = self.position empty_field.Position = self.position
empty_field.OpenTime = self.open_time empty_field.Opentime = self.open_time
print(FieldType.UNSPECIFIED) print(FieldType.UNSPECIFIED)
print(self.type) print(self.type)
empty_field.Type = self.type empty_field.Type = self.type

View File

@ -1,7 +1,7 @@
import clr import clr
from user import User from user import User
from field import Field from field import Field
from user_field import FieldRecord from field_record import FieldRecord
clr.AddReference('System') clr.AddReference('System')
from System import Guid, DateTime from System import Guid, DateTime
@ -19,10 +19,12 @@ class Layer:
# The value property will # The value property will
def find_field(self, key: str, value: str) -> [Field]: def find_field(self, key: str, value: str) -> [Field]:
if key == "Id":
return [Field(t) for t in self._field_db.FindAll(key, Guid.Parse(value))] return [Field(t) for t in self._field_db.FindAll(key, Guid.Parse(value))]
return [Field(t) for t in self._field_db.FindAll(key, value)]
def remove_field(self, field: Field) -> 'Layer': def remove_field(self, field: Field) -> 'Layer':
self._field_db.TryDelete(field.id, field.parse_to_csharp_object(self._field_db.GetDefaultEntity()).Id) self._field_db.TryDelete("Id", field.parse_to_csharp_object(self._field_db.GetDefaultEntity()).Id)
return self return self
def add_record(self, record: FieldRecord) -> 'Layer': def add_record(self, record: FieldRecord) -> 'Layer':
@ -37,15 +39,15 @@ class 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
def add_finished_record(self, record: UserFieldRecord) -> 'Layer': def add_finished_record(self, record: FieldRecord) -> 'Layer':
self._finished_field_recoed_db.Add(record.parse_to_csharp_object(self._finished_field_recoed_db.GetDefaultEntity())) self._finished_field_recoed_db.Add(record.parse_to_csharp_object(self._finished_field_recoed_db.GetDefaultEntity()))
return self return self
def find_finished_record(self, key: str, value: str) -> [UserFieldRecord]: def find_finished_record(self, key: str, value: str) -> [FieldRecord]:
return [UserFieldRecord(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: UserFieldRecord) -> '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

View File

@ -6,8 +6,8 @@
} }
}, },
"ConnectionStrings": { "ConnectionStrings": {
"Redis": "host.docker.internal:6379,abortConnect=false", "Redis": "127.0.0.1:6379,abortConnect=false",
"SQL": "Server=host.docker.internal;Port=3306;Database=SiteManagementSystem;Uid=SiteManagementSystem;Pwd=SiteManagementSystem;" "SQL": "Server=127.0.0.1;Port=3306;Database=SiteManagementSystem;Uid=SiteManagementSystem;Pwd=SiteManagementSystem;"
}, },
"RedisDB": 0, "RedisDB": 0,
"Jwt": { "Jwt": {