







--获取当前人待办事项
ALTER  PROCEDURE [dbo].[Sp_Project_GetToDoItems]
	@projectId NVARCHAR(50)=NULL,
	@userId NVARCHAR(200)=NULL
AS
/*获取当前人待办事项*/
BEGIN
SELECT HazardRegisterId AS DataId
	,'B6BE5FE0-CB84-47FF-A6C3-5AD9E1CCE079' AS MenuId
	,'安全巡检待整改' AS MenuName
	,(case when len(register.RegisterDef)>15 then left(register.RegisterDef,15)+'...' else register.RegisterDef end)AS Content
	,UserId
	,users.UserName
	,register.RegisterDate AS DataTime
	,CONVERT(varchar(100),register.RegisterDate, 23) AS DataTimeStr
	,'../HSSE/HiddenInspection/HiddenRectificationRectify.aspx?HazardRegisterId='+register.HazardRegisterId AS PCUrl
FROM HSSE_Hazard_HazardRegister AS register
LEFT JOIN Sys_User AS users ON users.UserId =@userId
WHERE register.ProjectId=@projectId AND
((register.states = '1' AND (register.ResponsibleMan =@userId OR register.CCManIds LIKE ('%'+@userId+'%') ))
)
UNION ALL

SELECT HazardRegisterId AS DataId
	,'B6BE5FE0-CB84-47FF-A6C3-5AD9E1CCE079' AS MenuId
	,'安全巡检待确认' AS MenuName
	,(case when len(register.RegisterDef)>15 then left(register.RegisterDef,15)+'...' else register.RegisterDef end) AS Content
	,UserId
	,users.UserName
	,register.RegisterDate AS DataTime
	,CONVERT(varchar(100),register.RegisterDate, 23) AS DataTimeStr
	,'../HSSE/HiddenInspection/HiddenRectificationConfirm.aspx?HazardRegisterId='+register.HazardRegisterId AS PCUrl
FROM HSSE_Hazard_HazardRegister AS register
LEFT JOIN Sys_User AS users ON users.UserId =@userId
WHERE register.ProjectId=@projectId AND
register.states = '2' AND register.CheckManId =@userId

UNION ALL
SELECT CheckControlCode AS DataId
	,'B3E99BD9-FDC7-4F15-8C3C-A7821AC9E306' AS MenuId
	,'质量巡检待处理' AS MenuName
	,checkControl.QuestionDef AS Content
	,UserId
	,users.UserName
	,checkControl.CheckDate AS DataTime
	,CONVERT(varchar(100),checkControl.CheckDate, 23) AS DataTimeStr
	,'../CQMS/Check/ChecklistEdit.aspx?ToDo=ToDo&CheckControlCode='+checkControl.CheckControlCode AS PCUrl
FROM Check_CheckControl AS checkControl
LEFT JOIN Sys_User AS users ON users.UserId =@userId
WHERE checkControl.ProjectId=@projectId AND
checkControl.State != '7' AND checkControl.CheckControlCode in (select CheckControlCode from Check_CheckControlApprove approve where approve.ApproveType!='S' and approve.ApproveMan=@userId and approve.ApproveDate is null )

UNION ALL
SELECT GJSXID AS DataId
	,'0BEA2126-7A48-40EB-8E21-99148E91A22B' AS MenuId
	,'关键事项待处理' AS MenuName
	,GJSX.Detail AS Content
	,users.UserId
	,users.UserName
	,GJSX.CreateDate AS DataTime
	,CONVERT(varchar(100),GJSX.CreateDate, 23) AS DataTimeStr
	,'../PZHGL/GJSX/GJSXListEdit.aspx?ToDo=ToDo&EditType=Edit&ID='+GJSXID AS PCUrl
FROM GJSX
LEFT JOIN Sys_User AS users ON users.UserId =@userId
WHERE GJSX.ProjectId=@projectId AND
GJSX.State != 0 AND (((select count(*) from GJSX_detail detail where detail.Progress_user=@userId and detail.GJSXID=GJSX.GJSXID)=0
and (select count(*) from GJSX_Process process where process.UserId=@userId and process.GJSXID=GJSX.GJSXID)>0)
or (GJSX.User_Acceptance like '%'+@userId+'%' and (select count(*) from GJSX_detail detail where detail.GJSXID=GJSX.GJSXID)=(select count(*) from GJSX_Process process where process.GJSXID=GJSX.GJSXID))
)

