本地代码提交
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package com.yaoyuan.jiscuss;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableCaching
|
||||
public class JiccussApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(JiccussApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package com.yaoyuan.jiscuss.common;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.custom.PostCustom;
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yaoyuan2.chu
|
||||
* @Title:
|
||||
* @Package com.yaoyuan.jiscuss.common
|
||||
* @Description:
|
||||
* @date 2020/8/17 14:51
|
||||
*/
|
||||
@Data
|
||||
public class Node {
|
||||
|
||||
public Node() {
|
||||
|
||||
}
|
||||
|
||||
private Integer id;
|
||||
|
||||
private Integer discussionId;
|
||||
|
||||
private Integer number;
|
||||
|
||||
private Date time;
|
||||
|
||||
private Integer userId;
|
||||
|
||||
private String type;
|
||||
|
||||
private String content;
|
||||
|
||||
private Integer parentId;
|
||||
|
||||
private Date editTime;
|
||||
|
||||
private Integer editUserId;
|
||||
|
||||
private String ipAddress;
|
||||
|
||||
private String copyright;
|
||||
|
||||
private Integer isApproved;
|
||||
|
||||
private Integer createId;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
//用户表相关
|
||||
private String avatar;
|
||||
|
||||
private String username;
|
||||
|
||||
private String realname;
|
||||
|
||||
private String avatarReply;
|
||||
|
||||
private String usernameReply;
|
||||
|
||||
private String realnameReply;
|
||||
|
||||
//下一条回复
|
||||
private List<Node> nextNodes = new ArrayList<Node>();
|
||||
|
||||
|
||||
/**
|
||||
* 将单个node添加到链表中
|
||||
*
|
||||
* @param list
|
||||
* @param node
|
||||
* @return
|
||||
*/
|
||||
public static boolean addNode(List<Node> list, Node node) {
|
||||
for (Node node1 : list) { //循环添加
|
||||
if (node1.getId().equals(node.getParentId())) { //判断留言的上一段是都是这条留言
|
||||
node1.getNextNodes().add(node); //是,添加,返回true;
|
||||
System.out.println("添加了一个");
|
||||
return true;
|
||||
} else { //否则递归继续判断
|
||||
if (node1.getNextNodes().size() != 0) {
|
||||
if (Node.addNode(node1.getNextNodes(), node)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将查出来的lastId不为null的回复都添加到第一层Node集合中
|
||||
*
|
||||
* @param firstList
|
||||
* @param thenList
|
||||
* @return
|
||||
*/
|
||||
public static List addAllNode(List<Node> firstList, List<PostCustom> thenList) {
|
||||
while (thenList.size() != 0) {
|
||||
int size = thenList.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
Node node = new Node();
|
||||
BeanUtils.copyProperties(thenList.get(i), node);
|
||||
if (Node.addNode(firstList, node)) {
|
||||
thenList.remove(i);
|
||||
i--;
|
||||
size--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return firstList;
|
||||
}
|
||||
|
||||
//打印
|
||||
public static void show(List<Node> list) {
|
||||
for (Node node : list) {
|
||||
System.out.println(node.getUserId() + " 用户回复了你:" + node.getContent());
|
||||
if (node.getNextNodes().size() != 0) {
|
||||
Node.show(node.getNextNodes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
package com.yaoyuan.jiscuss.common;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.custom.PostCustom;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Reader;
|
||||
import java.sql.Clob;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author yaoyuan2.chu
|
||||
* @Title:
|
||||
* @Package com.yaoyuan.jiscuss.common
|
||||
* @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();
|
||||
postCustom.setId(Integer.parseInt(String.valueOf(mapObj.get("id"))));
|
||||
postCustom.setParentId(mapObj.get("parent_id") != null ? Integer.parseInt(String.valueOf(mapObj.get("parent_id"))) : null);
|
||||
if (null != mapObj.get("create_time")) {
|
||||
postCustom.setCreateTime((Date) mapObj.get("create_time"));
|
||||
}
|
||||
String content = "";
|
||||
if (mapObj.get("content") != null) {
|
||||
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) {
|
||||
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) {
|
||||
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);
|
||||
postCustom.setRealnameReply(mapObj.get("user_realname") != null ? String.valueOf(mapObj.get("user_realname")) : null);
|
||||
|
||||
postCustomList.add(postCustom);
|
||||
}
|
||||
return postCustomList;
|
||||
}
|
||||
|
||||
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()) {
|
||||
mainList.add(mapObj);
|
||||
} else {
|
||||
List<PostCustom> tempList = new ArrayList<>();
|
||||
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 {
|
||||
tempList.add(mapObj);
|
||||
postMap.put(String.valueOf(mapObj.getParentId()), tempList);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<PostCustom> mainListResult = new ArrayList<>();
|
||||
for (PostCustom mapObj : mainList) {
|
||||
if (postMap.containsKey(String.valueOf(mapObj.getId()))) {
|
||||
PostCustom newObj = new PostCustom();
|
||||
BeanUtils.copyProperties(mapObj, newObj);
|
||||
newObj.setChild((List<PostCustom>) postMap.get(String.valueOf(mapObj.getId())));
|
||||
mainListResult.add(newObj);
|
||||
} else {
|
||||
mainListResult.add(mapObj);
|
||||
}
|
||||
}
|
||||
|
||||
return mainListResult;
|
||||
}
|
||||
|
||||
// Clob类型转换成String类型
|
||||
public static String clobToString(final Clob clob) {
|
||||
|
||||
if (clob == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reader is = null;
|
||||
try {
|
||||
is = clob.getCharacterStream();
|
||||
} catch (Exception e) {
|
||||
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);
|
||||
try {
|
||||
str = br.readLine();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
String returnString = sb.toString();
|
||||
|
||||
return returnString;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
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;
|
||||
|
||||
@Configuration
|
||||
public class MyMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
|
||||
@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/");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.yaoyuan.jiscuss.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
@Configuration
|
||||
@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();
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.yaoyuan.jiscuss.config;
|
||||
|
||||
import com.yaoyuan.jiscuss.handler.CustomAccessDeniedHandler;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Configurable;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
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..] 是否可用.
|
||||
*/
|
||||
@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;
|
||||
|
||||
/**
|
||||
* 静态资源设置
|
||||
*/
|
||||
@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()
|
||||
// .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());
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码加密算法
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public BCryptPasswordEncoder passwordEncoder() {
|
||||
return new BCryptPasswordEncoder();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.yaoyuan.jiscuss.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
/**
|
||||
* 后台系统控制器
|
||||
*/
|
||||
@Controller
|
||||
public class AdminSystemController {
|
||||
|
||||
//后台登录
|
||||
|
||||
//后台退出
|
||||
|
||||
//后台设置管理
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.yaoyuan.jiscuss.controller;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.UserInfo;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* @author yaoyuan2.chu
|
||||
* @Title: BaseController
|
||||
* @Package com.yaoyuan.jiscuss.controller
|
||||
* @Description: BaseController
|
||||
* @date 2020/7/16 14:36
|
||||
*/
|
||||
public class BaseController {
|
||||
|
||||
/**
|
||||
* 获取当前用户
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected UserInfo getUserInfo(HttpServletRequest request) {
|
||||
UserInfo user = null;
|
||||
//获得session对象
|
||||
HttpSession session = request.getSession();
|
||||
//取出session域中所有属性名
|
||||
Enumeration attributeNames = session.getAttributeNames();
|
||||
while (attributeNames.hasMoreElements()) {
|
||||
System.out.println(attributeNames.nextElement());
|
||||
}
|
||||
//SPRING_SECURITY_CONTEXT
|
||||
Object spring_security_context = session.getAttribute("SPRING_SECURITY_CONTEXT");
|
||||
System.out.println(spring_security_context);
|
||||
SecurityContext securityContext = (SecurityContext) spring_security_context;
|
||||
if (securityContext != null) {
|
||||
//获得认证信息
|
||||
Authentication authentication = securityContext.getAuthentication();
|
||||
//获得用户详情
|
||||
Object principal = authentication.getPrincipal();
|
||||
user = (UserInfo) principal;
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.yaoyuan.jiscuss.controller;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@Controller
|
||||
public class TestController {
|
||||
|
||||
|
||||
/**
|
||||
* 登录页面跳转
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("loginpage")
|
||||
public String loginpage() {
|
||||
return "login";
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/world")
|
||||
public String world(Map<String, Object> model) {
|
||||
model.put("data", "2019");
|
||||
// request.setAttribute("name", "xxxxxxxxx");
|
||||
model.put("msg", "xxxxxxx2222xx");
|
||||
return "world";
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.yaoyuan.jiscuss.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
/**
|
||||
* 用户消息控制器
|
||||
*/
|
||||
@Controller
|
||||
public class UserMsgController extends BaseController {
|
||||
//首页最新消息
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.yaoyuan.jiscuss.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
/**
|
||||
* 其他控制器——积分/权限等
|
||||
*/
|
||||
@Controller
|
||||
public class UserOtherController extends BaseController {
|
||||
|
||||
//用户积分获取
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
package com.yaoyuan.jiscuss.controller;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
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.*;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
/**
|
||||
* 主题帖子评论控制器
|
||||
*/
|
||||
@Controller
|
||||
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;
|
||||
|
||||
@Autowired
|
||||
private IUsersService usersService;
|
||||
|
||||
|
||||
//首页查看主题列表(各种条件筛选,最热最新标签等)
|
||||
|
||||
|
||||
//查看主题详情
|
||||
@RequestMapping("/getdiscussionsbyid")
|
||||
public String getDiscussionsById(HttpServletRequest request, ModelMap map, @RequestParam("id") Integer 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()) {
|
||||
User startUser = usersService.findOne(newdd.getStartUserId());
|
||||
newdd.setAvatar(startUser.getAvatar());
|
||||
newdd.setRealname(startUser.getRealname());
|
||||
newdd.setUsername(startUser.getUsername());
|
||||
}
|
||||
if (null != newdd.getLastUserId()) {
|
||||
User lastUser = usersService.findOne(newdd.getLastUserId());
|
||||
newdd.setAvatarLast(lastUser.getAvatar());
|
||||
newdd.setRealnameLast(lastUser.getRealname());
|
||||
newdd.setUsernameLast(lastUser.getUsername());
|
||||
}
|
||||
|
||||
|
||||
List<Tag> tags = tagsService.findByDId(id);
|
||||
|
||||
List postsObj = postsService.findPostCustomById(id);
|
||||
|
||||
map.put("tags", tags);
|
||||
|
||||
map.put("discussions", newdd);
|
||||
map.put("posts", postsObj);
|
||||
UserInfo user = getUserInfo(request);
|
||||
if (user != null) {
|
||||
map.put("username", user.getUsername());
|
||||
}
|
||||
return "discussions";
|
||||
}
|
||||
|
||||
|
||||
//新建主题
|
||||
@PostMapping(value = "/newdiscussions")
|
||||
@ResponseBody
|
||||
public String newDiscussions(@RequestBody DiscussionCustom discussion) {
|
||||
logger.info(">>> newPost" + discussion);
|
||||
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = servletRequestAttributes.getRequest();
|
||||
UserInfo user = getUserInfo(request);
|
||||
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 discussionOne = new Discussion();
|
||||
BeanUtils.copyProperties(discussion, discussionOne);
|
||||
|
||||
Discussion saveDiscussion = discussionsService.insert(discussionOne);
|
||||
|
||||
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(); //
|
||||
|
||||
}
|
||||
|
||||
|
||||
//编辑主题
|
||||
|
||||
//删除主题
|
||||
|
||||
//新建评论
|
||||
@PostMapping(value = "/newpost")
|
||||
@ResponseBody
|
||||
public String newPosts(@RequestBody Post post) {
|
||||
logger.info(">>> newpost" + post);
|
||||
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = servletRequestAttributes.getRequest();
|
||||
|
||||
UserInfo user = getUserInfo(request);
|
||||
if (user != null) {
|
||||
post.setCreateId(user.getId());
|
||||
}
|
||||
post.setCreateTime(new Date());
|
||||
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("flag", true);
|
||||
return resultobj.toString(); //
|
||||
}
|
||||
|
||||
//删除评论
|
||||
|
||||
//新建标签
|
||||
@PostMapping(value = "/newtags")
|
||||
@ResponseBody
|
||||
public String newTags(@RequestBody Tag tag) {
|
||||
logger.info(">>> newTags" + tag);
|
||||
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = servletRequestAttributes.getRequest();
|
||||
|
||||
UserInfo user = getUserInfo(request);
|
||||
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(); //
|
||||
|
||||
}
|
||||
|
||||
//排行榜等
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package com.yaoyuan.jiscuss.controller;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Discussion;
|
||||
import com.yaoyuan.jiscuss.entity.Tag;
|
||||
import com.yaoyuan.jiscuss.entity.UserInfo;
|
||||
import com.yaoyuan.jiscuss.entity.User;
|
||||
import com.yaoyuan.jiscuss.entity.custom.DiscussionCustom;
|
||||
import com.yaoyuan.jiscuss.service.IDiscussionsService;
|
||||
import com.yaoyuan.jiscuss.service.ITagsService;
|
||||
import com.yaoyuan.jiscuss.service.IUsersService;
|
||||
import com.yaoyuan.jiscuss.util.DelTagsUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户页面系统控制器
|
||||
*/
|
||||
@Controller
|
||||
public class UserSystemController extends BaseController {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(UserSystemController.class);
|
||||
|
||||
@Autowired
|
||||
private IUsersService usersService;
|
||||
|
||||
@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
|
||||
pageNum, HttpServletRequest request, ModelMap map) {
|
||||
logger.info(">>> index");
|
||||
logger.info(">>> tag:" + tag);
|
||||
logger.info(">>> pageNum:" + pageNum);
|
||||
List<User> userall = usersService.getAllList();
|
||||
logger.info(">>> 第一遍的全部用户:" + userall);
|
||||
|
||||
List<User> useral2 = usersService.getAllList();
|
||||
logger.info(">>> 第二遍的全部用户:" + useral2);
|
||||
|
||||
int pageSiz = 10;
|
||||
int pageNumNew = pageNum - 1;
|
||||
Discussion discussion = new Discussion();
|
||||
//分页获取主题帖子
|
||||
Page<Discussion> allDiscussionsPage = discussionsService.queryAllDiscussionsList(discussion, pageNumNew, pageSiz);
|
||||
|
||||
List<Discussion> allDiscussions = allDiscussionsPage.getContent();
|
||||
List<DiscussionCustom> newAllD = new ArrayList<>();
|
||||
|
||||
for (Discussion dd : allDiscussions) {
|
||||
DiscussionCustom newdd = new DiscussionCustom();
|
||||
BeanUtils.copyProperties(dd, newdd);
|
||||
String newCon = "";
|
||||
String content = DelTagsUtil.getTextFromHtml(newdd.getContent());
|
||||
if (null != content && content.length() > 30) {
|
||||
newCon = content.substring(0, 29);
|
||||
} else {
|
||||
newCon = content;
|
||||
}
|
||||
newdd.setContent(newCon);
|
||||
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()) {
|
||||
User lastUser = usersService.findOne(newdd.getLastUserId());
|
||||
newdd.setAvatarLast(lastUser.getAvatar());
|
||||
newdd.setRealnameLast(lastUser.getRealname());
|
||||
newdd.setUsernameLast(lastUser.getUsername());
|
||||
}
|
||||
|
||||
newAllD.add(newdd);
|
||||
}
|
||||
|
||||
logger.info("全部主题==>:{}", allDiscussions);
|
||||
|
||||
Long total = allDiscussionsPage.getTotalElements();
|
||||
|
||||
//获取主题帖子的分页数据
|
||||
List<String> pageNumList = getPageNumList(allDiscussionsPage.getTotalPages());
|
||||
|
||||
//获取所有标签(以后尝试去缓存中取)
|
||||
List<Tag> allTags = tagsService.getAllList();
|
||||
logger.info("全部标签==>:{}", allTags);
|
||||
|
||||
System.out.println(userall.toString());
|
||||
map.put("data", "Jiscuss 用户");
|
||||
map.put("allDiscussions", newAllD);
|
||||
map.put("pageDiscussions", pageNumList);
|
||||
map.put("allTags", allTags);
|
||||
map.put("tag", tag);
|
||||
map.put("type", type);
|
||||
|
||||
map.put("pageSize", pageSiz);
|
||||
map.put("pageTotal", total);
|
||||
map.put("pageNum", pageNum);
|
||||
map.put("pageTotalPages", allDiscussionsPage.getTotalPages());
|
||||
UserInfo user = getUserInfo(request);
|
||||
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));
|
||||
}
|
||||
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) {
|
||||
if (error != null) {
|
||||
map.put("msg", "您输入的用户名密码错误!");
|
||||
return "login";
|
||||
}
|
||||
if (logout != null) {
|
||||
map.put("msg", "退出成功!");
|
||||
return "login";
|
||||
}
|
||||
|
||||
return "login";
|
||||
}
|
||||
|
||||
|
||||
//注册
|
||||
|
||||
//获取设置信息
|
||||
|
||||
//获取首页统计
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.yaoyuan.jiscuss.controller.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Discussion;
|
||||
import com.yaoyuan.jiscuss.exception.BaseException;
|
||||
import com.yaoyuan.jiscuss.response.ResponseCode;
|
||||
import com.yaoyuan.jiscuss.service.IDiscussionsService;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(path="/other_api",produces="application/json;charset=utf-8")
|
||||
@Api(value = "主题帖子(其他)接口管理", tags = { "主题帖子(其他)接口管理"})
|
||||
public class RestPostController {
|
||||
private static Logger logger = LoggerFactory.getLogger(RestPostController.class);
|
||||
|
||||
@Autowired
|
||||
private IDiscussionsService discussionsService;
|
||||
|
||||
@PostMapping("/discussion")
|
||||
@ApiOperation("新增主题")
|
||||
public Discussion save(@RequestBody Discussion discussion) {
|
||||
Discussion saveDiscussion = discussionsService.insert(discussion);
|
||||
if (saveDiscussion !=null) {
|
||||
return saveDiscussion;
|
||||
} else {
|
||||
throw new BaseException(ResponseCode.RESOURCES_NOT_EXIST);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/discussion/{id}")
|
||||
@ApiOperation("获取主题")
|
||||
public Discussion getDiscussions(@PathVariable Integer id) {
|
||||
Discussion discussion = discussionsService.findOne(id);
|
||||
return discussion;
|
||||
}
|
||||
|
||||
@GetMapping("/discussions")
|
||||
@ApiOperation("获取全部主题")
|
||||
public List<Discussion> getAllDiscussions() {
|
||||
List<Discussion> allDiscussions = discussionsService.getAllList();
|
||||
logger.info("全部主题==>:{}",allDiscussions);
|
||||
return allDiscussions;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.yaoyuan.jiscuss.controller.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.User;
|
||||
import com.yaoyuan.jiscuss.exception.BaseException;
|
||||
import com.yaoyuan.jiscuss.response.ResponseCode;
|
||||
import com.yaoyuan.jiscuss.service.IUsersService;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user_api")
|
||||
@Api(value = "用户接口管理", tags = { "用户接口管理" })
|
||||
public class RestUserController {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(RestUserController.class);
|
||||
|
||||
@Autowired
|
||||
private IUsersService usersService;
|
||||
|
||||
@PostMapping("/user")
|
||||
@ApiOperation("新增用户")
|
||||
public User save(@RequestBody User user) {
|
||||
User saveUser = usersService.insert(user);
|
||||
if (saveUser!=null) {
|
||||
return saveUser;
|
||||
} else {
|
||||
throw new BaseException(ResponseCode.RESOURCES_NOT_EXIST);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@DeleteMapping("/user/{id}")
|
||||
@ApiOperation("删除用户")
|
||||
public Boolean delete(@PathVariable Integer id) {
|
||||
Boolean delete = true;
|
||||
usersService.remove(id);
|
||||
if (delete) {
|
||||
return delete;
|
||||
} else {
|
||||
throw new BaseException(ResponseCode.RESOURCES_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/user/{id}")
|
||||
@ApiOperation("修改用户")
|
||||
public User update(@RequestBody User user, @PathVariable Integer id) {
|
||||
User updateuser = usersService.update(user, id);
|
||||
if (updateuser!=null) {
|
||||
return updateuser;
|
||||
} else {
|
||||
throw new BaseException(ResponseCode.RESOURCES_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/user/{id}")
|
||||
@ApiOperation("获取用户")
|
||||
public User getUser(@PathVariable Integer id) {
|
||||
User user = usersService.findOne(id);
|
||||
return user;
|
||||
}
|
||||
|
||||
@GetMapping("/user")
|
||||
@ApiOperation("获取全部用户")
|
||||
public List<User> getUser(User user) {
|
||||
List<User> userall = usersService.getAllList();
|
||||
logger.info("全部用户==>:{}",userall);
|
||||
return userall;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.yaoyuan.jiscuss.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import lombok.Data;
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="discussion")
|
||||
public class Discussion implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", unique = true)
|
||||
private Integer id;
|
||||
|
||||
@Column(name="title")
|
||||
private String title;
|
||||
|
||||
@Column(name="content")
|
||||
private String content;
|
||||
|
||||
@Column(name="comments_count")
|
||||
private Integer commentsCount;
|
||||
|
||||
@Column(name="participants_count")
|
||||
private Integer participantsCount;
|
||||
|
||||
@Column(name="number_index")
|
||||
private Integer numberIndex;
|
||||
|
||||
@Column(name="start_time")
|
||||
private Date startTime;
|
||||
|
||||
@Column(name="start_user_id")
|
||||
private Integer startUserId;
|
||||
|
||||
@Column(name="start_post_id")
|
||||
private Integer startPostId;
|
||||
|
||||
@Column(name="last_time")
|
||||
private Date lastTime;
|
||||
|
||||
@Column(name="last_user_id")
|
||||
private Integer lastUserId;
|
||||
|
||||
@Column(name="last_post_id")
|
||||
private Integer lastPostId;
|
||||
|
||||
@Column(name="last_post_number")
|
||||
private Integer lastPostNumber;
|
||||
|
||||
@Column(name="is_approved")
|
||||
private Integer isApproved;
|
||||
|
||||
@Column(name="like_count")
|
||||
private Integer likeCount;
|
||||
|
||||
|
||||
@Column(name="ip_address")
|
||||
private String ipAddress;
|
||||
|
||||
@Column(name="create_id")
|
||||
private Integer createId;
|
||||
|
||||
@Column(name="create_time")
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
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 lombok.Data;
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="discussiontag")
|
||||
public class DiscussionTag implements Serializable{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@Column(name="discussion_id")
|
||||
private Integer discussionId;
|
||||
|
||||
@Column(name="tag_id")
|
||||
private Integer tagId;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.yaoyuan.jiscuss.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="post")
|
||||
public class Post implements Serializable{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
@Column(name="discussion_id")
|
||||
private Integer discussionId;
|
||||
|
||||
@Column(name="number")
|
||||
private Integer number;
|
||||
|
||||
@Column(name="time")
|
||||
private Date time;
|
||||
|
||||
@Column(name="user_id")
|
||||
private Integer userId;
|
||||
|
||||
@Column(name="type")
|
||||
private String type;
|
||||
|
||||
@Column(name="content")
|
||||
private String content;
|
||||
|
||||
@Column(name="parent_id")
|
||||
private Integer parentId;
|
||||
|
||||
@Column(name="edit_time")
|
||||
private Date editTime;
|
||||
|
||||
@Column(name="edit_user_id")
|
||||
private Integer editUserId;
|
||||
|
||||
@Column(name="ip_address")
|
||||
private String ipAddress;
|
||||
|
||||
@Column(name="copyright")
|
||||
private String copyright;
|
||||
|
||||
@Column(name="is_approved")
|
||||
private Integer isApproved;
|
||||
|
||||
@Column(name="create_id")
|
||||
private Integer createId;
|
||||
|
||||
@Column(name="create_time")
|
||||
private Date createTime;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.yaoyuan.jiscuss.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="setting")
|
||||
public class Setting implements Serializable{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
@Column(name="setting_key")
|
||||
private String settingKey;
|
||||
|
||||
@Column(name="setting_value")
|
||||
private String settingValue;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.yaoyuan.jiscuss.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="tag")
|
||||
public class Tag implements Serializable{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
@Column(name="name")
|
||||
private String name;
|
||||
|
||||
@Column(name="description")
|
||||
private String description;
|
||||
|
||||
@Column(name="color")
|
||||
private String color;
|
||||
|
||||
@Column(name="icon")
|
||||
private String icon;
|
||||
|
||||
@Column(name="position")
|
||||
private Integer position;
|
||||
|
||||
@Column(name="parent_id")
|
||||
private Integer parentId;
|
||||
|
||||
@Column(name="discussions_count")
|
||||
private String discussionsCount;
|
||||
|
||||
@Column(name="last_time")
|
||||
private Date lastTime;
|
||||
|
||||
@Column(name="last_discussion_id")
|
||||
private Integer lastDiscussionId;
|
||||
|
||||
@Column(name="create_id")
|
||||
private Integer createId;
|
||||
|
||||
@Column(name="create_time")
|
||||
private Date createTime;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.yaoyuan.jiscuss.entity;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="user")
|
||||
public class User implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
@Column(name="username")
|
||||
private String username;
|
||||
|
||||
@Column(name="realname")
|
||||
private String realname;
|
||||
|
||||
@Column(name="email")
|
||||
private String email;
|
||||
|
||||
@Column(name="password")
|
||||
private String password;
|
||||
|
||||
@Column(name="join_time")
|
||||
private Date joinTime;
|
||||
|
||||
@Column(name="age")
|
||||
private Integer age;
|
||||
|
||||
@Column(name="gender")
|
||||
private String gender;
|
||||
|
||||
@Column(name="avatar")
|
||||
private String avatar;
|
||||
|
||||
@Column(name="phone")
|
||||
private String phone;
|
||||
|
||||
@Column(name="discussions_count")
|
||||
private Integer discussionsCount;
|
||||
|
||||
@Column(name="comments_count")
|
||||
private Integer commentsCount;
|
||||
|
||||
@Column(name="last_seen_time")
|
||||
private Date lastSeenTime;
|
||||
|
||||
@Column(name="flag")
|
||||
private Integer flag;
|
||||
|
||||
@Column(name="level")
|
||||
private Integer level;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.yaoyuan.jiscuss.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author yaoyuan2.chu
|
||||
* @Title:
|
||||
* @Package com.yaoyuan.jiscuss.entity
|
||||
* @Description:
|
||||
* @date 2020/7/16 14:55
|
||||
*/
|
||||
@Data
|
||||
public class UserInfo implements UserDetails{
|
||||
|
||||
private Collection<GrantedAuthority> authorities;
|
||||
private String password;
|
||||
private String username;
|
||||
private String phone;
|
||||
private Integer age;
|
||||
private Integer id;
|
||||
private String realname;
|
||||
private String email;
|
||||
private String gender;
|
||||
private Integer level;
|
||||
private Integer flag;
|
||||
|
||||
public UserInfo() {
|
||||
}
|
||||
|
||||
public UserInfo(Collection<GrantedAuthority> authorities, Integer id, String password, String username, String phone) {
|
||||
this.authorities = authorities;
|
||||
this.id = id;
|
||||
this.password = password;
|
||||
this.username = username;
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
return authorities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonLocked() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserInfo{" +
|
||||
"authorities=" + authorities +
|
||||
", password='" + password + '\'' +
|
||||
", username='" + username + '\'' +
|
||||
", id='" + id + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.yaoyuan.jiscuss.entity.custom;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Discussion;
|
||||
import com.yaoyuan.jiscuss.entity.Tag;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yaoyuan2.chu
|
||||
* @Title:
|
||||
* @Package com.yaoyuan.jiscuss.entity.custom
|
||||
* @Description:
|
||||
* @date 2020/9/9 14:44
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Setter
|
||||
@Getter
|
||||
public class DiscussionCustom extends Discussion {
|
||||
|
||||
private String avatar;
|
||||
|
||||
private String username;
|
||||
|
||||
private String realname;
|
||||
|
||||
private String avatarLast;
|
||||
|
||||
private String usernameLast;
|
||||
|
||||
private String realnameLast;
|
||||
|
||||
private String tag;
|
||||
|
||||
private List<Tag> tagList;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.yaoyuan.jiscuss.entity.custom;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Post;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yaoyuan2.chu
|
||||
* @Title:
|
||||
* @Package com.yaoyuan.jiscuss.entity.custom
|
||||
* @Description:
|
||||
* @date 2020/9/9 14:44
|
||||
*/
|
||||
@Data
|
||||
@Setter
|
||||
@Getter
|
||||
public class PostCustom extends Post {
|
||||
|
||||
private String avatar;
|
||||
|
||||
private String username;
|
||||
|
||||
private String realname;
|
||||
|
||||
private String avatarReply;
|
||||
|
||||
private String usernameReply;
|
||||
|
||||
private String realnameReply;
|
||||
|
||||
private List<PostCustom> child;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.yaoyuan.jiscuss.exception;
|
||||
|
||||
import com.yaoyuan.jiscuss.response.ResponseCode;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 业务异常类,继承运行时异常,确保事务正常回滚
|
||||
*
|
||||
* @author NULL
|
||||
* @since 2019-07-16
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class BaseException extends RuntimeException{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
private ResponseCode code;
|
||||
|
||||
public BaseException(ResponseCode code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public BaseException(Throwable cause, ResponseCode code) {
|
||||
super(cause);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.yaoyuan.jiscuss.handler;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.security.web.WebAttributes;
|
||||
import org.springframework.security.web.access.AccessDeniedHandler;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* 处理无权请求
|
||||
* @author charlie
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class CustomAccessDeniedHandler implements AccessDeniedHandler {
|
||||
|
||||
private Logger log = LoggerFactory.getLogger(CustomAccessDeniedHandler.class);
|
||||
|
||||
@Override
|
||||
public void handle(HttpServletRequest request, HttpServletResponse response,
|
||||
AccessDeniedException accessDeniedException) throws IOException, ServletException {
|
||||
boolean isAjax = ControllerTools.isAjaxRequest(request);
|
||||
System.out.println("CustomAccessDeniedHandler handle");
|
||||
if (!response.isCommitted()) {
|
||||
if (isAjax) {
|
||||
String msg = accessDeniedException.getMessage();
|
||||
log.info("accessDeniedException.message:" + msg);
|
||||
String accessDenyMsg = "{\"code\":\"403\",\"msg\":\"没有权限\"}";
|
||||
ControllerTools.print(response, accessDenyMsg);
|
||||
} else {
|
||||
request.setAttribute(WebAttributes.ACCESS_DENIED_403, accessDeniedException);
|
||||
response.setStatus(HttpStatus.FORBIDDEN.value());
|
||||
RequestDispatcher dispatcher = request.getRequestDispatcher("/403");
|
||||
dispatcher.forward(request, response);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class ControllerTools {
|
||||
public static boolean isAjaxRequest(HttpServletRequest request) {
|
||||
return "XMLHttpRequest".equals(request.getHeader("X-Requested-With"));
|
||||
}
|
||||
|
||||
public static void print(HttpServletResponse response, String msg) throws IOException {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/json; charset=utf-8");
|
||||
PrintWriter writer = response.getWriter();
|
||||
writer.write(msg);
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.yaoyuan.jiscuss.handler;
|
||||
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* RBAC数据模型控制权限
|
||||
* @author charlie
|
||||
*
|
||||
*/
|
||||
@Component("rbacPermission")
|
||||
public class RbacPermission{
|
||||
|
||||
private AntPathMatcher antPathMatcher = new AntPathMatcher();
|
||||
|
||||
public boolean hasPermission(HttpServletRequest request, Authentication authentication) {
|
||||
Object principal = authentication.getPrincipal();
|
||||
boolean hasPermission = false;
|
||||
|
||||
hasPermission = true;
|
||||
// if (principal instanceof UserEntity) {
|
||||
// // 读取用户所拥有的权限菜单
|
||||
// List<Menu> menus = ((UserEntity) principal).getRoleMenus();
|
||||
// System.out.println(menus.size());
|
||||
// for (Menu menu : menus) {
|
||||
// if (antPathMatcher.match(menu.getMenuUrl(), request.getRequestURI())) {
|
||||
// hasPermission = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
return hasPermission;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.yaoyuan.jiscuss.repository;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Discussion;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface DiscussionsRepository extends JpaRepository<Discussion,Integer> {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.yaoyuan.jiscuss.repository;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.DiscussionTag;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
||||
@Repository
|
||||
public interface DiscussionsTagsRepository extends JpaRepository<DiscussionTag,Integer> {
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.yaoyuan.jiscuss.repository;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Post;
|
||||
import com.yaoyuan.jiscuss.entity.custom.PostCustom;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Repository
|
||||
public interface PostsRepository extends JpaRepository<Post,Integer> {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dId
|
||||
* @return
|
||||
*/
|
||||
@Query("from Post where discussionId = :dId")
|
||||
List<Post> findOneBy(@Param("dId")Integer dId);
|
||||
|
||||
@Query(value = "select p.*,u.avatar as user_avatar ,u.username as user_username ,u.realname as user_realname ," +
|
||||
"u2.avatar as create_avatar ,u2.username as create_username ,u2.realname as create_realname \n" +
|
||||
"from Post p \n" +
|
||||
"left join User u on p.user_id = u.id \n" +
|
||||
"left join User u2 on p.create_id = u2.id \n" +
|
||||
"where p.discussion_id = :dId order by p.create_time desc"
|
||||
, nativeQuery = true)
|
||||
List<Map<String, Object>> findPostCustomById(@Param("dId")Integer dId);
|
||||
|
||||
|
||||
@Query(value = "select p.*,u.avatar as user_avatar ,u.username as user_username ,u.realname as user_realname ," +
|
||||
"u2.avatar as create_avatar ,u2.username as create_username ,u2.realname as create_realname \n" +
|
||||
"from Post p \n" +
|
||||
"left join User u on p.user_id = u.id \n" +
|
||||
"left join User u2 on p.create_id = u2.id \n" +
|
||||
"where p.discussion_id = :dId and p.parent_id is null order by p.create_time desc"
|
||||
, nativeQuery = true)
|
||||
List<Map<String, Object>> findAllByDIdAndparentIdNull(@Param("dId")Integer dId);
|
||||
|
||||
@Query(value = "select p.*,u.avatar as user_avatar ,u.username as user_username ,u.realname as user_realname ," +
|
||||
"u2.avatar as create_avatar ,u2.username as create_username ,u2.realname as create_realname \n" +
|
||||
"from Post p \n" +
|
||||
"left join User u on p.user_id = u.id \n" +
|
||||
"left join User u2 on p.create_id = u2.id \n" +
|
||||
"where p.discussion_id = :dId and p.parent_id is not null order by p.create_time desc"
|
||||
, nativeQuery = true)
|
||||
List<Map<String, Object>> findAllByDIdAndparentIdNotNull(@Param("dId")Integer dId);
|
||||
|
||||
|
||||
// @Query("from Post where parentId is null and discussionId = :dId")
|
||||
// List<Post> findAllByDIdAndparentIdNull(@Param("dId")Integer dId);
|
||||
//
|
||||
// @Query("from Post where parentId is not null and discussionId = :dId")
|
||||
// List<Post> findAllByDIdAndparentIdNotNull(@Param("dId")Integer dId);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.yaoyuan.jiscuss.repository;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Setting;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface SettingsRepository extends JpaRepository<Setting,Integer> {
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.yaoyuan.jiscuss.repository;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Tag;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.yaoyuan.jiscuss.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.User;
|
||||
|
||||
|
||||
@Repository
|
||||
public interface UsersRepository extends JpaRepository<User,Integer> {
|
||||
/**
|
||||
*
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@Query("from User where username like %:username%")
|
||||
List<User> getByUsernameIsLike(@Param("username")String username);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
User getById(Integer id);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@Query("from User where username = :username")
|
||||
User getByUsername(String username);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param username
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
@Query("from User where username = :username and password = :password")
|
||||
User checkByUsernameAndPassword(String username, String password);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.yaoyuan.jiscuss.response;
|
||||
|
||||
/**
|
||||
* 返回状态码
|
||||
*
|
||||
* @author NULL
|
||||
* @date 2019-12-16
|
||||
*/
|
||||
public enum ResponseCode {
|
||||
/**
|
||||
* 成功返回的状态码
|
||||
*/
|
||||
SUCCESS(10000, "success"),
|
||||
/**
|
||||
* 资源不存在的状态码
|
||||
*/
|
||||
RESOURCES_NOT_EXIST(10001, "资源不存在"),
|
||||
/**
|
||||
* 所有无法识别的异常默认的返回状态码
|
||||
*/
|
||||
SERVICE_ERROR(50000, "服务器异常");
|
||||
/**
|
||||
* 状态码
|
||||
*/
|
||||
private int code;
|
||||
/**
|
||||
* 返回信息
|
||||
*/
|
||||
private String msg;
|
||||
|
||||
ResponseCode(int code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.yaoyuan.jiscuss.response;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 统一的公共响应体
|
||||
* @author NULL
|
||||
* @date 2019-12-16
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class ResponseResult implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 返回状态码
|
||||
*/
|
||||
private Integer code;
|
||||
/**
|
||||
* 返回信息
|
||||
*/
|
||||
private String msg;
|
||||
/**
|
||||
* 数据
|
||||
*/
|
||||
private Object data;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.yaoyuan.jiscuss.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Discussion;
|
||||
|
||||
public interface IDiscussionsService {
|
||||
|
||||
List<Discussion> getAllList();
|
||||
|
||||
Discussion insert(Discussion discussion);
|
||||
|
||||
Discussion findOne(Integer id);
|
||||
|
||||
Page<Discussion> queryAllDiscussionsList(Discussion discussion, int pageNum, int pageSize);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.yaoyuan.jiscuss.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.DiscussionTag;
|
||||
|
||||
public interface IDiscussionsTagsService {
|
||||
|
||||
List<DiscussionTag> getAllList();
|
||||
|
||||
DiscussionTag insert(DiscussionTag discussionTag);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.yaoyuan.jiscuss.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Post;
|
||||
import com.yaoyuan.jiscuss.entity.custom.PostCustom;
|
||||
|
||||
public interface IPostsService {
|
||||
List<Post> getAllList();
|
||||
|
||||
Post insert(Post post);
|
||||
|
||||
List<Post> findOneBy(Integer id);
|
||||
|
||||
List<PostCustom> findPostCustomById(Integer id);
|
||||
|
||||
Post findOneByid(Integer parentId);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.yaoyuan.jiscuss.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Setting;
|
||||
|
||||
public interface ISettingsService {
|
||||
|
||||
List<Setting> getAllList();
|
||||
|
||||
Setting insert(Setting setting);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.yaoyuan.jiscuss.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Tag;
|
||||
|
||||
public interface ITagsService {
|
||||
|
||||
List<Tag> getAllList();
|
||||
|
||||
Tag insert(Tag tag);
|
||||
|
||||
List<Tag> findByDId(Integer id);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.yaoyuan.jiscuss.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.User;
|
||||
|
||||
public interface IUsersService {
|
||||
|
||||
List<User> getAllList();
|
||||
|
||||
Page<User> queryAllUsersList(int pageNum, int pageSize);
|
||||
|
||||
List<User> getByUsernameIsLike(String name);
|
||||
|
||||
// @Cacheable("myCache")
|
||||
User findOne(Integer id);
|
||||
|
||||
User insert(User user);
|
||||
|
||||
void remove(Integer id);
|
||||
|
||||
void deleteAll();
|
||||
|
||||
User getByUsername(String username);
|
||||
|
||||
User checkByUsernameAndPassword(String username, String password);
|
||||
|
||||
User update(User user, Integer id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.yaoyuan.jiscuss.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Discussion;
|
||||
import com.yaoyuan.jiscuss.repository.DiscussionsRepository;
|
||||
import com.yaoyuan.jiscuss.service.IDiscussionsService;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class DiscussionsServiceImpl implements IDiscussionsService {
|
||||
@Autowired
|
||||
private DiscussionsRepository discussionsRepository;
|
||||
|
||||
@Override
|
||||
public List<Discussion> getAllList() {
|
||||
return discussionsRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Discussion insert(Discussion discussion) {
|
||||
|
||||
return discussionsRepository.save(discussion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Discussion findOne(Integer id) {
|
||||
Discussion discussion = new Discussion();
|
||||
discussion.setId(id);
|
||||
return discussionsRepository.getOne(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);
|
||||
//将匹配对象封装成Example对象
|
||||
Example<Discussion> example = Example.of(discussion);
|
||||
|
||||
return discussionsRepository.findAll(example, pageable);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.yaoyuan.jiscuss.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.DiscussionTag;
|
||||
import com.yaoyuan.jiscuss.repository.DiscussionsTagsRepository;
|
||||
import com.yaoyuan.jiscuss.service.IDiscussionsTagsService;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class DiscussionsTagsServiceImpl implements IDiscussionsTagsService {
|
||||
@Autowired
|
||||
private DiscussionsTagsRepository discussionsTagsRepository;
|
||||
|
||||
@Override
|
||||
public List<DiscussionTag> getAllList() {
|
||||
return discussionsTagsRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiscussionTag insert(DiscussionTag discussionTag) {
|
||||
return discussionsTagsRepository.save(discussionTag);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.yaoyuan.jiscuss.service.impl;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Reader;
|
||||
import java.sql.Clob;
|
||||
import java.util.*;
|
||||
|
||||
import com.yaoyuan.jiscuss.common.Node;
|
||||
import com.yaoyuan.jiscuss.common.PostCommonUtil;
|
||||
import com.yaoyuan.jiscuss.entity.Discussion;
|
||||
import com.yaoyuan.jiscuss.entity.custom.DiscussionCustom;
|
||||
import com.yaoyuan.jiscuss.entity.custom.PostCustom;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Post;
|
||||
import com.yaoyuan.jiscuss.repository.PostsRepository;
|
||||
import com.yaoyuan.jiscuss.service.IPostsService;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class PostsServiceImpl implements IPostsService {
|
||||
@Autowired
|
||||
private PostsRepository postsRepository;
|
||||
|
||||
@Override
|
||||
public List<Post> getAllList() {
|
||||
return postsRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Post> findOneBy(Integer id) {
|
||||
|
||||
List<Post> posts = postsRepository.findOneBy(id);
|
||||
return posts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Post findOneByid(Integer id) {
|
||||
Post post = new Post();
|
||||
post.setId(id);
|
||||
Example<Post> example = Example.of(post);
|
||||
Optional<Post> postRes = postsRepository.findOne(example);
|
||||
return postRes.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
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集合中
|
||||
for (PostCustom post : firstpostCustomList) {
|
||||
Node node = new Node();
|
||||
BeanUtils.copyProperties(post, node);
|
||||
nodes.add(node);
|
||||
}
|
||||
//将回复添加到对应的位置
|
||||
List list = Node.addAllNode(nodes, thenpostCustomList);
|
||||
System.out.println();
|
||||
//打印回复链表
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.yaoyuan.jiscuss.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Setting;
|
||||
import com.yaoyuan.jiscuss.repository.SettingsRepository;
|
||||
import com.yaoyuan.jiscuss.service.ISettingsService;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class SettingsServiceImpl implements ISettingsService {
|
||||
@Autowired
|
||||
private SettingsRepository settingsRepository;
|
||||
|
||||
@Override
|
||||
public List<Setting> getAllList() {
|
||||
return settingsRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Setting insert(Setting setting) {
|
||||
return settingsRepository.save(setting);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.yaoyuan.jiscuss.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Tag;
|
||||
import com.yaoyuan.jiscuss.repository.TagsRepository;
|
||||
import com.yaoyuan.jiscuss.service.ITagsService;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class TagsServiceImpl implements ITagsService {
|
||||
@Autowired
|
||||
private TagsRepository tagsRepository;
|
||||
|
||||
@Override
|
||||
public List<Tag> getAllList() {
|
||||
return tagsRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag insert(Tag tag) {
|
||||
return tagsRepository.save(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tag> findByDId(Integer id) {
|
||||
return tagsRepository.findByDId(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.yaoyuan.jiscuss.service.impl;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.UserInfo;
|
||||
import com.yaoyuan.jiscuss.entity.User;
|
||||
import com.yaoyuan.jiscuss.service.IUsersService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yaoyuan2.chu
|
||||
* @Title:
|
||||
* @Package com.yaoyuan.jiscuss.service.impl
|
||||
* @Description:
|
||||
* @date 2020/7/15 16:34
|
||||
*/
|
||||
@Component
|
||||
public class UserDetailServiceImpl implements UserDetailsService {
|
||||
@Autowired
|
||||
private IUsersService userInfoService;
|
||||
|
||||
/**
|
||||
* 需新建配置类注册一个指定的加密方式Bean,或在下一步Security配置类中注册指定
|
||||
*/
|
||||
@Autowired
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
@Override
|
||||
public UserInfo loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
// 通过用户名从数据库获取用户信息
|
||||
User userInfo = userInfoService.getByUsername(username);
|
||||
if (userInfo == null) {
|
||||
throw new UsernameNotFoundException("用户不存在");
|
||||
}
|
||||
|
||||
// 得到用户角色
|
||||
String role = "admin";
|
||||
|
||||
// 角色集合
|
||||
List<GrantedAuthority> authorities = new ArrayList<>();
|
||||
// 角色必须以`ROLE_`开头,数据库中没有,则在这里加
|
||||
authorities.add(new SimpleGrantedAuthority("ROLE_" + role));
|
||||
|
||||
return new UserInfo(
|
||||
authorities,
|
||||
userInfo.getId(),
|
||||
// 因为数据库是明文,所以这里需加密密码
|
||||
passwordEncoder.encode(userInfo.getPassword()),
|
||||
userInfo.getUsername(),
|
||||
userInfo.getPhone()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package com.yaoyuan.jiscuss.service.impl;
|
||||
|
||||
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.User;
|
||||
import com.yaoyuan.jiscuss.repository.UsersRepository;
|
||||
import com.yaoyuan.jiscuss.service.IUsersService;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class UsersServiceImpl implements IUsersService {
|
||||
@Autowired
|
||||
private UsersRepository usersRepository;
|
||||
|
||||
/**
|
||||
* 获取全部用户
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(value = "user")
|
||||
@Override
|
||||
public List<User> getAllList() {
|
||||
return usersRepository.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param pageNum
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Page<User> queryAllUsersList(int pageNum, int pageSize) {
|
||||
Sort sort=new Sort(Sort.Direction.DESC,"id");
|
||||
@SuppressWarnings("deprecation")
|
||||
Pageable pageable=new PageRequest(pageNum,pageSize,sort);
|
||||
return usersRepository.findAll(pageable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据名称模糊查询
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<User> getByUsernameIsLike(String name) {
|
||||
return usersRepository.getByUsernameIsLike(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(value = "user", key = "#id")
|
||||
@Override
|
||||
public User findOne(Integer id) {
|
||||
return usersRepository.getById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
@CachePut(value = "user", key = "#user.id")
|
||||
@Override
|
||||
public User insert(User user) {
|
||||
return usersRepository.save(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新修改
|
||||
* @param user
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@CachePut(value = "user", key = "#user.id")
|
||||
@Override
|
||||
public User update(User user, Integer id) {
|
||||
return usersRepository.saveAndFlush(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除
|
||||
* @param id
|
||||
*/
|
||||
@CacheEvict(value = "user", key = "#id")
|
||||
@Override
|
||||
public void remove(Integer id) {
|
||||
usersRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除所有
|
||||
*/
|
||||
@Override
|
||||
public void deleteAll() {
|
||||
usersRepository.deleteAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据名称查询
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public User getByUsername(String username) {
|
||||
return usersRepository.getByUsername(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证用户名密码
|
||||
* @param username
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public User checkByUsernameAndPassword(String username, String password) {
|
||||
return usersRepository.checkByUsernameAndPassword(username,password);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.yaoyuan.jiscuss.util;
|
||||
|
||||
/**
|
||||
* @author yaoyuan2.chu
|
||||
* @Title:
|
||||
* @Package com.yaoyuan.jiscuss.util
|
||||
* @Description:
|
||||
* @date 2020/8/31 20:52
|
||||
*/
|
||||
/**
|
||||
* 去除内容页代码里的HTML标签
|
||||
*
|
||||
*/
|
||||
public class DelTagsUtil {
|
||||
/**
|
||||
* 去除html代码中含有的标签
|
||||
* @param htmlStr
|
||||
* @return
|
||||
*/
|
||||
public static String delHtmlTags(String htmlStr) {
|
||||
//定义script的正则表达式,去除js可以防止注入
|
||||
String scriptRegex="<script[^>]*?>[\\s\\S]*?<\\/script>";
|
||||
//定义style的正则表达式,去除style样式,防止css代码过多时只截取到css样式代码
|
||||
String styleRegex="<style[^>]*?>[\\s\\S]*?<\\/style>";
|
||||
//定义HTML标签的正则表达式,去除标签,只提取文字内容
|
||||
String htmlRegex="<[^>]+>";
|
||||
//定义空格,回车,换行符,制表符
|
||||
String spaceRegex = "\\s*|\t|\r|\n";
|
||||
|
||||
// 过滤script标签
|
||||
htmlStr = htmlStr.replaceAll(scriptRegex, "");
|
||||
// 过滤style标签
|
||||
htmlStr = htmlStr.replaceAll(styleRegex, "");
|
||||
// 过滤html标签
|
||||
htmlStr = htmlStr.replaceAll(htmlRegex, "");
|
||||
// 过滤空格等
|
||||
htmlStr = htmlStr.replaceAll(spaceRegex, "");
|
||||
return htmlStr.trim(); // 返回文本字符串
|
||||
}
|
||||
/**
|
||||
* 获取HTML代码里的内容
|
||||
* @param htmlStr
|
||||
* @return
|
||||
*/
|
||||
public static String getTextFromHtml(String htmlStr){
|
||||
//去除html标签
|
||||
htmlStr = delHtmlTags(htmlStr);
|
||||
//去除空格" "
|
||||
htmlStr = htmlStr.replaceAll(" ","");
|
||||
return htmlStr;
|
||||
}
|
||||
|
||||
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>";
|
||||
System.out.println(getTextFromHtml(htmlStr));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user