<?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.nantian.cloud.jljc.mapper.TradeInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.nantian.cloud.jljc.entity.TradeInfo">
        <id column="id" property="id"/>
        <result column="num" property="num"/>
        <result column="trade_num" property="tradeNum"/>
        <result column="trade_name" property="tradeName"/>
        <result column="kind" property="kind"/>
        <result column="big_kind" property="bigKind"/>
        <result column="kind_code" property="kindCode"/>
        <result column="kind_name" property="kindName"/>
        <result column="product_type" property="productType"/>
        <result column="userid" property="userid"/>
        <result column="update_time" property="updateTime"/>
        <result column="del_flag" property="delFlag"/>
        <result column="dept_id" property="deptId"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, num, trade_num, trade_name, kind, big_kind, kind_code, kind_name, product_type, userid, update_time, del_flag, dept_id
    </sql>

    <select id="getPageScope" resultType="com.nantian.cloud.jljc.entity.TradeInfo">
        select
        <include refid="Base_Column_List"></include>
        from trade_info
        <trim prefix="where" prefixOverrides="and">
            <if test="query.tradeNum != null  and query.tradeNum != ''">
                and trade_num like concat("%",#{query.tradeNum},"%")
            </if>
            <if test="query.tradeName != null  and query.tradeName != ''">
                and trade_name like concat('%',#{query.tradeName},'%')
            </if>
            <if test="query.kindCode != null  and query.kindCode != ''">
                and kind_code = #{query.kindCode}
            </if>
            <if test="query.kindName != null  and query.kindName != ''">
                and kind_name = #{query.kindName}
            </if>
            <if test="query.delFlag != null  and query.delFlag != ''">
                and del_flag = #{query.delFlag}
            </if>
        </trim>
    </select>

    <select id="tradeInfoSelect" resultType="com.nantian.cloud.jljc.entity.TradeInfo">
        select DISTINCT big_kind, left(trade_num,3) trade_num from trade_info where del_flag = "1"
    </select>

    <select id="tradeInfoTree" resultType="com.nantian.cloud.jljc.vo.TreeVo">
    select DISTINCT tt.value, tt.label, tt.pvalue, tt.plabel
    from(
        select left(trade_num,3) value, big_kind label, null pvalue, null plabel from trade_info where del_flag = "1"
        union
        select trade_num value, trade_name label, left(trade_num,3) pvalue, big_kind plabel from trade_info where del_flag = "1"
    )tt
    </select>

</mapper>
