<?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.tuoheng.admin.mapper.GoodsMapper">
    
    <resultMap type="com.tuoheng.admin.entity.domain.Goods" id="GoodsResult">
        <result property="id"    column="id"    />
        <result property="tenantId"    column="tenant_id"    />
        <result property="warehouseId"    column="warehouse_id"    />
        <result property="goodsName"    column="goods_name"    />
        <result property="goodsType"    column="goods_type"    />
        <result property="goodsStock"    column="goods_stock"    />
        <result property="goodsAction"    column="goods_action"    />
        <result property="createUser"    column="create_user"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateUser"    column="update_user"    />
        <result property="updateTime"    column="update_time"    />
        <result property="mark"    column="mark"    />
    </resultMap>

    <sql id="selectGoodsVo">
        select id, tenant_id, warehouse_id, goods_name, goods_type, goods_stock, goods_action, create_user, create_time, update_user, update_time, mark from th_goods
    </sql>

    <select id="getListByWarehouseId" parameterType="com.tuoheng.admin.entity.request.goods.QueryGoodsListByWarehouseIdRequest" resultMap="GoodsResult">
        select
        g.id,
        g.tenant_id,
        g.warehouse_id,
        g.goods_name,
        g.goods_type,
        g.goods_stock,
        g.goods_action,
        g.create_user,
        g.create_time,
        g.update_user,
        g.update_time,
        g.mark,
        u.realname AS updateUserName
        from th_goods g
        LEFT JOIN sys_user u ON g.update_user = u.id
        <where>
            <if test="1 == 1"> and g.mark = 1 </if>
            <if test="tenantId != null "> and g.tenant_id = #{tenantId}</if>
            <if test="warehouseId != null "> and g.warehouse_id = #{warehouseId}</if>
            <if test="goodsType != null "> and g.goods_type = #{goodsType}</if>
            <if test="goodsName != null and goodsName != ''">
                and g.goods_name like concat('%',#{goodsName},'%')
            </if>
        </where>
        order by g.create_time desc
    </select>
    
    <select id="getOneById" parameterType="Integer" resultMap="GoodsResult">
        <include refid="selectGoodsVo"/>
        where mark = 1 and id = #{id}
    </select>
        
</mapper>