278 lines
11 KiB
Python
278 lines
11 KiB
Python
from io import BytesIO, TextIOWrapper
|
|
from typing import Optional
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException, Request
|
|
from fastapi.responses import HTMLResponse
|
|
from starlette import status
|
|
|
|
from src.depends.services import get_service
|
|
from src.model.internal.session import UserSession
|
|
from src.model.request.master_mainte_csvup import MasterMainteCsvUpModel
|
|
from src.model.view.inst_emp_csv_download_view_model import \
|
|
InstEmpCsvDownloadViewModel
|
|
from src.model.view.inst_emp_csv_upload_view_model import \
|
|
InstEmpCsvUploadViewModel
|
|
from src.model.view.master_mainte_menu_view_model import \
|
|
MasterMainteMenuViewModel
|
|
from src.model.view.table_override_view_model import TableOverrideViewModel
|
|
from src.router.session_router import AuthenticatedRoute
|
|
from src.services.batch_status_service import BatchStatusService
|
|
from src.services.master_mainte_service import MasterMainteService
|
|
from src.services.session_service import set_session
|
|
from src.system_var import constants
|
|
from src.templates import templates
|
|
|
|
router = APIRouter()
|
|
router.route_class = AuthenticatedRoute
|
|
|
|
#########################
|
|
# Views #
|
|
#########################
|
|
|
|
|
|
@router.get('/masterMainteMenu', response_class=HTMLResponse)
|
|
def menu_view(
|
|
request: Request,
|
|
batch_status_service: BatchStatusService = Depends(get_service(BatchStatusService))
|
|
):
|
|
session: UserSession = request.session
|
|
|
|
# マスタメンテメニューへのアクセス権がない場合、ログアウトさせる
|
|
if session.master_mainte_flg != '1':
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN)
|
|
|
|
# バッチ処理中の場合、ログアウトさせる
|
|
if batch_status_service.is_batch_processing():
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,
|
|
detail=constants.LOGOUT_REASON_BATCH_PROCESSING_FOR_MAINTE)
|
|
# dump処理中の場合、ログアウトさせる
|
|
if batch_status_service.is_dump_processing():
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=constants.LOGOUT_REASON_BACKUP_PROCESSING)
|
|
|
|
# 画面表示用のモデル
|
|
menu = MasterMainteMenuViewModel()
|
|
# セッション書き換え
|
|
session.update(
|
|
actions=[
|
|
UserSession.last_access_time.set(UserSession.new_last_access_time()),
|
|
UserSession.record_expiration_time.set(UserSession.new_record_expiration_time()),
|
|
]
|
|
)
|
|
set_session(session)
|
|
templates_response = templates.TemplateResponse(
|
|
'masterMainteMenu.html',
|
|
{
|
|
'request': request,
|
|
'menu': menu
|
|
},
|
|
headers={'session_key': session.session_key}
|
|
)
|
|
return templates_response
|
|
|
|
|
|
@router.get('/instEmpCsvUL', response_class=HTMLResponse)
|
|
def inst_emp_csv_upload_view(
|
|
request: Request,
|
|
batch_status_service: BatchStatusService = Depends(get_service(BatchStatusService))
|
|
):
|
|
session: UserSession = request.session
|
|
|
|
# マスタメンテメニューへのアクセス権がない場合、ログアウトさせる
|
|
if session.master_mainte_flg != '1':
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN)
|
|
|
|
# バッチ処理中の場合、ログアウトさせる
|
|
if batch_status_service.is_batch_processing():
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,
|
|
detail=constants.LOGOUT_REASON_BATCH_PROCESSING_FOR_MAINTE)
|
|
# dump処理中の場合、ログアウトさせる
|
|
if batch_status_service.is_dump_processing():
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=constants.LOGOUT_REASON_BACKUP_PROCESSING)
|
|
|
|
# 画面表示用のモデル
|
|
mainte_csv_up = InstEmpCsvUploadViewModel()
|
|
# セッション書き換え
|
|
session.update(
|
|
actions=[
|
|
UserSession.last_access_time.set(UserSession.new_last_access_time()),
|
|
UserSession.record_expiration_time.set(UserSession.new_record_expiration_time()),
|
|
]
|
|
)
|
|
set_session(session)
|
|
templates_response = templates.TemplateResponse(
|
|
'instEmpCsvUL.html',
|
|
{
|
|
'request': request,
|
|
'mainte_csv_up': mainte_csv_up
|
|
},
|
|
headers={'session_key': session.session_key}
|
|
)
|
|
return templates_response
|
|
|
|
|
|
@router.post('/instEmpCsvUL', response_class=HTMLResponse)
|
|
async def inst_emp_csv_upload(
|
|
request: Request,
|
|
csv_upload_form: Optional[MasterMainteCsvUpModel] = Depends(MasterMainteCsvUpModel.as_form),
|
|
master_mainte_service: MasterMainteService = Depends(get_service(MasterMainteService)),
|
|
batch_status_service: BatchStatusService = Depends(get_service(BatchStatusService))
|
|
):
|
|
session: UserSession = request.session
|
|
|
|
# マスタメンテメニューへのアクセス権がない場合、ログアウトさせる
|
|
if session.master_mainte_flg != '1':
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN)
|
|
|
|
# バッチ処理中の場合、ログアウトさせる
|
|
if batch_status_service.is_batch_processing():
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,
|
|
detail=constants.LOGOUT_REASON_BATCH_PROCESSING_FOR_MAINTE)
|
|
# dump処理中の場合、ログアウトさせる
|
|
if batch_status_service.is_dump_processing():
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=constants.LOGOUT_REASON_BACKUP_PROCESSING)
|
|
|
|
# 画面表示用のモデル
|
|
mainte_csv_up = master_mainte_service.prepare_mainte_csv_up_view(
|
|
TextIOWrapper(BytesIO(await csv_upload_form.csv_file.read())),
|
|
csv_upload_form.csv_file.filename,
|
|
csv_upload_form)
|
|
# セッション書き換え
|
|
session.update(
|
|
actions=[
|
|
UserSession.last_access_time.set(UserSession.new_last_access_time()),
|
|
UserSession.record_expiration_time.set(UserSession.new_record_expiration_time()),
|
|
]
|
|
)
|
|
set_session(session)
|
|
templates_response = templates.TemplateResponse(
|
|
'instEmpCsvUL.html',
|
|
{
|
|
'request': request,
|
|
'mainte_csv_up': mainte_csv_up
|
|
},
|
|
headers={'session_key': session.session_key}
|
|
)
|
|
return templates_response
|
|
|
|
|
|
@router.post('/newInst', response_class=HTMLResponse)
|
|
def new_inst_result_view(
|
|
request: Request,
|
|
csv_upload_form: Optional[MasterMainteCsvUpModel] = Depends(MasterMainteCsvUpModel.as_form),
|
|
master_mainte_service: MasterMainteService = Depends(get_service(MasterMainteService)),
|
|
batch_status_service: BatchStatusService = Depends(get_service(BatchStatusService))
|
|
):
|
|
session: UserSession = request.session
|
|
|
|
# マスタメンテメニューへのアクセス権がない場合、ログアウトさせる
|
|
if session.master_mainte_flg != '1':
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN)
|
|
|
|
# バッチ処理中の場合、ログアウトさせる
|
|
if batch_status_service.is_batch_processing():
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,
|
|
detail=constants.LOGOUT_REASON_BATCH_PROCESSING_FOR_MAINTE)
|
|
# dump処理中の場合、ログアウトさせる
|
|
if batch_status_service.is_dump_processing():
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=constants.LOGOUT_REASON_BACKUP_PROCESSING)
|
|
|
|
# 画面表示用のモデル
|
|
mainte_csv_up = master_mainte_service.prepare_mainte_new_inst_view(session.user_id, csv_upload_form)
|
|
# セッション書き換え
|
|
session.update(
|
|
actions=[
|
|
UserSession.last_access_time.set(UserSession.new_last_access_time()),
|
|
UserSession.record_expiration_time.set(UserSession.new_record_expiration_time()),
|
|
]
|
|
)
|
|
set_session(session)
|
|
templates_response = templates.TemplateResponse(
|
|
'instEmpCsvUL.html',
|
|
{
|
|
'request': request,
|
|
'mainte_csv_up': mainte_csv_up
|
|
},
|
|
headers={'session_key': session.session_key}
|
|
)
|
|
return templates_response
|
|
|
|
|
|
@ router.get('/instEmpCsvDL', response_class=HTMLResponse)
|
|
def inst_emp_csv_download_view(
|
|
request: Request,
|
|
batch_status_service: BatchStatusService = Depends(get_service(BatchStatusService))
|
|
):
|
|
session: UserSession = request.session
|
|
|
|
# マスタメンテメニューへのアクセス権がない場合、ログアウトさせる
|
|
if session.master_mainte_flg != '1':
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN)
|
|
|
|
# バッチ処理中の場合、ログアウトさせる
|
|
if batch_status_service.is_batch_processing():
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,
|
|
detail=constants.LOGOUT_REASON_BATCH_PROCESSING_FOR_MAINTE)
|
|
# dump処理中の場合、ログアウトさせる
|
|
if batch_status_service.is_dump_processing():
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=constants.LOGOUT_REASON_BACKUP_PROCESSING)
|
|
|
|
# 画面表示用のモデル
|
|
view_model = InstEmpCsvDownloadViewModel()
|
|
# セッション書き換え
|
|
session.update(
|
|
actions=[
|
|
UserSession.last_access_time.set(UserSession.new_last_access_time()),
|
|
UserSession.record_expiration_time.set(UserSession.new_record_expiration_time()),
|
|
]
|
|
)
|
|
set_session(session)
|
|
templates_response = templates.TemplateResponse(
|
|
'instEmpCsvDL.html',
|
|
{
|
|
'request': request,
|
|
'view': view_model
|
|
},
|
|
headers={'session_key': session.session_key}
|
|
)
|
|
return templates_response
|
|
|
|
|
|
@router.get('/tableOverride', response_class=HTMLResponse)
|
|
def table_override_view(
|
|
request: Request,
|
|
batch_status_service: BatchStatusService = Depends(get_service(BatchStatusService))
|
|
):
|
|
session: UserSession = request.session
|
|
|
|
# マスタメンテメニューへのアクセス権がない場合、ログアウトさせる
|
|
if session.master_mainte_flg != '1':
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN)
|
|
|
|
# バッチ処理中の場合、ログアウトさせる
|
|
if batch_status_service.is_batch_processing():
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,
|
|
detail=constants.LOGOUT_REASON_BATCH_PROCESSING_FOR_MAINTE)
|
|
# dump処理中の場合、ログアウトさせる
|
|
if batch_status_service.is_dump_processing():
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=constants.LOGOUT_REASON_BACKUP_PROCESSING)
|
|
|
|
# 画面表示用のモデル
|
|
view_model = TableOverrideViewModel()
|
|
# セッション書き換え
|
|
session.update(
|
|
actions=[
|
|
UserSession.last_access_time.set(UserSession.new_last_access_time()),
|
|
UserSession.record_expiration_time.set(UserSession.new_record_expiration_time()),
|
|
]
|
|
)
|
|
set_session(session)
|
|
templates_response = templates.TemplateResponse(
|
|
'tableOverride.html',
|
|
{
|
|
'request': request,
|
|
'view': view_model
|
|
},
|
|
headers={'session_key': session.session_key}
|
|
)
|
|
return templates_response
|