DatePickerと戦い抜いた結果

This commit is contained in:
野間 2023-07-19 13:27:34 +09:00
parent f3e6369f50
commit 87e45dca66
9 changed files with 58 additions and 84 deletions

View File

@ -61,10 +61,10 @@ async def download_bio_data(
return {'status': 'ok', 'download_url': None}
# ファイルに打ち出すカラムを抽出
extract_df = search_result_df[constants.BIO_EXTRACT_COLUMNS]
# extract_df = search_result_df[constants.BIO_EXTRACT_COLUMNS]
# ファイルを書き出し(Excel or CSV)
local_file_path = _write_bio_data_to_file(bio_service, download_param, extract_df, download_file_name)
local_file_path = _write_bio_data_to_file(bio_service, download_param, search_result_df, download_file_name)
# ローカルファイルからS3にアップロードし、ダウンロード用URLを取得する
try:

View File

@ -4,9 +4,9 @@ from typing import Optional
from src.model.db.base_db_model import BaseDBModel
class BioSalesViewModel(BaseDBModel):
class BioSalesLotDBModel(BaseDBModel):
slip_mgt_num: Optional[str]
conv_cdR: Optional[int]
conv_cd: Optional[int]
rec_whs_cd: Optional[str]
rec_whs_sub_cd: Optional[str]
rec_whs_org_cd: Optional[str]

View File

@ -1,13 +1,8 @@
from src.model.db.bio_sales_view import BioSalesViewModel
from src.model.db.bio_sales_view import BioSalesLotDBModel
from src.util.sanitize import sanitize
@sanitize
class BisDisplayModel(BioSalesViewModel):
def __init__(self, param: BioSalesViewModel) -> None:
class BisDisplayModel(BioSalesLotDBModel):
def __init__(self, param: BioSalesLotDBModel) -> None:
super().__init__(**param.dict())
# 訂正前伝票管理番号がセットされているときのみ修正日時、修正者、エラー詳細種別をセット
if (self.bef_slip_mgt_num is None):
self.ins_dt = ""
self.ins_usr = ""

View File

@ -23,7 +23,7 @@ class BioViewModel(BaseModel):
def display_wholesaler_names(self):
display_names = [
f'{whs_model.rec_whs_cd}-{whs_model.rec_whs_sub_cd}:{whs_model.name}'
f'{whs_model.rec_whs_cd}-{whs_model.rec_whs_sub_cd}:{whs_model.name or ""}'
for whs_model in self.whs_models
]
return display_names

View File

@ -1,7 +1,7 @@
from src.db import sql_condition as condition
from src.db.sql_condition import SQLCondition
from src.logging.get_logger import get_logger
from src.model.db.bio_sales_view import BioSalesViewModel
from src.model.db.bio_sales_view import BioSalesLotDBModel
from src.model.request.bio import BioModel
from src.repositories.base_repository import BaseRepository
from src.util.string_util import is_not_empty
@ -9,11 +9,10 @@ from src.util.string_util import is_not_empty
logger = get_logger('生物由来参照')
class BioSalesViewRepository(BaseRepository):
class BioSalesLotRepository(BaseRepository):
FETCH_SQL = """\
SELECT
slip_mgt_num,
conv_cd,
rec_whs_cd,
rec_whs_sub_cd,
rec_whs_org_cd,
@ -21,40 +20,28 @@ class BioSalesViewRepository(BaseRepository):
rec_tran_kbn,
rev_hsdnymd_srk,
rec_urag_num,
rec_comm_name,
rec_nonyu_fcl_name,
rec_nonyu_fcl_addr,
rec_lot_num,
rec_ymd,
v_tran_cd,
tran_kbn_name,
whs_org_cd,
v_whsorg_cd,
whs_org_name,
v_whs_cd,
whs_name,
nonyu_fcl_cd,
v_inst_cd,
v_inst_kn,
v_inst_name,
v_inst_addr,
comm_cd,
product_name,
whs_rep_comm_name,
whs_rep_nonyu_fcl_name,
whs_rep_nonyu_fcl_addr,
mkr_inf_1,
mkr_cd,
qty,
slip_org_kbn,
bef_slip_mgt_num,
lot_no_err_flg,
iko_flg,
rec_sts_kbn,
ins_dt,
ins_usr,
dwh_upd_dt,
inst_cd,
inst_name_form,
address,
tel_num,
@ -74,7 +61,7 @@ class BioSalesViewRepository(BaseRepository):
ASC\
"""
def fetch_many(self, parameter: BioModel) -> list[BioSalesViewModel]:
def fetch_many(self, parameter: BioModel) -> list[BioSalesLotDBModel]:
try:
self._database.connect()
logger.debug('DB参照実行')
@ -83,7 +70,7 @@ class BioSalesViewRepository(BaseRepository):
logger.debug(f'SQL: {query}')
result = self._database.execute_select(query, parameter.dict())
logger.debug(f'count= {len(result)}')
models = [BioSalesViewModel(**r) for r in result]
models = [BioSalesLotDBModel(**r) for r in result]
return models
except Exception as e:
logger.exception(f"DB Error : Exception={e.args}")

View File

@ -12,7 +12,7 @@ from src.model.request.bio import BioModel
from src.model.view.bio_disp_model import BisDisplayModel
from src.model.view.bio_view_model import BioViewModel
from src.repositories.base_repository import BaseRepository
from src.repositories.bio_sales_view_repository import BioSalesViewRepository
from src.repositories.bio_sales_view_repository import BioSalesLotRepository
from src.repositories.pharmacy_product_master_repository import \
PharmacyProductMasterRepository
from src.repositories.wholesaler_master_repository import \
@ -27,7 +27,7 @@ class BioViewService(BaseService):
REPOSITORIES = {
'whs_repository': WholesalerMasterRepository,
'phm_repository': PharmacyProductMasterRepository,
'bio_sales_repository': BioSalesViewRepository
'bio_sales_repository': BioSalesLotRepository
}
CLIENTS = {
@ -36,7 +36,7 @@ class BioViewService(BaseService):
whs_repository: WholesalerMasterRepository
phm_repository: PharmacyProductMasterRepository
bio_sales_repository: BioSalesViewRepository
bio_sales_repository: BioSalesLotRepository
s3_client: S3Client
def __init__(self, repositories: dict[str, BaseRepository], clients: dict[str, AWSAPIClient]) -> None:

View File

@ -84,55 +84,54 @@ function selectDropDowList(id, selectedName){
function enableDatePicker() {
// カレンダーの表示を日曜日始まりに変更
flatpickr.l10ns.ja.firstDayOfWeek = 0;
$('.date_picker').flatpickr(
{
$(".date_picker").each(function(i, elem) {
const date_picker_name = elem.name;
flatpickr(elem, {
locale: 'ja', // 日本語カレンダー
allowInput: true, // 入力可能にする
dateFormat: 'Y/m/d' // 日付のフォーマットを修正
}
)
}
dateFormat: "YYYY/MM/DD", // 日付のフォーマット
onChange(_dates, currentDateString, _picker, _data) {
},
parseDate: function(strFormat, format) {
function setDatePicker() {
// カレンダーの表示を日曜日始まりに変更
flatpickr.l10ns.ja.firstDayOfWeek = 0;
$(".date_picker").datepicker({
locale: 'ja',
dateFormat: 'YYY/mm/dd'
// yyyyMMddの場合→yyyy/MM/dd
const datePatternMatches = strFormat.match(/^(\d{4})(\d{2})(\d{2})$/);
if (datePatternMatches){
strFormat = `${datePatternMatches[1]}/${datePatternMatches[2]}/${datePatternMatches[3]}`;
}
// yyyy/00/00yyyy/00/00の場合→yyyy/01/01yyyy/12/31
// yyyy/MM/00yyyy/MM/01の場合→yyyy/MM/01yyyy/MM/末日
// 開始日の場合
if (date_picker_name.includes('from')){
strFormat = strFormat.replace("/00/00", "/01/01");
strFormat = strFormat.replace("/00", "/01");
}
// 終了日の場合
else if (date_picker_name.includes('to')){
strFormat = strFormat.replace("/00/00", "/12/31");
const date = new Date(strFormat.slice(0, 4), strFormat.slice(5, 7), 0).getDate();
strFormat = strFormat.replace("/00", "/"+date.toString());
}
return new Date(strFormat);
},
formatDate: (date, format) => {
// 日付の整合性チェック、不正の場合は空表示
if(isNaN(date.getDate())){
return;
}
// フォーマットを設定
const formatted = flatpickr.formatDate(date,'Y/m/d');
return formatted;
}
})
});
}
// 日付入力チェック
// 引数:チェックするテキストボックスNo
function autoModifyDate($this){
// 日付フォーマットチェック
let strFormat = $this.value;
// yyyyMMddの場合→yyyy/MM/dd
const datePatternMatches = strFormat.match(/^(\d{4})(\d{2})(\d{2})$/);
if (datePatternMatches){
strFormat = `${datePatternMatches[1]}/${datePatternMatches[2]}/${datePatternMatches[3]}`;
}
// yyyy/00/00yyyy/00/00の場合→yyyy/01/01yyyy/12/31
// yyyy/MM/00yyyy/MM/01の場合→yyyy/MM/01yyyy/MM/末日
// 開始日の場合
if ($this.name.includes('from')){
strFormat = strFormat.replace("00/00", "01/01");
strFormat = strFormat.replace("/00", "/01");
}
// 終了日の場合
else if ($this.name.includes('to')){
strFormat = strFormat.replace("00/00", "12/31");
const date = new Date(strFormat.slice(0, 4), strFormat.slice(5, 7), 0).getDate();
strFormat = strFormat.replace("/00", "/"+date.toString());
}
$this.value = strFormat;
return false;
}
// 前のスペースを許さない入力チェック
function checkSpaceForm($this)
{

View File

@ -15,5 +15,3 @@
<script src="https://cdn.jsdelivr.net/npm/flatpickr/dist/l10n/ja.min.js"></script>
<script src="/static/function/businessLogicScript.js"></script>
<script src="/static/lib/fixed_midashi.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/themes/base/jquery-ui.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>

View File

@ -13,8 +13,7 @@
// ボタン、テキストボックス初期化
formBtDisabled();
// DatePickerを有効化
setDatePicker();
enableDatePicker();
});
</script>
</head>
@ -56,13 +55,11 @@
<input type="text" id="shoribi_start" class="date_picker" name="ctrl_rec_ymd_from"
value="{{bio.is_input_rec_ymd_from()}}"
onchange="formBtDisabled()"
onblur="autoModifyDate(this)"
>
<input type="text" id="shoribi_end" class="date_picker" name="ctrl_rec_ymd_to"
value="{{bio.is_input_rec_ymd_to()}}"
onchange="formBtDisabled()"
onblur="autoModifyDate(this)"
>
</td>
</tr>
@ -100,13 +97,11 @@
<input type="text" id="hsdnymd_start" class="date_picker" name="ctrl_rev_hsdnymd_srk_from"
value="{{bio.is_input_rev_hsdnymd_srk_from()}}"
onchange="formBtDisabled()"
onblur="autoModifyDate(this)"
>
<input type="text" id="hsdnymd_end" class="date_picker" name="ctrl_rev_hsdnymd_srk_to"
value="{{bio.is_input_rev_hsdnymd_srk_to()}}"
onchange="formBtDisabled()"
onblur="autoModifyDate(this)"
>
</td>
<td colspan="2">