|  |  |  | 
|---|
|  |  |  | WITH  total as (select | 
|---|
|  |  |  | DISTINCT(t.device_no) device_no,t.curr_node,t.node_content,t.number,p.pro_name, p.plan_name,u.id user_id,u.`name` user_name | 
|---|
|  |  |  | FROM | 
|---|
|  |  |  | (select * from sta_device_production_log_past | 
|---|
|  |  |  | where repair_id IS NULL and out_time BETWEEN #{startDt} AND #{endDt} | 
|---|
|  |  |  | (select DISTINCT device_no,plan_id,station_id,curr_node,node_content,number,updated_by from sta_device_production_log_past | 
|---|
|  |  |  | <!-- repair_id IS NULL and  --> | 
|---|
|  |  |  | where out_time BETWEEN #{startDt} AND #{endDt} | 
|---|
|  |  |  | union | 
|---|
|  |  |  | select * from sta_device_production_log | 
|---|
|  |  |  | where repair_id IS NULL and out_time BETWEEN #{startDt} AND #{endDt} | 
|---|
|  |  |  | select DISTINCT device_no,plan_id,station_id,curr_node,node_content,number,updated_by from sta_device_production_log | 
|---|
|  |  |  | where out_time BETWEEN #{startDt} AND #{endDt} | 
|---|
|  |  |  | ) t | 
|---|
|  |  |  | left join (select pap.id,pap.`name` as plan_name,pp.`name` as pro_name | 
|---|
|  |  |  | from  pr_assembly_plan pap, plt_product pp where pap.pro_id = pp.id) p on t.plan_id = p.id | 
|---|
|  |  |  | left JOIN ba_user u on u.id=t.updated_by) | 
|---|
|  |  |  | left JOIN ba_user u on u.id=t.updated_by), | 
|---|
|  |  |  | WITH  assistants_total as (select t.device_no,t.curr_node,t.node_content,t.number,p.pro_name, p.plan_name,u.id user_id,u.`name` user_name | 
|---|
|  |  |  | FROM | 
|---|
|  |  |  | ( SELECT a.*,SUBSTRING_INDEX( SUBSTRING_INDEX( a.assistants, ',', b.help_topic_id + 1 ), ',', - 1 ) AS assistant FROM | 
|---|
|  |  |  | (select DISTINCT device_no,plan_id,station_id,curr_node,node_content,number,updated_by,assistants from sta_device_production_log_past | 
|---|
|  |  |  | where assistants IS NOT NULL AND out_time BETWEEN  #{startDt} AND #{endDt} | 
|---|
|  |  |  | union | 
|---|
|  |  |  | select DISTINCT device_no,plan_id,station_id,curr_node,node_content,number,updated_by,assistants from sta_device_production_log | 
|---|
|  |  |  | where assistants IS NOT NULL AND out_time BETWEEN #{startDt} AND #{endDt}) a | 
|---|
|  |  |  | JOIN mysql.help_topic AS b ON b.help_topic_id <![CDATA[ < ]]> ( LENGTH( a.assistants ) - LENGTH( REPLACE ( a.assistants, ',', '' ) ) + 1 ) | 
|---|
|  |  |  | ) t | 
|---|
|  |  |  | left join (select pap.id,pap.`name` as plan_name,pp.`name` as pro_name | 
|---|
|  |  |  | from  pr_assembly_plan pap, plt_product pp where pap.pro_id = pp.id) p on t.plan_id = p.id | 
|---|
|  |  |  | left JOIN ba_user u on u.id=t.assistant) | 
|---|
|  |  |  | select DATE_FORMAT(#{startDt}, '%Y-%m-%d') as statistic_date,user_id, user_name,'计划任务' AS type, node_content ,sum(number) as number  from total where curr_node IS NOT NULL GROUP BY user_id,user_name,node_content | 
|---|
|  |  |  | UNION | 
|---|
|  |  |  | select DATE_FORMAT(#{startDt}, '%Y-%m-%d') as statistic_date, user_id,  user_name,'临时任务' AS type, node_content, sum(number) as number  from total where curr_node IS NULL AND (device_no !='' AND device_no IS NOT NULL) | 
|---|
|  |  |  | GROUP BY user_id,user_name,node_content | 
|---|
|  |  |  | UNION | 
|---|
|  |  |  | select DATE_FORMAT(#{startDt}, '%Y-%m-%d') as statistic_date,user_id , user_name,'临时任务(无设备码)' AS type,node_content, sum(number) as number  from total where curr_node IS NULL AND (device_no IS NULL OR device_no ='') | 
|---|
|  |  |  | GROUP BY user_id,user_name,node_content | 
|---|
|  |  |  | UNION | 
|---|
|  |  |  | select DATE_FORMAT(#{startDt}, '%Y-%m-%d') as statistic_date,user_id , user_name,'辅助工作' AS type,node_content, sum(number) as number  from assistants_total | 
|---|
|  |  |  | GROUP BY user_id,user_name,node_content; | 
|---|
|  |  |  | </insert> | 
|---|
|  |  |  | <update id="updateByPrimaryKeySelective" parameterType="com.dy.pmsGlobal.pojoOth.OthStatisticWorkload"> | 
|---|