SGGL_HBAZ/DataBase/版本日志/SGGLDB_V2025-09-08-001-bwj.sql

85 lines
4.5 KiB
Transact-SQL

insert into Sys_Menu(MenuId,MenuName,Url,SortIndex,SuperMenu,MenuType,IsOffice,IsEnd,IsUsed)
values('0F3ECADA-F108-4C24-979C-67CA49E3726B','焊接统计分析表','HJGL/WeldingReport/WeldingStatistical.aspx',5,'F3B157B7-9BEE-4150-80CB-087828F1C51D','Menu_HJGL',0,1,1)
go
alter table ProjectData_WorkArea add CompletionDate datetime
go
CREATE PROC [dbo].[sp_rpt_WeldingStatistical]
@AreaNo nVARCHAR(50) = NULL,
@installationId nVARCHAR(50) = NULL,
@startTime datetime = NULL,
@endTime datetime = NULL,
@projectId NVARCHAR(50) = NULL,
@IsStandard NVARCHAR(50) = NULL
AS
/*焊接统计分析表*/
SELECT WorkArea.WorkAreaId,
WorkArea.ProjectId,
WorkArea.WorkAreaCode AS baw_areano,--工区代号
Unit.UnitCode AS bsu_unitcode,--单位代码
Unit.UnitName AS bsu_unitname, --单位名称
Installation.InstallationCode, --装置代号
Installation.InstallationName, --装置名称
ISNULL(total_jot.total_jot,0) AS total_jot, --总焊口
CAST(ISNULL(total_jot.total_din,0) AS DECIMAL(19,2)) AS total_din,--总达因
--施工工队 按焊工代号汇集数量,按施工队再次自动汇总
(select top 1 ProjectData_TeamGroup.TeamGroupName from PW_JointInfo
left join PW_IsoInfo on PW_IsoInfo.ISO_ID = PW_JointInfo.ISO_ID
left join BS_Welder on BS_Welder.WED_ID = PW_JointInfo.JOT_CellWelder
left join ProjectData_TeamGroup on ProjectData_TeamGroup.TeamGroupId= BS_Welder.TeamGroupId
where PW_IsoInfo.WorkAreaId = WorkArea.WorkAreaId and PW_JointInfo.DReportID is not null and BS_Welder.TeamGroupId is not null) as TeamGroup,
CAST(ISNULL(finished_total_jot_bq.finished_total_din_bq ,0) AS DECIMAL(19,2)) AS finished_total_din_bq, --本期完成达因
(CAST(ISNULL(total_jot.total_din,0)-ISNULL(finished_total_jot_bq.finished_total_din_bq ,0) AS DECIMAL(19,2))) as RemainingDain, --剩余达因(总达因-本期完成达因)
getdate() as CurrentDate,--当日日期
WorkArea.CompletionDate, --竣工日期
(DATEDIFF(DAY, getdate(), WorkArea.CompletionDate)+1) as RemainingConPeriod,--剩余工期
CEILING(case when (DATEDIFF(DAY, getdate(), WorkArea.CompletionDate)+1)>0 then
(ISNULL(total_jot.total_din,0)-ISNULL(finished_total_jot_bq.finished_total_din_bq ,0))/(DATEDIFF(DAY, getdate(), WorkArea.CompletionDate)+1)
else '0' end) as AvgDayCompletedDin,--日均应完成达因
(getdate()-1) as CurrentCompleted, --当日完成
(cast(isnull(finished_current_day_din.finished_current_day_din,0) as decimal(19,2))) as finished_current_day_din --当日完成达因
FROM ProjectData_WorkArea AS WorkArea
LEFT JOIN Base_Unit AS Unit ON WorkArea.UnitId =Unit.UnitId
LEFT JOIN Project_Installation AS Installation ON Installation.InstallationId = WorkArea.InstallationId
LEFT JOIN (SELECT COUNT(*) total_jot ,pw_isoinfo.WorkAreaId ,SUM(JOT_Size) AS total_din
,SUM(JOT_DoneDin) AS finished_total_din
FROM pw_jointinfo
LEFT JOIN pw_isoinfo ON pw_jointinfo.ISO_ID = pw_isoinfo.ISO_ID
WHERE (pw_isoinfo.Is_Standard=@IsStandard OR @IsStandard IS NULL)
GROUP BY pw_isoinfo.WorkAreaId) AS total_jot ON total_jot.WorkAreaId = WorkArea.WorkAreaId
LEFT JOIN (SELECT COUNT(*) finished_total_jot_bq ,pw_isoinfo.WorkAreaId ,SUM(JOT_DoneDin) AS finished_total_din_bq
FROM pw_jointinfo
LEFT JOIN pw_isoinfo ON pw_jointinfo.ISO_ID = pw_isoinfo.ISO_ID
LEFT JOIN BO_WeldReportMain ON BO_WeldReportMain.dreportid = pw_jointinfo.dreportid
WHERE pw_jointinfo.DReportID is not null
and (jot_welddate >= @startTime OR @startTime IS NULL) and (jot_welddate <=@endTime OR @endTime IS NULL) AND
(pw_isoinfo.Is_Standard=@IsStandard OR @IsStandard IS NULL)
GROUP BY pw_isoinfo.WorkAreaId) AS finished_total_jot_bq ON finished_total_jot_bq.WorkAreaId = WorkArea.WorkAreaId
--当日完成达因
LEFT JOIN (SELECT pw_isoinfo.WorkAreaId ,SUM(JOT_DoneDin) AS finished_current_day_din
FROM pw_jointinfo
LEFT JOIN pw_isoinfo ON pw_jointinfo.ISO_ID = pw_isoinfo.ISO_ID
LEFT JOIN BO_WeldReportMain ON BO_WeldReportMain.dreportid = pw_jointinfo.dreportid
WHERE pw_jointinfo.DReportID is not null
and (CONVERT(varchar(10), jot_welddate, 23) = CONVERT(varchar(10), GETDATE()-1, 23) ) AND
(pw_isoinfo.Is_Standard=@IsStandard OR @IsStandard IS NULL)
GROUP BY pw_isoinfo.WorkAreaId) AS finished_current_day_din ON finished_current_day_din.WorkAreaId = WorkArea.WorkAreaId
WHERE
(WorkArea.ProjectId=@projectId OR @projectId IS NULL ) AND
(WorkArea.WorkAreaId=@areano OR @AreaNo IS NULL ) AND
(WorkArea.InstallationId=@installationId OR @installationId IS NULL)
ORDER BY Unit.UnitCode ,Installation.InstallationCode
GO