就业模块修改

This commit is contained in:
Corning Zhao
2026-09-14 12:12:29 +08:00
parent c392cd90e6
commit 71118806f1
4 changed files with 11 additions and 14 deletions
+2 -1
View File
@@ -16,7 +16,7 @@ def query_list(
skip: int = 0,
limit: int = 100,
company_name: Optional[str] = None,
db: Session = Depends(get_db),
db: Session = Depends(get_db)
):
return EmpDAO.list_emps(db, skip, limit, company_name)
@@ -54,3 +54,4 @@ def remove_emp(stu_no: str, db: Session = Depends(get_db)):
if not EmpDAO.delete_emp(db, stu_no):
raise HTTPException(status_code=404, detail="就业信息不存在")
return {"code": 200, "msg": "删除成功"}
+3 -9
View File
@@ -17,18 +17,14 @@ class EmpDAO:
@staticmethod
def list_emps(db: Session, skip: int = 0, limit: int = 100, company_name: str = None):
"""查询就业列表,顺带把学生姓名带上"""
"""查询就业列表"""
q = db.query(Emp).filter(Emp.is_deleted == 0)
if company_name:
q = q.filter(Emp.company_name.like(f"%{company_name}%"))
emp_list = q.offset(skip).limit(limit).all()
for e in emp_list:
stu = db.query(Student).filter(
Student.stu_no == e.stu_no,
Student.is_deleted == 0,
).first()
e.stu_name = stu.stu_name if stu else None
e.stu_name = e.student.stu_name
return emp_list
@staticmethod
@@ -38,9 +34,7 @@ class EmpDAO:
Emp.stu_no == stu_no,
Emp.is_deleted == 0,
).first()
if emp:
stu = EmpDAO.get_student(db, stu_no)
emp.stu_name = stu.stu_name if stu else None
emp.stu_name =emp.student.stu_name
return emp
@staticmethod
+4 -3
View File
@@ -1,4 +1,4 @@
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, func
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
from database import Base
@@ -9,8 +9,8 @@ class Emp(Base):
# 学号做主键,同时做外键指向学生表,长度跟 Student.stu_no 保持一致
stu_no = Column(String(20), ForeignKey('wl_student.stu_no'), primary_key=True)
emp_open_time = Column(DateTime, default="2026-11-30 18:18:18")
offer_time = Column(DateTime, default=func.now())
emp_open_time = Column(DateTime)
offer_time = Column(DateTime)
company_name = Column(String(100), nullable=False)
salary = Column(Integer, nullable=False, default=15000)
@@ -21,3 +21,4 @@ class Emp(Base):
def __repr__(self):
return f"<Emp(stu_no={self.stu_no}, company='{self.company_name}')>"
+2 -1
View File
@@ -8,7 +8,7 @@ class EmpCreate(BaseModel):
emp_open_time: Optional[datetime] = Field(None, description="不传用表默认值")
offer_time: Optional[datetime] = Field(None, description="不传用数据库当前时间")
company_name: str = Field(..., max_length=100, description="公司名称")
salary: Optional[int] = Field(None, description="不传用默认值 15000")
salary: Optional[int] = Field(15000, description="不传用默认值 15000")
class EmpUpdate(BaseModel):
emp_open_time: Optional[datetime] = None
@@ -26,3 +26,4 @@ class EmpOut(BaseModel):
salary: Optional[int] = None
model_config = ConfigDict(from_attributes=True)