Search in sources :

Example 6 with BussinessLog

use of com.zyd.blog.business.annotation.BussinessLog in project OneBlog by zhangyd-c.

the class RestUserController method add.

@RequiresPermissions("user:add")
@PostMapping(value = "/add")
@BussinessLog("添加用户")
public ResponseVO add(User user) {
    User u = userService.getByUserName(user.getUsername());
    if (u != null) {
        return ResultUtil.error("该用户名[" + user.getUsername() + "]已存在!请更改用户名");
    }
    try {
        user.setPassword(PasswordUtil.encrypt(user.getPassword(), user.getUsername()));
        userService.insert(user);
        return ResultUtil.success("成功");
    } catch (Exception e) {
        e.printStackTrace();
        return ResultUtil.error("error");
    }
}
Also used : User(com.zyd.blog.business.entity.User) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) PostMapping(org.springframework.web.bind.annotation.PostMapping) BussinessLog(com.zyd.blog.business.annotation.BussinessLog)

Example 7 with BussinessLog

use of com.zyd.blog.business.annotation.BussinessLog in project OneBlog by zhangyd-c.

the class RenderController method edit.

@RequiresPermissions("article:publish")
@BussinessLog(value = "进入修改文章页[id={1}]")
@GetMapping("/article/update/{id}")
public ModelAndView edit(@PathVariable("id") Long id, Model model) {
    model.addAttribute("id", id);
    Article article = articleService.getByPrimaryKey(id);
    if (!Arrays.asList("we", "md", "tiny").contains(article.getEditorType())) {
        throw new ZhydException("文章异常,未知的编辑器类型");
    }
    return ResultUtil.view("article/publish-" + article.getEditorType());
}
Also used : ZhydException(com.zyd.blog.framework.exception.ZhydException) Article(com.zyd.blog.business.entity.Article) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) GetMapping(org.springframework.web.bind.annotation.GetMapping) BussinessLog(com.zyd.blog.business.annotation.BussinessLog)

Example 8 with BussinessLog

use of com.zyd.blog.business.annotation.BussinessLog in project OneBlog by zhangyd-c.

the class RestApiController method uploadFileForMd.

@BussinessLog("simpleMD编辑器中上传文件")
@RequiresPermissions("article:publish")
@PostMapping("/uploadFileForMd")
public Object uploadFileForMd(@RequestParam("file") MultipartFile file) {
    FileUploader uploader = new GlobalFileUploader();
    VirtualFile virtualFile = uploader.upload(file, FileUploadType.SIMPLE.getPath(), true);
    Map<String, Object> resultMap = new HashMap<>(3);
    resultMap.put("success", 1);
    resultMap.put("message", "上传成功");
    resultMap.put("filename", virtualFile.getFullFilePath());
    return resultMap;
}
Also used : VirtualFile(com.zyd.blog.file.entity.VirtualFile) GlobalFileUploader(com.zyd.blog.plugin.file.GlobalFileUploader) FileUploader(com.zyd.blog.file.FileUploader) GlobalFileUploader(com.zyd.blog.plugin.file.GlobalFileUploader) HashMap(java.util.HashMap) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) PostMapping(org.springframework.web.bind.annotation.PostMapping) BussinessLog(com.zyd.blog.business.annotation.BussinessLog)

Example 9 with BussinessLog

use of com.zyd.blog.business.annotation.BussinessLog in project OneBlog by zhangyd-c.

the class RestArticleController method pushToBaidu.

@RequiresPermissions(value = { "article:batchPush", "article:push" }, logical = Logical.OR)
@PostMapping(value = "/pushToBaidu/{type}")
@BussinessLog("推送文章[{2}]到百度站长平台")
public ResponseVO pushToBaidu(@PathVariable("type") BaiduPushTypeEnum type, Long[] ids) {
    if (null == ids) {
        return ResultUtil.error(500, "请至少选择一条记录");
    }
    Map config = configService.getConfigs();
    String siteUrl = (String) config.get(ConfigKeyEnum.SITE_URL.getKey());
    StringBuilder params = new StringBuilder();
    for (Long id : ids) {
        params.append(siteUrl).append("/article/").append(id).append("\n");
    }
    // urls: 推送, update: 更新, del: 删除
    String url = UrlBuildUtil.getBaiduPushUrl(type.toString(), (String) config.get(ConfigKeyEnum.SITE_URL.getKey()), (String) config.get(ConfigKeyEnum.BAIDU_PUSH_TOKEN.getKey()));
    String result = BaiduPushUtil.doPush(url, params.toString(), (String) config.get(ConfigKeyEnum.BAIDU_PUSH_COOKIE.getKey()));
    log.info(result);
    JSONObject resultJson = JSONObject.parseObject(result);
    if (resultJson.containsKey("error")) {
        return ResultUtil.error(resultJson.getString("message"));
    }
    return ResultUtil.success(null, result);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) Map(java.util.Map) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) PostMapping(org.springframework.web.bind.annotation.PostMapping) BussinessLog(com.zyd.blog.business.annotation.BussinessLog)

Example 10 with BussinessLog

use of com.zyd.blog.business.annotation.BussinessLog in project OneBlog by zhangyd-c.

the class RestCommentController method audit.

@RequiresPermissions("comment:audit")
@PostMapping("/audit")
@BussinessLog("审核评论")
public ResponseVO audit(Comment comment, String contentText, Boolean sendEmail) {
    try {
        commentService.updateSelective(comment);
        if (!StringUtils.isEmpty(contentText)) {
            comment.setContent(contentText);
            commentService.commentForAdmin(comment);
        }
        if (null != sendEmail && sendEmail) {
            Comment commentDB = commentService.getByPrimaryKey(comment.getId());
            mailService.send(commentDB, TemplateKeyEnum.TM_COMMENT_AUDIT, true);
        }
    } catch (Exception e) {
        e.printStackTrace();
        return ResultUtil.error("评论审核失败!");
    }
    return ResultUtil.success(ResponseStatus.SUCCESS);
}
Also used : Comment(com.zyd.blog.business.entity.Comment) ZhydCommentException(com.zyd.blog.framework.exception.ZhydCommentException) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) PostMapping(org.springframework.web.bind.annotation.PostMapping) BussinessLog(com.zyd.blog.business.annotation.BussinessLog)

Aggregations

BussinessLog (com.zyd.blog.business.annotation.BussinessLog)18 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)9 PostMapping (org.springframework.web.bind.annotation.PostMapping)9 GetMapping (org.springframework.web.bind.annotation.GetMapping)7 ArticleConditionVO (com.zyd.blog.business.vo.ArticleConditionVO)4 User (com.zyd.blog.business.entity.User)3 HashMap (java.util.HashMap)3 JSONObject (com.alibaba.fastjson.JSONObject)2 Article (com.zyd.blog.business.entity.Article)2 Notice (com.zyd.blog.business.entity.Notice)2 FileUploader (com.zyd.blog.file.FileUploader)2 VirtualFile (com.zyd.blog.file.entity.VirtualFile)2 ZhydCommentException (com.zyd.blog.framework.exception.ZhydCommentException)2 GlobalFileUploader (com.zyd.blog.plugin.file.GlobalFileUploader)2 JSONArray (com.alibaba.fastjson.JSONArray)1 Comment (com.zyd.blog.business.entity.Comment)1 Template (com.zyd.blog.business.entity.Template)1 PlatformEnum (com.zyd.blog.business.enums.PlatformEnum)1 ZhydArticleException (com.zyd.blog.framework.exception.ZhydArticleException)1 ZhydException (com.zyd.blog.framework.exception.ZhydException)1