From 2e072078b3c63c7f48f342b63fa66a15566c8b3d Mon Sep 17 00:00:00 2001 From: wanghb <17803890193@163.com> Date: Fri, 11 Aug 2023 17:20:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=8E=E7=AB=AF=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../course/controller/CourseController.java | 35 +++-- .../zhiyun03/course/mapper/CourseMapper.java | 13 +- .../course/service/CourseService.java | 27 ++-- .../service/impl/CourseServiceImpl.java | 45 ++++-- .../controller/DownloadController.java | 4 +- .../invite/controller/InviteController.java | 2 +- .../serve/controller/ServeController.java | 2 +- .../zhiyun03/utils/common/JsonResult.java | 3 + .../templates/layui-v2.6.8/courseList.html | 146 ++++++------------ .../templates/layui-v2.6.8/downloadList.html | 130 ++++++++++++++++ .../templates/layui-v2.6.8/index.html | 19 +-- .../templates/layui-v2.6.8/inviteList.html | 116 ++++++++++++++ .../templates/layui-v2.6.8/serveList.html | 131 ++++++++++++++++ 13 files changed, 528 insertions(+), 145 deletions(-) create mode 100644 src/main/resources/templates/layui-v2.6.8/downloadList.html create mode 100644 src/main/resources/templates/layui-v2.6.8/inviteList.html create mode 100644 src/main/resources/templates/layui-v2.6.8/serveList.html diff --git a/src/main/java/com/zhiyun/zhiyun03/course/controller/CourseController.java b/src/main/java/com/zhiyun/zhiyun03/course/controller/CourseController.java index 040e035..d1788dc 100644 --- a/src/main/java/com/zhiyun/zhiyun03/course/controller/CourseController.java +++ b/src/main/java/com/zhiyun/zhiyun03/course/controller/CourseController.java @@ -1,8 +1,6 @@ package com.zhiyun.zhiyun03.course.controller; -import com.zhiyun.zhiyun03.application.entity.Directory; -import com.zhiyun.zhiyun03.course.entity.Course; import com.zhiyun.zhiyun03.course.service.CourseService; import com.zhiyun.zhiyun03.course.vo.CourseVo; @@ -12,33 +10,42 @@ import com.zhiyun.zhiyun03.utils.common.JsonResult; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import io.swagger.models.auth.In; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import java.util.List; + +/** + * 课程控制层 + */ @Api("课程") @RestController @RequestMapping("/api/course") public class CourseController { + /** + * 引入service层 + */ @Resource private CourseService courseService; - + /** + * 查询分页课程信息 + */ @ApiOperation("查询课程") @GetMapping("/queryCourse") public JsonResult> queryCourse(@ApiParam @RequestParam(value = "page",required = false,defaultValue = "1")Integer page, - @ApiParam @RequestParam(value = "limit",required = false,defaultValue = "1")Integer limit ){ + @ApiParam @RequestParam(value = "limit",required = false,defaultValue = "5")Integer limit ){ PageVO lists = courseService.queryCourse(page,limit); - return JsonResult.success(lists); + return JsonResult.success(lists).setCount(lists.getTotal()); } + /** + * 根据ID查询课程 + */ @ApiOperation("根据ID查询课程") @GetMapping("/queryCourseById") public JsonResult queryCourseById(Integer id){ @@ -50,7 +57,9 @@ public class CourseController { - + /** + * 课程添加 + */ @ApiOperation("课程添加") @PostMapping("/addCourse") public JsonResult addCourse(CourseVo courseVo){ @@ -59,13 +68,19 @@ public class CourseController { return JsonResult.success(); } + /** + * 根据ID删除课程 + */ @ApiOperation("删除课程") - @DeleteMapping("delCourseById") + @GetMapping("delCourseById") public JsonResult delCourseById(Integer id){ courseService.delCourseById(id); return JsonResult.success(); } + /** + * 更新课程 + */ @ApiOperation("更新课程") @PostMapping("updateById") public JsonResult updateById(CourseVo courseVo){ diff --git a/src/main/java/com/zhiyun/zhiyun03/course/mapper/CourseMapper.java b/src/main/java/com/zhiyun/zhiyun03/course/mapper/CourseMapper.java index cef02f2..a55f6f1 100644 --- a/src/main/java/com/zhiyun/zhiyun03/course/mapper/CourseMapper.java +++ b/src/main/java/com/zhiyun/zhiyun03/course/mapper/CourseMapper.java @@ -11,12 +11,23 @@ import java.util.List; @Mapper public interface CourseMapper extends BaseMapper { - + /** + * 查询所有课程 + */ List queryCourse(); + /** + * 根据id查询课程 + */ CourseVo queryCourseById(Integer id); + /** + * 更新课程 + */ int updateCourseById(Course course); + /** + * 根据课程名 + */ int selectByName(String courseName); } diff --git a/src/main/java/com/zhiyun/zhiyun03/course/service/CourseService.java b/src/main/java/com/zhiyun/zhiyun03/course/service/CourseService.java index bf40208..ad42f6d 100644 --- a/src/main/java/com/zhiyun/zhiyun03/course/service/CourseService.java +++ b/src/main/java/com/zhiyun/zhiyun03/course/service/CourseService.java @@ -10,24 +10,29 @@ import org.springframework.web.bind.annotation.RequestParam; import java.util.List; public interface CourseService extends IService { -// public void addCourse(Course course); -// -// void delCourseById(Integer id); -// -// void updateById(Course course); - - /* - * 分页查询课程 - * */ + + /** + * 查询分页课程信息 + */ PageVO queryCourse(Integer page, Integer limit ); + /** + * 课程添加 + */ int addCourse(CourseVo courseVo); + /** + * 根据ID删除课程 + */ void delCourseById(Integer id); + + /** + * 更新课程 + */ int updateById(CourseVo courseVo); - /* + /** * 根据ID查询课程 - * */ + */ CourseVo queryCourseById(Integer id); } diff --git a/src/main/java/com/zhiyun/zhiyun03/course/service/impl/CourseServiceImpl.java b/src/main/java/com/zhiyun/zhiyun03/course/service/impl/CourseServiceImpl.java index fa75935..2375b75 100644 --- a/src/main/java/com/zhiyun/zhiyun03/course/service/impl/CourseServiceImpl.java +++ b/src/main/java/com/zhiyun/zhiyun03/course/service/impl/CourseServiceImpl.java @@ -17,17 +17,25 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.List; +/** + * 服务层 + */ @Service public class CourseServiceImpl extends ServiceImpl implements CourseService { + /** + * 引入CourseMapper + */ @Resource private CourseMapper courseMapper; - + /** + * 引入DirectoryMapper + */ @Resource private DirectoryMapper directoryMapper; /** - * 课程中心查询 + * 分页查询课程中心 */ @Override public PageVO queryCourse(Integer page, Integer limit) { @@ -62,7 +70,7 @@ public class CourseServiceImpl extends ServiceImpl implemen { throw new ServiceException("400","课程添加失败"); } - + //查询名称查询课程 int sum = courseMapper.selectByName(courseVo.getCourseName()); if (sum>0) { @@ -74,18 +82,20 @@ public class CourseServiceImpl extends ServiceImpl implemen BeanUtils.copyProperties(courseVo,course); + //获取目录名称 String dirName = courseVo.getDirName(); - + //查询目录id,并赋值给course Integer id = directoryMapper.selectByName(dirName); course.setDirId(id); - + //课程插入 int count = courseMapper.insert(course); - System.out.println("count====="+count); - if (count<0) + + if (count>0) { - throw new ServiceException("400","课程添加失败"); + return count; + }else { + throw new ServiceException("400", "课程添加失败"); } - return count; } @@ -95,6 +105,11 @@ public class CourseServiceImpl extends ServiceImpl implemen */ @Override public void delCourseById(Integer id) { + if (id==null) + { + throw new ServiceException("405", "查询不到课程信息"); + } + //根据id删除课程 courseMapper.deleteById(id); } @@ -103,6 +118,10 @@ public class CourseServiceImpl extends ServiceImpl implemen */ @Override public int updateById(CourseVo courseVo) { + if (courseVo==null) + { + throw new ServiceException("400","课程更新失败"); + } //将vo值赋给course Course course = new Course(); BeanUtils.copyProperties(courseVo,course); @@ -114,7 +133,7 @@ public class CourseServiceImpl extends ServiceImpl implemen int count = courseMapper.updateCourseById(course); if (count<0) { - throw new ServiceException("400","课程更新失败"); + throw new ServiceException("402","课程更新失败"); } return count; @@ -125,6 +144,12 @@ public class CourseServiceImpl extends ServiceImpl implemen */ @Override public CourseVo queryCourseById(Integer id) { + + if (id== null) + { + throw new ServiceException("405", "查询不到课程信息"); + } + //根据id查找数据 CourseVo courseVo = courseMapper.queryCourseById(id); if (courseVo==null) diff --git a/src/main/java/com/zhiyun/zhiyun03/download/controller/DownloadController.java b/src/main/java/com/zhiyun/zhiyun03/download/controller/DownloadController.java index 4306fcc..bb6b2f4 100644 --- a/src/main/java/com/zhiyun/zhiyun03/download/controller/DownloadController.java +++ b/src/main/java/com/zhiyun/zhiyun03/download/controller/DownloadController.java @@ -33,7 +33,7 @@ public class DownloadController { PageVO lists = downloadService.queryDownload(page,limit); - return JsonResult.success(lists); + return JsonResult.success(lists).setCount(lists.getTotal()); } @ApiOperation("添加下载") @@ -73,7 +73,7 @@ public class DownloadController { @ApiOperation("删除下载") - @PostMapping("/delDownload") + @GetMapping("/delDownload") public JsonResult delDownload(Integer id){ int count = downloadService.delDownload(id); return JsonResult.success(); diff --git a/src/main/java/com/zhiyun/zhiyun03/invite/controller/InviteController.java b/src/main/java/com/zhiyun/zhiyun03/invite/controller/InviteController.java index b5c8ba8..74b043c 100644 --- a/src/main/java/com/zhiyun/zhiyun03/invite/controller/InviteController.java +++ b/src/main/java/com/zhiyun/zhiyun03/invite/controller/InviteController.java @@ -48,7 +48,7 @@ public class InviteController { } @ApiOperation("删除课程") - @DeleteMapping("delInviteById") + @GetMapping("delInviteById") public JsonResult delInviteById(Integer id){ inviteService.delInviteById(id); return JsonResult.success(); diff --git a/src/main/java/com/zhiyun/zhiyun03/serve/controller/ServeController.java b/src/main/java/com/zhiyun/zhiyun03/serve/controller/ServeController.java index 8bbf925..f30545e 100644 --- a/src/main/java/com/zhiyun/zhiyun03/serve/controller/ServeController.java +++ b/src/main/java/com/zhiyun/zhiyun03/serve/controller/ServeController.java @@ -78,7 +78,7 @@ public class ServeController { @ApiOperation("删除服务") - @PostMapping("/delServe") + @GetMapping("/delServe") public JsonResult delServe(Integer id){ int count = serveService.delServe(id); return JsonResult.success(); diff --git a/src/main/java/com/zhiyun/zhiyun03/utils/common/JsonResult.java b/src/main/java/com/zhiyun/zhiyun03/utils/common/JsonResult.java index bbf4e0b..94ef153 100644 --- a/src/main/java/com/zhiyun/zhiyun03/utils/common/JsonResult.java +++ b/src/main/java/com/zhiyun/zhiyun03/utils/common/JsonResult.java @@ -1,13 +1,16 @@ package com.zhiyun.zhiyun03.utils.common; import lombok.Data; +import lombok.experimental.Accessors; @Data +@Accessors(chain = true) public class JsonResult { private String code; private String msg; private T data; + private Long count; public static JsonResult success() { diff --git a/src/main/resources/templates/layui-v2.6.8/courseList.html b/src/main/resources/templates/layui-v2.6.8/courseList.html index a3b4daf..f58ca0b 100644 --- a/src/main/resources/templates/layui-v2.6.8/courseList.html +++ b/src/main/resources/templates/layui-v2.6.8/courseList.html @@ -6,7 +6,7 @@ - + @@ -15,9 +15,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - diff --git a/src/main/resources/templates/layui-v2.6.8/downloadList.html b/src/main/resources/templates/layui-v2.6.8/downloadList.html new file mode 100644 index 0000000..1b61abf --- /dev/null +++ b/src/main/resources/templates/layui-v2.6.8/downloadList.html @@ -0,0 +1,130 @@ + + + + + Layui + + + + + + + + +
+ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/layui-v2.6.8/index.html b/src/main/resources/templates/layui-v2.6.8/index.html index fc35088..37424e2 100644 --- a/src/main/resources/templates/layui-v2.6.8/index.html +++ b/src/main/resources/templates/layui-v2.6.8/index.html @@ -54,23 +54,24 @@ diff --git a/src/main/resources/templates/layui-v2.6.8/inviteList.html b/src/main/resources/templates/layui-v2.6.8/inviteList.html new file mode 100644 index 0000000..6698f8c --- /dev/null +++ b/src/main/resources/templates/layui-v2.6.8/inviteList.html @@ -0,0 +1,116 @@ + + + + + Layui + + + + + + + + +
+ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/layui-v2.6.8/serveList.html b/src/main/resources/templates/layui-v2.6.8/serveList.html new file mode 100644 index 0000000..36dd2b6 --- /dev/null +++ b/src/main/resources/templates/layui-v2.6.8/serveList.html @@ -0,0 +1,131 @@ + + + + + Layui + + + + + + + + +
+ + + + + + + + + + + + + }); + + + + \ No newline at end of file