diff --git a/ecs/jskult-webapp/src/repositories/bio_sales_lot_repository.py b/ecs/jskult-webapp/src/repositories/bio_sales_lot_repository.py index 8816636b..30e2b562 100644 --- a/ecs/jskult-webapp/src/repositories/bio_sales_lot_repository.py +++ b/ecs/jskult-webapp/src/repositories/bio_sales_lot_repository.py @@ -101,6 +101,9 @@ class BioSalesLotRepository(BaseRepository): def __build_condition(self, parameter: BioModel): where_clauses: list[SQLCondition] = [] + # 検索条件が指定されずにSQLが壊れることを予防するため、常に真の固定条件を追加しておく + where_clauses.append(SQLCondition('', '', '1 = 1', literal=True)) + # 卸(コード/サブコード) if is_not_empty(parameter.rec_whs_cd) and is_not_empty(parameter.rec_whs_sub_cd): where_clauses.append(SQLCondition('rec_whs_cd', condition.EQ, 'rec_whs_cd')) @@ -141,5 +144,6 @@ class BioSalesLotRepository(BaseRepository): where_clauses.append(SQLCondition('LENGTH(TRIM(rec_lot_num))', condition.GT, '0', literal=True)) where_clauses_str = ' AND '.join([condition.apply() for condition in where_clauses]) + logger.debug(f'条件設定終了:{where_clauses_str}') return where_clauses_str diff --git a/ecs/jskult-webapp/src/repositories/emp_chg_inst_repository.py b/ecs/jskult-webapp/src/repositories/emp_chg_inst_repository.py index ce32a244..fc362257 100644 --- a/ecs/jskult-webapp/src/repositories/emp_chg_inst_repository.py +++ b/ecs/jskult-webapp/src/repositories/emp_chg_inst_repository.py @@ -13,7 +13,7 @@ class EmpChgInstRepository(BaseRepository): def connect(self): self._database.connect() - + def to_jst(self): self._database.to_jst() @@ -179,11 +179,11 @@ class EmpChgInstRepository(BaseRepository): FROM {table_name} AS eci LEFT JOIN mst_inst AS mi - ON eci.inst_cd = mi.inst_cd + ON eci.inst_cd = mi.inst_cd LEFT JOIN emp - ON eci.emp_cd = emp.emp_cd + ON eci.emp_cd = emp.emp_cd LEFT JOIN bu - ON eci.bu_cd = bu.bu_cd + ON eci.bu_cd = bu.bu_cd WHERE {where_clause} """ @@ -206,6 +206,9 @@ class EmpChgInstRepository(BaseRepository): def __build_condition(self, parameter: MasterMainteCsvDlModel): where_clauses: list[SQLCondition] = [] + # 検索条件が指定されずにSQLが壊れることを予防するため、常に真の固定条件を追加しておく + where_clauses.append(SQLCondition('', '', '1 = 1', literal=True)) + # 領域コードが入力されていた場合 if is_not_empty(parameter.ta_cd): parameter.adapt_ta_cd = f'%{parameter.ta_cd}%' @@ -223,62 +226,43 @@ class EmpChgInstRepository(BaseRepository): # 適用期間内が入力されていた場合 if is_not_empty(parameter.adapt_apply_date_from): - where_clauses.append(SQLCondition('eci.start_date', - condition.LE, - 'adapt_apply_date_from')) - where_clauses.append(SQLCondition('eci.end_date', - condition.GE, - 'adapt_apply_date_from')) + where_clauses.append(SQLCondition('eci.start_date', condition.LE, 'adapt_apply_date_from')) + where_clauses.append(SQLCondition('eci.end_date', condition.GE, 'adapt_apply_date_from')) # 適用開始日(FROM)が入力されていた場合 if is_not_empty(parameter.adapt_start_date_from): - where_clauses.append(SQLCondition('eci.start_date', - condition.GE, - 'adapt_start_date_from')) + where_clauses.append(SQLCondition('eci.start_date', condition.GE, 'adapt_start_date_from')) # 適用開始日(TO)が入力されていた場合 if is_not_empty(parameter.adapt_start_date_to): - where_clauses.append(SQLCondition('eci.start_date', - condition.LE, - 'adapt_start_date_to')) + where_clauses.append(SQLCondition('eci.start_date', condition.LE, 'adapt_start_date_to')) # 適用終了日(FROM)が入力されていた場合 if is_not_empty(parameter.adapt_end_date_from): - where_clauses.append(SQLCondition('eci.end_date', - condition.GE, - 'adapt_end_date_from')) + where_clauses.append(SQLCondition('eci.end_date', condition.GE, 'adapt_end_date_from')) # 適用終了日(TO)が入力されていた場合 if is_not_empty(parameter.adapt_end_date_to): - where_clauses.append(SQLCondition('eci.end_date', - condition.LE, - 'adapt_end_date_to')) + where_clauses.append(SQLCondition('eci.end_date', condition.LE, 'adapt_end_date_to')) # データ作成日(FROM)が入力されていた場合 if is_not_empty(parameter.adapt_create_date_from): - where_clauses.append(SQLCondition('eci.create_date', - condition.GE, - 'adapt_create_date_from')) + where_clauses.append(SQLCondition('eci.create_date', condition.GE, 'adapt_create_date_from')) # データ作成日(TO)が入力されていた場合 if is_not_empty(parameter.adapt_create_date_to): - where_clauses.append(SQLCondition('eci.create_date', - condition.LE, - 'adapt_create_date_to')) + where_clauses.append(SQLCondition('eci.create_date', condition.LE, 'adapt_create_date_to')) # データ更新日(FROM)が入力されていた場合 if is_not_empty(parameter.adapt_update_date_from): - where_clauses.append(SQLCondition('eci.update_date', - condition.GE, - 'adapt_update_date_from')) + where_clauses.append(SQLCondition('eci.update_date', condition.GE, 'adapt_update_date_from')) # データ更新日(TO)が入力されていた場合 if is_not_empty(parameter.adapt_update_date_to): - where_clauses.append(SQLCondition('eci.update_date', - condition.LE, - 'adapt_update_date_to')) + where_clauses.append(SQLCondition('eci.update_date', condition.LE, 'adapt_update_date_to')) where_clauses_str = ' AND '.join([condition.apply() for condition in where_clauses]) + logger.debug(f'条件設定終了:{where_clauses_str}') return where_clauses_str diff --git a/ecs/jskult-webapp/src/repositories/ultmarc_doctor_repository.py b/ecs/jskult-webapp/src/repositories/ultmarc_doctor_repository.py index 810f045d..a60a3583 100644 --- a/ecs/jskult-webapp/src/repositories/ultmarc_doctor_repository.py +++ b/ecs/jskult-webapp/src/repositories/ultmarc_doctor_repository.py @@ -7,6 +7,7 @@ from src.model.db.ultmarc_doctor import UltmarcDoctorDBModel from src.model.db.ultmarc_doctor_info import UltmarcDoctorInfoDBModel from src.model.request.ultmarc_doctor import UltmarcDoctorSearchModel from src.repositories.base_repository import BaseRepository +from src.system_var import environment from src.util.string_util import is_not_empty logger = get_logger('COM_医師取得') @@ -46,6 +47,7 @@ class UltmarcDoctorRepository(BaseRepository): com_dr_wrkplace.dcf_dsf_inst_cd, com_dr_wrkplace.blng_sec_cd, com_dr_trt_course.trt_course_cd + LIMIT {limit} \ """ @@ -55,7 +57,8 @@ class UltmarcDoctorRepository(BaseRepository): # 文字列の検索を部分一致にするため、モデルをコピー。以降はこのコピーを使用する。 clone_parameter = UltmarcDoctorSearchModel(**parameter.model_dump()) where_clause = self.__build_condition(clone_parameter) - query = self.FETCH_SQL.format(where_clause=where_clause) + query = self.FETCH_SQL.format( + where_clause=where_clause, limit=environment.ULTMARC_SEARCH_RESULT_MAX_COUNT + 1) result = self._database.execute_select(query, clone_parameter.model_dump()) models = [UltmarcDoctorDBModel(**r) for r in result] @@ -69,6 +72,9 @@ class UltmarcDoctorRepository(BaseRepository): def __build_condition(self, parameter: UltmarcDoctorSearchModel): where_clauses: list[SQLCondition] = [] + # 検索条件が指定されずにSQLが壊れることを予防するため、常に真の固定条件を追加しておく + where_clauses.append(SQLCondition('', '', '1 = 1', literal=True)) + # 医師コード if is_not_empty(parameter.dcf_pcf_dr_cd): # 必ず部分一致で検索 @@ -149,7 +155,7 @@ class UltmarcDoctorRepository(BaseRepository): '', '', "(com_dr.use_stop_div NOT IN ('01','03','04') OR com_dr.use_stop_div IS NULL)", literal=True)) # 廃業除外 - if where_clauses: + if len(where_clauses) > 0: where_clauses.append(SQLCondition( '', '', '(length(com_inst.abolish_ymd) = 0 OR com_inst.abolish_ymd IS NULL)', literal=True)) where_clauses.append(SQLCondition( diff --git a/ecs/jskult-webapp/src/repositories/ultmarc_inst_repository.py b/ecs/jskult-webapp/src/repositories/ultmarc_inst_repository.py index f94fae16..3b485402 100644 --- a/ecs/jskult-webapp/src/repositories/ultmarc_inst_repository.py +++ b/ecs/jskult-webapp/src/repositories/ultmarc_inst_repository.py @@ -7,6 +7,7 @@ from src.model.db.ultmarc_inst import UltmarcInstDBModel from src.model.db.ultmarc_inst_info import UltmarcInstInfoDBModel from src.model.request.ultmarc_inst import UltmarcInstSearchModel from src.repositories.base_repository import BaseRepository +from src.system_var import environment from src.util.string_util import is_not_empty logger = get_logger('COM_施設取得') @@ -32,6 +33,7 @@ class UltmarcInstRepository(BaseRepository): LEFT JOIN src05.com_hp_assrt ON com_inst.hp_assrt_cd = com_hp_assrt.hp_assrt_cd WHERE {where_clause} ORDER BY dcf_dsf_inst_cd + LIMIT {limit} \ """ @@ -41,7 +43,8 @@ class UltmarcInstRepository(BaseRepository): # 文字列の検索を部分一致にするため、モデルをコピー。以降はこのコピーを使用する。 clone_parameter = UltmarcInstSearchModel(**parameter.model_dump()) where_clause = self.__build_condition(clone_parameter) - query = self.FETCH_SQL.format(where_clause=where_clause) + query = self.FETCH_SQL.format( + where_clause=where_clause, limit=environment.ULTMARC_SEARCH_RESULT_MAX_COUNT + 1) result = self._database.execute_select(query, clone_parameter.model_dump()) models = [UltmarcInstDBModel(**r) for r in result] @@ -55,6 +58,9 @@ class UltmarcInstRepository(BaseRepository): def __build_condition(self, parameter: UltmarcInstSearchModel): where_clauses: list[SQLCondition] = [] + # 検索条件が指定されずにSQLが壊れることを予防するため、常に真の固定条件を追加しておく + where_clauses.append(SQLCondition('', '', '1 = 1', literal=True)) + # ULT施設コード if is_not_empty(parameter.dcf_dsf_inst_cd): # 部分一致検索