|
|
package com.ibeetl.jlw.service;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.jlw.util.ToolUtils;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ibeetl.admin.core.service.CoreBaseService;
|
|
|
import com.ibeetl.admin.core.util.PlatformException;
|
|
|
import com.ibeetl.admin.core.web.JsonResult;
|
|
|
import com.ibeetl.admin.core.web.JsonReturnCode;
|
|
|
import com.ibeetl.jlw.dao.ResourcesQuestionSnapshotDao;
|
|
|
import com.ibeetl.jlw.dao.StudentDao;
|
|
|
import com.ibeetl.jlw.dao.TeacherOpenCourseMergeResourcesQuestionDao;
|
|
|
import com.ibeetl.jlw.entity.*;
|
|
|
import com.ibeetl.jlw.entity.dto.TeacherOpenCourseQuestionSettingDTO;
|
|
|
import com.ibeetl.jlw.web.query.ResourcesQuestionSnapshotQuery;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.assertj.core.util.Lists;
|
|
|
import org.beetl.sql.core.SQLReady;
|
|
|
import org.beetl.sql.core.SqlId;
|
|
|
import org.beetl.sql.core.engine.PageQuery;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.validation.constraints.NotBlank;
|
|
|
import javax.validation.constraints.NotEmpty;
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
import java.util.Set;
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
import static com.ibeetl.admin.core.util.user.CacheUserUtil.getUserId;
|
|
|
|
|
|
/**
|
|
|
* 题目快照 Service
|
|
|
* 当分布式ID开启后请勿使用insert(*,true)
|
|
|
*/
|
|
|
|
|
|
@Service
|
|
|
@Transactional
|
|
|
@Validated
|
|
|
public class ResourcesQuestionSnapshotService extends CoreBaseService<ResourcesQuestionSnapshot>{
|
|
|
|
|
|
@Autowired private ResourcesQuestionSnapshotDao resourcesQuestionSnapshotDao;
|
|
|
@Autowired private StudentDao studentDao;
|
|
|
@Autowired private TeacherOpenCourseMergeResourcesQuestionDao teacherOpenCourseMergeResourcesQuestionDao;
|
|
|
|
|
|
public PageQuery<ResourcesQuestionSnapshot>queryByCondition(PageQuery query){
|
|
|
PageQuery ret = resourcesQuestionSnapshotDao.queryByCondition(query);
|
|
|
queryListAfter(ret.getList());
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
public PageQuery<ResourcesQuestionSnapshot>queryByConditionQuery(PageQuery query){
|
|
|
PageQuery ret = resourcesQuestionSnapshotDao.queryByConditionQuery(query);
|
|
|
queryListAfter(ret.getList());
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
public void deleteByList(List list){
|
|
|
String ids = "";
|
|
|
ToolUtils.deleteNullList(list);
|
|
|
for(int i=0;null != list && i<list.size();i++){
|
|
|
ids += list.get(i).toString()+(i==list.size()-1?"":",");
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(ids)){
|
|
|
resourcesQuestionSnapshotDao.deleteResourcesQuestionSnapshotByIds(ids);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void deleteResourcesQuestionSnapshot(String ids){
|
|
|
try {
|
|
|
resourcesQuestionSnapshotDao.deleteResourcesQuestionSnapshotByIds(ids);
|
|
|
} catch (Exception e) {
|
|
|
throw new PlatformException("批量删除题目快照失败", e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public String addAll(ResourcesQuestionSnapshotQuery resourcesQuestionSnapshotQuery){
|
|
|
String msg = "";
|
|
|
List<ResourcesQuestionSnapshot> resourcesQuestionSnapshotList = new ArrayList<>();
|
|
|
try {
|
|
|
resourcesQuestionSnapshotList = JSON.parseArray(resourcesQuestionSnapshotQuery.getResourcesQuestionSnapshotJsonStr(), ResourcesQuestionSnapshot.class);
|
|
|
} catch (Exception e) {
|
|
|
try {
|
|
|
resourcesQuestionSnapshotList.add(JSONObject.parseObject(resourcesQuestionSnapshotQuery.getResourcesQuestionSnapshotJsonStr(), ResourcesQuestionSnapshot.class));
|
|
|
} catch (Exception e1) {}
|
|
|
}
|
|
|
ToolUtils.deleteNullList(resourcesQuestionSnapshotList);
|
|
|
if(null != resourcesQuestionSnapshotList && resourcesQuestionSnapshotList.size()>0){
|
|
|
for(int i=0;i<resourcesQuestionSnapshotList.size();i++){
|
|
|
ResourcesQuestionSnapshot resourcesQuestionSnapshot = resourcesQuestionSnapshotList.get(i);
|
|
|
resourcesQuestionSnapshot.setUserId(resourcesQuestionSnapshotQuery.getUserId());
|
|
|
resourcesQuestionSnapshot.setOrgId(resourcesQuestionSnapshotQuery.getOrgId());
|
|
|
}
|
|
|
insertBatch(resourcesQuestionSnapshotList);
|
|
|
}
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
public JsonResult add(ResourcesQuestionSnapshotQuery resourcesQuestionSnapshotQuery){
|
|
|
String msg = "";
|
|
|
ResourcesQuestionSnapshot resourcesQuestionSnapshot = resourcesQuestionSnapshotQuery.pojo();
|
|
|
resourcesQuestionSnapshotDao.insert(resourcesQuestionSnapshot);
|
|
|
resourcesQuestionSnapshotQuery.setResourcesQuestionSnapshotId(resourcesQuestionSnapshot.getResourcesQuestionSnapshotId());
|
|
|
JsonResult jsonResult = new JsonResult();
|
|
|
jsonResult.setData(resourcesQuestionSnapshot.getResourcesQuestionSnapshotId());//自增的ID丢进去
|
|
|
jsonResult.setCode(JsonReturnCode.SUCCESS.getCode());
|
|
|
jsonResult.setMsg(msg);
|
|
|
return jsonResult;
|
|
|
}
|
|
|
|
|
|
public String edit(ResourcesQuestionSnapshotQuery resourcesQuestionSnapshotQuery){
|
|
|
String msg = "";
|
|
|
ResourcesQuestionSnapshot resourcesQuestionSnapshot = resourcesQuestionSnapshotQuery.pojo();
|
|
|
resourcesQuestionSnapshotDao.updateTemplateById(resourcesQuestionSnapshot);
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
public String updateGivenByIds(ResourcesQuestionSnapshotQuery resourcesQuestionSnapshotQuery){
|
|
|
String msg = "";
|
|
|
if(StringUtils.isNotBlank(resourcesQuestionSnapshotQuery.get_given())){
|
|
|
boolean flag = resourcesQuestionSnapshotDao.updateGivenByIds(resourcesQuestionSnapshotQuery) > 0;
|
|
|
if(!flag){
|
|
|
msg = "更新指定参数失败";
|
|
|
}
|
|
|
}else{
|
|
|
msg = "指定参数为空";
|
|
|
}
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
public List<ResourcesQuestionSnapshot> getValues (Object paras){
|
|
|
return sqlManager.select(SqlId.of("jlw.resourcesQuestionSnapshot.getResourcesQuestionSnapshotValues"), ResourcesQuestionSnapshot.class, paras);
|
|
|
}
|
|
|
|
|
|
public List<ResourcesQuestionSnapshot> getValuesByQuery (ResourcesQuestionSnapshotQuery resourcesQuestionSnapshotQuery){
|
|
|
return resourcesQuestionSnapshotDao.getValuesByQuery(resourcesQuestionSnapshotQuery);
|
|
|
}
|
|
|
|
|
|
public ResourcesQuestionSnapshot getInfo (Long resourcesQuestionSnapshotId){
|
|
|
ResourcesQuestionSnapshotQuery resourcesQuestionSnapshotQuery = new ResourcesQuestionSnapshotQuery();
|
|
|
resourcesQuestionSnapshotQuery.setResourcesQuestionSnapshotId(resourcesQuestionSnapshotId);
|
|
|
List<ResourcesQuestionSnapshot> list = resourcesQuestionSnapshotDao.getValuesByQuery(resourcesQuestionSnapshotQuery);
|
|
|
if(null != list && list.size()>0){
|
|
|
return list.get(0);
|
|
|
}else{
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public ResourcesQuestionSnapshot getInfo (ResourcesQuestionSnapshotQuery resourcesQuestionSnapshotQuery){
|
|
|
List<ResourcesQuestionSnapshot> list = resourcesQuestionSnapshotDao.getValuesByQuery(resourcesQuestionSnapshotQuery);
|
|
|
if(null != list && list.size()>0){
|
|
|
return list.get(0);
|
|
|
}else{
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 传入题目ID 批量导入到快照表中
|
|
|
*
|
|
|
* @param teacherOpenCourseQuestionSettingId 开课题目配置ID
|
|
|
* @param questionSettingOptions 根据题型动态分配题目
|
|
|
*/
|
|
|
public void insertBatchByQuestionIds(@NotNull(message = "开课题目配置ID不能为空!") final Long teacherOpenCourseQuestionSettingId,
|
|
|
List<TeacherOpenCourseQuestionSettingDTO> questionSettingOptions) {
|
|
|
|
|
|
// 在插入之前,先清空列表。这种情况下,支持题目配置还在,重置题目列表的操作。
|
|
|
ResourcesQuestionSnapshot deleteCondition = new ResourcesQuestionSnapshot();
|
|
|
deleteCondition.setTeacherOpenCourseQuestionSettingId(teacherOpenCourseQuestionSettingId);
|
|
|
deleteCondition.setQuestionStatus(1);
|
|
|
deleteByCondition(deleteCondition);
|
|
|
|
|
|
// 题目设置,来动态获取题目
|
|
|
if(ObjectUtil.isNotEmpty(questionSettingOptions)) {
|
|
|
List<ResourcesQuestionSnapshot> insertList = getResourcesQuestionSnapshotListByQuestionSettingOptions(
|
|
|
teacherOpenCourseQuestionSettingId, questionSettingOptions);
|
|
|
resourcesQuestionSnapshotDao.insertBatch(insertList);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 根据题目ID集合
|
|
|
* 获取题目快照列表。并配置题目配置ID
|
|
|
*
|
|
|
* @param teacherOpenCourseQuestionSettingId 题目配置ID
|
|
|
* @param questionIdPlural 题目ID复数
|
|
|
* @param otherConsumer 其他消费操作
|
|
|
* @return
|
|
|
*/
|
|
|
public List<ResourcesQuestionSnapshot> getResourcesQuestionSnapshotListByQuestionIds(
|
|
|
@NotNull(message = "开课题目配置ID不能为空!") final Long teacherOpenCourseQuestionSettingId,
|
|
|
@NotBlank(message = "题目ID列表不能为空!") String questionIdPlural, Consumer<ResourcesQuestionSnapshot> otherConsumer) {
|
|
|
// 批量插入快照表
|
|
|
List<TeacherOpenCourseMergeResourcesQuestion> questionList = teacherOpenCourseMergeResourcesQuestionDao.getByIds(questionIdPlural);
|
|
|
|
|
|
Consumer<ResourcesQuestionSnapshot> resourcesQuestionSnapshotConsumer = (e) -> {};
|
|
|
List<ResourcesQuestionSnapshot> resourcesQuestionSnapshotList = getResourcesQuestionSnapshotList(questionList, teacherOpenCourseQuestionSettingId, resourcesQuestionSnapshotConsumer);
|
|
|
resourcesQuestionSnapshotList
|
|
|
.forEach(resourcesQuestionSnapshotConsumer.andThen(otherConsumer));
|
|
|
return resourcesQuestionSnapshotList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据题目ID集合
|
|
|
* 获取题目快照列表。并配置题目配置ID
|
|
|
*
|
|
|
* @param questionList 题目集合
|
|
|
* @param teacherOpenCourseQuestionSettingId 题目ID复数
|
|
|
* @param otherConsumer 其他消费操作
|
|
|
* @return
|
|
|
*/
|
|
|
public List<ResourcesQuestionSnapshot> getResourcesQuestionSnapshotList(
|
|
|
@NotEmpty(message = "开课题库列表不能为空!") final List<TeacherOpenCourseMergeResourcesQuestion> questionList,
|
|
|
@NotBlank(message = "题目配置ID不能为空!") Long teacherOpenCourseQuestionSettingId, Consumer<ResourcesQuestionSnapshot> otherConsumer) {
|
|
|
// 批量插入快照表
|
|
|
List<ResourcesQuestionSnapshot> snapshotList = BeanUtil.copyToList(questionList, ResourcesQuestionSnapshot.class);
|
|
|
Consumer<ResourcesQuestionSnapshot> resourcesQuestionSnapshotConsumer = snapshot -> {
|
|
|
snapshot.setTeacherOpenCourseQuestionSettingId(teacherOpenCourseQuestionSettingId);
|
|
|
};
|
|
|
|
|
|
Optional.ofNullable(snapshotList).orElse(Lists.emptyList())
|
|
|
.forEach(resourcesQuestionSnapshotConsumer.andThen(otherConsumer));
|
|
|
|
|
|
return snapshotList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据题目ID集合
|
|
|
* 获取题目快照列表。并配置题目配置ID
|
|
|
*
|
|
|
* @param teacherOpenCourseQuestionSettingId 题目配置ID
|
|
|
* @param questionIdPlural 题目ID复数
|
|
|
* @param questionScore 统一给这些题目ID设置分数
|
|
|
* @return
|
|
|
*/
|
|
|
public List<ResourcesQuestionSnapshot> getResourcesQuestionSnapshotListByQuestionIds(
|
|
|
@NotNull(message = "开课题目配置ID不能为空!") final Long teacherOpenCourseQuestionSettingId,
|
|
|
@NotBlank(message = "题目ID列表不能为空!") String questionIdPlural,
|
|
|
@NotNull(message = "题目分数不能为空!") final BigDecimal questionScore) {
|
|
|
|
|
|
// 设置题目分数。这个操作也可以在SQL中来做
|
|
|
Consumer<ResourcesQuestionSnapshot> resourcesQuestionSnapshotConsumer = item -> {
|
|
|
item.setQuestionScore(questionScore);
|
|
|
};
|
|
|
return getResourcesQuestionSnapshotListByQuestionIds(
|
|
|
teacherOpenCourseQuestionSettingId, questionIdPlural, resourcesQuestionSnapshotConsumer);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据题目类型配置
|
|
|
* 获取题目快照列表。并配置题目配置ID
|
|
|
*
|
|
|
* @param teacherOpenCourseQuestionSettingId
|
|
|
* @param questionSettingOptions
|
|
|
* @return
|
|
|
*/
|
|
|
public List<ResourcesQuestionSnapshot> getResourcesQuestionSnapshotListByQuestionSettingOptions(
|
|
|
@NotNull(message = "开课题目配置ID不能为空!") final Long teacherOpenCourseQuestionSettingId,
|
|
|
@NotBlank(message = "题目设置不能为空!") List<TeacherOpenCourseQuestionSettingDTO> questionSettingOptions) {
|
|
|
|
|
|
List<ResourcesQuestionSnapshot> result = new ArrayList<>();
|
|
|
|
|
|
for (TeacherOpenCourseQuestionSettingDTO questionSettingOption : questionSettingOptions) {
|
|
|
// 根据配置随机出题。这里直接设置题目的分值。
|
|
|
List<TeacherOpenCourseMergeResourcesQuestion> randomMergeResourcesQuestionList =
|
|
|
teacherOpenCourseMergeResourcesQuestionDao.getRandomMergeResourcesQuestionList(questionSettingOption);
|
|
|
|
|
|
// 放入最终的集合中
|
|
|
result.addAll(getResourcesQuestionSnapshotList(randomMergeResourcesQuestionList, teacherOpenCourseQuestionSettingId, e -> {}));
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 学生端-开课相关
|
|
|
* 查询学生的得分信息
|
|
|
*
|
|
|
* @param teacherOpenCourseQuestionSettingId 开课题目配置ID
|
|
|
* @return
|
|
|
*/
|
|
|
public TeacherOpenCourseQuestionLogScoreInfo getScoreInfo(
|
|
|
@NotNull(message = "开课题目配置ID不能为空!") final Long teacherOpenCourseQuestionSettingId) {
|
|
|
|
|
|
// 查询学生身份
|
|
|
Student student = studentDao.getByUserId(getUserId());
|
|
|
|
|
|
// 给实体类传参数,剩下来的交给Fetch 来处理
|
|
|
// 查询符合条件的实体
|
|
|
TeacherOpenCourseQuestionLogScoreInfo scoreInfo = sqlManager.executeQueryOne(
|
|
|
new SQLReady("SELECT " +
|
|
|
"? as teacher_open_course_question_setting_id, " +
|
|
|
"? as student_id ",
|
|
|
teacherOpenCourseQuestionSettingId, student.getStudentId()
|
|
|
),
|
|
|
TeacherOpenCourseQuestionLogScoreInfo.class
|
|
|
);
|
|
|
return scoreInfo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 简单获取题目的信息
|
|
|
* @param questionSettingId 开课题目配置ID
|
|
|
* @return
|
|
|
*/
|
|
|
public TeacherOpenCourseQuestionTestSimpleInfo getQuestionTestSimpleInfo(
|
|
|
@NotNull(message = "开课题目配置ID不能为空!") final Long questionSettingId) {
|
|
|
return resourcesQuestionSnapshotDao.getQuestionTestSimpleInfo(questionSettingId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 题目测试后的结果
|
|
|
*
|
|
|
* @param testDetail 封装实体
|
|
|
* @return
|
|
|
*/
|
|
|
public Object questionTestResults(
|
|
|
@NotNull(message = "参数不能为空!") final TeacherOpenCourseQuestionTestDetail testDetail) {
|
|
|
return resourcesQuestionSnapshotDao.questionTestResults(testDetail);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 练习详情
|
|
|
*
|
|
|
* @param questionSettingId 开课题目配置ID
|
|
|
* @return
|
|
|
*/
|
|
|
public Object questionTestDetail(@NotNull(message = "开课题目配置ID不能为空!") final Long questionSettingId) {
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 题目管理
|
|
|
*
|
|
|
* @param questionSettingId 开课题目配置ID
|
|
|
* @return
|
|
|
*/
|
|
|
public Object questionManagement(@NotNull(message = "开课题目配置ID不能为空!") final Long questionSettingId) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param teacherOpenCourseIds
|
|
|
* @param chapterIds
|
|
|
* @param teacherOpenCourseKnowledgePointsIds
|
|
|
* @return
|
|
|
*/
|
|
|
public Object bindKnowledgePoints(@NotBlank(message = "开课ID不能为空!") String teacherOpenCourseIds,
|
|
|
@NotBlank(message = "章节ID不能为空!") String chapterIds,
|
|
|
@NotEmpty(message = "知识点ID不能为空!") Set<Long> teacherOpenCourseKnowledgePointsIds) {
|
|
|
return null;
|
|
|
}
|
|
|
}
|