feat: Call2_Discussion_vod__cの振分処理追加
This commit is contained in:
parent
8cc4569fe2
commit
92320d1aaa
@ -0,0 +1,106 @@
|
||||
-- A5M2で実行時に[SQL] - [スラッシュ(/)のみの行でSQLを区切る]に変えてから実行する
|
||||
-- $$から始まる文字は後からREPLACEする文字を示す独自ルール
|
||||
-- 当プロシージャは、同一セッション内での並列処理を実行することができない
|
||||
-- 実行者の権限でストアドプロシージャを実行するために、「SQL SECURITY INVOKER」を付与している
|
||||
CREATE PROCEDURE `internal02`.`crm_distribution_Call2_Discussion_vod__c`()
|
||||
SQL SECURITY INVOKER
|
||||
BEGIN
|
||||
|
||||
-- 振り分けスキーマ
|
||||
DECLARE distribution_schema VARCHAR(20);
|
||||
-- 振り分けカラム
|
||||
DECLARE target_column_value VARCHAR(100);
|
||||
-- 振り分け先テーブルID
|
||||
DECLARE temp_table_id VARCHAR(18);
|
||||
-- カーソルフェッチステータス
|
||||
DECLARE fetch_done BOOLEAN DEFAULT FALSE;
|
||||
|
||||
-- カーソル設定
|
||||
DECLARE table_cursor CURSOR FOR SELECT Id, medaca_parent_record_type_id FROM internal02.crm_Call2_Discussion_vod__c;
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET fetch_done = TRUE;
|
||||
|
||||
-- エラー処理
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
GET DIAGNOSTICS CONDITION 1
|
||||
@error_state = RETURNED_SQLSTATE, @error_msg = MESSAGE_TEXT;
|
||||
ROLLBACK;
|
||||
SET @error_msg = (
|
||||
CASE
|
||||
WHEN LENGTH(@error_msg) > 128 THEN CONCAT(SUBSTRING(@error_msg, 1, 125), '...')
|
||||
ELSE @error_msg
|
||||
END
|
||||
);
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MYSQL_ERRNO = @error_state, MESSAGE_TEXT = @error_msg;
|
||||
END;
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
-- UPSERT STATEMENT設定
|
||||
SET @upsert_statement_base =
|
||||
'INSERT INTO $$distribution_schema$$.crm_Call2_Discussion_vod__c(
|
||||
Id, IsDeleted, Name, RecordTypeId, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, MayEdit,
|
||||
IsLocked, Account_vod__c, Call2_vod__c, Activity__c, Comments__c, Contact_vod__c, Call_Date_vod__c, Product_Strategy_vod__c,
|
||||
Product_Tactic_vod__c, Restricted_Comments__c, Product_vod__c, Presentation__c, Discussion_Topics__c, Slides__c, User_vod__c,
|
||||
Indication__c, Mobile_ID_vod__c, Medical_Event_vod__c, Is_Parent_Call_vod__c, Override_Lock_vod__c, zvod_Product_Map_vod__c,
|
||||
Attendee_Type_vod__c, Entity_Reference_Id_vod__c, Account_Tactic_vod__c, MSJ_Material_Type__c, MSJ_Discussion_Contents__c,
|
||||
MSJ_IST_Minutes__c, MSJ_Off_Label_Minutes__c, MSJ_Discussion_Objectives__c, MSJ_Insight__c, EMDS_Materials__c, EMDS_Topic__c,
|
||||
MSJ_Visit_Purpose__c, MSJ_Insight_Count__c,
|
||||
file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date)
|
||||
SELECT
|
||||
Id, IsDeleted, Name, RecordTypeId, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, MayEdit,
|
||||
IsLocked, Account_vod__c, Call2_vod__c, Activity__c, Comments__c, Contact_vod__c, Call_Date_vod__c, Product_Strategy_vod__c,
|
||||
Product_Tactic_vod__c, Restricted_Comments__c, Product_vod__c, Presentation__c, Discussion_Topics__c, Slides__c, User_vod__c,
|
||||
Indication__c, Mobile_ID_vod__c, Medical_Event_vod__c, Is_Parent_Call_vod__c, Override_Lock_vod__c, zvod_Product_Map_vod__c,
|
||||
Attendee_Type_vod__c, Entity_Reference_Id_vod__c, Account_Tactic_vod__c, MSJ_Material_Type__c, MSJ_Discussion_Contents__c,
|
||||
MSJ_IST_Minutes__c, MSJ_Off_Label_Minutes__c, MSJ_Discussion_Objectives__c, MSJ_Insight__c, EMDS_Materials__c, EMDS_Topic__c,
|
||||
MSJ_Visit_Purpose__c, MSJ_Insight_Count__c,
|
||||
file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date
|
||||
FROM
|
||||
internal02.crm_Call2_Discussion_vod__c AS internaltb
|
||||
WHERE
|
||||
internaltb.Id = ?
|
||||
ON DUPLICATE KEY UPDATE
|
||||
IsDeleted=internaltb.IsDeleted, Name=internaltb.Name, RecordTypeId=internaltb.RecordTypeId, CreatedDate=internaltb.CreatedDate, CreatedById=internaltb.CreatedById,
|
||||
LastModifiedDate=internaltb.LastModifiedDate, LastModifiedById=internaltb.LastModifiedById, SystemModstamp=internaltb.SystemModstamp, MayEdit=internaltb.MayEdit,
|
||||
IsLocked=internaltb.IsLocked, Account_vod__c=internaltb.Account_vod__c, Call2_vod__c=internaltb.Call2_vod__c, Activity__c=internaltb.Activity__c,
|
||||
Comments__c=internaltb.Comments__c, Contact_vod__c=internaltb.Contact_vod__c, Call_Date_vod__c=internaltb.Call_Date_vod__c, Product_Strategy_vod__c=internaltb.Product_Strategy_vod__c,
|
||||
Product_Tactic_vod__c=internaltb.Product_Tactic_vod__c, Restricted_Comments__c=internaltb.Restricted_Comments__c, Product_vod__c=internaltb.Product_vod__c, Presentation__c=internaltb.Presentation__c,
|
||||
Discussion_Topics__c=internaltb.Discussion_Topics__c, Slides__c=internaltb.Slides__c, User_vod__c=internaltb.User_vod__c, Indication__c=internaltb.Indication__c, Mobile_ID_vod__c=internaltb.Mobile_ID_vod__c,
|
||||
Medical_Event_vod__c=internaltb.Medical_Event_vod__c, Is_Parent_Call_vod__c=internaltb.Is_Parent_Call_vod__c, Override_Lock_vod__c=internaltb.Override_Lock_vod__c,
|
||||
zvod_Product_Map_vod__c=internaltb.zvod_Product_Map_vod__c, Attendee_Type_vod__c=internaltb.Attendee_Type_vod__c, Entity_Reference_Id_vod__c=internaltb.Entity_Reference_Id_vod__c,
|
||||
Account_Tactic_vod__c=internaltb.Account_Tactic_vod__c, MSJ_Material_Type__c=internaltb.MSJ_Material_Type__c, MSJ_Discussion_Contents__c=internaltb.MSJ_Discussion_Contents__c,
|
||||
MSJ_IST_Minutes__c=internaltb.MSJ_IST_Minutes__c, MSJ_Off_Label_Minutes__c=internaltb.MSJ_Off_Label_Minutes__c, MSJ_Discussion_Objectives__c=internaltb.MSJ_Discussion_Objectives__c,
|
||||
MSJ_Insight__c=internaltb.MSJ_Insight__c, EMDS_Materials__c=internaltb.EMDS_Materials__c, EMDS_Topic__c=internaltb.EMDS_Topic__c,
|
||||
MSJ_Visit_Purpose__c=internaltb.MSJ_Visit_Purpose__c, MSJ_Insight_Count__c=internaltb.MSJ_Insight_Count__c,
|
||||
file_name=internaltb.file_name, file_row_cnt=internaltb.file_row_cnt,
|
||||
upd_user = CURRENT_USER(), upd_date = CURRENT_TIMESTAMP();';
|
||||
|
||||
OPEN table_cursor;
|
||||
|
||||
-- ループ
|
||||
TableCursorLoop: LOOP
|
||||
-- スキーマ取得
|
||||
FETCH table_cursor INTO temp_table_id, target_column_value;
|
||||
|
||||
-- 終了条件ループ抜き
|
||||
IF fetch_done THEN
|
||||
LEAVE TableCursorLoop;
|
||||
END IF;
|
||||
|
||||
SET @distribution_schema = internal02.get_distribution_to_schema('crm_Call2_Discussion_vod__c', 'medaca_parent_record_type_id', target_column_value);
|
||||
SET @temp_table_id = temp_table_id;
|
||||
|
||||
SET @upsert_statement = REPLACE(@upsert_statement_base, "$$distribution_schema$$", @distribution_schema);
|
||||
|
||||
-- UPSERT実行
|
||||
PREPARE stmt FROM @upsert_statement;
|
||||
EXECUTE stmt USING @temp_table_id;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
END LOOP;
|
||||
CLOSE table_cursor;
|
||||
COMMIT;
|
||||
|
||||
END
|
||||
Loading…
x
Reference in New Issue
Block a user