<?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.ruoyi.ss.user.mapper.UserMapper">

	<resultMap type="UserVO" id="EUserResult" autoMapping="true" >
		<result property="appMenus" column="app_menus" typeHandler="com.ruoyi.system.mapper.typehandler.LongSplitListTypeHandler"/>
		<result property="channelIds" column="channel_ids" typeHandler="com.ruoyi.system.mapper.typehandler.LongSplitListTypeHandler"/>
		<collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
	</resultMap>

	<resultMap id="RoleResult" type="SysRole">
		<id property="roleId" column="role_id" />
		<result property="roleName" column="role_name" />
		<result property="roleKey" column="role_key" />
		<result property="roleSort" column="role_sort" />
		<result property="dataScope" column="data_scope" />
		<result property="status" column="role_status" />
	</resultMap>

	<sql id="selectUserVo">
		select u.user_id, u.user_name, u.real_name, u.id_card, u.nick_name, u.email, u.avatar,u.user_type,u.channel_ids,u.merchant_id,u.dividend_proportion,u.app_menus,
			   u.phonenumber, u.password, u.sex, u.status,u.service_fee_proportion,u.clean_duration, u.clean_notice,u.ago_cancel,u.penalty, u.before_time,
			   u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.wxopenid,u.is_authentication,u.store_id,u.device_admin,
			   r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status,u.balance,multi_store
		from ss_user u
				 left join sys_user_role ur on u.user_id = ur.user_id
				 left join sys_role r on r.role_id = ur.role_id
	</sql>

	<sql id="selectUserVo2">
		select u.user_id, u.user_name, u.real_name, u.id_card, u.nick_name, u.email, u.avatar,u.user_type,u.channel_ids,u.merchant_id,u.dividend_proportion,u.app_menus,
			   u.phonenumber, u.password, u.sex, u.status, u.service_fee_proportion,u.clean_duration, u.clean_notice,u.ago_cancel,u.penalty, u.before_time,
			   u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.wxopenid,u.is_authentication,u.store_id,u.device_admin,
			   u.balance,u.multi_store
		from ss_user u
	</sql>
	<sql id="searchCondition">
		<if test="userId != null and userId != 0">
			AND u.user_id = #{userId}
		</if>
		<if test="storeId != null">
			AND u.store_id = #{storeId}
		</if>
		<if test="userName != null and userName != ''">
			AND u.user_name like concat('%', #{userName}, '%')
		</if>
		<if test="realName != null and realName != ''">
			AND u.real_name like concat('%', #{realName}, '%')
		</if>
		<if test="status != null and status != ''">
			AND u.status = #{status}
		</if>
		<if test="userType != null and userType != ''">
			AND u.user_type = #{userType}
		</if>
		<if test="phonenumber != null and phonenumber != ''">
			AND u.phonenumber like concat('%', #{phonenumber}, '%')
		</if>
		<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
			AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
		</if>
		<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
			AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
		</if>
		<if test="typeList != null and  typeList !=''">
			AND u.user_type IN
			<foreach item="item" index="index" collection="typeList" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
	</sql>

	<select id="selectUserList" parameterType="UserQuery" resultMap="EUserResult">
		select u.user_id,
		       u.nick_name,
		       u.user_name,
		       u.real_name,
		       u.email,
		       u.avatar,
		       u.phonenumber,
		       u.user_type,
		       u.service_fee_proportion,
		       u.clean_duration,
		       u.clean_notice,
		       u.ago_cancel,
		       u.penalty,
		       u.merchant_id,
		       u.store_id,
		       s.name as storeName,
		       u.device_admin,
			   u.sex,
			   u.dividend_proportion,
			   u.status,
			   u.del_flag,
			   u.login_ip,
			   u.login_date,
			   u.create_by,
			   u.create_time,
			   u.remark,
			   u.is_authentication,
			   u.balance,
			   u.wxopenid from ss_user u
			  left join ss_store s on u.store_id = s.store_id
		where u.del_flag = '0' and u.user_name != 'admin'
		<include refid="searchCondition"/>
		${params.dataScope}
		GROUP BY u.user_name
		order by u.create_time desc
	</select>

	<select id="selectAppUserList" parameterType="User" resultMap="EUserResult">
		<include refid="selectUserVo"/>
		where u.del_flag = '0'
	</select>

	<select id="selectCount" resultType="java.lang.Integer">
		select count(u.user_id)
		from ss_user u
		<where>
			<include refid="searchCondition"/>
		</where>
	</select>

	<select id="selectAllocatedList" parameterType="User" resultMap="EUserResult">
		select distinct u.user_id, u.user_name, u.nick_name,u.real_name, u.email, u.phonenumber, u.status, u.create_time
		from ss_user u
		left join sys_user_role ur on u.user_id = ur.user_id
		left join sys_role r on r.role_id = ur.role_id
		where u.del_flag = '0' and r.role_id = #{roleId}
		<if test="userName != null and userName != ''">
			AND u.user_name like concat('%', #{userName}, '%')
		</if>
		<if test="phonenumber != null and phonenumber != ''">
			AND u.phonenumber like concat('%', #{phonenumber}, '%')
		</if>
	</select>

	<select id="selectDividendUserList" parameterType="Long" resultMap="EUserResult">
		<include refid="selectUserVo2"/>
		where u.del_flag = '0' and u.user_type in('02','03','04','05') and u.dividend_status = '1' and u.dividend_proportion > 0
		AND u.merchant_id = #{merchantId}
	</select>

	<select id="selectUnallocatedList" parameterType="User" resultMap="EUserResult">
		select distinct u.user_id, u.user_name,u.real_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time
		from ss_user u
		where u.del_flag = '0'
		<if test="userName != null and userName != ''">
			AND u.user_name like concat('%', #{userName}, '%')
		</if>
		<if test="phonenumber != null and phonenumber != ''">
			AND u.phonenumber like concat('%', #{phonenumber}, '%')
		</if>
	</select>

	<select id="selectUserByUserName" parameterType="String" resultMap="EUserResult">
		<include refid="selectUserVo"/>
		where u.user_name = #{userName} and u.del_flag = '0'
	</select>

	<select id="selectUserById" parameterType="Long" resultMap="EUserResult">
		select u.user_id,
		       u.user_name,
		       u.real_name,
		       u.id_card,
		       u.nick_name,
		       u.email,
		       u.avatar,
		       u.service_fee_proportion,
		       u.channel_ids,
		       u.merchant_id,
		       u.clean_duration,
		       u.clean_notice,
		       u.ago_cancel,
		       u.penalty,
			   u.phonenumber,
			   u.password,
			   u.store_id,
			   u.sex,
			   u.status,
			   u.user_type,
			   r.role_id,
			   r.role_name,
			   r.role_key,
			   r.role_sort,
			   r.data_scope,
			   r.status,
			   u.balance,
			   u.device_admin,
			   u.app_menus,
			   u.before_time,
			   u.del_flag,
			   u.login_ip,
			   u.login_date,
			   u.create_by,
			   u.create_time,
			   u.remark,u.wxopenid,
			   u.is_authentication,
			   u.channel_ids,
			   u.dividend_proportion,
			   u.multi_store
		from ss_user u
				 left join sys_user_role ur on u.user_id = ur.user_id
				 left join sys_role r on r.role_id = ur.role_id
		where u.user_id = #{userId} and u.del_flag = '0'
	</select>

	<select id="selectAppUserById" parameterType="Long" resultMap="EUserResult">
		select u.user_id, u.user_name, u.real_name, u.id_card, u.nick_name, u.email, u.avatar,u.service_fee_proportion,u.clean_duration, u.clean_notice,u.ago_cancel,u.penalty,u.app_menus,
			   u.phonenumber, u.password, u.sex, u.status,u.user_type,u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time,u.balance,u.before_time,u.device_admin,u.before_time,
			   u.remark,u.wxopenid,u.is_authentication,u.channel_ids,ub.balance
		from ss_user u
		left join ss_user_balance ub on ub.user_id = u.user_id
		where u.user_id = #{userId}
		order by
			ub.balance DESC
			limit 1
	</select>

	<select id="myAccountInfoByUserId" parameterType="Long" resultMap="EUserResult">
		select u.user_id, u.user_name, u.real_name, u.id_card, u.nick_name, u.email, u.avatar,
			   u.phonenumber, u.password, u.sex, u.status,u.user_type,u.service_fee_proportion,u.clean_duration, u.clean_notice,u.ago_cancel,u.penalty,u.before_time,
			   u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.wxopenid,u.is_authentication,u.channel_ids,u.device_admin,u.app_menus,
			   ub.balance
		from ss_user u
		left join ss_user_balance ub on ub.user_id = u.user_id
		where u.user_id = #{userId}
		order by
			ub.balance DESC
			limit 1
	</select>

	<select id="checkUserNameUnique" parameterType="String" resultMap="EUserResult">
		select user_id, user_name from ss_user where user_name = #{userName} and del_flag = '0' limit 1
	</select>

	<select id="checkPhoneUnique" parameterType="String" resultMap="EUserResult">
		select user_id, phonenumber from ss_user where phonenumber = #{phonenumber} and del_flag = '0' limit 1
	</select>

	<select id="checkEmailUnique" parameterType="String" resultMap="EUserResult">
		select user_id, email from ss_user where email = #{email} and del_flag = '0' limit 1
	</select>

	<select id="selectUserByPhone" parameterType="String" resultMap="EUserResult">
		<include refid="selectUserVo"/>
		where u.phonenumber = #{phonenumber}
	</select>

	<select id="selectUserByPhoneAndAppId" parameterType="String" resultMap="EUserResult">
		<include refid="selectUserVo"/>
		where u.phonenumber = #{phone}
	</select>

	<select id="selectUserByWxopenid" parameterType="String" resultMap="EUserResult">
		<include refid="selectUserVo"/>
		where u.wxopenid = #{openid}
	</select>

	<select id="getNewUser" resultType="java.lang.String">
		select count(1) from ss_user
		where date_format(create_time,'%y%m%d') &gt;= date_format(#{timeStart},'%y%m%d')
		and date_format(create_time,'%y%m%d') &lt;= date_format(#{timeEnd},'%y%m%d')
		and status = '0'
		<if test="areaId != null and areaId != ''">
			and area_id = #{areaId}
		</if>
	</select>

	<select id="getLeaseUser" resultType="java.lang.String">
		SELECT COUNT(DISTINCT o.user_id) from et_order  o LEFT JOIN ss_user u on o.user_id = u.user_id
		where date_format(o.create_time,'%y%m%d') &gt;= date_format(#{timeStart},'%y%m%d')
		and date_format(o.create_time,'%y%m%d') &lt;= date_format(#{timeEnd},'%y%m%d')
		and type = 1
		<if test="areaId != null and areaId != ''">
			and o.area_id = #{areaId}
		</if>
	</select>

	<select id="getTotalUser" resultType="java.lang.String">
		select count(1) from ss_user
		where  status = '0'
		<if test="areaId != null and areaId != ''">
			and area_id = #{areaId}
		</if>
	</select>

	<select id="fastSearch" resultType="com.ruoyi.common.core.domain.vo.LabelVo">
		select phonenumber label,user_id as `value`,app_name appName from ss_user where phonenumber like concat('%', #{phonenumber}, '%')
	</select>
	<select id="selectAllCount" resultType="java.lang.Integer">
		select count(DISTINCT phonenumber) from ss_user where 1=1
		<if test="timeStart != null  and timeStart != ''">
			AND date_format(create_time,'%y%m%d') &gt;= date_format(#{timeStart},'%y%m%d')
		</if>
		<if test="timeEnd != null  and timeEnd != ''">
			AND date_format(create_time,'%y%m%d') &lt;= date_format(#{timeEnd},'%y%m%d')
		</if>
	</select>

	<select id="selectUserBalanceById" resultType="java.math.BigDecimal">
		select balance from ss_user
		where user_id = #{userId}
	</select>

	<select id="selectTodayOrderAmount" resultType="java.math.BigDecimal">
		SELECT
			COALESCE(SUM(CASE WHEN type = '1' THEN amount ELSE 0 END), 0) -
			COALESCE(SUM(CASE WHEN type = '2' THEN amount ELSE 0 END), 0) AS net_amount
		FROM
			ss_change_balance
		WHERE
			DATE(create_time) = CURDATE()
		  AND owner_id = #{ownerId}
		  AND bus_type in (1,2,4)
	</select>

    <select id="getClearUserByStoreId" resultMap="EUserResult">
		select u.user_id, u.user_name,
			   u.phonenumber
		from ss_user u
		where u.store_id = #{storeId} and u.status = '0' and u.del_flag = '0' and u.user_type = '04'
	</select>

	<select id="selectAllBalance" resultType="java.math.BigDecimal">
		select COALESCE(SUM(u.balance), 0) from ss_user u where u.del_flag = '0' and u.status = '0' and u.user_type = '01'
	</select>

	<insert id="insertUser" parameterType="User" useGeneratedKeys="true" keyProperty="userId">
		insert into ss_user(
		<if test="userId != null and userId != 0">user_id,</if>
		<if test="userName != null and userName != ''">user_name,</if>
		<if test="realName != null and realName != ''">real_name,</if>
		<if test="userType != null and userType != ''">user_type,</if>
		<if test="deviceAdmin != null and deviceAdmin != ''">device_admin,</if>
		<if test="idCard != null and idCard != ''">id_card,</if>
		<if test="nickName != null and nickName != ''">nick_name,</if>
		<if test="email != null and email != ''">email,</if>
		<if test="avatar != null and avatar != ''">avatar,</if>
		<if test="phonenumber != null and phonenumber != ''">phonenumber,</if>
		<if test="sex != null and sex != ''">sex,</if>
		<if test="password != null and password != ''">password,</if>
		<if test="status != null and status != ''">status,</if>
		<if test="createBy != null and createBy != ''">create_by,</if>
		<if test="remark != null and remark != ''">remark,</if>
		<if test="wxopenid != null and wxopenid != ''">wxopenid,</if>
		<if test="serviceFeeProportion != null">service_fee_proportion,</if>
		<if test="cleanDuration != null">clean_duration,</if>
		<if test="cleanNotice != null">clean_notice,</if>
		<if test="agoCancel != null">ago_cancel,</if>
		<if test="penalty != null">penalty,</if>
		<if test="appMenus != null">app_menus,</if>
		<if test="merchantId != null">merchant_id,</if>
		<if test="storeId != null">store_id,</if>
		create_time
		)values(
		<if test="userId != null and userId != ''">#{userId},</if>
		<if test="userName != null and userName != ''">#{userName},</if>
		<if test="realName != null and realName != ''">#{realName},</if>
		<if test="userType != null and userType != ''">#{userType},</if>
		<if test="deviceAdmin != null and deviceAdmin != ''">#{deviceAdmin},</if>
		<if test="idCard != null and idCard != ''">#{idCard},</if>
		<if test="nickName != null and nickName != ''">#{nickName},</if>
		<if test="email != null and email != ''">#{email},</if>
		<if test="avatar != null and avatar != ''">#{avatar},</if>
		<if test="phonenumber != null and phonenumber != ''">#{phonenumber},</if>
		<if test="sex != null and sex != ''">#{sex},</if>
		<if test="password != null and password != ''">#{password},</if>
		<if test="status != null and status != ''">#{status},</if>
		<if test="createBy != null and createBy != ''">#{createBy},</if>
		<if test="remark != null and remark != ''">#{remark},</if>
		<if test="wxopenid != null and wxopenid != ''">#{wxopenid},</if>
		<if test="serviceFeeProportion != null">#{serviceFeeProportion},</if>
		<if test="cleanDuration != null">#{cleanDuration},</if>
		<if test="cleanNotice != null">#{cleanNotice},</if>
		<if test="agoCancel != null">#{agoCancel},</if>
		<if test="penalty != null">#{penalty},</if>
		<if test="appMenus != null">#{appMenus,typeHandler=com.ruoyi.system.mapper.typehandler.LongSplitListTypeHandler},</if>
		<if test="merchantId != null">#{merchantId},</if>
		<if test="storeId != null">#{storeId},</if>
		sysdate()
		)
	</insert>

	<update id="updateUser" parameterType="User">
		update ss_user
		<set>
			<if test="userName != null and userName != ''">user_name = #{userName},</if>
			<if test="realName != null and realName != ''">real_name = #{realName},</if>
			<if test="idCard != null and idCard != ''">id_card = #{idCard},</if>
			<if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
			<if test="userType != null and userType != ''">user_type = #{userType},</if>
		    <if test="deviceAdmin != null">device_admin = #{deviceAdmin},</if>
			<if test="email != null ">email = #{email},</if>
			<if test="phonenumber != null ">phonenumber = #{phonenumber},</if>
			<if test="isAuthentication != null">is_authentication = #{isAuthentication},</if>
			<if test="sex != null and sex != ''">sex = #{sex},</if>
			<if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
			<if test="password != null and password != ''">password = #{password},</if>
			<if test="status != null and status != ''">status = #{status},</if>
			<if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>
			<if test="loginDate != null">login_date = #{loginDate},</if>
			<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
			<if test="remark != null">remark = #{remark},</if>
			<if test="wxopenid != null">wxopenid = #{wxopenid},</if>
			<if test="channelIds != null">channel_ids = #{channelIds,typeHandler=com.ruoyi.system.mapper.typehandler.StringSplitListTypeHandler},</if>
			<if test="serviceFeeProportion != null">service_fee_proportion = #{serviceFeeProportion},</if>
			<if test="dividendProportion != null">dividend_proportion = #{dividendProportion},</if>
		    <if test="merchantId != null">merchant_id = #{merchantId},</if>
		    <if test="cleanDuration != null">clean_duration = #{cleanDuration},</if>
		    <if test="cleanNotice != null">clean_notice = #{cleanNotice},</if>
		    <if test="agoCancel != null">ago_cancel = #{agoCancel},</if>
		    <if test="penalty != null">penalty = #{penalty},</if>
		    <if test="appMenus != null">app_menus = #{appMenus,typeHandler=com.ruoyi.system.mapper.typehandler.LongSplitListTypeHandler},</if>
		    <if test="beforeTime != null">before_time = #{beforeTime},</if>
		    <if test="storeId != null">store_id = #{storeId},</if>
		    <if test="multiStore != null">multi_store = #{multiStore},</if>
			update_time = sysdate()
		</set>
		where user_id = #{userId}
	</update>

	<update id="updateUserByPhone" parameterType="User">
		update ss_user
		<set>
			<if test="wxopenid != null">wxopenid = #{wxopenid},</if>
			update_time = sysdate()
		</set>
		where phonenumber = #{phonenumber}
	</update>

	<update id="updateUserStatus" parameterType="User">
		update ss_user set status = #{status} where user_id = #{userId}
	</update>

	<update id="updateUserAvatar" parameterType="User">
		update ss_user set avatar = #{avatar} where user_name = #{userName}
	</update>

	<update id="resetUserPwd" parameterType="User">
		update ss_user set password = #{password} where user_name = #{userName}
	</update>

	<update id="updateUserPwd">
		update ss_user set password = #{password} where  user_id = #{userId}
	</update>

	<update id="changeBalance">
		update ss_user set balance = balance + #{changeAmount} where user_id = #{userId}
	</update>

	<delete id="deleteUserById" parameterType="Long">
		update ss_user set del_flag = '2' where user_id = #{userId}
	</delete>

	<delete id="deleteUserByIds" parameterType="Long">
		update ss_user set del_flag = '2' where user_id in
		<foreach collection="array" item="userId" open="(" separator="," close=")">
			#{userId}
		</foreach>
	</delete>


	<!--    <resultMap type="EUser" id="EUserResult">-->
<!--        <id     property="userId"       column="user_id"      />-->
<!--        <result property="userName"     column="user_name"    />-->
<!--        <result property="realName"     column="real_name"    />-->
<!--        <result property="idCard"     column="id_card"    />-->
<!--        <result property="nickName"     column="nick_name"    />-->
<!--        <result property="email"        column="email"        />-->
<!--        <result property="phonenumber"  column="phonenumber"  />-->
<!--        <result property="balance"  column="balance"  />-->
<!--        <result property="birthday"  column="birthday"  />-->
<!--        <result property="sex"          column="sex"          />-->
<!--        <result property="avatar"       column="avatar"       />-->
<!--        <result property="password"     column="password"     />-->
<!--        <result property="payPassword"  column="pay_password" />-->
<!--        <result property="status"       column="status"       />-->
<!--        <result property="delFlag"      column="del_flag"     />-->
<!--        <result property="loginIp"      column="login_ip"     />-->
<!--        <result property="loginDate"    column="login_date"   />-->
<!--        <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="remark"       column="remark"       />-->
<!--        <result property="wxopenid"       column="wxopenid"       />-->
<!--    </resultMap>-->

<!--	<sql id="selectUserVo">-->
<!--        select u.user_id, u.user_name, u.real_name, u.id_card, u.nick_name, u.email, u.avatar,-->
<!--               u.phonenumber, u.balance, u.birthday, u.password, u.pay_password, u.sex, u.status,-->
<!--               u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.wxopenid-->
<!--        from ss_user u-->
<!--    </sql>-->

<!--    <select id="selectUserList" parameterType="EUser" resultMap="EUserResult">-->
<!--		select u.user_id, u.nick_name, u.user_name, u.real_name,u.email, u.avatar, u.phonenumber, u.balance,-->
<!--		       u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,-->
<!--		       u.wxopenid from ss_user u-->
<!--		where u.del_flag = '0'-->
<!--		<if test="userId != null and userId != 0">-->
<!--			AND u.user_id = #{userId}-->
<!--		</if>-->
<!--		<if test="userName != null and userName != ''">-->
<!--			AND u.user_name like concat('%', #{userName}, '%')-->
<!--		</if>-->
<!--		<if test="status != null and status != ''">-->
<!--			AND u.status = #{status}-->
<!--		</if>-->
<!--		<if test="phonenumber != null and phonenumber != ''">-->
<!--			AND u.phonenumber like concat('%', #{phonenumber}, '%')-->
<!--		</if>-->
<!--		<if test="params.beginTime != null and params.beginTime != ''">&lt;!&ndash; 开始时间检索 &ndash;&gt;-->
<!--			AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')-->
<!--		</if>-->
<!--		<if test="params.endTime != null and params.endTime != ''">&lt;!&ndash; 结束时间检索 &ndash;&gt;-->
<!--			AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')-->
<!--		</if>-->
<!--		order by u.login_date desc-->
<!--	</select>-->

<!--	<select id="selectAllocatedList" parameterType="EUser" resultMap="EUserResult">-->
<!--	    select distinct u.user_id, u.user_name, u.nick_name,u.real_name, u.email, u.phonenumber, u.balance, u.status, u.create_time-->
<!--	    from ss_user u-->
<!--	    where u.del_flag = '0'-->
<!--	    <if test="userName != null and userName != ''">-->
<!--			AND u.user_name like concat('%', #{userName}, '%')-->
<!--		</if>-->
<!--		<if test="phonenumber != null and phonenumber != ''">-->
<!--			AND u.phonenumber like concat('%', #{phonenumber}, '%')-->
<!--		</if>-->
<!--	</select>-->

<!--	<select id="selectUnallocatedList" parameterType="EUser" resultMap="EUserResult">-->
<!--	    select distinct u.user_id, u.user_name,u.real_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time-->
<!--	    from ss_user u-->
<!--	    where u.del_flag = '0'-->
<!--	    <if test="userName != null and userName != ''">-->
<!--			AND u.user_name like concat('%', #{userName}, '%')-->
<!--		</if>-->
<!--		<if test="phonenumber != null and phonenumber != ''">-->
<!--			AND u.phonenumber like concat('%', #{phonenumber}, '%')-->
<!--		</if>-->
<!--	</select>-->

<!--	<select id="selectUserByUserName" parameterType="String" resultMap="EUserResult">-->
<!--	    <include refid="selectUserVo"/>-->
<!--		where u.user_name = #{userName} and u.del_flag = '0'-->
<!--	</select>-->

<!--	<select id="selectUserById" parameterType="Long" resultMap="EUserResult">-->
<!--		<include refid="selectUserVo"/>-->
<!--		where u.user_id = #{userId}-->
<!--	</select>-->

<!--	<select id="checkUserNameUnique" parameterType="String" resultMap="EUserResult">-->
<!--		select user_id, user_name from ss_user where user_name = #{userName} and del_flag = '0' limit 1-->
<!--	</select>-->

<!--	<select id="checkPhoneUnique" parameterType="String" resultMap="EUserResult">-->
<!--		select user_id, phonenumber from ss_user where phonenumber = #{phonenumber} and del_flag = '0' limit 1-->
<!--	</select>-->

<!--	<select id="checkEmailUnique" parameterType="String" resultMap="EUserResult">-->
<!--		select user_id, email from ss_user where email = #{email} and del_flag = '0' limit 1-->
<!--	</select>-->

<!--	<select id="selectUserByPhone" parameterType="String" resultMap="EUserResult">-->
<!--		<include refid="selectUserVo"/>-->
<!--		where u.phonenumber = #{phonenumber}-->
<!--	</select>-->

<!--	<select id="selectUserByPhoneAndAppId" parameterType="String" resultMap="EUserResult">-->
<!--		<include refid="selectUserVo"/>-->
<!--		where u.phonenumber = #{phone} and u.appid = #{appid}-->
<!--	</select>-->

<!--	<select id="selectUserByWxopenid" parameterType="String" resultMap="EUserResult">-->
<!--		<include refid="selectUserVo"/>-->
<!--		where u.wxopenid = #{openid}-->
<!--	</select>-->

<!--    <select id="getNewUser" resultType="java.lang.String">-->
<!--		select count(1) from ss_user-->
<!--		where date_format(create_time,'%y%m%d') &gt;= date_format(#{timeStart},'%y%m%d')-->
<!--		and date_format(create_time,'%y%m%d') &lt;= date_format(#{timeEnd},'%y%m%d')-->
<!--		and status = '0'-->
<!--		<if test="areaId != null and areaId != ''">-->
<!--			and area_id = #{areaId}-->
<!--		</if>-->
<!--	</select>-->

<!--	<select id="getLeaseUser" resultType="java.lang.String">-->
<!--		SELECT COUNT(DISTINCT o.user_id) from et_order  o LEFT JOIN ss_user u on o.user_id = u.user_id-->
<!--		where date_format(o.create_time,'%y%m%d') &gt;= date_format(#{timeStart},'%y%m%d')-->
<!--		and date_format(o.create_time,'%y%m%d') &lt;= date_format(#{timeEnd},'%y%m%d')-->
<!--		  and type = 1-->
<!--		<if test="areaId != null and areaId != ''">-->
<!--			and o.area_id = #{areaId}-->
<!--		</if>-->
<!--	</select>-->

<!--	<select id="getTotalUser" resultType="java.lang.String">-->
<!--		select count(1) from ss_user-->
<!--		where  status = '0'-->
<!--		<if test="areaId != null and areaId != ''">-->
<!--			and area_id = #{areaId}-->
<!--		</if>-->
<!--	</select>-->

<!--    <select id="fastSearch" resultType="com.ruoyi.common.core.domain.vo.LabelVo">-->
<!--		select phonenumber label,user_id as `value`,app_name appName from ss_user where phonenumber like concat('%', #{phonenumber}, '%')-->
<!--	</select>-->
<!--    <select id="selectAllCount" resultType="java.lang.Integer">-->
<!--		select count(DISTINCT phonenumber) from ss_user where 1=1-->
<!--		<if test="timeStart != null  and timeStart != ''">-->
<!--			AND date_format(create_time,'%y%m%d') &gt;= date_format(#{timeStart},'%y%m%d')-->
<!--		</if>-->
<!--		<if test="timeEnd != null  and timeEnd != ''">-->
<!--			AND date_format(create_time,'%y%m%d') &lt;= date_format(#{timeEnd},'%y%m%d')-->
<!--		</if>-->
<!--	</select>-->

<!--    <insert id="insertUser" parameterType="EUser" useGeneratedKeys="true" keyProperty="userId">-->
<!-- 		insert into ss_user(-->
<!-- 			<if test="userId != null and userId != 0">user_id,</if>-->
<!-- 			<if test="userName != null and userName != ''">user_name,</if>-->
<!-- 			<if test="realName != null and realName != ''">real_name,</if>-->
<!-- 			<if test="idCard != null and idCard != ''">id_card,</if>-->
<!-- 			<if test="nickName != null and nickName != ''">nick_name,</if>-->
<!-- 			<if test="email != null and email != ''">email,</if>-->
<!-- 			<if test="avatar != null and avatar != ''">avatar,</if>-->
<!-- 			<if test="phonenumber != null and phonenumber != ''">phonenumber,</if>-->
<!-- 			<if test="balance != null and balance != ''">balance,</if>-->
<!-- 			<if test="sex != null and sex != ''">sex,</if>-->
<!-- 			<if test="password != null and password != ''">password,</if>-->
<!-- 			<if test="status != null and status != ''">status,</if>-->
<!-- 			<if test="createBy != null and createBy != ''">create_by,</if>-->
<!-- 			<if test="remark != null and remark != ''">remark,</if>-->
<!-- 			<if test="wxopenid != null and wxopenid != ''">wxopenid,</if>-->
<!-- 			create_time-->
<!-- 		)values(-->
<!-- 			<if test="userId != null and userId != ''">#{userId},</if>-->
<!-- 			<if test="userName != null and userName != ''">#{userName},</if>-->
<!-- 			<if test="realName != null and realName != ''">#{realName},</if>-->
<!-- 			<if test="idCard != null and idCard != ''">#{idCard},</if>-->
<!-- 			<if test="nickName != null and nickName != ''">#{nickName},</if>-->
<!-- 			<if test="email != null and email != ''">#{email},</if>-->
<!-- 			<if test="avatar != null and avatar != ''">#{avatar},</if>-->
<!-- 			<if test="phonenumber != null and phonenumber != ''">#{phonenumber},</if>-->
<!-- 			<if test="balance != null and balance != ''">#{balance},</if>-->
<!-- 			<if test="sex != null and sex != ''">#{sex},</if>-->
<!-- 			<if test="password != null and password != ''">#{password},</if>-->
<!-- 			<if test="status != null and status != ''">#{status},</if>-->
<!-- 			<if test="createBy != null and createBy != ''">#{createBy},</if>-->
<!-- 			<if test="remark != null and remark != ''">#{remark},</if>-->
<!-- 			<if test="wxopenid != null and wxopenid != ''">#{wxopenid},</if>-->
<!-- 			sysdate()-->
<!-- 		)-->
<!--	</insert>-->

<!--	<update id="updateUser" parameterType="EUser">-->
<!-- 		update ss_user-->
<!-- 		<set>-->
<!-- 			<if test="userName != null and userName != ''">user_name = #{userName},</if>-->
<!-- 			<if test="realName != null and realName != ''">real_name = #{realName},</if>-->
<!-- 			<if test="idCard != null and idCard != ''">id_card = #{idCard},</if>-->
<!-- 			<if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>-->
<!-- 			<if test="email != null ">email = #{email},</if>-->
<!-- 			<if test="phonenumber != null ">phonenumber = #{phonenumber},</if>-->
<!-- 			<if test="balance != null ">balance = #{balance},</if>-->
<!-- 			<if test="sex != null and sex != ''">sex = #{sex},</if>-->
<!-- 			<if test="avatar != null and avatar != ''">avatar = #{avatar},</if>-->
<!-- 			<if test="password != null and password != ''">password = #{password},</if>-->
<!-- 			<if test="status != null and status != ''">status = #{status},</if>-->
<!-- 			<if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>-->
<!-- 			<if test="loginDate != null">login_date = #{loginDate},</if>-->
<!-- 			<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>-->
<!-- 			<if test="remark != null">remark = #{remark},</if>-->
<!-- 			<if test="wxopenid != null">wxopenid = #{wxopenid},</if>-->
<!-- 			update_time = sysdate()-->
<!-- 		</set>-->
<!-- 		where user_id = #{userId}-->
<!--	</update>-->

<!--	<update id="updateUserStatus" parameterType="EUser">-->
<!-- 		update ss_user set status = #{status} where user_id = #{userId}-->
<!--	</update>-->

<!--	<update id="updateUserAvatar" parameterType="EUser">-->
<!-- 		update ss_user set avatar = #{avatar} where user_name = #{userName}-->
<!--	</update>-->

<!--	<update id="resetUserPwd" parameterType="EUser">-->
<!-- 		update ss_user set password = #{password} where user_name = #{userName}-->
<!--	</update>-->

<!--	<update id="updateUserPwd">-->
<!--		update ss_user set password = #{password} where  user_id = #{userId}-->
<!--	</update>-->

<!--	<delete id="deleteUserById" parameterType="Long">-->
<!-- 		update ss_user set del_flag = '2' where user_id = #{userId}-->
<!-- 	</delete>-->

<!-- 	<delete id="deleteUserByIds" parameterType="Long">-->
<!-- 		update ss_user set del_flag = '2' where user_id in-->
<!-- 		<foreach collection="array" item="userId" open="(" separator="," close=")">-->
<!-- 			#{userId}-->
<!--        </foreach>-->
<!-- 	</delete>-->

</mapper>
