package com.ruoyi.study.controller;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.study.domain.*;
import com.ruoyi.study.dto.StoryDTO;
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/tStory")
public class TStoryController {
@Autowired
private ITStoryListenService storyListenService;
@Autowired
private ITStoryService service;
@Autowired
private ICategoryService categoryService;
@PostMapping("/storyList")
public R> storyList(@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, 2)
.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, 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 list = service.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;
// }
// }
// 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 = {"故事管理"})
public R add(@RequestBody StoryDTO dto) {
TStory tSubject = new TStory();
BeanUtils.copyProperties(dto,tSubject);
service.save(tSubject);
return R.ok("添加成功");
}
@PostMapping("/update")
// @ApiOperation(value = "编辑", tags = {"故事管理"})
public R update(@RequestBody StoryDTO dto) {
TStory tSubject = new TStory();
// R