<?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.securitycontrol.system.mapper.LoginMapper">
    <update id="updateUserLogin">
        update sys_user set
        login_ip=#{ip},login_time=now() where user_id=#{userId}

    </update>

    <!--查询用户角色-->
    <select id="selectUserByUserName" parameterType="String" resultType="com.securitycontrol.system.api.domain.SysUser">
        select user_id userId,user_name userName,login_name nickName,
        `password`,su.org_id AS orgId,dept_name deptName,org_name orgName,is_admin AS isAdmin,sr.role_id AS roleId,
        su.user_type AS userType,su.login_type AS loginType,status,
        sr.role_name roleName,phone,su.login_ip loginIp,su.login_name login_time,
        sr.role_code AS roleCode
        FROM sys_user su
        LEFT JOIN sys_role sr ON su.role_id = sr.role_id
        where su.del_flag=0 AND su.login_name=#{username}
    </select>
    <!--查询用户已分配的权限-->
    <select id="getMenuPermission" parameterType="com.securitycontrol.system.api.domain.SysUser" resultType="String">
        select DISTINCT sm.menu_auth
        FROM sys_user su
        left join sys_role_menu srm on srm .role_id=su.role_id
        left join sys_menu sm on sm.menu_id=srm.menu_id and sm.menu_type=2 AND sm.del_flag=0
        where su.user_id=#{userId}
    </select>
    <select id="getAllMenuList" resultType="com.securitycontrol.system.api.domain.decision.SysMenu">
        select sm.menu_url url,sm.menu_id menuId,sm.menu_name menuName,sm.menu_logo AS icon,sm.menu_auth AS menuAuth
        FROM sys_user su
        left join sys_role_menu srm on srm .role_id=su.role_id
        left join sys_menu sm on sm.menu_id=srm.menu_id and sm.del_flag=0 and (sm.menu_type=0 or sm.menu_type=1)
        where su.user_id=#{userId} and sm.p_id=#{pid}
        ORDER BY sm.menu_sort ASC

    </select>
    <!--获取用户绑定的标段工程 1.管理员 2.项目经理 3.地市值班员-->
    <select id="getUserBandingBidPro" resultType="com.securitycontrol.system.api.model.BidProVo">
        <if test="type == 1">
            SELECT tp.bid_code AS bidCode,
            tp.pro_name AS proName
            FROM tb_project tp
            WHERE del_flag = 0
            ORDER BY plan_start_time
        </if>
        <if test="type == 2">
            SELECT tup.bid_cod AS bidCode,
            tp.pro_name AS proName
            FROM tb_user_pro tup
            LEFT JOIN tb_project tp on tup.bid_cod = tp.bid_code AND tp.del_flag = 0
            WHERE tup.user_id = #{param} AND tup.del_flag = '0'
            ORDER BY tup.times
        </if>
        <if test="type == 3">
            SELECT tp.bid_code AS bidCode,
                   tp.pro_name AS proName
            FROM tb_project tp
            WHERE tp.org = #{param} AND tp.del_flag = 0
            ORDER BY plan_start_time
        </if>
    </select>
</mapper>