更新外键
This commit is contained in:
+5
-8
@@ -83,10 +83,10 @@ def get_emp_dao( #获取学生
|
||||
# ,page_size
|
||||
): #根据选择条件获取信息
|
||||
q = db.query(Employments,Company.employment_company,Address.somewhere) \
|
||||
.outerjoin(Company, Students.id == Employments.stuid) \
|
||||
.outerjoin(Company, ClassInfo.id == Employments.class_id)\
|
||||
.outerjoin(Students, Students.id == Employments.stuid) \
|
||||
.outerjoin(ClassInfo, ClassInfo.id == Employments.class_id)\
|
||||
.outerjoin(Company,Employments.company_id==Company.id)\
|
||||
.outerjoin(Address,Company.address_id==Address.id)\
|
||||
.outerjoin(Address,Employments.address_id==Address.id)\
|
||||
.filter(Employments.is_deleted == 0) #连接公司表和地址表,筛选未被删除信息
|
||||
# if stuid:
|
||||
# q = q.filter( Employments.id == stuid )
|
||||
@@ -99,7 +99,6 @@ def get_emp_dao( #获取学生
|
||||
q = q.filter(Address.somewhere.like(f'%{somewhere}%'))
|
||||
if employment_company: #根据公司姓名筛选
|
||||
q=q.filter(Company.employment_company.like(f'%{employment_company}%'))
|
||||
# r = q.offset( (page-1)*page_size ).limit( page_size ).all()
|
||||
if min_salary is not None: #根据最小薪资筛选
|
||||
q = q.filter(Employments.employment_salary >= min_salary)
|
||||
if max_salary is not None: ##根据最大薪资筛选
|
||||
@@ -116,13 +115,11 @@ def get_emp_dao( #获取学生
|
||||
r= q.all()
|
||||
if r:
|
||||
return [ {"id": i.id,
|
||||
'学生姓名':i.sname,
|
||||
'学生班级编号':i.class_id,
|
||||
'学生姓名':sname,
|
||||
'学生班级编号':class_id,
|
||||
"公司": employment_company or '未就业',
|
||||
"公司区域":somewhere or '-',
|
||||
# "company_id": i.company_id,
|
||||
"薪资":i.employment_salary or '-',
|
||||
# "address_id": i.address_id,
|
||||
"就业开放时间":i.employment_open_time.strftime('%Y-%m-%d') ,
|
||||
"offer下发时间":i.offer_recived_time.strftime('%Y-%m-%d')
|
||||
# , "创建时间": i.create_time,
|
||||
|
||||
+7
-7
@@ -19,12 +19,14 @@ class Employments(Base_all): #学生
|
||||
class_id = Column(Integer
|
||||
, ForeignKey('classes.id')
|
||||
) #学生班级,冗余字段
|
||||
company_id = Column(Integer #公司id,外键匹配公司表
|
||||
company_id = Column(Integer # 公司id,外键匹配公司表
|
||||
, ForeignKey('Company.id')
|
||||
, nullable=True
|
||||
|
||||
)
|
||||
|
||||
address_id = Column(Integer # 地址id,匹配地址表
|
||||
, ForeignKey('Address.id') # 外键地址表id
|
||||
, nullable=False # 非空约束
|
||||
)
|
||||
employment_salary = Column(Integer, nullable=True) #薪资
|
||||
|
||||
employment_open_time = Column(DATE, nullable=True) #就业开放时间
|
||||
@@ -49,10 +51,7 @@ class Company(Base_all): #公司
|
||||
employment_company = Column(String(50) #公司姓名
|
||||
, nullable=False #非空约束
|
||||
)
|
||||
address_id = Column(Integer #地址id,匹配地址表
|
||||
, ForeignKey('Address.id') #外键地址表id
|
||||
, nullable=False #非空约束
|
||||
)
|
||||
|
||||
create_time = Column(DATETIME
|
||||
, default=datetime.now
|
||||
)
|
||||
@@ -71,6 +70,7 @@ class Address(Base_all):
|
||||
somewhere=Column(String(50) #地址区域
|
||||
, nullable=False
|
||||
)
|
||||
|
||||
create_time = Column(DATETIME
|
||||
, default=datetime.now
|
||||
)
|
||||
|
||||
@@ -4,10 +4,10 @@ from pydantic import BaseModel
|
||||
|
||||
class PostRequest(BaseModel): #学生就业信息请求体模型
|
||||
# compname: str|None=None
|
||||
sname: str|None=None
|
||||
stuid: int|None=None
|
||||
class_id: int|None=None
|
||||
company_id:int|None=None
|
||||
# address_id: int|None=None
|
||||
address_id: int|None=None
|
||||
employment_salary: int|None=None
|
||||
employment_open_time:date|None=None
|
||||
offer_recived_time:date|None=None
|
||||
@@ -21,7 +21,7 @@ class EmpResponse(BaseModel): #学生就
|
||||
|
||||
class CompRequest(BaseModel): #公司信息请求体模型
|
||||
employment_company:str
|
||||
address_id: int
|
||||
# address_id: int
|
||||
|
||||
class CompResponse(BaseModel): #公司信息响应体
|
||||
code: int = 200
|
||||
|
||||
Reference in New Issue
Block a user