<?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.ucard.dao.mapper.CardIdTypeConfigMapper">

    <insert id="batchSave" parameterType="com.crm.rely.backend.core.entity.ucard.CardIdTypeConfigAddEntity">
        INSERT INTO `ucard_id_type_config` (`code`, `id_type`, `cn_name`, `en_name`,`add_time`)
        VALUES
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.code},#{item.idType},#{item.cnName},#{item.enName},NOW())
        </foreach>
        ON DUPLICATE KEY UPDATE
        `id_type` = VALUES(`id_type`),
        `cn_name` = VALUES(`cn_name`),
        `en_name` = VALUES(`en_name`),
        `modify_time` = VALUES(`add_time`)
    </insert>

    <select id="countList" resultType="integer"
            parameterType="com.crm.rely.backend.core.entity.ucard.CardIdTypeConfigPageEntity">
        SELECT COUNT(*) FROM ucard_id_type_config
        <where>
            <if test="code != null and code != ''">
                and `code` = #{code}
            </if>
            <if test="idType != null and idType != ''">
                and `id_type` like concat('%', #{idType},'%')
            </if>
        </where>
    </select>

    <select id="pageList" resultType="com.crm.rely.backend.core.dto.ucard.CardIdTypeConfigDto"
            parameterType="com.crm.rely.backend.core.entity.ucard.CardIdTypeConfigPageEntity">
        SELECT * FROM ucard_id_type_config
        <where>
            <if test="code != null and code != ''">
                and `code` = #{code}
            </if>
            <if test="idType != null and idType != ''">
                and `id_type` like concat('%', #{idType},'%')
            </if>
        </where>
        order by id desc
        <if test="page != null">
            limit #{page.offset},#{page.row}
        </if>
    </select>

</mapper> 