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()
没有合适的资源?快使用搜索试试~ 我知道了~
springboot003线上阅读系统
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共484个文件
js:125个
png:83个
java:67个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 16 浏览量
2023-12-03
21:11:05
上传
评论
收藏 7.8MB ZIP 举报
温馨提示
使用Microsoft公司的JSP开发工具,使用MSSQL制作系统的数据库,结合JSP技术,做一个具有页面样式设计站内新闻,用户注册,在线留言,书籍查询,关于本站,用户登录,按类别查询,查看书籍简介,阅读书籍正文,插入书签用户添加/查看/修改自己书库,是小型的网上阅读平台。
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![exe](https://img-home.csdnimg.cn/images/20210720083343.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
共 484 条
- 1
- 2
- 3
- 4
- 5
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
玥沐春风
- 粉丝: 108
- 资源: 745
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
- matlab神经网络的简单应用(用于预测光伏出力,输入为温度湿度等因素,输出为光伏出力).zip
- 面试资格确认c语言,一些常见的知识点以及简要说明
- Matlab基本算法智能微电网粒子群优化算法.zip
- 搜索网站-通过特定算法和系统,使用户能够在互联网上查找和获取相关信息的技术
- 基于Matlab和CPLEX的2变量机组组合调度程序.zip
- 2019华为杯研究生数学建模竞赛A题-基于 python 实现无线智能传播模型
- c语言连接两个字符串,一个简单的示例代码
- java EE 酒店管理系统项目源码
- 建模比赛数学建模、数据分析、工程设计数据清洗、特征提取或其他预处理步骤
- HTML Document Structure
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)