学生管理+个人中心邮箱绑定手机绑定

hehai
mzh820631607 4 years ago
parent 05e9786c62
commit 67dba3d9dd
  1. 48
      pom.xml
  2. 6
      src/main/java/com/msdw/tms/api/StudentControllerApi.java
  3. 15
      src/main/java/com/msdw/tms/api/UserControllerApi.java
  4. 33
      src/main/java/com/msdw/tms/config/CheckCodeQuartzConfig.java
  5. 39
      src/main/java/com/msdw/tms/config/CheckCodeUtils.java
  6. 52
      src/main/java/com/msdw/tms/config/EmailUtils.java
  7. 91
      src/main/java/com/msdw/tms/config/SendSMS.java
  8. 24
      src/main/java/com/msdw/tms/config/quartz/CheckCodeQuartz.java
  9. 45
      src/main/java/com/msdw/tms/controller/StudentController.java
  10. 119
      src/main/java/com/msdw/tms/controller/UserController.java
  11. 9
      src/main/java/com/msdw/tms/dao/StudentDao.java
  12. 23
      src/main/java/com/msdw/tms/dao/UserDao.java
  13. 2
      src/main/java/com/msdw/tms/entity/StudentEntity.java
  14. 29
      src/main/java/com/msdw/tms/entity/vo/CheckVo.java
  15. 8
      src/main/java/com/msdw/tms/entity/vo/StudentVo.java
  16. 8
      src/main/java/com/msdw/tms/service/StudentService.java
  17. 26
      src/main/java/com/msdw/tms/service/UserService.java
  18. 36
      src/main/java/com/msdw/tms/service/impl/StudentServiceImpl.java
  19. 100
      src/main/java/com/msdw/tms/service/impl/UserServiceImpl.java
  20. 50
      src/main/resources/mapper/tms/StudentDao.xml
  21. 97
      src/main/resources/mapper/tms/UserDao.xml
  22. 4
      src/main/resources/mapper/tms/UserInfoDao.xml
  23. 27
      src/test/java/com/msdw/tms/EmaiTest.java
  24. 20
      src/test/java/com/msdw/tms/service/StudentTest.java

@ -150,6 +150,54 @@
<artifactId>spring-boot-configuration-processor</artifactId> <artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.8.3</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
<!--阿里云-->
<!-- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-core -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.0.8</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-dysmsapi</artifactId>
<version>1.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

@ -23,4 +23,10 @@ public interface StudentControllerApi {
@ApiOperation(value = "编辑学生信息",notes = "编辑学生信息") @ApiOperation(value = "编辑学生信息",notes = "编辑学生信息")
public R updateStudent(StudentVo studentVo); public R updateStudent(StudentVo studentVo);
@ApiOperation(value = "重置密码",notes = "重置密码")
public R reSetPassword(Integer userId);
@ApiOperation(value = "禁用账号",notes = "禁用账号")
public R disableAccount(Integer userId);
} }

@ -2,10 +2,14 @@ package com.msdw.tms.api;
import com.msdw.tms.common.utils.R; import com.msdw.tms.common.utils.R;
import com.msdw.tms.entity.UserEntity; import com.msdw.tms.entity.UserEntity;
import com.msdw.tms.entity.vo.CheckVo;
import com.msdw.tms.entity.vo.UserEntityVo; import com.msdw.tms.entity.vo.UserEntityVo;
import com.msdw.tms.entity.vo.UserProsonalEntityVo; import com.msdw.tms.entity.vo.UserProsonalEntityVo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List; import java.util.List;
@ -21,4 +25,15 @@ public interface UserControllerApi {
@ApiOperation(value = "更新密码",notes = "更新密码") @ApiOperation(value = "更新密码",notes = "更新密码")
R examinePassword(UserEntityVo entity); R examinePassword(UserEntityVo entity);
@ApiOperation(value = "发送邮箱验证码", notes = "发送邮箱验证码")
public R sendEmailCode(CheckVo checkVo);
@ApiOperation(value = "邮箱验证并更新",notes = "邮箱验证并更新")
public R bindEmail(CheckVo checkVo);
@ApiOperation(value = "发送手机验证码",notes = "发送手机验证码")
R sendPhoneCode(CheckVo checkVo);
@ApiOperation(value = "校验手机验证码",notes = "校验手机验证码")
R bindPhone(CheckVo checkVo);
} }

@ -0,0 +1,33 @@
package com.msdw.tms.config;
import com.msdw.tms.config.quartz.CheckCodeQuartz;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class CheckCodeQuartzConfig {
//定义任务详情
@Bean
public JobDetail orderjobDetail() {
//指定job的名称和持久化保存任务
return JobBuilder
.newJob(CheckCodeQuartz.class) //自定义任务
.withIdentity("checkCodeQuartz") //为任务定义名称
.storeDurably()
.build();
}
//定义触发器
@Bean
public Trigger orderTrigger() {
//通知调度器,程序多久执行一次
CronScheduleBuilder scheduleBuilder
// = CronScheduleBuilder.cronSchedule("5/20 * * ? * *"); //时间表达式 每分钟的5,25秒执行任务
= CronScheduleBuilder.cronSchedule("0 0 18 * * ? "); //时间表达式,每天的18点执行任务
return TriggerBuilder
.newTrigger()
.forJob(orderjobDetail())
.withIdentity("checkCodeQuartz")
.withSchedule(scheduleBuilder).build();
}
}

