<?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.docus.server.archive.mapper.PowerUserMapper">
    <insert id="insertBatch">
        INSERT INTO docus_system.power_user (user_id, user_name, user_pwd, user_sex, user_age, user_tel, user_email,
                                             user_head, user_position, role_id, dept_id, effective, create_date,
                                             creater, update_date, updater, remark, login_flag, name, power_dept,
                                             power_attending, wx_bank, enabled, pwd_change, mnemonic_words, account_state,
                                             att_role_id, open_id, is_third)
         VALUES
            <foreach collection="userList" item="user" separator=",">
                (
                 #{user.userId},#{user.userName},#{user.userPwd},#{user.userSex},#{user.userAge},#{user.userTel},#{user.userEmail},
                 #{user.userHead},#{user.userPosition},#{user.roleId},#{user.deptId},#{user.effective},#{user.createDate},
                 #{user.creater},#{user.updateDate},#{user.updater},#{user.remark},#{user.loginFlag},#{user.name},#{user.powerDept},
                 #{user.powerAttending},#{user.wxBank},#{user.enabled},#{user.pwdChange},#{user.mnemonicWords},#{user.accountState},
                 #{user.attRoleId},#{user.openId},#{user.isThird}
                )
            </foreach>
    </insert>
    <update id="updateBatch">
        <foreach collection="userList" item="user" >
            UPDATE docus_system.power_user
            SET user_name=#{user.userName}, user_pwd=#{user.userPwd}, user_sex=#{user.userSex},
                user_age=#{user.userAge}, user_tel=#{user.userTel}, user_email=#{user.userEmail},
                user_head=#{user.userHead}, user_position=#{user.userPosition}, role_id=#{user.roleId},
                dept_id=#{user.deptId}, effective=#{user.effective}, create_date=#{user.createDate},
                creater=#{user.creater}, update_date=#{user.updateDate}, updater=#{user.updater}, remark=#{user.remark},
                login_flag=#{user.loginFlag}, name=#{user.name}, power_dept=#{user.powerDept} ,power_attending=#{user.powerAttending},
                wx_bank=#{user.wxBank},enabled=#{user.enabled}, pwd_change=#{user.pwdChange}, mnemonic_words=#{user.mnemonicWords},
                account_state=#{user.accountState}, att_role_id=#{user.attRoleId},
                open_id=#{user.openId}, is_third=#{user.isThird}
            WHERE user_id=#{user.userId};
        </foreach>

    </update>

    <select id="list" resultType="com.docus.server.archive.entity.PowerUser">
        SELECT
            user_name as    userName,
            name
        FROM `docus_system`.`power_user`
    </select>
    <select id="findByUserNames" resultType="com.docus.server.archive.entity.PowerUser">
        SELECT user_id, user_name, user_pwd, user_sex, user_age, user_tel,
               user_email, user_head, user_position,role_id, dept_id, effective,
               create_date, creater,update_date, updater, remark, login_flag, name,
               power_dept, power_attending, wx_bank, enabled, pwd_change, mnemonic_words,
               account_state, att_role_id, open_id, is_third
        FROM docus_system.power_user
        WHERE user_name in <foreach collection="userNames" item="userName" open="(" close=")" separator=",">
                                #{userName}
                            </foreach>
    </select>
</mapper>
