first commit

This commit is contained in:
8324144
2026-05-18 14:39:26 +08:00
commit 3e9264ebc6
109 changed files with 13139 additions and 0 deletions

View File

@@ -0,0 +1,136 @@
package cn.wepact.dfm.training.controller;
import cn.hutool.captcha.CaptchaUtil;
import cn.wepact.dfm.common.util.Constant;
import cn.wepact.dfm.common.util.GeneralRespBean;
import cn.wepact.dfm.common.util.StringUtils;
import cn.wepact.dfm.training.dto.entity.TOrg;
import cn.wepact.dfm.training.dto.entity.TUser;
import cn.wepact.dfm.training.service.UserService;
import cn.wepact.dfm.training.utils.EmailUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;
@RestController
@RequestMapping("users")
public class UserController extends BaseController{
@Autowired
private UserService userService;
// 登录
@PostMapping("/login")
public GeneralRespBean<TUser> login(@RequestBody TUser loginRequest) {
GeneralRespBean<TUser> respBean = new GeneralRespBean();
TUser user = userService.loginAndGetUser(loginRequest);
String jsonString=null;
if (user != null) {
respBean.setData(user);
respBean.setMsg(Constant.SUCCESS_MSG);
respBean.setCode(Constant.SUCCESS_CODE);
} else {
respBean.setData(null);
respBean.setMsg("登录失败,账号密码错误,或单位选择有误!");
respBean.setCode(Constant.ERROR_CODE);
}
return respBean;
}
// 注册
@PostMapping("/register")
public GeneralRespBean<String> register(@RequestBody TUser registerRequest) {
GeneralRespBean<String> respBean = new GeneralRespBean();
Boolean result = userService.register(registerRequest);
if (result) {
respBean.setMsg(Constant.SUCCESS_MSG);
respBean.setCode(Constant.SUCCESS_CODE);
} else {
respBean.setMsg("注册失败,账号已经存在!");
respBean.setCode(Constant.ERROR_CODE);
}
return respBean;
}
@GetMapping("/getDeptList")
public GeneralRespBean<List<TOrg>> getDeptList() {
GeneralRespBean<List<TOrg>> respBean = new GeneralRespBean();
List<TOrg> tOrgList = userService.getDeptList();
respBean.setData(tOrgList);
respBean.setMsg(Constant.SUCCESS_MSG);
respBean.setCode(Constant.SUCCESS_CODE);
return respBean;
}
/**
* 用于生成带六位数字验证码并发送邮件
*/
@PostMapping(value = "/captcha")
public GeneralRespBean<Boolean> captchacode(HttpSession session) throws Exception {
GeneralRespBean<Boolean> respBean = new GeneralRespBean<>();
TUser user = getUserInfo();
String randomCode = userService.generateRandomCode();
session.setAttribute("randomCode", randomCode);
session.setAttribute("codeTime",System.currentTimeMillis());
//发送邮件
EmailUtil.Email email = new EmailUtil.Email();
email.setTo(user.getEmail());
email.setSubject("任职资格管理系统验证码");
email.setContent("您的验证码为:"+randomCode);
EmailUtil.sendMail(email);
respBean.setMsg("验证码发送成功!");
respBean.setCode("200");
return respBean;
}
/**
* 更新密码
*/
@PostMapping(value = "/updatePwd")
public GeneralRespBean<Boolean> updatePwd(HttpSession session,
@RequestBody TUser tUser) throws Exception {
GeneralRespBean<Boolean> respBean = new GeneralRespBean<>();
TUser user = getUserInfo();
tUser.setUserNo(user.getUserNo());
// 获得验证码对象
Object cko = session.getAttribute("randomCode");
if (cko == null) {
return respBean.processErrorMsg("验证码已失效,请重新获取!");
}
String captcha = cko.toString();
// 判断验证码输入是否正确
if (StringUtils.isEmpty(tUser.getRandomCode()) || captcha == null || !(tUser.getRandomCode().equalsIgnoreCase(captcha))) {
return respBean.processErrorMsg("验证码错误,请重新输入!");
} else {
Long codeTime = Long.valueOf(session.getAttribute("codeTime") + "");
if ((System.currentTimeMillis() - codeTime) / 1000 / 60 > 4) {
return respBean.processErrorMsg("验证码已失效,请重新获取!");
}
return userService.updatePwd(tUser);
}
}
// 取消预览
@PostMapping("/cancelPreview")
public GeneralRespBean<Boolean> cancelPreview() {
GeneralRespBean<Boolean> respBean = new GeneralRespBean();
TUser user = getUserInfo();
Boolean result = userService.cancelPreview(user);
respBean.setData(result);
if (result) {
respBean.setMsg(Constant.SUCCESS_MSG);
respBean.setCode(Constant.SUCCESS_CODE);
} else {
respBean.setMsg("取消预览失败");
respBean.setCode(Constant.ERROR_CODE);
}
return respBean;
}
}