44323
2024-05-21 781b5fea46cd55220b5ffca17aa6bb1b83551410
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
package com.ruoyi.study.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.*;
import com.ruoyi.study.service.*;
import com.ruoyi.study.vo.*;
import io.swagger.annotations.ApiOperation;
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;
 
/**
 * <p>
 * 学习类型前端控制器
 * </p>
 *
 * @author 无关风月
 * @since 2024-04-26
 */
@RestController
@RequestMapping("/base/study")
public class TStudyController {
    @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;
 
    @PostMapping("/storyList")
    @ApiOperation(value = "配置学习类型选择故事", tags = {"题目管理"})
    public R<PageInfo<TStory>> storyList(@RequestBody ChoiceStory query) {
        PageInfo<TStory> res = new PageInfo<>(query.getPageNumber(), query.getPageSize());
        QueryWrapper<TStory> wrapper = new QueryWrapper<>();
        if (StringUtils.hasLength(query.getName())){
            wrapper.like("name",query.getName());
        }
        if (StringUtils.hasLength(query.getEnglish())){
            wrapper.like("english",query.getEnglish());
        }
        if (StringUtils.hasLength(query.getType())){
            wrapper.like("type",query.getType());
        }
        wrapper.eq("state",1);
        switch (query.getStoryType()){
            case 2:
                List<TStory> list = storyService.list(wrapper);
                res.setRecords(list);
                res.setTotal(list.size());
                return R.ok(res);
            case 1:
                // 查询出error字段不为空的数据
                wrapper.isNotNull("error");
                List<TStory> list1 = storyService.list(wrapper);
                res.setRecords(list1);
                res.setTotal(list1.size());
                return R.ok(res);
 
        }
        List<TStory> objects = new ArrayList<>();
        res.setRecords(objects);
        res.setTotal(0);
        return R.ok(res);
    }
    @PostMapping("/subjectList")
    @ApiOperation(value = "配置学习类型选择题目", tags = {"题目管理"})
    public R<PageInfo<TSubject>> subjectList(@RequestBody ChoiceSubject query) {
        PageInfo<TSubject> res = new PageInfo<>(query.getPageNumber(), query.getPageSize());
        QueryWrapper<TSubject> wrapper = new QueryWrapper<>();
 
        if (StringUtils.hasLength(query.getName())){
            wrapper.like("name",query.getName());
        }
        if (StringUtils.hasLength(query.getEnglish())){
            wrapper.like("english",query.getEnglish());
        }
        if (StringUtils.hasLength(query.getType())){
            wrapper.like("type",query.getType());
        }
        wrapper.eq("state",1);
        switch (query.getStudyType()){
            case 1:
                List<TSubject> list = subjectService.list(wrapper);
                res.setRecords(list);
                res.setTotal(list.size());
                return R.ok(res);
            case 2:
                // 查询出error字段不为空的数据
                wrapper.isNotNull("error");
                List<TSubject> list1 = subjectService.list(wrapper);
                res.setRecords(list1);
                res.setTotal(list1.size());
                return R.ok(res);
            case 3:
                List<TSubject> list2 = subjectService.list(wrapper);
                res.setRecords(list2);
                res.setTotal(list2.size());
                return R.ok(res);
            case 4:
                List<TSubject> list3 = subjectService.list(wrapper);
                res.setRecords(list3);
                res.setTotal(list3.size());
                return R.ok(res);
            case 5:
                List<TSubject> list4 = subjectService.list(wrapper);
                res.setRecords(list4);
                res.setTotal(list4.size());
                return R.ok(res);
        }
        List<TSubject> objects = new ArrayList<>();
        res.setRecords(objects);
        res.setTotal(0);
        return R.ok(res);
    }
    /**
     * 添加学习配置
     * @param dto
     * @return
     */
    @PostMapping("/addStudySet")
    public R<Object> addStudySet(@RequestBody AddStudySetDTO dto) {
        Integer week = dto.getWeek();
        Integer day = dto.getDay();
        Integer type = dto.getType();
        TStudy one = studyService.getOne(new QueryWrapper<TStudy>()
                .eq("week", week)
                .eq("type", type));
        GameDTO game = dto.getGame();
        StoryListenDTO storyListen = dto.getStoryListen();
        if (day == 6){
            // 先判断有没有配置
            TGame studyId = gameService.getOne(new QueryWrapper<TGame>()
                    .eq("studyId", one.getId())
                    .eq("week",week));
            if (studyId!=null){
                studyId.setWeek(dto.getWeek());
                studyId.setStudyId(one.getId());
                studyId.setCount(game.getCount());
                studyId.setIntegral(game.getIntegral());
                studyId.setTime(game.getTime());
                studyId.setAnswerTime(game.getAnswerTime());
                studyId.setAnswerIntegral(game.getAnswerIntegral());
                studyId.setAnswerCount(game.getAnswerCount());
                gameService.updateById(studyId);
            }else{
                TGame tGame = new TGame();
                tGame.setWeek(dto.getWeek());
                tGame.setStudyId(one.getId());
                tGame.setCount(game.getCount());
                tGame.setIntegral(game.getIntegral());
                tGame.setTime(game.getTime());
                tGame.setAnswerTime(game.getAnswerTime());
                tGame.setAnswerIntegral(game.getAnswerIntegral());
                tGame.setAnswerCount(game.getAnswerCount());
                gameService.save(tGame);
            }
 
        }else if(day == 7){
            String story = storyListen.getStory();
            TStoryListen studyId = storyListenService.getOne(new QueryWrapper<TStoryListen>()
                    .eq("studyId", one.getId())
                    .eq("week",week));
            if (studyId!=null){
                String sort = storyListen.getSort();
                String lookStory = storyListen.getLookStory();
                String lookSort = storyListen.getLookSort();
                Integer integral = storyListen.getIntegral();
                Integer lookIntegral = storyListen.getLookIntegral();
                studyId.setLookIntegral(lookIntegral);
                studyId.setIntegral(integral);
                studyId.setWeek(week);
                studyId.setStory(story);
                studyId.setSort(sort);
                studyId.setLookStory(lookStory);
                studyId.setLookSort(lookSort);
                studyId.setStudyId(one.getId());
                storyListenService.updateById(studyId);
            }else{
                String sort = storyListen.getSort();
                String lookStory = storyListen.getLookStory();
                String lookSort = storyListen.getLookSort();
                Integer integral = storyListen.getIntegral();
                Integer lookIntegral = storyListen.getLookIntegral();
                TStoryListen tStoryListen = new TStoryListen();
                tStoryListen.setLookIntegral(lookIntegral);
                tStoryListen.setIntegral(integral);
                tStoryListen.setWeek(week);
                tStoryListen.setStory(story);
                tStoryListen.setSort(sort);
                tStoryListen.setLookStory(lookStory);
                tStoryListen.setLookSort(lookSort);
                tStoryListen.setStudyId(one.getId());
                storyListenService.save(tStoryListen);
            }
        }else{
            // 删除原有数据
            studyListenService.remove(new QueryWrapper<TStudyListen>()
                    .eq("studyId", one.getId())
                    .eq("week",week)
                    .eq("day",day));
            List<StudyListenDTO> studyListen = dto.getStudyListen();
            for (StudyListenDTO studyListenDTO : studyListen) {
                TStudyListen tStudyListen = new TStudyListen();
                tStudyListen.setStudyId(one.getId());
                tStudyListen.setDay(day);
                tStudyListen.setSubject(studyListenDTO.getSubject());
                tStudyListen.setIntegral(studyListenDTO.getIntegral());
                tStudyListen.setWeek(week);
                tStudyListen.setIsVip(studyListenDTO.getIsVip());
                studyListenService.save(tStudyListen);
            }
            studyLookService.remove(new QueryWrapper<TStudyLook>()
                    .eq("studyId", one.getId())
                    .eq("week",week)
                    .eq("day",day));
            List<StudyLookDTO> studyLook = dto.getStudyLook();
            for (StudyLookDTO studyLookDTO : studyLook) {
                TStudyLook tStudyLook = new TStudyLook();
                tStudyLook.setStudyId(one.getId());
                tStudyLook.setDay(day);
                tStudyLook.setSubject(studyLookDTO.getSubject());
                tStudyLook.setIntegral(studyLookDTO.getIntegral());
                tStudyLook.setWeek(week);
                tStudyLook.setIsVip(studyLookDTO.getIsVip());
                studyLookService.save(tStudyLook);
            }
            studyInductionService.remove(new QueryWrapper<TStudyInduction>()
                    .eq("studyId", one.getId())
                    .eq("week",week)
                    .eq("day",day));
            List<StudyInductionDTO> studyInduction = dto.getStudyInduction();
            for (StudyInductionDTO studyInductionDTO : studyInduction) {
                TStudyInduction tStudyInduction = new TStudyInduction();
                tStudyInduction.setStudyId(one.getId());
                tStudyInduction.setDay(day);
                tStudyInduction.setSubject(studyInductionDTO.getSubject());
                tStudyInduction.setIntegral(studyInductionDTO.getIntegral());
                tStudyInduction.setWeek(week);
                tStudyInduction.setIsVip(studyInductionDTO.getIsVip());
            }
            studyAnswerService.remove(new QueryWrapper<TStudyAnswer>()
                    .eq("studyId", one.getId())
                    .eq("week",week)
                    .eq("day",day));
            List<StudyAnswerDTO> studyAnswer = dto.getStudyAnswer();
            for (StudyAnswerDTO studyAnswerDTO : studyAnswer) {
                TStudyAnswer tStudyAnswer = new TStudyAnswer();
                tStudyAnswer.setStudyId(one.getId());
                tStudyAnswer.setDay(day);
                tStudyAnswer.setIsAnswer(studyAnswerDTO.getIsAnswer());
                tStudyAnswer.setSubject(studyAnswerDTO.getSubject());
                tStudyAnswer.setAnswerSubject(studyAnswerDTO.getAnswerSubject());
                tStudyAnswer.setIntegral(studyAnswerDTO.getIntegral());
                tStudyAnswer.setWeek(week);
                tStudyAnswer.setIsVip(studyAnswerDTO.getIsVip());
                studyAnswerService.save(tStudyAnswer);
            }
            studyPairService.remove(new QueryWrapper<TStudyPair>()
                    .eq("studyId", one.getId())
                    .eq("week",week)
                    .eq("day",day));
            List<StudyPairDTO> studyPair = dto.getStudyPair();
            for (StudyPairDTO studyPairDTO : studyPair) {
                TStudyPair tStudyPair = new TStudyPair();
                tStudyPair.setStudyId(one.getId());
                tStudyPair.setDay(day);
                tStudyPair.setSubject(studyPairDTO.getSubject());
                tStudyPair.setIntegral(studyPairDTO.getIntegral());
                tStudyPair.setWeek(week);
                tStudyPair.setIsVip(studyPairDTO.getIsVip());
                studyPairService.save(tStudyPair);
            }
        }
        return R.ok();
    }
 
