<?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.tofly.watermeter.custom.mapper.SynchronousAboutMapper">

    <delete id="deleteDictionaryByPcid">
        delete from TF_YWPN_SYSCHILDCODE_D where PCID = #{pcid}
    </delete>

    <insert id="insertDictionary">
        insert into TF_YWPN_SYSCHILDCODE_D(ID,PCID,PCNAME,CCODE,CNAME)
        <foreach collection="dto" item="a" separator="union all">
            select
            #{a.id},#{a.pcid},#{a.pcname},#{a.code},#{a.name}
            from DUAL
        </foreach>
    </insert>

    <insert id="insertDictionaryVendor">
        insert into TF_YWPN_SYSCHILDCODE_D(ID,PCID,PCNAME,CCODE,CNAME)
        <foreach collection="dto" item="a" separator="union all">
            select
            #{a.id},
            2,
            '水表厂家',
            to_number(#{a.SBCJ_BM}),
            #{a.SBCJ_MC}
            from DUAL
        </foreach>
    </insert>

    <select id="getMaxId" resultType="long">
        select nvl(max(id), 0) + 1
        from ${tableName}
    </select>

    <insert id="insertFile">
        insert into TF_YWPN_FILE_W (ID, TABLE_NAME, FILE_PATH, FILE_NAME, OTHER_NAME, FILE_FORMAT, FILE_SIZE,
        CREATE_TIME, CREATE_USER)
        <foreach collection="fileList" item="file" separator="union all">
            select
            #{file.id},#{file.tableName},#{file.filePath},#{file.fileName},#{file.otherName},#{file.fileFormat},#{file.fileSize},
            sysdate,#{file.createUser}
            from DUAL
        </foreach>
    </insert>

    <select id="getQybm" resultType="string">
        select nvl(max(QYBM),100) + 1
        from TF_YWPN_CBQYBM_W
    </select>

    <update id="updateMeterNum">
        MERGE INTO TF_YWPN_YHBINGQY_W a
        USING (
            SELECT CBXH,
                   YHBH
            FROM TF_YWPN_QFKHJBXX_W b
        ) b ON (a.yhbh = b.YHBH)
        WHEN MATCHED THEN
            UPDATE SET a.CBXH = b.CBXH
    </update>

    <select id="doesNotExistClient" resultType="string">
        select YHBH
        from TF_YWPN_YHBINGQY_W y
        where not exists(select yhbh from TF_YWPN_QFKHJBXX_W q where q.YHBH = y.YHBH)
    </select>

    <select id="queryUserByName" resultType="map">
        select ID,REAL_NAME name
        from TF_SMPN_USER_X
        where REAL_NAME in
        <foreach collection="name" item="n" open="(" separator="," close=")">
            #{n}
        </foreach>
    </select>

    <delete id="deleteClientInfo">
        delete from TF_XRTY_NEW.TF_YWPN_QFKHJBXX_W
        where YHBH in
        <foreach collection="code.split(',')" item="c" open="(" separator="," close=")">
            #{c}
        </foreach>
    </delete>

</mapper>
