baizonghao
2023-07-31 98b2f41e13c48219e054cf8b80c459298a01c910
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
package com.mindskip.xzs.controller.admin;
 
 
import com.mindskip.xzs.base.BaseApiController;
import com.mindskip.xzs.base.RestResponse;
import com.mindskip.xzs.domain.Subject;
import com.mindskip.xzs.domain.Video;
import com.mindskip.xzs.service.SubjectService;
import com.mindskip.xzs.service.VideoService;
import com.mindskip.xzs.utility.DateTimeUtil;
import com.mindskip.xzs.utility.PageInfoHelper;
import com.mindskip.xzs.viewmodel.admin.video.VideoEditRequestVM;
import com.mindskip.xzs.viewmodel.admin.video.VideoPageRequestVM;
import com.mindskip.xzs.viewmodel.admin.video.VideoResponseVM;
import com.github.pagehelper.PageInfo;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.Valid;
import java.util.Date;
 
/**
 * @version 2.2.0
 * @description: 视频学习
 * Copyright (C), 2020-2021, 武汉思维跳跃科技有限公司
 * @date 2021 /9/7 9:45
 */
@RestController("AdminVideoController")
@RequestMapping(value = "/api/admin")
@AllArgsConstructor
public class VideoController extends BaseApiController {
 
    private final VideoService videoService;
    private final SubjectService subjectService;
 
    /**
     * 视频分页
     *
     * @param model the model
     * @return the rest response
     */
    @RequestMapping(value = "/video/page", method = RequestMethod.POST)
    public RestResponse<PageInfo<VideoResponseVM>> pageList(@RequestBody VideoPageRequestVM model) {
        PageInfo<Video> pageInfo = videoService.page(model);
        PageInfo<VideoResponseVM> page = PageInfoHelper.copyMap(pageInfo, e -> {
                    VideoResponseVM vm = modelMapper.map(e, VideoResponseVM.class);
                    Subject subject = subjectService.selectById(vm.getSubjectId());
                    vm.setSubjectName(subject.getName());
                    vm.setCreateTime(DateTimeUtil.dateFormat(e.getCreateTime()));
                    return vm;
                }
        );
        return RestResponse.ok(page);
    }
 
    /**
     * 视频编辑
     *
     * @param model the model
     * @return the rest response
     */
    @RequestMapping(value = "/video/edit", method = RequestMethod.POST)
    public RestResponse edit(@RequestBody @Valid VideoEditRequestVM model) {
        Video video = modelMapper.map(model, Video.class);
        if (model.getId() == null) {
            video.setCreateUser(getCurrentUser().getId());
            video.setCreateTime(new Date());
            video.setDeleted(false);
            videoService.insertByFilter(video);
        } else {
            videoService.updateByIdFilter(video);
        }
        return RestResponse.ok();
    }
 
    /**
     * 视频查询
     *
     * @param id the id
     * @return the rest response
     */
    @RequestMapping(value = "/video/select/{id}", method = RequestMethod.POST)
    public RestResponse<VideoEditRequestVM> select(@PathVariable Integer id) {
        Video video = videoService.selectById(id);
        VideoEditRequestVM vm = modelMapper.map(video, VideoEditRequestVM.class);
        return RestResponse.ok(vm);
    }
 
    /**
     * 删除视频
     *
     * @param id the id
     * @return the rest response
     */
    @RequestMapping(value = "/video/delete/{id}", method = RequestMethod.POST)
    public RestResponse delete(@PathVariable Integer id) {
        Video video = videoService.selectById(id);
        video.setDeleted(true);
        videoService.updateByIdFilter(video);
        return RestResponse.ok();
    }
}