@ -0,0 +1,39 @@
package com.msdw.tms.config;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
public class CheckCodeUtils {
/**
* 获取六位随机数验证码
* @return
*/
public String sendCode(){
Random random = new Random();
String code="";
for (int i=0;i<6;i++)
{
code+=random.nextInt(10);
}
return code;
}
/**
* 生成时间
*/
public String letTimes(int letTime){
Calendar instance = Calendar.getInstance();
instance.add(Calendar.MINUTE,+letTime);
Date time = instance.getTime();
SimpleDateFormat myFmt=new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
String format1 = myFmt.format(time);
return format1;
}
}

@ -0,0 +1,52 @@
package com.msdw.tms.config;
import org.apache.commons.mail.HtmlEmail;
import java.util.Random;
/**
* 邮箱验证工具
*/
public class EmailUtils {
//服务器地址
private static final String SERVER_ADDRESS = "smtp.163.com";
//邮箱地址
private static final String EMAILADDRESS = "mzh820631607@163.com";
//发送人姓名
private static final String EMAILUSERNAME = "michonne";
//授权码
private static final String AUTHORIZATION_CODE = "ZPAASKPCYJDIFFDR";
//邮件标题
private static final String EMAILHEAD = "京喜";
//邮件信息(后接验证码)头部信息
private static final String EMAILMASSAGEHEAD = "尊敬的用户您好,您本次注册的验证码是: ";
//邮件信息(后接验证码)尾部信息
private static final String EMAILMASSAGETAIL = ",有效时间为5分钟";
//邮箱验证码
public static boolean sendEmail(String emailaddress,String code){
try {
HtmlEmail email = new HtmlEmail();
email.setHostName(SERVER_ADDRESS);
email.setCharset("UTF-8");
email.addTo(emailaddress);
email.setFrom(EMAILADDRESS, EMAILUSERNAME);
email.setAuthentication(EMAILADDRESS, AUTHORIZATION_CODE);
email.setSubject(EMAILHEAD);
email.setMsg( EMAILMASSAGEHEAD + code + EMAILMASSAGETAIL);
email.send();
return true;
}
catch(Exception e){
e.printStackTrace();
return false;
}
}
}

@ -0,0 +1,91 @@
package com.msdw.tms.config;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class SendSMS {
// 短信模板id,此处将其封装为变量,是为了由该方法的调用者决定自己来发送哪种类型的短信验证码,比如注册,重置密码类的
private static final String PHONSMSTEMPLATE = "SMS_204155294";
public static void main(String[] args){
String mobile="17376370737";//需要接受短信验证码的手机号
// String sendTemplate="SMS_204155294";//短信模板ID,需要去阿里云平台申请,审核通过后方能使用,通常是以"SMS_"开头字符串
String code = (int)((Math.random() * 9 + 1) * 100000)+ "";//要发送给用户的短信验证码,行业通常使用六位纯数字
boolean result= sendCode(mobile,code);
if(result){
System.out.println("短信发送成功");
}else{
System.out.println("短信发送失败");
}
}
/**
* 通过阿里云平台发送短信如果发送成功返回"OK" ;否则返回的是错误信息
* @param mobile 要接收该短信的用户手机号
* @param
* @param code 您将发送到用户手机的短信验证码
*/
public static Boolean sendCode(String mobile,String code){
boolean isSend = false;
//请求失败这里会抛ClientException异常
String result="";
try {
//设置超时时间-可自行调整
System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
System.setProperty("sun.net.client.defaultReadTimeout", "10000");
//初始化ascClient需要的几个参数
final String product = "Dysmsapi";//短信API产品名称(短信产品名固定,无需修改)
final String domain = "dysmsapi.aliyuncs.com";//短信API产品域名(接口地址固定,无需修改)
//替换成你的AK
final String accessKeyId = "LTAI4FzqQHnk4rozqLZ8jCNj";//你的accessKeyId,参考本文档步骤2
final String accessKeySecret = "mveW7B1OyFoKUkHm8WsxmrjHmkJWHq";//你的accessKeySecret,参考本文档步骤2
//初始化ascClient,暂时不支持多region(请勿修改)
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId,
accessKeySecret);
DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
IAcsClient acsClient = new DefaultAcsClient(profile);
//组装请求对象
SendSmsRequest request = new SendSmsRequest();
//使用post提交
request.setMethod(MethodType.POST);
//必填:待发送手机号。支持以逗号分隔的形式进行批量调用,批量上限为1000个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式;发送国际/港澳台消息时,接收号码格式为00+国际区号+号码,如“0085200000000”
request.setPhoneNumbers(mobile);
//必填:短信签名-可在短信控制台中找到
request.setSignName("职站");//注意要与你在短信控制台中的签名一致
//必填:短信模板-可在短信控制台中找到
request.setTemplateCode(PHONSMSTEMPLATE);
//可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
//友情提示:如果JSON中需要带换行符,请参照标准的JSON协议对换行符的要求,比如短信内容中包含\r\n的情况在JSON中需要表示成\\r\\n,否则会导致JSON在服务端解析失败
// request.setTemplateParam("{\"name\":\"Tom\", \"code\":\"123\"}");
request.setTemplateParam("{\"code\":\""+code+"\"}");
//可选-上行短信扩展码(扩展码字段控制在7位或以下,无特殊需求用户请忽略此字段)
//request.setSmsUpExtendCode("90997");
//可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
// request.setOutId("yourOutId");
SendSmsResponse response = acsClient.getAcsResponse(request);
result=response.getCode();
if(result!=null&&"OK".equals(result.toUpperCase())){
System.out.println("短信发送成功");
isSend = true;
}else{
isSend = false;
System.out.println("短信发送失败");
}
} catch (Exception e) {
result=e.getMessage();
isSend = false;
}
return isSend;
}
}

