更新debug

This commit is contained in:
2026-09-21 15:07:50 +08:00
parent c45cae80c7
commit 3976d8c20e
7 changed files with 46 additions and 31 deletions
+7 -7
View File
@@ -9,15 +9,15 @@ CURD=APIRouter()
@CURD.get('/emp',tags=['查询就业信息'])
def get_stuinfo(
# stuid:int|None=None,
comname:str|None=None
stuname:str| None = None
,compname:str|None=None
,min_salary:int=0
,max_salary:int|None=None
,db=Depends(get_db)
):
r=get_orders_dao(
# stuid,
comname,
r=get_emp_dao(
stuname,
compname,
db,
min_salary,
max_salary)
@@ -41,7 +41,7 @@ def add_company(c:CompRequest,db=Depends(get_db)):
r = add_company_dao(o=d, db=db)
if not r:
raise HTTPException(status_code=500, detail='服务器繁忙,请稍后添加!')
return EmpResponse(totals=1, data=d)
return CompResponse(totals=1, data=d)
@CURD.post('/emp/company/address',response_model=AddResponse,tags=['新增公司所在区域'])
@@ -52,7 +52,7 @@ def add_address(
r = add_address_dao(o=d, db=db)
if not r:
raise HTTPException(status_code=500, detail='服务器繁忙,请稍后添加!')
return EmpResponse(totals=1, data=d)
return AddResponse(totals=1, data=d)
@CURD.put('/emp',tags=['更改就业信息'])
+18 -10
View File
@@ -1,3 +1,5 @@
import like
from model import Employments,Address,Company
@@ -45,7 +47,8 @@ def add_address_dao(o,db):
def update_orders_dao(id,update_data,db):
try: # 数据更新是有返回值的,返回的是影响的行数
rows = db.query( Employments ).filter( Employments.id == id ).update( update_data )
except:
except Exception as e:
print(f'更新失败,{e}')
db.rollback()
return False
else:
@@ -54,21 +57,25 @@ def update_orders_dao(id,update_data,db):
def get_emp_dao(
# stuid,
name
stuname
,compname
,db
, min_salary: int = 0
, max_salary: int | None = None
# ,page
# ,page_size
):
q = db.query(Employments)\
q = db.query(Employments,Company.compname,Address.somewhere)\
.join(Company,Employments.company_id==Company.id)\
.join(Address,Company.address_id==Address.id)
.join(Address,Company.address_id==Address.id)\
.filter(Employments.is_deleted == 0)
# if stuid:
# q = q.filter( Employments.id == stuid )
if name:
q = q.filter( Employments.stuname == name )
if stuname:
q = q.filter( Employments.stuname == stuname )
if compname:
q=q.filter(Company.compname.like(f'%{compname}%'))
# r = q.offset( (page-1)*page_size ).limit( page_size ).all()
if min_salary is not None:
q = q.filter(Employments.salary >= min_salary)
@@ -79,15 +86,16 @@ def get_emp_dao(
return [ {"id": i.id,
'stuname':i.stuname,
'stuclass':i.stuclass,
"company_name": i.compname,
"company_id": i.company_id,
"company_name": compname,
"address":somewhere,
# "company_id": i.company_id,
"salary":i.salary,
"address_id": i.address_id,
# "address_id": i.address_id,
"employment_open_date":i.employment_open_date,
"offer_date":i.offer_date,
"created_date": i.created_date,
"updated_date": i.updated_date,
"is_deleted":i.is_deleted } for i in r ]
"is_deleted":i.is_deleted } for i,compname,somewhere in r ]
def delete_orders_dao(id,db):
+1 -1
View File
@@ -1,7 +1,7 @@
from sqlalchemy import *
from sqlalchemy.orm import declarative_base,sessionmaker
db_url = "mysql+pymysql://root:123456@127.0.0.1:3306/ai0824?charset=utf8mb4"
db_url = "mysql+pymysql://root:123456@127.0.0.1:3306/ai0824_001?charset=utf8mb4"
engine = create_engine(db_url
, pool_size=50
, echo=True
+9 -11
View File
@@ -41,18 +41,18 @@ class Employments(Base):
stuname = Column(String(50))
stuclass = Column(String(50))
compname=Column(String(50)
,nullable=False
)
# compname=Column(String(50)
# ,nullable=False
# )
company_id = Column(Integer
, ForeignKey('Company.id')
, nullable=False
)
address_id = Column(Integer
, ForeignKey('Address.id')
, nullable=False
)
# address_id = Column(Integer
# , ForeignKey('Address.id')
# , nullable=False
# )
salary = Column(Integer)
employment_open_date = Column(DATETIME)
@@ -71,9 +71,8 @@ class Employments(Base):
class Company(Base):
__tablename__ = 'Company'
id = Column(Integer
, primary_key=True
,autoincrement=True
)
compname = Column(String(50), nullable=False)
address_id = Column(Integer
@@ -92,9 +91,8 @@ class Company(Base):
class Address(Base):
__tablename__ = 'Address'
id = Column(Integer
, primary_key=True
,autoincrement=True
)
somewhere=Column(String(50)
, nullable=False
+2 -2
View File
@@ -4,11 +4,11 @@ from pydantic import BaseModel, Field
class PostRequest(BaseModel):
compname: str|None=None
# compname: str|None=None
stuname: str|None=None
stuclass: str|None=None
company_id:int|None=None
address_id: int|None=None
# address_id: int|None=None
salary: int|None=None
employment_open_date:date|None=None
offer_date:date|None=None