Merge pull request #385 feature-NEWDWH2021-1540 into develop-emp-chg-inst

This commit is contained in:
下田雅人 2024-04-24 11:12:39 +09:00
commit fa23ae3964

View File

@ -1,17 +1,17 @@
import csv import csv
import json import json
from io import TextIOWrapper
from datetime import datetime
from abc import ABCMeta, abstractmethod 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.system_var import constants
from src.util.string_util import is_not_empty 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('マスターメンテ') logger = get_logger('マスターメンテ')
@ -119,6 +119,16 @@ class MasterMainteCSVItem(metaclass=ABCMeta):
def make_require_error_message(self, line_num: str, col_name: str) -> str: def make_require_error_message(self, line_num: str, col_name: str) -> str:
return f'{line_num}行目の{col_name}が入力されておりません。' 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]: def __parse_str_to_date(self, check_date: str) -> tuple[bool, datetime]:
try: try:
check_date_time: datetime = datetime.strptime(check_date, '%Y%m%d') 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]: def check_data_exists(self) -> list[str]:
error_list = [] error_list = []
if super().emp_chg_inst_count(self.start_date) > 0: 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 return error_list
@ -579,10 +597,26 @@ class MasterMainteChangeInstEmpCSVItem(MasterMainteCSVItem):
error_list = [] error_list = []
emp_chg_inst_count = super().emp_chg_inst_count(self.inst_emp_start_date) emp_chg_inst_count = super().emp_chg_inst_count(self.inst_emp_start_date)
if self.comment == '追加' and emp_chg_inst_count > 0: 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: 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 return error_list