@ -0,0 +1,24 @@
package com.msdw.tms.config.quartz;
import com.msdw.tms.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class CheckCodeQuartz implements Job {
@Autowired
private UserService userService;
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
boolean clean = userService.cleanUp();
log.info("清理过期验证码");
}
}

@ -1,5 +1,6 @@
package com.msdw.tms.controller; package com.msdw.tms.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.msdw.tms.api.StudentControllerApi; import com.msdw.tms.api.StudentControllerApi;
import com.msdw.tms.common.utils.PageUtils; import com.msdw.tms.common.utils.PageUtils;
import com.msdw.tms.common.utils.R; import com.msdw.tms.common.utils.R;
@ -34,13 +35,20 @@ public class StudentController implements StudentControllerApi{
@Override @Override
@PostMapping("/addStudent") @PostMapping("/addStudent")
public R addStudent(@RequestBody StudentVo studentVo){ public R addStudent(@RequestBody StudentVo studentVo){
String studentIdNumber = studentVo.getStudentIdNumber();
Integer result = studentService.queryStudentIdNumber(studentIdNumber);
if (result==1){
return R.error("学号不能重复");
}else{
UserInfoEntity userInfoList = studentVo.getUserInfo(); UserInfoEntity userInfoList = studentVo.getUserInfo();
int userId= userInfoService.saveUserInfo(userInfoList); userInfoService.saveUserInfo(userInfoList);
studentVo.setUserId(userInfoList.getUserId()); studentVo.setUserId(userInfoList.getUserId());
boolean saveStudent = studentService.saveStudent(studentVo); boolean saveStudent = studentService.saveStudent(studentVo);
return saveStudent ? R.ok() : R.error(); return saveStudent ? R.ok() : R.error();
} }
}
/** /**
* 学生列表 * 学生列表
@ -76,11 +84,42 @@ public class StudentController implements StudentControllerApi{
* @return * @return
*/ */
@Override @Override
@PostMapping("/updateStudent") @PutMapping("/updateStudent")
public R updateStudent(@RequestBody StudentVo studentVo) { public R updateStudent(@RequestBody StudentVo studentVo) {
return R.ok(); String studentIdNumber = studentVo.getStudentIdNumber();
Integer result = studentService.queryStudentIdNumber(studentIdNumber);
if (result==1){
return R.error("学号不能重复");
}else{
boolean saveStudent = studentService.updateStudent(studentVo);
return saveStudent ? R.ok() : R.error();
}
} }
/**
* 重置密码
* @param userId
* @return
*/
@Override
@PutMapping("/reSetPassword")
public R reSetPassword(@RequestBody Integer userId){
boolean initial = studentService.initialPassword(userId);
return initial ? R.ok() : R.error();
}
/**
* 禁用账号
* @param studentId
* @return
*/
@Override
@PutMapping("/disableAccount")
public R disableAccount(@RequestBody Integer studentId) {
boolean disable = studentService.disableAccount(studentId);
return disable ? R.ok() : R.error();
}
} }

