feat 适配文章详细的交互

This commit is contained in:
damonyuan 2024-10-15 01:10:45 +08:00
parent b8997b8062
commit 51061ad76b
9 changed files with 181 additions and 108 deletions

View File

@ -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;

View File

@ -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;
}
}

View File

@ -67,7 +67,7 @@ public class ArticleController {
return AjaxResult.success(list);
}
@PostMapping("/collectAdd")
@PostMapping("/addCollect")
@ApiOperation(value="收藏加入")
public AjaxResult<Object> addCollect(@Validated @RequestBody ArticleCollectValidate collectValidate) {
Integer articleId = collectValidate.getArticleId();

View File

@ -42,23 +42,23 @@ public class PcController {
Map<String, Object> config = iPcService.getConfig();
return AjaxResult.success(config);
}
//
// @NotLogin
// @GetMapping("/articleCenter")
// @ApiOperation(value="资讯中心")
// public AjaxResult<List<PcArticleCenterVo>> articleCenter() {
// List<PcArticleCenterVo> list = iPcService.articleCenter();
// return AjaxResult.success(list);
// }
//
// @NotLogin
// @GetMapping("/articleDetail")
// @ApiOperation(value="文章详情")
// public AjaxResult<PcArticleDetailVo> 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<List<PcArticleCenterVo>> infoCenter() {
List<PcArticleCenterVo> list = iPcService.infoCenter();
return AjaxResult.success(list);
}
@NotLogin
@GetMapping("/articleDetail")
@ApiOperation(value="文章详情")
public AjaxResult<PcArticleDetailVo> articleDetail(@Validated @IDMust() @RequestParam("id") Integer id) {
Integer userId = LikeFrontThreadLocal.getUserId();
PcArticleDetailVo vo = iPcService.articleDetail(id, userId);
return AjaxResult.success(vo);
}
}

View File

@ -28,7 +28,7 @@ public interface IPcService {
* @author fzr
* @return PcArticleCenterVo
*/
List<PcArticleCenterVo> articleCenter();
List<PcArticleCenterVo> infoCenter();
/**
* 文章详情

View File

@ -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<Article> 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<ArticleCollect> articleCollects = articleCollectMapper.selectList(
new QueryWrapper<ArticleCollect>()
.eq("user_id", userId)
.eq("is_delete", 0)
.isNull("delete_time")
.eq("status", YesNoEnum.YES.getCode())
.in("article_id", ids));
List<Integer> 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<ArticleCollect>()
.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<ArticleCollect> 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<ArticleCollect>()
.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<ArticleCollect>()
.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);
}

View File

@ -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);
}

View File

@ -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<String, Object> 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<String, Object> 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<String, Object> 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<String, String> websiteConfig = ConfigUtils.get("copyright");
String copyright = websiteConfig.getOrDefault("config", "[]");
List<Map<String, String>> 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<PcArticleCenterVo>
*/
@Override
public List<PcArticleCenterVo> articleCenter() {
public List<PcArticleCenterVo> infoCenter() {
List<ArticleCate> articleCategoryList = articleCategoryMapper.selectList(
new QueryWrapper<ArticleCate>()
.eq("is_show", 1)
@ -188,11 +216,20 @@ public class PcServiceImpI implements IPcService {
List<Map<String, Object>> articles = new LinkedList<>();
for (Article article : articleList) {
Map<String, Object> a = new LinkedHashMap<>();
a.put("id", article.getId());
a.put("title", article.getTitle());
a.put("image", UrlUtils.toAbsoluteUrl(article.getImage()));
articles.add(a);
Map<String, Object> 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<Article>()
.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<ArticleCollect>()
.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<String, Object> prevMap = new LinkedHashMap<>();
prevMap.put("id", prev.getId());
prevMap.put("title", prev.getTitle());
vo.setPrev(prevMap);
vo.setLast(prevMap);
}
if (StringUtils.isNotNull(next)) {

View File

@ -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;
}