package com.ruoyi.study.controller; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.web.page.PageInfo; import com.ruoyi.management.api.feignClient.ManagementClient; import com.ruoyi.study.domain.*; import com.ruoyi.study.dto.SubjectDTO; import com.ruoyi.study.dto.SubjectQuery; import com.ruoyi.study.service.*; import com.ruoyi.study.vo.SubjectVO; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; /** *

* 题目管理 前端控制器 *

* * @author 无关风月 * @since 2024-04-26 */ @RestController @RequestMapping("/base/tSubject") public class TSubjectController { @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; @Autowired private ICategoryService categoryService; @PostMapping("/subjectList") @ApiOperation(value = "列表查询", tags = {"题目管理"}) public R> subjectList(@RequestBody SubjectQuery query) { PageInfo res = new PageInfo<>(query.getPageNumber(), query.getPageSize()); List integers = new ArrayList<>(); if (StringUtils.hasLength(query.getCategoryName())){ List collect = categoryService.lambdaQuery() .eq(TCategory::getType, 2) .eq(TCategory::getState, 1) .like(TCategory::getName, query.getCategoryName()) .list().stream().map(TCategory::getParentId).collect(Collectors.toList()); integers.addAll(collect); List collect2 = categoryService.lambdaQuery() .eq(TCategory::getType, 1) .eq(TCategory::getState, 1) .like(TCategory::getName, query.getCategoryName()) .list().stream().map(TCategory::getId).collect(Collectors.toList()); integers.addAll(collect2); } if (StringUtils.hasLength(query.getCategoryName())){ if (integers.isEmpty()){ integers.add(-1); } } query.setIds(integers); List list = subjectService.listAll(query); for (SubjectVO subjectVO : list) { if (subjectVO.getFirstCategory()!=null&&subjectVO.getSecondCategory()!=null){ TCategory byId1 = categoryService.getById(subjectVO.getFirstCategory()); TCategory byId2 = categoryService.getById(subjectVO.getSecondCategory()); if (byId1!=null&& byId2!=null){ subjectVO.setCategoryName(byId1.getName()+"-"+byId2.getName()); } } // StringBuilder stringBuilder = new StringBuilder(""); // for (String s : subjectVO.getType().split(",")) { // switch (s) { // case "1": // stringBuilder.append("自主学习一、"); // break; // case "2": // stringBuilder.append("自主学习二、"); // break; // case "3": // stringBuilder.append("自主学习三、"); // break; // case "4": // stringBuilder.append("自主学习四、"); // break; // case "5": // stringBuilder.append("自主学习五、"); // break; // } // } // String string = stringBuilder.toString(); // String substring = string.substring(0, string.length() - 1); subjectVO.setType(subjectVO.getType()); } res.setRecords(list); res.setTotal(list.size()); return R.ok(res); } @PostMapping("/add") @ApiOperation(value = "添加", tags = {"题目管理"}) public R add(@RequestBody SubjectDTO dto) { TSubject tSubject = new TSubject(); BeanUtils.copyProperties(dto,tSubject); subjectService.save(tSubject); return R.ok("添加成功"); } @PostMapping("/update") @ApiOperation(value = "编辑", tags = {"题目管理"}) public R update(@RequestBody SubjectDTO dto) { TSubject tSubject = new TSubject(); // 判断当前题目有没有被使用 // R week = getObjectR(dto.getId()); // if (week != null) return week; BeanUtils.copyProperties(dto,tSubject); subjectService.updateById(tSubject); return R.ok("编辑成功"); } private R getObjectR(Integer id) { List list = studyListenService.list(); List list1 = studyLookService.list(); List list2 = studyInductionService.list(); List list3 = studyAnswerService.list(); List list4 = studyPairService.list(); if (!list.isEmpty()) { for (TStudyListen tStudyListen : list) { String[] split = tStudyListen.getSubject().split(","); for (String s : split) { if (s.equals(String.valueOf(id))) { Integer week = tStudyListen.getWeek(); Integer day = tStudyListen.getDay(); return R.failUpdate("操作失败,当前题目在" + "周目" + week + "、" + "day" + day + "、" + "听音选图中使用"); } } } } if (!list1.isEmpty()) { for (TStudyLook tStudyListen : list1) { String[] split = tStudyListen.getSubject().split(","); for (String s : split) { if (s.equals(String.valueOf(id))) { Integer week = tStudyListen.getWeek(); Integer day = tStudyListen.getDay(); return R.failUpdate("操作失败,当前题目在" + "周目" + week + "、" + "day" + day + "、" + "看图选音中使用"); } } } } if (!list2.isEmpty()) { for (TStudyInduction tStudyListen : list2) { String[] split = tStudyListen.getSubject().split(","); for (String s : split) { if (s.equals(String.valueOf(id))) { Integer week = tStudyListen.getWeek(); Integer day = tStudyListen.getDay(); return R.failUpdate("操作失败,当前题目在" + "周目" + week + "、" + "day" + day + "、" + "归纳排除中使用"); } } } } if (!list3.isEmpty()) { for (TStudyAnswer tStudyListen : list3) { Integer subject = tStudyListen.getSubject(); Integer answerSubject = tStudyListen.getAnswerSubject(); if (subject.equals(id) || answerSubject.equals(id)) { Integer week = tStudyListen.getWeek(); Integer day = tStudyListen.getDay(); return R.failUpdate("操作失败,当前题目在" + "周目" + week + "、" + "day" + day + "、" + "有问有答中使用"); } } } if (!list4.isEmpty()) { for (TStudyPair tStudyListen : list4) { String[] split = tStudyListen.getSubject().split(","); for (String s : split) { if (s.equals(String.valueOf(id))) { Integer week = tStudyListen.getWeek(); Integer day = tStudyListen.getDay(); return R.failUpdate("操作失败,当前题目在" + "周目" + week + "、" + "day" + day + "、" + "音图相配中使用"); } } } } return null; } @PostMapping("/getInfo") // @ApiOperation(value = "查看详情", tags = {"题目管理"}) public R getInfo(@RequestParam("id") Integer id) { TSubject byId = subjectService.getById(id); SubjectDTO subjectDTO = new SubjectDTO(); BeanUtils.copyProperties(byId,subjectDTO); return R.ok(subjectDTO); } @PostMapping("/updateState/{id}/{state}") // @ApiOperation(value = "修改状态", tags = {"题目管理"}) @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "题目id", required = true), @ApiImplicitParam(name = "state", value = "1上架2下架3删除", required = true), }) public R updateState(@PathVariable("id") Integer id,@PathVariable("state") Integer state) { if (state == 2){ R week = getObjectR(id); if (week != null) return week; } if (state == 3){ R week = getObjectR(id); if (week != null) return week; } TSubject byId = subjectService.getById(id); byId.setState(state); subjectService.updateById(byId); if (state == 3){ subjectService.removeById(byId); } return R.ok("编辑成功"); } }