UNION ALL
SELECT GJSXID AS DataId
	,'0BEA2126-7A48-40EB-8E21-99148E91A22B' AS MenuId
	,'关键事项待关闭' AS MenuName
	,GJSX.Detail AS Content
	,users.UserId
	,users.UserName
	,GJSX.CreateDate AS DataTime
	,CONVERT(varchar(100),GJSX.CreateDate, 23) AS DataTimeStr
	,'../PZHGL/GJSX/GJSXListEdit.aspx?ToDo=ToDo&EditType=Edit&ID='+GJSXID AS PCUrl
FROM GJSX
left join Project_ProjectUser as projectUser on projectUser.UserId=@userId
LEFT JOIN Sys_User AS users ON users.UserId = projectUser.UserId
left join Base_Project as project on project.ProjectId =projectUser.ProjectId
WHERE GJSX.ProjectId = projectUser.ProjectId and (project.ProjectState = '1' OR project.ProjectState IS NULL) and 
GJSX.State = 3 and GJSX.ProgressStatus=1 and (GJSX.UserID = @userId OR GJSX.User_ReceiveID = @userId )

--UNION ALL
--SELECT InspectionEquipmentId AS DataId
--	,'6c2c1e5e-1812-4e1c-a683-7125518e28c7' AS MenuId
--	,'设备材料报验待确认' AS MenuName
--	,Equipment.InspectionName AS Content
--	,UserId
--	,users.UserName
--	,Equipment.InspectionDate AS DataTime
--	,CONVERT(varchar(100),Equipment.InspectionDate, 23) AS DataTimeStr
--	,'../CQMS/Comprehensive/InspectionEquipmentEdit.aspx?ToDo=ToDo&InspectionEquipmentId='+Equipment.InspectionEquipmentId AS PCUrl
--FROM Comprehensive_InspectionEquipment AS Equipment
--LEFT JOIN Sys_User AS users ON users.UserId =@userId
--WHERE Equipment.ProjectId=@projectId and
--Equipment.Status!='3' AND Equipment.InspectionEquipmentId in (select InspectionEquipmentId from Comprehensive_InspectionEquipmentApprove approve where approve.ApproveType!='S' and approve.ApproveMan=@userId and approve.ApproveDate is null )
--UNION ALL
--SELECT InspectionPersonId AS DataId
--	,'8ed133de-5899-4687-878a-20b1f5280f18' AS MenuId
--	,'人员报验待确认' AS MenuName
--	,Person.PersonName AS Content
--	,UserId
--	,users.UserName
--	,Person.CompileDate AS DataTime
--	,CONVERT(varchar(100),Person.CompileDate, 23) AS DataTimeStr
--	,'../CQMS/Comprehensive/InspectionPersonEdit.aspx?ToDo=ToDo&InspectionPersonId='+Person.InspectionPersonId AS PCUrl
--FROM Comprehensive_InspectionPerson AS Person
--LEFT JOIN Sys_User AS users ON users.UserId =@userId
--WHERE Person.ProjectId=@projectId and
--Person.Status!='3' AND Person.InspectionPersonId in (select InspectionPersonId from Comprehensive_InspectionPersonApprove approve where approve.ApproveType!='S' and approve.ApproveMan=@userId and approve.ApproveDate is null )
--UNION ALL
--SELECT InspectionMachineId AS DataId
--	,'aa55fad1-6c51-43f5-8c99-3c6aaae79118' AS MenuId
--	,'机具报验待确认' AS MenuName
--	,Machine.InspectionMachineName AS Content
--	,UserId
--	,users.UserName
--	,Machine.CompileDate AS DataTime
--	,CONVERT(varchar(100),Machine.CompileDate, 23) AS DataTimeStr
--	,'../CQMS/Comprehensive/InspectionMachineEdit.aspx?ToDo=ToDo&InspectionMachineId='+Machine.InspectionMachineId AS PCUrl
--FROM Comprehensive_InspectionMachine AS Machine
--LEFT JOIN Sys_User AS users ON users.UserId =@userId
--WHERE Machine.ProjectId=@projectId and
--Machine.Status!='3' AND Machine.InspectionMachineId in (select InspectionMachineId from Comprehensive_InspectionMachineApprove approve where approve.ApproveType!='S' and approve.ApproveMan=@userId and approve.ApproveDate is null )
UNION ALL
SELECT ConstructSolutionId AS DataId
	,'91C4BFDB-0A51-4992-99CC-EB4EC185593D' AS MenuId
	,'施工方案待处理' AS MenuName
	,Solution.SolutionName AS Content
	,UserId
	,users.UserName
	,Solution.CompileDate AS DataTime
	,CONVERT(varchar(100),Solution.CompileDate, 23) AS DataTimeStr
	,'../CQMS/Solution/EditConstructSolution.aspx?ToDo=ToDo&ConstructSolutionId='+Solution.ConstructSolutionId AS PCUrl
