| | |
| | | package vip.xiaonuo.modular.blogarticle.controller; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.PageUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.crypto.SecureUtil; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import vip.xiaonuo.core.annotion.BusinessLog; |
| | |
| | | import vip.xiaonuo.core.pojo.response.ResponseData; |
| | | import vip.xiaonuo.core.pojo.response.SuccessResponseData; |
| | | import vip.xiaonuo.modular.blogarticle.entity.BlogArticle; |
| | | import vip.xiaonuo.modular.blogarticle.entity.BlogArticleVo; |
| | | import vip.xiaonuo.modular.blogarticle.param.BlogArticleAddDto; |
| | | import vip.xiaonuo.modular.blogarticle.param.BlogArticleQueryDto; |
| | | import vip.xiaonuo.modular.blogarticle.param.BlogArticleVo; |
| | | import vip.xiaonuo.modular.blogarticle.service.BlogArticleService; |
| | | import vip.xiaonuo.modular.blogarticletype.entity.BlogArticleType; |
| | | import vip.xiaonuo.modular.blogarticletype.service.BlogArticleTypeService; |
| | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.Future; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/outside") |
| | | @Slf4j |
| | | public class BlogArticleOutsideController { |
| | | |
| | | @Resource |
| | |
| | | @PostMapping("/blogArticle/add") |
| | | @BusinessLog(title = "外部blog系统_blog文章_增加", opType = LogAnnotionOpTypeEnum.ADD) |
| | | public ResponseData add(@RequestBody @Validated(BlogArticleAddDto.add.class) BlogArticleAddDto addDto) { |
| | | if (!SecureUtil.md5(addDto.getSecret()).equals("b49e4cc48616cfb8d5ed3e5b983165c8")) { |
| | | if (!SecureUtil.md5(addDto.getSecret()).equals(ConstantContextHolder.getPushCode())) { |
| | | throw new BlogException("口令错误.."); |
| | | } |
| | | |
| | |
| | | BlogArticle article = new BlogArticle(); |
| | | BeanUtil.copyProperties(addDto, article); |
| | | article.setSeparateYear(DateUtil.year(article.getPublishDate())); |
| | | article.setSeparateMonth(DateUtil.month(article.getPublishDate())+1); |
| | | article.setSeparateMonth(DateUtil.month(article.getPublishDate()) + 1); |
| | | article.setSeparateDay(DateUtil.dayOfMonth(article.getPublishDate())); |
| | | |
| | | article.setIsEnable(MyConstant.Yes); |
| | |
| | | param.put("pageNo", PageUtil.getStart(queryDto.getPageNo() - 1, queryDto.getPageSize())); |
| | | param.put("pageSize", queryDto.getPageSize()); |
| | | param.put("typeId", queryDto.getTypeId()); |
| | | param.put("fileType", queryDto.getFileType()); |
| | | |
| | | String blogSourcePrefix = ConstantContextHolder.getBlogSourcePrefix(); |
| | | |
| | | Date now = DateUtil.date(); |
| | | //空类型查询条件,排除笔记系列,按更新时间倒序 |
| | | //含有类型查询,按发布时间倒序 |
| | | List<BlogArticleVo> resList = blogArticleService.searchList(param).stream().map(e -> { |
| | | if (StrUtil.isNotEmpty(e.getCoverFileURL())) { |
| | | if (!e.getCoverFileURL().startsWith("http")) { |
| | |
| | | e.setCoverFileURL(blogSourcePrefix + e.getCoverFileURL()); |
| | | } |
| | | } |
| | | |
| | | //前端根据条件标注小红点(发布时间小于更新时间,且在7天内) |
| | | if (e.getPublishDate().before(e.getUpdateDate()) |
| | | && DateUtil.between(e.getUpdateDate(), now, DateUnit.DAY) <= 7) { |
| | | e.setIsAnyUpdate(MyConstant.Yes); |
| | | } else { |
| | | e.setIsAnyUpdate(MyConstant.No); |
| | | } |
| | | |
| | | return e; |
| | | }).collect(Collectors.toList()); |
| | | |
| | |
| | | throw new BlogException(BlogExceptionEnum.article_auth_error); |
| | | } |
| | | //授权码比对 |
| | | if (!SecureUtil.md5(find.getAuthPassword()).equals(queryDto.getAuthWord())) { |
| | | if (!find.getAuthPassword().equals(queryDto.getAuthWord())) { |
| | | throw new BlogException(BlogExceptionEnum.article_auth_pass_error); |
| | | } |
| | | } else if (find.getAuthStatus().equals(MyConstant.AuthStatus.privateCode)) { |
| | | throw new BlogException(BlogExceptionEnum.article_auth_private_error); |
| | | } |
| | | |
| | | //异步查询相邻记录 |
| | | Future<List<BlogArticleVo>> adjoiningRecord = blogArticleService.getAdjoiningRecord(queryDto); |
| | | |
| | | BlogArticleVo vo = new BlogArticleVo(); |
| | | |
| | |
| | | |
| | | String tempURL = this.getBlogSourceURL(find.getArticleFileId()); |
| | | |
| | | if (StrUtil.isEmpty(tempURL)) |
| | | throw new BlogException(BlogExceptionEnum.article_file_lose); |
| | | //if (StrUtil.isEmpty(tempURL)) |
| | | //throw new BlogException(BlogExceptionEnum.article_file_lose); |
| | | |
| | | vo.setArticleFileURL(tempURL); |
| | | vo.setCoverFileURL(this.getBlogSourceURL(vo.getCoverFileId())); |
| | | |
| | | while (!adjoiningRecord.isDone()) { |
| | | try { |
| | | Thread.sleep(50); |
| | | } catch (InterruptedException e) { |
| | | } |
| | | } |
| | | |
| | | try { |
| | | vo.setPreviousRecord(adjoiningRecord.get().get(0)); |
| | | vo.setNextRecord(adjoiningRecord.get().get(1)); |
| | | } catch (Exception e) { |
| | | log.error("异步获取上下相邻日志id异常,id:{} ,msg:{}", queryDto.getId(), e.getMessage()); |
| | | } |
| | | |
| | | return new SuccessResponseData(vo); |
| | | } |