<?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.CustomGroupDemoMapper">
    <select id="getOne"
            resultType="com.crm.rely.backend.core.pojo.view.CustomGroupDemoView">
        select cg.*
--         ,ct.`name` type_name
        from custom_group_demo cg
--         left join custom_type ct on cg.type = ct.id
        where cg.id=#{id}
    </select>

    <select id="getList"
            parameterType="com.crm.rely.backend.core.entity.custom.group.CustomGroupListEntity"
            resultType="com.crm.rely.backend.core.pojo.view.CustomGroupDemoView">
        select cg.*
        -- ,ct.`name` type_name
        from custom_group_demo cg
        -- left join custom_type ct on cg.type = ct.id
        <where>
            <if test="platform != null and platform!=''">
                and cg.platform=#{platform}
            </if>
            <if test="name != null and name!=''">
                and cg.`name` like concat('%',#{name},'%')
            </if>
            <if test="type != null">
                and cg.`type` =#{type}
            </if>
            <if test="code != null and code!=''">
                and cg.`code` like concat('%',#{code},'%')
            </if>
            <if test="startDate != null">
                and cg.add_time <![CDATA[>=]]>#{startDate}
            </if>
            <if test="endDate != null">
                and cg.add_time <![CDATA[<=]]>#{endDate}
            </if>
        </where>
        order by cg.id desc
        <if test="page != null">
            limit #{page.offset},#{page.row}
        </if>
    </select>

    <select id="countList"
            parameterType="com.crm.rely.backend.core.entity.custom.group.CustomGroupListEntity"
            resultType="Integer">
        select count(*)
        from custom_group_demo cg
        <where>
            <if test="platform != null and platform!=''">
                and cg.platform=#{platform}
            </if>
            <if test="name != null  and name!=''">
                and cg.`name` like concat('%',#{name},'%')
            </if>
            <if test="type != null">
                and cg.`type` =#{type}
            </if>
            <if test="code != null and code!=''">
                and cg.`code` like concat('%',#{code},'%')
            </if>
            <if test="startDate != null">
                and cg.add_time <![CDATA[>=]]>#{startDate}
            </if>
            <if test="endDate != null">
                and cg.add_time <![CDATA[<=]]>#{endDate}
            </if>
        </where>
    </select>
</mapper>