38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
from src.logging.get_logger import get_logger
|
|
from src.model.db.wholesaler_master import WholesalerMasterModel
|
|
from src.repositories.base_repository import BaseRepository
|
|
|
|
logger = get_logger('卸データ取得')
|
|
|
|
|
|
class WholesalerMasterRepository(BaseRepository):
|
|
|
|
FETCH_SQL = """\
|
|
SELECT DISTINCT
|
|
b.orig_whlslr_cd as rec_whs_cd,
|
|
b.orig_whlslr_sub_cd as rec_whs_sub_cd,
|
|
v2.ws_nm_kj as name,
|
|
b.cls_whlslr_nm as whs_name
|
|
FROM src07.trn_result_data_bio_lot b
|
|
LEFT OUTER JOIN
|
|
(
|
|
SELECT
|
|
ws_cd,
|
|
ws_nm_kj
|
|
FROM src07.mst_whlslr
|
|
WHERE src07.get_syor_date() BETWEEN str_to_date(concat(eff_start_ym, '01'), '%Y%m%d') AND str_to_date(concat(eff_end_ym, '01'), '%Y%m%d')
|
|
) v2
|
|
ON b.orig_whlslr_cd = v2.ws_cd
|
|
ORDER BY b.orig_whlslr_cd, b.orig_whlslr_sub_cd , b.cls_whlslr_nm DESC
|
|
"""
|
|
|
|
def fetch_all(self) -> list[WholesalerMasterModel]:
|
|
try:
|
|
result = self._database.execute_select(self.FETCH_SQL)
|
|
result_data = [res for res in result]
|
|
models = [WholesalerMasterModel(**r) for r in result_data]
|
|
return models
|
|
except Exception as e:
|
|
logger.exception(f"DB Error : Exception={e}")
|
|
raise e
|