diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..c3ea340 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,12 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# 已忽略包含查询文件的默认文件夹 +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +*.xml +*.iml \ No newline at end of file diff --git a/stu_jiuye/CURD_api.py b/stu_jiuye/CURD_api.py index eb02158..403a5c7 100644 --- a/stu_jiuye/CURD_api.py +++ b/stu_jiuye/CURD_api.py @@ -9,25 +9,25 @@ CURD=APIRouter() @CURD.get('/emp',tags=['查询就业信息']) def get_stuinfo( #查询学生就业信息 - stuname:str| None = None - ,stuclass:str| None = None - ,compname:str|None=None + 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_date:datetime.date|None=None - ,offer_date:datetime.date|None=None + ,employment_open_time:datetime.date|None=None + ,offer_recived_time:datetime.date|None=None ,db=Depends(get_db) ): #查询条件 r=get_emp_dao( #调用函数 - stuname, - stuclass, - compname, + sname, + class_num, + employment_company, min_salary, max_salary, somewhere, - employment_open_date, - offer_date, + employment_open_time, + offer_recived_time, db ) if r: @@ -91,23 +91,23 @@ def delete_stuinfo( #删除模块 @CURD.get('/Top5',tags=['就业薪资Top5']) def salarytop5(db=Depends(get_db)): - q = db.query(Employments,Company.compname) \ + q = db.query(Employments,Company.employment_company) \ .join(Company, Employments.company_id == Company.id) \ .filter(Employments.is_deleted == 0)\ - .order_by(Employments.salary.desc())\ + .order_by(Employments.employment_salary.desc())\ .offset(0).limit(5) .all() - return [{'学生姓名':i.stuname,'学生班级':i.stuclass,'就业时间':i.offer_date,'公司':compname} for i,compname in q] + return [{'学生姓名':i.sname,'学生班级编号':i.class_num,'就业时间':i.offer_recived_time,'公司':employment_company} for i,employment_company in q] @CURD.get('/worktime',tags=['学生就业时常']) def worktime(db=Depends(get_db)): q = db.query(Employments).all() - return [{'学生姓名':i.stuname,'就业时常':f'{i.offer_date-i.employment_open_date}'} for i in q] + return [{'学生姓名':i.stuname,'就业时常':f'{i.offer_recived_time-i.employment_open_time}'} for i in q] @CURD.get('/avgworktime',tags=['学生平均就业时常']) def worktime(db=Depends(get_db)): q = db.query(Employments)\ - .filter(Employments.employment_open_date is not None)\ + .filter(Employments.employment_open_time is not None)\ .all() - return [{'学生姓名':i.stuname,'平均就业时常':f'{(i.offer_date-i.employment_open_date)/len(q)}'} for i in q] \ No newline at end of file + return [{'学生姓名':i.stuname,'平均就业时常':f'{(i.offer_recived_time-i.employment_open_time)/len(q)}'} for i in q] \ No newline at end of file diff --git a/stu_jiuye/dao.py b/stu_jiuye/dao.py index 34e0245..09196a1 100644 --- a/stu_jiuye/dao.py +++ b/stu_jiuye/dao.py @@ -33,7 +33,7 @@ def add_address_dao(o,db): #添加地址区域信息函数 try: o.pop('id', None) #摘除id字段,自增字段无需手动添加 o1 = Address( **o) #实例化参数 - db.add(o1) #添加数据进入表 + db.add(o1) #添加数据进入表 except Exception as e: #失败返回 print(f'添加失败,{e}') db.rollback() #回滚数据 @@ -58,58 +58,58 @@ def update_emp_dao(id,update_data,db): #更新数据函数 def get_emp_dao( #获取学生就业信息函数 # stuid, - stuname - ,stuclass - ,compname + sname + ,class_num + ,employment_company ,min_salary ,max_salary ,somewhere - ,employment_open_date - ,offer_date + ,employment_open_time + ,offer_recived_time ,db # ,page # ,page_size ): #根据选择条件获取信息 - q = db.query(Employments,Company.compname,Address.somewhere)\ + q = db.query(Employments,Company.employment_company,Address.somewhere)\ .join(Company,Employments.company_id==Company.id)\ .join(Address,Company.address_id==Address.id)\ .filter(Employments.is_deleted == 0) #连接公司表和地址表,筛选未被删除信息 # if stuid: # q = q.filter( Employments.id == stuid ) - if stuname: #根据学生姓名筛选 - q = q.filter( Employments.stuname == stuname ) - if stuclass: - q = q.filter(Employments.stuclass == stuclass) + if sname: #根据学生姓名筛选 + q = q.filter( Employments.sname == sname ) + if class_num: + q = q.filter(Employments.class_num == class_num) if somewhere: q = q.filter(Address.somewhere.like(f'%{somewhere}%')) - if compname: #根据公司姓名筛选 - q=q.filter(Company.compname.like(f'%{compname}%')) + 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.salary >= min_salary) + q = q.filter(Employments.employment_salary >= min_salary) if max_salary is not None: ##根据最大薪资筛选 - q = q.filter(Employments.salary <= max_salary) - if employment_open_date: - q = q.filter(Employments.employment_open_date == employment_open_date) - if offer_date: - q = q.filter(Employments.offer_date == offer_date) + 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) r= q.all() if r: return [ {"id": i.id, - '学生姓名':i.stuname, - '学生班级':i.stuclass, - "公司": compname, + '学生姓名':i.sname, + '学生班级编号':i.class_num, + "公司": employment_company, "公司区域":somewhere, # "company_id": i.company_id, - "薪资":i.salary, + "薪资":i.employment_salary, # "address_id": i.address_id, - "就业开放时间":i.employment_open_date, - "offer下发时间":i.offer_date, - "created_date": i.created_date, - "updated_date": i.updated_date, - "is_deleted":i.is_deleted } for i,compname,somewhere in r ] #返回信息列表 + "就业开放时间":i.employment_open_time, + "offer下发时间":i.offer_recived_time, + "created_date": i.create_time, + "updated_date": i.update_time, + "is_deleted":i.is_deleted } for i,employment_company,somewhere in r ] #返回信息列表 def delete_emp_dao(id,db): #删除函数 diff --git a/stu_jiuye/database.py b/stu_jiuye/database.py index 230d3a7..b220e81 100644 --- a/stu_jiuye/database.py +++ b/stu_jiuye/database.py @@ -2,6 +2,7 @@ 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" engine = create_engine(db_url , pool_size=50 , echo=True diff --git a/stu_jiuye/model.py b/stu_jiuye/model.py index 0e0779d..7ce7c94 100644 --- a/stu_jiuye/model.py +++ b/stu_jiuye/model.py @@ -38,8 +38,8 @@ class Employments(Base): #学生就 # , ForeignKey='student.id' , comment='自增主键' ) - stuname = Column(String(50)) #学生姓名,冗余字段 - stuclass = Column(String(50)) #学生班级,冗余字段 + sname = Column(String(50)) #学生姓名,冗余字段 + class_num = Column(Integer) #学生班级,冗余字段 # compname=Column(String(50) # ,nullable=False @@ -53,16 +53,16 @@ class Employments(Base): #学生就 # , ForeignKey('Address.id') # , nullable=False # ) - salary = Column(Integer) #薪资 + employment_salary = Column(Integer) #薪资 - employment_open_date = Column(DATETIME) #就业开放时间 + employment_open_time = Column(DATETIME) #就业开放时间 - offer_date = Column(DATETIME) #offer下发时间 + offer_recived_time = Column(DATETIME) #offer下发时间 - 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 ) @@ -74,7 +74,7 @@ class Company(Base): #公司信 , primary_key=True ,autoincrement=True ) #主键id,自增主键 - compname = Column(String(50) #公司姓名 + employment_company = Column(String(50) #公司姓名 , nullable=False #非空约束 ) address_id = Column(Integer #地址id,匹配地址表 diff --git a/stu_jiuye/request.py b/stu_jiuye/request.py index 89acbbc..2f8fab2 100644 --- a/stu_jiuye/request.py +++ b/stu_jiuye/request.py @@ -4,14 +4,14 @@ from pydantic import BaseModel, Field class PostRequest(BaseModel): #学生就业信息请求体模型 # compname: str|None=None - stuname: str|None=None - stuclass: str|None=None + sname: str|None=None + class_num: int|None=None company_id:int|None=None # address_id: int|None=None - salary: int|None=None - employment_open_date:date|None=None - offer_date:date|None=None - updated_date:date|None=None + employment_salary: int|None=None + employment_open_time:date|None=None + offer_recived_time:date|None=None + create_time:date|None=None is_deleted:int=0 class EmpResponse(BaseModel): #学生就业信息响应体 code: int = 200 @@ -21,7 +21,7 @@ class EmpResponse(BaseModel): #学生就 class CompRequest(BaseModel): #公司信息请求体模型 - compname:str + employment_company:str address_id: int | None = None class CompResponse(BaseModel): #公司信息响应体