Compare commits

...

31 Commits

Author SHA1 Message Date
zhaolongfei
eaafb57b83 视频进行工号验证 2024-11-11 15:15:28 +08:00
zhaolongfei
ee74f47261 视频进行工号验证 2024-11-11 15:12:27 +08:00
zhaolongfei
d9d1e0fecc 视频进行工号验证 2024-11-08 17:34:07 +08:00
zhaolongfei
af0c26294d 视频进行工号验证 2024-11-08 17:12:01 +08:00
zhaolongfei
87adf2aca5 在线视频播放时进行token和工号验证 2024-11-06 09:03:06 +08:00
yang
b0f01c6300 取消定时任务 2024-10-27 18:08:39 +08:00
nisen
e51d4dd8cb 视频请求头解析时间对比注释 2024-10-24 19:29:42 +08:00
zhaolongfei
ea1cda25bd 删除报名信息添加日志 2024-10-24 16:22:51 +08:00
zhaolongfei
3d3e660e68 在线课多目录重复学习记录问题修复 2024-10-22 16:49:23 +08:00
zhaolongfei
b509b783a1 视频解析添加日志 2024-10-21 14:04:52 +08:00
nisen
469145d25c Merge remote-tracking branch 'yx/master-0930' 2024-10-09 18:53:40 +08:00
yang
25d8594a2b 案例,bug 2024-10-09 18:52:23 +08:00
nisen
3001c25590 Merge remote-tracking branch '104/master' 2024-10-09 17:48:11 +08:00
nisen
95b63155cd Merge branch 'zcwy0927-yang-random' 2024-10-09 17:46:52 +08:00
yang
85517dcd57 随机选题,bug 2024-10-09 14:57:56 +08:00
nisen
0e897b5f14 Merge remote-tracking branch 'yx/master-0930' into 104-master 2024-10-08 20:18:33 +08:00
yang
39e336d044 案例bug修复 2024-10-08 20:17:08 +08:00
yang
9da0eae4c0 考试随机选题 2024-10-08 19:27:46 +08:00
yang
74a36d72a1 作业导出,考试随机选题 2024-10-08 17:40:28 +08:00
nisen
4ef1b5b1e9 Merge branch 'zcwy0912-llf' into 104-master 2024-09-30 12:02:11 +08:00
Wangxxz
33df8b0831 加判断 2024-09-30 11:57:55 +08:00
nisen
b61923233a Merge branch 'zcwy0912-llf' 2024-09-30 11:52:29 +08:00
Wangxxz
effb45c6d0 加判断 2024-09-30 11:51:47 +08:00
nisen
95aa5f7abe Merge branch 'zcwy0912-llf' 2024-09-30 10:43:13 +08:00
zhaolongfei
3af3c2eedf 考试随机试题功能修改 2024-09-29 11:17:00 +08:00
yang
516225f52e 作业导出,案例类型处理代码回退版本 2024-09-27 22:38:35 +08:00
nisen
e3c060b8d9 Merge remote-tracking branch 'yx/zcwy0913-yang-case-prod' 2024-09-27 18:00:06 +08:00
nisen
72783fb1ac Merge remote-tracking branch 'yx/zcwy0923-wjwyyk-online-prod2' 2024-09-27 17:59:32 +08:00
nisen
f5f8fcee98 Merge branch 'zcwy0912-llf' into 104-master 2024-09-27 17:47:55 +08:00
yang
003d227ba3 案例萃取,案例榜单排序,定时任务 2024-09-27 17:07:24 +08:00
zhaolongfei
57e04f46c0 试题管理模板修改 2024-09-27 14:22:51 +08:00
19 changed files with 456 additions and 143 deletions

View File

@@ -205,7 +205,11 @@
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/aspose/aspose-cells-java-18.11.jar</systemPath>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.17.graal</version>
</dependency>
<!--加密配置文件-->
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
@@ -232,7 +236,7 @@
<artifactId>spring-retry</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
</dependencies>
<build>
<resources>
<resource>

View File

@@ -0,0 +1,25 @@
package com.xboe.config;
public class ConditionException extends RuntimeException{
private Integer code;
private String message;
public ConditionException(Integer code, String message) {
this.code = code;
this.message = message;
}
public ConditionException(String message) {
this(600, message);
}
public Integer getCode() {
return this.code;
}
@Override
public String getMessage() {
return message;
}
}

