This commit is contained in:
Gitea
2022-07-14 16:21:44 +09:00
parent 8245c32224
commit 592a174bb7
15 changed files with 123 additions and 75 deletions

View File

@ -35,6 +35,19 @@ def exec_procedure_wo_result(session, proc_name, params, database: str = None):
sql_string, params).fetchall()
session.commit()
def exec_procedure_no_result(session, proc_name, params, database: str = None):
sql_params = ",".join([f"@{key} = :{key}"
for key, value in params.items()])
dbstr = ""
if database:
dbstr = f"[{database}]."
sql_string = sql.text(f'''
EXEC {dbstr}[dbo].[{proc_name}] {sql_params};
''')
session.execute(
sql_string, params)
session.commit()
"""PersonalAccountViewSet"""
@ -45,7 +58,7 @@ class PersonalAccountViewSet:
def get_details(db: Session, id: int = None):
table = get_table("PersonalAccount")
return db.query(table).filter(table.c["ID"] == id).first()
return db.query(table).filter(table.c["ID"] == id).all()
def get_services(db: Session, IDPersonalAccount: int = None):
return exec_procedure(db, 'uspGetPersonalAccountServices', {'IDPersonalAccount': IDPersonalAccount})
@ -59,16 +72,18 @@ class PersonalAccountViewSet:
def get_financial_account(db: Session, data: schemas.PersonalAccountReportTOFinancialInit = None):
return exec_procedure(db, 'uspGetPersonalAccountReportTOFinancialAccount', data.dict())
def edit(db: Session, data: schemas.PersonalAccountDetailsInit = None):
return exec_procedure_no_result(db, 'uspEditPersonalAccount', data.dict())
"""AddressInfoViewSet"""
class AddressInfoViewSet:
class AddressViewSet:
"""get"""
def get_details(db: Session, id: int = None):
table = get_table("RefAddresses", "General")
return db.query(table).filter(table.c["ID"] == id).first()
return db.query(table).filter(table.c["ID"] == id).all()
def get_personal_accounts(db: Session, IDCity: int = None):
return exec_procedure(db, 'uspGetPersonalAccountsList', {'IDCity': IDCity})
@ -88,18 +103,7 @@ class AddressInfoViewSet:
"""post"""
def edit(db: Session, data: schemas.EditAdressInit = None):
try:
exec_procedure_wo_result(db, 'uspEditAddress', **data)
return {'msg': 'success'}
except:
return {'msg': 'error'}
def edit_personal_account(db: Session, data: schemas.PersonalAccountDetailsSerializer = None):
try:
exec_procedure_wo_result(db, 'uspEditPersonalAccount', **data)
return {'msg': 'success'}
except:
return {'msg': 'error'}
exec_procedure_no_result(db, 'uspEditAddress', data.dict())
def edit_personal_account_address(db: Session, data: schemas.EditPersonalAccountAddressInit = None):
try:
@ -134,34 +138,18 @@ class ObjectViewSet:
"""post"""
def edit(db: Session, data: schemas.ObjectDetailsSerializer = None):
try:
exec_procedure_wo_result(db, 'uspEditObject', **data)
return {'msg': 'success'}
except:
return {'msg': 'error'}
def edit(db: Session, data: schemas.ObjectEditInit = None):
exec_procedure_no_result(db, 'uspEditObject', data.dict())
def edit_service(db: Session, data: schemas.EditObjectServiceInit = None):
try:
exec_procedure_wo_result(db, 'uspEditObject', **data)
return {'msg': 'success'}
except:
return {'msg': 'error'}
exec_procedure_no_result(db, 'uspEditObject', data.dict())
def edit_temp_metering_device_address(db: Session, data: schemas.EditTempMeteringDeviceAddressInit = None):
try:
exec_procedure_wo_result(
exec_procedure_no_result(
db, 'uspEditTempMeteringDeviceAddress', **data, database='General')
return {'msg': 'success'}
except:
return {'msg': 'error'}
def add_object(db: Session, data: schemas.AddObjectInit = None):
try:
exec_procedure_wo_result(db, 'uspAddObject', **data)
return {'msg': 'success'}
except:
return {'msg': 'error'}
exec_procedure_no_result(db, 'uspAddObject', **data)
"""TurnOverViewSet"""
@ -212,10 +200,10 @@ class PaymentViewSet:
return exec_procedure(db, 'uspSaveReceipt', data.dict())
def repayment_info(db: Session, data: schemas.RepaymentInfoInit):
return exec_procedure(db, 'uspGetRepaymentInfo', **data)
return exec_procedure(db, 'uspGetRepaymentInfo', data.dict())
def repayment(db: Session, data: schemas.RepaymentInit):
return exec_procedure(db, 'uspRepayment', **data)
return exec_procedure(db, 'uspRepayment', data.dict())
"""ReportViewSet"""
@ -270,11 +258,7 @@ class RecalculationViewSet:
return {'msg': 'error'}
def save_recalculation(db: Session, data: schemas.RecalculationSave = None):
try:
exec_procedure_wo_result(db, 'uspSaveRecalculation', data.dict())
return {'msg': 'success'}
except:
return {'msg': 'error'}
exec_procedure_no_result(db, 'uspSaveRecalculation', data.dict())
"""ReferenceViewSet"""
@ -409,7 +393,7 @@ class ReferenceViewSet:
return exec_procedure(db, 'uspGetMeteringDeviceTypes', params=data, database='General')
def get_object_water_system_volumes(db: Session, data: schemas.ObjectWaterSystemVolumesInit):
return exec_procedure(db, 'uspGetObjectWaterSystemVolumes', **data)
return exec_procedure(db, 'uspGetObjectWaterSystemVolumes', data.dict())
def get_tariff_population(db: Session, data: schemas.TariffsPopulationInit):
return exec_procedure(db, 'uspGetTariffsPopulation', **data)