From ca69c8a86aadc50483675239ca3b0779a7a81b8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=80=C3=AE=C3=97=C3=9A=C3=95=C3=B1?= Date: Fri, 26 Aug 2022 17:17:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=A5=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/api_v1/endpoints/interview.py | 22 ++++++++++++++++++++++ crud/__init__.py | 1 + crud/crud_interview_tables.py | 28 ++++++++++++++++++++++++++++ schemas/__init__.py | 1 + schemas/interview_modes.py | 3 +-- schemas/interview_tables.py | 30 ++++++++++++++++++++++++++++++ 6 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 crud/crud_interview_tables.py create mode 100644 schemas/interview_tables.py diff --git a/api/api_v1/endpoints/interview.py b/api/api_v1/endpoints/interview.py index b432722..fb69970 100644 --- a/api/api_v1/endpoints/interview.py +++ b/api/api_v1/endpoints/interview.py @@ -848,6 +848,28 @@ async def add_mode( return schemas.Msg(code=200, msg='ok', data='') +@router.post("/add_table") +async def add_table( + request: Request, + data_in: schemas.InsertTables, + db: AsyncIOMotorDatabase = Depends(get_database), +) -> schemas.Msg: + """添加分组报表""" + await crud.api_interview_tables.insert_modes(db, data_in) + return schemas.Msg(code=200, msg='ok', data='') + + +@router.post("/update_table") +async def update_table( + request: Request, + data_in: schemas.UpdateTables, + db: AsyncIOMotorDatabase = Depends(get_database), +) -> schemas.Msg: + """修改表报""" + await crud.api_interview_tables.insert_modes(db, data_in) + return schemas.Msg(code=200, msg='ok', data='') + + @router.post("/find_mode") async def find_mode( request: Request, diff --git a/crud/__init__.py b/crud/__init__.py index f74cdda..cd445a5 100644 --- a/crud/__init__.py +++ b/crud/__init__.py @@ -24,6 +24,7 @@ from .crud_event_list import event_list from .crud_jobs import jobs from .crud_interview_remark import api_interview_remark from .crud_interview_modes import api_interview_modes +from .crud_interview_tables import api_interview_tables from .crud_email_record import email_record from .crud_operate_log import operate_log from .crud_interview_record import interview_record diff --git a/crud/crud_interview_tables.py b/crud/crud_interview_tables.py new file mode 100644 index 0000000..0b8d0b2 --- /dev/null +++ b/crud/crud_interview_tables.py @@ -0,0 +1,28 @@ +from motor.motor_asyncio import AsyncIOMotorDatabase +import schemas +from crud.base import CRUDBase + +__all__ = 'api_interview_tables', + + +class ApiInterviewModes(CRUDBase): + + # 获取分组所有报表 + async def get_interview_modes(self, db: AsyncIOMotorDatabase, data_in: schemas.FindTables): + where = data_in.where + where.update({'mode_id': data_in.mode_id}) + return await self.find_many(db, where, {'_id': 0}) + + # 插入一条全新的分组 + async def insert_tables(self, db: AsyncIOMotorDatabase, data_in: schemas.InsertTables): + data = {k: v for k, v in data_in.dict().items() if k != 'table_data'} + insert_data = data_in.table_data + insert_data.update(data) + return await self.insert_one(db, insert_data) + + # 更新一条报表信息 + async def update_tables(self, db: AsyncIOMotorDatabase, data_in: schemas.UpdateTables): + return await self.update_one(db, {'table_id': data_in.table_id}, {'$set': data_in.update_data}) + + +api_interview_modes = ApiInterviewModes('interview_tables') diff --git a/schemas/__init__.py b/schemas/__init__.py index 1177dce..2ea487e 100644 --- a/schemas/__init__.py +++ b/schemas/__init__.py @@ -32,6 +32,7 @@ from .interview_remark import * from .email_record import * from .operate_log import * from .interview_modes import * +from .interview_tables import * from .interview_record import * from .worker import * from .owner_info import * diff --git a/schemas/interview_modes.py b/schemas/interview_modes.py index 87d79ae..5368fb1 100644 --- a/schemas/interview_modes.py +++ b/schemas/interview_modes.py @@ -15,8 +15,7 @@ class InsertModes(BaseModel): mode_name: str # 模版名称 hr_name: str # 模板所属hr名字 hr_uid: str # 模板所属hr的uid - mode_list: list = ['招聘职位', '流程中的申请', '完成招聘职位', '归档的申请', '招聘漏斗', '性别分布', '渠道质量', - '年龄分布', '招聘网站质量', '职位投录比'] # 分组包含的基础分析报表 + mode_list: list = [] # 分组包含的基础分析报表 mode_time: datetime = datetime.now() # 修改时间 diff --git a/schemas/interview_tables.py b/schemas/interview_tables.py new file mode 100644 index 0000000..753267f --- /dev/null +++ b/schemas/interview_tables.py @@ -0,0 +1,30 @@ +import time +import random +from datetime import datetime + +from pydantic import BaseModel + + +def get_id(): + return hex(int(time.time() * 10 ** 7) + random.randint(0, 10000))[2:] + + +# 报表分组模板 +class InsertTables(BaseModel): + table_id: str = get_id() # 报表唯一id + mode_id: str # 模版id + table_name: str # 报表名称 + table_data: dict = {} # 报表其他数据 + mode_time: datetime = datetime.now() # 修改时间 + + +# 查询报表 +class FindTables(BaseModel): + mode_id: str # 模板所属hr的uid + where: dict = {} # 其他条件 + + +# 更新报表 +class UpdateTables(BaseModel): + table_id: str # 模板唯一id + update_data: dict # 更新的数据