<?xml version="1.0" encoding="UTF-8" ?>
|
|
<sqls>
|
<dataSpace name="account">
|
|
<sql name="getAccountNccList">
|
<![CDATA[
|
select md_org_account_ncc.*, (
|
select count(1) from md_org_account where md_org_account.org_ncc_id = md_org_account_ncc.id
|
) as account_count,
|
md_org.id as md_org__id, md_org.oa_no as md_org__oa_no,
|
md_org.state_code as md_org__state_code, md_org.state_name as md_org__state_name,
|
md_org.source as md_org__source, md_org.code as md_org__code, md_org.ncc_code as md_org__ncc_code,
|
md_org.name as md_org__name, md_org.short_name as md_org__short_name,
|
md_org.category_code as md_org__category_code, md_org.category_name as md_org__category_name,
|
md_org.license_business_no as md_org__license_business_no,
|
md_org.province as md_org__province, md_org.city as md_org__city, md_org.county as md_org__county,
|
md_org.register_address as md_org__register_address, md_org.business_address as md_org__business_address,
|
md_org.business_person as md_org__business_person, md_org.business_phone as md_org__business_phone,
|
md_org.business_email as md_org__business_email,md_org.receiver_name md_org__receiver_name,
|
md_org.receiver_phone md_org__receiver_phone, md_org.receive_address md_org__receive_address,
|
md_org.is_frozen as md_org__is_frozen,
|
md_org.is_distributor as md_org__is_distributor
|
from md_org_account_ncc left join md_org on md_org_account_ncc.org_id = md_org.id
|
where @{filter} @{orderby} @{limit}
|
]]>
|
</sql>
|
|
<sql name="activateAgreementRecord">
|
<![CDATA[
|
update @{tableName} set agreement_no = '@{agreement_no}',
|
date_from = ifnull(date_from, @{date_from}), date_to = ifnull(date_to, @{date_to}),
|
state_code = '@{state_code}', state_name = '@{state_name}'
|
where agreement_id = '@{agreement_id}'
|
]]>
|
</sql>
|
|
<sql name="stopAgreementRecord">
|
<![CDATA[
|
update @{tableName} set state_code = '@{state_code}', state_name = '@{state_name}'
|
where agreement_id = '@{agreement_id}'
|
]]>
|
</sql>
|
|
<sql name="getChannelStructureLastTime">
|
<![CDATA[
|
select max(run_time) from md_channel_structure_log
|
]]>
|
</sql>
|
|
<sql name="createChannelStructure">
|
<![CDATA[
|
insert into md_channel_structure (
|
id, company_id, company_name, bu_id, bu_name, org_id, account_ncc_id,
|
authorize_id, category_code, state_code, state_name,
|
account_id, account_code, account_name,
|
distributor_id, distributor_code, distributor_name,
|
hospital_id, hospital_code, hospital_name,
|
authorization_code, file_authorization, file_name_authorization,
|
position_id,
|
date_from, date_to, create_time, update_time
|
)
|
select UUID_SHORT(), md_org_account_hospital.company_id, md_company.short_name company_name,
|
md_org_account_hospital.bu_id, md_bu.name bu_name, md_org_account_hospital.org_id, md_org_account.org_ncc_id,
|
md_org_account_hospital.id, category_code, md_org_account_hospital.state_code, md_org_account_hospital.state_name,
|
account_id, md_org_account_hospital.org_code, md_org_account_hospital.org_name,
|
account_id, md_org_account_hospital.org_code, md_org_account_hospital.org_name,
|
md_org_account_hospital.hospital_id, md_hospital.code, md_hospital.name,
|
md_org_account_hospital.code, file_authorization, file_name_authorization,
|
md_position_hospital.position_id,
|
date_from, date_to, now(), now()
|
from md_org_account_hospital
|
left join md_bu on md_bu.id = md_org_account_hospital.bu_id
|
left join (select id, short_name, name from md_org where is_master = 'T') md_company on md_company.id = md_org_account_hospital.company_id
|
left join md_org_account on md_org_account.id = md_org_account_hospital.account_id
|
left join md_hospital on md_org_account_hospital.hospital_id = md_hospital.id
|
left join md_position_hospital on md_org_account_hospital.hospital_id = md_position_hospital.hospital_id
|
where md_org_account_hospital.update_time >= @{updateTime}
|
and md_org_account_hospital.state_code = 'Open' and md_org_account_hospital.term_code <> 'terminate'
|
and category_code = 'Dealer' and is_content_dealer = 'T' and is_content_distributor = 'T'
|
and not exists (
|
select 1 from md_channel_structure
|
where md_channel_structure.authorize_id = md_org_account_hospital.id
|
)
|
]]>
|
</sql>
|
|
<sql name="createChannelStructure_dealerOnly">
|
<![CDATA[
|
insert into md_channel_structure (
|
id, company_id, company_name, bu_id, bu_name, org_id, account_ncc_id,
|
authorize_id, category_code, state_code, state_name,
|
account_id, account_code, account_name,
|
hospital_id, hospital_code, hospital_name,department,
|
authorization_code, file_authorization, file_name_authorization,
|
position_id,
|
date_from, date_to, create_time, update_time
|
)
|
select UUID_SHORT(), md_org_account_hospital.company_id, md_company.short_name company_name,
|
md_org_account_hospital.bu_id, md_bu.name bu_name, md_org_account_hospital.org_id, md_org_account.org_ncc_id,
|
md_org_account_hospital.id, category_code, md_org_account_hospital.state_code, md_org_account_hospital.state_name,
|
account_id, md_org_account_hospital.org_code, md_org_account_hospital.org_name,
|
md_org_account_hospital.hospital_id, md_hospital.code, md_hospital.name, md_org_account_hospital.department,
|
md_org_account_hospital.code, file_authorization, file_name_authorization,
|
md_position_hospital.position_id,
|
date_from, date_to, now(), now()
|
from md_org_account_hospital
|
left join md_bu on md_bu.id = md_org_account_hospital.bu_id
|
left join (select id, short_name, name from md_org where is_master = 'T') md_company on md_company.id = md_org_account_hospital.company_id
|
left join md_org_account on md_org_account.id = md_org_account_hospital.account_id
|
left join md_hospital on md_org_account_hospital.hospital_id = md_hospital.id
|
left join md_position_hospital on md_org_account_hospital.hospital_id = md_position_hospital.hospital_id
|
where md_org_account_hospital.update_time >= @{updateTime}
|
and md_org_account_hospital.state_code = 'Open' and md_org_account_hospital.term_code <> 'terminate'
|
and category_code = 'Dealer' and is_content_dealer = 'T' and is_content_distributor is null
|
and not exists (
|
select 1 from md_channel_structure
|
where md_channel_structure.authorize_id = md_org_account_hospital.id
|
)
|
]]>
|
</sql>
|
|
<sql name="createChannelStructure_dealerDistributor">
|
<![CDATA[
|
insert into md_channel_structure (
|
id, company_id, company_name, bu_id, bu_name, org_id, account_ncc_id,
|
authorize_id, category_code, state_code, state_name,
|
account_id, account_code, account_name,
|
distributor_id, distributor_code, distributor_name,
|
hospital_id, hospital_code, hospital_name, department,
|
authorization_code, file_authorization, file_name_authorization,
|
position_id,
|
date_from, date_to, create_time, update_time
|
)
|
select UUID_SHORT(), md_org_account_hospital.company_id, md_company.short_name company_name,
|
md_org_account_hospital.bu_id, md_bu.name bu_name, md_org_account_hospital.org_id, md_org_account.org_ncc_id,
|
md_org_account_hospital.id, category_code, md_org_account_hospital.state_code, md_org_account_hospital.state_name,
|
account_id, md_org_account_hospital.org_code, md_org_account_hospital.org_name,
|
account_id, md_org_account_hospital.org_code, md_org_account_hospital.org_name,
|
md_org_account_hospital.hospital_id, md_hospital.code, md_hospital.name, md_org_account_hospital.department,
|
md_org_account_hospital.code, file_authorization, file_name_authorization,
|
md_position_hospital.position_id,
|
date_from, date_to, now(), now()
|
from md_org_account_hospital
|
left join md_bu on md_bu.id = md_org_account_hospital.bu_id
|
left join (select id, short_name, name from md_org where is_master = 'T') md_company on md_company.id = md_org_account_hospital.company_id
|
left join md_org_account on md_org_account.id = md_org_account_hospital.account_id
|
left join md_hospital on md_org_account_hospital.hospital_id = md_hospital.id
|
left join md_position_hospital on md_org_account_hospital.hospital_id = md_position_hospital.hospital_id
|
where md_org_account_hospital.update_time >= @{updateTime}
|
and md_org_account_hospital.state_code = 'Open' and md_org_account_hospital.term_code <> 'terminate'
|
and category_code = 'Dealer'
|
and not exists (
|
select 1 from md_channel_structure
|
where md_channel_structure.authorize_id = md_org_account_hospital.id
|
)
|
]]>
|
</sql>
|
|
<sql name="createChannelStructure_distributor">
|
<![CDATA[
|
insert into md_channel_structure (
|
id, company_id, company_name, bu_id, bu_name, org_id, account_ncc_id,
|
account_code,account_name,
|
authorize_id, category_code, state_code, state_name,
|
distributor_id, distributor_code, distributor_name,
|
hospital_id, hospital_code, hospital_name, department,
|
authorization_code, file_authorization, file_name_authorization,
|
position_id,
|
date_from, date_to, create_time, update_time
|
)
|
select UUID_SHORT(), md_org_account_hospital.company_id, md_company.short_name company_name,
|
md_org_account_hospital.bu_id, md_bu.name bu_name, md_org_account_hospital.org_id, md_org_account.org_ncc_id,
|
md_org_account_hospital.org_code, md_org_account_hospital.org_name,
|
md_org_account_hospital.id, category_code, md_org_account_hospital.state_code, md_org_account_hospital.state_name, connected_org_id,
|
md_org_account_hospital.connected_org_code, md_org_account_hospital.connected_org_name,
|
md_org_account_hospital.hospital_id, md_hospital.code, md_hospital.name, md_org_account_hospital.department,
|
md_org_account_hospital.code, file_authorization, file_name_authorization,
|
md_position_hospital.position_id,
|
date_from, date_to, now(), now()
|
from md_org_account_hospital
|
left join md_bu on md_bu.id = md_org_account_hospital.bu_id
|
left join (select id, short_name, name from md_org where is_master = 'T') md_company on md_company.id = md_org_account_hospital.company_id
|
left join md_org_account on md_org_account.id = md_org_account_hospital.account_id
|
left join md_hospital on md_org_account_hospital.hospital_id = md_hospital.id
|
left join md_position_hospital on md_org_account_hospital.hospital_id = md_position_hospital.hospital_id
|
where md_org_account_hospital.update_time >= @{updateTime}
|
and md_org_account_hospital.state_code = 'Open' and md_org_account_hospital.term_code <> 'terminate'
|
and category_code = 'Distributor' and not exists (
|
select 1 from md_channel_structure
|
where md_channel_structure.authorize_id = md_org_account_hospital.id
|
)
|
]]>
|
</sql>
|
|
<sql name="closeChannelStructure">
|
<![CDATA[
|
update md_channel_structure left join md_org_account_hospital
|
on md_channel_structure.authorize_id = md_org_account_hospital.id
|
|
set md_channel_structure.state_code = 'Close', md_channel_structure.state_name = '已终止',
|
md_channel_structure.suspend_date = md_org_account_hospital.suspend_date,
|
md_channel_structure.suspend_remark = md_org_account_hospital.suspend_remark
|
|
where md_org_account_hospital.update_time >= @{updateTime}
|
and md_org_account_hospital.state_code = 'Closed'
|
and md_org_account_hospital.id is not null
|
]]>
|
</sql>
|
|
<sql name="createChannelStructure_platform">
|
<![CDATA[
|
insert into md_channel_structure (
|
id, type_code,
|
company_name, bu_name,
|
hospital_id, hospital_code, hospital_name, department,
|
org_id, account_ncc_id,
|
platform_id, platform_code, platform_name,
|
create_time, update_time
|
)
|
select UUID_SHORT(), md_org_account.actor_code,
|
md_company.short_name company_name, md_bu.name bu_name,
|
md_hospital.id, md_hospital.code, md_hospital.name, md_org_account_hospital.department,
|
md_org_account_hospital.org_id, md_org_account.org_ncc_id,
|
md_org_account.id, md_org_account_hospital.org_code, md_org_account_hospital.org_name,
|
now(), now()
|
from md_org_account_hospital
|
left join md_bu on md_bu.id = md_org_account_hospital.bu_id
|
left join (select id, short_name, name from md_org where is_master = 'T') md_company on md_company.id = md_org_account_hospital.company_id
|
left join md_org_account on md_org_account.id = md_org_account_hospital.account_id
|
left join md_hospital on md_org_account_hospital.hospital_id = md_hospital.id
|
left join agm_authorization on agm_authorization.org_hospital_id = md_org_account_hospital.id
|
where md_org_account.actor_code = 'Platform' and md_org_account_hospital.state_code = 'Open'
|
and not exists (
|
select 1 from md_channel_structure where md_channel_structure.type_code = md_org_account.actor_code
|
and md_org_account.company_name = md_channel_structure.company_name
|
and md_org_account.bu_name = md_channel_structure.bu_name
|
and platform_id = md_org_account.id
|
)
|
]]>
|
</sql>
|
|
<sql name="getCustomerSalesEmployee">
|
<![CDATA[
|
select md_employee.id, md_employee.code, md_employee.name,
|
md_employee.nc_org_id, md_employee.nc_org_code,
|
md_department_oa_nc.oa_department_id,md_department_oa_nc.oa_department_name,
|
md_department_oa_nc.nc_region_id, md_department_oa_nc.nc_region_code, md_department_oa_nc.nc_region_name,
|
md_department_oa_nc.nc_area_id, md_department_oa_nc.nc_area_code, md_department_oa_nc.nc_area_name
|
from md_employee
|
left join md_department_oa_nc on md_employee.job_title_code = md_department_oa_nc.oa_department_code
|
where exists (
|
select 1 from md_org_account_position left join md_position_employee
|
on md_org_account_position.position_id = md_position_employee.position_id
|
where @{filter} and md_employee.id = md_position_employee.employee_id
|
) and md_employee.is_active = 'T'
|
]]>
|
</sql>
|
|
<sql name="getAccountEntity">
|
<![CDATA[
|
select md_org_account.id account_id, md_org_account.account_name account_name,
|
md_org_account_position.position_id from md_org_account
|
left join md_org_account_position on md_org_account_position.parent_id = md_org_account.id
|
where md_org_account.id = '@{accountId}'
|
]]>
|
</sql>
|
|
<sql name="getPositionDistributor">
|
<![CDATA[
|
select count(distinct distributor_id) customerCount
|
from md_channel_structure
|
where @{filter} @{orderby} @{limit}
|
]]>
|
</sql>
|
|
<sql name="getEmployeePositions">
|
<![CDATA[
|
select md_position.* from md_position_employee
|
left join md_position on md_position_employee.position_id = md_position.id
|
where md_position_employee.employee_id = '@{employeeId}' and md_position.is_delete = 'F'
|
]]>
|
</sql>
|
|
</dataSpace>
|
|
</sqls>
|