<?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.jsh.erp.datasource.mappers.TaskStocktakingItemMapper">

    <select id="listByTaskStocktakingId" resultType="com.jsh.erp.datasource.vo.TaskStocktakingItemVO">
        SELECT
            tsi.id AS id,
            mc.`name` AS category_name,
            m.`name` AS material_name,
            m.system_sku AS system_sku,
            me.commodity_unit AS commodity_unit,
            me.production_date AS production_date,
            s.supplier AS supplier_name,
            me.bar_code AS bar_code,
            me.inventory AS inventory,
            d.`name` AS depot_name,
            tsi.new_position AS new_position,
            tsi.new_inventory AS new_inventory,
            tsi.difference_count AS difference_count,
            tsi.difference_reason AS difference_reason
        FROM
            task_stocktaking_item tsi
                LEFT JOIN jsh_material_extend me ON tsi.material_item_id = me.id
                LEFT JOIN jsh_material m ON me.material_id = m.id
                LEFT JOIN jsh_material_category mc ON mc.id = m.category_id
                LEFT JOIN jsh_supplier s ON me.supplier_id = s.id
                LEFT JOIN jsh_depot d ON me.depot_id = d.id
        WHERE
            tsi.delete_flag = 0
            AND tsi.task_stocktaking_id = #{taskStocktakingId}
        ORDER BY
            tsi.oper_time DESC,
            tsi.id DESC
    </select>

    <select id="pdaList" resultType="com.jsh.erp.datasource.pda.vo.PDATaskStocktakingItemVO">
        SELECT
            me.position AS position,
            mc.`name` AS category_name,
            m.`name` AS material_name,
            m.standard AS standard,
            u.username AS creator_name,
            tsi.oper_time AS oper_time,
            me.inventory AS inventory,
            tsi.new_inventory AS new_inventory
        FROM
            task_stocktaking_item tsi
                LEFT JOIN jsh_material_extend me ON tsi.material_item_id = me.id
                LEFT JOIN jsh_material m ON me.material_id = m.id
                LEFT JOIN jsh_material_category mc ON m.category_id = mc.id
                LEFT JOIN jsh_user u ON u.id = tsi.creator
        WHERE
            tsi.delete_flag = 0
            AND tsi.task_stocktaking_id = #{taskId}
        ORDER BY
            tsi.oper_time DESC,
            tsi.id DESC
    </select>

</mapper>