package com.zyy.book.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zyy.book.component.UserInterceptor;
import com.zyy.book.entity.*;
import com.zyy.book.exception.MyException;
import com.zyy.book.output.MyMsg;
import com.zyy.book.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Calendar;
import java.util.Date;
/**
* <p>
* 前端控制器
* </p>
*
* @author zyy
* @since 2021-02-23
*/
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private IUserService userService;
@Autowired
private IOrderService orderService;
@Autowired
private IRechargeService rechargeService;
@Autowired
private IBookService bookService;
@Autowired
private IBookChapterService bookChapterService;
@RequestMapping(method = RequestMethod.GET, path = "/logout")
public void logout(HttpServletRequest request, HttpServletResponse response) throws IOException {
HttpSession session = request.getSession();
session.removeAttribute(UserInterceptor.USER_SESSION_KEY);
response.sendRedirect("/");
}
@RequestMapping(method = RequestMethod.GET, path = "/login")
public ModelAndView login() {
return new ModelAndView("home/user/login");
}
@RequestMapping(method = RequestMethod.POST, path = "/login")
public MyMsg loginPost(@RequestParam String username,
@RequestParam String password,
HttpServletRequest request) throws MyException {
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
userQueryWrapper.eq("username", username);
User user = userService.getOne(userQueryWrapper);
if (user == null) {
throw new MyException("用户或密码不正确");
}
if (!user.getPassword().equals(DigestUtils.md5DigestAsHex(password.getBytes()))) {
throw new MyException("用户或密码不正确");
}
HttpSession session = request.getSession();
session.setAttribute(UserInterceptor.USER_SESSION_KEY, user);
/*更新时间*/
user.setUpdatedAt(LocalDateTime.now());
userService.saveOrUpdate(user);
return new MyMsg(MyMsg.SUCCESS, "登陆成功");
}
@RequestMapping(method = RequestMethod.GET, path = "/reg")
public ModelAndView reg() {
return new ModelAndView("home/user/reg");
}
@RequestMapping(method = RequestMethod.POST, path = "/reg")
public MyMsg regPost(@RequestBody User user) throws MyException {
if (!StringUtils.hasText(user.getUsername()) || !StringUtils.hasText(user.getPassword())) {
throw new MyException("用户名或密码不能为空");
}
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
userQueryWrapper.eq("username", user.getUsername());
int count = userService.count(userQueryWrapper);
if (count > 0) {
throw new MyException("用户名已存在");
}
if (user.getPhone().length() != 11) {
throw new MyException("手机号码长度为11位");
}
user.setPassword(DigestUtils.md5DigestAsHex(user.getPassword().getBytes()));
user.setBalance(new BigDecimal(0));
boolean save = userService.save(user);
if (!save) {
throw new MyException("注册失败");
}
return new MyMsg(MyMsg.SUCCESS, "", user);
}
@RequestMapping(method = RequestMethod.GET, path = "/index")
public ModelAndView index() {
return new ModelAndView("home/user/index");
}
@RequestMapping(method = RequestMethod.POST, path = "/vip")
public MyMsg vip(HttpServletRequest request) throws MyException {
HttpSession session = request.getSession();
User user1 = (User) session.getAttribute(UserInterceptor.USER_SESSION_KEY);
User user = userService.getById(user1.getId());
if (user.getVipExpirationAt() != null && user.getVipExpirationAt().isAfter(LocalDateTime.now())) {
throw new MyException("会员未过期");
}
if (user.getBalance().compareTo(new BigDecimal(100)) < 0) {
throw new MyException("开通VIP余额不足 ¥" + User.VIP_PRICE);
}
user.setBalance(user.getBalance().subtract(new BigDecimal(User.VIP_PRICE)));
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.YEAR, 1);
LocalDateTime localDateTime = LocalDateTime.ofInstant(calendar.toInstant(), ZoneOffset.systemDefault());
user.setVipExpirationAt(localDateTime);
userService.saveOrUpdate(user);
return new MyMsg(MyMsg.SUCCESS, "开通成功", user);
}
@RequestMapping(method = RequestMethod.GET, path = "/info")
public ModelAndView info(HttpServletRequest request) {
HttpSession session = request.getSession();
User user1 = (User) session.getAttribute(UserInterceptor.USER_SESSION_KEY);
User user = userService.getById(user1.getId());
return new ModelAndView("home/user/info", "user", user);
}
@RequestMapping(method = RequestMethod.POST, path = "/info")
public MyMsg infoPost(@RequestParam String gender,
@RequestParam String birthday,
@RequestParam String phone,
HttpServletRequest request) throws MyException, ParseException {
if (phone == null || phone.length() != 11) {
throw new MyException("手机号必须为11位");
}
HttpSession session = request.getSession();
User user1 = (User) session.getAttribute(UserInterceptor.USER_SESSION_KEY);
User user = userService.getById(user1.getId());
user.setGender(gender);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
user.setBirthday(simpleDateFormat.parse(birthday));
user.setPhone(phone);
userService.saveOrUpdate(user);
return new MyMsg(MyMsg.SUCCESS, "操作成功");
}
@RequestMapping(method = RequestMethod.GET, path = "/recharge")
public ModelAndView recharge(HttpServletRequest request) {
HttpSession session = request.getSession();
User user1 = (User) session.getAttribute(UserInterceptor.USER_SESSION_KEY);
User user = userService.getById(user1.getId());
ModelAndView view = new ModelAndView();
view.setViewName("home/user/recharge");
view.addObject("user", user);
view.addObject("vipPrice", User.VIP_PRICE);
return view;
}
@RequestMapping(method = RequestMethod.POST, path = "/recharge")
public MyMsg recharge(@RequestParam BigDecimal balance, HttpServletRequest request) throws MyException {
if (balance.compareTo(BigDecimal.ZERO) < 0) {
throw new MyException("金额必须大于0");
}
HttpSession session = request.getSession();
User user1 = (User) session.getAttribute(UserInterceptor.USER_SESSION_KEY);
User user = userService.getById(user1.getId());
if (user.getBalance() == null) {
user.setBalance(new BigDecimal(0));
}
BigDecimal newBalance = user.getBalance().add(balance);
user.setBalance(newBalance);
userService.saveOrUpdate(user);
/*log*/
Recharge recharge = new Recharge()
没有合适的资源?快使用搜索试试~ 我知道了~
Java毕业设计--SpringBoot+html5的线上阅读系统.zip
共484个文件
js:125个
png:83个
java:67个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 139 浏览量
2023-06-07
18:06:19
上传
评论
收藏 7.89MB ZIP 举报
温馨提示
Java 毕业设计,Java 课程设计,基于 SpringBoot 开发的,含有代码注释,新手也可看懂。毕业设计、期末大作业、课程设计、高分必看,下载下来,简单部署,就可以使用。 包含:项目源码、数据库脚本、软件工具等,前后端代码都在里面。 该系统功能完善、界面美观、操作简单、功能齐全、管理便捷,具有很高的实际应用价值。 项目都经过严格调试,确保可以运行! 1. 技术组成 前端:html/javascript 后台框架:SpringBoot 开发环境:idea 数据库:MySql(建议用 5.7 版本,8.0 有时候会有坑) 数据库工具:navicat 部署环境:Tomcat(建议用 7.x 或者 8.x 版本), maven
资源推荐
资源详情
资源评论
收起资源包目录
Java毕业设计--SpringBoot+html5的线上阅读系统.zip (484个子文件)
book.mwb.bak 21KB
mvnw.cmd 6KB
summernote-bs3.css 143KB
bootstrap.min.css 118KB
bootstrap.min14ed.css 118KB
style.min862f.css 97KB
style.min.css 97KB
style.css 53KB
animate.min.css 46KB
user.css 42KB
style.css 38KB
datepicker3.css 33KB
font-awesome.min93e3.css 26KB
ambiance.css 25KB
style.min.css 25KB
sweetalert.css 18KB
simditor.css 17KB
ui.jqgridffe4.css 16KB
style.css 15KB
layer.css 14KB
jasny-bootstrap.min.css 14KB
chosen.css 12KB
dropzone.css 11KB
fullcalendar.css 11KB
summernote.css 10KB
plyr.css 10KB
codemirror.css 7KB
blueimp-gallery.min.css 7KB
awesome-bootstrap-checkbox.css 7KB
toastr.min.css 7KB
webuploader-demo.min.css 6KB
jquery.steps.css 6KB
footable.core.css 5KB
layer.css 5KB
jquery.fancybox.css 5KB
dataTables.bootstrap.css 5KB
bootstrap-table.min.css 4KB
clockpicker.css 4KB
basic.css 4KB
bootstrap-colorpicker.min.css 3KB
cropper.min.css 3KB
ion.rangeSlider.css 3KB
jquery.nouislider.css 3KB
bootstrap-markdown.min.css 3KB
jquery.gritter.css 3KB
ion.rangeSlider.skinFlat.css 2KB
login.min.css 1KB
custom.css 1KB
bootstrap-treeview.css 1KB
fullcalendar.print.css 660B
switchery.css 611B
webuploader.css 515B
morris-0.4.3.min.css 443B
fontawesome-webfont93e3.eot 67KB
fontawesome-webfontd41d.eot 67KB
qd_iconfont.eot 49KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regulard41d.eot 20KB
iconfont.eot 7KB
iconfont.eot 7KB
footable.eot 5KB
footabled41d.eot 5KB
fancybox_loading@2x.gif 14KB
loading.gif 11KB
fancybox_loading.gif 6KB
loading-0.gif 6KB
loading.gif 4KB
loading-2.gif 2KB
loading-upload.gif 2KB
loading-1.gif 701B
blank.gif 43B
ie-spacer.gif 43B
.gitignore 422B
read.html 13KB
detail.html 8KB
list.html 7KB
edit.html 7KB
add.html 7KB
reg.html 6KB
category.html 5KB
search.html 5KB
list.html 5KB
index.html 5KB
readRecord.html 4KB
edit.html 4KB
rank.html 4KB
add.html 4KB
list.html 4KB
login.html 3KB
list.html 3KB
index.html 3KB
recharge.html 3KB
edit.html 3KB
add.html 3KB
password.html 3KB
count.html 3KB
login.html 3KB
info.html 2KB
new.html 2KB
right.html 2KB
共 484 条
- 1
- 2
- 3
- 4
- 5
资源评论
gdutxiaoxu
- 粉丝: 1543
- 资源: 3119
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- (175923204)JAVAWEB校园订餐系统项目源码.rar
- (170624028)ffmpeg+SDL2的简易流媒体播放器,仅供大家参考学习 缺少dll库,在我资源里面下载ffmpeg+SDL2较新发布那个有
- 基于java+ssm+mysql+微信小程序的付费自习室系统 源码+数据库(高分毕业设计).zip
- (14638450)最简单的基于FFMPEG+SDL的音频播放器(2014.5.6)
- 基于java+springboot+mysql+微信小程序的校园点餐系统 源码+数据库+论文(高分毕业设计).zip
- (174871244)自适应动态规划(近似动态规划)-ADP MATLAB-MATLAB编程
- (175426820)ChatGPT接入项目实例【 AI问答小程序源码-内置3.5接口】.rar
- (21614630)STM32F10xUSB开发工具包-cn 20181126
- 简单的登录系统-MySQL+Node.JS服务端+HTML+JS
- 全自动焊锡机sw18可编辑全套技术资料100%好用.zip
- 平台所需服务器、数据库、操作系统安全技术要点梳理
- 使用py异步编程实现接口并发测试
- 批量QSO生成ADIF工具是一款方便快捷的工具,用于生成ADIF格式的QSO日志文件 通过输入一串QSO信息,用户可以轻松生成符合规范的ADIF文件,以便快速上传lotw日志
- IMG_1134.JPG
- qt/C++ 学习笔记 MD5文件重复搜索工具
- html+css 圣诞树html网页代码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功