<?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.crm.manager.dao.mapper.SysSymbolDao">

    <select id="getList"
            parameterType="com.crm.rely.backend.core.entity.system.symbol.SysSymbolListEntity"
            resultType="com.crm.rely.backend.core.pojo.view.SysSymbolView">
        select s.id,s.`code`,s.`type`,st.`name` type_name,
        s.is_scale,ss.name is_scale_name,
        s.add_time,s.category,cate.`name` category_name
        from sys_symbol s
        left join sys_symbol_type st on s.`type` = st.id
        left join sys_symbol_type cate on s.category=cate.id
        left join sys_symbol_scale ss on s.is_scale = ss.scale
        <where>
            <if test="code != null">
                and s.`code` like concat(#{code},'%')
            </if>
            <if test="type !=null and type != 0">
                and s.`type` = #{type}
            </if>
            <if test="startDate != null">
                and s.add_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and s.add_time <![CDATA[ < ]]> #{endDate}
            </if>
        </where>
        order by s.add_time desc
        <if test="page != null">
            limit #{page.offset},#{page.row}
        </if>
    </select>

    <select id="countList"
            parameterType="com.crm.rely.backend.core.entity.system.symbol.SysSymbolListEntity"
            resultType="Integer">
        select count(*)
        from sys_symbol
        <where>
            <if test="code != null">
                and `code` like concat(#{code},'%')
            </if>
            <if test="type !=null and type != 0">
                and `type` = #{type}
            </if>
            <if test="startDate != null">
                and add_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and add_time <![CDATA[ < ]]> #{endDate}
            </if>
        </where>
    </select>

    <select id="getOne"
            parameterType="Long"
            resultType="com.crm.rely.backend.core.pojo.view.SysSymbolView">
        select s.id,s.`code`,s.`type`,st.`name` type_name,
        s.is_scale,ss.name is_scale_name,
        s.add_time,s.category,cate.`name` category_name
        from sys_symbol s
        left join sys_symbol_type st on s.`type` = st.id
        left join sys_symbol_type cate on s.category=cate.id
        left join sys_symbol_scale ss on s.is_scale = ss.scale
        where s.id=#{id}
    </select>
</mapper>