CustomerShortMapper.xml 3.61 KB
<?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.lframework.xingyun.basedata.mappers.CustomerShortMapper">

    <resultMap id="CustomerShort" type="com.lframework.xingyun.basedata.entity.CustomerShort">
        <id column="id" property="id"/>
        <result column="short_name" property="shortName"/>
        <result column="customer_id" property="customerId"/>
        <result column="customer_name" property="customerName"/>
        <result column="type" property="type"/>
        <result column="dept_id" property="deptId"/>
        <result column="dept_name" property="deptName"/>
        <result column="region" property="region"/>
        <result column="region_name" property="regionName"/>
        <result column="create_by_id" property="createById"/>
        <result column="update_by_id" property="updateById"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <sql id="CustomerShort_sql">
        SELECT
            tb.id,
            tb.short_name,
            tb.customer_id,
            c.name as customer_name,
            tb.type,
            tb.dept_id,
            d.name as dept_name,
            tb.region,
            r.name as region_name,
            tb.create_by_id,
            tb.update_by_id,
            tb.create_time,
            tb.update_time
        FROM base_data_customer_short AS tb
        LEFT JOIN base_data_customer c ON tb.customer_id = c.id
        LEFT JOIN sys_dept d ON tb.dept_id = d.id
        LEFT JOIN sys_dept r ON tb.region = r.id
    </sql>

    <select id="query" resultMap="CustomerShort">
        <include refid="CustomerShort_sql"/>
        <where>
            <if test="vo.customerId != null and vo.customerId != ''">
                AND tb.customer_id = #{vo.customerId}
            </if>
            <if test="vo.type != null and vo.type != ''">
                AND tb.type = #{vo.type}
            </if>
            <if test="vo.deptId != null and vo.deptId != ''">
                AND tb.dept_id = #{vo.deptId}
            </if>
            <if test="vo.region != null and vo.region != ''">
                AND tb.region = #{vo.region}
            </if>
            <if test="vo.customerName != null and vo.customerName != ''">
                AND c.name LIKE CONCAT('%', #{vo.customerName}, '%')
            </if>
            <if test="vo.shortName != null and vo.shortName != ''">
                AND tb.short_name LIKE CONCAT('%', #{vo.shortName}, '%')
            </if>
            <if test="vo.deptName != null and vo.deptName != ''">
                AND d.name LIKE CONCAT('%', #{vo.deptName}, '%')
            </if>
        </where>
    </select>

    <select id="queryShortName" resultMap="CustomerShort">
        SELECT id,
        short_name,
        customer_id,
        type,
        create_by_id,
        update_by_id,
        create_time,
        update_time
        FROM (
        SELECT tb.id,
        tb.short_name,
        tb.customer_id,
        tb.type,
        tb.create_by_id,
        tb.update_by_id,
        tb.create_time,
        tb.update_time,
        ROW_NUMBER() OVER (PARTITION BY tb.short_name ORDER BY tb.id) AS rn
        FROM base_data_customer_short AS tb
        <where>
            <if test="vo.shortName != null and vo.shortName != ''">
                AND tb.short_name LIKE CONCAT('%', #{vo.shortName}, '%')
            </if>
        </where>
        ) t
        WHERE rn = 1
        ORDER BY create_time desc
        LIMIT #{pageIndex}, #{pageSize}
    </select>
</mapper>