From 51061ad76ba4daaf44438c26968d0cd4e17f25cc Mon Sep 17 00:00:00 2001 From: damonyuan <404054358@qq.com> Date: Tue, 15 Oct 2024 01:10:45 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E9=80=82=E9=85=8D=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E8=AF=A6=E7=BB=86=E7=9A=84=E4=BA=A4=E4=BA=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/entity/article/ArticleCollect.java | 5 +- .../java/com/mdd/common/enums/YesNoEnum.java | 41 ++++++ .../front/controller/ArticleController.java | 2 +- .../mdd/front/controller/PcController.java | 36 +++--- .../com/mdd/front/service/IPcService.java | 2 +- .../service/impl/ArticleServiceImpl.java | 24 ++-- .../front/service/impl/IndexServiceImpl.java | 2 +- .../mdd/front/service/impl/PcServiceImpI.java | 118 ++++++++++++------ .../front/vo/article/PcArticleDetailVo.java | 59 ++++----- 9 files changed, 181 insertions(+), 108 deletions(-) create mode 100644 server/like-common/src/main/java/com/mdd/common/enums/YesNoEnum.java diff --git a/server/like-common/src/main/java/com/mdd/common/entity/article/ArticleCollect.java b/server/like-common/src/main/java/com/mdd/common/entity/article/ArticleCollect.java index 0eaa906a..b88a7f30 100644 --- a/server/like-common/src/main/java/com/mdd/common/entity/article/ArticleCollect.java +++ b/server/like-common/src/main/java/com/mdd/common/entity/article/ArticleCollect.java @@ -24,9 +24,8 @@ public class ArticleCollect implements Serializable { @ApiModelProperty("文章ID") private Integer articleId; - @ApiModelProperty("是否删除") - private Integer isDelete; - + @ApiModelProperty("收藏状态 0-未收藏 1-已收藏") + private Integer status; @ApiModelProperty("创建时间") private Long createTime; diff --git a/server/like-common/src/main/java/com/mdd/common/enums/YesNoEnum.java b/server/like-common/src/main/java/com/mdd/common/enums/YesNoEnum.java new file mode 100644 index 00000000..030d6d63 --- /dev/null +++ b/server/like-common/src/main/java/com/mdd/common/enums/YesNoEnum.java @@ -0,0 +1,41 @@ +package com.mdd.common.enums; + +/** + * 相册枚举 + */ +public enum YesNoEnum { + + YES(1, "是"), + NO(0, "否"); + + /** + * 构造方法 + */ + private final int code; + private final String msg; + YesNoEnum(int code, String msg) { + this.code = code; + this.msg = msg; + } + + /** + * 获取状态码 + * + * @author fzr + * @return Long + */ + public int getCode() { + return this.code; + } + + /** + * 获取提示 + * + * @author fzr + * @return String + */ + public String getMsg() { + return this.msg; + } + +} diff --git a/server/like-front/src/main/java/com/mdd/front/controller/ArticleController.java b/server/like-front/src/main/java/com/mdd/front/controller/ArticleController.java index 9c4347bc..9998d877 100644 --- a/server/like-front/src/main/java/com/mdd/front/controller/ArticleController.java +++ b/server/like-front/src/main/java/com/mdd/front/controller/ArticleController.java @@ -67,7 +67,7 @@ public class ArticleController { return AjaxResult.success(list); } - @PostMapping("/collectAdd") + @PostMapping("/addCollect") @ApiOperation(value="收藏加入") public AjaxResult addCollect(@Validated @RequestBody ArticleCollectValidate collectValidate) { Integer articleId = collectValidate.getArticleId(); diff --git a/server/like-front/src/main/java/com/mdd/front/controller/PcController.java b/server/like-front/src/main/java/com/mdd/front/controller/PcController.java index 6f05d54b..a3d6f125 100644 --- a/server/like-front/src/main/java/com/mdd/front/controller/PcController.java +++ b/server/like-front/src/main/java/com/mdd/front/controller/PcController.java @@ -42,23 +42,23 @@ public class PcController { Map config = iPcService.getConfig(); return AjaxResult.success(config); } -// -// @NotLogin -// @GetMapping("/articleCenter") -// @ApiOperation(value="资讯中心") -// public AjaxResult> articleCenter() { -// List list = iPcService.articleCenter(); -// return AjaxResult.success(list); -// } -// -// @NotLogin -// @GetMapping("/articleDetail") -// @ApiOperation(value="文章详情") -// public AjaxResult articleDetail(@Validated @IDMust() @RequestParam("id") Integer id) { -// Integer userId = LikeFrontThreadLocal.getUserId(); -// -// PcArticleDetailVo vo = iPcService.articleDetail(id, userId); -// return AjaxResult.success(vo); -// } + + @NotLogin + @GetMapping("/infoCenter") + @ApiOperation(value="资讯中心") + public AjaxResult> infoCenter() { + List list = iPcService.infoCenter(); + return AjaxResult.success(list); + } + + @NotLogin + @GetMapping("/articleDetail") + @ApiOperation(value="文章详情") + public AjaxResult articleDetail(@Validated @IDMust() @RequestParam("id") Integer id) { + Integer userId = LikeFrontThreadLocal.getUserId(); + + PcArticleDetailVo vo = iPcService.articleDetail(id, userId); + return AjaxResult.success(vo); + } } diff --git a/server/like-front/src/main/java/com/mdd/front/service/IPcService.java b/server/like-front/src/main/java/com/mdd/front/service/IPcService.java index f0a481bb..58c1335c 100644 --- a/server/like-front/src/main/java/com/mdd/front/service/IPcService.java +++ b/server/like-front/src/main/java/com/mdd/front/service/IPcService.java @@ -28,7 +28,7 @@ public interface IPcService { * @author fzr * @return PcArticleCenterVo */ - List articleCenter(); + List infoCenter(); /** * 文章详情 diff --git a/server/like-front/src/main/java/com/mdd/front/service/impl/ArticleServiceImpl.java b/server/like-front/src/main/java/com/mdd/front/service/impl/ArticleServiceImpl.java index 8c30fe61..388f1bf8 100644 --- a/server/like-front/src/main/java/com/mdd/front/service/impl/ArticleServiceImpl.java +++ b/server/like-front/src/main/java/com/mdd/front/service/impl/ArticleServiceImpl.java @@ -10,6 +10,7 @@ import com.mdd.common.core.PageResult; import com.mdd.common.entity.article.Article; import com.mdd.common.entity.article.ArticleCate; import com.mdd.common.entity.article.ArticleCollect; +import com.mdd.common.enums.YesNoEnum; import com.mdd.common.mapper.article.ArticleCateMapper; import com.mdd.common.mapper.article.ArticleCollectMapper; import com.mdd.common.mapper.article.ArticleMapper; @@ -87,7 +88,7 @@ public class ArticleServiceImpl implements IArticleService { QueryWrapper
queryWrapper = new QueryWrapper<>(); queryWrapper.select("id,title,image,intro,visit,create_time"); - queryWrapper.eq("is_delete", 0); + queryWrapper.isNull("delete_time"); queryWrapper.eq("is_show", 1); articleMapper.setSearch(queryWrapper, searchValidate, new String[]{ @@ -130,7 +131,8 @@ public class ArticleServiceImpl implements IArticleService { List articleCollects = articleCollectMapper.selectList( new QueryWrapper() .eq("user_id", userId) - .eq("is_delete", 0) + .isNull("delete_time") + .eq("status", YesNoEnum.YES.getCode()) .in("article_id", ids)); List collects = new LinkedList<>(); @@ -160,7 +162,7 @@ public class ArticleServiceImpl implements IArticleService { .select("id,title,image,intro,summary,visit,author,content,create_time") .eq("id", id) .eq("is_show", 1) - .eq("is_delete", 0) + .isNull("delete_time" ) .last("limit 1")); Assert.notNull(article, "数据不存在!"); @@ -168,7 +170,8 @@ public class ArticleServiceImpl implements IArticleService { ArticleCollect articleCollect = articleCollectMapper.selectOne(new QueryWrapper() .eq("user_id", userId) .eq("article_id", article.getId()) - .eq("is_delete", 0) + .isNull("delete_time") + .eq("status", YesNoEnum.YES.getCode()) .last("limit 1")); ArticleDetailVo vo = new ArticleDetailVo(); @@ -199,8 +202,8 @@ public class ArticleServiceImpl implements IArticleService { MPJQueryWrapper mpjQueryWrapper = new MPJQueryWrapper<>(); mpjQueryWrapper.select("t.id,t.article_id,a.title,a.image,a.intro,a.visit,a.create_time") .eq("t.user_id", userId) - .eq("t.is_delete", 0) - .eq("a.is_delete", 0) + .isNull("t.delete_time") + .isNull("a.delete_time") .orderByDesc("t.id") .innerJoin("?_article a ON a.id=t.article_id".replace("?_", GlobalConfig.tablePrefix)); @@ -230,17 +233,18 @@ public class ArticleServiceImpl implements IArticleService { new QueryWrapper() .eq("article_id", articleId) .eq("user_id", userId) + .isNull("delete_time") .last("limit 1")); if (StringUtils.isNotNull(articleCollect)) { - articleCollect.setIsDelete(0); articleCollect.setUpdateTime(System.currentTimeMillis() / 1000); + articleCollect.setStatus(YesNoEnum.NO.getCode()); articleCollectMapper.updateById(articleCollect); } else { ArticleCollect model = new ArticleCollect(); model.setArticleId(articleId); model.setUserId(userId); - model.setIsDelete(0); + model.setStatus(YesNoEnum.YES.getCode()); model.setCreateTime(System.currentTimeMillis() / 1000); model.setUpdateTime(System.currentTimeMillis() / 1000); articleCollectMapper.insert(model); @@ -260,12 +264,12 @@ public class ArticleServiceImpl implements IArticleService { new QueryWrapper() .eq("article_id", articleId) .eq("user_id", userId) - .eq("is_delete", 0) + .isNull("delete_time") .last("limit 1")); Assert.notNull(articleCollect, "收藏不存在!"); - articleCollect.setIsDelete(1); + articleCollect.setStatus(YesNoEnum.NO.getCode()); articleCollect.setUpdateTime(System.currentTimeMillis() / 1000); articleCollectMapper.updateById(articleCollect); } diff --git a/server/like-front/src/main/java/com/mdd/front/service/impl/IndexServiceImpl.java b/server/like-front/src/main/java/com/mdd/front/service/impl/IndexServiceImpl.java index 0bfcb1fe..407a2aac 100644 --- a/server/like-front/src/main/java/com/mdd/front/service/impl/IndexServiceImpl.java +++ b/server/like-front/src/main/java/com/mdd/front/service/impl/IndexServiceImpl.java @@ -65,7 +65,7 @@ public class IndexServiceImpl implements IIndexService { map.put("summary", article.getAbstractField()); map.put("image", UrlUtils.toAbsoluteUrl(article.getImage())); map.put("author", article.getAuthor()); - map.put("visit", article.getClickActual()); + map.put("click", article.getClickActual() + article.getClickVirtual()); map.put("createTime", TimeUtils.timestampToDate(article.getCreateTime())); articleList.add(map); } diff --git a/server/like-front/src/main/java/com/mdd/front/service/impl/PcServiceImpI.java b/server/like-front/src/main/java/com/mdd/front/service/impl/PcServiceImpI.java index 47398d66..f32f418b 100644 --- a/server/like-front/src/main/java/com/mdd/front/service/impl/PcServiceImpI.java +++ b/server/like-front/src/main/java/com/mdd/front/service/impl/PcServiceImpI.java @@ -1,12 +1,14 @@ package com.mdd.front.service.impl; import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.mdd.common.config.GlobalConfig; import com.mdd.common.entity.article.ArticleCate; import com.mdd.common.entity.decorate.DecoratePage; import com.mdd.common.entity.article.Article; import com.mdd.common.entity.article.ArticleCollect; +import com.mdd.common.enums.YesNoEnum; import com.mdd.common.exception.OperateException; import com.mdd.common.mapper.article.ArticleCateMapper; import com.mdd.common.mapper.decorate.DecoratePageMapper; @@ -61,14 +63,14 @@ public class PcServiceImpI implements IPcService { for (Article article : articlesAll) { Map map = new LinkedHashMap<>(); map.put("id", article.getId()); - map.put("title", article.getTitle()); - map.put("intro", article.getContent()); - map.put("summary", article.getAbstractField()); - map.put("image", UrlUtils.toAbsoluteUrl(article.getImage())); - map.put("visit", article.getClickActual()); + map.put("cid", article.getCid()); map.put("author", article.getAuthor()); - map.put("sort", article.getSort()); - map.put("createTime", TimeUtils.timestampToDate(article.getCreateTime())); + map.put("title", article.getTitle()); + map.put("abstract", article.getAbstractField()); + map.put("click", article.getClickActual() + article.getClickVirtual()); + map.put("create_time", TimeUtils.timestampToDate(article.getCreateTime())); + map.put("desc", article.getDesc()); + map.put("image", UrlUtils.toAbsoluteUrl(article.getImage())); articlesAllList.add(map); } @@ -82,14 +84,14 @@ public class PcServiceImpI implements IPcService { for (Article article : articlesNew) { Map map = new LinkedHashMap<>(); map.put("id", article.getId()); - map.put("title", article.getTitle()); - map.put("intro", article.getContent()); - map.put("summary", article.getAbstractField()); - map.put("image", UrlUtils.toAbsoluteUrl(article.getImage())); - map.put("visit", article.getClickActual()); - map.put("sort", article.getSort()); + map.put("cid", article.getCid()); map.put("author", article.getAuthor()); - map.put("createTime", TimeUtils.timestampToDate(article.getCreateTime())); + map.put("title", article.getTitle()); + map.put("abstract", article.getAbstractField()); + map.put("click", article.getClickActual() + article.getClickVirtual()); + map.put("create_time", TimeUtils.timestampToDate(article.getCreateTime())); + map.put("desc", article.getDesc()); + map.put("image", UrlUtils.toAbsoluteUrl(article.getImage())); articlesNewList.add(map); } @@ -103,18 +105,18 @@ public class PcServiceImpI implements IPcService { for (Article article : articlesHot) { Map map = new LinkedHashMap<>(); map.put("id", article.getId()); - map.put("title", article.getTitle()); - map.put("intro", article.getContent()); - map.put("summary", article.getAbstractField()); - map.put("image", UrlUtils.toAbsoluteUrl(article.getImage())); + map.put("cid", article.getCid()); map.put("author", article.getAuthor()); - map.put("click_actual", article.getClickActual()); - map.put("sort", article.getSort()); - map.put("createTime", TimeUtils.timestampToDate(article.getCreateTime())); + map.put("title", article.getTitle()); + map.put("abstract", article.getAbstractField()); + map.put("click", article.getClickActual() + article.getClickVirtual()); + map.put("create_time", TimeUtils.timestampToDate(article.getCreateTime())); + map.put("desc", article.getDesc()); + map.put("image", UrlUtils.toAbsoluteUrl(article.getImage())); articlesHostList.add(map); } - indexData.put("pages", decoratePage.getData()); + indexData.put("pages", JSONArray.parseArray(decoratePage.getData())); indexData.put("all", articlesAllList); indexData.put("new", articlesNewList); indexData.put("hot", articlesHostList); @@ -147,19 +149,45 @@ public class PcServiceImpI implements IPcService { // qq授权登录 loginMap.put("qq_auth", Integer.parseInt(loginConfig.getOrDefault("qq_auth", "0"))); + // 站点统计 + String siteStatistics = ConfigUtils.get("siteStatistics", "clarity_code", ""); + // 备案信息 Map websiteConfig = ConfigUtils.get("copyright"); String copyright = websiteConfig.getOrDefault("config", "[]"); List> copyrightMap = ListUtils.stringToListAsMapStr(copyright); - // 网址信息 + // 公众号二维码 + String oaQrCode = ConfigUtils.get("oa_setting", "qr_code", ""); + oaQrCode = StringUtils.isEmpty(oaQrCode) ? "" : UrlUtils.toAbsoluteUrl(oaQrCode); + + // 小程序二维码 + String mnpQrCode = ConfigUtils.get("mnp_setting", "qr_code", ""); + mnpQrCode = StringUtils.isEmpty(mnpQrCode) ? "" : UrlUtils.toAbsoluteUrl(mnpQrCode); + + JSONObject qrcode = new JSONObject(); + qrcode.put("oa", oaQrCode); + qrcode.put("mnp", mnpQrCode); + + // 网站信息 + JSONObject website = new JSONObject(); + website.put("shop_name", ConfigUtils.get("website", "shop_name", "")); + website.put("shop_logo", UrlUtils.toAbsoluteUrl(ConfigUtils.get("website", "shop_logo", ""))); + website.put("pc_logo", UrlUtils.toAbsoluteUrl(ConfigUtils.get("website", "pc_logo", ""))); + website.put("pc_title", ConfigUtils.get("website", "pc_title", "")); + website.put("pc_ico", UrlUtils.toAbsoluteUrl(ConfigUtils.get("website", "pc_ico", ""))); + website.put("pc_desc", ConfigUtils.get("website", "pc_desc", "")); + website.put("pc_keywords", ConfigUtils.get("website", "pc_keywords", "")); + response.put("admin_url", ""); response.put("copyright", copyrightMap); response.put("domain", UrlUtils.domain()); response.put("login", loginMap); response.put("version", GlobalConfig.version); - response.put("website", "xxxxx"); + response.put("siteStatistics", siteStatistics); + response.put("website", website); + response.put("qrcode", qrcode); return response; } @@ -170,7 +198,7 @@ public class PcServiceImpI implements IPcService { * @return List */ @Override - public List articleCenter() { + public List infoCenter() { List articleCategoryList = articleCategoryMapper.selectList( new QueryWrapper() .eq("is_show", 1) @@ -188,11 +216,20 @@ public class PcServiceImpI implements IPcService { List> articles = new LinkedList<>(); for (Article article : articleList) { - Map a = new LinkedHashMap<>(); - a.put("id", article.getId()); - a.put("title", article.getTitle()); - a.put("image", UrlUtils.toAbsoluteUrl(article.getImage())); - articles.add(a); + Map map = new LinkedHashMap<>(); + map.put("id", article.getId()); + map.put("cid", article.getCid()); + map.put("author", article.getAuthor()); + map.put("title", article.getTitle()); + map.put("abstract", article.getAbstractField()); + map.put("click", article.getClickActual() + article.getClickVirtual()); + map.put("create_time", TimeUtils.timestampToDate(article.getCreateTime())); + map.put("desc", article.getDesc()); + map.put("image", UrlUtils.toAbsoluteUrl(article.getImage())); + map.put("is_show", article.getIsShow()); + map.put("sort", article.getSort()); + map.put("update_time", TimeUtils.timestampToDate(article.getUpdateTime())); + articles.add(map); } PcArticleCenterVo vo = new PcArticleCenterVo(); @@ -217,11 +254,9 @@ public class PcServiceImpI implements IPcService { public PcArticleDetailVo articleDetail(Integer id, Integer userId) { // 文章详情 Article article = articleMapper.selectOne(new QueryWrapper
() - .select(Article.class, info-> - !info.getColumn().equals("is_show") && - !info.getColumn().equals("delete_time")) .eq("id", id) .isNull("delete_time") + .eq("is_show", YesNoEnum.YES.getCode()) .last("limit 1")); if (StringUtils.isNull(article)) { @@ -254,6 +289,7 @@ public class PcServiceImpI implements IPcService { ArticleCollect collect = articleCollectMapper.selectOne(new QueryWrapper() .eq("article_id", article.getId()) .eq("user_id", userId) + .eq("status", YesNoEnum.YES.getCode()) .isNull("delete_time") .last("limit 1")); @@ -279,19 +315,21 @@ public class PcServiceImpI implements IPcService { // 处理数据 PcArticleDetailVo vo = new PcArticleDetailVo(); BeanUtils.copyProperties(article, vo); - vo.setCreateTime(TimeUtils.timestampToDate(vo.getCreateTime())); - vo.setUpdateTime(TimeUtils.timestampToDate(vo.getUpdateTime())); - vo.setCategory(StringUtils.isNotNull(articleCategory) ? articleCategory.getName() : ""); - vo.setIsCollect(StringUtils.isNotNull(collect) ? 1 : 0); + vo.setCreateTime(TimeUtils.timestampToDate(article.getCreateTime())); + vo.setUpdateTime(TimeUtils.timestampToDate(article.getUpdateTime())); + vo.setCateName(StringUtils.isNotNull(articleCategory) ? articleCategory.getName() : ""); + vo.setCollect(StringUtils.isNotNull(collect) ? true : false); + vo.setIsShow(article.getIsShow()); + vo.setClick(article.getClickActual() + article.getClickVirtual()); vo.setNews(newsList); - vo.setPrev(null); - vo.setNext(null); + vo.setLast(new JSONArray()); + vo.setNext(new JSONArray()); if (StringUtils.isNotNull(prev)) { Map prevMap = new LinkedHashMap<>(); prevMap.put("id", prev.getId()); prevMap.put("title", prev.getTitle()); - vo.setPrev(prevMap); + vo.setLast(prevMap); } if (StringUtils.isNotNull(next)) { diff --git a/server/like-front/src/main/java/com/mdd/front/vo/article/PcArticleDetailVo.java b/server/like-front/src/main/java/com/mdd/front/vo/article/PcArticleDetailVo.java index 21bd27fb..fa7a31de 100644 --- a/server/like-front/src/main/java/com/mdd/front/vo/article/PcArticleDetailVo.java +++ b/server/like-front/src/main/java/com/mdd/front/vo/article/PcArticleDetailVo.java @@ -1,5 +1,7 @@ package com.mdd.front.vo.article; +import com.baomidou.mybatisplus.annotation.TableField; +import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -13,52 +15,41 @@ public class PcArticleDetailVo implements Serializable { @ApiModelProperty(value = "文章ID") private Integer id; - @ApiModelProperty(value = "分类ID") - private Integer cid; - - @ApiModelProperty(value = "分类名称") - private String category; - - @ApiModelProperty(value = "文章标题") - private String title; - - @ApiModelProperty(value = "文章简介") - private String intro; - - @ApiModelProperty(value = "文章描述") - private String summary; - - @ApiModelProperty(value = "文章封面") - private String image; - - @ApiModelProperty(value = "文章内容") - private String content; - + @ApiModelProperty("摘要") + @JsonProperty(value = "abstract") + private String abstractField; @ApiModelProperty(value = "文章作者") private String author; - + @ApiModelProperty(value = "分类名称") + private String cateName; + @ApiModelProperty(value = "分类ID") + private Integer cid; @ApiModelProperty(value = "浏览数量") - private Integer visit; - - @ApiModelProperty(value = "排序编号") - private Integer sort; - + private Integer click; + @ApiModelProperty(value = "文章标题") + private String title; @ApiModelProperty(value = "是否收藏") - private Integer isCollect; - + private Boolean collect; + @ApiModelProperty(value = "文章内容") + private String content; @ApiModelProperty(value = "创建时间") private String createTime; - @ApiModelProperty(value = "更新时间") private String updateTime; - + @ApiModelProperty("简介") + private String desc; + @ApiModelProperty(value = "文章封面") + private String image; + @ApiModelProperty("是否显示: [0=否, 1=是]") + private Integer isShow; + @ApiModelProperty(value = "排序编号") + private Integer sort; @ApiModelProperty(value = "上一页") - private Object prev; - + private Object last; @ApiModelProperty(value = "下一页") private Object next; - @ApiModelProperty(value = "最新推荐") + @JsonProperty("new") private Object news; }