select dt.label, aa.old_activity_date , aa.activity_date , case when cc.rate is null then aa.eqp_name else concat(concat(aa.eqp_name ,' 利用率:'),concat(decode(substr(cc.rate,1,1),'.','0'||cc.rate,cc.rate),'%')) end as eqpName from sys_dict dt left join ( select ss.ID, ss.eqp_code, ss.eqp_name, ss.States, case when '${start_date}' is null then ss.old_activity_date when ss.old_activity_date < to_date('${start_date}', 'yyyy-mm-dd hh24:mi:ss') then to_date('${start_date}', 'yyyy-mm-dd hh24:mi:ss') else ss.old_activity_date end as old_activity_date, case when '${end_date}' is null then ss.activity_date when ss.activity_date < to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') then ss.activity_date else to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') end as activity_date from ( SELECT T.ID, eq.eqp_code, eq.eqp_name, t.old_state as States, t.old_activity_date, t.activity_date FROM mp_eqp_activity t left join mc_eqp_eqpver eq on eq.equipment_id = t.eqp_id and eq.del_flag='0' where t.old_state is not null and t.activity_date is not null and t.eqp_activity='AdjustState' and t.old_activity_date is not null and (t.eqp_name like '%${eqp_name}%' or '${eqp_name}' is null) and (('${start_date}' is null and '${end_date}' is null) or ('${start_date}' is null and t.activity_date < to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') ) or (t.activity_date >= to_date('${start_date}', 'yyyy-mm-dd hh24:mi:ss') and '${end_date}' is null ) or (t.old_activity_date >= to_date('${start_date}', 'yyyy-mm-dd hh24:mi:ss') and t.old_activity_date < to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') ) or (t.activity_date >= to_date('${start_date}', 'yyyy-mm-dd hh24:mi:ss') and t.activity_date < to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') ) ) union all select c.ID, c.eqp_code, c.eqp_name, case when '${end_date}' is null then c.NEW_STATE when c.activity_date >= to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') then c.OLD_STATE else c.NEW_STATE end as status, case when '${end_date}' is null then c.activity_date when c.activity_date >= to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') then c.old_activity_date else c.activity_date end as old_activity_date, case when '${end_date}' is null then sysdate when c.activity_date >= to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') then c.activity_date else SYSDATE end as activity_date from (SELECT T.ID, eq.eqp_code, eq.eqp_name, t.old_state, t.new_state, t.old_activity_date, t.activity_date, row_number() over(partition by t.eqp_id order by t.activity_date desc) rn FROM mp_eqp_activity t left join mc_eqp_eqpver eq on eq.equipment_id = t.eqp_id and eq.del_flag='0' where t.old_state is not null and t.activity_date is not null and t.eqp_activity='AdjustState' and t.old_activity_date is not null and (t.eqp_name like '%${eqp_name}%' or '${eqp_name}' is null) and (('${start_date}' is null and '${end_date}' is null) or ('${start_date}' is null and t.activity_date < to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') ) or (t.activity_date >= to_date('${start_date}', 'yyyy-mm-dd hh24:mi:ss') and '${end_date}' is null ) or (t.old_activity_date >= to_date('${start_date}', 'yyyy-mm-dd hh24:mi:ss') and t.old_activity_date < to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') ) or (t.activity_date >= to_date('${start_date}', 'yyyy-mm-dd hh24:mi:ss') and t.activity_date < to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') ) ) ) c where c.rn = 1 and ('${end_date}' is null or c.activity_date < to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') ) ) ss )aa on dt.VALUE =aa.states left join ( select pp.eqp_code,round(sum((TO_DATE(to_char(pp.activity_date,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss')- TO_DATE(to_char(pp.old_activity_date,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss'))) /(to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss')-to_date('${start_date}', 'yyyy-mm-dd hh24:mi:ss')+1)*100,2) as rate from (select ss.ID, ss.eqp_code, ss.eqp_name, ss.States, case when '${start_date}' is null then ss.old_activity_date when ss.old_activity_date < to_date('${start_date}', 'yyyy-mm-dd hh24:mi:ss') then to_date('${start_date}', 'yyyy-mm-dd hh24:mi:ss') else ss.old_activity_date end as old_activity_date, case when '${end_date}' is null then ss.activity_date when ss.activity_date < to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') then ss.activity_date else to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') end as activity_date from ( SELECT T.ID, eq.eqp_code, eq.eqp_name, t.old_state as States, t.old_activity_date, t.activity_date FROM mp_eqp_activity t left join mc_eqp_eqpver eq on eq.equipment_id = t.eqp_id and eq.del_flag='0' where t.old_state is not null and t.activity_date is not null and t.eqp_activity='AdjustState'-- and t.old_state='InWork' and t.old_activity_date is not null and (t.eqp_name like '%${eqp_name}%' or '${eqp_name}' is null) and (('${start_date}' is null and '${end_date}' is null) or ('${start_date}' is null and t.activity_date < to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') ) or (t.activity_date >= to_date('${start_date}', 'yyyy-mm-dd hh24:mi:ss') and '${end_date}' is null ) or (t.old_activity_date >= to_date('${start_date}', 'yyyy-mm-dd hh24:mi:ss') and t.old_activity_date < to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') ) or (t.activity_date >= to_date('${start_date}', 'yyyy-mm-dd hh24:mi:ss') and t.activity_date < to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') ) ) union all select c.ID, c.eqp_code, c.eqp_name, case when '${end_date}' is null then c.NEW_STATE when c.activity_date >= to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') then c.OLD_STATE else c.NEW_STATE end as status, case when '${end_date}' is null then c.activity_date when c.activity_date >= to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') then c.old_activity_date else c.activity_date end as old_activity_date, case when '${end_date}' is null then sysdate when c.activity_date >= to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') then c.activity_date else SYSDATE end as activity_date from (SELECT T.ID, eq.eqp_code, eq.eqp_name, t.old_state, t.new_state, t.old_activity_date, t.activity_date, row_number() over(partition by t.eqp_id order by t.activity_date desc) rn FROM mp_eqp_activity t left join mc_eqp_eqpver eq on eq.equipment_id = t.eqp_id and eq.del_flag='0' where t.old_state is not null and t.activity_date is not null and t.eqp_activity='AdjustState' --and t.old_state='InWork' and t.old_activity_date is not null and (t.eqp_name like '%${eqp_name}%' or '${eqp_name}' is null) and (('${start_date}' is null and '${end_date}' is null) or ('${start_date}' is null and t.activity_date < to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') ) or (t.activity_date >= to_date('${start_date}', 'yyyy-mm-dd hh24:mi:ss') and '${end_date}' is null ) or (t.old_activity_date >= to_date('${start_date}', 'yyyy-mm-dd hh24:mi:ss') and t.old_activity_date < to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') ) or (t.activity_date >= to_date('${start_date}', 'yyyy-mm-dd hh24:mi:ss') and t.activity_date < to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') ) ) ) c where c.rn = 1 and ('${end_date}' is null or c.activity_date < to_date('${end_date}', 'yyyy-mm-dd hh24:mi:ss') ) ) ss)pp where pp.States='InWork' group by pp.eqp_code)cc on aa.eqp_code = cc.eqp_code where dt.type='MC_EQP_EQUIPMENT.EQP_STATE' order by aa.eqp_code, aa.eqp_name, aa.activity_date,decode(dt.label,'设备待料',1,'正常生产',2,'计划停机',3,'故障维修',4,'故障停机',5,'设备扣留',6,'设备调试',7) |
最佳回答 |
||||
0
|
|