﻿CREATE OR ALTER PROCEDURE [dbo].[装配中心任务看板_可执行任务数]
AS
BEGIN
    SET NOCOUNT ON;

    SELECT
        SUM(CASE WHEN 物料描述 NOT LIKE '%系统%' AND 齐套时间 IS NOT NULL THEN 1 ELSE 0 END) AS 阀类可执行任务数,
        SUM(CASE WHEN 物料描述 LIKE '%系统%' AND 派工时间 IS NOT NULL THEN 1 ELSE 0 END) AS 系统类可执行任务数,
        SUM(CASE
            WHEN 物料描述 NOT LIKE '%系统%' AND 齐套时间 IS NOT NULL THEN 1
            WHEN 物料描述 LIKE '%系统%' AND 派工时间 IS NOT NULL THEN 1
            ELSE 0
        END) AS 可执行任务数
    FROM [dbo].[View_生产订单_MES]
    WHERE [物料类型] = 'pit_Resource'
        AND [自制件属性] LIKE '%装配%'
        AND ISNULL(任务状态, 0) < 4
        AND [物料描述] NOT LIKE '%软管总成%'
        AND [物料描述] NOT LIKE '%发货部件%'
        AND [不装配] <> '否';
END;