From e29bbe445506c90090c86bf7bd6b452299098791 Mon Sep 17 00:00:00 2001 From: "nik.n" Date: Wed, 17 Apr 2024 18:45:07 +0900 Subject: [PATCH] =?UTF-8?q?=E6=96=BD=E8=A8=AD=E6=8B=85=E5=BD=93=E8=80=85?= =?UTF-8?q?=E5=A4=89=E6=9B=B4=E5=AE=9F=E8=A3=85=E3=83=BB=E6=8C=87=E6=91=98?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/model/db/generic_kbn_mst.py | 19 ------- .../src/model/internal/master_mainte_csv.py | 57 ++++++++++++++----- .../generic_kbn_mst_repository.py | 13 +++-- .../src/services/master_mainte_service.py | 2 +- ecs/jskult-webapp/src/system_var/constants.py | 15 +++-- 5 files changed, 62 insertions(+), 44 deletions(-) delete mode 100644 ecs/jskult-webapp/src/model/db/generic_kbn_mst.py diff --git a/ecs/jskult-webapp/src/model/db/generic_kbn_mst.py b/ecs/jskult-webapp/src/model/db/generic_kbn_mst.py deleted file mode 100644 index ee189cd6..00000000 --- a/ecs/jskult-webapp/src/model/db/generic_kbn_mst.py +++ /dev/null @@ -1,19 +0,0 @@ -from datetime import datetime -from typing import Optional - -from src.model.db.base_db_model import BaseDBModel - - -class GenericKbnMstModel(BaseDBModel): - generic_kbn_cd: Optional[str] - kbn_cd: Optional[str] - kbn_fulll_name_jp: Optional[str] - kbn_full_name_en: Optional[str] - kbn_name: Optional[str] - start_date: Optional[datetime] - end_date: Optional[datetime] - creator: Optional[str] - create_date: Optional[datetime] - updater: Optional[str] - update_date: Optional[datetime] - 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 3f1d5c42..be740eb7 100644 --- a/ecs/jskult-webapp/src/model/internal/master_mainte_csv.py +++ b/ecs/jskult-webapp/src/model/internal/master_mainte_csv.py @@ -63,6 +63,8 @@ class MasterMainteCSVItem(metaclass=ABCMeta): error_list.extend(self.check_inst_cd_exists()) # 担当者種別コード存在チェック error_list.extend(self.check_emp_chg_type_cd_exists()) + # 領域コード存在チェック + error_list.extend(self.check_ta_cd_exists()) # MUID存在チェック error_list.extend(self.check_emp_cd_exists()) # BuCd存在チェック @@ -97,8 +99,11 @@ class MasterMainteCSVItem(metaclass=ABCMeta): def is_exist_inst_cd(self) -> bool: return True if self.mst_inst_repository.fetch_count(self.inst_cd) > 0 else False - def is_exist_emp_chg_type_cd(self) -> bool: - return True if self.generic_kbn_mst_repository.fetch_count(self.emp_chg_type_cd) > 0 else False + def is_exist_emp_chg_type_cd(self, start_date) -> bool: + return True if self.generic_kbn_mst_repository.fetch_count('emp_chg_type_cd', self.emp_chg_type_cd, start_date) > 0 else False + + def is_exist_ta_cd(self, start_date: str) -> bool: + return True if self.generic_kbn_mst_repository.fetch_count('ta_cd', self.ta_cd, start_date) > 0 else False def is_exist_bu_cd(self) -> bool: return True if self.bu_master_repository.fetch_count(self.bu_cd) > 0 else False @@ -175,6 +180,12 @@ class MasterMainteCSVItem(metaclass=ABCMeta): pass ... + @abstractmethod + def check_ta_cd_exists(self) -> list[str]: + """領域コード存在チェック""" + pass + ... + @abstractmethod def check_emp_cd_exists(self) -> list[str]: """MUID存在チェック""" @@ -255,12 +266,12 @@ class MasterMainteNewInstEmpCSVItem(MasterMainteCSVItem): if len(self.ta_cd) == 0: error_list.append(self.make_require_error_message( self.line_num, constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_TA_CD_COL_NO])) - if len(self.emp_cd) == 0: - error_list.append(self.make_require_error_message( - self.line_num, constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_EMP_CD_COL_NO])) if len(self.emp_chg_type_cd) == 0: error_list.append(self.make_require_error_message( self.line_num, constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_EMP_CHG_TYPE_CD_COL_NO])) + if len(self.emp_cd) == 0: + error_list.append(self.make_require_error_message( + self.line_num, constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_EMP_CD_COL_NO])) if len(self.bu_cd) == 0: error_list.append(self.make_require_error_message( self.line_num, constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_BU_CD_COL_NO])) @@ -291,12 +302,19 @@ class MasterMainteNewInstEmpCSVItem(MasterMainteCSVItem): error_list.append(f'{self.line_num}行目の{constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_EMP_CD_COL_NO]}\ は従業員マスタに存在しない もしくは 適用期間外のIDです。') return error_list - + def check_emp_chg_type_cd_exists(self) -> list[str]: error_list = [] - if is_not_empty(self.emp_chg_type_cd) and super().is_exist_emp_chg_type_cd() is False: + if is_not_empty(self.emp_chg_type_cd) and super().is_exist_emp_chg_type_cd(self.start_date) is False: error_list.append(f'{self.line_num}行目の{constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_EMP_CHG_TYPE_CD_COL_NO]}\ -は汎用区分マスタに存在しないコードです。') +は汎用区分マスタに存在しない もしくは 適用期間外のコードです。') + return error_list + + def check_ta_cd_exists(self) -> list[str]: + error_list = [] + if is_not_empty(self.ta_cd) and super().is_exist_ta_cd(self.start_date) is False: + error_list.append(f'{self.line_num}行目の{constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_TA_CD_COL_NO]}\ +は汎用区分マスタに存在しない もしくは 適用期間外のコードです。') return error_list def check_bu_cd_exists(self) -> list[str]: @@ -357,7 +375,8 @@ class MasterMainteChangeInstEmpCSVItem(MasterMainteCSVItem): mst_inst_repository: MstInstRepository, emp_master_repository: EmpMasterRepository, bu_master_repository: BuMasterRepository, - emp_chginst_repository: EmpChgInstRepository + emp_chginst_repository: EmpChgInstRepository, + generic_kbn_mst_repository: GenericKbnMstRepository ): super().__init__( csv_row, @@ -366,7 +385,8 @@ class MasterMainteChangeInstEmpCSVItem(MasterMainteCSVItem): mst_inst_repository, emp_master_repository, bu_master_repository, - emp_chginst_repository + emp_chginst_repository, + generic_kbn_mst_repository ) self.bu_cd = super().get_csv_value(constants.CSV_CHANGE_BU_CD_COL_NO) self.bu_name = super().get_csv_value(constants.CSV_CHANGE_BU_NAME_COL_NO) @@ -376,6 +396,7 @@ class MasterMainteChangeInstEmpCSVItem(MasterMainteCSVItem): self.inst_name = super().get_csv_value(constants.CSV_CHANGE_INST_NAME_COL_NO) self.ta_cd = super().get_csv_value(constants.CSV_CHANGE_TA_CD_COL_NO) self.explain = super().get_csv_value(constants.CSV_CHANGE_EXPLAIN_COL_NO) + self.emp_chg_type_cd = super().get_csv_value(constants.CSV_CHANGE_EMP_CHG_TYPE_CD_COL_NO) self.emp_cd = super().get_csv_value(constants.CSV_CHANGE_EMP_CD_COL_NO) self.emp_full_name = super().get_csv_value(constants.CSV_CHANGE_EMP_FULL_NAME_COL_NO) self.inst_emp_start_date = super().get_csv_value(constants.CSV_CHANGE_INST_EMP_START_DATE_COL_NO) @@ -398,6 +419,9 @@ class MasterMainteChangeInstEmpCSVItem(MasterMainteCSVItem): if len(self.ta_cd) == 0: error_list.append(self.make_require_error_message( self.line_num, constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_TA_CD_COL_NO])) + if len(self.emp_chg_type_cd) == 0: + error_list.append(self.make_require_error_message( + self.line_num, constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_EMP_CHG_TYPE_CD_COL_NO])) if len(self.emp_cd) == 0: error_list.append(self.make_require_error_message( self.line_num, constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_EMP_CD_COL_NO])) @@ -466,9 +490,16 @@ class MasterMainteChangeInstEmpCSVItem(MasterMainteCSVItem): def check_emp_chg_type_cd_exists(self) -> list[str]: error_list = [] - if is_not_empty(self.emp_chg_type_cd) and super().is_exist_emp_chg_type_cd() is False: - error_list.append(f'{self.line_num}行目の{constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_EMP_CHG_TYPE_CD_COL_NO]}\ -は汎用区分マスタに存在しないコードです。') + if is_not_empty(self.emp_chg_type_cd) and super().is_exist_emp_chg_type_cd(self.inst_emp_start_date) is False: + error_list.append(f'{self.line_num}行目の{constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_EMP_CHG_TYPE_CD_COL_NO]}\ +は汎用区分マスタに存在しない もしくは 適用期間外のコードです。') + return error_list + + def check_ta_cd_exists(self) -> list[str]: + error_list = [] + if is_not_empty(self.ta_cd) and super().is_exist_ta_cd(self.inst_emp_start_date) is False: + error_list.append(f'{self.line_num}行目の{constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_TA_CD_COL_NO]}\ +は汎用区分マスタに存在しない もしくは 適用期間外のコードです。') return error_list def check_bu_cd_exists(self) -> list[str]: diff --git a/ecs/jskult-webapp/src/repositories/generic_kbn_mst_repository.py b/ecs/jskult-webapp/src/repositories/generic_kbn_mst_repository.py index 36d59fbd..18995972 100644 --- a/ecs/jskult-webapp/src/repositories/generic_kbn_mst_repository.py +++ b/ecs/jskult-webapp/src/repositories/generic_kbn_mst_repository.py @@ -1,6 +1,4 @@ -from src.model.db.base_db_model import BaseDBModel from src.repositories.base_repository import BaseRepository -from src.model.db.generic_kbn_mst import GenericKbnMstModel from src.model.db.master_mente_count import MasterMenteCountModel from src.logging.get_logger import get_logger @@ -14,13 +12,18 @@ class GenericKbnMstRepository(BaseRepository): FROM src05.generic_kbn_mst WHERE - generic_kbn_mst.kbn_cd = :kbn_cd\ + generic_kbn_mst.generic_kbn_cd = :generic_kbn_cd + AND + generic_kbn_mst.kbn_cd = :kbn_cd + AND + STR_TO_DATE( :start_date , '%Y%m%d') BETWEEN generic_kbn_mst.start_date AND generic_kbn_mst.end_date\ """ - def fetch_count(self, parameter) -> MasterMenteCountModel: + + def fetch_count(self, generic_kbn_cd, kbn_cd, start_date) -> MasterMenteCountModel: try: query = self.FETCH_SQL - result = self._database.execute_select(query, {'kbn_cd': parameter}) + result = self._database.execute_select(query, {'generic_kbn_cd': generic_kbn_cd, 'kbn_cd': kbn_cd, 'start_date' : start_date}) models = [MasterMenteCountModel(**r) for r in result] if len(models) == 0: return 0 diff --git a/ecs/jskult-webapp/src/services/master_mainte_service.py b/ecs/jskult-webapp/src/services/master_mainte_service.py index d7e85638..168f1075 100644 --- a/ecs/jskult-webapp/src/services/master_mainte_service.py +++ b/ecs/jskult-webapp/src/services/master_mainte_service.py @@ -73,7 +73,7 @@ class MasterMainteService(BaseService): raise Exception(f'登録テーブルの選択値が不正です: {csv_upload_form.select_table}') (table_name, selected_table_msg) = self.__choose_target_table(csv_upload_form.select_table) - +# TODO csv_items = MasterMainteCSVItems( file, csv_upload_form.select_function, diff --git a/ecs/jskult-webapp/src/system_var/constants.py b/ecs/jskult-webapp/src/system_var/constants.py index f592f370..5bd8a878 100644 --- a/ecs/jskult-webapp/src/system_var/constants.py +++ b/ecs/jskult-webapp/src/system_var/constants.py @@ -119,6 +119,7 @@ CHANGE_INST_CSV_LOGICAL_NAMES = [ '施設名', '領域コード', '説明', + '担当者種別コード', 'MUID', '担当者名', '施設担当_開始日', @@ -142,18 +143,20 @@ CSV_CHANGE_INST_NAME_COL_NO = 5 CSV_CHANGE_TA_CD_COL_NO = 6 # 説明の列No CSV_CHANGE_EXPLAIN_COL_NO = 7 +# 担当者種別コード +CSV_CHANGE_EMP_CHG_TYPE_CD_COL_NO = 8 # MUIDの列No -CSV_CHANGE_EMP_CD_COL_NO = 8 +CSV_CHANGE_EMP_CD_COL_NO = 9 # 担当者名の列No -CSV_CHANGE_EMP_FULL_NAME_COL_NO = 9 +CSV_CHANGE_EMP_FULL_NAME_COL_NO = 10 # 施設担当_開始日の列No -CSV_CHANGE_INST_EMP_START_DATE_COL_NO = 10 +CSV_CHANGE_INST_EMP_START_DATE_COL_NO = 11 # 施設担当_終了日の列No -CSV_CHANGE_INST_EMP_END_DATE_COL_NO = 11 +CSV_CHANGE_INST_EMP_END_DATE_COL_NO = 12 # 終了日の変更の列No -CSV_CHANGE_CHANGE_END_DATE_COL_NO = 12 +CSV_CHANGE_CHANGE_END_DATE_COL_NO = 13 # コメントの列No -CSV_CHANGE_COMMENT = 13 +CSV_CHANGE_COMMENT = 14 # CSVアップロードテーブル名(マスターメンテ) CSV_REAL_TABLE_NAME = '本番テーブル'