67 lines
4.9 KiB
MySQL
67 lines
4.9 KiB
MySQL
|
|
CREATE PROCEDURE [dbo].[Sp_HJGL_ProductionPlanStatistics]
|
|||
|
|
@projectId nvarchar(50)=null
|
|||
|
|
AS
|
|||
|
|
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>
|
|||
|
|
p.Days as TotalDays,--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
(case when p.PlanEndDate>= getdate() then (p.Days-(DATEDIFF(day,p.PlanStartDate,GETDATE()))) else '' end) as RemainingDays,--ʣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
(case when p.Days>0 then cast(isnull(total.TotalDia,0)/p.Days 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 (p.Days-(DATEDIFF(day,p.PlanStartDate,GETDATE()))) else 0 end)>0 then
|
|||
|
|
(isnull(total.TotalDia,0)-isnull(totalCompleted.totalCompletedDia,0))/ (case when p.PlanEndDate>= getdate() then (p.Days-(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>
|
|||
|
|
FROM WBS_UnitWork AS unitWork
|
|||
|
|
LEFT JOIN (select FlowingSection,UnitWorkId from HJGL_Pipeline where PipeArea='1' and FlowingSection is not null and FlowingSection!='') as pipeline on pipeline.UnitWorkId = unitWork.UnitWorkId
|
|||
|
|
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>
|
|||
|
|
left join (select sum(Size) as TotalDia,HJGL_Pipeline.UnitWorkId,HJGL_Pipeline.FlowingSection from HJGL_WeldJoint
|
|||
|
|
left join HJGL_Pipeline on HJGL_Pipeline.PipelineId = HJGL_WeldJoint.PipelineId
|
|||
|
|
where HJGL_Pipeline.PipeArea='1' and HJGL_WeldJoint.JointAttribute='Ԥ<EFBFBD>ƿ<EFBFBD>'
|
|||
|
|
group by HJGL_Pipeline.UnitWorkId,HJGL_Pipeline.FlowingSection) as 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 (select sum(Size) as CurrentDayCompletedDia,HJGL_Pipeline.UnitWorkId,HJGL_Pipeline.FlowingSection from HJGL_WeldJoint
|
|||
|
|
left join HJGL_Pipeline on HJGL_Pipeline.PipelineId = HJGL_WeldJoint.PipelineId
|
|||
|
|
left join HJGL_WeldingDaily on HJGL_WeldingDaily.WeldingDailyId = HJGL_WeldJoint.WeldingDailyId
|
|||
|
|
where HJGL_Pipeline.PipeArea='1' and HJGL_WeldJoint.JointAttribute='Ԥ<EFBFBD>ƿ<EFBFBD>'
|
|||
|
|
and HJGL_WeldJoint.WeldingDailyId is not null
|
|||
|
|
and YEAR(HJGL_WeldingDaily.WeldingDate)=YEAR(GETDATE())
|
|||
|
|
and MONTH(HJGL_WeldingDaily.WeldingDate)=MONTH(GETDATE())
|
|||
|
|
and DAY(HJGL_WeldingDaily.WeldingDate)=DAY(GETDATE())
|
|||
|
|
group by HJGL_Pipeline.UnitWorkId,HJGL_Pipeline.FlowingSection) as currentDay on currentDay.UnitWorkId = unitWork.UnitWorkId and currentDay.FlowingSection = pipeline.FlowingSection
|
|||
|
|
|
|||
|
|
--<EFBFBD>ۼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
left join (select sum(Size) as totalCompletedDia,HJGL_Pipeline.UnitWorkId,HJGL_Pipeline.FlowingSection from HJGL_WeldJoint
|
|||
|
|
left join HJGL_Pipeline on HJGL_Pipeline.PipelineId = HJGL_WeldJoint.PipelineId
|
|||
|
|
where HJGL_Pipeline.PipeArea='1' and HJGL_WeldJoint.JointAttribute='Ԥ<EFBFBD>ƿ<EFBFBD>'
|
|||
|
|
and HJGL_WeldJoint.WeldingDailyId is not null
|
|||
|
|
group by HJGL_Pipeline.UnitWorkId,HJGL_Pipeline.FlowingSection) as totalCompleted on totalCompleted.UnitWorkId = unitWork.UnitWorkId and totalCompleted.FlowingSection = pipeline.FlowingSection
|
|||
|
|
|
|||
|
|
--<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
left join (select count(*) as WelderCount,HJGL_Pipeline.UnitWorkId,HJGL_Pipeline.FlowingSection from Person_Persons
|
|||
|
|
left join HJGL_WeldJoint on HJGL_WeldJoint.BackingWelderId = Person_Persons.PersonId
|
|||
|
|
left join HJGL_Pipeline on HJGL_Pipeline.PipelineId = HJGL_WeldJoint.PipelineId
|
|||
|
|
where HJGL_Pipeline.PipeArea='1' and HJGL_WeldJoint.JointAttribute='Ԥ<EFBFBD>ƿ<EFBFBD>'
|
|||
|
|
and HJGL_WeldJoint.WeldingDailyId is not null
|
|||
|
|
group by HJGL_Pipeline.UnitWorkId,HJGL_Pipeline.FlowingSection) as welder on welder.UnitWorkId = unitWork.UnitWorkId and welder.FlowingSection = pipeline.FlowingSection
|
|||
|
|
|
|||
|
|
--Ԥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
left join (select count(*) as WarningWelderCount,HJGL_Pipeline.UnitWorkId,HJGL_Pipeline.FlowingSection from Person_Persons
|
|||
|
|
left join HJGL_WeldJoint on HJGL_WeldJoint.BackingWelderId = Person_Persons.PersonId
|
|||
|
|
left join HJGL_Pipeline on HJGL_Pipeline.PipelineId = HJGL_WeldJoint.PipelineId
|
|||
|
|
where HJGL_Pipeline.PipeArea='1' and HJGL_WeldJoint.JointAttribute='Ԥ<EFBFBD>ƿ<EFBFBD>'
|
|||
|
|
and HJGL_WeldJoint.WeldingDailyId is not null
|
|||
|
|
and PersonId in (select WelderId from Welder_WelderQualify where LimitDate < GETDATE())
|
|||
|
|
group by HJGL_Pipeline.UnitWorkId,HJGL_Pipeline.FlowingSection) as warningWelder on warningWelder.UnitWorkId = unitWork.UnitWorkId and warningWelder.FlowingSection = pipeline.FlowingSection
|
|||
|
|
|
|||
|
|
where unitWork.ProjectId = @projectId
|
|||
|
|
and pipeline.FlowingSection is not null
|