package com.cyksj.service.market.task.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.cyksj.common.EnvCommonService;
import com.cyksj.common.constant.TaskTypeEnum;
import com.cyksj.common.exception.BusinessRuntimeException;
import com.cyksj.common.snowflake.Sequence;
import com.cyksj.common.util.Codec;
import com.cyksj.common.util.Jsons;
import com.cyksj.config.wxlogin.WxOpenPlatYHLXLoginConfig;
import com.cyksj.dto.Result;
import com.cyksj.enums.GatewayApiCode;
import com.cyksj.enums.GatewayResponse;
import com.cyksj.mapper.PhoneCodeMapper;
import com.cyksj.mapper.UserMapper;
import com.cyksj.mapper.market.task.TaskTypeMapper;
import com.cyksj.mapper.market.task.UserBindDetailMapper;
import com.cyksj.model.dto.AuthRedirect;
import com.cyksj.model.entity.PhoneCode;
import com.cyksj.model.entity.TaskType;
import com.cyksj.model.entity.User;
import com.cyksj.model.entity.UserBindDetail;
import com.cyksj.model.request.UserBindInfoReq;
import com.cyksj.redis.RedisService;
import com.cyksj.service.authorization.AuthorizationService;
import com.cyksj.service.market.task.BindTaskService;
import com.cyksj.service.market.task.TaskService;
import com.cyksj.service.user.UserCommonService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Optional;

/*
 *项目名: netflix
 *文件名: BindTaskServiceImpl
 *创建者: JavaZou
 *创建时间:2023/4/13 9:53
 */
@Service
@RequiredArgsConstructor
public class BindTaskServiceImpl implements BindTaskService {
	private final TaskService taskService;

	private final TaskTypeMapper taskTypeMapper;

	private final UserBindDetailMapper userBindDetailMapper;

	private final RedisService redisService;

	private final PhoneCodeMapper phoneCodeMapper;

	private final UserMapper userMapper;

	private final AuthorizationService authorizationService;

	private final EnvCommonService envCommonService;

	private final WxOpenPlatYHLXLoginConfig wxOpenPlatYHLXLoginConfig;

	private final UserCommonService userCommonService;

	private final static Sequence SEQUENCE = new Sequence(0);

