From 6208fb1ac317511611c7433e7cb4fc953fd2be5f Mon Sep 17 00:00:00 2001 From: "shimoda.m@nds-tyo.co.jp" Date: Tue, 23 Apr 2024 18:24:24 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=AC=E3=83=93=E3=83=A5=E3=83=BC?= =?UTF-8?q?=E6=8C=87=E6=91=98=E4=BF=AE=E6=AD=A3=E3=80=82=E3=83=87=E3=83=BC?= =?UTF-8?q?=E3=82=BF=E5=AD=98=E5=9C=A8=E3=83=81=E3=82=A7=E3=83=83=E3=82=AF?= =?UTF-8?q?=E3=81=AE=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8=E7=94=9F?= =?UTF-8?q?=E6=88=90=E3=81=AB=E3=80=81=E9=A0=85=E7=9B=AE=E8=AB=96=E7=90=86?= =?UTF-8?q?=E5=90=8D=E3=81=AE=E5=AE=9A=E6=95=B0=E3=82=92=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/model/internal/master_mainte_csv.py | 58 +++++++++++++++---- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/ecs/jskult-webapp/src/model/internal/master_mainte_csv.py b/ecs/jskult-webapp/src/model/internal/master_mainte_csv.py index 6b5b7754..a6146731 100644 --- a/ecs/jskult-webapp/src/model/internal/master_mainte_csv.py +++ b/ecs/jskult-webapp/src/model/internal/master_mainte_csv.py @@ -1,17 +1,17 @@ import csv import json - -from io import TextIOWrapper -from datetime import datetime from abc import ABCMeta, abstractmethod +from datetime import datetime +from io import TextIOWrapper + +from src.logging.get_logger import get_logger +from src.repositories.bu_master_cd_repository import BuMasterRepository +from src.repositories.emp_chg_inst_repository import EmpChgInstRepository +from src.repositories.emp_master_repository import EmpMasterRepository +from src.repositories.generic_kbn_mst_repository import GenericKbnMstRepository +from src.repositories.mst_inst_repository import MstInstRepository from src.system_var import constants from src.util.string_util import is_not_empty -from src.repositories.mst_inst_repository import MstInstRepository -from src.repositories.bu_master_cd_repository import BuMasterRepository -from src.repositories.emp_master_repository import EmpMasterRepository -from src.repositories.emp_chg_inst_repository import EmpChgInstRepository -from src.repositories.generic_kbn_mst_repository import GenericKbnMstRepository -from src.logging.get_logger import get_logger logger = get_logger('マスターメンテ') @@ -119,6 +119,16 @@ class MasterMainteCSVItem(metaclass=ABCMeta): def make_require_error_message(self, line_num: str, col_name: str) -> str: return f'{line_num}行目の{col_name}が入力されておりません。' + def make_data_exist_error_message(self, line_num: str, primary_key_col_names: list[str]) -> str: + return self.__make_check_data_exists_error_message(line_num, primary_key_col_names, 'がすべて同一のデータが既に登録されています。') + + def make_data_not_exist_error_message(self, line_num: str, primary_key_col_names: list[str]) -> str: + return self.__make_check_data_exists_error_message(line_num, primary_key_col_names, 'がすべて同一のデータが存在しないため更新できません。') + + def __make_check_data_exists_error_message(self, line_num: str, primary_key_col_names: list[str], suffix_message: str) -> str: + primary_key_logical_names = '、'.join(primary_key_col_names) + return f'{line_num}行目の{primary_key_logical_names}{suffix_message}' + def __parse_str_to_date(self, check_date: str) -> tuple[bool, datetime]: try: check_date_time: datetime = datetime.strptime(check_date, '%Y%m%d') @@ -363,7 +373,15 @@ class MasterMainteNewInstEmpCSVItem(MasterMainteCSVItem): def check_data_exists(self) -> list[str]: error_list = [] if super().emp_chg_inst_count(self.start_date) > 0: - error_list.append(f'{self.line_num}行目の施設コード、領域コード、担当者種別コード、適用開始日がすべて同一のデータが既に登録されています。') + error_list.append(super().make_data_exist_error_message( + self.line_num, + primary_key_col_names=[ + constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_INST_CD_COL_NO], + constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_TA_CD_COL_NO], + constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_EMP_CHG_TYPE_CD_COL_NO], + constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_START_DATE] + ] + )) return error_list @@ -579,10 +597,26 @@ class MasterMainteChangeInstEmpCSVItem(MasterMainteCSVItem): error_list = [] emp_chg_inst_count = super().emp_chg_inst_count(self.inst_emp_start_date) if self.comment == '追加' and emp_chg_inst_count > 0: - error_list.append(f'{self.line_num}行目の施設コード、領域コード、担当者種別コード、施設担当_開始日がすべて同一のデータが既に登録されています。') + error_list.append(super().make_data_exist_error_message( + self.line_num, + primary_key_col_names=[ + constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_INST_CD_COL_NO], + constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_TA_CD_COL_NO], + constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_EMP_CHG_TYPE_CD_COL_NO], + constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_INST_EMP_START_DATE_COL_NO] + ] + )) elif (self.comment == '終了' or self.comment == '担当者修正') and emp_chg_inst_count == 0: - error_list.append(f'{self.line_num}行目の施設コード、領域コード、担当者種別コード、施設担当_開始日がすべて同一のデータが存在しないため更新できません。') + error_list.append(super().make_data_not_exist_error_message( + self.line_num, + primary_key_col_names=[ + constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_INST_CD_COL_NO], + constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_TA_CD_COL_NO], + constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_EMP_CHG_TYPE_CD_COL_NO], + constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_INST_EMP_START_DATE_COL_NO] + ] + )) return error_list