Merge remote-tracking branch 'origin/coffee_all' into lon_students_merge_code_test
# Conflicts: # stu_jiuye/database.py # stu_jiuye/main.py
This commit is contained in:
+16
-12
@@ -1,6 +1,6 @@
|
||||
import datetime
|
||||
|
||||
from fastapi import APIRouter,Depends,HTTPException
|
||||
from fastapi import APIRouter,Depends,HTTPException,Query
|
||||
from stu_jiuye.dao import *
|
||||
from stu_jiuye.request import PostRequest, EmpResponse, AddRequest,AddResponse,CompRequest,CompResponse
|
||||
from stu_jiuye.database import get_db
|
||||
@@ -9,14 +9,16 @@ CURD=APIRouter()
|
||||
|
||||
@CURD.get('/emp',summary='查询就业信息')
|
||||
def get_stuinfo( #查询学生就业信息
|
||||
sname:str| None = None
|
||||
,class_num:int| None = None
|
||||
,employment_company:str|None=None
|
||||
,min_salary:int=0
|
||||
,max_salary:int|None=None
|
||||
,somewhere:str|None=None
|
||||
,employment_open_time:datetime.date|None=None
|
||||
,offer_recived_time:datetime.date|None=None
|
||||
sname:str| None = Query(None,description='学生姓名')
|
||||
,class_num:int| None = Query(None,description='班级编号')
|
||||
,employment_company:str|None=Query(None,description='公司名称')
|
||||
,min_salary:int|None=Query(None,description='最小薪资范围')
|
||||
,max_salary:int|None=Query(None,description='最大薪资范围')
|
||||
,somewhere:str|None=Query(None,description='公司地区')
|
||||
,employment_open_start: datetime.date | None = Query(None,description='就业开放起始时间')
|
||||
,employment_open_end: datetime.date | None = Query(None,description='就业开放结束时间')
|
||||
,offer_recived_start: datetime.date | None = Query(None,description='offer下发起始时间')
|
||||
,offer_recived_end: datetime.date | None = Query(None,description='offer下发结束时间')
|
||||
,db=Depends(get_db)
|
||||
): #查询条件
|
||||
r=get_emp_dao( #调用函数
|
||||
@@ -26,8 +28,10 @@ def get_stuinfo( #查询学生就业信息
|
||||
min_salary,
|
||||
max_salary,
|
||||
somewhere,
|
||||
employment_open_time,
|
||||
offer_recived_time,
|
||||
employment_open_start,
|
||||
employment_open_end,
|
||||
offer_recived_start,
|
||||
offer_recived_end,
|
||||
db
|
||||
)
|
||||
if r:
|
||||
@@ -75,9 +79,9 @@ def updata_stuinfo( #更新数据模块
|
||||
d = up.model_dump(exclude_unset=True) #解析
|
||||
d.pop('create_time', None)
|
||||
d.pop('is_deleted', None)
|
||||
r = update_emp_dao(id=id, update_data=d, db=db) #调用更新函数
|
||||
if not d:
|
||||
raise HTTPException(status_code=400, detail='没有需要更新的字段')
|
||||
r = update_emp_dao(id=id, update_data=d, db=db) #调用更新函数
|
||||
if not r:
|
||||
raise HTTPException(status_code=404, detail='未找到对应记录') #失败返回错误信息
|
||||
return {'code': 200, 'totals': r, 'detail': '更新成功'} #成功返回信息
|
||||
|
||||
+19
-11
@@ -73,8 +73,10 @@ def get_emp_dao( #获取学生
|
||||
,min_salary
|
||||
,max_salary
|
||||
,somewhere
|
||||
,employment_open_time
|
||||
,offer_recived_time
|
||||
,employment_open_start
|
||||
,employment_open_end
|
||||
,offer_recived_start
|
||||
,offer_recived_end
|
||||
,db
|
||||
|
||||
# ,page
|
||||
@@ -100,10 +102,15 @@ def get_emp_dao( #获取学生
|
||||
q = q.filter(Employments.employment_salary >= min_salary)
|
||||
if max_salary is not None: ##根据最大薪资筛选
|
||||
q = q.filter(Employments.employment_salary <= max_salary)
|
||||
if employment_open_time:
|
||||
q = q.filter(Employments.employment_open_time == employment_open_time)
|
||||
if offer_recived_time:
|
||||
q = q.filter(Employments.offer_recived_time == offer_recived_time)
|
||||
if employment_open_start:
|
||||
q = q.filter(Employments.employment_open_time >= employment_open_start)
|
||||
if employment_open_end:
|
||||
q = q.filter(Employments.employment_open_time <= employment_open_end)
|
||||
if offer_recived_start:
|
||||
q = q.filter(Employments.offer_recived_time >= offer_recived_start)
|
||||
if offer_recived_end:
|
||||
q = q.filter(Employments.offer_recived_time <= offer_recived_end)
|
||||
|
||||
r= q.all()
|
||||
if r:
|
||||
return [ {"id": i.id,
|
||||
@@ -114,11 +121,12 @@ def get_emp_dao( #获取学生
|
||||
# "company_id": i.company_id,
|
||||
"薪资":i.employment_salary or '-',
|
||||
# "address_id": i.address_id,
|
||||
"就业开放时间":i.employment_open_time,
|
||||
"offer下发时间":i.offer_recived_time or '-',
|
||||
"创建时间": i.create_time,
|
||||
"更新时间": i.update_time,
|
||||
"是否删除":i.is_deleted } for i,employment_company,somewhere in r ] #返回信息列表
|
||||
"就业开放时间":i.employment_open_time.strftime('%Y-%m-%d') ,
|
||||
"offer下发时间":i.offer_recived_time.strftime('%Y-%m-%d')
|
||||
# , "创建时间": i.create_time,
|
||||
# "更新时间": i.update_time,
|
||||
# "是否删除":i.is_deleted
|
||||
} for i,employment_company,somewhere in r ] #返回信息列表
|
||||
|
||||
|
||||
def delete_emp_dao(id,db): #删除函数
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
# from sqlalchemy import *
|
||||
# from sqlalchemy.orm import declarative_base,sessionmaker
|
||||
#
|
||||
# db_url = "mysql+pymysql://root:123456@127.0.0.1:3306/ai0824_001?charset=utf8mb4"
|
||||
# # db_url = "mysql+pymysql://root:420821@localhost:3306/student_manage_system?charset=utf8mb4"
|
||||
|
||||
from sqlalchemy import *
|
||||
from sqlalchemy.orm import declarative_base,sessionmaker
|
||||
|
||||
@@ -12,6 +18,7 @@ DB_PORT = os.getenv("DB_PORT", "3306")
|
||||
DB_NAME = os.getenv("DB_NAME", "student_manage_system")
|
||||
|
||||
db_url = f"mysql+pymysql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}?charset=utf8mb4"
|
||||
|
||||
engine = create_engine(db_url
|
||||
, pool_size=50
|
||||
, echo=True
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
from fastapi import FastAPI,APIRouter
|
||||
from stu_jiuye.CURD_api import CURD
|
||||
from stu_jiuye.database import Base,engine
|
||||
import stu_jiuye.model
|
||||
|
||||
# 合并接口
|
||||
Shtudent_Jiuye = APIRouter()
|
||||
Shtudent_Jiuye.include_router(CURD)
|
||||
|
||||
# 自测接口
|
||||
|
||||
|
||||
app=FastAPI()
|
||||
Base.metadata.create_all(engine)
|
||||
app.include_router(CURD,tags=['就业管理系统'])
|
||||
|
||||
+10
-31
@@ -5,31 +5,6 @@ from stu_jiuye.database import DATETIME,Base,Column,Integer,String,DATE
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
# class Student(Base):
|
||||
# __tablename__ = 'Student'
|
||||
# id = Column(Integer
|
||||
# , primary_key=True
|
||||
# , autoincrement=True
|
||||
# # 外键
|
||||
# ,comment='自增主键'
|
||||
# )
|
||||
# stuname = Column(String(50)
|
||||
# ,nullable=False
|
||||
# )
|
||||
# stuid=Column(Integer
|
||||
# ,nullable=False
|
||||
# )
|
||||
# stuclass=Column(String(50)
|
||||
# ,nullable=False
|
||||
# )
|
||||
# created_date = Column(DATETIME
|
||||
# ,default=datetime.now
|
||||
# )
|
||||
# updated_date = Column(DATETIME
|
||||
# ,default=datetime.now
|
||||
# ,onupdate=datetime.now
|
||||
# )
|
||||
|
||||
|
||||
class Employments(Base_all): #学生就业信息基类
|
||||
__tablename__ = 'Employments' #表名
|
||||
@@ -39,8 +14,12 @@ class Employments(Base_all): #学生
|
||||
# , ForeignKey('student.id')
|
||||
, comment='自增主键'
|
||||
)
|
||||
sname = Column(String(50)) #学生姓名,冗余字段
|
||||
class_num = Column(Integer) #学生班级,冗余字段
|
||||
sname = Column(String(50)
|
||||
# , ForeignKey='student.name'
|
||||
) #学生姓名,冗余字段
|
||||
class_num = Column(Integer
|
||||
# , ForeignKey='class.id'
|
||||
) #学生班级,冗余字段
|
||||
|
||||
# compname=Column(String(50)
|
||||
# ,nullable=False
|
||||
@@ -82,10 +61,10 @@ class Company(Base_all): #公司
|
||||
, ForeignKey('Address.id') #外键地址表id
|
||||
, nullable=False #非空约束
|
||||
)
|
||||
created_date = Column(DATETIME
|
||||
create_time = Column(DATETIME
|
||||
, default=datetime.now
|
||||
)
|
||||
updated_date = Column(DATETIME
|
||||
update_time = Column(DATETIME
|
||||
, default=datetime.now
|
||||
, onupdate=datetime.now
|
||||
)
|
||||
@@ -100,10 +79,10 @@ class Address(Base_all):
|
||||
somewhere=Column(String(50) #地址区域
|
||||
, nullable=False
|
||||
)
|
||||
created_date = Column(DATETIME
|
||||
create_time = Column(DATETIME
|
||||
, default=datetime.now
|
||||
)
|
||||
updated_date = Column(DATETIME
|
||||
update_time = Column(DATETIME
|
||||
, default=datetime.now
|
||||
, onupdate=datetime.now
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user