FROM Solution_CQMSConstructSolution AS Solution
LEFT JOIN Sys_User AS users ON users.UserId =@userId
WHERE Solution.ProjectId=@projectId and
Solution.State!='3'
AND Solution.ConstructSolutionId in
(select top 1 ConstructSolutionId from (
SELECT Solution_CQMSConstructSolutionApprove.*
FROM Solution_CQMSConstructSolutionApprove,
(SELECT MIN([order]) AS [order],ConstructSolutionId FROM Solution_CQMSConstructSolutionApprove where ApproveType!='S' and  ApproveDate is null GROUP BY ConstructSolutionId )b
WHERE Solution_CQMSConstructSolutionApprove.[order] = b.[order] and Solution_CQMSConstructSolutionApprove.ConstructSolutionId = b.ConstructSolutionId
 ) approve
where approve.ApproveMan=@userId )

UNION ALL
SELECT InspectionId AS DataId
	,'4781f467-35bf-4cf2-aaa4-7960a175eb61' AS MenuId
	,'共检通知单待处理' AS MenuName
	,InspectionManagement.AcceptanceSite AS Content
	,UserId
	,users.UserName
	,InspectionManagement.CompileDate AS DataTime
	,CONVERT(varchar(100),InspectionManagement.CompileDate, 23) AS DataTimeStr
	,'../CQMS/ProcessControl/InspectionNoticeEdit.aspx?View=View&InspectionId='+InspectionManagement.InspectionId AS PCUrl
FROM ProcessControl_InspectionManagement AS InspectionManagement
LEFT JOIN Sys_User AS users ON users.UserId =@userId
WHERE InspectionManagement.ProjectId=@projectId and
dateadd(day,3,InspectionManagement.CompileDate)>getdate() and InspectionManagement.AcceptanceCheckMan like '%'+@userId+'%'
UNION ALL
SELECT CheckSpecialId AS DataId
	,'1B08048F-93ED-4E84-AE65-DB7917EA2DFB' AS MenuId
	,'专项检查' AS MenuName
	,CheckItemSet.CheckItemName AS Content
	,UserId
	,users.UserName
	,CheckSpecial.CheckTime AS DataTime
	,CONVERT(varchar(100),CheckSpecial.CheckTime, 23) AS DataTimeStr
	,'../HSSE/Check/CheckSpecialView.aspx?CheckSpecialId='+CheckSpecial.CheckSpecialId AS PCUrl
