添加邮箱发送验证码的业务实现

This commit is contained in:
Dftre 2024-06-09 11:54:50 +08:00
parent 4c15dfef9e
commit 57ca64b0f7
14 changed files with 361 additions and 135 deletions

View File

@ -1,12 +1,4 @@
spring:
cache:
redis:
# 指定存活时间ms
time-to-live: 86400000
# 指定前缀
use-key-prefix: true
# 是否缓存空值,可以防止缓存穿透
cache-null-values: true
data:
# redis 配置
redis:

View File

@ -16,3 +16,11 @@ oauth:
dysms:
appId: appId
appSecret: appSecret
spring:
mail:
host: smtp.qq.com
# 邮箱地址
username: username
# 授权码
password: password

View File

@ -50,6 +50,13 @@ spring:
cache:
# 指定缓存类型 jcache 本地缓存 redis 缓存
type: redis
redis:
# 指定存活时间ms
time-to-live: 86400000
# 指定前缀
use-key-prefix: true
# 是否缓存空值,可以防止缓存穿透
cache-null-values: true
mvc:
pathmatch:
matching-strategy: ANT_PATH_MATCHER

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ruoyi-oauth</artifactId>
<groupId>com.ruoyi</groupId>
@ -22,6 +21,21 @@
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-oauth-common</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>jakarta.mail</groupId>
<artifactId>jakarta.mail-api</artifactId>
<version>1.6.7</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<version>1.6.7</version>
</dependency>
</dependencies>

View File

@ -0,0 +1,19 @@
package com.ruoyi.oauth.email.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.oauth.email.service.IMailService;
@RestController
@Anonymous
@RequestMapping("/mail")
public class MailController extends BaseController {
@Autowired
IMailService serviceImpl;
}

View File

@ -0,0 +1,7 @@
package com.ruoyi.oauth.email.service;
import com.ruoyi.oauth.common.service.OauthVerificationCodeService;
public interface IMailService extends OauthVerificationCodeService {
public boolean sendMimeMail(String email, String code);
}

View File

