|
|
@@ -43,10 +43,16 @@ import com.xjrsoft.module.assessment.vo.AssessmentPlanAnswerDetailVo;
|
|
|
import com.xjrsoft.module.assessment.vo.AssessmentPlanAnswerStudentPageVo;
|
|
|
import com.xjrsoft.module.assessment.vo.AssessmentPlanAnswerStudentVo;
|
|
|
import com.xjrsoft.module.assessment.vo.AssessmentPlanAnswerTeacherPageVo;
|
|
|
+import com.xjrsoft.module.assessment.vo.AssessmentQuestionOptionResultVo;
|
|
|
import com.xjrsoft.module.assessment.vo.AssessmentQuestionResultVo;
|
|
|
import com.xjrsoft.module.assessment.vo.AssessmentQuestionVo;
|
|
|
import com.xjrsoft.module.assessment.vo.AssessmentTemplatePlanPageVo;
|
|
|
import com.xjrsoft.module.assessment.vo.AssessmentTemplatePlanQuestionVo;
|
|
|
+import com.xjrsoft.module.assessment.vo.AssessmentTemplatePlanResultVo;
|
|
|
+import com.xjrsoft.module.assessment.vo.OneQuestionVo;
|
|
|
+import com.xjrsoft.module.assessment.vo.TwoQuestionVo;
|
|
|
+import com.xjrsoft.module.base.entity.BaseClass;
|
|
|
+import com.xjrsoft.module.base.mapper.BaseClassMapper;
|
|
|
import com.xjrsoft.module.organization.dto.WeChatSendMessageDto;
|
|
|
import com.xjrsoft.module.organization.service.IWeChatService;
|
|
|
import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
|
|
|
@@ -56,6 +62,8 @@ import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
@@ -72,7 +80,8 @@ import java.util.Random;
|
|
|
*/
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
-public class AssessmentTemplatePlanServiceImpl extends MPJBaseServiceImpl<AssessmentTemplatePlanMapper, AssessmentTemplatePlan> implements IAssessmentTemplatePlanService {
|
|
|
+public
|
|
|
+class AssessmentTemplatePlanServiceImpl extends MPJBaseServiceImpl<AssessmentTemplatePlanMapper, AssessmentTemplatePlan> implements IAssessmentTemplatePlanService {
|
|
|
private final AssessmentTemplatePlanMapper templatePlanMapper;
|
|
|
|
|
|
private final AssessmentPlanQuestionMapper planQuestionMapper;
|
|
|
@@ -84,6 +93,7 @@ public class AssessmentTemplatePlanServiceImpl extends MPJBaseServiceImpl<Assess
|
|
|
private final XjrUserMapper xjrUserMapper;
|
|
|
private final IWeChatService weChatService;
|
|
|
private final CommonPropertiesConfig commonPropertiesConfig;
|
|
|
+ private final BaseClassMapper baseClassMapper;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
@@ -111,6 +121,30 @@ public class AssessmentTemplatePlanServiceImpl extends MPJBaseServiceImpl<Assess
|
|
|
planQuestion.setAssessmentTemplatePlanId(assessmentTemplatePlan.getId());
|
|
|
planQuestionMapper.insert(planQuestion);
|
|
|
}
|
|
|
+ List<BaseClass> classList = baseClassMapper.selectList(
|
|
|
+ new QueryWrapper<BaseClass>().lambda()
|
|
|
+ .eq(BaseClass::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ .eq(BaseClass::getIsGraduate, 1)
|
|
|
+ );
|
|
|
+ List<Long> classIds = new ArrayList<>();
|
|
|
+ if("all".equals(dto.getType())){
|
|
|
+ for (BaseClass baseClass : classList) {
|
|
|
+ classIds.add(baseClass.getId());
|
|
|
+ }
|
|
|
+ }else if("random".equals(dto.getType())){
|
|
|
+ List<Integer> randomList = new ArrayList<>();
|
|
|
+ Random random = new Random();
|
|
|
+ while(randomList.size() < dto.getRandomNumber()){
|
|
|
+ int nextInt = random.nextInt(classList.size());
|
|
|
+ if(!randomList.contains(nextInt) && nextInt >= 0){
|
|
|
+ randomList.add(nextInt);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (Integer i : randomList) {
|
|
|
+ classIds.add(classList.get(i).getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
//存入班级,并根据选人方式存入答题学生
|
|
|
for (Long classId : dto.getClassIds()) {
|
|
|
@@ -123,29 +157,7 @@ public class AssessmentTemplatePlanServiceImpl extends MPJBaseServiceImpl<Assess
|
|
|
query.leftJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getUserId, XjrUser::getId)
|
|
|
.eq(BaseStudentSchoolRoll::getClassId, classId);
|
|
|
List<XjrUser> studentList = xjrUserMapper.selectJoinList(XjrUser.class, query);
|
|
|
- List<XjrUser> needStudentList = new ArrayList<>();
|
|
|
- if("all".equals(dto.getType())){
|
|
|
- needStudentList.addAll(studentList);
|
|
|
- }else if("random".equals(dto.getType())){
|
|
|
- int maxCount = studentList.size();//班级最大人数
|
|
|
- if(dto.getRandomNumber() > maxCount){
|
|
|
- needStudentList.addAll(studentList);
|
|
|
- }else{
|
|
|
- List<Integer> randomList = new ArrayList<>();
|
|
|
- Random random = new Random();
|
|
|
- while(randomList.size() < dto.getRandomNumber()){
|
|
|
- int nextInt = random.nextInt(studentList.size());
|
|
|
- if(!randomList.contains(nextInt) && nextInt >= 0){
|
|
|
- randomList.add(nextInt);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- for (Integer i : randomList) {
|
|
|
- needStudentList.add(studentList.get(i));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- for (XjrUser xjrUser : needStudentList) {
|
|
|
+ for (XjrUser xjrUser : studentList) {
|
|
|
AssessmentPlanAnswerStudent answer = new AssessmentPlanAnswerStudent();
|
|
|
answer.setAssessmentTemplatePlanId(assessmentTemplatePlan.getId());
|
|
|
answer.setStudentUserId(xjrUser.getId());
|
|
|
@@ -187,6 +199,30 @@ public class AssessmentTemplatePlanServiceImpl extends MPJBaseServiceImpl<Assess
|
|
|
//删除班级和学生
|
|
|
answerClassMapper.deleteByPlanId(assessmentTemplatePlan.getId(), StpUtil.getLoginIdAsLong());
|
|
|
studentMapper.deleteByPlanId(assessmentTemplatePlan.getId(), StpUtil.getLoginIdAsLong());
|
|
|
+ List<BaseClass> classList = baseClassMapper.selectList(
|
|
|
+ new QueryWrapper<BaseClass>().lambda()
|
|
|
+ .eq(BaseClass::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ .eq(BaseClass::getIsGraduate, 1)
|
|
|
+ );
|
|
|
+ List<Long> classIds = new ArrayList<>();
|
|
|
+ if("all".equals(dto.getType())){
|
|
|
+ for (BaseClass baseClass : classList) {
|
|
|
+ classIds.add(baseClass.getId());
|
|
|
+ }
|
|
|
+ }else if("random".equals(dto.getType())){
|
|
|
+ List<Integer> randomList = new ArrayList<>();
|
|
|
+ Random random = new Random();
|
|
|
+ while(randomList.size() < dto.getRandomNumber()){
|
|
|
+ int nextInt = random.nextInt(classList.size());
|
|
|
+ if(!randomList.contains(nextInt) && nextInt >= 0){
|
|
|
+ randomList.add(nextInt);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (Integer i : randomList) {
|
|
|
+ classIds.add(classList.get(i).getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//存入班级,并根据选人方式存入答题学生
|
|
|
for (Long classId : dto.getClassIds()) {
|
|
|
AssessmentPlanAnswerClass answerClass = new AssessmentPlanAnswerClass();
|
|
|
@@ -198,29 +234,7 @@ public class AssessmentTemplatePlanServiceImpl extends MPJBaseServiceImpl<Assess
|
|
|
query.leftJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getUserId, XjrUser::getId)
|
|
|
.eq(BaseStudentSchoolRoll::getClassId, classId);
|
|
|
List<XjrUser> studentList = xjrUserMapper.selectJoinList(XjrUser.class, query);
|
|
|
- List<XjrUser> needStudentList = new ArrayList<>();
|
|
|
- if("all".equals(dto.getType())){
|
|
|
- needStudentList.addAll(studentList);
|
|
|
- }else if("random".equals(dto.getType())){
|
|
|
- int maxCount = studentList.size();//班级最大人数
|
|
|
- if(dto.getRandomNumber() > maxCount){
|
|
|
- needStudentList.addAll(studentList);
|
|
|
- }else{
|
|
|
- List<Integer> randomList = new ArrayList<>();
|
|
|
- Random random = new Random();
|
|
|
- while(randomList.size() < dto.getRandomNumber()){
|
|
|
- int nextInt = random.nextInt(studentList.size());
|
|
|
- if(!randomList.contains(nextInt) && nextInt >= 0){
|
|
|
- randomList.add(nextInt);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- for (Integer i : randomList) {
|
|
|
- needStudentList.add(studentList.get(i));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- for (XjrUser xjrUser : needStudentList) {
|
|
|
+ for (XjrUser xjrUser : studentList) {
|
|
|
AssessmentPlanAnswerStudent answer = new AssessmentPlanAnswerStudent();
|
|
|
answer.setAssessmentTemplatePlanId(assessmentTemplatePlan.getId());
|
|
|
answer.setStudentUserId(xjrUser.getId());
|
|
|
@@ -335,17 +349,42 @@ public class AssessmentTemplatePlanServiceImpl extends MPJBaseServiceImpl<Assess
|
|
|
public Boolean saveAnswer(AssessmentPlanSubmitDto dto) {
|
|
|
long studentUserId = StpUtil.getLoginIdAsLong();
|
|
|
Date date = new Date();
|
|
|
+
|
|
|
+ List<Long> questionIds = new ArrayList<>();
|
|
|
+ for (AssessmentPlanAnswerSubmitDto answerSubmitDto : dto.getAnswerList()) {
|
|
|
+ questionIds.add(answerSubmitDto.getQuestionId());
|
|
|
+ }
|
|
|
+ Map<Long, String> questionTypeMaps = new HashMap<>();
|
|
|
+ planQuestionMapper.selectList(
|
|
|
+ new QueryWrapper<AssessmentPlanQuestion>().lambda()
|
|
|
+ .in(AssessmentPlanQuestion::getId, questionIds)
|
|
|
+ ).forEach(question ->{
|
|
|
+ questionTypeMaps.put(question.getId(), question.getType());
|
|
|
+ });
|
|
|
+
|
|
|
// 学生提交
|
|
|
studentMapper.submitAnswer(dto.getAssessmentTemplatePlanId(), studentUserId);
|
|
|
for (AssessmentPlanAnswerSubmitDto answerSubmitDto : dto.getAnswerList()) {
|
|
|
- AssessmentPlanAnswerResult answerStudent = new AssessmentPlanAnswerResult();
|
|
|
- answerStudent.setAssessmentTemplatePlanId(dto.getAssessmentTemplatePlanId());
|
|
|
- answerStudent.setStudentUserId(studentUserId);
|
|
|
- answerStudent.setCreateDate(date);
|
|
|
- answerStudent.setQuestionId(answerSubmitDto.getQuestionId());
|
|
|
- answerStudent.setAnswerId(answerSubmitDto.getAnswerId());
|
|
|
- resultMapper.insert(answerStudent);
|
|
|
-
|
|
|
+ if("multi_question".equals(questionTypeMaps.get(answerSubmitDto.getQuestionId()))){
|
|
|
+ String[] split = answerSubmitDto.getAnswerId().split(",");
|
|
|
+ for (String answerId : split) {
|
|
|
+ AssessmentPlanAnswerResult answerStudent = new AssessmentPlanAnswerResult();
|
|
|
+ answerStudent.setAssessmentTemplatePlanId(dto.getAssessmentTemplatePlanId());
|
|
|
+ answerStudent.setStudentUserId(studentUserId);
|
|
|
+ answerStudent.setCreateDate(date);
|
|
|
+ answerStudent.setQuestionId(answerSubmitDto.getQuestionId());
|
|
|
+ answerStudent.setAnswerId(answerId);
|
|
|
+ resultMapper.insert(answerStudent);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ AssessmentPlanAnswerResult answerStudent = new AssessmentPlanAnswerResult();
|
|
|
+ answerStudent.setAssessmentTemplatePlanId(dto.getAssessmentTemplatePlanId());
|
|
|
+ answerStudent.setStudentUserId(studentUserId);
|
|
|
+ answerStudent.setCreateDate(date);
|
|
|
+ answerStudent.setQuestionId(answerSubmitDto.getQuestionId());
|
|
|
+ answerStudent.setAnswerId(answerSubmitDto.getAnswerId());
|
|
|
+ resultMapper.insert(answerStudent);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
@@ -376,65 +415,96 @@ public class AssessmentTemplatePlanServiceImpl extends MPJBaseServiceImpl<Assess
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public AssessmentTemplatePlanQuestionVo getQuestionResult(Long id) {
|
|
|
+ public AssessmentTemplatePlanResultVo getQuestionResult(Long id) {
|
|
|
AssessmentTemplatePlan templatePlan = templatePlanMapper.selectById(id);
|
|
|
- AssessmentTemplatePlanQuestionVo vo = BeanUtil.toBean(templatePlan, AssessmentTemplatePlanQuestionVo.class);
|
|
|
+ AssessmentTemplatePlanResultVo vo = BeanUtil.toBean(templatePlan, AssessmentTemplatePlanResultVo.class);
|
|
|
vo.setStudentCount(studentMapper.getStudentCount(id));
|
|
|
List<AssessmentPlanQuestion> questionList = planQuestionMapper.selectList(
|
|
|
new QueryWrapper<AssessmentPlanQuestion>().lambda()
|
|
|
.eq(AssessmentPlanQuestion::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
.eq(AssessmentPlanQuestion::getAssessmentTemplatePlanId, id)
|
|
|
);
|
|
|
- List<AssessmentPlanAnswerDetailVo> questionResult = resultMapper.getQuestionResult(id);
|
|
|
- Map<String, Integer> answerCountMap = new HashMap<>();
|
|
|
- for (AssessmentPlanAnswerDetailVo countVo : questionResult) {
|
|
|
- answerCountMap.put(countVo.getQuestionId().toString() + countVo.getAnswerId(), countVo.getChooseCount());
|
|
|
- }
|
|
|
+
|
|
|
//循环大题
|
|
|
- List<AssessmentQuestionVo> oneList = new ArrayList<>();
|
|
|
+ List<OneQuestionVo> oneList = new ArrayList<>();
|
|
|
for (AssessmentPlanQuestion assessmentQuestion : questionList) {
|
|
|
if(assessmentQuestion.getCategory() == 1){
|
|
|
- oneList.add(BeanUtil.toBean(assessmentQuestion, AssessmentQuestionVo.class));
|
|
|
+ oneList.add(BeanUtil.toBean(assessmentQuestion, OneQuestionVo.class));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
//循环小题
|
|
|
- for (AssessmentQuestionVo oneQuestion : oneList) {
|
|
|
- List<AssessmentQuestionVo> twoList = new ArrayList<>();
|
|
|
+ for (OneQuestionVo oneQuestion : oneList) {
|
|
|
+ List<TwoQuestionVo> twoList = new ArrayList<>();
|
|
|
for (AssessmentPlanQuestion assessmentQuestion : questionList) {
|
|
|
if(assessmentQuestion.getCategory() == 2 && assessmentQuestion.getParentId().equals(oneQuestion.getId())){
|
|
|
- AssessmentQuestionVo questionVo = BeanUtil.toBean(assessmentQuestion, AssessmentQuestionVo.class);
|
|
|
+ TwoQuestionVo questionVo = BeanUtil.toBean(assessmentQuestion, TwoQuestionVo.class);
|
|
|
twoList.add(questionVo);
|
|
|
}
|
|
|
}
|
|
|
oneQuestion.setChildren(twoList);
|
|
|
}
|
|
|
+ List<AssessmentPlanAnswerDetailVo> questionResult = resultMapper.getQuestionResult(id);
|
|
|
+ Map<String, Integer> answerCountMap = new HashMap<>();
|
|
|
+ for (AssessmentPlanAnswerDetailVo countVo : questionResult) {
|
|
|
+ answerCountMap.put(countVo.getQuestionId().toString() + countVo.getAnswerId(), countVo.getChooseCount());
|
|
|
+ }
|
|
|
+
|
|
|
+ //量表
|
|
|
+ List<AssessmentPlanAnswerDetailVo> scaleQuestionResult = resultMapper.getScaleQuestionResult(id);
|
|
|
|
|
|
//循环选项
|
|
|
- for (AssessmentQuestionVo oneQuestion : oneList) {
|
|
|
- for (AssessmentQuestionVo twoQuestion : oneQuestion.getChildren()) {
|
|
|
- List<AssessmentQuestionVo> optionList = new ArrayList<>();
|
|
|
+ for (OneQuestionVo oneQuestion : oneList) {
|
|
|
+ for (TwoQuestionVo twoQuestion : oneQuestion.getChildren()) {
|
|
|
+ List<AssessmentQuestionOptionResultVo> optionList = new ArrayList<>();
|
|
|
for (AssessmentPlanQuestion assessmentQuestion : questionList) {
|
|
|
if(assessmentQuestion.getCategory() == 3 && assessmentQuestion.getParentId().equals(twoQuestion.getId())){
|
|
|
- AssessmentQuestionVo questionVo = BeanUtil.toBean(assessmentQuestion, AssessmentQuestionVo.class);
|
|
|
- questionVo.setChooseCount(answerCountMap.get(assessmentQuestion.getParentId().toString() + assessmentQuestion.getId().toString()));
|
|
|
+ AssessmentQuestionOptionResultVo questionVo = BeanUtil.toBean(assessmentQuestion, AssessmentQuestionOptionResultVo.class);
|
|
|
+ questionVo.setCount(answerCountMap.get(assessmentQuestion.getParentId().toString() + assessmentQuestion.getId().toString()));
|
|
|
+ BigDecimal bigDecimal = BigDecimal.valueOf(questionVo.getCount())
|
|
|
+ .divide(BigDecimal.valueOf(vo.getStudentCount()))
|
|
|
+ .multiply(BigDecimal.valueOf(100))
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ questionVo.setPercentage(bigDecimal.floatValue());
|
|
|
optionList.add(questionVo);
|
|
|
}
|
|
|
if(assessmentQuestion.getCategory() == 2 && "judge_question".equals(assessmentQuestion.getType())){
|
|
|
- optionList.add(new AssessmentQuestionVo(){{
|
|
|
- setId(1L);
|
|
|
- setChooseCount(answerCountMap.get(assessmentQuestion.getId().toString() + "1"));
|
|
|
+ optionList.add(new AssessmentQuestionOptionResultVo(){{
|
|
|
+ setName("是");
|
|
|
+ BigDecimal bigDecimal = BigDecimal.valueOf(answerCountMap.get(assessmentQuestion.getId().toString() + "1"))
|
|
|
+ .divide(BigDecimal.valueOf(vo.getStudentCount()))
|
|
|
+ .multiply(BigDecimal.valueOf(100))
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ setPercentage(bigDecimal.floatValue());
|
|
|
+ setCount(answerCountMap.get(assessmentQuestion.getId().toString() + "1"));
|
|
|
}});
|
|
|
- optionList.add(new AssessmentQuestionVo(){{
|
|
|
- setId(2L);
|
|
|
- setChooseCount(answerCountMap.get(assessmentQuestion.getId().toString() + "2"));
|
|
|
+ optionList.add(new AssessmentQuestionOptionResultVo(){{
|
|
|
+ setName("否");
|
|
|
+ BigDecimal bigDecimal = BigDecimal.valueOf(answerCountMap.get(assessmentQuestion.getId().toString() + "2"))
|
|
|
+ .divide(BigDecimal.valueOf(vo.getStudentCount()))
|
|
|
+ .multiply(BigDecimal.valueOf(100))
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ setPercentage(bigDecimal.floatValue());
|
|
|
+ setCount(answerCountMap.get(assessmentQuestion.getId().toString() + "2"));
|
|
|
}});
|
|
|
}
|
|
|
}
|
|
|
- twoQuestion.setOptions(optionList);
|
|
|
+ if("scale_question".equals(twoQuestion.getType())) {
|
|
|
+ for (AssessmentPlanAnswerDetailVo detailVo : scaleQuestionResult) {
|
|
|
+ if(detailVo.getQuestionId().equals(twoQuestion.getId())){
|
|
|
+ optionList.add(new AssessmentQuestionOptionResultVo(){{
|
|
|
+ setName(detailVo.getAnswerId());
|
|
|
+ BigDecimal bigDecimal = BigDecimal.valueOf(detailVo.getChooseCount())
|
|
|
+ .divide(BigDecimal.valueOf(vo.getStudentCount())).multiply(BigDecimal.valueOf(100))
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ setPercentage(bigDecimal.floatValue());
|
|
|
+ setCount(detailVo.getChooseCount());
|
|
|
+ }});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ twoQuestion.setResultList(optionList);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
vo.setChildren(oneList);
|
|
|
return vo;
|
|
|
}
|