Merge remote-tracking branch 'origin/zcc'

This commit is contained in:
wangjinlei
2024-08-30 17:27:15 +08:00
9 changed files with 298 additions and 70 deletions

View File

@@ -306,7 +306,7 @@ public class BuyOrderController {
addEbookToUser(buyOrderProductList, buyOrder, 0); addEbookToUser(buyOrderProductList, buyOrder, 0);
addCourseToUser(buyOrder); addCourseToUser(buyOrder);
} else { } else {
return R.error(500, "花生币余额不足!"); return R.error(500, "天医币余额不足!");
} }
} }
// 2. 微信支付,需要预支付 // 2. 微信支付,需要预支付

View File

@@ -2,16 +2,16 @@ package com.peanut.modules.common.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.peanut.common.utils.R; import com.peanut.common.utils.R;
import com.peanut.modules.common.entity.ClassEntity; import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.entity.ClassModel;
import com.peanut.modules.common.entity.ClassTask;
import com.peanut.modules.common.entity.ClassTaskAndQuesReply;
import com.peanut.modules.common.service.ClassEntityService; import com.peanut.modules.common.service.ClassEntityService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -33,6 +33,15 @@ public class ClassController {
//新增班级模型 //新增班级模型
@RequestMapping("/addClassModel") @RequestMapping("/addClassModel")
public R addClassModel(@RequestBody ClassModel classModel){ public R addClassModel(@RequestBody ClassModel classModel){
String[] courseIds = classModel.getCourseIds().split(",");
if(courseIds.length > 0){
HashSet<String> set = new HashSet<>();
for (String courseId : courseIds) {
if (!set.add(courseId)){
return R.error("课程不能重复");
}
}
}
int score = 0; int score = 0;
if (classModel.getIsQuestion()==1){ if (classModel.getIsQuestion()==1){
score += classModel.getQuestionScore(); score += classModel.getQuestionScore();
@@ -50,11 +59,7 @@ public class ClassController {
score += classModel.getExamScore(); score += classModel.getExamScore();
} }
if (score==100){ if (score==100){
if (classEntityService.addClassModel(classModel)){ return classEntityService.addClassModel(classModel);
return R.ok();
}else {
return R.error("保存出错");
}
}else { }else {
return R.error("请设置各模块占比总和为100"); return R.error("请设置各模块占比总和为100");
} }
@@ -63,6 +68,15 @@ public class ClassController {
//修改班级模型 //修改班级模型
@RequestMapping("/editClassModel") @RequestMapping("/editClassModel")
public R editClassModel(@RequestBody ClassModel classModel){ public R editClassModel(@RequestBody ClassModel classModel){
String[] courseIds = classModel.getCourseIds().split(",");
if(courseIds.length > 0){
HashSet<String> set = new HashSet<>();
for (String courseId : courseIds) {
if (!set.add(courseId)){
return R.error("课程不能重复");
}
}
}
int score = 0; int score = 0;
if (classModel.getIsQuestion()==1){ if (classModel.getIsQuestion()==1){
score += classModel.getQuestionScore(); score += classModel.getQuestionScore();
@@ -86,6 +100,13 @@ public class ClassController {
} }
} }
//获取模型可选课程
@RequestMapping("/getClassModelCourseList")
public R getClassModelCourseList(@RequestBody Map<String,Object> params){
List<CourseEntity> courseList = classEntityService.getClassModelCourseList(params);
return R.ok().put("courseList",courseList);
}
//获取主任下的班级模型 //获取主任下的班级模型
@RequestMapping("/getClassModelByUserid") @RequestMapping("/getClassModelByUserid")
public R getClassModelByUserid(@RequestBody Map<String,Object> params){ public R getClassModelByUserid(@RequestBody Map<String,Object> params){
@@ -318,4 +339,10 @@ public class ClassController {
return R.ok().put("result",classEntityService.getUserScore(params)); return R.ok().put("result",classEntityService.getUserScore(params));
} }
//学员成绩列表
@RequestMapping("/userScoreList")
public R userScoreList(@RequestBody Map<String,Object> params){
return R.ok().put("result",classEntityService.userScoreList(params));
}
} }

View File

@@ -39,13 +39,12 @@ public class ClassExamController {
public R importSubject(@RequestParam("file") MultipartFile file, @RequestParam("courseId") int courseId) { public R importSubject(@RequestParam("file") MultipartFile file, @RequestParam("courseId") int courseId) {
int num = 0; int num = 0;
try (InputStream fis = file.getInputStream()) { try (InputStream fis = file.getInputStream()) {
List<ClassExamOption> optionList = new ArrayList<>(); //解析数据
Long time = System.currentTimeMillis();
ExcelUtil example = new ExcelUtil(); ExcelUtil example = new ExcelUtil();
example.processOneSheet(fis); example.processOneSheet(fis);
Long endtime = System.currentTimeMillis();
LinkedHashMap<String, String> map = example.getRowContents(); LinkedHashMap<String, String> map = example.getRowContents();
Iterator<Map.Entry<String, String>> it = map.entrySet().iterator(); Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
//处理数据
int count = 0; int count = 0;
while (it.hasNext()) { while (it.hasNext()) {
Map.Entry<String, String> entry = it.next(); Map.Entry<String, String> entry = it.next();
@@ -54,20 +53,54 @@ public class ClassExamController {
count = Integer.parseInt(rowNo); count = Integer.parseInt(rowNo);
// System.out.println(pos + ";" + entry.getValue()); // System.out.println(pos + ";" + entry.getValue());
} }
List<ClassExamOption> optionList = new ArrayList<>();
//先校验数据
StringBuffer sb = new StringBuffer();
for (int i=2;i<=count;i++){
//类型
String type = map.containsKey("A"+i)?map.get("A"+i):"";
if (type.contains("单选")||type.contains("多选")){
}else {
sb.append(""+i+"行题目类型出错\n");
}
String option1 = map.containsKey("C"+i)?map.get("C"+i):"";
if (StringUtils.isBlank(option1)){
sb.append(""+i+"行无选项1\n");
}
String option2 = map.containsKey("D"+i)?map.get("D"+i):"";
if (StringUtils.isBlank(option2)){
sb.append(""+i+"行无选项2\n");
}
String option3 = map.containsKey("E"+i)?map.get("E"+i):"";
if (StringUtils.isBlank(option3)){
sb.append(""+i+"行无选项3\n");
}
String option4 = map.containsKey("F"+i)?map.get("F"+i):"";
if (StringUtils.isBlank(option4)){
sb.append(""+i+"行无选项4\n");
}
String answer = map.containsKey("I"+i)?map.get("I"+i):"";
if (StringUtils.isBlank(answer)){
sb.append(""+i+"行无答案\n");
}
//题目
String content = map.containsKey("B"+i)?map.get("B"+i):"";
if (StringUtils.isBlank(content)) {
sb.append(""+i+"行无题目\n");
}
}
if (sb.length() > 0){
throw new Exception(sb.toString());
}
for (int i=2;i<=count;i++){ for (int i=2;i<=count;i++){
ClassExamSubject subject = new ClassExamSubject(); ClassExamSubject subject = new ClassExamSubject();
subject.setCourseId(courseId); subject.setCourseId(courseId);
//类型 if (map.get("A"+i).contains("单选")){
String type = map.containsKey("A"+i)?map.get("A"+i):"";
if (type.contains("单选")){
subject.setType(0); subject.setType(0);
}else if (type.contains("多选")){ }else if (map.get("A"+i).contains("多选")){
subject.setType(1); subject.setType(1);
}else {
throw new Exception(""+i+"题无题目类型");
} }
//题目 subject.setContent(map.get("B"+i));
subject.setContent(map.containsKey("B"+i)?map.get("B"+i):"");
//所属章节 //所属章节
subject.setChapter(map.containsKey("N"+i)?map.get("N"+i):""); subject.setChapter(map.containsKey("N"+i)?map.get("N"+i):"");
//音视频序号 //音视频序号
@@ -78,15 +111,15 @@ public class ClassExamController {
subject.setCreateUser(map.containsKey("Q"+i)?map.get("Q"+i):""); subject.setCreateUser(map.containsKey("Q"+i)?map.get("Q"+i):"");
classExamSubjectService.save(subject); classExamSubjectService.save(subject);
num++; num++;
insertOption(optionList,subject.getId(),map.containsKey("C"+i)?map.get("C"+i):"",map.containsKey("I"+i)?map.get("I"+i):""); //插入选项
insertOption(optionList,subject.getId(),map.containsKey("D"+i)?map.get("D"+i):"",map.containsKey("I"+i)?map.get("I"+i):""); insertOption(optionList,subject.getId(),map.get("C"+i),map.get("I"+i));
insertOption(optionList,subject.getId(),map.containsKey("E"+i)?map.get("E"+i):"",map.containsKey("I"+i)?map.get("I"+i):""); insertOption(optionList,subject.getId(),map.get("D"+i),map.get("I"+i));
insertOption(optionList,subject.getId(),map.containsKey("F"+i)?map.get("F"+i):"",map.containsKey("I"+i)?map.get("I"+i):""); insertOption(optionList,subject.getId(),map.get("E"+i),map.get("I"+i));
insertOption(optionList,subject.getId(),map.containsKey("G"+i)?map.get("G"+i):"",map.containsKey("I"+i)?map.get("I"+i):""); insertOption(optionList,subject.getId(),map.get("F"+i),map.get("I"+i));
insertOption(optionList,subject.getId(),map.containsKey("H"+i)?map.get("H"+i):"",map.containsKey("I"+i)?map.get("I"+i):""); insertOption(optionList,subject.getId(),map.containsKey("G"+i)?map.get("G"+i):"",map.get("I"+i));
insertOption(optionList,subject.getId(),map.containsKey("H"+i)?map.get("H"+i):"",map.get("I"+i));
} }
classExamOptionService.saveBatch(optionList); classExamOptionService.saveBatch(optionList);
System.out.println("解析数据" + count + "条;耗时" + (endtime - time) / 1000 + "");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
@@ -127,20 +160,26 @@ public class ClassExamController {
return R.ok().put("page",classExamSubjectList); return R.ok().put("page",classExamSubjectList);
} }
//考试题目列表 //生成试卷
@RequestMapping("/generateExamPaper") @RequestMapping("/generateExamPaper")
public R generateExamPaper(@RequestBody Map<String,Object> params){ public R generateExamPaper(@RequestBody Map<String,Object> params){
Object examPaper = classExamService.generateExamPaper(params); return classExamService.generateExamPaper(params);
return R.ok().put("examPaper",examPaper);
} }
//提交 //提交
@RequestMapping("/submitExamPaper") @RequestMapping("/submitExamPaper")
public R submitExamPaper(@RequestBody Map<String,Object> params){ public R submitExamPaper(@RequestBody Map<String,Object> params){
Object examPaper = classExamService.submitExamPaper(params); Object examPaper = classExamService.submitExamPaper(params);
return R.ok().put("examPaper",examPaper); return R.ok().put("examPaper",examPaper);
} }
//试卷详情
@RequestMapping("/getExamPaperInfo")
public R getExamPaperInfo(@RequestBody Map<String,Object> params){
Object examPaper = classExamService.getExamPaperInfo(params);
return R.ok().put("examPaper",examPaper);
}

View File

@@ -12,7 +12,7 @@ public class ClassExamUser {
@TableId @TableId
private Integer id; private Integer id;
private Integer examId; private Integer classId;
private Integer userId; private Integer userId;

View File

@@ -11,10 +11,12 @@ public interface ClassEntityService extends IService<ClassEntity> {
Page getClassModelList(Map<String ,Object> params); Page getClassModelList(Map<String ,Object> params);
boolean addClassModel(ClassModel classModel); R addClassModel(ClassModel classModel);
R editClassModel(ClassModel classModel); R editClassModel(ClassModel classModel);
List<CourseEntity> getClassModelCourseList(Map<String, Object> params);
List<ClassModel> getClassModelByUserid(Map<String ,Object> params); List<ClassModel> getClassModelByUserid(Map<String ,Object> params);
List<Map<String, Object>> getClassByDirectorid(Map<String,Object> params); List<Map<String, Object>> getClassByDirectorid(Map<String,Object> params);
@@ -85,4 +87,6 @@ public interface ClassEntityService extends IService<ClassEntity> {
Map<String,Object> getUserScore(Map<String,Object> params); Map<String,Object> getUserScore(Map<String,Object> params);
List userScoreList(Map<String,Object> params);
} }

View File

@@ -2,6 +2,7 @@ package com.peanut.modules.common.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.common.utils.R;
import com.peanut.modules.common.entity.ClassExam; import com.peanut.modules.common.entity.ClassExam;
import com.peanut.modules.common.entity.ClassExamOption; import com.peanut.modules.common.entity.ClassExamOption;
import com.peanut.modules.common.entity.ClassExamSubject; import com.peanut.modules.common.entity.ClassExamSubject;
@@ -25,8 +26,10 @@ public interface ClassExamService extends IService<ClassExam> {
Page getClassExamSubjectList(Map<String,Object> params); Page getClassExamSubjectList(Map<String,Object> params);
Object generateExamPaper(Map<String,Object> params); R generateExamPaper(Map<String,Object> params);
Object submitExamPaper(Map<String,Object> params); Object submitExamPaper(Map<String,Object> params);
Object getExamPaperInfo(Map<String,Object> params);
} }

View File

@@ -17,6 +17,8 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.*; import java.util.*;
@@ -43,6 +45,10 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
private UserCourseBuyDao userCourseBuyDao; private UserCourseBuyDao userCourseBuyDao;
@Autowired @Autowired
private CourseDao courseDao; private CourseDao courseDao;
@Autowired
private ClassExamUserDao classExamUserDao;
@Autowired
private CourseCatalogueChapterDao courseCatalogueChapterDao;
@Override @Override
public Page getClassModelList(Map<String, Object> params) { public Page getClassModelList(Map<String, Object> params) {
@@ -62,7 +68,8 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
} }
@Override @Override
public boolean addClassModel(ClassModel classModel) { @Transactional
public R addClassModel(ClassModel classModel) {
classModelDao.insert(classModel); classModelDao.insert(classModel);
String[] courseIds = classModel.getCourseIds().split(","); String[] courseIds = classModel.getCourseIds().split(",");
if(courseIds.length > 0){ if(courseIds.length > 0){
@@ -73,7 +80,7 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
classCourseDao.insert(classCourse); classCourseDao.insert(classCourse);
} }
} }
return true; return R.ok();
} }
@Override @Override
@@ -102,6 +109,17 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
} }
} }
@Override
public List<CourseEntity> getClassModelCourseList(Map<String, Object> params) {
MPJLambdaWrapper<CourseEntity> wrapper = new MPJLambdaWrapper();
wrapper.exists("select * from course_to_medicine where del_flag = 0 and course_id = t.id");
wrapper.like(CourseEntity::getTitle,params.get("title"));
wrapper.selectAs(CourseEntity::getId,"id");
wrapper.selectAs(CourseEntity::getTitle,"title");
List<CourseEntity> list = courseDao.selectList(wrapper);
return list;
}
@Override @Override
public List<ClassModel> getClassModelByUserid(Map<String, Object> params) { public List<ClassModel> getClassModelByUserid(Map<String, Object> params) {
LambdaQueryWrapper<ClassModel> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<ClassModel> wrapper = new LambdaQueryWrapper<>();
@@ -530,6 +548,7 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
public List<ClassEntity> getClassNoUser() { public List<ClassEntity> getClassNoUser() {
MPJLambdaWrapper<ClassEntity> wrapper = new MPJLambdaWrapper<>(); MPJLambdaWrapper<ClassEntity> wrapper = new MPJLambdaWrapper<>();
wrapper.selectAll(ClassEntity.class); wrapper.selectAll(ClassEntity.class);
wrapper.eq(ClassEntity::getState,"0");
String classSql = "select 1 from ( select c.id from class c left join class_course cc on cc.model_id = c.model_id left join class_user cu on cu.class_id = c.id where c.del_flag = 0 and cc.del_flag = 0 and cu.del_flag = 0 and cu.user_id = "+ShiroUtils.getUId()+" ) s where s.id = t.id"; String classSql = "select 1 from ( select c.id from class c left join class_course cc on cc.model_id = c.model_id left join class_user cu on cu.class_id = c.id where c.del_flag = 0 and cc.del_flag = 0 and cu.del_flag = 0 and cu.user_id = "+ShiroUtils.getUId()+" ) s where s.id = t.id";
String courseSql = "select 1 from (select cc.model_id from class_course cc where cc.del_flag = 0 and cc.course_id in (select cc.course_id from class_course cc left join class_model cm on cm.id = cc.model_id left join class c on c.model_id = cm.id left join class_user cu on cu.class_id = c.id where cc.del_flag = 0 and cm.del_flag = 0 and c.del_flag = 0 and cu.del_flag = 0 and cu.user_id = "+ShiroUtils.getUId()+")) q where q.model_id = t.model_id"; String courseSql = "select 1 from (select cc.model_id from class_course cc where cc.del_flag = 0 and cc.course_id in (select cc.course_id from class_course cc left join class_model cm on cm.id = cc.model_id left join class c on c.model_id = cm.id left join class_user cu on cu.class_id = c.id where cc.del_flag = 0 and cm.del_flag = 0 and c.del_flag = 0 and cu.del_flag = 0 and cu.user_id = "+ShiroUtils.getUId()+")) q where q.model_id = t.model_id";
wrapper.notExists(classSql); wrapper.notExists(classSql);
@@ -968,9 +987,13 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
questionWrapper.leftJoin(ClassModel.class,ClassModel::getId,ClassCourse::getModelId); questionWrapper.leftJoin(ClassModel.class,ClassModel::getId,ClassCourse::getModelId);
questionWrapper.leftJoin(ClassEntity.class,ClassEntity::getModelId,ClassModel::getId); questionWrapper.leftJoin(ClassEntity.class,ClassEntity::getModelId,ClassModel::getId);
questionWrapper.selectAll(ClassTaskAndQuesReply.class); questionWrapper.selectAll(ClassTaskAndQuesReply.class);
questionWrapper.eq(ClassEntity::getId,params.get("classId")); questionWrapper.eq(ClassEntity::getId,classEntity.getId());
if (params.containsKey("userId")){
questionWrapper.eq(ClassTaskAndQuesReply::getUserId,params.get("userId"));
}else {
questionWrapper.eq(ClassTaskAndQuesReply::getUserId,ShiroUtils.getUId()); questionWrapper.eq(ClassTaskAndQuesReply::getUserId,ShiroUtils.getUId());
questionWrapper.eq(ClassTaskAndQuesReply::getClassId,params.get("classId")); }
questionWrapper.eq(ClassTaskAndQuesReply::getClassId,classEntity.getId());
List<ClassTaskAndQuesReply> questionReplys = classTaskAndQuesReplyDao.selectList(questionWrapper); List<ClassTaskAndQuesReply> questionReplys = classTaskAndQuesReplyDao.selectList(questionWrapper);
if (questionReplys.size() > 0) { if (questionReplys.size() > 0) {
for (ClassTaskAndQuesReply reply : questionReplys) { for (ClassTaskAndQuesReply reply : questionReplys) {
@@ -986,7 +1009,7 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
MPJLambdaWrapper<ClassTaskAndQuesReply> task0wrapper = new MPJLambdaWrapper<>(); MPJLambdaWrapper<ClassTaskAndQuesReply> task0wrapper = new MPJLambdaWrapper<>();
task0wrapper.leftJoin(ClassTask.class,ClassTask::getId,ClassTaskAndQuesReply::getRelationId); task0wrapper.leftJoin(ClassTask.class,ClassTask::getId,ClassTaskAndQuesReply::getRelationId);
task0wrapper.selectAll(ClassTaskAndQuesReply.class); task0wrapper.selectAll(ClassTaskAndQuesReply.class);
task0wrapper.eq(ClassTask::getClassId,params.get("classId")); task0wrapper.eq(ClassTask::getClassId,classEntity.getId());
task0wrapper.eq(ClassTask::getType,"0"); task0wrapper.eq(ClassTask::getType,"0");
task0wrapper.eq(ClassTaskAndQuesReply::getUserId,ShiroUtils.getUId()); task0wrapper.eq(ClassTaskAndQuesReply::getUserId,ShiroUtils.getUId());
List<ClassTaskAndQuesReply> task0Replys = classTaskAndQuesReplyDao.selectList(task0wrapper); List<ClassTaskAndQuesReply> task0Replys = classTaskAndQuesReplyDao.selectList(task0wrapper);
@@ -1004,7 +1027,7 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
MPJLambdaWrapper<ClassTaskAndQuesReply> task1wrapper = new MPJLambdaWrapper<>(); MPJLambdaWrapper<ClassTaskAndQuesReply> task1wrapper = new MPJLambdaWrapper<>();
task1wrapper.leftJoin(ClassTask.class,ClassTask::getId,ClassTaskAndQuesReply::getRelationId); task1wrapper.leftJoin(ClassTask.class,ClassTask::getId,ClassTaskAndQuesReply::getRelationId);
task1wrapper.selectAll(ClassTaskAndQuesReply.class); task1wrapper.selectAll(ClassTaskAndQuesReply.class);
task1wrapper.eq(ClassTask::getClassId,params.get("classId")); task1wrapper.eq(ClassTask::getClassId,classEntity.getId());
task1wrapper.eq(ClassTask::getType,"1"); task1wrapper.eq(ClassTask::getType,"1");
task1wrapper.eq(ClassTaskAndQuesReply::getUserId,ShiroUtils.getUId()); task1wrapper.eq(ClassTaskAndQuesReply::getUserId,ShiroUtils.getUId());
List<ClassTaskAndQuesReply> task1Replys = classTaskAndQuesReplyDao.selectList(task1wrapper); List<ClassTaskAndQuesReply> task1Replys = classTaskAndQuesReplyDao.selectList(task1wrapper);
@@ -1021,7 +1044,7 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
double experienceScore = 0; double experienceScore = 0;
MPJLambdaWrapper<ClassTask> experiencewrapper = new MPJLambdaWrapper<>(); MPJLambdaWrapper<ClassTask> experiencewrapper = new MPJLambdaWrapper<>();
experiencewrapper.eq(ClassTask::getUserId,ShiroUtils.getUId()); experiencewrapper.eq(ClassTask::getUserId,ShiroUtils.getUId());
experiencewrapper.eq(ClassTask::getClassId,params.get("classId")); experiencewrapper.eq(ClassTask::getClassId,classEntity.getId());
experiencewrapper.eq(ClassTask::getType,"2"); experiencewrapper.eq(ClassTask::getType,"2");
List<ClassTask> experiences = classTaskDao.selectList(experiencewrapper); List<ClassTask> experiences = classTaskDao.selectList(experiencewrapper);
if (experiences.size() > 0) { if (experiences.size() > 0) {
@@ -1036,5 +1059,106 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
return map; return map;
} }
@Override
public List userScoreList(Map<String, Object> params) {
ClassEntity classEntity = this.getBaseMapper().selectById(params.get("classId").toString());
ClassModel classModel = classModelDao.selectById(classEntity.getModelId());
List<ClassUser> classUsers = classUserDao.selectList(new LambdaQueryWrapper<ClassUser>()
.eq(ClassUser::getClassId,classEntity.getId()).eq(ClassUser::getRole,"0"));
List<Map<String,Object>> resultList = new ArrayList<>();
if (classUsers.size() > 0){
for (ClassUser classUser:classUsers){
params.put("userId",classUser.getUserId());
Map<String,Object> map = getUserScore(params);
map.put("user",myUserDao.selectById(classUser.getUserId()));
if (classModel.getIsExam()==1){
List<ClassExamUser> classExamUsers = classExamUserDao.selectList(new LambdaQueryWrapper<ClassExamUser>()
.eq(ClassExamUser::getUserId,classUser.getUserId())
.eq(ClassExamUser::getClassId,classEntity.getId()));
int examScore = 0;
for (ClassExamUser classExamUser:classExamUsers){
if (classExamUser.getScore()>examScore){
examScore = classExamUser.getScore();
}
}
map.put("examScore",examScore);
}
//处理分数占比
BigDecimal userScore = new BigDecimal(0);;
double staticScore = 2.5;
if(classModel.getIsExam()==1){
BigDecimal examScore = new BigDecimal(map.get("examScore").toString());
examScore.divide(new BigDecimal(100));
examScore.multiply(new BigDecimal(classModel.getQuestionScore()));
examScore = examScore.setScale(2,RoundingMode.HALF_UP);
map.put("examScore",examScore);
userScore.add(examScore);
}
if(classModel.getIsQuestion()==1){
BigDecimal questionScore = new BigDecimal(map.get("questionScore").toString());
MPJLambdaWrapper<CourseCatalogueChapterEntity> wrapper = new MPJLambdaWrapper();
wrapper.leftJoin(ClassCourse.class,ClassCourse::getCourseId,CourseCatalogueChapterEntity::getCourseId);
wrapper.leftJoin(ClassModel.class,ClassModel::getId,ClassCourse::getModelId);
wrapper.eq(ClassModel::getId,classModel.getId());
wrapper.ne(CourseCatalogueChapterEntity::getQuestions,"");
int count = courseCatalogueChapterDao.selectCount(wrapper);
BigDecimal totalScore = new BigDecimal(staticScore*count);
questionScore.divide(totalScore);
questionScore.multiply(new BigDecimal(classModel.getQuestionScore()));
questionScore = questionScore.setScale(2,RoundingMode.HALF_UP);
map.put("questionScore",questionScore);
userScore.add(questionScore);
}
if(classModel.getIsTask()==1){
BigDecimal task0Score = new BigDecimal(map.get("task0Score").toString());
MPJLambdaWrapper<ClassTask> wrapper = new MPJLambdaWrapper();
wrapper.eq(ClassTask::getClassId,classEntity.getId());
wrapper.eq(ClassTask::getType,"0");
int count = classTaskDao.selectCount(wrapper);
BigDecimal totalScore = new BigDecimal(staticScore*count);
task0Score.divide(totalScore);
task0Score.multiply(new BigDecimal(classModel.getTaskScore()));
task0Score = task0Score.setScale(2,RoundingMode.HALF_UP);
map.put("task0Score",task0Score);
userScore.add(task0Score);
}
if(classModel.getIsMedicalcase()==1){
BigDecimal task1Score = new BigDecimal(map.get("task1Score").toString());
MPJLambdaWrapper<ClassTask> wrapper = new MPJLambdaWrapper();
wrapper.eq(ClassTask::getClassId,classEntity.getId());
wrapper.eq(ClassTask::getType,"1");
int count = classTaskDao.selectCount(wrapper);
BigDecimal totalScore = new BigDecimal(staticScore*count);
task1Score.divide(totalScore);
task1Score.multiply(new BigDecimal(classModel.getMedicalcaseScore()));
task1Score = task1Score.setScale(2,RoundingMode.HALF_UP);
map.put("task1Score",task1Score);
userScore.add(task1Score);
}
if(classModel.getIsExperience()==1){
BigDecimal experienceScore = new BigDecimal(map.get("experienceScore").toString());
if (experienceScore.compareTo(new BigDecimal(classModel.getExperienceScore()))>-1){
experienceScore = new BigDecimal(classModel.getExperienceScore());
}
map.put("experienceScore",experienceScore);
userScore.add(experienceScore);
}
map.put("userScore",userScore);
resultList.add(map);
}
Collections.sort(resultList, new Comparator<Map<String,Object>>() {
@Override
public int compare(Map<String,Object> m1, Map<String,Object> m2) {
if((double)(m2.get("userScore")) > (double)(m1.get("userScore"))){
return 1;
}else {
return -1;
}
}
});
}
return resultList;
}
} }

View File

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.utils.R;
import com.peanut.common.utils.ShiroUtils; import com.peanut.common.utils.ShiroUtils;
import com.peanut.modules.common.dao.*; import com.peanut.modules.common.dao.*;
import com.peanut.modules.common.entity.*; import com.peanut.modules.common.entity.*;
@@ -27,6 +28,8 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
private ClassCourseDao classCourseDao; private ClassCourseDao classCourseDao;
@Autowired @Autowired
private ClassExamUserDao classExamUserDao; private ClassExamUserDao classExamUserDao;
@Autowired
private CourseDao courseDao;
@Override @Override
public void addClassExamSubject(ClassExamSubject classExamSubject) { public void addClassExamSubject(ClassExamSubject classExamSubject) {
@@ -104,61 +107,80 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
} }
@Override @Override
public Object generateExamPaper(Map<String, Object> params) { public R generateExamPaper(Map<String, Object> params) {
MPJLambdaWrapper<ClassCourse> courseWrapper = new MPJLambdaWrapper<>(); MPJLambdaWrapper<ClassCourse> courseWrapper = new MPJLambdaWrapper<>();
courseWrapper.leftJoin(ClassModel.class,ClassModel::getId,ClassCourse::getModelId); courseWrapper.leftJoin(ClassModel.class,ClassModel::getId,ClassCourse::getModelId);
courseWrapper.leftJoin(ClassEntity.class,ClassEntity::getModelId,ClassModel::getId); courseWrapper.leftJoin(ClassEntity.class,ClassEntity::getModelId,ClassModel::getId);
courseWrapper.eq(ClassEntity::getId,params.get("classId")); courseWrapper.eq(ClassEntity::getId,params.get("classId"));
courseWrapper.selectAll(ClassCourse.class); courseWrapper.selectAll(ClassCourse.class);
List<ClassCourse> courseList = classCourseDao.selectList(courseWrapper); List<ClassCourse> courseList = classCourseDao.selectList(courseWrapper);
List<ClassExamSubject> resultList = new ArrayList<>(); List<Map<String,Object>> resultList = new ArrayList<>();
List<ClassExamSubject> sList = new ArrayList<>(); List<Map<String,Object>> sList = new ArrayList<>();
List<ClassExamSubject> mList = new ArrayList<>(); List<Map<String,Object>> mList = new ArrayList<>();
if (courseList.size() > 0) { if (courseList.size() > 0) {
int stotal = 50;//单选题总数 int stotal = 5;//单选题总数
int mtotal = 50;//多选题总数 int mtotal = 5;//多选题总数
int snum = (int)Math.floor(stotal/courseList.size()); int snum = (int)Math.floor(stotal/courseList.size());
int mnum = (int)Math.floor(mtotal/courseList.size()); int mnum = (int)Math.floor(mtotal/courseList.size());
for (ClassCourse course:courseList){ for (ClassCourse classCourse:courseList){
CourseEntity course = courseDao.selectById(classCourse.getCourseId());
//单选 //单选
List<ClassExamSubject> singleList = classExamSubjectDao.selectList(new LambdaQueryWrapper<ClassExamSubject>() List<Map<String,Object>> singleList = classExamSubjectDao.selectMaps(new MPJLambdaWrapper<ClassExamSubject>()
.eq(ClassExamSubject::getCourseId,course.getCourseId()) .selectAs(ClassExamSubject::getId,"id")
.selectAs(ClassExamSubject::getType,"type")
.selectAs(ClassExamSubject::getContent,"content")
.eq(ClassExamSubject::getCourseId,classCourse.getCourseId())
.eq(ClassExamSubject::getType,0)); .eq(ClassExamSubject::getType,0));
Collections.shuffle(singleList);//打乱顺序 Collections.shuffle(singleList);//打乱顺序
try {
if (sList.size()+snum>stotal){ if (sList.size()+snum>stotal){
sList.addAll(singleList.subList(0,stotal-sList.size())); sList.addAll(singleList.subList(0,stotal-sList.size()));
}else { }else {
sList.addAll(singleList.subList(0,snum)); sList.addAll(singleList.subList(0,snum));
} }
}catch (Exception e) {
return R.error(course.getTitle()+"-单选题数量不足");
}
//多选 //多选
List<ClassExamSubject> mulList = classExamSubjectDao.selectList(new LambdaQueryWrapper<ClassExamSubject>() List<Map<String,Object>> mulList = classExamSubjectDao.selectMaps(new MPJLambdaWrapper<ClassExamSubject>()
.eq(ClassExamSubject::getCourseId,course.getCourseId()) .selectAs(ClassExamSubject::getId,"id")
.selectAs(ClassExamSubject::getType,"type")
.selectAs(ClassExamSubject::getContent,"content")
.eq(ClassExamSubject::getCourseId,classCourse.getCourseId())
.eq(ClassExamSubject::getType,1)); .eq(ClassExamSubject::getType,1));
Collections.shuffle(mulList);//打乱顺序 Collections.shuffle(mulList);//打乱顺序
try {
if (mList.size()+mnum>mtotal){ if (mList.size()+mnum>mtotal){
mList.addAll(mulList.subList(0,mtotal-mList.size())); mList.addAll(mulList.subList(0,mtotal-mList.size()));
}else { }else {
mList.addAll(mulList.subList(0,mnum)); mList.addAll(mulList.subList(0,mnum));
} }
}catch (Exception e) {
return R.error(course.getTitle()+"-多选题数量不足");
}
} }
} }
resultList.addAll(sList); resultList.addAll(sList);
resultList.addAll(mList); resultList.addAll(mList);
//拼装选项 //拼装选项
if (resultList.size()>0){ if (resultList.size()>0){
for (ClassExamSubject subject:resultList) { for (Map<String,Object> subject:resultList) {
List<ClassExamOption> options = classExamOptionDao.selectList( List<Map<String,Object>> options = classExamOptionDao.selectMaps(new MPJLambdaWrapper<ClassExamOption>()
new LambdaQueryWrapper<ClassExamOption>().eq(ClassExamOption::getSubjectId,subject.getId())); .selectAs(ClassExamOption::getId,"id")
.selectAs(ClassExamOption::getContent,"content")
.selectAs(ClassExamOption::getRightWrong,"rightWrong")
.eq(ClassExamOption::getSubjectId,subject.get("id")));
Collections.shuffle(options);//打乱顺序 Collections.shuffle(options);//打乱顺序
subject.setOptions(options); subject.put("options",options);
} }
} }
ClassExamUser classExamUser = new ClassExamUser(); ClassExamUser classExamUser = new ClassExamUser();
classExamUser.setExamId(this.getBaseMapper().selectOne(new LambdaQueryWrapper<ClassExam>().eq(ClassExam::getClassId,params.get("classId"))).getId()); classExamUser.setClassId(Integer.parseInt(params.get("classId").toString()));
classExamUser.setSubject(JSONUtil.toJsonStr(resultList)); classExamUser.setSubject(JSONUtil.toJsonStr(resultList));
classExamUser.setUserId(ShiroUtils.getUId()); classExamUser.setUserId(ShiroUtils.getUId());
classExamUserDao.insert(classExamUser); classExamUserDao.insert(classExamUser);
return resultList; return R.ok().put("examPaper",resultList).put("id",classExamUser.getId());
} }
@Override @Override
@@ -204,4 +226,13 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
return classExamUser; return classExamUser;
} }
@Override
public Object getExamPaperInfo(Map<String, Object> params) {
List<ClassExamUser> classExamUserList = classExamUserDao.selectList(new LambdaQueryWrapper<ClassExamUser>()
.eq(ClassExamUser::getClassId,params.get("classId"))
.eq(ClassExamUser::getUserId,params.get("userId"))
.orderByDesc(ClassExamUser::getScore));
return classExamUserList;
}
} }

View File

@@ -85,7 +85,7 @@ public class UserVipController {
return R.error("积分不足"); return R.error("积分不足");
} }
}else { }else {
return R.error("花生币不足"); return R.error("天医币不足");
} }
} }
@@ -107,7 +107,7 @@ public class UserVipController {
return R.error("积分不足"); return R.error("积分不足");
} }
}else { }else {
return R.error("花生币不足"); return R.error("天医币不足");
} }
} }