当前位置:   article > 正文

Java项目:客户管理系统(java+SpringBoot+JSP+LayUI+jQ+mysql)_简单的jsp管理系统

简单的jsp管理系统

源码获取:博客首页 "资源" 里下载!

项目介绍

本项目为后管系统,主要功能包括:

登录、修改密码、客户模块、充值模块、消费模块、对账单模块等功能。

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;

6.是否Maven项目:是;

技术栈

1. 后端:SpringBoot+Mybatis

2. 前端:JSP+LayUI+jQuery

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;

2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;

若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;

3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 修改logback-spring.xml文件中,第16行
5. 运行项目,输入http://localhost:8081/ 登录

 

 

 

 

客户管理控制层:

  1. @Controller
  2. @RequestMapping("customer")
  3. public class CustomerController {
  4. @Autowired
  5. private ICustomerService customerService;
  6. private User user = null;
  7. private User getUser(HttpServletRequest request) {
  8. HttpSession session = request.getSession();
  9. user = (User)session.getAttribute("user");
  10. return user;
  11. }
  12. /**
  13. *
  14. * 描述:分页查询客户
  15. * @author huangwanzong
  16. * @date 2018/07/06
  17. * @version 1.0
  18. * @param page 可选参数,查询的页数,默认值 1
  19. * @param limit 可选参数,分页的大小,默认值 10
  20. * @param customer 可选参数,查询的条件
  21. * @param findtype 可选参数,该参数值为 all 时不执行分页查询,返回全部符合条件的客户
  22. * @param request
  23. * @return Map<String,Object>
  24. * @since 1.8
  25. *
  26. */
  27. @RequiresPermissions("5001")
  28. @Operation(name="分页查询客户")
  29. @RequestMapping("list")
  30. @ResponseBody
  31. public Map<String, Object> listCustomer(Integer page,Integer limit,Customer customer,String findtype,HttpServletRequest request){
  32. Map<String, Object> map = new HashMap<String,Object>(16);
  33. //获取用户
  34. user = this.getUser(request);
  35. //检验用户正确性
  36. if(user == null || user.getId() == null) {
  37. map.put("code", -1);
  38. map.put("msg", "用户不存在,无法执行操作.");
  39. return map;
  40. }
  41. CustomerExample example = new CustomerExample();
  42. Criteria criteria = example.createCriteria();
  43. //设置分页参数
  44. if(page == null || page <= 0) {
  45. page = 1;
  46. }
  47. if(limit == null || limit <= 0) {
  48. limit = 10;
  49. }
  50. String all = "all";
  51. if(!all.equals(findtype)) {
  52. example.setLimit(limit);
  53. Long offset = new Long((page-1)*limit);
  54. example.setOffset(offset);
  55. }
  56. //设置管理者ID
  57. criteria.andManagerIdEqualTo(user.getId());
  58. //只查询未删除的客户
  59. criteria.andDeleteStatusEqualTo(0);
  60. System.out.println(customer);
  61. //检测属性是否存在,存在则进行条件查询
  62. if(customer != null) {
  63. if(customer.getName() != null) {
  64. criteria.andNameLike("%" + customer.getName() + "%");
  65. }
  66. if(customer.getType() != null && !"".equals(customer.getType())) {
  67. criteria.andTypeEqualTo(customer.getType());
  68. }
  69. if(customer.getStatus() != null && !"".equals(customer.getStatus())) {
  70. criteria.andStatusEqualTo(customer.getStatus());
  71. }
  72. if(customer.getSource() != null && !"".equals(customer.getSource())) {
  73. criteria.andSourceEqualTo(customer.getSource());
  74. }
  75. if(customer.getLevel() != null && !"".equals(customer.getLevel())) {
  76. criteria.andLevelEqualTo(customer.getLevel());
  77. }
  78. if(customer.getCredit() != null && !"".equals(customer.getCredit())) {
  79. criteria.andCreditEqualTo(customer.getCredit());
  80. }
  81. if(customer.getMaturity() != null && !"".equals(customer.getMaturity())) {
  82. criteria.andMaturityEqualTo(customer.getMaturity());
  83. }
  84. }
  85. Long count = customerService.countByCustomerExample(example);
  86. List<Customer> customers = customerService.selectByCustomerExample(example);
  87. map.put("data", customers);
  88. map.put("count", count);
  89. map.put("code", 0);
  90. return map;
  91. }
  92. /**
  93. *
  94. * 描述:添加一个客户
  95. * @author huangwanzong
  96. * @date 2018/07/17
  97. * @version 1.0
  98. * @param customer 客户信息
  99. * @param linkman 联系人信息
  100. * @param customerName 客户名称
  101. * @param linkmanName 联系人名称
  102. * @param customerLevel 客户等级
  103. * @param request
  104. * @return Map<String,Object>
  105. * @since 1.8
  106. *
  107. */
  108. @RequiresPermissions("5002")
  109. @Operation(name="添加客户")
  110. @RequestMapping("add")
  111. @ResponseBody
  112. public Map<String, Object> addCustomer(Customer customer,Linkman linkman,String customerName,String linkmanName,String customerLevel,HttpServletRequest request){
  113. Map<String, Object> map = new HashMap<String,Object>(16);
  114. this.getUser(request);
  115. //检测是否存在customer对象
  116. if(customer == null || linkman == null) {
  117. map.put("msg", "参数为空");
  118. map.put("success", false);
  119. return map;
  120. }
  121. //检测客户名是否存在
  122. if(customerName == null || "".equals(customerName)) {
  123. map.put("msg", "用户名称参数不能为空");
  124. map.put("success", false);
  125. return map;
  126. }
  127. //检测联系人姓名是否存在
  128. if(linkmanName == null || "".equals(linkmanName)) {
  129. map.put("msg", "联系人名称参数不能为空");
  130. map.put("success", false);
  131. return map;
  132. }
  133. //客户所属者默认为创建者
  134. customer.setManagerId(user.getId());
  135. //设置创建者id
  136. customer.setCreater(user.getId());
  137. //设置创建时间
  138. customer.setCreateTime(LocalDateTime.now());
  139. //设置客户名称
  140. customer.setName(customerName);
  141. //设置客户等级
  142. customer.setLevel(customerLevel);
  143. //设置未删除
  144. customer.setDeleteStatus(0);
  145. //设置联系人名称
  146. linkman.setName(linkmanName);
  147. //进行数据插入
  148. if(customerService.insertSelective(customer,linkman)) {
  149. map.put("msg", "添加成功");
  150. map.put("success", true);
  151. }else {
  152. map.put("msg", "添加失败");
  153. map.put("success", false);
  154. }
  155. return map;
  156. }
  157. @RequiresPermissions("7009")
  158. @Operation(name="检测客户名称是否存在")
  159. @RequestMapping("checkname")
  160. @ResponseBody
  161. public boolean checkCustomerName(String name){
  162. CustomerExample example = new CustomerExample();
  163. example.createCriteria().andNameEqualTo(name);
  164. List<Customer> list = customerService.selectByCustomerExample(example);
  165. if(list.size()>0) {
  166. return true;
  167. }
  168. return false;
  169. }
  170. @RequiresPermissions("5003")
  171. @Operation(name="更新客户信息")
  172. @RequestMapping("update")
  173. @ResponseBody
  174. public Map<String, Object> updateCustomer(Customer customer){
  175. Map<String, Object> map = new HashMap<String,Object>(16);
  176. if(customerService.updateCustomerByPrimaryKeySelective(customer)) {
  177. map.put("msg", "更新成功");
  178. map.put("success", true);
  179. }else {
  180. map.put("msg", "更新失败");
  181. map.put("success", false);
  182. }
  183. return map;
  184. }
  185. @RequiresPermissions("5004")
  186. @Operation(name="删除客户")
  187. @RequestMapping("delete")
  188. @ResponseBody
  189. public Map<String, Object> deleteCustomer(int[] ids){
  190. Map<String, Object> map = new HashMap<String,Object>(16);
  191. List<Integer> success = new ArrayList<Integer>();
  192. List<Integer> fail = new ArrayList<Integer>();
  193. for(int id : ids) {
  194. if(customerService.deleteByPrimaryKey(id)) {
  195. success.add(id);
  196. }else {
  197. fail.add(id);
  198. }
  199. }
  200. map.put("msg", "删除完成");
  201. map.put("status", true);
  202. map.put("success", success);
  203. map.put("fail", fail);
  204. return map;
  205. }
  206. @RequiresPermissions("7010")
  207. @Operation(name="id查找客户")
  208. @RequestMapping("find")
  209. @ResponseBody
  210. public Map<String, Object> findCustomer(Integer id){
  211. Map<String, Object> map = new HashMap<String,Object>(16);
  212. Customer customer = null;
  213. if(id == null) {
  214. map.put("msg", "非法操作");
  215. map.put("success", false);
  216. return map;
  217. }
  218. customer = customerService.selectCustomerByPrimaryKey(id);
  219. if(customer != null) {
  220. map.put("msg", "查找成功");
  221. map.put("success", true);
  222. map.put("data", customer);
  223. }else {
  224. map.put("msg", "查找失败");
  225. map.put("success", false);
  226. }
  227. return map;
  228. }
  229. }

