<?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.ruoyi.system.mapper.ClewMapper">

    <resultMap type="Clew" id="ClewResult">
        <result property="id"    column="id"    />
        <result property="company"    column="company"    />
        <result property="saleId"    column="sale_id"    />
        <result property="infoFlow"    column="info_flow"    />
        <result property="nextTime"    column="next_time"    />
        <result property="wxName"    column="wx_name"    />
        <result property="phone"    column="phone"    />
        <result property="debtType"    column="debt_type"    />
        <result property="debtMoney"    column="debt_money"    />
        <result property="sourceType"    column="source_type"    />
        <result property="sourceApp"    column="source_app"    />
        <result property="wxAccount"    column="wx_account"    />
        <result property="customerStatus"    column="customer_status"    />
        <result property="customerLevel"    column="customer_level"    />
        <result property="touchQrcode"    column="touch_qrcode"    />
        <result property="contactNumber"    column="contact_number"    />
        <result property="isTouch"    column="is_touch"    />
        <result property="isAddWx"    column="is_add_wx"    />
        <result property="isEffective"    column="is_effective"    />
        <result property="isPlan"    column="is_plan"    />
        <result property="isDeal"    column="is_deal"    />
        <result property="provinceName"    column="province_name"    />
        <result property="cityName"    column="city_name"    />
        <result property="customerName"    column="customer_name"    />
        <result property="contactTime"    column="contact_time"    />
        <result property="otherPhone"    column="other_phone"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="customerRemark"    column="customer_remark"    />
    </resultMap>

    <sql id="selectClewVo">
        select id, company, sale_id, info_flow, next_time,
               wx_name, phone, debt_type, debt_money, source_type,
               source_app, wx_account, customer_status, customer_level, touch_qrcode,
               contact_number, is_touch, is_add_wx, is_effective, is_plan, is_deal,
               province_name, city_name, customer_name, contact_time, other_phone,
               create_time, create_by, update_by, update_time, remark, customer_remark from clew
    </sql>

    <select id="selectClewList" parameterType="Clew" resultMap="ClewResult">
        <include refid="selectClewVo"/>
        <where>
            <if test="company != null "> and company = #{company}</if>
            <if test="saleId != null "> and sale_id = #{saleId}</if>
            <if test="infoFlow != null  and infoFlow != ''"> and info_flow = #{infoFlow}</if>
            <if test="nextTime != null "> and next_time = #{nextTime}</if>
            <if test="wxName != null  and wxName != ''"> and wx_name like concat('%', #{wxName}, '%')</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="debtType != null  and debtType != ''"> and debt_type = #{debtType}</if>
            <if test="debtMoney != null  and debtMoney != ''"> and debt_money = #{debtMoney}</if>
            <if test="sourceType != null  and sourceType != ''"> and source_type = #{sourceType}</if>
            <if test="sourceApp != null "> and source_app = #{sourceApp}</if>
            <if test="wxAccount != null  and wxAccount != ''"> and wx_account = #{wxAccount}</if>
            <if test="customerStatus != null  and customerStatus != ''"> and customer_status = #{customerStatus}</if>
            <if test="customerLevel != null  and customerLevel != ''"> and customer_level = #{customerLevel}</if>
            <if test="touchQrcode != null  and touchQrcode != ''"> and touch_qrcode = #{touchQrcode}</if>
            <if test="contactNumber != null "> and contact_number = #{contactNumber}</if>
            <if test="isTouch != null  and isTouch != ''"> and is_touch = #{isTouch}</if>
            <if test="isAddWx != null  and isAddWx != ''"> and is_add_wx = #{isAddWx}</if>
            <if test="isEffective != null  and isEffective != ''"> and is_effective = #{isEffective}</if>
            <if test="isPlan != null  and isPlan != ''"> and is_plan = #{isPlan}</if>
            <if test="isDeal != null  and isDeal != ''"> and is_deal = #{isDeal}</if>
            <if test="provinceName != null  and provinceName != ''"> and province_name like concat('%', #{provinceName}, '%')</if>
            <if test="cityName != null  and cityName != ''"> and city_name like concat('%', #{cityName}, '%')</if>
            <if test="customerName != null  and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if>
            <if test="contactTime != null "> and contact_time = #{contactTime}</if>
            <if test="otherPhone != null  and otherPhone != ''"> and other_phone = #{otherPhone}</if>
            <if test="remark != null  and remark != ''"> and remark = #{remark}</if>
            <if test="searchStatus == '01'">
                and is_add_wx = '1'
            </if>
            <if test="searchStatus == '02'">
                and is_effective = '0'
            </if>
            <if test="searchStatus == '03'">
                and is_plan = '1'
            </if>
            <if test="searchStatus == '04'">
                and is_deal = '1'
            </if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="selectClewById" parameterType="Long" resultMap="ClewResult">
        <include refid="selectClewVo"/>
        where id = #{id}
    </select>

    <insert id="insertClew" parameterType="Clew" useGeneratedKeys="true" keyProperty="id">
        insert into clew
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="company != null">company,</if>
            <if test="saleId != null">sale_id,</if>
            <if test="infoFlow != null and infoFlow != ''">info_flow,</if>
            <if test="nextTime != null">next_time,</if>
            <if test="wxName != null">wx_name,</if>
            <if test="phone != null">phone,</if>
            <if test="debtType != null">debt_type,</if>
            <if test="debtMoney != null">debt_money,</if>
            <if test="sourceType != null">source_type,</if>
            <if test="sourceApp != null">source_app,</if>
            <if test="wxAccount != null">wx_account,</if>
            <if test="customerStatus != null">customer_status,</if>
            <if test="customerLevel != null">customer_level,</if>
            <if test="touchQrcode != null">touch_qrcode,</if>
            <if test="contactNumber != null">contact_number,</if>
            <if test="isTouch != null">is_touch,</if>
            <if test="isAddWx != null">is_add_wx,</if>
            <if test="isEffective != null">is_effective,</if>
            <if test="isPlan != null">is_plan,</if>
            <if test="isDeal != null">is_deal,</if>
            <if test="provinceName != null">province_name,</if>
            <if test="cityName != null">city_name,</if>
            <if test="customerName != null">customer_name,</if>
            <if test="contactTime != null">contact_time,</if>
            <if test="otherPhone != null">other_phone,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="company != null">#{company},</if>
            <if test="saleId != null">#{saleId},</if>
            <if test="infoFlow != null and infoFlow != ''">#{infoFlow},</if>
            <if test="nextTime != null">#{nextTime},</if>
            <if test="wxName != null">#{wxName},</if>
            <if test="phone != null">#{phone},</if>
            <if test="debtType != null">#{debtType},</if>
            <if test="debtMoney != null">#{debtMoney},</if>
            <if test="sourceType != null">#{sourceType},</if>
            <if test="sourceApp != null">#{sourceApp},</if>
            <if test="wxAccount != null">#{wxAccount},</if>
            <if test="customerStatus != null">#{customerStatus},</if>
            <if test="customerLevel != null">#{customerLevel},</if>
            <if test="touchQrcode != null">#{touchQrcode},</if>
            <if test="contactNumber != null">#{contactNumber},</if>
            <if test="isTouch != null">#{isTouch},</if>
            <if test="isAddWx != null">#{isAddWx},</if>
            <if test="isEffective != null">#{isEffective},</if>
            <if test="isPlan != null">#{isPlan},</if>
            <if test="isDeal != null">#{isDeal},</if>
            <if test="provinceName != null">#{provinceName},</if>
            <if test="cityName != null">#{cityName},</if>
            <if test="customerName != null">#{customerName},</if>
            <if test="contactTime != null">#{contactTime},</if>
            <if test="otherPhone != null">#{otherPhone},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateClew" parameterType="Clew">
        update clew
        <trim prefix="SET" suffixOverrides=",">
            <if test="company != null">company = #{company},</if>
            <if test="saleId != null">sale_id = #{saleId},</if>
            <if test="infoFlow != null and infoFlow != ''">info_flow = #{infoFlow},</if>
            <if test="nextTime != null">next_time = #{nextTime},</if>
            <if test="wxName != null">wx_name = #{wxName},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="debtType != null">debt_type = #{debtType},</if>
            <if test="debtMoney != null">debt_money = #{debtMoney},</if>
            <if test="sourceType != null">source_type = #{sourceType},</if>
            <if test="sourceApp != null">source_app = #{sourceApp},</if>
            <if test="wxAccount != null">wx_account = #{wxAccount},</if>
            <if test="customerStatus != null">customer_status = #{customerStatus},</if>
            <if test="customerLevel != null">customer_level = #{customerLevel},</if>
            <if test="touchQrcode != null">touch_qrcode = #{touchQrcode},</if>
            <if test="contactNumber != null">contact_number = #{contactNumber},</if>
            <if test="isTouch != null">is_touch = #{isTouch},</if>
            <if test="isAddWx != null">is_add_wx = #{isAddWx},</if>
            <if test="isEffective != null">is_effective = #{isEffective},</if>
            <if test="isPlan != null">is_plan = #{isPlan},</if>
            <if test="isDeal != null">is_deal = #{isDeal},</if>
            <if test="provinceName != null">province_name = #{provinceName},</if>
            <if test="cityName != null">city_name = #{cityName},</if>
            <if test="customerName != null">customer_name = #{customerName},</if>
            <if test="contactTime != null">contact_time = #{contactTime},</if>
            <if test="otherPhone != null">other_phone = #{otherPhone},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="customerRemark != null">customer_remark = #{customerRemark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteClewById" parameterType="Long">
        delete from clew where id = #{id}
    </delete>

    <delete id="deleteClewByIds" parameterType="String">
        delete from clew where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>