<?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.sckw.goods.mapper.InventoryMapper">

    <select id="findList" resultType="com.sckw.goods.entity.res.InventoryFindListRes">
        select id, `name` from kw_business_inventory
        <where>
            del_flag = 0
            <if test="name != null and name != ''">
                and `name` like concat('%',#{name},'%')
            </if>
        </where>
    </select>


    <resultMap type="com.sckw.goods.entity.res.InventoryPageListRes" id="listDetail">
        <id property="id" column="id" />
        <result property="name" column="name" />
        <!-- 一对多级联查询，ofType表示集合中的元素类型，将id传递给selectOrderById -->
        <collection property="InventoryPageListRes" column="id" select="selectListDetail" />
    </resultMap>


    <select id="findPage" resultMap="listDetail" resultType="com.sckw.goods.entity.res.InventoryPageListRes">
        select id, `name`, descn, create_by ,`create_time`, `update_time`
        from kw_business_inventory
        <where>
            del_flag = 0
            <if test="name != null and name != ''">
                and `name` like concat('%', #{name}, '%')
            </if>
            <if test="ids != null and !ids.isEmpty()">
                AND id IN
                <foreach item="item" collection="ids" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <select id="selectListDetail" resultType="com.sckw.goods.entity.res.InventoryDetailRes">
        select id, goods_id, goods_num, inventory_id from kw_business_inventory_detail where del_flag = 0 and inventory_id = #{id}
    </select>
</mapper>