@ -3,22 +3,24 @@ package com.msdw.tms.controller;
import com.msdw.tms.api.UserControllerApi; import com.msdw.tms.api.UserControllerApi;
import com.msdw.tms.common.utils.PageUtils; import com.msdw.tms.common.utils.PageUtils;
import com.msdw.tms.common.utils.R; import com.msdw.tms.common.utils.R;
import com.msdw.tms.config.CheckCodeUtils;
import com.msdw.tms.config.EmailUtils;
import com.msdw.tms.config.SendSMS;
import com.msdw.tms.entity.PersonalFileEntity; import com.msdw.tms.entity.PersonalFileEntity;
import com.msdw.tms.entity.UserEntity; import com.msdw.tms.entity.UserEntity;
import com.msdw.tms.entity.UserInfoEntity; import com.msdw.tms.entity.UserInfoEntity;
import com.msdw.tms.entity.UserPersonalFileEntity; import com.msdw.tms.entity.UserPersonalFileEntity;
import com.msdw.tms.entity.vo.CheckVo;
import com.msdw.tms.entity.vo.UserEntityVo; import com.msdw.tms.entity.vo.UserEntityVo;
import com.msdw.tms.entity.vo.UserProsonalEntityVo; import com.msdw.tms.entity.vo.UserProsonalEntityVo;
import com.msdw.tms.service.UserInfoService; import com.msdw.tms.service.UserInfoService;
import com.msdw.tms.service.UserService; import com.msdw.tms.service.UserService;
import com.sun.org.apache.bcel.internal.generic.CHECKCAST;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Arrays; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController @RestController
@RequestMapping("tms/user") @RequestMapping("tms/user")
@ -102,22 +104,6 @@ public class UserController implements UserControllerApi {
return R.ok(); return R.ok();
} }
} }
// /**
// * 修改
// */
// @Override
// @Transactional
// @PutMapping("/update")
// public R update(@RequestBody UserProsonalEntityVo vo){
// List<UserEntityVo> userEntityVoList = vo.getUserEntityVoList();
// UserEntity userInfo = vo.getUserEntity();
// userService.updateById(userInfo);
// for (int i = 0;i<userEntityVoList.size();i++){
// UserEntityVo personalFile = userEntityVoList.get(i);
// userService.updateUserPersonal(personalFile);
// }
// return R.ok();
// }
/** /**
* 删除 * 删除
@ -155,4 +141,97 @@ public class UserController implements UserControllerApi {
} }
} }
/**
* 发送邮箱验证码
* @param checkVo
* @return
*/
@Override
@PostMapping("/sendEmailCode")
public R sendEmailCode(@RequestBody CheckVo checkVo){
boolean re = userService.queryEmial(checkVo);
if (re){
return R.error(403,"邮箱号不能重复");
}else{
boolean save = userService.saveCheckCode(checkVo);
return save ? R.ok() : R.error();
}
}
/**
* 校验邮箱验证码通过则更新邮箱
* @param checkVo
* @return
*/
@Override
@PutMapping("/bingEmail")
public R bindEmail(@RequestBody CheckVo checkVo){
String email = checkVo.getEmail();
Integer types = checkVo.getTypes();
List<String> emailCode = userService.findEmailCode(email,types);//获取最近的验证码
if (emailCode.size()==1){
String checkCode = emailCode.get(0);
List<String> result = userService.findEmailSetTime(email,checkCode,types);//验证最近验证码是否过期
if (result.size()==1){
String code = checkVo.getCode();
if (code.equals(checkCode)){
boolean bind = userService.bindEmail(checkVo);
return bind ? R.ok() : R.error();
}else{
return R.error(403,"验证失败!!!");
}
}else{
return R.error(403,"验证码过期!!!");
}
}else{
return R.error(403,"请发送验证码!!!");
}
}
/**
* 发送手机验证码
* @param checkVo
* @return
*/
@Override
@PostMapping("/sendPhoneCode")
public R sendPhoneCode(@RequestBody CheckVo checkVo){
boolean re = userService.queryPhone(checkVo);
if (re){
return R.error(403,"电话号码不能重复");
}else {
boolean save = userService.sendCheckPhoneCode(checkVo);
return save ? R.ok() : R.error();
}
}
/**
* 绑定手机
* @param checkVo
* @return
*/
@Override
@PutMapping("/bindPhone")
public R bindPhone(@RequestBody CheckVo checkVo){
String phone = checkVo.getPhone();
Integer types = checkVo.getTypes();
List<String> phoneCode = userService.findPhoneCode(phone,types);//获取最近的验证码
if (phoneCode.size()==1){
String checkCode = phoneCode.get(0);
List<String> result = userService.findPhoneSetTime(phone,checkCode,types);//验证最近验证码是否过期
if (result.size()==1){
if (checkVo.getCode().equals(checkCode)){
boolean bind = userService.bindPhone(checkVo);
return bind ? R.ok() : R.error();
}else{
return R.error(403,"验证失败!!!");
}
}else{
return R.error(403,"验证码过期!!!");
}
}else{
return R.error(403,"请发送验证码!!!");
}
}
} }

@ -12,9 +12,18 @@ import java.util.List;
@Mapper @Mapper
public interface StudentDao extends BaseMapper<StudentEntity> { public interface StudentDao extends BaseMapper<StudentEntity> {
List<Integer> queryStudentIdNumber(String studentIdNumber);
boolean saveStudent(StudentVo studentVo); boolean saveStudent(StudentVo studentVo);
IPage<StudentVo> queryStudent(Page<T> tpage,String searchContent,Integer schoolId); IPage<StudentVo> queryStudent(Page<T> tpage,String searchContent,Integer schoolId);
boolean deleteStudent(List<Integer> studentId); boolean deleteStudent(List<Integer> studentId);
boolean updateStudent(StudentVo studentVo);
boolean initialPassword(Integer userId,String password);
boolean disableAccount(Integer studentId);
} }

@ -3,6 +3,7 @@ package com.msdw.tms.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.msdw.tms.entity.UserEntity; import com.msdw.tms.entity.UserEntity;
import com.msdw.tms.entity.UserPersonalFileEntity; import com.msdw.tms.entity.UserPersonalFileEntity;
import com.msdw.tms.entity.vo.CheckVo;
import com.msdw.tms.entity.vo.UserEntityVo; import com.msdw.tms.entity.vo.UserEntityVo;
import com.msdw.tms.entity.vo.UserProsonalEntityVo; import com.msdw.tms.entity.vo.UserProsonalEntityVo;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
@ -12,6 +13,12 @@ import java.util.List;
@Mapper @Mapper
public interface UserDao extends BaseMapper<UserEntity> { public interface UserDao extends BaseMapper<UserEntity> {
boolean cleanUp();
List<Integer> queryEmial(CheckVo checkVo);
boolean saveCheckCode(CheckVo checkVo);
UserEntityVo getByUserId(UserEntity userEntity); UserEntityVo getByUserId(UserEntity userEntity);
void updateUserPersonal(UserPersonalFileEntity vo); void updateUserPersonal(UserPersonalFileEntity vo);
@ -23,4 +30,20 @@ public interface UserDao extends BaseMapper<UserEntity> {
List<UserProsonalEntityVo> queryUserInfo(Integer userid); List<UserProsonalEntityVo> queryUserInfo(Integer userid);
void insertPersonalInfo(UserPersonalFileEntity personalFile); void insertPersonalInfo(UserPersonalFileEntity personalFile);
boolean bindEmail(CheckVo checkVo);
boolean bindPhone(CheckVo checkVo);
List<String> findEmailCode(String email,Integer types);
List<String> findEmailSetTime(String email, String checkCode,Integer types);
List<String> findPhoneCode(String phone,Integer types);
List<String> findPhoneSetTime(String phone, String checkCode,Integer types);
boolean saveCheckPhoneCode(CheckVo checkVo);
List<Integer> queryPhone(CheckVo checkVo);
} }

@ -30,4 +30,6 @@ public class StudentEntity {
private Integer roleId; private Integer roleId;
//是否删除(0未删除,1已删除) //是否删除(0未删除,1已删除)
private Integer isdel; private Integer isdel;
//是否禁用账号(0禁用,1不禁用,默认0)
private Integer disableAccount;
} }

