From 8a554ad4afa9f431068728926f6b6b56edac266a Mon Sep 17 00:00:00 2001 From: wolin_ck666_999 Date: Tue, 22 Sep 2026 15:13:23 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=87=B3=E3=80=8Capi=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/e_api.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 api/e_api.py diff --git a/api/e_api.py b/api/e_api.py new file mode 100644 index 0000000..68db826 --- /dev/null +++ b/api/e_api.py @@ -0,0 +1,37 @@ +from fastapi import APIRouter,HTTPException,Depends +from database import Session +from model.e_model import Employment +from schema.e_schema import EmploymentRequest +from dao.e_dao import get_employment_dao,wq_employment_dao,upd_employment_dao,del_employment_dao +employment_api = APIRouter() + + +def get_db(): + db = Session() + try: + yield db + finally: + db.close() +@employment_api.get('/',summary='查询就业信息') +def get_employment(db=Depends(get_db)): + r = get_employment_dao(db) + return {'code':200,'detail':'查询成功!','data':r} + + +@employment_api.post('/',summary='新增就业信息') +def add_employment(e:EmploymentRequest,db=Depends(get_db)): + d= e.model_dump() + r = wq_employment_dao(d,db) + return {'code':200,'detail':'添加成功!','total':r} +# +# +@employment_api.put('/',summary='更新就业信息') +def update_employment(e:EmploymentRequest,db=Depends(get_db)): + e1 = e.model_dump() + r = upd_employment_dao(e1,db) + return {'code':200,'msg':'更新成功','total':r} +# +@employment_api.delete('/',summary='删除就业信息') +def delete_employment(stu_id:str,db=Depends(get_db)): + r =del_employment_dao(stu_id,db) + return {'code':200,'totals':r,'detail':'删除成功!'} From 0984210387e119ed44c213d43999656c87facf5d Mon Sep 17 00:00:00 2001 From: wolin_ck666_999 Date: Tue, 22 Sep 2026 15:14:10 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=87=B3=E3=80=8Cdao=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/e_dao.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 dao/e_dao.py diff --git a/dao/e_dao.py b/dao/e_dao.py new file mode 100644 index 0000000..015e65d --- /dev/null +++ b/dao/e_dao.py @@ -0,0 +1,52 @@ +from http.client import HTTPException + +from model.e_model import Employment +from fastapi import HTTPException + +def get_employment_dao(db): + try: + r = db.query(Employment).all() + except Exception as e: + db.rollback() + raise HTTPException(status_code=500, detail=f'查询失败:str(e)') + else: + db.commit() + return [{'stu_id':i.stu_id,'class_name':i.class_name} for i in r ] + + +def wq_employment_dao(o,db): + try: + o1 = Employment(**o) + db.add(o1) + except Exception as e: + db.rollback() + raise HTTPException(status_code=500, detail=f'添加失败:str(e)') + else: + db.commit() + return 1 + +def upd_employment_dao(e,db): + try: + rows = db.query(Employment).filter(Employment.stu_id == e['stu_id']).update(e) + except: + db.rollback() + raise HTTPException(status_code=500, detail='更新异常,请稍后再执行!') + else: + db.commit() + return 1 + +def del_employment_dao(stu_id,db): + try: + row = db.query(Employment).filter(Employment.stu_id == stu_id).all() + if not row: + raise HTTPException(status_code=404,detail='记录不存在') + for i in row: + if i.deleted == 0: + db.query(Employment).filter(Employment.stu_id == i.stu_id).update({'deleted':1}) + except Exception as e: + db.rollback() + raise HTTPException(status_code=500,detail=f'删除失败:{str(e)}') + else: + db.commit() + return 1 + From 42130285a375a6a1c138483eb484b927ebcddcca Mon Sep 17 00:00:00 2001 From: wolin_ck666_999 Date: Tue, 22 Sep 2026 15:14:28 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=87=B3=E3=80=8Cmodel=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/e_model.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 model/e_model.py diff --git a/model/e_model.py b/model/e_model.py new file mode 100644 index 0000000..580afd2 --- /dev/null +++ b/model/e_model.py @@ -0,0 +1,45 @@ +from sqlalchemy import * +from datetime import datetime +from sqlalchemy.orm import declarative_base,sessionmaker + +db_url = "mysql+pymysql://root:123456@127.0.0.1:3306/ai0824_stu?charset=utf8" + +engine = create_engine(db_url, pool_size=100,echo=False) + +Base = declarative_base() + +class Employment(Base): + __tablename__ = 's_employment' + id = Column(Integer + , primary_key=True + , autoincrement=True + , comment='编号,自增主键') + stu_id = Column(String(20) + # , ForeingKey('s_student.stu_id') + , unique=True + , nullable=True + , comment='学生学号,唯一') + class_name = Column(String(32)) + company = Column(String(100)) + salary = Column(Integer + , default=0) + open_date = Column(DATETIME + , default=datetime.now()) + offer_date = Column(DATETIME + , default=datetime.now()) + work_date = Column(DATETIME + , default=datetime.now() + , onupdate=datetime.now) + is_delete = Column(Integer + , default=0 + ) + + +Session = sessionmaker( bind = engine, autoflush = False, autocommit = False ) + +def get_db(): + db = Session() + try: + yield db + finally: + db.close() \ No newline at end of file From d50af7ecc3db663e6cfa4b28538621dc56c3a968 Mon Sep 17 00:00:00 2001 From: wolin_ck666_999 Date: Tue, 22 Sep 2026 15:14:45 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=87=B3=E3=80=8Cschema=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- schema/e_schema.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 schema/e_schema.py diff --git a/schema/e_schema.py b/schema/e_schema.py new file mode 100644 index 0000000..f0f122b --- /dev/null +++ b/schema/e_schema.py @@ -0,0 +1,13 @@ +from pydantic import BaseModel +from typing import Optional + +class EmploymentRequest(BaseModel): + stu_id: str|None = None + class_name: str|None = None + company: Optional[str] = None + salary: Optional[int] = None + + + + +