View File

@@ -0,0 +1,63 @@
package com.xboe.config;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.xboe.common.utils.Sha256Mac;
import org.apache.commons.codec.binary.Base64;
import java.util.Map;
/**
* Jwt工具类
*
* @author ruoyi
*/
public class JwtUtils {
public static final String secretKey = "JDF_BOE";
/**
* 从数据声明生成令牌
*
* @param claims 数据声明
* @return 令牌
*/
public static String createToken(Map<String, Object> claims) {
JSONObject header = new JSONObject();
header.put("alg", "HS256");
header.put("type", "token");
String payload64 = Base64.encodeBase64String(JSON.toJSONString(claims).getBytes());
String header64 = Base64.encodeBase64String(header.toString().getBytes());
String sign = Sha256Mac.sha256_mac(header64 + payload64, secretKey);
return header64 + "." + payload64 + "." + sign;
}
/**
* 从令牌中获取数据声明
*
* @param token 令牌
* @return 数据声明
*/
public static Map<String, Object> parseToken(String token) throws ConditionException {
String[] tokens = token.split("\\.");
if (tokens.length != 3) {
throw new ConditionException("token不合法 : " + token);
}
String payload = new String(Base64.decodeBase64(tokens[1]));
String sign = Sha256Mac.sha256_mac(tokens[0] + tokens[1], secretKey);
if (sign.equals(tokens[2])) {
JSONObject jsonObject = JSON.parseObject(payload);
long exp = jsonObject.getLong("exp");
long now = System.currentTimeMillis() / 1000;
if (now > exp) {
throw new ConditionException("token过期 : " + token);
}
Map<String, Object> map = JSON.parseObject(payload, new TypeReference<Map<String, Object>>() {
});
return map;
} else {
throw new ConditionException("token错误 : " + token);
}
}
}

View File

