修改博客

master
zhangmeng 2021-11-17 18:20:30 +08:00
parent 33be0d7c00
commit b40d043645
17 changed files with 355 additions and 105 deletions

View File

@ -8,12 +8,15 @@ import com.zhangmeng.admin.manager.service.*;
import com.zhangmeng.admin.manager.utils.UserUtil; import com.zhangmeng.admin.manager.utils.UserUtil;
import com.zhangmeng.model.base.baseController.BaseController; import com.zhangmeng.model.base.baseController.BaseController;
import com.zhangmeng.model.base.baseUtil.CommonUtil; import com.zhangmeng.model.base.baseUtil.CommonUtil;
import com.zhangmeng.model.dto.article.ArticleDto;
import com.zhangmeng.model.dto.article.ArticleModel;
import com.zhangmeng.model.dto.system.EncryptType; import com.zhangmeng.model.dto.system.EncryptType;
import com.zhangmeng.model.dto.system.Menu; import com.zhangmeng.model.dto.system.Menu;
import com.zhangmeng.model.dto.query.QueryParams; import com.zhangmeng.model.dto.query.QueryParams;
import com.zhangmeng.model.dto.system.SysConstant; import com.zhangmeng.model.dto.system.SysConstant;
import com.zhangmeng.model.entity.*; import com.zhangmeng.model.entity.*;
import com.zhangmeng.model.vo.Result; import com.zhangmeng.model.vo.Result;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
@ -30,8 +33,8 @@ import java.util.*;
/** /**
* @author zhangmeng * @author zhangmeng
* @date 202111909:06:23
* @version 1.0 * @version 1.0
* @date 202111909:06:23
*/ */
@Controller @Controller
public class UrlRequestController extends BaseController { public class UrlRequestController extends BaseController {
@ -74,21 +77,21 @@ public class UrlRequestController extends BaseController {
//跳转首页 //跳转首页
@GetMapping({"/login"}) @GetMapping({"/login"})
public ModelAndView login (){ public ModelAndView login() {
return this.jumpPage("admin/login"); return this.jumpPage("admin/login");
} }
//首页 //首页
@PostMapping("/admin/index") @PostMapping("/admin/index")
public ModelAndView admin_index(Model model){ public ModelAndView admin_index(Model model) {
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
model.addAttribute("uuid",uuid); model.addAttribute("uuid", uuid);
User user = this.userUtil.currentUser(); User user = this.userUtil.currentUser();
String photo = "/mystyle-cloud-admin-manager/system/admin/images/avatar.jpg"; String photo = "/mystyle-cloud-admin-manager/system/admin/images/avatar.jpg";
if (user.getAvatar() == null ){ if (user.getAvatar() == null) {
user.setAvatar(photo); user.setAvatar(photo);
} }
model.addAttribute("loginUser",user); model.addAttribute("loginUser", user);
return this.jumpPage("admin/index"); return this.jumpPage("admin/index");
} }
@ -112,71 +115,74 @@ public class UrlRequestController extends BaseController {
model.addAttribute("loginUser", loginUser); model.addAttribute("loginUser", loginUser);
//用户人数 //用户人数
Integer user_count = this.userService.selectCountEq("deleteStatus", false); Integer user_count = this.userService.selectCountEq("deleteStatus", false);
model.addAttribute("user_count",user_count); model.addAttribute("user_count", user_count);
//文章数量 //文章数量
Integer article_count = this.articleFeign.selectCountEq( false); Integer article_count = this.articleFeign.selectCountEq(false);
model.addAttribute("article_count",article_count); model.addAttribute("article_count", article_count);
//小说数量 //小说数量
model.addAttribute("fiction_count",16); model.addAttribute("fiction_count", 16);
//消息数量 //消息数量
model.addAttribute("message_count",200); model.addAttribute("message_count", 200);
//最新的十篇文章 //最新的十篇文章
List<Article> articleList = this.articleFeign.findByCondition(); List<Article> articleList = this.articleFeign.findByCondition();
//折线图 //折线图
List<String> X_date = CommonUtil.day_of_pass(7);//x List<String> X_date = CommonUtil.day_of_pass(7);//x
List<Integer> Y_data= this.articleFeign.selectCountByDayOfPass(X_date); List<Integer> Y_data = this.articleFeign.selectCountByDayOfPass(X_date);
Map<String,Object> data_x_y = new HashMap<>(); Map<String, Object> data_x_y = new HashMap<>();
data_x_y.put("X_date", JSONObject.toJSONString(X_date)); data_x_y.put("X_date", JSONObject.toJSONString(X_date));
data_x_y.put("Y_data",JSONObject.toJSONString(Y_data)); data_x_y.put("Y_data", JSONObject.toJSONString(Y_data));
model.addAttribute("data_x_y",data_x_y); model.addAttribute("data_x_y", data_x_y);
model.addAttribute("articleList",articleList); model.addAttribute("articleList", articleList);
//日志 //日志
List<SysLog> sysLogs = this.sysLogService.findAll(new QueryParams(1, 10, "addTime desc")); List<SysLog> sysLogs = this.sysLogService.findAll(new QueryParams(1, 10, "addTime desc"));
List<Map<String,Object>> list = new ArrayList<>(); List<Map<String, Object>> list = new ArrayList<>();
if (sysLogs.size()>0){ if (sysLogs.size() > 0) {
for (SysLog sysLog : sysLogs) { for (SysLog sysLog : sysLogs) {
Map<String,Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
User user = this.userService.findById(sysLog.getUser_id()); User user = this.userService.findById(sysLog.getUser_id());
map.put("avatar",user.getAvatar() == null ? "/mystyle-cloud-admin-manager/system/admin/images/avatar.jpg":user.getAvatar()); map.put("avatar", user.getAvatar() == null ? "/mystyle-cloud-admin-manager/system/admin/images/avatar.jpg" : user.getAvatar());
map.put("username",user.getUsername()); map.put("username", user.getUsername());
map.put("addTime",sysLog.getAddTime()); map.put("addTime", sysLog.getAddTime());
map.put("description",sysLog.getDescription()); map.put("description", sysLog.getDescription());
String date_difference = CommonUtil.date_difference(sysLog.getAddTime()); String date_difference = CommonUtil.date_difference(sysLog.getAddTime());
map.put("date_difference",date_difference); map.put("date_difference", date_difference);
list.add(map); list.add(map);
} }
} }
model.addAttribute("sysLogs",list); model.addAttribute("sysLogs", list);
return jumpPage("admin/home/home"); return jumpPage("admin/home/home");
} }
/** /**
* *
*
* @param model * @param model
* @return * @return
*/ */
@GetMapping("/user/index") @GetMapping("/user/index")
public ModelAndView user_index(Model model){ public ModelAndView user_index(Model model) {
return this.jumpPage("admin/user/list"); return this.jumpPage("admin/user/list");
} }
/** /**
* *
*
* @param model * @param model
* @return * @return
*/ */
@GetMapping("/user/add") @GetMapping("/user/add")
public ModelAndView user_add(Model model){ public ModelAndView user_add(Model model) {
return this.jumpPage("admin/user/add"); return this.jumpPage("admin/user/add");
} }
/** /**
* *
*
* @param model * @param model
* @return * @return
*/ */
@GetMapping("/user/edit") @GetMapping("/user/edit")
public ModelAndView user_edit(Model model,String userId){ public ModelAndView user_edit(Model model, String userId) {
if (userId != null && !userId.equals("")) { if (userId != null && !userId.equals("")) {
User user = this.userService.findById(Long.parseLong(userId)); User user = this.userService.findById(Long.parseLong(userId));
model.addAttribute("user", user); model.addAttribute("user", user);
@ -186,6 +192,7 @@ public class UrlRequestController extends BaseController {
/** /**
* *
*
* @return * @return
*/ */
@GetMapping("/role/index") @GetMapping("/role/index")
@ -195,6 +202,7 @@ public class UrlRequestController extends BaseController {
/** /**
* *
*
* @param model * @param model
* @return * @return
*/ */
@ -216,6 +224,7 @@ public class UrlRequestController extends BaseController {
/** /**
* *
*
* @param model * @param model
* @param roleId * @param roleId
* @return * @return
@ -237,7 +246,7 @@ public class UrlRequestController extends BaseController {
@GetMapping("/permission/add") @GetMapping("/permission/add")
public ModelAndView permission_add(Model model) { public ModelAndView permission_add(Model model) {
model.addAttribute("permissionTypeList",Permission.Type.valueListMap()); model.addAttribute("permissionTypeList", Permission.Type.valueListMap());
return this.jumpPage("admin/permission/add"); return this.jumpPage("admin/permission/add");
} }
@ -246,16 +255,16 @@ public class UrlRequestController extends BaseController {
if (CommonUtil.isNotNull(permissionId)) { if (CommonUtil.isNotNull(permissionId)) {
Permission permission = this.permissionService.findById(Long.parseLong(permissionId)); Permission permission = this.permissionService.findById(Long.parseLong(permissionId));
model.addAttribute("permission", permission); model.addAttribute("permission", permission);
model.addAttribute("permissionTypeList",Permission.Type.valueListMap()); model.addAttribute("permissionTypeList", Permission.Type.valueListMap());
} }
return this.jumpPage("admin/permission/edit"); return this.jumpPage("admin/permission/edit");
} }
@GetMapping("/article/index") @GetMapping("/article/index")
public ModelAndView article_index(Model model,Long categoryId) { public ModelAndView article_index(Model model, Long categoryId) {
List<Category> categoryList = this.categoryFeign.findAll(); List<Category> categoryList = this.categoryFeign.findAll();
model.addAttribute("categoryList",categoryList); model.addAttribute("categoryList", categoryList);
model.addAttribute("categoryId",categoryId == null ? 0L : categoryId); model.addAttribute("categoryId", categoryId == null ? 0L : categoryId);
return this.jumpPage("admin/article/list"); return this.jumpPage("admin/article/list");
} }
@ -268,10 +277,10 @@ public class UrlRequestController extends BaseController {
} }
@GetMapping("/article/edit") @GetMapping("/article/edit")
public ModelAndView article_edit(Model model,String articleId) { public ModelAndView article_edit(Model model, String articleId) {
if (CommonUtil.isNotNull(articleId)){ if (CommonUtil.isNotNull(articleId)) {
Article article = this.articleFeign.findById(Long.parseLong(articleId)); Article article = this.articleFeign.findById(Long.parseLong(articleId));
model.addAttribute("article",article); model.addAttribute("article", article);
//查询分类 //查询分类
List<Category> categoryList = this.categoryFeign.findAll(); List<Category> categoryList = this.categoryFeign.findAll();
model.addAttribute("categoryList", categoryList); model.addAttribute("categoryList", categoryList);
@ -280,64 +289,64 @@ public class UrlRequestController extends BaseController {
} }
@GetMapping("/category/index") @GetMapping("/category/index")
public ModelAndView category_index(){ public ModelAndView category_index() {
return this.jumpPage("admin/category/list"); return this.jumpPage("admin/category/list");
} }
@GetMapping("/category/add") @GetMapping("/category/add")
public ModelAndView category_add(Model model){ public ModelAndView category_add(Model model) {
Category.Type[] values = Category.Type.values(); Category.Type[] values = Category.Type.values();
model.addAttribute("categoryTypeList",values); model.addAttribute("categoryTypeList", values);
return this.jumpPage("admin/category/add"); return this.jumpPage("admin/category/add");
} }
@GetMapping("/category/edit") @GetMapping("/category/edit")
public ModelAndView category_edit(Model model,String categoryId){ public ModelAndView category_edit(Model model, String categoryId) {
Category.Type[] values = Category.Type.values(); Category.Type[] values = Category.Type.values();
model.addAttribute("categoryTypeList",values); model.addAttribute("categoryTypeList", values);
Category category = null; Category category = null;
if (categoryId != null && !categoryId.equals("")){ if (categoryId != null && !categoryId.equals("")) {
category = this.categoryFeign.findById(Long.parseLong(categoryId)); category = this.categoryFeign.findById(Long.parseLong(categoryId));
} }
model.addAttribute("category",category); model.addAttribute("category", category);
return this.jumpPage("admin/category/edit"); return this.jumpPage("admin/category/edit");
} }
@GetMapping("/file/index") @GetMapping("/file/index")
public ModelAndView file_index(){ public ModelAndView file_index() {
return this.jumpPage("admin/file/list"); return this.jumpPage("admin/file/list");
} }
@GetMapping("/file/add") @GetMapping("/file/add")
public ModelAndView file_add(){ public ModelAndView file_add() {
return this.jumpPage("admin/file/add"); return this.jumpPage("admin/file/add");
} }
@GetMapping("/file/upload") @GetMapping("/file/upload")
public ModelAndView file_upload(){ public ModelAndView file_upload() {
return this.jumpPage("admin/file/upload"); return this.jumpPage("admin/file/upload");
} }
@GetMapping("/quartz/index") @GetMapping("/quartz/index")
public ModelAndView quartz_index(){ public ModelAndView quartz_index() {
return this.jumpPage("admin/job/job-list"); return this.jumpPage("admin/job/job-list");
} }
@GetMapping("/quartz/add") @GetMapping("/quartz/add")
public ModelAndView quartz_add(Model model){ public ModelAndView quartz_add(Model model) {
Set<String> names = this.quartzFeign.spring_bean_list(); Set<String> names = this.quartzFeign.spring_bean_list();
model.addAttribute("spring_bean_list",names); model.addAttribute("spring_bean_list", names);
return this.jumpPage("admin/job/job-add"); return this.jumpPage("admin/job/job-add");
} }
@GetMapping("/quartz/edit") @GetMapping("/quartz/edit")
public ModelAndView quartz_edit(Model model,String jobId){ public ModelAndView quartz_edit(Model model, String jobId) {
Set<String> names = this.quartzFeign.spring_bean_list(); Set<String> names = this.quartzFeign.spring_bean_list();
model.addAttribute("spring_bean_list",names); model.addAttribute("spring_bean_list", names);
if (CommonUtil.isNotNull(jobId)){ if (CommonUtil.isNotNull(jobId)) {
QuartzJob job = this.quartzFeign.findById(Long.parseLong(jobId)); QuartzJob job = this.quartzFeign.findById(Long.parseLong(jobId));
model.addAttribute("job",job); model.addAttribute("job", job);
} }
return this.jumpPage("admin/job/job-edit"); return this.jumpPage("admin/job/job-edit");
} }
@ -345,12 +354,12 @@ public class UrlRequestController extends BaseController {
@GetMapping("/crypt/encrypt") @GetMapping("/crypt/encrypt")
public ModelAndView index(Model model) { public ModelAndView index(Model model) {
EncryptType[] values = EncryptType.values(); EncryptType[] values = EncryptType.values();
model.addAttribute("encryptTypeList",values); model.addAttribute("encryptTypeList", values);
return this.jumpPage("admin/code/encrypt"); return this.jumpPage("admin/code/encrypt");
} }
@GetMapping("/admin/form/tools") @GetMapping("/admin/form/tools")
public ModelAndView form_gen(){ public ModelAndView form_gen() {
return this.jumpPage("admin/code/form"); return this.jumpPage("admin/code/form");
} }
@ -365,12 +374,12 @@ public class UrlRequestController extends BaseController {
} }
@GetMapping(SysConstant.mail_prefix + "/edit") @GetMapping(SysConstant.mail_prefix + "/edit")
public ModelAndView mail_edit(String mail_id,Model model) { public ModelAndView mail_edit(String mail_id, Model model) {
if (mail_id != null ){ if (mail_id != null) {
Mail mail = this.mailFeign.findById(Long.parseLong(mail_id)); Mail mail = this.mailFeign.findById(Long.parseLong(mail_id));
if (CommonUtil.isNotNull(mail)){ if (CommonUtil.isNotNull(mail)) {
model.addAttribute("mail",mail); model.addAttribute("mail", mail);
} }
} }
return this.jumpPage("admin/mail/edit"); return this.jumpPage("admin/mail/edit");
} }
@ -384,26 +393,26 @@ public class UrlRequestController extends BaseController {
public ModelAndView chapter(Model model, @PathVariable Long id) { public ModelAndView chapter(Model model, @PathVariable Long id) {
Fiction fiction = this.fictionFeign.findById(id); Fiction fiction = this.fictionFeign.findById(id);
model.addAttribute("fiction",fiction); model.addAttribute("fiction", fiction);
List<FictionChapter> fictionChapterList = this.fictionFeign.findByFictionId(id); List<FictionChapter> fictionChapterList = this.fictionFeign.findByFictionId(id);
model.addAttribute("fictionChapter",fictionChapterList.get(0)); model.addAttribute("fictionChapter", fictionChapterList.get(0));
model.addAttribute("fictionChapterList",fictionChapterList); model.addAttribute("fictionChapterList", fictionChapterList);
return this.jumpPage("xiaoshuo/fiction_chapter"); return this.jumpPage("xiaoshuo/fiction_chapter");
} }
@GetMapping(SysConstant.fiction_prefix + "/details/{chapter_id}") @GetMapping(SysConstant.fiction_prefix + "/details/{chapter_id}")
public ModelAndView details(Model model, @PathVariable String chapter_id){ public ModelAndView details(Model model, @PathVariable String chapter_id) {
String replace = chapter_id.replace(",", ""); String replace = chapter_id.replace(",", "");
Long id = Long.parseLong(replace); Long id = Long.parseLong(replace);
List<FictionDetails> fictionDetailsList = this.fictionFeign.fictionDetailsId(id); List<FictionDetails> fictionDetailsList = this.fictionFeign.fictionDetailsId(id);
if (fictionDetailsList.size() > 0){ if (fictionDetailsList.size() > 0) {
FictionDetails fictionDetails = fictionDetailsList.get(0); FictionDetails fictionDetails = fictionDetailsList.get(0);
String content = fictionDetails.getContent(); String content = fictionDetails.getContent();
content = "<br>&nbsp;&nbsp;&nbsp;&nbsp;" + content; content = "<br>&nbsp;&nbsp;&nbsp;&nbsp;" + content;
String replace1 = content.replace(" ", "<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;"); String replace1 = content.replace(" ", "<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;");
fictionDetails.setContent(replace1); fictionDetails.setContent(replace1);
model.addAttribute("fictionDetails",fictionDetails); model.addAttribute("fictionDetails", fictionDetails);
} }
return this.jumpPage("xiaoshuo/fiction_details"); return this.jumpPage("xiaoshuo/fiction_details");
} }
@ -439,9 +448,9 @@ public class UrlRequestController extends BaseController {
@GetMapping(SysConstant.fictionCollection_prefix + "/edit") @GetMapping(SysConstant.fictionCollection_prefix + "/edit")
public ModelAndView fictionCollection_edit(@RequestParam("fiction_id") Long fiction_id,Model model){ public ModelAndView fictionCollection_edit(@RequestParam("fiction_id") Long fiction_id, Model model) {
FictionCollection fictionCollection = this.fictionFeign.findFictionCollectionById(fiction_id); FictionCollection fictionCollection = this.fictionFeign.findFictionCollectionById(fiction_id);
model.addAttribute("fictionCollection",fictionCollection); model.addAttribute("fictionCollection", fictionCollection);
return this.jumpPage("admin/fiction/fiction_edit"); return this.jumpPage("admin/fiction/fiction_edit");
} }
@ -469,13 +478,13 @@ public class UrlRequestController extends BaseController {
@RequestMapping("/zipkin") @RequestMapping("/zipkin")
public RedirectView zipkin_loginPage() { public RedirectView zipkin_loginPage() {
String url = "http://localhost:9411/zipkin/"; String url = "http://localhost:9411/zipkin/";
return new RedirectView(url); return new RedirectView(url);
} }
@RequestMapping("/sentinel") @RequestMapping("/sentinel")
public RedirectView nacos_loginPage() { public RedirectView nacos_loginPage() {
String url = "http://localhost:8748/#/login"; String url = "http://localhost:8748/#/login";
return new RedirectView(url); return new RedirectView(url);
} }
@ -488,4 +497,25 @@ public class UrlRequestController extends BaseController {
String path = serviceInstance.getUri().toString(); String path = serviceInstance.getUri().toString();
return new RedirectView(path); return new RedirectView(path);
} }
/**
*
*
* @param model
* @param pageNum
* @param pageSize
* @return
*/
@GetMapping("/blog/index")
public ModelAndView index(Model model, Integer pageNum, Integer pageSize) {
if (pageNum == null) {
pageNum = CommonUtil.pageNum;
}
if (pageSize == null) {
pageSize = CommonUtil.pageSize;
}
Map<String, Object> map = this.articleFeign.getListByPage(pageNum, pageSize);
model.addAllAttributes(map);
return this.jumpPage("blog/v1/index");
}
} }

View File

@ -159,4 +159,10 @@ public class UserController extends BaseController implements UserControllerApi
public User findByUserName(String username) { public User findByUserName(String username) {
return this.userService.loadUserByUsername(username); return this.userService.loadUserByUsername(username);
} }
@Override
@GetMapping("findByUserId")
public User findByUserId(@RequestParam("userId") Long userId){
return this.userService.findById(userId);
}
} }

View File

@ -1,5 +1,7 @@
package com.zhangmeng.admin.manager.feign; package com.zhangmeng.admin.manager.feign;
import com.github.pagehelper.PageInfo;
import com.zhangmeng.model.dto.query.QueryParams;
import com.zhangmeng.model.dto.system.SysConstant; import com.zhangmeng.model.dto.system.SysConstant;
import com.zhangmeng.model.entity.Article; import com.zhangmeng.model.entity.Article;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
@ -8,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
import java.util.Map;
@FeignClient(value = SysConstant.mystyle_cloud_blog,contextId ="ArticleFeign") @FeignClient(value = SysConstant.mystyle_cloud_blog,contextId ="ArticleFeign")
public interface ArticleFeign { public interface ArticleFeign {
@ -23,4 +26,7 @@ public interface ArticleFeign {
@GetMapping("/article/findById") @GetMapping("/article/findById")
Article findById(@RequestParam(value = "articleId") Long articleId); Article findById(@RequestParam(value = "articleId") Long articleId);
@GetMapping("/article/getListByPage")
Map<String,Object> getListByPage(@RequestParam("pageNum") Integer pageNum,@RequestParam("pageSize") Integer pageSize);
} }

View File

@ -53,11 +53,9 @@ mapper:
enum-as-simple-type: true enum-as-simple-type: true
identity: MYSQL identity: MYSQL
check-example-entity-class: true check-example-entity-class: true
mystyle: mystyle:
security: security:
open-api: open-api:
- /
- /login - /login
- /favicon.ico # 开放FAVICON - /favicon.ico # 开放FAVICON
- /system/** - /system/**
@ -73,6 +71,8 @@ mystyle:
- /webjars/** - /webjars/**
- /actuator/** - /actuator/**
- /instances/** - /instances/**
- /blog/index
- /user/findByUserId
verification-code: verification-code:
type: mysql type: mysql
expiration-time: 300 expiration-time: 300

View File

@ -35,4 +35,7 @@ public interface UserControllerApi {
@ApiOperation("根据用户名称查询用户") @ApiOperation("根据用户名称查询用户")
public User findByUserName(String username); public User findByUserName(String username);
@ApiOperation("根据用户id查询用户")
public User findByUserId(@RequestParam("userId") Long userId);
} }

View File

@ -1,5 +1,7 @@
package com.zhangmeng.api.service.blog; package com.zhangmeng.api.service.blog;
import com.github.pagehelper.PageInfo;
import com.zhangmeng.model.dto.query.QueryParams;
import com.zhangmeng.model.entity.Article; import com.zhangmeng.model.entity.Article;
import com.zhangmeng.model.vo.Result; import com.zhangmeng.model.vo.Result;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -35,4 +37,7 @@ public interface ArticleControllerApi {
@ApiOperation("根据id查询") @ApiOperation("根据id查询")
public Article findById(@RequestParam Long articleId); public Article findById(@RequestParam Long articleId);
@ApiOperation("查询文章")
Map<String,Object> getListByPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize);
} }

View File

@ -7,6 +7,8 @@ import com.zhangmeng.blog.service.ArticleService;
import com.zhangmeng.blog.service.CategoryService; import com.zhangmeng.blog.service.CategoryService;
import com.zhangmeng.model.base.baseController.BaseController; import com.zhangmeng.model.base.baseController.BaseController;
import com.zhangmeng.model.base.baseUtil.CommonUtil; import com.zhangmeng.model.base.baseUtil.CommonUtil;
import com.zhangmeng.model.dto.article.ArticleDto;
import com.zhangmeng.model.dto.article.ArticleModel;
import com.zhangmeng.model.dto.query.QueryParams; import com.zhangmeng.model.dto.query.QueryParams;
import com.zhangmeng.model.entity.Article; import com.zhangmeng.model.entity.Article;
import com.zhangmeng.model.entity.Category; import com.zhangmeng.model.entity.Category;
@ -15,6 +17,7 @@ import com.zhangmeng.model.vo.Result;
import com.zhangmeng.model.vo.StatusCode; import com.zhangmeng.model.vo.StatusCode;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -24,9 +27,7 @@ import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.entity.Example;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.*;
import java.util.List;
import java.util.Map;
@RestController @RestController
@ -179,8 +180,40 @@ public class ArticleController extends BaseController implements ArticleControll
return this.articleService.findByCondition(new QueryParams(new Condition(Article.class))); return this.articleService.findByCondition(new QueryParams(new Condition(Article.class)));
} }
@Override
@GetMapping("/findById") @GetMapping("/findById")
public Article findById(@RequestParam Long articleId){ public Article findById(@RequestParam Long articleId){
return this.articleService.findById(articleId); return this.articleService.findById(articleId);
} }
@Override
@GetMapping("/getListByPage")
public Map<String,Object> getListByPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize){
Map<String,Object> map = new HashMap<>();
ArticleModel articleModel = new ArticleModel();
//文章总数
Condition article_condition = new Condition(Article.class);
Example.Criteria article_criteria = article_condition.createCriteria();
article_criteria.andEqualTo("deleteStatus", false);
//文章列表
PageInfo<Article> pageInfo = this.articleService.findByCondition(new QueryParams(pageNum, pageSize, article_condition, "addTime desc"), true);
articleModel.setPrePage(pageInfo.getPrePage());
articleModel.setNextPage(pageInfo.getNextPage());
articleModel.setPageNum(pageInfo.getPageNum());
articleModel.setPageSize(pageInfo.getPageSize());
List<ArticleDto> article_dto_list = new ArrayList<>();
if (pageInfo.getList().size() > 0) {
for (Article article : pageInfo.getList()) {
ArticleDto articleDto = new ArticleDto();
BeanUtils.copyProperties(article, articleDto);
Long user_id = article.getUser_id();
User user = this.userFeign.findByUserId(user_id);
articleDto.setAvatar(user.getAvatar());
article_dto_list.add(articleDto);
}
}
articleModel.setArticleDto_list(article_dto_list);
map.put("articleModel", articleModel);
return map;
}
} }

View File

@ -4,10 +4,14 @@ import com.zhangmeng.model.dto.system.SysConstant;
import com.zhangmeng.model.entity.User; import com.zhangmeng.model.entity.User;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(SysConstant.mystyle_cloud_admin_manager) @FeignClient(SysConstant.mystyle_cloud_admin_manager)
public interface UserFeign { public interface UserFeign {
@GetMapping("/user/current") @GetMapping("/user/current")
public User getCurrentUser(); public User getCurrentUser();
@GetMapping("/user/findByUserId")
public User findByUserId(@RequestParam("userId") Long userId);
} }

View File

@ -58,6 +58,7 @@ mystyle:
- /webjars/** - /webjars/**
- /actuator/** - /actuator/**
- /instances/** - /instances/**
- /article/getListByPage
management: management:
endpoints: endpoints:
web: web:
@ -69,5 +70,4 @@ management:
enabled: true enabled: true
logging: logging:
file: file:
name: ./logs/mystyle-cloud-blog.log name: ./logs/mystyle-cloud-blog.log
level: debug

View File

@ -0,0 +1,79 @@
package com.zhangmeng.gateway.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* @author
* @date 202191416:50:47
* @version 1.0
* */
@Configuration
@ConfigurationProperties("mystyle.security")
public class SecurityProperty {
/**
*
* */
private boolean superAuthOpen;
/**
*
* */
private String superAdmin;
/**
*
* */
private String rememberKey;
/**
*
* */
private String[] openApi;
/**
* 线
* */
private Integer maximum = 1;
public boolean isSuperAuthOpen() {
return superAuthOpen;
}
public void setSuperAuthOpen(boolean superAuthOpen) {
this.superAuthOpen = superAuthOpen;
}
public String getSuperAdmin() {
return superAdmin;
}
public void setSuperAdmin(String superAdmin) {
this.superAdmin = superAdmin;
}
public String getRememberKey() {
return rememberKey;
}
public void setRememberKey(String rememberKey) {
this.rememberKey = rememberKey;
}
public String[] getOpenApi() {
return openApi;
}
public void setOpenApi(String[] openApi) {
this.openApi = openApi;
}
public Integer getMaximum() {
return maximum;
}
public void setMaximum(Integer maximum) {
this.maximum = maximum;
}
}

View File

@ -4,9 +4,5 @@ package com.zhangmeng.gateway.feign;
* *
*/ */
public class SysConstant { public class SysConstant {
public static final String mystyle_cloud_admin_manager = "mystyle-cloud-admin-manager";
public static final String mystyle_cloud_oauth = "mystyle-cloud-oauth"; public static final String mystyle_cloud_oauth = "mystyle-cloud-oauth";
} }

View File

@ -1,5 +1,7 @@
package com.zhangmeng.gateway.filter; package com.zhangmeng.gateway.filter;
import com.zhangmeng.gateway.config.SecurityProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.filter.GatewayFilterChain; import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter; import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
@ -29,6 +31,9 @@ public class AuthorizeFilter implements GlobalFilter, Ordered {
private static final String AUTHORIZE_TOKEN = "Authorization"; private static final String AUTHORIZE_TOKEN = "Authorization";
@Autowired
private SecurityProperty securityProperty;
@Override @Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
@ -36,25 +41,15 @@ public class AuthorizeFilter implements GlobalFilter, Ordered {
ServerHttpRequest request = exchange.getRequest(); ServerHttpRequest request = exchange.getRequest();
//2.获取响应对象 //2.获取响应对象
ServerHttpResponse response = exchange.getResponse(); ServerHttpResponse response = exchange.getResponse();
//3.开发端口直接放行
//3.判断 是否为登录的URL 如果是 放行 String[] openApi = this.securityProperty.getOpenApi();
if (request.getURI().getPath().startsWith("/mystyle-cloud-oauth/user/login")) { if (openApi.length > 0 ){
return chain.filter(exchange); for (String url : openApi) {
if (request.getURI().getPath().startsWith(url)){
return chain.filter(exchange);
}
}
} }
if (request.getURI().getPath().startsWith("/mystyle-cloud-admin-manager/login")) {
return chain.filter(exchange);
}
if (request.getURI().getPath().startsWith("/mystyle-cloud-admin-manager/system")) {
return chain.filter(exchange);
}
//mystyle-cloud-admin-manager/verificationCode/generate 验证码
if (request.getURI().getPath().startsWith("/mystyle-cloud-admin-manager/verificationCode/generate")) {
return chain.filter(exchange);
}
//4.判断 是否为登录的URL 如果不是 权限校验 //4.判断 是否为登录的URL 如果不是 权限校验
//4.1 从头header中获取令牌数据 //4.1 从头header中获取令牌数据
String token = request.getHeaders().getFirst(AUTHORIZE_TOKEN); String token = request.getHeaders().getFirst(AUTHORIZE_TOKEN);
@ -97,10 +92,11 @@ public class AuthorizeFilter implements GlobalFilter, Ordered {
/** /**
* *
*
* @param serverHttpRequest * @param serverHttpRequest
* @return * @return
*/ */
private String resolveBodyFromRequest(ServerHttpRequest serverHttpRequest){ private String resolveBodyFromRequest(ServerHttpRequest serverHttpRequest) {
//获取请求体 //获取请求体
Flux<DataBuffer> body = serverHttpRequest.getBody(); Flux<DataBuffer> body = serverHttpRequest.getBody();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

View File

@ -84,6 +84,12 @@ spring:
- Path=/mystyle-cloud-admin-monitor/** - Path=/mystyle-cloud-admin-monitor/**
filters: filters:
- StripPrefix=1 - StripPrefix=1
- id: mystyle-cloud-blog-web
uri: lb://mystyle-cloud-admin-manager
predicates:
- Path=/mystyle-cloud-web-blog/**
filters:
- StripPrefix=1
management: management:
endpoints: endpoints:
web: web:
@ -95,4 +101,14 @@ management:
enabled: true enabled: true
logging: logging:
file: file:
name: ./logs/mystyle-cloud-gateway.log name: ./logs/mystyle-cloud-gateway.log
#开放接口
mystyle:
security:
open-api:
- /mystyle-cloud-admin-manager/verificationCode/generate
- /mystyle-cloud-admin-manager/system
- /mystyle-cloud-admin-manager/login
- /mystyle-cloud-oauth/user/login
- /mystyle-cloud-web-blog/blog/index

View File

@ -97,9 +97,9 @@ public class CommonUtil {
private static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; private static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
private static Integer pageNum = 1; public static Integer pageNum = 1;
private static Integer pageSize = 10; public static Integer pageSize = 10;
private static String[] parsePatterns = { private static String[] parsePatterns = {
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM", "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",

View File

@ -0,0 +1,16 @@
package com.zhangmeng.model.dto.article;
import com.zhangmeng.model.entity.Article;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
@EqualsAndHashCode(callSuper = true)
@Data
public class ArticleDto extends Article implements Serializable {
private String avatar;
private String username;
}

View File

@ -0,0 +1,41 @@
package com.zhangmeng.model.dto.article;
import com.zhangmeng.model.dto.comment.CommentModel;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
public class ArticleModel implements Serializable {
private Integer count;
private List<ArticleDto> articleDto_list;
private List<ArticleDto> latest_article_list;//最新推荐
private String blog_title;
//当前页
private int pageNum;
//每页的数量
private int pageSize;
//前一页
private int prePage;
//下一页
private int nextPage;
private String message;
private String QQ;
private String email;
private ArticleDto details;
List<CommentModel> commentModelList;//评论
}

View File

@ -0,0 +1,19 @@
package com.zhangmeng.model.dto.comment;
import com.zhangmeng.model.entity.Comment;
import com.zhangmeng.model.entity.Reply;
import com.zhangmeng.model.entity.User;
import lombok.Data;
import java.io.Serializable;
@Data
public class CommentModel implements Serializable {
private Comment comment;
private Reply reply;
private User reply_user;//回复的博主信息
}