| | |
| | | import com.mindskip.xzs.repository.PracticeQuestionConditionMapper; |
| | | import com.mindskip.xzs.service.PracticeQuestionConditionService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | |
| | | private final WebContext webContext; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void save(PracticeQuestionCondition entity) { |
| | | // 如果做错了,加入错题集 |
| | | if (! entity.getQuestionCondition().getRight()) { |
| | | |
| | | } |
| | | PracticeQuestionCondition old = mapper.selectByPracticeId(entity.getPracticeId()); |
| | | if (Objects.isNull(old)) { |
| | | old = new PracticeQuestionCondition(); |
| | | old.setUserId(webContext.getCurrentUser().getId()); |
| | | old.setPracticeId(entity.getPracticeId()); |
| | | old.setContent(JSON.toJSONString(entity.getQuestionConditions())); |
| | | ArrayList<Object> objects = new ArrayList<>(1); |
| | | objects.add(entity.getQuestionCondition()); |
| | | old.setContent(JSON.toJSONString(objects)); |
| | | old.setLatestTime(new Date()); |
| | | mapper.save(old); |
| | | } else { |
| | | // 更新内容 |
| | | mapper.updateContentById(JSON.toJSONString(entity.getQuestionConditions()), old.getId(), new Date()); |
| | | List<PracticeQuestionCondition.QuestionFinishCondition> list = JSON.parseArray(old.getContent(), PracticeQuestionCondition.QuestionFinishCondition.class); |
| | | if (list.stream().anyMatch(item -> item.getQuestionId().equals(entity.getQuestionCondition().getQuestionId()))) { |
| | | for (PracticeQuestionCondition.QuestionFinishCondition item : list) { |
| | | if (item.getQuestionId().equals(entity.getQuestionCondition().getQuestionId())) { |
| | | BeanUtils.copyProperties(entity.getQuestionCondition(), item); |
| | | break; |
| | | } |
| | | } |
| | | } else { |
| | | list.add(entity.getQuestionCondition()); |
| | | } |
| | | mapper.updateContentById(JSON.toJSONString(list), old.getId(), new Date()); |
| | | } |
| | | } |
| | | |