<?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.njzscloud.dispose.wh.mapper.InventoryMapper">
    <resultMap id="BaseResultMap" type="com.njzscloud.dispose.wh.pojo.result.SearchInventoryResult">
        <id column="id" property="id"/>
        <result column="warehouse_id" property="warehouseId"/>
        <result column="goods_id" property="goodsId"/>
        <result column="location" property="location"/>
        <result column="stock_quantity" property="stockQuantity"/>
        <result column="lock_quantity" property="lockQuantity"/>
        <result column="total_quantity" property="totalQuantity"/>
        <result column="remaining_quantity" property="remainingQuantity"/>
        <result column="unit" property="unit"/>
        <result column="creator_id" property="creatorId"/>
        <result column="modifier_id" property="modifierId"/>
        <result column="create_time" property="createTime"/>
        <result column="modify_time" property="modifyTime"/>
        <result column="deleted" property="deleted"/>
        <result column="warehouse_name" property="warehouseName"/>
        <result column="warehouse_location" property="warehouseLocation"/>
        <result column="goods_name" property="goodsName"/>
    </resultMap>

    <sql id="Base_Column_List">
        wi.id AS id,
        wi.warehouse_id AS warehouse_id,
        wi.goods_id AS goods_id,
        wi.location AS location,
        wi.stock_quantity AS stock_quantity,
        wi.lock_quantity AS lock_quantity,
        wi.total_quantity AS total_quantity,
        wi.remaining_quantity AS remaining_quantity,
        wi.unit AS unit,
        wi.creator_id AS creator_id,
        wi.modifier_id AS modifier_id,
        wi.create_time AS create_time,
        wi.modify_time AS modify_time,
        wi.deleted AS deleted,
        ww.warehouse_name,
        ww.location AS warehouse_location,
        gg.goods_name
    </sql>

    <select id="detail" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM wh_inventory wi
        LEFT JOIN wh_warehouse ww on ww.id = wi.warehouse_id
        LEFT JOIN gds_goods gg on gg.id = wi.goods_id
        WHERE wi.id = #{id}
    </select>

    <select id="paging" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM wh_inventory wi
        LEFT JOIN wh_warehouse ww on ww.id = wi.warehouse_id
        LEFT JOIN gds_goods gg on gg.id = wi.goods_id
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
        </if>
    </select>
</mapper>