登录管理控制层:

  1. @Controller
  2. @RequestMapping("/user")
  3. public class LoginController {
  4. @Autowired
  5. private IUserService userService;
  6. private Logger logger = LoggerFactory.getLogger(LoginController.class);
  7. /**
  8. *
  9. * 描述:登陆
  10. * @author wanghaoyu
  11. * @version 1.0
  12. * @param user 用户
  13. * @param verifyCode 验证码
  14. * @param request 请求
  15. * @return Map<String,Object> map封装要返回到前端的信息
  16. * @exception Nothing
  17. * @since 1.8
  18. *
  19. */
  20. @Operation(name="登陆")
  21. @RequestMapping("/login")
  22. @ResponseBody
  23. public Map<String, Object> login(User user, String verifyCode,
  24. HttpServletRequest request){
  25. Map<String, Object> maps = new HashMap<String, Object>(16);
  26. //1. 验证验证码
  27. if(verifyCode == null || "".equals(verifyCode) ) {
  28. maps.put("code", 200);
  29. maps.put("msg", "请输入验证码");
  30. return maps;
  31. }
  32. verifyCode = verifyCode.toLowerCase();
  33. String sessionCode = (String) request.getSession().getAttribute("verifyCode");
  34. if( sessionCode == null || "".equals(sessionCode)){
  35. maps.put("code", 200);
  36. maps.put("msg", "验证码获取失败! 请刷新页面!");
  37. return maps;
  38. }
  39. sessionCode = sessionCode.toLowerCase();
  40. if(!sessionCode.equals(verifyCode)) {
  41. maps.put("code", 200);
  42. maps.put("msg", "验证码不正确!");
  43. return maps;
  44. }
  45. //2.判断用户账号密码
  46. Subject subject = SecurityUtils.getSubject();
  47. System.err.println("==============================" +subject.isAuthenticated());
  48. //判断用户是否已经登陆
  49. if(!subject.isAuthenticated()) {
  50. UsernamePasswordToken token = new UsernamePasswordToken(user.getAccount(),user.getPassword());
  51. try {
  52. subject.login(token);
  53. //验证成功
  54. //登陆成功后的用户账号信息
  55. String account = (String)subject.getPrincipal();
  56. //根据用户账号,查询用户,并保存到session域中
  57. User loginUser = userService.findByAccount(account);
  58. LocalDateTime now = LocalDateTime.now();
  59. //如果上次登陆的时间为空,则说明这次是首次登陆,前台应该跳转到修改密码界面
  60. if(loginUser.getLastLoginTime() == null) {
  61. maps.put("firstLogin", true);
  62. }
  63. //修改最后一次登录的时间,并保存到数据库
  64. loginUser.setLastLoginTime(now);
  65. loginUser.setPassword(null);
  66. //新创建对象用来更新user的最后一次登录时间
  67. User updateUser = new User();
  68. updateUser.setId(loginUser.getId());
  69. updateUser.setLastLoginTime(now);
  70. userService.edit(updateUser);
  71. request.getSession().setAttribute("user", loginUser);
  72. logger.info("登陆的用户信息:" + loginUser.toString());
  73. request.getSession().setAttribute("user", loginUser);
  74. maps.put("code", 0);
  75. //账号被锁定
  76. } catch(LockedAccountException e){
  77. maps.put("code",200);
  78. maps.put("msg","账号已被锁定,请联系管理员进行处理!");
  79. //不存在的账号
  80. } catch(UnknownAccountException e) {
  81. maps.put("code",200);
  82. maps.put("msg","账号或密码错误!");
  83. //密码错误
  84. } catch(IncorrectCredentialsException e) {
  85. maps.put("code",200);
  86. maps.put("msg","账号或密码错误!");
  87. }catch (Exception e) {
  88. e.printStackTrace();
  89. maps.put("code", 200);
  90. maps.put("msg", "系统出了小差,请稍等...");
  91. }
  92. }else {
  93. maps.put("code", 0);
  94. }
  95. return maps;
  96. }
  97. /**
  98. *
  99. * 描述:
  100. * @author wanghaoyu
  101. * @version 1.0
  102. * @param request request请求
  103. * @return ModelAndView
  104. * @exception Nothing
  105. * @since 1.8
  106. *
  107. */
  108. @Operation(name="注销")
  109. @RequestMapping("/logout")
  110. public ModelAndView logout(HttpServletRequest request) {
  111. ModelAndView view = new ModelAndView();
  112. //获取shiro中的用户
  113. Subject subject = SecurityUtils.getSubject();
  114. //获取用户账号信息
  115. String account = (String) subject.getPrincipal();
  116. if(account != null) {
  117. //登出
  118. subject.logout();
  119. //同时删除session中的用户信息
  120. request.getSession().removeAttribute("user");
  121. request.getSession().invalidate();
  122. }
  123. //重定向到登陆页面
  124. view.setViewName("redirect:/pages/login.jsp");
  125. return view;
  126. }
  127. }

