SGGL_SHJ/DataBase/版本日志/SGGLDB_V2025-10-23-001-bwj.sql

124 lines
5.8 KiB
MySQL
Raw Normal View History

2025-10-23 16:35:37 +08:00
ALTER PROCEDURE [dbo].[Sp_HJGL_ProductionPlanStatistics]
@projectId nvarchar(50)=null
AS
BEGIN
SET NOCOUNT ON; -- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
-- ʹ<><CAB9>CTEԤ<45>ȹ<EFBFBD><C8B9>˺;ۺ<CDBE><DBBA><EFBFBD><EFBFBD><EFBFBD>
WITH PipelineFiltered AS (
SELECT UnitWorkId, FlowingSection, PipelineId
FROM HJGL_Pipeline
WHERE PipeArea='1'
AND FlowingSection IS NOT NULL
AND FlowingSection != ''
AND (@projectId IS NULL OR UnitWorkId IN (
SELECT UnitWorkId FROM WBS_UnitWork WHERE ProjectId = @projectId
))
),
-- <20><><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD>
TotalDiaCTE AS (
SELECT p.UnitWorkId, p.FlowingSection, SUM(wj.Size) as TotalDia
FROM HJGL_WeldJoint wj
INNER JOIN PipelineFiltered p ON p.PipelineId = wj.PipelineId
WHERE wj.JointAttribute='Ԥ<EFBFBD>ƿ<EFBFBD>'
GROUP BY p.UnitWorkId, p.FlowingSection
),
-- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD>
CurrentDayCompletedCTE AS (
SELECT p.UnitWorkId, p.FlowingSection, SUM(wj.Size) as CurrentDayCompletedDia
FROM HJGL_WeldJoint wj
INNER JOIN PipelineFiltered p ON p.PipelineId = wj.PipelineId
INNER JOIN HJGL_WeldingDaily wd ON wd.WeldingDailyId = wj.WeldingDailyId
WHERE wj.JointAttribute='Ԥ<EFBFBD>ƿ<EFBFBD>'
AND wj.WeldingDailyId IS NOT NULL
AND wd.WeldingDate >= CAST(GETDATE() AS DATE) -- <20>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD>ڱȽϣ<C8BD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD>Χ
AND wd.WeldingDate < DATEADD(DAY, 1, CAST(GETDATE() AS DATE))
GROUP BY p.UnitWorkId, p.FlowingSection
),
-- <20>ۼ<EFBFBD><DBBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TotalCompletedCTE AS (
SELECT p.UnitWorkId, p.FlowingSection, SUM(wj.Size) as totalCompletedDia
FROM HJGL_WeldJoint wj
INNER JOIN PipelineFiltered p ON p.PipelineId = wj.PipelineId
WHERE wj.JointAttribute='Ԥ<EFBFBD>ƿ<EFBFBD>'
AND wj.WeldingDailyId IS NOT NULL
GROUP BY p.UnitWorkId, p.FlowingSection
),
-- <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WelderCountCTE AS (
SELECT p.UnitWorkId, p.FlowingSection,
COUNT(DISTINCT pp.PersonId) as WelderCount -- ʹ<><CAB9>DISTINCT<43><54><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD>
FROM Person_Persons pp
INNER JOIN HJGL_WeldJoint wj ON wj.BackingWelderId = pp.PersonId
INNER JOIN PipelineFiltered p ON p.PipelineId = wj.PipelineId
WHERE wj.JointAttribute='Ԥ<EFBFBD>ƿ<EFBFBD>'
AND wj.WeldingDailyId IS NOT NULL
GROUP BY p.UnitWorkId, p.FlowingSection
)--,
---- Ԥ<><D4A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
--WarningWelderCountCTE AS (
-- SELECT p.UnitWorkId, p.FlowingSection,
-- COUNT(DISTINCT pp.PersonId) as WarningWelderCount
-- FROM Person_Persons pp
-- INNER JOIN HJGL_WeldJoint wj ON wj.BackingWelderId = pp.PersonId
-- INNER JOIN PipelineFiltered p ON p.PipelineId = wj.PipelineId
-- INNER JOIN Welder_WelderQualify wq ON wq.WelderId = pp.PersonId
-- WHERE wj.JointAttribute='Ԥ<>ƿ<EFBFBD>'
-- AND wj.WeldingDailyId IS NOT NULL
-- AND wq.LimitDate < GETDATE() -- <20><><EFBFBD><EFBFBD><EFBFBD>ʸ<EFBFBD><CAB8><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4>
-- GROUP BY p.UnitWorkId, p.FlowingSection
--)
SELECT DISTINCT
unitWork.UnitWorkId,
unitWork.UnitWorkCode,
unitWork.UnitWorkName,
unitWork.ProjectId,
pipeline.FlowingSection,
isnull(total.TotalDia,0) as TotalDia,--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><EFBFBD><EFBFBD>
p.PlanStartDate,--<EFBFBD>ƻ<EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
p.PlanEndDate,--<EFBFBD>ƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
--(DATEDIFF(day, p.PlanStartDate, p.PlanEndDate) +1) as TotalDays,--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
--(case when p.PlanEndDate>= getdate() then (DATEDIFF(day, p.PlanStartDate, p.PlanEndDate)-(DATEDIFF(day,p.PlanStartDate,GETDATE()))) else '' end) as RemainingDays,--ʣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
--(case when DATEDIFF(day, p.PlanStartDate, p.PlanEndDate)>0 then cast(isnull(total.TotalDia,0)/DATEDIFF(day, p.PlanStartDate, p.PlanEndDate) as decimal(18,2)) else 0 end) as AvgDayCompleteDia, --ƽ<EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ISNULL(currentDay.CurrentDayCompletedDia,0) as CurrentDayCompletedDia, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
--cast(case when (case when p.PlanEndDate>= getdate() then (DATEDIFF(day, p.PlanStartDate, p.PlanEndDate)-(DATEDIFF(day,p.PlanStartDate,GETDATE()))) else 0 end)>0 then
--(isnull(total.TotalDia,0)-isnull(totalCompleted.totalCompletedDia,0))/ (case when p.PlanEndDate>= getdate() then (DATEDIFF(day, p.PlanStartDate, p.PlanEndDate)-(DATEDIFF(day,p.PlanStartDate,GETDATE()))) else 0 end) else 0 end as decimal(18,2)) as NextDayComplete, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
isnull(totalCompleted.totalCompletedDia,0) as totalCompletedDia, --<EFBFBD>ۼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cast(cast((case when isnull(total.TotalDia,0)>0 then
(isnull(totalCompleted.totalCompletedDia,0) / isnull(total.TotalDia,0)*100) else 0 end) as decimal(18,2)) as varchar(10))+'%' as CompletedRate, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɰٷֱ<EFBFBD>
welder.WelderCount, --<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
--warningWelder.WarningWelderCount --Ԥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
(case when welder.WelderCount>0 then cast((ISNULL(currentDay.CurrentDayCompletedDia,0)/welder.WelderCount) as decimal(18,2)) else 0 end) as WarningWelderCount--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD>Ч
FROM WBS_UnitWork AS unitWork
INNER JOIN PipelineFiltered pipeline ON pipeline.UnitWorkId = unitWork.UnitWorkId -- ʹ<><CAB9>INNER JOIN<49><4E><EFBFBD><EFBFBD>Ϊpipeline<6E><65><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
--LEFT JOIN HJGL_ProductionSchedulingPlan p ON p.PipelineId = unitWork.UnitWorkId AND p.FlowNum = pipeline.FlowingSection
--<EFBFBD>Ų<EFBFBD><EFBFBD>ƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
left join (select min(PlanStartDate) as PlanStartDate,max(PlanEndDate) as PlanEndDate,PipelineId,FlowNum from HJGL_ProductionSchedulingPlan
group by PipelineId,FlowNum
) as p on p.PipelineId=unitWork.UnitWorkId and p.FlowNum = pipeline.FlowingSection
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><EFBFBD><EFBFBD>
LEFT JOIN TotalDiaCTE total ON total.UnitWorkId = unitWork.UnitWorkId AND total.FlowingSection = pipeline.FlowingSection
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LEFT JOIN CurrentDayCompletedCTE currentDay ON currentDay.UnitWorkId = unitWork.UnitWorkId AND currentDay.FlowingSection = pipeline.FlowingSection
--<EFBFBD>ۼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LEFT JOIN TotalCompletedCTE totalCompleted ON totalCompleted.UnitWorkId = unitWork.UnitWorkId AND totalCompleted.FlowingSection = pipeline.FlowingSection
--<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LEFT JOIN WelderCountCTE welder ON welder.UnitWorkId = unitWork.UnitWorkId AND welder.FlowingSection = pipeline.FlowingSection
--Ԥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
--LEFT JOIN WarningWelderCountCTE warningWelder ON warningWelder.UnitWorkId = unitWork.UnitWorkId AND warningWelder.FlowingSection = pipeline.FlowingSection
WHERE (@projectId IS NULL OR unitWork.ProjectId = @projectId)
AND pipeline.FlowingSection IS NOT NULL
END
GO