|
@@ -43,28 +43,32 @@ class TemplateConfigListApi(Resource):
|
|
|
report_type = request.args.get('report_type')
|
|
|
template_type = request.args.get('template_type')
|
|
|
|
|
|
- with Session(current_app.engine) as session:
|
|
|
- stmt = select(Template).where(Template.template_type == template_type)
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = select(Template).where(Template.template_type == template_type)
|
|
|
|
|
|
- count = select(func.count(Template.id)).where(Template.template_type == template_type)
|
|
|
- count_results = session.execute(count).scalars().first()
|
|
|
+ count = select(func.count(Template.id)).where(Template.template_type == template_type)
|
|
|
+ count_results = session.execute(count).scalars().first()
|
|
|
|
|
|
- if template_name:
|
|
|
- stmt = stmt.where(Template.name == template_name)
|
|
|
+ if template_name:
|
|
|
+ stmt = stmt.where(Template.name == template_name)
|
|
|
|
|
|
- if template_format:
|
|
|
- stmt = stmt.where(Template.format == template_format)
|
|
|
+ if template_format:
|
|
|
+ stmt = stmt.where(Template.format == template_format)
|
|
|
|
|
|
- if report_type:
|
|
|
- stmt = stmt.where(Template.report_type == report_type)
|
|
|
+ if report_type:
|
|
|
+ stmt = stmt.where(Template.report_type == report_type)
|
|
|
|
|
|
- stmt = stmt.offset(page_size * (page - 1)).limit(page_size)
|
|
|
+ stmt = stmt.offset(page_size * (page - 1)).limit(page_size)
|
|
|
|
|
|
- results = session.execute(stmt).scalars().all()
|
|
|
+ results = session.execute(stmt).scalars().all()
|
|
|
|
|
|
- save_log(request, Module.DATA, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
+ save_log(request, Module.DATA, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='成功', total=count_results, data=to_dict(results))
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功', total=count_results, data=to_dict(results))
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.DATA, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
|
|
|
template = reqparse.RequestParser(bundle_errors=True)
|
|
@@ -92,15 +96,19 @@ class TemplateConfigApi(Resource):
|
|
|
template_id = request.args.get('template_id')
|
|
|
|
|
|
if template_id is None:
|
|
|
- return jsonify(code=StatesCode.UNKNOWN_ERROR, message='模版id不能为空')
|
|
|
+ return jsonify(code=StatesCode.PARA_ERROR, message='模版id不能为空')
|
|
|
|
|
|
- with Session(current_app.engine) as session:
|
|
|
- stmt = select(Template).where(Template.id == template_id)
|
|
|
- results = session.execute(stmt).scalars().all()
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = select(Template).where(Template.id == template_id)
|
|
|
+ results = session.execute(stmt).scalars().all()
|
|
|
|
|
|
- save_log(request, Module.DATA, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
+ save_log(request, Module.DATA, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='获取成功', data=to_dict(results))
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='获取成功', data=to_dict(results))
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.DATA, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
@ns.doc(id='add_template', description='添加报表模版')
|
|
|
@ns.expect(building_details)
|
|
@@ -114,7 +122,7 @@ class TemplateConfigApi(Resource):
|
|
|
template_type = request.form.get('template_type')
|
|
|
|
|
|
if template_name is None and template_type is None:
|
|
|
- return jsonify(code=StatesCode.UNKNOWN_ERROR, message='报表模版名和模版类型不能为空')
|
|
|
+ return jsonify(code=StatesCode.PARA_ERROR, message='报表模版名和模版类型不能为空')
|
|
|
|
|
|
# 模版存储(url),
|
|
|
if template_file:
|
|
@@ -123,32 +131,36 @@ class TemplateConfigApi(Resource):
|
|
|
else:
|
|
|
template_url = None
|
|
|
|
|
|
- with Session(current_app.engine) as session:
|
|
|
- # 判断是否存在
|
|
|
- stmt = select(Template).where(Template.name == template_name)
|
|
|
- result = session.execute(stmt).scalars().first()
|
|
|
- if result:
|
|
|
- return jsonify(code=StatesCode.UNKNOWN_ERROR, message="模版已存在")
|
|
|
-
|
|
|
- # 添加
|
|
|
- stmt = insert(Template).values(
|
|
|
- name=template_name,
|
|
|
- format=template_format,
|
|
|
- introduction=introduction,
|
|
|
- report_type=report_type,
|
|
|
- creator=g.user_name,
|
|
|
- create_time=cn_now(),
|
|
|
- update_time=cn_now(),
|
|
|
- template_url=template_url,
|
|
|
- template_type=template_type
|
|
|
- )
|
|
|
- session.execute(stmt)
|
|
|
-
|
|
|
- session.commit()
|
|
|
-
|
|
|
- save_log(request, Module.DATA, OperationType.ADD, StatesCode.SUCCESS)
|
|
|
-
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='添加成功')
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ # 判断是否存在
|
|
|
+ stmt = select(Template).where(Template.name == template_name)
|
|
|
+ result = session.execute(stmt).scalars().first()
|
|
|
+ if result:
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message="模版已存在")
|
|
|
+
|
|
|
+ # 添加
|
|
|
+ stmt = insert(Template).values(
|
|
|
+ name=template_name,
|
|
|
+ format=template_format,
|
|
|
+ introduction=introduction,
|
|
|
+ report_type=report_type,
|
|
|
+ creator=g.user_name,
|
|
|
+ create_time=cn_now(),
|
|
|
+ update_time=cn_now(),
|
|
|
+ template_url=template_url,
|
|
|
+ template_type=template_type
|
|
|
+ )
|
|
|
+ session.execute(stmt)
|
|
|
+
|
|
|
+ session.commit()
|
|
|
+
|
|
|
+ save_log(request, Module.DATA, OperationType.ADD, StatesCode.SUCCESS)
|
|
|
+
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='添加成功')
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.DATA, OperationType.ADD, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
@ns.doc(id='update_templatet', description='修改模版信息')
|
|
|
@ns.expect(building_details)
|
|
@@ -163,7 +175,7 @@ class TemplateConfigApi(Resource):
|
|
|
template_type = request.form.get('template_type')
|
|
|
|
|
|
if template_id is None or template_name is None:
|
|
|
- return jsonify(code=StatesCode.UNKNOWN_ERROR, message="模版id和模版名不能为空")
|
|
|
+ return jsonify(code=StatesCode.PARA_ERROR, message="模版id和模版名不能为空")
|
|
|
|
|
|
# 报表模版存储(url),
|
|
|
if template_file:
|
|
@@ -171,25 +183,28 @@ class TemplateConfigApi(Resource):
|
|
|
template_url = config.common.TEMPLATE_FILE_URL + template_file.filename
|
|
|
else:
|
|
|
template_url = None
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = update(Template).where(Template.id == template_id).values(
|
|
|
+ name=template_name,
|
|
|
+ format=template_format,
|
|
|
+ introduction=introduction,
|
|
|
+ report_type=report_type,
|
|
|
+ creator=g.user_name,
|
|
|
+ create_time=cn_now(),
|
|
|
+ update_time=cn_now(),
|
|
|
+ template_url=template_url,
|
|
|
+ template_type=template_type
|
|
|
+ )
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
+
|
|
|
+ save_log(request, Module.DATA, OperationType.UPDATE, StatesCode.SUCCESS)
|
|
|
|
|
|
- with Session(current_app.engine) as session:
|
|
|
- stmt = update(Template).where(Template.id == template_id).values(
|
|
|
- name=template_name,
|
|
|
- format=template_format,
|
|
|
- introduction=introduction,
|
|
|
- report_type=report_type,
|
|
|
- creator=g.user_name,
|
|
|
- create_time=cn_now(),
|
|
|
- update_time=cn_now(),
|
|
|
- template_url=template_url,
|
|
|
- template_type=template_type
|
|
|
- )
|
|
|
- session.execute(stmt)
|
|
|
- session.commit()
|
|
|
-
|
|
|
- save_log(request, Module.DATA, OperationType.UPDATE, StatesCode.SUCCESS)
|
|
|
-
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='修改成功')
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='修改成功')
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.DATA, OperationType.UPDATE, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
@ns.doc(id='delete_template', description='删除模版')
|
|
|
@ns.expect(building_details)
|
|
@@ -198,16 +213,20 @@ class TemplateConfigApi(Resource):
|
|
|
template_id = request.form.get('template_id')
|
|
|
|
|
|
if template_id is None:
|
|
|
- return jsonify(code=StatesCode.UNKNOWN_ERROR, message="模版id不能为空")
|
|
|
+ return jsonify(code=StatesCode.PARA_ERROR, message="模版id不能为空")
|
|
|
|
|
|
- with Session(current_app.engine) as session:
|
|
|
- stmt = delete(Template).where(Template.id == template_id)
|
|
|
- session.execute(stmt)
|
|
|
- session.commit()
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = delete(Template).where(Template.id == template_id)
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
|
|
|
- save_log(request, Module.DATA, OperationType.DELETE, StatesCode.SUCCESS)
|
|
|
+ save_log(request, Module.DATA, OperationType.DELETE, StatesCode.SUCCESS)
|
|
|
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='删除成功')
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='删除成功')
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.DATA, OperationType.DELETE, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
|
|
|
batch_delete_template = reqparse.RequestParser(bundle_errors=True)
|
|
@@ -227,19 +246,23 @@ class BatchTemplateConfigApi(Resource):
|
|
|
if template_ids is not None:
|
|
|
template_ids = json.loads(template_ids)
|
|
|
else:
|
|
|
- return jsonify(code=StatesCode.UNKNOWN_ERROR, message='模版id不能为空')
|
|
|
+ return jsonify(code=StatesCode.PARA_ERROR, message='模版id不能为空')
|
|
|
|
|
|
- with Session(current_app.engine) as session:
|
|
|
- stmt = select(Template).where(Template.id.in_(template_ids))
|
|
|
- results = session.execute(stmt).scalars().all()
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = select(Template).where(Template.id.in_(template_ids))
|
|
|
+ results = session.execute(stmt).scalars().all()
|
|
|
|
|
|
- for result in results:
|
|
|
- session.delete(result)
|
|
|
- session.commit()
|
|
|
+ for result in results:
|
|
|
+ session.delete(result)
|
|
|
+ session.commit()
|
|
|
|
|
|
- save_log(request, Module.DATA, OperationType.BATCH_DELETE, StatesCode.SUCCESS)
|
|
|
+ save_log(request, Module.DATA, OperationType.BATCH_DELETE, StatesCode.SUCCESS)
|
|
|
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='批量删除成功')
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='批量删除成功')
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.DATA, OperationType.BATCH_DELETE, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
|
|
|
company_id = reqparse.RequestParser(bundle_errors=True)
|
|
@@ -266,15 +289,20 @@ class CompanyApi(Resource):
|
|
|
company_id = request.args.get('company_id')
|
|
|
|
|
|
if company_id is None:
|
|
|
- return jsonify(code=StatesCode.UNKNOWN_ERROR, message='公司id不能为空')
|
|
|
+ return jsonify(code=StatesCode.PARA_ERROR, message='公司id不能为空')
|
|
|
|
|
|
- with Session(current_app.engine) as session:
|
|
|
- stmt = select(CompanyData).where(CompanyData.id == company_id)
|
|
|
- results = session.execute(stmt).scalars().all()
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = select(CompanyData).where(CompanyData.id == company_id)
|
|
|
+ results = session.execute(stmt).scalars().all()
|
|
|
+
|
|
|
+ save_log(request, Module.DATA, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
|
|
|
- save_log(request, Module.DATA, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='获取成功', data=to_dict(results))
|
|
|
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='获取成功', data=to_dict(results))
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.DATA, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
@ns.doc(id='add_company', description='添加公司信息')
|
|
|
@ns.expect(company_data)
|
|
@@ -297,29 +325,33 @@ class CompanyApi(Resource):
|
|
|
picture.save(os.path.join(config.common.COMPANY_PICTURE_PATH, picture.filename))
|
|
|
picture_urls.append(config.common.COMPANY_PICTURE_URL + picture.filename)
|
|
|
|
|
|
- with Session(current_app.engine) as session:
|
|
|
- # 判断是否存在
|
|
|
- stmt = select(CompanyData).where(CompanyData.management_unit == management_unit)
|
|
|
- result = session.execute(stmt).scalars().first()
|
|
|
- if result:
|
|
|
- return jsonify(code=StatesCode.UNKNOWN_ERROR, message="管理单位已存在")
|
|
|
-
|
|
|
- # 添加
|
|
|
- stmt = insert(CompanyData).values(
|
|
|
- management_unit=management_unit,
|
|
|
- custodian_unit=custodian_unit,
|
|
|
- introduction=introduction,
|
|
|
- contact_person=contact_person,
|
|
|
- contact_information=contact_information,
|
|
|
- picture=json.dumps(picture_urls),
|
|
|
- )
|
|
|
- session.execute(stmt)
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ # 判断是否存在
|
|
|
+ stmt = select(CompanyData).where(CompanyData.management_unit == management_unit)
|
|
|
+ result = session.execute(stmt).scalars().first()
|
|
|
+ if result:
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message="管理单位已存在")
|
|
|
+
|
|
|
+ # 添加
|
|
|
+ stmt = insert(CompanyData).values(
|
|
|
+ management_unit=management_unit,
|
|
|
+ custodian_unit=custodian_unit,
|
|
|
+ introduction=introduction,
|
|
|
+ contact_person=contact_person,
|
|
|
+ contact_information=contact_information,
|
|
|
+ picture=json.dumps(picture_urls),
|
|
|
+ )
|
|
|
+ session.execute(stmt)
|
|
|
|
|
|
- session.commit()
|
|
|
+ session.commit()
|
|
|
|
|
|
- save_log(request, Module.DATA, OperationType.ADD, StatesCode.SUCCESS)
|
|
|
+ save_log(request, Module.DATA, OperationType.ADD, StatesCode.SUCCESS)
|
|
|
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='新增成功')
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='新增成功')
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.DATA, OperationType.ADD, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
@ns.doc(id='update_company', description='修改公司信息')
|
|
|
@ns.expect(company_data)
|
|
@@ -335,7 +367,7 @@ class CompanyApi(Resource):
|
|
|
pictures = request.files.getlist('picture')
|
|
|
|
|
|
if company_id is None:
|
|
|
- return jsonify(code=StatesCode.UNKNOWN_ERROR, message='公司id不能为空')
|
|
|
+ return jsonify(code=StatesCode.PARA_ERROR, message='公司id不能为空')
|
|
|
|
|
|
# 多图片存储(url),
|
|
|
picture_urls = []
|
|
@@ -344,22 +376,26 @@ class CompanyApi(Resource):
|
|
|
picture.save(os.path.join(config.common.COMPANY_PICTURE_PATH, picture.filename))
|
|
|
picture_urls.append(config.common.COMPANY_PICTURE_URL + picture.filename)
|
|
|
|
|
|
- with Session(current_app.engine) as session:
|
|
|
- stmt = update(CompanyData).where(CompanyData.id == company_id).values(
|
|
|
- management_unit=management_unit,
|
|
|
- custodian_unit=custodian_unit,
|
|
|
- introduction=introduction,
|
|
|
- contact_person=contact_person,
|
|
|
- contact_information=contact_information,
|
|
|
- picture=json.dumps(picture_urls),
|
|
|
- )
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = update(CompanyData).where(CompanyData.id == company_id).values(
|
|
|
+ management_unit=management_unit,
|
|
|
+ custodian_unit=custodian_unit,
|
|
|
+ introduction=introduction,
|
|
|
+ contact_person=contact_person,
|
|
|
+ contact_information=contact_information,
|
|
|
+ picture=json.dumps(picture_urls),
|
|
|
+ )
|
|
|
|
|
|
- session.execute(stmt)
|
|
|
- session.commit()
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
|
|
|
- save_log(request, Module.DATA, OperationType.UPDATE, StatesCode.SUCCESS)
|
|
|
+ save_log(request, Module.DATA, OperationType.UPDATE, StatesCode.SUCCESS)
|
|
|
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='修改成功')
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='修改成功')
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.DATA, OperationType.UPDATE, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
|
|
|
@ns.route('/building_list')
|
|
@@ -369,14 +405,17 @@ class BuildingListApi(Resource):
|
|
|
@ns.doc(id='building_list', description='获取楼宇列表')
|
|
|
def get(self):
|
|
|
"""获取楼宇列表"""
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = select(Building)
|
|
|
+ results = session.execute(stmt).scalars().all()
|
|
|
|
|
|
- with Session(current_app.engine) as session:
|
|
|
- stmt = select(Building)
|
|
|
- results = session.execute(stmt).scalars().all()
|
|
|
-
|
|
|
- save_log(request, Module.DATA, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
+ save_log(request, Module.DATA, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='获取成功', data=to_dict(results))
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='获取成功', data=to_dict(results))
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.DATA, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
|
|
|
building = reqparse.RequestParser(bundle_errors=True)
|
|
@@ -406,15 +445,19 @@ class BuildingApi(Resource):
|
|
|
building_id = request.args.get('building_id')
|
|
|
|
|
|
if building_id is None:
|
|
|
- return jsonify(code=StatesCode.UNKNOWN_ERROR, message='楼宇id不能为空')
|
|
|
+ return jsonify(code=StatesCode.PARA_ERROR, message='楼宇id不能为空')
|
|
|
|
|
|
- with Session(current_app.engine) as session:
|
|
|
- stmt = select(Building).where(Building.id == building_id)
|
|
|
- results = session.execute(stmt).scalars().all()
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = select(Building).where(Building.id == building_id)
|
|
|
+ results = session.execute(stmt).scalars().all()
|
|
|
|
|
|
- save_log(request, Module.DATA, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
+ save_log(request, Module.DATA, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='获取成功', data=to_dict(results))
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='获取成功', data=to_dict(results))
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.DATA, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
@ns.doc(id='add_building', description='增加楼宇')
|
|
|
@ns.expect(building_details)
|
|
@@ -440,24 +483,28 @@ class BuildingApi(Resource):
|
|
|
picture.save(os.path.join(config.common.BUILDING_PICTURE_PATH, picture.filename))
|
|
|
picture_urls.append(config.common.BUILDING_PICTURE_URL + picture.filename)
|
|
|
|
|
|
- with Session(current_app.engine) as session:
|
|
|
- stmt = insert(Building).values(
|
|
|
- name=building_name,
|
|
|
- area=building_area,
|
|
|
- floor=building_floor,
|
|
|
- trem=trem,
|
|
|
- date=date,
|
|
|
- contact_person=contact_person,
|
|
|
- contact_information=contact_information,
|
|
|
- introduction=building_introduction,
|
|
|
- picture=json.dumps(picture_urls)
|
|
|
- )
|
|
|
- session.execute(stmt)
|
|
|
- session.commit()
|
|
|
-
|
|
|
- save_log(request, Module.DATA, OperationType.ADD, StatesCode.SUCCESS)
|
|
|
-
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='添加成功')
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = insert(Building).values(
|
|
|
+ name=building_name,
|
|
|
+ area=building_area,
|
|
|
+ floor=building_floor,
|
|
|
+ trem=trem,
|
|
|
+ date=date,
|
|
|
+ contact_person=contact_person,
|
|
|
+ contact_information=contact_information,
|
|
|
+ introduction=building_introduction,
|
|
|
+ picture=json.dumps(picture_urls)
|
|
|
+ )
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
+
|
|
|
+ save_log(request, Module.DATA, OperationType.ADD, StatesCode.SUCCESS)
|
|
|
+
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='添加成功')
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.DATA, OperationType.ADD, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
@ns.doc(id='update_building', description='修改楼宇')
|
|
|
@ns.expect(building_details)
|
|
@@ -484,24 +531,28 @@ class BuildingApi(Resource):
|
|
|
picture.save(os.path.join(config.common.BUILDING_PICTURE_PATH, picture.filename))
|
|
|
picture_urls.append(config.common.BUILDING_PICTURE_URL + picture.filename)
|
|
|
|
|
|
- with Session(current_app.engine) as session:
|
|
|
- stmt = update(Building).where(Building.id == building_id).values(
|
|
|
- name=building_name,
|
|
|
- area=building_area,
|
|
|
- floor=building_floor,
|
|
|
- trem=trem,
|
|
|
- date=date,
|
|
|
- contact_person=contact_person,
|
|
|
- contact_information=contact_information,
|
|
|
- introduction=building_introduction,
|
|
|
- picture=json.dumps(picture_urls)
|
|
|
- )
|
|
|
- session.execute(stmt)
|
|
|
- session.commit()
|
|
|
-
|
|
|
- save_log(request, Module.DATA, OperationType.UPDATE, StatesCode.SUCCESS)
|
|
|
-
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='修改成功')
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = update(Building).where(Building.id == building_id).values(
|
|
|
+ name=building_name,
|
|
|
+ area=building_area,
|
|
|
+ floor=building_floor,
|
|
|
+ trem=trem,
|
|
|
+ date=date,
|
|
|
+ contact_person=contact_person,
|
|
|
+ contact_information=contact_information,
|
|
|
+ introduction=building_introduction,
|
|
|
+ picture=json.dumps(picture_urls)
|
|
|
+ )
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
+
|
|
|
+ save_log(request, Module.DATA, OperationType.UPDATE, StatesCode.SUCCESS)
|
|
|
+
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='修改成功')
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.DATA, OperationType.UPDATE, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
@ns.doc(id='delete_building', description='删除楼宇')
|
|
|
@ns.expect(building_details)
|
|
@@ -511,14 +562,18 @@ class BuildingApi(Resource):
|
|
|
if building_id is None:
|
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message='楼宇id不能为空')
|
|
|
|
|
|
- with Session(current_app.engine) as session:
|
|
|
- stmt = delete(Building).where(Building.id == building_id)
|
|
|
- session.execute(stmt)
|
|
|
- session.commit()
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = delete(Building).where(Building.id == building_id)
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
|
|
|
- save_log(request, Module.DATA, OperationType.DELETE, StatesCode.SUCCESS)
|
|
|
+ save_log(request, Module.DATA, OperationType.DELETE, StatesCode.SUCCESS)
|
|
|
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='删除成功')
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='删除成功')
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.DATA, OperationType.DELETE, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
|
|
|
underlying_system = reqparse.RequestParser(bundle_errors=True)
|
|
@@ -534,11 +589,17 @@ class UnderlyingSystemMessageApi(Resource):
|
|
|
def get(self):
|
|
|
"""获取底层系统"""
|
|
|
|
|
|
- with Session(current_app.engine) as session:
|
|
|
- stmt = select(UnderlyingSystem)
|
|
|
- results = session.execute(stmt).scalars().all()
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = select(UnderlyingSystem)
|
|
|
+ results = session.execute(stmt).scalars().all()
|
|
|
+
|
|
|
+ save_log(request, Module.DATA, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='添加成功', data=to_dict(results))
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功', data=to_dict(results))
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.DATA, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
@ns.doc(id='update_underlying_system', description='添加底层系统')
|
|
|
@ns.expect(underlying_system)
|
|
@@ -551,11 +612,18 @@ class UnderlyingSystemMessageApi(Resource):
|
|
|
picture.save(os.path.join(config.common.UNDERLYING_SYSTEM_PICTURE_PATH, picture.filename))
|
|
|
picture_url = config.common.UNDERLYING_SYSTEM_PICTURE_URL + picture.filename
|
|
|
|
|
|
- with Session(current_app.engine) as session:
|
|
|
- stmt = insert(UnderlyingSystem).values(
|
|
|
- picture=picture_url
|
|
|
- )
|
|
|
- session.execute(stmt)
|
|
|
- session.commit()
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = insert(UnderlyingSystem).values(
|
|
|
+ picture=picture_url
|
|
|
+ )
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
+
|
|
|
+ save_log(request, Module.DATA, OperationType.ADD, StatesCode.SUCCESS)
|
|
|
+
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功')
|
|
|
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='成功')
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.DATA, OperationType.ADD, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|