<?xml version="1.0" encoding="UTF-8" ?>
|
|
<sqls>
|
<dataSpace name="importSet">
|
<sql name="importStateTemplate">
|
<![CDATA[
|
update @{toTempTable}
|
set state_code = (
|
select distinct code from sys_state_machine_state
|
where EXISTS (
|
select 1 from sys_state_machine
|
inner join sys_state_machine_detail on sys_state_machine_detail.parent_id = sys_state_machine.id
|
inner join sys_state_machine_target on sys_state_machine_target.package_name = '@{dataName}' and sys_state_machine_target.state_machine_id = sys_state_machine.id
|
where sys_state_machine.state_category_code = sys_state_machine_state.category_code and sys_state_machine_detail.@{original_field} = sys_state_machine_state.code
|
)
|
),
|
state_name = (
|
select distinct name from sys_state_machine_state
|
where EXISTS (
|
select 1 from sys_state_machine
|
inner join sys_state_machine_detail on sys_state_machine_detail.parent_id = sys_state_machine.id
|
inner join sys_state_machine_target on sys_state_machine_target.package_name = '@{dataName}' and sys_state_machine_target.state_machine_id = sys_state_machine.id
|
where sys_state_machine.state_category_code = sys_state_machine_state.category_code and sys_state_machine_detail.@{original_field} = sys_state_machine_state.code
|
)
|
)
|
where io_batch_id = '@{ioBatchId}' and @{field} is null
|
]]>
|
</sql>
|
|
<sql name="importCodeTemplate">
|
<![CDATA[
|
update @{toTempTable} set @{field} = temp_code
|
where io_batch_id = '@{ioBatchId}' and @{field} is null
|
]]>
|
</sql>
|
|
<sql name="importSetNewId">
|
<![CDATA[
|
update @{toTable} set id = @{guid}
|
where io_batch_id = '@{ioBatchId}' and id is null
|
]]>
|
</sql>
|
|
<sql name="importSetDictionaryTemplate">
|
<![CDATA[
|
update @{toTempTable} set @{field} = (
|
select sys_dictionary_detail.code from sys_dictionary
|
left join sys_dictionary_detail on sys_dictionary_detail.parent_id = sys_dictionary.id
|
where sys_dictionary.code = @{dictionaryKey} and sys_dictionary_detail.value = @{toTempTable}.type_name
|
)
|
where io_batch_id = '@{ioBatchId}' and @{field} is null
|
]]>
|
</sql>
|
|
<sql name="importDatanameTemplate">
|
<![CDATA[
|
update @{toTempTable} set @{field} = (
|
select @{original_field} from @{dataName}
|
where @{mapping}
|
)
|
where io_batch_id = '@{ioBatchId}' and @{field} is null
|
]]>
|
</sql>
|
|
<sql name="importUpdateCustomerId">
|
<![CDATA[
|
update @{toTempTable}
|
set customer_id = (
|
select id from dscn_crm.hm_institution
|
where hm_institution.institution_code = @{toTempTable}.customer_code
|
)
|
where io_batch_id = '@{ioBatchId}' and customer_id is null
|
]]>
|
</sql>
|
|
<sql name="importUpdateProvinceCodeByCustomerId">
|
<![CDATA[
|
update @{toTempTable}
|
set province_code = (
|
select province_id from dscn_crm.hm_institution
|
where hm_institution.id = @{toTempTable}.customer_id
|
)
|
where io_batch_id = '@{ioBatchId}' and province_code is null
|
]]>
|
</sql>
|
|
<sql name="importUpdateCityCodeByCustomerId">
|
<![CDATA[
|
update @{toTempTable}
|
set city_code = (
|
select city_id from dscn_crm.hm_institution
|
where hm_institution.id = @{toTempTable}.customer_id
|
)
|
where io_batch_id = '@{ioBatchId}' and city_code is null
|
]]>
|
</sql>
|
|
<sql name="importUpdateProvinceByProvinceCode">
|
<![CDATA[
|
update @{toTempTable}
|
inner join md_geo_city on md_geo_city.code = @{toTempTable}.city_code
|
set @{toTempTable}.province = md_geo_city.province
|
where io_batch_id = '@{ioBatchId}' and @{toTempTable}.province is null
|
]]>
|
</sql>
|
|
<sql name="importUpdateCityByCityCode">
|
<![CDATA[
|
update @{toTempTable}
|
inner join md_geo_city on md_geo_city.code = @{toTempTable}.city_code
|
set @{toTempTable}.city = md_geo_city.name
|
where io_batch_id = '@{ioBatchId}' and @{toTempTable}.city is null
|
]]>
|
</sql>
|
|
<sql name="importSetTypeByImportType">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.type_code = (
|
select sys_dictionary_detail.code from sys_dictionary
|
left join sys_dictionary_detail on sys_dictionary_detail.parent_id = sys_dictionary.id
|
where sys_dictionary.code = concat('@{taskName}','_type'),
|
@{toTempTable}.type_name = (
|
select sys_dictionary_detail.value from sys_dictionary
|
left join sys_dictionary_detail on sys_dictionary_detail.parent_id = sys_dictionary.id
|
where sys_dictionary.code = concat('@{taskName}','_type')
|
where io_batch_id = '@{ioBatchId}' and type_code is null
|
]]>
|
</sql>
|
|
<sql name="importSetCategoryCode">
|
<![CDATA[
|
update @{toTempTable} set category_code = (
|
select sys_dictionary_detail.code from sys_dictionary
|
left join sys_dictionary_detail on sys_dictionary_detail.parent_id = sys_dictionary.id
|
where sys_dictionary.code = 'authorization_sort' and sys_dictionary_detail.value = @{toTempTable}.category_name
|
)
|
where io_batch_id = '@{ioBatchId}' and category_code is null
|
]]>
|
</sql>
|
|
<sql name="importSetStateCodeInit">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.state_code = (
|
select sys_dictionary_detail.code from sys_dictionary
|
left join sys_dictionary_detail on sys_dictionary_detail.parent_id = sys_dictionary.id
|
where sys_dictionary.code = concat('@{toTempTable}','_state')),
|
@{toTempTable}.state_name = (
|
select sys_dictionary_detail.value from sys_dictionary
|
left join sys_dictionary_detail on sys_dictionary_detail.parent_id = sys_dictionary.id
|
where sys_dictionary.code = concat('@{toTempTable}','_state'))
|
where io_batch_id = '@{ioBatchId}' and state_code is null
|
]]>
|
</sql>
|
|
<sql name="importSetInitState">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.state_code = 'InitVersion',
|
@{toTempTable}.state_name = '初版'
|
where io_batch_id = '@{ioBatchId}' and state_code is null
|
]]>
|
</sql>
|
|
<sql name="importSetDefaultState">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.state_code = 'Input' , @{toTempTable}.state_name = '录入'
|
where io_batch_id = '@{ioBatchId}' and state_code is null
|
]]>
|
</sql>
|
|
<sql name="importSetDefaultValidState">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.state_code = 'Open' , @{toTempTable}.state_name = '生效'
|
where io_batch_id = '@{ioBatchId}' and state_code is null
|
]]>
|
</sql>
|
|
<sql name="importSetProductIdByProductName">
|
<![CDATA[
|
update @{toTempTable} set product_id = (
|
select DISTINCT product_id from md_prod_sku
|
where md_prod_sku.product_name = @{toTempTable}.product_name and product_id is not null
|
)
|
where io_batch_id = '@{ioBatchId}' and product_id is null
|
]]>
|
</sql>
|
|
<sql name="importUpdateProductId">
|
<![CDATA[
|
update @{toTempTable}
|
set product_id = (
|
select max(id)
|
from hm_product
|
where hm_product.product_code = @{toTempTable}.product_code
|
)
|
where io_batch_id = '@{ioBatchId}' and product_id is null
|
]]>
|
</sql>
|
|
<sql name="importUpdateSkuId">
|
<![CDATA[
|
update @{toTempTable}
|
set sku_id = (
|
select sku_id
|
from md_product_sku
|
where md_product_sku.product_id = @{toTempTable}.product_id and md_product_sku.sku_code = @{toTempTable}.sku_code
|
)
|
where io_batch_id = '@{ioBatchId}' and sku_id is null
|
]]>
|
</sql>
|
|
<sql name="importUpdatePriceByProductId">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.price = (
|
select ifnull(hm_rsm_product_province.unit_price,0)
|
from (
|
select product_code, quarter_no, max(unit_price) unit_price
|
from dscn_crm.hm_rsm_product_province
|
group by product_code, quarter_no
|
) hm_rsm_product_province
|
where hm_rsm_product_province.product_code = @{toTempTable}.sku_code
|
and hm_rsm_product_province.quarter_no = @{toTempTable}.quarter_no )
|
where io_batch_id = '@{ioBatchId}' and price is null
|
]]>
|
</sql>
|
|
<sql name="importSetEmployeeId">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.employee_id = (
|
select min(id) from md_employee
|
where md_employee.code = @{toTempTable}.employee_code
|
and md_employee.is_active != 'F')
|
where @{toTempTable}.io_batch_id = '@{ioBatchId}' and @{toTempTable}.employee_id is null
|
]]>
|
</sql>
|
|
<sql name="importUpdatePositionId">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.position_id = (
|
select @{IfEmpty}(md_position.id, @{toTempTable}.position_code)
|
from md_position
|
where md_position.code = @{toTempTable}.position_code)
|
where @{toTempTable}.io_batch_id = '@{ioBatchId}' and @{toTempTable}.position_id is null
|
and exists ( select 1 from md_position where md_position.code = @{toTempTable}.position_code)
|
]]>
|
</sql>
|
|
<sql name="importUpdateTypeByPositionId">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.position_type = (
|
select duty from md_position
|
where md_position.id = @{toTempTable}.position_id)
|
where @{toTempTable}.io_batch_id = '@{ioBatchId}' and @{toTempTable}.position_type is null
|
]]>
|
</sql>
|
|
<sql name="importUpdateParentByPositionId">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.parent_position_id = (
|
select parent_id from md_position
|
where md_position.id = @{toTempTable}.position_id)
|
where @{toTempTable}.io_batch_id = '@{ioBatchId}' and @{toTempTable}.parent_position_id is null
|
]]>
|
</sql>
|
|
<sql name="importUpdateTerritoryByPositionId">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.territory_id = (
|
select territory_id from md_position
|
where md_position.id = @{toTempTable}.position_id)
|
where @{toTempTable}.io_batch_id = '@{ioBatchId}' and @{toTempTable}.territory_id is null
|
]]>
|
</sql>
|
|
<sql name="importUpdateParentByTerritoryId">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.parent_territory_id = (
|
select parent_id from md_territory
|
where md_territory.id = @{toTempTable}.territory_id)
|
where @{toTempTable}.io_batch_id = '@{ioBatchId}' and @{toTempTable}.parent_territory_id is null
|
]]>
|
</sql>
|
|
<sql name="importSetPositionIdByEmployee">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.position_id = (
|
select position_id from (
|
select position_id, md_employee.code empployee_code, md_position.name position_name
|
from md_position
|
left join md_position_employee on md_position.id = md_position_employee.position_id
|
left join md_employee on md_employee.id = md_position_employee.employee_id
|
where md_position.is_delete = 'F' ) positionEmployee
|
where positionEmployee.empployee_code = @{toTempTable}.position_employee_code
|
and positionEmployee.position_name = @{toTempTable}.position_name )
|
where @{toTempTable}.io_batch_id = '@{ioBatchId}'
|
]]>
|
</sql>
|
|
<sql name="importSetPositionIdByEmployeeId">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.position_id = (
|
select distinct md_position.id from md_position
|
left join md_position_employee on md_position.id = md_position_employee.position_id
|
left join md_employee on md_employee.id = md_position_employee.employee_id
|
where md_position.is_delete = 'F'and md_position_employee.employee_id = @{toTempTable}.employee_id )
|
where @{toTempTable}.position_id is null and @{toTempTable}.io_batch_id = '@{ioBatchId}'
|
]]>
|
</sql>
|
|
<sql name="importSetPositionNameById">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.position_name = (
|
select distinct md_position.name from md_position
|
where md_position.id = @{toTempTable}.position_id and md_position.is_delete = 'F' )
|
where @{toTempTable}.position_name is null and @{toTempTable}.io_batch_id = '@{ioBatchId}'
|
]]>
|
</sql>
|
|
<sql name="importSetRegionIdByPositionId">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.region_id = (
|
select distinct level2 from md_position_hierarchy
|
where md_position_hierarchy.position_id = @{toTempTable}.position_id)
|
where @{toTempTable}.region_id is null and @{toTempTable}.io_batch_id = '@{ioBatchId}'
|
]]>
|
</sql>
|
|
<sql name="importSetRegionNameByPositionId">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.region_name = (
|
select distinct md_position.region from md_position
|
where md_position.id = @{toTempTable}.position_id and md_position.is_delete = 'F' )
|
where @{toTempTable}.region_name is null and @{toTempTable}.io_batch_id = '@{ioBatchId}'
|
]]>
|
</sql>
|
|
<sql name="importSetRegionByPositionId">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.region = (
|
select distinct md_position.region from md_position
|
where md_position.id = @{toTempTable}.position_id and md_position.is_delete = 'F' )
|
where @{toTempTable}.region is null and @{toTempTable}.io_batch_id = '@{ioBatchId}'
|
]]>
|
</sql>
|
|
<sql name="importSetPositionLevelPositionId">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.position_level = (
|
select level_no from md_position
|
where md_position.id = @{toTempTable}.position_id )
|
where @{toTempTable}.io_batch_id = '@{ioBatchId}' and @{toTempTable}.position_level is null
|
]]>
|
</sql>
|
|
<sql name="importUpdateQuarterNo">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.quarter_no = concat(year, 'Q', quarter)
|
where @{toTempTable}.io_batch_id = '@{ioBatchId}' and @{toTempTable}.quarter_no is null
|
]]>
|
</sql>
|
|
<sql name="importUpdateCoManagerRatio">
|
<![CDATA[
|
update @{toTempTable}
|
inner join md_territory on md_territory.id = @{toTempTable}.territory_id
|
inner join dscn_crm.hm_territory_hospital_product_relation on
|
hm_territory_hospital_product_relation.product_code = @{toTempTable}.product_code
|
and hm_territory_hospital_product_relation.hospital_code = @{toTempTable}.customer_code
|
and hm_territory_hospital_product_relation.territory_code = md_territory.code
|
set @{toTempTable}.co_manage_ratio = hm_territory_hospital_product_relation.co_manage_ratio
|
where @{toTempTable}.io_batch_id = '@{ioBatchId}' and @{toTempTable}.co_manage_ratio is null
|
]]>
|
</sql>
|
|
<sql name="importUpdateCoManagerType">
|
<![CDATA[
|
update @{toTempTable}
|
left join (
|
select customer_id, sku_id , count(*) co_manage_cnt from @{toTempTable}
|
group by customer_id, sku_id
|
) co_manage on co_manage.customer_id = @{toTempTable}.customer_id and co_manage.sku_id = @{toTempTable}.sku_id
|
set @{toTempTable}.co_manage_type_code =
|
case when co_manage_cnt = 1 then '1Call'
|
when co_manage_cnt = 2 then '2Call'
|
else 'nCall' end ,
|
@{toTempTable}.co_manage_type_name =
|
case when co_manage_cnt = 1 then null
|
when co_manage_cnt = 2 then '双Call'
|
else '多Call' end
|
where @{toTempTable}.io_batch_id = '@{ioBatchId}' and @{toTempTable}.co_manage_type_code is null
|
]]>
|
</sql>
|
|
<sql name="importSetCurrentPlanningId">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.planning_id = (select id from tgt_planning order by quarter_no desc limit 1 )
|
where @{toTempTable}.io_batch_id = '@{ioBatchId}' and @{toTempTable}.planning_id is null
|
]]>
|
</sql>
|
|
<sql name="importUpdateInitAmt">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.init_amt = init_qty * price
|
where @{toTempTable}.io_batch_id = '@{ioBatchId}' and @{toTempTable}.init_amt is null
|
]]>
|
</sql>
|
|
<sql name="importUpdateDefaultFinal">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.final_amt = init_amt, final_qty = init_qty
|
where @{toTempTable}.io_batch_id = '@{ioBatchId}' and @{toTempTable}.final_amt is null
|
]]>
|
</sql>
|
|
<sql name="importUpdateFinal">
|
<![CDATA[
|
update tgt_planning_detail
|
left join @{toTempTable} on @{toTempTable}.quarter_no = tgt_planning_detail.quarter_no
|
and @{toTempTable}.position_id = tgt_planning_detail.position_id
|
and @{toTempTable}.territory_id = tgt_planning_detail.territory_id
|
and @{toTempTable}.customer_id = tgt_planning_detail.customer_id
|
and @{toTempTable}.sku_id = tgt_planning_detail.sku_id and @{toTempTable}.io_batch_id = '@{ioBatchId}'
|
set tgt_planning_detail.final_amt = ifnull(@{toTempTable}.final_amt, 0),
|
tgt_planning_detail.final_qty = ifnull(@{toTempTable}.final_qty, 0)
|
]]>
|
</sql>
|
|
<sql name="importUpdateDefaultIssue">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.issue_amt = final_amt, issue_qty = final_qty
|
where @{toTempTable}.io_batch_id = '@{ioBatchId}' and @{toTempTable}.issue_amt is null
|
]]>
|
</sql>
|
|
<sql name="importUpdateDefaultPre">
|
<![CDATA[
|
update @{toTempTable}
|
set @{toTempTable}.pre_amt = 0, pre_qty = 0
|
where @{toTempTable}.io_batch_id = '@{ioBatchId}' and @{toTempTable}.pre_amt is null
|
]]>
|
</sql>
|
|
<sql name="importCalculatePre3MSales">
|
<![CDATA[
|
update @{toTempTable}
|
left join tgt_flow_last3 on tgt_flow_last3.customer_id = @{toTempTable}.customer_id and tgt_flow_last3.sku_id = @{toTempTable}.sku_id
|
and tgt_flow_last3.position_id = @{toTempTable}.position_id and tgt_flow_last3.quarter_no = @{toTempTable}.quarter_no
|
set @{toTempTable}.sales_amt = ifnull(tgt_flow_last3.position_amt, 0) , @{toTempTable}.sales_qty = ifnull(tgt_flow_last3.position_qty , 0)
|
where @{toTempTable}.io_batch_id = '@{ioBatchId}' and @{toTempTable}.sales_amt is null
|
]]>
|
</sql>
|
|
<sql name="importCalculateProductivity">
|
<![CDATA[
|
update @{toTempTable}
|
left join tgt_productity_quarter on tgt_productity_quarter.institution_id = @{toTempTable}.customer_id
|
and tgt_productity_quarter.sku_id = @{toTempTable}.sku_id
|
set @{toTempTable}.vbp_productivity_amt = if(tgt_productity_quarter.productivity is null or tgt_productity_quarter.tag != 'VBP', 0, tgt_productity_quarter.productivity),
|
@{toTempTable}.no_vbp_productivity_amt = if(tgt_productity_quarter.productivity is null or tgt_productity_quarter.tag != 'NoVBP', 0, tgt_productity_quarter.productivity)
|
where @{toTempTable}.io_batch_id = '@{ioBatchId}' and @{toTempTable}.vbp_productivity_amt is null
|
]]>
|
</sql>
|
|
<sql name="importCalculateYoy">
|
<![CDATA[
|
update @{toTempTable}
|
left join (
|
select year, quarter, territory_id, position_id, customer_id, sku_id,sum(final_amt) final_amt, sum(final_qty) final_qty
|
from tgt_working_detail group by year, quarter, territory_id, position_id,customer_id,sku_id
|
) history_planning_detail on history_planning_detail.year + 1 = @{toTempTable}.year
|
and history_planning_detail.quarter = @{toTempTable}.quarter
|
and history_planning_detail.territory_id = @{toTempTable}.territory_id
|
and history_planning_detail.position_id = @{toTempTable}.position_id
|
and history_planning_detail.sku_id = @{toTempTable}.sku_id
|
and history_planning_detail.customer_id = @{toTempTable}.customer_id
|
set @{toTempTable}.history_amt = ifnull(history_planning_detail.final_amt, 0) ,
|
@{toTempTable}.history_qty = ifnull(history_planning_detail.final_qty, 0)
|
where @{toTempTable}.io_batch_id = '@{ioBatchId}' and @{toTempTable}.history_amt is null
|
]]>
|
</sql>
|
|
<sql name="importCalculateMom">
|
<![CDATA[
|
update @{toTempTable}
|
left join (
|
select year, quarter, territory_id, position_id, customer_id, sku_id,sum(final_amt) final_amt, sum(final_qty) final_qty
|
from tgt_working_detail group by year, quarter, territory_id, position_id,customer_id,sku_id
|
) history_planning_detail on history_planning_detail.year*4 + history_planning_detail.quarter + 1= @{toTempTable}.year*4 + @{toTempTable}.quarter
|
and history_planning_detail.territory_id = @{toTempTable}.territory_id
|
and history_planning_detail.position_id = @{toTempTable}.position_id
|
and history_planning_detail.sku_id = @{toTempTable}.sku_id
|
and history_planning_detail.customer_id = @{toTempTable}.customer_id
|
set @{toTempTable}.mom_amt = ifnull(history_planning_detail.final_amt, 0) ,
|
@{toTempTable}.mom_qty = ifnull(history_planning_detail.final_qty, 0)
|
where @{toTempTable}.io_batch_id = '@{ioBatchId}' and @{toTempTable}.mom_amt is null
|
]]>
|
</sql>
|
|
<sql name="importSummaryPlanning">
|
<![CDATA[
|
update tgt_planning
|
inner join (
|
select planning_id, sum(init_amt) init_amt, sum(issue_amt) actual_amt, sum(history_amt) history_amt,
|
sum(final_amt) final_amt, sum(init_qty) init_qty, sum(issue_qty) actual_qty, sum(history_qty) history_qty,
|
sum(final_qty) final_qty from tgt_planning_detail group by planning_id
|
) v_planning on v_planning.planning_id = tgt_planning.id
|
set tgt_planning.init_amt = v_planning.init_amt, tgt_planning.init_qty = v_planning.init_qty,
|
tgt_planning.actual_amt = v_planning.actual_amt, tgt_planning.actual_qty = v_planning.actual_qty,
|
tgt_planning.final_amt = v_planning.final_amt, tgt_planning.final_qty = v_planning.final_qty
|
]]>
|
</sql>
|
|
<sql name="importCalculateInitRate">
|
<![CDATA[
|
update tgt_planning_detail
|
inner join tgt_planning on tgt_planning.id = tgt_planning_detail.planning_id
|
set tgt_planning_detail.init_rate = tgt_planning_detail.init_qty/tgt_planning.init_qty
|
]]>
|
</sql>
|
|
<sql name="importCalculateActualRate">
|
<![CDATA[
|
update tgt_planning_detail
|
inner join tgt_planning on tgt_planning.id = tgt_planning_detail.planning_id
|
set tgt_planning_detail.actual_rate = tgt_planning_detail.final_qty/ tgt_planning.final_qty
|
]]>
|
</sql>
|
|
<sql name="importCalculateInitTeamRate">
|
<![CDATA[
|
update tgt_planning_detail
|
inner join (
|
select planning_id, territory_id, position_id,sum(init_qty) init_qty
|
from tgt_planning_detail group by planning_id, territory_id, position_id
|
) tgt_planning_position on tgt_planning_position.planning_id = tgt_planning_detail.planning_id
|
and tgt_planning_position.position_id = tgt_planning_detail.position_id and tgt_planning_position.territory_id = tgt_planning_detail.territory_id
|
set tgt_planning_detail.init_rate_team = tgt_planning_detail.init_qty / tgt_planning_position.init_qty
|
]]>
|
</sql>
|
|
<sql name="importCalculateActualTeamRate">
|
<![CDATA[
|
update tgt_planning_detail
|
inner join (
|
select planning_id, territory_id, position_id, sum(final_qty) final_qty
|
from tgt_planning_detail group by planning_id, territory_id, position_id
|
) tgt_planning_position on tgt_planning_position.planning_id = tgt_planning_detail.planning_id
|
and tgt_planning_position.position_id = tgt_planning_detail.position_id and tgt_planning_position.territory_id = tgt_planning_detail.territory_id
|
set tgt_planning_detail.actual_rate_team = tgt_planning_detail.final_qty / tgt_planning_position.final_qty
|
]]>
|
</sql>
|
</dataSpace>
|
|
<dataSpace name="importSetError">
|
|
<sql name="importCheckMatchDocument">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '业务数据不匹配'
|
where io_batch_id = '@{ioBatchId}' and is_error is null and not @{filter}
|
]]>
|
</sql>
|
|
<sql name="importCheckCompanyId">
|
<![CDATA[
|
update @{toTempTable} set error_message = '公司主体无法识别'
|
where io_batch_id = '@{ioBatchId}' and company_id is null
|
]]>
|
</sql>
|
|
<sql name="importCheckBuId">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = 'BU无法识别'
|
where io_batch_id = '@{ioBatchId}' and bu_id is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckCustomerId">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '客户无法识别'
|
where io_batch_id = '@{ioBatchId}' and customer_id is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckAccountId">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '客户无法识别'
|
where io_batch_id = '@{ioBatchId}' and account_id is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckOrgId">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '客商无法识别'
|
where io_batch_id = '@{ioBatchId}' and org_id is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckNCId">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '客商无首营'
|
where io_batch_id = '@{ioBatchId}' and org_ncc_id is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckConnectedOrgId">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '授权客商无法识别'
|
where io_batch_id = '@{ioBatchId}' and connected_org_id is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckDateFrom">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '开始日期为空'
|
where io_batch_id = '@{ioBatchId}' and date_from is null and is_error is null
|
]]>
|
</sql>
|
|
|
<sql name="importCheckDocDate">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '开始日期为空'
|
where io_batch_id = '@{ioBatchId}' and doc_date is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckExpireDate">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '到期日期为空'
|
where io_batch_id = '@{ioBatchId}' and expire_date is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckDateTo">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '到期日期为空'
|
where io_batch_id = '@{ioBatchId}' and date_to is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckValidFrom">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '生产日期格式未能识别'
|
where io_batch_id = '@{ioBatchId}' and valid_from is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckValidTo">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '效期格式未能识别'
|
where io_batch_id = '@{ioBatchId}'
|
and valid_to is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckValidFromUnique">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '生产日期与已存在库存不一致'
|
where io_batch_id = '@{ioBatchId}' and is_error is null and exists (
|
select 1 from wm_book_detail
|
where wm_book_detail.product_id = @{toTempTable}.product_id
|
and wm_book_detail.warehouse_id = @{toTempTable}.warehouse_id
|
and wm_book_detail.batch_no = @{toTempTable}.batch_no
|
and wm_book_detail.batch_sn = @{toTempTable}.batch_sn
|
and wm_book_detail.valid_from != @{toTempTable}.valid_from)
|
]]>
|
</sql>
|
|
<sql name="importCheckValidToUnique">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '有效期与已存在库存不一致'
|
where io_batch_id = '@{ioBatchId}' and is_error is null and exists (
|
select 1 from wm_book_detail
|
where wm_book_detail.product_id = @{toTempTable}.product_id
|
and wm_book_detail.warehouse_id = @{toTempTable}.warehouse_id
|
and wm_book_detail.batch_no = @{toTempTable}.batch_no
|
and wm_book_detail.batch_sn = @{toTempTable}.batch_sn
|
and wm_book_detail.valid_to != @{toTempTable}.valid_to)
|
]]>
|
</sql>
|
|
<sql name="importCheckType">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '类型无法识别'
|
where io_batch_id = '@{ioBatchId}' and type_code is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckProductId">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '产品无法识别'
|
where io_batch_id = '@{ioBatchId}' and product_id is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckSkuId">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '无法识别规格'
|
where io_batch_id = '@{ioBatchId}' and sku_id is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckDistinctSkuId">
|
<![CDATA[
|
update @{toTempTable}
|
set is_error = 'T', error_message = 'SKU不唯一'
|
where io_batch_id = '@{ioBatchId}' and is_error is null
|
and EXISTS (
|
select 1 from (
|
select company_id, bu_id, sku_id from @{toTempTable}
|
where io_batch_id = '@{ioBatchId}'
|
group by sku_id, company_id, bu_id
|
HAVING count(1) > 1
|
) tempSkuGroup
|
where @{toTempTable}.sku_id = tempSkuGroup.sku_id
|
and @{toTempTable}.bu_id = tempSkuGroup.bu_id
|
and @{toTempTable}.company_id = tempSkuGroup.company_id
|
)
|
]]>
|
</sql>
|
|
<sql name="importCheckGiftProductId">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '买赠产品无法识别'
|
where io_batch_id = '@{ioBatchId}' and gift_product_id is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckPolicyName">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '政策名称为空'
|
where io_batch_id = '@{ioBatchId}' and policy_name is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckPrice">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '价格无法识别'
|
where io_batch_id = '@{ioBatchId}'
|
and price is null
|
and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckAmtBook">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '折扣金额无法识别'
|
where io_batch_id = '@{ioBatchId}'
|
and amt_book is null
|
and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckQtyBook">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '记账数量无法识别'
|
where io_batch_id = '@{ioBatchId}'
|
and qty_book is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckEmptionQty">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '购买数量无法识别'
|
where io_batch_id = '@{ioBatchId}'
|
and emption_qty is null
|
and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckGiftQty">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '买赠数量无法识别'
|
where io_batch_id = '@{ioBatchId}'
|
and gift_qty is null
|
and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckQty">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '数量无法识别'
|
where io_batch_id = '@{ioBatchId}'
|
and qty is null
|
and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckStockQty">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '库存数量不足'
|
where io_batch_id = '@{ioBatchId}' and is_error is null
|
and ( EXISTS (
|
select 1 from (
|
select book_detail_id from (
|
select book_detail_id, sum(qty) qty
|
from @{toTempTable}
|
where io_batch_id = '@{ioBatchId}'
|
group by book_detail_id ) document
|
left join wm_book_detail on document.book_detail_id = wm_book_detail.id
|
where wm_book_detail.qty_available < document.qty ) errorStock
|
where errorStock.book_detail_id = @{toTempTable}.book_detail_id
|
) or @{toTempTable}.book_detail_id is null)
|
]]>
|
</sql>
|
|
<sql name="importCheckHospital">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '医院无法识别'
|
where io_batch_id = '@{ioBatchId}' and hospital_id is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckEmployeeId">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '员工编号为空'
|
where io_batch_id = '@{ioBatchId}' and employee_id is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckEmployeeMatch">
|
<![CDATA[
|
update @{toTempTable} set error_message = '员工无法识别'
|
where io_batch_id = '@{ioBatchId}' and employee_code is not null and employee_id is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckPositionId">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '岗位编码为空'
|
where io_batch_id = '@{ioBatchId}' and position_id is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckDistinctPosition">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '岗位编码不唯一'
|
where io_batch_id = '@{ioBatchId}' and is_error is null
|
and EXISTS (
|
select 1 from (
|
select position_id from @{toTempTable} position
|
where position.io_batch_id = '@{ioBatchId}'
|
group by position_id
|
having count(position_id) > 1
|
) v where @{toTempTable}.position_id = v.position_id )
|
]]>
|
</sql>
|
|
<sql name="importCheckDistinctPositionHospital">
|
<![CDATA[
|
update @{toTempTable}
|
set is_error = 'T', error_message = '医院+BU+科室不唯一'
|
where io_batch_id = '@{ioBatchId}' and is_error is null
|
and EXISTS (
|
select 1 from (
|
select bu_id, hospital_id ,department from temp_position_hospital
|
where io_batch_id = '@{ioBatchId}'
|
group by bu_id, hospital_id ,department
|
HAVING count(1) > 1
|
) tempHospitalGroup
|
where temp_position_hospital.hospital_id = tempHospitalGroup.hospital_id
|
and tempHospitalGroup.bu_id = temp_position_hospital.bu_id
|
and @{IfEmpty}(tempHospitalGroup.department,'--') = @{IfEmpty}(temp_position_hospital.department ,'--')
|
)
|
]]>
|
</sql>
|
|
<sql name="importCheckDistinctTargetHospital">
|
<![CDATA[
|
update @{toTempTable}
|
set is_error = 'T', error_message = '年份+公司+BU+医院+科室不唯一'
|
where io_batch_id = '@{ioBatchId}' and is_error is null
|
and EXISTS (
|
select 1 from (
|
select year, company_id, bu_id, hospital_id ,department from @{toTempTable}
|
where io_batch_id = '@{ioBatchId}'
|
group by year, company_id, bu_id, hospital_id ,department
|
HAVING count(1) > 1
|
) tempHospitalGroup
|
where @{toTempTable}.hospital_id = tempHospitalGroup.hospital_id
|
and tempHospitalGroup.company_id = @{toTempTable}.company_id
|
and tempHospitalGroup.bu_id = @{toTempTable}.bu_id
|
and tempHospitalGroup.year = @{toTempTable}.year
|
and @{IfEmpty}(tempHospitalGroup.department,'--') = @{IfEmpty}(@{toTempTable}.department ,'--')
|
)
|
]]>
|
</sql>
|
|
<sql name="importCheckTargetHospitalExist">
|
<![CDATA[
|
update @{toTempTable}
|
set is_error = 'T', error_message = '年份+公司+BU+医院+科室系统已存在'
|
where io_batch_id = '@{ioBatchId}' and is_error is null
|
and EXISTS (
|
select 1 from @{toTable}
|
where @{toTempTable}.hospital_id = @{toTable}.hospital_id
|
and @{toTempTable}.company_id = @{toTable}.company_id
|
and @{toTempTable}.bu_id = @{toTable}.bu_id
|
and @{toTempTable}.year = @{toTable}.year
|
and @{IfEmpty}(@{toTempTable}.department,'--') = @{IfEmpty}(@{toTable}.department ,'--')
|
)
|
]]>
|
</sql>
|
|
<sql name="importCheckTargetHospitalExist">
|
<![CDATA[
|
update @{toTempTable}
|
set is_error = 'T', error_message = '年份+公司+BU+医院+科室系统已存在'
|
where io_batch_id = '@{ioBatchId}' and is_error is null
|
and EXISTS (
|
select 1 from @{toTable}
|
where @{toTempTable}.hospital_id = @{toTable}.hospital_id
|
and @{toTempTable}.company_id = @{toTable}.company_id
|
and @{toTempTable}.bu_id = @{toTable}.bu_id
|
and @{toTempTable}.year = @{toTable}.year
|
and @{IfEmpty}(@{toTempTable}.department,'--') = @{IfEmpty}(@{toTable}.department ,'--')
|
)
|
]]>
|
</sql>
|
|
<sql name="importCheckCategoryCode">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '授权分类无法识别'
|
where io_batch_id = '@{ioBatchId}' and category_code is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckTermCode">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '授权类型无法识别'
|
where io_batch_id = '@{ioBatchId}' and term_code is null and is_error is null
|
]]>
|
</sql>
|
|
<sql name="importCheckActorCode">
|
<![CDATA[
|
update @{toTempTable} set is_error = 'T', error_message = '角色无法匹配'
|
where io_batch_id = '@{ioBatchId}' and actor_code is null and is_error is null
|
]]>
|
</sql>
|
</dataSpace>
|
|
<dataSpace name="imporSelectError">
|
|
<sql name="importGetImportErrors">
|
<![CDATA[
|
select error_message, count(1) error_count from @{toTempTable}
|
where io_batch_id = '@{ioBatchId}' and is_error = 'T'
|
group by error_message
|
]]>
|
</sql>
|
|
</dataSpace>
|
</sqls>
|