FROM Check_CheckSpecial AS CheckSpecial
LEFT JOIN Sys_User AS users ON users.UserId =@userId
LEFT JOIN Technique_CheckItemSet AS CheckItemSet ON CheckItemSet.CheckItemSetId =CheckSpecial.CheckItemSetId
WHERE CheckSpecial.ProjectId=@projectId and
dateadd(day,3,CheckSpecial.CheckTime)>getdate() and CheckSpecial.PartInPersonIds like '%'+@userId+'%'
UNION ALL
SELECT CheckColligationId AS DataId
	,'C198EBA8-9E23-4654-92E1-09C61105C522' AS MenuId
	,'综合检查待处理' AS MenuName
	,case CheckType when '0' then '周检' when '1' then '月检' else '其它' end AS Content
	,users.UserId
	,users.UserName
	,CheckColligation.CheckTime AS DataTime
	,CONVERT(varchar(100),CheckColligation.CheckTime, 23) AS DataTimeStr
	,'../HSSE/Check/CheckColligationEdit.aspx?CheckColligationId='+CheckColligation.CheckColligationId AS PCUrl
FROM Check_CheckColligation AS CheckColligation
LEFT JOIN Sys_User AS users ON users.UserId =@userId
LEFT JOIN Sys_FlowOperate AS FlowOperate ON CheckColligation.CheckColligationId=FlowOperate.DataId
LEFT JOIN Sys_User AS OperateUser ON FlowOperate.OperaterId=OperateUser.UserId
WHERE CheckColligation.ProjectId=@projectId and FlowOperate.IsClosed <> 1 and FlowOperate.OperaterId=@userId
UNION ALL
SELECT PatrolPlanId AS DataId
	,'D256E5C8-DC76-4F4D-BABE-A253418823F4' AS MenuId
	,'风险巡检待处理' AS MenuName
	,HazardListItem.HazardItems AS Content
	,UserId
	,users.UserName
	,PatrolPlan.LimitCheckDate AS DataTime
	,CONVERT(varchar(100),PatrolPlan.LimitCheckDate, 23) AS DataTimeStr
	,'../HSSE/Hazard/RoutingInspectionEdit.aspx?PatrolPlanId='+PatrolPlan.PatrolPlanId AS PCUrl
FROM Hazard_PatrolPlan AS PatrolPlan
LEFT JOIN Sys_User AS users ON users.UserId =@userId
LEFT JOIN Hazard_HazardSelectedItem AS HazardListItem on HazardListItem.HazardSelectedItemId=PatrolPlan.HazardSelectedItemId
WHERE HazardListItem.ProjectId=@projectId and
dateadd(day,-3,PatrolPlan.LimitCheckDate)<getdate() and PatrolPlan.DutyPerson=@userId
and (select COUNT(*) from Hazard_RoutingInspection ri where ri.PatrolPlanId=PatrolPlan.PatrolPlanId)=0
UNION ALL
SELECT PersonQuality.PersonId AS DataId
	,'EBEA762D-1F46-47C5-9EAD-759E13D9B41C' AS MenuId
	,'特种作业人员资质还有'+convert(nvarchar(6),DATEDIFF(day,getdate(),PersonQuality.LimitDate))+'天过期' AS MenuName
	,Person.PersonName AS Content
	,users.UserId
	,users.UserName
	,PersonQuality.LimitDate AS DataTime
	,CONVERT(varchar(100),PersonQuality.LimitDate, 23) AS DataTimeStr
	,'../HSSE/QualityAudit/PersonQualityEdit.aspx?PersonId='+PersonQuality.PersonId AS PCUrl
FROM QualityAudit_PersonQuality AS PersonQuality
LEFT JOIN Sys_User AS users ON users.UserId =@userId
LEFT JOIN SitePerson_Person AS Person on Person.PersonId=PersonQuality.PersonId
WHERE Person.ProjectId=@projectId and Person.IsUsed=1 and  Person.InTime<getdate() and (Person.OutTime is null or Person.OutTime  >getdate() ) and
dateadd(day,-15,PersonQuality.LimitDate)<getdate() and getdate()<PersonQuality.LimitDate
UNION ALL
SELECT PersonQuality.PersonId AS DataId
	,'EBEA762D-1F46-47C5-9EAD-759E13D9B41C' AS MenuId
	,'特种作业人员资质已过期'+convert(nvarchar(6),DATEDIFF(day,PersonQuality.LimitDate,getdate()))+'天' AS MenuName
	,Person.PersonName AS Content
	,users.UserId
	,users.UserName
	,PersonQuality.LimitDate AS DataTime
	,CONVERT(varchar(100),PersonQuality.LimitDate, 23) AS DataTimeStr
	,'../HSSE/QualityAudit/PersonQualityEdit.aspx?PersonId='+PersonQuality.PersonId AS PCUrl
