讲义结构与内容录入 功能适配 讲义内容上传至mariadb的情形

This commit is contained in:
wangweiye7840 2024-06-17 09:38:16 +08:00
parent da99fcb6e3
commit f9fa43bb77
2 changed files with 25 additions and 18 deletions

View File

@ -298,7 +298,7 @@ def generate_classid(string): #返回班级列表
def generate_id_set(string,*thedict): #除了生成题号列表外, 还能根据首字母生成基础知识编号列表或课时目标列表 def generate_id_set(string,*thedict): #除了生成题号列表外, 还能根据首字母生成基础知识编号列表或课时目标列表
string = RefinePunctuations(string) string = RefinePunctuations(string).upper()
if re.findall(r"[BXK]",string) == []: if re.findall(r"[BXK]",string) == []:
if thedict == (): if thedict == ():
return generate_number_set(string) return generate_number_set(string)
@ -3362,15 +3362,16 @@ def generateUsagedetail(zipfilepath,tempdir,answersheetseekingpath,statsfilename
def load_notes_dict_from_mariadb(cursor): #从mariadb获取讲义列表 def load_notes_dict_from_mariadb(cursor): #从mariadb获取讲义列表
sql = "SELECT nid,name,filename,structure FROM notes WHERE NOT obsolete;" sql = "SELECT nid,name,filename,structure,remarks FROM notes WHERE NOT obsolete;"
cursor.execute(sql) cursor.execute(sql)
ret = cursor.fetchall() ret = cursor.fetchall()
notes_dict = {} notes_dict = {}
for nid,name,filename,structure in ret: for nid,name,filename,structure,remarks in ret:
temp_dict = json.loads(structure) temp_dict = json.loads(structure)
notes_dict[nid] = {'id':nid,'name':name,'filename':filename} notes_dict[nid] = {'id':nid,'name':name,'filename':filename}
for key in temp_dict: for key in temp_dict:
notes_dict[nid][key] = temp_dict[key] notes_dict[nid][key] = temp_dict[key]
# notes_dict[nid]["remarks"] = "" if remarks is None else remarks
return notes_dict return notes_dict
def load_structures_dict_from_mariadb(cursor): # 从mariadb获取讲义结构列表 def load_structures_dict_from_mariadb(cursor): # 从mariadb获取讲义结构列表

View File

@ -68,21 +68,18 @@ class MyWindow_jglr(QWidget,Ui_Form):
val = (GetDate(),GetTime(),get_git_username(),"添加新讲义结构",self.prefix[0:5]) val = (GetDate(),GetTime(),get_git_username(),"添加新讲义结构",self.prefix[0:5])
mycursor.execute(sql,val) mycursor.execute(sql,val)
mydb.commit() mydb.commit()
####20240616到这里
# notes_dict["structures"][self.prefix[0]] = new_struct_dict.copy()
# save_dict(notes_dict,jsonfile)
else: else:
pass pass
else: else:
numberlist = [] numberlist = []
for id in notes_dict["notes"]: for existing_nid in notes_dict:
if self.prefix in id: if self.prefix in existing_nid:
numberlist.append(id[-2:]) numberlist.append(existing_nid[-2:])
print("该分类下已有材料编号: "+generate_exp(numberlist)) print("该分类下已有材料编号: "+generate_exp(numberlist))
pid = self.prefix + input("请输入新材料编号(两位数):") nid = self.prefix + input("请输入新材料编号(两位数):")
while pid in notes_dict["notes"]: while nid in notes_dict:
print("编号重复, 请重新输入.") print("编号重复, 请重新输入.")
pid = self.prefix + input("请输入新材料编号(两位数):") nid = self.prefix + input("请输入新材料编号(两位数):")
name = input("请输入材料名称:") name = input("请输入材料名称:")
filenameraw = input("生成的文件名和材料名称是否一致?([Y]/如果不一致请输入文件名):") filenameraw = input("生成的文件名和材料名称是否一致?([Y]/如果不一致请输入文件名):")
if filenameraw.upper() == "Y" or len(filenameraw.strip()) == 0: if filenameraw.upper() == "Y" or len(filenameraw.strip()) == 0:
@ -90,26 +87,35 @@ class MyWindow_jglr(QWidget,Ui_Form):
else: else:
filename = filenameraw filename = filenameraw
new_note_dict = { new_note_dict = {
"id": pid, "nid": nid,
"name": name, "name": name,
"filename": filename "filename": filename
} }
structure = notes_dict['structures'][self.prefix[0]]['structure'] new_note_dict_structure = {}
structure = structure_dict[self.prefix[0:5]]['structure']
print(f"此类材料共有 {len(structure)} 个部分, 分别是:") print(f"此类材料共有 {len(structure)} 个部分, 分别是:")
for p in structure: for p in structure:
print(f"{p}: {structure[p]['name']}") print(f"{p}: {structure[p]['name']}")
new_note_dict[p] = [] new_note_dict_structure[p] = []
for p in structure: for p in structure:
rawdata = input(f"现在输入 {p}: {structure[p]['name']} 部分的内容编号:") rawdata = input(f"现在输入 {p}: {structure[p]['name']} 部分的内容编号:")
rawdata = RefinePunctuations(rawdata)
rawdata = re.sub(r"[^BXK\d:,]","",rawdata) rawdata = re.sub(r"[^BXK\d:,]","",rawdata)
if re.findall(r"\d",rawdata) == []: if re.findall(r"\d",rawdata) == []:
new_note_dict[p] = [] new_note_dict[p] = []
else: else:
new_note_dict[p] = generate_id_set(rawdata) new_note_dict[p] = generate_id_set(rawdata)
print(f"{p}: {new_note_dict[p]}") print(f"{p}: {new_note_dict[p]}")
notes_dict["notes"][pid] = new_note_dict.copy() temp_dict = new_note_dict.copy()
notes_dict["notes"] = SortDict(notes_dict["notes"]) for key in ["nid","name","filename"]:
save_dict(notes_dict,jsonfile) temp_dict.pop(key)
sql = "INSERT INTO notes (nid,name,filename,structure) VALUES (%s,%s,%s,%s);"
val = (nid,name,filename,json.dumps(temp_dict,ensure_ascii = False))
mycursor.execute(sql,val)
sql = "INSERT INTO logs (DATE,TIME,username,action,db_content) VALUE (%s,%s,%s,%s,%s);"
val = (GetDate(),GetTime(),get_git_username(),"添加新讲义内容",self.prefix)
mycursor.execute(sql,val)
mydb.commit()
print("处理完成") print("处理完成")
mydb.close() mydb.close()