|
@@ -7,6 +7,7 @@ import cn.hutool.extra.tokenizer.Word;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.zhongzheng.common.constant.Constants;
|
|
|
import com.zhongzheng.common.core.domain.entity.SysUser;
|
|
|
import com.zhongzheng.common.core.redis.RedisCache;
|
|
@@ -31,12 +32,21 @@ import com.zhongzheng.modules.exam.bo.ExamKnowledgeAddBo;
|
|
|
import com.zhongzheng.modules.exam.bo.ExamKnowledgeBusinessAddBo;
|
|
|
import com.zhongzheng.modules.exam.domain.ExamKnowledge;
|
|
|
import com.zhongzheng.modules.exam.service.IExamKnowledgeService;
|
|
|
+import com.zhongzheng.modules.goods.bo.BankGoodsExamAddBo;
|
|
|
import com.zhongzheng.modules.goods.bo.GoodsQueryBo;
|
|
|
+import com.zhongzheng.modules.goods.domain.Goods;
|
|
|
+import com.zhongzheng.modules.goods.domain.GoodsExamTime;
|
|
|
+import com.zhongzheng.modules.goods.service.IGoodsExamTimeService;
|
|
|
import com.zhongzheng.modules.goods.service.IGoodsService;
|
|
|
+import com.zhongzheng.modules.goods.vo.BankGoodsExamVo;
|
|
|
+import com.zhongzheng.modules.goods.vo.GoodsExamTimeVo;
|
|
|
import com.zhongzheng.modules.goods.vo.GoodsUserQuestionVo;
|
|
|
|
|
|
import com.zhongzheng.modules.user.bo.CheckUserExamRecordBo;
|
|
|
+import com.zhongzheng.modules.user.bo.UserSpecialExamRecord;
|
|
|
+import com.zhongzheng.modules.user.domain.UserExamRecord;
|
|
|
import com.zhongzheng.modules.user.service.IUserExamRecordService;
|
|
|
+import com.zhongzheng.modules.user.service.IUserSpecialExamRecordService;
|
|
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
|
@@ -50,12 +60,14 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.github.pagehelper.Page;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.unit.DataUnit;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.w3c.dom.NamedNodeMap;
|
|
|
import org.w3c.dom.Node;
|
|
|
import org.w3c.dom.NodeList;
|
|
|
|
|
|
import java.io.*;
|
|
|
+import java.text.NumberFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -98,6 +110,12 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
@Autowired
|
|
|
private IUserExamRecordService iUserExamRecordService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IGoodsExamTimeService goodsExamTimeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IUserSpecialExamRecordService userSpecialExamRecordService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private IGoodsService iGoodsService;
|
|
|
|
|
@@ -1741,6 +1759,90 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
.in(Question::getQuestionId,bo.getIds()));
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<BankGoodsExamVo> getBankGoodsExamList(Long goodsId) {
|
|
|
+ Goods goods = iGoodsService.getById(goodsId);
|
|
|
+ if (ObjectUtils.isNull(goods)){
|
|
|
+ throw new CustomException("商品信息获取失败!");
|
|
|
+ }
|
|
|
+ //获取题库商品的所有试卷
|
|
|
+ List<BankGoodsExamVo> examAllList = baseMapper.getBankGoodsExamList(goodsId);
|
|
|
+ //筛选每日一练试卷
|
|
|
+ List<BankGoodsExamVo> examList = examAllList.stream().filter(item -> item.getPaperName().equals("每日一练")).collect(Collectors.toList());
|
|
|
+ //获取试卷时间
|
|
|
+ examList.forEach(item -> {
|
|
|
+ GoodsExamTime examTime = goodsExamTimeService.getOne(new LambdaQueryWrapper<GoodsExamTime>()
|
|
|
+ .eq(GoodsExamTime::getGoodsId, goodsId)
|
|
|
+ .eq(GoodsExamTime::getModuleExamId, item.getModuleExamId())
|
|
|
+ .eq(GoodsExamTime::getChapterExamId, item.getChapterExamId())
|
|
|
+ .eq(GoodsExamTime::getExamId, item.getExamId())
|
|
|
+ .eq(GoodsExamTime::getStatus, 1));
|
|
|
+ if (ObjectUtils.isNotNull(examTime)){
|
|
|
+ item.setExamTime(examTime.getExamTime());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return examList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean addGoodsExamTime(List<BankGoodsExamAddBo> addBo) {
|
|
|
+ Long goodsId = addBo.get(0).getGoodsId();
|
|
|
+ //先删除之前的时间
|
|
|
+ goodsExamTimeService.remove(new LambdaQueryWrapper<GoodsExamTime>()
|
|
|
+ .eq(GoodsExamTime::getGoodsId,goodsId));
|
|
|
+ //添加新时间
|
|
|
+ List<GoodsExamTime> entitys = addBo.stream().filter(x -> ObjectUtils.isNotNull(x.getExamTime())).map(item -> {
|
|
|
+ GoodsExamTime examTime = BeanUtil.toBean(item, GoodsExamTime.class);
|
|
|
+ examTime.setStatus(1);
|
|
|
+ examTime.setCreateTime(DateUtils.getNowTime());
|
|
|
+ examTime.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return examTime;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return goodsExamTimeService.saveBatch(entitys);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public GoodsExamTimeVo getToDayExam(Long goodsId,Long userId) {
|
|
|
+ Long todayZeroTime = DateUtils.getTodayZeroTime();
|
|
|
+ GoodsExamTime goodsExamTime = goodsExamTimeService.getOne(new LambdaQueryWrapper<GoodsExamTime>()
|
|
|
+ .eq(GoodsExamTime::getGoodsId, goodsId)
|
|
|
+ .eq(GoodsExamTime::getExamTime, todayZeroTime));
|
|
|
+ if (ObjectUtils.isNull(goodsExamTime)){
|
|
|
+ //当天没有设置试卷
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ GoodsExamTimeVo vo = BeanUtil.toBean(goodsExamTime, GoodsExamTimeVo.class);
|
|
|
+ //获取打卡记录
|
|
|
+ List<UserSpecialExamRecord> list = userSpecialExamRecordService.list(new LambdaQueryWrapper<UserSpecialExamRecord>()
|
|
|
+ .eq(UserSpecialExamRecord::getGoodsId, vo.getGoodsId()));
|
|
|
+ if (CollectionUtils.isNotEmpty(list)){
|
|
|
+ //我的累计打卡次数
|
|
|
+ Long recordCount = list.stream().filter(x -> x.getUserId().equals(userId)).count();
|
|
|
+ vo.setRecordCount(recordCount.intValue());
|
|
|
+ //打卡百分比
|
|
|
+ Map<Long, List<UserSpecialExamRecord>> collect = list.stream().collect(Collectors.groupingBy(UserSpecialExamRecord::getUserId));
|
|
|
+ Long count = collect.values().stream().filter(item -> item.size() < recordCount).count();
|
|
|
+ Long countAll = collect.keySet().stream().filter(x -> !x.equals(userId)).count();
|
|
|
+ String percent = getPercent(count.intValue(), countAll.intValue());
|
|
|
+ vo.setRecordPercentage(percent);
|
|
|
+ }else {
|
|
|
+ vo.setRecordCount(0);
|
|
|
+ vo.setRecordPercentage("0.00%");
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getPercent(Integer x,Integer y){
|
|
|
+ Double d1 = x * 1.0;
|
|
|
+ Double d2 = y * 1.0;
|
|
|
+
|
|
|
+ NumberFormat format = NumberFormat.getPercentInstance();
|
|
|
+ format.setMinimumFractionDigits(2);
|
|
|
+ return format.format(d1 / d2);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
private String removeNo(String txt) {
|
|
|
int intIndex = txt.indexOf("、");
|