|
|
|
@ -284,4 +284,95 @@ |
|
|
|
) AS subquery |
|
|
|
WHERE rn > 1 and rn2 = 1; |
|
|
|
</select> |
|
|
|
<select id="getEamWorkOrderCoreComponentsList3" resultType="com.xujie.sys.modules.pms.entity.EamWorkOrderCoreComponentsData"> |
|
|
|
WITH SerialStatus AS ( |
|
|
|
SELECT |
|
|
|
site, |
|
|
|
bu_no, |
|
|
|
OrderNo, |
|
|
|
partno, |
|
|
|
oldSerialNo AS serialNo, |
|
|
|
'下机' AS action, |
|
|
|
created_by, |
|
|
|
created_date |
|
|
|
FROM eam_workOrder_coreComponents |
|
|
|
WHERE oldSerialNo IS NOT NULL |
|
|
|
UNION ALL |
|
|
|
SELECT |
|
|
|
site, |
|
|
|
bu_no, |
|
|
|
OrderNo, |
|
|
|
partno, |
|
|
|
newSerialNo AS serialNo, |
|
|
|
'上机' AS action, |
|
|
|
created_by, |
|
|
|
created_date |
|
|
|
FROM eam_workOrder_coreComponents |
|
|
|
WHERE newSerialNo IS NOT NULL |
|
|
|
), |
|
|
|
RankedSerials AS ( |
|
|
|
SELECT |
|
|
|
site, |
|
|
|
bu_no, |
|
|
|
OrderNo, |
|
|
|
partno, |
|
|
|
serialNo, |
|
|
|
action, |
|
|
|
created_by, |
|
|
|
created_date, |
|
|
|
ROW_NUMBER() OVER (PARTITION BY partno, serialNo,SerialStatus.action ORDER BY created_date) AS rn |
|
|
|
FROM SerialStatus |
|
|
|
), |
|
|
|
TimeDifferences AS ( |
|
|
|
SELECT |
|
|
|
site, |
|
|
|
bu_no, |
|
|
|
OrderNo, |
|
|
|
partno, |
|
|
|
serialNo, |
|
|
|
action, |
|
|
|
created_by, |
|
|
|
created_date, |
|
|
|
CASE |
|
|
|
WHEN action = '上机' THEN '第' + CAST(rn AS VARCHAR) + '次上机' |
|
|
|
WHEN action = '下机' THEN '第' + CAST(rn AS VARCHAR) + '次下机' |
|
|
|
END AS status, |
|
|
|
DATEDIFF(MONTH, |
|
|
|
LAG(created_date) OVER (PARTITION BY partno, serialNo ORDER BY created_date), |
|
|
|
created_date |
|
|
|
) AS time_diff_months |
|
|
|
FROM RankedSerials |
|
|
|
) |
|
|
|
SELECT |
|
|
|
ewc.site, |
|
|
|
ewc.bu_no, |
|
|
|
ewc.OrderNo, |
|
|
|
ewc.partno, |
|
|
|
ps.part_description, |
|
|
|
ewc.serialNo, |
|
|
|
ewc.action, |
|
|
|
ewc.created_by, |
|
|
|
ewc.created_date, |
|
|
|
ewc.status as onOffStatus, |
|
|
|
edf.FeedBackDesc, |
|
|
|
ewc.time_diff_months |
|
|
|
FROM TimeDifferences ewc |
|
|
|
LEFT JOIN part_spare ps ON ewc.site = ps.site AND ewc.bu_no = ps.bu_no AND ewc.partNo = ps.part_no |
|
|
|
LEFT JOIN eam_workOrder ew ON ewc.site = ew.site AND ewc.bu_no = ew.bu_no AND ewc.OrderNo = ew.OrderNo |
|
|
|
LEFT JOIN eam_defect_feedBack edf on ew.site = edf.site and ew.PlanID = edf.feedBackID and ew.bu_no = edf.bu_no |
|
|
|
WHERE ps.coreFlag = 'Y' |
|
|
|
<if test="query.site != null and query.site != ''"> |
|
|
|
and ewc.site = #{query.site} |
|
|
|
</if> |
|
|
|
<if test="query.buNo != null and query.buNo != ''"> |
|
|
|
and ewc.bu_no = #{query.buNo} |
|
|
|
</if> |
|
|
|
<if test="query.partNo != null and query.partNo != ''"> |
|
|
|
and ewc.partNo = #{query.partNo} |
|
|
|
</if> |
|
|
|
<if test="query.partDescription != null and query.partDescription != ''"> |
|
|
|
and ps.part_description like '%'+ #{query.partDescription} +'%' |
|
|
|
</if> |
|
|
|
ORDER BY partno, serialNo, created_date |
|
|
|
</select> |
|
|
|
</mapper> |