From f6a75c77e3d65b6f59298c4cf4a0f46fdb85fad2 Mon Sep 17 00:00:00 2001 From: FPC5719 Date: Sat, 26 Feb 2022 21:00:54 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BA=86volcert=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- student.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/student.py b/student.py index 3e6599b..49ddfab 100644 --- a/student.py +++ b/student.py @@ -9,7 +9,7 @@ Student = Blueprint('student', __name__) @Student.route('/student/volbook/', methods = ['GET']) @Deco def getVolunteerWork(stuId): - fl,r=OP.select("volId,volTimeInside,volTimeOutside,volTimeLarge,status","stu_vol","stuId=%s", stuId, + fl,r=OP.select("volId,volTimeInside,volTimeOutside,volTimeLarge,status","stu_vol","stuId=%s",stuId, ["volId","inside","outside","large","status"],only=False) if not fl: return r for i in r: @@ -17,3 +17,21 @@ def getVolunteerWork(stuId): if not ff: return rr i.update({"name": rr["name"]}) return {"type":"SUCCESS","message":"获取成功","rec":r} + +@Student.route('/student/volcert/', methods = ['POST']) +@Deco +def getVolunteerCertification(): + stuId,volId=json_data()["stuId"],json_data()["volId"] + f1,r1=OP.select( + "stuId,volTimeInside,volTimeOutside,volTimeLarge,status,thought", + "stu_vol","stuId=%s AND volId=%s",(stuId,volId), + ["id","inside","outside","large","status","thought"],only=True + ) + if not f1: return r1 + f2,r2=OP.select( + "volId,volName,description,volTime,volDate,volTimeInside,volTimeOutside,volTimeLarge", + "volunteer","volId=%s",volId, + ["id","name","description","time","date","inside","outside","large"],only=True + ) + if not f2: return r2 + return {"type":"SUCCESS","message":"获取成功","stu":r1,"vol":r2} \ No newline at end of file -- Gitee From e0f5819692e06aaaa6daf69cd8fe19f19883e3b1 Mon Sep 17 00:00:00 2001 From: fpc5719 Date: Wed, 2 Mar 2022 17:07:26 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=BA=86=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=8F=90=E7=A4=BA=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oppressor.py | 7 ++++-- student.py | 21 ++++++++++-------- volunteer.py | 62 ++++++++++++++++++++++++++++++++-------------------- 3 files changed, 55 insertions(+), 35 deletions(-) diff --git a/oppressor.py b/oppressor.py index 51cbd7f..0304800 100644 --- a/oppressor.py +++ b/oppressor.py @@ -41,6 +41,9 @@ def classIdToString(a): return ret +OP_NOT_FOUND = "数据库信息错误:未查询到相关信息" +OP_NOT_ONLY = "数据库信息错误:要求一个但查询到多个" + # 下面三个是对MySQL操作的封装 # 对SQL的操作尽量使用这三个而不是直接DB.execute() # 标出来的是调试输出 @@ -59,7 +62,7 @@ def select(col,src,exp,val,ret,only=True): # 估计能用了 ret=list(col.split(",")) for i in len(ret): ret[i]=ret[i].strip() if len(r)==0: - return False, {"type":"ERROR","message":"数据库信息错误:未查询到相关信息"} + return False, {"type":"ERROR","message":OP_NOT_FOUND} if len(r)==1: result={} # 格式化返回值 for j in range(0,len(ret)): @@ -68,7 +71,7 @@ def select(col,src,exp,val,ret,only=True): # 估计能用了 else: return True, [result] # 就算只有一个,没有Only还是要返回数组 else: if only: # 理论上不应该有这种情况,真出现了估计是Insert的锅 - return False, {"type":"ERROR","message":"数据库信息错误:要求一个但查询到多个"} + return False, {"type":"ERROR","message":OP_NOT_ONLY} result=[] for i in range(0,len(r)): result.append({}) # 格式化返回值 diff --git a/student.py b/student.py index 49ddfab..0da7472 100644 --- a/student.py +++ b/student.py @@ -9,14 +9,17 @@ Student = Blueprint('student', __name__) @Student.route('/student/volbook/', methods = ['GET']) @Deco def getVolunteerWork(stuId): - fl,r=OP.select("volId,volTimeInside,volTimeOutside,volTimeLarge,status","stu_vol","stuId=%s",stuId, - ["volId","inside","outside","large","status"],only=False) - if not fl: return r - for i in r: - ff,rr=OP.select("volName","volunteer","volId=%s",i["volId"], ["name"]) - if not ff: return rr - i.update({"name": rr["name"]}) - return {"type":"SUCCESS","message":"获取成功","rec":r} + fl,r=OP.select("volId,volTimeInside,volTimeOutside,volTimeLarge,status","stu_vol","stuId=%s", stuId, + ["volId","inside","outside","large","status"],only=False) + if not fl: + if "message" in r and r["message"]==OP.OP_NOT_FOUND: + return {"type":"ERROR","messsage":"该学生没有义工记录"} + return r + for i in r: + ff,rr=OP.select("volName","volunteer","volId=%s",i["volId"], ["name"]) + if not ff: return rr + i.update({"name": rr["name"]}) + return {"type":"SUCCESS","message":"获取成功","rec":r} @Student.route('/student/volcert/', methods = ['POST']) @Deco @@ -34,4 +37,4 @@ def getVolunteerCertification(): ["id","name","description","time","date","inside","outside","large"],only=True ) if not f2: return r2 - return {"type":"SUCCESS","message":"获取成功","stu":r1,"vol":r2} \ No newline at end of file + return {"type":"SUCCESS","message":"获取成功","stu":r1,"vol":r2} diff --git a/volunteer.py b/volunteer.py index 3f8633b..5578988 100644 --- a/volunteer.py +++ b/volunteer.py @@ -1,5 +1,6 @@ from flask import Blueprint, request import json +import time from deco import * from res import * import oppressor as OP @@ -10,16 +11,20 @@ Volunteer = Blueprint('volunteer', __name__) @Deco def getVolunteerList(): # 可以了 fl,r=OP.select("volId,volName,description,volDate,volTime,status,stuMax","volunteer","true",(), - ["id", "name", "description","date","time","status","stuMax"],only=False) - if not fl: return r # 数据库错误 - return {"type":"SUCCESS","message":"获取成功","volunteer":r} + ["id", "name", "description","date","time","status","stuMax"],only=False) + if not fl: + if "message" in r and r["message"]==OP.OP_NOT_FOUND: + return {"type":"ERROR","message":"当前无义工"} + return r + r=sorted(r,key=lambda x: x["date"]) + return {"type":"SUCCESS","message":"获取成功","volunteer":r[::-1]} @Volunteer.route('/volunteer/fetch/', methods = ['GET', 'OPTIONS']) @Deco def getVolunteer(volId): # 可以了 fl,r=OP.select("volName,volDate,volTime,stuMax,nowStuCount,description,status,volTimeInside,volTimeOutside,volTimeLarge", "volunteer","volId=%s",(volId), - ["name", "date", "time", "stuMax","stuNow","description","status","inside", "outside", "large"]) + ["name", "date", "time", "stuMax","stuNow","description","status","inside", "outside", "large"]) if not fl: return r # 数据库错误 r.update({"type":"SUCCESS","message":"获取成功"}) return r @@ -57,10 +62,14 @@ def signupVolunteer(volId): # 过了 if not checkPermission(tkData()["class"],tkData()["permission"],i): return {"type":"ERROR", "message":"权限不足:学生列表中有别班学生"} # 判断人数是否超过这个义工的人数上限 - fl,r=OP.select("stuMax,nowStuCount","volunteer","volId=%s",(volId),["stuMax","nowStuCount"]) + fl,r=OP.select("stuMax,nowStuCount,volDate,volTime","volunteer","volId=%s",(volId),["stuMax","nowStuCount","volDate","volTime"]) if not fl: return r # 数据库错误 if len(json_data()['stulst'])>r["stuMax"]-r["nowStuCount"]: return {"type":"ERROR", "message":"人数超限"} + nowTime=time.time() + endTime=time.mktime(time.strptime(r["volDate"] + ' ' + r["volTime"], "%Y-%m-%d %H:%M")) + if nowTime > endTime: + return {"type":"ERROR", "message":"义工时间已过"} # 判断是否有人已经报名了 for i in json_data()["stulst"]: fl,r=OP.select("status","stu_vol","volId=%s AND stuId=%s",(volId,i),["status"]) @@ -105,6 +114,8 @@ def createVolunteer(): # 大概可以了 print("count check failed.") return {"type":"ERROR", "message":"最大人数不符合要求:义工人数永远无法报满"} print(666) + if json_data()["inside"]<0 or json_data()["outside"]<0 or json_data()["large"]<0: + return {"type":"ERROR", "message":"义工时间不能为负数"} # 创建一条总的记录 OP.insert("volName,volDate,volTime,stuMax,nowStuCount,description,status," +"volTimeInside,volTimeOutside,volTimeLarge,holderId", @@ -127,10 +138,13 @@ def createVolunteer(): # 大概可以了 def getSignerList(volId): # 过了 # 判断权限 # if not tkData().get("permission") in [PMS_TEACHER,PMS_MANAGER,PMS_SYSTEM]: - # return {'type':'ERROR', 'message':"权限不足"} + # return {'type':'ERROR', 'message':"权限不足"} ret={"type":"SUCCESS", "message":"获取成功","result":[]} fl,r=OP.select("stuId","stu_vol","volId=%s",(volId),["stuId"],only=False) - if not fl: return r # 数据库错误:没有这个义工 + if not fl: + if "message" in r and r["message"]==OP.OP_NOT_FOUND: + return {"type":"SUCCESS","message":"当前义工无人报名"} + return r for i in r: # 返回学生姓名 ff,rr=OP.select("stuId,stuName","student","stuId=%s",(i["stuId"]),["stuId","stuName"]) if not ff: return rr # 数据库错误:没有这个人 @@ -164,7 +178,7 @@ def getJoinerList(volId): # 这个到底要不要? def getUnaudited(): fl,r=OP.select("volId,stuId,thought","stu_vol","((status=%s)and length(thought)>0)",(STATUS_WAITING),["volId","stuId","thought"],only=False) if not fl: - if r["message"]=="数据库信息错误:未查询到相关信息": + if "message" in r and r["message"]==OP.OP_NOT_FOUND: r={"type":"SUCCESS","message":"全部审核完毕"} return r return {"type":"SUCCESS","message":"获取成功","result":r} @@ -187,7 +201,7 @@ def auditThought(volId): # 大概是过了 for i in json_data()["thought"]: stuId=i["stuId"] if i["status"]!=STATUS_ACCEPT: - OP.update("thought=%s","stu_vol","volId=%s AND stuId=%s",("",volId,stuId)) + OP.update("thought=%s","stu_vol","volId=%s AND stuId=%s",("",volId,stuId)) # 修改状态。状态由JSON传入 OP.update("status=%s","stu_vol","volId=%s AND stuId=%s",(i["status"],volId,stuId)) # 把stu_vol的表里的数据填上 @@ -265,20 +279,20 @@ def modifyVolunteer(volId): return {"type":"SUCCESS", "message":"创建成功"} return {"type":"SUCCESS", "message":"修改成功"} { - "name": "义工活动1", - "date": "2020.10.1", - "time": "13:00", - "stuMax": 20, - "description": "...", - "inside": 0, - "outside": 3, - "large": 0, - "class": [ - {"id": 202001, "stuMax": 10, "visible": true}, - {"id": 202002, "stuMax": 5, "visible": true}, - {"id": 202003, "stuMax": 10, "visible": true} - {"id": 202004, "stuMax": 0, "visible": false}, - ] + "name": "义工活动1", + "date": "2020.10.1", + "time": "13:00", + "stuMax": 20, + "description": "...", + "inside": 0, + "outside": 3, + "large": 0, + "class": [ + {"id": 202001, "stuMax": 10, "visible": true}, + {"id": 202002, "stuMax": 5, "visible": true}, + {"id": 202003, "stuMax": 10, "visible": true} + {"id": 202004, "stuMax": 0, "visible": false}, + ] } ''' @@ -310,7 +324,7 @@ def randthought(): # 随机一条感想 cnt = 0 while True: cnt += 1 - if cnt > 10: break # 说明系统刚上线 + if cnt > 10: break # 说明系统刚上线 r = OP.getRandThought() if r == None: break if r[2] == 1: -- Gitee From 90bedf19331e83917debe0fd81c0533c7c35c2e4 Mon Sep 17 00:00:00 2001 From: FPC5719 Date: Tue, 5 Apr 2022 15:57:17 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=B8=8E=E6=9C=80=E6=96=B0=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E7=89=88=E6=9C=AC=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- res.py | 2 +- user.py | 70 ++++++++++++++++++++++++++++----------------------------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/res.py b/res.py index 4f1799f..29aca44 100644 --- a/res.py +++ b/res.py @@ -20,5 +20,5 @@ def checkPermission(cls,pms,stu): # 判断一个用户是否有权限管理该 # 班级编号为6位:202001,学号为8位:20200100~20200199 return pms in [PMS_CLASS,PMS_TEACHER,PMS_SYSTEM] or(pms==PMS_CLASS and stu>=cls*100 and stu', methods=['POST']) @Deco def getInfo(userId): - fl,r=OP.select("userName,class,permission","user","userId=%s",userId,["userName","class","permission"]) - if not fl: return r - r.update({"type":"SUCCESS", "message":"获取成功"}) - return r + fl,r=OP.select("userName,class,permission","user","userId=%s",userId,["userName","class","permission"]) + if not fl: return r + r.update({"type":"SUCCESS", "message":"获取成功"}) + return r @User.route('/user/modPwd', methods = ['POST']) @Deco def modifyPassword(): - old=json_data().get("oldPwd") - new=json_data().get("newPwd") - fl, r = OP.select("userid","user", "userId = %s and password = %s", (tkData().get("userid"), old), ["user"]) - if not fl: return {"type": "ERROR", "message": "密码错误"} - print(type(tkData().get("userid"))) - OP.update("password=%s","user","userId=%s",(new, tkData().get("userid"),)) - return {"type":"SUCCESS", "message":"修改成功"} + old=json_data().get("oldPwd") + new=json_data().get("newPwd") + fl, r = OP.select("userid","user", "userId = %s and password = %s", (tkData().get("userid"), old), ["user"]) + if not fl: return {"type": "ERROR", "message": "密码错误"} + print(type(tkData().get("userid"))) + OP.update("password=%s","user","userId=%s",(new, tkData().get("userid"),)) + return {"type":"SUCCESS", "message":"修改成功"} -- Gitee