HJGL_DS/DataBase/版本日志/HJGLDB_DS_2025-05-12_gf.sql

522 lines
27 KiB
Transact-SQL

CREATE PROC [dbo].[HJGL_sp_rpt_welderPerformanceSum]
@unitcode VARCHAR(50) = NULL,
@steel VARCHAR(50) = NULL,
@WED_ID NVARCHAR(50) = NULL,
@date1 DATETIME = NULL,
@date2 DATETIME = NULL,
@projectId NVARCHAR(500) = NULL,
@installationId NVARCHAR(50)=NULL
AS
/*焊工业绩分析*/
SELECT
NEWID() AS Id,
-------------本期start
CAST(ISNULL(total.totalSize,0) AS DECIMAL(19,2)) AS totalSize, --总寸径
ISNULL(total.totalJoint,0) AS totalJoint, --总焊口
ISNULL(JointNum1.JointNum1,0) AS JointNum1, --一次拍片焊口数
ISNULL(JointNum1.JointNum1,0)-ISNULL(JointNoPassNum1.JointNoPassNum1,0) AS JointPassNum1, --一次拍片合格焊口数
ISNULL(JointNoPassNum1.JointNoPassNum1,0) AS RepairJoint1, --一次返修焊口数
ISNULL(RepairJoint2.RepairJoint2,0) AS RepairJoint2, --二次返修焊口数
ISNULL(RepairJoint3.RepairJoint3,0) AS RepairJoint3, --三次返修焊口数
CAST((CASE ISNULL((ISNULL(JointNum1.JointNum1,0)-ISNULL(JointNoPassNum1.JointNoPassNum1,0)),0) WHEN 0 THEN 0
ELSE (CASE(ISNULL(JointNum1.JointNum1,0)) WHEN 0 THEN 0
ELSE 1.0 * ISNULL((ISNULL(JointNum1.JointNum1,0)-ISNULL(JointNoPassNum1.JointNoPassNum1,0)),0)/(1.0 * JointNum1.JointNum1)
END)END) AS DECIMAL(19,3)) AS JointPassRate , ---一次拍片焊口合格率
ISNULL(JointNum1.totalfilm,0) AS totalfilm, --一次拍片数
(ISNULL(JointNum1.totalfilm,0)- ISNULL(JointNoPassNum2.JointNoPassFilmNum2,0)) AS totalPassfilm, --一次拍片合格数
ISNULL(JointNoPassNum2.JointNoPassFilmNum2,0) AS repairFilm1, --一次返修片子数
ISNULL(RepairJoint2.repairFilm2,0) AS repairFilm2, --二次返修片子数
ISNULL(RepairJoint3.repairFilm3,0) AS repairFilm3, --三次返修片子数
CAST((CASE (ISNULL(JointNum1.totalfilm,0)- ISNULL(JointNoPassNum2.JointNoPassFilmNum2,0)) WHEN 0 THEN 0
ELSE (CASE(ISNULL(JointNum1.totalfilm,0)) WHEN 0 THEN 0
ELSE 1.0 * (ISNULL(JointNum1.totalfilm,0)- ISNULL(JointNoPassNum2.JointNoPassFilmNum2,0))/(1.0 * JointNum1.totalfilm)
END) END) AS DECIMAL(19,3)) AS JointFilmPassRate ---一次拍片合格率
FROM
--总达因值 --总焊口
(SELECT SUM(joint.JOT_Size) AS totalSize,COUNT(*) AS totalJoint
,joint.ProjectId,joint.InstallationId,iso.BSU_ID
FROM HJGL_PW_JointInfo joint
LEFT JOIN HJGL_PW_IsoInfo iso ON iso.ISO_ID = joint.ISO_ID
LEFT JOIN HJGL_BO_WeldReportMain report ON joint.DReportID = report.DReportID
WHERE joint.DReportID IS NOT NULL
AND (report.JOT_WeldDate >= @date1 OR @date1 IS NULL) AND (report.JOT_WeldDate <= @date2 OR @date2 IS NULL)
AND (joint.ste_id=@steel OR @steel IS NULL)
GROUP BY joint.ProjectId,joint.InstallationId,iso.BSU_ID) AS total
--一次拍片焊口数 , 一次拍片总数,一次拍片合格总数
LEFT JOIN (SELECT COUNT(joint.JOT_ID) AS JointNum1, SUM(joint.RT_FilmNum) AS totalfilm,
joint.ProjectId,joint.InstallationId,iso.BSU_ID
FROM HJGL_PW_JointInfo joint
LEFT JOIN HJGL_PW_IsoInfo iso ON iso.ISO_ID = joint.ISO_ID
WHERE joint.PointType='点口' AND joint.RT_FilmNum IS NOT NULL and joint.RT_FilmNum>0 and (select COUNT(*) from dbo.HJGL_BO_QualityRating where JOT_ID=joint.JOT_ID and FilmNum is not null)>0
AND (joint.ste_id=@steel OR @steel IS NULL) AND joint.dreportid IS NOT NULL
AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_BO_QualityRating WHERE JOT_ID=joint.JOT_ID)>= @date1 OR @date1 IS NULL)
AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_BO_QualityRating WHERE JOT_ID=joint.JOT_ID)<= @date2 OR @date2 IS NULL)
GROUP BY joint.ProjectId,joint.InstallationId,iso.BSU_ID) AS JointNum1
ON JointNum1.ProjectId=total.ProjectId AND JointNum1.InstallationId = total.InstallationId
AND JointNum1.BSU_ID = total.BSU_ID
--一次拍片不合格焊口数
LEFT JOIN (SELECT COUNT(distinct joint.JOT_ID) AS JointNoPassNum1,
joint.ProjectId,joint.InstallationId,iso.BSU_ID
FROM HJGL_PW_JointInfo joint
LEFT JOIN HJGL_PW_IsoInfo iso ON iso.ISO_ID = joint.ISO_ID
left join dbo.HJGL_CH_RepairItemRecord rr on rr.JOT_ID=joint.JOT_ID
WHERE joint.PointType='点口' AND (joint.RT1_RepairFilm IS NOT NULL or (select top 1 CH_TrustItemID from dbo.HJGL_CH_TrustItem ti where ti.JOT_ID=joint.JOT_ID and ti.States='4') is not null)
AND (joint.ste_id=@steel OR @steel IS NULL) AND joint.dreportid IS NOT NULL and rr.RepairMark='R1'
AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R1')>= @date1 OR @date1 IS NULL)
AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R1')<= @date2 OR @date2 IS NULL)
GROUP BY joint.ProjectId,joint.InstallationId,iso.BSU_ID) AS JointNoPassNum1
ON JointNoPassNum1.ProjectId=total.ProjectId AND JointNoPassNum1.InstallationId = total.InstallationId
AND JointNoPassNum1.BSU_ID = total.BSU_ID
--一次拍片不合格拍片数
LEFT JOIN (SELECT count(rr.RepairItemRecordId) as JointNoPassFilmNum2,
joint.ProjectId,joint.InstallationId,iso.BSU_ID
FROM dbo.HJGL_CH_RepairItemRecord rr
left join HJGL_PW_JointInfo joint on rr.JOT_ID=joint.JOT_ID
LEFT JOIN HJGL_PW_IsoInfo iso ON iso.ISO_ID = joint.ISO_ID
WHERE joint.PointType='点口'
--AND (joint.RT1_RepairFilm IS NOT NULL or (select top 1 CH_TrustItemID from dbo.HJGL_CH_TrustItem ti where ti.JOT_ID=joint.JOT_ID and ti.States='4') is not null)
AND (joint.ste_id=@steel OR @steel IS NULL) AND joint.dreportid IS NOT NULL and rr.RepairMark='R1'
AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R1')>= @date1 OR @date1 IS NULL)
AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R1')<= @date2 OR @date2 IS NULL)
GROUP BY joint.ProjectId,joint.InstallationId,iso.BSU_ID) AS JointNoPassNum2
ON JointNoPassNum2.ProjectId=total.ProjectId AND JointNoPassNum2.InstallationId = total.InstallationId
AND JointNoPassNum2.BSU_ID = total.BSU_ID
--二次返修拍片焊口数,二次返修拍片总数
LEFT JOIN (SELECT COUNT(joint.JOT_ID) AS RepairJoint2, SUM(ISNULL(joint.RT2_RepairFilmNum,0)) AS RepairFilm2,
joint.ProjectId,joint.InstallationId,iso.BSU_ID
FROM HJGL_PW_JointInfo joint
LEFT JOIN HJGL_PW_IsoInfo iso ON iso.ISO_ID = joint.ISO_ID
WHERE joint.PointType='点口' AND joint.RT2_RepairFilm IS NOT NULL
AND (joint.ste_id=@steel OR @steel IS NULL) AND joint.dreportid IS NOT NULL
AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R2')>= @date1 OR @date1 IS NULL)
AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R2')<= @date2 OR @date2 IS NULL)
GROUP BY joint.ProjectId,joint.InstallationId,iso.BSU_ID) AS RepairJoint2
ON RepairJoint2.ProjectId=total.ProjectId AND RepairJoint2.InstallationId = total.InstallationId
AND RepairJoint2.BSU_ID = total.BSU_ID
--三次返修拍片焊口数,三次返修拍片总数
LEFT JOIN (SELECT COUNT(joint.JOT_ID) AS RepairJoint3, SUM(ISNULL(joint.RT3_RepairFilmNum,0)) AS RepairFilm3,
joint.ProjectId,joint.InstallationId,iso.BSU_ID
FROM HJGL_PW_JointInfo joint
LEFT JOIN HJGL_PW_IsoInfo iso ON iso.ISO_ID = joint.ISO_ID
WHERE joint.PointType='点口' AND joint.RT3_RepairFilm IS NOT NULL
AND (joint.ste_id=@steel OR @steel IS NULL) AND joint.dreportid IS NOT NULL
AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R3')>= @date1 OR @date1 IS NULL)
AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R3')<= @date2 OR @date2 IS NULL)
GROUP BY joint.ProjectId,joint.InstallationId,iso.BSU_ID) AS RepairJoint3
ON RepairJoint3.ProjectId=total.ProjectId AND RepairJoint3.InstallationId = total.InstallationId
AND RepairJoint3.BSU_ID = total.BSU_ID
LEFT JOIN Base_Project project ON total.ProjectId=project.ProjectId
WHERE
(CHARINDEX(total.ProjectId,@projectId)>0 OR @projectId IS NULL)
AND (total.InstallationId = @installationId OR @installationId IS NULL)
AND (total.BSU_ID=@unitcode OR @unitcode IS NULL)
--AND (total.Welder = @WED_ID OR @WED_ID IS NULL)
GO
ALTER PROC [dbo].[HJGL_sp_rpt_welderStatistics]
@unitcode varchar(50) = NULL,
@WED_ID nvarchar(50) = NULL,
@projectId NVARCHAR(50) = NULL
AS
/*焊工焊接检测统计表*/
SELECT
welder.ProjectId,
project.ProjectCode,--施工号
wld.wed_code,-- 焊工代码
wld.wed_name,--焊工名称
ISNULL(totalJoint.totalJoint,0) AS totalJoint, --已焊焊缝数
ISNULL(TrustJointNum.TrustJointNum,0) AS TrustJointNum, --已委托焊缝数
CAST((CASE ISNULL(TrustJointNum.TrustJointNum,0) WHEN 0 THEN 0
ELSE 1.0 * ISNULL(TrustJointNum.TrustJointNum,0)/(1.0 * totalJoint.totalJoint) END) AS DECIMAL(19,3))
AS OneCheckRate , ---一次检测比例
ISNULL(FixedJoint.FixedJoint,0) AS FixedJoint, --已焊固定口数
ISNULL(TrustFixedJoint.TrustFixedJoint,0) AS TrustFixedJoint, --已委托固定口数
CAST((CASE ISNULL(TrustFixedJoint.TrustFixedJoint,0) WHEN 0 THEN 0
ELSE 1.0 * ISNULL(TrustFixedJoint.TrustFixedJoint,0)/(1.0 * FixedJoint.FixedJoint) END) AS DECIMAL(19,3))
AS FixedJointCheckRate , ---固定口检测比例
ISNULL(ButtJoint.ButtJoint,0) AS ButtJoint, --已焊对接焊缝数
ISNULL(TrustButtJoint.TrustButtJoint,0) AS TrustButtJoint, --已委托对接焊缝数
CAST((CASE ISNULL(TrustButtJoint.TrustButtJoint,0) WHEN 0 THEN 0
ELSE 1.0 * ISNULL(TrustButtJoint.TrustButtJoint,0)/(1.0 * ButtJoint.ButtJoint) END) AS DECIMAL(19,3))
AS ButtJointCheckRate , ---对接焊缝检测比例
ISNULL(FilletJoint.FilletJoint,0) AS FilletJoint, --已焊角焊缝数
ISNULL(TrustFilletJoint.TrustFilletJoint,0) AS TrustFilletJoint, --已委托角焊缝数
CAST((CASE ISNULL(TrustFilletJoint.TrustFilletJoint,0) WHEN 0 THEN 0
ELSE 1.0 * ISNULL(TrustFilletJoint.TrustFilletJoint,0)/(1.0 * FilletJoint.FilletJoint) END) AS DECIMAL(19,3))
AS FilletJointCheckRate
FROM dbo.Project_Welder AS welder
LEFT JOIN Base_Project project on welder.ProjectId=project.ProjectId
LEFT JOIN dbo.HJGL_BS_Welder wld on wld.WED_ID=welder.WED_ID
--已焊焊口数
LEFT JOIN (SELECT COUNT(*) AS totalJoint,HJGL_pw_jointinfo.JOT_CellWelder,ProjectId
FROM HJGL_PW_JointInfo
WHERE HJGL_pw_jointinfo.DReportID is not null
GROUP BY HJGL_pw_jointinfo.JOT_CellWelder,ProjectId) AS totalJoint ON totalJoint.JOT_CellWelder = welder.WED_ID and totalJoint.ProjectId=welder.ProjectId
--已焊固定口数
LEFT JOIN (SELECT COUNT(*) AS FixedJoint,JOT_CellWelder,ProjectId
FROM HJGL_PW_JointInfo
WHERE DReportID is not null AND JOT_JointAttribute='固定'
GROUP BY HJGL_pw_jointinfo.JOT_CellWelder,ProjectId) AS FixedJoint ON FixedJoint.JOT_CellWelder = welder.WED_ID and FixedJoint.ProjectId=welder.ProjectId
--已焊对接焊缝数
LEFT JOIN (SELECT COUNT(*) AS ButtJoint,joint.JOT_CellWelder,ProjectId
FROM HJGL_PW_JointInfo joint
LEFT JOIN dbo.HJGL_BS_JointType jointType on jointType.JOTY_ID=joint.JOTY_ID
WHERE DReportID is not null AND jointType.JOTY_Group='1'
GROUP BY joint.JOT_CellWelder,ProjectId) AS ButtJoint ON ButtJoint.JOT_CellWelder = welder.WED_ID and ButtJoint.ProjectId=welder.ProjectId
--已焊角焊缝数
LEFT JOIN (SELECT COUNT(*) AS FilletJoint,joint.JOT_CellWelder,ProjectId
FROM HJGL_PW_JointInfo joint
LEFT JOIN dbo.HJGL_BS_JointType jointType on jointType.JOTY_ID=joint.JOTY_ID
WHERE DReportID is not null AND jointType.JOTY_Group='2'
GROUP BY joint.JOT_CellWelder,ProjectId) AS FilletJoint ON FilletJoint.JOT_CellWelder = welder.WED_ID and FilletJoint.ProjectId=welder.ProjectId
--已委托焊口数
LEFT JOIN (SELECT COUNT(*) AS TrustJointNum,joint.JOT_CellWelder,ProjectId
FROM dbo.HJGL_BO_BatchDetail batchDetail
LEFT JOIN HJGL_pw_jointinfo joint ON joint.jot_id=batchDetail.jot_id
WHERE (batchDetail.NDT is not null OR batchDetail.NDT!='') and joint.JOT_JointNo not like '%A%' and joint.JOT_JointNo not like '%B%' and batchDetail.PointType!='2'
GROUP BY joint.JOT_CellWelder,ProjectId) AS TrustJointNum ON TrustJointNum.JOT_CellWelder = welder.WED_ID and TrustJointNum.ProjectId=welder.ProjectId
--已委托固定口数
LEFT JOIN (SELECT COUNT(*) AS TrustFixedJoint,joint.JOT_CellWelder,ProjectId
FROM dbo.HJGL_BO_BatchDetail batchDetail
LEFT JOIN HJGL_pw_jointinfo joint ON joint.jot_id=batchDetail.jot_id
WHERE (batchDetail.NDT is not null OR batchDetail.NDT!='')
AND joint.JOT_JointAttribute='固定' and joint.JOT_JointNo not like '%A%' and joint.JOT_JointNo not like '%B%' and batchDetail.PointType!='2'
GROUP BY joint.JOT_CellWelder,ProjectId) AS TrustFixedJoint ON TrustFixedJoint.JOT_CellWelder = welder.WED_ID and TrustFixedJoint.ProjectId=welder.ProjectId
--已委托对接焊缝数
LEFT JOIN (SELECT COUNT(*) AS TrustButtJoint,joint.JOT_CellWelder,ProjectId
FROM dbo.HJGL_BO_BatchDetail batchDetail
LEFT JOIN HJGL_pw_jointinfo joint ON joint.jot_id=batchDetail.jot_id
LEFT JOIN dbo.HJGL_BS_JointType jointType on jointType.JOTY_ID=joint.JOTY_ID
WHERE (batchDetail.NDT is not null OR batchDetail.NDT!='')
AND jointType.JOTY_Group='1' and joint.JOT_JointNo not like '%A%' and joint.JOT_JointNo not like '%B%' and batchDetail.PointType!='2'
GROUP BY joint.JOT_CellWelder,ProjectId) AS TrustButtJoint ON TrustButtJoint.JOT_CellWelder = welder.WED_ID and TrustButtJoint.ProjectId=welder.ProjectId
--已委托角焊缝数
LEFT JOIN (SELECT COUNT(*) AS TrustFilletJoint,joint.JOT_CellWelder,ProjectId
FROM dbo.HJGL_BO_BatchDetail batchDetail
LEFT JOIN HJGL_pw_jointinfo joint ON joint.jot_id=batchDetail.jot_id
LEFT JOIN dbo.HJGL_BS_JointType jointType on jointType.JOTY_ID=joint.JOTY_ID
WHERE (batchDetail.NDT is not null OR batchDetail.NDT!='')
AND jointType.JOTY_Group='2' and joint.JOT_JointNo not like '%A%' and joint.JOT_JointNo not like '%B%' and batchDetail.PointType!='2'
GROUP BY joint.JOT_CellWelder,ProjectId) AS TrustFilletJoint ON TrustFilletJoint.JOT_CellWelder = welder.WED_ID and TrustFilletJoint.ProjectId=welder.ProjectId
WHERE (welder.ProjectId = @projectId OR @projectId IS NULL)
AND (wld.WED_Unit=@unitcode OR @unitcode IS NULL)
AND (wld.WED_ID=@WED_ID OR @WED_ID is null)
order BY wld.WED_Code
GO
ALTER VIEW [dbo].[HJGL_View_JointInfo]
AS
/*管线焊口信息视图*/
SELECT
JointInfo.JOT_ID,
JointInfo.ProjectId,
JointInfo.PointType,
JointInfo.RT1_RepairFilm,
JointInfo.dreportid,
IsoInfo.BSU_ID,
JointInfo.STE_ID,
JOT_JointNo,
JOT_DailyReportNo, --日报告号
(CASE WHEN JointInfo.Jot_WeldingDate IS NOT NULL THEN JointInfo.Jot_WeldingDate
ELSE WeldReportMain.JOT_WeldDate END) AS JOT_WeldDate, --焊接日期
JointInfo.ISO_ID,
ISO_IsoNo, --管线号
Unit.UnitCode,
Unit.UnitName,
Steel.STE_Code AS STE_Name1,--材质1
Steel1.STE_Code AS STE_Name2,--材质2
Welder.WED_Code AS WED_Code1, --盖面焊工代号
Welder.WED_Name AS WED_Name1, --盖面焊工名称
FloorWelder.WED_Code AS WED_Code2, --打底焊工代号
FloorWelder.WED_Name AS WED_Name2, --打底焊工名称
JointInfo.WLO_Code,
(CASE WHEN JointInfo.WLO_Code='F' THEN '现场安装' ELSE '预制' END) AS WLO_Name,--焊接区域
JOT_DoneDin,
IS_Compute,
com1.Com_Name AS Component1,--组件1号
com1.COM_Code AS COM_Code1,--组件1号
com2.COM_Name AS Component2,--组件2号
com2.COM_Code AS COM_Code2,--组件1号
m1.WMT_MatCode AS WeldMat,--焊条
WeldMaterial.WMT_MatCode AS WeldSilk,--焊丝
batchDetail.PointType AS JointStatus,---焊口状态
JOT_Dia,
JOT_Size,
JOT_Sch,
JOT_FactSch,
JOT_JointFlag,
JOT_TrustFlag,
ProessTypes,
JOT_JointDesc,
JointInfo.JOTY_ID,
JointType.JOTY_Name,--焊缝类型
JointType.JOTY_Code,--焊缝类型
JointInfo.WME_ID,
WeldMethod.WME_Name AS WME_Name,--焊接方法
WeldMethod.WME_Code,--焊接方法代码
SlopeType.JST_Name, --坡口类型
SlopeType.JST_Code, --坡口类型代码
IS_Proess,
(CASE WHEN IS_Proess=1 THEN '' ELSE '' END) AS IS_ProessName,
JOT_PrepareTemp,
JOT_CellTemp,
JOT_LastTemp,
JOT_JointAttribute,
JOT_Location,
batch.BatchCode AS BatchCode,--批次号
batchDetail.PointDate AS PointDate,--点口日期
NULL AS CH_TrustCode, NULL AS CH_TrustDate,
--NDTType.NDT_Name as NDT_Name,--探伤类型
JointInfo.JOT_Remark,
JointInfo.RT_States,
JointInfo.UT_States,
JointInfo.MT_States,
JointInfo.PT_States,
JointInfo.PAUT_States,
(case when (select top 1 IsOK from HJGL_CH_HotProessResult hr where hr.JOT_ID=JointInfo.JOT_ID)=1 then '合格'
else '' end) as HotProessResult,
Servicess.SER_Code,--介质代号
--NDTRate.NDTR_Name as NDTR_Name, --探伤比例
--NDTRate.NDTR_Code, --探伤比例
isoInfo.ISO_TestPress,--试验压力
isoInfo.ISO_DesignPress,--设计压力
isoInfo.ISO_DesignTemperature,--设计温度
IsoClass.ISC_IsoCode,--管线等级
is_hj= CAST((CASE WHEN JointInfo.DReportID IS NULL THEN '0' ELSE '1' END ) AS BIT), --是否焊接
if_dk=CAST((CASE WHEN batchDetail.NDT IS NULL THEN '0' ELSE '1' END) AS BIT), --是否点口
JointInfo.InstallationId,
JointInfo.NDTR_ID,
JointInfo.IsSpecial,
JointInfo.IsSpecial AS IsSpecialName, --是否特殊
Installation.InstallationName,--装置
NDTRate.NDTR_Name,
JointInfo.Sort1,JointInfo.Sort2,JointInfo.Sort3,JointInfo.Sort4,JointInfo.Sort5
,JointType.JOTY_Group
FROM HJGL_PW_JointInfo AS JointInfo
LEFT JOIN HJGL_PW_IsoInfo AS IsoInfo ON IsoInfo.ISO_ID=JointInfo.ISO_ID
LEFT JOIN HJGL_BO_WeldReportMain AS WeldReportMain ON WeldReportMain.DReportID=JointInfo.DReportID
LEFT JOIN HJGL_BS_Steel AS Steel ON Steel.STE_ID=JointInfo.STE_ID
LEFT JOIN HJGL_BS_Steel AS Steel1 ON Steel1.STE_ID=JointInfo.STE_ID2
LEFT JOIN HJGL_BS_Welder AS Welder ON Welder.WED_ID= JointInfo.JOT_CellWelder
LEFT JOIN HJGL_BS_Welder AS FloorWelder ON FloorWelder.WED_ID=JointInfo.JOT_FloorWelder
--LEFT JOIN HJGL_BS_WeldLocation AS WeldLocation ON WeldLocation.WLO_Code =JointInfo.WLO_Code
LEFT JOIN HJGL_BS_Component AS com1 ON com1.COM_ID=JointInfo.JOT_Component1
LEFT JOIN HJGL_BS_Component AS com2 ON com2.COM_ID=JointInfo.JOT_Component2
LEFT JOIN HJGL_BS_WeldMaterial m1 ON m1.WMT_ID=JointInfo.JOT_WeldMat
LEFT JOIN HJGL_BS_WeldMaterial AS WeldMaterial ON WeldMaterial.WMT_ID=JointInfo.JOT_WeldSilk
LEFT JOIN HJGL_BS_JointType AS JointType ON JointType.JOTY_ID=JointInfo.JOTY_ID
LEFT JOIN HJGL_BS_WeldMethod AS WeldMethod ON WeldMethod .WME_ID=JointInfo.WME_ID
LEFT JOIN HJGL_BS_SlopeType AS SlopeType ON SlopeType.JST_ID=JointInfo.JST_ID
LEFT JOIN dbo.HJGL_BO_BatchDetail AS batchDetail ON batchDetail.JOT_ID = JointInfo.JOT_ID
LEFT JOIN dbo.HJGL_BO_Batch AS batch ON batch.BatchId = batchDetail.BatchId
LEFT JOIN Base_Unit AS Unit ON Unit.UnitId=IsoInfo.BSU_ID
--left join HJGL_BS_NDTRate AS NDTRate on NDTRate.NDTR_ID=IsoInfo.NDTR_ID
LEFT JOIN HJGL_BS_Service AS Servicess ON Servicess.SER_ID=IsoInfo.SER_ID
LEFT JOIN HJGL_BS_IsoClass AS IsoClass ON IsoClass.ISC_ID=IsoInfo.ISC_ID
LEFT JOIN Project_Installation AS Installation ON Installation.InstallationId =JointInfo.InstallationId
LEFT JOIN HJGL_BS_NDTRate AS NDTRate ON NDTRate.NDTR_ID =JointInfo.NDTR_ID
GO
ALTER PROC [dbo].[HJGL_sp_rpt_welderPerformance]
@unitcode VARCHAR(50) = NULL,
@steel VARCHAR(50) = NULL,
@WED_ID NVARCHAR(50) = NULL,
@date1 DATETIME = NULL,
@date2 DATETIME = NULL,
@projectId NVARCHAR(500) = NULL,
@installationId NVARCHAR(50)=NULL
AS
/*焊工业绩分析*/
SELECT
NEWID() AS Id,
total.ProjectId,
project.ProjectCode,--施工号
total.Welder,
wld.wed_code,-- 焊工代码
wld.wed_name,--焊工名称
wld.WED_Sex, --性别
-------------本期start
CAST(ISNULL(total.totalSize,0) AS DECIMAL(19,2)) AS totalSize, --总寸径
ISNULL(total.totalJoint,0) AS totalJoint, --总焊口
ISNULL(JointNum1.JointNum1,0) AS JointNum1, --一次拍片焊口数
ISNULL(JointNum1.JointNum1,0)-ISNULL(JointNoPassNum1.JointNoPassNum1,0) AS JointPassNum1, --一次拍片合格焊口数
ISNULL(JointNoPassNum1.JointNoPassNum1,0) AS RepairJoint1, --一次返修焊口数
ISNULL(RepairJoint2.RepairJoint2,0) AS RepairJoint2, --二次返修焊口数
ISNULL(RepairJoint3.RepairJoint3,0) AS RepairJoint3, --三次返修焊口数
CAST((CASE ISNULL((ISNULL(JointNum1.JointNum1,0)-ISNULL(JointNoPassNum1.JointNoPassNum1,0)),0) WHEN 0 THEN 0
ELSE (CASE(ISNULL(JointNum1.JointNum1,0)) WHEN 0 THEN 0
ELSE 1.0 * ISNULL((ISNULL(JointNum1.JointNum1,0)-ISNULL(JointNoPassNum1.JointNoPassNum1,0)),0)/(1.0 * JointNum1.JointNum1)
END)END) AS DECIMAL(19,3)) AS JointPassRate , ---一次拍片焊口合格率
ISNULL(JointNum1.totalfilm,0) AS totalfilm, --一次拍片数
(ISNULL(JointNum1.totalfilm,0)- ISNULL(JointNoPassNum2.JointNoPassFilmNum2,0)) AS totalPassfilm, --一次拍片合格数
ISNULL(JointNoPassNum2.JointNoPassFilmNum2,0) AS repairFilm1, --一次返修片子数
ISNULL(RepairJoint2.repairFilm2,0) AS repairFilm2, --二次返修片子数
ISNULL(RepairJoint3.repairFilm3,0) AS repairFilm3, --三次返修片子数
CAST((CASE (ISNULL(JointNum1.totalfilm,0)- ISNULL(JointNoPassNum2.JointNoPassFilmNum2,0)) WHEN 0 THEN 0
ELSE (CASE(ISNULL(JointNum1.totalfilm,0)) WHEN 0 THEN 0
ELSE 1.0 * (ISNULL(JointNum1.totalfilm,0)- ISNULL(JointNoPassNum2.JointNoPassFilmNum2,0))/(1.0 * JointNum1.totalfilm)
END) END) AS DECIMAL(19,3)) AS JointFilmPassRate ---一次拍片合格率
FROM
--总达因值 --总焊口
(SELECT SUM(joint.JOT_Size) AS totalSize,COUNT(*) AS totalJoint
,joint.ProjectId,joint.InstallationId,joint.BSU_ID,joint.Welder
FROM View_JointWelder joint
LEFT JOIN HJGL_BO_WeldReportMain report ON joint.DReportID = report.DReportID
WHERE joint.DReportID IS NOT NULL
AND (report.JOT_WeldDate >= @date1 OR @date1 IS NULL) AND (report.JOT_WeldDate <= @date2 OR @date2 IS NULL)
AND (joint.ste_id=@steel OR @steel IS NULL)
GROUP BY joint.ProjectId,joint.InstallationId,joint.BSU_ID, joint.Welder) AS total
--一次拍片焊口数 , 一次拍片总数,一次拍片合格总数
LEFT JOIN (SELECT COUNT(joint.JOT_ID) AS JointNum1, SUM(joint.RT_FilmNum) AS totalfilm,
joint.ProjectId,joint.InstallationId,joint.BSU_ID,joint.Welder
FROM dbo.View_JointWelder joint
WHERE joint.PointType='点口' AND joint.RT_FilmNum IS NOT NULL and joint.RT_FilmNum>0 and (select COUNT(*) from dbo.HJGL_BO_QualityRating where JOT_ID=joint.JOT_ID and FilmNum is not null)>0
AND (joint.ste_id=@steel OR @steel IS NULL) AND joint.dreportid IS NOT NULL
AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_BO_QualityRating WHERE JOT_ID=joint.JOT_ID)>= @date1 OR @date1 IS NULL)
AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_BO_QualityRating WHERE JOT_ID=joint.JOT_ID)<= @date2 OR @date2 IS NULL)
GROUP BY joint.ProjectId,joint.InstallationId,joint.BSU_ID, joint.Welder) AS JointNum1
ON JointNum1.ProjectId=total.ProjectId AND JointNum1.InstallationId = total.InstallationId
AND JointNum1.BSU_ID = total.BSU_ID AND JointNum1.Welder = total.Welder
--一次拍片不合格焊口数
LEFT JOIN (SELECT COUNT(distinct joint.JOT_ID) AS JointNoPassNum1,
joint.ProjectId,joint.InstallationId,joint.BSU_ID,rr.JOT_CellWelder as Welder
FROM dbo.HJGL_CH_RepairItemRecord rr
left join dbo.HJGL_View_JointInfo joint on rr.JOT_ID=joint.JOT_ID
WHERE joint.PointType='点口' AND (joint.RT1_RepairFilm IS NOT NULL or (select top 1 CH_TrustItemID from dbo.HJGL_CH_TrustItem ti where ti.JOT_ID=joint.JOT_ID and ti.States='4') is not null)
AND (joint.ste_id=@steel OR @steel IS NULL) AND joint.dreportid IS NOT NULL and rr.RepairMark='R1'
AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R1')>= @date1 OR @date1 IS NULL)
AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R1')<= @date2 OR @date2 IS NULL)
GROUP BY joint.ProjectId,joint.InstallationId,joint.BSU_ID, rr.JOT_CellWelder) AS JointNoPassNum1
ON JointNoPassNum1.ProjectId=total.ProjectId AND JointNoPassNum1.InstallationId = total.InstallationId
AND JointNoPassNum1.BSU_ID = total.BSU_ID AND JointNoPassNum1.Welder = total.Welder
--一次拍片不合格拍片数
LEFT JOIN (SELECT count(rr.RepairItemRecordId) as JointNoPassFilmNum2,
joint.ProjectId,joint.InstallationId,joint.BSU_ID,rr.JOT_CellWelder as Welder
FROM dbo.HJGL_CH_RepairItemRecord rr
left join dbo.HJGL_View_JointInfo joint on rr.JOT_ID=joint.JOT_ID
WHERE joint.PointType='点口'
--AND (joint.RT1_RepairFilm IS NOT NULL or (select top 1 CH_TrustItemID from dbo.HJGL_CH_TrustItem ti where ti.JOT_ID=joint.JOT_ID and ti.States='4') is not null)
AND (joint.ste_id=@steel OR @steel IS NULL) AND joint.dreportid IS NOT NULL and rr.RepairMark='R1'
AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R1')>= @date1 OR @date1 IS NULL)
AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R1')<= @date2 OR @date2 IS NULL)
GROUP BY joint.ProjectId,joint.InstallationId,joint.BSU_ID, rr.JOT_CellWelder) AS JointNoPassNum2
ON JointNoPassNum2.ProjectId=total.ProjectId AND JointNoPassNum2.InstallationId = total.InstallationId
AND JointNoPassNum2.BSU_ID = total.BSU_ID AND JointNoPassNum2.Welder = total.Welder
--二次返修拍片焊口数,二次返修拍片总数
LEFT JOIN (SELECT COUNT(joint.JOT_ID) AS RepairJoint2, SUM(ISNULL(joint.RT2_RepairFilmNum,0)) AS RepairFilm2,
joint.ProjectId,joint.InstallationId,joint.BSU_ID,joint.Welder
FROM dbo.View_JointWelder joint
WHERE joint.PointType='点口' AND joint.RT2_RepairFilm IS NOT NULL
AND (joint.ste_id=@steel OR @steel IS NULL) AND joint.dreportid IS NOT NULL
AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R2')>= @date1 OR @date1 IS NULL)
AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R2')<= @date2 OR @date2 IS NULL)
GROUP BY joint.ProjectId,joint.InstallationId,joint.BSU_ID, joint.Welder) AS RepairJoint2
ON RepairJoint2.ProjectId=total.ProjectId AND RepairJoint2.InstallationId = total.InstallationId
AND RepairJoint2.BSU_ID = total.BSU_ID AND RepairJoint2.Welder = total.Welder
--三次返修拍片焊口数,三次返修拍片总数
LEFT JOIN (SELECT COUNT(joint.JOT_ID) AS RepairJoint3, SUM(ISNULL(joint.RT3_RepairFilmNum,0)) AS RepairFilm3,
joint.ProjectId,joint.InstallationId,joint.BSU_ID,joint.Welder
FROM dbo.View_JointWelder joint
WHERE joint.PointType='点口' AND joint.RT3_RepairFilm IS NOT NULL
AND (joint.ste_id=@steel OR @steel IS NULL) AND joint.dreportid IS NOT NULL
AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R3')>= @date1 OR @date1 IS NULL)
AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R3')<= @date2 OR @date2 IS NULL)
GROUP BY joint.ProjectId,joint.InstallationId,joint.BSU_ID, joint.Welder) AS RepairJoint3
ON RepairJoint3.ProjectId=total.ProjectId AND RepairJoint3.InstallationId = total.InstallationId
AND RepairJoint3.BSU_ID = total.BSU_ID AND RepairJoint3.Welder = total.Welder
LEFT JOIN Base_Project project ON total.ProjectId=project.ProjectId
LEFT JOIN dbo.HJGL_BS_Welder wld ON wld.WED_ID=total.Welder
WHERE
(CHARINDEX(total.ProjectId,@projectId)>0 OR @projectId IS NULL)
AND (total.InstallationId = @installationId OR @installationId IS NULL)
AND (wld.WED_Unit=@unitcode OR @unitcode IS NULL)
AND (total.Welder = @WED_ID OR @WED_ID IS NULL)
GO