记录是否完成

master
wenyu441069198 3 months ago
parent 04df7b2cc3
commit fa0ff84bf9
  1. 2
      src/main/java/com/teaching/backend/mapper/records/KnowledgeLearningRecordMapper.java
  2. 23
      src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java
  3. 43
      src/main/java/com/teaching/backend/service/impl/records/RecordKnowledgeFinishServiceImpl.java
  4. 32
      src/main/java/com/teaching/backend/service/impl/records/RecordResourceFinishServiceImpl.java
  5. 32
      src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java
  6. 7
      src/main/java/com/teaching/backend/service/records/IRecordKnowledgeFinishService.java
  7. 4
      src/main/java/com/teaching/backend/service/records/IRecordResourceFinishService.java

@ -20,7 +20,7 @@ import java.util.List;
*/
public interface KnowledgeLearningRecordMapper extends BaseMapper<KnowledgeLearningRecord> {
@Select("SELECT knowledge_id FROM knowledge_learning_record WHERE user_id = #{userId} GROUP BY knowledge_id")
@Select("SELECT knowledge_id FROM record_knowledge_learning WHERE user_id = #{userId} GROUP BY knowledge_id")
List<String > selectDistinctKnowledgeIdsByUser(@Param("userId") String userId);
List<String> queryStudyKnowledgeMaxNumber();

@ -15,6 +15,7 @@ import com.teaching.backend.model.entity.records.KnowledgeLearningNumber;
import com.teaching.backend.model.entity.knowtmp.Knowtmp;
import com.teaching.backend.model.entity.records.KnowledgeLearningRecord;
import com.teaching.backend.model.entity.records.RecordKnowledgeFinish;
import com.teaching.backend.model.vo.knowGraph.KnowVO;
import com.teaching.backend.model.vo.records.KnowledgeLearningRecordVo;
@ -50,6 +51,8 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl<KnowledgeLea
private KnowledgeLearningRecordMapper knowledgeLearningRecordMapper;
@Resource
private KnowtmpService knowtmpService;
@Resource
private RecordKnowledgeFinishServiceImpl recordKnowledgeFinishService;
@Override
public BaseResponse<String> saveCoursesRecords(KnowledgeLearningRecord knowledgeLearningRecord) {
@ -78,7 +81,14 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl<KnowledgeLea
.eq("course_id", courseId)
.eq("knowledge_id",knowledgeId).update();
System.out.println("用户:"+userId+":第一次学这门课");
//添加完成状态
recordKnowledgeFinishService.addFinish(knowledgeLearningRecord);
}//自己学过
else {
if (knowledgeLearningRecord.getFinish() == 1){
//改变完成状态
recordKnowledgeFinishService.editFinish(knowledgeLearningRecord);
}
}
}else {//没人学过(自己肯定也没学)
//该课程第一次被学,人数设置为1
@ -87,18 +97,25 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl<KnowledgeLea
knowledgeLearningNumber.setCourseId(courseId);
knowledgeLearningNumber.setKnowledgeId(knowledgeId);
knowledgeLearningNumberService.save(knowledgeLearningNumber);
//添加完成状态
recordKnowledgeFinishService.addFinish(knowledgeLearningRecord);
}
//设置人数
String numberId = knowledgeLearningNumberService.query()
.eq("course_id", courseId)
.eq("knowledge_id",knowledgeId).one().getId();
knowledgeLearningRecord.setNumber(numberId);
//设置完成状态
Integer finishId = recordKnowledgeFinishService.query()
.eq("course_id", courseId)
.eq("knowledge_id", knowledgeId)
.eq("user_id",userId).one().getId();
knowledgeLearningRecord.setFinish(finishId);
//保存记录
save(knowledgeLearningRecord);
return ResultUtils.success("添加成功");
}
@Override
public BaseResponse<Page> getPage(int pagenum, int pagesize, String userId, String courseId) {
//格式化时间
@ -122,6 +139,8 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl<KnowledgeLea
knowledgeLearningRecordVo.setTime(sdf.format(date));
// //填充学习人数
knowledgeLearningRecordVo.setNumber(knowledgeLearningNumberService.getById(knowledgeLearningRecord.getNumber()).getNumber());
//获取完成状态
knowledgeLearningRecordVo.setFinish(recordKnowledgeFinishService.getById(knowledgeLearningRecord.getFinish()).getFinish());
recordsVos.add(knowledgeLearningRecordVo);
});
//System.out.println(recordsVos);