@ -0,0 +1,29 @@
package com.msdw.tms.entity.vo;
import lombok.Data;
import lombok.experimental.Accessors;
@Data
@Accessors(chain = true)
public class CheckVo {
//用户id
private Integer userId;
//用户的邮箱地址
private String email;
//验证码
private String checkCode;
//用户电话号码
private String phone;
//验证码存入时间(实际时间-允许验证时间)
private String setTime;
//验证码类型(1邮箱验证码,2手机验证码)
private Integer types;
//用户输入的验证码
private String code;
//用户设置的新邮箱地址
private String emailAddress;
//用户设置的新手机号
private String mobile;
}

@ -7,6 +7,9 @@ import lombok.experimental.Accessors;
import java.util.List; import java.util.List;
/**
* 学生管理
*/
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class StudentVo extends StudentEntity { public class StudentVo extends StudentEntity {
@ -23,6 +26,9 @@ public class StudentVo extends StudentEntity {
private Integer logInNumber; private Integer logInNumber;
//最后登陆时间 //最后登陆时间
private String lastLoginTime; private String lastLoginTime;
//电话
private String phone;
//邮箱
private String email;
} }

@ -10,9 +10,17 @@ import java.util.List;
public interface StudentService extends IService<StudentEntity>{ public interface StudentService extends IService<StudentEntity>{
Integer queryStudentIdNumber(String studentIdNumber);
boolean saveStudent(StudentVo studentvo); boolean saveStudent(StudentVo studentvo);
PageUtils queryStudent(Integer schoolId,String searchContent, Integer page, Integer size); PageUtils queryStudent(Integer schoolId,String searchContent, Integer page, Integer size);
boolean deleteStudent(List<Integer> studentId); boolean deleteStudent(List<Integer> studentId);
boolean updateStudent(StudentVo studentVo);
boolean initialPassword(Integer userId);
boolean disableAccount(Integer studentId);
} }

@ -2,14 +2,17 @@ package com.msdw.tms.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.msdw.tms.common.utils.PageUtils; import com.msdw.tms.common.utils.PageUtils;
import com.msdw.tms.common.utils.R;
import com.msdw.tms.entity.PersonalFileEntity; import com.msdw.tms.entity.PersonalFileEntity;
import com.msdw.tms.entity.UserEntity; import com.msdw.tms.entity.UserEntity;
import com.msdw.tms.entity.UserInfoEntity; import com.msdw.tms.entity.UserInfoEntity;
import com.msdw.tms.entity.UserPersonalFileEntity; import com.msdw.tms.entity.UserPersonalFileEntity;
import com.msdw.tms.entity.vo.CheckVo;
import com.msdw.tms.entity.vo.UserEntityVo; import com.msdw.tms.entity.vo.UserEntityVo;
import com.msdw.tms.entity.vo.UserProsonalEntityVo; import com.msdw.tms.entity.vo.UserProsonalEntityVo;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
public interface UserService extends IService<UserEntity> { public interface UserService extends IService<UserEntity> {
@ -24,4 +27,27 @@ public interface UserService extends IService<UserEntity> {
HashMap<String,UserProsonalEntityVo> queryUserInfo(Integer id); HashMap<String,UserProsonalEntityVo> queryUserInfo(Integer id);
void insertPersonalInfo(UserPersonalFileEntity personalFile); void insertPersonalInfo(UserPersonalFileEntity personalFile);
boolean bindEmail(CheckVo checkVo);
List<String> findEmailCode(String email,Integer types);
List<String> findEmailSetTime(String email,String checkCode,Integer types);
boolean bindPhone(CheckVo checkVo);
List<String> findPhoneCode(String phone,Integer types);
List<String> findPhoneSetTime(String email,String checkCode,Integer types);
boolean queryEmial(CheckVo checkVo);
boolean queryPhone(CheckVo checkVo);
boolean saveCheckCode(CheckVo checkVo);
boolean sendCheckPhoneCode(CheckVo checkVo);
//清空过期验证码
boolean cleanUp();
} }

@ -22,6 +22,20 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao,StudentEntity> im
@Autowired @Autowired
private StudentDao studentDao; private StudentDao studentDao;
/**
* 初始密码
*/
private static final String INITIAL_PASSWORD = "huoran123";
@Override
public Integer queryStudentIdNumber(String studentIdNumber) {
List<Integer> result = studentDao.queryStudentIdNumber(studentIdNumber);
if (result.size()==1){
return 1;
}
return 0;
}
@Transactional @Transactional
@Override @Override
public boolean saveStudent(StudentVo studentvo) { public boolean saveStudent(StudentVo studentvo) {
@ -46,4 +60,26 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao,StudentEntity> im
return delete; return delete;
} }
@Transactional
@Override
public boolean updateStudent(StudentVo studentVo) {
boolean update = studentDao.updateStudent(studentVo);
return update;
}
@Transactional
@Override
public boolean initialPassword(Integer userId) {
boolean initial = studentDao.initialPassword(userId,INITIAL_PASSWORD);
return initial;
}
@Transactional
@Override
public boolean disableAccount(Integer studentId) {
boolean disable = studentDao.disableAccount(studentId);
return disable;
}
} }

