CustomerMapper.xml 5.49 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.CustomerMapper">

    <resultMap id="CustomerDto" type="com.lframework.xingyun.basedata.entity.Customer">
        <id column="id" property="id"/>
        <result column="code" property="code"/>
        <result column="name" property="name"/>
        <result column="mnemonic_code" property="mnemonicCode"/>
        <result column="contact" property="contact"/>
        <result column="telephone" property="telephone"/>
        <result column="email" property="email"/>
        <result column="zip_code" property="zipCode"/>
        <result column="fax" property="fax"/>
        <result column="city_id" property="cityId"/>
        <result column="address" property="address"/>
        <result column="settle_type" property="settleType"/>
        <result column="credit_code" property="creditCode"/>
        <result column="tax_identify_no" property="taxIdentifyNo"/>
        <result column="bank_name" property="bankName"/>
        <result column="account_name" property="accountName"/>
        <result column="account_no" property="accountNo"/>
        <result column="available" property="available"/>
        <result column="description" property="description"/>
        <result column="create_by" property="createBy"/>
        <result column="create_time" property="createTime"/>
        <result column="update_by" property="updateBy"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <sql id="CustomerDto_sql">
        SELECT DISTINCT
            c.id,
            c.code,
            c.name,
            c.mnemonic_code,
            c.contact,
            c.telephone,
            c.email,
            c.zip_code,
            c.fax,
            c.city_id,
            c.address,
            c.settle_type,
            c.credit_code,
            c.tax_identify_no,
            c.bank_name,
            c.account_name,
            c.account_no,
            c.available,
            c.description,
            c.create_by,
            c.create_time,
            c.update_by,
            c.update_time
        FROM base_data_customer c
    </sql>

    <select id="query" resultMap="CustomerDto">
        <include refid="CustomerDto_sql"/>
        <where>
            <if test="vo != null">
                <if test="vo.code != null and vo.code != ''">
                    AND c.code like CONCAT('%', #{vo.code}, '%')
                </if>
                <if test="vo.name != null and vo.name != ''">
                    AND c.name LIKE CONCAT('%', #{vo.name}, '%')
                </if>
                <if test="vo.available != null">
                    AND c.available = #{vo.available}
                </if>
                <choose>
                    <when test="vo.source == 'CUSTOMER_CREDIT'">
                        AND NOT EXISTS (
                        SELECT 1
                        FROM customer_credit cc
                        WHERE cc.company_id = c.id
                        AND cc.status != 'CANCEL'
                        )
                    </when>
                    <when test="vo.source == 'CUSTOMER_DEVELOP'">
                        AND NOT EXISTS (
                        SELECT 1
                        FROM customer_develop_plan cdp
                        WHERE cdp.customer_id = c.id
                        AND cdp.status != 'CANCEL'
                        )
                    </when>
                    <otherwise>
                        AND 1 = 1  <!-- 确保查询到任何数据 -->
                    </otherwise>
                </choose>
            </if>
        </where>
        ORDER BY c.code
    </select>

    <select id="getByName" resultMap="CustomerDto">
        SELECT DISTINCT
        c.id,
        c.name
        FROM base_data_customer AS c
        <where>
            <if test="name != null and name != ''">
                AND name = #{name}
            </if>
        </where>
    </select>

    <select id="selector" resultMap="CustomerDto">
        <include refid="CustomerDto_sql"/>
        <where>
            <if test="vo != null">
                <if test="vo.code != null and vo.code != ''">
                    AND c.code = #{vo.code}
                </if>
                <if test="vo.name != null and vo.name != ''">
                    AND c.name LIKE CONCAT('%', #{vo.name}, '%')
                </if>
                <if test="vo.available != null">
                    AND c.available = #{vo.available}
                </if>
                <choose>
                    <when test="vo.source == 'CUSTOMER_CREDIT'">
                        AND NOT EXISTS (
                        SELECT 1
                        FROM customer_credit cc
                        WHERE cc.company_id = c.id
                        AND cc.status != 'CANCEL'
                        )
                    </when>
                    <when test="vo.source == 'CUSTOMER_DEVELOP'">
                        AND NOT EXISTS (
                        SELECT 1
                        FROM customer_develop_plan cdp
                        WHERE cdp.customer_id = c.id
                        AND cdp.status != 'CANCEL'
                        )
                    </when>
                    <otherwise>
                        AND 1 = 1  <!-- 确保查询到任何数据 -->
                    </otherwise>
                </choose>
            </if>
        </where>
        ORDER BY c.code
    </select>
</mapper>