| | |
| | | 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; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @RequestMapping("/base/tStory") |
| | | public class TStoryController { |
| | | @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 ITStoryService service; |
| | | |
| | | @Autowired |
| | | private ICategoryService categoryService; |
| | | @PostMapping("/storyList") |
| | | @ApiOperation(value = "列表查询", tags = {"故事管理"}) |
| | | public R<PageInfo<SubjectVO>> storyList(@RequestBody SubjectQuery query) { |
| | | PageInfo<SubjectVO> res = new PageInfo<>(query.getPageNumber(), query.getPageSize()); |
| | | List<Integer> integers = new ArrayList<>(); |
| | | if (StringUtils.hasLength(query.getCategoryName())){ |
| | | List<Integer> collect = categoryService.lambdaQuery() |
| | | .eq(TCategory::getType, 2) |
| | | .eq(TCategory::getState, 2) |
| | | .like(TCategory::getName, query.getCategoryName()) |
| | | .list().stream().map(TCategory::getParentId).collect(Collectors.toList()); |
| | | integers.addAll(collect); |
| | | List<Integer> collect2 = categoryService.lambdaQuery() |
| | | .eq(TCategory::getType, 1) |
| | | .eq(TCategory::getState, 2) |
| | | .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<SubjectVO> list = service.listAll(query); |
| | | // for (SubjectVO subjectVO : list) { |
| | | 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) { |
| | |
| | | // String string = stringBuilder.toString(); |
| | | // String substring = string.substring(0, string.length() - 1); |
| | | // subjectVO.setType(substring); |
| | | // } |
| | | } |
| | | res.setRecords(list); |
| | | res.setTotal(list.size()); |
| | | return R.ok(res); |
| | | } |
| | | @PostMapping("/add") |
| | | @ApiOperation(value = "添加", tags = {"故事管理"}) |
| | | // @ApiOperation(value = "添加", tags = {"故事管理"}) |
| | | public R add(@RequestBody StoryDTO dto) { |
| | | TStory tSubject = new TStory(); |
| | | BeanUtils.copyProperties(dto,tSubject); |
| | |
| | | return R.ok("添加成功"); |
| | | } |
| | | @PostMapping("/update") |
| | | @ApiOperation(value = "编辑", tags = {"故事管理"}) |
| | | // @ApiOperation(value = "编辑", tags = {"故事管理"}) |
| | | public R update(@RequestBody StoryDTO dto) { |
| | | TStory tSubject = new TStory(); |
| | | R<Object> week = getObjectR(dto.getId()); |
| | | if (week != null) return week; |
| | | // R<Object> week = getObjectR(dto.getId()); |
| | | // if (week != null) return week; |
| | | BeanUtils.copyProperties(dto,tSubject); |
| | | service.updateById(tSubject); |
| | | return R.ok("编辑成功"); |
| | | } |
| | | @PostMapping("/getInfo") |
| | | @ApiOperation(value = "查看详情", tags = {"故事管理"}) |
| | | // @ApiOperation(value = "查看详情", tags = {"故事管理"}) |
| | | public R<StoryDTO> getInfo1(@RequestParam("id") Integer id) { |
| | | TStory byId = service.getById(id); |
| | | StoryDTO subjectDTO = new StoryDTO(); |
| | |
| | | return R.ok(subjectDTO); |
| | | } |
| | | @PostMapping("/updateState/{id}/{state}") |
| | | @ApiOperation(value = "修改状态", tags = {"故事管理"}) |
| | | // @ApiOperation(value = "修改状态", tags = {"故事管理"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "题目id", required = true), |
| | | @ApiImplicitParam(name = "state", value = "1上架2下架3删除", required = true), |
| | |
| | | TStory byId = service.getById(id); |
| | | byId.setState(state); |
| | | service.updateById(byId); |
| | | if (state == 3){ |
| | | service.removeById(byId); |
| | | } |
| | | return R.ok("成功"); |
| | | } |
| | | private R<Object> getObjectR(Integer id) { |
| | |
| | | for (String s : split) { |
| | | if (s.equals(String.valueOf(id))) { |
| | | Integer week = tStudyListen.getWeek(); |
| | | return R.fail("操作失败,当前题目在" + "周目" + week + "、" + "听故事" + "、" + "框架记忆中使用"); |
| | | return R.failUpdate("操作失败,当前题目在" + "周目" + week + "、" + "听故事" + "、" + "框架记忆中使用"); |
| | | } |
| | | } |
| | | for (String s : split1) { |
| | | if (s.equals(String.valueOf(id))) { |
| | | Integer week = tStudyListen.getWeek(); |
| | | return R.fail("操作失败,当前题目在" + "周目" + week + "、" + "听故事" + "、" + "看图配音中使用"); |
| | | return R.failUpdate("操作失败,当前题目在" + "周目" + week + "、" + "听故事" + "、" + "看图配音中使用"); |
| | | } |
| | | } |
| | | } |