hejianhao
2026-09-01 587391ed908f11c8f8f735575bc1425346d05bb2
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
package com.tcm.training.admin.live.controller;
 
import com.tcm.training.admin.common.ApiResponse;
import com.tcm.training.admin.common.PageResponse;
import com.tcm.training.admin.live.dto.HealthCourseSaveRequest;
import com.tcm.training.admin.live.dto.HealthCourseStatusRequest;
import com.tcm.training.admin.live.dto.HealthCourseVideoSaveRequest;
import com.tcm.training.admin.live.service.HealthCourseAppService;
import com.tcm.training.admin.live.vo.HealthCourseDetailVO;
import com.tcm.training.admin.live.vo.HealthCourseListItemVO;
import com.tcm.training.admin.live.vo.HealthCourseOptionVO;
import com.tcm.training.admin.live.vo.HealthCourseStatusVO;
import com.tcm.training.admin.live.vo.HealthCourseVideoDetailVO;
import com.tcm.training.admin.live.vo.HealthCourseVideoItemVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;
 
@Validated
@RestController
@RequestMapping({"/api/v1", "/api"})
public class HealthCourseController {
 
    private final HealthCourseAppService healthCourseAppService;
 
    public HealthCourseController(HealthCourseAppService healthCourseAppService) {
        this.healthCourseAppService = healthCourseAppService;
    }
 
    @GetMapping("/health-courses")
    public ApiResponse<PageResponse<HealthCourseListItemVO>> page(@RequestParam(required = false, defaultValue = "1") int page,
                                                                  @RequestParam(required = false, defaultValue = "10") int pageSize,
                                                                  @RequestParam(required = false) String keyword,
                                                                  @RequestParam(required = false) Long levelCategoryId,
                                                                  @RequestParam(required = false) Long difficultyCategoryId,
                                                                  @RequestParam(required = false) Integer status) {
        return ApiResponse.ok(healthCourseAppService.page(page, pageSize, keyword, levelCategoryId, difficultyCategoryId, status));
    }
 
    @GetMapping("/health-courses/export")
    public void export(HttpServletResponse response,
                       @RequestParam(required = false) String keyword,
                       @RequestParam(required = false) Long levelCategoryId,
                       @RequestParam(required = false) Long difficultyCategoryId,
                       @RequestParam(required = false) Integer status) throws IOException {
        healthCourseAppService.export(response, keyword, levelCategoryId, difficultyCategoryId, status);
    }
 
    @GetMapping("/health-courses/options")
    public ApiResponse<List<HealthCourseOptionVO>> options(@RequestParam(required = false) String keyword) {
        return ApiResponse.ok(healthCourseAppService.options(keyword));
    }
 
    @PostMapping("/health-courses")
    public ApiResponse<HealthCourseDetailVO> create(@Valid @RequestBody HealthCourseSaveRequest req) {
        return ApiResponse.ok(healthCourseAppService.create(req));
    }
 
    @GetMapping("/health-courses/{id}")
    public ApiResponse<HealthCourseDetailVO> detail(@PathVariable("id") Long id) {
        return ApiResponse.ok(healthCourseAppService.detail(id));
    }
 
    @PutMapping("/health-courses/{id}")
    public ApiResponse<HealthCourseDetailVO> update(@PathVariable("id") Long id, @Valid @RequestBody HealthCourseSaveRequest req) {
        return ApiResponse.ok(healthCourseAppService.update(id, req));
    }
 
    @PatchMapping("/health-courses/{id}/status")
    public ApiResponse<HealthCourseStatusVO> patchStatus(@PathVariable("id") Long id, @Valid @RequestBody HealthCourseStatusRequest req) {
        return ApiResponse.ok(healthCourseAppService.patchStatus(id, req));
    }
 
    @DeleteMapping("/health-courses/{id}")
    public ApiResponse<Void> delete(@PathVariable("id") Long id) {
        healthCourseAppService.delete(id);
        return ApiResponse.ok(null);
    }
 
    @GetMapping("/health-courses/{courseId}/videos")
    public ApiResponse<PageResponse<HealthCourseVideoItemVO>> pageVideos(@PathVariable("courseId") Long courseId,
                                                                         @RequestParam(required = false, defaultValue = "1") int page,
                                                                         @RequestParam(required = false, defaultValue = "10") int pageSize,
                                                                         @RequestParam(required = false) String chapterName,
                                                                         @RequestParam(required = false) Integer priceType) {
        return ApiResponse.ok(healthCourseAppService.pageVideos(courseId, page, pageSize, chapterName, priceType));
    }
 
