insert into tb_ens_mobile_page_manage
select concat('KKO', send_detail_id)
     , 'KKO-MY-DOC'
     , details
     , regist_dt
     , 'system'
from ens_snd_dtl_mbl_page;


insert into tb_ens_unity_sndng_mastr
select (select c.elctrn_ntic_sndng_id from ens_snd_dtl_kko_md b inner join tb_elctrn_ntic_sndng_detail c on b.prop_external_document_uuid=c.external_document_uuid where a.send_mast_id = b.send_mast_id limit 1)
     , '51110'
     , '11'
     , tmplt_cd
     , 'ENS'
     , send_cnt
     , 'send-ok'  -- stat_cd
     , date_format(send_dt, '%Y%m%d%H%i%S')
     , ''
     , ''
     , 'KKO-MY-DOC'
     , ''
     , ''
     , '1'
     , date_format(close_dt, '%Y%m%d%H%i%S')
     , ''
     , ''
     , regist_dt
     , 'system'
     , last_updt_dt
     , 'system'
from ens_snd_mast a
where stat_cd IN ('open', 'sendcmplt');


insert into tb_ens_unity_sndng_detail
select (select b.elctrn_ntic_sndng_detail_id from tb_elctrn_ntic_sndng_detail b where a.prop_external_document_uuid=b.external_document_uuid)
     , (select c.elctrn_ntic_sndng_id from ens_snd_dtl_kko_md b inner join tb_elctrn_ntic_sndng_detail c on b.prop_external_document_uuid=c.external_document_uuid where a.send_mast_id = b.send_mast_id limit 1)
     , '51110'
     , '11'
     , ''
     , ''
     , ''
     , ''
     , ''
     , ''
     , ''
     , ''
     , ''
     , (select mobile_page_cn from tb_ens_mobile_page_manage b where b.sndng_detail_id=concat('KKO', a.send_detail_id))
     , ''
     , prop_external_document_uuid
     , regist_dt
     , 'system'
     , last_updt_dt
     , 'system'
from ens_snd_dtl_kko_md a
where send_mast_id in (select send_mast_id from ens_snd_mast where stat_cd IN ('open', 'sendcmplt'));


insert into tb_ens_sndng_mastr
select concat('KKO', send_mast_id)
     , (select c.elctrn_ntic_sndng_id from ens_snd_dtl_kko_md b inner join tb_elctrn_ntic_sndng_detail c on b.prop_external_document_uuid=c.external_document_uuid where a.send_mast_id = b.send_mast_id limit 1)
     , '51110'
     , '11'
     , tmplt_cd
     , 'ENS'
     , 'KKO-MY-DOC'
     , send_cnt
     , '1'
     , '1'
     , 'send-ok'  -- stat_cd
     , date_format(send_dt, '%Y%m%d%H%i%S')
     , date_format(close_dt, '%Y%m%d%H%i%S')
     , ''
     , ''
     , ''
     , null
     , ''
     , regist_dt
     , 'system'
     , last_updt_dt
     , 'system'
from ens_snd_mast a
where stat_cd IN ('open', 'sendcmplt');


insert into tb_ens_kakao_my_doc
select concat('KKO', send_detail_id)
     , (select b.elctrn_ntic_sndng_detail_id from tb_elctrn_ntic_sndng_detail b where a.prop_external_document_uuid=b.external_document_uuid)
     , concat('KKO', send_mast_id)
     , '51110'
     , '11'
     , title
     , hash
     , common_categories
     , read_expiread_at
     , recv_ci
     , ''
     , ''
     , ''
     , recv_is_require_vfy_name
     , prop_link
     , prop_payload
     , prop_message
     , prop_cs_number
     , prop_cs_name
     , prop_external_document_uuid
     , document_binder_uuid
     , error_code
     , error_message
     , kko_doc_stat
     , unix_timestamp(kko_doc_sent_dt)
     , unix_timestamp(kko_doc_received_dt)
     , unix_timestamp(kko_doc_auth_frst_dt)
     , unix_timestamp(kko_doc_token_vrfy_frst_dt)
     , unix_timestamp(kko_doc_read_frst_dt)
     , unix_timestamp(kko_doc_user_notied_dt)
     , regist_dt
     , 'system'
     , last_updt_dt
     , 'system'
from ens_snd_dtl_kko_md a
where send_mast_id in (select send_mast_id from ens_snd_mast where stat_cd IN ('open', 'sendcmplt'));