<?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.brilliance.isc.mda.dao.UsrMapper">

    <resultMap id="BaseResultMap" type="com.brilliance.isc.bo.Usr">
        <result property="inr" column="inr" jdbcType="VARCHAR"/>
        <result property="extkey" column="extkey" jdbcType="VARCHAR"/>
        <result property="nam" column="nam" jdbcType="VARCHAR"/>
        <result property="lgiflg" column="lgiflg" jdbcType="VARCHAR"/>
        <result property="ssnbegdattim" column="ssnbegdattim" jdbcType="DATE"/>
        <result property="ssninr" column="ssninr" jdbcType="VARCHAR"/>
        <result property="ver" column="ver" jdbcType="VARCHAR"/>
        <result property="pri" column="pri" jdbcType="VARCHAR"/>
        <result property="ety" column="ety" jdbcType="VARCHAR"/>
        <result property="usg" column="usg" jdbcType="VARCHAR"/>
        <result property="lstdiadat" column="lstdiadat" jdbcType="DATE"/>
        <result property="relcur" column="relcur" jdbcType="VARCHAR"/>
        <result property="relamt" column="relamt" jdbcType="DECIMAL"/>
        <result property="relamt2nd" column="relamt2nd" jdbcType="DECIMAL"/>
        <result property="relgrp" column="relgrp" jdbcType="VARCHAR"/>
        <result property="tel" column="tel" jdbcType="VARCHAR"/>
        <result property="fax" column="fax" jdbcType="VARCHAR"/>
        <result property="eml" column="eml" jdbcType="VARCHAR"/>
        <result property="letoenr" column="letoenr" jdbcType="VARCHAR"/>
        <result property="quepow" column="quepow" jdbcType="DECIMAL"/>
        <result property="etyextkey" column="etyextkey" jdbcType="VARCHAR"/>
        <result property="oenr" column="oenr" jdbcType="VARCHAR"/>
        <result property="etaextkey" column="etaextkey" jdbcType="VARCHAR"/>
        <result property="resusrflg" column="resusrflg" jdbcType="VARCHAR"/>
        <result property="secsta" column="secsta" jdbcType="VARCHAR"/>
        <result property="userdetailsid" column="userdetailsid" jdbcType="INTEGER"/>
        <result property="authlevel" column="authlevel" jdbcType="VARCHAR"/>
        <result property="authority" column="authority" jdbcType="VARCHAR"/>
    </resultMap>
    <resultMap id="BaseResultMapInfo" type="com.brilliance.isc.vo.component.usr.UsrInfoVo">
        <result property="inr" column="inr" jdbcType="VARCHAR"/>
        <result property="extkey" column="extkey" jdbcType="VARCHAR"/>
        <result property="nam" column="nam" jdbcType="VARCHAR"/>
        <result property="lgiflg" column="lgiflg" jdbcType="VARCHAR"/>
        <result property="ssnbegdattim" column="ssnbegdattim" jdbcType="DATE"/>
        <result property="ssninr" column="ssninr" jdbcType="VARCHAR"/>
        <result property="ver" column="ver" jdbcType="VARCHAR"/>
        <result property="pri" column="pri" jdbcType="VARCHAR"/>
        <result property="ety" column="ety" jdbcType="VARCHAR"/>
        <result property="usg" column="usg" jdbcType="VARCHAR"/>
        <result property="lstdiadat" column="lstdiadat" jdbcType="DATE"/>
        <result property="relcur" column="relcur" jdbcType="VARCHAR"/>
        <result property="relamt" column="relamt" jdbcType="DECIMAL"/>
        <result property="relamt2nd" column="relamt2nd" jdbcType="DECIMAL"/>
        <result property="relgrp" column="relgrp" jdbcType="VARCHAR"/>
        <result property="tel" column="tel" jdbcType="VARCHAR"/>
        <result property="fax" column="fax" jdbcType="VARCHAR"/>
        <result property="eml" column="eml" jdbcType="VARCHAR"/>
        <result property="letoenr" column="letoenr" jdbcType="VARCHAR"/>
        <result property="quepow" column="quepow" jdbcType="DECIMAL"/>
        <result property="etyextkey" column="etyextkey" jdbcType="VARCHAR"/>
        <result property="oenr" column="oenr" jdbcType="VARCHAR"/>
        <result property="etaextkey" column="etaextkey" jdbcType="VARCHAR"/>
        <result property="resusrflg" column="resusrflg" jdbcType="VARCHAR"/>
        <result property="secsta" column="secsta" jdbcType="VARCHAR"/>
        <result property="userdetailsid" column="userdetailsid" jdbcType="INTEGER"/>
        <result property="authlevel" column="authlevel" jdbcType="VARCHAR"/>
        <result property="authority" column="authority" jdbcType="VARCHAR"/>
        <result property="bchname" column="bchname" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        inr,extkey,nam,lgiflg,ssnbegdattim,ssninr,ver,pri,ety,usg,lstdiadat,relcur,relamt,relamt2nd,relgrp,tel,fax,eml,letoenr,quepow,etyextkey,oenr,etaextkey,resusrflg,secsta,userdetailsid,authlevel,authority
    </sql>

    <select id="getUsrByConditionSql" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from usr
        ${conditionSql}
    </select>

    <select id="selectByPrimaryKey" resultMap="BaseResultMap">
        select
            <include refid="Base_Column_List" />
        from usr
        where inr = #{inr,jdbcType=VARCHAR}
    </select>

    <delete id="deleteByPrimaryKey">
        delete from usr
        where inr = #{inr,jdbcType=VARCHAR}
    </delete>

    <insert id="insert">
        insert into usr (<include refid="Base_Column_List" />)
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{inr,jdbcType=VARCHAR},
            #{extkey,jdbcType=VARCHAR},
            #{nam,jdbcType=VARCHAR},
            #{lgiflg,jdbcType=VARCHAR},
            #{ssnbegdattim,jdbcType=DATE},
            #{ssninr,jdbcType=VARCHAR},
            #{ver,jdbcType=VARCHAR},
            #{pri,jdbcType=VARCHAR},
            #{ety,jdbcType=VARCHAR},
            #{usg,jdbcType=VARCHAR},
            #{lstdiadat,jdbcType=DATE},
            #{relcur,jdbcType=VARCHAR},
            #{relamt,jdbcType=DECIMAL},
            #{relamt2nd,jdbcType=DECIMAL},
            #{relgrp,jdbcType=VARCHAR},
            #{tel,jdbcType=VARCHAR},
            #{fax,jdbcType=VARCHAR},
            #{eml,jdbcType=VARCHAR},
            #{letoenr,jdbcType=VARCHAR},
            #{quepow,jdbcType=DECIMAL},
            #{etyextkey,jdbcType=VARCHAR},
            #{oenr,jdbcType=VARCHAR},
            #{etaextkey,jdbcType=VARCHAR},
            #{resusrflg,jdbcType=VARCHAR},
            #{secsta,jdbcType=VARCHAR},
            #{userdetailsid,jdbcType=INTEGER},
            #{authlevel,jdbcType=VARCHAR},
            #{authority,jdbcType=VARCHAR},
        </trim>
    </insert>

    <insert id="insertSelective">
        insert into usr
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="inr != null">inr,</if>
            <if test="extkey != null">extkey,</if>
            <if test="nam != null">nam,</if>
            <if test="lgiflg != null">lgiflg,</if>
            <if test="ssnbegdattim != null">ssnbegdattim,</if>
            <if test="ssninr != null">ssninr,</if>
            <if test="ver != null">ver,</if>
            <if test="pri != null">pri,</if>
            <if test="ety != null">ety,</if>
            <if test="usg != null">usg,</if>
            <if test="lstdiadat != null">lstdiadat,</if>
            <if test="relcur != null">relcur,</if>
            <if test="relamt != null">relamt,</if>
            <if test="relamt2nd != null">relamt2nd,</if>
            <if test="relgrp != null">relgrp,</if>
            <if test="tel != null">tel,</if>
            <if test="fax != null">fax,</if>
            <if test="eml != null">eml,</if>
            <if test="letoenr != null">letoenr,</if>
            <if test="quepow != null">quepow,</if>
            <if test="etyextkey != null">etyextkey,</if>
            <if test="oenr != null">oenr,</if>
            <if test="etaextkey != null">etaextkey,</if>
            <if test="resusrflg != null">resusrflg,</if>
            <if test="secsta != null">secsta,</if>
            <if test="userdetailsid != null">userdetailsid,</if>
            <if test="authlevel != null">authlevel,</if>
            <if test="authority != null">authority,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="inr != null">#{inr,jdbcType=VARCHAR}, </if>
            <if test="extkey != null">#{extkey,jdbcType=VARCHAR}, </if>
            <if test="nam != null">#{nam,jdbcType=VARCHAR}, </if>
            <if test="lgiflg != null">#{lgiflg,jdbcType=VARCHAR}, </if>
            <if test="ssnbegdattim != null">#{ssnbegdattim,jdbcType=DATE}, </if>
            <if test="ssninr != null">#{ssninr,jdbcType=VARCHAR}, </if>
            <if test="ver != null">#{ver,jdbcType=VARCHAR}, </if>
            <if test="pri != null">#{pri,jdbcType=VARCHAR}, </if>
            <if test="ety != null">#{ety,jdbcType=VARCHAR}, </if>
            <if test="usg != null">#{usg,jdbcType=VARCHAR}, </if>
            <if test="lstdiadat != null">#{lstdiadat,jdbcType=DATE}, </if>
            <if test="relcur != null">#{relcur,jdbcType=VARCHAR}, </if>
            <if test="relamt != null">#{relamt,jdbcType=DECIMAL}, </if>
            <if test="relamt2nd != null">#{relamt2nd,jdbcType=DECIMAL}, </if>
            <if test="relgrp != null">#{relgrp,jdbcType=VARCHAR}, </if>
            <if test="tel != null">#{tel,jdbcType=VARCHAR}, </if>
            <if test="fax != null">#{fax,jdbcType=VARCHAR}, </if>
            <if test="eml != null">#{eml,jdbcType=VARCHAR}, </if>
            <if test="letoenr != null">#{letoenr,jdbcType=VARCHAR}, </if>
            <if test="quepow != null">#{quepow,jdbcType=DECIMAL}, </if>
            <if test="etyextkey != null">#{etyextkey,jdbcType=VARCHAR}, </if>
            <if test="oenr != null">#{oenr,jdbcType=VARCHAR}, </if>
            <if test="etaextkey != null">#{etaextkey,jdbcType=VARCHAR}, </if>
            <if test="resusrflg != null">#{resusrflg,jdbcType=VARCHAR}, </if>
            <if test="secsta != null">#{secsta,jdbcType=VARCHAR}, </if>
            <if test="userdetailsid != null">#{userdetailsid,jdbcType=INTEGER}, </if>
            <if test="authlevel != null">#{authlevel,jdbcType=VARCHAR},</if>
            <if test="authority != null">#{authority,jdbcType=VARCHAR},</if>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective">
        update usr
        <set>
            <if test="extkey != null">extkey = #{extkey,jdbcType=VARCHAR},</if>
            <if test="nam != null">nam = #{nam,jdbcType=VARCHAR},</if>
            <if test="lgiflg != null">lgiflg = #{lgiflg,jdbcType=VARCHAR},</if>
            <if test="ssnbegdattim != null">ssnbegdattim = #{ssnbegdattim,jdbcType=DATE},</if>
            <if test="ssninr != null">ssninr = #{ssninr,jdbcType=VARCHAR},</if>
            <if test="ver != null">ver = #{ver,jdbcType=VARCHAR},</if>
            <if test="pri != null">pri = #{pri,jdbcType=VARCHAR},</if>
            <if test="ety != null">ety = #{ety,jdbcType=VARCHAR},</if>
            <if test="usg != null">usg = #{usg,jdbcType=VARCHAR},</if>
            <if test="lstdiadat != null">lstdiadat = #{lstdiadat,jdbcType=DATE},</if>
            <if test="relcur != null">relcur = #{relcur,jdbcType=VARCHAR},</if>
            <if test="relamt != null">relamt = #{relamt,jdbcType=DECIMAL},</if>
            <if test="relamt2nd != null">relamt2nd = #{relamt2nd,jdbcType=DECIMAL},</if>
            <if test="relgrp != null">relgrp = #{relgrp,jdbcType=VARCHAR},</if>
            <if test="tel != null">tel = #{tel,jdbcType=VARCHAR},</if>
            <if test="fax != null">fax = #{fax,jdbcType=VARCHAR},</if>
            <if test="eml != null">eml = #{eml,jdbcType=VARCHAR},</if>
            <if test="letoenr != null">letoenr = #{letoenr,jdbcType=VARCHAR},</if>
            <if test="quepow != null">quepow = #{quepow,jdbcType=DECIMAL},</if>
            <if test="etyextkey != null">etyextkey = #{etyextkey,jdbcType=VARCHAR},</if>
            <if test="oenr != null">oenr = #{oenr,jdbcType=VARCHAR},</if>
            <if test="etaextkey != null">etaextkey = #{etaextkey,jdbcType=VARCHAR},</if>
            <if test="resusrflg != null">resusrflg = #{resusrflg,jdbcType=VARCHAR},</if>
            <if test="secsta != null">secsta = #{secsta,jdbcType=VARCHAR},</if>
            <if test="userdetailsid != null">userdetailsid = #{userdetailsid,jdbcType=INTEGER}, </if>
            <if test="authlevel != null">authlevel = #{authlevel,jdbcType=VARCHAR},</if>
            <if test="authority != null">authority = #{authority,jdbcType=VARCHAR},</if>
        </set>
        where inr = #{inr,jdbcType=VARCHAR}
    </update>

    <update id="updateByPrimaryKey">
        update usr
        <set>
            extkey = #{extkey,jdbcType=VARCHAR},
            nam = #{nam,jdbcType=VARCHAR},
            lgiflg = #{lgiflg,jdbcType=VARCHAR},
            ssnbegdattim = #{ssnbegdattim,jdbcType=DATE},
            ssninr = #{ssninr,jdbcType=VARCHAR},
            ver = #{ver,jdbcType=VARCHAR},
            pri = #{pri,jdbcType=VARCHAR},
            ety = #{ety,jdbcType=VARCHAR},
            usg = #{usg,jdbcType=VARCHAR},
            lstdiadat = #{lstdiadat,jdbcType=DATE},
            relcur = #{relcur,jdbcType=VARCHAR},
            relamt = #{relamt,jdbcType=DECIMAL},
            relamt2nd = #{relamt2nd,jdbcType=DECIMAL},
            relgrp = #{relgrp,jdbcType=VARCHAR},
            tel = #{tel,jdbcType=VARCHAR},
            fax = #{fax,jdbcType=VARCHAR},
            eml = #{eml,jdbcType=VARCHAR},
            letoenr = #{letoenr,jdbcType=VARCHAR},
            quepow = #{quepow,jdbcType=DECIMAL},
            etyextkey = #{etyextkey,jdbcType=VARCHAR},
            oenr = #{oenr,jdbcType=VARCHAR},
            etaextkey = #{etaextkey,jdbcType=VARCHAR},
            resusrflg = #{resusrflg,jdbcType=VARCHAR},
            secsta = #{secsta,jdbcType=VARCHAR},
            userdetailsid = #{userdetailsid,jdbcType=INTEGER},
            authlevel = #{authlevel,jdbcType=VARCHAR},
            authority = #{authority,jdbcType=VARCHAR},
        </set>
        where inr = #{inr,jdbcType=VARCHAR}
    </update>

    <delete id="deleteByIds">
        delete from act where inr in
        <foreach item="item" index="index" collection="collection" open="(" separator="," close=")">
            #{item}
        </foreach>
    </delete>

    <update id="dyncUpdate">
        update usr
        <set>
            <if test="module.extkey != null">extkey = #{module.extkey,jdbcType=VARCHAR},</if>
            <if test="module.nam != null">nam = #{module.nam,jdbcType=VARCHAR},</if>
            <if test="module.lgiflg != null">lgiflg = #{module.lgiflg,jdbcType=VARCHAR},</if>
            <if test="module.ssnbegdattim != null">ssnbegdattim = #{module.ssnbegdattim,jdbcType=DATE},</if>
            <if test="module.ssninr != null">ssninr = #{module.ssninr,jdbcType=VARCHAR},</if>
            <if test="module.ver != null">ver = #{module.ver,jdbcType=VARCHAR},</if>
            <if test="module.pri != null">pri = #{module.pri,jdbcType=VARCHAR},</if>
            <if test="module.ety != null">ety = #{module.ety,jdbcType=VARCHAR},</if>
            <if test="module.usg != null">usg = #{module.usg,jdbcType=VARCHAR},</if>
            <if test="module.lstdiadat != null">lstdiadat = #{module.lstdiadat,jdbcType=DATE},</if>
            <if test="module.relcur != null">relcur = #{module.relcur,jdbcType=VARCHAR},</if>
            <if test="module.relamt != null">relamt = #{module.relamt,jdbcType=DECIMAL},</if>
            <if test="module.relamt2nd != null">relamt2nd = #{module.relamt2nd,jdbcType=DECIMAL},</if>
            <if test="module.relgrp != null">relgrp = #{module.relgrp,jdbcType=VARCHAR},</if>
            <if test="module.tel != null">tel = #{module.tel,jdbcType=VARCHAR},</if>
            <if test="module.fax != null">fax = #{module.fax,jdbcType=VARCHAR},</if>
            <if test="module.eml != null">eml = #{module.eml,jdbcType=VARCHAR},</if>
            <if test="module.letoenr != null">letoenr = #{module.letoenr,jdbcType=VARCHAR},</if>
            <if test="module.quepow != null">quepow = #{module.quepow,jdbcType=DECIMAL},</if>
            <if test="module.etyextkey != null">etyextkey = #{module.etyextkey,jdbcType=VARCHAR},</if>
            <if test="module.oenr != null">oenr = #{module.oenr,jdbcType=VARCHAR},</if>
            <if test="module.etaextkey != null">etaextkey = #{module.etaextkey,jdbcType=VARCHAR},</if>
            <if test="module.resusrflg != null">resusrflg = #{module.resusrflg,jdbcType=VARCHAR},</if>
            <if test="module.secsta != null">secsta = #{module.secsta,jdbcType=VARCHAR},</if>
            <if test="module.userdetailsid != null">userdetailsid = #{module.userdetailsid,jdbcType=INTEGER}, </if>
            <if test="module.authlevel != null">authlevel = #{module.authlevel,jdbcType=VARCHAR},</if>
            <if test="module.authority != null">authority = #{module.authority,jdbcType=VARCHAR},</if>
        </set>
        ${conditions}
    </update>

    <delete id="dyncDelete">
        ${sql}
    </delete>

    <select id="dyncRead" resultMap="BaseResultMap">
        ${sql}
    </select>

    <select id="getUsrByExtkey" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from usr
        where trim(extkey) = #{extkey,jdbcType=VARCHAR}
    </select>

    <select id="getUsrByRecord" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from usr
        <where>
            <if test="extkey != null and extkey != ''">
                and extkey = #{extkey,jdbcType=VARCHAR}
            </if>
            <if test="nam != null and nam != ''">
                and nam = #{nam,jdbcType=VARCHAR}
            </if>
            <if test="lgiflg != null and lgiflg != ''">
                and lgiflg = #{lgiflg,jdbcType=VARCHAR}
            </if>
            <if test="ssnbegdattim != null and ssnbegdattim != ''">
                and ssnbegdattim = #{ssnbegdattim,jdbcType=DATE}
            </if>
            <if test="ssninr != null and ssninr != ''">
                and ssninr = #{ssninr,jdbcType=VARCHAR}
            </if>
            <if test="ver != null and ver != ''">
                and ver = #{ver,jdbcType=VARCHAR}
            </if>
            <if test="pri != null and pri != ''">
                and pri = #{pri,jdbcType=VARCHAR}
            </if>
            <if test="ety != null and ety != ''">
                and ety = #{ety,jdbcType=VARCHAR}
            </if>
            <if test="usg != null and usg != ''">
                and usg = #{usg,jdbcType=VARCHAR}
            </if>
            <if test="lstdiadat != null and lstdiadat != ''">
                and lstdiadat = #{lstdiadat,jdbcType=DATE}
            </if>
            <if test="relcur != null and relcur != ''">
                and relcur = #{relcur,jdbcType=VARCHAR}
            </if>
            <if test="relamt != null and relamt != ''">
                and relamt = #{relamt,jdbcType=DECIMAL}
            </if>
            <if test="relamt2nd != null and relamt2nd != ''">
                and relamt2nd = #{relamt2nd,jdbcType=DECIMAL}
            </if>
            <if test="relgrp != null and relgrp != ''">
                and relgrp = #{relgrp,jdbcType=VARCHAR}
            </if>
            <if test="tel != null and tel != ''">
                and tel = #{tel,jdbcType=VARCHAR}
            </if>
            <if test="fax != null and fax != ''">
                and fax = #{fax,jdbcType=VARCHAR}
            </if>
            <if test="eml != null and eml != ''">
                and eml = #{eml,jdbcType=VARCHAR}
            </if>
            <if test="letoenr != null and letoenr != ''">
                and letoenr = #{letoenr,jdbcType=VARCHAR}
            </if>
            <if test="quepow != null and quepow != ''">
                and quepow = #{quepow,jdbcType=DECIMAL}
            </if>
            <if test="etyextkey != null and etyextkey != ''">
                and etyextkey = #{etyextkey,jdbcType=VARCHAR}
            </if>
            <if test="oenr != null and oenr != ''">
                and oenr = #{oenr,jdbcType=VARCHAR}
            </if>
            <if test="etaextkey != null and etaextkey != ''">
                and etaextkey = #{etaextkey,jdbcType=VARCHAR}
            </if>
            <if test="resusrflg != null and resusrflg != ''">
                and resusrflg = #{resusrflg,jdbcType=VARCHAR}
            </if>
            <if test="secsta != null and secsta != ''">
                and secsta = #{secsta,jdbcType=VARCHAR}
            </if>
            <if test="userdetailsid != null and userdetailsid != ''">
                and userdetailsid = #{userdetailsid,jdbcType=INTEGER}
            </if>
            <if test="authlevel != null and authlevel != ''">
                and authlevel = #{authlevel,jdbcType=VARCHAR}
            </if>
            <if test="authority != null and authority != ''">
                and authority = #{authority,jdbcType=VARCHAR}
            </if>
        </where>
    </select>
    <select id="selectByBranch" resultMap="BaseResultMapInfo">
        select
        distinct usr.inr,usr.EXTKEY,usr.NAM,'' as bchname
        from usr
        left join ec_org_personconndepartment ub on ub.personid=usr.USERDETAILSID
                  and  ub.STATE ='1'
        left join ec_org_department dep on dep.id=ub.DEPARTMENTID
        left join bch  on bch.branch=dep.DEPARTMENTNUMBER
        where 1=1
        <choose>
            <when test="list!=null and list.size()>0">
                and bch.inr in
                <foreach collection="list" item="items" open="(" separator="," close=")">
                    #{items}
                </foreach>
            </when>
            <otherwise>
            </otherwise>
        </choose>
        and (usr.extkey is not null and usr.extkey !='')
    </select>

    <select id="selectByBch" resultType="com.brilliance.isc.vo.component.usr.UsrInfoVo">
        select
            usr.inr,
            usr.EXTKEY ,
            usr.NAM nam,
            eod.NAME bchname,
            eod.DEPARTMENTNUMBER branch,
            b.inr bchinr
        from
            USR,
            ec_org_personconndepartment eop ,
            ec_org_department eod,
            bch b
        where
            USR.USERDETAILSID = eop.PERSONID
          and eod.id = eop.DEPARTMENTID
          and eod.DEPARTMENTNUMBER = b.BRANCH
          and b.inr in
            <foreach collection="list" item="items" open="(" separator="," close=")">
                    #{items}
            </foreach>
    </select>

    <select id="selectUsrForTsk" resultType="com.brilliance.isc.vo.component.usr.UsrInfoVo">
        select
        usr.INR,
        usr.EXTKEY ,
        usr.NAM nam,
        eod.NAME bchname,
        eod.DEPARTMENTNUMBER branch,
        b.inr bchinr
        from
        USR,
        ec_org_personconndepartment eop ,
        ec_org_department eod,
        bch b
        where
        USR.USERDETAILSID = eop.PERSONID
        and eod.id = eop.DEPARTMENTID
        and eod.DEPARTMENTNUMBER = b.BRANCH
        and b.inr in
        <foreach collection="list" item="items" open="(" separator="," close=")">
            #{items}
        </foreach>
        and usr.extkey not in (select extkey from tskusr where branchinr in
        <foreach collection="list" item="items" open="(" separator="," close=")">
            #{items}
        </foreach>
        )
    </select>

    <select id="listUserDepartmentNums" resultType="java.lang.String">
        select eod.DEPARTMENTNUMBER from ec_org_personconndepartment eop
        left join ec_org_department eod on eop.DEPARTMENTID = eod.ID
        where eop.PERSONID = #{userdetailsid,jdbcType=INTEGER}
    </select>

    <update id="updateByUserdetailsid">
        update
            usr
        set
            authlevel = '',
            authority = '0'
        where
            userdetailsid = #{userdetailsid,jdbcType=INTEGER}
    </update>
    <select id="getUserList" resultMap="BaseResultMapInfo">
        select distinct u.inr,u.EXTKEY,u.NAM,'' as bchname  from usr u
         left join uro uo on uo.ACCBCH=#{branch,jdbcType=VARCHAR} and uo.USERDETAILSID =u.USERDETAILSID
         left join ec_org_department d on d.DEPARTMENTNUMBER =uo.ACCBCH
         left join ec_org_department pd on pd.DEPARTMENTNUMBER = d.PARENTDEPARTMENTID
         left join ec_org_persondetails ud on ud.id=u.USERDETAILSID
         right join ec_org_personconndepartment dp on dp.PERSONID =u.USERDETAILSID and dp.state='1'
                     and ud.WORKORG !='1000' and (dp.DEPARTMENTID  =d.ID  or dp.DEPARTMENTID =pd.id)
        where  u.USERDETAILSID is not null
        and (u.secsta='Y' or u.secsta is null)
        order by u.extkey asc
    </select>

    <select id="getHeadUserList" resultMap="BaseResultMapInfo">
    select   distinct usr.inr,usr.EXTKEY,usr.NAM,'' as bchname  from usr
    where (usr.secsta='Y' or usr.secsta is null )  and USERDETAILSID  in(select eop.PERSONID  from ec_org_personconndepartment eop
    left join ec_org_department eod on eop.DEPARTMENTID = eod.ID
    left join ec_org_personconnrole pr on pr.PERSONID = eop.PERSONID
    where eod.DEPARTMENTNUMBER ='1000' and pr.ROLEID ='10255')
    order by usr.extkey asc
    </select>

    <select id="getUserListA" resultType="com.brilliance.isc.vo.lg.UsrExtkeyVo">
    select
	distinct usr.inr,usr.EXTKEY extkey,usr.NAM nam,'' idx
    from
	ec_org_personconnrole eopr
    left join usr on
	usr.USERDETAILSID = eopr.PERSONID
    left join ec_org_role eor on
	eor.id = eopr.ROLEID
    where
	eor.DESCRIPTION = '单证中心'
	and usr.extkey is not null
	and usr.extkey !=''
    </select>

    <select id="getUserListB" resultType="com.brilliance.isc.vo.lg.UsrExtkeyVo">
    select
	distinct usr.inr,usr.EXTKEY extkey,usr.NAM nam,'' idx
    from
	ec_org_personconnrole eopr
    left join usr on
	usr.USERDETAILSID = eopr.PERSONID
    left join ec_org_role eor on
	eor.id = eopr.ROLEID
    where
	eor.DESCRIPTION like '押汇中心%'
	and usr.extkey is not null
	and usr.extkey !=''
    </select>

</mapper>