网站首页

master
叮叮咚咚 6 months ago
parent fc7daeee79
commit 00b19991c5
  1. 15
      src/main/java/com/teaching/backend/controller/courses/CoursesController.java
  2. 6
      src/main/java/com/teaching/backend/mapper/courses/CoursesMapper.java
  3. 12
      src/main/java/com/teaching/backend/model/vo/CoursesVO.java
  4. 4
      src/main/java/com/teaching/backend/service/courses/ICoursesService.java
  5. 58
      src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java
  6. 2
      src/main/resources/application.yml

@ -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;
/**
* <p>
@ -33,6 +35,19 @@ public class CoursesController {
@Autowired
ICoursesService coursesService;
@ApiOperation("网站首页")
@GetMapping("/index")
public BaseResponse<Map<String,Object>> getData(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize) {
List<CoursesVO> coursesVo = coursesService.getPagePageSize(page, pageSize);
long totalcount = coursesService.count();
long toatlPages = (int) Math.ceil((double)totalcount / pageSize);
Map<String,Object> 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")

@ -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;
/**
* <p>
@ -14,5 +18,7 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface CoursesMapper extends BaseMapper<Courses> {
@Select("SELECT * FROM courses LIMIT #{start}, #{pageSize}")
List<Courses> getItemsByPage(@Param("start") int start, @Param("pageSize") int pageSize);
}

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

@ -27,4 +27,8 @@ public interface ICoursesService extends IService<Courses> {
void deleteBatchByIds(String id);
int countHours(String id);
List<CoursesVO> getPagePageSize(int page, int pageSize);
}

@ -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;
/**
* <p>
@ -115,4 +117,60 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
}
@Override
public List<CoursesVO> getPagePageSize(int page, int pageSize) {
int startIndex = (page-1) * pageSize;
List<Courses> list = coursesMapper.getItemsByPage(startIndex, pageSize);
// List<Courses> list = coursesMapper.selectList(null);
List<CoursesVO> 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;
}
}

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

Loading…
Cancel
Save