Compare commits

..

3 Commits

Author SHA1 Message Date
yang
ce1dae3ed2 案例萃取,案例榜单刷新 2024-09-18 15:33:09 +08:00
yang
4b1947bf06 案例萃取,案例标签排序 2024-09-14 17:15:39 +08:00
yang
39ba96f141 案例萃取,案例标签排序 2024-09-14 16:26:07 +08:00
16 changed files with 306 additions and 614 deletions

View File

@@ -13,12 +13,10 @@ import com.xboe.module.exam.entity.ExamTest;
import com.xboe.school.study.entity.StudyCourse;
import com.xboe.system.user.dao.UserDao;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Collection;
@@ -68,10 +66,6 @@ public class ThirdApi {
@Value("${manageApi.editExam}")
private String editExam;
@Value("${userBasic.getUserBasicInfo}")
private String getUserBasicInfo;
//获取例外人员的id
public List<String> getUserId(){
String responseBody = Optional.ofNullable(HttpRequest.get(infarasApiUrl+"?pid=316&type=1").execute() //prod 316
@@ -274,32 +268,4 @@ public class ThirdApi {
}
return builder.toString();
}
/**
* 虽然当前已存在接口查询用户基本信息目前仅仅包括用户名、工号、用户ID
*/
public List<UserBasicInfo> getUserBasicInfoByUserId(List<String> userIds, HttpServletRequest request) {
String token = request.getHeader("Xboe-Access-Token");
if (StringUtils.isEmpty(token)) {
token = request.getHeader("token");
}
if (StringUtils.isEmpty(token)) {
token = request.getHeader("x-access-token");
}
// 将userIds列表转换为逗号分隔的字符串
String userIdsStr = userIds.stream()
.collect(Collectors.joining(","));
String url = getUserBasicInfo +"?userIds=" + userIdsStr;
String respStr = Optional.ofNullable(HttpRequest
.get(url)
.header("token", token)
.execute().body()).orElseThrow(() -> new RuntimeException("用户中心用户数据获取失败"));
UserBasicInfoResult userBasicInfoResult = JSONUtil.parseObj(respStr).toBean(UserBasicInfoResult.class);
List<UserBasicInfo> basicInfos = userBasicInfoResult.getResult();
return basicInfos;
}
}

View File

@@ -1,23 +0,0 @@
package com.xboe.api.vo;
import lombok.Data;
@Data
public class UserBasicInfo {
/**
* 用户ID
*/
private String userId;
/**
* 用户名。
*/
private String userName;
/**
* 工号。
*/
private String workNum;
}

View File

@@ -1,35 +0,0 @@
package com.xboe.api.vo;
import cn.hutool.json.JSONUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.util.Date;
import java.util.List;
@Data
@Slf4j
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UserBasicInfoResult {
private String error;
private String message;
private String permissions;
private List<UserBasicInfo> result;
private int status;
private Date timestamp;
public UserBasicInfoResult success() {
if (this.status != 200) {
log.error("获取用户基本信息失败----{}", JSONUtil.toJsonPrettyStr(this));
return null;
}
return this;
}
}

View File

@@ -132,25 +132,7 @@ public class CasesApi extends ApiBaseController {
views = casesService.queryPageCasesV2(req);
}
if (views != null) {
List<Cases> cases = views.getList();
if (CollUtil.isNotEmpty(cases)) {
for (Cases c : cases) {
StringBuffer stringBuffer = new StringBuffer();
List<CasesMajorType> caseId = casesMajorTypeDao.findList(FieldFilters.eq("caseId", c.getId()));
if (caseId != null && !caseId.isEmpty()) {
for (CasesMajorType cm : caseId) {
stringBuffer.append(cm.getMajorId());
stringBuffer.append(",");
}
}
if (stringBuffer.length() > 0) {
stringBuffer.deleteCharAt(stringBuffer.length() - 1);
c.setMajorType(stringBuffer.toString());
}
}
}
} else {
if (views == null) {
views = new PageList();
views.setList(Collections.emptyList());
views.setPageSize(req.getPageSize());

View File

@@ -422,7 +422,7 @@ public class CasesServiceImpl implements ICasesService {
//2.标签处理,添加作者标签和新的案例标签
addAuthorTagAndCaseNewTag(casesList);
//3.案例类型处理
// majorTypeHandle(casesList);
majorTypeHandle(casesList);
return casesList;
}
@@ -1203,16 +1203,10 @@ public class CasesServiceImpl implements ICasesService {
}
//获取案例当月排名
// String sql =
// "SELECT bc.id,bcmt.major_id,bc.views - COALESCE(bc.last_month_views, 0) AS increment\n" +
// "FROM boe_cases bc\n" +
// "JOIN boe_cases_major_type bcmt ON bcmt.case_id = bc.id and bc.deleted=0 and file_path is not null and file_path!='' and bc.views - COALESCE(bc.last_month_views, 0)!=0";
String sql =
"SELECT bc.id,bcmt.major_id,bc.views AS increment\n" +
"FROM boe_cases bc\n" +
"JOIN boe_cases_major_type bcmt ON bcmt.case_id = bc.id and bc.deleted=0 and file_path is not null and file_path!='' and bc.views !=0 and bc.views is not null";
"SELECT bc.id,bcmt.major_id,bc.views - COALESCE(bc.last_month_views, 0) AS increment\n" +
"FROM boe_cases bc\n" +
"JOIN boe_cases_major_type bcmt ON bcmt.case_id = bc.id and bc.deleted=0 and file_path is not null and file_path!='' and bc.views - COALESCE(bc.last_month_views, 0)!=0";
List<Object> caseListOfObject = casesDao.sqlFindList(sql);
// 转为casesRank
@@ -1326,24 +1320,21 @@ public class CasesServiceImpl implements ICasesService {
}
});
//排序榜单案例标签顺序
casesList.forEach(cases -> {
List<CaseViewRankingItemVo> viewRankTags = cases.getViewRankTags();
// 使用 Stream API 进行排序,保持其余元素的原始顺序
List<CaseViewRankingItemVo> sortedList = viewRankTags.stream()
.sorted((o1, o2) -> {
// majorId 相等时放前面
boolean o1Matches = o1.getMajorId().equals(majorId);
boolean o2Matches = o2.getMajorId().equals(majorId);
if (o1Matches && !o2Matches) return -1; // o1是majorId, o2不是o1排前
if (!o1Matches && o2Matches) return 1; // o2是majorId, o1不是o2排前
return 0; // 如果两者都是或都不是majorId, 保持原有顺序
})
.collect(Collectors.toList());
// 更新原列表
cases.setViewRankTags(sortedList);
Collections.sort(viewRankTags, new Comparator<CaseViewRankingItemVo>() {
@Override
public int compare(CaseViewRankingItemVo o1, CaseViewRankingItemVo o2) {
// 将 majorId 等于 传参majorId 的项优先排序
if (o1.getMajorId().equals(majorId) && !o2.getMajorId().equals(majorId)) {
return -1; // o1 应该排在 o2 前面
} else if (!o1.getMajorId().equals(majorId) && o2.getMajorId().equals(majorId)) {
return 1; // o2 应该排在 o1 前面
}
return 0; // 相同或两者都不是 传参majorId 时,保持原有顺序
}
});
});
return casesList;
}

