<?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.matrix.biz.dao.BizUserDao">
|
<!-- 定义BizUser 的复杂关联map -->
|
<resultMap type="com.matrix.biz.bean.BizUser" id="BizUserMap">
|
<id property="userId" column="user_id" />
|
<result property="createBy" column="create_by" />
|
<result property="createTime" column="create_time" />
|
<result property="updateBy" column="update_by" />
|
<result property="updateTime" column="update_time" />
|
<result property="userName" column="user_name" />
|
<result property="userPassword" column="user_password" />
|
<result property="nickName" column="nick_name" />
|
<result property="avatarUrl" column="avatar_url" />
|
<result property="openId" column="open_id" />
|
<result property="unionId" column="union_id" />
|
<result property="gender" column="gender" />
|
<result property="phoneNumber" column="phone_number" />
|
<result property="area" column="area" />
|
<result property="city" column="city" />
|
<result property="province" column="province" />
|
<result property="country" column="country" />
|
<result property="sessionKey" column="session_key" />
|
<result property="lastLoginTime" column="last_login_time" />
|
<result property="userStatus" column="user_status" />
|
<result property="userVip" column="user_vip" />
|
<result property="userExpiryTime" column="user_expiry_time" />
|
<result property="userAuthentication" column="user_authentication" />
|
<result property="userIsAuthorize" column="user_is_authorize" />
|
<result property="userTempName" column="user_temp_name" />
|
<result property="userTempAvatarUrl" column="user_temp_avatar_url" />
|
<result property="userType" column="user_type" />
|
<result property="companyId" column="company_id" />
|
<result property="isSales" column="is_sales" />
|
<result property="withdrawalCash" column="withdrawal_cash" />
|
<result property="salesmanGrade" column="salesman_grade" />
|
</resultMap>
|
|
|
<!-- 定义BizUser 的简单map ,本map不添加其他的关联属性 -->
|
<resultMap type="com.matrix.biz.bean.BizUser" id="BizUserSimpleMap">
|
<id property="userId" column="user_id" />
|
<result property="createBy" column="create_by" />
|
<result property="createTime" column="create_time" />
|
<result property="updateBy" column="update_by" />
|
<result property="updateTime" column="update_time" />
|
<result property="userName" column="user_name" />
|
<result property="userPassword" column="user_password" />
|
<result property="nickName" column="nick_name" />
|
<result property="avatarUrl" column="avatar_url" />
|
<result property="openId" column="open_id" />
|
<result property="unionId" column="union_id" />
|
<result property="gender" column="gender" />
|
<result property="phoneNumber" column="phone_number" />
|
<result property="area" column="area" />
|
<result property="city" column="city" />
|
<result property="province" column="province" />
|
<result property="country" column="country" />
|
<result property="sessionKey" column="session_key" />
|
<result property="lastLoginTime" column="last_login_time" />
|
<result property="userStatus" column="user_status" />
|
<result property="userVip" column="user_vip" />
|
<result property="userExpiryTime" column="user_expiry_time" />
|
<result property="userAuthentication" column="user_authentication" />
|
<result property="userIsAuthorize" column="user_is_authorize" />
|
<result property="userTempName" column="user_temp_name" />
|
<result property="userTempAvatarUrl" column="user_temp_avatar_url" />
|
<result property="userType" column="user_type" />
|
<result property="companyId" column="company_id" />
|
<result property="isSales" column="is_sales" />
|
<result property="withdrawalCash" column="withdrawal_cash" />
|
<result property="salesmanGrade" column="salesman_grade" />
|
</resultMap>
|
|
<!-- 字段sql -->
|
<sql id="columns">
|
create_by,
|
create_time,
|
update_by,
|
update_time,
|
user_id,
|
user_name,
|
user_password,
|
nick_name,
|
avatar_url,
|
open_id,
|
union_id,
|
gender,
|
phone_number,
|
area,
|
city,
|
province,
|
country,
|
session_key,
|
last_login_time,
|
user_status,
|
user_vip,
|
user_expiry_time,
|
user_authentication,
|
user_is_authorize,
|
user_temp_name,
|
user_temp_avatar_url,
|
user_type,
|
company_id,
|
is_sales,
|
withdrawal_cash,
|
salesman_grade
|
|
</sql>
|
|
<!-- 属性sql -->
|
<sql id="propertys">
|
#{item.createBy},
|
now(),
|
#{item.updateBy},
|
now(),
|
#{item.userId},
|
#{item.userName},
|
#{item.userPassword},
|
#{item.nickName},
|
#{item.avatarUrl},
|
#{item.openId},
|
#{item.unionId},
|
#{item.gender},
|
#{item.phoneNumber},
|
#{item.area},
|
#{item.city},
|
#{item.province},
|
#{item.country},
|
#{item.sessionKey},
|
#{item.lastLoginTime},
|
#{item.userStatus},
|
#{item.userVip},
|
#{item.userExpiryTime},
|
#{item.userAuthentication},
|
#{item.userIsAuthorize},
|
#{item.userTempName},
|
#{item.userTempAvatarUrl},
|
#{item.userType},
|
#{item.companyId},
|
#{item.isSales},
|
#{item.withdrawalCash},
|
#{item.salesmanGrade}
|
|
</sql>
|
|
<!-- where sql -->
|
<sql id="where_sql">
|
|
<if test="record!=null">
|
<if test="(record.userId!=null and record.userId!='') or (record.userId!='' and record.userId==0) ">
|
and user_id = #{record.userId}
|
</if>
|
<if test="(record.userName!=null and record.userName!='') or (record.userName!='' and record.userName==0) ">
|
and user_name = #{record.userName}
|
</if>
|
<if test="(record.userPassword!=null and record.userPassword!='') or (record.userPassword!='' and record.userPassword==0) ">
|
and user_password = #{record.userPassword}
|
</if>
|
<if test="(record.nickName!=null and record.nickName!='') or (record.nickName!='' and record.nickName==0) ">
|
and nick_name like concat('%',#{record.nickName},'%')
|
</if>
|
<if test="(record.avatarUrl!=null and record.avatarUrl!='') or (record.avatarUrl!='' and record.avatarUrl==0) ">
|
and avatar_url = #{record.avatarUrl}
|
</if>
|
<if test="(record.openId!=null and record.openId!='') or (record.openId!='' and record.openId==0) ">
|
and open_id = #{record.openId}
|
</if>
|
<if test="(record.unionId!=null and record.unionId!='') or (record.unionId!='' and record.unionId==0) ">
|
and union_id = #{record.unionId}
|
</if>
|
<if test="(record.gender!=null and record.gender!='') or (record.gender!='' and record.gender==0) ">
|
and gender = #{record.gender}
|
<if test="record.gender==0">
|
or gender is null
|
</if>
|
</if>
|
<if test="(record.phoneNumber!=null and record.phoneNumber!='') or (record.phoneNumber!='' and record.phoneNumber==0) ">
|
and phone_number = #{record.phoneNumber}
|
</if>
|
<if test="(record.area!=null and record.area!='') or (record.area!='' and record.area==0) ">
|
and area = #{record.area}
|
</if>
|
<if test="(record.city!=null and record.city!='') or (record.city!='' and record.city==0) ">
|
and city = #{record.city}
|
</if>
|
<if test="(record.province!=null and record.province!='') or (record.province!='' and record.province==0) ">
|
and province = #{record.province}
|
</if>
|
<if test="(record.country!=null and record.country!='') or (record.country!='' and record.country==0) ">
|
and country = #{record.country}
|
</if>
|
<if test="(record.sessionKey!=null and record.sessionKey!='') or (record.sessionKey!='' and record.sessionKey==0) ">
|
and session_key = #{record.sessionKey}
|
</if>
|
<if test="(record.lastLoginTime!=null and record.lastLoginTime!='') or (record.lastLoginTime!='' and record.lastLoginTime==0) ">
|
and last_login_time = #{record.lastLoginTime}
|
</if>
|
<if test="(record.userStatus!=null and record.userStatus!='') or (record.userStatus!='' and record.userStatus==0) ">
|
and user_status = #{record.userStatus}
|
</if>
|
<if test="(record.userVip!=null and record.userVip!='') or (record.userVip!='' and record.userVip==0) ">
|
and user_vip = #{record.userVip}
|
</if>
|
<if test="(record.userExpiryTime!=null and record.userExpiryTime!='') or (record.userExpiryTime!='' and record.userExpiryTime==0) ">
|
and user_expiry_time = #{record.userExpiryTime}
|
</if>
|
<if test="(record.userAuthentication!=null and record.userAuthentication!='') or (record.userAuthentication!='' and record.userAuthentication==0) ">
|
and user_authentication = #{record.userAuthentication}
|
</if>
|
<if test="(record.userIsAuthorize!=null and record.userIsAuthorize!='') or (record.userIsAuthorize!='' and record.userIsAuthorize==0) ">
|
and user_is_authorize = #{record.userIsAuthorize}
|
</if>
|
<if test="(record.userTempName!=null and record.userTempName!='') or (record.userTempName!='' and record.userTempName==0) ">
|
and user_temp_name = #{record.userTempName}
|
</if>
|
<if test="(record.userTempAvatarUrl!=null and record.userTempAvatarUrl!='') or (record.userTempAvatarUrl!='' and record.userTempAvatarUrl==0) ">
|
and user_temp_avatar_url = #{record.userTempAvatarUrl}
|
</if>
|
<if test="(record.userType!=null and record.userType!='') or (record.userType!='' and record.userType==0) ">
|
and user_type = #{record.userType}
|
</if>
|
|
<if test="record.companyId != null and record.companyId !='' ">
|
and company_id = #{record.companyId}
|
</if>
|
|
<if test="record.isSales != null and record.isSales !='' ">
|
and is_sales = #{record.isSales}
|
</if>
|
|
<if test="record.withdrawalCash != null and record.withdrawalCash !='' ">
|
and withdrawal_cash = #{record.withdrawalCash}
|
</if>
|
|
<if test="record.salesmanGrade != null and record.salesmanGrade !='' ">
|
and salesman_grade = #{record.salesmanGrade}
|
</if>
|
|
|
<if test="(record.startTime!=null and record.startTime!='') or (record.startTime!='' and record.startTime==0) ">
|
and date_format(create_time,'%Y-%m-%d') >= #{record.startTime}
|
</if>
|
<if test="(record.endTime!=null and record.endTime!='') or (record.endTime!='' and record.endTime==0) ">
|
and date_format(create_time,'%Y-%m-%d') <= #{record.endTime}
|
</if>
|
</if>
|
|
</sql>
|
|
<!-- 插入方法 -->
|
<insert id="insert" parameterType="com.matrix.biz.bean.BizUser"
|
useGeneratedKeys="true" keyProperty="item.userId">
|
INSERT INTO biz_user (
|
<include refid="columns"></include>
|
)
|
VALUES (
|
<include refid="propertys"></include>
|
)
|
</insert>
|
|
|
|
<!-- 批量插入 -->
|
<insert id="batchInsert" parameterType="java.util.List">
|
INSERT INTO biz_user (
|
<include refid="columns"></include>
|
)
|
VALUES
|
<foreach collection="list" item="item" index="index" separator=",">(
|
<include refid="propertys"></include>
|
)</foreach>
|
</insert>
|
|
|
|
|
|
<!-- 根据Map更新 部分更新 -->
|
<update id="updateByMap" parameterType="java.util.HashMap" >
|
UPDATE biz_user
|
<set>
|
<if test="_parameter.containsKey('userName')">
|
user_name = #{userName},
|
</if>
|
<if test="_parameter.containsKey('userPassword')">
|
user_password = #{userPassword},
|
</if>
|
<if test="_parameter.containsKey('nickName')">
|
nick_name = #{nickName},
|
</if>
|
<if test="_parameter.containsKey('avatarUrl')">
|
avatar_url = #{avatarUrl},
|
</if>
|
<if test="_parameter.containsKey('openId')">
|
open_id = #{openId},
|
</if>
|
<if test="_parameter.containsKey('unionId')">
|
union_id = #{unionId},
|
</if>
|
<if test="_parameter.containsKey('gender')">
|
gender = #{gender},
|
</if>
|
<if test="_parameter.containsKey('phoneNumber')">
|
phone_number = #{phoneNumber},
|
</if>
|
<if test="_parameter.containsKey('area')">
|
area = #{area},
|
</if>
|
<if test="_parameter.containsKey('city')">
|
city = #{city},
|
</if>
|
<if test="_parameter.containsKey('province')">
|
province = #{province},
|
</if>
|
<if test="_parameter.containsKey('country')">
|
country = #{country},
|
</if>
|
<if test="_parameter.containsKey('sessionKey')">
|
session_key = #{sessionKey},
|
</if>
|
<if test="_parameter.containsKey('lastLoginTime')">
|
last_login_time = #{lastLoginTime},
|
</if>
|
<if test="_parameter.containsKey('userStatus')">
|
user_status = #{userStatus},
|
</if>
|
<if test="_parameter.containsKey('userVip')">
|
user_vip = #{userVip},
|
</if>
|
<if test="_parameter.containsKey('userExpiryTime')">
|
user_expiry_time = #{userExpiryTime},
|
</if>
|
<if test="_parameter.containsKey('userAuthentication')">
|
user_authentication = #{userAuthentication},
|
</if>
|
<if test="_parameter.containsKey('userIsAuthorize')">
|
user_is_authorize = #{userIsAuthorize},
|
</if>
|
<if test="_parameter.containsKey('userTempName')">
|
user_temp_name = #{userTempName},
|
</if>
|
<if test="_parameter.containsKey('userTempAvatarUrl')">
|
user_temp_avatar_url = #{userTempAvatarUrl},
|
</if>
|
|
|
<if test="_parameter.containsKey('userType')">
|
user_type = #{userType},
|
</if>
|
|
<if test="_parameter.containsKey('isSales')">
|
is_sales = #{isSales},
|
</if>
|
|
<if test="_parameter.containsKey('withdrawalCash')">
|
withdrawal_cash = #{withdrawalCash},
|
</if>
|
<if test="_parameter.containsKey('salesmanGrade')">
|
salesman_grade = #{salesmanGrade},
|
</if>
|
|
|
|
</set>
|
WHERE user_id=#{userId}
|
</update>
|
|
|
<!-- 根据对象更新 部分更新 -->
|
<update id="updateByModel" parameterType="String">
|
UPDATE biz_user
|
<set>
|
<if test="record.userName != null and record.userName != '' ">
|
user_name = #{record.userName},
|
</if>
|
<if test="record.userPassword != null and record.userPassword != '' ">
|
user_password = #{record.userPassword},
|
</if>
|
<if test="record.nickName != null and record.nickName != '' ">
|
nick_name = #{record.nickName},
|
</if>
|
<if test="record.avatarUrl != null and record.avatarUrl != '' ">
|
avatar_url = #{record.avatarUrl},
|
</if>
|
<if test="record.openId != null and record.openId != '' ">
|
open_id = #{record.openId},
|
</if>
|
<if test="record.unionId != null and record.unionId != '' ">
|
union_id = #{record.unionId},
|
</if>
|
<if test="record.gender != null and record.gender != '' ">
|
gender = #{record.gender},
|
</if>
|
<if test="record.phoneNumber != null and record.phoneNumber != '' ">
|
phone_number = #{record.phoneNumber},
|
</if>
|
<if test="record.area != null and record.area != '' ">
|
area = #{record.area},
|
</if>
|
<if test="record.city != null and record.city != '' ">
|
city = #{record.city},
|
</if>
|
<if test="record.province != null and record.province != '' ">
|
province = #{record.province},
|
</if>
|
<if test="record.country != null and record.country != '' ">
|
country = #{record.country},
|
</if>
|
<if test="record.sessionKey != null and record.sessionKey != '' ">
|
session_key = #{record.sessionKey},
|
</if>
|
<if test="record.lastLoginTime != null ">
|
last_login_time = #{record.lastLoginTime},
|
</if>
|
<if test="record.userStatus != null ">
|
user_status = #{record.userStatus},
|
</if>
|
<if test="record.userVip != null ">
|
user_vip = #{record.userVip},
|
</if>
|
<if test="record.userExpiryTime != null ">
|
user_expiry_time = #{record.userExpiryTime},
|
</if>
|
<if test="record.userAuthentication != null and record.userAuthentication != '' ">
|
user_authentication = #{record.userAuthentication},
|
</if>
|
<if test="record.userIsAuthorize != null ">
|
user_is_authorize = #{record.userIsAuthorize},
|
</if>
|
<if test="record.userTempName != null and record.userTempName != '' ">
|
user_temp_name = #{record.userTempName},
|
</if>
|
<if test="record.userTempAvatarUrl != null and record.userTempAvatarUrl != '' ">
|
user_temp_avatar_url = #{record.userTempAvatarUrl},
|
</if>
|
<if test="record.userType != null ">
|
user_type = #{record.userType},
|
</if>
|
<if test="record.isSales != null ">
|
is_sales = #{record.isSales},
|
</if>
|
<if test="record.withdrawalCash != null ">
|
withdrawal_cash = #{record.withdrawalCash},
|
</if>
|
<if test="record.salesmanGrade != null ">
|
salesman_grade = #{record.salesmanGrade},
|
</if>
|
|
|
</set>
|
WHERE user_id=#{record.userId}
|
</update>
|
|
<!-- 批量删除 -->
|
<delete id="deleteByIds" parameterType="java.util.List">
|
delete from biz_user where user_id in
|
<foreach collection="list" index="index" item="item" open="("
|
separator="," close=")">
|
#{item}
|
</foreach>
|
</delete>
|
|
<!-- 根据id删除-->
|
<delete id="deleteById" parameterType="String">
|
DELETE FROM biz_user
|
where user_id=#{userId}
|
</delete>
|
|
<!-- 根据对象删除-->
|
<delete id="deleteByModel" parameterType="com.matrix.biz.bean.BizUser">
|
DELETE FROM biz_user
|
<where>
|
<include refid="where_sql" ></include>
|
</where>
|
</delete>
|
|
|
|
<!-- 分页查询 -->
|
<select id="selectInPage" resultMap="BizUserMap">
|
select
|
<include refid="columns" ></include>
|
from biz_user
|
<where>
|
<include refid="where_sql"></include>
|
</where>
|
<if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
|
<if test="pageVo.sort !=null and pageVo.order !=null">
|
order by
|
${pageVo.sort} ${pageVo.order}
|
</if>
|
<if test="pageVo.offset >=0 and pageVo.limit >0">
|
limit
|
#{pageVo.offset},#{pageVo.limit}
|
</if>
|
</if>
|
</select>
|
|
<!-- 查询总条数 -->
|
<select id="selectTotalRecord" parameterType="long" resultType="java.lang.Integer">
|
select count(*)
|
from biz_user
|
<where>
|
<include refid="where_sql"></include>
|
</where>
|
</select>
|
|
<!-- 根据id查询-->
|
<select id="selectById" resultMap="BizUserMap">
|
select
|
<include refid="columns" ></include>
|
from biz_user
|
where user_id=#{userId}
|
</select>
|
|
|
<!-- 根据id 锁表查询-->
|
<select id="selectForUpdate" resultMap="BizUserMap">
|
select
|
<include refid="columns" ></include>
|
from biz_user
|
where user_id=#{user_id}
|
for update
|
</select>
|
|
|
|
<!-- 根据对象查询-->
|
<select id="selectByModel" resultMap="BizUserMap">
|
select
|
<include refid="columns" ></include>
|
from biz_user
|
<where>
|
<include refid="where_sql"></include>
|
</where>
|
</select>
|
|
|
<select id="findByOpenId" resultMap="BizUserMap">
|
select
|
<include refid="columns" ></include>
|
from biz_user where open_id=#{openId}
|
</select>
|
</mapper>
|