<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.sgzb.material.mapper.PurchaseAccessoryMapper">

    <resultMap type="com.bonus.sgzb.material.domain.PurchasePartDetails" id="PurchasePartDetailsResult">
        <result property="id"    column="id"    />
        <result property="taskId"    column="task_id"    />
        <result property="partId"    column="part_id"    />
        <result property="purchasePrice"    column="purchase_price"    />
        <result property="purchaseNum"    column="purchase_num"    />
        <result property="checkNum"    column="check_num"    />
        <result property="checkResult"    column="check_result"    />
        <result property="supplierId"    column="supplier_id"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="productionTime"    column="production_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="checkUrlName"    column="check_url_name"    />
        <result property="checkUrl"    column="check_url"    />
        <result property="fileName"    column="file_name"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="companyId"    column="company_id"    />
    </resultMap>

    <resultMap type="com.bonus.sgzb.material.domain.PurchasePartInfo" id="PurchasePartInfoResult">
        <result property="taskId"    column="task_id"    />
        <result property="purchaseTime"    column="purchase_time"    />
        <result property="arrivalTime"    column="arrival_time"    />
        <result property="purchaser"    column="purchaser"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="companyId"    column="company_id"    />
    </resultMap>



    <insert id="insertPurchasePartDetailsList">
        <foreach item="partDetails" collection="purchasePartDetailsList" open="" separator=";" close="">
            insert into purchase_part_details
            <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="partDetails.taskId != null">task_id,</if>
                <if test="partDetails.partId != null">part_id,</if>
                <if test="partDetails.purchasePrice != null">purchase_price,</if>
                <if test="partDetails.purchaseNum != null">purchase_num,</if>
                <if test="partDetails.checkNum != null">check_num,</if>
                <if test="partDetails.checkResult != null">check_result,</if>
                <if test="partDetails.supplierId != null">supplier_id,</if>
                <if test="partDetails.createBy != null">create_by,</if>
                <if test="partDetails.productionTime != null">production_time,</if>
                <if test="partDetails.createTime != null">create_time,</if>
                <if test="partDetails.updateBy != null">update_by,</if>
                <if test="partDetails.updateTime != null">update_time,</if>
                <if test="partDetails.remark != null">remark,</if>
                <if test="partDetails.fileName != null">file_name,</if>
                <if test="partDetails.fileUrl != null">file_url,</if>
                <if test="partDetails.companyId != null">company_id,</if>
            </trim>
            <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="partDetails.taskId != null">#{partDetails.taskId},</if>
                <if test="partDetails.partId != null">#{partDetails.partId},</if>
                <if test="partDetails.purchasePrice != null">#{partDetails.purchasePrice},</if>
                <if test="partDetails.purchaseNum != null">#{partDetails.purchaseNum},</if>
                <if test="partDetails.checkNum != null">#{partDetails.checkNum},</if>
                <if test="partDetails.checkResult != null">#{partDetails.checkResult},</if>
                <if test="partDetails.supplierId != null">#{partDetails.supplierId},</if>
                <if test="partDetails.createBy != null">#{partDetails.createBy},</if>
                <if test="partDetails.productionTime != null">#{partDetails.productionTime},</if>
                <if test="partDetails.createTime != null">#{partDetails.createTime},</if>
                <if test="partDetails.updateBy != null">#{partDetails.updateBy},</if>
                <if test="partDetails.updateTime != null">#{partDetails.updateTime},</if>
                <if test="partDetails.remark != null">#{partDetails.remark},</if>
                <if test="partDetails.fileName != null">#{partDetails.fileName},</if>
                <if test="partDetails.fileUrl != null">#{partDetails.fileUrl},</if>
                <if test="partDetails.companyId != null">#{partDetails.companyId},</if>
            </trim>
        </foreach>
    </insert>

    <insert id="insertPurchasePartInfo"  parameterType="com.bonus.sgzb.material.domain.PurchasePartInfo" useGeneratedKeys="true" keyProperty="taskId">
        insert into purchase_part_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskId != null">task_id,</if>
            <if test="purchaseTime != null">purchase_time,</if>
            <if test="arrivalTime != null">arrival_time,</if>
            <if test="purchaser != null">purchaser,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="companyId != null">company_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskId != null">#{taskId},</if>
            <if test="purchaseTime != null and purchaseTime != ''">#{purchaseTime},</if>
            <if test="arrivalTime != null">#{arrivalTime},</if>
            <if test="purchaser != null">#{purchaser},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="companyId != null">#{companyId},</if>
        </trim>
    </insert>

    <update id="updatePurchasePartInfo" parameterType="com.bonus.sgzb.material.domain.PurchasePartInfo">
        update purchase_part_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="purchaseTime != null">purchase_time = #{purchaseTime},</if>
            <if test="arrivalTime != null">arrival_time = #{arrivalTime},</if>
            <if test="purchaser != null">purchaser = #{purchaser},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
        </trim>
        where task_id = #{taskId}
    </update>
    <update id="updatePurchasePartDetails" parameterType="com.bonus.sgzb.material.domain.PurchasePartDetails">
        update purchase_part_details
        <trim prefix="SET" suffixOverrides=",">
            <if test="partId != null">part_id = #{partId},</if>
            <if test="purchasePrice != null">purchase_price = #{purchasePrice},</if>
            <if test="purchaseNum != null">purchase_num = #{purchaseNum},</if>
            <if test="checkNum != null">check_num = #{checkNum},</if>
            <if test="checkResult != null">check_result = #{checkResult},</if>
            <if test="supplierId != null">supplier_id = #{supplierId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
        </trim>
        where id = #{id}
    </update>
    <update id="updatePartTypeNum">
        UPDATE ma_part_type
        SET num = num + #{inputNum}
        WHERE
            pa_id = #{partId}
    </update>

    <select id="setlectStatusById" resultType="java.lang.Integer">
        SELECT
            COUNT(*)
        FROM
            purchase_part_details
        WHERE
            id=#{id}
          and (`status`='3' or `status`='4')
    </select>

    <delete id="deletePartDetailsByTaskId">
        delete from purchase_part_details where task_id = #{taskId}
    </delete>

    <delete id="deletePurchasePartInfoByTaskIds" parameterType="String">
        delete from purchase_part_info where task_id in
        <foreach item="taskId" collection="array" open="(" separator="," close=")">
            #{taskId}
        </foreach>;

        delete from tm_task where task_id in
        <foreach item="taskId" collection="array" open="(" separator="," close=")">
            #{taskId}
        </foreach>;

        delete from purchase_part_details where task_id in
        <foreach item="taskId" collection="array" open="(" separator="," close=")">
            #{taskId}
        </foreach>
    </delete>

    <select id="selectPurchasePartInfoList" resultType="com.bonus.sgzb.material.domain.PurchasePartInfo">
        SELECT
            ppi.task_id,
            ppi.purchase_time,
            ppi.arrival_time,
            ppi.purchaser,
            ppi.create_by,
            ppi.create_time,
            ppi.update_by,
            ppi.update_time,
            ppi.remark,
            ppi.company_id,
            dict.NAME purchasingStatus,
            tk.CODE,
            su.user_name purchaserName,
            tk.task_status taskStatus
        FROM
            purchase_part_info ppi
                LEFT JOIN tm_task tk ON ppi.task_id = tk.task_id
                LEFT JOIN ( SELECT id, NAME FROM sys_dic WHERE p_id = 67 ) dict ON tk.task_status = dict.id
                LEFT JOIN sys_user su ON ppi.purchaser = su.user_id
            WHERE
                task_type = 67
        <if test="keyWord != null  and keyWord != ''"> and tk.code like concat('%',#{keyWord},'%')</if>
        <if test="purchaseTime != null  and purchaseTime != ''"> and ppi.purchase_time = #{purchaseTime}</if>
        <if test="arrivalTime != null  and arrivalTime != ''"> and ppi.arrival_time = #{arrivalTime}</if>
        <if test="purchaser != null "> and ppi.purchaser = #{purchaser}</if>
        <if test="companyId != null "> and ppi.company_id = #{companyId}</if>
        ORDER BY
            ppi.create_time DESC
    </select>
    <select id="selectTypeNameByTaskId" resultType="java.lang.String">
        select GROUP_CONCAT(pa_name) typeName from
            (select distinct ppd.task_id, mpt1.pa_name
             from purchase_part_details ppd
                      left join ma_part_type mpt on ppd.part_id = mpt.pa_id
                      left join ma_part_type mpt1 on mpt.parent_id = mpt1.pa_id
             where ppd.task_id = #{taskId}
        <if test="type == 2">and ppd.`status`!=2</if>
            ) t
        GROUP BY task_id
    </select>
    <select id="selectPurchasePartInfoByTaskId" resultType="com.bonus.sgzb.material.domain.PurchasePartInfo">
        select pci.task_id, pci.purchase_time, pci.arrival_time, pci.purchaser, pci.create_by, pci.create_time,
               pci.update_by, pci.update_time, pci.remark, pci.company_id, tk.code
        from purchase_part_info pci
                 left join tm_task tk on pci.task_id = tk.task_id
        where pci.task_id = #{taskId}
    </select>
    <select id="selectPurchasePartDetailsList"
            parameterType="com.bonus.sgzb.material.domain.PurchasePartDetails" resultMap="PurchasePartDetailsResult">
        select pcd.id,pcd.task_id, pcd.part_id, pcd.purchase_price, pcd.purchase_num, pcd.check_num,
        pcd.check_result,pcd.`status`,
        CASE
        WHEN pcd.`status` = 0 THEN '待验收'
        WHEN pcd.`status` = 1 THEN '已验收'
        WHEN pcd.`status` = 2 THEN '验收不通过'
        WHEN pcd.`status` = 3 THEN '已入库'
        WHEN pcd.`status` = 4 THEN '入库不通过'
        ELSE ''
        END AS statusResult,
        pcd.supplier_id, msi.supplier, pcd.create_by, pcd.production_time, pcd.create_time,
        pcd.file_name, pcd.file_url,pcd.update_by, pcd.update_time, pcd.remark, pcd.company_id,
        mt1.pa_name machineTypeName,mt.pa_name specificationType, tk.code ,mt.pa_name typeName,
        mt.unit_id unitName
        from purchase_part_details pcd
        left join ma_part_type mt on pcd.part_id = mt.pa_id
        left join ma_part_type mt1 on mt.parent_id = mt1.pa_id
        left join ma_supplier_info msi on pcd.supplier_id = msi.supplier_id
        left join tm_task tk on pcd.task_id = tk.task_id
        <where>
            <if test="taskId != null ">and pcd.task_id = #{taskId}</if>
            <if test="keyWord != null and keyWord != ''">and (mt.pa_name like concat('%',#{keyWord},'%')
                or mt1.pa_name like concat('%',#{keyWord}) or msi.supplier like concat('%',#{keyWord}))
            </if>
            <if test="partId != null ">and pcd.part_id = #{partId}</if>
            <if test="purchasePrice != null  and purchasePrice != ''">and pcd.purchase_price = #{purchasePrice}</if>
            <if test="purchaseNum != null ">and pcd.purchase_num = #{purchaseNum}</if>
            <if test="supplierId != null ">and pcd.supplier_id = #{supplierId}</if>
            <if test="productionTime != null ">and pcd.production_time = #{productionTime}</if>
            <if test="companyId != null ">and pcd.company_id = #{companyId}</if>
        </where>
    </select>

    <select id="selectPutInListList" resultMap="PurchasePartInfoResult">
        SELECT
            pci.task_id, pci.purchase_time, pci.arrival_time, pci.purchaser, us.user_name as create_by, pci.create_time,
            pci.update_by,
            pci.update_time, pci.remark, pci.company_id ,tk.code,tk.task_status taskStatus,GROUP_CONCAT(distinct mpt1.pa_name) purchasingTypeName,
            CASE
                tk.task_status
                WHEN 69 THEN '待审核'
                WHEN 70 THEN '已审核'
                ELSE ''
                END taskStatusResult,
            su.user_name purchaserName
        FROM
            purchase_part_details ppd
                LEFT JOIN purchase_part_info pci on pci.task_id=ppd.task_id
                left join tm_task tk on pci.task_id = tk.task_id
                left join sys_user su on pci.purchaser = su.user_id
                left join ma_part_type mpt on ppd.part_id = mpt.pa_id
                left join ma_part_type mpt1 on mpt.parent_id = mpt1.pa_id
                LEFT JOIN sys_user us on us.user_id = pci.create_by
        where task_type = 67 and tk.task_status in (69,70)
        <if test="keyWord != null  and keyWord != ''"> and tk.code like concat('%',#{keyWord},'%')</if>
        <if test="submitStorageTime != null  and submitStorageTime != ''"> and pci.create_time like concat('%',#{submitStorageTime},'%')</if>
        <if test="partId != null  and partId != ''"> and mpt1.pa_id in (#{partId})</if>
        GROUP BY task_id
        order by create_time desc
    </select>
    <select id="selectPurchasePartDetailsStatus" resultType="java.lang.Integer">
        select count(*) from purchase_part_details where task_id = #{taskId} and status ='1'
    </select>
    <select id="getPartList" resultType="com.bonus.sgzb.material.domain.PurchasePartInfo">
        SELECT
            pa_id AS partId,
            pa_name AS partName
        FROM
            `ma_part_type`
        WHERE
            `level` = #{level}
    </select>

    <select id="selectPutinDetails" resultType="com.bonus.sgzb.material.domain.PurchasePartDetails">
        SELECT pcd.id,
        mt.pa_id as partId,
        mt1.pa_id as modelId,
        mt.pa_name specificationType,
        mt1.pa_name typeName,
        pcd.check_num as checkNum,
        ppi.remark,
        pcd.`status`,
        CASE
        WHEN pcd.`status` = 0 THEN '待验收'
        WHEN pcd.`status` = 1 THEN '待入库'
        WHEN pcd.`status` = 2 THEN '验收不通过'
        WHEN pcd.`status` = 3 THEN '已入库'
        WHEN pcd.`status` = 4 THEN '入库不通过'
        ELSE ''
        END AS statusResult,

        pcd.task_id taskId,

        CASE tt.task_status
        WHEN 70 THEN
        tt.update_time
        ELSE
        ''
        END as inputTime,
        CASE tt.task_status
        WHEN 70 THEN
        us.user_name
        ELSE
        ''
        END as inputBy
        FROM purchase_part_details pcd
        LEFT JOIN purchase_part_info ppi on ppi.task_id=pcd.task_id
        LEFT JOIN ma_part_type mt ON pcd.part_id = mt.pa_id
        LEFT JOIN ma_part_type mt1 ON mt.parent_id = mt1.pa_id
        LEFT JOIN tm_task tt on tt.task_id = pcd.task_id
        LEFT JOIN sys_user us on us.user_id = tt.update_by
        WHERE pcd.task_id = #{taskId}
        and pcd.`status`!=2
        <if test="keyWord != null  and keyWord != ''">
            and (mt.pa_name like concat('%',#{keyWord},'%') or
            mt1.pa_name like concat('%',#{keyWord},'%'))
        </if>
        <if test="deviceTypeId != null  and deviceTypeId != ''">
            and mt1.pa_id = #{deviceTypeId}
        </if>
        <if test="typeId != null  and typeId != ''">
            and mt.pa_id = #{typeId}
        </if>
        <if test="status != null  and status != ''">
            AND pcd.`status` = #{status}
        </if>
    </select>

    <select id="exportList" resultType="com.bonus.sgzb.material.domain.PurchasePartInfo">
        SELECT
            tk.`code`,
            ppi.purchase_time as purchaseTime,
            ppi.arrival_time as arrivalTime,
            mpt2.pa_name as purchasingTypeName,
            mpt.pa_name as purchasingTypeCode,
            su.user_name purchaserName,
            ppd.purchase_price as purchasePrice,
            ppd.purchase_num as purchaseNum,
            msi.supplier,
            CASE
                WHEN ppd.`status` = 0 THEN '待验收'
                WHEN ppd.`status` = 1 THEN '已验收'
                WHEN ppd.`status` = 2 THEN '验收不通过'
                WHEN ppd.`status` = 3 THEN '已入库'
                WHEN ppd.`status` = 4 THEN '入库不通过'
                ELSE ''
                END AS purchasingStatus
        FROM
            purchase_part_details ppd
                LEFT JOIN purchase_part_info ppi on ppd.task_id=ppi.task_id
                LEFT JOIN tm_task tk ON ppi.task_id = tk.task_id
                LEFT JOIN ( SELECT id, NAME FROM sys_dic WHERE p_id = 67 ) dict ON tk.task_status = dict.id
                LEFT JOIN sys_user su ON ppi.purchaser = su.user_id
                LEFT JOIN ma_part_type mpt on mpt.pa_id=ppd.part_id
                LEFT JOIN ma_part_type mpt2 on mpt2.pa_id=mpt.parent_id
                LEFT JOIN ma_supplier_info msi on msi.supplier_id=ppd.supplier_id
        WHERE
            task_type = 67
        <if test="keyWord != null  and keyWord != ''"> and tk.code like concat('%',#{keyWord},'%')</if>
        <if test="purchaseTime != null  and purchaseTime != ''"> and ppi.purchase_time = #{purchaseTime}</if>
        <if test="arrivalTime != null  and arrivalTime != ''"> and ppi.arrival_time = #{arrivalTime}</if>
        <if test="purchaser != null "> and ppi.purchaser = #{purchaser}</if>
        <if test="companyId != null "> and ppi.company_id = #{companyId}</if>
        ORDER BY
        ppi.create_time DESC
    </select>

    <select id="inputExport" resultType="com.bonus.sgzb.material.domain.PurchasePartDetails">

        SELECT
            tk.task_id as taskId,
            tk.`code`,
            pci.purchase_time as purchaseTime, pci.arrival_time as arrivalTime,mpt2.pa_name as machineTypeName,
            mpt.pa_name as specificationType,su.user_name purchaserName, us.user_name as createBy, pci.create_time as createTime,ppd.check_num as checkNum,
            CASE
                WHEN ppd.`status` = 0 THEN '待验收'
                WHEN ppd.`status` = 1 THEN '待入库'
                WHEN ppd.`status` = 2 THEN '验收不通过'
                WHEN ppd.`status` = 3 THEN '已入库'
                WHEN ppd.`status` = 4 THEN '入库不通过'
                ELSE ''
                END       AS statusResult
        FROM
            purchase_part_details ppd
                LEFT JOIN purchase_part_info pci on pci.task_id=ppd.task_id
                left join tm_task tk on pci.task_id = tk.task_id
                left join sys_user su on pci.purchaser = su.user_id
                left join ma_part_type mpt on ppd.part_id = mpt.pa_id
                left join ma_part_type mpt2 on mpt.parent_id = mpt2.pa_id
                LEFT JOIN sys_user us on us.user_id = pci.create_by
        where task_type = 67 and tk.task_status in (69,70)
        <if test="keyWord != null  and keyWord != ''"> and tk.code like concat('%',#{keyWord},'%')</if>
        <if test="submitStorageTime != null  and submitStorageTime != ''"> and pci.create_time like concat('%',#{submitStorageTime},'%')</if>
        <if test="partId != null  and partId != ''"> and mpt2.pa_id in (#{partId})</if>
        ORDER BY tk.task_id DESC
    </select>
    <select id="isOperateAll" resultType="java.lang.Integer">
        SELECT
            count(*)
        FROM
            purchase_part_details
        WHERE
            task_id =  #{taskId} and status != 1 and status!=2
    </select>
    <select id="selectPurchasePartDetailsStatusIsNoPass" resultType="java.lang.Integer">
        select count(*) from purchase_part_details where task_id = #{taskId} and status != 2
    </select>
    <select id="getAcceptanceForm" parameterType="com.bonus.sgzb.material.domain.PurchasePartDetails" resultMap="PurchasePartDetailsResult">
        select pcd.id,pcd.task_id, pcd.part_id, pcd.purchase_price, pcd.purchase_num, pcd.check_num,
        pcd.check_result,pcd.`status`,
        CASE
        WHEN pcd.`status` = 0 THEN '待验收'
        WHEN pcd.`status` = 1 THEN '已验收'
        WHEN pcd.`status` = 2 THEN '验收不通过'
        WHEN pcd.`status` = 3 THEN '已入库'
        WHEN pcd.`status` = 4 THEN '入库不通过'
        ELSE ''
        END AS statusResult,
        pcd.supplier_id, msi.supplier, pcd.create_by, pcd.production_time, pcd.create_time,
        pcd.file_name, pcd.file_url,pcd.update_by, pcd.update_time, pcd.remark, pcd.company_id,
        mt1.pa_name machineTypeName,mt.pa_name specificationType, tk.code ,mt.pa_name typeName,
        mt.unit_id unitName
        from purchase_part_details pcd
        left join ma_part_type mt on pcd.part_id = mt.pa_id
        left join ma_part_type mt1 on mt.parent_id = mt1.pa_id
        left join ma_supplier_info msi on pcd.supplier_id = msi.supplier_id
        left join tm_task tk on pcd.task_id = tk.task_id
       where
           1=1
           and (pcd.`status`=3 or pcd.`status`=1)
            <if test="taskId != null ">and pcd.task_id = #{taskId}</if>
            <if test="keyWord != null and keyWord != ''">and (mt.pa_name like concat('%',#{keyWord},'%')
                or mt1.pa_name like concat('%',#{keyWord}) or msi.supplier like concat('%',#{keyWord}))
            </if>
            <if test="partId != null ">and pcd.part_id = #{partId}</if>
            <if test="purchasePrice != null  and purchasePrice != ''">and pcd.purchase_price = #{purchasePrice}</if>
            <if test="purchaseNum != null ">and pcd.purchase_num = #{purchaseNum}</if>
            <if test="supplierId != null ">and pcd.supplier_id = #{supplierId}</if>
            <if test="productionTime != null ">and pcd.production_time = #{productionTime}</if>
            <if test="companyId != null ">and pcd.company_id = #{companyId}</if>
    </select>

    <select id="warehousingEntry" resultType="com.bonus.sgzb.material.domain.PurchasePartDetails">
        SELECT pcd.id,
        mt.pa_id as partId,
        mt1.pa_id as modelId,
        mt.pa_name specificationType,
        mt1.pa_name typeName,
        pcd.check_num as checkNum,
        pcd.`status`,
        ppi.remark,
        mt.unit_id as unitName,
        CASE
        WHEN pcd.`status` = 0 THEN '待验收'
        WHEN pcd.`status` = 1 THEN '待入库'
        WHEN pcd.`status` = 2 THEN '验收不通过'
        WHEN pcd.`status` = 3 THEN '已入库'
        WHEN pcd.`status` = 4 THEN '入库不通过'
        ELSE ''
        END AS statusResult,

        pcd.task_id taskId,

        CASE tt.task_status
        WHEN 70 THEN
        tt.update_time
        ELSE
        ''
        END as inputTime,
        CASE tt.task_status
        WHEN 70 THEN
        us.user_name
        ELSE
        ''
        END as inputBy
        FROM purchase_part_details pcd
        LEFT JOIN purchase_part_info ppi on ppi.task_id=pcd.task_id
        LEFT JOIN ma_part_type mt ON pcd.part_id = mt.pa_id
        LEFT JOIN ma_part_type mt1 ON mt.parent_id = mt1.pa_id
        LEFT JOIN tm_task tt on tt.task_id = pcd.task_id
        LEFT JOIN sys_user us on us.user_id = tt.update_by
        WHERE pcd.task_id = #{taskId}
        and pcd.`status`=3
    </select>
</mapper>