FROM QualityAudit_PersonQuality AS PersonQuality
LEFT JOIN Sys_User AS users ON users.UserId =@userId
LEFT JOIN SitePerson_Person AS Person on Person.PersonId=PersonQuality.PersonId
WHERE Person.ProjectId=@projectId and Person.IsUsed=1 and  Person.InTime<getdate() and (Person.OutTime is null or Person.OutTime  >getdate() ) and
PersonQuality.LimitDate<getdate()
UNION ALL
SELECT InspectionPersonId AS DataId
	,'8ed133de-5899-4687-878a-20b1f5280f18' AS MenuId
	,'人员报验还有'+convert(nvarchar(6),DATEDIFF(day,getdate(),Person.ValidityDate))+'天过期' AS MenuName
	,Person.PersonName AS Content
	,UserId
	,users.UserName
	,Person.ValidityDate AS DataTime
	,CONVERT(varchar(100),Person.CompileDate, 23) AS DataTimeStr
	,'../CQMS/Comprehensive/InspectionPersonEdit.aspx?ToDo=ToDo&InspectionPersonId='+Person.InspectionPersonId AS PCUrl
FROM Comprehensive_InspectionPerson AS Person
LEFT JOIN Sys_User AS users ON users.UserId =@userId
WHERE Person.ProjectId=@projectId and Person.IsOnSite=1 and
dateadd(day,-15,Person.ValidityDate)<getdate() and getdate()<Person.ValidityDate
UNION ALL
SELECT InspectionPersonId AS DataId
	,'8ed133de-5899-4687-878a-20b1f5280f18' AS MenuId
	,'人员报验已过期'+convert(nvarchar(6),DATEDIFF(day,Person.ValidityDate,getdate()))+'天' AS MenuName
	,Person.PersonName AS Content
	,UserId
	,users.UserName
	,Person.ValidityDate AS DataTime
	,CONVERT(varchar(100),Person.CompileDate, 23) AS DataTimeStr
	,'../CQMS/Comprehensive/InspectionPersonEdit.aspx?ToDo=ToDo&InspectionPersonId='+Person.InspectionPersonId AS PCUrl
FROM Comprehensive_InspectionPerson AS Person
LEFT JOIN Sys_User AS users ON users.UserId =@userId
WHERE Person.ProjectId=@projectId and Person.IsOnSite=1 and
Person.ValidityDate<getdate()
UNION ALL
SELECT InspectionMachineId AS DataId
	,'aa55fad1-6c51-43f5-8c99-3c6aaae79118' AS MenuId
	,'机具报验还有'+convert(nvarchar(6),DATEDIFF(day,getdate(),Machine.NextTestDate))+'天过期' AS MenuName
	,Machine.InspectionMachineName AS Content
	,UserId
	,users.UserName
	,Machine.NextTestDate AS DataTime
	,CONVERT(varchar(100),Machine.CompileDate, 23) AS DataTimeStr
	,'../CQMS/Comprehensive/InspectionMachineEdit.aspx?ToDo=ToDo&InspectionMachineId='+Machine.InspectionMachineId AS PCUrl
FROM Comprehensive_InspectionMachine AS Machine
LEFT JOIN Sys_User AS users ON users.UserId =@userId
WHERE Machine.ProjectId=@projectId and Machine.IsOnSite=1 and
dateadd(day,-15,Machine.NextTestDate)<getdate() and getdate()<Machine.NextTestDate
UNION ALL
SELECT InspectionMachineId AS DataId
	,'aa55fad1-6c51-43f5-8c99-3c6aaae79118' AS MenuId
	,'机具报验已过期'+convert(nvarchar(6),DATEDIFF(day,Machine.NextTestDate,getdate()))+'天' AS MenuName
	,Machine.InspectionMachineName AS Content
	,UserId
	,users.UserName
	,Machine.NextTestDate AS DataTime
	,CONVERT(varchar(100),Machine.CompileDate, 23) AS DataTimeStr
	,'../CQMS/Comprehensive/InspectionMachineEdit.aspx?ToDo=ToDo&InspectionMachineId='+Machine.InspectionMachineId AS PCUrl