    @GetMapping("/health-courses/{courseId}/videos/{videoId}")
    public ApiResponse<HealthCourseVideoDetailVO> detailVideo(@PathVariable("courseId") Long courseId,
                                                              @PathVariable("videoId") Long videoId) {
        return ApiResponse.ok(healthCourseAppService.detailVideo(courseId, videoId));
    }
 
    @PostMapping("/health-courses/{courseId}/videos")
    public ApiResponse<HealthCourseVideoDetailVO> createVideo(@PathVariable("courseId") Long courseId,
                                                              @Valid @RequestBody HealthCourseVideoSaveRequest req) {
        return ApiResponse.ok(healthCourseAppService.createVideo(courseId, req));
    }
 
    @PutMapping("/health-courses/{courseId}/videos/{videoId}")
    public ApiResponse<HealthCourseVideoDetailVO> updateVideo(@PathVariable("courseId") Long courseId,
                                                              @PathVariable("videoId") Long videoId,
                                                              @Valid @RequestBody HealthCourseVideoSaveRequest req) {
        return ApiResponse.ok(healthCourseAppService.updateVideo(courseId, videoId, req));
    }
 
    @DeleteMapping("/health-courses/{courseId}/videos/{videoId}")
    public ApiResponse<Void> deleteVideo(@PathVariable("courseId") Long courseId,
                                         @PathVariable("videoId") Long videoId) {
        healthCourseAppService.deleteVideo(courseId, videoId);
        return ApiResponse.ok(null);
    }
 
    @GetMapping("/health-course-video-resources")
    public ApiResponse<PageResponse<HealthCourseVideoItemVO>> pageVideoResources(@RequestParam(required = false, defaultValue = "1") int page,
                                                                                 @RequestParam(required = false, defaultValue = "10") int pageSize,
                                                                                 @RequestParam(required = false) String courseKeyword,
                                                                                 @RequestParam(required = false) Long courseId,
                                                                                 @RequestParam(required = false) Integer courseType,
                                                                                 @RequestParam(required = false) String chapterName,
                                                                                 @RequestParam(required = false) Integer priceType,
                                                                                 @RequestParam(required = false) Integer status) {
        return ApiResponse.ok(healthCourseAppService.pageVideoResources(page, pageSize, courseKeyword, courseId, courseType, chapterName, priceType, status));
    }
 
    @GetMapping("/health-course-video-resources/import-template")
    public void downloadVideoResourceTemplate(HttpServletResponse response) throws IOException {
        healthCourseAppService.downloadVideoResourceTemplate(response);
    }
 
    @GetMapping("/health-course-video-resources/{id}")
    public ApiResponse<HealthCourseVideoDetailVO> detailVideoResource(@PathVariable("id") Long id) {
        return ApiResponse.ok(healthCourseAppService.detailVideoResource(id));
    }
 
    @PostMapping("/health-course-video-resources")
    public ApiResponse<HealthCourseVideoDetailVO> createVideoResource(@Valid @RequestBody HealthCourseVideoSaveRequest req) {
        return ApiResponse.ok(healthCourseAppService.createVideoResource(req));
    }
 
    @PutMapping("/health-course-video-resources/{id}")
    public ApiResponse<HealthCourseVideoDetailVO> updateVideoResource(@PathVariable("id") Long id,
                                                                      @Valid @RequestBody HealthCourseVideoSaveRequest req) {
        return ApiResponse.ok(healthCourseAppService.updateVideoResource(id, req));
    }
 
    @DeleteMapping("/health-course-video-resources/{id}")
    public ApiResponse<Void> deleteVideoResource(@PathVariable("id") Long id) {
        healthCourseAppService.deleteVideoResource(id);
        return ApiResponse.ok(null);
    }
 
    @PostMapping("/health-course-video-resources/import")
    public ApiResponse<Void> importVideoResources(@RequestParam("file") MultipartFile file) throws IOException {
        healthCourseAppService.importVideoResources(file);
        return ApiResponse.ok(null);
    }
}