	@Override
	public UserBindDetail bindPhone(User user, String phone, String code) {
		Long userId = user.getId();
		if (StrUtil.isNotBlank(user.getLoginPhone())) {
			throw BusinessRuntimeException.getInstance("您通过手机号登录,无法绑定其他手机号");
		}
		LambdaQueryWrapper<UserBindDetail> wrapper = Wrappers.lambdaQuery(UserBindDetail.class)
				.eq(StrUtil.isNotBlank(user.getEmail()), UserBindDetail::getEmail, user.getEmail())
				.eq(StrUtil.isNotBlank(user.getOpenId()), UserBindDetail::getUserId, user.getId())
				.last("limit 1");

		UserBindDetail bindPhone = userBindDetailMapper.selectOne(wrapper);
		if (bindPhone != null && StrUtil.isNotBlank(bindPhone.getPhone())) {
			throw BusinessRuntimeException.getInstance("您已绑定手机号");
		}

		UserBindDetail other = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
				.eq(UserBindDetail::getPhone, phone)
				.ne(StrUtil.isNotBlank(user.getEmail()), UserBindDetail::getEmail, StrUtil.EMPTY)
				.isNotNull(StrUtil.isNotEmpty(user.getUnionid()), UserBindDetail::getUserId)
				.last("limit 1"));
		if (other != null) {
			throw BusinessRuntimeException.getInstance("该手机号已被绑定");
		}
		if (bindPhone == null) {
			bindPhone = Optional.ofNullable(userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
					.eq(UserBindDetail::getPhone, phone).last("limit 1"))).orElse(new UserBindDetail());
		}

		if (StrUtil.isNotBlank(code)) {
			//校验
			checkPhoneCode(phone, code);
		}
		if (StrUtil.isNotBlank(user.getOpenId())) {
			bindPhone.setUserId(userId);
		}
		if (StrUtil.isNotBlank(user.getEmail())) {
			bindPhone.setEmailUserId(userId);
			bindPhone.setEmail(user.getEmail());
		}
		if (bindPhone.getPhoneUserId() == null) {
			Long phoneUserId = user.getPhoneUserId();
			if (phoneUserId == null) {
				User phoneUser = userMapper.selectOne(Wrappers.lambdaQuery(User.class)
						.eq(User::getLoginPhone, phone).last("limit 1"));
				if (phoneUser != null) {
					phoneUserId = phoneUser.getId();
				}
			}
			bindPhone.setPhoneUserId(phoneUserId);
		}
		bindPhone.setPhone(phone);
		if (bindPhone.getId() == null) {
			if (redisService.setNx(RedisService.key.USER_BIND_ACCOUNT_INFO_KEY.getName() + phone, phone, RedisService.key.USER_BIND_ACCOUNT_INFO_KEY.getTimeout())) {
				userBindDetailMapper.insert(bindPhone);
			}
		} else {
			userBindDetailMapper.updateById(bindPhone);
		}
		TaskType taskType = taskTypeMapper.selectOne(Wrappers.lambdaQuery(TaskType.class)
				.eq(TaskType::getName, TaskTypeEnum.bind_phone.getDesc()).last("limit 1"));
		//完成任务
		taskService.completeTask(taskType, userId);
		return bindPhone;
	}

	@Override
	public void updateBindPhone(User user, String phone, String code) {
		Long userId = user.getId();
		LambdaQueryWrapper<UserBindDetail> wrapper = Wrappers.lambdaQuery(UserBindDetail.class).last("limit 1");
		if (StrUtil.isNotBlank(user.getLoginPhone())) {
			throw BusinessRuntimeException.getInstance("无法更换自身登录手机号");
		}
		if (StrUtil.isNotBlank(user.getOpenId())) {
			wrapper.eq(UserBindDetail::getUserId, userId);
		}
		if (StrUtil.isNotBlank(user.getEmail())) {
			wrapper.eq(UserBindDetail::getEmail, user.getEmail());
		}
		UserBindDetail bindPhone = userBindDetailMapper.selectOne(wrapper);
		if (bindPhone == null || StrUtil.isEmpty(bindPhone.getPhone())) {
			throw BusinessRuntimeException.getInstance("您未绑定手机号");
		}
		if (bindPhone.getPhone().equals(phone)) {
			throw BusinessRuntimeException.getInstance("换绑手机号重复");
		}
		UserBindDetail other = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
				.eq(UserBindDetail::getPhone, phone).select(UserBindDetail::getId).last("limit 1"));
		if (other != null) {
			throw BusinessRuntimeException.getInstance("该手机号已被绑定");
		}
		User phoneUser = userMapper.selectOne(Wrappers.lambdaQuery(User.class)
				.eq(User::getLoginPhone, phone).last("limit 1"));
		if (phoneUser == null) {
			phoneUser = userCommonService.insertUser(phone, true);
//			throw BusinessRuntimeException.getInstance("换绑手机号未注册");
		}
		checkPhoneCode(phone, code);
		bindPhone.setPhoneUserId(phoneUser.getId());
		bindPhone.setPhone(phone);

		userBindDetailMapper.update(null, Wrappers.lambdaUpdate(UserBindDetail.class)
				.set(UserBindDetail::getPhone, phone)
				.set(UserBindDetail::getPhoneUserId, bindPhone.getPhoneUserId())
				.eq(UserBindDetail::getId, bindPhone.getId()));
	}

	@Override
	public void updateBindEmail(User user, String email, String inputCode) {
		Long userId = user.getId();
		LambdaQueryWrapper<UserBindDetail> wrapper = Wrappers.lambdaQuery(UserBindDetail.class).last("limit 1");
		if (StrUtil.isNotBlank(user.getEmail())) {
			throw BusinessRuntimeException.getInstance("无法更换自身登录邮箱");
		}
		if (StrUtil.isNotBlank(user.getOpenId())) {
			wrapper.eq(UserBindDetail::getUserId, userId);
		}
		if (StrUtil.isNotBlank(user.getLoginPhone())) {
			wrapper.eq(UserBindDetail::getPhone, user.getLoginPhone());
		}
		UserBindDetail bindDetail = userBindDetailMapper.selectOne(wrapper);
		if (bindDetail == null || StrUtil.isEmpty(bindDetail.getEmail())) {
			throw BusinessRuntimeException.getInstance("您未绑定邮箱");
		}
		if (bindDetail.getEmail().equals(email)) {
			throw BusinessRuntimeException.getInstance("换绑邮箱重复");
		}
		UserBindDetail other = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
				.eq(UserBindDetail::getEmail, email).select(UserBindDetail::getId).last("limit 1"));
		if (other != null) {
			throw BusinessRuntimeException.getInstance("该邮箱已被绑定");
		}
		checkEmailCode(email, inputCode);
		User emailUser = userMapper.selectOne(Wrappers.lambdaQuery(User.class)
				.eq(User::getEmail, email).last("limit 1"));
		if (emailUser == null) {
			emailUser = userCommonService.insertUser(email, false);
//			throw BusinessRuntimeException.getInstance("绑定的邮箱未注册");
		}
		bindDetail.setEmailUserId(emailUser.getId());
		bindDetail.setEmail(email);

		userBindDetailMapper.update(null, Wrappers.lambdaUpdate(UserBindDetail.class)
				.set(UserBindDetail::getEmail, email)
				.set(UserBindDetail::getEmailUserId, bindDetail.getEmailUserId())
				.eq(UserBindDetail::getId, bindDetail.getId()));
	}

	@Override
	public UserBindDetail bindEmail(User user, String account, String inputCode) {
		Long userId = user.getId();
		if (!Validator.isEmail(account)) {
			throw BusinessRuntimeException.getInstance("请输入正确的邮箱");
		}
		if (StrUtil.isNotBlank(user.getEmail())) {
			throw BusinessRuntimeException.getInstance("您通过邮箱登录,无法绑定其他邮箱");
		}
		LambdaQueryWrapper<UserBindDetail> wrapper = Wrappers.lambdaQuery(UserBindDetail.class)
				.eq(StrUtil.isNotBlank(user.getLoginPhone()), UserBindDetail::getPhone, user.getLoginPhone())
				.eq(StrUtil.isNotBlank(user.getOpenId()), UserBindDetail::getUserId, user.getId())
				.last("limit 1");
		UserBindDetail bindPhone = userBindDetailMapper.selectOne(wrapper);
		if (bindPhone != null && StrUtil.isNotBlank(bindPhone.getEmail())) {
			throw BusinessRuntimeException.getInstance("您已绑定邮箱");
		}

		UserBindDetail other = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
				.eq(UserBindDetail::getEmail, account)
				.ne(StrUtil.isNotBlank(user.getPhone()), UserBindDetail::getPhone, StrUtil.EMPTY)
				.isNotNull(StrUtil.isNotBlank(user.getOpenId()), UserBindDetail::getUserId)
				.select(UserBindDetail::getId)
				.last("limit 1"));
		if (other != null) {
			throw BusinessRuntimeException.getInstance("该邮箱已被绑定");
		}
		if (bindPhone == null) {
			bindPhone = Optional.ofNullable(userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
					.eq(UserBindDetail::getEmail, account).last("limit 1"))).orElse(new UserBindDetail());
		}

		if (StrUtil.isNotBlank(inputCode)) {
			checkEmailCode(account, inputCode);
		}
		bindPhone.setEmail(account);
		if (StrUtil.isNotBlank(user.getOpenId())) {
			bindPhone.setUserId(userId);
		}
		if (StrUtil.isNotBlank(user.getLoginPhone())) {
			bindPhone.setPhoneUserId(userId);
			bindPhone.setPhone(user.getLoginPhone());
		}
		if (bindPhone.getEmailUserId() == null) {
			Long emailUserId = user.getEmailUserId();
			if (emailUserId == null) {
				User emailUser = userMapper.selectOne(Wrappers.lambdaQuery(User.class)
						.eq(User::getEmail, account).last("limit 1"));
				if (emailUser != null) {
					emailUserId = emailUser.getId();
				}
			}
			bindPhone.setEmailUserId(emailUserId);
		}
		if (bindPhone.getId() == null) {
			if (redisService.setNx(RedisService.key.USER_BIND_ACCOUNT_INFO_KEY.getName() + account, account, RedisService.key.USER_BIND_ACCOUNT_INFO_KEY.getTimeout())) {
				userBindDetailMapper.insert(bindPhone);
			}
		} else {
			userBindDetailMapper.updateById(bindPhone);
		}
		redisService.del(RedisService.key.EMAIL_CODE_KEY.getNameFormat(account));
		return bindPhone;
	}

	@Override
	public Result<String> bindOtherAccount(UserBindInfoReq request) throws Exception {
		Long userId = request.getUserId();
		User user = userMapper.selectById(userId);
		Integer type = request.getType();
		if (type == null) throw BusinessRuntimeException.getInstance("绑定类型为空");

		if (user == null) throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
		String account = request.getAccount();
		String code = request.getCode();
		if (type != 3 && (StrUtil.isEmpty(account) || StrUtil.isEmpty(code))) {
			throw BusinessRuntimeException.getInstance("请输入正确的绑定信息");
		}
		if (type == 1) {
			if (StrUtil.isNotBlank(user.getLoginPhone())) {
				throw BusinessRuntimeException.getInstance("您通过手机号登录,无法绑定其他手机号");
			}
			User phoneUser = userMapper.selectOne(Wrappers.lambdaQuery(User.class)
					.eq(User::getLoginPhone, account).last("limit 1"));
			if (phoneUser == null) {
				phoneUser = userCommonService.insertUser(account, true);
//				throw BusinessRuntimeException.getInstance("绑定的手机号未注册");
			}
			user.setPhoneUserId(phoneUser.getId());
			bindPhone(user, account, code);
			return GatewayResponse.SUCCESS.newBuilder().toResult();
		}
		if (type == 2) {
			if (StrUtil.isNotBlank(user.getEmail())) {
				throw BusinessRuntimeException.getInstance("您通过邮箱登录,无法绑定其他邮箱");
			}
			User emailUser = userMapper.selectOne(Wrappers.lambdaQuery(User.class)
					.eq(User::getEmail, account).last("limit 1"));
			if (emailUser == null) {
				emailUser = userCommonService.insertUser(account, false);
//				throw BusinessRuntimeException.getInstance("绑定的邮箱未注册");
			}
			user.setEmailUserId(emailUser.getId());
			bindEmail(user, account, code);
			return GatewayResponse.SUCCESS.newBuilder().toResult();
		}
		if (type == 3) {
			if (StrUtil.isNotBlank(user.getOpenId())) {
				throw BusinessRuntimeException.getInstance("您通过微信登录,无法绑定其他微信");
			}
			//网页授权二维码
			Long mappingId = SEQUENCE.nextId();
			AuthRedirect redirect = new AuthRedirect()
					.setMappingId(mappingId)
					.setLp(user.getLoginPhone())
					.setLe(user.getEmail());
			String returnUrl = request.getReturnUrl();
			String envType = request.getEnvType();
			if (StrUtil.isNotBlank(returnUrl)) {
				if (StrUtil.isNotBlank(envType)) {
					returnUrl = envCommonService.getDomain() + envType + "/web/" + returnUrl;
				} else {
					returnUrl = envCommonService.getDomain() + "/web/" + returnUrl;
				}
			}
			redisService.set(mappingId.toString(), returnUrl, 60 * 60 * 24L);
			String redirectUrl = wxOpenPlatYHLXLoginConfig.getBaRedirectUrl();
			String state = Codec.DoBase64.custom().setData(Jsons.toJson(redirect)).encodeAsText();
			String wxAuthUrl = authorizationService.createWxAuthLoginUrl(state, wxOpenPlatYHLXLoginConfig.getAppId(), redirectUrl);
			return GatewayResponse.SUCCESS.newBuilder().toResult(wxAuthUrl);
		}
		return GatewayResponse.SUCCESS.newBuilder().toResult();
	}

	@Override
	public void updateBindAccount(UserBindInfoReq request) {
		Long userId = request.getUserId();
		User user = userMapper.selectById(userId);
		String account = request.getAccount();
		String code = request.getCode();
		if (Validator.isMobile(account)) {
			updateBindPhone(user, account, code);
			return;
		}
		if (Validator.isEmail(account)) {
			updateBindEmail(user, account, code);
		}

	}

	@Override
	public void checkPhoneCode(String phone, String inputCode) {
		DateTime now = DateTime.now();
		PhoneCode phoneCode = phoneCodeMapper.selectOne(Wrappers.lambdaQuery(PhoneCode.class).eq(PhoneCode::getPhone, phone).last("limit 1"));
		if (phoneCode == null || StrUtil.isEmpty(phoneCode.getCode())) {
			throw BusinessRuntimeException.getInstance("请重新获取手机验证码");
		}
		//3分钟失效
		Date updateTime = phoneCode.getUpdateTime();
		DateTime afterFiveMinutes = DateUtil.offsetMinute(updateTime, 3);
		if (now.isAfter(afterFiveMinutes)) {
			throw BusinessRuntimeException.getInstance("手机验证码已失效,请重新获取");
		}
		if (!StrUtil.equals(inputCode, phoneCode.getCode())) {
			throw BusinessRuntimeException.getInstance("手机验证码错误,请重新输入");
		}
	}

	@Override
	public void checkEmailCode(String email, String inputCode) {
		String code = redisService.getStr(RedisService.key.EMAIL_CODE_KEY.getNameFormat(email));
		if (StrUtil.isEmpty(code)) {
			throw BusinessRuntimeException.getInstance("邮箱验证码已失效,请重新获取");
		}
		if (!StrUtil.equals(inputCode, code)) {
			throw BusinessRuntimeException.getInstance("邮箱验证码错误,请重新输入");
		}
	}

	@Override
	public void changeBindAccount(UserBindInfoReq request) {
		Long userId = request.getUserId();
		User user = userMapper.selectById(userId);
		if (user == null) throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
		String account = request.getAccount();
		String code = request.getCode();
		Integer type = request.getType();
		if (type == 1) {
			//校验手机号
			checkPhoneCode(account, code);
			String loginPhone = user.getLoginPhone();
			User phoneUser = user;
			Long phoneUserId = phoneUser.getId();
			//手机用户
			if (StrUtil.isNotBlank(loginPhone)) {
				//是否已注册
				User changeUser = userMapper.selectOne(Wrappers.lambdaQuery(User.class)
						.eq(User::getLoginPhone, account).last("limit 1"));
				if (changeUser != null) {
					throw BusinessRuntimeException.getInstance("您更换的手机号已注册,无法更换");
				}
				//是否已绑定
				UserBindDetail changeUserBindDetail = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
						.eq(UserBindDetail::getPhone, account).last("limit 1"));
				if (changeUserBindDetail != null) {
					throw BusinessRuntimeException.getInstance("您更换的手机号已被绑定,无法更换");
				}
				UserBindDetail userBindDetail = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
						.eq(UserBindDetail::getPhone, loginPhone).last("limit 1"));
				if (userBindDetail != null) {
					userBindDetail.setPhone(account);
					userBindDetail.setPhoneUserId(phoneUserId);
					userBindDetailMapper.updateById(userBindDetail);
				}
				user.setLoginPhone(account);
				userMapper.updateById(user);
				return;
			}
			//非手机用户
			UserBindDetail userBindDetail = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
					.and(qr -> qr.eq(UserBindDetail::getUserId, userId)
							.or().eq(UserBindDetail::getEmailUserId, userId))
					.last("limit 1"));
			if (userBindDetail == null) {
				throw BusinessRuntimeException.getInstance("你未有绑定其他账号");
			}
			if (StrUtil.isEmpty(userBindDetail.getPhone())) {
				throw BusinessRuntimeException.getInstance("您未绑定手机号,无法更换");
			}
			User toBIndPhone = userMapper.selectOne(Wrappers.lambdaQuery(User.class)
					.eq(User::getLoginPhone, account)
					.last("limit 1"));
			if (toBIndPhone != null) {
				throw BusinessRuntimeException.getInstance("您要换绑的手机号已经注册");
			}
			String phone = userBindDetail.getPhone();
			phoneUser = userMapper.selectOne(Wrappers.lambdaQuery(User.class)
					.eq(User::getLoginPhone, phone).last("limit 1"));
			if (phoneUser == null) throw BusinessRuntimeException.getInstance("你绑定的手机号未注册");
			phoneUserId = phoneUser.getId();
			userBindDetail.setPhone(account);
			userBindDetail.setPhoneUserId(phoneUserId);
			userBindDetailMapper.updateById(userBindDetail);

			phoneUser.setLoginPhone(account);
			userMapper.updateById(phoneUser);
			return;
		}

		if (type == 2) {
			//校验邮箱
			checkEmailCode(account, code);
			String email = user.getEmail();
			User emailUser = user;
			Long emailUserId = emailUser.getId();
			//邮箱用户
			if (StrUtil.isNotBlank(email)) {
				//是否已注册
				User changeUser = userMapper.selectOne(Wrappers.lambdaQuery(User.class)
						.eq(User::getEmail, account).last("limit 1"));
				if (changeUser != null) {
					throw BusinessRuntimeException.getInstance("您更换的邮箱已注册,无法更换");
				}
				//是否已绑定
				UserBindDetail changeUserBindDetail = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
						.eq(UserBindDetail::getEmail, account).last("limit 1"));
				if (changeUserBindDetail != null) {
					throw BusinessRuntimeException.getInstance("您更换的邮箱已被绑定,无法更换");
				}
				UserBindDetail userBindDetail = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
						.eq(UserBindDetail::getEmail, email).last("limit 1"));
				if (userBindDetail != null) {
					userBindDetail.setEmail(account);
					userBindDetail.setEmailUserId(emailUserId);
					userBindDetailMapper.updateById(userBindDetail);
				}
				user.setEmail(account);
				userMapper.updateById(user);
				return;
			}
			//非邮箱用户
			UserBindDetail userBindDetail = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
					.and(qr -> qr.eq(UserBindDetail::getUserId, userId)
							.or().eq(UserBindDetail::getPhoneUserId, userId))
					.last("limit 1"));
			if (userBindDetail == null) {
				throw BusinessRuntimeException.getInstance("你未有绑定其他账号");
			}
			if (StrUtil.isEmpty(userBindDetail.getEmail())) {
				throw BusinessRuntimeException.getInstance("您未绑定邮箱,无法更换");
			}
			User toBIndEmail = userMapper.selectOne(Wrappers.lambdaQuery(User.class)
					.eq(User::getEmail, account)
					.last("limit 1"));
			if (toBIndEmail != null) {
				throw BusinessRuntimeException.getInstance("您要换绑的邮箱已经注册");
			}
			email = userBindDetail.getEmail();
			emailUser = userMapper.selectOne(Wrappers.lambdaQuery(User.class)
					.eq(User::getEmail, email).last("limit 1"));
			if (emailUser == null) throw BusinessRuntimeException.getInstance("你绑定的邮箱未注册");
			emailUserId = emailUser.getId();
			userBindDetail.setEmail(account);
			userBindDetail.setEmailUserId(emailUserId);
			userBindDetailMapper.updateById(userBindDetail);

			emailUser.setEmail(account);
			userMapper.updateById(emailUser);
			return;
		}
	}
}