@ -3,7 +3,9 @@ package com.teaching.backend.service.impl.records;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.mapper.records.RecordKnowledgeFinishMapper;
import com.teaching.backend.model.entity.records.KnowledgeLearningRecord;
import com.teaching.backend.model.entity.records.RecordKnowledgeFinish;
import com.teaching.backend.model.entity.records.ResourceLearningRecord;
import com.teaching.backend.service.records.IRecordKnowledgeFinishService;
import org.springframework.stereotype.Service;
@ -18,4 +20,45 @@ import org.springframework.stereotype.Service;
@Service
public class RecordKnowledgeFinishServiceImpl extends ServiceImpl<RecordKnowledgeFinishMapper, RecordKnowledgeFinish> implements IRecordKnowledgeFinishService {
@Override
public void addFinish(KnowledgeLearningRecord knowledgeLearningRecord) {
RecordKnowledgeFinish recordKnowledgeFinish = new RecordKnowledgeFinish();
recordKnowledgeFinish.setUserId(knowledgeLearningRecord.getUserId());
recordKnowledgeFinish.setCourseId(knowledgeLearningRecord.getCoursesId());
recordKnowledgeFinish.setKnowledgeId(knowledgeLearningRecord.getKnowledgeId());
recordKnowledgeFinish.setFinish(knowledgeLearningRecord.getFinish());
save(recordKnowledgeFinish);
}
@Override
public void addFinish(ResourceLearningRecord resourceLearningRecord) {
RecordKnowledgeFinish recordKnowledgeFinish = new RecordKnowledgeFinish();
recordKnowledgeFinish.setUserId(resourceLearningRecord.getUserId());
recordKnowledgeFinish.setCourseId(resourceLearningRecord.getCoursesId());
recordKnowledgeFinish.setKnowledgeId(resourceLearningRecord.getKnowledgeId());
recordKnowledgeFinish.setFinish(resourceLearningRecord.getFinish());
save(recordKnowledgeFinish);
}
@Override
public void editFinish(KnowledgeLearningRecord knowledgeLearningRecord) {
//设置完成状态
RecordKnowledgeFinish one = query()
.eq("course_id", knowledgeLearningRecord.getCoursesId())
.eq("knowledge_id", knowledgeLearningRecord.getKnowledgeId())
.eq("user_id", knowledgeLearningRecord.getUserId()).one();
one.setFinish(1);
updateById(one);
}
@Override
public void editFinish(ResourceLearningRecord resourceLearningRecord) {
//设置完成状态
RecordKnowledgeFinish one = query()
.eq("course_id", resourceLearningRecord.getCoursesId())
.eq("knowledge_id", resourceLearningRecord.getKnowledgeId())
.eq("user_id", resourceLearningRecord.getUserId()).one();
one.setFinish(1);
updateById(one);
}
}

@ -3,10 +3,14 @@ package com.teaching.backend.service.impl.records;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.mapper.records.RecordResourceFinishMapper;
import com.teaching.backend.model.entity.records.RecordKnowledgeFinish;
import com.teaching.backend.model.entity.records.RecordResourceFinish;
import com.teaching.backend.model.entity.records.ResourceLearningRecord;
import com.teaching.backend.service.records.IRecordResourceFinishService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* <p>
* 服务实现类
@ -18,4 +22,32 @@ import org.springframework.stereotype.Service;
@Service
public class RecordResourceFinishServiceImpl extends ServiceImpl<RecordResourceFinishMapper, RecordResourceFinish> implements IRecordResourceFinishService {
@Resource
private RecordKnowledgeFinishServiceImpl recordKnowledgeFinishService;
@Override
public void addFinish(ResourceLearningRecord resourceLearningRecord) {
//如果资源学习完成,知识点也改为完成
if (resourceLearningRecord.getFinish() == 1){
recordKnowledgeFinishService.editFinish(resourceLearningRecord);
}
RecordResourceFinish recordResourceFinish = new RecordResourceFinish();
recordResourceFinish.setUserId(resourceLearningRecord.getUserId());
recordResourceFinish.setCourseId(resourceLearningRecord.getCoursesId());
recordResourceFinish.setKnowledgeId(resourceLearningRecord.getKnowledgeId());
recordResourceFinish.setResourceId(resourceLearningRecord.getResourceId());
recordResourceFinish.setFinish(resourceLearningRecord.getFinish());
System.out.println(recordResourceFinish);
save(recordResourceFinish);
}
@Override
public void editFinish(ResourceLearningRecord resourceLearningRecord) {
RecordResourceFinish one = query()
.eq("course_id", resourceLearningRecord.getCoursesId())
.eq("knowledge_id", resourceLearningRecord.getKnowledgeId())
.eq("resource_id",resourceLearningRecord.getResourceId())
.eq("user_id", resourceLearningRecord.getUserId()).one();
one.setFinish(1);
updateById(one);
}
}

