From 9956fcf4690b2e20f5ccd134579b7001910d0259 Mon Sep 17 00:00:00 2001 From: BINGWU Date: Wed, 10 Apr 2024 15:03:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=BD=E7=A6=BB=E5=85=AC=E5=85=B1=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__pycache__/commonViews.cpython-311.pyc | Bin 0 -> 5513 bytes serve/serve/commonViews/commonViews.py | 93 ++++++++++++++++++ serve/serve/models/request.py | 10 ++ .../__pycache__/decodeBody.cpython-311.pyc | Bin 0 -> 559 bytes .../utils/__pycache__/pyjwt.cpython-311.pyc | Bin 1693 -> 1693 bytes serve/serve/utils/decodeBody.py | 8 ++ serve/serve/utils/pyjwt.py | 2 +- .../views/__pycache__/index.cpython-311.pyc | Bin 451 -> 559 bytes .../views/__pycache__/request.cpython-311.pyc | Bin 0 -> 1501 bytes .../views/__pycache__/user.cpython-311.pyc | Bin 8482 -> 4303 bytes serve/serve/views/index.py | 2 + serve/serve/views/request.py | 29 ++++++ serve/serve/views/user.py | 87 ++-------------- 13 files changed, 149 insertions(+), 82 deletions(-) create mode 100644 serve/serve/commonViews/__pycache__/commonViews.cpython-311.pyc create mode 100644 serve/serve/commonViews/commonViews.py create mode 100644 serve/serve/utils/__pycache__/decodeBody.cpython-311.pyc create mode 100644 serve/serve/utils/decodeBody.py create mode 100644 serve/serve/views/__pycache__/request.cpython-311.pyc diff --git a/serve/serve/commonViews/__pycache__/commonViews.cpython-311.pyc b/serve/serve/commonViews/__pycache__/commonViews.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a57b072dc0d3fdb8668eb1c74aa2b1fe9be8d1b4 GIT binary patch literal 5513 zcmcgwU2GKB6~42xf8HPeEo*GA{{oBME%5@SfD6V1uov3|8)3u4%IRv^8O)fO-R+%O zz}A}P0acrX2NPArq?Xu7gcy+~eyCJeO(PzvDvvwvNM4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G#5oFEe-upoyB-s#$oRFi3G$j5q(>&b0nZv=Q=jEK z^qG<-#ySHBJ87H&K-nBy^*Efi7Uog@uEgJT5pQ);#)>&vG_1E&Vm;hqR9bT|%6k)@ ztGHX>wlgud1$x#hZ7s=efa2w?FQa&QtAVlp4-~hLsPu_}aSg(8EqoG_dj{77QLS;n zy)kZvRjUX$6lK_}*aIy(@Fwf0fpO%LVG#=?O#fO;F;ER=@i z;7rh>gnb4~W~0(fERqLz4MQ+dG}8tePVU zEXJ_v1R&OYx)1^34Y4)1B=``hXopAi!9`KR)`aZbr#SZ&vGw1m;dQZfYxDepg+q6a zd~{^-;F2VJdKFKvy!EiM^>Au%t6?f;Vd*_OK=i;#JKA^Y{thx`cxDPL1l-(y3_lZ>C zk+w4r8(@cI_n_h)Oa<1>sM)*Pw0EUx@6s{3>44I7AlulMZERV$7+b5?5s=iW7dEt| zBkh!3e#Pa_IQ*}O(}76Qt%L<6-iZd(zk!8(4WK5@Wx4A*_k+T;5ggBrT-OmjtX2S& zDQUnB@t(MmH_ zn?VIYgbjSl)1zY>;}-Ex*aWf9Cx80OZ$r6~`NC zuk7ej99;{3xb!^9ME+ zIP|3>3;qZABV}cM1XmH?QN++T^f4HVE@G?b$5BjG(!y0n%@y9m6tM*@y%a50N#sJ$ zr)1Sj23y|xvcZw`lXWGGS^rBvwQ}Kd%VvV)M_2Bk)Rlib zJ`I1pupPdUi?AEY8%uw@a@Ph4YBldmLwarRaRaF%A)t0HzP0wkF--7mA0CG~63C1H z0kTe06qQA-8GU|)ycvDYqLz$4XVK1#K4;Okj6P@4TN!=MqMv8FWLrI{+k|M#^Iz-Fz1si) literal 0 HcmV?d00001 diff --git a/serve/serve/commonViews/commonViews.py b/serve/serve/commonViews/commonViews.py new file mode 100644 index 0000000..bae5367 --- /dev/null +++ b/serve/serve/commonViews/commonViews.py @@ -0,0 +1,93 @@ +from datetime import datetime + +from django.http import JsonResponse +from django.urls import path +from serve.utils.connectdb import connectdb +from bson.objectid import ObjectId +from serve.middleware.handleErrorMethod import handleErrorMethod +from serve.middleware.handleEmpty import handleEmpty +from serve.utils.pyjwt import get_jwt_token, decode_jwt_token +from serve.utils.decodeBody import decodeBody + + +def delete(request, collection): + result = handleErrorMethod(request.method, 'DELETE') + if result[0]: + ret = decode_jwt_token(request.META.get('HTTP_AUTHORIZATION')) + if ret['code'] == 2000: + data = decodeBody(request) + _ids = list(data['_ids']) + filter_criteria = {'_id': {'$in': [ObjectId(_id) for _id in _ids]}} + deleteResult = collection.delete_many(filter_criteria) + res = handleEmpty(deleteResult.deleted_count, '删除') + return JsonResponse(res) + else: + return JsonResponse(ret) + + else: + return JsonResponse(result[1]) + + +def getAll(request, collection): + result = handleErrorMethod(request.method, 'GET') + if result[0]: + ret = decode_jwt_token(request.META.get('HTTP_AUTHORIZATION')) + if ret['code'] == 2000: + pageSize = int(request.GET.get('pageSize', None)) + pageIndex = int(request.GET.get('pageIndex', None)) + # 计算要跳过的文档数量 + skip_count = (pageIndex - 1) * pageSize + # 执行分页查询 + cursor = collection.find().skip(skip_count).limit(pageSize) + # 将查询结果转换为列表 + result = [{**doc, '_id': str(doc['_id'])} for doc in cursor] + # 构建JSON格式的响应 + response_data = { + 'total': collection.count_documents({}), # 获取总文档数 + 'data': result, + 'code': 2000 + } + return JsonResponse(response_data) + else: + return JsonResponse(ret) + + else: + return JsonResponse(result[1]) + + +def create(request, collection, useDate=False): + result = handleErrorMethod(request.method, 'POST') + if result[0]: + ret = decode_jwt_token(request.META.get('HTTP_AUTHORIZATION')) + if ret['code'] == 2000: + data = decodeBody(request) + if useDate: + data['date'] = datetime.now() + collection.insert_one(data) + return JsonResponse({"code": 2000, "msg": "添加成功"}) + else: + return JsonResponse(ret) + + else: + return JsonResponse(result[1]) + + +def update(request, collection, useDate=False): + result = handleErrorMethod(request.method, 'PUT') + if result[0]: + ret = decode_jwt_token(request.META.get('HTTP_AUTHORIZATION')) + if ret['code'] == 2000: + data = decodeBody(request) + if useDate: + data['date'] = datetime.now() + _id = data['_id'] + update_data = data['data'] + print(_id) + updateResult = collection.update_one({'_id': ObjectId(_id)}, {"$set": update_data}) + res = handleEmpty(updateResult.modified_count, '更新') + return JsonResponse(res) + else: + return JsonResponse(ret) + + else: + return JsonResponse(result[1]) diff --git a/serve/serve/models/request.py b/serve/serve/models/request.py index e69de29..77a6161 100644 --- a/serve/serve/models/request.py +++ b/serve/serve/models/request.py @@ -0,0 +1,10 @@ +from datetime import datetime + +from mongoengine import Document, EmbeddedDocument, fields, DateTimeField + + +class RequestModel(Document): + content = fields.StringField(max_length=30) + employeeName = fields.StringField(max_length=30) + status = fields.StringField(max_length=30) + date = DateTimeField(default=datetime.now) diff --git a/serve/serve/utils/__pycache__/decodeBody.cpython-311.pyc b/serve/serve/utils/__pycache__/decodeBody.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..01ac8f8e70f42e09178052e080aa0014f0928c77 GIT binary patch literal 559 zcmZWlze~eF6uwJZEyfZDakX@jQtPUSIEaWK6vRyelJ>6JlH_XcDn=?~a1kBcx+;i2 z5b7!j{tt>^2{@@(w?c7o@?EUI-;wWoKR#YQ-f=wMgCORI2MU+K53=|SrIWP#A*msP z2)587BFYw8!~`#(l=>ni**xwjC8?dSor9!?s;DHpVeJ3ZeKuk15%kZ#W}8?Qi7W2R_Pqj`Sye6rK5Up4Co#?#^P`7YgFFd|RD z(*Qnd=mWdeJ3V=$C-+CM_4KWt_Gj-keRq6sj!ViPta6^l-~I+XI62j`!oA7 F0|0_s4_*KO diff --git a/serve/serve/utils/decodeBody.py b/serve/serve/utils/decodeBody.py new file mode 100644 index 0000000..015c56e --- /dev/null +++ b/serve/serve/utils/decodeBody.py @@ -0,0 +1,8 @@ +import json + + +# 解码字节字符串并解析为 JSON 数据 +def decodeBody(request): + body_str = request.body.decode('utf-8') + data = json.loads(body_str) + return data diff --git a/serve/serve/utils/pyjwt.py b/serve/serve/utils/pyjwt.py index 00c96a7..dee28f6 100644 --- a/serve/serve/utils/pyjwt.py +++ b/serve/serve/utils/pyjwt.py @@ -9,7 +9,7 @@ def get_jwt_token(username, password, role_data='default'): 生成jwt-token """ payload = { - 'exp': datetime.utcnow() + timedelta(seconds=300), # 单位秒 + 'exp': datetime.utcnow() + timedelta(seconds=999999999), # 单位秒 'iat': datetime.utcnow(), 'data': {'username': username, 'password': password, 'role_data': role_data} } diff --git a/serve/serve/views/__pycache__/index.cpython-311.pyc b/serve/serve/views/__pycache__/index.cpython-311.pyc index 094097adbd896a94fda46388abc87a2344cb6096..a49c1d591c8454dadaf8abd5d1fb9f0053d3e52c 100644 GIT binary patch delta 296 zcmX@iyq<-3IWI340}x2O6;0bXkyp}91<0Askiw9{n8T3E7{$m4Vl(A1?OG#PJkloqEJ#g`W40NLC{sfDGf#U&F1r5N=l=18j4FqANX)ImTM zF9Sm@&_JMeMn6raB4(g)5zEBB`QfZURy(Iv&uPjxsEHkydSPx`5*qmF!$ih%}Oio}_}PLsPCr3`K`XkS1@ RAJ~`}n@N#2hJQDX{Vyh7ynj6jbptFw_E#0BT_LD`K8_WWF&AP^wq}NHj3q zVBw!?agjy3!5aiWgY@`mGT#ya8d#R9SC*MtUaSW)eey0wMJFDhEF%yX8vuz9%#4hT XHyBheprQ|KjEpiL7%+(on;)BPtk|GMp{It_B%UoQ2t~ZugB8IgP-1qPMrL>8?52_;n1ctU zm)_copdhWKP_I1||AYi`2n&K>i}e-=UOf5UZjv^()q_rUzMc2xW%hgDd$XykF#==n zdU9bmK*(1#`Xk(1bU(pjjp#(DoETK26xRVBFoIgpTL-yhgtU+$YqAm6!bU`kP!b?4 zs7o7^kZqX$(4uKw zQ?|@4>V|vYv+=ZvA63Aa>HM8CXZgdAd*42+9PaEL?!3z%yx-j4eZ9ZClCRX9Mavx8 zWJZNsHO8`KbHNfu0ng4F1+!3M1~Z+kU9%l#CGF|YKA$=rpc=}{u@h5$T3kT}ZSrA8te~CDP z3gGJ@60metzgB%}W8lNM?sUwXdsJcf1+L za`QCAItx@(U@orGV>=I@-tsf@+T&;B2He#uXSc)z#Nj=%4*)trN@<&1ZVW$dao=QHx+SIC fQUvYs^?OZeswGYJ?BDkXb|)H21nLU@yu$thmqcOP literal 0 HcmV?d00001 diff --git a/serve/serve/views/__pycache__/user.cpython-311.pyc b/serve/serve/views/__pycache__/user.cpython-311.pyc index 3693cfe649e0a59f9e3883ec06159b395486c2af..57f9655fb05609a4eeef10fc1719c2168a279ac8 100644 GIT binary patch delta 1922 zcmb_cTWB0r7(TOe*~{#1vYTWtxo%?IbkxQmidw6XLa+#J)kL9#5Vm_xH(TejJu_YD@LpAh4rH?}K$yZb8Ll_WzQOSc)$b;Ay{r@v%yO9+UI?R0YpYQy0 z&NtsV|M}v?kF)tNbGZzG>(=w7^Fx`B@|9psBIGKegi02%B~y|xPFM+BHf0gZmSU@> zDq_Xb?4+3#v1+C4w3!yMW@T*M)a|U9744*zv-4(N#3^gY9yW*Vf?2SOX3-uoMWs2GJqaq)d6gYjSpbUY~nE6N}7|jvPz8VKB_XLDEo@%I^9_u3OM(N*I2tR!TM_&r+)IjnG%>`14L1kb@&QKsoy7HDX@&W;o%IlI_p zo*&wYcY{nk(;FV+yac(Je^3OtOn%Y}+Y6r_yRFyn==EKtegG_K_RUWeAY^zB{;xJ( zfUiKE9>AO9bbJKB!@+BO3=j=MON6j-An*%bMyLQhEEzArSfC@1;|`V)uYiy-30bJ^ zzKrl&y?XQJ(4SKHgF2%|@_L(w-xsREPJ-7UE0S%mwU2*f=sbypW;1`or96!d<{*`w6?wnNulhj9&aWY6au4K`FhiiF0Q*R}je=J44ZGD;U#&Ql?*;RW7- zQBe|x6_S^rqZ*pU--Czg8Vm}iW#RQNrp4P>D0m98V0)wvxi(k5C~1-M>Y3HG@Z<4X zFbhdt9PhVl-|b&}|JN(qzkKkSAqyXQ9r#G~-M5*;AAy+9BRq<*0AM7AyZi_ec=E-X z9>*w!APm%mf&3^CkpeZ1m%GQF&}>px;(5QoHX9`DIW?`%y=C56-+o6 zHYUp9*HdR;>c6JW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