Merge pull request #1 from Chuyaoyuan/master

v1 merge
This commit is contained in:
2023-07-31 22:24:30 +08:00
committed by GitHub
25 changed files with 122 additions and 117 deletions
@@ -3,7 +3,6 @@ package com.yaoyuan.jiscuss.common;
import com.yaoyuan.jiscuss.entity.custom.PostCustom;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -18,8 +17,11 @@ import java.util.List;
@Data
public class Node {
/**
* Node
* 空方法
**/
public Node() {
}
private Integer id;
@@ -52,7 +54,10 @@ public class Node {
private Date createTime;
//用户表相关
/**
* avatar
* 用户表相关
**/
private String avatar;
private String username;
@@ -116,7 +121,10 @@ public class Node {
return firstList;
}
//打印
/**
* 打印
* show
**/
public static void show(List<Node> list) {
for (Node node : list) {
System.out.println(node.getUserId() + " 用户回复了你:" + node.getContent());
@@ -14,16 +14,14 @@ import java.util.Map;
/**
* @author yaoyuan2.chu
* @Title:
* @Title: 工具类
* @Package com.yaoyuan.jiscuss.common
* @Description:
* @Description: 通用工具类
* @date 2020/9/10 15:47
*/
public class PostCommonUtil {
public static List<PostCustom> getNewPostsObjMap(List<Map<String, Object>> posts) {
List<PostCustom> postCustomList = new ArrayList<>();
for (Map<String, Object> mapObj : posts) {
PostCustom postCustom = new PostCustom();
@@ -72,6 +70,11 @@ public class PostCommonUtil {
return postCustomList;
}
/**
* 获取post
* @param postCustomList
* @return List<PostCustom>
*/
public static List<PostCustom> getNewPostsObjCustom(List<PostCustom> postCustomList) {
List<PostCustom> mainList = new ArrayList<>();
Map<String, Object> postMap = new LinkedHashMap<>();
@@ -101,17 +104,18 @@ public class PostCommonUtil {
mainListResult.add(mapObj);
}
}
return mainListResult;
}
// Clob类型转换成String类型
/**
* Clob类型转换成String类型
* @param clob
* @return
*/
public static String clobToString(final Clob clob) {
if (clob == null) {
return null;
}
Reader is = null;
try {
is = clob.getCharacterStream();
@@ -119,14 +123,12 @@ public class PostCommonUtil {
e.printStackTrace();
}
BufferedReader br = new BufferedReader(is);
String str = null;
try {
str = br.readLine(); // 读取第一行
} catch (Exception e) {
e.printStackTrace();
}
StringBuffer sb = new StringBuffer();
while (str != null) { // 如果没有到达流的末尾,则继续读取下一行
sb.append(str);
@@ -136,9 +138,7 @@ public class PostCommonUtil {
e.printStackTrace();
}
}
String returnString = sb.toString();
return returnString;
}
}
@@ -7,16 +7,19 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
/*
* addResourceHandlers
* void
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
registry.addResourceHandler("/static/**")
.addResourceLocations("classpath:/static/");
}
}
@@ -18,15 +18,16 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
* prePostEnabled :决定Spring Security的前注解是否可用 [@PreAuthorize,@PostAuthorize,..]
* secureEnabled : 决定是否Spring Security的保障注解 [@Secured] 是否可用
* jsr250Enabled :决定 JSR-250 annotations 注解[@RolesAllowed..] 是否可用.
* 开启 Spring Security 方法级安全注解 @EnableGlobalMethodSecurity
*/
@Configurable
@EnableWebSecurity
//开启 Spring Security 方法级安全注解 @EnableGlobalMethodSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private CustomAccessDeniedHandler customAccessDeniedHandler;
@Qualifier("userDetailServiceImpl")
@Autowired
private UserDetailsService userDetailsService;
@@ -61,13 +62,13 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers("/login/**", "/initUserData")//不拦截登录相关方法
.permitAll()
//.antMatchers("/user").hasRole("ADMIN") // user接口只有ADMIN角色的可以访问
// .anyRequest()
// .authenticated()// 任何尚未匹配的URL只需要验证用户即可访问
//.anyRequest()
//.authenticated()// 任何尚未匹配的URL只需要验证用户即可访问
.anyRequest()
.access("@rbacPermission.hasPermission(request, authentication)")//根据账号权限访问
.and()
.formLogin()
// .loginPage("/")
//.loginPage("/")
.loginPage("/login") //登录请求页
.loginProcessingUrl("/login") //登录POST请求路径
.usernameParameter("username") //登录用户名参数
@@ -92,7 +93,6 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
/**
* 密码加密算法
*
* @return
*/
@Bean
@@ -100,4 +100,5 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
return new BCryptPasswordEncoder();
}
}
@@ -9,25 +9,34 @@ import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
/**
* @author yaoyuan2.chu
* 后台系统控制器
*/
@Controller
public class AdminSystemController {
//后台登录
/**
* 后台登录
*/
//后台退出
/**
* 后台退出
*/
@RequestMapping("/admin/logout")
public String logout(@RequestParam(defaultValue = "discussion") String type, HttpServletRequest request, ModelMap map) {
return "admin/logout";
}
//后台设置管理
/**
* 后台设置管理
*/
/**
* 后台页面
*
* @return
*/
@RequestMapping("/admin/home")
public String user(@RequestParam(defaultValue = "discussion") String type, HttpServletRequest request, ModelMap map) {
public String home(@RequestParam(defaultValue = "discussion") String type, HttpServletRequest request, ModelMap map) {
return "admin/home";
}
}
@@ -3,6 +3,7 @@ package com.yaoyuan.jiscuss.controller;
import org.springframework.stereotype.Controller;
/**
* @author yaoyuan2.chu
* 用户消息控制器
*/
@Controller
@@ -3,10 +3,13 @@ package com.yaoyuan.jiscuss.controller;
import org.springframework.stereotype.Controller;
/**
* @author yaoyuan2.chu
* 其他控制器——积分/权限等
*/
@Controller
public class UserOtherController extends BaseController {
//用户积分获取
/**
* 用户积分获取
*/
}
@@ -35,7 +35,6 @@ public class UserPageController extends BaseController {
@Autowired
private ITagsService tagsService;
/**
* 用户页面
*
@@ -44,12 +43,15 @@ public class UserPageController extends BaseController {
@RequestMapping("/user")
public String user(@RequestParam(defaultValue = "discussion") String type, HttpServletRequest request, ModelMap map) {
// type 判断
if (type.equals("discussion")) {
map.put("discussion", "active");
}
if (type.equals("change")) {
map.put("change", "active");
}
if (type.equals("like")) {
map.put("like", "active");
}
@@ -59,6 +61,8 @@ public class UserPageController extends BaseController {
map.put("username", user.getUsername());
map.put("data", "Jiscuss 用户:" + user.getUsername());
}
return "user";
}
}
@@ -32,6 +32,7 @@ import java.util.Date;
import java.util.List;
/**
* @author yaoyuan2.chu
* 主题帖子评论控制器
*/
@Controller
@@ -55,10 +56,18 @@ public class UserPostController extends BaseController {
private IUsersService usersService;
//首页查看主题列表(各种条件筛选,最热最新标签等)
/**
* 首页查看主题列表(各种条件筛选,最热最新标签等)
*/
//查看主题详情
/**
* 查看主题详情
* @param request
* @param map
* @param id
* @return
*/
@RequestMapping("/getdiscussionsbyid")
public String getDiscussionsById(HttpServletRequest request, ModelMap map, @RequestParam("id") Integer id) {
logger.info(">>> getDiscussionsById{}", id);
@@ -82,7 +91,6 @@ public class UserPostController extends BaseController {
newdd.setUsernameLast(lastUser.getUsername());
}
List<Tag> tags = tagsService.findByDId(id);
List postsObj = postsService.findPostCustomById(id);
map.put("tags", tags);
@@ -114,14 +122,12 @@ public class UserPostController extends BaseController {
discussion.setCreateId(user.getId());
}
discussion.setCreateTime(new Date());
discussion.setStartTime(new Date());
discussion.setLastTime(new Date());
Discussion discussionOne = new Discussion();
BeanUtils.copyProperties(discussion, discussionOne);
Discussion saveDiscussion = discussionsService.insert(discussionOne);
if (null != discussion.getTag()) {
@@ -138,7 +144,7 @@ public class UserPostController extends BaseController {
JSONObject resultobj = new JSONObject();
logger.info(">>>{}", saveDiscussion);
resultobj.put("msg", "添加成功");
resultobj.put("msg", "添加主题成功");
resultobj.put("flag", true);
return resultobj.toString(); //
@@ -178,14 +184,13 @@ public class UserPostController extends BaseController {
if (null != post.getParentId()) {
Post temp = postsService.findOneByid(post.getParentId());
post.setUserId(temp.getCreateId());
}
Post savePost = postsService.insert(post);
JSONObject resultobj = new JSONObject();
logger.info(">>>{}", savePost);
resultobj.put("msg", "添加成功");
resultobj.put("msg", "添加评论成功");
resultobj.put("flag", true);
return resultobj.toString(); //
}
@@ -205,7 +210,6 @@ public class UserPostController extends BaseController {
@ResponseBody
public String newTags(@RequestBody Tag tag) {
logger.info(">>> newTags" + tag);
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = servletRequestAttributes.getRequest();
@@ -219,13 +223,14 @@ public class UserPostController extends BaseController {
JSONObject resultobj = new JSONObject();
logger.info(">>>{}", saveTag);
resultobj.put("msg", "添加成功");
resultobj.put("msg", "添加标签成功");
resultobj.put("flag", true);
return resultobj.toString(); //
return resultobj.toString();
}
//排行榜等
/**
* 排行榜等
*/
/**
* 新建主题页
@@ -236,7 +241,6 @@ public class UserPostController extends BaseController {
*/
@RequestMapping({"/newDiscussionsPage"})
public String newdiccuss(HttpServletRequest request, ModelMap map) {
//获取所有标签(以后尝试去缓存中取)
List<Tag> allTags = tagsService.getAllListDiscussions();
map.put("allTags", allTags);
@@ -30,11 +30,11 @@ import java.util.List;
import java.util.Map;
/**
* @author yaoyuan2.chu
* 首页页面系统控制器
*/
@Controller
public class UserSystemController extends BaseController {
private static Logger logger = LoggerFactory.getLogger(UserSystemController.class);
@Autowired
@@ -48,7 +48,6 @@ public class UserSystemController extends BaseController {
/**
* 首页index
*
* @param tag
* @param type
* @param pageNum
@@ -62,7 +61,6 @@ public class UserSystemController extends BaseController {
logger.info(">>> index");
logger.info(">>> tag:" + tag);
logger.info(">>> pageNum:" + pageNum);
int pageSiz = 10;
int pageNumNew = pageNum - 1;
Discussion discussion = new Discussion();
@@ -71,14 +69,12 @@ public class UserSystemController extends BaseController {
List<Discussion> allDiscussions = allDiscussionsPage.getContent();
List<DiscussionCustom> newAllD = new ArrayList<>();
setTagAndUserList(newAllD, allDiscussions);
logger.info("全部主题==>{}", allDiscussions);
Long total = allDiscussionsPage.getTotalElements();
//获取主题帖子的分页数据
//获取主题帖子的分页数据(以后尝试去缓存中取)
List<String> pageNumList = getPageNumList(allDiscussionsPage.getTotalPages());
//获取所有标签(以后尝试去缓存中取)
@@ -169,7 +165,7 @@ public class UserSystemController extends BaseController {
newdd.setRealnameLast(lastUser != null && lastUser.getRealname() != null ? lastUser.getRealname() : "");
newdd.setUsernameLast(lastUser != null && lastUser.getUsername() != null ? lastUser.getUsername() : "");
}
//组装tag
// 组装tag
newdd.setTagList(tagMap.get(dd.getId()));
newAllD.add(newdd);
}
@@ -216,7 +212,6 @@ public class UserSystemController extends BaseController {
/**
* 注册提交
*
* @param username
* @param email
* @param password
@@ -232,7 +227,6 @@ public class UserSystemController extends BaseController {
return "register";
} else {
User user = new User();
user.setEmail(email);
user.setPassword(password);
user.setUsername(username);
@@ -254,7 +248,6 @@ public class UserSystemController extends BaseController {
return "register";
}
//获取设置信息
//获取首页统计
@@ -36,7 +36,6 @@ public class RestPostController {
} else {
throw new BaseException(ResponseCode.RESOURCES_NOT_EXIST);
}
}
@GetMapping("/discussion/{id}")
@@ -6,6 +6,7 @@ import com.yaoyuan.jiscuss.response.ResponseCode;
import com.yaoyuan.jiscuss.service.IUsersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -16,13 +16,21 @@ public class BaseException extends RuntimeException {
private static final long serialVersionUID = 1L;
private ResponseCode code;
/**
* BaseException
* ResponseCode code
**/
public BaseException(ResponseCode code) {
this.code = code;
}
/**
* BaseException
* ResponseCode code
* Throwable cause
**/
public BaseException(Throwable cause, ResponseCode code) {
super(cause);
this.code = code;
@@ -15,7 +15,6 @@ public interface TagsRepository extends JpaRepository<Tag, Integer> {
@Query(value = "FROM Tag a, DiscussionTag b WHERE a.id = b.tagId and b.discussionId = :dId")
List<Tag> findByDId(@Param("dId") Integer dId);
@Query("select new com.yaoyuan.jiscuss.entity.custom.TagCustom(" +
"u.name,u.color,u.icon,u.description, d.discussionId" +
") " +
@@ -8,7 +8,6 @@ import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface UsersRepository extends JpaRepository<User, Integer> {
/**
@@ -38,5 +37,4 @@ public interface UsersRepository extends JpaRepository<User, Integer> {
*/
@Query("from User where username = :username and password = :password")
User checkByUsernameAndPassword(String username, String password);
}
@@ -15,9 +15,8 @@ import java.io.Serializable;
@AllArgsConstructor
public class ResponseResult implements Serializable {
/**
*
* serialVersionUID
*/
private static final long serialVersionUID = 1L;
@@ -2,7 +2,6 @@ package com.yaoyuan.jiscuss.service;
import com.yaoyuan.jiscuss.entity.User;
import org.springframework.data.domain.Page;
import java.util.List;
public interface IUsersService {
@@ -11,9 +10,10 @@ public interface IUsersService {
Page<User> queryAllUsersList(int pageNum, int pageSize);
//Cacheable
List<User> getByUsernameIsLike(String name);
// @Cacheable("myCache")
//@Cacheable("myCache")
User findOne(Integer id);
User insert(User user);
@@ -27,5 +27,4 @@ public interface IUsersService {
User checkByUsernameAndPassword(String username, String password);
User update(User user, Integer id);
}
@@ -12,6 +12,7 @@ import java.util.List;
@Service
@Transactional
public class DiscussionsTagsServiceImpl implements IDiscussionsTagsService {
@Autowired
private DiscussionsTagsRepository discussionsTagsRepository;
@@ -24,6 +25,4 @@ public class DiscussionsTagsServiceImpl implements IDiscussionsTagsService {
public DiscussionTag insert(DiscussionTag discussionTag) {
return discussionsTagsRepository.save(discussionTag);
}
}
@@ -17,10 +17,10 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
@Service
@Transactional
public class PostsServiceImpl implements IPostsService {
@Autowired
private PostsRepository postsRepository;
@@ -31,7 +31,6 @@ public class PostsServiceImpl implements IPostsService {
@Override
public List<Post> findOneBy(Integer id) {
List<Post> posts = postsRepository.findOneBy(id);
return posts;
}
@@ -49,19 +48,14 @@ public class PostsServiceImpl implements IPostsService {
public List findPostCustomById(Integer id) {
//查询id为1且parentId为null的评论
List<Map<String, Object>> firstposts = postsRepository.findAllByDIdAndparentIdNull(id);
List<PostCustom> firstpostCustomList = PostCommonUtil.getNewPostsObjMap(firstposts);
// List<PostCustom> firstpostCustomListNew = PostCommonUtil.getNewPostsObjCustom(firstpostCustomList);
//查询id为1且parentId不为null的评论
List<Map<String, Object>> thenposts = postsRepository.findAllByDIdAndparentIdNotNull(id);
List<PostCustom> thenpostCustomList = PostCommonUtil.getNewPostsObjMap(thenposts);
// List<PostCustom> thenpostCustomListNew = PostCommonUtil.getNewPostsObjCustom(thenpostCustomList);
//新建一个Node集合。
ArrayList<Node> nodes = new ArrayList<>();
//将第一层评论都添加都Node集合中
@@ -76,17 +70,12 @@ public class PostsServiceImpl implements IPostsService {
//打印回复链表
Node.show(list);
// List<Map<String, Object>> posts = postsRepository.findPostCustomById(id);
//
// List<PostCustom> postCustomList = PostCommonUtil.getNewPostsObjMap(posts);
//
// List<PostCustom> postCustomListNew = PostCommonUtil.getNewPostsObjCustom(postCustomList);
return list;
}
@Override
public Post insert(Post post) {
return postsRepository.save(post);
@@ -1,6 +1,5 @@
package com.yaoyuan.jiscuss.service.impl;
import com.yaoyuan.jiscuss.entity.User;
import com.yaoyuan.jiscuss.repository.UsersRepository;
import com.yaoyuan.jiscuss.service.IUsersService;
@@ -20,6 +19,7 @@ import java.util.List;
@Service
@Transactional
public class UsersServiceImpl implements IUsersService {
@Autowired
private UsersRepository usersRepository;
@@ -110,6 +110,7 @@ public class UsersServiceImpl implements IUsersService {
/**
* 删除所有
*
*/
@Override
public void deleteAll() {
@@ -2,15 +2,11 @@ package com.yaoyuan.jiscuss.util;
/**
* @author yaoyuan2.chu
* @Title:
* @Title: 去除内容页代码里的HTML标签
* @Package com.yaoyuan.jiscuss.util
* @Description:
* @date 2020/8/31 20:52
*/
/**
* 去除内容页代码里的HTML标签
*/
public class DelTagsUtil {
/**
* 去除html代码中含有的标签
@@ -54,8 +50,7 @@ public class DelTagsUtil {
}
public static void main(String[] args) {
String htmlStr = "<script type>var i=1; alert(i)</script><style> .font1{font-size:12px}</style><span>少年中国说。</span>红日初升,其道大光。<h3>河出伏流,一泻汪洋。</h3>潜龙腾渊, 鳞爪飞扬。乳 虎啸 谷,百兽震惶。鹰隼试翼,风尘吸张。奇花初胎,矞矞皇皇。干将发硎,有作其芒。天戴其苍,地履其黄。纵有千古,横有" +
"八荒。<a href=\"www.baidu.com\">前途似海,来日方长</a>。<h1>美哉我少年中国,与天不老!</h1><p>壮哉我中国少年,与国无疆!</p>";
String htmlStr = "test";
System.out.println(getTextFromHtml(htmlStr));
}
+2 -5
View File
@@ -5,7 +5,6 @@
<!-- <link rel="stylesheet" type="text/css" href="static/semanticui/semantic.css"> -->
<!-- <script src="static/jquery/jquery-3.4.1.min.js"></script> -->
<!-- <script src="static/semanticui/semantic.min.js"></script> -->
<!-- default header name is X-CSRF-TOKEN -->
<meta name="_csrf" content="${_csrf.token}"/>
<meta name="_csrf_header" content="${_csrf.headerName}"/>
@@ -30,7 +29,6 @@
<div class="ui four column grid">
<div class="ui widescreen large screen computer tablet only twelve wide column">
<div id="context2" style="padding-left: 14px; padding-right: 14px;background: #FFFFFF; padding: 1em 1em; border-radius: 0.28571429rem; border: 1px solid rgba(34, 36, 38, 0.15);">
<h2 class="ui header">
<i class="edit outline icon"></i>
<div class="content">
@@ -198,14 +196,14 @@
<div class="ui card">
<div class="content">
<div class="header">作者热门主题</div>
<div class="header">作者热门主题</div>
</div>
<div class="content">
<div class="ui middle aligned divided list">
<div class="item">
<img class="ui avatar image" src="/static/assets/images/logo.png">
<div class="content">
<a class="header">他的测试主题1</a>
<a class="header">its here</a>
</div>
</div>
<div class="item">
@@ -301,7 +299,6 @@
console.log('已经登陆:' + username);
</#if>
setDiscussionsId('${discussions.id}');
});
</script>
+3 -3
View File
@@ -3,7 +3,6 @@
<title>Jiscuss Demo</title>
<head>
<#include "comm/commjs.ftl"/>
<style type="text/css">
body {
background-color: #f7f8fa;
@@ -44,7 +43,7 @@
<div class="field">
<div class="ui left icon input">
<i class="lock icon"></i>
<input type="password" name="password" placeholder="密码">
<input type="password" name="password" placeholder="密 码">
</div>
</div>
<div class="field" id="msgId" style="display:none">
@@ -52,7 +51,8 @@
${msg}
</div>
</div>
<button class="ui fluid large blue button" type="submit">登录</button>
<button class="ui fluid large blue button" type="submit">登 录</button>
</div>
<div class="ui error message"></div>
+1 -6
View File
@@ -5,13 +5,10 @@
<!-- <link rel="stylesheet" type="text/css" href="static/semanticui/semantic.css"> -->
<!-- <script src="static/jquery/jquery-3.4.1.min.js"></script> -->
<!-- <script src="static/semanticui/semantic.min.js"></script> -->
<!-- default header name is X-CSRF-TOKEN -->
<meta name="_csrf" content="${_csrf.token}"/>
<meta name="_csrf_header" content="${_csrf.headerName}"/>
<#include "comm/commjs.ftl"/>
</head>
<body>
<div class="ui container" id="container">
@@ -35,7 +32,6 @@
&nbsp;<button class="ui teal button" onclick="onNewtags()">新增标签</button>
</div>
<div class="field">
<label>内容</label>
<textarea id="discussionsContent"></textarea>
@@ -70,6 +66,7 @@
});
}
//点击事件
$("#newDiscussions").click(function () {
var token = $("meta[name='_csrf']").attr("content");
@@ -114,8 +111,6 @@
});
});
</script>
</body>