From bc3b900575a22bb515337411e53a9edd0ec510e8 Mon Sep 17 00:00:00 2001 From: wangqing <408564126@qq.com> Date: Wed, 24 Jul 2024 19:36:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?release-=E5=A2=9E=E5=8A=A0=E4=B8=93?= =?UTF-8?q?=E6=A0=8F=E6=96=87=E7=AB=A0=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../music/controller/CMSEssayController.java | 81 +++++++++++++++++++ .../music/controller/EssayController.java | 41 ++++++++++ .../java/com/luoo/music/dao/EssayDao.java | 14 ++++ .../main/java/com/luoo/music/pojo/Essay.java | 59 ++++++++++++++ .../com/luoo/music/service/EssayService.java | 51 ++++++++++++ .../src/main/resources/sql/20240724.sql | 19 +++++ 6 files changed, 265 insertions(+) create mode 100644 luoo_music/src/main/java/com/luoo/music/controller/CMSEssayController.java create mode 100644 luoo_music/src/main/java/com/luoo/music/controller/EssayController.java create mode 100644 luoo_music/src/main/java/com/luoo/music/dao/EssayDao.java create mode 100644 luoo_music/src/main/java/com/luoo/music/pojo/Essay.java create mode 100644 luoo_music/src/main/java/com/luoo/music/service/EssayService.java create mode 100644 luoo_music/src/main/resources/sql/20240724.sql diff --git a/luoo_music/src/main/java/com/luoo/music/controller/CMSEssayController.java b/luoo_music/src/main/java/com/luoo/music/controller/CMSEssayController.java new file mode 100644 index 0000000..c22c26f --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/controller/CMSEssayController.java @@ -0,0 +1,81 @@ +package com.luoo.music.controller; + + +import annotation.GlobalInterceptor; +import api.PageResult; +import api.Result; +import com.luoo.music.pojo.Essay; +import com.luoo.music.service.EssayService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.web.bind.annotation.*; + +/** + * 专栏文章后台管理Controller + * author: wangqing + */ +@RestController +@CrossOrigin +@Api(tags = "雀乐专栏文章后台管理") +@RequestMapping("/cms/essay") +public class CMSEssayController { + + @Autowired + private EssayService essayService; + + + @ApiOperation(value = "获取专栏文章列表",notes = "获取专栏文章列表,category=0代表全部文章, 1代表荐碟,2代表专访,3代表言之,4代表她说") + @GetMapping("/search/{category}/{page}/{size}") + public Result search(@PathVariable Integer category, @PathVariable int page, @PathVariable int size){ + Page pageData = null; + if(category == 0){ + pageData = essayService.search(page, size); + }else{ + pageData = essayService.getByCategory(category, page, size); + } + return Result.success(new PageResult(pageData.getTotalElements(),pageData.getContent())); + } + + + @ApiOperation("添加专栏文章") + @PostMapping + public Result add(@RequestBody Essay essay) { + essayService.add(essay); + return Result.success(); + } + + @ApiOperation("修改专栏文章") + @PutMapping("/{id}") + public Result update(@PathVariable String id, @RequestBody Essay essay) { + essay.setId(id); + essayService.update(essay); + return Result.success(); + } + + @ApiOperation("删除专栏文章") + @DeleteMapping("/{id}") + public Result delete(@PathVariable String id) { + essayService.delete(id); + return Result.success(); + } + +// @ApiOperation("批量删除专栏文章") +// @DeleteMapping +// public Result deleteBatch(@RequestBody String[] ids) { +// essayService.deleteBatch(ids); +// return Result.success(); +// } + + @ApiOperation("根据ID获取专栏文章") + @GetMapping("/{id}") + public Result getById(@PathVariable String id) { + Essay essay = essayService.getById(id); + return Result.success(essay); + } + + +} + + diff --git a/luoo_music/src/main/java/com/luoo/music/controller/EssayController.java b/luoo_music/src/main/java/com/luoo/music/controller/EssayController.java new file mode 100644 index 0000000..1047304 --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/controller/EssayController.java @@ -0,0 +1,41 @@ +package com.luoo.music.controller; + + +import api.PageResult; +import api.Result; +import com.luoo.music.pojo.Essay; +import com.luoo.music.service.EssayService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.web.bind.annotation.*; + +/** + * 专栏文章前台功能 + * author: wangqing + */ + +@RestController +@CrossOrigin +@Api(tags = "雀乐专栏文章前台功能") +@RequestMapping("/essay") +public class EssayController { + + @Autowired + private EssayService essayService; + + @ApiOperation(value = "获取专栏文章列表",notes = "获取专栏文章列表,category=0代表全部文章, 1代表荐碟,2代表专访,3代表言之,4代表她说") + @GetMapping("/search/{category}/{page}/{size}") + public Result search(@PathVariable Integer category, @PathVariable int page, @PathVariable int size){ + Page pageData = null; + if(category == 0){ + pageData = essayService.search(page, size); + }else{ + pageData = essayService.getByCategory(category, page, size); + } + return Result.success(new PageResult(pageData.getTotalElements(),pageData.getContent())); + } + +} + diff --git a/luoo_music/src/main/java/com/luoo/music/dao/EssayDao.java b/luoo_music/src/main/java/com/luoo/music/dao/EssayDao.java new file mode 100644 index 0000000..717e6fd --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/dao/EssayDao.java @@ -0,0 +1,14 @@ +package com.luoo.music.dao; + +import com.luoo.music.pojo.Essay; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +public interface EssayDao extends JpaRepository , JpaSpecificationExecutor { + + public Page findAllByOrderByCreateTimeDesc(Pageable pageable); + + Page findAllByCategoryOrderByCreateTimeDesc(int category, Pageable pageable); +} diff --git a/luoo_music/src/main/java/com/luoo/music/pojo/Essay.java b/luoo_music/src/main/java/com/luoo/music/pojo/Essay.java new file mode 100644 index 0000000..dead4f2 --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/pojo/Essay.java @@ -0,0 +1,59 @@ +package com.luoo.music.pojo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.persistence.Entity; +import javax.persistence.EntityListeners; +import javax.persistence.Id; +import javax.persistence.Table; +import java.time.LocalDateTime; + +/** + * 专栏 文章实体类 + * @author wangqing + * @date 2024/07/24 + */ +@Data +@Entity +@DynamicInsert +@DynamicUpdate +@Table(name="tb_essay") +@EntityListeners(AuditingEntityListener.class) +public class Essay { + + @Id + private String id; + // 标题 + private String title; + // 简介 + private String summary; + // 阅读数 + private Integer readCount; + // 内容 + private String content; + // 作者 + private String authorId; + private String authorName; + private String authorAvatar; + // 分类 + private Integer category; + // 封面路径 + private String cover; + + @CreatedDate + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime createTime; + + @LastModifiedDate + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime updateTime; +} diff --git a/luoo_music/src/main/java/com/luoo/music/service/EssayService.java b/luoo_music/src/main/java/com/luoo/music/service/EssayService.java new file mode 100644 index 0000000..41d0204 --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/service/EssayService.java @@ -0,0 +1,51 @@ +package com.luoo.music.service; + +import com.luoo.music.dao.EssayDao; +import com.luoo.music.pojo.Essay; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import util.IdWorker; + +@Service +@Transactional +public class EssayService { + + @Autowired + private EssayDao essayDao; + + @Autowired + private IdWorker idWorker; + + public Page search(int page, int size) { + // TODO: implement search logic + Pageable pageable = PageRequest.of(page-1, size); + return essayDao.findAllByOrderByCreateTimeDesc(pageable); + } + + public void add(Essay essay) { + essay.setId(idWorker.nextId()+""); + essayDao.save(essay); + } + + public void update(Essay essay) { + essayDao.save(essay); + } + + public void delete(String id) { + essayDao.deleteById(id); + } + + public Essay getById(String id) { + + return essayDao.findById(id).get(); + } + + public Page getByCategory(int category, int page, int size) { + Pageable pageable = PageRequest.of(page-1, size); + return essayDao.findAllByCategoryOrderByCreateTimeDesc(category, pageable); + } +} diff --git a/luoo_music/src/main/resources/sql/20240724.sql b/luoo_music/src/main/resources/sql/20240724.sql new file mode 100644 index 0000000..a54f131 --- /dev/null +++ b/luoo_music/src/main/resources/sql/20240724.sql @@ -0,0 +1,19 @@ +create table tb_essay +( + id varchar(20) not null comment 'id' + primary key, + title varchar(20) null comment '标题', + summary varchar(200) null comment '摘要', + read_count int null comment '阅读数', + content text null comment '内容', + author_id varchar(20) null comment '作者id', + author_name varchar(20) null comment '作者名称', + author_avatar varchar(200) null comment '作者头像', + category int null comment '分类 1:荐碟 2 专访 3:言之 4 她说', + cover varchar(200) null comment '封面url', + create_time datetime null comment '创建时间', + update_time datetime null comment '更新时间' + +) + comment 'tb_essay'; + From e9c30cdcdc96cf91dea9f4215f4c390a0b14bcc9 Mon Sep 17 00:00:00 2001 From: wangqing <408564126@qq.com> Date: Wed, 24 Jul 2024 21:40:23 +0800 Subject: [PATCH 2/2] =?UTF-8?q?release-=E4=B8=93=E6=A0=8F=E6=96=87?= =?UTF-8?q?=E7=AB=A0=E5=A2=9E=E5=8A=A0=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../music/controller/CMSEssayController.java | 33 +++++++++++-------- .../music/controller/EssayController.java | 2 +- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/luoo_music/src/main/java/com/luoo/music/controller/CMSEssayController.java b/luoo_music/src/main/java/com/luoo/music/controller/CMSEssayController.java index c22c26f..d02293e 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/CMSEssayController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/CMSEssayController.java @@ -6,8 +6,7 @@ import api.PageResult; import api.Result; import com.luoo.music.pojo.Essay; import com.luoo.music.service.EssayService; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.web.bind.annotation.*; @@ -26,11 +25,11 @@ public class CMSEssayController { private EssayService essayService; - @ApiOperation(value = "获取专栏文章列表",notes = "获取专栏文章列表,category=0代表全部文章, 1代表荐碟,2代表专访,3代表言之,4代表她说") + @ApiOperation(value = "1.获取专栏文章列表",notes = "获取专栏文章列表,category=0代表全部文章, 1代表荐碟,2代表专访,3代表言之,4代表她说") @GetMapping("/search/{category}/{page}/{size}") - public Result search(@PathVariable Integer category, @PathVariable int page, @PathVariable int size){ + public Result search(@ApiParam(value = "分类,category=0代表全部文章, 1代表荐碟,2代表专访,3代表言之,4代表她说", required = true) @PathVariable Integer category, @PathVariable int page, @PathVariable int size){ Page pageData = null; - if(category == 0){ + if(category == 0 || category == null){ pageData = essayService.search(page, size); }else{ pageData = essayService.getByCategory(category, page, size); @@ -40,15 +39,25 @@ public class CMSEssayController { @ApiOperation("添加专栏文章") + @GlobalInterceptor(checkAdminLogin = true) @PostMapping - public Result add(@RequestBody Essay essay) { + @ApiImplicitParams({ + @ApiImplicitParam(name = "essay", value = "专栏文章对象", required = true, dataType = "Essay", paramType = "body"), + @ApiImplicitParam(name = "Authorization", value = "authorization", required = true, dataType = "String", paramType = "header") + }) + public Result add(@RequestHeader(value="Authorization",required = true) String authorization , @RequestBody Essay essay) { essayService.add(essay); return Result.success(); } @ApiOperation("修改专栏文章") @PutMapping("/{id}") - public Result update(@PathVariable String id, @RequestBody Essay essay) { + @GlobalInterceptor(checkAdminLogin = true) + @ApiImplicitParams({ + @ApiImplicitParam(name = "essay", value = "专栏文章对象", required = true, dataType = "Essay", paramType = "body"), + @ApiImplicitParam(name = "Authorization", value = "authorization", required = true, dataType = "String", paramType = "header") + }) + public Result update(@RequestHeader(value="Authorization",required = true) String authorization ,@PathVariable String id, @RequestBody Essay essay) { essay.setId(id); essayService.update(essay); return Result.success(); @@ -56,17 +65,13 @@ public class CMSEssayController { @ApiOperation("删除专栏文章") @DeleteMapping("/{id}") - public Result delete(@PathVariable String id) { + @GlobalInterceptor(checkAdminLogin = true) + public Result delete(@RequestHeader(value="Authorization",required = true) String authorization,@PathVariable String id) { essayService.delete(id); return Result.success(); } -// @ApiOperation("批量删除专栏文章") -// @DeleteMapping -// public Result deleteBatch(@RequestBody String[] ids) { -// essayService.deleteBatch(ids); -// return Result.success(); -// } + @ApiOperation("根据ID获取专栏文章") @GetMapping("/{id}") diff --git a/luoo_music/src/main/java/com/luoo/music/controller/EssayController.java b/luoo_music/src/main/java/com/luoo/music/controller/EssayController.java index 1047304..a16bed1 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/EssayController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/EssayController.java @@ -25,7 +25,7 @@ public class EssayController { @Autowired private EssayService essayService; - @ApiOperation(value = "获取专栏文章列表",notes = "获取专栏文章列表,category=0代表全部文章, 1代表荐碟,2代表专访,3代表言之,4代表她说") + @ApiOperation(value = "1 获取专栏文章列表",notes = "获取专栏文章列表,category=0代表全部文章, 1代表荐碟,2代表专访,3代表言之,4代表她说") @GetMapping("/search/{category}/{page}/{size}") public Result search(@PathVariable Integer category, @PathVariable int page, @PathVariable int size){ Page pageData = null;