|
@@ -79,6 +79,33 @@ class CompanyListApi(Resource):
|
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
|
|
|
+@ns.route('/all_company')
|
|
|
+class AllCompanyApi(Resource):
|
|
|
+
|
|
|
+ @ns.doc(description='获取所有公司列表')
|
|
|
+ @ns.expect(company_list)
|
|
|
+ def get(self):
|
|
|
+ """获取所有公司列表"""
|
|
|
+
|
|
|
+ page_size = int(request.args.get('page_size', 20))
|
|
|
+ page = int(request.args.get('page', 1))
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ # 统计总数
|
|
|
+ count = select(func.count(Company.id))
|
|
|
+ count_results = session.execute(count).scalars().first()
|
|
|
+
|
|
|
+ # 获取公司
|
|
|
+ stmt = select(Company).offset(page_size * (page - 1)).limit(page_size)
|
|
|
+ results = session.execute(stmt).scalars().all()
|
|
|
+
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功', total=count_results, data=to_dict(results))
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.ORGANIZATION, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
+
|
|
|
+
|
|
|
company_details = reqparse.RequestParser(bundle_errors=True)
|
|
|
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='公司名')
|
|
@@ -259,8 +286,13 @@ class CompanyApi(Resource):
|
|
|
|
|
|
try:
|
|
|
with Session(current_app.engine) as session:
|
|
|
+ # 删除公司
|
|
|
stmt = delete(Company).where(Company.id == company_id)
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
|
|
|
+ # 删除部门
|
|
|
+ stmt = delete(Department).where(Department.company_id == company_id)
|
|
|
session.execute(stmt)
|
|
|
session.commit()
|
|
|
|
|
@@ -284,6 +316,10 @@ department_details.add_argument(name='freelance_staff', type=str, location='form
|
|
|
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='职责')
|
|
|
+department_details.add_argument(name='code', type=str, location='form', required=False, help='部门编码')
|
|
|
+department_details.add_argument(name='sort', type=str, location='form', required=False, help='部门排序')
|
|
|
+department_details.add_argument(name='ori_id', type=str, location='form', required=False, help='部门id')
|
|
|
+department_details.add_argument(name='parent_id', type=str, location='form', required=False, help='部门上级id')
|
|
|
|
|
|
|
|
|
@ns.route('/department_list')
|
|
@@ -302,12 +338,12 @@ class DepartmentListApi(Resource):
|
|
|
|
|
|
try:
|
|
|
with Session(current_app.engine) as session:
|
|
|
- stmt = select(Department.id, Department.department_name).where(Department.company_id == company_id)
|
|
|
+ stmt = select(Department.id, Department.name).where(Department.company_id == company_id)
|
|
|
results = session.execute(stmt)
|
|
|
|
|
|
data = []
|
|
|
for result in results:
|
|
|
- data.append({"id": result.id, "department_name": result.department_name})
|
|
|
+ data.append({"id": result.id, "department_name": result.name})
|
|
|
|
|
|
save_log(request, Module.ORGANIZATION, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
|
|
@@ -361,34 +397,42 @@ class DepartmentApi(Resource):
|
|
|
cooperation_staff = request.form.get('cooperation_staff')
|
|
|
thirdparty_staff = request.form.get('thirdparty_staff')
|
|
|
censure = request.form.get('censure')
|
|
|
+ code = request.form.get('code')
|
|
|
+ sort = request.form.get('sort')
|
|
|
+ ori_id = request.form.get('ori_id')
|
|
|
+ parent_id = request.form.get('parent_id')
|
|
|
|
|
|
if company_id is None or department_name is None:
|
|
|
return jsonify(code=StatesCode.PARA_ERROR, message="上级公司和部门名称不能为空")
|
|
|
|
|
|
- try:
|
|
|
- with Session(current_app.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()
|
|
|
-
|
|
|
- save_log(request, Module.ORGANIZATION, OperationType.ADD, StatesCode.SUCCESS)
|
|
|
-
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='成功')
|
|
|
- except Exception as e:
|
|
|
- save_log(request, Module.ORGANIZATION, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
|
|
|
- return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
+ # try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = insert(Department).values(
|
|
|
+ company_id=company_id,
|
|
|
+ name=department_name,
|
|
|
+ principal=principal,
|
|
|
+ liaison_officer=liaison_officer,
|
|
|
+ full_name=duplicate_name,
|
|
|
+ on_guard=on_guard,
|
|
|
+ freelance_staff=freelance_staff,
|
|
|
+ cooperation_staff=cooperation_staff,
|
|
|
+ thirdparty_staff=thirdparty_staff,
|
|
|
+ censure=censure,
|
|
|
+ code=code,
|
|
|
+ sort=sort,
|
|
|
+ ori_id=ori_id,
|
|
|
+ parent_id=parent_id
|
|
|
+
|
|
|
+ )
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
+
|
|
|
+ save_log(request, Module.ORGANIZATION, OperationType.ADD, StatesCode.SUCCESS)
|
|
|
+
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功')
|
|
|
+ # except Exception as e:
|
|
|
+ # save_log(request, Module.ORGANIZATION, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
|
|
|
+ # return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
@ns.doc(id='update_company_details', description='修改部门详情')
|
|
|
@ns.expect(department_details)
|
|
@@ -406,6 +450,10 @@ class DepartmentApi(Resource):
|
|
|
cooperation_staff = request.form.get('cooperation_staff')
|
|
|
thirdparty_staff = request.form.get('thirdparty_staff')
|
|
|
censure = request.form.get('censure')
|
|
|
+ code = request.form.get('code')
|
|
|
+ sort = request.form.get('sort')
|
|
|
+ ori_id = request.form.get('ori_id')
|
|
|
+ parent_id = request.form.get('parent_id')
|
|
|
|
|
|
if company_id is None or department_name is None:
|
|
|
return jsonify(code=StatesCode.PARA_ERROR, message="上级公司和部门名称不能为空")
|
|
@@ -414,16 +462,19 @@ class DepartmentApi(Resource):
|
|
|
with Session(current_app.engine) as session:
|
|
|
stmt = update(Department).where(Department.id == department_id).values(
|
|
|
company_id=company_id,
|
|
|
- department_name=department_name,
|
|
|
+ name=department_name,
|
|
|
principal=principal,
|
|
|
liaison_officer=liaison_officer,
|
|
|
- duplicate_name=duplicate_name,
|
|
|
+ full_name=duplicate_name,
|
|
|
on_guard=on_guard,
|
|
|
freelance_staff=freelance_staff,
|
|
|
cooperation_staff=cooperation_staff,
|
|
|
thirdparty_staff=thirdparty_staff,
|
|
|
censure=censure,
|
|
|
-
|
|
|
+ code=code,
|
|
|
+ sort=sort,
|
|
|
+ ori_id=ori_id,
|
|
|
+ parent_id=parent_id
|
|
|
)
|
|
|
session.execute(stmt)
|
|
|
session.commit()
|
|
@@ -462,33 +513,33 @@ 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):
|
|
|
- # method_decorators = [login_required]
|
|
|
-
|
|
|
- @ns.doc(id='batch_delete_users', description='批量删除公司')
|
|
|
- @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.PARA_ERROR, message='公司id不能为空')
|
|
|
-
|
|
|
- try:
|
|
|
- with Session(current_app.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()
|
|
|
-
|
|
|
- save_log(request, Module.ORGANIZATION, OperationType.BATCH_DELETE, StatesCode.SUCCESS)
|
|
|
-
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='批量删除成功')
|
|
|
- except Exception as e:
|
|
|
- save_log(request, Module.ORGANIZATION, OperationType.BATCH_DELETE, StatesCode.UNKNOWN_ERROR)
|
|
|
- return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
+# @ns.route('/batch_delete_company')
|
|
|
+# class BatchDeleteCompanyApi(Resource):
|
|
|
+# # method_decorators = [login_required]
|
|
|
+#
|
|
|
+# @ns.doc(id='batch_delete_users', description='批量删除公司')
|
|
|
+# @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.PARA_ERROR, message='公司id不能为空')
|
|
|
+#
|
|
|
+# try:
|
|
|
+# with Session(current_app.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()
|
|
|
+#
|
|
|
+# save_log(request, Module.ORGANIZATION, OperationType.BATCH_DELETE, StatesCode.SUCCESS)
|
|
|
+#
|
|
|
+# return jsonify(code=StatesCode.SUCCESS, message='批量删除成功')
|
|
|
+# except Exception as e:
|
|
|
+# save_log(request, Module.ORGANIZATION, OperationType.BATCH_DELETE, StatesCode.UNKNOWN_ERROR)
|
|
|
+# return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|