入职年份
This commit is contained in:
parent
df24abebf0
commit
8cb1391844
@ -107,3 +107,43 @@ async def update_worker(
|
||||
|
||||
data = await crud.worker_info.update_worker(db, data_in.worker_query, data_in.data_in)
|
||||
return schemas.Msg(code=200, msg='ok', data=data)
|
||||
|
||||
|
||||
# 添加统计数据
|
||||
@router.post("/add_count_info")
|
||||
async def add_count_info(
|
||||
request: Request,
|
||||
data_in: schemas.CountInWorkerQuery,
|
||||
db: AsyncIOMotorDatabase = Depends(get_database)
|
||||
) -> schemas.Msg:
|
||||
""" 增加一条统计数据 """
|
||||
count_id = data_in.count_id
|
||||
in_data = await crud.count_in_worker.find_one_count(db, count_id)
|
||||
# 本月数据已添加
|
||||
if in_data:
|
||||
return schemas.Msg(code=-10, msg='本月数据已添加', data=None)
|
||||
worker_data = await crud.worker_info.find_worker_some(db, findlist=['name', 'work_in'])
|
||||
insert_data = {
|
||||
'count_id': count_id
|
||||
}
|
||||
for chk_data in worker_data:
|
||||
worker_in = chk_data['work_in']
|
||||
key = str(datetime.strptime(worker_in, '%Y-%m-%d').year)
|
||||
if key not in insert_data:
|
||||
insert_data[key] = 1
|
||||
continue
|
||||
insert_data[key] += 1
|
||||
data = await crud.count_in_worker.insert_count_info(db, insert_data)
|
||||
return schemas.Msg(code=200, msg='ok', data=data)
|
||||
|
||||
|
||||
# 查询统计数据
|
||||
@router.post("/find_count_info")
|
||||
async def find_count_info(
|
||||
request: Request,
|
||||
db: AsyncIOMotorDatabase = Depends(get_database)
|
||||
) -> schemas.Msg:
|
||||
""" 查询所有统计数据 """
|
||||
|
||||
data = await crud.count_in_worker.find_count_some(db)
|
||||
return schemas.Msg(code=200, msg='ok', data=data)
|
||||
|
@ -29,3 +29,4 @@ from .crud_operate_log import operate_log
|
||||
from .crud_interview_record import interview_record
|
||||
from .crud_worker_info import worker_info
|
||||
from .crud_owner_info import owner_info
|
||||
from .crud_count_in_worker import count_in_worker
|
||||
|
33
crud/crud_count_in_worker.py
Normal file
33
crud/crud_count_in_worker.py
Normal file
@ -0,0 +1,33 @@
|
||||
from motor.motor_asyncio import AsyncIOMotorDatabase
|
||||
import schemas
|
||||
from crud.base import CRUDBase
|
||||
|
||||
__all__ = 'count_in_worker',
|
||||
|
||||
|
||||
class CRUDCountInWorker(CRUDBase):
|
||||
# 获取所有在职人员统计数据
|
||||
async def all_count_info(self, db: AsyncIOMotorDatabase):
|
||||
return await self.find_many(db, {}, {'_id': 0})
|
||||
|
||||
# 获取指定字段
|
||||
async def find_count_some(self, db: AsyncIOMotorDatabase, findlist=[]):
|
||||
findWhere = {'_id': 0}
|
||||
if findlist:
|
||||
for key in findlist:
|
||||
findWhere.update({
|
||||
key: 1
|
||||
})
|
||||
return await self.find_many(db, {}, findWhere)
|
||||
|
||||
# 查询单条数据
|
||||
async def find_one_count(self, db: AsyncIOMotorDatabase, count_id):
|
||||
return await self.find_one(db, {'count_id': count_id}, {'_id': 0})
|
||||
|
||||
# 插入一条新的在职人员统计数据
|
||||
async def insert_count_info(self, db: AsyncIOMotorDatabase, insertdata):
|
||||
|
||||
await self.insert_one(db, insertdata)
|
||||
|
||||
|
||||
count_in_worker = CRUDCountInWorker('count_in_worker')
|
@ -35,3 +35,4 @@ from .interview_modes import *
|
||||
from .interview_record import *
|
||||
from .worker import *
|
||||
from .owner_info import *
|
||||
from .count_in_worker import *
|
||||
|
12
schemas/count_in_worker.py
Normal file
12
schemas/count_in_worker.py
Normal file
@ -0,0 +1,12 @@
|
||||
from typing import Dict, List, Union, Any
|
||||
from pydantic import BaseModel
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def get_id():
|
||||
return datetime.strftime(datetime.now(), '%Y-%m')
|
||||
|
||||
|
||||
# 统计在职人员数据添加格式
|
||||
class CountInWorkerQuery(BaseModel):
|
||||
count_id: str = get_id()
|
45
接口文档/在职年份统计接口文档.txt
Normal file
45
接口文档/在职年份统计接口文档.txt
Normal file
@ -0,0 +1,45 @@
|
||||
路由: /api/v1/worker/add_count_info # 添加一条统计数据接口
|
||||
|
||||
参数: # 无
|
||||
{}
|
||||
|
||||
|
||||
返回值1:
|
||||
{
|
||||
"code": 200,
|
||||
"msg": "ok",
|
||||
"data": null
|
||||
}
|
||||
|
||||
返回值2:
|
||||
{
|
||||
"code": -10,
|
||||
"msg": "本月数据已添加",
|
||||
"data": null
|
||||
}
|
||||
|
||||
|
||||
|
||||
路由: /api/v1/worker/find_count_info # 查询统计数据接口
|
||||
|
||||
参数: # 无
|
||||
{}
|
||||
|
||||
|
||||
返回值:
|
||||
{
|
||||
"code": 200,
|
||||
"msg": "ok",
|
||||
"data": [
|
||||
{
|
||||
"2017": 1, # 入职年份对应人数
|
||||
"2021": 3, # 入职年份对应人数
|
||||
"count_id": "2022-07" # 统计日期 年月
|
||||
},
|
||||
{
|
||||
"2017": 1,
|
||||
"2021": 3,
|
||||
"count_id": "2022-06"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user