FROM Comprehensive_InspectionMachine AS Machine
LEFT JOIN Sys_User AS users ON users.UserId =@userId
WHERE Machine.ProjectId=@projectId and Machine.IsOnSite=1 and
Machine.NextTestDate<getdate()
UNION ALL
SELECT distinct Project.ProjectId AS DataId
	,'2AE9D982-A499-497F-8F54-ADDA5856887E' AS MenuId
	,'本月工程量完成情况尚未填报' AS MenuName
	,'' AS Content
	,users.UserId
	,users.UserName
	,GETDATE() AS DataTime
	,CONVERT(varchar(100),GETDATE(), 23) AS DataTimeStr
	,'../JDGL/Check/QuantityCompletion.aspx?ToDo=ToDo' AS PCUrl
FROM Base_Project AS Project
LEFT JOIN Sys_User AS users ON users.UserId =@userId
LEFT JOIN Project_ProjectUser as pu on pu.UserId=@userId
WHERE Project.ProjectId=@projectId
and (pu.RoleId like '%22F78A47-F59C-4FE8-9C43-2DD304CB2108%' or pu.RoleId like '%GCB64EF3-AB0A-40BC-824D-CC314598D5DC%') and ((DATENAME(DAY,GETDATE())>=22 and (select COUNT(*) from JDGL_QuantityCompletion WHERE ProjectId=@projectId and DATENAME(year,GETDATE())=DATENAME(year,EndDate) and DATENAME(MONTH,GETDATE())=DATENAME(MONTH,EndDate))=0)
--or (DATEADD(day,60,(select top 1 EndDate from JDGL_QuantityCompletion WHERE ProjectId=@projectId order by EndDate desc))<GETDATE())
)
UNION ALL
SELECT DISTINCT --MonthPlan.MonthPlanId AS DataId
	'' AS DataId
	,'94287B92-7E96-4B90-BC6F-DAF30AE3B314' AS MenuId
	,'进度管理，月度计划尚未完成' AS MenuName
	,'' AS Content
	,users.UserId
	,users.UserName
	,GETDATE() AS DataTime
	,CONVERT(varchar(100),GETDATE(), 23) AS DataTimeStr
	,'../JDGL/Check/MonthPlanEditNew.aspx?ToDo=ToDo&Months='+CONVERT(varchar(100),Months, 23) AS PCUrl
FROM JDGL_MonthPlan AS MonthPlan
LEFT JOIN Sys_User AS users ON users.UserId =@userId
LEFT JOIN Project_ProjectUser as pu on pu.UserId=@userId
WHERE MonthPlan.ProjectId=@projectId
and MonthPlan.DutyPerson like '%'+@userId+'%' and MonthPlan.RealDate is null and DATENAME(DAY,GETDATE())>=22 and 
DATENAME(year,GETDATE())=DATENAME(year,MonthPlan.PlanDate) and DATENAME(MONTH,GETDATE())=DATENAME(MONTH,MonthPlan.PlanDate)

UNION ALL
SELECT DISTINCT --WeekPlan.WeekPlanId AS DataId
	'' AS DataId
	,'56A54B4B-BBA3-4249-9FFC-3A60DAC79059' AS MenuId
	,'进度管理，周进度计划尚未完成' AS MenuName
	,'' AS Content
	,users.UserId
	,users.UserName
	,GETDATE() AS DataTime
	,CONVERT(varchar(100),GETDATE(), 23) AS DataTimeStr
	,'../JDGL/Check/WeekPlanEdit.aspx?ToDo=ToDo&WeekNo='+WeekPlan.WeekNo AS PCUrl