View File

@@ -4,10 +4,13 @@ import java.util.List;
import javax.annotation.Resource;
import com.xboe.common.utils.StringUtil;
import com.xboe.core.log.AutoLog;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.xboe.core.JsonResponse;
import com.xboe.core.api.ApiBaseController;
@@ -74,22 +77,7 @@ public class CourseContentApi extends ApiBaseController{
}
return success(obj);
}
@GetMapping("/exam/paper-content")
@AutoLog(module = "试卷",action = "查看试卷试题",info = "查看当前试题内容")
public JsonResponse<Object> paperContent(String courseExamId){
if(StringUtil.isBlank(courseExamId)){
return badRequest("缺少必要参数");
}
try {
Object paperContentOfOnline = ccontentService.getPaperContentOfOnline(courseExamId);
return success(paperContentOfOnline);
} catch (Exception e) {
log.error("查询试卷内容json错误",e);
return error("查询失败",e.getMessage());
}
}
/**
* 获取评估信息
* @param ccid

View File

@@ -1,51 +1,65 @@
package com.xboe.module.course.api;
import com.xboe.api.ThirdApi;
import com.xboe.api.vo.UserBasicInfo;
import com.xboe.common.PageList;
import com.xboe.common.Pagination;
import com.xboe.common.utils.StringUtil;
import com.xboe.core.JsonResponse;
import com.xboe.core.api.ApiBaseController;
import com.xboe.core.orm.FieldFilters;
import com.xboe.module.course.dto.CourseQueryDto;
import com.xboe.module.course.dto.CourseTeacherDto;
import com.xboe.module.course.dto.RankingDto;
import com.xboe.module.course.entity.*;
import com.xboe.module.course.service.ICourseContentService;
import com.xboe.module.course.service.ICourseSectionService;
import com.xboe.module.course.service.ICourseService;
import com.xboe.module.course.service.ICourseTeacherService;
import com.xboe.module.course.vo.CourseStudyVo;
import com.xboe.module.course.vo.TeacherVo;
import com.xboe.module.teacher.entity.Teacher;
import com.xboe.module.teacher.service.ITeacherService;
import com.xboe.module.usergroup.service.IUserGroupService;
import com.xboe.school.study.dao.StudyCourseDao;
import com.xboe.school.study.entity.StudyCourse;
import com.xboe.school.study.entity.StudyCourseItem;
import com.xboe.school.study.entity.StudyHomeWork;
import com.xboe.school.study.service.IStudyCourseService;
import com.xboe.school.study.service.IStudyHomeWorkService;
import com.xboe.school.study.service.IStudyService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.xboe.api.ThirdApi;
import com.xboe.core.orm.FieldFilters;
import com.xboe.module.course.entity.*;
import com.xboe.module.course.vo.TeacherVo;
import com.xboe.school.study.dao.StudyCourseDao;
import com.xboe.school.study.entity.StudyHomeWork;
import com.xboe.school.study.service.IStudyHomeWorkService;
import com.xboe.school.study.service.IStudyService;
import com.xboe.system.user.entity.User;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.xboe.common.PageList;
import com.xboe.common.Pagination;
import com.xboe.common.utils.StringUtil;
import com.xboe.core.JsonResponse;
import com.xboe.core.api.ApiBaseController;
import com.xboe.module.course.dto.CourseQueryDto;
import com.xboe.module.course.dto.CourseTeacherDto;
import com.xboe.module.course.dto.RankingDto;
import com.xboe.module.course.service.ICourseContentService;
import com.xboe.module.course.service.ICourseSectionService;
import com.xboe.module.course.service.ICourseService;
import com.xboe.module.course.service.ICourseTeacherService;
import com.xboe.module.course.vo.CourseStudyVo;
import com.xboe.module.teacher.entity.Teacher;
import com.xboe.module.teacher.service.ITeacherService;
import com.xboe.module.usergroup.service.IUserGroupService;
import com.xboe.school.study.entity.StudyCourse;
import com.xboe.school.study.entity.StudyCourseItem;
import com.xboe.school.study.service.IStudyCourseService;
import lombok.extern.slf4j.Slf4j;
/**
* 门户课程的相关接口处理,主要是查询显示。只查询已发布的.
@@ -351,15 +365,13 @@ public class CoursePortalApi extends ApiBaseController{
}
//作业导出
@GetMapping("/export")
public JsonResponse<String> export(String courseId,String courseName,String contentId,String name,Integer status,HttpServletRequest request) throws IOException {
public JsonResponse<String> export(String courseName,String courseId,String contentId,String name,Integer status) throws IOException {
Map<String, String>map=new HashMap<>();
List<String> userIds = studyCourseDao.findList(FieldFilters.eq("courseId", courseId)).stream().filter(Objects::nonNull).map(StudyCourse::getAid).collect(Collectors.toList());
if (userIds.isEmpty()){
return error("查询不到用户");
}
List <UserBasicInfo> userBasicInfoList =thirdApi.getUserBasicInfoByUserId(userIds,request);
List<User>user=studyService.getUserNo(userIds);
try {//筛选出的人员
List<StudyCourseItem> list = studyService.getList(courseId, contentId, name, status);
if(list.isEmpty()){
@@ -371,12 +383,12 @@ public class CoursePortalApi extends ApiBaseController{
return success("暂无数据");
}
studyHomeWorks.forEach(e->{
userBasicInfoList.forEach(u->{
if(u.getUserId().equals(s.getAid())){
user.forEach(u->{
if(u.getId().equals(s.getAid())){
//取后缀
int dotIndex = e.getFilePath().lastIndexOf('.'); // 查找最后一个'.'的位置
String extension = e.getFilePath().substring(dotIndex);
map.put(u.getUserName()+"-"+u.getWorkNum()+extension,"/home/www/elearning/upload"+e.getFilePath());
map.put(u.getName()+"-"+u.getUserNo()+extension,"/home/www/elearning/upload"+e.getFilePath());
}
});
});
@@ -392,36 +404,60 @@ public class CoursePortalApi extends ApiBaseController{
if (totalFileSize > 2L * 1024 * 1024 * 1024) {
return success("您要下载的作业过大,请分批下载或联系管理员!");
}
// 创建压缩文件
String zipFilePath = "/home/www/elearning/upload/saveZip/" + courseName+"【作业】" + ".zip";
createZipFile(map, zipFilePath);
return success(zipFilePath);
}
private static void createZipFile(Map<String, String> map, String zipFilePath) throws IOException {
try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFilePath))) {
for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
File file = new File(value);
if (!file.exists()) {
continue;
}
// String encodedFilename = URLEncoder.encode(courseName+"【作业】.zip")
// .replace("+", "%20") // 空格替换为"%20"
// .replace("%2F", "/"); // 解决斜杠问题
// StringBuilder contentDispositionValue = new StringBuilder();
// contentDispositionValue.append("attachment; filename=\"")
// .append(encodedFilename)
// .append("\"")
// .append("; filename*=utf-8''")
// .append(encodedFilename);
//
// // 设置响应类型和Content-Disposition头
// response.setContentType("application/zip");
byte[] buffer = new byte[1024];
FileInputStream fis = new FileInputStream(file);
ZipEntry zipEntry = new ZipEntry(key);
zos.putNextEntry(zipEntry);
// 创建一个临时文件用于存储ZIP文件
File tempZipFile = new File("/home/www/elearning/upload/temp.zip");
int length;
while ((length = fis.read(buffer)) > 0) {
zos.write(buffer, 0, length);
try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(tempZipFile))) {
for (Map.Entry<String, String> e : map.entrySet()) {
File fileToZip = new File(e.getValue());
// 添加 ZIP 条目
ZipEntry entry = new ZipEntry(e.getKey());
entry.setSize(fileToZip.length());
zos.putNextEntry(entry);
try (FileInputStream fis = new FileInputStream(fileToZip)) {
byte[] buffer = new byte[4096];
int len;
while ((len = fis.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
}
zos.closeEntry();
fis.close();
}
}
// 将临时文件移动到指定位置
Path source = tempZipFile.toPath();
//生成uuid
String uuid = UUID.randomUUID().toString();
Path destination = Paths.get("/home/www/elearning/upload/saveZip/" + uuid + ".zip");
// 删除目标文件如果已存在
if (Files.exists(destination)) {
Files.delete(destination);
}
// 移动文件
Files.copy(source, destination, StandardCopyOption.REPLACE_EXISTING);
// 返回文件路径给前端
String filePath = destination.toAbsolutePath().toString();
return success(filePath);
}
@GetMapping("/detail-study")
public JsonResponse<List<CourseStudyVo>> detailStudy(String courseId, String aid){

View File

@@ -85,6 +85,4 @@ public interface ICourseContentService{
void updateProcessVideo(String contentId, String courseId, Float processVideo);
Object getPaperContentOfOnline(String courseExamId);
}

View File

@@ -1,17 +1,23 @@
package com.xboe.module.course.service.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.xboe.common.OrderCondition;
import com.xboe.core.cache.IXaskCache;
import com.xboe.core.cache.XaskCacheProvider;
import com.xboe.core.orm.FieldFilters;
import com.xboe.core.orm.UpdateBuilder;
import com.xboe.module.course.dao.*;
import com.xboe.module.course.dao.CourseAssessDao;
import com.xboe.module.course.dao.CourseContentDao;
import com.xboe.module.course.dao.CourseExamDao;
import com.xboe.module.course.dao.CourseHomeWorkDao;
import com.xboe.module.course.dao.CourseSectionDao;
import com.xboe.module.course.dto.CourseContentDto;
import com.xboe.module.course.dto.SortItem;
import com.xboe.module.course.entity.CourseAssess;
@@ -19,21 +25,8 @@ import com.xboe.module.course.entity.CourseContent;
import com.xboe.module.course.entity.CourseExam;
import com.xboe.module.course.entity.CourseHomeWork;
import com.xboe.module.course.service.ICourseContentService;
import com.xboe.module.exam.dao.ExamPaperDao;
import com.xboe.module.exam.vo.TestQuestionVo;
import com.xboe.standard.enums.BoedxContentType;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
@Slf4j
@Service
public class CourseContentServiceImpl implements ICourseContentService {
@@ -51,13 +44,7 @@ public class CourseContentServiceImpl implements ICourseContentService {
@Resource
private CourseHomeWorkDao homeworkDao;
@Resource
private CourseExamDao courseExamDao;
@Resource
private ExamPaperDao examPaperDao;
@Override
@Transactional
@@ -91,9 +78,6 @@ public class CourseContentServiceImpl implements ICourseContentService {
assessDao.saveOrUpdate(assess);
}
if(exam!=null) {
if ((exam.getRandomMode() && !(exam.getQnum() > 0)) || (!exam.getRandomMode() && exam.getQnum() > 0)) {
throw new RuntimeException("随机选题处参数错误");
}
exam.setCourseId(cc.getCourseId());
exam.setContentId(cc.getId());
if(exam.getPercentScore()==null) {
@@ -204,68 +188,4 @@ public class CourseContentServiceImpl implements ICourseContentService {
return ccDao.sumDurationByCourseId(courseId);
}
@Override
public Object getPaperContentOfOnline(String courseExamId) {
CourseExam courseExam = courseExamDao.findOne(FieldFilters.eq("id", courseExamId));
if (courseExam == null) {
throw new RuntimeException("课程考试不存在");
}
String paperId = courseExam.getPaperId();
Integer qnum = courseExam.getQnum();
Boolean randomMode = courseExam.getRandomMode();
String paperJson = "";
ObjectMapper objectMapper = new ObjectMapper();
try {
// 判断试卷类型
if (courseExam.getPaperType() == 1 && StringUtils.isNotBlank(courseExam.getPaperContent())) {
paperJson = courseExam.getPaperContent();
JsonNode rootNode = objectMapper.readTree(paperJson);
JsonNode itemsNode = rootNode.path("items");
List<JsonNode> itemsNodes = new ArrayList<>();
itemsNode.forEach(itemsNodes::add);
if (randomMode && qnum != null && qnum > 0 && randomMode && qnum != null && qnum > 0 && itemsNodes.size() > qnum) {
Collections.shuffle(itemsNodes);
itemsNodes = itemsNodes.subList(0, qnum);
}
return itemsNodes;
} else if (courseExam.getPaperType() == 2) {
IXaskCache cache = XaskCacheProvider.getCache();
String cacheKey = "course:exam:" + courseExamId + ":" + paperId;
String cacheData = cache.getCacheObject(cacheKey);
if (StringUtils.isBlank(cacheData)) {
paperJson = (String) examPaperDao.findField("paperContent", FieldFilters.eq("id", paperId));
cache.setCacheObject(cacheKey, paperJson, 5, TimeUnit.HOURS);
} else {
paperJson = cacheData;
}
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
List<TestQuestionVo> eqVoList = objectMapper.readValue(paperJson, new TypeReference<List<TestQuestionVo>>() {
});
if (randomMode && qnum != null && qnum > 0 && eqVoList.size() > qnum) {
Collections.shuffle(eqVoList);
eqVoList = eqVoList.subList(0, qnum);
}
return eqVoList;
}
} catch (JsonProcessingException e) {
log.error("JSON处理错误", e);
throw new RuntimeException(e);
}
if (StringUtils.isBlank(paperJson)) {
throw new RuntimeException("此考试无试卷内容,考试已经过期或试卷已被删除");
}
return null;
}
}

View File

@@ -166,253 +166,118 @@ public class ExamQuestionApi extends ApiBaseController {
return badRequest("请上传正确的试题文件");
}
//获取表头
Row row ;
Row row = sheetAt.getRow(2);
//从第二行开始获取数据
List<ExamQuestion> examQuestions1 = new ArrayList<>();
QuestionDto questionDto = new QuestionDto();
if(sheetAt.getRow(1).getCell(0).getStringCellValue().equals("标题(*)") && !sheetAt.getRow(1).getCell(0).getStringCellValue().equals("")){
row = sheetAt.getRow(1);
for (int i = 2;i<sheetAt.getPhysicalNumberOfRows();i++) {
//获取每一行
Row row1 = sheetAt.getRow(i);
if(row1==null || row1.getCell(0)==null){
break;
}
if(StringUtil.isBlank(row1.getCell(0).getStringCellValue())){
break;
}
ExamQuestion examQuestion = new ExamQuestion();
examQuestion.setTitle(row1.getCell(0).getStringCellValue());
if(row1.getCell(1).getStringCellValue().equals("单选题")){
examQuestion.setType(1);
}
if(row1.getCell(1).getStringCellValue().equals("多选题")){
examQuestion.setType(2);
}
if(row1.getCell(2).getStringCellValue().equals("")){
examQuestion.setDifficulty(2f);
}else if(row1.getCell(2).getStringCellValue().equals("")){
examQuestion.setDifficulty(3f);
} else if(row1.getCell(2).getStringCellValue().equals("")){
examQuestion.setDifficulty(1f);
}else if(row1.getCell(2).getStringCellValue().equals("")){
examQuestion.setDifficulty(null);
}
Cell cell = row1.getCell(3);
cell.setCellType(CellType.STRING);
for (int i=3;i<sheetAt.getPhysicalNumberOfRows();i++) {
//获取每一行
// examQuestion.setDefaultScore(Float.valueOf(cell.getStringCellValue()));
//单选
if (!cell.getStringCellValue().contains(",")){
examQuestion.setAnswer(row1.getCell(5).getStringCellValue());
if (row1.getCell(3).getStringCellValue().isEmpty()){
examQuestion.setDefaultScore(null);
}else {
examQuestion.setDefaultScore(Float.valueOf(row1.getCell(3).getStringCellValue()));
}
Cell cell1 = row1.getCell(4, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
cell1.setCellType(CellType.STRING);
examQuestion.setAnalysis(cell1.getStringCellValue());
List<ExamOption> examOptions = new ArrayList<>();
for (int j=6;j<=12;j++) {
if(row1.getCell(j)!=null) {
ExamOption examOption = new ExamOption();
// 截取表头
String substring = row.getCell(j).getStringCellValue().substring(3, 4);
if (row1.getCell(5).getStringCellValue().contains(substring)) {
examOption.setIsAnswer(true);
if (row1.getCell(3).getStringCellValue().isEmpty()){
examOption.setScore(null);
}else {
examOption.setScore(Float.valueOf(row1.getCell(3).getStringCellValue()));
}
} else {
examOption.setIsAnswer(false);
}
if (examOption.getIsAnswer()) {
if (row1.getCell(3).getStringCellValue().isEmpty()){
examOption.setScore(null);
}else {
examOption.setScore(Float.valueOf(row1.getCell(3).getStringCellValue()));
}
}
examOption.setOptions(row.getCell(j).getStringCellValue());
Cell cell2 = row1.getCell(j);
cell2.setCellType(CellType.STRING);
examOption.setContent(cell2.getStringCellValue());
if (examOption != null && StringUtil.isNotBlank(examOption.getContent())) {
examOptions.add(examOption);
}
}
}
examQuestion.setOptionList(examOptions);
examQuestions1.add(examQuestion);
}
//多选 多选的默认分存的是最大分
else{
String stringCellValue = row1.getCell(4).getStringCellValue();
String[] strings = stringCellValue.split(",");
// String[] strings = new String[stringCellValue.length()];
String max=strings[0];
for (int j=0;j<strings.length;j++) {
if(Float.valueOf(max)<Float.valueOf(strings[j])){
max=strings[j];
}
}
examQuestion.setDefaultScore(Float.valueOf(max));
Cell cell1 = row1.getCell(4, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
cell1.setCellType(CellType.STRING);
examQuestion.setAnalysis(cell1.getStringCellValue());
examQuestion.setAnswer(row1.getCell(5).getStringCellValue());
List<ExamOption> examOptions = new ArrayList<>();
//A
for (int j=6;j<=12;j++){
if(row1.getCell(j)!=null && StringUtil.isNotBlank(row1.getCell(j).getStringCellValue())){
ExamOption examOption=new ExamOption();
examOption.setOptions(row.getCell(j).getStringCellValue());
examOption.setContent(row1.getCell(j).getStringCellValue());
examOption.setIsAnswer(true);
examOption.setScore(Float.valueOf(strings[j-6]));
if(examOption!=null && StringUtil.isNotBlank(examOption.getContent())){
examOptions.add(examOption);
}
}
}
examQuestion.setOptionList(examOptions);
examQuestions1.add(examQuestion);
}
Row row1 = sheetAt.getRow(i);
if(row1==null || row1.getCell(0)==null){
break;
}
}else {
row = sheetAt.getRow(2);
for (int i = 3;i<sheetAt.getPhysicalNumberOfRows();i++) {
//获取每一行
Row row1 = sheetAt.getRow(i);
if(row1==null || row1.getCell(0)==null){
break;
}
if(StringUtil.isBlank(row1.getCell(0).getStringCellValue())){
break;
}
ExamQuestion examQuestion = new ExamQuestion();
examQuestion.setTitle(row1.getCell(0).getStringCellValue());
if(row1.getCell(1).getStringCellValue().equals("单选题")){
examQuestion.setType(1);
}
if(row1.getCell(1).getStringCellValue().equals("多选题")){
examQuestion.setType(2);
}
if(row1.getCell(2).getStringCellValue().equals("")){
examQuestion.setDifficulty(2f);
}else if(row1.getCell(2).getStringCellValue().equals("")){
examQuestion.setDifficulty(3f);
} else if(row1.getCell(2).getStringCellValue().equals("")){
examQuestion.setDifficulty(1f);
}else if(row1.getCell(2).getStringCellValue().equals("")){
examQuestion.setDifficulty(null);
}
Cell cell = row1.getCell(3);
cell.setCellType(CellType.STRING);
if(StringUtil.isBlank(row1.getCell(0).getStringCellValue())){
break;
}
ExamQuestion examQuestion = new ExamQuestion();
examQuestion.setTitle(row1.getCell(0).getStringCellValue());
if(row1.getCell(1).getStringCellValue().equals("单选题")){
examQuestion.setType(1);
}
if(row1.getCell(1).getStringCellValue().equals("多选题")){
examQuestion.setType(2);
}
examQuestion.setKnowledge(row1.getCell(2).getStringCellValue());
if(row1.getCell(3).getStringCellValue().equals("")){
examQuestion.setDifficulty(2f);
}
if(row1.getCell(3).getStringCellValue().equals("")){
examQuestion.setDifficulty(3f);
}
if(row1.getCell(3).getStringCellValue().equals("")){
examQuestion.setDifficulty(1f);
}
Cell cell = row1.getCell(4);
cell.setCellType(CellType.STRING);
// examQuestion.setDefaultScore(Float.valueOf(cell.getStringCellValue()));
//单选
if (!cell.getStringCellValue().contains(",")){
examQuestion.setAnswer(row1.getCell(5).getStringCellValue());
if (row1.getCell(3).getStringCellValue().isEmpty()){
examQuestion.setDefaultScore(null);
}else {
examQuestion.setDefaultScore(Float.valueOf(row1.getCell(3).getStringCellValue()));
}
Cell cell1 = row1.getCell(4, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
cell1.setCellType(CellType.STRING);
examQuestion.setAnalysis(cell1.getStringCellValue());
//单选
if (!cell.getStringCellValue().contains(",")){
examQuestion.setAnswer(row1.getCell(6).getStringCellValue());
examQuestion.setDefaultScore(Float.valueOf(row1.getCell(4).getStringCellValue()));
Cell cell1 = row1.getCell(5, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
cell1.setCellType(CellType.STRING);
examQuestion.setAnalysis(cell1.getStringCellValue());
List<ExamOption> examOptions = new ArrayList<>();
for (int j=6;j<=12;j++) {
List<ExamOption> examOptions = new ArrayList<>();
for (int j=7;j<=13;j++) {
if(row1.getCell(j)!=null) {
ExamOption examOption = new ExamOption();
if(row1.getCell(j)!=null) {
ExamOption examOption = new ExamOption();
// 截取表头
String substring = row.getCell(j).getStringCellValue().substring(3, 4);
if (row1.getCell(5).getStringCellValue().contains(substring)) {
String substring = row.getCell(j).getStringCellValue().substring(3, 4);
if (row1.getCell(6).getStringCellValue().contains(substring)) {
examOption.setIsAnswer(true);
if (row1.getCell(3).getStringCellValue().isEmpty()){
examOption.setScore(null);
}else {
examOption.setScore(Float.valueOf(row1.getCell(3).getStringCellValue()));
}
} else {
examOption.setIsAnswer(false);
}
if (examOption.getIsAnswer()) {
if (row1.getCell(3).getStringCellValue().isEmpty()){
examOption.setScore(null);
}else {
examOption.setScore(Float.valueOf(row1.getCell(3).getStringCellValue()));
}
}
examOption.setOptions(row.getCell(j).getStringCellValue());
Cell cell2 = row1.getCell(j);
cell2.setCellType(CellType.STRING);
examOption.setContent(cell2.getStringCellValue());
if (examOption != null && StringUtil.isNotBlank(examOption.getContent())) {
examOptions.add(examOption);
}
}
}
examQuestion.setOptionList(examOptions);
examQuestions1.add(examQuestion);
}
//多选 多选的默认分存的是最大分
else{
String stringCellValue = row1.getCell(4).getStringCellValue();
String[] strings = stringCellValue.split(",");
// String[] strings = new String[stringCellValue.length()];
String max=strings[0];
for (int j=0;j<strings.length;j++) {
if(Float.valueOf(max)<Float.valueOf(strings[j])){
max=strings[j];
}
}
examQuestion.setDefaultScore(Float.valueOf(max));
Cell cell1 = row1.getCell(4, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
cell1.setCellType(CellType.STRING);
examQuestion.setAnalysis(cell1.getStringCellValue());
examQuestion.setAnswer(row1.getCell(5).getStringCellValue());
List<ExamOption> examOptions = new ArrayList<>();
//A
for (int j=6;j<=13;j++){
if(row1.getCell(j)!=null && StringUtil.isNotBlank(row1.getCell(j).getStringCellValue())){
ExamOption examOption=new ExamOption();
examOption.setOptions(row.getCell(j).getStringCellValue());
examOption.setContent(row1.getCell(j).getStringCellValue());
examOption.setIsAnswer(true);
examOption.setScore(Float.valueOf(strings[j-6]));
if(examOption!=null && StringUtil.isNotBlank(examOption.getContent())){
examOptions.add(examOption);
}
examOption.setScore(Float.valueOf(row1.getCell(4).getStringCellValue()));
} else {
examOption.setIsAnswer(false);
}
if (examOption.getIsAnswer()) {
examOption.setScore(Float.valueOf(row1.getCell(4).getStringCellValue()));
}
examOption.setOptions(row.getCell(j).getStringCellValue());
Cell cell2 = row1.getCell(j);
cell2.setCellType(CellType.STRING);
examOption.setContent(cell2.getStringCellValue());
if (examOption != null && StringUtil.isNotBlank(examOption.getContent())) {
examOptions.add(examOption);
}
}
examQuestion.setOptionList(examOptions);
examQuestions1.add(examQuestion);
}
examQuestion.setOptionList(examOptions);
examQuestions1.add(examQuestion);
}
//多选 多选的默认分存的是最大分
else{
String stringCellValue = row1.getCell(4).getStringCellValue();
String[] strings = stringCellValue.split(",");
// String[] strings = new String[stringCellValue.length()];
String max=strings[0];
for (int j=0;j<strings.length;j++) {
if(Float.valueOf(max)<Float.valueOf(strings[j])){
max=strings[j];
}
}
examQuestion.setDefaultScore(Float.valueOf(max));
Cell cell1 = row1.getCell(5, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
cell1.setCellType(CellType.STRING);
examQuestion.setAnalysis(cell1.getStringCellValue());
examQuestion.setAnswer(row1.getCell(6).getStringCellValue());
List<ExamOption> examOptions = new ArrayList<>();
//A
for (int j=7;j<=13;j++){
if(row1.getCell(j)!=null && StringUtil.isNotBlank(row1.getCell(j).getStringCellValue())){
ExamOption examOption=new ExamOption();
examOption.setOptions(row.getCell(j).getStringCellValue());
examOption.setContent(row1.getCell(j).getStringCellValue());
examOption.setIsAnswer(true);
examOption.setScore(Float.valueOf(strings[j-7]));
if(examOption!=null && StringUtil.isNotBlank(examOption.getContent())){
examOptions.add(examOption);
}
}
}
examQuestion.setOptionList(examOptions);
examQuestions1.add(examQuestion);
}
}
//判断题 只存在试题表中
@@ -435,30 +300,27 @@ public class ExamQuestionApi extends ApiBaseController {
ExamQuestion examQuestion1 = new ExamQuestion();
examQuestion1.setTitle(row2.getCell(0).getStringCellValue());
examQuestion1.setType(3);
System.out.println("1+++++++"+row2.getCell(1));
if(row2.getCell(1).getStringCellValue().equals("")){
examQuestion1.setKnowledge(row2.getCell(1).getStringCellValue());
if(row2.getCell(2).getStringCellValue().equals("")){
examQuestion1.setDifficulty(2f);
}else if(row2.getCell(1).getStringCellValue().equals("")){
}
if(row2.getCell(2).getStringCellValue().equals("")){
examQuestion1.setDifficulty(3f);
} else if(row2.getCell(1).getStringCellValue().equals("")){
}
if(row2.getCell(2).getStringCellValue().equals("")){
examQuestion1.setDifficulty(1f);
}else if(row2.getCell(1).getStringCellValue().equals("")){
examQuestion1.setDifficulty(null);
}
Cell cell1 = row2.getCell(2);
Cell cell1 = row2.getCell(3);
cell1.setCellType(CellType.STRING);
if (row2.getCell(2).getStringCellValue().isEmpty()){
examQuestion1.setDefaultScore(null);
}else {
examQuestion1.setDefaultScore(Float.valueOf(row2.getCell(2).getStringCellValue()));
}
if(row2.getCell(3)!=null) {
examQuestion1.setAnalysis(row2.getCell(3).getStringCellValue());
examQuestion1.setDefaultScore(Float.valueOf(cell1.getStringCellValue()));
if(row2.getCell(4)!=null) {
examQuestion1.setAnalysis(row2.getCell(4).getStringCellValue());
}else {
examQuestion1.setAnalysis("");
}
String cvalue=row2.getCell(4).getStringCellValue();
String cvalue=row2.getCell(5).getStringCellValue();
examQuestion1.setAnswer(cvalue.equals("正确")? "true":"false");
if(examQuestion1!=null){
examQuestions2.add(examQuestion1);

View File

@@ -117,7 +117,7 @@ public class StudyExam extends IdEntity {
/*
* 开始时间
* */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy--MM-dd HH:mm:ss")
@Column(name = "start_time")
private LocalDateTime startTime;
/*

View File

@@ -99,4 +99,5 @@ public interface IStudyService {
List<StudyCourseItem> getList(String courseId, String contentId, String name, Integer status);
List<User> getUserNo(List<String> userIds);
}

View File

@@ -1,9 +1,24 @@
package com.xboe.school.study.service.impl;
import java.time.LocalDateTime;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import com.xboe.api.ThirdApi;
import com.xboe.core.orm.QueryBuilder;
import com.xboe.school.study.entity.StudyCourse;
import com.xboe.system.user.entity.Message;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import com.xboe.common.OrderCondition;
import com.xboe.core.orm.FieldFilters;
import com.xboe.core.orm.QueryBuilder;
import com.xboe.core.orm.UpdateBuilder;
import com.xboe.module.course.dao.CourseContentDao;
import com.xboe.module.course.dao.CourseExamDao;
import com.xboe.module.course.entity.CourseExam;
@@ -13,17 +28,6 @@ import com.xboe.school.study.dao.StudyExamDao;
import com.xboe.school.study.entity.StudyCourseItem;
import com.xboe.school.study.entity.StudyExam;
import com.xboe.school.study.service.IStudyExamService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;
@Slf4j
@Service
@@ -69,31 +73,29 @@ public class StudyExamServiceImpl implements IStudyExamService{
exam.setPassLine(0);
}
int prog=exam.getScore().intValue()>=exam.getPassLine()?100:exam.getScore().intValue();
//完成处理,判断是否已存在
Object obj=scItemDao.findField("id", FieldFilters.eq("studyId", exam.getStudyId()), FieldFilters.eq("contentId", exam.getContentId()));
//获取本次考试提交,学习状态与学习进度
int status=exam.getScore()>=exam.getPassLine()?StudyCourseItem.STATUS_FINISH:StudyCourseItem.STATUS_STUDYING;
int progress = exam.getScore().intValue() >= exam.getPassLine() ? 100 : 0;
//计算时长
LocalDateTime ldt=LocalDateTime.now();
if(obj==null) {
StudyCourseItem sci=new StudyCourseItem();
LocalDateTime ldt=LocalDateTime.now();
sci.setStudyId(exam.getStudyId());
sci.setContentId(exam.getContentId());
sci.setContentName("考试");
sci.setCourseId(exam.getCourseId());
//sci.setCsectionId(homework.getCsectionId());
sci.setProgress(progress);//直接设置为学习完成
sci.setProgress(prog);//直接设置为学习完成
sci.setStatus(status);//状态直接更新为已完成
sci.setStartTime(exam.getStartTime());
sci.setStartTime(ldt);
sci.setAid(exam.getStudentId());
sci.setAname(exam.getStudentName());
sci.setFinishTime(ldt);
sci.setFinishTime(LocalDateTime.now());
sci.setLastStudyTime(0);//此项用户记录视频内容当前学习的时间点
sci.setLastTime(ldt);
sci.setScore(exam.getScore());
sci.setStudyDuration(exam.getTestDuration());
if(cexam.getScoringType()==CourseExam.SCORINGTYPE_LAST) {
sci.setScore(exam.getScore());
}
scItemDao.save(sci);
exam.setStudyItemId(sci.getId());
dao.save(exam);
@@ -106,34 +108,35 @@ public class StudyExamServiceImpl implements IStudyExamService{
}else {
exam.setStudyItemId(obj.toString());//此项就是学习条目的id
Float maxScore = (Float) dao.findField("max(score)", FieldFilters.eq("contentId", exam.getContentId()), FieldFilters.eq("courseId", exam.getCourseId()), FieldFilters.eq("studyId", exam.getStudyId()));
dao.save(exam);
//最新考试分值
if (cexam.getScoringType() == CourseExam.SCORINGTYPE_LAST) {
scItemDao.updateMultiFieldById(exam.getStudyItemId(),
UpdateBuilder.create("startTime", exam.getStartTime()),
UpdateBuilder.create("finishTime", ldt),
UpdateBuilder.create("score", exam.getScore()),
UpdateBuilder.create("progress", progress),
UpdateBuilder.create("status", status),
UpdateBuilder.create("studyDuration", exam.getTestDuration())
);
}
//最高分
if (cexam.getScoringType() == CourseExam.SCORINGTYPE_MAX) {
if (exam.getScore() > maxScore) {
scItemDao.updateMultiFieldById(exam.getStudyItemId(),
UpdateBuilder.create("startTime", exam.getStartTime()),
UpdateBuilder.create("finishTime", LocalDateTime.now()),
UpdateBuilder.create("score", exam.getScore()),
UpdateBuilder.create("progress", progress),
UpdateBuilder.create("status", status)
);
if(cexam.getScoringType()==CourseExam.SCORINGTYPE_LAST){
scItemDao.updateFieldById(exam.getStudyItemId(), "score",exam.getScore());
scItemDao.updateFieldById(exam.getStudyItemId(), "progress",prog);
if(exam.getScore()>=exam.getPassLine()){
scItemDao.updateFieldById(exam.getStudyId(), "progress",100);
scItemDao.updateFieldById(exam.getStudyId(), "finish_time",LocalDateTime.now());
scItemDao.updateFieldById(exam.getStudyId(), "status",StudyCourseItem.STATUS_FINISH);
scItemDao.updateFieldById(exam.getStudyId(), "score",exam.getScore());
//scDao.updateFieldById(exam.getStudyId(), "last_score",100.0f);
}
}
}
//1最高一次,用于最高一次的计算
if(cexam.getScoringType()==CourseExam.SCORINGTYPE_MAX) {
Float f=(Float)dao.findField("max(score)", FieldFilters.eq("contentId", exam.getContentId()), FieldFilters.eq("courseId", exam.getCourseId()), FieldFilters.eq("studyId", exam.getStudyId()));
scItemDao.updateFieldById(exam.getStudyItemId(), "score", f);
scItemDao.updateFieldById(exam.getStudyItemId(), "status", f>=exam.getPassLine()?StudyCourseItem.STATUS_FINISH:StudyCourseItem.STATUS_STUDYING);
scItemDao.updateFieldById(exam.getStudyItemId(), "progress",f>=exam.getPassLine()?100:f.intValue());
if(f>=exam.getPassLine()){
scItemDao.updateFieldById(exam.getStudyId(), "progress",100);
scItemDao.updateFieldById(exam.getStudyId(), "finish_time",LocalDateTime.now());
scItemDao.updateFieldById(exam.getStudyId(), "status",StudyCourseItem.STATUS_FINISH);
scItemDao.updateFieldById(exam.getStudyId(), "score",exam.getScore());
//scDao.updateFieldById(exam.getStudyId(), "last_score",100.0f);
}
}
int totalContent = courseContentDao.getCount(exam.getCourseId());
scDao.finishCheck(exam.getStudyId(),exam.getCourseId(),totalContent,token);
scDao.updateFieldById(exam.getStudyId(), "last_score",exam.getScore());

View File

@@ -64,7 +64,6 @@ public class StudyHomeWorkServiceImpl implements IStudyHomeWorkService{
int totalContent=courseContentDao.count(FieldFilters.eq("courseId", homework.getCourseId()),FieldFilters.eq("deleted",false));
scDao.finishCheck(homework.getStudyId(),homework.getCourseId(),totalContent,token);
}else {
scItemDao.updateFieldById(obj.toString(), "finishTime", LocalDateTime.now());
//只是保留一条作业记录,不再保存多条记录了
//dao.save(homework);
//设置id。然后进行悠

View File

@@ -294,11 +294,16 @@ public class StudyServiceImpl implements IStudyService{
}
if(StringUtils.isNotBlank(name)) {
query.addFilter(FieldFilters.like("aname", name));
query.addFilter(FieldFilters.eq("aname", name));
}
return scItemDao.findList(query.builder());
}
@Override
public List<User> getUserNo(List<String> userIds) {
return userDao.findList(FieldFilters.in("id", userIds));
}
@Override
@Transactional
public void updateProcess(String studyContentId,String studyId, String courseId,Integer total, Integer progress,String token) {

View File

@@ -74,5 +74,4 @@ manageApi.stu.offcourse=${boe.domain}/manageApi/stu/offcourse/getOffCourseId
manageApi.editExam=${boe.domain}/manageApi/admin/project/editExam
#获取离职教师id
userBasic.getTeacherIds=${boe.domain}/userbasic/user/getTeacherInfo
coursesuilt.getStudyStatus=${boe.domain}/manageApi/stu/project/completeStatus
userBasic.getUserBasicInfo=${boe.domain}/userbasic/user/getUserBasicInfo
coursesuilt.getStudyStatus=${boe.domain}/manageApi/stu/project/completeStatus