|
@@ -1,3 +1,5 @@
|
|
|
+import json
|
|
|
+
|
|
|
from flask import request, jsonify
|
|
|
from flask_restx import Resource, Namespace, reqparse
|
|
|
from sqlalchemy import select, insert, delete, update
|
|
@@ -13,7 +15,7 @@ ns = Namespace('organization', description='组织管理接口')
|
|
|
|
|
|
company_list = reqparse.RequestParser(bundle_errors=True)
|
|
|
company_list.add_argument(name='page_size', type=int, location='args', required=False, help='每页记录数量,默认:20')
|
|
|
-company_list.add_argument(name='page', type=int, location='args', required=False, help='第几页')
|
|
|
+company_list.add_argument(name='page', type=int, location='args', required=False, help='页数')
|
|
|
|
|
|
|
|
|
@ns.route('/company_list')
|
|
@@ -34,7 +36,7 @@ class CompanyListApi(Resource):
|
|
|
|
|
|
|
|
|
company_details = reqparse.RequestParser(bundle_errors=True)
|
|
|
-company_details.add_argument(name='id', type=int, location='form', required=False, help='id')
|
|
|
+company_details.add_argument(name='company_id', type=int, location='form', required=False, help='公司id')
|
|
|
company_details.add_argument(name='company_name', type=str, location='form', required=True, help='公司名')
|
|
|
company_details.add_argument(name='logo', type=FileStorage, location='files', required=False, help='商标')
|
|
|
company_details.add_argument(name='abbreviation', type=str, location='form', required=False, help='公司简称')
|
|
@@ -47,7 +49,7 @@ company_details.add_argument(name='staff_size', type=str, location='form', requi
|
|
|
company_details.add_argument(name='on_guard_size', type=str, location='form', required=False, help='在岗人数')
|
|
|
|
|
|
delete_company = reqparse.RequestParser(bundle_errors=True)
|
|
|
-delete_company.add_argument(name='id', type=int, location='form', required=False, help='id')
|
|
|
+delete_company.add_argument(name='company_id', type=int, location='form', required=False, help='公司id')
|
|
|
|
|
|
|
|
|
@ns.route('/company')
|
|
@@ -87,20 +89,19 @@ class CompanyApi(Resource):
|
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message="公司已存在")
|
|
|
|
|
|
# 添加公司
|
|
|
- session.execute(
|
|
|
- insert(Company).values(
|
|
|
- company_name=company_name,
|
|
|
- logo=logo,
|
|
|
- abbreviation=abbreviation,
|
|
|
- code=code,
|
|
|
- registered_address=registered_address,
|
|
|
- business_address=business_address,
|
|
|
- legal_person_name=legal_person_name,
|
|
|
- company_code=company_code,
|
|
|
- staff_size=staff_size,
|
|
|
- on_guard_size=on_guard_size
|
|
|
- )
|
|
|
+ stmt = insert(Company).values(
|
|
|
+ company_name=company_name,
|
|
|
+ logo=logo,
|
|
|
+ abbreviation=abbreviation,
|
|
|
+ code=code,
|
|
|
+ registered_address=registered_address,
|
|
|
+ business_address=business_address,
|
|
|
+ legal_person_name=legal_person_name,
|
|
|
+ company_code=company_code,
|
|
|
+ staff_size=staff_size,
|
|
|
+ on_guard_size=on_guard_size
|
|
|
)
|
|
|
+ session.execute(stmt)
|
|
|
|
|
|
session.commit()
|
|
|
|
|
@@ -110,7 +111,7 @@ class CompanyApi(Resource):
|
|
|
@ns.expect(delete_company)
|
|
|
def delete(self):
|
|
|
"""删除公司"""
|
|
|
- company_id = request.form.get('id')
|
|
|
+ company_id = request.form.get('company_id')
|
|
|
|
|
|
if company_id is None:
|
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message="公司id不能为空")
|
|
@@ -125,7 +126,7 @@ class CompanyApi(Resource):
|
|
|
|
|
|
|
|
|
get_company_details = reqparse.RequestParser(bundle_errors=True)
|
|
|
-get_company_details.add_argument(name='id', type=int, location='args', required=False, help='id')
|
|
|
+get_company_details.add_argument(name='company_id', type=int, location='args', required=False, help='公司id')
|
|
|
|
|
|
|
|
|
@ns.route('/company_details')
|
|
@@ -136,7 +137,7 @@ class CompanyDetailsApi(Resource):
|
|
|
def get(self):
|
|
|
"""获取公司详情"""
|
|
|
|
|
|
- company_id = request.args.get('id')
|
|
|
+ company_id = request.args.get('company_id')
|
|
|
|
|
|
if company_id is None:
|
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message="公司id不能为空")
|
|
@@ -151,7 +152,7 @@ class CompanyDetailsApi(Resource):
|
|
|
@ns.expect(company_details)
|
|
|
def put(self):
|
|
|
"""更新公司详情"""
|
|
|
- id = request.form.get('id')
|
|
|
+ company_id = request.form.get('company_id')
|
|
|
company_name = request.form.get('company_name')
|
|
|
logo = request.files.get('logo')
|
|
|
if logo:
|
|
@@ -169,7 +170,7 @@ class CompanyDetailsApi(Resource):
|
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message="公司名不能为空")
|
|
|
|
|
|
with Session(engine) as session:
|
|
|
- stmt = update(Company).where(Company.id == id).values(
|
|
|
+ stmt = update(Company).where(Company.id == company_id).values(
|
|
|
company_name=company_name,
|
|
|
logo=logo,
|
|
|
abbreviation=abbreviation,
|
|
@@ -187,60 +188,183 @@ class CompanyDetailsApi(Resource):
|
|
|
return jsonify(code=StatesCode.SUCCESS, message='修改成功')
|
|
|
|
|
|
|
|
|
+department_details = reqparse.RequestParser(bundle_errors=True)
|
|
|
+department_details.add_argument(name='department_id', type=str, location='form', required=False, help='部门id')
|
|
|
+department_details.add_argument(name='company_id', type=str, location='form', required=False, help='上级公司')
|
|
|
+department_details.add_argument(name='department_name', type=str, location='form', required=False, help='部门名')
|
|
|
+department_details.add_argument(name='principal', type=str, location='form', required=False, help='负责人')
|
|
|
+department_details.add_argument(name='liaison_officer', type=str, location='form', required=False, help='接口人')
|
|
|
+department_details.add_argument(name='duplicate_name', type=str, location='form', required=False, help='拍重名')
|
|
|
+department_details.add_argument(name='on_guard', type=str, location='form', required=False, help='在岗人数')
|
|
|
+department_details.add_argument(name='freelance_staff', type=str, location='form', required=False, help='自由员工')
|
|
|
+department_details.add_argument(name='cooperation_staff', type=str, location='form', required=False, help='协作员工')
|
|
|
+department_details.add_argument(name='thirdparty_staff', type=str, location='form', required=False, help='第三方员工')
|
|
|
+department_details.add_argument(name='censure', type=str, location='form', required=False, help='职责')
|
|
|
+
|
|
|
+
|
|
|
@ns.route('/department')
|
|
|
class DepartmentApi(Resource):
|
|
|
|
|
|
+ @ns.doc(id='department_list', description='获取公司下部门列表')
|
|
|
+ @ns.expect(get_company_details)
|
|
|
+ def get(self):
|
|
|
+ """获取公司下部门列表"""
|
|
|
+
|
|
|
+ company_id = request.args.get('company_id')
|
|
|
+
|
|
|
+ if company_id is None:
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message="公司id不能为空")
|
|
|
+
|
|
|
+ with Session(engine) as session:
|
|
|
+ stmt = select(Department).where(Department.company_id == company_id)
|
|
|
+ results = session.execute(stmt).scalars().all()
|
|
|
+
|
|
|
+ data = []
|
|
|
+ for result in results:
|
|
|
+ data.append({"id": result.id, "department_name": result.department_name})
|
|
|
+
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功', data=data)
|
|
|
+
|
|
|
@ns.doc(id='add_department', description='添加部门')
|
|
|
- @ns.expect()
|
|
|
+ @ns.expect(department_details)
|
|
|
def post(self):
|
|
|
"""添加部门"""
|
|
|
+ company_id = request.form.get('company_id')
|
|
|
+ department_name = request.form.get('department_name')
|
|
|
+ principal = request.form.get('principal')
|
|
|
+ liaison_officer = request.form.get('liaison_officer')
|
|
|
+ duplicate_name = request.form.get('duplicate_name')
|
|
|
+ on_guard = request.form.get('on_guard')
|
|
|
+ freelance_staff = request.form.get('freelance_staff')
|
|
|
+ cooperation_staff = request.form.get('cooperation_staff')
|
|
|
+ thirdparty_staff = request.form.get('thirdparty_staff')
|
|
|
+ censure = request.form.get('censure')
|
|
|
+
|
|
|
+ if company_id is None or department_name is None:
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message="上级公司和部门名称不能为空")
|
|
|
+
|
|
|
+ with Session(engine) as session:
|
|
|
+ stmt = insert(Department).values(
|
|
|
+ company_id=company_id,
|
|
|
+ department_name=department_name,
|
|
|
+ principal=principal,
|
|
|
+ liaison_officer=liaison_officer,
|
|
|
+ duplicate_name=duplicate_name,
|
|
|
+ on_guard=on_guard,
|
|
|
+ freelance_staff=freelance_staff,
|
|
|
+ cooperation_staff=cooperation_staff,
|
|
|
+ thirdparty_staff=thirdparty_staff,
|
|
|
+ censure=censure,
|
|
|
+
|
|
|
+ )
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
|
|
|
- return {"code": StatesCode.SUCCESS, "message": "成功", "data": '添加部门'}
|
|
|
+ return {"code": StatesCode.SUCCESS, "message": "成功"}
|
|
|
|
|
|
@ns.doc(id='delete_company_details', description='删除部门')
|
|
|
- @ns.expect()
|
|
|
+ @ns.expect(department_details)
|
|
|
def delete(self):
|
|
|
"""删除部门"""
|
|
|
+ department_id = request.form.get('department_id')
|
|
|
+
|
|
|
+ if department_id is None:
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message="部门id不能为空")
|
|
|
+
|
|
|
+ with Session(engine) as session:
|
|
|
+ stmt = delete(Department).where(Department.id == department_id)
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
+
|
|
|
return {"code": StatesCode.SUCCESS, "message": "成功", "data": '删除部门'}
|
|
|
|
|
|
|
|
|
+get_department = reqparse.RequestParser(bundle_errors=True)
|
|
|
+get_department.add_argument(name='department_id', type=str, location='args', required=False, help='部门id')
|
|
|
+
|
|
|
+
|
|
|
@ns.route('/department_details')
|
|
|
class DepartmentDetailsApi(Resource):
|
|
|
|
|
|
@ns.doc(id='get_department_details', description='获取部门详情')
|
|
|
- @ns.expect()
|
|
|
+ @ns.expect(get_department)
|
|
|
def get(self):
|
|
|
- """获取department部门详情"""
|
|
|
-
|
|
|
- data = {
|
|
|
- "iclass": "1",
|
|
|
- "parent_business": "智慧城市设计院",
|
|
|
- "department": "智慧楼宇BU",
|
|
|
- "principal": "张三",
|
|
|
- "liaison_officer": "李四",
|
|
|
- "duplicate_name": "z-智慧楼宇BU",
|
|
|
- "staff_num": 100,
|
|
|
- "freelance_staff": 100,
|
|
|
- "collaborative_work": 100,
|
|
|
- "etw": 100,
|
|
|
- "duties": "中讯邮电咨询设计有限公司"
|
|
|
-
|
|
|
- }
|
|
|
- return {"code": StatesCode.SUCCESS, "message": "成功", "data": data}
|
|
|
+ """获取部门详情"""
|
|
|
+
|
|
|
+ department_id = request.args.get('department_id')
|
|
|
+
|
|
|
+ if department_id is None:
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message="部门id不能为空")
|
|
|
+
|
|
|
+ with Session(engine) as session:
|
|
|
+ stmt = select(Department).where(Department.id == department_id)
|
|
|
+ results = session.execute(stmt).scalars().all()
|
|
|
+
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message="成功", data=to_dict(results))
|
|
|
|
|
|
@ns.doc(id='update_company_details', description='修改部门详情')
|
|
|
- @ns.expect()
|
|
|
+ @ns.expect(department_details)
|
|
|
def put(self):
|
|
|
- """更新department部门详情"""
|
|
|
+ """更新部门详情"""
|
|
|
+
|
|
|
+ department_id = request.form.get('department_id')
|
|
|
+ company_id = request.form.get('company_id')
|
|
|
+ department_name = request.form.get('department_name')
|
|
|
+ principal = request.form.get('principal')
|
|
|
+ liaison_officer = request.form.get('liaison_officer')
|
|
|
+ duplicate_name = request.form.get('duplicate_name')
|
|
|
+ on_guard = request.form.get('on_guard')
|
|
|
+ freelance_staff = request.form.get('freelance_staff')
|
|
|
+ cooperation_staff = request.form.get('cooperation_staff')
|
|
|
+ thirdparty_staff = request.form.get('thirdparty_staff')
|
|
|
+ censure = request.form.get('censure')
|
|
|
+
|
|
|
+ if company_id is None or department_name is None:
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message="上级公司和部门名称不能为空")
|
|
|
+
|
|
|
+ with Session(engine) as session:
|
|
|
+ stmt = update(Department).where(Department.id == department_id).values(
|
|
|
+ company_id=company_id,
|
|
|
+ department_name=department_name,
|
|
|
+ principal=principal,
|
|
|
+ liaison_officer=liaison_officer,
|
|
|
+ duplicate_name=duplicate_name,
|
|
|
+ on_guard=on_guard,
|
|
|
+ freelance_staff=freelance_staff,
|
|
|
+ cooperation_staff=cooperation_staff,
|
|
|
+ thirdparty_staff=thirdparty_staff,
|
|
|
+ censure=censure,
|
|
|
+
|
|
|
+ )
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
+
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message="成功")
|
|
|
|
|
|
- return {"code": StatesCode.SUCCESS, "message": "成功", "data": '修改部门详情'}
|
|
|
+
|
|
|
+batch_delete_company = reqparse.RequestParser(bundle_errors=True)
|
|
|
+batch_delete_company.add_argument(name='company_ids', type=list, location='form', required=False, help='公司ids')
|
|
|
|
|
|
|
|
|
@ns.route('/batch_delete_company')
|
|
|
class BatchDeletecompanyApi(Resource):
|
|
|
@ns.doc(id='batch_delete_users', description='批量删除公司')
|
|
|
- @ns.expect()
|
|
|
+ @ns.expect(batch_delete_company)
|
|
|
def delete(self):
|
|
|
"""批量删除公司"""
|
|
|
+ company_ids = request.form.get('company_ids')
|
|
|
+
|
|
|
+ if company_ids is not None:
|
|
|
+ company_ids = json.loads(company_ids)
|
|
|
+ else:
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message='公司id不能为空')
|
|
|
+
|
|
|
+ with Session(engine) as session:
|
|
|
+ stmt = select(Company).where(Company.id.in_(company_ids))
|
|
|
+ results = session.execute(stmt).scalars().all()
|
|
|
+
|
|
|
+ for result in results:
|
|
|
+ session.delete(result)
|
|
|
+ session.commit()
|
|
|
|
|
|
- return {"code": StatesCode.SUCCESS, "message": "成功", "data": "user004"}
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='批量删除成功')
|