USERSMapper.xml 13.5 KB
<?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.tianbo.warehouse.dao.USERSMapper" >
  <resultMap id="BaseResultMap" type="com.tianbo.warehouse.model.USERS" >
    <id column="user_id" property="userId" jdbcType="INTEGER" />
    <result column="username" property="username" jdbcType="VARCHAR" />
    <result column="password" property="password" jdbcType="VARCHAR" />
    <result column="birthday" property="birthday" jdbcType="TIMESTAMP" />
    <result column="sex" property="sex" jdbcType="CHAR" />
    <result column="address" property="address" jdbcType="VARCHAR" />
    <result column="state" property="state" jdbcType="BIT" />
    <result column="mobilePhone" property="mobilephone" jdbcType="VARCHAR" />
    <result column="creatTime" property="creattime" jdbcType="TIMESTAMP" />
    <result column="updateTime" property="updatetime" jdbcType="TIMESTAMP" />
    <result column="userFace" property="userface" jdbcType="VARCHAR" />
    <result column="realName" property="realname" jdbcType="VARCHAR" />
    <result column="email" property="email" jdbcType="VARCHAR" />
    <result column="age" property="age" jdbcType="INTEGER" />
    <result column="company_id" property="companyId" jdbcType="INTEGER" />
  </resultMap>
  <resultMap id="SecurityResult" type="com.tianbo.warehouse.model.USERS">
    <id column="user_id" property="userId" jdbcType="INTEGER" />
    <result column="username" property="username" jdbcType="VARCHAR" />
    <result column="birthday" property="birthday" jdbcType="TIMESTAMP" />
    <result column="sex" property="sex" jdbcType="CHAR" />
    <result column="address" property="address" jdbcType="VARCHAR" />
    <result column="state" property="state" jdbcType="BIT" />
    <result column="mobilePhone" property="mobilephone" jdbcType="VARCHAR" />
    <result column="userFace" property="userface" jdbcType="VARCHAR" />
    <result column="realName" property="realname" jdbcType="VARCHAR" />
    <result column="email" property="email" jdbcType="VARCHAR" />
    <result column="age" property="age" jdbcType="INTEGER" />
    <result column="company_id" property="companyId" jdbcType="INTEGER" />
  </resultMap>
  <resultMap id="WithRoleResultMap" type="com.tianbo.warehouse.model.USERS" extends="BaseResultMap">
    <collection property="roles" javaType="java.util.ArrayList" ofType="com.tianbo.warehouse.model.ROLE">
      <result column="role_id" jdbcType="INTEGER" property="roleId" />
      <result column="role_name" jdbcType="VARCHAR" property="roleName" />
      <result column="role_sign" jdbcType="VARCHAR" property="roleSign" />
      <result column="rdescription" jdbcType="VARCHAR" property="description" />
      <result column="type" jdbcType="VARCHAR" property="type" />
      <result column="parentId" jdbcType="INTEGER" property="parentid" />
      <result column="rsort" jdbcType="INTEGER" property="rsort" />
      <result column="customs_reg_code" jdbcType="VARCHAR" property="customsRegCode" />
      <result column="business_license" jdbcType="VARCHAR" property="businessLicense" />
      <result column="departmentId" jdbcType="VARCHAR" property="departmentid" />
      <result column="mq_code" jdbcType="VARCHAR" property="mqcode" />
    </collection>
  </resultMap>
  <resultMap id="WithRoleAndPermResultMap" type="com.tianbo.warehouse.model.USERS" extends="BaseResultMap">
    <collection property="roles" javaType="java.util.ArrayList" ofType="com.tianbo.warehouse.model.ROLE">
      <result column="role_id" jdbcType="INTEGER" property="roleId" />
      <result column="role_name" jdbcType="VARCHAR" property="roleName" />
      <result column="role_sign" jdbcType="VARCHAR" property="roleSign" />
      <result column="rdescription" jdbcType="VARCHAR" property="description" />
      <result column="type" jdbcType="VARCHAR" property="type" />
      <result column="parentId" jdbcType="INTEGER" property="parentid" />
      <result column="rsort" jdbcType="INTEGER" property="rsort" />
      <result column="customs_reg_code" jdbcType="VARCHAR" property="customsRegCode" />
      <result column="business_license" jdbcType="VARCHAR" property="businessLicense" />
      <result column="departmentId" jdbcType="VARCHAR" property="departmentid" />
      <result column="mq_code" jdbcType="VARCHAR" property="mqcode" />
    </collection>
    <collection property="permissions" javaType="java.util.ArrayList" ofType="com.tianbo.warehouse.model.PERMISSION">
      <result column="permission_id" property="permissionId" jdbcType="INTEGER" />
      <result column="name" property="name" jdbcType="VARCHAR" />
      <result column="permission_order" property="permissionOrder" jdbcType="VARCHAR" />
      <result column="pdescription" property="description" jdbcType="VARCHAR" />
      <result column="ismenu" property="ismenu" jdbcType="BOOLEAN" />
      <result column="hidden" property="hidden" jdbcType="BOOLEAN" />
      <result column="parent_id" property="parentId" jdbcType="INTEGER" />
      <result column="path" property="path" jdbcType="VARCHAR" />
      <result column="url" property="url" jdbcType="VARCHAR" />
      <result column="method" property="method" jdbcType="VARCHAR" />
      <result column="iconCls" property="iconCls" jdbcType="VARCHAR" />
      <result column="component" property="component" jdbcType="VARCHAR" />
    </collection>
  </resultMap>
  <sql id="Base_Column_List" >
    user_id, username, password, birthday, sex, address, state, mobilePhone, creatTime,
    updateTime, userFace, realName, email, age,company_id
  </sql>
  <sql id="user_List" >
    user_id, username, birthday, sex, address, state, mobilePhone,userFace, realName, email, age
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select
    <include refid="Base_Column_List" />
    from users
    where user_id = #{userId,jdbcType=INTEGER}
  </select>
  <select id="selectByUsername" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select
    <include refid="Base_Column_List" />
    from users
    where username = #{username,jdbcType=VARCHAR}
  </select>

  <select id="selectByUsernameWithRoleAndPerm" resultMap="WithRoleAndPermResultMap" parameterType="java.lang.String" >
    select
    u.user_id, username, password, birthday, sex, address, state, mobilePhone, creatTime,
    updateTime, userFace, realName, email, age,company_id,

    r.role_id, role_name, role_sign, r.description as rdescription, `type`, parentId, rsort, customs_reg_code,
    business_license, departmentId, mq_code,

    p.permission_id, `name`, permission_order, p.description as pdescription, ismenu,hidden,parent_id,
    path, url, method, iconCls, component
    from
    (select
    <include refid="Base_Column_List" />
    from users
    where username = 'nmms') u
    left join user_role ur on u.user_id = ur.user_id
    left join role r on r.role_id = ur.role_id
    left join role_permission rp on r.role_id = rp.role_id
    left join permission p on rp.permission_id = p.permission_id
  </select>
  <select id="selectAllUser" resultMap="WithRoleResultMap" parameterType="com.tianbo.warehouse.model.USERS" >
    SELECT
      u.user_id,
      username,
      birthday,
      sex,
      address,
      state,
      mobilePhone,
      creatTime,
      updateTime,
      userFace,
      realName,
      email,
      age,
      company_id,
      r.role_id,role_name,role_sign,r.description AS rdescription,`type`,parentId,rsort,customs_reg_code,business_license,departmentId,mq_code
    FROM
    (
        SELECT
            user_id,username,birthday,sex,address,state,mobilePhone,creatTime,updateTime,userFace,realName,email,age,company_id
         FROM users
         <where>
           <if test=" username != null and username != ''" >
             and  username = #{username,jdbcType=VARCHAR}
           </if>
           <if test="realname != null and realname != ''" >
             and realName = #{realname,jdbcType=VARCHAR}
           </if>
         </where>
    ) u
    LEFT JOIN user_role ur ON u.user_id = ur.user_id
    LEFT JOIN role r ON ur.role_id = r.role_id
    <if test=" companyId != null and companyId != ''" >
      WHERE r.role_id =  #{companyId,jdbcType=INTEGER}
    </if>
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from users
    where user_id = #{userId,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.tianbo.warehouse.model.USERS" >
    insert into users (user_id, username, password,
      birthday, sex, address,
      state, mobilePhone, creatTime,
      updateTime, userFace, realName,
      email, age)
    values (#{userId,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
      #{birthday,jdbcType=TIMESTAMP}, #{sex,jdbcType=CHAR}, #{address,jdbcType=VARCHAR},
      #{state,jdbcType=BIT}, #{mobilephone,jdbcType=VARCHAR}, #{creattime,jdbcType=TIMESTAMP},
      #{updatetime,jdbcType=TIMESTAMP}, #{userface,jdbcType=VARCHAR}, #{realname,jdbcType=VARCHAR},
      #{email,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.tianbo.warehouse.model.USERS" >
    insert into users
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="userId != null" >
        user_id,
      </if>
      <if test="username != null" >
        username,
      </if>
      <if test="password != null" >
        password,
      </if>
      <if test="birthday != null" >
        birthday,
      </if>
      <if test="sex != null" >
        sex,
      </if>
      <if test="address != null" >
        address,
      </if>
      <if test="state != null" >
        state,
      </if>
      <if test="mobilephone != null" >
        mobilePhone,
      </if>
      <if test="creattime != null" >
        creatTime,
      </if>
      <if test="updatetime != null" >
        updateTime,
      </if>
      <if test="userface != null" >
        userFace,
      </if>
      <if test="realname != null" >
        realname,
      </if>
      <if test="email != null" >
        email,
      </if>
      <if test="age != null" >
        age,
      </if>
      <if test="companyId != null" >
        company_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="userId != null" >
        #{userId,jdbcType=INTEGER},
      </if>
      <if test="username != null" >
        #{username,jdbcType=VARCHAR},
      </if>
      <if test="password != null" >
        #{password,jdbcType=VARCHAR},
      </if>
      <if test="birthday != null" >
        #{birthday,jdbcType=TIMESTAMP},
      </if>
      <if test="sex != null" >
        #{sex,jdbcType=CHAR},
      </if>
      <if test="address != null" >
        #{address,jdbcType=VARCHAR},
      </if>
      <if test="state != null" >
        #{state,jdbcType=BIT},
      </if>
      <if test="mobilephone != null" >
        #{mobilephone,jdbcType=VARCHAR},
      </if>
      <if test="creattime != null" >
        #{creattime,jdbcType=TIMESTAMP},
      </if>
      <if test="updatetime != null" >
        #{updatetime,jdbcType=TIMESTAMP},
      </if>
      <if test="userface != null" >
        #{userface,jdbcType=VARCHAR},
      </if>
      <if test="realname != null" >
        #{realname,jdbcType=VARCHAR},
      </if>
      <if test="email != null" >
        #{email,jdbcType=VARCHAR},
      </if>
      <if test="age != null" >
        #{age,jdbcType=INTEGER},
      </if>
      <if test="companyId != null" >
        #{companyId,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.tianbo.warehouse.model.USERS" >
    update users
    <set >
      <if test="password != null" >
        password = #{password,jdbcType=VARCHAR},
      </if>
      <if test="birthday != null" >
        birthday = #{birthday,jdbcType=TIMESTAMP},
      </if>
      <if test="sex != null" >
        sex = #{sex,jdbcType=CHAR},
      </if>
      <if test="address != null" >
        address = #{address,jdbcType=VARCHAR},
      </if>
      <if test="state != null" >
        state = #{state,jdbcType=BIT},
      </if>
      <if test="mobilephone != null" >
        mobilePhone = #{mobilephone,jdbcType=VARCHAR},
      </if>
      <if test="creattime != null" >
        creatTime = #{creattime,jdbcType=TIMESTAMP},
      </if>
      <if test="updatetime != null" >
        updateTime = #{updatetime,jdbcType=TIMESTAMP},
      </if>
      <if test="userface != null" >
        userFace = #{userface,jdbcType=VARCHAR},
      </if>
      <if test="realname != null" >
        realname = #{realname,jdbcType=VARCHAR},
      </if>
      <if test="email != null" >
        email = #{email,jdbcType=VARCHAR},
      </if>
      <if test="age != null" >
        age = #{age,jdbcType=INTEGER},
      </if>
      <if test="companyId != null" >
        company_id = #{companyId,jdbcType=INTEGER},
      </if>
    </set>
    where user_id = #{userId,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.tianbo.warehouse.model.USERS" >
    update users
    set password = #{password,jdbcType=VARCHAR},
      birthday = #{birthday,jdbcType=TIMESTAMP},
      sex = #{sex,jdbcType=CHAR},
      address = #{address,jdbcType=VARCHAR},
      state = #{state,jdbcType=BIT},
      mobilePhone = #{mobilephone,jdbcType=VARCHAR},
      creatTime = #{creattime,jdbcType=TIMESTAMP},
      updateTime = #{updatetime,jdbcType=TIMESTAMP},
      userFace = #{userface,jdbcType=VARCHAR},
      realName = #{realname,jdbcType=VARCHAR},
      email = #{email,jdbcType=VARCHAR},
      age = #{age,jdbcType=INTEGER}
    where user_id = #{userId,jdbcType=INTEGER}
  </update>
</mapper>