|
|
|
@ -1,7 +1,10 @@ |
|
|
|
package org.jeecg.modules.applet.service.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
import org.jeecg.common.system.util.AppletUserUtil; |
|
|
|
import org.jeecg.common.system.vo.AppletUser; |
|
|
|
import org.jeecg.modules.applet.contains.AppletQuestionContains; |
|
|
|
import org.jeecg.modules.applet.service.AppletApiPaperService; |
|
|
|
import org.jeecg.modules.demo.appletPaper.entity.AppletPaper; |
|
|
|
import org.jeecg.modules.demo.appletPaper.entity.AppletQuestions; |
|
|
|
@ -15,6 +18,8 @@ import org.jeecg.modules.demo.appletPaperReport.entity.AppletPaperReport; |
|
|
|
import org.jeecg.modules.demo.appletPaperReport.entity.AppletPaperReportItem; |
|
|
|
import org.jeecg.modules.demo.appletPaperReport.service.IAppletPaperReportItemService; |
|
|
|
import org.jeecg.modules.demo.appletPaperReport.service.IAppletPaperReportService; |
|
|
|
import org.jeecg.modules.demo.appletProductSpec.entity.AppletProductSpec; |
|
|
|
import org.jeecg.modules.demo.appletProductSpec.service.IAppletProductSpecService; |
|
|
|
import org.jeecg.modules.demo.appletScheme.service.IAppletSchemeService; |
|
|
|
import org.jeecg.modules.demo.appletSchemeCategory.service.IAppletSchemeCategoryService; |
|
|
|
import org.jeecg.modules.demo.appletProduct.entity.AppletProduct; |
|
|
|
@ -63,18 +68,32 @@ public class AppletApiPaperServiceImpl implements AppletApiPaperService { |
|
|
|
private IAppletProductService appletProductService; |
|
|
|
@Autowired |
|
|
|
private ObjectMapper objectMapper; |
|
|
|
@Autowired |
|
|
|
private IAppletProductSpecService appletProductSpecService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public IPage<AppletPaper> list(Page<AppletPaper> page, String type) { |
|
|
|
String userId = AppletUserUtil.getCurrentAppletUserId(); |
|
|
|
|
|
|
|
String userId = null; |
|
|
|
|
|
|
|
AppletUser user = AppletUserUtil.getAppletUserFromRequest(); |
|
|
|
if (user != null){ |
|
|
|
userId = user.getId(); |
|
|
|
} |
|
|
|
|
|
|
|
// 查询当前用户已答题过的试卷ID列表 |
|
|
|
List<String> answeredPaperIds = appletPaperReportService.lambdaQuery() |
|
|
|
.eq(AppletPaperReport::getUserId, userId) |
|
|
|
.list() |
|
|
|
.stream() |
|
|
|
.map(AppletPaperReport::getPaperId) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
List<String> answeredPaperIds = new ArrayList<>(); |
|
|
|
|
|
|
|
if(StringUtils.isNotBlank(userId)){ |
|
|
|
answeredPaperIds = appletPaperReportService.lambdaQuery() |
|
|
|
.eq(AppletPaperReport::getUserId, userId) |
|
|
|
.eq(AppletPaperReport::getStatus, "1") |
|
|
|
.list() |
|
|
|
.stream() |
|
|
|
.map(AppletPaperReport::getPaperId) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
} |
|
|
|
|
|
|
|
LambdaQueryWrapper<AppletPaper> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
|
|
|
@ -92,8 +111,27 @@ public class AppletApiPaperServiceImpl implements AppletApiPaperService { |
|
|
|
} |
|
|
|
} |
|
|
|
// 如果type为空或其他值,查询所有试卷(不过滤) |
|
|
|
|
|
|
|
return appletPaperService.page(page, queryWrapper); |
|
|
|
|
|
|
|
Page<AppletPaper> page1 = appletPaperService.page(page, queryWrapper); |
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(userId)){ |
|
|
|
for (AppletPaper record : page1.getRecords()) { |
|
|
|
record.setReports(appletPaperReportService |
|
|
|
.lambdaQuery() |
|
|
|
.last("limit 2") |
|
|
|
.orderByDesc(AppletPaperReport::getCreateTime) |
|
|
|
.eq(AppletPaperReport::getPaperId, record.getId()) |
|
|
|
.eq(AppletPaperReport::getUserId, userId) |
|
|
|
.select( |
|
|
|
AppletPaperReport::getId, |
|
|
|
AppletPaperReport::getScore, |
|
|
|
AppletPaperReport::getCreateTime |
|
|
|
) |
|
|
|
.list()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return page1; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@ -104,6 +142,7 @@ public class AppletApiPaperServiceImpl implements AppletApiPaperService { |
|
|
|
.eq(AppletPaperReport::getPaperId, id) |
|
|
|
.eq(AppletPaperReport::getUserId, userId) |
|
|
|
.eq(AppletPaperReport::getStatus, "1") |
|
|
|
.orderByDesc(AppletPaperReport::getCreateTime) |
|
|
|
.list(); |
|
|
|
return list; |
|
|
|
} |
|
|
|
@ -132,6 +171,9 @@ public class AppletApiPaperServiceImpl implements AppletApiPaperService { |
|
|
|
if (!productId.isEmpty()) { |
|
|
|
AppletProduct product = appletProductService.getById(productId); |
|
|
|
if (product != null) { |
|
|
|
product.setSpecs(appletProductSpecService.lambdaQuery() |
|
|
|
.eq(AppletProductSpec::getProductId, product.getId()) |
|
|
|
.last("limit 1").list()); |
|
|
|
productList.add(product); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -234,32 +276,35 @@ public class AppletApiPaperServiceImpl implements AppletApiPaperService { |
|
|
|
// 如果是选择题,需要获取选项的商品和方案信息 |
|
|
|
String productId = null; |
|
|
|
String schemeId = null; |
|
|
|
|
|
|
|
if (answer != null && !answer.trim().isEmpty()) { |
|
|
|
// 解析答案(可能是多个选项ID,用逗号分隔) |
|
|
|
String[] optionIds = answer.split(","); |
|
|
|
List<String> productIds = new ArrayList<>(); |
|
|
|
List<String> schemeIds = new ArrayList<>(); |
|
|
|
|
|
|
|
for (String optionId : optionIds) { |
|
|
|
optionId = optionId.trim(); |
|
|
|
if (!optionId.isEmpty()) { |
|
|
|
AppletQuestionsOptions option = appletQuestionsOptionsService.getById(optionId); |
|
|
|
if (option != null) { |
|
|
|
if (option.getProductId() != null && !option.getProductId().trim().isEmpty()) { |
|
|
|
productIds.add(option.getProductId()); |
|
|
|
} |
|
|
|
if (option.getSchemeId() != null && !option.getSchemeId().trim().isEmpty()) { |
|
|
|
schemeIds.add(option.getSchemeId()); |
|
|
|
|
|
|
|
if (answer != null && !answer.trim().isEmpty()){ |
|
|
|
if (AppletQuestionContains.CHOOSE.contains(questions.getType())) { |
|
|
|
// 解析答案(可能是多个选项ID,用逗号分隔) |
|
|
|
String[] optionIds = answer.split(","); |
|
|
|
List<String> productIds = new ArrayList<>(); |
|
|
|
List<String> schemeIds = new ArrayList<>(); |
|
|
|
|
|
|
|
for (String optionId : optionIds) { |
|
|
|
optionId = optionId.trim(); |
|
|
|
if (!optionId.isEmpty()) { |
|
|
|
AppletQuestionsOptions option = appletQuestionsOptionsService.getById(optionId); |
|
|
|
if (option != null) { |
|
|
|
if (option.getProductId() != null && !option.getProductId().trim().isEmpty()) { |
|
|
|
productIds.add(option.getProductId()); |
|
|
|
} |
|
|
|
if (option.getSchemeId() != null && !option.getSchemeId().trim().isEmpty()) { |
|
|
|
schemeIds.add(option.getSchemeId()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 合并商品ID和方案ID |
|
|
|
productId = productIds.isEmpty() ? null : String.join(",", productIds); |
|
|
|
schemeId = schemeIds.isEmpty() ? null : String.join(",", schemeIds); |
|
|
|
} |
|
|
|
|
|
|
|
// 合并商品ID和方案ID |
|
|
|
productId = productIds.isEmpty() ? null : String.join(",", productIds); |
|
|
|
schemeId = schemeIds.isEmpty() ? null : String.join(",", schemeIds); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (existingItem != null) { |
|
|
|
// 更新现有记录 |
|
|
|
@ -358,6 +403,47 @@ public class AppletApiPaperServiceImpl implements AppletApiPaperService { |
|
|
|
appletPaperReportService.updateById(report); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<AppletPaperReport> recentReport() { |
|
|
|
String userId = AppletUserUtil.getCurrentAppletUserId(); |
|
|
|
|
|
|
|
List<AppletPaperReport> list = appletPaperReportService |
|
|
|
.lambdaQuery() |
|
|
|
.orderByDesc(AppletPaperReport::getCreateTime) |
|
|
|
.eq(AppletPaperReport::getUserId, userId) |
|
|
|
.last("limit 1") |
|
|
|
.select( |
|
|
|
AppletPaperReport::getId, |
|
|
|
AppletPaperReport::getCreateTime, |
|
|
|
AppletPaperReport::getPaperId, |
|
|
|
AppletPaperReport::getScore |
|
|
|
) |
|
|
|
.list(); |
|
|
|
|
|
|
|
if (list.isEmpty()){ |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
AppletPaperReport one = appletPaperReportService |
|
|
|
.lambdaQuery() |
|
|
|
.orderByDesc(AppletPaperReport::getCreateTime) |
|
|
|
.eq(AppletPaperReport::getUserId, userId) |
|
|
|
.eq(AppletPaperReport::getPaperId, list.get(0).getPaperId()) |
|
|
|
.ne(AppletPaperReport::getId, list.get(0).getId()) |
|
|
|
.last("limit 1") |
|
|
|
.select( |
|
|
|
AppletPaperReport::getId, |
|
|
|
AppletPaperReport::getCreateTime, |
|
|
|
AppletPaperReport::getPaperId, |
|
|
|
AppletPaperReport::getScore |
|
|
|
) |
|
|
|
.one(); |
|
|
|
|
|
|
|
list.add(one); |
|
|
|
|
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 组合方案数据 |
|
|
|
* @param schemeIds 方案ID列表,逗号分隔 |
|
|
|
|