<?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.aiotagro.cattletrade.business.mapper.SysUserMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.aiotagro.cattletrade.business.entity.SysUser">
        <id column="id" property="id" />
        <result column="name" property="name" />
        <result column="mobile" property="mobile" />
        <result column="role_id" property="roleId" />
        <result column="password" property="password" />
        <result column="status" property="status" />
        <result column="create_time" property="createTime" />
        <result column="create_by" property="createBy" />
        <result column="update_time" property="updateTime" />
        <result column="update_by" property="updateBy" />
        <result column="last_login_time" property="lastLoginTime" />
        <result column="is_delete" property="isDelete" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, name, mobile, role_id, password, status, type, company_name, conpany_id, create_time, create_by, update_time, update_by, last_login_time, is_delete
    </sql>

    <select id="queryList" resultType="com.aiotagro.cattletrade.business.entity.SysUser">
        SELECT u.id, u.`name`, u.`status`, u.mobile,
               u.create_time, r.`name` as roleName,
               r.id as roleId
        FROM sys_user u
                 LEFT JOIN sys_role r ON u.role_id = r.id
        WHERE u.is_delete = 0
        <if test="item.name != null and item.name != ''">
            and u.name like concat ('%', #{item.name}, '%')
        </if>
        order by u.id desc
    </select>

    <select id="getUserInfoById" resultType="com.aiotagro.cattletrade.business.entity.SysUser">
        SELECT u.id, u.name, u.mobile, r.`name` AS roleName
        FROM sys_user u
                 LEFT JOIN sys_role r ON u.role_id = r.id
        WHERE u.id = #{id}
    </select>

    <select id="selectUserListForPermission" resultType="com.aiotagro.cattletrade.business.entity.SysUser">
        SELECT id, name, mobile, role_id, status
        FROM sys_user
        WHERE is_delete = 0
          AND status = 1
        ORDER BY id ASC
    </select>

</mapper>