@ -6,15 +6,20 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.msdw.tms.common.utils.Constant; import com.msdw.tms.common.utils.Constant;
import com.msdw.tms.common.utils.PageUtils; import com.msdw.tms.common.utils.PageUtils;
import com.msdw.tms.common.utils.Query; import com.msdw.tms.common.utils.Query;
import com.msdw.tms.common.utils.R;
import com.msdw.tms.config.CheckCodeUtils;
import com.msdw.tms.config.EmailUtils;
import com.msdw.tms.config.SendSMS;
import com.msdw.tms.dao.UserDao; import com.msdw.tms.dao.UserDao;
import com.msdw.tms.entity.UserEntity; import com.msdw.tms.entity.UserEntity;
import com.msdw.tms.entity.UserInfoEntity;
import com.msdw.tms.entity.UserPersonalFileEntity; import com.msdw.tms.entity.UserPersonalFileEntity;
import com.msdw.tms.entity.vo.CheckVo;
import com.msdw.tms.entity.vo.UserEntityVo; import com.msdw.tms.entity.vo.UserEntityVo;
import com.msdw.tms.entity.vo.UserProsonalEntityVo; import com.msdw.tms.entity.vo.UserProsonalEntityVo;
import com.msdw.tms.service.UserService; import com.msdw.tms.service.UserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -25,6 +30,13 @@ import java.util.Map;
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService { public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {
@Autowired @Autowired
private UserDao userMapper; private UserDao userMapper;
@Override
public boolean cleanUp(){
boolean clean = userMapper.cleanUp();
return clean;
}
@Override @Override
public PageUtils queryPage(Map<String, Object> params) { public PageUtils queryPage(Map<String, Object> params) {
@ -58,9 +70,6 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
List<UserProsonalEntityVo> userInfo = userMapper.queryUserInfo(id); List<UserProsonalEntityVo> userInfo = userMapper.queryUserInfo(id);
map.put("userInfo",userInfo); map.put("userInfo",userInfo);
//个人档案sql
// List<UserProsonalEntityVo> userEntityVos = userMapper.queryPersonalFile(id);//档案里有学校信息时
// map.put("userPersonalFile",userEntityVos);
List<UserProsonalEntityVo> prosonalEntityESVos = userMapper.queryPersonalFileES(id);//档案里无学校信息时 List<UserProsonalEntityVo> prosonalEntityESVos = userMapper.queryPersonalFileES(id);//档案里无学校信息时
map.put("userPersonalFile",prosonalEntityESVos); map.put("userPersonalFile",prosonalEntityESVos);
@ -71,4 +80,87 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
public void insertPersonalInfo(UserPersonalFileEntity personalFile) { public void insertPersonalInfo(UserPersonalFileEntity personalFile) {
userMapper.insertPersonalInfo(personalFile); userMapper.insertPersonalInfo(personalFile);
} }
@Transactional
@Override
public boolean bindEmail(CheckVo checkVo) {
boolean bind = userMapper.bindEmail(checkVo);
return bind;
}
@Transactional
@Override
public List<String> findEmailCode(String email,Integer types) {
List<String> bind = userMapper.findEmailCode(email,types);
return bind;
}
@Transactional
@Override
public List<String> findEmailSetTime(String email,String checkCode,Integer types) {
List<String> bind = userMapper.findEmailSetTime(email,checkCode,types);
return bind;
}
@Override
public boolean queryEmial(CheckVo checkVo){
List<Integer> re = userMapper.queryEmial(checkVo);
if (re.size()>0){
return true;
}else{
return false;
}
}
@Override
public boolean queryPhone(CheckVo checkVo){
List<Integer> re = userMapper.queryPhone(checkVo);
if (re.size()>0){
return true;
}else{
return false;
}
}
@Override
public boolean saveCheckCode(CheckVo checkVo) {
CheckCodeUtils checkCodeUtils = new CheckCodeUtils();
//获取六位随机数验证码
String code = checkCodeUtils.sendCode();
EmailUtils.sendEmail(checkVo.getEmail(),code);//发送邮箱验证码
String letTimes = checkCodeUtils.letTimes(5);//设定验证码5分钟内有效
checkVo.setCheckCode(code).setSetTime(letTimes);
boolean save = userMapper.saveCheckCode(checkVo);
return save;
}
@Override
public boolean sendCheckPhoneCode(CheckVo checkVo) {
CheckCodeUtils checkCodeUtils = new CheckCodeUtils();
//获取六位随机数验证码
String code = checkCodeUtils.sendCode();
SendSMS.sendCode(checkVo.getPhone(),code);//发送邮箱验证码
String letTimes = checkCodeUtils.letTimes(5);//设定验证码5分钟内有效
checkVo.setCheckCode(code).setSetTime(letTimes);
boolean save = userMapper.saveCheckPhoneCode(checkVo);
return save;
}
@Transactional
@Override
public boolean bindPhone(CheckVo checkVo) {
boolean bind = userMapper.bindPhone(checkVo);
return bind;
}
@Transactional
@Override
public List<String> findPhoneCode(String phone,Integer types) {
List<String> bind = userMapper.findPhoneCode(phone,types);
return bind;
}
@Transactional
@Override
public List<String> findPhoneSetTime(String phone,String checkCode,Integer types) {
List<String> bind = userMapper.findPhoneSetTime(phone,checkCode,types);
return bind;
}
} }

@ -26,6 +26,15 @@
lastLoginTime DESC lastLoginTime DESC
</select> </select>
<select id="queryStudentIdNumber" resultType="java.lang.Integer">
SELECT
userId
FROM
tms_student
WHERE
studentIdNumber = #{studentIdNumber}
</select>
<insert id="saveStudent" useGeneratedKeys="true" keyProperty="studentId"> <insert id="saveStudent" useGeneratedKeys="true" keyProperty="studentId">
INSERT INTO tms_student ( schoolId, userId, studentIdNumber, professionalId, gradeId, classId, roleId, isdel ) INSERT INTO tms_student ( schoolId, userId, studentIdNumber, professionalId, gradeId, classId, roleId, isdel )
VALUES VALUES
@ -40,4 +49,45 @@
<foreach collection="list" separator="," item="studentId">#{studentId}</foreach> <foreach collection="list" separator="," item="studentId">#{studentId}</foreach>
) )
</update> </update>
<update id="updateStudent">
UPDATE
tms_student s,hr_user_info u
<set>
<if test="schoolId!=null">s.schoolId = #{schoolId},</if>
<if test="studentIdNumber!=null">s.studentIdNumber = #{studentIdNumber},</if>
<if test="professionalId!=null">s.professionalId = #{professionalId},</if>
<if test="gradeId!=null">s.gradeId = #{gradeId},</if>
<if test="classId!=null">s.classId = #{classId},</if>
<if test="userName!=null">u.userName = #{userName},</if>
<if test="schoolId!=null">u.schoolId = #{schoolId},</if>
<if test="account!=null">u.account = #{account},</if>
<if test="phone!=null">u.phone = #{phone},</if>
<if test="phone!==null">u.phone = NULL,</if>
<if test="email!=null">u.email = #{email}</if>
<if test="email!==null">u.email = NULL</if>
</set>
WHERE
u.userId = s.userId
AND
u.userId = #{userId}
AND
s.studentId = #{studentId}
</update>
<update id="initialPassword">
UPDATE
hr_user_info
SET
password = #{password}
WHERE
userId = #{userId}
</update>
<update id="disableAccount">
UPDATE
tms_student
SET
disableAccount = 1
WHERE
studentId = #{studentId}
</update>
</mapper> </mapper>

