parent
2cc709e009
commit
0cd1adf54c
18 changed files with 683 additions and 272 deletions
@ -1,12 +1,54 @@ |
||||
package com.teaching.backend.controller.records; |
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.teaching.backend.common.BaseResponse; |
||||
import com.teaching.backend.filter.ValidateParams; |
||||
import com.teaching.backend.model.entity.records.CourseLearningRecord; |
||||
import com.teaching.backend.service.impl.records.CourseLearningRecordServiceImpl; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.List; |
||||
|
||||
@RestController |
||||
@RequestMapping("/api/courselearingRecord") |
||||
@RequestMapping("/api/courselearingrecord") |
||||
public class CourseLearningRecordController { |
||||
@Resource |
||||
private CourseLearningRecordServiceImpl courseLearningRecordService; |
||||
|
||||
@ApiOperation("添加课程学习记录") |
||||
@ValidateParams({"userId","courseId"}) |
||||
@PostMapping("/saverecords") |
||||
public BaseResponse<String> saveCoursesRecords(@RequestBody CourseLearningRecord courseLearningRecord){ |
||||
return courseLearningRecordService.saveCoursesRecords(courseLearningRecord); |
||||
} |
||||
|
||||
/** |
||||
* 获取当前登录用户的学习课程记录 |
||||
* @param pagenum |
||||
* @param pagesize |
||||
* @return |
||||
*/ |
||||
@ApiOperation("根据用户id查询学习记录") |
||||
@ValidateParams({"userId"}) |
||||
@GetMapping("/page") |
||||
public BaseResponse<Page> getAll(@RequestParam(value = "pagenum", defaultValue = "1") int pagenum, |
||||
@RequestParam(value = "pagesize", defaultValue = "10") int pagesize, |
||||
@RequestParam String userId){ |
||||
return courseLearningRecordService.getPage(pagenum, pagesize, userId); |
||||
} |
||||
|
||||
/** |
||||
* 根据ids删除 |
||||
* @param ids |
||||
* @return |
||||
*/ |
||||
@ApiOperation("学习记录删除") |
||||
@DeleteMapping("/delete") |
||||
public BaseResponse<String> deleteRecords(@RequestParam List<Long> ids){ |
||||
return courseLearningRecordService.removeCoursesRecords(ids); |
||||
} |
||||
|
||||
} |
||||
|
@ -0,0 +1,31 @@ |
||||
package com.teaching.backend.controller.records; |
||||
|
||||
import com.teaching.backend.common.BaseResponse; |
||||
import com.teaching.backend.common.ResultUtils; |
||||
import com.teaching.backend.filter.ValidateParams; |
||||
import com.teaching.backend.model.entity.records.CourseLearningRecord; |
||||
import com.teaching.backend.model.entity.records.KnowledgeLearningRecord; |
||||
import com.teaching.backend.service.impl.records.KnowledgeLearningRecordServiceImpl; |
||||
import io.swagger.annotations.ApiOperation; |
||||
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.RestController; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
@RestController |
||||
@RequestMapping("/api/knowledgelearning") |
||||
public class KnowledgeLearningRecordController { |
||||
@Resource |
||||
private KnowledgeLearningRecordServiceImpl knowledgeLearningRecordService; |
||||
|
||||
@ApiOperation("添加知识点学习记录") |
||||
// @ValidateParams({"userId","type","coursesId"})
|
||||
@PostMapping("/saverecords") |
||||
public BaseResponse<String> saveKnowledgeRecords(@RequestBody KnowledgeLearningRecord knowledgeLearningRecord){ |
||||
knowledgeLearningRecordService.save(knowledgeLearningRecord); |
||||
return ResultUtils.success("添加成功"); |
||||
} |
||||
|
||||
} |
@ -1,89 +1,105 @@ |
||||
//package com.teaching.backend.controller.records;
|
||||
//
|
||||
//
|
||||
//import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
|
||||
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
//import com.teaching.backend.common.BaseResponse;
|
||||
//import com.teaching.backend.common.ResultUtils;
|
||||
//
|
||||
//import com.teaching.backend.filter.ValidateParams;
|
||||
//import com.teaching.backend.model.entity.records.LearningRecords;
|
||||
//import com.teaching.backend.model.vo.records.LearningRecordsVo;
|
||||
//import com.teaching.backend.service.impl.records.LearningRecordsServiceImpl;
|
||||
//import io.swagger.annotations.ApiOperation;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.ui.Model;
|
||||
//import org.springframework.web.bind.annotation.*;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//
|
||||
//@RestController
|
||||
//@RequestMapping("/api/learningrecords")
|
||||
//public class LearningRecordsController {
|
||||
//
|
||||
// @Autowired
|
||||
// private LearningRecordsServiceImpl learningRecordsService;
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 获取当前登录用户的学习记录
|
||||
// * @param pagenum
|
||||
// * @param pagesize
|
||||
// * @return
|
||||
// */
|
||||
// @ApiOperation("根据用户id查询学习记录")
|
||||
// @ValidateParams({"userId"})
|
||||
// @GetMapping("/getall")
|
||||
// public BaseResponse<Page> getAll(@RequestParam(value = "pagenum", defaultValue = "1") int pagenum,
|
||||
// @RequestParam(value = "pagesize", defaultValue = "10") int pagesize,
|
||||
// @RequestParam String userId){
|
||||
// //根据用户查询
|
||||
// Page<LearningRecords> page = learningRecordsService.query()
|
||||
// .orderByDesc("time")
|
||||
// .eq("status", "1")
|
||||
// .eq("user_id", userId).page(new Page<>(pagenum, pagesize));
|
||||
// //获取当前页数据
|
||||
// List<LearningRecords> list = page.getRecords();
|
||||
// List<LearningRecordsVo> cs= learningRecordsService.getAll(list);
|
||||
//
|
||||
// long total = page.getTotal(); // 总记录数
|
||||
// Page<LearningRecordsVo> pageInfo = new Page<>(pagenum,pagesize,total);
|
||||
// pageInfo.setRecords(cs);
|
||||
// pageInfo.setPages(page.getPages());//设置总页数
|
||||
// return ResultUtils.success(pageInfo);
|
||||
// }
|
||||
//
|
||||
// @ApiOperation("查询所有")
|
||||
// @GetMapping("/all")
|
||||
// public BaseResponse<List<LearningRecords>> All(){
|
||||
//// System.out.println("学习记录:"+learningRecordsService.list());
|
||||
//
|
||||
// return ResultUtils.success(learningRecordsService.list());
|
||||
// }
|
||||
//
|
||||
// //资源类型: 1,课程学习记录,2,知识点学习记录,3课程资源学习记录
|
||||
// /**
|
||||
// * 添加课程记录
|
||||
// * @param learningRecords
|
||||
// * @return
|
||||
// */
|
||||
// @ApiOperation("添加学习记录")
|
||||
// @ValidateParams({"userId","type","coursesId"})
|
||||
// @PostMapping("/saverecords")
|
||||
// public BaseResponse<String> saveRecords(@RequestBody LearningRecords learningRecords){
|
||||
//// System.out.println(learningRecords);
|
||||
// return ResultUtils.success(learningRecordsService.saveRecords(learningRecords));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 根据id删除
|
||||
// * @param ids
|
||||
// * @return
|
||||
// */
|
||||
// @DeleteMapping("/delete")
|
||||
// //@ValidateParams({"ids"})
|
||||
// public BaseResponse<String> deleteRecords(@RequestParam List<Long> ids){
|
||||
// return ResultUtils.success(learningRecordsService.delete(ids));
|
||||
// }
|
||||
//}
|
||||
package com.teaching.backend.controller.records; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.teaching.backend.common.BaseResponse; |
||||
import com.teaching.backend.common.ResultUtils; |
||||
|
||||
import com.teaching.backend.filter.ValidateParams; |
||||
import com.teaching.backend.model.entity.records.CourseLearningRecord; |
||||
import com.teaching.backend.model.entity.records.LearningRecords; |
||||
import com.teaching.backend.model.vo.records.CourseLearningRecordsVo; |
||||
import com.teaching.backend.model.vo.records.LearningRecordsVo; |
||||
import com.teaching.backend.service.impl.records.LearningRecordsServiceImpl; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.ui.Model; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
@RestController |
||||
@RequestMapping("/api/learningrecords") |
||||
public class LearningRecordsController { |
||||
|
||||
@Autowired |
||||
private LearningRecordsServiceImpl learningRecordsService; |
||||
|
||||
|
||||
/** |
||||
* 获取当前登录用户的学习记录 |
||||
* @param pagenum |
||||
* @param pagesize |
||||
* @return |
||||
*/ |
||||
@ApiOperation("根据用户id查询学习记录") |
||||
@ValidateParams({"userId"}) |
||||
@GetMapping("/getall") |
||||
public BaseResponse<Page> getAll(@RequestParam(value = "pagenum", defaultValue = "1") int pagenum, |
||||
@RequestParam(value = "pagesize", defaultValue = "10") int pagesize, |
||||
@RequestParam String userId){ |
||||
//根据用户查询
|
||||
Page<LearningRecords> page = learningRecordsService.query() |
||||
.orderByDesc("time") |
||||
.eq("status", "1") |
||||
.eq("user_id", userId).page(new Page<>(pagenum, pagesize)); |
||||
//获取当前页数据
|
||||
List<LearningRecords> list = page.getRecords(); |
||||
List<LearningRecordsVo> cs= learningRecordsService.getAll(list); |
||||
|
||||
long total = page.getTotal(); // 总记录数
|
||||
Page<LearningRecordsVo> pageInfo = new Page<>(pagenum,pagesize,total); |
||||
pageInfo.setRecords(cs); |
||||
pageInfo.setPages(page.getPages());//设置总页数
|
||||
return ResultUtils.success(pageInfo); |
||||
} |
||||
|
||||
@ApiOperation("查询所有") |
||||
@GetMapping("/all") |
||||
public BaseResponse<List<LearningRecords>> All(){ |
||||
// System.out.println("学习记录:"+learningRecordsService.list());
|
||||
|
||||
return ResultUtils.success(learningRecordsService.list()); |
||||
} |
||||
|
||||
//资源类型: 1,课程学习记录,2,知识点学习记录,3课程资源学习记录
|
||||
/** |
||||
* 添加课程记录 |
||||
* @param learningRecords |
||||
* @return |
||||
*/ |
||||
@ApiOperation("添加学习记录") |
||||
@ValidateParams({"userId","type","coursesId"}) |
||||
@PostMapping("/saverecords") |
||||
public BaseResponse<String> saveRecords(@RequestBody LearningRecords learningRecords){ |
||||
// System.out.println(learningRecords);
|
||||
return ResultUtils.success(learningRecordsService.saveRecords(learningRecords)); |
||||
} |
||||
/** |
||||
* |
||||
*/ |
||||
|
||||
|
||||
/** |
||||
* 根据ids删除 |
||||
* @param ids |
||||
* @return |
||||
*/ |
||||
@ApiOperation("学习记录删除") |
||||
@DeleteMapping("/delete") |
||||
public BaseResponse<String> deleteRecords(@RequestParam List<Long> ids){ |
||||
return ResultUtils.success(learningRecordsService.delete(ids)); |
||||
} |
||||
|
||||
/** |
||||
* 统计单个学生的学习记录 |
||||
*/ |
||||
@ApiOperation("单个学生学习记录统计") |
||||
@GetMapping("/count") |
||||
public BaseResponse<CourseLearningRecordsVo> countLearningRecord(@RequestParam String userId, @RequestParam String courseId){ |
||||
return learningRecordsService.countLearningRecord(userId,courseId); |
||||
} |
||||
|
||||
} |
||||
|
@ -0,0 +1,30 @@ |
||||
package com.teaching.backend.controller.records; |
||||
|
||||
import com.teaching.backend.common.BaseResponse; |
||||
import com.teaching.backend.common.ResultUtils; |
||||
import com.teaching.backend.model.entity.records.KnowledgeLearningRecord; |
||||
import com.teaching.backend.model.entity.records.ResourceLearningRecord; |
||||
import com.teaching.backend.service.impl.records.KnowledgeLearningRecordServiceImpl; |
||||
import com.teaching.backend.service.impl.records.ResourceLearningRecordServiceImpl; |
||||
import io.swagger.annotations.ApiOperation; |
||||
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.RestController; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
@RestController |
||||
@RequestMapping("/api/resourcelearningrecords") |
||||
public class ResourceLearningRecordController { |
||||
@Resource |
||||
private ResourceLearningRecordServiceImpl resourceLearningRecordService; |
||||
|
||||
@ApiOperation("添加资源学习记录") |
||||
// @ValidateParams({"userId","type","coursesId"})
|
||||
@PostMapping("/saverecords") |
||||
public BaseResponse<String> saveResourceRecords(@RequestBody ResourceLearningRecord resourceLearningRecord) { |
||||
resourceLearningRecordService.save(resourceLearningRecord); |
||||
return ResultUtils.success("添加成功"); |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
package com.teaching.backend.mapper.courses; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.teaching.backend.model.entity.courses.CourseLearningNumber; |
||||
|
||||
/** |
||||
* <p> |
||||
* Mapper 接口 |
||||
* </p> |
||||
* |
||||
* @author author |
||||
* @since 2024-07-29 |
||||
*/ |
||||
public interface CourseLearningNumberMapper extends BaseMapper<CourseLearningNumber> { |
||||
|
||||
} |
@ -0,0 +1,44 @@ |
||||
package com.teaching.backend.model.entity.courses; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import java.io.Serializable; |
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
/** |
||||
* <p> |
||||
* |
||||
* </p> |
||||
* |
||||
* @author author |
||||
* @since 2024-07-29 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = false) |
||||
@Accessors(chain = true) |
||||
@TableName("course_learning_number") |
||||
@ApiModel(value="CourseLearningNumber对象", description="") |
||||
public class CourseLearningNumber implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@ApiModelProperty(value = "课程学习id") |
||||
@TableId(value = "id", type = IdType.ASSIGN_ID) |
||||
private String id; |
||||
|
||||
@ApiModelProperty(value = "课程id") |
||||
@TableField("course_id") |
||||
private String courseId; |
||||
|
||||
@ApiModelProperty(value = "课程学习人数") |
||||
@TableField("number") |
||||
private Integer number; |
||||
|
||||
|
||||
} |
@ -0,0 +1,40 @@ |
||||
package com.teaching.backend.model.vo.records; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
import java.time.LocalDateTime; |
||||
|
||||
@Data |
||||
@ApiModel(description = "课程学习记录") |
||||
public class CourseLearningRecordsVo { |
||||
|
||||
/** |
||||
* 课程学习id |
||||
*/ |
||||
private String id; |
||||
/** |
||||
* 课程名称 |
||||
*/ |
||||
private String courseName; |
||||
/** |
||||
* 用户id |
||||
*/ |
||||
private String userId; |
||||
/** |
||||
* 学习人数 |
||||
*/ |
||||
private Integer number; |
||||
/** |
||||
* 封面 |
||||
*/ |
||||
private String img; |
||||
/** |
||||
* 学习时间 |
||||
*/ |
||||
private String time; |
||||
} |
@ -0,0 +1,17 @@ |
||||
package com.teaching.backend.service.courses; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import com.teaching.backend.model.entity.courses.CourseLearningNumber; |
||||
|
||||
/** |
||||
* <p> |
||||
* 服务类 |
||||
* </p> |
||||
* |
||||
* @author author |
||||
* @since 2024-07-29 |
||||
*/ |
||||
public interface ICourseLearningNumberService extends IService<CourseLearningNumber> { |
||||
|
||||
} |
@ -0,0 +1,22 @@ |
||||
package com.teaching.backend.service.impl.courses; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import com.teaching.backend.mapper.courses.CourseLearningNumberMapper; |
||||
import com.teaching.backend.model.entity.courses.CourseLearningNumber; |
||||
import com.teaching.backend.service.courses.ICourseLearningNumberService; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* <p> |
||||
* 服务实现类 |
||||
* </p> |
||||
* |
||||
* @author author |
||||
* @since 2024-07-29 |
||||
*/ |
||||
@Service |
||||
public class CourseLearningNumberServiceImpl extends ServiceImpl<CourseLearningNumberMapper, CourseLearningNumber> implements ICourseLearningNumberService { |
||||
|
||||
|
||||
} |
@ -1,179 +1,215 @@ |
||||
//package com.teaching.backend.service.impl.records;
|
||||
//
|
||||
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
//import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
//
|
||||
//import com.teaching.backend.common.ErrorCode;
|
||||
//import com.teaching.backend.exception.BusinessException;
|
||||
//import com.teaching.backend.mapper.records.LearningRecordsMapper;
|
||||
//
|
||||
//import com.teaching.backend.model.entity.records.LearningRecords;
|
||||
//import com.teaching.backend.model.vo.records.LearningRecordsVo;
|
||||
//import com.teaching.backend.service.impl.courses.CoursesServiceImpl;
|
||||
//import com.teaching.backend.service.records.LearningRecordsService;
|
||||
//import org.springframework.beans.BeanUtils;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//import org.springframework.transaction.annotation.Transactional;
|
||||
//
|
||||
//import java.text.SimpleDateFormat;
|
||||
//import java.time.LocalDateTime;
|
||||
//import java.time.ZoneId;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.Date;
|
||||
//import java.util.List;
|
||||
//
|
||||
//@Service
|
||||
//public class LearningRecordsServiceImpl extends ServiceImpl<LearningRecordsMapper, LearningRecords> implements LearningRecordsService {
|
||||
//
|
||||
// @Autowired
|
||||
// private CoursesServiceImpl coursesService;
|
||||
// @Autowired
|
||||
// private LearningRecordsMapper learningRecordsMapper;
|
||||
package com.teaching.backend.service.impl.records; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
||||
import com.teaching.backend.common.BaseResponse; |
||||
import com.teaching.backend.common.ErrorCode; |
||||
import com.teaching.backend.common.ResultUtils; |
||||
import com.teaching.backend.exception.BusinessException; |
||||
import com.teaching.backend.mapper.records.LearningRecordsMapper; |
||||
|
||||
import com.teaching.backend.model.entity.records.LearningRecords; |
||||
import com.teaching.backend.model.vo.records.CourseLearningRecordsVo; |
||||
import com.teaching.backend.model.vo.records.LearningRecordsVo; |
||||
//import com.teaching.backend.service.impl.CourseResourcesServiceImpl;
|
||||
import com.teaching.backend.service.impl.courses.CoursesServiceImpl; |
||||
import com.teaching.backend.service.records.LearningRecordsService; |
||||
import org.springframework.beans.BeanUtils; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import java.text.SimpleDateFormat; |
||||
import java.time.LocalDateTime; |
||||
import java.time.ZoneId; |
||||
import java.util.ArrayList; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
@Service |
||||
public class LearningRecordsServiceImpl extends ServiceImpl<LearningRecordsMapper, LearningRecords> implements LearningRecordsService { |
||||
|
||||
@Autowired |
||||
private CoursesServiceImpl coursesService; |
||||
@Autowired |
||||
private LearningRecordsMapper learningRecordsMapper; |
||||
// @Autowired
|
||||
// private CourseResourcesServiceImpl courseResourcesService;
|
||||
//// @Autowired
|
||||
//// private ChapterServiceImpl chapterService;
|
||||
//
|
||||
// @Override
|
||||
// public IPage<LearningRecords> selectPageList(Page<LearningRecords> page, LearningRecords model) {
|
||||
// return learningRecordsMapper.selectPageList(page,model);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String delete(List<Long> ids) {
|
||||
// LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
// lambdaQueryWrapper.in(LearningRecords::getId, ids);
|
||||
// List<LearningRecords> list = this.list(lambdaQueryWrapper);
|
||||
// //把即将要删除的记录状态调成0
|
||||
// @Autowired
|
||||
// private ChapterServiceImpl chapterService;
|
||||
|
||||
@Override |
||||
public IPage<LearningRecords> selectPageList(Page<LearningRecords> page, LearningRecords model) { |
||||
return learningRecordsMapper.selectPageList(page,model); |
||||
} |
||||
|
||||
@Override |
||||
public String delete(List<Long> ids) { |
||||
LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
lambdaQueryWrapper.in(LearningRecords::getId, ids); |
||||
List<LearningRecords> list = this.list(lambdaQueryWrapper); |
||||
//把即将要删除的记录状态调成0
|
||||
for (LearningRecords learningRecords : list) { |
||||
learningRecords.setStatus("0"); |
||||
} |
||||
updateBatchById(list); |
||||
// System.out.println(this.updateBatchById(list));
|
||||
// this.remove(lambdaQueryWrapper);
|
||||
return "删除成功"; |
||||
} |
||||
|
||||
@Override |
||||
public BaseResponse<CourseLearningRecordsVo> countLearningRecord(String userId, String courseId) { |
||||
// CourseLearningRecordsVo courseLearningRecordsVo = new CourseLearningRecordsVo();
|
||||
// //统计章节学习数量
|
||||
// Long chapterCount = query()
|
||||
// .eq("courses_id", courseId)
|
||||
// .eq("user_id", userId)
|
||||
// .eq("type", 2).count();
|
||||
// //统计知识点学习数量
|
||||
// Long knowledgeCount = query()
|
||||
// .eq("courses_id", courseId)
|
||||
// .eq("user_id", userId)
|
||||
// .eq("type", 3).count();
|
||||
// //统计资源学习数量
|
||||
// Long resourceCount = query()
|
||||
// .eq("courses_id", courseId)
|
||||
// .eq("user_id", userId)
|
||||
// .eq("type", 4).count();
|
||||
// courseLearningRecordsVo.setChapterCount(chapterCount.intValue());
|
||||
// courseLearningRecordsVo.setKnowledgeCount(knowledgeCount.intValue());
|
||||
// courseLearningRecordsVo.setResourceCount(resourceCount.intValue());
|
||||
// //统计课程学习时长
|
||||
// List<LearningRecords> list = query()
|
||||
// .eq("courses_id", courseId)
|
||||
// .eq("user_id", userId).list();
|
||||
// int duration = list.stream().mapToInt(LearningRecords::getVideoDuration).sum();
|
||||
// courseLearningRecordsVo.setDuration(duration);
|
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public List<LearningRecordsVo> getAll(List<LearningRecords> list){ |
||||
List<LearningRecordsVo> records = new ArrayList<>(); |
||||
//格式化时间
|
||||
String strDateFormat = "yyyy-MM-dd HH:mm:ss"; |
||||
SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); |
||||
//如果为空-------------------?????
|
||||
list.forEach(learningRecords -> { |
||||
LearningRecordsVo learningRecordsVo = new LearningRecordsVo();//好像可以拿出去-----------??
|
||||
BeanUtils.copyProperties(learningRecords,learningRecordsVo);//从多传到少(时间需要转格式)
|
||||
Date date = Date.from(learningRecords.getTime().atZone(ZoneId.systemDefault()).toInstant()); |
||||
learningRecordsVo.setTime(sdf.format(date)); |
||||
// //统计记录表里有多少人查看过这门资源
|
||||
// LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
// lambdaQueryWrapper.eq(LearningRecords::getCoursesId, learningRecords.getCoursesId());
|
||||
// long count = this.count(lambdaQueryWrapper);
|
||||
learningRecordsVo.setNumber(learningRecords.getNumber()); |
||||
//把整合后该用户的学习记录添加到List里
|
||||
records.add(learningRecordsVo); |
||||
}); |
||||
// for (LearningRecords learningRecords : list) {
|
||||
// learningRecords.setStatus("0");
|
||||
// }
|
||||
// updateBatchById(list);
|
||||
//// System.out.println(this.updateBatchById(list));
|
||||
//// this.remove(lambdaQueryWrapper);
|
||||
// return "删除成功";
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<LearningRecordsVo> getAll(List<LearningRecords> list){
|
||||
// List<LearningRecordsVo> records = new ArrayList<>();
|
||||
// //格式化时间
|
||||
// String strDateFormat = "yyyy-MM-dd HH:mm:ss";
|
||||
// SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
|
||||
// //如果为空-------------------?????
|
||||
// list.forEach(learningRecords -> {
|
||||
// LearningRecordsVo learningRecordsVo = new LearningRecordsVo();//好像可以拿出去-----------??
|
||||
// BeanUtils.copyProperties(learningRecords,learningRecordsVo);//从多传到少(时间需要转格式)
|
||||
// Date date = Date.from(learningRecords.getTime().atZone(ZoneId.systemDefault()).toInstant());
|
||||
// learningRecordsVo.setTime(sdf.format(date));
|
||||
//// //统计记录表里有多少人查看过这门资源
|
||||
//// LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
//// lambdaQueryWrapper.eq(LearningRecords::getCoursesId, learningRecords.getCoursesId());
|
||||
//// long count = this.count(lambdaQueryWrapper);
|
||||
// learningRecordsVo.setNumber(learningRecords.getNumber());
|
||||
// //把整合后该用户的学习记录添加到List里
|
||||
// records.add(learningRecordsVo);
|
||||
// });
|
||||
//// for (LearningRecords learningRecords : list) {
|
||||
//// //查找该用户的学习记录
|
||||
//// LearningRecordsVo learningRecordsVo = new LearningRecordsVo();//好像可以拿出去-----------??
|
||||
//// BeanUtils.copyProperties(learningRecords,learningRecordsVo);//从多传到少(缺少人数,和资源名称,时间需要转格式)
|
||||
//// //添加时间
|
||||
//// //LocalDateTime转Date
|
||||
//// Date date = Date.from(learningRecords.getTime().atZone(ZoneId.systemDefault()).toInstant());
|
||||
//// learningRecordsVo.setTime(sdf.format(date));
|
||||
//// LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
//// lambdaQueryWrapper.eq(LearningRecords::getCoursesId, learningRecords.getCoursesId());
|
||||
//// String name;
|
||||
//// //添加课程名称
|
||||
//// switch (learningRecords.getType()) {
|
||||
//// case "4": //如果是资源学习
|
||||
//// if (courseResourcesService.getById(learningRecords.getCoursesId()) != null){
|
||||
//// learningRecordsVo.setCoursesName(courseResourcesService.getById(learningRecords.getCoursesId()).getName());
|
||||
//// }
|
||||
//// break;
|
||||
//// case "1": //如果是课程学习记录
|
||||
//// if (coursesService.getById(learningRecords.getCoursesId()) != null){
|
||||
//// learningRecordsVo.setCoursesName(coursesService.getById(learningRecords.getCoursesId()).getName());
|
||||
//// }
|
||||
//// break;
|
||||
//// }
|
||||
//// //添加观看人数
|
||||
//// //统计记录表里有多少人查看过这门资源
|
||||
//// long count = this.count(lambdaQueryWrapper);
|
||||
//// learningRecordsVo.setNumber(count);
|
||||
//// //把整合后该用户的学习记录添加到List里
|
||||
//// records.add(learningRecordsVo);
|
||||
//// }
|
||||
// return records;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 根据用户id和学习资源id来判断记录是否存在
|
||||
// * @param learningRecords
|
||||
// * @return
|
||||
// */
|
||||
// @Override
|
||||
// @Transactional
|
||||
// public String saveRecords(LearningRecords learningRecords) {
|
||||
// String userId = learningRecords.getUserId();
|
||||
// String coursesId = learningRecords.getCoursesId();
|
||||
// //如果userId或者coursesId为空就抛出异常事务回滚----------------------------
|
||||
// if (userId == null || userId.equals("") || coursesId == null || coursesId.equals("")){
|
||||
// throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
// }
|
||||
//
|
||||
//// System.out.println("学习记录:"+learningRecords);
|
||||
// //查找该用户是否观看过该学习资源
|
||||
// LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
// lambdaQueryWrapper
|
||||
// .eq(LearningRecords::getUserId, userId)
|
||||
// .eq(LearningRecords::getCoursesId, coursesId)
|
||||
// .eq(LearningRecords::getType, learningRecords.getType());
|
||||
// long count = this.count(lambdaQueryWrapper);
|
||||
// //System.out.println("数据库:"+count);
|
||||
// learningRecords.setStatus("1");//将该记录的状态设置为1
|
||||
// //更新观看时间
|
||||
// learningRecords.setTime(LocalDateTime.now());
|
||||
// //设置默认封面
|
||||
// if (learningRecords.getContent() == null || learningRecords.getContent().equals("")){
|
||||
// learningRecords.setContent("img/v2-c57eb7863ec4233f503176ca3f90f8d5_1440w.png");
|
||||
// }
|
||||
// List<LearningRecords> list = query().eq("courses_id", coursesId).eq("type", learningRecords.getType()).list();
|
||||
// LearningRecords one1 = query().eq("courses_id", coursesId).eq("type", learningRecords.getType()).eq("user_id", userId).one();
|
||||
// int number = list.size();
|
||||
// //该用户是否学习过
|
||||
// if (one1 != null){//学习过观看人数不加
|
||||
// learningRecords.setNumber(number);
|
||||
// list.forEach(learningRecords1 -> {
|
||||
// learningRecords1.setNumber(number);
|
||||
// });
|
||||
// } else {//否则观看人数加1
|
||||
// learningRecords.setNumber(number + 1);
|
||||
// }
|
||||
// updateBatchById(list);
|
||||
// if (count == 0){//如果没有就新增并记录学习方式是打开还是下载
|
||||
// //根据传上来的type设置
|
||||
//// learningRecords.setType(learningRecords.getType());
|
||||
// this.save(learningRecords);
|
||||
// return "添加成功";
|
||||
// }else {//有就修改记录,更新学习方式
|
||||
// LearningRecords one = this.getOne(lambdaQueryWrapper);
|
||||
// System.out.println(one);
|
||||
// learningRecords.setId(one.getId());//找到该条记录的id并赋值给本次观看记录
|
||||
// if ( one.getOpen() != null && one.getOpen().equals("1")){
|
||||
// learningRecords.setOpen(one.getOpen());
|
||||
// }
|
||||
// if (one.getDownload() != null && one.getDownload().equals("1")){
|
||||
// learningRecords.setDownload(one.getDownload());
|
||||
// //查找该用户的学习记录
|
||||
// LearningRecordsVo learningRecordsVo = new LearningRecordsVo();//好像可以拿出去-----------??
|
||||
// BeanUtils.copyProperties(learningRecords,learningRecordsVo);//从多传到少(缺少人数,和资源名称,时间需要转格式)
|
||||
// //添加时间
|
||||
// //LocalDateTime转Date
|
||||
// Date date = Date.from(learningRecords.getTime().atZone(ZoneId.systemDefault()).toInstant());
|
||||
// learningRecordsVo.setTime(sdf.format(date));
|
||||
// LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
// lambdaQueryWrapper.eq(LearningRecords::getCoursesId, learningRecords.getCoursesId());
|
||||
// String name;
|
||||
// //添加课程名称
|
||||
// switch (learningRecords.getType()) {
|
||||
// case "4": //如果是资源学习
|
||||
// if (courseResourcesService.getById(learningRecords.getCoursesId()) != null){
|
||||
// learningRecordsVo.setCoursesName(courseResourcesService.getById(learningRecords.getCoursesId()).getName());
|
||||
// }
|
||||
// break;
|
||||
// case "1": //如果是课程学习记录
|
||||
// if (coursesService.getById(learningRecords.getCoursesId()) != null){
|
||||
// learningRecordsVo.setCoursesName(coursesService.getById(learningRecords.getCoursesId()).getName());
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// this.updateById(learningRecords);
|
||||
// return "修改成功";
|
||||
// //添加观看人数
|
||||
// //统计记录表里有多少人查看过这门资源
|
||||
// long count = this.count(lambdaQueryWrapper);
|
||||
// learningRecordsVo.setNumber(count);
|
||||
// //把整合后该用户的学习记录添加到List里
|
||||
// records.add(learningRecordsVo);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
return records; |
||||
} |
||||
|
||||
/** |
||||
* 根据用户id和学习资源id来判断记录是否存在 |
||||
* @param learningRecords |
||||
* @return |
||||
*/ |
||||
@Override |
||||
@Transactional |
||||
public String saveRecords(LearningRecords learningRecords) { |
||||
String userId = learningRecords.getUserId(); |
||||
String coursesId = learningRecords.getCoursesId(); |
||||
//如果userId或者coursesId为空就抛出异常事务回滚----------------------------
|
||||
if (userId == null || userId.equals("") || coursesId == null || coursesId.equals("")){ |
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR); |
||||
} |
||||
|
||||
// System.out.println("学习记录:"+learningRecords);
|
||||
//查找该用户是否观看过该学习资源
|
||||
LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
lambdaQueryWrapper |
||||
.eq(LearningRecords::getUserId, userId) |
||||
.eq(LearningRecords::getCoursesId, coursesId) |
||||
.eq(LearningRecords::getType, learningRecords.getType()); |
||||
long count = this.count(lambdaQueryWrapper); |
||||
//System.out.println("数据库:"+count);
|
||||
learningRecords.setStatus("1");//将该记录的状态设置为1
|
||||
//更新观看时间
|
||||
learningRecords.setTime(LocalDateTime.now()); |
||||
//设置默认封面
|
||||
if (learningRecords.getContent() == null || learningRecords.getContent().equals("")){ |
||||
learningRecords.setContent("img/v2-c57eb7863ec4233f503176ca3f90f8d5_1440w.png"); |
||||
} |
||||
List<LearningRecords> list = query().eq("courses_id", coursesId).eq("type", learningRecords.getType()).list(); |
||||
LearningRecords one1 = query().eq("courses_id", coursesId).eq("type", learningRecords.getType()).eq("user_id", userId).one(); |
||||
int number = list.size(); |
||||
//该用户是否学习过
|
||||
if (one1 != null){//学习过观看人数不加
|
||||
learningRecords.setNumber(number); |
||||
list.forEach(learningRecords1 -> { |
||||
learningRecords1.setNumber(number); |
||||
}); |
||||
} else {//否则观看人数加1
|
||||
learningRecords.setNumber(number + 1); |
||||
} |
||||
updateBatchById(list); |
||||
if (count == 0){//如果没有就新增并记录学习方式是打开还是下载
|
||||
//根据传上来的type设置
|
||||
// learningRecords.setType(learningRecords.getType());
|
||||
this.save(learningRecords); |
||||
return "添加成功"; |
||||
}else {//有就修改记录,更新学习方式
|
||||
LearningRecords one = this.getOne(lambdaQueryWrapper); |
||||
System.out.println(one); |
||||
learningRecords.setId(one.getId());//找到该条记录的id并赋值给本次观看记录
|
||||
if ( one.getOpen() != null && one.getOpen().equals("1")){ |
||||
learningRecords.setOpen(one.getOpen()); |
||||
} |
||||
if (one.getDownload() != null && one.getDownload().equals("1")){ |
||||
learningRecords.setDownload(one.getDownload()); |
||||
} |
||||
this.updateById(learningRecords); |
||||
return "修改成功"; |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
} |
||||
|
Loading…
Reference in new issue