无关风月
2024-12-31 52461f1688e83970d4aa3aa6b835bdf7719f5769
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
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;
 
/**
 * <p>
 * 题目管理 前端控制器
 * </p>
 *
 * @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<PageInfo<SubjectVO>> subjectList(@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, 1)
                    .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, 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<SubjectVO> 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<Object> week = getObjectR(dto.getId());
//        if (week != null) return week;
        BeanUtils.copyProperties(dto,tSubject);
        subjectService.updateById(tSubject);
        return R.ok("编辑成功");
    }
 
    private R<Object> getObjectR(Integer id) {
        List<TStudyListen> list = studyListenService.list();
        List<TStudyLook> list1 = studyLookService.list();
        List<TStudyInduction> list2 = studyInductionService.list();
        List<TStudyAnswer> list3 = studyAnswerService.list();
        List<TStudyPair> 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<SubjectDTO> 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<Object> week = getObjectR(id);
            if (week != null) return week;
        }
        if (state == 3){
            R<Object> 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("编辑成功");
    }
}