diff --git a/doc/Wusthelper-内部rpc接口.postman_collection.json b/doc/Wusthelper-内部rpc接口.postman_collection.json new file mode 100644 index 0000000..935e219 --- /dev/null +++ b/doc/Wusthelper-内部rpc接口.postman_collection.json @@ -0,0 +1,2867 @@ +{ + "info": { + "_postman_id": "c62d9103-34a1-4db6-bae8-ccbf5c91bf35", + "name": "Wusthelper-内部rpc接口", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "19106199" + }, + "item": [ + { + "name": "本科生", + "item": [ + { + "name": "课表", + "item": [ + { + "name": "课表", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"undergrad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"undergrad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_undergrad}}/course_table?cookie={{undergrad_cookie_encoded}}&term=2023-2024-1", + "host": [ + "{{address_undergrad}}" + ], + "path": [ + "course_table" + ], + "query": [ + { + "key": "cookie", + "value": "{{undergrad_cookie_encoded}}" + }, + { + "key": "term", + "value": "2023-2024-1" + } + ] + } + }, + "response": [] + }, + { + "name": "课表 - 仅解析", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "postData = pm.request.body.raw\r", + "if(postData == '' || postData == undefined || postData == null) {\r", + " pm.request.body.raw = pm.collectionVariables.get(\"undergrad_course_table_html\");\r", + " pm.request.body.mode = 'raw';\r", + " console.log(\"body: \" + pm.request.body);\r", + "}\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{address_undergrad}}/course_table/parse", + "host": [ + "{{address_undergrad}}" + ], + "path": [ + "course_table", + "parse" + ] + } + }, + "response": [] + }, + { + "name": "课表 - 仅获取", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"undergrad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"undergrad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"登录接口请求完成\", function() {\r", + " json = pm.response.json()\r", + " if(json.code == 20000) {\r", + " data = json.data;\r", + " console.log(\"html长度:\" + data.length);\r", + " pm.collectionVariables.set(\"undergrad_course_table_html\", data);\r", + " }\r", + "})" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_undergrad}}/course_table/agent?cookie={{undergrad_cookie_encoded}}&term", + "host": [ + "{{address_undergrad}}" + ], + "path": [ + "course_table", + "agent" + ], + "query": [ + { + "key": "cookie", + "value": "{{undergrad_cookie_encoded}}" + }, + { + "key": "term", + "value": null + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "学生信息", + "item": [ + { + "name": "学生信息", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"undergrad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"undergrad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_undergrad}}/student_info?cookie={{undergrad_cookie_encoded}}", + "host": [ + "{{address_undergrad}}" + ], + "path": [ + "student_info" + ], + "query": [ + { + "key": "cookie", + "value": "{{undergrad_cookie_encoded}}" + } + ] + } + }, + "response": [] + }, + { + "name": "学生信息 - 仅解析", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "postData = pm.request.body.raw\r", + "if(postData == '' || postData == undefined || postData == null) {\r", + " pm.request.body.raw = pm.collectionVariables.get(\"undergrad_student_info_html\");\r", + " pm.request.body.mode = 'raw';\r", + " console.log(\"body长度: \" + pm.request.body.raw.length);\r", + "}\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{address_undergrad}}/student_info/parse", + "host": [ + "{{address_undergrad}}" + ], + "path": [ + "student_info", + "parse" + ] + } + }, + "response": [] + }, + { + "name": "学生信息 - 仅获取", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"undergrad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"undergrad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"登录接口请求完成\", function() {\r", + " json = pm.response.json()\r", + " if(json.code == 20000) {\r", + " data = json.data;\r", + " console.log(\"html长度:\" + data.length);\r", + " pm.collectionVariables.set(\"undergrad_student_info_html\", data);\r", + " }\r", + "})" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_undergrad}}/student_info/agent?cookie={{undergrad_cookie_encoded}}", + "host": [ + "{{address_undergrad}}" + ], + "path": [ + "student_info", + "agent" + ], + "query": [ + { + "key": "cookie", + "value": "{{undergrad_cookie_encoded}}" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "成绩", + "item": [ + { + "name": "成绩", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"undergrad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"undergrad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_undergrad}}/score?cookie={{undergrad_cookie_encoded}}", + "host": [ + "{{address_undergrad}}" + ], + "path": [ + "score" + ], + "query": [ + { + "key": "cookie", + "value": "{{undergrad_cookie_encoded}}" + } + ] + } + }, + "response": [] + }, + { + "name": "成绩 - 仅解析", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "postData = pm.request.body.raw\r", + "if(postData == '' || postData == undefined || postData == null) {\r", + " pm.request.body.raw = pm.collectionVariables.get(\"undergrad_score_html\");\r", + " pm.request.body.mode = 'raw';\r", + " console.log(\"body长度: \" + pm.request.body.raw.length);\r", + "}\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{address_undergrad}}/score/parse", + "host": [ + "{{address_undergrad}}" + ], + "path": [ + "score", + "parse" + ] + } + }, + "response": [] + }, + { + "name": "成绩 - 仅获取", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"undergrad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"undergrad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"登录接口请求完成\", function() {\r", + " json = pm.response.json()\r", + " if(json.code == 20000) {\r", + " data = json.data;\r", + " console.log(\"html长度:\" + data.length);\r", + " pm.collectionVariables.set(\"undergrad_score_html\", data);\r", + " }\r", + "})" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_undergrad}}/score/agent?cookie={{undergrad_cookie_encoded}}", + "host": [ + "{{address_undergrad}}" + ], + "path": [ + "score", + "agent" + ], + "query": [ + { + "key": "cookie", + "value": "{{undergrad_cookie_encoded}}" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "培养方案", + "item": [ + { + "name": "培养方案", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"undergrad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"undergrad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_undergrad}}/training_plan?cookie={{undergrad_cookie_encoded}}", + "host": [ + "{{address_undergrad}}" + ], + "path": [ + "training_plan" + ], + "query": [ + { + "key": "cookie", + "value": "{{undergrad_cookie_encoded}}" + } + ] + } + }, + "response": [] + }, + { + "name": "培养方案 - 仅解析", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "postData = pm.request.body.raw\r", + "if(postData == '' || postData == undefined || postData == null) {\r", + " pm.request.body.raw = pm.collectionVariables.get(\"undergrad_training_plan_html\");\r", + " pm.request.body.mode = 'raw';\r", + " console.log(\"body长度: \" + pm.request.body.raw.length);\r", + "}\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{address_undergrad}}/training_plan/parse", + "host": [ + "{{address_undergrad}}" + ], + "path": [ + "training_plan", + "parse" + ] + } + }, + "response": [] + }, + { + "name": "培养方案 - 仅获取", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"undergrad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"undergrad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"登录接口请求完成\", function() {\r", + " json = pm.response.json()\r", + " if(json.code == 20000) {\r", + " data = json.data;\r", + " console.log(\"html长度:\" + data.length);\r", + " pm.collectionVariables.set(\"undergrad_training_plan_html\", data);\r", + " }\r", + "})" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_undergrad}}/training_plan/agent?cookie={{undergrad_cookie_encoded}}", + "host": [ + "{{address_undergrad}}" + ], + "path": [ + "training_plan", + "agent" + ], + "query": [ + { + "key": "cookie", + "value": "{{undergrad_cookie_encoded}}" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "学分修读情况", + "item": [ + { + "name": "学分修读情况", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"undergrad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"undergrad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_undergrad}}/credit_status?cookie={{undergrad_cookie_encoded}}", + "host": [ + "{{address_undergrad}}" + ], + "path": [ + "credit_status" + ], + "query": [ + { + "key": "cookie", + "value": "{{undergrad_cookie_encoded}}" + } + ] + } + }, + "response": [] + }, + { + "name": "学分修读情况 - 仅解析", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "postData = pm.request.body.raw\r", + "if(postData == '' || postData == undefined || postData == null) {\r", + " pm.request.body.raw = pm.collectionVariables.get(\"undergrad_credit_status_html\");\r", + " pm.request.body.mode = 'raw';\r", + " console.log(\"body长度: \" + pm.request.body.raw.length);\r", + "}\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{address_undergrad}}/credit_status/parse", + "host": [ + "{{address_undergrad}}" + ], + "path": [ + "credit_status", + "parse" + ] + } + }, + "response": [] + }, + { + "name": "学分修读情况 - 仅获取", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"undergrad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"undergrad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"登录接口请求完成\", function() {\r", + " json = pm.response.json()\r", + " if(json.code == 20000) {\r", + " data = json.data;\r", + " console.log(\"html长度:\" + data.length);\r", + " pm.collectionVariables.set(\"undergrad_credit_status_html\", data);\r", + " }\r", + "})" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_undergrad}}/credit_status/agent?cookie={{undergrad_cookie_encoded}}", + "host": [ + "{{address_undergrad}}" + ], + "path": [ + "credit_status", + "agent" + ], + "query": [ + { + "key": "cookie", + "value": "{{undergrad_cookie_encoded}}" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "考试活动id", + "item": [ + { + "name": "考试活动id", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"undergrad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"undergrad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_undergrad}}/exam_activities?cookie={{undergrad_cookie_encoded}}&term=2022-2023-2", + "host": [ + "{{address_undergrad}}" + ], + "path": [ + "exam_activities" + ], + "query": [ + { + "key": "cookie", + "value": "{{undergrad_cookie_encoded}}" + }, + { + "key": "term", + "value": "2022-2023-2" + } + ] + } + }, + "response": [] + }, + { + "name": "考试活动id - 仅获取", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"undergrad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"undergrad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_undergrad}}/exam_activities/agent?cookie={{undergrad_cookie_encoded}}&term=2022-2023-1", + "host": [ + "{{address_undergrad}}" + ], + "path": [ + "exam_activities", + "agent" + ], + "query": [ + { + "key": "cookie", + "value": "{{undergrad_cookie_encoded}}" + }, + { + "key": "term", + "value": "2022-2023-1" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "缓考申请", + "item": [ + { + "name": "缓考申请", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"undergrad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"undergrad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_undergrad}}/exam_delay_application?cookie={{undergrad_cookie_encoded}}&term=2022-2023-1&activity_id=9FF84C58B1CA4BDBB656E4C224B617A9", + "host": [ + "{{address_undergrad}}" + ], + "path": [ + "exam_delay_application" + ], + "query": [ + { + "key": "cookie", + "value": "{{undergrad_cookie_encoded}}" + }, + { + "key": "term", + "value": "2022-2023-1" + }, + { + "key": "activity_id", + "value": "9FF84C58B1CA4BDBB656E4C224B617A9" + } + ] + } + }, + "response": [] + }, + { + "name": "缓考申请 - 仅解析", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "postData = pm.request.body.raw\r", + "if(postData == '' || postData == undefined || postData == null) {\r", + " pm.request.body.raw = pm.collectionVariables.get(\"undergrad_exam_delay_application_html\");\r", + " pm.request.body.mode = 'raw';\r", + " console.log(\"body长度: \" + pm.request.body.raw.length);\r", + "}\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{address_undergrad}}/exam_delay_application/parse", + "host": [ + "{{address_undergrad}}" + ], + "path": [ + "exam_delay_application", + "parse" + ] + } + }, + "response": [] + }, + { + "name": "缓考申请 - 仅获取", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"undergrad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"undergrad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"登录接口请求完成\", function() {\r", + " json = pm.response.json()\r", + " if(json.code == 20000) {\r", + " data = json.data;\r", + " console.log(\"html长度:\" + data.length);\r", + " pm.collectionVariables.set(\"undergrad_exam_delay_application_html\", data);\r", + " }\r", + "})" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_undergrad}}/exam_delay_application/agent?cookie={{undergrad_cookie_encoded}}&term=2022-2023-1&activity_id=9FF84C58B1CA4BDBB656E4C224B617A9", + "host": [ + "{{address_undergrad}}" + ], + "path": [ + "exam_delay_application", + "agent" + ], + "query": [ + { + "key": "cookie", + "value": "{{undergrad_cookie_encoded}}" + }, + { + "key": "term", + "value": "2022-2023-1" + }, + { + "key": "activity_id", + "value": "9FF84C58B1CA4BDBB656E4C224B617A9" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "登录", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"登录接口请求完成\", function() {\r", + " json = pm.response.json()\r", + " if(json.code == 20000) {\r", + " cookie = json.data;\r", + " console.log(\"获取到Cookie: \" + cookie);\r", + " pm.collectionVariables.set(\"undergrad_cookie\", cookie);\r", + " }\r", + "})" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_undergrad}}/cookie?username={{undergrad_username}}&password={{undergrad_password}}", + "host": [ + "{{address_undergrad}}" + ], + "path": [ + "cookie" + ], + "query": [ + { + "key": "username", + "value": "{{undergrad_username}}" + }, + { + "key": "password", + "value": "{{undergrad_password}}" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "研究生", + "item": [ + { + "name": "课表", + "item": [ + { + "name": "课表", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"grad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"grad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_grad}}/course_table?cookie={{grad_cookie}}", + "host": [ + "{{address_grad}}" + ], + "path": [ + "course_table" + ], + "query": [ + { + "key": "cookie", + "value": "{{grad_cookie}}" + } + ] + } + }, + "response": [] + }, + { + "name": "课表 - 仅解析", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "postData = pm.request.body.raw\r", + "if(postData == '' || postData == undefined || postData == null) {\r", + " pm.request.body.raw = pm.collectionVariables.get(\"grad_course_table_html\");\r", + " pm.request.body.mode = 'raw';\r", + " console.log(\"body: \" + pm.request.body);\r", + "}\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{address_grad}}/course_table/parse", + "host": [ + "{{address_grad}}" + ], + "path": [ + "course_table", + "parse" + ] + } + }, + "response": [] + }, + { + "name": "课表 - 仅获取", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"grad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"grad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"登录接口请求完成\", function() {\r", + " json = pm.response.json()\r", + " if(json.code == 20000) {\r", + " data = json.data;\r", + " console.log(\"html长度:\" + data.length);\r", + " pm.collectionVariables.set(\"grad_course_table_html\", data);\r", + " }\r", + "})" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_grad}}/course_table/agent?cookie={{grad_cookie}}&term", + "host": [ + "{{address_grad}}" + ], + "path": [ + "course_table", + "agent" + ], + "query": [ + { + "key": "cookie", + "value": "{{grad_cookie}}" + }, + { + "key": "term", + "value": null + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "学生信息", + "item": [ + { + "name": "学生信息", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"grad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"grad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_grad}}/student_info?cookie={{grad_cookie_encoded}}", + "host": [ + "{{address_grad}}" + ], + "path": [ + "student_info" + ], + "query": [ + { + "key": "cookie", + "value": "{{grad_cookie_encoded}}" + } + ] + } + }, + "response": [] + }, + { + "name": "学生信息 - 仅解析", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "postData = pm.request.body.raw\r", + "if(postData == '' || postData == undefined || postData == null) {\r", + " pm.request.body.raw = pm.collectionVariables.get(\"grad_student_info_html\");\r", + " pm.request.body.mode = 'raw';\r", + " console.log(\"body长度: \" + pm.request.body.raw.length);\r", + "}\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{address_grad}}/student_info/parse", + "host": [ + "{{address_grad}}" + ], + "path": [ + "student_info", + "parse" + ] + } + }, + "response": [] + }, + { + "name": "学生信息 - 仅获取", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"grad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"grad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"登录接口请求完成\", function() {\r", + " json = pm.response.json()\r", + " if(json.code == 20000) {\r", + " data = json.data;\r", + " console.log(\"html长度:\" + data.length);\r", + " pm.collectionVariables.set(\"grad_student_info_html\", data);\r", + " }\r", + "})" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_grad}}/student_info/agent?cookie={{grad_cookie_encoded}}", + "host": [ + "{{address_grad}}" + ], + "path": [ + "student_info", + "agent" + ], + "query": [ + { + "key": "cookie", + "value": "{{grad_cookie_encoded}}" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "成绩", + "item": [ + { + "name": "成绩", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"grad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"grad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_grad}}/score?cookie={{grad_cookie_encoded}}", + "host": [ + "{{address_grad}}" + ], + "path": [ + "score" + ], + "query": [ + { + "key": "cookie", + "value": "{{grad_cookie_encoded}}" + } + ] + } + }, + "response": [] + }, + { + "name": "成绩 - 仅解析", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "postData = pm.request.body.raw\r", + "if(postData == '' || postData == undefined || postData == null) {\r", + " pm.request.body.raw = pm.collectionVariables.get(\"grad_score_html\");\r", + " pm.request.body.mode = 'raw';\r", + " console.log(\"body长度: \" + pm.request.body.raw.length);\r", + "}\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{address_grad}}/score/parse", + "host": [ + "{{address_grad}}" + ], + "path": [ + "score", + "parse" + ] + } + }, + "response": [] + }, + { + "name": "成绩 - 仅获取", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"grad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"grad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"接口请求完成\", function() {\r", + " json = pm.response.json()\r", + " if(json.code == 20000) {\r", + " data = json.data;\r", + " console.log(\"html长度:\" + data.length);\r", + " pm.collectionVariables.set(\"grad_score_html\", data);\r", + " }\r", + "})" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_grad}}/score/agent?cookie={{grad_cookie_encoded}}", + "host": [ + "{{address_grad}}" + ], + "path": [ + "score", + "agent" + ], + "query": [ + { + "key": "cookie", + "value": "{{grad_cookie_encoded}}" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "培养方案", + "item": [ + { + "name": "培养方案", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"grad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"grad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_grad}}/training_plan?cookie={{grad_cookie_encoded}}", + "host": [ + "{{address_grad}}" + ], + "path": [ + "training_plan" + ], + "query": [ + { + "key": "cookie", + "value": "{{grad_cookie_encoded}}" + } + ] + } + }, + "response": [] + }, + { + "name": "培养方案 - 仅解析", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "postData = pm.request.body.raw\r", + "if(postData == '' || postData == undefined || postData == null) {\r", + " pm.request.body.raw = pm.collectionVariables.get(\"grad_training_plan_html\");\r", + " pm.request.body.mode = 'raw';\r", + " console.log(\"body长度: \" + pm.request.body.raw.length);\r", + "}\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{address_grad}}/training_plan/parse", + "host": [ + "{{address_grad}}" + ], + "path": [ + "training_plan", + "parse" + ] + } + }, + "response": [] + }, + { + "name": "培养方案 - 仅获取", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"grad_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"grad_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"接口请求完成\", function() {\r", + " json = pm.response.json()\r", + " if(json.code == 20000) {\r", + " data = json.data;\r", + " console.log(\"html长度:\" + data.length);\r", + " pm.collectionVariables.set(\"grad_training_plan_html\", data);\r", + " }\r", + "})" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_grad}}/training_plan/agent?cookie={{grad_cookie_encoded}}", + "host": [ + "{{address_grad}}" + ], + "path": [ + "training_plan", + "agent" + ], + "query": [ + { + "key": "cookie", + "value": "{{grad_cookie_encoded}}" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "登录", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"登录接口请求完成\", function() {\r", + " json = pm.response.json()\r", + " if(json.code == 20000) {\r", + " cookie = json.data;\r", + " console.log(\"获取到Cookie: \" + cookie);\r", + " pm.collectionVariables.set(\"grad_cookie\", cookie);\r", + " }\r", + "})" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_grad}}/cookie?username={{grad_username}}&password={{grad_password}}", + "host": [ + "{{address_grad}}" + ], + "path": [ + "cookie" + ], + "query": [ + { + "key": "username", + "value": "{{grad_username}}" + }, + { + "key": "password", + "value": "{{grad_password}}" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "图书馆", + "item": [ + { + "name": "图书封面获取", + "item": [ + { + "name": "二合一", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"lib_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"lib_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_lib}}/course_table?cookie={{lib_cookie_encoded}}&term=2023-2024-1", + "host": [ + "{{address_lib}}" + ], + "path": [ + "course_table" + ], + "query": [ + { + "key": "cookie", + "value": "{{lib_cookie_encoded}}" + }, + { + "key": "term", + "value": "2023-2024-1" + } + ] + } + }, + "response": [] + }, + { + "name": "仅解析", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "postData = pm.request.body.raw\r", + "if(postData == '' || postData == undefined || postData == null) {\r", + " pm.request.body.raw = pm.collectionVariables.get(\"lib_course_table_html\");\r", + " pm.request.body.mode = 'raw';\r", + " console.log(\"body: \" + pm.request.body);\r", + "}\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{address_lib}}/course_table/parse", + "host": [ + "{{address_lib}}" + ], + "path": [ + "course_table", + "parse" + ] + } + }, + "response": [] + }, + { + "name": "课表 - 仅获取", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"lib_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"lib_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"登录接口请求完成\", function() {\r", + " json = pm.response.json()\r", + " if(json.code == 20000) {\r", + " data = json.data;\r", + " console.log(\"html长度:\" + data.length);\r", + " pm.collectionVariables.set(\"lib_course_table_html\", data);\r", + " }\r", + "})" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_lib}}/course_table/agent?cookie={{lib_cookie_encoded}}&term", + "host": [ + "{{address_lib}}" + ], + "path": [ + "course_table", + "agent" + ], + "query": [ + { + "key": "cookie", + "value": "{{lib_cookie_encoded}}" + }, + { + "key": "term", + "value": null + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "图书详情", + "item": [ + { + "name": "学生信息", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"lib_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"lib_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_lib}}/student_info?cookie={{lib_cookie_encoded}}", + "host": [ + "{{address_lib}}" + ], + "path": [ + "student_info" + ], + "query": [ + { + "key": "cookie", + "value": "{{lib_cookie_encoded}}" + } + ] + } + }, + "response": [] + }, + { + "name": "学生信息 - 仅解析", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "postData = pm.request.body.raw\r", + "if(postData == '' || postData == undefined || postData == null) {\r", + " pm.request.body.raw = pm.collectionVariables.get(\"lib_student_info_html\");\r", + " pm.request.body.mode = 'raw';\r", + " console.log(\"body长度: \" + pm.request.body.raw.length);\r", + "}\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{address_lib}}/student_info/parse", + "host": [ + "{{address_lib}}" + ], + "path": [ + "student_info", + "parse" + ] + } + }, + "response": [] + }, + { + "name": "学生信息 - 仅获取", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"lib_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"lib_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"登录接口请求完成\", function() {\r", + " json = pm.response.json()\r", + " if(json.code == 20000) {\r", + " data = json.data;\r", + " console.log(\"html长度:\" + data.length);\r", + " pm.collectionVariables.set(\"lib_student_info_html\", data);\r", + " }\r", + "})" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_lib}}/student_info/agent?cookie={{lib_cookie_encoded}}", + "host": [ + "{{address_lib}}" + ], + "path": [ + "student_info", + "agent" + ], + "query": [ + { + "key": "cookie", + "value": "{{lib_cookie_encoded}}" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "当前借阅", + "item": [ + { + "name": "成绩", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"lib_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"lib_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_lib}}/score?cookie={{lib_cookie_encoded}}", + "host": [ + "{{address_lib}}" + ], + "path": [ + "score" + ], + "query": [ + { + "key": "cookie", + "value": "{{lib_cookie_encoded}}" + } + ] + } + }, + "response": [] + }, + { + "name": "成绩 - 仅解析", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "postData = pm.request.body.raw\r", + "if(postData == '' || postData == undefined || postData == null) {\r", + " pm.request.body.raw = pm.collectionVariables.get(\"lib_score_html\");\r", + " pm.request.body.mode = 'raw';\r", + " console.log(\"body长度: \" + pm.request.body.raw.length);\r", + "}\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{address_lib}}/score/parse", + "host": [ + "{{address_lib}}" + ], + "path": [ + "score", + "parse" + ] + } + }, + "response": [] + }, + { + "name": "成绩 - 仅获取", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"lib_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"lib_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"登录接口请求完成\", function() {\r", + " json = pm.response.json()\r", + " if(json.code == 20000) {\r", + " data = json.data;\r", + " console.log(\"html长度:\" + data.length);\r", + " pm.collectionVariables.set(\"lib_score_html\", data);\r", + " }\r", + "})" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_lib}}/score/agent?cookie={{lib_cookie_encoded}}", + "host": [ + "{{address_lib}}" + ], + "path": [ + "score", + "agent" + ], + "query": [ + { + "key": "cookie", + "value": "{{lib_cookie_encoded}}" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "借阅历史", + "item": [ + { + "name": "培养方案", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"lib_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"lib_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_lib}}/training_plan?cookie={{lib_cookie_encoded}}", + "host": [ + "{{address_lib}}" + ], + "path": [ + "training_plan" + ], + "query": [ + { + "key": "cookie", + "value": "{{lib_cookie_encoded}}" + } + ] + } + }, + "response": [] + }, + { + "name": "培养方案 - 仅解析", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "postData = pm.request.body.raw\r", + "if(postData == '' || postData == undefined || postData == null) {\r", + " pm.request.body.raw = pm.collectionVariables.get(\"lib_training_plan_html\");\r", + " pm.request.body.mode = 'raw';\r", + " console.log(\"body长度: \" + pm.request.body.raw.length);\r", + "}\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{address_lib}}/training_plan/parse", + "host": [ + "{{address_lib}}" + ], + "path": [ + "training_plan", + "parse" + ] + } + }, + "response": [] + }, + { + "name": "培养方案 - 仅获取", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"lib_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"lib_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"登录接口请求完成\", function() {\r", + " json = pm.response.json()\r", + " if(json.code == 20000) {\r", + " data = json.data;\r", + " console.log(\"html长度:\" + data.length);\r", + " pm.collectionVariables.set(\"lib_training_plan_html\", data);\r", + " }\r", + "})" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_lib}}/training_plan/agent?cookie={{lib_cookie_encoded}}", + "host": [ + "{{address_lib}}" + ], + "path": [ + "training_plan", + "agent" + ], + "query": [ + { + "key": "cookie", + "value": "{{lib_cookie_encoded}}" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "即将过期", + "item": [ + { + "name": "学分修读情况", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"lib_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"lib_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_lib}}/credit_status?cookie={{lib_cookie_encoded}}", + "host": [ + "{{address_lib}}" + ], + "path": [ + "credit_status" + ], + "query": [ + { + "key": "cookie", + "value": "{{lib_cookie_encoded}}" + } + ] + } + }, + "response": [] + }, + { + "name": "学分修读情况 - 仅解析", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "postData = pm.request.body.raw\r", + "if(postData == '' || postData == undefined || postData == null) {\r", + " pm.request.body.raw = pm.collectionVariables.get(\"lib_credit_status_html\");\r", + " pm.request.body.mode = 'raw';\r", + " console.log(\"body长度: \" + pm.request.body.raw.length);\r", + "}\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{address_lib}}/credit_status/parse", + "host": [ + "{{address_lib}}" + ], + "path": [ + "credit_status", + "parse" + ] + } + }, + "response": [] + }, + { + "name": "学分修读情况 - 仅获取", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"lib_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"lib_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"登录接口请求完成\", function() {\r", + " json = pm.response.json()\r", + " if(json.code == 20000) {\r", + " data = json.data;\r", + " console.log(\"html长度:\" + data.length);\r", + " pm.collectionVariables.set(\"lib_credit_status_html\", data);\r", + " }\r", + "})" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_lib}}/credit_status/agent?cookie={{lib_cookie_encoded}}", + "host": [ + "{{address_lib}}" + ], + "path": [ + "credit_status", + "agent" + ], + "query": [ + { + "key": "cookie", + "value": "{{lib_cookie_encoded}}" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "搜索", + "item": [ + { + "name": "考试活动id", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"lib_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"lib_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_lib}}/exam_activities?cookie={{lib_cookie_encoded}}&term=2022-2023-2", + "host": [ + "{{address_lib}}" + ], + "path": [ + "exam_activities" + ], + "query": [ + { + "key": "cookie", + "value": "{{lib_cookie_encoded}}" + }, + { + "key": "term", + "value": "2022-2023-2" + } + ] + } + }, + "response": [] + }, + { + "name": "考试活动id - 仅获取", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"lib_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"lib_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_lib}}/exam_activities/agent?cookie={{lib_cookie_encoded}}&term=2022-2023-1", + "host": [ + "{{address_lib}}" + ], + "path": [ + "exam_activities", + "agent" + ], + "query": [ + { + "key": "cookie", + "value": "{{lib_cookie_encoded}}" + }, + { + "key": "term", + "value": "2022-2023-1" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "登录", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"登录接口请求完成\", function() {\r", + " json = pm.response.json()\r", + " if(json.code == 20000) {\r", + " cookie = json.data;\r", + " console.log(\"获取到Cookie: \" + cookie);\r", + " pm.collectionVariables.set(\"lib_cookie\", cookie);\r", + " }\r", + "})" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_lib}}/cookie?username={{lib_username}}&password={{lib_password}}", + "host": [ + "{{address_lib}}" + ], + "path": [ + "cookie" + ], + "query": [ + { + "key": "username", + "value": "{{lib_username}}" + }, + { + "key": "password", + "value": "{{lib_password}}" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "物理实验", + "item": [ + { + "name": "课表", + "item": [ + { + "name": "课表", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"physics_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"physics_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_physics}}/course_table?cookie={{physics_cookie_encoded}}", + "host": [ + "{{address_physics}}" + ], + "path": [ + "course_table" + ], + "query": [ + { + "key": "cookie", + "value": "{{physics_cookie_encoded}}" + } + ] + } + }, + "response": [] + }, + { + "name": "课表 - 仅解析", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "postData = pm.request.body.raw\r", + "if(postData == '' || postData == undefined || postData == null) {\r", + " pm.request.body.raw = pm.collectionVariables.get(\"physics_course_table_html\");\r", + " pm.request.body.mode = 'raw';\r", + " console.log(\"body: \" + pm.request.body);\r", + "}\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{addredd_physics}}/course_table/parse", + "host": [ + "{{addredd_physics}}" + ], + "path": [ + "course_table", + "parse" + ] + } + }, + "response": [] + }, + { + "name": "课表 - 仅获取", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"physics_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"physics_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"登录接口请求完成\", function() {\r", + " json = pm.response.json()\r", + " if(json.code == 20000) {\r", + " data = json.data;\r", + " console.log(\"html长度:\" + data.length);\r", + " pm.collectionVariables.set(\"physics_course_table_html\", data);\r", + " }\r", + "})" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_physics}}/course_table/agent?cookie={{physics_cookie_encoded}}&term", + "host": [ + "{{address_physics}}" + ], + "path": [ + "course_table", + "agent" + ], + "query": [ + { + "key": "cookie", + "value": "{{physics_cookie_encoded}}" + }, + { + "key": "term", + "value": null + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "成绩", + "item": [ + { + "name": "成绩", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"physics_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"physics_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_physics}}/score?cookie={{physics_cookie_encoded}}", + "host": [ + "{{address_physics}}" + ], + "path": [ + "score" + ], + "query": [ + { + "key": "cookie", + "value": "{{physics_cookie_encoded}}" + } + ] + } + }, + "response": [] + }, + { + "name": "成绩 - 仅解析", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "postData = pm.request.body.raw\r", + "if(postData == '' || postData == undefined || postData == null) {\r", + " pm.request.body.raw = pm.collectionVariables.get(\"physics_score_html\");\r", + " pm.request.body.mode = 'raw';\r", + " console.log(\"body长度: \" + pm.request.body.raw.length);\r", + "}\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{address_physics}}/score/parse", + "host": [ + "{{address_physics}}" + ], + "path": [ + "score", + "parse" + ] + } + }, + "response": [] + }, + { + "name": "成绩 - 仅获取", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.environment.set(\r", + " \"physics_cookie_encoded\",\r", + " encodeURIComponent(pm.collectionVariables.get(\"physics_cookie\"))\r", + ")" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"登录接口请求完成\", function() {\r", + " json = pm.response.json()\r", + " if(json.code == 20000) {\r", + " data = json.data;\r", + " console.log(\"html长度:\" + data.length);\r", + " pm.collectionVariables.set(\"physics_score_html\", data);\r", + " }\r", + "})" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_physics}}/score/agent?cookie={{physics_cookie_encoded}}", + "host": [ + "{{address_physics}}" + ], + "path": [ + "score", + "agent" + ], + "query": [ + { + "key": "cookie", + "value": "{{physics_cookie_encoded}}" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "登录", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"登录接口请求完成\", function() {\r", + " json = pm.response.json()\r", + " if(json.code == 20000) {\r", + " cookie = json.data;\r", + " console.log(\"获取到Cookie: \" + cookie);\r", + " pm.collectionVariables.set(\"physics_cookie\", cookie);\r", + " }\r", + "})" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{address_physics}}/cookie?username={{physics_username}}&password={{physics_password}}", + "host": [ + "{{address_physics}}" + ], + "path": [ + "cookie" + ], + "query": [ + { + "key": "username", + "value": "{{physics_username}}" + }, + { + "key": "password", + "value": "{{physics_password}}" + } + ] + } + }, + "response": [] + } + ] + } + ], + "event": [ + { + "listen": "prerequest", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + }, + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ], + "variable": [ + { + "key": "address_undergrad", + "value": "http://127.0.0.1:22800", + "type": "string" + }, + { + "key": "address_grad", + "value": "http://127.0.0.1:22802", + "type": "string" + }, + { + "key": "address_lib", + "value": "http://127.0.0.1:22804", + "type": "string" + }, + { + "key": "address_physics", + "value": "http://127.0.0.1:22806", + "type": "string" + }, + { + "key": "undergrad_username", + "value": "" + }, + { + "key": "undergrad_password", + "value": "" + }, + { + "key": "grad_username", + "value": "", + "type": "string" + }, + { + "key": "grad_password", + "value": "", + "type": "string" + }, + { + "key": "lib_username", + "value": "", + "type": "string" + }, + { + "key": "lib_password", + "value": "", + "type": "string" + }, + { + "key": "physics_username", + "value": "", + "type": "string" + }, + { + "key": "physics_password", + "value": "", + "type": "string" + }, + { + "key": "undergrad_cookie", + "value": "" + }, + { + "key": "undergrad_course_table_html", + "value": "" + }, + { + "key": "undergrad_student_info_html", + "value": "" + }, + { + "key": "undergrad_score_html", + "value": "" + }, + { + "key": "undergrad_exam_delay_application_html", + "value": "" + }, + { + "key": "undergrad_credit_status_html", + "value": "" + }, + { + "key": "undergrad_training_plan_html", + "value": "" + }, + { + "key": "grad_cookie", + "value": "" + }, + { + "key": "grad_student_info_html", + "value": "" + }, + { + "key": "grad_course_table_html", + "value": "" + }, + { + "key": "grad_training_plan_html", + "value": "" + }, + { + "key": "lib_cookie", + "value": "" + } + ] +} \ No newline at end of file diff --git a/external-library/mywust b/external-library/mywust index e186a0d..5fd5099 160000 --- a/external-library/mywust +++ b/external-library/mywust @@ -1 +1 @@ -Subproject commit e186a0d9f014c27aecbfd0775302dcb99ce89619 +Subproject commit 5fd50991814322760c7f4fb8b17a51ae8270e973 diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookCoverImageApi.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookCoverImageApi.java index bbf178e..94c57f6 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookCoverImageApi.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookCoverImageApi.java @@ -1,8 +1,7 @@ package cn.wustlinghang.wusthelper.internal.library.api.http; import cn.wustlinghang.mywust.data.global.Score; -import cn.wustlinghang.wusthelper.internal.library.services.ParseService; -import cn.wustlinghang.wusthelper.internal.library.services.RequestAgentService; +import cn.wustlinghang.wusthelper.internal.library.services.BookCoverImageUrlService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.constraints.NotNull; @@ -16,13 +15,10 @@ import java.util.List; @Path("/cover_image") @ApplicationScoped public class BookCoverImageApi { - private final RequestAgentService agentService; - private final ParseService parseService; + private final BookCoverImageUrlService service; - public BookCoverImageApi(RequestAgentService agentService, - ParseService parseService) { - this.agentService = agentService; - this.parseService = parseService; + public BookCoverImageApi(BookCoverImageUrlService service) { + this.service = service; } @GET @@ -36,7 +32,7 @@ public class BookCoverImageApi { @Path("/agent") public String agent(@QueryParam("isbn") @NotNull String isbn) throws RpcException { - return agentService.getBookCoverImageUrl(isbn); + return service.getBookCoverImageUrl(isbn); } @POST diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookDetailApi.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookDetailApi.java index 0db43db..70de036 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookDetailApi.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookDetailApi.java @@ -1,8 +1,7 @@ package cn.wustlinghang.wusthelper.internal.library.api.http; import cn.wustlinghang.mywust.data.global.Score; -import cn.wustlinghang.wusthelper.internal.library.services.ParseService; -import cn.wustlinghang.wusthelper.internal.library.services.RequestAgentService; +import cn.wustlinghang.wusthelper.internal.library.services.BookDetailService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.constraints.NotNull; @@ -16,27 +15,24 @@ import java.util.List; @Path("/book_detail") @ApplicationScoped public class BookDetailApi { - private final RequestAgentService agentService; - private final ParseService parseService; + private final BookDetailService service; - public BookDetailApi(RequestAgentService agentService, - ParseService parseService) { - this.agentService = agentService; - this.parseService = parseService; + public BookDetailApi(BookDetailService service) { + this.service = service; } @GET @Path("/") - public List get(@QueryParam("isbn") @NotNull String isbn) + public List get(@QueryParam("id") @NotNull String id) throws RpcException { - return this.parse(this.agent(isbn)); + return this.parse(this.agent(id)); } @GET @Path("/agent") - public String agent(@QueryParam("isbn") @NotNull String isbn) + public String agent(@QueryParam("id") @NotNull String id) throws RpcException { - return agentService.getBookCoverImageUrl(isbn); + return service.getBookDetail(id); } @POST diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/CurrentLoanApi.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/CurrentLoanApi.java index de2fe3c..552e8dc 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/CurrentLoanApi.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/CurrentLoanApi.java @@ -1,8 +1,7 @@ package cn.wustlinghang.wusthelper.internal.library.api.http; import cn.wustlinghang.mywust.data.global.Score; -import cn.wustlinghang.wusthelper.internal.library.services.ParseService; -import cn.wustlinghang.wusthelper.internal.library.services.RequestAgentService; +import cn.wustlinghang.wusthelper.internal.library.services.CurrentLoanService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.constraints.NotNull; @@ -16,27 +15,24 @@ import java.util.List; @Path("/current_loan") @ApplicationScoped public class CurrentLoanApi { - private final RequestAgentService agentService; - private final ParseService parseService; + private final CurrentLoanService service; - public CurrentLoanApi(RequestAgentService agentService, - ParseService parseService) { - this.agentService = agentService; - this.parseService = parseService; + public CurrentLoanApi(CurrentLoanService service) { + this.service = service; } @GET @Path("/") - public List get(@QueryParam("isbn") @NotNull String isbn) + public List get(@QueryParam("cookie") @NotNull String cookie) throws RpcException { - return this.parse(this.agent(isbn)); + return this.parse(this.agent(cookie)); } @GET @Path("/agent") - public String agent(@QueryParam("isbn") @NotNull String isbn) + public String agent(@QueryParam("cookie") @NotNull String cookie) throws RpcException { - return agentService.getBookCoverImageUrl(isbn); + return service.getCurrentLoan(cookie); } @POST diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/LoanHistoryApi.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/LoanHistoryApi.java index 3af4d41..3ec5953 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/LoanHistoryApi.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/LoanHistoryApi.java @@ -1,8 +1,7 @@ package cn.wustlinghang.wusthelper.internal.library.api.http; import cn.wustlinghang.mywust.data.global.Score; -import cn.wustlinghang.wusthelper.internal.library.services.ParseService; -import cn.wustlinghang.wusthelper.internal.library.services.RequestAgentService; +import cn.wustlinghang.wusthelper.internal.library.services.LoanHistoryService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.constraints.NotNull; @@ -16,27 +15,24 @@ import java.util.List; @Path("/loan_history") @ApplicationScoped public class LoanHistoryApi { - private final RequestAgentService agentService; - private final ParseService parseService; + private final LoanHistoryService service; - public LoanHistoryApi(RequestAgentService agentService, - ParseService parseService) { - this.agentService = agentService; - this.parseService = parseService; + public LoanHistoryApi(LoanHistoryService service) { + this.service = service; } @GET @Path("/") - public List get(@QueryParam("isbn") @NotNull String isbn) + public List get(@QueryParam("cookie") @NotNull String cookie) throws RpcException { - return this.parse(this.agent(isbn)); + return this.parse(this.agent(cookie)); } @GET @Path("/agent") - public String agent(@QueryParam("isbn") @NotNull String isbn) + public String agent(@QueryParam("cookie") @NotNull String cookie) throws RpcException { - return agentService.getBookCoverImageUrl(isbn); + return service.getLoanHistory(cookie); } @POST diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/OverdueSoonApi.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/OverdueSoonApi.java index 075e7a0..137a222 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/OverdueSoonApi.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/OverdueSoonApi.java @@ -1,8 +1,7 @@ package cn.wustlinghang.wusthelper.internal.library.api.http; import cn.wustlinghang.mywust.data.global.Score; -import cn.wustlinghang.wusthelper.internal.library.services.ParseService; -import cn.wustlinghang.wusthelper.internal.library.services.RequestAgentService; +import cn.wustlinghang.wusthelper.internal.library.services.OverdueSoonService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.constraints.NotNull; @@ -16,27 +15,24 @@ import java.util.List; @Path("/overdue_soon") @ApplicationScoped public class OverdueSoonApi { - private final RequestAgentService agentService; - private final ParseService parseService; + private final OverdueSoonService service; - public OverdueSoonApi(RequestAgentService agentService, - ParseService parseService) { - this.agentService = agentService; - this.parseService = parseService; + public OverdueSoonApi(OverdueSoonService service) { + this.service = service; } @GET @Path("/") - public List get(@QueryParam("isbn") @NotNull String isbn) + public List get(@QueryParam("cookie") @NotNull String cookie) throws RpcException { - return this.parse(this.agent(isbn)); + return this.parse(this.agent(cookie)); } @GET @Path("/agent") - public String agent(@QueryParam("isbn") @NotNull String isbn) + public String agent(@QueryParam("cookie") @NotNull String cookie) throws RpcException { - return agentService.getBookCoverImageUrl(isbn); + return service.getOverdueSoon(cookie); } @POST diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/SearchApi.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/SearchApi.java index 03b956a..c455d8e 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/SearchApi.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/SearchApi.java @@ -1,8 +1,7 @@ package cn.wustlinghang.wusthelper.internal.library.api.http; import cn.wustlinghang.mywust.data.global.Score; -import cn.wustlinghang.wusthelper.internal.library.services.ParseService; -import cn.wustlinghang.wusthelper.internal.library.services.RequestAgentService; +import cn.wustlinghang.wusthelper.internal.library.services.SearchService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.constraints.NotNull; @@ -16,13 +15,10 @@ import java.util.List; @Path("/search") @ApplicationScoped public class SearchApi { - private final RequestAgentService agentService; - private final ParseService parseService; + private final SearchService service; - public SearchApi(RequestAgentService agentService, - ParseService parseService) { - this.agentService = agentService; - this.parseService = parseService; + public SearchApi(SearchService service) { + this.service = service; } @GET @@ -38,7 +34,7 @@ public class SearchApi { @QueryParam("page") @NotNull int page, @QueryParam("page_size") @NotNull int pageSize) throws RpcException { - return agentService.search(keyword, page, pageSize); + return service.search(keyword, page, pageSize); } @POST diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/bean/MywustRequestAgentBeans.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/bean/MywustRequestAgentBeans.java index d747890..331619a 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/bean/MywustRequestAgentBeans.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/bean/MywustRequestAgentBeans.java @@ -1,9 +1,7 @@ package cn.wustlinghang.wusthelper.internal.library.bean; import cn.wustlinghang.mywust.core.request.service.auth.LibraryLogin; -import cn.wustlinghang.mywust.core.request.service.auth.UndergraduateLogin; -import cn.wustlinghang.mywust.core.request.service.library.LibraryApiService; -import cn.wustlinghang.mywust.core.request.service.undergraduate.*; +import cn.wustlinghang.mywust.core.request.service.library.*; import cn.wustlinghang.mywust.network.RequestClientOption; import cn.wustlinghang.mywust.network.Requester; import cn.wustlinghang.mywust.network.okhttp.SimpleOkhttpRequester; @@ -34,7 +32,32 @@ public class MywustRequestAgentBeans { } @Singleton - public LibraryApiService libraryApiService(Requester requester) { - return new LibraryApiService(requester); + public BookCoverImageUrlApiService bookCoverImageUrlApiService(Requester requester) { + return new BookCoverImageUrlApiService(requester); + } + + @Singleton + public BookDetailApiService bookDetailApiService(Requester requester) { + return new BookDetailApiService(requester); + } + + @Singleton + public CurrentLoanApiService currentLoanApiService(Requester requester) { + return new CurrentLoanApiService(requester); + } + + @Singleton + public LoanHistoryApiService loanHistoryApiService(Requester requester) { + return new LoanHistoryApiService(requester); + } + + @Singleton + public OverdueSoonApiService overdueSoonApiService(Requester requester) { + return new OverdueSoonApiService(requester); + } + + @Singleton + public SearchApiService searchApiService(Requester requester) { + return new SearchApiService(requester); } } \ No newline at end of file diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BaseService.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BaseService.java new file mode 100644 index 0000000..15481a4 --- /dev/null +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BaseService.java @@ -0,0 +1,32 @@ +package cn.wustlinghang.wusthelper.internal.library.services; + +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public abstract class BaseService { + protected LibraryRpcException wrapApiException(ApiException e, LibraryRpcException.SubModuleCode subModuleCode) { + return switch (e.getCode()) { + case NETWORK_EXCEPTION -> new LibraryRpcException( + LibraryRpcException.TypeCode.NETWORK_EXCEPTION, + subModuleCode, + LibraryRpcException.ErrorCode.NETWORK_ERROR + ); + case COOKIE_INVALID -> new LibraryRpcException( + LibraryRpcException.TypeCode.AUTH_EXCEPTION, + subModuleCode, + LibraryRpcException.ErrorCode.COOKIE_INVALID + ); + default -> { + log.error("图书馆:{}代理请求异常,异常未处理", subModuleCode.name()); + log.error("异常:", e); + yield new LibraryRpcException( + LibraryRpcException.TypeCode.AUTH_EXCEPTION, + subModuleCode, + LibraryRpcException.ErrorCode.COOKIE_INVALID + ); + } + }; + } +} diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookCoverImageUrlService.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookCoverImageUrlService.java new file mode 100644 index 0000000..1c99e83 --- /dev/null +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookCoverImageUrlService.java @@ -0,0 +1,33 @@ +package cn.wustlinghang.wusthelper.internal.library.services; + +import cn.wustlinghang.mywust.core.request.service.library.BookCoverImageUrlApiService; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; +import cn.wustlinghang.wusthelper.rpc.exception.RpcException; +import jakarta.enterprise.context.ApplicationScoped; + +import java.io.IOException; + +@ApplicationScoped +public class BookCoverImageUrlService extends BaseService { + private final BookCoverImageUrlApiService service; + + public BookCoverImageUrlService(BookCoverImageUrlApiService service) { + this.service = service; + } + + public String getBookCoverImageUrl(String isbn) throws RpcException { + try { + return service.getBookCoverImageUrl(isbn); + } catch (ApiException e) { + throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API); + } catch (IOException e) { + throw new LibraryRpcException( + LibraryRpcException.TypeCode.NETWORK_EXCEPTION, + LibraryRpcException.SubModuleCode.PUBLIC_API, + LibraryRpcException.ErrorCode.NETWORK_ERROR + ); + } + } + +} diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookDetailService.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookDetailService.java new file mode 100644 index 0000000..6e3e459 --- /dev/null +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookDetailService.java @@ -0,0 +1,33 @@ +package cn.wustlinghang.wusthelper.internal.library.services; + +import cn.wustlinghang.mywust.core.request.service.library.BookDetailApiService; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; +import cn.wustlinghang.wusthelper.rpc.exception.RpcException; +import jakarta.enterprise.context.ApplicationScoped; + +import java.io.IOException; + +@ApplicationScoped +public class BookDetailService extends BaseService { + private final BookDetailApiService service; + + public BookDetailService(BookDetailApiService service) { + this.service = service; + } + + public String getBookDetail(String bookId) throws RpcException { + try { + return service.getBookDetail(bookId); + } catch (ApiException e) { + throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API); + } catch (IOException e) { + throw new LibraryRpcException( + LibraryRpcException.TypeCode.NETWORK_EXCEPTION, + LibraryRpcException.SubModuleCode.PUBLIC_API, + LibraryRpcException.ErrorCode.NETWORK_ERROR + ); + } + } + +} diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/CurrentLoanService.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/CurrentLoanService.java new file mode 100644 index 0000000..ae44fd1 --- /dev/null +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/CurrentLoanService.java @@ -0,0 +1,33 @@ +package cn.wustlinghang.wusthelper.internal.library.services; + +import cn.wustlinghang.mywust.core.request.service.library.CurrentLoanApiService; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; +import cn.wustlinghang.wusthelper.rpc.exception.RpcException; +import jakarta.enterprise.context.ApplicationScoped; + +import java.io.IOException; + +@ApplicationScoped +public class CurrentLoanService extends BaseService { + private final CurrentLoanApiService service; + + public CurrentLoanService(CurrentLoanApiService service) { + this.service = service; + } + + public String getCurrentLoan(String cookie) throws RpcException { + try { + return service.getCurrentLoan(cookie); + } catch (ApiException e) { + throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API); + } catch (IOException e) { + throw new LibraryRpcException( + LibraryRpcException.TypeCode.NETWORK_EXCEPTION, + LibraryRpcException.SubModuleCode.PERSONAL_API, + LibraryRpcException.ErrorCode.NETWORK_ERROR + ); + } + } + +} diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/LoanHistoryService.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/LoanHistoryService.java new file mode 100644 index 0000000..1a87cac --- /dev/null +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/LoanHistoryService.java @@ -0,0 +1,32 @@ +package cn.wustlinghang.wusthelper.internal.library.services; + +import cn.wustlinghang.mywust.core.request.service.library.LoanHistoryApiService; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; +import cn.wustlinghang.wusthelper.rpc.exception.RpcException; +import jakarta.enterprise.context.ApplicationScoped; + +import java.io.IOException; + +@ApplicationScoped +public class LoanHistoryService extends BaseService { + private final LoanHistoryApiService service; + + public LoanHistoryService(LoanHistoryApiService service) { + this.service = service; + } + + public String getLoanHistory(String cookie) throws RpcException { + try { + return service.getLoanHistory(cookie); + } catch (ApiException e) { + throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API); + } catch (IOException e) { + throw new LibraryRpcException( + LibraryRpcException.TypeCode.NETWORK_EXCEPTION, + LibraryRpcException.SubModuleCode.PERSONAL_API, + LibraryRpcException.ErrorCode.NETWORK_ERROR + ); + } + } +} diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/OverdueSoonService.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/OverdueSoonService.java new file mode 100644 index 0000000..11491f7 --- /dev/null +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/OverdueSoonService.java @@ -0,0 +1,32 @@ +package cn.wustlinghang.wusthelper.internal.library.services; + +import cn.wustlinghang.mywust.core.request.service.library.OverdueSoonApiService; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; +import cn.wustlinghang.wusthelper.rpc.exception.RpcException; +import jakarta.enterprise.context.ApplicationScoped; + +import java.io.IOException; + +@ApplicationScoped +public class OverdueSoonService extends BaseService { + private final OverdueSoonApiService service; + + public OverdueSoonService(OverdueSoonApiService service) { + this.service = service; + } + + public String getOverdueSoon(String cookie) throws RpcException { + try { + return service.getOverdueSoon(cookie); + } catch (ApiException e) { + throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API); + } catch (IOException e) { + throw new LibraryRpcException( + LibraryRpcException.TypeCode.NETWORK_EXCEPTION, + LibraryRpcException.SubModuleCode.PERSONAL_API, + LibraryRpcException.ErrorCode.NETWORK_ERROR + ); + } + } +} diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/ParseService.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/ParseService.java new file mode 100644 index 0000000..86cd95c --- /dev/null +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/ParseService.java @@ -0,0 +1,8 @@ +package cn.wustlinghang.wusthelper.internal.library.services; + +import jakarta.enterprise.context.ApplicationScoped; + +@ApplicationScoped +public class ParseService { + +} diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/RequestAgentService.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/RequestAgentService.java deleted file mode 100644 index 3e9ec41..0000000 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/RequestAgentService.java +++ /dev/null @@ -1,129 +0,0 @@ -package cn.wustlinghang.wusthelper.internal.library.services; - -import cn.wustlinghang.mywust.core.request.service.library.LibraryApiService; -import cn.wustlinghang.mywust.exception.ApiException; -import cn.wustlinghang.mywust.network.RequestClientOption; -import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; -import cn.wustlinghang.wusthelper.rpc.exception.RpcException; -import jakarta.enterprise.context.ApplicationScoped; -import lombok.extern.slf4j.Slf4j; - -import java.io.IOException; - -@Slf4j -@ApplicationScoped -public class RequestAgentService { - private final LibraryApiService libraryApiService; - - public RequestAgentService(LibraryApiService libraryApiService) { - this.libraryApiService = libraryApiService; - } - - public String getBookCoverImageUrl(String isbn) throws RpcException { - try { - return libraryApiService.getBookCoverImageUrl(isbn); - } catch (ApiException e) { - throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API); - } catch (IOException e) { - throw new LibraryRpcException( - LibraryRpcException.TypeCode.NETWORK_EXCEPTION, - LibraryRpcException.SubModuleCode.PUBLIC_API, - LibraryRpcException.ErrorCode.NETWORK_ERROR - ); - } - } - - public String getBookDetail(String bookId) throws RpcException { - try { - return libraryApiService.getBookDetail(bookId); - } catch (ApiException e) { - throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API); - } catch (IOException e) { - throw new LibraryRpcException( - LibraryRpcException.TypeCode.NETWORK_EXCEPTION, - LibraryRpcException.SubModuleCode.PUBLIC_API, - LibraryRpcException.ErrorCode.NETWORK_ERROR - ); - } - } - - public String getCurrentLoan(String cookie) throws RpcException { - try { - return libraryApiService.getCurrentLoan(cookie); - } catch (ApiException e) { - throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API); - } catch (IOException e) { - throw new LibraryRpcException( - LibraryRpcException.TypeCode.NETWORK_EXCEPTION, - LibraryRpcException.SubModuleCode.PERSONAL_API, - LibraryRpcException.ErrorCode.NETWORK_ERROR - ); - } - } - - public String search(String keyword, int page, int pageSize) throws RpcException { - try { - return libraryApiService.search(keyword, page, pageSize); - } catch (ApiException e) { - throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API); - } catch (IOException e) { - throw new LibraryRpcException( - LibraryRpcException.TypeCode.NETWORK_EXCEPTION, - LibraryRpcException.SubModuleCode.PUBLIC_API, - LibraryRpcException.ErrorCode.NETWORK_ERROR - ); - } - } - - public String getLoanHistory(String cookie) throws RpcException { - try { - return libraryApiService.getLoanHistory(cookie); - } catch (ApiException e) { - throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API); - } catch (IOException e) { - throw new LibraryRpcException( - LibraryRpcException.TypeCode.NETWORK_EXCEPTION, - LibraryRpcException.SubModuleCode.PERSONAL_API, - LibraryRpcException.ErrorCode.NETWORK_ERROR - ); - } - } - - public String getOverdueSoon(String cookie) throws RpcException { - try { - return libraryApiService.getOverdueSoon(cookie); - } catch (ApiException e) { - throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API); - } catch (IOException e) { - throw new LibraryRpcException( - LibraryRpcException.TypeCode.NETWORK_EXCEPTION, - LibraryRpcException.SubModuleCode.PERSONAL_API, - LibraryRpcException.ErrorCode.NETWORK_ERROR - ); - } - } - - private LibraryRpcException wrapApiException(ApiException e, LibraryRpcException.SubModuleCode subModuleCode) { - return switch (e.getCode()) { - case NETWORK_EXCEPTION -> new LibraryRpcException( - LibraryRpcException.TypeCode.NETWORK_EXCEPTION, - subModuleCode, - LibraryRpcException.ErrorCode.NETWORK_ERROR - ); - case COOKIE_INVALID -> new LibraryRpcException( - LibraryRpcException.TypeCode.AUTH_EXCEPTION, - subModuleCode, - LibraryRpcException.ErrorCode.COOKIE_INVALID - ); - default -> { - log.error("本科生:{}代理请求异常,异常未处理", subModuleCode.name()); - log.error("异常:", e); - yield new LibraryRpcException( - LibraryRpcException.TypeCode.AUTH_EXCEPTION, - subModuleCode, - LibraryRpcException.ErrorCode.COOKIE_INVALID - ); - } - }; - } -} diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/SearchService.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/SearchService.java new file mode 100644 index 0000000..8f6f9ff --- /dev/null +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/SearchService.java @@ -0,0 +1,32 @@ +package cn.wustlinghang.wusthelper.internal.library.services; + +import cn.wustlinghang.mywust.core.request.service.library.SearchApiService; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; +import cn.wustlinghang.wusthelper.rpc.exception.RpcException; +import jakarta.enterprise.context.ApplicationScoped; + +import java.io.IOException; + +@ApplicationScoped +public class SearchService extends BaseService { + private final SearchApiService service; + + public SearchService(SearchApiService service) { + this.service = service; + } + + public String search(String keyword, int page, int pageSize) throws RpcException { + try { + return service.search(keyword, page, pageSize); + } catch (ApiException e) { + throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API); + } catch (IOException e) { + throw new LibraryRpcException( + LibraryRpcException.TypeCode.NETWORK_EXCEPTION, + LibraryRpcException.SubModuleCode.PUBLIC_API, + LibraryRpcException.ErrorCode.NETWORK_ERROR + ); + } + } +} \ No newline at end of file diff --git a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/http/CourseTableApi.java b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/http/CourseTableApi.java index 0d774c5..bf32dd5 100644 --- a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/http/CourseTableApi.java +++ b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/http/CourseTableApi.java @@ -1,8 +1,7 @@ package cn.wustlinghang.wusthelper.internal.physics.api.http; import cn.wustlinghang.mywust.data.physics.PhysicsCourse; -import cn.wustlinghang.wusthelper.internal.physics.services.ParseService; -import cn.wustlinghang.wusthelper.internal.physics.services.RequestAgentService; +import cn.wustlinghang.wusthelper.internal.physics.services.CourseTableService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.constraints.NotNull; @@ -16,13 +15,10 @@ import java.util.List; @Path("/course_table") @ApplicationScoped public class CourseTableApi { - private final RequestAgentService agentService; - private final ParseService parseService; + private final CourseTableService service; - public CourseTableApi(RequestAgentService agentService, - ParseService parseService) { - this.agentService = agentService; - this.parseService = parseService; + public CourseTableApi(CourseTableService service) { + this.service = service; } @GET @@ -36,12 +32,12 @@ public class CourseTableApi { @Path("/agent") public String agent(@QueryParam("cookie") @NotNull String cookie) throws RpcException { - return agentService.getCourseTable(cookie); + return service.getCourseTable(cookie); } @POST @Path("/parse") public List parse(String html) throws RpcException { - return parseService.parseCourseTable(html); + return service.parseCourseTable(html); } } diff --git a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/http/ScoreApi.java b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/http/ScoreApi.java index 3dd7c4f..c506a11 100644 --- a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/http/ScoreApi.java +++ b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/http/ScoreApi.java @@ -1,8 +1,7 @@ package cn.wustlinghang.wusthelper.internal.physics.api.http; import cn.wustlinghang.mywust.data.global.Score; -import cn.wustlinghang.wusthelper.internal.physics.services.ParseService; -import cn.wustlinghang.wusthelper.internal.physics.services.RequestAgentService; +import cn.wustlinghang.wusthelper.internal.physics.services.ScoreService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.constraints.NotNull; @@ -16,13 +15,10 @@ import java.util.List; @Path("/score") @ApplicationScoped public class ScoreApi { - private final RequestAgentService agentService; - private final ParseService parseService; + private final ScoreService service; - public ScoreApi(RequestAgentService agentService, - ParseService parseService) { - this.agentService = agentService; - this.parseService = parseService; + public ScoreApi(ScoreService service) { + this.service = service; } @GET @@ -36,18 +32,18 @@ public class ScoreApi { @Path("/agent") public List agent(@QueryParam("cookie") @NotNull String cookie) throws RpcException { - return agentService.getScore(cookie); + return service.getScore(cookie); } @POST @Path("/parse") public List parse(String html) throws RpcException { - return parseService.parseScore(html); + return service.parseScore(html); } @POST @Path("/parse/all") public List parseAll(List pages) throws RpcException { - return parseService.parseAllScore(pages); + return service.parseScore(pages); } } diff --git a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/BaseService.java b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/BaseService.java new file mode 100644 index 0000000..233ae1a --- /dev/null +++ b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/BaseService.java @@ -0,0 +1,32 @@ +package cn.wustlinghang.wusthelper.internal.physics.services; + +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.wusthelper.internal.physics.exception.PhysicsRpcException; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public abstract class BaseService { + protected PhysicsRpcException wrapApiException(ApiException e, PhysicsRpcException.SubModuleCode subModuleCode) { + return switch (e.getCode()) { + case NETWORK_EXCEPTION -> new PhysicsRpcException( + PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, + subModuleCode, + PhysicsRpcException.ErrorCode.NETWORK_ERROR + ); + case COOKIE_INVALID -> new PhysicsRpcException( + PhysicsRpcException.TypeCode.AUTH_EXCEPTION, + subModuleCode, + PhysicsRpcException.ErrorCode.COOKIE_INVALID + ); + default -> { + log.error("物理实验:{}代理请求异常,异常未处理", subModuleCode.name()); + log.error("异常:", e); + yield new PhysicsRpcException( + PhysicsRpcException.TypeCode.AUTH_EXCEPTION, + subModuleCode, + PhysicsRpcException.ErrorCode.COOKIE_INVALID + ); + } + }; + } +} diff --git a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/CourseTableService.java b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/CourseTableService.java new file mode 100644 index 0000000..220ca8f --- /dev/null +++ b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/CourseTableService.java @@ -0,0 +1,57 @@ +package cn.wustlinghang.wusthelper.internal.physics.services; + +import cn.wustlinghang.mywust.core.parser.physics.PhysicsCoursePageParser; +import cn.wustlinghang.mywust.core.request.service.physics.PhysicsCourseApiService; +import cn.wustlinghang.mywust.data.physics.PhysicsCourse; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.mywust.network.RequestClientOption; +import cn.wustlinghang.wusthelper.internal.physics.exception.PhysicsRpcException; +import cn.wustlinghang.wusthelper.rpc.exception.RpcException; +import jakarta.enterprise.context.ApplicationScoped; + +import java.io.IOException; +import java.util.List; + +@ApplicationScoped +public class CourseTableService extends BaseService { + + private final RequestClientOption requestClientOption; + + private final PhysicsCourseApiService agent; + private final PhysicsCoursePageParser parser; + + public CourseTableService(RequestClientOption requestClientOption, + PhysicsCourseApiService agent, + PhysicsCoursePageParser parser) { + this.requestClientOption = requestClientOption; + + this.agent = agent; + this.parser = parser; + } + + public String getCourseTable(String cookie) throws RpcException { + try { + return agent.getPage(cookie, requestClientOption); + } catch (ApiException e) { + throw wrapApiException(e, PhysicsRpcException.SubModuleCode.COURSE_TABLE); + } catch (IOException e) { + throw new PhysicsRpcException( + PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, + PhysicsRpcException.SubModuleCode.COURSE_TABLE, + PhysicsRpcException.ErrorCode.NETWORK_ERROR + ); + } + } + + public List parseCourseTable(String data) throws PhysicsRpcException { + try { + return parser.parse(data); + } catch (Exception e) { + throw new PhysicsRpcException( + PhysicsRpcException.TypeCode.PARSE_EXCEPTION, + PhysicsRpcException.SubModuleCode.COURSE_TABLE, + PhysicsRpcException.ErrorCode.PARSE_ERROR + ); + } + } +} diff --git a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/ParseService.java b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/ParseService.java deleted file mode 100644 index ff462ff..0000000 --- a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/ParseService.java +++ /dev/null @@ -1,69 +0,0 @@ -package cn.wustlinghang.wusthelper.internal.physics.services; - -import cn.wustlinghang.mywust.core.parser.physics.PhysicsCoursePageParser; -import cn.wustlinghang.mywust.core.parser.physics.PhysicsScorePageParser; -import cn.wustlinghang.mywust.data.global.Score; -import cn.wustlinghang.mywust.data.physics.PhysicsCourse; -import cn.wustlinghang.wusthelper.internal.physics.exception.PhysicsRpcException; -import cn.wustlinghang.wusthelper.rpc.exception.RpcException; -import jakarta.enterprise.context.ApplicationScoped; - -import java.util.ArrayList; -import java.util.List; - -@ApplicationScoped -public class ParseService { - private final PhysicsCoursePageParser coursePageParser; - private final PhysicsScorePageParser scorePageParser; - - public ParseService(PhysicsCoursePageParser coursePageParser, - PhysicsScorePageParser scorePageParser) { - this.coursePageParser = coursePageParser; - this.scorePageParser = scorePageParser; - } - - public List parseCourseTable(String data) throws PhysicsRpcException { - try { - return coursePageParser.parse(data); - } catch (Exception e) { - throw new PhysicsRpcException( - PhysicsRpcException.TypeCode.PARSE_EXCEPTION, - PhysicsRpcException.SubModuleCode.COURSE_TABLE, - PhysicsRpcException.ErrorCode.PARSE_ERROR - ); - } - } - - public List parseScore(String data) throws RpcException { - try { - return scorePageParser.parse(data); - } catch (PhysicsRpcException e) { - throw e; - } catch (Exception e) { - throw new PhysicsRpcException( - PhysicsRpcException.TypeCode.PARSE_EXCEPTION, - PhysicsRpcException.SubModuleCode.SCORE, - PhysicsRpcException.ErrorCode.PARSE_ERROR - ); - } - } - - public List parseAllScore(List pages) throws RpcException { - try { - List scores = new ArrayList<>(); - for (String page : pages) { - scores.addAll(scorePageParser.parse(page)); - } - - return scores; - } catch (PhysicsRpcException e) { - throw e; - } catch (Exception e) { - throw new PhysicsRpcException( - PhysicsRpcException.TypeCode.PARSE_EXCEPTION, - PhysicsRpcException.SubModuleCode.SCORE, - PhysicsRpcException.ErrorCode.PARSE_ERROR - ); - } - } -} diff --git a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/RequestAgentService.java b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/RequestAgentService.java deleted file mode 100644 index 2dc8f71..0000000 --- a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/RequestAgentService.java +++ /dev/null @@ -1,91 +0,0 @@ -package cn.wustlinghang.wusthelper.internal.physics.services; - -import cn.wustlinghang.mywust.core.request.service.physics.PhysicsCourseApiService; -import cn.wustlinghang.mywust.core.request.service.physics.PhysicsScoreApiService; -import cn.wustlinghang.mywust.exception.ApiException; -import cn.wustlinghang.mywust.exception.ParseException; -import cn.wustlinghang.mywust.network.RequestClientOption; -import cn.wustlinghang.wusthelper.internal.physics.exception.PhysicsRpcException; -import cn.wustlinghang.wusthelper.rpc.exception.RpcException; -import jakarta.enterprise.context.ApplicationScoped; -import lombok.extern.slf4j.Slf4j; - -import java.io.IOException; -import java.util.List; - -@Slf4j -@ApplicationScoped -public class RequestAgentService { - - private final RequestClientOption requestClientOption; - - private final PhysicsCourseApiService physicsCourseApiService; - private final PhysicsScoreApiService physicsScoreApiService; - - public RequestAgentService(RequestClientOption requestClientOption, - PhysicsCourseApiService physicsCourseApiService, - PhysicsScoreApiService physicsScoreApiService) { - this.requestClientOption = requestClientOption; - - this.physicsCourseApiService = physicsCourseApiService; - this.physicsScoreApiService = physicsScoreApiService; - } - - public String getCourseTable(String cookie) throws RpcException { - try { - return physicsCourseApiService.getPage(cookie, requestClientOption); - } catch (ApiException e) { - throw wrapApiException(e, PhysicsRpcException.SubModuleCode.COURSE_TABLE); - } catch (IOException e) { - throw new PhysicsRpcException( - PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, - PhysicsRpcException.SubModuleCode.COURSE_TABLE, - PhysicsRpcException.ErrorCode.NETWORK_ERROR - ); - } - } - - public List getScore(String cookie) throws RpcException { - try { - return physicsScoreApiService.getAllPages(cookie, requestClientOption); - } catch (ApiException e) { - throw wrapApiException(e, PhysicsRpcException.SubModuleCode.SCORE); - } catch (IOException e) { - throw new PhysicsRpcException( - PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, - PhysicsRpcException.SubModuleCode.SCORE, - PhysicsRpcException.ErrorCode.NETWORK_ERROR - ); - } catch (ParseException e) { - throw new PhysicsRpcException( - PhysicsRpcException.TypeCode.OTHER_EXCEPTION, - PhysicsRpcException.SubModuleCode.SCORE, - PhysicsRpcException.ErrorCode.PARSE_ERROR - ); - } - } - - private PhysicsRpcException wrapApiException(ApiException e, PhysicsRpcException.SubModuleCode subModuleCode) { - return switch (e.getCode()) { - case NETWORK_EXCEPTION -> new PhysicsRpcException( - PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, - subModuleCode, - PhysicsRpcException.ErrorCode.NETWORK_ERROR - ); - case COOKIE_INVALID -> new PhysicsRpcException( - PhysicsRpcException.TypeCode.AUTH_EXCEPTION, - subModuleCode, - PhysicsRpcException.ErrorCode.COOKIE_INVALID - ); - default -> { - log.error("物理实验:{}代理请求异常,异常未处理", subModuleCode.name()); - log.error("异常:", e); - yield new PhysicsRpcException( - PhysicsRpcException.TypeCode.AUTH_EXCEPTION, - subModuleCode, - PhysicsRpcException.ErrorCode.COOKIE_INVALID - ); - } - }; - } -} diff --git a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/ScoreService.java b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/ScoreService.java new file mode 100644 index 0000000..9591499 --- /dev/null +++ b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/ScoreService.java @@ -0,0 +1,87 @@ +package cn.wustlinghang.wusthelper.internal.physics.services; + +import cn.wustlinghang.mywust.core.parser.physics.PhysicsScorePageParser; +import cn.wustlinghang.mywust.core.request.service.physics.PhysicsScoreApiService; +import cn.wustlinghang.mywust.data.global.Score; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.mywust.exception.ParseException; +import cn.wustlinghang.mywust.network.RequestClientOption; +import cn.wustlinghang.wusthelper.internal.physics.exception.PhysicsRpcException; +import cn.wustlinghang.wusthelper.rpc.exception.RpcException; +import jakarta.enterprise.context.ApplicationScoped; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +@ApplicationScoped +public class ScoreService extends BaseService { + + private final RequestClientOption requestClientOption; + + private final PhysicsScoreApiService agent; + private final PhysicsScorePageParser parser; + + public ScoreService(RequestClientOption requestClientOption, + PhysicsScoreApiService agent, + PhysicsScorePageParser parser) { + this.requestClientOption = requestClientOption; + + this.agent = agent; + this.parser = parser; + } + + public List getScore(String cookie) throws RpcException { + try { + return agent.getAllPages(cookie, requestClientOption); + } catch (ApiException e) { + throw wrapApiException(e, PhysicsRpcException.SubModuleCode.SCORE); + } catch (IOException e) { + throw new PhysicsRpcException( + PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, + PhysicsRpcException.SubModuleCode.SCORE, + PhysicsRpcException.ErrorCode.NETWORK_ERROR + ); + } catch (ParseException e) { + throw new PhysicsRpcException( + PhysicsRpcException.TypeCode.OTHER_EXCEPTION, + PhysicsRpcException.SubModuleCode.SCORE, + PhysicsRpcException.ErrorCode.PARSE_ERROR + ); + } + } + + + public List parseScore(String data) throws RpcException { + try { + return parser.parse(data); + } catch (PhysicsRpcException e) { + throw e; + } catch (Exception e) { + throw new PhysicsRpcException( + PhysicsRpcException.TypeCode.PARSE_EXCEPTION, + PhysicsRpcException.SubModuleCode.SCORE, + PhysicsRpcException.ErrorCode.PARSE_ERROR + ); + } + } + + public List parseScore(List pages) throws RpcException { + try { + List scores = new ArrayList<>(); + for (String page : pages) { + scores.addAll(parser.parse(page)); + } + + return scores; + } catch (PhysicsRpcException e) { + throw e; + } catch (Exception e) { + throw new PhysicsRpcException( + PhysicsRpcException.TypeCode.PARSE_EXCEPTION, + PhysicsRpcException.SubModuleCode.SCORE, + PhysicsRpcException.ErrorCode.PARSE_ERROR + ); + } + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/CourseTableApi.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/CourseTableApi.java index cc200c0..7e4be8a 100644 --- a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/CourseTableApi.java +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/CourseTableApi.java @@ -1,8 +1,7 @@ package cn.wustlinghang.wusthelper.internal.undergrad.api.http; import cn.wustlinghang.mywust.data.global.Course; -import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService; -import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService; +import cn.wustlinghang.wusthelper.internal.undergrad.services.CourseTableService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.constraints.NotNull; @@ -16,13 +15,10 @@ import java.util.List; @Path("/course_table") @ApplicationScoped public class CourseTableApi { - private final RequestAgentService agentService; - private final ParseService parseService; + private final CourseTableService service; - public CourseTableApi(RequestAgentService agentService, - ParseService parseService) { - this.agentService = agentService; - this.parseService = parseService; + public CourseTableApi(CourseTableService service) { + this.service = service; } @GET @@ -38,12 +34,12 @@ public class CourseTableApi { public String agent(@QueryParam("cookie") @NotNull String cookie, @QueryParam("term") String term) throws RpcException { - return agentService.getCourseTable(cookie, term); + return service.getCourseTable(cookie, term); } @POST @Path("/parse") public List parse(String html) throws RpcException { - return parseService.parseCourseTable(html); + return service.parseCourseTable(html); } } diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/CreditStatusApi.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/CreditStatusApi.java index b10377c..ceed384 100644 --- a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/CreditStatusApi.java +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/CreditStatusApi.java @@ -1,7 +1,6 @@ package cn.wustlinghang.wusthelper.internal.undergrad.api.http; -import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService; -import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService; +import cn.wustlinghang.wusthelper.internal.undergrad.services.CreditStatusService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.constraints.NotNull; @@ -13,15 +12,12 @@ import jakarta.ws.rs.QueryParam; @Path("/credit_status") @ApplicationScoped public class CreditStatusApi { - private final RequestAgentService agentService; - private final ParseService parseService; + private final CreditStatusService service; - public CreditStatusApi(RequestAgentService agentService, - ParseService parseService) { - this.agentService = agentService; - this.parseService = parseService; + public CreditStatusApi(CreditStatusService service) { + this.service = service; } - + @GET @Path("/") public String get(@QueryParam("cookie") @NotNull String cookie) @@ -34,12 +30,12 @@ public class CreditStatusApi { @Path("/agent") public String agent(@QueryParam("cookie") @NotNull String cookie) throws RpcException { - return agentService.getCreditStatus(cookie); + return service.getCreditStatus(cookie); } @POST @Path("/parse") public String parse(String html) throws RpcException { - return parseService.parseCreditStatus(html); + return service.parseCreditStatus(html); } } diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/ExamActivitiesApi.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/ExamActivitiesApi.java index 4e5e362..416f878 100644 --- a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/ExamActivitiesApi.java +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/ExamActivitiesApi.java @@ -2,7 +2,7 @@ package cn.wustlinghang.wusthelper.internal.undergrad.api.http; import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradExamDelayApiService; import cn.wustlinghang.mywust.data.global.Score; -import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService; +import cn.wustlinghang.wusthelper.internal.undergrad.services.ExamActivitiesService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.constraints.NotNull; @@ -16,10 +16,10 @@ import java.util.List; @Path("/exam_activities") @ApplicationScoped public class ExamActivitiesApi { - private final RequestAgentService agentService; + private final ExamActivitiesService service; - public ExamActivitiesApi(RequestAgentService agentService) { - this.agentService = agentService; + public ExamActivitiesApi(ExamActivitiesService service) { + this.service = service; } @GET @@ -37,12 +37,12 @@ public class ExamActivitiesApi { @QueryParam("cookie") @NotNull String cookie, @QueryParam("term") @NotNull String term) throws RpcException { - return agentService.getExamActivities(cookie, term); + return service.getExamActivities(cookie, term); } @POST @Path("/parse") - public List parse(String html) throws RpcException { + public List parse() throws RpcException { throw RpcException.ApiNotImplement(); } } diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/ExamDelayApplicationApi.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/ExamDelayApplicationApi.java index cedf5ef..96da3c3 100644 --- a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/ExamDelayApplicationApi.java +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/ExamDelayApplicationApi.java @@ -1,8 +1,7 @@ package cn.wustlinghang.wusthelper.internal.undergrad.api.http; import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication; -import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService; -import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService; +import cn.wustlinghang.wusthelper.internal.undergrad.services.ExamDelayApplicationService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.constraints.NotNull; @@ -16,13 +15,10 @@ import java.util.List; @Path("/exam_delay_application") @ApplicationScoped public class ExamDelayApplicationApi { - private final RequestAgentService agentService; - private final ParseService parseService; + private final ExamDelayApplicationService service; - public ExamDelayApplicationApi(RequestAgentService agentService, - ParseService parseService) { - this.agentService = agentService; - this.parseService = parseService; + public ExamDelayApplicationApi(ExamDelayApplicationService service) { + this.service = service; } @GET @@ -41,12 +37,12 @@ public class ExamDelayApplicationApi { @QueryParam("term") @NotNull String term, @QueryParam("activity_id") @NotNull String activityId) throws RpcException { - return agentService.getExamDelayApplications(cookie, term, activityId); + return service.getExamDelayApplications(cookie, term, activityId); } @POST @Path("/parse") public List parse(String html) throws RpcException { - return parseService.parseExamDelayApplications(html); + return service.parseExamDelayApplications(html); } } diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/ScoreApi.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/ScoreApi.java index c284187..6905e75 100644 --- a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/ScoreApi.java +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/ScoreApi.java @@ -1,8 +1,7 @@ package cn.wustlinghang.wusthelper.internal.undergrad.api.http; import cn.wustlinghang.mywust.data.global.Score; -import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService; -import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService; +import cn.wustlinghang.wusthelper.internal.undergrad.services.ScoreService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.constraints.NotNull; @@ -16,13 +15,10 @@ import java.util.List; @Path("/score") @ApplicationScoped public class ScoreApi { - private final RequestAgentService agentService; - private final ParseService parseService; + private final ScoreService service; - public ScoreApi(RequestAgentService agentService, - ParseService parseService) { - this.agentService = agentService; - this.parseService = parseService; + public ScoreApi(ScoreService service) { + this.service = service; } @GET @@ -36,12 +32,12 @@ public class ScoreApi { @Path("/agent") public String agent(@QueryParam("cookie") @NotNull String cookie) throws RpcException { - return agentService.getScore(cookie); + return service.getScore(cookie); } @POST @Path("/parse") public List parse(String html) throws RpcException { - return parseService.parseScore(html); + return service.parseScore(html); } } diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/StudentInfoApi.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/StudentInfoApi.java index d1079e7..1da83b8 100644 --- a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/StudentInfoApi.java +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/StudentInfoApi.java @@ -1,8 +1,7 @@ package cn.wustlinghang.wusthelper.internal.undergrad.api.http; import cn.wustlinghang.mywust.data.global.StudentInfo; -import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService; -import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService; +import cn.wustlinghang.wusthelper.internal.undergrad.services.StudentInfoService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.constraints.NotNull; @@ -14,13 +13,10 @@ import jakarta.ws.rs.QueryParam; @Path("/student_info") @ApplicationScoped public class StudentInfoApi { - private final RequestAgentService agentService; - private final ParseService parseService; + private final StudentInfoService service; - public StudentInfoApi(RequestAgentService agentService, - ParseService parseService) { - this.agentService = agentService; - this.parseService = parseService; + public StudentInfoApi(StudentInfoService service) { + this.service = service; } @GET @@ -34,12 +30,12 @@ public class StudentInfoApi { @Path("/agent") public String agent(@QueryParam("cookie") @NotNull String cookie) throws RpcException { - return agentService.getStudentInfoPage(cookie); + return service.getStudentInfoPage(cookie); } @POST @Path("/parse") public StudentInfo parse(String html) throws RpcException { - return parseService.parseStudentInfo(html); + return service.parseStudentInfo(html); } } diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/TrainingPlanApi.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/TrainingPlanApi.java index 5536c4f..d3a25ed 100644 --- a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/TrainingPlanApi.java +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/TrainingPlanApi.java @@ -1,7 +1,6 @@ package cn.wustlinghang.wusthelper.internal.undergrad.api.http; -import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService; -import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService; +import cn.wustlinghang.wusthelper.internal.undergrad.services.TrainingPlanService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.constraints.NotNull; @@ -13,13 +12,10 @@ import jakarta.ws.rs.QueryParam; @Path("/training_plan") @ApplicationScoped public class TrainingPlanApi { - private final RequestAgentService agentService; - private final ParseService parseService; + private final TrainingPlanService service; - public TrainingPlanApi(RequestAgentService agentService, - ParseService parseService) { - this.agentService = agentService; - this.parseService = parseService; + public TrainingPlanApi(TrainingPlanService service) { + this.service = service; } @GET @@ -33,12 +29,12 @@ public class TrainingPlanApi { @Path("/agent") public String agent(@QueryParam("cookie") @NotNull String cookie) throws RpcException { - return agentService.getTrainingPlan(cookie); + return service.getTrainingPlan(cookie); } @POST @Path("/parse") public String parse(String html) throws RpcException { - return parseService.parseTrainingPlan(html); + return service.parseTrainingPlan(html); } } diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/BaseService.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/BaseService.java new file mode 100644 index 0000000..059f822 --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/BaseService.java @@ -0,0 +1,32 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.services; + +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public abstract class BaseService { + protected UndergradRpcException wrapApiException(ApiException e, UndergradRpcException.SubModuleCode subModuleCode) { + return switch (e.getCode()) { + case NETWORK_EXCEPTION -> new UndergradRpcException( + UndergradRpcException.TypeCode.NETWORK_EXCEPTION, + subModuleCode, + UndergradRpcException.ErrorCode.NETWORK_ERROR + ); + case COOKIE_INVALID -> new UndergradRpcException( + UndergradRpcException.TypeCode.AUTH_EXCEPTION, + subModuleCode, + UndergradRpcException.ErrorCode.COOKIE_INVALID + ); + default -> { + log.error("本科生:{}代理请求异常,异常未处理", subModuleCode.name()); + log.error("异常:", e); + yield new UndergradRpcException( + UndergradRpcException.TypeCode.AUTH_EXCEPTION, + subModuleCode, + UndergradRpcException.ErrorCode.COOKIE_INVALID + ); + } + }; + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/CourseTableService.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/CourseTableService.java new file mode 100644 index 0000000..db642cd --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/CourseTableService.java @@ -0,0 +1,58 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.services; + +import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradCourseTableParser; +import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradCourseTableApiService; +import cn.wustlinghang.mywust.data.global.Course; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException; +import cn.wustlinghang.wusthelper.rpc.exception.RpcException; +import jakarta.enterprise.context.ApplicationScoped; + +import java.io.IOException; +import java.util.List; + +@ApplicationScoped +public class CourseTableService extends BaseService { + private final UndergradCourseTableParser courseTableParser; + private final UndergradCourseTableApiService courseTableApiService; + + public CourseTableService(UndergradCourseTableParser courseTableParser, + UndergradCourseTableApiService courseTableApiService) { + this.courseTableParser = courseTableParser; + this.courseTableApiService = courseTableApiService; + } + + public String getCourseTable(String cookie, String term) throws RpcException { + try { + return courseTableApiService.getPage(term, cookie); + } catch (ApiException e) { + throw wrapApiException(e, UndergradRpcException.SubModuleCode.COURSE_TABLE); + } catch (IOException e) { + throw new UndergradRpcException( + UndergradRpcException.TypeCode.NETWORK_EXCEPTION, + UndergradRpcException.SubModuleCode.COURSE_TABLE, + UndergradRpcException.ErrorCode.NETWORK_ERROR + ); + } + } + + public List parseCourseTable(String data) throws UndergradRpcException { + try { + if (data.contains("评教")) { + throw new UndergradRpcException( + UndergradRpcException.TypeCode.PARSE_EXCEPTION, + UndergradRpcException.SubModuleCode.COURSE_TABLE, + UndergradRpcException.ErrorCode.NEED_EVALUATE + ); + } + + return courseTableParser.parse(data); + } catch (Exception e) { + throw new UndergradRpcException( + UndergradRpcException.TypeCode.PARSE_EXCEPTION, + UndergradRpcException.SubModuleCode.COURSE_TABLE, + UndergradRpcException.ErrorCode.PARSE_ERROR + ); + } + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/CreditStatusService.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/CreditStatusService.java new file mode 100644 index 0000000..caee00b --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/CreditStatusService.java @@ -0,0 +1,53 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.services; + +import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradCreditStatusParser; +import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradCreditStatusApiService; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.mywust.network.RequestClientOption; +import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException; +import cn.wustlinghang.wusthelper.rpc.exception.RpcException; +import jakarta.enterprise.context.ApplicationScoped; + +import java.io.IOException; + +@ApplicationScoped +public class CreditStatusService extends BaseService { + private final UndergradCreditStatusApiService creditStatusApiService; + private final UndergradCreditStatusParser creditStatusParser; + + private final RequestClientOption requestClientOption; + public CreditStatusService(UndergradCreditStatusApiService creditStatusApiService, + UndergradCreditStatusParser creditStatusParser, + RequestClientOption requestClientOption) { + this.creditStatusApiService = creditStatusApiService; + this.creditStatusParser = creditStatusParser; + + this.requestClientOption = requestClientOption; + } + + public String getCreditStatus(String cookie) throws RpcException { + try { + return creditStatusApiService.getPage(cookie, requestClientOption, false); + } catch (ApiException e) { + throw wrapApiException(e, UndergradRpcException.SubModuleCode.CREDIT_STATUS); + } catch (IOException e) { + throw new UndergradRpcException( + UndergradRpcException.TypeCode.NETWORK_EXCEPTION, + UndergradRpcException.SubModuleCode.CREDIT_STATUS, + UndergradRpcException.ErrorCode.NETWORK_ERROR + ); + } + } + + public String parseCreditStatus(String data) throws RpcException { + try { + return creditStatusParser.parse(data); + } catch (Exception e) { + throw new UndergradRpcException( + UndergradRpcException.TypeCode.PARSE_EXCEPTION, + UndergradRpcException.SubModuleCode.CREDIT_STATUS, + UndergradRpcException.ErrorCode.PARSE_ERROR + ); + } + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ExamActivitiesService.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ExamActivitiesService.java new file mode 100644 index 0000000..c7b2662 --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ExamActivitiesService.java @@ -0,0 +1,34 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.services; + +import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradExamDelayApiService; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException; +import cn.wustlinghang.wusthelper.rpc.exception.RpcException; +import jakarta.enterprise.context.ApplicationScoped; + +import java.io.IOException; + +@ApplicationScoped +public class ExamActivitiesService extends BaseService { + private final UndergradExamDelayApiService examDelayApiService; + + public ExamActivitiesService(UndergradExamDelayApiService examDelayApiService) { + this.examDelayApiService = examDelayApiService; + } + + public UndergradExamDelayApiService.ExamActivity[] getExamActivities(String cookie, String term) + throws RpcException { + try { + return examDelayApiService.getActivities(term, cookie); + } catch (ApiException e) { + throw wrapApiException(e, UndergradRpcException.SubModuleCode.EXAM_ACTIVITIES); + } catch (IOException e) { + throw new UndergradRpcException( + UndergradRpcException.TypeCode.NETWORK_EXCEPTION, + UndergradRpcException.SubModuleCode.EXAM_ACTIVITIES, + UndergradRpcException.ErrorCode.NETWORK_ERROR + ); + } + } + +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ExamDelayApplicationService.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ExamDelayApplicationService.java new file mode 100644 index 0000000..5008b0c --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ExamDelayApplicationService.java @@ -0,0 +1,51 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.services; + +import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradExamDelayParser; +import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradExamDelayApiService; +import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException; +import cn.wustlinghang.wusthelper.rpc.exception.RpcException; +import jakarta.enterprise.context.ApplicationScoped; + +import java.io.IOException; +import java.util.List; + +@ApplicationScoped +public class ExamDelayApplicationService extends BaseService { + private final UndergradExamDelayApiService examDelayApiService; + private final UndergradExamDelayParser examDelayParser; + + public ExamDelayApplicationService(UndergradExamDelayApiService examDelayApiService, + UndergradExamDelayParser examDelayParser) { + this.examDelayApiService = examDelayApiService; + this.examDelayParser = examDelayParser; + } + + public String getExamDelayApplications(String cookie, String term, String activityId) + throws RpcException { + try { + return examDelayApiService.getPage(term, activityId, cookie); + } catch (ApiException e) { + throw wrapApiException(e, UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION); + } catch (IOException e) { + throw new UndergradRpcException( + UndergradRpcException.TypeCode.NETWORK_EXCEPTION, + UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION, + UndergradRpcException.ErrorCode.NETWORK_ERROR + ); + } + } + + public List parseExamDelayApplications(String data) throws RpcException { + try { + return examDelayParser.parse(data); + } catch (Exception e) { + throw new UndergradRpcException( + UndergradRpcException.TypeCode.PARSE_EXCEPTION, + UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION, + UndergradRpcException.ErrorCode.PARSE_ERROR + ); + } + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ParseService.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ParseService.java deleted file mode 100644 index 22aae56..0000000 --- a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ParseService.java +++ /dev/null @@ -1,132 +0,0 @@ -package cn.wustlinghang.wusthelper.internal.undergrad.services; - -import cn.wustlinghang.mywust.core.parser.undergraduate.*; -import cn.wustlinghang.mywust.data.global.Course; -import cn.wustlinghang.mywust.data.global.Score; -import cn.wustlinghang.mywust.data.global.StudentInfo; -import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication; -import cn.wustlinghang.mywust.exception.ParseException; -import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException; -import cn.wustlinghang.wusthelper.rpc.exception.RpcException; -import jakarta.enterprise.context.ApplicationScoped; - -import java.util.List; - -@ApplicationScoped -public class ParseService { - private final UndergradCourseTableParser courseTableParser; - private final UndergradScoreParser scoreParser; - private final UndergradStudentInfoPageParser studentInfoPageParser; - private final UndergradTrainingPlanPageParser trainingPlanPageParser; - private final UndergradCreditStatusParser creditStatusParser; - private final UndergradExamDelayParser examDelayParser; - - public ParseService(UndergradCourseTableParser courseTableParser, - UndergradScoreParser scoreParser, - UndergradStudentInfoPageParser studentInfoPageParser, - UndergradTrainingPlanPageParser trainingPlanPageParser, - UndergradCreditStatusParser creditStatusParser, - UndergradExamDelayParser examDelayParser) { - - this.courseTableParser = courseTableParser; - this.scoreParser = scoreParser; - this.studentInfoPageParser = studentInfoPageParser; - this.trainingPlanPageParser = trainingPlanPageParser; - this.creditStatusParser = creditStatusParser; - this.examDelayParser = examDelayParser; - } - - public List parseCourseTable(String data) throws UndergradRpcException { - try { - if (data.contains("评教")) { - throw new UndergradRpcException( - UndergradRpcException.TypeCode.PARSE_EXCEPTION, - UndergradRpcException.SubModuleCode.COURSE_TABLE, - UndergradRpcException.ErrorCode.NEED_EVALUATE - ); - } - - return courseTableParser.parse(data); - - } catch (UndergradRpcException e) { - throw e; - } catch (Exception e) { - throw new UndergradRpcException( - UndergradRpcException.TypeCode.PARSE_EXCEPTION, - UndergradRpcException.SubModuleCode.COURSE_TABLE, - UndergradRpcException.ErrorCode.PARSE_ERROR - ); - } - } - - public List parseScore(String data) throws RpcException { - try { - if (data.contains("评教")) { - throw new UndergradRpcException( - UndergradRpcException.TypeCode.PARSE_EXCEPTION, - UndergradRpcException.SubModuleCode.SCORE, - UndergradRpcException.ErrorCode.NEED_EVALUATE - ); - } - - return scoreParser.parse(data); - - } catch (UndergradRpcException e) { - throw e; - } catch (Exception e) { - throw new UndergradRpcException( - UndergradRpcException.TypeCode.PARSE_EXCEPTION, - UndergradRpcException.SubModuleCode.SCORE, - UndergradRpcException.ErrorCode.PARSE_ERROR - ); - } - } - - public StudentInfo parseStudentInfo(String data) throws RpcException { - try { - return studentInfoPageParser.parse(data); - } catch (Exception e) { - throw new UndergradRpcException( - UndergradRpcException.TypeCode.PARSE_EXCEPTION, - UndergradRpcException.SubModuleCode.STUDENT_INFO, - UndergradRpcException.ErrorCode.PARSE_ERROR - ); - } - } - - public String parseTrainingPlan(String data) throws RpcException { - try { - return trainingPlanPageParser.parse(data); - } catch (Exception e) { - throw new UndergradRpcException( - UndergradRpcException.TypeCode.PARSE_EXCEPTION, - UndergradRpcException.SubModuleCode.TRAINING_PLAN, - UndergradRpcException.ErrorCode.PARSE_ERROR - ); - } - } - - public String parseCreditStatus(String data) throws RpcException { - try { - return creditStatusParser.parse(data); - } catch (Exception e) { - throw new UndergradRpcException( - UndergradRpcException.TypeCode.PARSE_EXCEPTION, - UndergradRpcException.SubModuleCode.CREDIT_STATUS, - UndergradRpcException.ErrorCode.PARSE_ERROR - ); - } - } - - public List parseExamDelayApplications(String data) throws RpcException { - try { - return examDelayParser.parse(data); - } catch (Exception e) { - throw new UndergradRpcException( - UndergradRpcException.TypeCode.PARSE_EXCEPTION, - UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION, - UndergradRpcException.ErrorCode.PARSE_ERROR - ); - } - } -} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/RequestAgentService.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/RequestAgentService.java deleted file mode 100644 index e608b5e..0000000 --- a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/RequestAgentService.java +++ /dev/null @@ -1,166 +0,0 @@ -package cn.wustlinghang.wusthelper.internal.undergrad.services; - -import cn.wustlinghang.mywust.core.request.service.undergraduate.*; -import cn.wustlinghang.mywust.exception.ApiException; -import cn.wustlinghang.mywust.network.RequestClientOption; -import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException; -import cn.wustlinghang.wusthelper.rpc.exception.RpcException; -import jakarta.enterprise.context.ApplicationScoped; -import lombok.extern.slf4j.Slf4j; - -import java.io.IOException; - -@Slf4j -@ApplicationScoped -public class RequestAgentService { - private final UndergradCourseTableApiService courseTableApiService; - private final UndergradScoreApiService scoreApiService; - private final UndergradStudentInfoApiService studentInfoApiService; - private final UndergradTrainingPlanApiService trainingPlanApiService; - private final UndergradCreditStatusApiService creditStatusApiService; - private final UndergradExamDelayApiService examDelayApiService; - - private final RequestClientOption requestClientOption; - - public RequestAgentService(UndergradCourseTableApiService courseTableApiService, - UndergradScoreApiService scoreApiService, - UndergradStudentInfoApiService studentInfoApiService, - UndergradTrainingPlanApiService trainingPlanApiService, - UndergradCreditStatusApiService creditStatusApiService, - UndergradExamDelayApiService examDelayApiService, - RequestClientOption requestClientOption) { - - this.courseTableApiService = courseTableApiService; - this.scoreApiService = scoreApiService; - this.studentInfoApiService = studentInfoApiService; - this.trainingPlanApiService = trainingPlanApiService; - this.creditStatusApiService = creditStatusApiService; - this.examDelayApiService = examDelayApiService; - - this.requestClientOption = requestClientOption; - } - - public String getStudentInfoPage(String cookie) throws RpcException { - try { - return studentInfoApiService.getPage(cookie); - } catch (ApiException e) { - throw wrapApiException(e, UndergradRpcException.SubModuleCode.STUDENT_INFO); - } catch (IOException e) { - throw new UndergradRpcException( - UndergradRpcException.TypeCode.NETWORK_EXCEPTION, - UndergradRpcException.SubModuleCode.STUDENT_INFO, - UndergradRpcException.ErrorCode.NETWORK_ERROR - ); - } - } - - public String getCourseTable(String cookie, String term) throws RpcException { - try { - return courseTableApiService.getPage(term, cookie); - } catch (ApiException e) { - throw wrapApiException(e, UndergradRpcException.SubModuleCode.COURSE_TABLE); - } catch (IOException e) { - throw new UndergradRpcException( - UndergradRpcException.TypeCode.NETWORK_EXCEPTION, - UndergradRpcException.SubModuleCode.COURSE_TABLE, - UndergradRpcException.ErrorCode.NETWORK_ERROR - ); - } - } - - public String getScore(String cookie) throws RpcException { - try { - return scoreApiService.getPage(cookie); - } catch (ApiException e) { - throw wrapApiException(e, UndergradRpcException.SubModuleCode.SCORE); - } catch (IOException e) { - throw new UndergradRpcException( - UndergradRpcException.TypeCode.NETWORK_EXCEPTION, - UndergradRpcException.SubModuleCode.SCORE, - UndergradRpcException.ErrorCode.NETWORK_ERROR - ); - } - } - - public String getTrainingPlan(String cookie) throws RpcException { - try { - return trainingPlanApiService.getPage(cookie); - } catch (ApiException e) { - throw wrapApiException(e, UndergradRpcException.SubModuleCode.TRAINING_PLAN); - } catch (IOException e) { - throw new UndergradRpcException( - UndergradRpcException.TypeCode.NETWORK_EXCEPTION, - UndergradRpcException.SubModuleCode.TRAINING_PLAN, - UndergradRpcException.ErrorCode.NETWORK_ERROR - ); - } - } - - public String getCreditStatus(String cookie) throws RpcException { - try { - return creditStatusApiService.getPage(cookie, requestClientOption, false); - } catch (ApiException e) { - throw wrapApiException(e, UndergradRpcException.SubModuleCode.CREDIT_STATUS); - } catch (IOException e) { - throw new UndergradRpcException( - UndergradRpcException.TypeCode.NETWORK_EXCEPTION, - UndergradRpcException.SubModuleCode.CREDIT_STATUS, - UndergradRpcException.ErrorCode.NETWORK_ERROR - ); - } - } - - public UndergradExamDelayApiService.ExamActivity[] getExamActivities(String cookie, String term) - throws RpcException { - try { - return examDelayApiService.getActivities(term, cookie); - } catch (ApiException e) { - throw wrapApiException(e, UndergradRpcException.SubModuleCode.EXAM_ACTIVITIES); - } catch (IOException e) { - throw new UndergradRpcException( - UndergradRpcException.TypeCode.NETWORK_EXCEPTION, - UndergradRpcException.SubModuleCode.EXAM_ACTIVITIES, - UndergradRpcException.ErrorCode.NETWORK_ERROR - ); - } - } - - public String getExamDelayApplications(String cookie, String term, String activityId) - throws RpcException { - try { - return examDelayApiService.getPage(term, activityId, cookie); - } catch (ApiException e) { - throw wrapApiException(e, UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION); - } catch (IOException e) { - throw new UndergradRpcException( - UndergradRpcException.TypeCode.NETWORK_EXCEPTION, - UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION, - UndergradRpcException.ErrorCode.NETWORK_ERROR - ); - } - } - - private UndergradRpcException wrapApiException(ApiException e, UndergradRpcException.SubModuleCode subModuleCode) { - return switch (e.getCode()) { - case NETWORK_EXCEPTION -> new UndergradRpcException( - UndergradRpcException.TypeCode.NETWORK_EXCEPTION, - subModuleCode, - UndergradRpcException.ErrorCode.NETWORK_ERROR - ); - case COOKIE_INVALID -> new UndergradRpcException( - UndergradRpcException.TypeCode.AUTH_EXCEPTION, - subModuleCode, - UndergradRpcException.ErrorCode.COOKIE_INVALID - ); - default -> { - log.error("本科生:{}代理请求异常,异常未处理", subModuleCode.name()); - log.error("异常:", e); - yield new UndergradRpcException( - UndergradRpcException.TypeCode.AUTH_EXCEPTION, - subModuleCode, - UndergradRpcException.ErrorCode.COOKIE_INVALID - ); - } - }; - } -} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ScoreService.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ScoreService.java new file mode 100644 index 0000000..3c4d641 --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ScoreService.java @@ -0,0 +1,58 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.services; + +import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradScoreParser; +import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradScoreApiService; +import cn.wustlinghang.mywust.data.global.Score; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException; +import cn.wustlinghang.wusthelper.rpc.exception.RpcException; +import jakarta.enterprise.context.ApplicationScoped; + +import java.io.IOException; +import java.util.List; + +@ApplicationScoped +public class ScoreService extends BaseService { + private final UndergradScoreApiService scoreApiService; + private final UndergradScoreParser scoreParser; + + public ScoreService(UndergradScoreApiService scoreApiService, + UndergradScoreParser scoreParser) { + this.scoreApiService = scoreApiService; + this.scoreParser = scoreParser; + } + + public String getScore(String cookie) throws RpcException { + try { + return scoreApiService.getPage(cookie); + } catch (ApiException e) { + throw wrapApiException(e, UndergradRpcException.SubModuleCode.SCORE); + } catch (IOException e) { + throw new UndergradRpcException( + UndergradRpcException.TypeCode.NETWORK_EXCEPTION, + UndergradRpcException.SubModuleCode.SCORE, + UndergradRpcException.ErrorCode.NETWORK_ERROR + ); + } + } + + public List parseScore(String data) throws RpcException { + try { + if (data.contains("评教")) { + throw new UndergradRpcException( + UndergradRpcException.TypeCode.PARSE_EXCEPTION, + UndergradRpcException.SubModuleCode.SCORE, + UndergradRpcException.ErrorCode.NEED_EVALUATE + ); + } + + return scoreParser.parse(data); + } catch (Exception e) { + throw new UndergradRpcException( + UndergradRpcException.TypeCode.PARSE_EXCEPTION, + UndergradRpcException.SubModuleCode.SCORE, + UndergradRpcException.ErrorCode.PARSE_ERROR + ); + } + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/StudentInfoService.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/StudentInfoService.java new file mode 100644 index 0000000..83330b5 --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/StudentInfoService.java @@ -0,0 +1,49 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.services; + +import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradStudentInfoPageParser; +import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradStudentInfoApiService; +import cn.wustlinghang.mywust.data.global.StudentInfo; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException; +import cn.wustlinghang.wusthelper.rpc.exception.RpcException; +import jakarta.enterprise.context.ApplicationScoped; + +import java.io.IOException; + +@ApplicationScoped +public class StudentInfoService extends BaseService { + private final UndergradStudentInfoApiService studentInfoApiService; + private final UndergradStudentInfoPageParser studentInfoPageParser; + + public StudentInfoService(UndergradStudentInfoApiService studentInfoApiService, + UndergradStudentInfoPageParser studentInfoPageParser) { + this.studentInfoApiService = studentInfoApiService; + this.studentInfoPageParser = studentInfoPageParser; + } + + public String getStudentInfoPage(String cookie) throws RpcException { + try { + return studentInfoApiService.getPage(cookie); + } catch (ApiException e) { + throw wrapApiException(e, UndergradRpcException.SubModuleCode.STUDENT_INFO); + } catch (IOException e) { + throw new UndergradRpcException( + UndergradRpcException.TypeCode.NETWORK_EXCEPTION, + UndergradRpcException.SubModuleCode.STUDENT_INFO, + UndergradRpcException.ErrorCode.NETWORK_ERROR + ); + } + } + + public StudentInfo parseStudentInfo(String data) throws RpcException { + try { + return studentInfoPageParser.parse(data); + } catch (Exception e) { + throw new UndergradRpcException( + UndergradRpcException.TypeCode.PARSE_EXCEPTION, + UndergradRpcException.SubModuleCode.STUDENT_INFO, + UndergradRpcException.ErrorCode.PARSE_ERROR + ); + } + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/TrainingPlanService.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/TrainingPlanService.java new file mode 100644 index 0000000..be2a1b5 --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/TrainingPlanService.java @@ -0,0 +1,48 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.services; + +import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradTrainingPlanPageParser; +import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradTrainingPlanApiService; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException; +import cn.wustlinghang.wusthelper.rpc.exception.RpcException; +import jakarta.enterprise.context.ApplicationScoped; + +import java.io.IOException; + +@ApplicationScoped +public class TrainingPlanService extends BaseService { + private final UndergradTrainingPlanApiService trainingPlanApiService; + private final UndergradTrainingPlanPageParser trainingPlanPageParser; + + public TrainingPlanService(UndergradTrainingPlanApiService trainingPlanApiService, + UndergradTrainingPlanPageParser trainingPlanPageParser) { + this.trainingPlanApiService = trainingPlanApiService; + this.trainingPlanPageParser = trainingPlanPageParser; + } + + public String getTrainingPlan(String cookie) throws RpcException { + try { + return trainingPlanApiService.getPage(cookie); + } catch (ApiException e) { + throw wrapApiException(e, UndergradRpcException.SubModuleCode.TRAINING_PLAN); + } catch (IOException e) { + throw new UndergradRpcException( + UndergradRpcException.TypeCode.NETWORK_EXCEPTION, + UndergradRpcException.SubModuleCode.TRAINING_PLAN, + UndergradRpcException.ErrorCode.NETWORK_ERROR + ); + } + } + + public String parseTrainingPlan(String data) throws RpcException { + try { + return trainingPlanPageParser.parse(data); + } catch (Exception e) { + throw new UndergradRpcException( + UndergradRpcException.TypeCode.PARSE_EXCEPTION, + UndergradRpcException.SubModuleCode.TRAINING_PLAN, + UndergradRpcException.ErrorCode.PARSE_ERROR + ); + } + } +}