@ -0,0 +1,153 @@
package com.ruoyi.oauth.email.service.impl;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.CacheUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.framework.web.service.UserDetailsServiceImpl;
import com.ruoyi.oauth.common.enums.OauthVerificationUse;
import com.ruoyi.oauth.email.service.IMailService;
import com.ruoyi.system.service.ISysUserService;
@Service
public class MailServiceImpl implements IMailService {
public String CACHE_NAME = "mail_codes";
@Autowired
private JavaMailSenderImpl mailSender;
@Autowired
private ISysUserService userService;
@Autowired
private TokenService tokenService;
@Autowired
private UserDetailsServiceImpl userDetailsServiceImpl;
private static final Logger log = LoggerFactory.getLogger(MailServiceImpl.class);
// application.properties配置的值
@Value("${spring.mail.username}")
private String from;
public boolean beforeSendCode(String email, OauthVerificationUse use) throws Exception {// 1.查验手机号是否存在分辨登录和删除用户以及注册用户
boolean haveEmailFlag = userService.selectUserByEmail(email) != null;
if ((use.equals(OauthVerificationUse.LOGIN) || use.equals(OauthVerificationUse.DISABLE)
|| use.equals(OauthVerificationUse.RESET_PASSWORD)) && !haveEmailFlag) {
throw new ServiceException("该邮箱未绑定用户");
} else if ((use.equals(OauthVerificationUse.REGISTER) || use.equals(OauthVerificationUse.RESET_PHONE))
&& haveEmailFlag) {
throw new ServiceException("该邮箱已绑定用户");
}
return true;
}
/**
* 给前端输入的邮箱发送验证码
*
* @param email
* @param session
* @return
*/
@Override
public boolean sendMimeMail(String email, String code) {
try {
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
simpleMailMessage.setSubject("验证码邮件"); // 主题
simpleMailMessage.setText("您收到的验证码是:" + code); // 内容
simpleMailMessage.setFrom(from); // 发件人
simpleMailMessage.setTo(email); // 收件人
mailSender.send(simpleMailMessage); // 发送
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 随机生成6位数的验证码
*
* @return String code
*/
public static String generateRandomString(int n) {
String characters = "0123456789"; // ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
StringBuilder result = new StringBuilder();
Random random = new Random();
for (int i = 0; i < n; i++) {
int index = random.nextInt(characters.length());
result.append(characters.charAt(index));
}
return result.toString();
}
@Override
public boolean sendCode(String email, String code, OauthVerificationUse use) throws Exception {
// 限制短信一分钟只能发送一次短信
if (CacheUtils.hasKey(CACHE_NAME, email + use.getValue())) {
throw new ServiceException("请在1分钟后再发送短信");
}
try {
sendMimeMail(email, code);
CacheUtils.put(CACHE_NAME, email + use.getValue(), code, 1, TimeUnit.MINUTES);
log.info("发送邮箱验证码成功:{ phone: " + email + " code:" + code + "}");
return true;
} catch (Exception e) {
log.error("发送邮箱验证码异常:" + email);
throw e;
}
}
@Override
public String checkCode(String email, String code, OauthVerificationUse use) throws Exception {
String cachedCode = CacheUtils.get(use.getValue(), use.getValue() + email, String.class); // 从缓存中获取验证码
CacheUtils.remove(use.getValue(), use.getValue() + email);
boolean haveEmailFlag = userService.selectUserByEmail(email) != null;
if (use.equals(OauthVerificationUse.LOGIN) && haveEmailFlag) {// 登录校验
if (code.equals(cachedCode)) {
SysUser sysUser = userService.selectUserByEmail(email);
LoginUser loginUser = (LoginUser) userDetailsServiceImpl.createLoginUser(sysUser);
return tokenService.createToken(loginUser);
} else {
throw new ServiceException("验证码错误");
}
} else if (use.equals(OauthVerificationUse.REGISTER) && !haveEmailFlag) {// 注册校验
if (code.equals(cachedCode)) {
return Boolean.toString(true);
} else {
throw new ServiceException("验证码错误");
}
} else if (use.equals(OauthVerificationUse.DISABLE) && haveEmailFlag) {// 注销校验
if (code.equals(cachedCode)) {
return Boolean.toString(true);
} else {
throw new ServiceException("验证码错误");
}
} else if (use.equals(OauthVerificationUse.RESET_PASSWORD) && haveEmailFlag) {// 重置密码校验
if (code.equals(cachedCode)) {
return Boolean.toString(true);
} else {
throw new ServiceException("验证码错误");
}
} else if (use.equals(OauthVerificationUse.RESET_PHONE) && !haveEmailFlag) {// 重置账号校验
if (code.equals(cachedCode)) {
return Boolean.toString(true);
} else {
throw new ServiceException("验证码错误");
}
}
return Boolean.toString(false);
}
}

View File

@ -1,6 +1,6 @@
package com.ruoyi.oauth.phone.service;
import com.ruoyi.oauth.common.enums.OauthVerificationUse;
import com.ruoyi.oauth.common.service.OauthVerificationCodeService;
/**
* 手机号认证Servcie
@ -8,14 +8,7 @@ import com.ruoyi.oauth.common.enums.OauthVerificationUse;
* @author zlh
* @date 2024-04-16
*/
public interface DySmsService {
public interface DySmsService extends OauthVerificationCodeService {
public String doLogin(String phone);
public boolean sendCode(String phone, String code, OauthVerificationUse use) throws Exception;
public String checkCode(String phone, String code, OauthVerificationUse use) throws Exception;
// public String doenroll(String phone,String username, String password);
}

View File

@ -16,7 +16,6 @@ import com.ruoyi.common.utils.CacheUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.framework.web.service.UserDetailsServiceImpl;
import com.ruoyi.oauth.common.enums.OauthVerificationUse;
import com.ruoyi.oauth.common.service.OauthVerificationCodeService;
import com.ruoyi.oauth.phone.enums.DySmsTemplate;
import com.ruoyi.oauth.phone.service.DySmsService;
import com.ruoyi.oauth.phone.utils.DySmsUtil;
@ -29,7 +28,7 @@ import com.ruoyi.system.service.ISysUserService;
* @date 2024-04-16
*/
@Service
public class DySmsServiceImpl implements DySmsService, OauthVerificationCodeService {
public class DySmsServiceImpl implements DySmsService {
@Autowired
private DySmsUtil dySmsUtil;
@ -79,6 +78,7 @@ public class DySmsServiceImpl implements DySmsService, OauthVerificationCodeServ
@Override
public String checkCode(String phone, String code, OauthVerificationUse use) throws Exception {
String cachedCode = CacheUtils.get(use.getValue(), use.getValue() + phone, String.class); // 从缓存中获取验证码
CacheUtils.remove(use.getValue(), use.getValue() + phone);
boolean havePhoneFlag = userService.selectUserByPhone(phone) != null;
if (use.equals(OauthVerificationUse.LOGIN) && havePhoneFlag) {// 登录校验
if (code.equals(cachedCode)) {

View File

@ -10,6 +10,7 @@ import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson2.JSON;
@ -22,6 +23,7 @@ import com.ruoyi.pay.domain.PayOrder;
import com.ruoyi.pay.sqb.config.SqbConfig;
@Service
@ConditionalOnProperty(prefix = "pay.sqb", name = "enabled", havingValue = "true")
public class SQBServiceImpl {
@Autowired
private SqbConfig sqbConfig;

View File

@ -11,8 +11,7 @@ import com.ruoyi.common.core.domain.entity.SysUser;
*
* @author ruoyi
*/
public interface SysUserMapper
{
public interface SysUserMapper {
/**
* 根据条件分页查询用户列表
*
@ -56,11 +55,19 @@ public interface SysUserMapper
/**
* 通过手机号查询用户
*
* @param userId 用户ID
* @param phone 手机号
* @return 用户对象信息
*/
public SysUser selectUserByPhone(String phone);
/**
* 通过邮箱查询用户
*
* @param email 邮箱
* @return 用户对象信息
*/
public SysUser selectUserByEmail(String email);
/**
* 新增用户信息
*
@ -81,7 +88,7 @@ public interface SysUserMapper
* 修改用户头像
*
* @param userName 用户名
* @param avatar 头像地址
* @param avatar 头像地址
* @return 结果
*/
public int updateUserAvatar(@Param("userName") String userName, @Param("avatar") String avatar);

View File

@ -58,6 +58,14 @@ public interface ISysUserService {
*/
public SysUser selectUserByPhone(String phone);
/**
* 通过邮箱查询用户
*
* @param userName 用户名
* @return 用户对象信息
*/
public SysUser selectUserByEmail(String email);
/**
* 根据用户ID查询用户所属角色组
*

View File

@ -124,7 +124,7 @@ public class SysUserServiceImpl implements ISysUserService {
/**
* 通过手机号查询用户
*
* @param userId 用户ID
* @param phone 用户ID
* @return 用户对象信息
*/
@Override
@ -132,6 +132,17 @@ public class SysUserServiceImpl implements ISysUserService {
return userMapper.selectUserByPhone(phone);
}
/**
* 通过邮箱查询用户
*
* @param email 用户名
* @return 用户对象信息
*/
@Override
public SysUser selectUserByEmail(String email){
return userMapper.selectUserByEmail(email);
}
/**
* 查询用户所属角色组
*

View File

@ -4,48 +4,48 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.SysUserMapper">
<resultMap type="SysUser" id="SysUserResult">
<id property="userId" column="user_id" />
<result property="deptId" column="dept_id" />
<result property="userName" column="user_name" />
<result property="nickName" column="nick_name" />
<result property="email" column="email" />
<result property="phonenumber" column="phonenumber" />
<result property="sex" column="sex" />
<result property="avatar" column="avatar" />
<result property="password" column="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" />
<association property="dept" column="dept_id" javaType="SysDept" resultMap="deptResult" />
<collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
</resultMap>
<resultMap id="deptResult" type="SysDept">
<id property="deptId" column="dept_id" />
<result property="parentId" column="parent_id" />
<result property="deptName" column="dept_name" />
<result property="ancestors" column="ancestors" />
<result property="orderNum" column="order_num" />
<result property="leader" column="leader" />
<result property="status" column="dept_status" />
</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>
<resultMap type="SysUser" id="SysUserResult">
<id property="userId" column="user_id" />
<result property="deptId" column="dept_id" />
<result property="userName" column="user_name" />
<result property="nickName" column="nick_name" />
<result property="email" column="email" />
<result property="phonenumber" column="phonenumber" />
<result property="sex" column="sex" />
<result property="avatar" column="avatar" />
<result property="password" column="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" />
<association property="dept" column="dept_id" javaType="SysDept" resultMap="deptResult" />
<collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
</resultMap>
<resultMap id="deptResult" type="SysDept">
<id property="deptId" column="dept_id" />
<result property="parentId" column="parent_id" />
<result property="deptName" column="dept_name" />
<result property="ancestors" column="ancestors" />
<result property="orderNum" column="order_num" />
<result property="leader" column="leader" />
<result property="status" column="dept_status" />
</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.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status,
@ -54,9 +54,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
left join sys_dept d on u.dept_id = d.dept_id
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>
<select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">
</sql>
<select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u
left join sys_dept d on u.dept_id = d.dept_id
where u.del_flag = '0'
@ -72,10 +72,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="phonenumber != null and phonenumber != ''">
AND u.phonenumber like concat('%', #{phonenumber}, '%')
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
<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 != ''"><!-- 结束时间检索 -->
<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="deptId != null and deptId != 0">
@ -84,7 +84,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
<select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult">
select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time
from sys_user u
@ -92,7 +92,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
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 != ''">
<if test="userName != null and userName != ''">
AND u.user_name like concat('%', #{userName}, '%')
</if>
<if test="phonenumber != null and phonenumber != ''">
@ -101,7 +101,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
<select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult">
select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time
from sys_user u
@ -110,7 +110,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
left join sys_role r on r.role_id = ur.role_id
where u.del_flag = '0' and (r.role_id != #{roleId} or r.role_id IS NULL)
and u.user_id not in (select u.user_id from sys_user u inner join sys_user_role ur on u.user_id = ur.user_id and ur.role_id = #{roleId})
<if test="userName != null and userName != ''">
<if test="userName != null and userName != ''">
AND u.user_name like concat('%', #{userName}, '%')
</if>
<if test="phonenumber != null and phonenumber != ''">
@ -119,12 +119,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
<select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">
<include refid="selectUserVo"/>
<include refid="selectUserVo"/>
where u.user_name = #{userName} and u.del_flag = '0'
</select>
<select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
<include refid="selectUserVo"/>
where u.user_id = #{userId}
@ -134,93 +134,98 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectUserVo"/>
where u.phonenumber = #{phone}
</select>
<select id="selectUserByEmail" parameterType="String" resultMap="SysUserResult">
<include refid="selectUserVo"/>
where u.email = #{email}
</select>
<select id="checkUserNameUnique" parameterType="String" resultMap="SysUserResult">
select user_id, user_name from sys_user where user_name = #{userName} and del_flag = '0' limit 1
</select>
<select id="checkPhoneUnique" parameterType="String" resultMap="SysUserResult">
select user_id, phonenumber from sys_user where phonenumber = #{phonenumber} and del_flag = '0' limit 1
</select>
<select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
select user_id, email from sys_user where email = #{email} and del_flag = '0' limit 1
</select>
<insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
insert into sys_user(
<if test="userId != null and userId != 0">user_id,</if>
<if test="deptId != null and deptId != 0">dept_id,</if>
<if test="userName != null and userName != ''">user_name,</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="userId != null and userId != 0">user_id,</if>
<if test="deptId != null and deptId != 0">dept_id,</if>
<if test="userName != null and userName != ''">user_name,</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>
create_time
)values(
<if test="userId != null and userId != ''">#{userId},</if>
<if test="deptId != null and deptId != ''">#{deptId},</if>
<if test="userName != null and userName != ''">#{userName},</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="userId != null and userId != ''">#{userId},</if>
<if test="deptId != null and deptId != ''">#{deptId},</if>
<if test="userName != null and userName != ''">#{userName},</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>
sysdate()
)
</insert>
<update id="updateUser" parameterType="SysUser">
update sys_user
<set>
<if test="deptId != null and deptId != 0">dept_id = #{deptId},</if>
<if test="userName != null and userName != ''">user_name = #{userName},</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="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>
<set>
<if test="deptId != null and deptId != 0">dept_id = #{deptId},</if>
<if test="userName != null and userName != ''">user_name = #{userName},</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="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>
update_time = sysdate()
</set>
</set>
where user_id = #{userId}
</update>
<update id="updateUserStatus" parameterType="SysUser">
update sys_user set status = #{status} where user_id = #{userId}
</update>
<update id="updateUserAvatar" parameterType="SysUser">
update sys_user set avatar = #{avatar} where user_name = #{userName}
</update>
<update id="resetUserPwd" parameterType="SysUser">
update sys_user set password = #{password} where user_name = #{userName}
</update>
<delete id="deleteUserById" parameterType="Long">
update sys_user set del_flag = '2' where user_id = #{userId}
</delete>
<delete id="deleteUserByIds" parameterType="Long">
</delete>
<delete id="deleteUserByIds" parameterType="Long">
update sys_user set del_flag = '2' where user_id in
<foreach collection="array" item="userId" open="(" separator="," close=")">
<foreach collection="array" item="userId" open="(" separator="," close=")">
#{userId}
</foreach>
</delete>
</foreach>
</delete>
</mapper>