@ -2,7 +2,9 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.msdw.tms.dao.UserDao"> <mapper namespace="com.msdw.tms.dao.UserDao">
<delete id="cleanUp">
DELETE FROM tms_checkcode WHERE now() > setTime
</delete>
<select id="queryUserInfo" parameterType="com.msdw.tms.entity.UserInfoEntity" resultType="hashMap"> <select id="queryUserInfo" parameterType="com.msdw.tms.entity.UserInfoEntity" resultType="hashMap">
SELECT SELECT
@ -83,6 +85,72 @@
WHERE WHERE
userId = #{userId} userId = #{userId}
</select> </select>
<select id="findEmailCode" resultType="java.lang.String">
SELECT
checkCode
FROM
tms_checkcode
WHERE
email = #{email}
AND
types = #{types}
ORDER BY
setTime DESC
LIMIT 0,1
</select>
<select id="findEmailSetTime" resultType="java.lang.String">
SELECT
setTime
FROM
tms_checkcode
WHERE
email = #{email}
AND
checkCode = #{checkCode}
AND
types = #{types}
AND
setTime > NOW()
ORDER BY
setTime DESC
LIMIT 0,1
</select>
<select id="findPhoneCode" resultType="java.lang.String">
SELECT
checkCode
FROM
tms_checkcode
WHERE
phone = #{phone}
AND
types = #{types}
ORDER BY
setTime DESC
LIMIT 0,1
</select>
<select id="findPhoneSetTime" resultType="java.lang.String">
SELECT
setTime
FROM
tms_checkcode
WHERE
phone = #{phone}
AND
checkCode = #{checkCode}
AND
types = #{types}
AND
setTime > NOW()
ORDER BY
setTime DESC
LIMIT 0,1
</select>
<select id="queryEmial" resultType="java.lang.Integer">
select * from hr_user_info where userId=#{userId} and email = #{email}
</select>
<select id="queryPhone" resultType="java.lang.Integer">
select * from hr_user_info where userId=#{userId} and phone = #{phone}
</select>
<update id="updateUserPersonal" parameterType="com.msdw.tms.entity.vo.UserProsonalEntityVo"> <update id="updateUserPersonal" parameterType="com.msdw.tms.entity.vo.UserProsonalEntityVo">
UPDATE UPDATE
@ -112,10 +180,37 @@
AND AND
per.personalFileId = #{personalFileId} per.personalFileId = #{personalFileId}
</update> </update>
<update id="bindEmail">
UPDATE
hr_user_info
SET
email = #{email}
WHERE
userId = #{userId}
</update>
<update id="bindPhone">
UPDATE
hr_user_info
SET
phone = #{phone}
WHERE
userId = #{userId}
</update>
<insert id="insertPersonalInfo" useGeneratedKeys="true"> <insert id="insertPersonalInfo" useGeneratedKeys="true">
INSERT INTO hr_personal_file ( userId, personalCareerId, schoolId, schoolName, disciplineId, disciplineName, professionalId, professionalName, professionalClassId, professionalClassName, updatetime ) INSERT INTO hr_personal_file ( userId, personalCareerId, schoolId, schoolName, disciplineId, disciplineName, professionalId, professionalName, professionalClassId, professionalClassName, updatetime )
VALUES VALUES
(#{userId},#{personalCareerId},#{schoolId},#{schoolName},#{disciplineId},#{disciplineName},#{professionalId},#{professionalName},#{professionalClassId},#{professionalClassName},NOW()) (#{userId},#{personalCareerId},#{schoolId},#{schoolName},#{disciplineId},#{disciplineName},#{professionalId},#{professionalName},#{professionalClassId},#{professionalClassName},NOW())
</insert> </insert>
<insert id="saveCheckCode">
INSERT INTO tms_checkcode ( userId, email, types, checkCode, setTime )
VALUES
(#{userId},#{email},#{types},#{checkCode},#{setTime})
</insert>
<insert id="saveCheckPhoneCode">
INSERT INTO tms_checkcode ( userId, phone, types, checkCode, setTime )
VALUES
(#{userId},#{phone},#{types},#{checkCode},#{setTime})
</insert>
</mapper> </mapper>

@ -61,8 +61,8 @@
</select> </select>
<insert id="saveUserInfo" useGeneratedKeys="true" keyProperty="userId" keyColumn="userId"> <insert id="saveUserInfo" useGeneratedKeys="true" keyProperty="userId" keyColumn="userId">
INSERT INTO hr_user_info ( uniqueIdentificationAccount, schoolId, account, roleId,isdel) INSERT INTO hr_user_info ( userName,email,phone,uniqueIdentificationAccount, schoolId, account, roleId,isdel)
VALUES VALUES
( #{uniqueIdentificationAccount}, #{schoolId}, #{account}, 4 ,#{isdel}) ( #{userName},#{email},#{phone},#{uniqueIdentificationAccount}, #{schoolId}, #{account}, 4 ,#{isdel})
</insert> </insert>
</mapper> </mapper>

@ -0,0 +1,27 @@
package com.msdw.tms;
import com.msdw.tms.config.EmailUtils;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.Random;
@SpringBootTest
public class EmaiTest {
@Test
public void sendEmailTest(){
String emailaddress = "820631607@qq.com";
//获取六位随机数验证码
Random random = new Random();
String code="";
for (int i=0;i<6;i++)
{
code+=random.nextInt(10);
}
System.out.println(code);
boolean b = EmailUtils.sendEmail(emailaddress, code);
System.out.println(b?"发送成功":"发送失败");
}
}

@ -30,7 +30,7 @@ public class StudentTest {
Integer a = 1; Integer a = 1;
UserInfoEntity userInfoEntity = new UserInfoEntity(); UserInfoEntity userInfoEntity = new UserInfoEntity();
userInfoEntity.setAccount("123456").setUserName("michonne").setSchoolId(a); userInfoEntity.setAccount("123456").setUserName("michonne").setSchoolId(a);
studentVo.setSchoolId(a).setUserId(257).setStudentIdNumber("888888").setRoleId(4).setProfessionalId(1).setGradeId(1).setClassId(1); studentVo.setSchoolId(a).setStudentIdNumber("888888").setRoleId(4).setProfessionalId(1).setGradeId(1).setClassId(1);
studentVo.setUserInfo(userInfoEntity); studentVo.setUserInfo(userInfoEntity);
boolean aa= studentService.saveStudent(studentVo); boolean aa= studentService.saveStudent(studentVo);
// boolean bb = userInfoService.saveUserInfo(userInfoEntity); // boolean bb = userInfoService.saveUserInfo(userInfoEntity);
@ -53,14 +53,14 @@ public class StudentTest {
/** /**
* 删除学生 * 删除学生
*/ */
// @Test @Test
// public void deleteStudent(){ public void deleteStudent(){
// List<Integer> studentId = {1,2}; // List<Integer> studentId = {1,2};
//// List<Integer> studentId = new ArrayList<>(); List<Integer> studentId = new ArrayList<>();
//// studentId.add(1); studentId.add(1);
//// studentId.add(2); studentId.add(2);
//
// boolean b = studentService.deleteStudent(studentId); boolean b = studentService.deleteStudent(studentId);
// System.out.println(b ? "删除成功" : "删除失败"); System.out.println(b ? "删除成功" : "删除失败");
// } }
} }

Loading…
Cancel
Save