<?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.jeeplus.psimanage.foodPurchase.mapper.PsiFoodPurchaseChangeMapper">

    <update id="updateStatusById">
        UPDATE psi_management_food_purchase_change
        SET status = #{status}
        WHERE id = #{id}
    </update>

    <select id="findActiveBySourceBasicId" resultType="com.jeeplus.psimanage.foodPurchase.domain.PsiFoodPurchaseChange">
        SELECT
            id,
            source_basic_id,
            remarks,
            purchase_no,
            handled_by,
            handled_by_office,
            purchase_time,
            total_price,
            proc_ins_id,
            status,
            process_definition_id,
            create_time,
            create_by_id,
            update_time,
            update_by_id,
            del_flag,
            tenant_id
        FROM psi_management_food_purchase_change
        WHERE source_basic_id = #{sourceBasicId}
          AND del_flag = 0
          AND status IN ('1', '2', '3', '4')
        ORDER BY update_time DESC, create_time DESC
        LIMIT 1
    </select>

    <select id="getIdsBySourceBasicId" resultType="java.lang.String">
        SELECT id
        FROM psi_management_food_purchase_change
        WHERE source_basic_id = #{sourceBasicId}
          AND del_flag = 0
    </select>
</mapper>
