代码提交--标签相关
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
package com.yaoyuan.jiscuss.common;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.custom.PostCustom;
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -7,6 +8,7 @@ import javax.persistence.Column;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yaoyuan2.chu
|
||||
* @Title:
|
||||
@@ -77,7 +79,7 @@ public class Node {
|
||||
*/
|
||||
public static boolean addNode(List<Node> list, Node node) {
|
||||
for (Node node1 : list) { //循环添加
|
||||
if (node1.getId() .equals(node.getParentId()) ) { //判断留言的上一段是都是这条留言
|
||||
if (node1.getId().equals(node.getParentId())) { //判断留言的上一段是都是这条留言
|
||||
node1.getNextNodes().add(node); //是,添加,返回true;
|
||||
System.out.println("添加了一个");
|
||||
return true;
|
||||
|
||||
@@ -30,22 +30,34 @@ public class PostCommonUtil {
|
||||
}
|
||||
String content = "";
|
||||
if (mapObj.get("content") != null) {
|
||||
Clob clob = (Clob) mapObj.get("content");
|
||||
content = PostCommonUtil.clobToString(clob);
|
||||
if (mapObj.get("content") instanceof Clob) {
|
||||
Clob clob = (Clob) mapObj.get("content");
|
||||
content = PostCommonUtil.clobToString(clob);
|
||||
} else if (mapObj.get("content") instanceof String) {
|
||||
content = String.valueOf(mapObj.get("content"));
|
||||
}
|
||||
}
|
||||
postCustom.setContent(content);
|
||||
String avatar = "";
|
||||
if (mapObj.get("create_avatar") != null) {
|
||||
Clob clob = (Clob) mapObj.get("create_avatar");
|
||||
avatar = PostCommonUtil.clobToString(clob);
|
||||
if (mapObj.get("create_avatar") instanceof Clob) {
|
||||
Clob clob = (Clob) mapObj.get("create_avatar");
|
||||
avatar = PostCommonUtil.clobToString(clob);
|
||||
} else if (mapObj.get("create_avatar") instanceof String) {
|
||||
avatar = String.valueOf(mapObj.get("create_avatar"));
|
||||
}
|
||||
}
|
||||
postCustom.setAvatar(avatar);
|
||||
postCustom.setUsername(mapObj.get("create_username") != null ? String.valueOf(mapObj.get("create_username")) : null);
|
||||
postCustom.setRealname(mapObj.get("create_realname") != null ? String.valueOf(mapObj.get("create_realname")) : null);
|
||||
String avatarReply = "";
|
||||
if (mapObj.get("user_avatar") != null) {
|
||||
Clob clob = (Clob) mapObj.get("user_avatar");
|
||||
avatarReply = PostCommonUtil.clobToString(clob);
|
||||
if (mapObj.get("user_avatar") instanceof Clob) {
|
||||
Clob clob = (Clob) mapObj.get("user_avatar");
|
||||
avatarReply = PostCommonUtil.clobToString(clob);
|
||||
} else if (mapObj.get("user_avatar") instanceof String) {
|
||||
avatarReply = String.valueOf(mapObj.get("user_avatar"));
|
||||
}
|
||||
}
|
||||
postCustom.setAvatarReply(avatarReply);
|
||||
postCustom.setUsernameReply(mapObj.get("user_username") != null ? String.valueOf(mapObj.get("user_username")) : null);
|
||||
@@ -59,29 +71,29 @@ public class PostCommonUtil {
|
||||
public static List<PostCustom> getNewPostsObjCustom(List<PostCustom> postCustomList) {
|
||||
List<PostCustom> mainList = new ArrayList<>();
|
||||
Map<String, Object> postMap = new LinkedHashMap<>();
|
||||
for(PostCustom mapObj : postCustomList){
|
||||
if(null == mapObj.getParentId() ){
|
||||
for (PostCustom mapObj : postCustomList) {
|
||||
if (null == mapObj.getParentId()) {
|
||||
mainList.add(mapObj);
|
||||
}else{
|
||||
} else {
|
||||
List<PostCustom> tempList = new ArrayList<>();
|
||||
if(postMap.containsKey(String.valueOf(mapObj.getParentId()))){
|
||||
if (postMap.containsKey(String.valueOf(mapObj.getParentId()))) {
|
||||
tempList = (List<PostCustom>) postMap.get(String.valueOf(mapObj.getParentId()));
|
||||
tempList.add(mapObj);
|
||||
postMap.put(String.valueOf(mapObj.getParentId()),tempList);
|
||||
}else{
|
||||
postMap.put(String.valueOf(mapObj.getParentId()), tempList);
|
||||
} else {
|
||||
tempList.add(mapObj);
|
||||
postMap.put(String.valueOf(mapObj.getParentId()),tempList);
|
||||
postMap.put(String.valueOf(mapObj.getParentId()), tempList);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<PostCustom> mainListResult = new ArrayList<>();
|
||||
for(PostCustom mapObj : mainList){
|
||||
if(postMap.containsKey(String.valueOf(mapObj.getId()))){
|
||||
for (PostCustom mapObj : mainList) {
|
||||
if (postMap.containsKey(String.valueOf(mapObj.getId()))) {
|
||||
PostCustom newObj = new PostCustom();
|
||||
BeanUtils.copyProperties(mapObj , newObj);
|
||||
BeanUtils.copyProperties(mapObj, newObj);
|
||||
newObj.setChild((List<PostCustom>) postMap.get(String.valueOf(mapObj.getId())));
|
||||
mainListResult.add(newObj);
|
||||
}else{
|
||||
} else {
|
||||
mainListResult.add(mapObj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package com.yaoyuan.jiscuss.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@@ -15,18 +15,18 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
@EnableSwagger2
|
||||
public class SwaggerConfiguration {
|
||||
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.yaoyuan.jiscuss.controller")).paths(PathSelectors.any())
|
||||
.build();
|
||||
}
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.yaoyuan.jiscuss.controller")).paths(PathSelectors.any())
|
||||
.build();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder().title("swagger-ui RESTful APIs").description("Jiscuss")
|
||||
.termsOfServiceUrl("http://localhost/").contact("developer@mail.com").version("1.0").build();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder().title("swagger-ui RESTful APIs").description("Jiscuss")
|
||||
.termsOfServiceUrl("http://localhost/").contact("developer@mail.com").version("1.0").build();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -15,85 +15,89 @@ import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
|
||||
/**
|
||||
prePostEnabled :决定Spring Security的前注解是否可用 [@PreAuthorize,@PostAuthorize,..]
|
||||
secureEnabled : 决定是否Spring Security的保障注解 [@Secured] 是否可用
|
||||
jsr250Enabled :决定 JSR-250 annotations 注解[@RolesAllowed..] 是否可用.
|
||||
* prePostEnabled :决定Spring Security的前注解是否可用 [@PreAuthorize,@PostAuthorize,..]
|
||||
* secureEnabled : 决定是否Spring Security的保障注解 [@Secured] 是否可用
|
||||
* jsr250Enabled :决定 JSR-250 annotations 注解[@RolesAllowed..] 是否可用.
|
||||
*/
|
||||
@Configurable
|
||||
@EnableWebSecurity
|
||||
//开启 Spring Security 方法级安全注解 @EnableGlobalMethodSecurity
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true,securedEnabled = true,jsr250Enabled = true)
|
||||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true)
|
||||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Autowired
|
||||
private CustomAccessDeniedHandler customAccessDeniedHandler;
|
||||
@Qualifier("userDetailServiceImpl")
|
||||
@Autowired
|
||||
private UserDetailsService userDetailsService;
|
||||
|
||||
/**
|
||||
* 静态资源设置
|
||||
*/
|
||||
@Override
|
||||
public void configure(WebSecurity webSecurity) {
|
||||
//不拦截静态资源,所有用户均可访问的资源
|
||||
webSecurity.ignoring().antMatchers(
|
||||
"/",
|
||||
"/css/**",
|
||||
"/js/**",
|
||||
"/images/**",
|
||||
"/static/**",
|
||||
"/h2-console/**",
|
||||
"/druid/**"
|
||||
);
|
||||
}
|
||||
/**
|
||||
* http请求设置
|
||||
*/
|
||||
@Override
|
||||
public void configure(HttpSecurity http) throws Exception {
|
||||
//http.csrf().disable(); //注释就是使用 csrf 功能
|
||||
http.headers().frameOptions().disable();//解决 in a frame because it set 'X-Frame-Options' to 'DENY' 问题
|
||||
//http.anonymous().disable();
|
||||
http.authorizeRequests()
|
||||
.antMatchers("/login/**","/initUserData")//不拦截登录相关方法
|
||||
.permitAll()
|
||||
//.antMatchers("/user").hasRole("ADMIN") // user接口只有ADMIN角色的可以访问
|
||||
@Autowired
|
||||
private CustomAccessDeniedHandler customAccessDeniedHandler;
|
||||
@Qualifier("userDetailServiceImpl")
|
||||
@Autowired
|
||||
private UserDetailsService userDetailsService;
|
||||
|
||||
/**
|
||||
* 静态资源设置
|
||||
*/
|
||||
@Override
|
||||
public void configure(WebSecurity webSecurity) {
|
||||
//不拦截静态资源,所有用户均可访问的资源
|
||||
webSecurity.ignoring().antMatchers(
|
||||
"/",
|
||||
"/css/**",
|
||||
"/js/**",
|
||||
"/images/**",
|
||||
"/static/**",
|
||||
"/h2-console/**",
|
||||
"/test/**",
|
||||
"/druid/**"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* http请求设置
|
||||
*/
|
||||
@Override
|
||||
public void configure(HttpSecurity http) throws Exception {
|
||||
//http.csrf().disable(); //注释就是使用 csrf 功能
|
||||
http.headers().frameOptions().disable();//解决 in a frame because it set 'X-Frame-Options' to 'DENY' 问题
|
||||
//http.anonymous().disable();
|
||||
http.authorizeRequests()
|
||||
.antMatchers("/login/**", "/initUserData")//不拦截登录相关方法
|
||||
.permitAll()
|
||||
//.antMatchers("/user").hasRole("ADMIN") // user接口只有ADMIN角色的可以访问
|
||||
// .anyRequest()
|
||||
// .authenticated()// 任何尚未匹配的URL只需要验证用户即可访问
|
||||
.anyRequest()
|
||||
.access("@rbacPermission.hasPermission(request, authentication)")//根据账号权限访问
|
||||
.and()
|
||||
.formLogin()
|
||||
.anyRequest()
|
||||
.access("@rbacPermission.hasPermission(request, authentication)")//根据账号权限访问
|
||||
.and()
|
||||
.formLogin()
|
||||
// .loginPage("/")
|
||||
.loginPage("/login") //登录请求页
|
||||
.loginProcessingUrl("/login") //登录POST请求路径
|
||||
.usernameParameter("username") //登录用户名参数
|
||||
.passwordParameter("password") //登录密码参数
|
||||
.defaultSuccessUrl("/index") //默认登录成功页面
|
||||
.and()
|
||||
.exceptionHandling()
|
||||
.accessDeniedHandler(customAccessDeniedHandler) //无权限处理器
|
||||
.and()
|
||||
.logout()
|
||||
.logoutSuccessUrl("/login?logout"); //退出登录成功URL
|
||||
|
||||
}
|
||||
/**
|
||||
* 自定义获取用户信息接口
|
||||
*/
|
||||
@Override
|
||||
public void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
|
||||
}
|
||||
|
||||
/**
|
||||
.loginPage("/login") //登录请求页
|
||||
.loginProcessingUrl("/login") //登录POST请求路径
|
||||
.usernameParameter("username") //登录用户名参数
|
||||
.passwordParameter("password") //登录密码参数
|
||||
.defaultSuccessUrl("/index") //默认登录成功页面
|
||||
.and()
|
||||
.exceptionHandling()
|
||||
.accessDeniedHandler(customAccessDeniedHandler) //无权限处理器
|
||||
.and()
|
||||
.logout()
|
||||
.logoutSuccessUrl("/login?logout"); //退出登录成功URL
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义获取用户信息接口
|
||||
*/
|
||||
@Override
|
||||
public void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码加密算法
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public BCryptPasswordEncoder passwordEncoder() {
|
||||
return new BCryptPasswordEncoder();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,10 @@ public class BaseController {
|
||||
|
||||
/**
|
||||
* 获取当前用户
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected UserInfo getUserInfo(HttpServletRequest request){
|
||||
protected UserInfo getUserInfo(HttpServletRequest request) {
|
||||
UserInfo user = null;
|
||||
//获得session对象
|
||||
HttpSession session = request.getSession();
|
||||
@@ -35,7 +36,7 @@ public class BaseController {
|
||||
Object spring_security_context = session.getAttribute("SPRING_SECURITY_CONTEXT");
|
||||
System.out.println(spring_security_context);
|
||||
SecurityContext securityContext = (SecurityContext) spring_security_context;
|
||||
if(securityContext!=null){
|
||||
if (securityContext != null) {
|
||||
//获得认证信息
|
||||
Authentication authentication = securityContext.getAuthentication();
|
||||
//获得用户详情
|
||||
|
||||
@@ -10,22 +10,22 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
public class TestController {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 登录页面跳转
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("loginpage")
|
||||
public String loginpage() {
|
||||
return "login";
|
||||
return "login";
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/world")
|
||||
public String world(Map<String, Object> model) {
|
||||
model.put("data","2019");
|
||||
model.put("data", "2019");
|
||||
// request.setAttribute("name", "xxxxxxxxx");
|
||||
model.put("msg", "xxxxxxx2222xx");
|
||||
model.put("msg", "xxxxxxx2222xx");
|
||||
return "world";
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.springframework.stereotype.Controller;
|
||||
* 用户消息控制器
|
||||
*/
|
||||
@Controller
|
||||
public class UserMsgController extends BaseController {
|
||||
public class UserMsgController extends BaseController {
|
||||
//首页最新消息
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.springframework.stereotype.Controller;
|
||||
* 其他控制器——积分/权限等
|
||||
*/
|
||||
@Controller
|
||||
public class UserOtherController extends BaseController {
|
||||
public class UserOtherController extends BaseController {
|
||||
|
||||
//用户积分获取
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import com.yaoyuan.jiscuss.entity.*;
|
||||
import com.yaoyuan.jiscuss.entity.custom.DiscussionCustom;
|
||||
import com.yaoyuan.jiscuss.entity.custom.PostCustom;
|
||||
import com.yaoyuan.jiscuss.service.IPostsService;
|
||||
import com.yaoyuan.jiscuss.service.IUsersService;
|
||||
import com.yaoyuan.jiscuss.service.*;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -24,24 +23,24 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import com.yaoyuan.jiscuss.service.IDiscussionsService;
|
||||
import com.yaoyuan.jiscuss.service.ITagsService;
|
||||
|
||||
/**
|
||||
* 主题帖子评论控制器
|
||||
*/
|
||||
@Controller
|
||||
public class UserPostController extends BaseController {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(UserPostController.class);
|
||||
public class UserPostController extends BaseController {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(UserPostController.class);
|
||||
|
||||
|
||||
@Autowired
|
||||
private IDiscussionsService discussionsService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private ITagsService tagsService;
|
||||
|
||||
@Autowired
|
||||
private IDiscussionsTagsService iDiscussionsTagsService;
|
||||
|
||||
@Autowired
|
||||
private IPostsService postsService;
|
||||
|
||||
@@ -50,27 +49,26 @@ public class UserPostController extends BaseController {
|
||||
|
||||
|
||||
//首页查看主题列表(各种条件筛选,最热最新标签等)
|
||||
|
||||
|
||||
|
||||
//查看主题详情
|
||||
|
||||
//查看主题详情
|
||||
@RequestMapping("/getdiscussionsbyid")
|
||||
public String getDiscussionsById(HttpServletRequest request, ModelMap map, @RequestParam("id") Integer id) {
|
||||
logger.info(">>> getDiscussionsById{}",id);
|
||||
logger.info(">>> getDiscussionsById{}", id);
|
||||
|
||||
Discussion discussion = discussionsService.findOne(id);
|
||||
// 获取此主题下的评论
|
||||
List<Post> posts = postsService.findOneBy(id);
|
||||
|
||||
DiscussionCustom newdd = new DiscussionCustom();
|
||||
BeanUtils.copyProperties(discussion , newdd);
|
||||
if (null != newdd.getStartUserId()){
|
||||
BeanUtils.copyProperties(discussion, newdd);
|
||||
if (null != newdd.getStartUserId()) {
|
||||
User startUser = usersService.findOne(newdd.getStartUserId());
|
||||
newdd.setAvatar(startUser.getAvatar());
|
||||
newdd.setRealname(startUser.getRealname());
|
||||
newdd.setUsername(startUser.getUsername());
|
||||
}
|
||||
if (null != newdd.getLastUserId()){
|
||||
if (null != newdd.getLastUserId()) {
|
||||
User lastUser = usersService.findOne(newdd.getLastUserId());
|
||||
newdd.setAvatarLast(lastUser.getAvatar());
|
||||
newdd.setRealnameLast(lastUser.getRealname());
|
||||
@@ -87,37 +85,53 @@ public class UserPostController extends BaseController {
|
||||
map.put("discussions", newdd);
|
||||
map.put("posts", postsObj);
|
||||
UserInfo user = getUserInfo(request);
|
||||
if(user != null){
|
||||
if (user != null) {
|
||||
map.put("username", user.getUsername());
|
||||
}
|
||||
return "discussions";
|
||||
}
|
||||
|
||||
|
||||
|
||||
//新建主题
|
||||
@PostMapping(value = "/newdiscussions")
|
||||
@ResponseBody
|
||||
public String newDiscussions(@RequestBody Discussion discussion) {
|
||||
logger.info(">>> newPost"+ discussion);
|
||||
public String newDiscussions(@RequestBody DiscussionCustom discussion) {
|
||||
logger.info(">>> newPost" + discussion);
|
||||
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = servletRequestAttributes.getRequest();
|
||||
UserInfo user = getUserInfo(request);
|
||||
if(user != null){
|
||||
discussion.setLastUserId( user.getId());
|
||||
discussion.setCreateId( user.getId());
|
||||
if (user != null) {
|
||||
discussion.setStartUserId(user.getId());
|
||||
discussion.setLastUserId(user.getId());
|
||||
discussion.setCreateId(user.getId());
|
||||
}
|
||||
|
||||
|
||||
discussion.setCreateTime(new Date());
|
||||
|
||||
discussion.setStartTime(new Date());
|
||||
discussion.setLastTime(new Date());
|
||||
|
||||
Discussion saveDiscussion = discussionsService.insert(discussion);
|
||||
|
||||
if (null != discussion.getTag()) {
|
||||
//执行组装标签
|
||||
String[] strArray = discussion.getTag().split(",");
|
||||
for(String str : strArray){
|
||||
DiscussionTag dtag= new DiscussionTag();
|
||||
dtag.setDiscussionId(saveDiscussion.getId());
|
||||
dtag.setTagId(Integer.parseInt(str));
|
||||
iDiscussionsTagsService.insert(dtag);
|
||||
}
|
||||
}
|
||||
|
||||
JSONObject resultobj = new JSONObject();
|
||||
|
||||
|
||||
logger.info(">>>{}", saveDiscussion);
|
||||
resultobj.put("msg", "添加成功");
|
||||
resultobj.put("flag", true);
|
||||
return resultobj.toString(); //
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -129,18 +143,18 @@ public class UserPostController extends BaseController {
|
||||
@PostMapping(value = "/newpost")
|
||||
@ResponseBody
|
||||
public String newPosts(@RequestBody Post post) {
|
||||
logger.info(">>> newpost"+ post);
|
||||
logger.info(">>> newpost" + post);
|
||||
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = servletRequestAttributes.getRequest();
|
||||
|
||||
UserInfo user = getUserInfo(request);
|
||||
if(user != null){
|
||||
post.setCreateId( user.getId());
|
||||
if (user != null) {
|
||||
post.setCreateId(user.getId());
|
||||
}
|
||||
post.setCreateTime(new Date());
|
||||
if(null != post.getParentId()){
|
||||
Post temp =postsService.findOneByid(post.getParentId());
|
||||
if (null != post.getParentId()) {
|
||||
Post temp = postsService.findOneByid(post.getParentId());
|
||||
post.setUserId(temp.getCreateId());
|
||||
|
||||
}
|
||||
@@ -148,37 +162,37 @@ public class UserPostController extends BaseController {
|
||||
Post savePost = postsService.insert(post);
|
||||
JSONObject resultobj = new JSONObject();
|
||||
|
||||
logger.info(">>>{}",savePost );
|
||||
logger.info(">>>{}", savePost);
|
||||
resultobj.put("msg", "添加成功");
|
||||
resultobj.put("flag", true);
|
||||
return resultobj.toString(); //
|
||||
}
|
||||
|
||||
//删除评论
|
||||
|
||||
|
||||
//新建标签
|
||||
@PostMapping(value = "/newtags")
|
||||
@ResponseBody
|
||||
public String newTags(@RequestBody Tag tag) {
|
||||
logger.info(">>> newTags"+ tag);
|
||||
logger.info(">>> newTags" + tag);
|
||||
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = servletRequestAttributes.getRequest();
|
||||
|
||||
UserInfo user = getUserInfo(request);
|
||||
if(user != null){
|
||||
tag.setCreateId( user.getId());
|
||||
if (user != null) {
|
||||
tag.setCreateId(user.getId());
|
||||
}
|
||||
tag.setCreateTime(new Date());
|
||||
|
||||
Tag saveTag = tagsService.insert(tag);
|
||||
JSONObject resultobj = new JSONObject();
|
||||
|
||||
|
||||
logger.info(">>>{}", saveTag);
|
||||
resultobj.put("msg", "添加成功");
|
||||
resultobj.put("flag", true);
|
||||
return resultobj.toString(); //
|
||||
|
||||
|
||||
}
|
||||
|
||||
//排行榜等
|
||||
|
||||
@@ -37,50 +37,50 @@ public class UserSystemController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private IDiscussionsService discussionsService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private ITagsService tagsService;
|
||||
|
||||
//首页
|
||||
@RequestMapping({"/","/main","/index"})
|
||||
public String home(@RequestParam(defaultValue = "all") String tag, @RequestParam(defaultValue = "all") String type,@RequestParam(defaultValue = "1") Integer
|
||||
@RequestMapping({"/", "/main", "/index"})
|
||||
public String home(@RequestParam(defaultValue = "all") String tag, @RequestParam(defaultValue = "all") String type, @RequestParam(defaultValue = "1") Integer
|
||||
pageNum, HttpServletRequest request, ModelMap map) {
|
||||
logger.info(">>> index");
|
||||
logger.info(">>> tag:" + tag);
|
||||
logger.info(">>> pageNum:" + pageNum);
|
||||
List<User> userall = usersService.getAllList();
|
||||
logger.info(">>> 第一遍的全部用户:"+userall);
|
||||
|
||||
logger.info(">>> 第一遍的全部用户:" + userall);
|
||||
|
||||
List<User> useral2 = usersService.getAllList();
|
||||
logger.info(">>> 第二遍的全部用户:"+useral2);
|
||||
logger.info(">>> 第二遍的全部用户:" + useral2);
|
||||
|
||||
int pageSiz = 10;
|
||||
int pageNumNew = pageNum - 1;
|
||||
Discussion discussion = new Discussion();
|
||||
//分页获取主题帖子
|
||||
Page<Discussion> allDiscussionsPage = discussionsService.queryAllDiscussionsList(discussion,pageNumNew,pageSiz);
|
||||
|
||||
Page<Discussion> allDiscussionsPage = discussionsService.queryAllDiscussionsList(discussion, pageNumNew, pageSiz);
|
||||
|
||||
List<Discussion> allDiscussions = allDiscussionsPage.getContent();
|
||||
List<DiscussionCustom> newAllD = new ArrayList<>();
|
||||
|
||||
for (Discussion dd : allDiscussions){
|
||||
for (Discussion dd : allDiscussions) {
|
||||
DiscussionCustom newdd = new DiscussionCustom();
|
||||
BeanUtils.copyProperties(dd , newdd);
|
||||
BeanUtils.copyProperties(dd, newdd);
|
||||
String newCon = "";
|
||||
String content = DelTagsUtil.getTextFromHtml(newdd.getContent());
|
||||
if(null != content && content.length()>30){
|
||||
newCon = content.substring(0,29);
|
||||
}else{
|
||||
if (null != content && content.length() > 30) {
|
||||
newCon = content.substring(0, 29);
|
||||
} else {
|
||||
newCon = content;
|
||||
}
|
||||
newdd.setContent(newCon);
|
||||
if (null != newdd.getStartUserId()){
|
||||
if (null != newdd.getStartUserId()) {
|
||||
User startUser = usersService.findOne(newdd.getStartUserId());
|
||||
newdd.setAvatar(startUser.getAvatar());
|
||||
newdd.setRealname(startUser.getRealname());
|
||||
newdd.setUsername(startUser.getUsername());
|
||||
}
|
||||
if (null != newdd.getLastUserId()){
|
||||
if (null != newdd.getLastUserId()) {
|
||||
User lastUser = usersService.findOne(newdd.getLastUserId());
|
||||
newdd.setAvatarLast(lastUser.getAvatar());
|
||||
newdd.setRealnameLast(lastUser.getRealname());
|
||||
@@ -89,18 +89,18 @@ public class UserSystemController extends BaseController {
|
||||
|
||||
newAllD.add(newdd);
|
||||
}
|
||||
|
||||
logger.info("全部主题==>:{}",allDiscussions);
|
||||
|
||||
logger.info("全部主题==>:{}", allDiscussions);
|
||||
|
||||
Long total = allDiscussionsPage.getTotalElements();
|
||||
|
||||
|
||||
//获取主题帖子的分页数据
|
||||
List<String> pageNumList = getPageNumList(allDiscussionsPage.getTotalPages());
|
||||
List<String> pageNumList = getPageNumList(allDiscussionsPage.getTotalPages());
|
||||
|
||||
//获取所有标签(以后尝试去缓存中取)
|
||||
List<Tag> allTags = tagsService.getAllList();
|
||||
logger.info("全部标签==>:{}",allTags);
|
||||
|
||||
logger.info("全部标签==>:{}", allTags);
|
||||
|
||||
System.out.println(userall.toString());
|
||||
map.put("data", "Jiscuss 用户");
|
||||
map.put("allDiscussions", newAllD);
|
||||
@@ -109,32 +109,38 @@ public class UserSystemController extends BaseController {
|
||||
map.put("tag", tag);
|
||||
map.put("type", type);
|
||||
|
||||
map.put("pageSize",pageSiz);
|
||||
map.put("pageSize", pageSiz);
|
||||
map.put("pageTotal", total);
|
||||
map.put("pageNum", pageNum);
|
||||
map.put("pageTotalPages", allDiscussionsPage.getTotalPages());
|
||||
UserInfo user = getUserInfo(request);
|
||||
if(user != null){
|
||||
if (user != null) {
|
||||
map.put("username", user.getUsername());
|
||||
map.put("data", "Jiscuss 用户:" + user.getUsername());
|
||||
}
|
||||
return "index";
|
||||
}
|
||||
|
||||
|
||||
private List<String> getPageNumList(int size) {
|
||||
List<String> pageNumList = new ArrayList<String>();
|
||||
for(int i = 0;i<size;i++) {
|
||||
pageNumList.add(""+(i+1));
|
||||
|
||||
private List<String> getPageNumList(int size) {
|
||||
List<String> pageNumList = new ArrayList<String>();
|
||||
for (int i = 0; i < size; i++) {
|
||||
pageNumList.add("" + (i + 1));
|
||||
}
|
||||
return pageNumList;
|
||||
}
|
||||
return pageNumList;
|
||||
}
|
||||
|
||||
//登录页
|
||||
@GetMapping("/test")
|
||||
public String test() {
|
||||
return "test";
|
||||
}
|
||||
|
||||
|
||||
//登录页
|
||||
@GetMapping("/login")
|
||||
public String login(@RequestParam(value = "error", required = false) String error,
|
||||
@RequestParam(value = "logout", required = false) String logout,ModelMap map) {
|
||||
@RequestParam(value = "logout", required = false) String logout, ModelMap map) {
|
||||
if (error != null) {
|
||||
map.put("msg", "您输入的用户名密码错误!");
|
||||
return "login";
|
||||
|
||||
@@ -2,10 +2,7 @@ package com.yaoyuan.jiscuss.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.*;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -19,9 +16,12 @@ public class Setting implements Serializable{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@Column(name="key")
|
||||
private String key;
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
@Column(name="setting_key")
|
||||
private String settingKey;
|
||||
|
||||
@Column(name="value")
|
||||
private String value;
|
||||
@Column(name="setting_value")
|
||||
private String settingValue;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.yaoyuan.jiscuss.entity.custom;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Discussion;
|
||||
import com.yaoyuan.jiscuss.entity.Tag;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yaoyuan2.chu
|
||||
* @Title:
|
||||
@@ -26,4 +29,9 @@ public class DiscussionCustom extends Discussion {
|
||||
|
||||
private String realnameLast;
|
||||
|
||||
private String tag;
|
||||
|
||||
private List<Tag> tagList;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -36,14 +36,14 @@ public class DiscussionsServiceImpl implements IDiscussionsService {
|
||||
return discussionsRepository.getOne(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Discussion> queryAllDiscussionsList(Discussion discussion, int pageNum, int pageSize) {
|
||||
Sort sort=new Sort(Sort.Direction.DESC,"id");
|
||||
@Override
|
||||
public Page<Discussion> queryAllDiscussionsList(Discussion discussion, int pageNum, int pageSize) {
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "id");
|
||||
@SuppressWarnings("deprecation")
|
||||
Pageable pageable=new PageRequest(pageNum,pageSize,sort);
|
||||
Pageable pageable = new PageRequest(pageNum, pageSize, sort);
|
||||
//将匹配对象封装成Example对象
|
||||
Example<Discussion> example = Example.of(discussion);
|
||||
|
||||
return discussionsRepository.findAll(example,pageable);
|
||||
return discussionsRepository.findAll(example, pageable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class PostsServiceImpl implements IPostsService {
|
||||
|
||||
@Override
|
||||
public Post findOneByid(Integer id) {
|
||||
Post post =new Post();
|
||||
Post post = new Post();
|
||||
post.setId(id);
|
||||
Example<Post> example = Example.of(post);
|
||||
Optional<Post> postRes = postsRepository.findOne(example);
|
||||
@@ -66,7 +66,6 @@ public class PostsServiceImpl implements IPostsService {
|
||||
// List<PostCustom> thenpostCustomListNew = PostCommonUtil.getNewPostsObjCustom(thenpostCustomList);
|
||||
|
||||
|
||||
|
||||
//新建一个Node集合。
|
||||
ArrayList<Node> nodes = new ArrayList<>();
|
||||
//将第一层评论都添加都Node集合中
|
||||
@@ -82,8 +81,6 @@ public class PostsServiceImpl implements IPostsService {
|
||||
Node.show(list);
|
||||
|
||||
|
||||
|
||||
|
||||
// List<Map<String, Object>> posts = postsRepository.findPostCustomById(id);
|
||||
//
|
||||
// List<PostCustom> postCustomList = PostCommonUtil.getNewPostsObjMap(posts);
|
||||
|
||||
Reference in New Issue
Block a user