Commit 705d15ea authored by Phạm Duy Phi's avatar Phạm Duy Phi
parents cae4f155 e8919827
...@@ -27,4 +27,6 @@ public interface ScenarioAnswerRepository extends JpaRepository<ScenarioAnswer, ...@@ -27,4 +27,6 @@ public interface ScenarioAnswerRepository extends JpaRepository<ScenarioAnswer,
@Query(value = "SELECT COUNT(1) FROM ScenarioAnswer WHERE 1 = 1 AND code = :code AND scenarioQuestionId = :scenarioQuestionId AND scenarioAnswerId <> :scenarioAnswerId") @Query(value = "SELECT COUNT(1) FROM ScenarioAnswer WHERE 1 = 1 AND code = :code AND scenarioQuestionId = :scenarioQuestionId AND scenarioAnswerId <> :scenarioAnswerId")
Integer countDuplicateScenarioCode(@Param("code") String code, @Param("scenarioQuestionId") Long scenarioQuestionId, @Param("scenarioAnswerId") Long scenarioAnswerId); Integer countDuplicateScenarioCode(@Param("code") String code, @Param("scenarioQuestionId") Long scenarioQuestionId, @Param("scenarioAnswerId") Long scenarioAnswerId);
ScenarioAnswer findScenarioAnswerByScenarioQuestionIdAndCode(Long questionId, String code);
} }
...@@ -23,4 +23,6 @@ public interface ScenarioQuestionRepository extends JpaRepository<ScenarioQuesti ...@@ -23,4 +23,6 @@ public interface ScenarioQuestionRepository extends JpaRepository<ScenarioQuesti
Integer countDuplicateQuestionCode(@Param("code") String code, @Param("scenarioId") Long scenarioId, @Param("campaignId") Long campaignId, @Param("companySiteId") Long companySiteId); Integer countDuplicateQuestionCode(@Param("code") String code, @Param("scenarioId") Long scenarioId, @Param("campaignId") Long campaignId, @Param("companySiteId") Long companySiteId);
ScenarioQuestion findScenarioQuestionByScenarioQuestionId(Long scenarioQuestionId); ScenarioQuestion findScenarioQuestionByScenarioQuestionId(Long scenarioQuestionId);
ScenarioQuestion findScenarioQuestionByCodeAndCompanySiteId(String code, Long companySiteId);
} }
...@@ -410,9 +410,26 @@ public class ScenarioServiceImpl implements ScenarioService { ...@@ -410,9 +410,26 @@ public class ScenarioServiceImpl implements ScenarioService {
//insert data //insert data
if (isValid) { if (isValid) {
List<ScenarioQuestionDTO> lstQuestion = buildQuestionsLst(rawDataList, scenarioId, campaignId, companySiteId); List<ScenarioQuestionDTO> lstQuestion = buildQuestionsLst(rawDataList, scenarioId, campaignId, companySiteId);
List<ScenarioAnswerDTO> lstAnswerTmp = new ArrayList<>();
lstQuestion.forEach(question -> { lstQuestion.forEach(question -> {
lstAnswerTmp.addAll(question.getLstAnswers());
questionService.add(question); questionService.add(question);
}); });
//for import mapping question from xls: update mapping question id for answer
// lstAnswerTmp.forEach(item -> {
// if (item.getMappingQuestionCode() != null && item.getMappingQuestionId() == null) {
// ScenarioQuestion question = questionRepository.findScenarioQuestionByCodeAndCompanySiteId(item.getMappingQuestionCode(), item.getCompanySiteId());
// if (question != null) {
// ScenarioAnswer answerForUpdate = answerRepository.findScenarioAnswerByScenarioQuestionIdAndCode(question.getScenarioQuestionId(), item.code);
// if(answerForUpdate != null) {
// answerForUpdate.setMappingQuestionId(question.getScenarioQuestionId());
// answerRepository.save(answerForUpdate);
// }
// }
// }
// });
workbook.write(os); workbook.write(os);
os.flush(); os.flush();
os.close(); os.close();
...@@ -445,8 +462,8 @@ public class ScenarioServiceImpl implements ScenarioService { ...@@ -445,8 +462,8 @@ public class ScenarioServiceImpl implements ScenarioService {
findAny().orElse(null); findAny().orElse(null);
if (duplicateCode == null) return false; if (duplicateCode == null) return false;
// String notMappedCode = lstQuestionCode.stream().filter(p -> (!p.equals(mappingQuestion))).findAny().orElse(null); String notMappedCode = lstQuestionCode.stream().filter(p -> (!p.equals(mappingQuestion))).findAny().orElse(null);
// if(notMappedCode != null) return false; if (notMappedCode != null) return false;
return true; return true;
} }
...@@ -517,6 +534,17 @@ public class ScenarioServiceImpl implements ScenarioService { ...@@ -517,6 +534,17 @@ public class ScenarioServiceImpl implements ScenarioService {
}); });
q.setLstAnswers(answers); q.setLstAnswers(answers);
}); });
lstQuestions.forEach(q2 -> {
List<ScenarioAnswerDTO> lstAnswers = q2.getLstAnswers();
lstAnswers.forEach(a2 -> {
ScenarioQuestionDTO mappingQuestion = lstQuestions.stream().filter(mq -> mq.getImportCode().equals(a2.getMappingQuestionCode())).findFirst().orElse(null);
if (mappingQuestion != null) {
a2.setMappingQuestionCode(mappingQuestion.getCode());
}
});
});
questionOrderIndex = null; questionOrderIndex = null;
return lstQuestions; return lstQuestions;
} }
......
...@@ -6,6 +6,7 @@ import lombok.Setter; ...@@ -6,6 +6,7 @@ import lombok.Setter;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author anhvd_itsol * @author anhvd_itsol
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment