Skip to content

Commit

Permalink
Merge pull request #55 from Rockytkg:feature/teacher
Browse files Browse the repository at this point in the history
fast: 支持教师端打卡
  • Loading branch information
Rockytkg authored Jan 3, 2025
2 parents 6f99f3d + 810d263 commit ba3158b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
29 changes: 18 additions & 11 deletions coreApi/MainLogicApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ def get_checkin_info(self) -> Dict[str, Any]:
ValueError: 如果获取打卡信息失败,抛出包含详细错误信息的异常。
"""
url = "attendence/clock/v2/listSynchro"
if self.config.get_value("userInfo.userType") == "teacher":
url = "attendence/clock/teacher/v1/listSynchro"
headers = self._get_authenticated_headers()
data = {
**get_current_month_info(),
Expand All @@ -407,7 +409,20 @@ def submit_clock_in(self, checkin_info: Dict[str, Any]) -> None:
Raises:
ValueError: 如果打卡提交失败,抛出包含详细错误信息的异常。
"""
url = "attendence/clock/v5/save"
url = "attendence/clock/teacher/v2/save"
sign_data = None
planId = self.config.get_value("planInfo.planId")

if self.config.get_value("userInfo.userType") != "teacher":
url = "attendence/clock/v5/save"
sign_data = [
self.config.get_value("config.device"),
checkin_info.get("type"),
planId,
self.config.get_value("userInfo.userId"),
self.config.get_value("config.clockIn.location.address"),
]

logger.info(f'打卡类型:{checkin_info.get("type")}')

data = {
Expand All @@ -432,7 +447,7 @@ def submit_clock_in(self, checkin_info: Dict[str, Any]) -> None:
"teacherNumber": None,
"type": checkin_info.get("type"),
"stuId": None,
"planId": self.config.get_value("planInfo.planId"),
"planId": planId,
"attendanceType": None,
"username": None,
"attachments": checkin_info.get("attachments", None),
Expand All @@ -456,15 +471,7 @@ def submit_clock_in(self, checkin_info: Dict[str, Any]) -> None:

data.update(self.config.get_value("config.clockIn.location"))

headers = self._get_authenticated_headers(
sign_data=[
self.config.get_value("config.device"),
checkin_info.get("type"),
self.config.get_value("planInfo.planId"),
self.config.get_value("userInfo.userId"),
self.config.get_value("config.clockIn.location.address"),
]
)
headers = self._get_authenticated_headers(sign_data)

self._post_request(url, headers, data, "打卡失败")

Expand Down
12 changes: 9 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,18 @@ def run(config: ConfigManager) -> None:

try:
api_client = ApiClient(config)
# 检查是否登录
if not config.get_value("userInfo.token"):
api_client.login()
if not config.get_value("planInfo.planId"):

logger.info("获取用户信息成功")
# 检查用户类型和计划信息
if config.get_value("userInfo.userType") == "teacher":
logger.info("用户身份为教师,跳过计划信息检查")
elif not config.get_value("planInfo.planId"):
api_client.fetch_internship_plan()
else:
logger.info("使用本地数据")
logger.info("已获取实习计划信息")

except Exception as e:
error_message = f"获取API客户端失败: {str(e)}"
logger.error(error_message)
Expand Down

0 comments on commit ba3158b

Please sign in to comment.