From 6e83d1e5b6b348bc9804753db5bb3070143cdd5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A6=81=E6=87=82=E5=BE=97=E8=88=8D=E5=BE=97?= Date: Sat, 11 Apr 2020 23:59:44 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=9A=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=B8=8E=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7=E6=97=B6=E5=A4=B4?= =?UTF-8?q?=E5=83=8F=E5=9B=9E=E6=98=BE=E4=B8=8E=E5=AE=9E=E6=97=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../blog/controller/RestUserController.java | 118 ++++- .../main/resources/templates/user/list.ftl | 464 +++++++++++------- 2 files changed, 378 insertions(+), 204 deletions(-) diff --git a/blog-admin/src/main/java/com/zyd/blog/controller/RestUserController.java b/blog-admin/src/main/java/com/zyd/blog/controller/RestUserController.java index 75587fb..578d2d9 100644 --- a/blog-admin/src/main/java/com/zyd/blog/controller/RestUserController.java +++ b/blog-admin/src/main/java/com/zyd/blog/controller/RestUserController.java @@ -3,12 +3,16 @@ package com.zyd.blog.controller; import com.github.pagehelper.PageInfo; import com.zyd.blog.business.annotation.BussinessLog; import com.zyd.blog.business.entity.User; +import com.zyd.blog.business.enums.FileUploadType; import com.zyd.blog.business.enums.ResponseStatus; import com.zyd.blog.business.service.SysUserRoleService; import com.zyd.blog.business.service.SysUserService; import com.zyd.blog.business.vo.UserConditionVO; +import com.zyd.blog.file.FileUploader; +import com.zyd.blog.file.entity.VirtualFile; import com.zyd.blog.framework.object.PageResult; import com.zyd.blog.framework.object.ResponseVO; +import com.zyd.blog.plugin.file.GlobalFileUploader; import com.zyd.blog.util.PasswordUtil; import com.zyd.blog.util.ResultUtil; import org.apache.shiro.authz.annotation.Logical; @@ -19,6 +23,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; /** * 用户管理 @@ -48,16 +53,16 @@ public class RestUserController { * 保存用户角色 * * @param userId - * @param roleIds - * 用户角色 - * 此处获取的参数的角色id是以 “,” 分隔的字符串 + * @param roleIds 用户角色 + * 此处获取的参数的角色id是以 “,” 分隔的字符串 * @return */ @RequiresPermissions("user:allotRole") @PostMapping("/saveUserRoles") @BussinessLog("分配用户角色") public ResponseVO saveUserRoles(Long userId, String roleIds) { - if (StringUtils.isEmpty(userId)) { + if (StringUtils.isEmpty(userId)) + { return ResultUtil.error("error"); } userRoleService.addUserRole(userId, roleIds); @@ -69,33 +74,112 @@ public class RestUserController { @BussinessLog("添加用户") public ResponseVO add(User user) { User u = userService.getByUserName(user.getUsername()); - if (u != null) { - return ResultUtil.error("该用户名["+user.getUsername()+"]已存在!请更改用户名"); + if (u != null) + { + return ResultUtil.error("该用户名[" + user.getUsername() + "]已存在!请更改用户名"); } - try { - user.setPassword(PasswordUtil.encrypt(user.getPassword(), user.getUsername())); + try + { + String password = user.getPassword(); + if (StringUtils.isEmpty(password)) + { + return ResultUtil.error("error"); + } + user.setPassword(PasswordUtil.encrypt(password, user.getUsername())); userService.insert(user); return ResultUtil.success("成功"); - } catch (Exception e) { + } + catch (Exception e) + { e.printStackTrace(); return ResultUtil.error("error"); } } + @RequiresPermissions("user:edit") + @PostMapping("/edit") + @BussinessLog("编辑用户") + public ResponseVO edit(User user) { + try + { + encryptPassword(user); + userService.updateSelective(user); + } + catch (Exception e) + { + e.printStackTrace(); + return ResultUtil.error("用户修改失败!"); + } + return ResultUtil.success(ResponseStatus.SUCCESS); + } + + @RequiresPermissions("user:edit") + @PostMapping("/addorupdate") + @BussinessLog("编辑用户") + public ResponseVO addOrUpdate(User user, MultipartFile file) { + VirtualFile virtualFile = this.saveFile(file); + try + { + if (virtualFile != null) + { + user.setAvatar(virtualFile.getFullFilePath()); + } + encryptPassword(user); + if (user.getId() != null) + { + userService.updateSelective(user); + } + else + { + userService.insert(user); + } + } + catch (Exception e) + { + e.printStackTrace(); + return ResultUtil.error("用户修改失败!"); + } + return ResultUtil.success(ResponseStatus.SUCCESS); + } + + private void encryptPassword(User user) throws Exception { + String password = user.getPassword(); + if (StringUtils.isEmpty(password)) + { + user.setPassword(null); + } + else + { + user.setPassword(PasswordUtil.encrypt(password, user.getUsername())); + } + } + + public VirtualFile saveFile(MultipartFile file) { + if (file != null) + { + FileUploader uploader = new GlobalFileUploader(); + return uploader.upload(file, FileUploadType.QRCODE.getPath(), true); + } + return null; + } + @RequiresPermissions(value = {"user:batchDelete", "user:delete"}, logical = Logical.OR) @PostMapping(value = "/remove") @BussinessLog("删除用户") public ResponseVO remove(Long[] ids) { - if (null == ids) { + if (null == ids) + { return ResultUtil.error(500, "请至少选择一条记录"); } - for (Long id : ids) { + for (Long id : ids) + { userService.removeByPrimaryKey(id); userRoleService.removeByUserId(id); } return ResultUtil.success("成功删除 [" + ids.length + "] 个用户"); } + @RequiresPermissions("user:get") @PostMapping("/get/{id}") @BussinessLog("获取用户详情") @@ -103,17 +187,5 @@ public class RestUserController { return ResultUtil.success(null, this.userService.getByPrimaryKey(id)); } - @RequiresPermissions("user:edit") - @PostMapping("/edit") - @BussinessLog("编辑用户") - public ResponseVO edit(User user) { - try { - userService.updateSelective(user); - } catch (Exception e) { - e.printStackTrace(); - return ResultUtil.error("用户修改失败!"); - } - return ResultUtil.success(ResponseStatus.SUCCESS); - } } diff --git a/blog-admin/src/main/resources/templates/user/list.ftl b/blog-admin/src/main/resources/templates/user/list.ftl index f4a7b6b..3752429 100644 --- a/blog-admin/src/main/resources/templates/user/list.ftl +++ b/blog-admin/src/main/resources/templates/user/list.ftl @@ -14,9 +14,7 @@
-<@addOrUpdateMOdal defaultTitle="添加用户"> - -
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- + + + + + + <@footer> - + + }); + + \ No newline at end of file -- Gitee From 0dcee70d00f6eacf43ffb386af83e0573f5ec7f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A6=81=E6=87=82=E5=BE=97=E8=88=8D=E5=BE=97?= Date: Sun, 12 Apr 2020 00:48:16 +0800 Subject: [PATCH 2/9] =?UTF-8?q?PR=E7=9C=8B=E8=BF=99=E4=B8=AAlist.ftl?= =?UTF-8?q?=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list_ftl.md | 316 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 316 insertions(+) create mode 100644 list_ftl.md diff --git a/list_ftl.md b/list_ftl.md new file mode 100644 index 0000000..fe37159 --- /dev/null +++ b/list_ftl.md @@ -0,0 +1,316 @@ +```ftl +<#include "/include/macros.ftl"> +<@header> +
+
+
+ <@breadcrumb> + + +
+
+
+ + +
+
+
+
+
+
+ + + +<@addOrUpdateMOdal defaultTitle="添加用户"> + +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ + +<@footer> + + + + +``` \ No newline at end of file -- Gitee From db39df360ed31eb3cf7ca04b73d0087b1197fb33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A6=81=E6=87=82=E5=BE=97=E8=88=8D=E5=BE=97?= Date: Sun, 12 Apr 2020 12:48:58 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20list?= =?UTF-8?q?=5Fftl.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list_ftl.md | 316 ---------------------------------------------------- 1 file changed, 316 deletions(-) delete mode 100644 list_ftl.md diff --git a/list_ftl.md b/list_ftl.md deleted file mode 100644 index fe37159..0000000 --- a/list_ftl.md +++ /dev/null @@ -1,316 +0,0 @@ -```ftl -<#include "/include/macros.ftl"> -<@header> -
-
-
- <@breadcrumb> - - -
-
-
- - -
-
-
-
-
-
- - - -<@addOrUpdateMOdal defaultTitle="添加用户"> - -
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
- - -<@footer> - - - - -``` \ No newline at end of file -- Gitee From 825e52f6e6d0cb1ce07089fe0103528b4697cfab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A6=81=E6=87=82=E5=BE=97=E8=88=8D=E5=BE=97?= Date: Sun, 12 Apr 2020 12:54:11 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=8E=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=97=B6=E5=A4=B4=E5=83=8F=E5=9B=9E=E6=98=BE=E4=B8=8E=E5=AE=9E?= =?UTF-8?q?=E6=97=B6=E6=9B=B4=E6=96=B0=EF=BC=8C=E5=8F=A6=E5=A4=96=E5=AF=B9?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=B5=84=E6=BA=90=E7=AE=A1=E7=90=86=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E4=BC=98=E5=8C=96=E3=80=82=E4=BF=AE=E5=A4=8Dbtn?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=B8=8D=E5=AF=B9=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/templates/user/list.ftl | 411 +++++++++--------- list2.ftl | 314 +++++++++++++ 2 files changed, 520 insertions(+), 205 deletions(-) create mode 100644 list2.ftl diff --git a/blog-admin/src/main/resources/templates/user/list.ftl b/blog-admin/src/main/resources/templates/user/list.ftl index 3752429..07c725c 100644 --- a/blog-admin/src/main/resources/templates/user/list.ftl +++ b/blog-admin/src/main/resources/templates/user/list.ftl @@ -14,7 +14,8 @@
+
@@ -125,229 +126,229 @@ <@footer> - + }); + \ No newline at end of file diff --git a/list2.ftl b/list2.ftl new file mode 100644 index 0000000..cdb1a12 --- /dev/null +++ b/list2.ftl @@ -0,0 +1,314 @@ +<#include "/include/macros.ftl"> +<@header> +
+
+
+ <@breadcrumb> + + +
+
+
+ + +
+
+
+
+
+
+ + + +<@addOrUpdateMOdal defaultTitle="添加用户"> + +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ + +<@footer> + + + + \ No newline at end of file -- Gitee From f1fcf5a5fd59c069a02d9453e9147a46faa676d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A6=81=E6=87=82=E5=BE=97=E8=88=8D=E5=BE=97?= Date: Sun, 12 Apr 2020 12:54:58 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20list?= =?UTF-8?q?2.ftl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list2.ftl | 314 ------------------------------------------------------ 1 file changed, 314 deletions(-) delete mode 100644 list2.ftl diff --git a/list2.ftl b/list2.ftl deleted file mode 100644 index cdb1a12..0000000 --- a/list2.ftl +++ /dev/null @@ -1,314 +0,0 @@ -<#include "/include/macros.ftl"> -<@header> -
-
-
- <@breadcrumb> - - -
-
-
- - -
-
-
-
-
-
- - - -<@addOrUpdateMOdal defaultTitle="添加用户"> - -
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
- - -<@footer> - - - - \ No newline at end of file -- Gitee From 9a3672de916ce6c468d37a1015fa84dfc455081b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A6=81=E6=87=82=E5=BE=97=E8=88=8D=E5=BE=97?= Date: Sun, 12 Apr 2020 13:12:46 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=8E=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=97=B6=E5=A4=B4=E5=83=8F=E5=9B=9E=E6=98=BE=E4=B8=8E=E5=AE=9E?= =?UTF-8?q?=E6=97=B6=E6=9B=B4=E6=96=B0=EF=BC=8C=E5=8F=A6=E5=A4=96=E5=AF=B9?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=B5=84=E6=BA=90=E7=AE=A1=E7=90=86=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E4=BC=98=E5=8C=96=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/templates/user/list2.ftl | 289 ++++++++++++++++++ 1 file changed, 289 insertions(+) create mode 100644 blog-admin/src/main/resources/templates/user/list2.ftl diff --git a/blog-admin/src/main/resources/templates/user/list2.ftl b/blog-admin/src/main/resources/templates/user/list2.ftl new file mode 100644 index 0000000..4f53537 --- /dev/null +++ b/blog-admin/src/main/resources/templates/user/list2.ftl @@ -0,0 +1,289 @@ +<#include "/include/macros.ftl"> +<@header> +
+
+
+ <@breadcrumb> + + +
+
+
+ + +
+
+
+
+
+
+ + + +<@addOrUpdateMOdal defaultTitle="添加用户"> + +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ + +<@footer> + + + + \ No newline at end of file -- Gitee From 2c22fbda85fd1ae164ce22fad0961de95138c097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A6=81=E6=87=82=E5=BE=97=E8=88=8D=E5=BE=97?= Date: Sun, 12 Apr 2020 13:17:13 +0800 Subject: [PATCH 7/9] =?UTF-8?q?update=20blog-admin/src/main/resources/temp?= =?UTF-8?q?lates/user/list.ftl.=20=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=8E=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=97=B6=E5=A4=B4=E5=83=8F=E5=9B=9E=E6=98=BE=E4=B8=8E=E5=AE=9E?= =?UTF-8?q?=E6=97=B6=E6=9B=B4=E6=96=B0=EF=BC=8C=E5=8F=A6=E5=A4=96=E5=AF=B9?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=B5=84=E6=BA=90=E7=AE=A1=E7=90=86=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E4=BC=98=E5=8C=96=E3=80=82=E5=88=A0=E9=99=A4=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog-admin/src/main/resources/templates/user/list.ftl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/blog-admin/src/main/resources/templates/user/list.ftl b/blog-admin/src/main/resources/templates/user/list.ftl index 07c725c..bd8ce59 100644 --- a/blog-admin/src/main/resources/templates/user/list.ftl +++ b/blog-admin/src/main/resources/templates/user/list.ftl @@ -183,8 +183,7 @@ $("#addOrUpdateForm #avatarPreview").html(""); }); - $(".addOrUpdateBtn").click(function () { - console.log("========================================") + $(".addOrUpdateBtn").click(function () { var $form = $("#addOrUpdateForm"); var $modal = $("#modal-container-user"); if (validator.checkAll($form)) { -- Gitee From d53201a05c4a29b2c170d5d087031b27eb588136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A6=81=E6=87=82=E5=BE=97=E8=88=8D=E5=BE=97?= Date: Mon, 13 Apr 2020 14:45:14 +0800 Subject: [PATCH 8/9] =?UTF-8?q?1.=20=E6=94=B9=E8=BF=9B=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=99=A8=E7=9A=84=E9=80=89=E6=8B=A9=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=EF=BC=8C=E7=9B=B4=E6=8E=A5=E5=8F=AF=E4=BB=A5=E5=9C=A8?= =?UTF-8?q?=E8=BF=9B=E5=85=A5=E7=BC=96=E8=BE=91=E7=8A=B6=E6=80=81=E5=89=8D?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E7=BC=96=E8=BE=91=E5=99=A8=EF=BC=9B=202.=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E7=AB=A0=E5=88=97=E8=A1=A8=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E3=80=81=E6=8E=A8=E8=8D=90=E3=80=81=E7=BD=AE=E9=A1=B6?= =?UTF-8?q?=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?article:list=E6=9D=83=E9=99=90=EF=BC=88=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E6=89=80=E6=9C=89=E6=96=87=E7=AB=A0=E5=88=97=E8=A1=A8=EF=BC=8C?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E6=AD=A4=E6=9D=83=E9=99=90=E6=97=B6=E5=8F=AA?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E8=87=AA=E5=B7=B1=E7=9A=84=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E5=88=97=E8=A1=A8=EF=BC=89=EF=BC=8C=E7=94=A8=E4=BA=8E=E6=9B=B4?= =?UTF-8?q?=E5=A5=BD=E7=9A=84=E6=8E=A7=E5=88=B6=E6=96=87=E7=AB=A0=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=EF=BC=88=EF=BC=89=EF=BC=9B=203.=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=9C=A8=E6=96=87=E7=AB=A0=E6=A0=87=E7=AD=BE=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=B8=8E=E4=BF=AE=E6=94=B9=E6=97=B6=E7=9A=84=E5=88=A4=E7=A9=BA?= =?UTF-8?q?=E5=88=A4=E6=96=AD=EF=BC=9B=204.=20=E6=B7=BB=E5=8A=A0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=88=A0=E9=99=A4=E6=9D=83=E9=99=90=EF=BC=8C=E7=BB=86?= =?UTF-8?q?=E5=8C=96=E5=90=8E=E7=AB=AF=E6=96=87=E4=BB=B6=E6=9D=83=E9=99=90?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/RestArticleController.java | 20 +- .../blog/controller/RestFileController.java | 6 +- .../blog/controller/RestTagController.java | 17 +- .../main/resources/templates/article/list.ftl | 491 ++++++++++-------- .../main/resources/templates/file/list.ftl | 6 +- .../blog/business/consts/PermissionConst.java | 13 + .../resources/mybatis/BizArticleMapper.xml | 3 + 7 files changed, 336 insertions(+), 220 deletions(-) create mode 100644 blog-core/src/main/java/com/zyd/blog/business/consts/PermissionConst.java diff --git a/blog-admin/src/main/java/com/zyd/blog/controller/RestArticleController.java b/blog-admin/src/main/java/com/zyd/blog/controller/RestArticleController.java index 9cdc1a5..78d0ccb 100644 --- a/blog-admin/src/main/java/com/zyd/blog/controller/RestArticleController.java +++ b/blog-admin/src/main/java/com/zyd/blog/controller/RestArticleController.java @@ -3,12 +3,17 @@ package com.zyd.blog.controller; import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.PageInfo; import com.zyd.blog.business.annotation.BussinessLog; +import com.zyd.blog.business.consts.SessionConst; import com.zyd.blog.business.entity.Article; +import com.zyd.blog.business.entity.Resources; +import com.zyd.blog.business.entity.User; import com.zyd.blog.business.enums.BaiduPushTypeEnum; import com.zyd.blog.business.enums.ConfigKeyEnum; import com.zyd.blog.business.enums.ResponseStatus; +import com.zyd.blog.business.enums.UserTypeEnum; import com.zyd.blog.business.service.BizArticleService; import com.zyd.blog.business.service.SysConfigService; +import com.zyd.blog.business.service.SysResourcesService; import com.zyd.blog.business.util.BaiduPushUtil; import com.zyd.blog.business.vo.ArticleConditionVO; import com.zyd.blog.framework.object.PageResult; @@ -25,8 +30,12 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpSession; +import java.util.List; import java.util.Map; +import static com.zyd.blog.business.consts.PermissionConst.ARTICLE_LIST_PERMISSION; + /** * 文章管理 * @@ -44,10 +53,19 @@ public class RestArticleController { private BizArticleService articleService; @Autowired private SysConfigService configService; + @Autowired + private SysResourcesService resourcesService; @RequiresPermissions("articles") @PostMapping("/list") - public PageResult list(ArticleConditionVO vo) { + public PageResult list(ArticleConditionVO vo, HttpSession session) { + User user = (User) session.getAttribute(SessionConst.USER_SESSION_KEY); + List resourcesList = resourcesService.listByUserId(user.getId()); + boolean matchPermission = resourcesList.stream().anyMatch(resources -> ARTICLE_LIST_PERMISSION.equals(resources.getPermission())); + if (!matchPermission) + { + vo.setUserId(user.getId()); + } PageInfo
pageInfo = articleService.findPageBreakByCondition(vo); return ResultUtil.tablePage(pageInfo); } diff --git a/blog-admin/src/main/java/com/zyd/blog/controller/RestFileController.java b/blog-admin/src/main/java/com/zyd/blog/controller/RestFileController.java index 2fa9ff3..28b1535 100644 --- a/blog-admin/src/main/java/com/zyd/blog/controller/RestFileController.java +++ b/blog-admin/src/main/java/com/zyd/blog/controller/RestFileController.java @@ -35,7 +35,7 @@ public class RestFileController { return fileService.findPageBreakByCondition(vo); } - @RequiresPermissions("files") + @RequiresPermissions("file:delete") @PostMapping(value = "/remove") @BussinessLog("删除文件,ids:{1}") public ResponseVO remove(Long[] ids) { @@ -47,7 +47,7 @@ public class RestFileController { return ResultUtil.success("成功删除 [" + ids.length + "] 张图片"); } - @RequiresPermissions("files") + @RequiresPermissions("files:add") @PostMapping(value = "/add") @BussinessLog("添加文件") public ResponseVO add(MultipartFile[] file) { @@ -57,4 +57,4 @@ public class RestFileController { int res = fileService.upload(file); return ResultUtil.success("成功上传" + res + "张图片"); } -} +} \ No newline at end of file diff --git a/blog-admin/src/main/java/com/zyd/blog/controller/RestTagController.java b/blog-admin/src/main/java/com/zyd/blog/controller/RestTagController.java index 7a25bf3..1ab0edd 100644 --- a/blog-admin/src/main/java/com/zyd/blog/controller/RestTagController.java +++ b/blog-admin/src/main/java/com/zyd/blog/controller/RestTagController.java @@ -12,6 +12,7 @@ import com.zyd.blog.util.ResultUtil; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -43,8 +44,12 @@ public class RestTagController { @PostMapping(value = "/add") @BussinessLog("添加标签") public ResponseVO add(Tags tags) { - tags = tagsService.insert(tags); - return ResultUtil.success("标签添加成功!新标签 - " + tags.getName(), tags); + if (!StringUtils.isEmpty(tags)) + { + tags = tagsService.insert(tags); + return ResultUtil.success("标签添加成功!新标签 - " + tags.getName(), tags); + } + return ResultUtil.error(500, "标签不能为空!"); } @RequiresPermissions(value = {"tag:batchDelete", "tag:delete"}, logical = Logical.OR) @@ -72,12 +77,16 @@ public class RestTagController { @BussinessLog("编辑标签") public ResponseVO edit(Tags tags) { try { - tagsService.updateSelective(tags); + if (!StringUtils.isEmpty(tags)) + { + tagsService.updateSelective(tags); + return ResultUtil.success(ResponseStatus.SUCCESS); + } } catch (Exception e) { e.printStackTrace(); return ResultUtil.error("标签修改失败!"); } - return ResultUtil.success(ResponseStatus.SUCCESS); + return ResultUtil.error("标签修改失败!"); } @PostMapping("/listAll") diff --git a/blog-admin/src/main/resources/templates/article/list.ftl b/blog-admin/src/main/resources/templates/article/list.ftl index e843a31..9d2e633 100644 --- a/blog-admin/src/main/resources/templates/article/list.ftl +++ b/blog-admin/src/main/resources/templates/article/list.ftl @@ -15,7 +15,7 @@
@@ -43,234 +49,299 @@
<@footer> - + /** + * 推送到百度 + */ + table.bindClickEvent('.btn-push', function () { + var $this = $(this); + var userId = $this.attr("data-id"); + push(userId); + }); + + /** + * 批量推送到百度 + */ + $("#btn_push_ids").click(function () { + var selectedId = table.getSelectedIds(); + if (!selectedId || selectedId == '[]' || selectedId.length == 0) { + $.alert.error("请至少选择一条记录"); + return; + } + push(selectedId); + }); + + /** + * 批量修改状态 + */ + $("#btn_update_status").click(function () { + var selectedId = table.getSelectedIds(); + if (!selectedId || selectedId == '[]' || selectedId.length == 0) { + $.alert.error("请至少选择一条记录"); + return; + } + $.alert.confirm("确定批量发布?发布完成后用户可见", function () { + $.ajax({ + type: "post", + url: "/article/batchPublish", + traditional: true, + data: {'ids': selectedId}, + success: function (json) { + $.alert.ajaxSuccess(json); + table.refresh(); + }, + error: $.alert.ajaxError + }); + }, function () { + + }, 5000); + }); + + function push(ids) { + $.alert.confirm("确定推送到百度站长平台?", function () { + $.ajax({ + type: "post", + url: "/article/pushToBaidu/urls", + traditional: true, + data: {'ids': ids}, + success: function (json) { + $.alert.ajaxSuccess(json); + if (json.status == 200) { + var dataJson = JSON.parse(json.data); + /** + * success int 成功推送的url条数 + * remain int 当天剩余的可推送url条数 + * not_same_site array 由于不是本站url而未处理的url列表 + * not_valid array 不合法的url列表 + */ + var successNum = dataJson.success; + var remain = dataJson.remain; + var notSameSite = dataJson.not_same_site; + var notValid = dataJson.not_valid; + var message = '成功推送' + successNum + '条url\n'; + if (notValid) { + message += '不合法的url:' + notValid + '\n'; + } + message += '今日剩余' + remain + '条可推送的url。'; + $.alert.info(message, null, 5000); + } + }, + error: $.alert.ajaxError + }); + }, function () { + + }, 5000); + } + }); + \ No newline at end of file diff --git a/blog-admin/src/main/resources/templates/file/list.ftl b/blog-admin/src/main/resources/templates/file/list.ftl index 50c0951..afe3fda 100644 --- a/blog-admin/src/main/resources/templates/file/list.ftl +++ b/blog-admin/src/main/resources/templates/file/list.ftl @@ -12,12 +12,12 @@
\n' + '
\n' + diff --git a/blog-core/src/main/java/com/zyd/blog/business/consts/PermissionConst.java b/blog-core/src/main/java/com/zyd/blog/business/consts/PermissionConst.java new file mode 100644 index 0000000..8922106 --- /dev/null +++ b/blog-core/src/main/java/com/zyd/blog/business/consts/PermissionConst.java @@ -0,0 +1,13 @@ +package com.zyd.blog.business.consts; + +/** + * 权限控制常量 + * @author zyw + * @version V1.0 Created by 2020/4/13 13:02 + */ +public class PermissionConst { + /** + * 文章列表权限:展示所有文章列表,没有此权限时只显示自己的文章列表 + */ + public static final String ARTICLE_LIST_PERMISSION = "article:list"; +} \ No newline at end of file diff --git a/blog-core/src/main/resources/mybatis/BizArticleMapper.xml b/blog-core/src/main/resources/mybatis/BizArticleMapper.xml index d4172af..6b4f357 100644 --- a/blog-core/src/main/resources/mybatis/BizArticleMapper.xml +++ b/blog-core/src/main/resources/mybatis/BizArticleMapper.xml @@ -63,6 +63,9 @@ INNER JOIN biz_type btype ON a.type_id = btype.id INNER JOIN biz_article_tags atag ON a.id = atag.article_id WHERE 1 = 1 + + AND a.user_id = #{userId} + AND a.type_id = #{typeId} -- Gitee From 4457c33ffc0910674e0d3f23c96197c01b4c13cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A6=81=E6=87=82=E5=BE=97=E8=88=8D=E5=BE=97?= Date: Mon, 13 Apr 2020 15:18:25 +0800 Subject: [PATCH 9/9] =?UTF-8?q?1.=20=E6=94=B9=E8=BF=9B=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=99=A8=E7=9A=84=E9=80=89=E6=8B=A9=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=EF=BC=8C=E7=9B=B4=E6=8E=A5=E5=8F=AF=E4=BB=A5=E5=9C=A8?= =?UTF-8?q?=E8=BF=9B=E5=85=A5=E7=BC=96=E8=BE=91=E7=8A=B6=E6=80=81=E5=89=8D?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E7=BC=96=E8=BE=91=E5=99=A8=EF=BC=9B=202.=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E7=AB=A0=E5=88=97=E8=A1=A8=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E3=80=81=E6=8E=A8=E8=8D=90=E3=80=81=E7=BD=AE=E9=A1=B6?= =?UTF-8?q?=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?article:list=E6=9D=83=E9=99=90=EF=BC=88=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E6=89=80=E6=9C=89=E6=96=87=E7=AB=A0=E5=88=97=E8=A1=A8=EF=BC=8C?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E6=AD=A4=E6=9D=83=E9=99=90=E6=97=B6=E5=8F=AA?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E8=87=AA=E5=B7=B1=E7=9A=84=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E5=88=97=E8=A1=A8=EF=BC=89=EF=BC=8C=E7=94=A8=E4=BA=8E=E6=9B=B4?= =?UTF-8?q?=E5=A5=BD=E7=9A=84=E6=8E=A7=E5=88=B6=E6=96=87=E7=AB=A0=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=EF=BC=88=EF=BC=89=EF=BC=9B=203.=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=9C=A8=E6=96=87=E7=AB=A0=E6=A0=87=E7=AD=BE=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=B8=8E=E4=BF=AE=E6=94=B9=E6=97=B6=E7=9A=84=E5=88=A4=E7=A9=BA?= =?UTF-8?q?=E5=88=A4=E6=96=AD=EF=BC=9B=204.=20=E6=B7=BB=E5=8A=A0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=88=A0=E9=99=A4=E6=9D=83=E9=99=90=EF=BC=8C=E7=BB=86?= =?UTF-8?q?=E5=8C=96=E5=90=8E=E7=AB=AF=E6=96=87=E4=BB=B6=E6=9D=83=E9=99=90?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog-admin/sysResourcesSql.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 blog-admin/sysResourcesSql.md diff --git a/blog-admin/sysResourcesSql.md b/blog-admin/sysResourcesSql.md new file mode 100644 index 0000000..24733ef --- /dev/null +++ b/blog-admin/sysResourcesSql.md @@ -0,0 +1,13 @@ +### sys_resources + +| id | role_id | resources_id | +| --- | --- | --- | +| 566 | 1 | 80 | +| 567 | 1 | 77 | +### sys_role_resources + +| id | name | type | url | permission | parent_id | sort | external| available | icon| +| --- | ------------ | ------ | --- | ------------ | --------- | ---- | --------- | --------- | --------- | +| 77 | 删除文件 | button | \N | file:delete | 75 | 3 | 0 | 1 | \N | +| 80 | 浏览文章列表 | button | \N | article:list | 21 | 10 | 0 | 1 | fa fa-bars| + -- Gitee