<?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.ibs.cmpm.mapper.GridCmpmRetailMapper">
    <select id="getGridCmpmRetailByCustId" resultType="GridCmpmRetail">
        select * from grid_cmpm_retail_${deptCode} where cust_id = #{custId}
    </select>

    <select id="getGridCmpmRetailByUserName" resultType="GridCmpmRetail">
        select * from grid_cmpm_retail_${deptCode} gcr
        where gcr.user_name = #{userName}
        and not exists (
            select 1 from grid_cmpm_transfer
            where (transfer_status != '3' or transfer_status != '-1') and cust_id = gcr.cust_id
        )
    </select>

    <update id="updateGridCmpmRetail">
        update grid_cmpm_retail_${deptCode}
        set user_name = #{userName},
        nick_name = #{nickName},
        outlet_id = #{outletId},
        outlet_name = #{outletName},
        branch_id = #{branchId},
        branch_name = #{branchName},
        source = '1',
        lock_flag = '1'
        where cust_id = #{custId}
    </update>

    <select id="getAllCustLevel" resultType="String">
        select distinct cust_level from grid_cmpm_retail;
    </select>




</mapper>