<?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.izouma.awesomeadmin.dao.UserInfoMapper">
    <resultMap id="BaseResultMap" type="com.izouma.awesomeadmin.model.UserInfo">
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="username" property="username" jdbcType="VARCHAR"/>
        <result column="nickname" property="nickname" jdbcType="VARCHAR"/>
        <result column="password" property="password" jdbcType="VARCHAR"/>
        <result column="icon" property="icon" jdbcType="VARCHAR"/>
        <result column="birthday" property="birthday" jdbcType="TIMESTAMP"/>
        <result column="sex" property="sex" jdbcType="CHAR"/>
        <result column="open_id" property="openId" jdbcType="VARCHAR"/>
        <result column="union_id" property="unionId" jdbcType="VARCHAR"/>
        <result column="phone" property="phone" jdbcType="VARCHAR"/>
        <result column="mail" property="mail" jdbcType="VARCHAR"/>
        <result column="country" property="country" jdbcType="VARCHAR"/>
        <result column="province" property="province" jdbcType="VARCHAR"/>
        <result column="city" property="city" jdbcType="VARCHAR"/>
        <result column="district" property="district" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="del_flag" property="delFlag" jdbcType="CHAR"/>
        <result column="money_coin" property="moneyCoin" jdbcType="DECIMAL"/>
        <result column="money_point" property="moneyPoint" jdbcType="DECIMAL"/>
        <result column="contacter" property="contacter" jdbcType="VARCHAR"/>
        <result column="contact_phone" property="contactPhone" jdbcType="VARCHAR"/>
        <result column="company_name" property="companyName" jdbcType="VARCHAR"/>
        <result column="company_type" property="companyType" jdbcType="VARCHAR"/>
        <result column="admin_flag" property="adminFlag" jdbcType="CHAR"/>
        <result column="cash_pledge" property="cashPledge" jdbcType="INTEGER"/>
        <result column="approve_flag" property="approveFlag" jdbcType="CHAR"/>
        <result column="store_flag" property="storeFlag" jdbcType="CHAR"/>
        <result column="company_flag" property="companyFlag" jdbcType="CHAR"/>
        <result column="approve_step" property="approveStep" jdbcType="INTEGER"/>
        <association property="departId" javaType="string" column="id"
                     select="com.izouma.awesomeadmin.dao.DepartInfoMapper.getUserDepartId"/>
        <association property="roleId" javaType="string" column="id"
                     select="com.izouma.awesomeadmin.dao.SysRoleMapper.getUserRoleId"/>
        <association property="storeInfo" javaType="com.izouma.awesomeadmin.model.StoreInfo" column="{userId=id}"
                     select="com.izouma.awesomeadmin.dao.StoreInfoMapper.queryStoreInfo"/>
    </resultMap>
    <sql id="Base_Column_List">
        id, username, nickname, icon, birthday, sex, open_id, union_id, phone, mail,
        country, province, city, district, create_time, del_flag, money_coin, money_point,
        contacter, contact_phone, company_name, company_type, admin_flag, cash_pledge,
        approve_flag, store_flag, company_flag, approve_step
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
        select
        <include refid="Base_Column_List"/>
        from sys_user
        where id = #{id,jdbcType=INTEGER}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        delete
        from sys_user
        where id = #{id,jdbcType=INTEGER}
    </delete>
    <insert id="insertSelective" parameterType="com.izouma.awesomeadmin.model.UserInfo" useGeneratedKeys="true"
            keyProperty="id">
        insert into sys_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="username != null">
                username,
            </if>
            <if test="nickname != null">
                nickname,
            </if>
            <if test="password != null">
                password,
            </if>
            <if test="icon != null">
                icon,
            </if>
            <if test="birthday != null">
                birthday,
            </if>
            <if test="sex != null">
                sex,
            </if>
            <if test="openId != null">
                open_id,
            </if>
            <if test="unionId != null">
                union_id,
            </if>
            <if test="phone != null">
                phone,
            </if>
            <if test="mail != null">
                mail,
            </if>
            <if test="country != null">
                country,
            </if>
            <if test="province != null">
                province,
            </if>
            <if test="city != null">
                city,
            </if>
            <if test="district != null">
                district,
            </if>
            <if test="roleId != null">
                role_id,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="delFlag != null">
                del_flag,
            </if>
            <if test="moneyCoin != null">
                money_coin,
            </if>
            <if test="moneyPoint != null">
                money_point,
            </if>
            <if test="contacter != null">
                contacter,
            </if>
            <if test="contactPhone != null">
                contact_phone,
            </if>
            <if test="companyName != null">
                company_name,
            </if>
            <if test="companyType != null">
                company_type,
            </if>
            <if test="adminFlag != null">
                admin_flag,
            </if>
            <if test="cashPledge != null">
                cash_pledge,
            </if>
            <if test="approveFlag != null">
                approve_flag,
            </if>
            <if test="storeFlag != null">
                store_flag,
            </if>
            <if test="companyFlag != null">
                company_flag,
            </if>
            <if test="approveStep != null">
                approve_step,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="username != null">
                #{username,jdbcType=VARCHAR},
            </if>
            <if test="nickname != null">
                #{nickname,jdbcType=VARCHAR},
            </if>
            <if test="password != null">
                #{password,jdbcType=VARCHAR},
            </if>
            <if test="icon != null">
                #{icon,jdbcType=VARCHAR},
            </if>
            <if test="birthday != null">
                #{birthday,jdbcType=TIMESTAMP},
            </if>
            <if test="sex != null">
                #{sex,jdbcType=CHAR},
            </if>
            <if test="openId != null">
                #{openId,jdbcType=VARCHAR},
            </if>
            <if test="unionId != null">
                #{unionId,jdbcType=VARCHAR},
            </if>
            <if test="phone != null">
                #{phone,jdbcType=VARCHAR},
            </if>
            <if test="mail != null">
                #{mail,jdbcType=VARCHAR},
            </if>
            <if test="country != null">
                #{country,jdbcType=VARCHAR},
            </if>
            <if test="province != null">
                #{province,jdbcType=VARCHAR},
            </if>
            <if test="city != null">
                #{city,jdbcType=VARCHAR},
            </if>
            <if test="district != null">
                #{district,jdbcType=VARCHAR},
            </if>
            <if test="roleId != null">
                #{roleId,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="delFlag != null">
                #{delFlag,jdbcType=CHAR},
            </if>
            <if test="moneyCoin != null">
                #{moneyCoin},
            </if>
            <if test="moneyPoint != null">
                #{moneyPoint},
            </if>
            <if test="contacter != null">
                #{contacter},
            </if>
            <if test="contactPhone != null">
                #{contactPhone},
            </if>
            <if test="companyName != null">
                #{companyName},
            </if>
            <if test="companyType != null">
                #{companyType},
            </if>
            <if test="adminFlag != null">
                #{adminFlag},
            </if>
            <if test="cashPledge != null">
                #{cashPledge},
            </if>
            <if test="approveFlag != null">
                #{approveFlag},
            </if>
            <if test="storeFlag != null">
                #{storeFlag},
            </if>
            <if test="companyFlag != null">
                #{companyFlag},
            </if>
            <if test="approveStep != null">
                #{approveStep},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.izouma.awesomeadmin.model.UserInfo">
        update sys_user
        <set>
            <if test="username != null">
                username = #{username,jdbcType=VARCHAR},
            </if>
            <if test="nickname != null">
                nickname = #{nickname,jdbcType=VARCHAR},
            </if>
            <if test="password != null">
                password = #{password,jdbcType=VARCHAR},
            </if>
            <if test="icon != null">
                icon = #{icon,jdbcType=VARCHAR},
            </if>
            <if test="birthday != null">
                birthday = #{birthday,jdbcType=TIMESTAMP},
            </if>
            <if test="sex != null">
                sex = #{sex,jdbcType=CHAR},
            </if>
            <if test="openId != null">
                open_id = #{openId,jdbcType=VARCHAR},
            </if>
            <if test="unionId != null">
                union_id = #{unionId,jdbcType=VARCHAR},
            </if>
            <if test="phone != null">
                phone = #{phone,jdbcType=VARCHAR},
            </if>
            <if test="mail != null">
                mail = #{mail,jdbcType=VARCHAR},
            </if>
            <if test="country != null">
                country = #{country,jdbcType=VARCHAR},
            </if>
            <if test="province != null">
                province = #{province,jdbcType=VARCHAR},
            </if>
            <if test="city != null">
                city = #{city,jdbcType=VARCHAR},
            </if>
            <if test="district != null">
                district = #{district,jdbcType=VARCHAR},
            </if>
            <if test="roleId != null">
                role_id = #{roleId,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="delFlag != null">
                del_flag = #{delFlag,jdbcType=CHAR},
            </if>
            <if test="moneyCoin != null">
                money_coin = #{moneyCoin},
            </if>
            <if test="moneyPoint != null">
                money_point = #{moneyPoint},
            </if>
            <if test="contacter != null">
                contacter = #{contacter},
            </if>
            <if test="contactPhone != null">
                contact_phone = #{contactPhone},
            </if>
            <if test="companyName != null">
                company_name = #{companyName},
            </if>
            <if test="companyType != null">
                company_type = #{companyType},
            </if>
            <if test="adminFlag != null">
                admin_flag = #{adminFlag},
            </if>
            <if test="cashPledge != null">
                cash_pledge = #{cashPledge},
            </if>
            <if test="approveFlag != null">
                approve_flag = #{approveFlag},
            </if>
            <if test="storeFlag != null">
                store_flag = #{storeFlag},
            </if>
            <if test="companyFlag != null">
                company_flag = #{companyFlag},
            </if>
            <if test="approveStep != null">
                approve_step = #{approveStep},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <select id="queryUserInfosByPage" parameterType="java.util.Map"
            resultType="com.izouma.awesomeadmin.model.UserInfo">
        select
        <include refid="Base_Column_List"/>
        from sys_user
        <where>
            and del_flag = 'N'
            <if test="record.id != null and !&quot;&quot;.equals(record.id)">
                and id = #{record.id}
            </if>
            <if test="record.username != null and !&quot;&quot;.equals(record.username)">
                and username = #{record.username}
            </if>
            <if test="record.nickname != null and !&quot;&quot;.equals(record.nickname)">
                and nickname = #{record.nickname}
            </if>
            <if test="record.password != null and !&quot;&quot;.equals(record.password)">
                and password = #{record.password}
            </if>
            <if test="record.icon != null and !&quot;&quot;.equals(record.icon)">
                and icon = #{record.icon}
            </if>
            <if test="record.birthday != null and !&quot;&quot;.equals(record.birthday)">
                and birthday = #{record.birthday}
            </if>
            <if test="record.sex != null and !&quot;&quot;.equals(record.sex)">
                and sex = #{record.sex}
            </if>
            <if test="record.openId != null and !&quot;&quot;.equals(record.openId)">
                and open_id = #{record.openId}
            </if>
            <if test="record.unionId != null and !&quot;&quot;.equals(record.unionId)">
                and union_id = #{record.unionId}
            </if>
            <if test="record.phone != null and !&quot;&quot;.equals(record.phone)">
                and phone = #{record.phone}
            </if>
            <if test="record.mail != null and !&quot;&quot;.equals(record.mail)">
                and mail = #{record.mail}
            </if>
            <if test="record.country != null and !&quot;&quot;.equals(record.country)">
                and country = #{record.country}
            </if>
            <if test="record.province != null and !&quot;&quot;.equals(record.province)">
                and province = #{record.province}
            </if>
            <if test="record.city != null and !&quot;&quot;.equals(record.city)">
                and city = #{record.city}
            </if>
            <if test="record.district != null and !&quot;&quot;.equals(record.district)">
                and district = #{record.district}
            </if>
            <if test="record.roleId != null and !&quot;&quot;.equals(record.roleId)">
                and role_id = #{record.roleId}
            </if>
            <if test="record.createTime != null and !&quot;&quot;.equals(record.createTime)">
                and create_time = #{record.createTime}
            </if>
            <if test="record.delFlag != null and !&quot;&quot;.equals(record.delFlag)">
                and del_flag = #{record.delFlag}
            </if>
            <if test="record.contacter != null and !&quot;&quot;.equals(record.contacter)">
                and contacter = #{record.contacter}
            </if>
            <if test="record.contactPhone != null and !&quot;&quot;.equals(record.contactPhone)">
                and contact_phone = #{record.contactPhone}
            </if>
            <if test="record.companyName != null and !&quot;&quot;.equals(record.companyName)">
                and company_name = #{record.companyName}
            </if>
            <if test="record.companyType != null and !&quot;&quot;.equals(record.companyType)">
                and company_type = #{record.companyType}
            </if>
            <if test="record.adminFlag != null and !&quot;&quot;.equals(record.adminFlag)">
                and admin_flag = #{record.adminFlag}
            </if>
            <if test="record.cashPledge != null and !&quot;&quot;.equals(record.cashPledge)">
                and cash_pledge = #{record.cashPledge}
            </if>
            <if test="record.approveFlag != null and !&quot;&quot;.equals(record.approveFlag)">
                and approve_flag = #{record.approveFlag}
            </if>
            <if test="record.storeFlag != null and !&quot;&quot;.equals(record.storeFlag)">
                and store_flag = #{record.storeFlag}
            </if>
            <if test="record.companyFlag != null and !&quot;&quot;.equals(record.companyFlag)">
                and company_flag = #{record.companyFlag}
            </if>
            <if test="record.approveStep != null and !&quot;&quot;.equals(record.approveStep)">
                and approve_step = #{record.approveStep}
            </if>

        </where>
        order by id desc
    </select>
    <select id="queryAllUserInfo" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.UserInfo">
        select
        <include refid="Base_Column_List"/>
        from sys_user
        <where>
            and del_flag = 'N'
            <if test="id != null and !&quot;&quot;.equals(id)">
                and id = #{id}
            </if>
            <if test="username != null and !&quot;&quot;.equals(username)">
                and username = #{username}
            </if>
            <if test="nickname != null and !&quot;&quot;.equals(nickname)">
                and nickname = #{nickname}
            </if>
            <if test="password != null and !&quot;&quot;.equals(password)">
                and password = #{password}
            </if>
            <if test="icon != null and !&quot;&quot;.equals(icon)">
                and icon = #{icon}
            </if>
            <if test="birthday != null and !&quot;&quot;.equals(birthday)">
                and birthday = #{birthday}
            </if>
            <if test="sex != null and !&quot;&quot;.equals(sex)">
                and sex = #{sex}
            </if>
            <if test="openId != null and !&quot;&quot;.equals(openId)">
                and open_id = #{openId}
            </if>
            <if test="unionId != null and !&quot;&quot;.equals(unionId)">
                and union_id = #{unionId}
            </if>
            <if test="phone != null and !&quot;&quot;.equals(phone)">
                and phone = #{phone}
            </if>
            <if test="mail != null and !&quot;&quot;.equals(mail)">
                and mail = #{mail}
            </if>
            <if test="country != null and !&quot;&quot;.equals(country)">
                and country = #{country}
            </if>
            <if test="province != null and !&quot;&quot;.equals(province)">
                and province = #{province}
            </if>
            <if test="city != null and !&quot;&quot;.equals(city)">
                and city = #{city}
            </if>
            <if test="district != null and !&quot;&quot;.equals(district)">
                and district = #{district}
            </if>
            <if test="roleId != null and !&quot;&quot;.equals(roleId)">
                and role_id = #{roleId}
            </if>
            <if test="createTime != null and !&quot;&quot;.equals(createTime)">
                and create_time = #{createTime}
            </if>
            <if test="delFlag != null and !&quot;&quot;.equals(delFlag)">
                and del_flag = #{delFlag}
            </if>

            <if test="contacter != null and !&quot;&quot;.equals(contacter)">
                and contacter = #{contacter}
            </if>
            <if test="contactPhone != null and !&quot;&quot;.equals(contactPhone)">
                and contact_phone = #{contactPhone}
            </if>
            <if test="companyName != null and !&quot;&quot;.equals(companyName)">
                and company_name = #{companyName}
            </if>
            <if test="companyType != null and !&quot;&quot;.equals(companyType)">
                and company_type = #{companyType}
            </if>
            <if test="adminFlag != null and !&quot;&quot;.equals(adminFlag)">
                and admin_flag = #{adminFlag}
            </if>
            <if test="cashPledge != null and !&quot;&quot;.equals(cashPledge)">
                and cash_pledge = #{cashPledge}
            </if>
            <if test="approveFlag != null and !&quot;&quot;.equals(approveFlag)">
                and approve_flag = #{approveFlag}
            </if>
            <if test="storeFlag != null and !&quot;&quot;.equals(storeFlag)">
                and store_flag = #{storeFlag}
            </if>
            <if test="companyFlag != null and !&quot;&quot;.equals(companyFlag)">
                and company_flag = #{companyFlag}
            </if>
            <if test="approveStep != null and !&quot;&quot;.equals(approveStep)">
                and approve_step = #{approveStep}
            </if>

        </where>
        order by id desc
    </select>
    <select id="queryUserInfo" parameterType="java.util.Map" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from sys_user
        <where>
            and del_flag = 'N'
            <if test="id != null and !&quot;&quot;.equals(id)">
                and id = #{id}
            </if>
            <if test="username != null and !&quot;&quot;.equals(username)">
                and username = #{username}
            </if>
            <if test="nickname != null and !&quot;&quot;.equals(nickname)">
                and nickname = #{nickname}
            </if>
            <if test="password != null and !&quot;&quot;.equals(password)">
                and password = #{password}
            </if>
            <if test="icon != null and !&quot;&quot;.equals(icon)">
                and icon = #{icon}
            </if>
            <if test="birthday != null and !&quot;&quot;.equals(birthday)">
                and birthday = #{birthday}
            </if>
            <if test="sex != null and !&quot;&quot;.equals(sex)">
                and sex = #{sex}
            </if>
            <if test="openId != null and !&quot;&quot;.equals(openId)">
                and open_id = #{openId}
            </if>
            <if test="unionId != null and !&quot;&quot;.equals(unionId)">
                and union_id = #{unionId}
            </if>
            <if test="phone != null and !&quot;&quot;.equals(phone)">
                and phone = #{phone}
            </if>
            <if test="mail != null and !&quot;&quot;.equals(mail)">
                and mail = #{mail}
            </if>
            <if test="country != null and !&quot;&quot;.equals(country)">
                and country = #{country}
            </if>
            <if test="province != null and !&quot;&quot;.equals(province)">
                and province = #{province}
            </if>
            <if test="city != null and !&quot;&quot;.equals(city)">
                and city = #{city}
            </if>
            <if test="district != null and !&quot;&quot;.equals(district)">
                and district = #{district}
            </if>
            <if test="roleId != null and !&quot;&quot;.equals(roleId)">
                and role_id = #{roleId}
            </if>
            <if test="createTime != null and !&quot;&quot;.equals(createTime)">
                and create_time = #{createTime}
            </if>
            <if test="delFlag != null and !&quot;&quot;.equals(delFlag)">
                and del_flag = #{delFlag}
            </if>
        </where>
        LIMIT 1
    </select>
    <select id="querySingleUserInfo" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.UserInfo">
        select
        <include refid="Base_Column_List"/>
        from sys_user
        <where>
            and del_flag = 'N'
            <if test="id != null and !&quot;&quot;.equals(id)">
                and id = #{id}
            </if>
            <if test="username != null and !&quot;&quot;.equals(username)">
                and username = #{username}
            </if>
            <if test="nickname != null and !&quot;&quot;.equals(nickname)">
                and nickname = #{nickname}
            </if>
            <if test="password != null and !&quot;&quot;.equals(password)">
                and password = #{password}
            </if>
            <if test="icon != null and !&quot;&quot;.equals(icon)">
                and icon = #{icon}
            </if>
            <if test="birthday != null and !&quot;&quot;.equals(birthday)">
                and birthday = #{birthday}
            </if>
            <if test="sex != null and !&quot;&quot;.equals(sex)">
                and sex = #{sex}
            </if>
            <if test="openId != null and !&quot;&quot;.equals(openId)">
                and open_id = #{openId}
            </if>
            <if test="unionId != null and !&quot;&quot;.equals(unionId)">
                and union_id = #{unionId}
            </if>
            <if test="phone != null and !&quot;&quot;.equals(phone)">
                and phone = #{phone}
            </if>
            <if test="mail != null and !&quot;&quot;.equals(mail)">
                and mail = #{mail}
            </if>
            <if test="country != null and !&quot;&quot;.equals(country)">
                and country = #{country}
            </if>
            <if test="province != null and !&quot;&quot;.equals(province)">
                and province = #{province}
            </if>
            <if test="city != null and !&quot;&quot;.equals(city)">
                and city = #{city}
            </if>
            <if test="district != null and !&quot;&quot;.equals(district)">
                and district = #{district}
            </if>
            <if test="roleId != null and !&quot;&quot;.equals(roleId)">
                and role_id = #{roleId}
            </if>
            <if test="createTime != null and !&quot;&quot;.equals(createTime)">
                and create_time = #{createTime}
            </if>
            <if test="delFlag != null and !&quot;&quot;.equals(delFlag)">
                and del_flag = #{delFlag}
            </if>
        </where>
        LIMIT 1
    </select>
    <select id="login" resultMap="BaseResultMap" parameterType="java.util.Map">
        SELECT
        <include refid="Base_Column_List"/>
        from sys_user
        WHERE (username = #{username} or phone = #{username} or mail = #{username}) AND password = #{password} AND del_flag = 'N'
    </select>
    <select id="findDepartLeader" resultType="java.lang.String">
        SELECT *
        FROM (SELECT user_id, GROUP_CONCAT(depart_id ORDER BY depart_id) AS depart_id
              FROM sys_user_depart
              GROUP BY user_id) AS tmp
                 LEFT JOIN sys_user_role ON tmp.user_id = sys_user_role.user_id
        WHERE tmp.depart_id =
              (SELECT GROUP_CONCAT(depart_id ORDER BY depart_id) FROM sys_user_depart WHERE user_id = #{userId})
          AND role_id = 9
    </select>
    <select id="findUserByRoleName" resultType="java.lang.String">
        SELECT user_id
        FROM sys_user_role
        WHERE FIND_IN_SET((SELECT id FROM sys_role WHERE enname = #{roleName}
                                                     AND sys_role.del_flag = 'N'), role_id)
    </select>
    <update id="delete">
        UPDATE sys_user SET del_flag = 'Y'
        <where>
            AND id = #{id}
        </where>
    </update>

    <update id="updatePassword" parameterType="com.izouma.awesomeadmin.model.UserInfo">
        update sys_user
        <set>
            <if test="password != null">
                password = #{password,jdbcType=VARCHAR},
            </if>
        </set>
        <where>
            and del_flag = 'N'
            <if test="id != null and !&quot;&quot;.equals(id)">
                and id = #{id}
            </if>
            <if test="username != null and !&quot;&quot;.equals(username)">
                and username = #{username}
            </if>
            <if test="phone != null and !&quot;&quot;.equals(phone)">
                and phone = #{phone}
            </if>
            <if test="mail != null and !&quot;&quot;.equals(mail)">
                and mail = #{mail}
            </if>
        </where>

    </update>

</mapper>

