Commit f62d76ec authored by 耿迪迪's avatar 耿迪迪

从题库批量新增 gengdidi

parent e867b9be
package com.zehong.web.controller.system; package com.zehong.web.controller.system;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
......
...@@ -2,6 +2,7 @@ package com.zehong.web.controller.train; ...@@ -2,6 +2,7 @@ package com.zehong.web.controller.train;
import java.util.List; import java.util.List;
import com.zehong.system.domain.vo.BatchTopicVo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
...@@ -122,4 +123,14 @@ public class TTrainCourseTopicController extends BaseController ...@@ -122,4 +123,14 @@ public class TTrainCourseTopicController extends BaseController
{ {
return toAjax(tTrainCourseTopicService.deleteTTrainCourseTopicById(topicId)); return toAjax(tTrainCourseTopicService.deleteTTrainCourseTopicById(topicId));
} }
/**
* 题库批量导入试题
* @param batchTopicVo 试题实体
* @return AjaxResult
*/
@PostMapping("/bachAddTopic")
public AjaxResult bachAddTopic(@RequestBody BatchTopicVo batchTopicVo){
return toAjax(tTrainCourseTopicService.bachAddTopic(batchTopicVo));
}
} }
package com.zehong.system.domain.vo;
import java.util.List;
/**
* @author geng
* 批量导入试题
*/
public class BatchTopicVo {
/**
* 所属考试id
*/
private Long courseId;
private List<TopicInfos> topicInfos;
public Long getCourseId() {
return courseId;
}
public void setCourseId(Long courseId) {
this.courseId = courseId;
}
public List<TopicInfos> getTopicInfos() {
return topicInfos;
}
public void setTopicInfos(List<TopicInfos> topicInfos) {
this.topicInfos = topicInfos;
}
/**
* @author geng
* 题库批量导入试题实体
*/
public static class TopicInfos{
/**
* 题库id
*/
private Long bankId;
/**
* 随机抽取题数量
*/
private int quan;
public Long getBankId() {
return bankId;
}
public void setBankId(Long bankId) {
this.bankId = bankId;
}
public int getQuan() {
return quan;
}
public void setQuan(int quan) {
this.quan = quan;
}
}
}
...@@ -60,4 +60,11 @@ public interface TTrainCourseTopicMapper ...@@ -60,4 +60,11 @@ public interface TTrainCourseTopicMapper
* @return 结果 * @return 结果
*/ */
public int deleteTTrainCourseTopicByIds(Long[] topicIds); public int deleteTTrainCourseTopicByIds(Long[] topicIds);
/**
* 批量新增
* @param topics 试题试题
* @return
*/
int batchInsertTTrainCourseTopic(List<TTrainCourseTopic> topics);
} }
package com.zehong.system.service; package com.zehong.system.service;
import java.util.List;
import com.zehong.system.domain.TTrainCourseTopic; import com.zehong.system.domain.TTrainCourseTopic;
import com.zehong.system.domain.vo.BatchTopicVo;
import java.util.List;
/** /**
* 培训课程题库Service接口 * 培训课程题库Service接口
...@@ -59,4 +61,11 @@ public interface ITTrainCourseTopicService ...@@ -59,4 +61,11 @@ public interface ITTrainCourseTopicService
* @return 结果 * @return 结果
*/ */
public int deleteTTrainCourseTopicById(Long topicId); public int deleteTTrainCourseTopicById(Long topicId);
/**
* 题库批量导入试题
* @param batchTopicVo 试题实体
* @return int
*/
int bachAddTopic(BatchTopicVo batchTopicVo);
} }
package com.zehong.system.service.impl; package com.zehong.system.service.impl;
import java.util.List; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.zehong.common.utils.DateUtils; import com.zehong.common.utils.DateUtils;
import com.zehong.common.utils.StringUtils;
import com.zehong.system.domain.TBankSubject;
import com.zehong.system.domain.TTrainCourse; import com.zehong.system.domain.TTrainCourse;
import com.zehong.system.domain.TTrainCourseTopic;
import com.zehong.system.domain.vo.BatchTopicVo;
import com.zehong.system.mapper.TBankSubjectMapper;
import com.zehong.system.mapper.TTrainCourseMapper; import com.zehong.system.mapper.TTrainCourseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zehong.system.mapper.TTrainCourseTopicMapper; import com.zehong.system.mapper.TTrainCourseTopicMapper;
import com.zehong.system.domain.TTrainCourseTopic;
import com.zehong.system.service.ITTrainCourseTopicService; import com.zehong.system.service.ITTrainCourseTopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
/** /**
* 培训课程题库Service业务层处理 * 培训课程题库Service业务层处理
* *
...@@ -24,6 +35,8 @@ public class TTrainCourseTopicServiceImpl implements ITTrainCourseTopicService ...@@ -24,6 +35,8 @@ public class TTrainCourseTopicServiceImpl implements ITTrainCourseTopicService
private TTrainCourseTopicMapper tTrainCourseTopicMapper; private TTrainCourseTopicMapper tTrainCourseTopicMapper;
@Autowired @Autowired
private TTrainCourseMapper tTrainCourseMapper; private TTrainCourseMapper tTrainCourseMapper;
@Resource
private TBankSubjectMapper tBankSubjectMapper;
/** /**
* 查询培训课程题库 * 查询培训课程题库
...@@ -118,4 +131,37 @@ public class TTrainCourseTopicServiceImpl implements ITTrainCourseTopicService ...@@ -118,4 +131,37 @@ public class TTrainCourseTopicServiceImpl implements ITTrainCourseTopicService
} }
return tTrainCourseTopicMapper.deleteTTrainCourseTopicById(topicId); return tTrainCourseTopicMapper.deleteTTrainCourseTopicById(topicId);
} }
/**
* 题库批量导入试题
* @param batchTopicVo 试题实体
* @return int
*/
@Override
@Transactional(rollbackFor = Exception.class)
public int bachAddTopic(BatchTopicVo batchTopicVo){
if(CollectionUtil.isEmpty(batchTopicVo.getTopicInfos()) || StringUtils.isEmpty(String.valueOf(batchTopicVo.getCourseId()))){
return 0;
}
List<TTrainCourseTopic> topics = new ArrayList<>();
for(BatchTopicVo.TopicInfos topic : batchTopicVo.getTopicInfos()){
//获取题库试题
TBankSubject tBankSubject = new TBankSubject();
tBankSubject.setBankId(topic.getBankId());
List<TBankSubject> bankSubjects = tBankSubjectMapper.selectTBankSubjectList(tBankSubject);
//获取随机试题
Collections.shuffle(bankSubjects);
for(int i = 0;i<topic.getQuan();i++){
TTrainCourseTopic courseTopic = new TTrainCourseTopic();
courseTopic.setCourseId(batchTopicVo.getCourseId());
courseTopic.setTopicTitle(bankSubjects.get(i).getTopicTitle());
courseTopic.setTopicOption(bankSubjects.get(i).getTopicOption());
courseTopic.setAnswer(bankSubjects.get(i).getAnswer());
courseTopic.setCreateTime(new Date());
topics.add(courseTopic);
}
}
//批量新增试题
return tTrainCourseTopicMapper.batchInsertTTrainCourseTopic(topics);
}
} }
...@@ -77,4 +77,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -77,4 +77,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{topicId} #{topicId}
</foreach> </foreach>
</delete> </delete>
<insert id="batchInsertTTrainCourseTopic" parameterType="java.util.List">
insert into t_train_course_topic(course_id,topic_title,topic_option,answer,create_time) values
<foreach collection="list" item="topic" index="index" separator="," >
(#{topic.courseId},#{topic.topicTitle},#{topic.topicOption},#{topic.answer},#{topic.createTime})
</foreach>
</insert>
</mapper> </mapper>
\ No newline at end of file
...@@ -159,3 +159,15 @@ export function testPersonDetailByCourseId(query) { ...@@ -159,3 +159,15 @@ export function testPersonDetailByCourseId(query) {
}) })
} }
/**
* 从题库导入试题
* @param data
*/
export function bachAddTopic(data) {
return request({
url: '/system/course/bachAddTopic',
method: 'post',
data: data
})
}
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