    /**
     * 添加周目
     * @param dto
     * @return
     */
    @PostMapping("/addWeek")
    public R<Object> addWeek(@RequestBody AddWeekDTO dto) {
        TStudy tStudy = new TStudy();
        tStudy.setType(dto.getType());
        tStudy.setWeek(dto.getWeek());
        tStudy.setTitle(dto.getTitle());
        tStudy.setQuarter(dto.getQuarter());
        studyService.save(tStudy);
        return R.ok();
    }
    /**
     * 学习类型列表查询
     * @return
     */
    @PostMapping("/getStudyList")
    public R<List<StudyListVO>> getStudyList() {
        List<StudyListVO> res = new ArrayList<>();
        StudyListVO studyListVO = new StudyListVO();
        List<TStudy> count = studyService.list(new QueryWrapper<TStudy>()
                .eq("type", 1));
        studyListVO.setWeeks(count.size());
        // todo 补充开始学习人数
        studyListVO.setCount(0);
        // 查询听类型有多少周目
        res.add(studyListVO);
        // 后续类型 不在1.0功能中
        for (int i = 1; i <= 6; i++) {
            res.add(new StudyListVO(0,0));
        }
        return R.ok(res);
    }
    /**
     * 通过类型、周目、day查询学习配置
     * @return
     */
    @PostMapping("/getStudySet")
    public R<StudyVO> getStudySet(@RequestBody StudyDTO dto) {
        StudyVO res = new StudyVO();
        // todo 开始学习人数后续补充
        res.setCount(0);
        int type = studyService.list(new QueryWrapper<TStudy>()
                .eq("type", dto.getType())).size();
        res.setWeeks(type);
        List<StudyListenVO> listenVOS = new ArrayList<>();
        List<GameVO> gameVOS = new ArrayList<>();
        List<StoryVO> storyVOS = new ArrayList<>();
        List<StudyAnswerVO> answerVOS = new ArrayList<>();
        List<StudyInductionVO> inductionVOS = new ArrayList<>();
        List<StudyLookVO> lookVOS = new ArrayList<>();
        List<StudyPairVO> pairVOS = new ArrayList<>();
//        Integer type = dto.getType();
        Integer week = dto.getWeek();
        Integer day = dto.getDay();
        // 根据类型 周目 day 查询对应数据
        // 听音选图
        List<TStudyListen> list = studyListenService.list(new QueryWrapper<TStudyListen>()
                .eq("week", week)
                .eq("day", day));
        for (TStudyListen tStudyListen : list) {
            StringBuilder temp = new StringBuilder();
            StudyListenVO studyListenVO = new StudyListenVO();
            for (String s : tStudyListen.getSubject().split(",")) {
                TSubject byId = subjectService.getById(s);
                temp.append(byId.getName()).append(",");
            }
            String string = temp.toString();
            studyListenVO.setName(string.substring(0, string.length() - 1));
            studyListenVO.setIntegral(tStudyListen.getIntegral());
            listenVOS.add(studyListenVO);
        }
        // 看音选图
        List<TStudyLook> list1 = studyLookService.list(new QueryWrapper<TStudyLook>()
                .eq("week", week)
                .eq("day", day)
                );
        for (TStudyLook tStudyLook : list1) {
            int index = 0;
            StringBuilder names = new StringBuilder();
            StringBuilder sorts = new StringBuilder();
            StudyLookVO studyLookVO1 = new StudyLookVO();
            for (String s : tStudyLook.getSubject().split(",")) {
                TSubject byId = subjectService.getById(s);
                names.append(byId.getName()).append(",");
                String[] split = tStudyLook.getSort().split(",");
                String s1 = split[index];
                sorts.append(s1).append(",");
                index++;
            }
            String string = names.toString();
            String string1 = sorts.toString();
            studyLookVO1.setName(string.substring(0, string.length() - 1));
            studyLookVO1.setSort(string1.substring(0, string1.length() - 1));
            studyLookVO1.setIntegral(tStudyLook.getIntegral());
            lookVOS.add(studyLookVO1);
        }
        // 归纳排除
        List<TStudyInduction> list2 = studyInductionService.list(new QueryWrapper<TStudyInduction>()
                .eq("week", week)
                .eq("day", day)
                );
        for (TStudyInduction tStudyInduction : list2) {
            StringBuilder names = new StringBuilder();
            StudyInductionVO studyInductionVO = new StudyInductionVO();
            for (String s : tStudyInduction.getSubject().split(",")) {
                String replace = s.replace("-", "");
                if (s.contains("-")){
                    TSubject byId = subjectService.getById(replace);
                    names.append("-").append(byId.getName()).append(",");
                }else{
                    TSubject byId = subjectService.getById(s);
                    names.append(byId.getName()).append(",");
                }
            }
            String string = names.toString();
            studyInductionVO.setName(string.substring(0, string.length() - 1));
            studyInductionVO.setIntegral(tStudyInduction.getIntegral());
            inductionVOS.add(studyInductionVO);
        }
        // 有问有答
        List<TStudyAnswer> list3 = studyAnswerService.list(new QueryWrapper<TStudyAnswer>()
                .eq("week", week)
                .eq("day", day));
        for (TStudyAnswer tStudyAnswer : list3) {
            StringBuilder names = new StringBuilder();
            StudyAnswerVO studyAnswerVO = new StudyAnswerVO();
            if (tStudyAnswer.getIsAnswer() == 1){
                TSubject byId = subjectService.getById(tStudyAnswer.getSubject());
                names.append("-").append(byId.getName()).append(",");
                TSubject byId1 = subjectService.getById(tStudyAnswer.getAnswerSubject());
                names.append("-").append(byId1.getName()).append(",");
            }else{
                TSubject byId = subjectService.getById(tStudyAnswer.getSubject());
                names.append(byId.getName()).append(",");
                TSubject byId1 = subjectService.getById(tStudyAnswer.getAnswerSubject());
                names.append("-").append(byId1.getName()).append(",");
            }
            String string = names.toString();
            studyAnswerVO.setName(string.substring(0, string.length() - 1));
            studyAnswerVO.setIntegral(tStudyAnswer.getIntegral());
            answerVOS.add(studyAnswerVO);
        }
        // 音图相配
        List<TStudyPair> list4 = studyPairService.list(new QueryWrapper<TStudyPair>()
                .eq("week", week)
                .eq("day", day)
                );
        for (TStudyPair tStudyPair : list4) {
            StringBuilder names = new StringBuilder();
            StudyPairVO studyPairVO = new StudyPairVO();
            for (String s : tStudyPair.getSubject().split(",")) {
                TSubject byId = subjectService.getById(s);
                names.append(byId.getName()).append(",");
            }
            String string = names.toString();
            studyPairVO.setName(string.substring(0, string.length() - 1));
            studyPairVO.setIntegral(tStudyPair.getIntegral());
            pairVOS.add(studyPairVO);
        }
        List<TGame> list5 = gameService.list(new QueryWrapper<TGame>()
                .eq("week", week));
        for (TGame tGame : list5) {
            GameVO gameVO = new GameVO();
            gameVO.setIntegral(tGame.getIntegral());
            gameVO.setTime(tGame.getTime());
            gameVO.setCount(tGame.getCount());
            gameVO.setAnswerTime(tGame.getAnswerTime());
            gameVO.setAnswerIntegral(tGame.getAnswerIntegral());
            gameVO.setAnswerCount(tGame.getAnswerCount());
            gameVOS.add(gameVO);
        }
        List<TStoryListen> list6 = storyListenService.list(new QueryWrapper<TStoryListen>()
                .eq("week", week));
        for (TStoryListen tStory : list6) {
            StoryVO storyVO = new StoryVO();
            StringBuilder names = new StringBuilder();
            StringBuilder names1 = new StringBuilder();
            StringBuilder sort = new StringBuilder();
            StringBuilder sort1 = new StringBuilder();
            for (String s : tStory.getStory().split(",")) {
                TStory byId = storyService.getById(s);
                names.append(byId.getName()).append(",");
            }
            for (String s : tStory.getLookStory().split(",")) {
                TStory byId = storyService.getById(s);
                names1.append(byId.getName()).append(",");
            }
            for (String s : tStory.getSort().split(",")) {
                sort.append(s).append(",");
            }
            for (String s : tStory.getLookSort().split(",")) {
                sort1.append(s).append(",");
            }
            storyVO.setName(names.substring(0, names.length() - 1));
            storyVO.setSort(sort.substring(0, sort.length() - 1));
            storyVO.setIntegral(tStory.getIntegral());
            storyVO.setLookName(names1.substring(0, names.length() - 1));
            storyVO.setLookSort(sort1.substring(0, sort.length() - 1));
            storyVO.setLookIntegral(tStory.getLookIntegral());
            storyVOS.add(storyVO);
        }
        int temp = 0;
        if (!list.isEmpty()){
            temp = list.get(0).getStudyId();
        }
        if (!list1.isEmpty()){
            temp = list1.get(0).getStudyId();
        }
        if (!list2.isEmpty()){
            temp = list2.get(0).getStudyId();
        }
        if (!list3.isEmpty()){
            temp = list3.get(0).getStudyId();
        }
        if (!list4.isEmpty()){
            temp = list4.get(0).getStudyId();
        }
        if (!list5.isEmpty()){
            temp = list5.get(0).getStudyId();
        }
        if (!list6.isEmpty()){
            temp = list6.get(0).getStudyId();
        }
        if (temp == 0){
            res.setTitle("");
        }else{
            res.setTitle(studyService.getById(temp).getTitle());
        }
        res.setAnswer(answerVOS);
        res.setPair(pairVOS);
        res.setListen(listenVOS);
        res.setLook(lookVOS);
        res.setInduction(inductionVOS);
        res.setGame(gameVOS);
        res.setStory(storyVOS);
        return R.ok(res);
    }
}