<?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.fuxi.ws.data.dao.WUserMapper">
  <resultMap id="BaseResultMap" type="com.fuxi.ws.data.entity.WUser">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 08 11:03:46 CST 2016.
    -->
    <id column="UserID" jdbcType="INTEGER" property="userid" />
    <result column="RoleID" jdbcType="INTEGER" property="roleid" />
    <result column="UserNo" jdbcType="VARCHAR" property="userno" />
    <result column="UserName" jdbcType="NVARCHAR" property="username" />
    <result column="PassWord" jdbcType="VARCHAR" property="password" />
    <result column="UserType" jdbcType="TINYINT" property="usertype" />
    <result column="ActiveFlag" jdbcType="BIT" property="activeflag" />
    <result column="DepartmentID" jdbcType="VARCHAR" property="departmentid" />
    <result column="BossID" jdbcType="INTEGER" property="bossid" />
    <result column="AllowDate" jdbcType="TIMESTAMP" property="allowdate" />
    <result column="SupplierID" jdbcType="INTEGER" property="supplierid" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 08 11:03:46 CST 2016.
    -->
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 08 11:03:46 CST 2016.
    -->
    UserID, RoleID, UserNo, UserName, PassWord, UserType, ActiveFlag, DepartmentID, BossID, 
    AllowDate, SupplierID
  </sql>
  <select id="selectByExample" parameterType="com.fuxi.ws.data.entity.WUserExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 08 11:03:46 CST 2016.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    'false' as QUERYID,
    <include refid="Base_Column_List" />
    from W_User
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 08 11:03:46 CST 2016.
    -->
    select 
    <include refid="Base_Column_List" />
    from W_User
    where UserID = #{userid,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 08 11:03:46 CST 2016.
    -->
    delete from W_User
    where UserID = #{userid,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.fuxi.ws.data.entity.WUser">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 08 11:03:46 CST 2016.
    -->
    insert into W_User (UserID, RoleID, UserNo, 
      UserName, PassWord, UserType, 
      ActiveFlag, DepartmentID, BossID, 
      AllowDate, SupplierID)
    values (#{userid,jdbcType=INTEGER}, #{roleid,jdbcType=INTEGER}, #{userno,jdbcType=VARCHAR}, 
      #{username,jdbcType=NVARCHAR}, #{password,jdbcType=VARCHAR}, #{usertype,jdbcType=TINYINT}, 
      #{activeflag,jdbcType=BIT}, #{departmentid,jdbcType=VARCHAR}, #{bossid,jdbcType=INTEGER}, 
      #{allowdate,jdbcType=TIMESTAMP}, #{supplierid,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.fuxi.ws.data.entity.WUser">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 08 11:03:46 CST 2016.
    -->
    insert into W_User
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="userid != null">
        UserID,
      </if>
      <if test="roleid != null">
        RoleID,
      </if>
      <if test="userno != null">
        UserNo,
      </if>
      <if test="username != null">
        UserName,
      </if>
      <if test="password != null">
        PassWord,
      </if>
      <if test="usertype != null">
        UserType,
      </if>
      <if test="activeflag != null">
        ActiveFlag,
      </if>
      <if test="departmentid != null">
        DepartmentID,
      </if>
      <if test="bossid != null">
        BossID,
      </if>
      <if test="allowdate != null">
        AllowDate,
      </if>
      <if test="supplierid != null">
        SupplierID,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="userid != null">
        #{userid,jdbcType=INTEGER},
      </if>
      <if test="roleid != null">
        #{roleid,jdbcType=INTEGER},
      </if>
      <if test="userno != null">
        #{userno,jdbcType=VARCHAR},
      </if>
      <if test="username != null">
        #{username,jdbcType=NVARCHAR},
      </if>
      <if test="password != null">
        #{password,jdbcType=VARCHAR},
      </if>
      <if test="usertype != null">
        #{usertype,jdbcType=TINYINT},
      </if>
      <if test="activeflag != null">
        #{activeflag,jdbcType=BIT},
      </if>
      <if test="departmentid != null">
        #{departmentid,jdbcType=VARCHAR},
      </if>
      <if test="bossid != null">
        #{bossid,jdbcType=INTEGER},
      </if>
      <if test="allowdate != null">
        #{allowdate,jdbcType=TIMESTAMP},
      </if>
      <if test="supplierid != null">
        #{supplierid,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.fuxi.ws.data.entity.WUserExample" resultType="java.lang.Integer">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 08 11:03:46 CST 2016.
    -->
    select count(*) from W_User
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByPrimaryKeySelective" parameterType="com.fuxi.ws.data.entity.WUser">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 08 11:03:46 CST 2016.
    -->
    update W_User
    <set>
      <if test="roleid != null">
        RoleID = #{roleid,jdbcType=INTEGER},
      </if>
      <if test="userno != null">
        UserNo = #{userno,jdbcType=VARCHAR},
      </if>
      <if test="username != null">
        UserName = #{username,jdbcType=NVARCHAR},
      </if>
      <if test="password != null">
        PassWord = #{password,jdbcType=VARCHAR},
      </if>
      <if test="usertype != null">
        UserType = #{usertype,jdbcType=TINYINT},
      </if>
      <if test="activeflag != null">
        ActiveFlag = #{activeflag,jdbcType=BIT},
      </if>
      <if test="departmentid != null">
        DepartmentID = #{departmentid,jdbcType=VARCHAR},
      </if>
      <if test="bossid != null">
        BossID = #{bossid,jdbcType=INTEGER},
      </if>
      <if test="allowdate != null">
        AllowDate = #{allowdate,jdbcType=TIMESTAMP},
      </if>
      <if test="supplierid != null">
        SupplierID = #{supplierid,jdbcType=INTEGER},
      </if>
    </set>
    where UserID = #{userid,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WUser">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 08 11:03:46 CST 2016.
    -->
    update W_User
    set RoleID = #{roleid,jdbcType=INTEGER},
      UserNo = #{userno,jdbcType=VARCHAR},
      UserName = #{username,jdbcType=NVARCHAR},
      PassWord = #{password,jdbcType=VARCHAR},
      UserType = #{usertype,jdbcType=TINYINT},
      ActiveFlag = #{activeflag,jdbcType=BIT},
      DepartmentID = #{departmentid,jdbcType=VARCHAR},
      BossID = #{bossid,jdbcType=INTEGER},
      AllowDate = #{allowdate,jdbcType=TIMESTAMP},
      SupplierID = #{supplierid,jdbcType=INTEGER}
    where UserID = #{userid,jdbcType=INTEGER}
  </update>
  
  <!-- 读取用户信息列表 -->
	<select id="wuserList" resultType="java.util.LinkedHashMap">
		SELECT a.UserID, a.RoleID, a.UserNo, a.UserName,a.ActiveFlag, b.RoleName,
			case a.UserType when 1 then '总部' when 2 then '门店' when 3 then '供应商' when 4 then '自定义' end as UserType,a.DepartmentID,c.Department
		FROM W_User AS a INNER JOIN
        W_Role AS b ON a.RoleID = b.RoleID left join
        Department c on c.DepartmentID=a.DepartmentID
		<if test="conditions != null and conditions != ''">
			where
			${conditions}
		</if>
	</select>
</mapper>