记录是否完成

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> { 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 > selectDistinctKnowledgeIdsByUser(@Param("userId") String userId);
List<String> queryStudyKnowledgeMaxNumber(); 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.knowtmp.Knowtmp;
import com.teaching.backend.model.entity.records.KnowledgeLearningRecord; 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.knowGraph.KnowVO;
import com.teaching.backend.model.vo.records.KnowledgeLearningRecordVo; import com.teaching.backend.model.vo.records.KnowledgeLearningRecordVo;
@ -50,6 +51,8 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl<KnowledgeLea
private KnowledgeLearningRecordMapper knowledgeLearningRecordMapper; private KnowledgeLearningRecordMapper knowledgeLearningRecordMapper;
@Resource @Resource
private KnowtmpService knowtmpService; private KnowtmpService knowtmpService;
@Resource
private RecordKnowledgeFinishServiceImpl recordKnowledgeFinishService;
@Override @Override
public BaseResponse<String> saveCoursesRecords(KnowledgeLearningRecord knowledgeLearningRecord) { public BaseResponse<String> saveCoursesRecords(KnowledgeLearningRecord knowledgeLearningRecord) {
@ -78,7 +81,14 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl<KnowledgeLea
.eq("course_id", courseId) .eq("course_id", courseId)
.eq("knowledge_id",knowledgeId).update(); .eq("knowledge_id",knowledgeId).update();
System.out.println("用户:"+userId+":第一次学这门课"); System.out.println("用户:"+userId+":第一次学这门课");
//添加完成状态
recordKnowledgeFinishService.addFinish(knowledgeLearningRecord);
}//自己学过
else {
if (knowledgeLearningRecord.getFinish() == 1){
//改变完成状态
recordKnowledgeFinishService.editFinish(knowledgeLearningRecord);
}
} }
}else {//没人学过(自己肯定也没学) }else {//没人学过(自己肯定也没学)
//该课程第一次被学,人数设置为1 //该课程第一次被学,人数设置为1
@ -87,18 +97,25 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl<KnowledgeLea
knowledgeLearningNumber.setCourseId(courseId); knowledgeLearningNumber.setCourseId(courseId);
knowledgeLearningNumber.setKnowledgeId(knowledgeId); knowledgeLearningNumber.setKnowledgeId(knowledgeId);
knowledgeLearningNumberService.save(knowledgeLearningNumber); knowledgeLearningNumberService.save(knowledgeLearningNumber);
//添加完成状态
recordKnowledgeFinishService.addFinish(knowledgeLearningRecord);
} }
//设置人数 //设置人数
String numberId = knowledgeLearningNumberService.query() String numberId = knowledgeLearningNumberService.query()
.eq("course_id", courseId) .eq("course_id", courseId)
.eq("knowledge_id",knowledgeId).one().getId(); .eq("knowledge_id",knowledgeId).one().getId();
knowledgeLearningRecord.setNumber(numberId); 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); save(knowledgeLearningRecord);
return ResultUtils.success("添加成功"); return ResultUtils.success("添加成功");
} }
@Override @Override
public BaseResponse<Page> getPage(int pagenum, int pagesize, String userId, String courseId) { 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.setTime(sdf.format(date));
// //填充学习人数 // //填充学习人数
knowledgeLearningRecordVo.setNumber(knowledgeLearningNumberService.getById(knowledgeLearningRecord.getNumber()).getNumber()); knowledgeLearningRecordVo.setNumber(knowledgeLearningNumberService.getById(knowledgeLearningRecord.getNumber()).getNumber());
//获取完成状态
knowledgeLearningRecordVo.setFinish(recordKnowledgeFinishService.getById(knowledgeLearningRecord.getFinish()).getFinish());
recordsVos.add(knowledgeLearningRecordVo); recordsVos.add(knowledgeLearningRecordVo);
}); });
//System.out.println(recordsVos); //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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.mapper.records.RecordKnowledgeFinishMapper; 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.RecordKnowledgeFinish;
import com.teaching.backend.model.entity.records.ResourceLearningRecord;
import com.teaching.backend.service.records.IRecordKnowledgeFinishService; import com.teaching.backend.service.records.IRecordKnowledgeFinishService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -18,4 +20,45 @@ import org.springframework.stereotype.Service;
@Service @Service
public class RecordKnowledgeFinishServiceImpl extends ServiceImpl<RecordKnowledgeFinishMapper, RecordKnowledgeFinish> implements IRecordKnowledgeFinishService { 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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.mapper.records.RecordResourceFinishMapper; 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.RecordResourceFinish;
import com.teaching.backend.model.entity.records.ResourceLearningRecord;
import com.teaching.backend.service.records.IRecordResourceFinishService; import com.teaching.backend.service.records.IRecordResourceFinishService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/** /**
* <p> * <p>
* 服务实现类 * 服务实现类
@ -18,4 +22,32 @@ import org.springframework.stereotype.Service;
@Service @Service
public class RecordResourceFinishServiceImpl extends ServiceImpl<RecordResourceFinishMapper, RecordResourceFinish> implements IRecordResourceFinishService { 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 @Resource
private ResourceLearningNumberServiceImpl resourceLearningNumberService; private ResourceLearningNumberServiceImpl resourceLearningNumberService;
@Resource @Resource
private KnowledgeLearningRecordServiceImpl knowledgeLearningRecordService; private RecordResourceFinishServiceImpl recordResourceFinishService;
@Override @Override
public BaseResponse<String> saveCoursesRecords(ResourceLearningRecord resourceLearningRecord) { public BaseResponse<String> saveCoursesRecords(ResourceLearningRecord resourceLearningRecord) {
@ -68,6 +68,13 @@ public class ResourceLearningRecordServiceImpl extends ServiceImpl<ResourceLearn
.eq("knowledge_id",knowledgeId) .eq("knowledge_id",knowledgeId)
.eq("resource_id",resourceId).update(); .eq("resource_id",resourceId).update();
// System.out.println("用户:"+userId+"第一次学这门课"); // System.out.println("用户:"+userId+"第一次学这门课");
//添加完成状态
recordResourceFinishService.addFinish(resourceLearningRecord);
}else {
if (resourceLearningRecord.getFinish() == 1){
//改变完成状态
recordResourceFinishService.editFinish(resourceLearningRecord);
}
} }
}else { }else {
//该课程第一次被学,人数设置为1 //该课程第一次被学,人数设置为1
@ -77,6 +84,8 @@ public class ResourceLearningRecordServiceImpl extends ServiceImpl<ResourceLearn
resourceLearningNumber.setKnowledgeId(knowledgeId); resourceLearningNumber.setKnowledgeId(knowledgeId);
resourceLearningNumber.setResourceId(resourceId); resourceLearningNumber.setResourceId(resourceId);
resourceLearningNumberService.save(resourceLearningNumber); resourceLearningNumberService.save(resourceLearningNumber);
//添加完成状态
recordResourceFinishService.addFinish(resourceLearningRecord);
} }
//设置人数 //设置人数
String numberId = resourceLearningNumberService.query() String numberId = resourceLearningNumberService.query()
@ -84,21 +93,12 @@ public class ResourceLearningRecordServiceImpl extends ServiceImpl<ResourceLearn
.eq("knowledge_id",knowledgeId) .eq("knowledge_id",knowledgeId)
.eq("resource_id",resourceId).one().getId(); .eq("resource_id",resourceId).one().getId();
resourceLearningRecord.setNumber(numberId); resourceLearningRecord.setNumber(numberId);
//判断该资源是否学习完成 //设置完成状态
if (resourceLearningRecord.getFinish() == 1){ Integer finishId = recordResourceFinishService.query()
//如果完成将该资源,新加一条所属知识点已完成的学习记录 .eq("course_id", courseId)
KnowledgeLearningRecord kl = new KnowledgeLearningRecord(); .eq("knowledge_id", knowledgeId)
kl.setFinish(1); .eq("user_id",userId).one().getId();
kl.setCoursesId(resourceLearningRecord.getCoursesId()); resourceLearningRecord.setFinish(finishId);
kl.setUserId(resourceLearningRecord.getUserId());
kl.setKnowledgeId(resourceLearningRecord.getKnowledgeId());
// kl.setKnowledgeName()
System.out.println(kl);
// kl.setFinish(1);
//更新知识点完成状态
knowledgeLearningRecordService.save(kl);
//knowledgeLearningRecordService.updateById(kl);
}
//保存记录 //保存记录
save(resourceLearningRecord); save(resourceLearningRecord);
return ResultUtils.success("添加成功"); return ResultUtils.success("添加成功");

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

Loading…
Cancel
Save