|
@@ -20,6 +20,7 @@ import cn.hutool.crypto.SecureUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -32,6 +33,7 @@ import java.util.concurrent.TimeUnit;
|
|
|
* @description 登录 Service 层
|
|
|
*/
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
|
public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
@@ -217,4 +219,43 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
|
return Response.success(true);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 登录前重置密码
|
|
|
+ *
|
|
|
+ * @param personnelUserName 人员账号
|
|
|
+ */
|
|
|
+ public void reSetPasswordBeforeLogin(String personnelUserName) {
|
|
|
+ log.info("开始处理【登录前重置密码】的业务,参数为:{}", personnelUserName);
|
|
|
+
|
|
|
+ //检查账号是否存在,若不存在则返回提示"账号不存在,请检查账号是否输入正确"
|
|
|
+ Personnel personnel = this.getOne(new LambdaQueryWrapper<Personnel>().eq(Personnel::getPersonnelUserName, personnelUserName).last("LIMIT 1"));
|
|
|
+ if (personnel == null) {
|
|
|
+ ThrowException.throwXiaoShiException("该账号不存在或已被禁用,请检查账号是否输入正确");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //检查邮箱是否存在,若没有邮箱则返回提示"该账号未绑定邮箱无法重置密码,您可在登陆后进行密码重置"
|
|
|
+ String personnelEmail = personnel.getPersonnelEmail();
|
|
|
+ if (personnelEmail == null || personnelEmail.trim().equals("")) {
|
|
|
+ ThrowException.throwXiaoShiException("该账号未绑定邮箱无法重置密码,您可在登陆后进行密码重置");
|
|
|
+ }
|
|
|
+
|
|
|
+ //重置密码,发送邮件通知
|
|
|
+ int tem = (int) ((Math.random() * 9 + 1) * 100000);
|
|
|
+ String newPassword = String.valueOf(tem);
|
|
|
+ personnel.setPersonnelPassword(SecureUtil.md5(newPassword));
|
|
|
+ if (personnel.updateById()) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("title", "密码重置通知");
|
|
|
+ map.put("template", "mail/email.html");
|
|
|
+ map.put("value1", newPassword);
|
|
|
+ map.put("img", "/logo.png");
|
|
|
+ map.put("email", personnelEmail);
|
|
|
+ map.put("value2", personnel.getPersonnelName());
|
|
|
+ mailUtils.sendEmailMessage(map);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|