FROM JDGL_WeekPlan AS WeekPlan
LEFT JOIN Sys_User AS users ON users.UserId =@userId
LEFT JOIN Project_ProjectUser as pu on pu.UserId=@userId
WHERE WeekPlan.ProjectId=@projectId
and WeekPlan.DutyPerson like '%'+@userId+'%' and WeekPlan.IsOK =0 and DATENAME(DAY,GETDATE())<=DATENAME(DAY,WeekPlan.EndDate)  
and DATENAME(year,GETDATE())=DATENAME(year,WeekPlan.EndDate) and DATENAME(MONTH,GETDATE())=DATENAME(MONTH,WeekPlan.EndDate)

UNION ALL
SELECT DISTINCT --MonthPlan.MonthPlanId AS DataId
	'' AS DataId
	,'C62F4256-4AC5-44BB-A990-2D330541A968' AS MenuId
	,'档案文件已下发，请查收' AS MenuName
	,'' AS Content
	,users.UserId
	,users.UserName
	,GETDATE() AS DataTime
	,CONVERT(varchar(100),GETDATE(), 23) AS DataTimeStr
	,'../CQMS/DesignDrawing/ArchivesLibReceive.aspx' AS PCUrl
FROM IDP_DesignDrawingIssue AS DesignDrawingIssue
LEFT JOIN Sys_User AS users ON users.UserId =@userId
LEFT JOIN Project_ProjectUser as pu on pu.UserId=@userId
WHERE DesignDrawingIssue.ProjectId=@projectId and DesignDrawingIssue.ReceiveUserId=@userId
and DesignDrawingIssue.IsSee is null


UNION ALL
SELECT DISTINCT
	ww.ResultId AS DataId
	,'C62F4256-4AC5-44BB-A990-2D330541A968' AS MenuId
	,u.ShortUnitName + '管理人员预警 ' + CONVERT(varchar(20), ww.StartDate, 23) + '~' +  FORMAT(ww.EndDate, 'MM-dd') + ',计划人力' + CONVERT(varchar(10), ww.PlanQuantity) + ',实际考勤为' + CONVERT(varchar(10), ww.ActualQuantity) AS MenuName
	,'' AS Content
	,users.UserId
	,users.UserName
	,GETDATE() AS DataTime
	,CONVERT(varchar(100),GETDATE(), 23) AS DataTimeStr
	,'../JDGL/SGManPower/SGWarningDetailsEdit.aspx' AS PCUrl
FROM SGManPower_WarningWeeklyStatisticsResult AS ww
LEFT JOIN Sys_User AS users ON users.UserId =@userId
LEFT JOIN Project_ProjectUser as pu on pu.UserId=@userId
left join Base_Unit as u on ww.UnitId = u.UnitId
WHERE ww.ProjectId=@projectId and ww.UserId=@userId
and ww.IsRead = '0' and ww.WorkPostType = '1'

UNION ALL
SELECT DISTINCT
	ww.ResultId AS DataId
	,'C62F4256-4AC5-44BB-A990-2D330541A968' AS MenuId
	,u.ShortUnitName + '作业人员预警' + CONVERT(varchar(20), ww.StartDate, 23) + '~' + FORMAT(ww.EndDate, 'MM-dd') + ',计划人力' + CONVERT(varchar(10), ww.PlanQuantity) + ',实际考勤为' + CONVERT(varchar(10), ww.ActualQuantity) AS MenuName
	,'' AS Content
	,users.UserId
	,users.UserName
	,GETDATE() AS DataTime
	,CONVERT(varchar(100),GETDATE(), 23) AS DataTimeStr
	,'../JDGL/SGManPower/SGWarningDetailsEdit.aspx' AS PCUrl
FROM SGManPower_WarningWeeklyStatisticsResult AS ww
LEFT JOIN Sys_User AS users ON users.UserId =@userId
LEFT JOIN Project_ProjectUser as pu on pu.UserId=@userId
left join Base_Unit as u on ww.UnitId = u.UnitId
WHERE ww.ProjectId=@projectId and ww.UserId=@userId
and ww.IsRead = '0' and ww.WorkPostType = '2'


ORDER BY DataTime DESC
END
go



