15 changed files with 208 additions and 6 deletions
@ -0,0 +1,8 @@ |
|||||
|
package com.project.interaction.domain.dto; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
@Data |
||||
|
public class QuestionCallBackDTO { |
||||
|
|
||||
|
} |
||||
@ -1,9 +1,55 @@ |
|||||
package com.project.question.domain.dto; |
package com.project.question.domain.dto; |
||||
|
|
||||
import com.project.base.domain.dto.BaseDTO; |
import com.project.base.domain.dto.BaseDTO; |
||||
|
import com.project.question.domain.entity.QuestionEntity; |
||||
|
import com.project.question.domain.enums.QuestionUseStatusEnum; |
||||
import lombok.Data; |
import lombok.Data; |
||||
|
import org.springframework.beans.BeanUtils; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
import java.util.function.Supplier; |
||||
|
|
||||
@Data |
@Data |
||||
public class QuestionDTO extends BaseDTO { |
public class QuestionDTO extends BaseDTO { |
||||
private Long id; |
private Long id; |
||||
|
|
||||
|
private Integer sourceType; |
||||
|
|
||||
|
private Boolean useStatus = QuestionUseStatusEnum.Not_Use.getValue(); |
||||
|
|
||||
|
private List<Long> kpIdList; |
||||
|
|
||||
|
private String uniqueHash; |
||||
|
|
||||
|
private Integer questionType; |
||||
|
|
||||
|
private QuestionDetailDTO questionDetailDTO; |
||||
|
|
||||
|
|
||||
|
@Data |
||||
|
public static class QuestionDetailDTO { |
||||
|
private String questionContent; // 题干
|
||||
|
private Integer type; // 题目类型
|
||||
|
private Map<String, String> options; // 选项
|
||||
|
private String rightAnswer; // 正确选项
|
||||
|
private String analysis; // AI解析
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public <T> T toEntity(Supplier<T> supplier) { |
||||
|
T result = super.toEntity(supplier); |
||||
|
|
||||
|
if (result instanceof QuestionEntity entity) { |
||||
|
if (this.questionDetailDTO != null) { |
||||
|
QuestionEntity.QuestionDetail detail = new QuestionEntity.QuestionDetail(); |
||||
|
BeanUtils.copyProperties(this.questionDetailDTO, detail); |
||||
|
entity.setQuestionDetail(detail); |
||||
|
} |
||||
|
|
||||
|
entity.setId(this.getId()); |
||||
|
} |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,7 @@ |
|||||
|
package com.project.question.domain.service; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
import com.project.question.domain.entity.QuestionEntity; |
||||
|
|
||||
|
public interface QuestionBaseService extends IService<QuestionEntity> { |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
package com.project.question.domain.service; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
import com.project.question.domain.entity.QuestionKpRelEntity; |
||||
|
|
||||
|
public interface QuestionKpRelBaseService extends IService<QuestionKpRelEntity> { |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
package com.project.question.domain.service; |
||||
|
|
||||
|
import com.project.base.domain.result.Result; |
||||
|
import com.project.question.domain.dto.QuestionDTO; |
||||
|
|
||||
|
public interface SaveQuestionDomainService { |
||||
|
Result<QuestionDTO> save(QuestionDTO dto) throws Exception; |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
package com.project.question.domain.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import com.project.question.domain.entity.QuestionEntity; |
||||
|
import com.project.question.domain.service.QuestionBaseService; |
||||
|
import com.project.question.mapper.QuestionMapper; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
@Service |
||||
|
public class QuestionBaseServiceImpl extends ServiceImpl<QuestionMapper, QuestionEntity> implements QuestionBaseService { |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
package com.project.question.domain.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import com.project.question.domain.entity.QuestionKpRelEntity; |
||||
|
import com.project.question.domain.service.QuestionKpRelBaseService; |
||||
|
import com.project.question.mapper.QuestionKpRelMapper; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
|
||||
|
@Service |
||||
|
public class QuestionKpRelBaseServiceImpl extends ServiceImpl<QuestionKpRelMapper, QuestionKpRelEntity> implements QuestionKpRelBaseService { |
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
package com.project.question.domain.service.impl; |
||||
|
|
||||
|
import cn.hutool.core.collection.CollUtil; |
||||
|
import com.project.base.domain.exception.BusinessErrorException; |
||||
|
import com.project.base.domain.result.Result; |
||||
|
import com.project.question.domain.dto.QuestionDTO; |
||||
|
import com.project.question.domain.entity.QuestionEntity; |
||||
|
import com.project.question.domain.enums.QuestionSourceTypeEnum; |
||||
|
import com.project.question.domain.service.QuestionBaseService; |
||||
|
import com.project.question.domain.service.SaveQuestionDomainService; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
|
||||
|
@Service |
||||
|
public class SaveQuestionDomainServiceImpl implements SaveQuestionDomainService { |
||||
|
|
||||
|
@Autowired |
||||
|
private QuestionBaseService questionBaseService; |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public Result<QuestionDTO> save(QuestionDTO dto) throws Exception { |
||||
|
if (CollUtil.isEmpty(dto.getKpIdList())) { |
||||
|
throw new BusinessErrorException("知识点集合不能为空"); |
||||
|
} |
||||
|
dto.setKpIdList(dto.getKpIdList().stream().sorted().toList()); |
||||
|
if (dto.getKpIdList().size() > 1) { |
||||
|
dto.setSourceType(QuestionSourceTypeEnum.Multi_Concept.getValue()); |
||||
|
} else { |
||||
|
dto.setSourceType(QuestionSourceTypeEnum.Single_Concept.getValue()); |
||||
|
} |
||||
|
QuestionEntity entity = dto.toEntity(QuestionEntity::new); |
||||
|
questionBaseService.save(entity); |
||||
|
return Result.success(entity.toDTO(QuestionDTO::new)); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
package com.project.question.mapper; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.project.question.domain.entity.QuestionKpRelEntity; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
|
||||
|
@Mapper |
||||
|
public interface QuestionKpRelMapper extends BaseMapper<QuestionKpRelEntity> { |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
package com.project.question.mapper; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.project.question.domain.entity.QuestionEntity; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
|
||||
|
@Mapper |
||||
|
public interface QuestionMapper extends BaseMapper<QuestionEntity> { |
||||
|
} |
||||
Loading…
Reference in new issue