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 9cdc1a5d4cf9a2a0f715fead4a5c728b7532e5b5..78d0ccba951616d7404cc398fbe0faca00bdc093 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 2fa9ff37116bfddecea9060b51962b415d1e5a4d..28b1535cab07f7a8fc2f10d6deeebc98fda3f7b9 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 7a25bf3e855720c08db801b46edc01393069ad96..1ab0edd326af5389f806551852921d4a8276b9d1 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/java/com/zyd/blog/controller/RestUserController.java b/blog-admin/src/main/java/com/zyd/blog/controller/RestUserController.java index 75587fb9bf544481dbcc10531533d751d4e2b1a9..578d2d96498ae70e7b7da7a831771e4525610808 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/article/list.ftl b/blog-admin/src/main/resources/templates/article/list.ftl index e843a317f2c632699e333fa61bd4c177137b7d24..9d2e6334846850f6167767eb47046244478cce75 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 50c09516d6fbdb138d2d82fbc624f4b1d84ea2a6..afe3fda5e7182c9d26b448e9f88913cf431f3991 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-admin/src/main/resources/templates/user/list.ftl b/blog-admin/src/main/resources/templates/user/list.ftl index f4a7b6b553b2788258f2ba1af093f428e8795cd5..bd8ce59bd05379547bc39fd755984845bd99a1ca 100644 --- a/blog-admin/src/main/resources/templates/user/list.ftl +++ b/blog-admin/src/main/resources/templates/user/list.ftl @@ -14,9 +14,8 @@
-<@addOrUpdateMOdal defaultTitle="添加用户"> - -
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- + + + + + + <@footer> + + \ No newline at end of file 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 0000000000000000000000000000000000000000..4f535372126cf5564e6f835ee3d6979f5afc72fe --- /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 diff --git a/blog-admin/sysResourcesSql.md b/blog-admin/sysResourcesSql.md new file mode 100644 index 0000000000000000000000000000000000000000..24733ef692d4b7fce789d55a169504bf7a31f758 --- /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| + 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 0000000000000000000000000000000000000000..89221061fc0742bdcf4bca490a8582b2bba9823a --- /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 d4172afa5f23fb7d1ccc6dd92d7cff02009eec0c..6b4f35776d0bd72418e22a55815be3138003069e 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}