@ -37,7 +37,7 @@ public class ResourceLearningRecordServiceImpl extends ServiceImpl<ResourceLearn
@Resource
private ResourceLearningNumberServiceImpl resourceLearningNumberService;
@Resource
private KnowledgeLearningRecordServiceImpl knowledgeLearningRecordService;
private RecordResourceFinishServiceImpl recordResourceFinishService;
@Override
public BaseResponse<String> saveCoursesRecords(ResourceLearningRecord resourceLearningRecord) {
@ -68,6 +68,13 @@ public class ResourceLearningRecordServiceImpl extends ServiceImpl<ResourceLearn
.eq("knowledge_id",knowledgeId)
.eq("resource_id",resourceId).update();
// System.out.println("用户:"+userId+"第一次学这门课");
//添加完成状态
recordResourceFinishService.addFinish(resourceLearningRecord);
}else {
if (resourceLearningRecord.getFinish() == 1){
//改变完成状态
recordResourceFinishService.editFinish(resourceLearningRecord);
}
}
}else {
//该课程第一次被学,人数设置为1
@ -77,6 +84,8 @@ public class ResourceLearningRecordServiceImpl extends ServiceImpl<ResourceLearn
resourceLearningNumber.setKnowledgeId(knowledgeId);
resourceLearningNumber.setResourceId(resourceId);
resourceLearningNumberService.save(resourceLearningNumber);
//添加完成状态
recordResourceFinishService.addFinish(resourceLearningRecord);
}
//设置人数
String numberId = resourceLearningNumberService.query()
@ -84,21 +93,12 @@ public class ResourceLearningRecordServiceImpl extends ServiceImpl<ResourceLearn
.eq("knowledge_id",knowledgeId)
.eq("resource_id",resourceId).one().getId();
resourceLearningRecord.setNumber(numberId);
//判断该资源是否学习完成
if (resourceLearningRecord.getFinish() == 1){
//如果完成将该资源,新加一条所属知识点已完成的学习记录
KnowledgeLearningRecord kl = new KnowledgeLearningRecord();
kl.setFinish(1);
kl.setCoursesId(resourceLearningRecord.getCoursesId());
kl.setUserId(resourceLearningRecord.getUserId());
kl.setKnowledgeId(resourceLearningRecord.getKnowledgeId());
// kl.setKnowledgeName()
System.out.println(kl);
// kl.setFinish(1);
//更新知识点完成状态
knowledgeLearningRecordService.save(kl);
//knowledgeLearningRecordService.updateById(kl);
}
//设置完成状态
Integer finishId = recordResourceFinishService.query()
.eq("course_id", courseId)
.eq("knowledge_id", knowledgeId)
.eq("user_id",userId).one().getId();
resourceLearningRecord.setFinish(finishId);
//保存记录
save(resourceLearningRecord);
return ResultUtils.success("添加成功");

@ -2,7 +2,10 @@ package com.teaching.backend.service.records;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.entity.records.KnowledgeLearningRecord;
import com.teaching.backend.model.entity.records.RecordKnowledgeFinish;
import com.teaching.backend.model.entity.records.RecordResourceFinish;
import com.teaching.backend.model.entity.records.ResourceLearningRecord;
/**
* <p>
@ -13,5 +16,9 @@ import com.teaching.backend.model.entity.records.RecordKnowledgeFinish;
* @since 2024-08-20
*/
public interface IRecordKnowledgeFinishService extends IService<RecordKnowledgeFinish> {
void addFinish(KnowledgeLearningRecord knowledgeLearningRecord);
void addFinish(ResourceLearningRecord resourceLearningRecord);
void editFinish(KnowledgeLearningRecord knowledgeLearningRecord);
void editFinish(ResourceLearningRecord resourceLearningRecord);
}

@ -2,7 +2,9 @@ package com.teaching.backend.service.records;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.entity.records.KnowledgeLearningRecord;
import com.teaching.backend.model.entity.records.RecordResourceFinish;
import com.teaching.backend.model.entity.records.ResourceLearningRecord;
/**
* <p>
@ -13,5 +15,7 @@ import com.teaching.backend.model.entity.records.RecordResourceFinish;
* @since 2024-08-20
*/
public interface IRecordResourceFinishService extends IService<RecordResourceFinish> {
void addFinish(ResourceLearningRecord resourceLearningRecord);
void editFinish(ResourceLearningRecord resourceLearningRecord);
}

Loading…
Cancel
Save