package com.xiaoshouwaliang.practice.server.service.Impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.xiaoshouwaliang.practice.api.enums.*;
import com.xiaoshouwaliang.practice.api.req.*;
import com.xiaoshouwaliang.practice.api.vo.*;
import com.xiaoshouwaliang.practice.server.dao.*;
import com.xiaoshouwaliang.practice.server.entity.dto.*;
import com.xiaoshouwaliang.practice.server.entity.po.*;
import com.xiaoshouwaliang.practice.server.rpc.UserRpc;
import com.xiaoshouwaliang.practice.server.service.PracticeDetailService;
import com.xiaoshouwaliang.practice.server.utils.DateUtils;
import com.xiaoshouwaliang.practice.server.utils.LoginUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@Service
@Slf4j
public class PracticeDetailServiceImpl implements PracticeDetailService {
@Resource
private PracticeDetailDao practiceDetailDao;
@Resource
private PracticeSetDao practiceSetDao;
@Resource
private PracticeSetDetailDao practiceSetDetailDao;
@Resource
private PracticeDao practiceDao;
@Resource
private SubjectDao subjectDao;
@Resource
private SubjectRadioDao subjectRadioDao;
@Resource
private SubjectMultipleDao subjectMultipleDao;
@Resource
private SubjectJudgeDao subjectJudgeDao;
@Resource
private SubjectMappingDao subjectMappingDao;
@Resource
private SubjectLabelDao subjectLabelDao;
@Resource
private UserRpc userRpc;
@Override
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public Boolean submit(SubmitPracticeDetailReq req) {
PracticePO practicePO = new PracticePO();
Long practiceId = req.getPracticeId();
Long setId = req.getSetId();
practicePO.setSetId(setId);
String timeUse = req.getTimeUse();
String hour = timeUse.substring(0, 2);
String minute = timeUse.substring(2, 4);
String second = timeUse.substring(4, 6);
practicePO.setTimeUse(hour + ":" + minute + ":" + second);
practicePO.setSubmitTime(DateUtils.parseStrToDate(req.getSubmitTime()));
practicePO.setCompleteStatus(CompleteStatusEnum.COMPLETE.getCode());
practicePO.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
practicePO.setCreatedBy(LoginUtil.getLoginId());
practicePO.setCreatedTime(new Date());
//计算正确率
Integer correctCount = practiceDetailDao.selectCorrectCount(practiceId);
List<PracticeSetDetailPO> practiceSetDetailPOS = practiceSetDetailDao.selectBySetId(setId);
Integer totalCount = practiceSetDetailPOS.size();
BigDecimal correctRate = new BigDecimal(correctCount).divide(new BigDecimal(totalCount), 4, BigDecimal.ROUND_HALF_UP)
.multiply(new BigDecimal("100.00"));
practicePO.setCorrectRate(correctRate);
PracticePO po = practiceDao.selectById(practiceId);
if (Objects.isNull(po)) {
practiceDao.insert(practicePO);
} else {
practicePO.setId(practiceId);
practiceDao.update(practicePO);
}
practiceSetDao.updateHeat(setId);
//补充剩余题目的记录
List<PracticeDetailPO> practiceDetailPOList = practiceDetailDao.selectByPracticeId(practiceId);
List<PracticeSetDetailPO> minusList = practiceSetDetailPOS.stream()
.filter(item -> !practiceDetailPOList.stream()
.map(e -> e.getSubjectId())
.collect(Collectors.toList())
.contains(item.getSubjectId()))
.collect(Collectors.toList());
if (log.isInfoEnabled()) {
log.info("题目差集{}", JSON.toJSONString(minusList));
}
if (CollectionUtils.isNotEmpty(minusList)) {
minusList.forEach(e -> {
PracticeDetailPO practiceDetailPO = new PracticeDetailPO();
practiceDetailPO.setPracticeId(practiceId);
practiceDetailPO.setSubjectType(e.getSubjectType());
practiceDetailPO.setSubjectId(e.getSubjectId());
practiceDetailPO.setAnswerStatus(0);
practiceDetailPO.setAnswerContent("");
practiceDetailPO.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
practiceDetailPO.setCreatedTime(new Date());
practiceDetailPO.setCreatedBy(LoginUtil.getLoginId());
practiceDetailDao.insertSingle(practiceDetailPO);
});
}
return true;
}
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean submitSubject(SubmitSubjectDetailReq req) {
String timeUse = req.getTimeUse();
if (timeUse.equals("0")) {
timeUse = "000000";
}
String hour = timeUse.substring(0, 2);
String minute = timeUse.substring(2, 4);
String second = timeUse.substring(4, 6);
PracticePO practicePO = new PracticePO();
practicePO.setId(req.getPracticeId());
practicePO.setTimeUse(hour + ":" + minute + ":" + second);
practicePO.setSubmitTime(new Date());
practiceDao.update(practicePO);
PracticeDetailPO practiceDetailPO = new PracticeDetailPO();
practiceDetailPO.setPracticeId(req.getPracticeId());
practiceDetailPO.setSubjectId(req.getSubjectId());
practiceDetailPO.setSubjectType(req.getSubjectType());
String answerContent = "";
//排序答案
if (CollectionUtils.isNotEmpty(req.getAnswerContents())) {
List<Integer> answerContents = req.getAnswerContents();
Collections.sort(answerContents);
answerContent = StringUtils.join(answerContents, ",");
}
practiceDetailPO.setAnswerContent(answerContent);
SubjectDTO subjectDTO = new SubjectDTO();
subjectDTO.setSubjectId(req.getSubjectId());
subjectDTO.setSubjectType(req.getSubjectType());
//获取正确答案,并判断答案是否正确
SubjectDetailDTO subjectDetail = getSubjectDetail(subjectDTO);
StringBuffer correctAnswer = new StringBuffer();
if (req.getSubjectType().equals(SubjectInfoTypeEnum.JUDGE.getCode())) {
Integer isCorrect = subjectDetail.getIsCorrect();
correctAnswer.append(isCorrect);
} else {
subjectDetail.getOptionList().forEach(e -> {
if (Objects.equals(e.getIsCorrect(), 1)) {
correctAnswer.append(e.getOptionType()).append(",");
}
});
if (correctAnswer.length() > 0) {
correctAnswer.deleteCharAt(correctAnswer.length() - 1);
}
}
if (Objects.equals(correctAnswer.toString(), answerContent)) {
practiceDetailPO.setAnswerStatus(1);
} else {
practiceDetailPO.setAnswerStatus(0);
}
practiceDetailPO.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
practiceDetailPO.setCreatedBy(LoginUtil.getLoginId());
practiceDetailPO.setCreatedTime(new Date());
PracticeDetailPO existDetail = practiceDetailDao.selectDetail(req.getPracticeId(), req.getSubjectId(), LoginUtil.getLoginId());
if (Objects.isNull(existDetail)) {
practiceDetailDao.insertSingle(practiceDetailPO);
} else {
practiceDetailPO.setId(existDetail.getId());
practiceDetailDao.update(practiceDetailPO);
}
return true;
}
public SubjectDetailDTO getSubjectDetail(SubjectDTO dto) {
SubjectDetailD
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
该项目是一款基于Java语言的sa-club上岸俱乐部设计源码,总文件量为366个,其中包含296个Java源文件、55个XML配置文件、11个YML配置文件、2个Markdown文档、1个Git忽略文件和1个LICENSE文件。该系统旨在为上岸俱乐部提供支持,功能完善,代码结构清晰,适用于相关领域的开发和应用。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java语言的sa-club上岸俱乐部设计源码 (365个子文件)
.gitignore 417B
PracticeDetailServiceImpl.java 18KB
PracticeSetServiceImpl.java 16KB
EsRestClient.java 14KB
SubjectInfoDomainServiceImpl.java 9KB
PracticeDetailController.java 8KB
SubjectCategoryController.java 8KB
SubjectEsServiceImpl.java 8KB
PracticeSetController.java 7KB
UserInfoDomainServiceImpl.java 7KB
SubjectCategoryDomainServiceImpl.java 7KB
SubjectController.java 6KB
SubjectLikedDomainServiceImpl.java 6KB
UserController.java 6KB
MybatisPlusAllSqlLog.java 5KB
MybatisPlusAllSqlLog.java 5KB
MybatisInterceptor.java 5KB
MybatisInterceptor.java 5KB
SubjectLabelController.java 5KB
SubjectLabelDomainServiceImpl.java 5KB
PermissionInfoDomainServiceImpl.java 4KB
PermissionController.java 4KB
RedisUtil.java 4KB
RoleController.java 3KB
SubjectLikedController.java 3KB
MinioUtil.java 3KB
IdWorkerUtil.java 3KB
RedisUtil.java 3KB
RedisUtil.java 3KB
RedisUtil.java 3KB
RedisUtil.java 3KB
WXController.java 3KB
SubjectInfoDao.java 2KB
SubjectInfoServiceImpl.java 2KB
JudgeTypeHandler.java 2KB
AuthRolePermissionServiceImpl.java 2KB
ReceiveTextMessageHandler.java 2KB
SubjectLikedServiceImpl.java 2KB
MultipleTypeHandler.java 2KB
RedisConfig.java 2KB
RadioTypeHandler.java 2KB
SubjectMappingServiceImpl.java 2KB
AuthRolePermissionDao.java 2KB
RedisConfig.java 2KB
RedisConfig.java 2KB
RedisConfig.java 2KB
RedisConfig.java 2KB
RolePermissionController.java 2KB
SubjectMultipleServiceImpl.java 2KB
MinioStorageAdapter.java 2KB
GlobalConfig.java 2KB
RoleInfoDomainServiceImpl.java 2KB
SubjectRadioServiceImpl.java 2KB
GatewayExceptionHandler.java 2KB
SubjectMappingDao.java 2KB
SubjectJudgeServiceImpl.java 2KB
SubjectBriefServiceImpl.java 2KB
SubjectCategoryDao.java 2KB
SubjectLikedDao.java 2KB
SubjectLabelServiceImpl.java 2KB
AuthPermissionDao.java 2KB
SubjectCategoryServiceImpl.java 2KB
BriefTypeHandler.java 2KB
SubjectLabelDao.java 2KB
AuthUserRoleDao.java 2KB
Result.java 2KB
SubjectMultipleDao.java 2KB
SqlStatementInterceptor.java 2KB
SqlStatementInterceptor.java 2KB
SubjectRadioDao.java 2KB
GlobalConfig.java 2KB
SubjectJudgeDao.java 2KB
SubjectBriefDao.java 2KB
AuthPermissionServiceImpl.java 2KB
AuthUserRoleServiceImpl.java 2KB
SubjectInfoDTO.java 2KB
AuthRoleDao.java 2KB
GlobalConfig.java 2KB
AuthRoleServiceImpl.java 2KB
XxlJobConfig.java 2KB
SubjectInfoBO.java 2KB
AuthUserDao.java 2KB
DruidEncryptUtil.java 2KB
AuthUserServiceImpl.java 2KB
AuthRolePermissionDomainServiceImpl.java 2KB
SHA1.java 2KB
AuthRolePermissionService.java 1KB
StpInterfaceImpl.java 1KB
Result.java 1KB
SubjectInfoService.java 1KB
SubjectMappingService.java 1KB
MessageUtil.java 1KB
CustomNameThreadFactory.java 1KB
PageResult.java 1KB
Result.java 1KB
TestController.java 1KB
SaTokenConfigure.java 1KB
LoginFilter.java 1KB
PracticeDetailDao.java 1KB
SubjectLikedService.java 1KB
共 365 条
- 1
- 2
- 3
- 4
资源评论
csbysj2020
- 粉丝: 2752
- 资源: 5563
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 自考02197概率论与数理统计(二)试卷及答案解释2016-2021
- java毕设项目之游戏分享网站lw(完整前后端+说明文档+mysql).zip
- java毕设项目之ssm助学贷款+jsp(完整前后端+说明文档+mysql+lw).zip
- IBM Instana应用性能监视.pptx
- webview+H5来实现的android短视频(短剧)音视频播放依赖控件资源
- 黑马最新Hive存储压缩与优化课程总结
- 商城系统项目源代码全套技术资料.zip
- 番茄图像目标检测数据【已标注,约4,300张数据,YOLO 标注格式】
- 校园生活相关项目源代码全套技术资料.zip
- C语言上机实验_1.pptx
- 基于遗传算法求解TSP问题的研究 50个样本点
- 基于XGBoost的振动数据预警模型与参数优化技术-构建一个基于XGBoost的振动信息数据集预警模型 首先引入算法实现动态阈值设置,然后进行参数优化
- sublimeText 4
- 西红柿叶片缺陷分类数据集【已标注,约500张数据】
- 自考00023《高等数学(工本)》试题及答案及复习资料
- 智能点阵笔项目源代码全套技术资料.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功