|
|
@ -25,6 +25,9 @@ import com.project.task.domain.service.TaskBaseService; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
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 org.springframework.transaction.support.TransactionSynchronization; |
|
|
|
|
|
import org.springframework.transaction.support.TransactionSynchronizationManager; |
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
@ -91,6 +94,7 @@ public class SaveClusterDomainServiceImpl implements SaveClusterDomainService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public void saveCluster(Long taskId, List<ClusterCallbackDTO.ClusterItem> clusters) { |
|
|
public void saveCluster(Long taskId, List<ClusterCallbackDTO.ClusterItem> clusters) { |
|
|
TaskEntity taskEntity = taskBaseService.getById(taskId); |
|
|
TaskEntity taskEntity = taskBaseService.getById(taskId); |
|
|
int u = 0; |
|
|
int u = 0; |
|
|
@ -128,7 +132,7 @@ public class SaveClusterDomainServiceImpl implements SaveClusterDomainService { |
|
|
// 生成目标量
|
|
|
// 生成目标量
|
|
|
int targetNum = (int) Math.ceil(1.2 * u); |
|
|
int targetNum = (int) Math.ceil(1.2 * u); |
|
|
//题目总数
|
|
|
//题目总数
|
|
|
Integer totalNum = taskEntity.getMultipleChoiceNum() + taskEntity.getSingleChoiceNum() + taskEntity.getTrueFalseNum(); |
|
|
int totalNum = taskEntity.getMultipleChoiceNum() + taskEntity.getSingleChoiceNum() + taskEntity.getTrueFalseNum(); |
|
|
//题目占比系数
|
|
|
//题目占比系数
|
|
|
Map<String,Double> questionTypeMap = new HashMap<>(); |
|
|
Map<String,Double> questionTypeMap = new HashMap<>(); |
|
|
questionTypeMap.put(QuestionTypeEnum.SINGLE_CHOICE.name(), taskEntity.getSingleChoiceNum() * 1.0/totalNum); |
|
|
questionTypeMap.put(QuestionTypeEnum.SINGLE_CHOICE.name(), taskEntity.getSingleChoiceNum() * 1.0/totalNum); |
|
|
@ -149,8 +153,13 @@ public class SaveClusterDomainServiceImpl implements SaveClusterDomainService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//生成题目
|
|
|
// 事务提交后再执行题目生成(避免异步查询时数据未提交)
|
|
|
produce(produceDTOList); |
|
|
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void afterCommit() { |
|
|
|
|
|
produce(produceDTOList); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void produce(List<ProduceDTO> produceDTOList) { |
|
|
private void produce(List<ProduceDTO> produceDTOList) { |
|
|
|