无关风月
2024-07-01 4712c04afe2aedeed20ddc5b1a3b0ba66b89cb9b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * <p>
 * 故事管理 前端控制器
 * </p>
 *
 * @author 无关风月
 * @since 2024-04-26
 */
@RestController
@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;
    @PostMapping("/storyList")
//    @ApiOperation(value = "列表查询", tags = {"故事管理"})
    public R<PageInfo<SubjectVO>> storyList(@RequestBody SubjectQuery query) {
        PageInfo<SubjectVO> res = new PageInfo<>(query.getPageNumber(), query.getPageSize());
        List<SubjectVO> list =  service.listAll(query);
//        for (SubjectVO subjectVO : list) {
//            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<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 = {"故事管理"})
    public R<StoryDTO> getInfo1(@RequestParam("id") Integer id) {
        TStory byId = service.getById(id);
        StoryDTO subjectDTO = new StoryDTO();
        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 updateState1(@PathVariable("id") Integer id,@PathVariable("state")Integer state) {
        if (state == 2){
            R<Object> week = getObjectR(id);
            if (week != null) return week;
            // 判断当前故事有没有被使用
        }
        if (state == 3){
            R<Object> week = getObjectR(id);
            if (week != null) return week;
            // 判断当前故事有没有被使用
        }
        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) {
        List<TStoryListen> list = storyListenService.list();
        if (!list.isEmpty()) {
            for (TStoryListen tStudyListen : list) {
                String[] split = tStudyListen.getStory().split(",");
                String[] split1 = tStudyListen.getLookStory().split(",");
                for (String s : split) {
                    if (s.equals(String.valueOf(id))) {
                        Integer week = tStudyListen.getWeek();
                        return R.failUpdate("操作失败,当前题目在" + "周目" + week + "、" + "听故事"  + "、" + "框架记忆中使用");
                    }
                }
                for (String s : split1) {
                    if (s.equals(String.valueOf(id))) {
                        Integer week = tStudyListen.getWeek();
                        return R.failUpdate("操作失败,当前题目在" + "周目" + week + "、" + "听故事"  + "、" + "看图配音中使用");
                    }
                }
            }
        }
        return null;
    }
}