系统用户管理控制层:

  1. @Controller
  2. @RequestMapping("/user")
  3. public class UserController {
  4. @Autowired
  5. IUserService userService;
  6. @Autowired
  7. IRoleService roleService;
  8. @Autowired
  9. RedisUtil redisUtil;
  10. @Autowired
  11. MailUtil mailUtil;
  12. Logger logger = LoggerFactory.getLogger(UserController.class);
  13. /**
  14. * 描述:查找用户
  15. * @param page
  16. * @param limit
  17. * @param user
  18. * @return
  19. */
  20. @Operation(name="查找用户")
  21. @RequiresPermissions("1001")
  22. @RequestMapping("/findUser")
  23. @ResponseBody
  24. public Map<String, Object> findUser(Integer page,Integer limit, User user){
  25. Map<String, Object> map = new HashMap<String,Object>(16);
  26. //创建用户模板类
  27. UserExample userExample = new UserExample();
  28. //创建查询准则
  29. Criteria criteria = userExample.createCriteria();
  30. if(page == null || page <= 0) {
  31. page = 1;
  32. }
  33. if(limit == null || limit <= 0) {
  34. limit = 10;
  35. }
  36. //判断user类的条件是否为空
  37. if(user.getRealName() != null) {
  38. criteria.andRealNameLike("%"+user.getRealName()+"%");
  39. }
  40. if(user.getRoleId() != null) {
  41. logger.info("获得到的角色编号为:" + user.getRoleId());
  42. criteria.andRoleIdEqualTo(user.getRoleId());
  43. }
  44. if(user.getAccount() != null) {
  45. criteria.andAccountLike("%"+user.getAccount()+"%");
  46. }
  47. Long offset = new Long((page - 1) * limit);
  48. Long count = userService.countByExample(userExample);
  49. userExample.setLimit(limit);
  50. userExample.setOffset(offset);
  51. List<User> list = userService.findByExample(userExample);
  52. logger.info(list.toString());
  53. map.put("data", list);
  54. map.put("code", 0);
  55. map.put("msg", "success");
  56. map.put("count", count);
  57. return map;
  58. }
  59. /**
  60. *
  61. * 描述:根据编号查找用户
  62. * @author wanghaoyu
  63. * @version 1.0
  64. * @param id
  65. * @return
  66. * @exception Nothing
  67. * @since 1.8
  68. *
  69. */
  70. @Operation(name="根据编号查找用户")
  71. @RequiresAuthentication
  72. @RequestMapping("/findUserById")
  73. @ResponseBody
  74. public Map<String, Object> findUserById(Integer id){
  75. Map<String, Object> map = new HashMap<String, Object>(16);
  76. boolean success = false;
  77. String msg = "";
  78. User user = userService.findById(id);
  79. if(user != null){
  80. user.setPassword(null);
  81. user.setSalt(null);
  82. success = true;
  83. }else{
  84. msg = "读取用户数据出错,请稍后再试!";
  85. }
  86. map.put("success", success);
  87. map.put("user", user);
  88. map.put("msg",msg);
  89. map.put("code", 0);
  90. return map;
  91. }
  92. /**
  93. *
  94. * 描述:根据用户ID删除用户
  95. * @author wanghaoyu
  96. * @version 1.0
  97. * @param id 用户编号
  98. * @return Map<String,Object>
  99. * @exception Nothing
  100. * @since 1.8
  101. *
  102. */
  103. @Operation(name="删除用户")
  104. @RequiresPermissions("1004")
  105. @RequestMapping("/deleteUser")
  106. @ResponseBody
  107. public Map<String, Object> deleteUser(Integer id){
  108. Map<String, Object> map = new HashMap<String, Object>(16);
  109. boolean success = false;
  110. //删除成功
  111. if(userService.deleteById(id) == true) {
  112. success = true;
  113. }
  114. map.put("success", success);
  115. map.put("code", 0);
  116. return map;
  117. }
  118. /**
  119. *
  120. * 描述:编辑用户
  121. * @author wanghaoyu
  122. * @version 1.0
  123. * @param user 要编辑的用户信息
  124. * @return Map<String,Object>
  125. * @exception Nothing
  126. * @since 1.8
  127. *
  128. */
  129. @Operation(name="修改用户")
  130. @RequiresPermissions(value={"1002","13002"}, logical=Logical.OR)
  131. @RequestMapping("/editUser")
  132. @ResponseBody
  133. public Map<String, Object> editUser(User user){
  134. Map<String, Object> map = new HashMap<String, Object>(16);
  135. boolean success = false;
  136. String msg = "";
  137. //修改成功
  138. if(userService.edit(user) == true) {
  139. success = true;
  140. msg = "修改成功!";
  141. }else {
  142. msg = "修改失败!";
  143. }
  144. map.put("success", success);
  145. map.put("msg", msg);
  146. map.put("code", 0);
  147. return map;
  148. }
  149. /**
  150. *
  151. * 描述:添加用户
  152. * @author wanghaoyu
  153. * @version 1.0
  154. * @param user 要添加的用户信息
  155. * @return Map<String,Object>
  156. * @exception Nothing
  157. * @since 1.8
  158. *
  159. */
  160. @Operation(name="添加用户")
  161. @RequiresPermissions("1003")
  162. @RequestMapping("/addUser")
  163. @ResponseBody
  164. public Map<String, Object> addUser(User user){
  165. Map<String, Object> map = new HashMap<String, Object>(16);
  166. boolean success = false;
  167. //设置user的初始密码为123456
  168. user.setPassword("123456");
  169. //添加
  170. if(userService.save(user) == true) {
  171. success = true;
  172. }
  173. map.put("success", success);
  174. map.put("code", 0);
  175. return map;
  176. }
  177. /**
  178. *
  179. * 描述:查找所有的角色
  180. * @author wanghaoyu
  181. * @version 1.0
  182. * @return Map<String,Object>
  183. * @exception Nothing
  184. * @since 1.8
  185. *
  186. */
  187. @Operation(name="后台查找角色列表")
  188. @RequiresAuthentication
  189. @RequestMapping("/findRoles")
  190. @ResponseBody
  191. public Map<String, Object> findRoles(){
  192. Map<String, Object> map = new HashMap<String, Object>(16);
  193. List<Role> roles = roleService.selectByRoleExample(new RoleExample());
  194. map.put("success", true);
  195. map.put("list", roles);
  196. logger.info(roles.toString());
  197. return map;
  198. }
  199. /**
  200. *
  201. * 描述:查找除当前登录的客户经理外的所有的客户经理
  202. * @author wanghaoyu
  203. * @version 1.0
  204. * @param request
  205. * @return Map<String,Object>
  206. * @exception Nothing
  207. * @since 1.8
  208. *
  209. */
  210. @Operation(name="后台查找其他客户经理角色")
  211. @RequiresAuthentication
  212. @RequestMapping("/findOthersManager")
  213. @ResponseBody
  214. public Map<String, Object> findOthersManager(HttpServletRequest request){
  215. Map<String, Object> map = new HashMap<String, Object>(16);
  216. boolean success = false;
  217. //获取当前登录用户
  218. User user = (User)request.getSession().getAttribute("user");
  219. //创建用户模块
  220. UserExample userExample = new UserExample();
  221. //创建查询准则
  222. Criteria criteria = userExample.createCriteria();
  223. //如果当前用户为客户经理
  224. if(user.getRoleId() == 1) {
  225. criteria.andIdNotEqualTo(user.getId());
  226. }
  227. criteria.andRoleIdEqualTo(1);
  228. List<User> users = userService.findByExample(userExample);
  229. success = true;
  230. map.put("success", success);
  231. map.put("list", users);
  232. map.put("code", 0);
  233. return map;
  234. }
  235. /**
  236. *
  237. * 描述:检查用户账号是否可用
  238. * @author wanghaoyu
  239. * @version 1.0
  240. * @param account
  241. * @return Map<String,Object>
  242. * @exception Nothing
  243. * @since 1.8
  244. *
  245. */
  246. @Operation(name="检查用户账号")
  247. @RequestMapping("/checkUserAccount")
  248. @ResponseBody
  249. public Map<String, Object> checkUserAccount(String account){
  250. Map<String, Object> map = new HashMap<String, Object>(16);
  251. boolean success = false;
  252. //没有找到该账号名,说明账号可用
  253. if(userService.findByAccount(account) == null) {
  254. success = true;
  255. }
  256. map.put("success", success);
  257. map.put("code", 0);
  258. return map;
  259. }
  260. /**
  261. *
  262. * 描述:检查用户邮箱是否可用
  263. * @author wanghaoyu
  264. * @version 1.0
  265. * @param email
  266. * @return Map<String,Object>
  267. * @exception Nothing
  268. * @since 1.8
  269. *
  270. */
  271. @Operation(name="检查用户邮箱")
  272. @RequestMapping("/checkUserEmail")
  273. @ResponseBody
  274. public Map<String, Object> checkUserEmail(String email){
  275. Map<String, Object> map = new HashMap<String, Object>(16);
  276. boolean success = false;
  277. //没有找到该账号名,说明邮箱可用
  278. if(userService.findByEmail(email) == null) {
  279. success = true;
  280. }
  281. map.put("success", success);
  282. map.put("code", 0);
  283. return map;
  284. }
  285. /**
  286. *
  287. * 描述:根据session域里面的用户编号查找当前登录的用户
  288. * @author wanghaoyu
  289. * @version 1.0
  290. * @param id
  291. * @return Map<String,Object>
  292. * @exception Nothing
  293. * @since 1.8
  294. *
  295. */
  296. @Operation(name="查找当前登录的用户")
  297. @RequiresPermissions("13001")
  298. @RequestMapping("/findCurrentUser")
  299. @ResponseBody
  300. public Map<String, Object> findCurrentUser(Integer id){
  301. Map<String, Object> map = new HashMap<String, Object>(16);
  302. boolean success = false;
  303. String msg = "";
  304. //根据ID查找用户
  305. User user = userService.findById(id);
  306. if(user != null){
  307. user.setPassword(null);
  308. user.setSalt(null);
  309. success = true;
  310. msg = "查找成功!";
  311. }else{
  312. success = false;
  313. msg = "查找失败!";
  314. }
  315. map.put("success", success);
  316. map.put("code",0);
  317. map.put("data", user);
  318. map.put("msg", msg);
  319. return map;
  320. }
  321. /**
  322. *
  323. * 描述:用户修改密码
  324. * @author wanghaoyu
  325. * @version 1.0
  326. * @param user
  327. * @return Map<String,Object>
  328. * @exception Nothing
  329. * @since 1.8
  330. *
  331. */
  332. @Operation(name="修改用户密码")
  333. @RequiresPermissions("14001")
  334. @RequestMapping("/editUserPasswd")
  335. @ResponseBody
  336. public Map<String, Object> editUserPasswd(User user,String oldPassword){
  337. Map<String, Object> map = new HashMap<String, Object>(16);
  338. boolean success = false;
  339. String msg = "";
  340. if(userService.editPasswd(user,oldPassword)) {
  341. success = true;
  342. msg = "修改成功!";
  343. }else {
  344. success = false;
  345. msg = "修改失败!";
  346. }
  347. map.put("success", success);
  348. map.put("msg", msg);
  349. map.put("code", 0);
  350. return map;
  351. }
  352. /**
  353. *
  354. * 描述:获取忘记密码时的验证码
  355. * @author wanghaoyu
  356. * @version 1.0
  357. * @param email
  358. * @return
  359. * @exception Nothing
  360. * @since 1.8
  361. *
  362. */
  363. @Operation(name="获取找回密码所需的验证码")
  364. @RequestMapping("/getForgotPasswdCode")
  365. @ResponseBody
  366. public Map<String, Object> getForgotPasswdCode(String email){
  367. Map<String, Object> map = new HashMap<String, Object>(16);
  368. boolean success = false;
  369. String msg = "";
  370. if(userService.findByEmail(email) == null){
  371. //找不到该邮箱的账号
  372. msg = "不存在的账号!";
  373. }else{
  374. try {
  375. //生成长度为4的随机数字
  376. String code = RandomStringUtil.getRandomCode(4, 0);
  377. //存到redis缓存中,有效时间为5分钟
  378. //先删除原来已存在的验证码
  379. redisUtil.remove(email);
  380. redisUtil.set(email, code, 300L);
  381. //发送邮件
  382. mailUtil.send(email, "找回密码", "验证码:" + code + "(验证码有效期为5分钟)");
  383. success = true;
  384. msg = "发送验证码成功!";
  385. } catch (Exception e) {
  386. e.printStackTrace();
  387. msg = "获取验证码失败!";
  388. }
  389. }
  390. map.put("success", success);
  391. map.put("code", 0);
  392. map.put("msg", msg);
  393. return map;
  394. }
  395. /**
  396. *
  397. * 描述: 重设密码
  398. * @author wanghaoyu
  399. * @version 1.0
  400. * @param email
  401. * @return
  402. * @exception Nothing
  403. * @since 1.8
  404. *
  405. */
  406. @Operation(name="重设密码")
  407. @RequestMapping("/resetPasswd")
  408. @ResponseBody
  409. public Map<String, Object> resetPasswd(String email, String code, String password){
  410. Map<String, Object> map = new HashMap<String, Object>(16);
  411. boolean success = false;
  412. String msg = "";
  413. try {
  414. //先根据邮箱获取相应用户的信息
  415. User user = userService.findByEmail(email);
  416. if(user == null){
  417. msg = "不存在的账号!";
  418. }else{
  419. //从redis缓存中获取验证码
  420. if(redisUtil.exists(email)){
  421. String redisCode = (String) redisUtil.get(email);
  422. if(redisCode.equals(code)){
  423. //验证码正确,修改密码
  424. User editUser = new User();
  425. editUser.setId(user.getId());
  426. editUser.setPassword(password);
  427. if(userService.edit(editUser)){
  428. msg = "修改成功!";
  429. success = true;
  430. }else{
  431. msg = "修改失败!";
  432. }
  433. }else{
  434. msg = "验证码错误!";
  435. }
  436. }else{
  437. msg = "验证码已过期,请重新获取!";
  438. }
  439. }
  440. } catch (Exception e) {
  441. e.printStackTrace();
  442. msg = "服务器出了小差,请稍等...";
  443. }
  444. map.put("success", success);
  445. map.put("code", 0);
  446. map.put("msg", msg);
  447. return map;
  448. }
  449. }

源码获取:博客首页 "资源" 里下载! 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/155656
推荐阅读
相关标签
  

闽ICP备14008679号