From 83a7f5a1c0f667d1b5d232d4ceb297a8ae4e81ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E8=8B=B1=E6=9D=B0?= <327782001@qq.com> Date: Sat, 28 Oct 2023 02:55:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=9C=80=E8=BF=91=E7=9A=84=E6=96=87?= =?UTF-8?q?=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CsdnArticleInfoController.java | 131 ++++++++++++++++++ .../controller/CsdnUserController.java | 25 ++-- .../dao/CsdnArticleInfoDao.java | 15 ++ .../entity/CsdnArticleInfo.java | 38 +++++ .../entity/dto/CsdnArticleInfoDTO.java | 46 ++++++ .../entity/query/CsdnArticleInfoQuery.java | 27 ++++ .../service/CsdnArticleInfoService.java | 15 ++ .../impl/CsdnArticleInfoServiceImpl.java | 19 +++ 8 files changed, 304 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/kwan/springbootkwan/controller/CsdnArticleInfoController.java create mode 100644 src/main/java/com/kwan/springbootkwan/dao/CsdnArticleInfoDao.java create mode 100644 src/main/java/com/kwan/springbootkwan/entity/CsdnArticleInfo.java create mode 100644 src/main/java/com/kwan/springbootkwan/entity/dto/CsdnArticleInfoDTO.java create mode 100644 src/main/java/com/kwan/springbootkwan/entity/query/CsdnArticleInfoQuery.java create mode 100644 src/main/java/com/kwan/springbootkwan/service/CsdnArticleInfoService.java create mode 100644 src/main/java/com/kwan/springbootkwan/service/impl/CsdnArticleInfoServiceImpl.java diff --git a/src/main/java/com/kwan/springbootkwan/controller/CsdnArticleInfoController.java b/src/main/java/com/kwan/springbootkwan/controller/CsdnArticleInfoController.java new file mode 100644 index 0000000..2a630fa --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/controller/CsdnArticleInfoController.java @@ -0,0 +1,131 @@ +package com.kwan.springbootkwan.controller; + + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.kwan.springbootkwan.entity.CsdnArticleInfo; +import com.kwan.springbootkwan.entity.Result; +import com.kwan.springbootkwan.entity.dto.CsdnArticleInfoDTO; +import com.kwan.springbootkwan.entity.query.CsdnArticleInfoQuery; +import com.kwan.springbootkwan.service.CsdnArticleInfoService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.Objects; + +@Api(tags = "csdn文章管理") +@RestController +@RequestMapping("/csdnArticleInfo") +public class CsdnArticleInfoController { + + @Resource + private CsdnArticleInfoService csdnArticleInfoService; + + @ApiOperation(value = "分页查询所有数据", nickname = "分页查询所有数据") + @PostMapping("/page") + public Result selectAll(@RequestBody CsdnArticleInfoQuery query) { + final String nickName = query.getNickName(); + final String userName = query.getUserName(); + final Integer likeStatus = query.getLikeStatus(); + final Integer collectStatus = query.getCollectStatus(); + final Integer commentStatus = query.getCommentStatus(); + Page pageParm = new Page<>(); + pageParm.setCurrent(query.getPage()); + pageParm.setSize(query.getPageSize()); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("is_delete", 0); + if (StringUtils.isNotEmpty(userName)) { + wrapper.eq("user_name", userName); + } + if (Objects.nonNull(likeStatus)) { + wrapper.eq("like_status", likeStatus); + } + if (Objects.nonNull(collectStatus)) { + wrapper.eq("collect_status", collectStatus); + } + if (Objects.nonNull(commentStatus)) { + wrapper.eq("comment_status", commentStatus); + } + if (StringUtils.isNotEmpty(nickName)) { + wrapper.like("nick_name", nickName); + } + wrapper.orderByDesc("update_time"); + return Result.ok(CsdnArticleInfoDTO.Converter.INSTANCE.from(this.csdnArticleInfoService.page(pageParm, wrapper))); + } + + + @ApiOperation(value = "新增用户", nickname = "新增用户") + @PostMapping("/add") + public Result add(@RequestBody CsdnArticleInfoQuery addInfo) { + final String userName = addInfo.getUserName(); + final Integer addType = addInfo.getAddType(); + final String articleId = addInfo.getArticleId(); + if (StringUtils.isNotEmpty(userName)) { + //批量添加 + if (addType == 1) { + final String[] split = articleId.split("\n"); + for (String str : split) { + str = str.trim(); + if (StringUtils.isNotEmpty(str)) { + CsdnArticleInfo csdnArticleInfo = new CsdnArticleInfo(); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("article_id", str); + wrapper.eq("is_delete", 0); + final CsdnArticleInfo one = this.csdnArticleInfoService.getOne(wrapper); + if (one == null) { + BeanUtils.copyProperties(addInfo, csdnArticleInfo); + csdnArticleInfo.setArticleId(str); + csdnArticleInfo.setArticleUrl("https://blog.csdn.net/" + userName + "/article/details/" + articleId); + this.csdnArticleInfoService.save(csdnArticleInfo); + } + } + } + } else { + CsdnArticleInfo csdnArticleInfo = new CsdnArticleInfo(); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("user_name", userName); + wrapper.eq("is_delete", 0); + final CsdnArticleInfo one = this.csdnArticleInfoService.getOne(wrapper); + if (one == null) { + BeanUtils.copyProperties(addInfo, csdnArticleInfo); + csdnArticleInfo.setArticleUrl("https://blog.csdn.net/" + userName + "/article/details/" + articleId); + this.csdnArticleInfoService.save(csdnArticleInfo); + return Result.ok(); + } else { + return Result.error("该用户已存在"); + } + } + } + return Result.ok(); + } + + @ApiOperation(value = "更新用户", nickname = "更新用户") + @PostMapping("/update") + public Result update(@RequestBody CsdnArticleInfoQuery query) { + CsdnArticleInfo csdnUserInfo = new CsdnArticleInfo(); + csdnUserInfo.setId(query.getId()); + csdnUserInfo.setUserName(query.getUserName()); + csdnUserInfo.setNickName(query.getNickName()); + return Result.ok(this.csdnArticleInfoService.updateById(csdnUserInfo)); + } + + @ApiOperation(value = "删除用户", nickname = "删除用户") + @GetMapping("/delete") + public Result delete(@RequestParam("id") Integer id) { + CsdnArticleInfo csdnArticleInfo = new CsdnArticleInfo(); + csdnArticleInfo.setIsDelete(1); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("id", id); + return Result.ok(this.csdnArticleInfoService.update(csdnArticleInfo, wrapper)); + } +} + diff --git a/src/main/java/com/kwan/springbootkwan/controller/CsdnUserController.java b/src/main/java/com/kwan/springbootkwan/controller/CsdnUserController.java index ecc4edb..52fb48d 100644 --- a/src/main/java/com/kwan/springbootkwan/controller/CsdnUserController.java +++ b/src/main/java/com/kwan/springbootkwan/controller/CsdnUserController.java @@ -84,18 +84,18 @@ public class CsdnUserController { final String[] split = userName.split("\n"); for (String str : split) { str = str.trim(); - if (StringUtils.isEmpty(str)) { - continue; - } - CsdnUserInfo csdnUserInfo = new CsdnUserInfo(); - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("user_name", str); - wrapper.eq("is_delete", 0); - final CsdnUserInfo one = this.csdnUserInfoService.getOne(wrapper); - if (one == null) { - BeanUtils.copyProperties(addInfo, csdnUserInfo); - csdnUserInfo.setUserName(str); - this.csdnUserInfoService.save(csdnUserInfo); + if (StringUtils.isNotEmpty(str)) { + CsdnUserInfo csdnUserInfo = new CsdnUserInfo(); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("user_name", str); + wrapper.eq("is_delete", 0); + final CsdnUserInfo one = this.csdnUserInfoService.getOne(wrapper); + if (one == null) { + BeanUtils.copyProperties(addInfo, csdnUserInfo); + csdnUserInfo.setUserName(str); + csdnUserInfo.setUserHomeUrl("https://blog.csdn.net/" + str); + this.csdnUserInfoService.save(csdnUserInfo); + } } } } else { @@ -106,6 +106,7 @@ public class CsdnUserController { final CsdnUserInfo one = this.csdnUserInfoService.getOne(wrapper); if (one == null) { BeanUtils.copyProperties(addInfo, csdnUserInfo); + csdnUserInfo.setUserHomeUrl("https://blog.csdn.net/" + userName); this.csdnUserInfoService.save(csdnUserInfo); return Result.ok(); } else { diff --git a/src/main/java/com/kwan/springbootkwan/dao/CsdnArticleInfoDao.java b/src/main/java/com/kwan/springbootkwan/dao/CsdnArticleInfoDao.java new file mode 100644 index 0000000..f8eccde --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/dao/CsdnArticleInfoDao.java @@ -0,0 +1,15 @@ +package com.kwan.springbootkwan.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.kwan.springbootkwan.entity.CsdnArticleInfo; + +/** + * csdn文章信息(CsdnArticleInfo)表数据库访问层 + * + * @author makejava + * @since 2023-10-28 01:58:46 + */ +public interface CsdnArticleInfoDao extends BaseMapper { + +} + diff --git a/src/main/java/com/kwan/springbootkwan/entity/CsdnArticleInfo.java b/src/main/java/com/kwan/springbootkwan/entity/CsdnArticleInfo.java new file mode 100644 index 0000000..5a2b264 --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/entity/CsdnArticleInfo.java @@ -0,0 +1,38 @@ +package com.kwan.springbootkwan.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.activerecord.Model; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + +@Data +@ApiModel("csdn文章类") +@TableName("csdn_article_info") +public class CsdnArticleInfo extends Model { + @ApiModelProperty("主键id") + private Integer id; + @ApiModelProperty("文章id") + private String articleId; + @ApiModelProperty("文章URL") + private String articleUrl; + @ApiModelProperty("用户名称") + private String userName; + @ApiModelProperty("用户昵称") + private String nickName; + @ApiModelProperty("点赞状态") + private Integer likeStatus; + @ApiModelProperty("收藏状态") + private Integer collectStatus; + @ApiModelProperty("评论状态") + private Integer commentStatus; + @ApiModelProperty("创建时间") + private Date createTime; + @ApiModelProperty("更新时间") + private Date updateTime; + @ApiModelProperty("逻辑删除,0未删除,1已删除") + private Integer isDelete; +} + diff --git a/src/main/java/com/kwan/springbootkwan/entity/dto/CsdnArticleInfoDTO.java b/src/main/java/com/kwan/springbootkwan/entity/dto/CsdnArticleInfoDTO.java new file mode 100644 index 0000000..cbb08ba --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/entity/dto/CsdnArticleInfoDTO.java @@ -0,0 +1,46 @@ +package com.kwan.springbootkwan.entity.dto; + +import com.baomidou.mybatisplus.extension.activerecord.Model; +import com.kwan.springbootkwan.entity.CsdnArticleInfo; +import com.kwan.springbootkwan.mapstruct.FromConverter; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +import java.util.Date; + +@Data +@ApiModel("csdn文章DTO") +public class CsdnArticleInfoDTO extends Model { + + @ApiModelProperty("主键id") + private Integer id; + @ApiModelProperty("文章id") + private String articleId; + @ApiModelProperty("文章URL") + private String articleUrl; + @ApiModelProperty("用户名称") + private String userName; + @ApiModelProperty("用户昵称") + private String nickName; + @ApiModelProperty("点赞状态") + private Integer likeStatus; + @ApiModelProperty("收藏状态") + private Integer collectStatus; + @ApiModelProperty("评论状态") + private Integer commentStatus; + @ApiModelProperty("创建时间") + private Date createTime; + @ApiModelProperty("更新时间") + private Date updateTime; + @ApiModelProperty("逻辑删除,0未删除,1已删除") + private Integer isDelete; + + @Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) + public interface Converter extends FromConverter { + Converter INSTANCE = Mappers.getMapper(Converter.class); + } +} \ No newline at end of file diff --git a/src/main/java/com/kwan/springbootkwan/entity/query/CsdnArticleInfoQuery.java b/src/main/java/com/kwan/springbootkwan/entity/query/CsdnArticleInfoQuery.java new file mode 100644 index 0000000..13edfe8 --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/entity/query/CsdnArticleInfoQuery.java @@ -0,0 +1,27 @@ +package com.kwan.springbootkwan.entity.query; + +import com.kwan.springbootkwan.entity.BasePage; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +@ApiModel("csdn文章查询参数类") +public class CsdnArticleInfoQuery extends BasePage { + @ApiModelProperty("主键id") + private Integer id; + @ApiModelProperty("用户code") + private String userName; + @ApiModelProperty("CSDN用户名称") + private String nickName; + @ApiModelProperty("CSDN文章id") + private String articleId; + @ApiModelProperty("点赞状态") + private Integer likeStatus = 0; + @ApiModelProperty("收藏状态") + private Integer collectStatus = 0; + @ApiModelProperty("评论状态") + private Integer commentStatus = 0; + @ApiModelProperty("添加类型") + private Integer addType; +} \ No newline at end of file diff --git a/src/main/java/com/kwan/springbootkwan/service/CsdnArticleInfoService.java b/src/main/java/com/kwan/springbootkwan/service/CsdnArticleInfoService.java new file mode 100644 index 0000000..7144dc7 --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/service/CsdnArticleInfoService.java @@ -0,0 +1,15 @@ +package com.kwan.springbootkwan.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.kwan.springbootkwan.entity.CsdnArticleInfo; + +/** + * csdn文章信息(CsdnArticleInfo)表服务接口 + * + * @author makejava + * @since 2023-10-28 01:58:46 + */ +public interface CsdnArticleInfoService extends IService { + +} + diff --git a/src/main/java/com/kwan/springbootkwan/service/impl/CsdnArticleInfoServiceImpl.java b/src/main/java/com/kwan/springbootkwan/service/impl/CsdnArticleInfoServiceImpl.java new file mode 100644 index 0000000..cded008 --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/service/impl/CsdnArticleInfoServiceImpl.java @@ -0,0 +1,19 @@ +package com.kwan.springbootkwan.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.kwan.springbootkwan.dao.CsdnArticleInfoDao; +import com.kwan.springbootkwan.entity.CsdnArticleInfo; +import com.kwan.springbootkwan.service.CsdnArticleInfoService; +import org.springframework.stereotype.Service; + +/** + * csdn文章信息(CsdnArticleInfo)表服务实现类 + * + * @author makejava + * @since 2023-10-28 01:58:46 + */ +@Service("csdnArticleInfoService") +public class CsdnArticleInfoServiceImpl extends ServiceImpl implements CsdnArticleInfoService { + +} + -- GitLab