@@ -22,6 +22,8 @@ public interface CacheName {
*/
String NAME_USER = "user";
String NAME_INFO = "userInfo";
/**
* 用户名缓存KEY前缀
*/

View File

@@ -12,13 +12,16 @@ public class CaseScheduledTasks {
@Resource
private ICasesService casesService;
@Scheduled(cron = "0 0 1 1 * ?") // 每月的第一天的1:00执行
/**
* 每月的第一天的1:00执行
*/
// @Scheduled(cron = "0 0 1 1 * ?")
public void refreshViewsRankOfMajor() {
casesService.refreshViewsRankOfMajor();
}
/**
* 季初执行cron表达式设置为每个季度的第一个月的第一天的特定时间。每个季度的第一个月是1月、4月、7月和10月
* 季初第一天两点执行cron表达式设置为每个季度的第一个月的第一天的特定时间。每个季度的第一个月是1月、4月、7月和10月
*/
@Scheduled(cron = "0 0 2 1 1,4,7,10 ?")
public void refreshLastQuarterStatistics() {

View File

@@ -15,7 +15,9 @@ import java.util.stream.Collectors;
@Repository
@Slf4j
public class CasesRankDao extends BaseDao<CasesRank> {
/**
* 获取类别榜记录,默认按上榜时间降序排列
*/
public List<CasesRank> findViewsRankRecordByCaseId(String caseId) {
String sql =
"SELECT bdmt.name,bcvr.rise_rank_time,bcvr.rank,bcvr.major_id \n" +
@@ -24,8 +26,7 @@ public class CasesRankDao extends BaseDao<CasesRank> {
"JOIN boe_dict_major_type bdmt \n" +
" ON bdmt.code = bcvr.major_id \n" +
"WHERE bcvr.case_id = ?1 AND bcvr.deleted=0 AND bdmt.deleted=0\n" +
"ORDER BY bcvr.sys_update_time DESC \n" +
"LIMIT 2;";
"ORDER BY bcvr.rise_rank_time DESC;";
List<Object[]> list = this.sqlFindList(sql, caseId);

View File

@@ -44,6 +44,7 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Array;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
@@ -416,14 +417,36 @@ public class CasesServiceImpl implements ICasesService {
if (CollUtil.isEmpty(casesList)) {
return casesList;
}
//1.推荐案例数据处理
recommendCasesDataHandle(casesList, accountId);
//2.标签处理,添加作者标签和新的案例标签
addAuthorTagAndCaseNewTag(casesList);
//3.案例类型处理
// majorTypeHandle(casesList);
return casesList;
}
private void majorTypeHandle(List<Cases> casesList) {
if (CollUtil.isNotEmpty(casesList)) {
for (Cases c : casesList) {
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());
}
}
}
}
private void recommendCasesDataHandle(List<Cases> casesList, String accountId) {
if (StrUtil.isNotBlank(accountId)) {
List<String> caseIdList = casesList.stream().map(Cases::getId).collect(Collectors.toList());
@@ -483,7 +506,7 @@ public class CasesServiceImpl implements ICasesService {
caseList.forEach(e -> {
// 获取最新的两个浏览量上榜记录
// 获取浏览量上榜记录
List<CasesRank> viewsRankRecords = casesRankDao.findViewsRankRecordByCaseId(e.getId());
if (CollUtil.isNotEmpty(viewsRankRecords)) {
// 拼接生成浏览量排行榜的标签
@@ -1181,15 +1204,15 @@ 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";
// 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";
List<Object> caseListOfObject = casesDao.sqlFindList(sql);
@@ -1231,7 +1254,7 @@ public class CasesServiceImpl implements ICasesService {
@Override
public void refreshLastQuarterStatistics() {
log.info("开始执行每季案例相关定时任务");
int i = casesDao.sqlUpdate("update boe_cases set last_quarter_views=views,last_quarter_praise=praise where deleted=0");
int i = casesDao.sqlUpdate("update boe_cases set last_quarter_views=views,last_quarter_praises=praises where deleted=0");
log.info("每季案例相关定时任务执行完成boe_cases更新数据量为条数为"+i);
}
@@ -1277,21 +1300,24 @@ public class CasesServiceImpl implements ICasesService {
pageSize = 10;
}
LocalDateTime startTime = month.withDayOfMonth(1);
LocalDateTime endTime = month.plusMonths(1).withDayOfMonth(1).withMinute(0);
LocalDateTime startTime = month.withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0);
LocalDateTime endTime = YearMonth.from(month).atEndOfMonth().atTime(23, 59, 59);
List<HashMap<String, Object>> popularityOfMajor = casesRankDao.findPopularityOfMajor(pageSize, startTime, endTime, majorId);
List<String> caseIdList = popularityOfMajor.stream().map(map -> map.get("caseId").toString()).collect(Collectors.toList());
Map<Object, Integer> collect = popularityOfMajor.stream().collect(Collectors.toMap(map -> map.get("caseId").toString(), map -> Integer.valueOf(map.get("rank").toString())));
QueryBuilder query = QueryBuilder.from(Cases.class);
query.addFilter(FieldFilters.in("id",caseIdList));
query.addFilter(FieldFilters.eq("deleted",false));
List<Cases> casesList = casesDao.findList(query.builder());
//处理案例数据-通用操作
casesList = caseListCommonHandle(casesList, accountId);
//获取案例与排名的映射关系
Map<Object, Integer> collect = popularityOfMajor.stream().collect(Collectors.toMap(map -> map.get("caseId").toString(), map -> Integer.valueOf(map.get("rank").toString())));
//排序榜单案例顺序
Collections.sort(casesList, new Comparator<Cases>() {
@Override
public int compare(Cases c1, Cases c2) {
@@ -1300,6 +1326,26 @@ public class CasesServiceImpl implements ICasesService {
return Integer.compare(order1, order2);
}
});
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);
});
return casesList;
}

View File

@@ -4,13 +4,10 @@ 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.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 org.springframework.web.bind.annotation.*;
import com.xboe.core.JsonResponse;
import com.xboe.core.api.ApiBaseController;
@@ -77,7 +74,22 @@ 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,15 +1,20 @@
package com.xboe.module.course.api;
import java.util.Base64;
import java.util.HashSet;
import java.util.Set;
import java.util.*;
import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.hutool.json.JSONUtil;
import com.xboe.constants.CacheName;
import com.xboe.data.outside.IOutSideDataService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -28,16 +33,22 @@ import com.xboe.module.course.service.ICourseFileService;
*/
@RestController
@RequestMapping(value = "/xboe/m/course/cware")
@Slf4j
public class CourseWareApi extends ApiBaseController {
private String cookieName = "PLAYSIGN_TIME";
@Autowired
IOutSideDataService outsideDataService;
@Resource
private ICourseFileService courseFileService;
@Resource
private XFileUploader fileUploader;
@Resource
RedisTemplate<String, Object> redisTemplate;
private static Set<String> allowUrlSet = new HashSet<String>();
static {
@@ -48,7 +59,7 @@ public class CourseWareApi extends ApiBaseController {
/**
* 资源地址的加密,返回加密后的地址
*
*
* @param request
* @param response
* @param cfid 资源地址的id
@@ -83,64 +94,90 @@ public class CourseWareApi extends ApiBaseController {
/**
* 获取资源在header中保存
*
*
* @param request
* @param response
* @param cfid
* @param cf
* @throws Exception
*/
@GetMapping("/resource")
public JsonResponse<String> getVideo(HttpServletRequest request, HttpServletResponse response, String sign) throws Exception {
public JsonResponse<String> getVideo(HttpServletRequest request, HttpServletResponse response, String sign,
@CookieValue(name = "token",required = false)String token
) throws Exception {
if (StringUtils.isBlank(sign)) {
return badRequest("非法请求");
// return;
}
String httpReferer = request.getHeader("referer");
if (StringUtils.isBlank(httpReferer)) {
return badRequest("非法请求");
// return "非法请求";
}
boolean has=false;
for(String txt :allowUrlSet) {
if(httpReferer.indexOf(txt)>-1) {
has=true;
}
}
if(!has) {
return badRequest("页面不存在");
//return "非法请求";
}
//读取cookies中的时间
String cookieTime = getSignTimeCookie(request);
if (StringUtils.isBlank(cookieTime)) {
return badRequest("不支持的请求");
// return;
for(String txt :allowUrlSet) {
if(httpReferer.indexOf(txt)>-1) {
has=true;
}
}
if(!has) {
return badRequest("页面不存在");
}
// String token = request.getHeader("Xboe-Access-Token");
// if (StringUtils.isEmpty(token)) {
// token = request.getHeader("token");
// }
// 读取cookies中的时间
// String cookieTime = getSignTimeCookie(request);
// if (StringUtils.isBlank(cookieTime)) {
// return badRequest("不支持的请求");
// }
String userInfo = CacheName.NAME_INFO + ":"+ token;
log.info("请求头里的token值:"+token);
log.info("从 Redis 获取的userInfo:"+userInfo);
Object o = redisTemplate.opsForValue().get(userInfo);
if (o == null) {
log.error("从 Redis 获取的值为 null ,", userInfo);
return badRequest("token验证错误");
}
// 将对象转换为字符串
String userNoStr = o.toString();
// 检查字符串是否为空或空白
if (StringUtils.isBlank(userNoStr)) {
log.error("从 Redis 获取的值为空或空白,", userInfo);
return badRequest("token验证错误");
}
HashMap bean = JSONUtil.toBean(userNoStr, HashMap.class);
Object userNo = bean.get("userNo");
byte[] signBytes = Base64.getDecoder().decode(sign);
// byte[] signBytes = RSAUtil.decryptBase64(sign);
byte[] signDecryt = RSAUtil.decryptByPrivateKey(ConfigSecretKey.TEMP_PRIVATESTR, signBytes);
String signStr = new String(signDecryt);
// System.out.println("解密后的字符串:"+signStr);
// 第一个/前端是时间
int index = signStr.indexOf("/");
if (index <= 0) {
log.info("解密后的字符串:"+signStr);
log.info("解密后的字符串的时间拼接:"+index);
return badRequest("验证错误");
}
String time = signStr.substring(0, signStr.indexOf("/"));// 时间字符中long
String[] split = signStr.split("/");
String cfid = signStr.substring(index+1);// 文件路径
log.info("解密后的字符串:"+signStr);
if (!time.equals(cookieTime)) {
return badRequest("验证错误");
log.info("workNum工号对比:"+split[2]);
log.info("userNo工号对比:"+userNo);
if (!split[2].equals(userNo)){
return badRequest("token验证失效");
}
// if (!time.equals(cookieTime)) {
// log.info("请求头时间和解析后的时间对比:"+"解析时间:"+time+" 请求头时间:"+cookieTime);
// log.info("解密后的字符串的时间拼接:"+signStr);
// return badRequest("验证错误");
// }
if(StringUtils.isBlank(cfid) || cfid.length()<10) {
log.info("查看时间文件路径:"+cfid);
log.info("解密后的字符串的时间拼接:"+signStr);
return badRequest("验证错误");
}
@@ -164,7 +201,7 @@ public class CourseWareApi extends ApiBaseController {
/**
* 读取cookies值
*
*
* @param request
* @return
*/

View File

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

View File

@@ -1,23 +1,17 @@
package com.xboe.module.course.service.impl;
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.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 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.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.dao.*;
import com.xboe.module.course.dto.CourseContentDto;
import com.xboe.module.course.dto.SortItem;
import com.xboe.module.course.entity.CourseAssess;
@@ -25,8 +19,21 @@ 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 {
@@ -44,7 +51,13 @@ public class CourseContentServiceImpl implements ICourseContentService {
@Resource
private CourseHomeWorkDao homeworkDao;
@Resource
private CourseExamDao courseExamDao;
@Resource
private ExamPaperDao examPaperDao;
@Override
@Transactional
@@ -78,6 +91,9 @@ 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) {
@@ -188,4 +204,68 @@ 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

@@ -354,18 +354,18 @@ public class AloneExamApi extends ApiBaseController {
if(StringUtils.isBlank(paperJson)) {
return badRequest("此考试无试卷内容,考试已经过期或试卷已被删除");
}
try {
List<TestQuestionVo> qlist=this.randomQuestion(examTest, paperJson);
ObjectMapper objectMapper = new ObjectMapper();
paperJson=objectMapper.writeValueAsString(qlist);
} catch (XaskException e) {
log.error("生成试卷错误",e);
return error("生成考试试卷错误",e.getMessage(),map);
} catch (JsonProcessingException e) {
log.error("生成试卷解析生成json错误",e);
return error("生成考试试卷解析错误",e.getMessage(),map);
}
}
try {
List<TestQuestionVo> qlist=this.randomQuestion(examTest, paperJson);
ObjectMapper objectMapper = new ObjectMapper();
paperJson=objectMapper.writeValueAsString(qlist);
} catch (XaskException e) {
log.error("生成试卷错误",e);
return error("生成考试试卷错误",e.getMessage(),map);
} catch (JsonProcessingException e) {
log.error("生成试卷解析生成json错误",e);
return error("生成考试试卷解析错误",e.getMessage(),map);
}
map.put("paper", paperJson);
long end=System.currentTimeMillis();
log.info("开始考试用时="+(end-start)+" ms");

View File

@@ -170,7 +170,7 @@ public class ExamQuestionApi extends ApiBaseController {
//从第二行开始获取数据
List<ExamQuestion> examQuestions1 = new ArrayList<>();
QuestionDto questionDto = new QuestionDto();
if(sheetAt.getRow(1).getCell(0).getStringCellValue().equals("标题(*)")){
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++) {
//获取每一行
@@ -190,45 +190,56 @@ public class ExamQuestionApi extends ApiBaseController {
if(row1.getCell(1).getStringCellValue().equals("多选题")){
examQuestion.setType(2);
}
examQuestion.setKnowledge(row1.getCell(2).getStringCellValue());
if(row1.getCell(3).getStringCellValue().equals("")){
if(row1.getCell(2).getStringCellValue().equals("")){
examQuestion.setDifficulty(2f);
}
if(row1.getCell(3).getStringCellValue().equals("")){
}else if(row1.getCell(2).getStringCellValue().equals("")){
examQuestion.setDifficulty(3f);
}
if(row1.getCell(3).getStringCellValue().equals("")){
} else if(row1.getCell(2).getStringCellValue().equals("")){
examQuestion.setDifficulty(1f);
}else if(row1.getCell(2).getStringCellValue().equals("")){
examQuestion.setDifficulty(null);
}
Cell cell = row1.getCell(4);
Cell cell = row1.getCell(3);
cell.setCellType(CellType.STRING);
// examQuestion.setDefaultScore(Float.valueOf(cell.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);
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=7;j<=13;j++) {
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(6).getStringCellValue().contains(substring)) {
if (row1.getCell(5).getStringCellValue().contains(substring)) {
examOption.setIsAnswer(true);
examOption.setScore(Float.valueOf(row1.getCell(4).getStringCellValue()));
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()) {
examOption.setScore(Float.valueOf(row1.getCell(4).getStringCellValue()));
if (row1.getCell(3).getStringCellValue().isEmpty()){
examOption.setScore(null);
}else {
examOption.setScore(Float.valueOf(row1.getCell(3).getStringCellValue()));
}
}
examOption.setOptions(row.getCell(j).getStringCellValue());
@@ -258,19 +269,19 @@ public class ExamQuestionApi extends ApiBaseController {
}
}
examQuestion.setDefaultScore(Float.valueOf(max));
Cell cell1 = row1.getCell(5, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
Cell cell1 = row1.getCell(4, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
cell1.setCellType(CellType.STRING);
examQuestion.setAnalysis(cell1.getStringCellValue());
examQuestion.setAnswer(row1.getCell(6).getStringCellValue());
examQuestion.setAnswer(row1.getCell(5).getStringCellValue());
List<ExamOption> examOptions = new ArrayList<>();
//A
for (int j=7;j<=13;j++){
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-7]));
examOption.setScore(Float.valueOf(strings[j-6]));
if(examOption!=null && StringUtil.isNotBlank(examOption.getContent())){
examOptions.add(examOption);
}
@@ -301,45 +312,61 @@ public class ExamQuestionApi extends ApiBaseController {
if(row1.getCell(1).getStringCellValue().equals("多选题")){
examQuestion.setType(2);
}
examQuestion.setKnowledge(row1.getCell(2).getStringCellValue());
if(row1.getCell(3).getStringCellValue().equals("")){
examQuestion.setDifficulty(2f);
log.debug("row1.getCell(2) = " + row1.getCell(2));
if (row1.getCell(2)==null ||row1.getCell(2).getStringCellValue() == null || row1.getCell(2).getStringCellValue().equals("")){
examQuestion.setDifficulty(null);
}else{
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);
}
}
if(row1.getCell(3).getStringCellValue().equals("")){
examQuestion.setDifficulty(3f);
}
if(row1.getCell(3).getStringCellValue().equals("")){
examQuestion.setDifficulty(1f);
}
Cell cell = row1.getCell(4);
Cell cell = row1.getCell(3);
cell.setCellType(CellType.STRING);
// examQuestion.setDefaultScore(Float.valueOf(cell.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);
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=7;j<=13;j++) {
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(6).getStringCellValue().contains(substring)) {
if (row1.getCell(5).getStringCellValue().contains(substring)) {
examOption.setIsAnswer(true);
examOption.setScore(Float.valueOf(row1.getCell(4).getStringCellValue()));
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()) {
examOption.setScore(Float.valueOf(row1.getCell(4).getStringCellValue()));
if (row1.getCell(3).getStringCellValue().isEmpty()){
examOption.setScore(null);
}else {
examOption.setScore(Float.valueOf(row1.getCell(3).getStringCellValue()));
}
}
examOption.setOptions(row.getCell(j).getStringCellValue());
@@ -369,19 +396,19 @@ public class ExamQuestionApi extends ApiBaseController {
}
}
examQuestion.setDefaultScore(Float.valueOf(max));
Cell cell1 = row1.getCell(5, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
Cell cell1 = row1.getCell(4, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
cell1.setCellType(CellType.STRING);
examQuestion.setAnalysis(cell1.getStringCellValue());
examQuestion.setAnswer(row1.getCell(6).getStringCellValue());
examQuestion.setAnswer(row1.getCell(5).getStringCellValue());
List<ExamOption> examOptions = new ArrayList<>();
//A
for (int j=7;j<=13;j++){
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-7]));
examOption.setScore(Float.valueOf(strings[j-6]));
if(examOption!=null && StringUtil.isNotBlank(examOption.getContent())){
examOptions.add(examOption);
}
@@ -413,27 +440,30 @@ public class ExamQuestionApi extends ApiBaseController {
ExamQuestion examQuestion1 = new ExamQuestion();
examQuestion1.setTitle(row2.getCell(0).getStringCellValue());
examQuestion1.setType(3);
examQuestion1.setKnowledge(row2.getCell(1).getStringCellValue());
if(row2.getCell(2).getStringCellValue().equals("")){
System.out.println("1+++++++"+row2.getCell(1));
if(row2.getCell(1).getStringCellValue().equals("")){
examQuestion1.setDifficulty(2f);
}
if(row2.getCell(2).getStringCellValue().equals("")){
}else if(row2.getCell(1).getStringCellValue().equals("")){
examQuestion1.setDifficulty(3f);
}
if(row2.getCell(2).getStringCellValue().equals("")){
} else if(row2.getCell(1).getStringCellValue().equals("")){
examQuestion1.setDifficulty(1f);
}else if(row2.getCell(1).getStringCellValue().equals("")){
examQuestion1.setDifficulty(null);
}
Cell cell1 = row2.getCell(3);
Cell cell1 = row2.getCell(2);
cell1.setCellType(CellType.STRING);
examQuestion1.setDefaultScore(Float.valueOf(cell1.getStringCellValue()));
if(row2.getCell(4)!=null) {
examQuestion1.setAnalysis(row2.getCell(4).getStringCellValue());
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());
}else {
examQuestion1.setAnalysis("");
}
String cvalue=row2.getCell(5).getStringCellValue();
String cvalue=row2.getCell(4).getStringCellValue();
examQuestion1.setAnswer(cvalue.equals("正确")? "true":"false");
if(examQuestion1!=null){
examQuestions2.add(examQuestion1);

View File

@@ -116,4 +116,8 @@ public class StudyCourseDao extends BaseDao<StudyCourse> {
this.update(update.builder());
}
public StudyCourse findByCourseIdAndAid(String aid, String courseId) {
return this.findOne(FieldFilters.eq("aid",aid),FieldFilters.eq("courseId",courseId));
}
}

View File

@@ -265,6 +265,7 @@ public class StudyCourseServiceImpl implements IStudyCourseService{
}
@Override
public void deleteSignUp(String id,String courseId,String aid) {
log.info("参数id"+id+"参数课程id"+courseId+"参数用户id"+aid);
//删除课程学习记录主表
studyCourseDao.deleteById(id);
//删除学习课程的评估测试结果

View File

@@ -61,7 +61,10 @@ public class StudySignupServiceImpl implements IStudySignupService{
@Override
public void selfSignup(StudySignup signup) {
signup.setSignType(StudySignup.SIGNTYPE_SELF);
this.addSignup(signup);
StudyCourse sc=studyCourseDao.findByCourseIdAndAid(signup.getAid(), signup.getCourseId());
if (sc == null){
this.addSignup(signup);
}
//更新课程学习人数
courseDao.updateMultiFieldById(signup.getCourseId(),UpdateBuilder.create("studys", "studys+1",FieldUpdateType.EXPRESSION));
}

View File

@@ -26,7 +26,7 @@ logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
# 设置logback.xml位置
logging.config=classpath:log/logback-dev.xml
logging.config=classpath:log/logback-@profileActive@.xml
## 静态文件目录默认是在static下面以后独立到nginx下面配置
spring.web.resources.static-locations=file:E:/Projects/BOE/10/static

View File

@@ -23,7 +23,7 @@ logging.level.org.hibernate.SQL=ERROR
#logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
# 设置logback.xml位置
logging.config=classpath:log/logback-dev.xml
logging.config=classpath:log/logback-@profileActive@.xml
## 静态文件目录默认是在static下面以后独立到nginx下面配置
spring.web.resources.static-locations=file:E:/Projects/BOE/java/static

View File

@@ -34,7 +34,7 @@ logging.level.org.hibernate.SQL=ERROR
# logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
# 设置logback.xml位置
logging.config=classpath:log/logback-dev.xml
logging.config=classpath:log/logback-@profileActive@.xml
## ???????????static????????nginx????
spring.web.resources.static-locations=file:E:/Projects/BOE/java/static