<?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.willalp.erms.mapper.HsGoodsTypeMapper">

    <resultMap type="com.willalp.erms.domain.HsGoodsType" id="HsGoodsTypeResult">
        <result property="id" column="id"/>
        <result property="goodsTypeNo" column="goods_type_no"/>
        <result property="goodsTypeName" column="goods_type_name"/>
        <result property="parentId" column="parent_id"/>
        <result property="orderNum" column="order_num"/>
        <result property="isDelete" column="is_delete"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
        <result property="parentName" column="parent_name"/>
        <result property="ancestors" column="ancestors"/>
    </resultMap>

    <sql id="selectHsGoodsTypeVo">
        select id,
               goods_type_no,
               goods_type_name,
               parent_id,
               order_num,
               is_delete,
               create_by,
               create_time,
               update_by,
               update_time,
               remark,
               parent_name,
               ancestors
        from hs_goods_type
    </sql>

    <select id="selectHsGoodsTypeList" parameterType="HsGoodsType" resultMap="HsGoodsTypeResult">
        <include refid="selectHsGoodsTypeVo"/>
        <where>
            is_delete = 0
            <if test="goodsTypeNo != null  and goodsTypeNo != ''">
                and goods_type_no = #{goodsTypeNo}
            </if>
            <if test="goodsTypeName != null  and goodsTypeName != ''">
                and goods_type_name like concat('%', #{goodsTypeName}, '%')
            </if>
            <if test="parentId != null  and parentId != ''">
                and parent_id = #{parentId}
            </if>
        </where>
    </select>
    <select id="appGetGoodsType" resultType="com.willalp.erms.domain.HsGoodsType">
        select id,
        goods_type_name
        from hs_goods_type
        <where>
            is_delete = 0
            <if test="type == null or type == ''">
                AND parent_id = 0
            </if>
            <if test="type != '' and type != null">
                AND parent_id = #{type}
            </if>
        </where>
    </select>
</mapper>
