<?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="cn.cordys.crm.customer.mapper.ExtCustomerCapacityMapper">
    <select id="getCapacityByScopeIds" resultType="cn.cordys.crm.customer.domain.CustomerCapacity">
        select * from customer_capacity where
        <foreach collection="ids" item="id" separator="or">
           scope_id like concat('%', #{id}, '%')
        </foreach>
        order by create_time desc limit 1
    </select>

    <update id="updateCapacity" parameterType="cn.cordys.crm.customer.domain.CustomerCapacity">
        update customer_capacity
        <set>
            <if test="capacity.scopeId != null">
                scope_id = #{capacity.scopeId},
            </if>
            <if test="capacity.filter != null">
                filter = #{capacity.filter},
            </if>
            <if test="capacity.updateUser != null">
                update_user = #{capacity.updateUser},
            </if>
            <if test="capacity.updateTime != null">
                update_time = #{capacity.updateTime},
            </if>
            capacity = #{capacity.capacity},
        </set>
        <where>
            id = #{capacity.id}
        </where>
    </update>
</mapper>