<?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.foreverwin.mesnac.meapi.mapper.NwaUserMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.foreverwin.mesnac.meapi.model.NwaUser">
        <id column="HANDLE" property="handle" />
        <result column="USER_NAME" property="userName" />
        <result column="FIRST_NAME" property="firstName" />
        <result column="LAST_NAME" property="lastName" />
        <result column="FULL_NAME" property="fullName" />
        <result column="PASSWORD" property="password" />
        <result column="SALT" property="salt" />
        <result column="PHONE" property="phone" />
        <result column="AVATAR" property="avatar" />
        <result column="DEPT_ID" property="deptId" />
        <result column="CREATE_TIME" property="createTime" />
        <result column="UPDATE_TIME" property="updateTime" />
        <result column="LOCK_FLAG" property="lockFlag" />
        <result column="DEL_FLAG" property="delFlag" />
        <result column="SITE" property="site" />
        <result column="DEPT_DESC" property="deptDesc" />
        <result column="VALID_FROM" property="validFrom" />
        <result column="VALID_TO" property="validTo" />
        <result column="JOB_TITLE" property="jobTitle" />
        <result column="EMAIL" property="email" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        HANDLE, USER_NAME, FIRST_NAME, LAST_NAME, FULL_NAME, PASSWORD, SALT, PHONE, AVATAR, DEPT_ID, CREATE_TIME, UPDATE_TIME, LOCK_FLAG, DEL_FLAG, SITE, DEPT_DESC, VALID_FROM, VALID_TO, JOB_TITLE, EMAIL
    </sql>

    <!-- BaseMapper标准查询/修改/删除 -->
    <select id="selectById" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"></include> FROM Z_NWA_USER WHERE HANDLE=#{handle}
    </select>

    <select id="selectByMap" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"></include>
        FROM Z_NWA_USER
        <if test="cm!=null and !cm.isEmpty">
            <where>
                <foreach collection="cm.keys" item="k" separator="AND">
                    <if test="cm[k] != null">
                        ${k} = #{cm[${k}]}
                    </if>
                </foreach>
            </where>
        </if>
    </select>

    <select id="selectBatchIds" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"></include>
        FROM Z_NWA_USER WHERE HANDLE IN (
        <foreach item="item" index="index" collection="coll" separator=",">#{item}
        </foreach>)
    </select>

    <select id="selectOne" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"></include> FROM Z_NWA_USER
        <where>
            <if test="ew.entity.handle!=null">
              HANDLE=#{ew.handle}
            </if>
            <if test="ew.entity.userName!=null"> AND USER_NAME=#{ew.entity.userName}</if>
            <if test="ew.entity.firstName!=null"> AND FIRST_NAME=#{ew.entity.firstName}</if>
            <if test="ew.entity.lastName!=null"> AND LAST_NAME=#{ew.entity.lastName}</if>
            <if test="ew.entity.fullName!=null"> AND FULL_NAME=#{ew.entity.fullName}</if>
            <if test="ew.entity.password!=null"> AND PASSWORD=#{ew.entity.password}</if>
            <if test="ew.entity.salt!=null"> AND SALT=#{ew.entity.salt}</if>
            <if test="ew.entity.phone!=null"> AND PHONE=#{ew.entity.phone}</if>
            <if test="ew.entity.avatar!=null"> AND AVATAR=#{ew.entity.avatar}</if>
            <if test="ew.entity.deptId!=null"> AND DEPT_ID=#{ew.entity.deptId}</if>
            <if test="ew.entity.createTime!=null"> AND CREATE_TIME=#{ew.entity.createTime}</if>
            <if test="ew.entity.updateTime!=null"> AND UPDATE_TIME=#{ew.entity.updateTime}</if>
            <if test="ew.entity.lockFlag!=null"> AND LOCK_FLAG=#{ew.entity.lockFlag}</if>
            <if test="ew.entity.delFlag!=null"> AND DEL_FLAG=#{ew.entity.delFlag}</if>
            <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
            <if test="ew.entity.deptDesc!=null"> AND DEPT_DESC=#{ew.entity.deptDesc}</if>
            <if test="ew.entity.validFrom!=null"> AND VALID_FROM=#{ew.entity.validFrom}</if>
            <if test="ew.entity.validTo!=null"> AND VALID_TO=#{ew.entity.validTo}</if>
            <if test="ew.entity.jobTitle!=null"> AND JOB_TITLE=#{ew.entity.jobTitle}</if>
            <if test="ew.entity.email!=null"> AND EMAIL=#{ew.entity.email}</if>
        </where>
    </select>

    <select id="selectCount" resultType="Integer">
        SELECT COUNT(1) FROM Z_NWA_USER
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                <if test="ew.entity.handle!=null">
                    HANDLE=#{ew.entity.handle}
                </if>
                <if test="ew.entity.userName!=null"> AND USER_NAME=#{ew.entity.userName}</if>
                <if test="ew.entity.firstName!=null"> AND FIRST_NAME=#{ew.entity.firstName}</if>
                <if test="ew.entity.lastName!=null"> AND LAST_NAME=#{ew.entity.lastName}</if>
                <if test="ew.entity.fullName!=null"> AND FULL_NAME=#{ew.entity.fullName}</if>
                <if test="ew.entity.password!=null"> AND PASSWORD=#{ew.entity.password}</if>
                <if test="ew.entity.salt!=null"> AND SALT=#{ew.entity.salt}</if>
                <if test="ew.entity.phone!=null"> AND PHONE=#{ew.entity.phone}</if>
                <if test="ew.entity.avatar!=null"> AND AVATAR=#{ew.entity.avatar}</if>
                <if test="ew.entity.deptId!=null"> AND DEPT_ID=#{ew.entity.deptId}</if>
                <if test="ew.entity.createTime!=null"> AND CREATE_TIME=#{ew.entity.createTime}</if>
                <if test="ew.entity.updateTime!=null"> AND UPDATE_TIME=#{ew.entity.updateTime}</if>
                <if test="ew.entity.lockFlag!=null"> AND LOCK_FLAG=#{ew.entity.lockFlag}</if>
                <if test="ew.entity.delFlag!=null"> AND DEL_FLAG=#{ew.entity.delFlag}</if>
                <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                <if test="ew.entity.deptDesc!=null"> AND DEPT_DESC=#{ew.entity.deptDesc}</if>
                <if test="ew.entity.validFrom!=null"> AND VALID_FROM=#{ew.entity.validFrom}</if>
                <if test="ew.entity.validTo!=null"> AND VALID_TO=#{ew.entity.validTo}</if>
                <if test="ew.entity.jobTitle!=null"> AND JOB_TITLE=#{ew.entity.jobTitle}</if>
                <if test="ew.entity.email!=null"> AND EMAIL=#{ew.entity.email}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <select id="selectList" resultMap="BaseResultMap">
        SELECT <choose><when test="ew != null and ew.sqlSelect != null">${ew.sqlSelect}</when><otherwise><include refid="Base_Column_List"></include></otherwise></choose> FROM Z_NWA_USER
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.userName!=null"> AND USER_NAME=#{ew.entity.userName}</if>
                    <if test="ew.entity.firstName!=null"> AND FIRST_NAME=#{ew.entity.firstName}</if>
                    <if test="ew.entity.lastName!=null"> AND LAST_NAME=#{ew.entity.lastName}</if>
                    <if test="ew.entity.fullName!=null"> AND FULL_NAME=#{ew.entity.fullName}</if>
                    <if test="ew.entity.password!=null"> AND PASSWORD=#{ew.entity.password}</if>
                    <if test="ew.entity.salt!=null"> AND SALT=#{ew.entity.salt}</if>
                    <if test="ew.entity.phone!=null"> AND PHONE=#{ew.entity.phone}</if>
                    <if test="ew.entity.avatar!=null"> AND AVATAR=#{ew.entity.avatar}</if>
                    <if test="ew.entity.deptId!=null"> AND DEPT_ID=#{ew.entity.deptId}</if>
                    <if test="ew.entity.createTime!=null"> AND CREATE_TIME=#{ew.entity.createTime}</if>
                    <if test="ew.entity.updateTime!=null"> AND UPDATE_TIME=#{ew.entity.updateTime}</if>
                    <if test="ew.entity.lockFlag!=null"> AND LOCK_FLAG=#{ew.entity.lockFlag}</if>
                    <if test="ew.entity.delFlag!=null"> AND DEL_FLAG=#{ew.entity.delFlag}</if>
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.deptDesc!=null"> AND DEPT_DESC=#{ew.entity.deptDesc}</if>
                    <if test="ew.entity.validFrom!=null"> AND VALID_FROM=#{ew.entity.validFrom}</if>
                    <if test="ew.entity.validTo!=null"> AND VALID_TO=#{ew.entity.validTo}</if>
                    <if test="ew.entity.jobTitle!=null"> AND JOB_TITLE=#{ew.entity.jobTitle}</if>
                    <if test="ew.entity.email!=null"> AND EMAIL=#{ew.entity.email}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                   AND ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            AND ${ew.sqlSegment}
        </if>
    </select>

    <select id="selectMaps" resultType="HashMap">
        SELECT <choose><when test="ew != null and ew.sqlSelect != null">${ew.sqlSelect}</when><otherwise><include refid="Base_Column_List"></include></otherwise></choose> FROM Z_NWA_USER
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.userName!=null"> AND USER_NAME=#{ew.entity.userName}</if>
                    <if test="ew.entity.firstName!=null"> AND FIRST_NAME=#{ew.entity.firstName}</if>
                    <if test="ew.entity.lastName!=null"> AND LAST_NAME=#{ew.entity.lastName}</if>
                    <if test="ew.entity.fullName!=null"> AND FULL_NAME=#{ew.entity.fullName}</if>
                    <if test="ew.entity.password!=null"> AND PASSWORD=#{ew.entity.password}</if>
                    <if test="ew.entity.salt!=null"> AND SALT=#{ew.entity.salt}</if>
                    <if test="ew.entity.phone!=null"> AND PHONE=#{ew.entity.phone}</if>
                    <if test="ew.entity.avatar!=null"> AND AVATAR=#{ew.entity.avatar}</if>
                    <if test="ew.entity.deptId!=null"> AND DEPT_ID=#{ew.entity.deptId}</if>
                    <if test="ew.entity.createTime!=null"> AND CREATE_TIME=#{ew.entity.createTime}</if>
                    <if test="ew.entity.updateTime!=null"> AND UPDATE_TIME=#{ew.entity.updateTime}</if>
                    <if test="ew.entity.lockFlag!=null"> AND LOCK_FLAG=#{ew.entity.lockFlag}</if>
                    <if test="ew.entity.delFlag!=null"> AND DEL_FLAG=#{ew.entity.delFlag}</if>
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.deptDesc!=null"> AND DEPT_DESC=#{ew.entity.deptDesc}</if>
                    <if test="ew.entity.validFrom!=null"> AND VALID_FROM=#{ew.entity.validFrom}</if>
                    <if test="ew.entity.validTo!=null"> AND VALID_TO=#{ew.entity.validTo}</if>
                    <if test="ew.entity.jobTitle!=null"> AND JOB_TITLE=#{ew.entity.jobTitle}</if>
                    <if test="ew.entity.email!=null"> AND EMAIL=#{ew.entity.email}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <select id="selectObjs" resultType="Object">
        SELECT <choose><when test="ew != null and ew.sqlSelect != null">${ew.sqlSelect}</when><otherwise><include refid="Base_Column_List"></include></otherwise></choose> FROM Z_NWA_USER
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.userName!=null"> AND USER_NAME=#{ew.entity.userName}</if>
                    <if test="ew.entity.firstName!=null"> AND FIRST_NAME=#{ew.entity.firstName}</if>
                    <if test="ew.entity.lastName!=null"> AND LAST_NAME=#{ew.entity.lastName}</if>
                    <if test="ew.entity.fullName!=null"> AND FULL_NAME=#{ew.entity.fullName}</if>
                    <if test="ew.entity.password!=null"> AND PASSWORD=#{ew.entity.password}</if>
                    <if test="ew.entity.salt!=null"> AND SALT=#{ew.entity.salt}</if>
                    <if test="ew.entity.phone!=null"> AND PHONE=#{ew.entity.phone}</if>
                    <if test="ew.entity.avatar!=null"> AND AVATAR=#{ew.entity.avatar}</if>
                    <if test="ew.entity.deptId!=null"> AND DEPT_ID=#{ew.entity.deptId}</if>
                    <if test="ew.entity.createTime!=null"> AND CREATE_TIME=#{ew.entity.createTime}</if>
                    <if test="ew.entity.updateTime!=null"> AND UPDATE_TIME=#{ew.entity.updateTime}</if>
                    <if test="ew.entity.lockFlag!=null"> AND LOCK_FLAG=#{ew.entity.lockFlag}</if>
                    <if test="ew.entity.delFlag!=null"> AND DEL_FLAG=#{ew.entity.delFlag}</if>
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.deptDesc!=null"> AND DEPT_DESC=#{ew.entity.deptDesc}</if>
                    <if test="ew.entity.validFrom!=null"> AND VALID_FROM=#{ew.entity.validFrom}</if>
                    <if test="ew.entity.validTo!=null"> AND VALID_TO=#{ew.entity.validTo}</if>
                    <if test="ew.entity.jobTitle!=null"> AND JOB_TITLE=#{ew.entity.jobTitle}</if>
                    <if test="ew.entity.email!=null"> AND EMAIL=#{ew.entity.email}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <select id="selectPage" resultMap="BaseResultMap">
        SELECT <choose><when test="ew != null and ew.sqlSelect != null">${ew.sqlSelect}</when><otherwise><include refid="Base_Column_List"></include></otherwise></choose> FROM Z_NWA_USER
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.userName!=null"> AND USER_NAME=#{ew.entity.userName}</if>
                    <if test="ew.entity.firstName!=null"> AND FIRST_NAME=#{ew.entity.firstName}</if>
                    <if test="ew.entity.lastName!=null"> AND LAST_NAME=#{ew.entity.lastName}</if>
                    <if test="ew.entity.fullName!=null"> AND FULL_NAME=#{ew.entity.fullName}</if>
                    <if test="ew.entity.password!=null"> AND PASSWORD=#{ew.entity.password}</if>
                    <if test="ew.entity.salt!=null"> AND SALT=#{ew.entity.salt}</if>
                    <if test="ew.entity.phone!=null"> AND PHONE=#{ew.entity.phone}</if>
                    <if test="ew.entity.avatar!=null"> AND AVATAR=#{ew.entity.avatar}</if>
                    <if test="ew.entity.deptId!=null"> AND DEPT_ID=#{ew.entity.deptId}</if>
                    <if test="ew.entity.createTime!=null"> AND CREATE_TIME=#{ew.entity.createTime}</if>
                    <if test="ew.entity.updateTime!=null"> AND UPDATE_TIME=#{ew.entity.updateTime}</if>
                    <if test="ew.entity.lockFlag!=null"> AND LOCK_FLAG=#{ew.entity.lockFlag}</if>
                    <if test="ew.entity.delFlag!=null"> AND DEL_FLAG=#{ew.entity.delFlag}</if>
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.deptDesc!=null"> AND DEPT_DESC=#{ew.entity.deptDesc}</if>
                    <if test="ew.entity.validFrom!=null"> AND VALID_FROM=#{ew.entity.validFrom}</if>
                    <if test="ew.entity.validTo!=null"> AND VALID_TO=#{ew.entity.validTo}</if>
                    <if test="ew.entity.jobTitle!=null"> AND JOB_TITLE=#{ew.entity.jobTitle}</if>
                    <if test="ew.entity.email!=null"> AND EMAIL=#{ew.entity.email}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <select id="selectMapsPage" resultType="HashMap">
        SELECT <choose><when test="ew != null and ew.sqlSelect != null">${ew.sqlSelect}</when><otherwise><include refid="Base_Column_List"></include></otherwise></choose> FROM Z_NWA_USER
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.userName!=null"> AND USER_NAME=#{ew.entity.userName}</if>
                    <if test="ew.entity.firstName!=null"> AND FIRST_NAME=#{ew.entity.firstName}</if>
                    <if test="ew.entity.lastName!=null"> AND LAST_NAME=#{ew.entity.lastName}</if>
                    <if test="ew.entity.fullName!=null"> AND FULL_NAME=#{ew.entity.fullName}</if>
                    <if test="ew.entity.password!=null"> AND PASSWORD=#{ew.entity.password}</if>
                    <if test="ew.entity.salt!=null"> AND SALT=#{ew.entity.salt}</if>
                    <if test="ew.entity.phone!=null"> AND PHONE=#{ew.entity.phone}</if>
                    <if test="ew.entity.avatar!=null"> AND AVATAR=#{ew.entity.avatar}</if>
                    <if test="ew.entity.deptId!=null"> AND DEPT_ID=#{ew.entity.deptId}</if>
                    <if test="ew.entity.createTime!=null"> AND CREATE_TIME=#{ew.entity.createTime}</if>
                    <if test="ew.entity.updateTime!=null"> AND UPDATE_TIME=#{ew.entity.updateTime}</if>
                    <if test="ew.entity.lockFlag!=null"> AND LOCK_FLAG=#{ew.entity.lockFlag}</if>
                    <if test="ew.entity.delFlag!=null"> AND DEL_FLAG=#{ew.entity.delFlag}</if>
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.deptDesc!=null"> AND DEPT_DESC=#{ew.entity.deptDesc}</if>
                    <if test="ew.entity.validFrom!=null"> AND VALID_FROM=#{ew.entity.validFrom}</if>
                    <if test="ew.entity.validTo!=null"> AND VALID_TO=#{ew.entity.validTo}</if>
                    <if test="ew.entity.jobTitle!=null"> AND JOB_TITLE=#{ew.entity.jobTitle}</if>
                    <if test="ew.entity.email!=null"> AND EMAIL=#{ew.entity.email}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>
    <select id="findUserByUserName" resultType="com.foreverwin.mesnac.meapi.model.NwaUser">
        SELECT *
        FROM Z_NWA_USER
        WHERE SITE = #{site}
        <if test="user != null and user != ''">
            AND USER_NAME = #{user}
        </if>
    </select>
    <select id="findAllUser" resultMap="BaseResultMap">
        SELECT USER_NAME, FULL_NAME
        FROM Z_NWA_USER
        WHERE SITE = #{site}
    </select>

    <insert id="insert" parameterType="com.foreverwin.mesnac.meapi.model.NwaUser">
        INSERT INTO Z_NWA_USER
        <trim prefix="(" suffix=")" suffixOverrides=",">
            HANDLE,
            <if test="userName!=null">USER_NAME,</if>
            <if test="firstName!=null">FIRST_NAME,</if>
            <if test="lastName!=null">LAST_NAME,</if>
            <if test="fullName!=null">FULL_NAME,</if>
            <if test="password!=null">PASSWORD,</if>
            <if test="salt!=null">SALT,</if>
            <if test="phone!=null">PHONE,</if>
            <if test="avatar!=null">AVATAR,</if>
            <if test="deptId!=null">DEPT_ID,</if>
            <if test="createTime!=null">CREATE_TIME,</if>
            <if test="updateTime!=null">UPDATE_TIME,</if>
            <if test="lockFlag!=null">LOCK_FLAG,</if>
            <if test="delFlag!=null">DEL_FLAG,</if>
            <if test="site!=null">SITE,</if>
            <if test="deptDesc!=null">DEPT_DESC,</if>
            <if test="validFrom!=null">VALID_FROM,</if>
            <if test="validTo!=null">VALID_TO,</if>
            <if test="jobTitle!=null">JOB_TITLE,</if>
            <if test="email!=null">EMAIL,</if>
        </trim> VALUES
        <trim prefix="(" suffix=")" suffixOverrides=",">
            #{handle},
            <if test="userName!=null">#{userName},</if>
            <if test="firstName!=null">#{firstName},</if>
            <if test="lastName!=null">#{lastName},</if>
            <if test="fullName!=null">#{fullName},</if>
            <if test="password!=null">#{password},</if>
            <if test="salt!=null">#{salt},</if>
            <if test="phone!=null">#{phone},</if>
            <if test="avatar!=null">#{avatar},</if>
            <if test="deptId!=null">#{deptId},</if>
            <if test="createTime!=null">#{createTime},</if>
            <if test="updateTime!=null">#{updateTime},</if>
            <if test="lockFlag!=null">#{lockFlag},</if>
            <if test="delFlag!=null">#{delFlag},</if>
            <if test="site!=null">#{site},</if>
            <if test="deptDesc!=null">#{deptDesc},</if>
            <if test="validFrom!=null">#{validFrom},</if>
            <if test="validTo!=null">#{validTo},</if>
            <if test="jobTitle!=null">#{jobTitle},</if>
            <if test="email!=null">#{email},</if>
        </trim>
    </insert>

    <insert id="insertAllColumn" parameterType="com.foreverwin.mesnac.meapi.model.NwaUser">
        INSERT INTO Z_NWA_USER
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <include refid="Base_Column_List"></include>
        </trim> VALUES
        <trim prefix="(" suffix=")" suffixOverrides=",">
            #{handle},
            #{userName},
            #{firstName},
            #{lastName},
            #{fullName},
            #{password},
            #{salt},
            #{phone},
            #{avatar},
            #{deptId},
            #{createTime},
            #{updateTime},
            #{lockFlag},
            #{delFlag},
            #{site},
            #{deptDesc},
            #{validFrom},
            #{validTo},
            #{jobTitle},
            #{email},
        </trim>
    </insert>


    <update id="updateById">
        UPDATE Z_NWA_USER <trim prefix="SET" suffixOverrides=",">
        <if test="et.userName!=null">USER_NAME=#{et.userName},</if>
        <if test="et.firstName!=null">FIRST_NAME=#{et.firstName},</if>
        <if test="et.lastName!=null">LAST_NAME=#{et.lastName},</if>
        <if test="et.fullName!=null">FULL_NAME=#{et.fullName},</if>
        <if test="et.password!=null">PASSWORD=#{et.password},</if>
        <if test="et.salt!=null">SALT=#{et.salt},</if>
        <if test="et.phone!=null">PHONE=#{et.phone},</if>
        <if test="et.avatar!=null">AVATAR=#{et.avatar},</if>
        <if test="et.deptId!=null">DEPT_ID=#{et.deptId},</if>
        <if test="et.createTime!=null">CREATE_TIME=#{et.createTime},</if>
        <if test="et.updateTime!=null">UPDATE_TIME=#{et.updateTime},</if>
        <if test="et.lockFlag!=null">LOCK_FLAG=#{et.lockFlag},</if>
        <if test="et.delFlag!=null">DEL_FLAG=#{et.delFlag},</if>
        <if test="et.site!=null">SITE=#{et.site},</if>
        <if test="et.deptDesc!=null">DEPT_DESC=#{et.deptDesc},</if>
        <if test="et.validFrom!=null">VALID_FROM=#{et.validFrom},</if>
        <if test="et.validTo!=null">VALID_TO=#{et.validTo},</if>
        <if test="et.jobTitle!=null">JOB_TITLE=#{et.jobTitle},</if>
        <if test="et.email!=null">EMAIL=#{et.email},</if>
        </trim> WHERE HANDLE=#{et.handle} <if test="et instanceof java.util.Map"><if test="et.MP_OPTLOCK_VERSION_ORIGINAL!=null">and ${et.MP_OPTLOCK_VERSION_COLUMN}=#{et.MP_OPTLOCK_VERSION_ORIGINAL}</if></if>
    </update>


    <update id="updateAllColumnById">
        UPDATE Z_NWA_USER <trim prefix="SET" suffixOverrides=",">
        USER_NAME=#{et.userName},
        FIRST_NAME=#{et.firstName},
        LAST_NAME=#{et.lastName},
        FULL_NAME=#{et.fullName},
        PASSWORD=#{et.password},
        SALT=#{et.salt},
        PHONE=#{et.phone},
        AVATAR=#{et.avatar},
        DEPT_ID=#{et.deptId},
        CREATE_TIME=#{et.createTime},
        UPDATE_TIME=#{et.updateTime},
        LOCK_FLAG=#{et.lockFlag},
        DEL_FLAG=#{et.delFlag},
        SITE=#{et.site},
        DEPT_DESC=#{et.deptDesc},
        VALID_FROM=#{et.validFrom},
        VALID_TO=#{et.validTo},
        JOB_TITLE=#{et.jobTitle},
        EMAIL=#{et.email},
     </trim> WHERE HANDLE=#{et.handle} <if test="et instanceof java.util.Map"><if test="et.MP_OPTLOCK_VERSION_ORIGINAL!=null">and ${et.MP_OPTLOCK_VERSION_COLUMN}=#{et.MP_OPTLOCK_VERSION_ORIGINAL}</if></if>
    </update>


    <update id="update">
        UPDATE Z_NWA_USER <trim prefix="SET" suffixOverrides=",">
        <if test="et.userName!=null">USER_NAME=#{et.userName},</if>
        <if test="et.firstName!=null">FIRST_NAME=#{et.firstName},</if>
        <if test="et.lastName!=null">LAST_NAME=#{et.lastName},</if>
        <if test="et.fullName!=null">FULL_NAME=#{et.fullName},</if>
        <if test="et.password!=null">PASSWORD=#{et.password},</if>
        <if test="et.salt!=null">SALT=#{et.salt},</if>
        <if test="et.phone!=null">PHONE=#{et.phone},</if>
        <if test="et.avatar!=null">AVATAR=#{et.avatar},</if>
        <if test="et.deptId!=null">DEPT_ID=#{et.deptId},</if>
        <if test="et.createTime!=null">CREATE_TIME=#{et.createTime},</if>
        <if test="et.updateTime!=null">UPDATE_TIME=#{et.updateTime},</if>
        <if test="et.lockFlag!=null">LOCK_FLAG=#{et.lockFlag},</if>
        <if test="et.delFlag!=null">DEL_FLAG=#{et.delFlag},</if>
        <if test="et.site!=null">SITE=#{et.site},</if>
        <if test="et.deptDesc!=null">DEPT_DESC=#{et.deptDesc},</if>
        <if test="et.validFrom!=null">VALID_FROM=#{et.validFrom},</if>
        <if test="et.validTo!=null">VALID_TO=#{et.validTo},</if>
        <if test="et.jobTitle!=null">JOB_TITLE=#{et.jobTitle},</if>
        <if test="et.email!=null">EMAIL=#{et.email},</if>
    </trim>
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    HANDLE=#{ew.entity.handle}
                    <if test="ew.entity.userName!=null"> AND USER_NAME=#{ew.entity.userName}</if>
                    <if test="ew.entity.firstName!=null"> AND FIRST_NAME=#{ew.entity.firstName}</if>
                    <if test="ew.entity.lastName!=null"> AND LAST_NAME=#{ew.entity.lastName}</if>
                    <if test="ew.entity.fullName!=null"> AND FULL_NAME=#{ew.entity.fullName}</if>
                    <if test="ew.entity.password!=null"> AND PASSWORD=#{ew.entity.password}</if>
                    <if test="ew.entity.salt!=null"> AND SALT=#{ew.entity.salt}</if>
                    <if test="ew.entity.phone!=null"> AND PHONE=#{ew.entity.phone}</if>
                    <if test="ew.entity.avatar!=null"> AND AVATAR=#{ew.entity.avatar}</if>
                    <if test="ew.entity.deptId!=null"> AND DEPT_ID=#{ew.entity.deptId}</if>
                    <if test="ew.entity.createTime!=null"> AND CREATE_TIME=#{ew.entity.createTime}</if>
                    <if test="ew.entity.updateTime!=null"> AND UPDATE_TIME=#{ew.entity.updateTime}</if>
                    <if test="ew.entity.lockFlag!=null"> AND LOCK_FLAG=#{ew.entity.lockFlag}</if>
                    <if test="ew.entity.delFlag!=null"> AND DEL_FLAG=#{ew.entity.delFlag}</if>
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.deptDesc!=null"> AND DEPT_DESC=#{ew.entity.deptDesc}</if>
                    <if test="ew.entity.validFrom!=null"> AND VALID_FROM=#{ew.entity.validFrom}</if>
                    <if test="ew.entity.validTo!=null"> AND VALID_TO=#{ew.entity.validTo}</if>
                    <if test="ew.entity.jobTitle!=null"> AND JOB_TITLE=#{ew.entity.jobTitle}</if>
                    <if test="ew.entity.email!=null"> AND EMAIL=#{ew.entity.email}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </update>

    <delete id="deleteById">
        DELETE FROM Z_NWA_USER WHERE HANDLE=#{handle}
    </delete>

    <delete id="deleteByMap">
        DELETE FROM Z_NWA_USER
        <if test="cm!=null and !cm.isEmpty">
            <where>
                <foreach collection="cm.keys" item="k" separator="AND">
                    <if test="cm[k] != null">
                        ${k} = #{cm[${k}]}
                    </if>
                </foreach>
            </where>
        </if>
    </delete>

    <delete id="delete">
        DELETE FROM Z_NWA_USER
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.userName!=null"> AND USER_NAME=#{ew.entity.userName}</if>
                    <if test="ew.entity.firstName!=null"> AND FIRST_NAME=#{ew.entity.firstName}</if>
                    <if test="ew.entity.lastName!=null"> AND LAST_NAME=#{ew.entity.lastName}</if>
                    <if test="ew.entity.fullName!=null"> AND FULL_NAME=#{ew.entity.fullName}</if>
                    <if test="ew.entity.password!=null"> AND PASSWORD=#{ew.entity.password}</if>
                    <if test="ew.entity.salt!=null"> AND SALT=#{ew.entity.salt}</if>
                    <if test="ew.entity.phone!=null"> AND PHONE=#{ew.entity.phone}</if>
                    <if test="ew.entity.avatar!=null"> AND AVATAR=#{ew.entity.avatar}</if>
                    <if test="ew.entity.deptId!=null"> AND DEPT_ID=#{ew.entity.deptId}</if>
                    <if test="ew.entity.createTime!=null"> AND CREATE_TIME=#{ew.entity.createTime}</if>
                    <if test="ew.entity.updateTime!=null"> AND UPDATE_TIME=#{ew.entity.updateTime}</if>
                    <if test="ew.entity.lockFlag!=null"> AND LOCK_FLAG=#{ew.entity.lockFlag}</if>
                    <if test="ew.entity.delFlag!=null"> AND DEL_FLAG=#{ew.entity.delFlag}</if>
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.deptDesc!=null"> AND DEPT_DESC=#{ew.entity.deptDesc}</if>
                    <if test="ew.entity.validFrom!=null"> AND VALID_FROM=#{ew.entity.validFrom}</if>
                    <if test="ew.entity.validTo!=null"> AND VALID_TO=#{ew.entity.validTo}</if>
                    <if test="ew.entity.jobTitle!=null"> AND JOB_TITLE=#{ew.entity.jobTitle}</if>
                    <if test="ew.entity.email!=null"> AND EMAIL=#{ew.entity.email}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </delete>

    <delete id="deleteBatchIds">
        DELETE FROM Z_NWA_USER WHERE HANDLE IN (
        <foreach item="item" index="index" collection="coll" separator=",">#{item}
        </foreach>)
    </delete>
    <!-- BaseMapper标准查询/修改/删除 -->
    <select id="selectAllByUserGroups" resultMap="BaseResultMap">
        SELECT ZNU.USER_NAME USER_NAME,ZNU.FULL_NAME FULL_NAME
        FROM USER_GROUP UG
        INNER JOIN USER_GROUP_MEMBER UGM ON UG.HANDLE = UGM.USER_GROUP_BO
        INNER JOIN USR ON UGM.USER_OR_GROUP_GBO  = USR.HANDLE
        INNER JOIN Z_NWA_USER ZNU ON ZNU.USER_NAME  = USR.USER_ID
        WHERE UG.SITE = #{site}
        <if test="list != null and list.size > 0">
            AND UG.USER_GROUP IN (
                <foreach collection="list" index="index" separator="," item="item">
                    UPPER(#{item})
                </foreach>
            )
        </if>
    </select>
    <select id="checkUser" resultType="integer">
        SELECT COUNT(*)
        FROM Z_NWA_USER
        WHERE SITE = #{site}
        <if test="list != null and !list.isEmpty">
            AND USER_NAME IN (
            <foreach item="item" index="index" collection="list" separator=",">UPPER(#{item})
            </foreach>)
        </if>
    </select>
    
    <select id="getFullNameCommaByUserNameList" resultType="java.lang.String">
        SELECT LISTAGG(ZNU.FULL_NAME ,',') WITHIN GROUP (ORDER BY ZNU.SITE) AS STR
        FROM Z_NWA_USER ZNU
        WHERE ZNU.SITE = #{site}
        <if test="list != null and !list.isEmpty">
            AND ZNU.USER_NAME IN (
            <foreach item="item" index="index" collection="list" separator=",">
             UPPER(#{item})
            </foreach>)
        </if>
        GROUP BY ZNU.SITE
    </select>
    
</mapper>
