diff --git a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java index 9bdde4c..4206336 100644 --- a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java +++ b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java @@ -16,7 +16,9 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** *

@@ -33,6 +35,19 @@ public class CoursesController { @Autowired ICoursesService coursesService; + @ApiOperation("网站首页") + @GetMapping("/index") + public BaseResponse> getData(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize) { + List coursesVo = coursesService.getPagePageSize(page, pageSize); + long totalcount = coursesService.count(); + long toatlPages = (int) Math.ceil((double)totalcount / pageSize); + Map objectMap = new HashMap<>(); + objectMap.put("content",coursesVo); + objectMap.put("totalcount", totalcount); + objectMap.put("totalPages", toatlPages); + objectMap.put("currentPage", page); + return ResultUtils.success(objectMap); + } @ApiOperation("新增课程--同步新增课程的总体目标") @PostMapping("/addcourse") diff --git a/src/main/java/com/teaching/backend/mapper/courses/CoursesMapper.java b/src/main/java/com/teaching/backend/mapper/courses/CoursesMapper.java index d3574bf..2a01805 100644 --- a/src/main/java/com/teaching/backend/mapper/courses/CoursesMapper.java +++ b/src/main/java/com/teaching/backend/mapper/courses/CoursesMapper.java @@ -3,6 +3,10 @@ package com.teaching.backend.mapper.courses; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.teaching.backend.model.entity.courses.Courses; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; /** *

@@ -14,5 +18,7 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface CoursesMapper extends BaseMapper { + @Select("SELECT * FROM courses LIMIT #{start}, #{pageSize}") + List getItemsByPage(@Param("start") int start, @Param("pageSize") int pageSize); } diff --git a/src/main/java/com/teaching/backend/model/vo/CoursesVO.java b/src/main/java/com/teaching/backend/model/vo/CoursesVO.java index 3a14a6e..4c1920b 100644 --- a/src/main/java/com/teaching/backend/model/vo/CoursesVO.java +++ b/src/main/java/com/teaching/backend/model/vo/CoursesVO.java @@ -45,4 +45,16 @@ public class CoursesVO { @ApiModelProperty(value = "课程学时",required = true) private Integer classhours; + @ApiModelProperty(value = "课程描述",required = true) + private String description; + + @ApiModelProperty(value = "课程总学时",required = true) + private Integer totalHours; + + @ApiModelProperty(value = "课程章节总数",required = true) + private Integer totalchapter; + + @ApiModelProperty(value = "课程知识点总数",required = true) + private Integer totalKnow; + } diff --git a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java index c4705e6..f1ea1ee 100644 --- a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java +++ b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java @@ -27,4 +27,8 @@ public interface ICoursesService extends IService { void deleteBatchByIds(String id); + + int countHours(String id); + + List getPagePageSize(int page, int pageSize); } diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java index e029902..b4c3519 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java @@ -1,6 +1,7 @@ package com.teaching.backend.service.impl.courses; +import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -25,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; import java.util.List; +import java.util.stream.Collectors; /** *

@@ -115,4 +117,60 @@ public class CoursesServiceImpl extends ServiceImpl impl } + @Override + public List getPagePageSize(int page, int pageSize) { + int startIndex = (page-1) * pageSize; + List list = coursesMapper.getItemsByPage(startIndex, pageSize); +// List list = coursesMapper.selectList(null); + List coursesVo = BeanUtil.copyToList(list, CoursesVO.class); + coursesVo = coursesVo.stream().map((item) -> { + + item.setTotalHours(countHours(item.getId())); + item.setTotalchapter(100); + item.setTotalKnow(100); +// if (StringUtils.isBlank(item.getName()) || +// StringUtils.isBlank(item.getDescription()) ){ +// throw new BusinessException(ErrorCode.OPERATION_ERROR,"数据格式有问题,请修改"); +// } + return item; + }).collect(Collectors.toList()); + return coursesVo; + + } + + @Override + public int countHours(String id) { + Courses courses = coursesMapper.selectById(id); + + Integer classhours = 0; + Integer theoryhours = 0; + Integer practicehours = 0; + Integer experimenthours = 0; + Integer otherhours = 0; + if (courses.getClasshours() != null) { + classhours = courses.getClasshours(); + } + + if (courses.getTheoryhours() != null) { + theoryhours = courses.getTheoryhours(); + } + + if (courses.getPracticehours() != null) { + practicehours = courses.getPracticehours(); + } + + if (courses.getExperimenthours() != null) { + experimenthours = courses.getExperimenthours(); + } + + if (courses.getOtherhours() != null) { + otherhours = courses.getOtherhours(); + } + int total = classhours + theoryhours + practicehours + experimenthours + otherhours; + + return total; + + } + + } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index e98798c..2a97162 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -10,7 +10,7 @@ spring: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/teaching_db username: root - password: root + password: 1234567788 mybatis: configuration: map-underscore-to-camel-case: true