|
@@ -9,7 +9,7 @@ from sqlalchemy.orm import Session
|
|
|
from werkzeug.datastructures import FileStorage
|
|
|
|
|
|
from app.defines import StatesCode, Module, OperationType
|
|
|
-from app.modle.data import Template, CompanyData, Building, UnderlyingSystem
|
|
|
+from app.modle.data import Template, Building, UnderlyingSystem
|
|
|
from app.utils.jwt_util import login_required
|
|
|
from app.utils.save_log import save_log
|
|
|
from app.utils.util import to_dict, cn_now
|
|
@@ -28,6 +28,9 @@ template_list.add_argument(name='report_type', type=str, location='args', requir
|
|
|
|
|
|
config = Config()
|
|
|
|
|
|
+manage_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
|
|
+company_file_path = os.path.join(manage_path, 'config', 'company_data.json')
|
|
|
+
|
|
|
|
|
|
@ns.route('/template_list')
|
|
|
class TemplateConfigListApi(Resource):
|
|
@@ -264,11 +267,7 @@ class BatchTemplateConfigApi(Resource):
|
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
|
|
|
-company_id = reqparse.RequestParser(bundle_errors=True)
|
|
|
-company_id.add_argument(name='company_id', type=int, location='args', required=False, help='公司id')
|
|
|
-
|
|
|
company_data = reqparse.RequestParser(bundle_errors=True)
|
|
|
-company_data.add_argument(name='company_id', type=int, location='form', required=False, help='公司id')
|
|
|
company_data.add_argument(name='management_unit', type=str, location='form', required=False, help='管理单位')
|
|
|
company_data.add_argument(name='custodian_unit', type=str, location='form', required=False, help='托管单位')
|
|
|
company_data.add_argument(name='introduction', type=str, location='form', required=False, help='楼宇简介')
|
|
@@ -282,22 +281,16 @@ class CompanyApi(Resource):
|
|
|
method_decorators = [login_required]
|
|
|
|
|
|
@ns.doc(id='get_company', description='获取公司信息')
|
|
|
- @ns.expect(company_id)
|
|
|
def get(self):
|
|
|
"""获取公司基本信息"""
|
|
|
- company_id = request.args.get('company_id')
|
|
|
-
|
|
|
- if company_id is None:
|
|
|
- return jsonify(code=StatesCode.PARA_ERROR, message='公司id不能为空')
|
|
|
-
|
|
|
try:
|
|
|
- with Session(current_app.engine) as session:
|
|
|
- stmt = select(CompanyData).where(CompanyData.id == company_id)
|
|
|
- results = session.execute(stmt).scalars().all()
|
|
|
+ # 公司基本信息写入本地文件
|
|
|
+ with open(company_file_path, 'r') as f:
|
|
|
+ data = f.read()
|
|
|
|
|
|
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=json.loads(data))
|
|
|
|
|
|
except Exception as e:
|
|
|
save_log(request, Module.DATA, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
|
|
@@ -314,9 +307,6 @@ class CompanyApi(Resource):
|
|
|
contact_information = request.form.get('contact_information')
|
|
|
pictures = request.files.getlist('picture')
|
|
|
|
|
|
- if management_unit is None:
|
|
|
- return jsonify(code=StatesCode.UNKNOWN_ERROR, message='管理单位不能为空')
|
|
|
-
|
|
|
pictures_base64 = []
|
|
|
|
|
|
if pictures:
|
|
@@ -326,26 +316,18 @@ class CompanyApi(Resource):
|
|
|
base64_data = base64_data.decode('utf-8')
|
|
|
pictures_base64.append(base64_data)
|
|
|
|
|
|
+ data = {
|
|
|
+ 'management_unit': management_unit,
|
|
|
+ 'custodian_unit': custodian_unit,
|
|
|
+ 'introduction': introduction,
|
|
|
+ 'contact_person': contact_person,
|
|
|
+ 'contact_information': contact_information,
|
|
|
+ 'pictures': pictures_base64
|
|
|
+ }
|
|
|
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(pictures_base64),
|
|
|
- )
|
|
|
- session.execute(stmt)
|
|
|
-
|
|
|
- session.commit()
|
|
|
+ # 公司基本信息写入本地文件
|
|
|
+ with open(company_file_path, 'w') as f:
|
|
|
+ f.write(json.dumps(data, ensure_ascii=False))
|
|
|
|
|
|
save_log(request, Module.DATA, OperationType.ADD, StatesCode.SUCCESS)
|
|
|
|
|
@@ -359,7 +341,6 @@ class CompanyApi(Resource):
|
|
|
def put(self):
|
|
|
"""修改公司基本信息"""
|
|
|
|
|
|
- company_id = request.form.get('company_id')
|
|
|
management_unit = request.form.get('management_unit')
|
|
|
custodian_unit = request.form.get('custodian_unit')
|
|
|
introduction = request.form.get('introduction')
|
|
@@ -367,32 +348,28 @@ class CompanyApi(Resource):
|
|
|
contact_information = request.form.get('contact_information')
|
|
|
pictures = request.files.getlist('picture')
|
|
|
|
|
|
- if company_id is None:
|
|
|
- return jsonify(code=StatesCode.PARA_ERROR, message='公司id不能为空')
|
|
|
-
|
|
|
pictures_base64 = []
|
|
|
|
|
|
if pictures:
|
|
|
for picture in pictures:
|
|
|
-
|
|
|
ext = picture.filename.split('.')[-1]
|
|
|
base64_data = b'data:image/%s;base64,' % ext.encode('utf-8') + base64.b64encode(picture.read())
|
|
|
base64_data = base64_data.decode('utf-8')
|
|
|
pictures_base64.append(base64_data)
|
|
|
|
|
|
- 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(pictures_base64),
|
|
|
- )
|
|
|
+ data = {
|
|
|
+ 'management_unit': management_unit,
|
|
|
+ 'custodian_unit': custodian_unit,
|
|
|
+ 'introduction': introduction,
|
|
|
+ 'contact_person': contact_person,
|
|
|
+ 'contact_information': contact_information,
|
|
|
+ 'pictures': pictures_base64
|
|
|
+ }
|
|
|
|
|
|
- session.execute(stmt)
|
|
|
- session.commit()
|
|
|
+ try:
|
|
|
+ # 公司基本信息写入本地文件
|
|
|
+ with open(company_file_path, 'w') as f:
|
|
|
+ f.write(json.dumps(data, ensure_ascii=False))
|
|
|
|
|
|
save_log(request, Module.DATA, OperationType.UPDATE, StatesCode.SUCCESS)
|
|
|
|
|
@@ -483,7 +460,6 @@ class BuildingApi(Resource):
|
|
|
pictures_base64 = []
|
|
|
if pictures:
|
|
|
for picture in pictures:
|
|
|
-
|
|
|
ext = picture.filename.split('.')[-1]
|
|
|
base64_data = b'data:image/%s;base64,' % ext.encode('utf-8') + base64.b64encode(picture.read())
|
|
|
base64_data = base64_data.decode('utf-8')
|
|
@@ -533,7 +509,6 @@ class BuildingApi(Resource):
|
|
|
pictures_base64 = []
|
|
|
if pictures:
|
|
|
for picture in pictures:
|
|
|
-
|
|
|
ext = picture.filename.split('.')[-1]
|
|
|
base64_data = b'data:image/%s;base64,' % ext.encode('utf-8') + base64.b64encode(picture.read())
|
|
|
base64_data = base64_data.decode('utf-8')
|
|
@@ -637,3 +612,7 @@ class UnderlyingSystemMessageApi(Resource):
|
|
|
except Exception as e:
|
|
|
save_log(request, Module.DATA, OperationType.ADD, StatesCode.UNKNOWN_ERROR)
|
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ print(manage_path)
|