<?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.material.part.mapper.PartAcceptMapper">

    <select id="getTypeTree" resultType="com.bonus.material.part.domain.PartTypeDto">
        SELECT
        pa_id as partId,
        pa_name as partName,
        parent_id as parentId,
        storage_num as storageNum,
        level as level
        FROM
        ma_part_type
        WHERE del_flag = '0'
       <if test="level != null and level != ''">
        and level = 3
        </if>
    </select>

    <select id="getStorageNum" resultType="int">
        SELECT
        purchase_num
        FROM
            purchase_part_details
        WHERE id = #{id} and del_flag = '0'

    </select>

    <update id="partTypeWarehouse">
        update purchase_part_details
        set
            input_num = #{purchaseNum},
            input_time = now(),
            status = 19
        where id = #{id} and del_flag = 0
    </update>

    <update id="updatePartTypeStorage">
        update ma_part_type
        set storage_num = storage_num + #{purchaseNum}
        where pa_id = #{partId} and del_flag = '0'
    </update>

    <update id="partTypeReject">
        update purchase_part_details
        set status = 2
        where id = #{id} and del_flag = 0
    </update>

    <select id="selectStatus" resultType="int">
        select
            count(id)
        from purchase_part_details
        where task_id = #{taskId} and status = 0 and del_flag = 0

    </select>

    <update id="updateStatus">
        update tm_task
        set task_status = 1
        where task_id = #{taskId}
    </update>

    <update id="passAll">
        update purchase_part_details
        set status = 1
        where task_id = #{taskId} and status = 0 and del_flag = 0
    </update>

    <update id="rejectAll">
        update purchase_part_details
        set status = 2
        where task_id = #{taskId} and status = 0 and del_flag = 0
    </update>
</mapper>