|
@@ -26,14 +26,14 @@ import javax.annotation.Resource;
|
|
|
* @date 2024-05-28
|
|
|
*/
|
|
|
@Service
|
|
|
-public class TElQuServiceImpl implements ITElQuService
|
|
|
-{
|
|
|
+public class TElQuServiceImpl implements ITElQuService {
|
|
|
@Resource
|
|
|
private TElQuMapper tElQuMapper;
|
|
|
@Resource
|
|
|
private TElQuAnswerMapper tElQuAnswerMapper;
|
|
|
@Resource
|
|
|
private TElQuRepoMapper tElQuRepoMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询试题
|
|
|
*
|
|
@@ -41,8 +41,7 @@ public class TElQuServiceImpl implements ITElQuService
|
|
|
* @return 试题
|
|
|
*/
|
|
|
@Override
|
|
|
- public TElQu selectTElQuById(Long quId)
|
|
|
- {
|
|
|
+ public TElQu selectTElQuById(Long quId) {
|
|
|
TElQu tElQu = tElQuMapper.selectTElQuById(quId);
|
|
|
|
|
|
//答案
|
|
@@ -56,7 +55,7 @@ public class TElQuServiceImpl implements ITElQuService
|
|
|
queyRepo.setQuId(tElQu.getQuId());
|
|
|
List<TElQuRepo> repoList = tElQuRepoMapper.selectTElQuRepoList(queyRepo);
|
|
|
List<String> ids = new ArrayList<>();
|
|
|
- for (TElQuRepo t: repoList
|
|
|
+ for (TElQuRepo t : repoList
|
|
|
) {
|
|
|
ids.add(String.valueOf(t.getRepoId()));
|
|
|
}
|
|
@@ -72,8 +71,7 @@ public class TElQuServiceImpl implements ITElQuService
|
|
|
* @return 试题
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<TElQu> selectTElQuList(TElQu tElQu)
|
|
|
- {
|
|
|
+ public List<TElQu> selectTElQuList(TElQu tElQu) {
|
|
|
return tElQuMapper.selectTElQuList(tElQu);
|
|
|
}
|
|
|
|
|
@@ -85,26 +83,25 @@ public class TElQuServiceImpl implements ITElQuService
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public int insertTElQu(TElQu tElQu)
|
|
|
- {
|
|
|
- checkData(tElQu,"");
|
|
|
- //更新答案
|
|
|
- tElQuMapper.insertTElQu(tElQu);
|
|
|
+ public int insertTElQu(TElQu tElQu) {
|
|
|
+ checkData(tElQu, "");
|
|
|
new Thread(() -> {
|
|
|
- for (TElQuAnswer as: tElQu.getAnswerList()
|
|
|
+ //更新答案
|
|
|
+ tElQuMapper.insertTElQu(tElQu);
|
|
|
+ for (TElQuAnswer as : tElQu.getAnswerList()
|
|
|
) {
|
|
|
as.setQuId(tElQu.getQuId());
|
|
|
tElQuAnswerMapper.insertTElQuAnswer(as);
|
|
|
}
|
|
|
//更新题库
|
|
|
- for(String repoId: tElQu.getRepoIds()){
|
|
|
+ for (String repoId : tElQu.getRepoIds()) {
|
|
|
TElQuRepo ref = new TElQuRepo();
|
|
|
ref.setQuId(tElQu.getQuId());
|
|
|
ref.setRepoId(Long.parseLong(repoId));
|
|
|
ref.setQuType(tElQu.getQuType());
|
|
|
tElQuRepoMapper.insertTElQuRepo(ref);
|
|
|
}
|
|
|
- },"insertTElQu").start();
|
|
|
+ }, "新增试题").start();
|
|
|
|
|
|
return 1;
|
|
|
}
|
|
@@ -116,9 +113,8 @@ public class TElQuServiceImpl implements ITElQuService
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int updateTElQu(TElQu tElQu)
|
|
|
- {
|
|
|
- checkData(tElQu,"");
|
|
|
+ public int updateTElQu(TElQu tElQu) {
|
|
|
+ checkData(tElQu, "");
|
|
|
tElQuMapper.updateTElQu(tElQu);
|
|
|
//更新答案
|
|
|
TElQuAnswer queyAs = new TElQuAnswer();
|
|
@@ -127,43 +123,43 @@ public class TElQuServiceImpl implements ITElQuService
|
|
|
|
|
|
List<Long> ids = new ArrayList<>();
|
|
|
if (oldList.size() > 0) {
|
|
|
- for (TElQuAnswer old: oldList
|
|
|
- ) {
|
|
|
+ for (TElQuAnswer old : oldList
|
|
|
+ ) {
|
|
|
ids.add(old.getAnswerId());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- for (TElQuAnswer as: tElQu.getAnswerList()
|
|
|
+ for (TElQuAnswer as : tElQu.getAnswerList()
|
|
|
) {
|
|
|
//补全ID避免新增
|
|
|
- if(ids.contains(as.getAnswerId())){
|
|
|
+ if (ids.contains(as.getAnswerId())) {
|
|
|
ids.remove(as.getAnswerId());
|
|
|
}
|
|
|
as.setQuId(tElQu.getQuId());
|
|
|
if (as.getAnswerId() == null) {
|
|
|
tElQuAnswerMapper.insertTElQuAnswer(as);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
tElQuAnswerMapper.updateTElQuAnswer(as);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
//删除答案
|
|
|
for (Long id : ids
|
|
|
- ) {
|
|
|
+ ) {
|
|
|
tElQuAnswerMapper.deleteTElQuAnswerById(id);
|
|
|
}
|
|
|
|
|
|
//先删除题库
|
|
|
TElQuRepo queyRepo = new TElQuRepo();
|
|
|
- queyRepo.setQuId(tElQu.getQuId());
|
|
|
+ queyRepo.setQuId(tElQu.getQuId());
|
|
|
List<TElQuRepo> repoList = tElQuRepoMapper.selectTElQuRepoList(queyRepo);
|
|
|
- for (TElQuRepo t: repoList
|
|
|
- ) {
|
|
|
+ for (TElQuRepo t : repoList
|
|
|
+ ) {
|
|
|
tElQuRepoMapper.deleteTElQuRepoById(t.getId());
|
|
|
}
|
|
|
|
|
|
//更新题库
|
|
|
- for(String repoId: tElQu.getRepoIds()){
|
|
|
+ for (String repoId : tElQu.getRepoIds()) {
|
|
|
TElQuRepo ref = new TElQuRepo();
|
|
|
ref.setQuId(tElQu.getQuId());
|
|
|
ref.setRepoId(Long.parseLong(repoId));
|
|
@@ -181,9 +177,8 @@ public class TElQuServiceImpl implements ITElQuService
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteTElQuByIds(Long[] quIds)
|
|
|
- {
|
|
|
- int i = tElQuMapper.deleteTElQuByIds(quIds);
|
|
|
+ public int deleteTElQuByIds(Long[] quIds) {
|
|
|
+ int i = tElQuMapper.deleteTElQuByIds(quIds);
|
|
|
tElQuRepoMapper.deleteQu();
|
|
|
return i;
|
|
|
}
|
|
@@ -195,10 +190,10 @@ public class TElQuServiceImpl implements ITElQuService
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteTElQuById(Long quId)
|
|
|
- {
|
|
|
+ public int deleteTElQuById(Long quId) {
|
|
|
return tElQuMapper.deleteTElQuById(quId);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 校验题目信息
|
|
|
*
|