This commit is contained in:
wangjinlei
2023-09-26 16:55:44 +08:00
parent e42d0243cd
commit 1755a78a8d
16 changed files with 159 additions and 146 deletions

View File

@@ -41,7 +41,7 @@ public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper {
@Override
public ServletInputStream getInputStream() throws IOException {
//非json类型直接返回
if(!MediaType.APPLICATION_JSON_VALUE.equalsIgnoreCase(super.getHeader(HttpHeaders.CONTENT_TYPE))){
if(!MediaType.APPLICATION_JSON_VALUE.equalsIgnoreCase(super.getHeader(HttpHeaders.CONTENT_TYPE))||!MediaType.MULTIPART_FORM_DATA_VALUE.equalsIgnoreCase(super.getHeader(HttpHeaders.CONTENT_TYPE))||!MediaType.APPLICATION_FORM_URLENCODED_VALUE.equalsIgnoreCase(super.getHeader(HttpHeaders.CONTENT_TYPE))){
return super.getInputStream();
}

View File

@@ -42,23 +42,23 @@ public class AppLoginController {
/**
* 登录
*/
@PostMapping("login")
@ApiOperation("登录")
public R login(@RequestBody LoginForm form){
//表单校验
ValidatorUtils.validateEntity(form);
//用户登录
long userId = userService.login(form);
//生成token
String token = jwtUtils.generateToken(userId);
Map<String, Object> map = new HashMap<>();
map.put("token", token);
map.put("expire", jwtUtils.getExpire());
return R.ok(map);
}
// @PostMapping("login")
// @ApiOperation("登录")
// public R login(@RequestBody LoginForm form){
// //表单校验
// ValidatorUtils.validateEntity(form);
//
// //用户登录
// long userId = userService.login(form);
//
// //生成token
// String token = jwtUtils.generateToken(userId);
//
// Map<String, Object> map = new HashMap<>();
// map.put("token", token);
// map.put("expire", jwtUtils.getExpire());
//
// return R.ok(map);
// }
}

View File

@@ -11,7 +11,6 @@ package com.peanut.modules.app.controller;
import com.peanut.common.utils.R;
import com.peanut.common.validator.ValidatorUtils;
import com.peanut.modules.app.entity.UserEntity;
import com.peanut.modules.app.form.RegisterForm;
import com.peanut.modules.app.service.UserService;
import io.swagger.annotations.Api;
@@ -37,19 +36,19 @@ public class AppRegisterController {
@Autowired
private UserService userService;
@PostMapping("register")
@ApiOperation("注册")
public R register(@RequestBody RegisterForm form){
//表单校验
ValidatorUtils.validateEntity(form);
UserEntity user = new UserEntity();
user.setMobile(form.getMobile());
user.setUsername(form.getMobile());
user.setPassword(DigestUtils.sha256Hex(form.getPassword()));
user.setCreateTime(new Date());
userService.save(user);
return R.ok();
}
// @PostMapping("register")
// @ApiOperation("注册")
// public R register(@RequestBody RegisterForm form){
// //表单校验
// ValidatorUtils.validateEntity(form);
//
// UserEntity user = new UserEntity();
// user.setMobile(form.getMobile());
// user.setUsername(form.getMobile());
// user.setPassword(DigestUtils.sha256Hex(form.getPassword()));
// user.setCreateTime(new Date());
// userService.save(user);
//
// return R.ok();
// }
}

View File

@@ -12,7 +12,7 @@ package com.peanut.modules.app.controller;
import com.peanut.common.utils.R;
import com.peanut.modules.app.annotation.Login;
import com.peanut.modules.app.annotation.LoginUser;
import com.peanut.modules.app.entity.UserEntity;
import com.peanut.modules.book.entity.UserEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;

View File

@@ -1,51 +0,0 @@
/**
* Copyright (c) 2016-2019 人人开源 All rights reserved.
*
* https://www.renren.io
*
* 版权所有,侵权必究!
*/
package com.peanut.modules.app.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 用户
*
* @author Mark sunlightcs@gmail.com
*/
@Data
@TableName("tb_user")
public class UserEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 用户ID
*/
@TableId
private Long userId;
/**
* 用户名
*/
private String username;
/**
* 手机号
*/
private String mobile;
/**
* 密码
*/
private String password;
/**
* 创建时间
*/
private Date createTime;
}

View File

@@ -8,10 +8,10 @@
package com.peanut.modules.app.resolver;
import com.peanut.modules.app.entity.UserEntity;
import com.peanut.modules.app.service.UserService;
import com.peanut.modules.app.annotation.LoginUser;
import com.peanut.modules.app.interceptor.AuthorizationInterceptor;
import com.peanut.modules.book.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.MethodParameter;
import org.springframework.stereotype.Component;

View File

@@ -10,8 +10,8 @@ package com.peanut.modules.app.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.app.entity.UserEntity;
import com.peanut.modules.app.form.LoginForm;
import com.peanut.modules.book.entity.UserEntity;
/**
* 用户
@@ -20,12 +20,12 @@ import com.peanut.modules.app.form.LoginForm;
*/
public interface UserService extends IService<UserEntity> {
UserEntity queryByMobile(String mobile);
/**
* 用户登录
* @param form 登录表单
* @return 返回用户ID
*/
long login(LoginForm form);
// UserEntity queryByMobile(String mobile);
//
// /**
// * 用户登录
// * @param form 登录表单
// * @return 返回用户ID
// */
// long login(LoginForm form);
}

View File

@@ -13,10 +13,10 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.common.exception.RRException;
import com.peanut.common.validator.Assert;
import com.peanut.modules.app.dao.UserDao;
import com.peanut.modules.app.entity.UserEntity;
import com.peanut.modules.book.dao.UserDao;
import com.peanut.modules.app.form.LoginForm;
import com.peanut.modules.app.service.UserService;
import com.peanut.modules.book.entity.UserEntity;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Service;
@@ -24,21 +24,21 @@ import org.springframework.stereotype.Service;
@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {
@Override
public UserEntity queryByMobile(String mobile) {
return baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("mobile", mobile));
}
@Override
public long login(LoginForm form) {
UserEntity user = queryByMobile(form.getMobile());
Assert.isNull(user, "手机号或密码错误");
// public UserEntity queryByMobile(String mobile) {
// return baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("mobile", mobile));
// }
//密码错误
if(!user.getPassword().equals(DigestUtils.sha256Hex(form.getPassword()))){
throw new RRException("手机号或密码错误");
}
return user.getUserId();
}
// public long login(LoginForm form) {
// UserEntity user = queryByMobile(form.getMobile());
// Assert.isNull(user, "手机号或密码错误");
//
// //密码错误
// if(!user.getPassword().equals(DigestUtils.sha256Hex(form.getPassword()))){
// throw new RRException("手机号或密码错误");
// }
//
// return user.getUserId();
// }
}

View File

@@ -1,5 +1,4 @@
package com.peanut.modules.book.controller;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@@ -7,7 +6,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.R;
import com.peanut.modules.app.entity.UserEntity;
import com.peanut.modules.app.service.UserService;
import com.peanut.modules.book.dao.BookForumArticlesDao;
import com.peanut.modules.book.entity.*;
@@ -180,7 +178,8 @@ public class BookForumArticlesServiceController {
wrapper.orderByDesc(BookForumArticlesEntity::getCreateTime);
Page<BookForumArticlesEntity> bookForumArticlesEntityPage = bookForumArticlesService.getBaseMapper().selectPage(new Page<>(page, limit), wrapper);
for (BookForumArticlesEntity b:bookForumArticlesEntityPage.getRecords()){
b.setUser(userService.getById(b.getUserid()));
UserEntity byId = userService.getById(b.getUserid());
b.setUser(byId);
b.setComment(bookForumCommenService.getCommentsLimit(b.getId(),3));
}
return R.ok().put("page",bookForumArticlesEntityPage);
@@ -198,26 +197,28 @@ public class BookForumArticlesServiceController {
LambdaQueryWrapper<BookForumCommentEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(BookForumCommentEntity::getDelflag,0);
wrapper.eq(BookForumCommentEntity::getPid,0);
wrapper.eq(BookForumCommentEntity::getBfaid,forumId);
wrapper.orderByAsc(BookForumCommentEntity::getCreateTime);
Page<BookForumCommentEntity> bookForumCommentEntityPage = bookForumCommenService.getBaseMapper().selectPage(new Page<>(page, limit), wrapper);
for (BookForumCommentEntity b : bookForumCommentEntityPage.getRecords()){
b.setComments(bookForumCommenService.getChildComments(b.getId()));
b.setUser(userService.getById(b.getUserid()));
b.setPuser(userService.getById(b.getPuserid()));
b.setCommentsNum(bookForumCommenService.getCommentCountInComment(b.getId()));
}
return R.ok().put("page",bookForumCommentEntityPage);
}
/**
*
* 获取书评详情
* @param forumId
* @return
*/
@RequestMapping("/getForumdetail")
public R getForumdetail(@RequestParam Integer forumId){
return R.ok();
BookForumArticlesEntity byId = bookForumArticlesService.getById(forumId);
return R.ok().put("forum",byId);
}
/**
@@ -244,8 +245,8 @@ public class BookForumArticlesServiceController {
@RequestParam Integer forumId,
@RequestParam String content,
@RequestParam Integer userId,
@RequestParam(required = false,value = "0") Integer pid,
@RequestParam(required = false,value = "0") Integer puserId){
@RequestParam(required = false,defaultValue = "0") Integer pid,
@RequestParam(required = false,defaultValue = "0") Integer puserId){
BookForumArticlesEntity forumInfo = bookForumArticlesService.getById(forumId);
BookForumCommentEntity bookForumCommentEntity = new BookForumCommentEntity();
bookForumCommentEntity.setBfaid(forumId);
@@ -259,20 +260,6 @@ public class BookForumArticlesServiceController {
}
/**
* 添加书评项目
* @return
*/
@RequestMapping("/addForum")
public R addForum(@RequestParam Integer userId,@RequestParam String content){
return null;
}
@RequestMapping("/desc/{page}")
public R Descupd(@RequestParam Map<String, Object> params,@PathVariable("page") Integer page){
HashMap<Object, Object> map = new HashMap<>();

View File

@@ -6,10 +6,11 @@
* 版权所有侵权必究
*/
package com.peanut.modules.app.dao;
package com.peanut.modules.book.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.peanut.modules.app.entity.UserEntity;
import com.github.yulichang.base.MPJBaseMapper;
import com.peanut.modules.book.entity.UserEntity;
import org.apache.ibatis.annotations.Mapper;
/**
@@ -18,6 +19,6 @@ import org.apache.ibatis.annotations.Mapper;
* @author Mark sunlightcs@gmail.com
*/
@Mapper
public interface UserDao extends BaseMapper<UserEntity> {
public interface UserDao extends MPJBaseMapper<UserEntity> {
}

View File

@@ -1,12 +1,10 @@
package com.peanut.modules.book.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.peanut.modules.app.entity.UserEntity;
import lombok.Data;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 文章表主表

View File

@@ -2,7 +2,6 @@ package com.peanut.modules.book.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.peanut.modules.app.entity.UserEntity;
import lombok.Data;
import java.util.Date;
@@ -80,4 +79,7 @@ public class BookForumCommentEntity {
//子对话
@TableField(exist = false)
private List<BookForumCommentEntity> comments;
//子对话数量
@TableField(exist = false)
private Integer commentsNum;
}

View File

@@ -0,0 +1,65 @@
package com.peanut.modules.book.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
@Data
@TableName("user")
public class UserEntity {
private static final long serialVersionUID = 1L;
@TableId
@TableField("id")
private Integer id;
private String name;
private Integer age;
private Integer sex;
private String avatar;
private String nickname;
private String tel;
private String password;
private String vip;
@TableField("vip_start_time")
private Date vipStartTime;
@TableField("vip_validtime")
private Date vipValidtime;
@TableField("peanut_coin")
private BigDecimal peanutCoin;
@TableField("read_time")
private Date readTime;
@TableField("last_login_time")
private Date lastLoginTime;
@TableField("yljk_oid")
private String yljkOid;
@TableField("create_time")
private Date createTime;
@TableField("update_time")
private Date updateTime;
@TableField("del_flag")
private Integer delFlag;
private String remark;
}

View File

@@ -17,5 +17,7 @@ public interface BookForumCommenService extends IService<BookForumCommentEntit
Integer getCommentcount(Integer forum_id);
Integer getCommentCountInComment(Integer comment_id);
List<BookForumCommentEntity> getChildComments(Integer cid);
}

View File

@@ -1,16 +1,13 @@
package com.peanut.modules.book.service.impl;
import cn.com.marsoft.base.impl.BaseServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.Query;
import com.peanut.modules.app.entity.UserEntity;
import com.peanut.modules.app.service.UserService;
import com.peanut.modules.book.dao.BookForumCommentDao;
import com.peanut.modules.book.entity.BookForumArticlesEntity;
import com.peanut.modules.book.entity.BookForumCommentEntity;
import com.peanut.modules.book.service.BookForumCommenService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -83,6 +80,19 @@ public class BookForumCommenServiceImpl extends ServiceImpl<BookForumCommentDao,
wrapper.eq(BookForumCommentEntity::getDelflag,0);
wrapper.orderByAsc(BookForumCommentEntity::getCreateTime);
List<BookForumCommentEntity> bookForumCommentEntities = this.getBaseMapper().selectList(wrapper);
for (BookForumCommentEntity b:bookForumCommentEntities){
b.setUser(userService.getById(b.getUserid()));
b.setPuser(userService.getById(b.getPuserid()));
}
return bookForumCommentEntities;
}
@Override
public Integer getCommentCountInComment(Integer comment_id) {
LambdaQueryWrapper<BookForumCommentEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(BookForumCommentEntity::getPid,comment_id);
wrapper.eq(BookForumCommentEntity::getDelflag,0);
Integer integer = this.getBaseMapper().selectCount(wrapper);
return integer;
}
}

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.peanut.modules.app.dao.UserDao">
<mapper namespace="com.peanut.modules.book.dao.UserDao">
</mapper>