package com.ruoyi.study.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.exception.GlobalException;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.goods.api.feignClient.GoodsClient;
import com.ruoyi.goods.api.model.TGoodsVO;
import com.ruoyi.management.api.feignClient.ManagementClient;
import com.ruoyi.management.api.model.TSysSet;
import com.ruoyi.study.domain.*;
import com.ruoyi.study.dto.*;
import com.ruoyi.study.service.*;
import com.ruoyi.study.vo.*;
import com.ruoyi.system.api.model.LoginUserParent;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
/**
*
* 学习类型前端控制器
*
*
* @author 无关风月
* @since 2024-04-26
*/
@RestController
@RequestMapping("/base/study")
@Api(tags = "学习端-主接口")
public class TStudyController {
@Autowired
private ITStudyAnswerService studyAnswerService;
@Autowired
private ITStudyInductionService studyInductionService;
@Autowired
private ITStudyLookService studyLookService;
@Autowired
private ITStudyListenService studyListenService;
@Autowired
private ITStudyPairService studyPairService;
@Autowired
private ITGameService gameService;
@Autowired
private ITStoryListenService storyListenService;
@Autowired
private ITSubjectService subjectService;
@Autowired
private ITStoryService storyService;
@Autowired
private ITStudyService studyService;
@Resource
private GoodsClient goodsClient;
@Resource
private ITGameRecordService gameRecordService;
@Resource
private ITUserStudyService userStudyService;
@Resource
private ITIntegralRecordService integralRecordService;
@Resource
private ITUserService userService;
@Resource
private TokenService tokenService;
@Resource
private ITSubjectRecordService subjectRecordService;
@Resource
private IUserStudyRecordService studyRecordService;
@Resource
private ManagementClient managementClient;
@PostMapping("/storyList")
// @ApiOperation(value = "配置学习类型选择故事", tags = {"题目管理"})
public R> storyList(@RequestBody ChoiceStory query) {
PageInfo res = new PageInfo<>(query.getPageNumber(), query.getPageSize());
QueryWrapper wrapper = new QueryWrapper<>();
if (StringUtils.hasLength(query.getName())) {
wrapper.like("name", query.getName());
}
if (StringUtils.hasLength(query.getEnglish())) {
wrapper.like("english", query.getEnglish());
}
if (StringUtils.hasLength(query.getType())) {
wrapper.like("type", query.getType());
}
wrapper.eq("state", 1);
switch (query.getStoryType()) {
case 2:
List list = storyService.list(wrapper);
List tSubjects = new ArrayList<>();
for (TStory tSubject : list) {
if (!tSubject.getError().isEmpty()) {
tSubjects.add(tSubject);
}
}
res.setRecords(tSubjects);
res.setTotal(tSubjects.size());
return R.ok(res);
case 1:
// 查询出error字段不为空的数据
wrapper.isNotNull("error");
List list1 = storyService.list(wrapper);
res.setRecords(list1);
res.setTotal(list1.size());
return R.ok(res);
}
List objects = new ArrayList<>();
res.setRecords(objects);
res.setTotal(0);
return R.ok(res);
}
@PostMapping("/subjectList")
// @ApiOperation(value = "配置学习类型选择题目", tags = {"题目管理"})
public R> subjectList(@RequestBody ChoiceSubject query) {
PageInfo res = new PageInfo<>(query.getPageNumber(), query.getPageSize());
QueryWrapper wrapper = new QueryWrapper<>();
if (StringUtils.hasLength(query.getName())) {
wrapper.like("name", query.getName());
}
if (StringUtils.hasLength(query.getEnglish())) {
wrapper.like("english", query.getEnglish());
}
if (StringUtils.hasLength(query.getType())) {
wrapper.like("type", query.getType());
}
wrapper.eq("state", 1);
switch (query.getStudyType()) {
case 1:
List list = subjectService.list(wrapper);
res.setRecords(list);
res.setTotal(list.size());
return R.ok(res);
case 2:
// 查询出error字段不为空的数据
wrapper.isNotNull("error");
List list1 = subjectService.list(wrapper);
List tSubjects = new ArrayList<>();
for (TSubject tSubject : list1) {
if (!tSubject.getError().isEmpty()) {
tSubjects.add(tSubject);
}
}
res.setRecords(tSubjects);
res.setTotal(tSubjects.size());
return R.ok(res);
case 3:
List list2 = subjectService.list(wrapper);
res.setRecords(list2);
res.setTotal(list2.size());
return R.ok(res);
case 4:
// 查询出error字段不为空的数据
wrapper.isNotNull("error");
List list3 = subjectService.list(wrapper);
List tSubjects3 = new ArrayList<>();
for (TSubject tSubject : list3) {
if (!tSubject.getError().isEmpty()) {
tSubjects3.add(tSubject);
}
}
res.setRecords(tSubjects3);
res.setTotal(tSubjects3.size());
return R.ok(res);
case 5:
List list4 = subjectService.list(wrapper);
res.setRecords(list4);
res.setTotal(list4.size());
return R.ok(res);
}
List objects = new ArrayList<>();
res.setRecords(objects);
res.setTotal(0);
return R.ok(res);
}
/**
* 添加学习配置
*
* @param dto
* @return
*/
@PostMapping("/addStudySet")
public R