当前位置:网站首页>[PROJECT] Xiaomao school (IX)

[PROJECT] Xiaomao school (IX)

2022-06-30 18:04:00 Lemon cap

Xiaomao school

20. The course is finally released

@RestController
@RequestMapping("/eduservice/course")
@CrossOrigin
public class EduCourseController {
    

    @Autowired
    private EduCourseService courseService;

    //  The course is finally released 
    //  Modify course status 
    @PostMapping("publishCourse/{id}")
    public R publishCourse(@PathVariable String id) {
    
        EduCourse eduCourse = new EduCourse();
        eduCourse.setId(id);
        eduCourse.setStatus("Normal");    //  Set course publishing status 
        courseService.updateById(eduCourse);
        return R.ok();
    }
}


// src\api\edu\course.js
import request from '@/utils/request'

export default {
    
    //  The course is finally released 
    publishCourse(id) {
    
      return request({
    
        url: '/eduservice/course/publishCourse/' + id,
        method: 'post',
      })
    }
}
// src\views\edu\course\publish.vue
<script> import course from '@/api/edu/course' export default {
       methods: {
       publish() {
       course.publishCourse(this.courseId) .then(response => {
       //  Tips  this.$message({
       type: 'success', message: ' The course was published successfully !' }); //  Jump to the course list page  this.$router.push({
       path: '/course/list' }) }) } } } </script>

21. Course list

 Insert picture description here

@RestController
@RequestMapping("/eduservice/course")
@CrossOrigin
public class EduCourseController {
    

    @Autowired
    private EduCourseService courseService;

    //  Course list   Basic implementation 
    // TODO  Perfect conditional query with paging 
    @GetMapping
    public R getCourseList() {
    
        List<EduCourse> list = courseService.list(null);
        return R.ok().data("list",list);
    }
}
// src\api\edu\course.js
import request from '@/utils/request'

export default {
    
    // TODO  Course list 
    getListCourse() {
    
      return request({
    
        url: '/eduservice/course',
        method: 'get'
      })
    }
}
// src\views\edu\course\list.vue
<template>
  <div class="app-container">
     Course list 
    <!-- Query form -->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="courseQuery.title" placeholder=" Course name "/>
      </el-form-item>
      <el-form-item>
        <el-select v-model="courseQuery.status" clearable placeholder=" Course status ">
          <el-option :value="Normal" label=" The published "/>
          <el-option :value="Draft" label=" Unpublished "/>
        </el-select>
      </el-form-item>
      <el-button type="primary" icon="el-icon-search" @click="getList()"> Inquire about </el-button>
      <el-button type="default" @click="resetData()"> Empty </el-button>
    </el-form>
    <!--  form  -->
    <el-table :data="list" border fit highlight-current-row>
      <el-table-column label=" Serial number " width="70" align="center">
        <template slot-scope="scope">
          {
   { (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column prop="title" label=" Course name " width="80" />
      <el-table-column label=" Course status " width="80">
        <template slot-scope="scope">
          {
   { scope.row.status==='Normal'?' The published ':' Unpublished ' }}
        </template>
      </el-table-column>
      <el-table-column prop="lessonNum" label=" Class hours " />
      <el-table-column prop="gmtCreate" label=" Add the time " width="160"/>
      <el-table-column prop="viewCount" label=" Number of views " width="60" />
      <el-table-column label=" operation " width="200" align="center">
        <template slot-scope="scope">
          <router-link :to="'/teacher/edit/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit"> Edit course basic information </el-button>
          </router-link>
          <router-link :to="'/teacher/edit/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit"> Edit course outline information </el-button>
          </router-link>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)"> Delete course information </el-button>
        </template>
      </el-table-column>
    </el-table>

   <!--  Pagination  -->
    <el-pagination :current-page="page" :page-size="limit" :total="total" style="padding: 30px 0; text-align: center;" layout="total, prev, pager, next, jumper" @current-change="getList" />
  </div>
</template>
<script> //  Introduce call course.js file  import course from '@/api/edu/course' export default {
       //  Where to write core code  data() {
       //  Define variables and initial values  return {
       list: null, //  The collection returned by the interface after query  page: 1, //  The current page  limit: 10, //  Records per page  total: 0, //  Total number of records  courseQuery: {
      } //  Conditional encapsulation object  } }, created() {
       //  Execute before rendering the page , The general call methods Method of definition  this.getList() }, methods: {
       //  Create specific methods , call teacher.js Method of definition  //  How to list lecturers  getList() {
       course.getListCourse() .then(response => {
       //  The request is successful  // response  The data returned by the interface  // console.log(response); this.list= response.data.list }) }, resetData() {
       //  How to clear  //  The form entry data is cleared  this.courseQuery = {
      } //  Query all instructor data  this.getList() }, } } </script>

22. Delete course ( Back end )

 Insert picture description here

@RestController
@RequestMapping("/eduservice/course")
@CrossOrigin
public class EduCourseController {
    

    @Autowired
    private EduCourseService courseService;
    
    //  Delete course 
    @DeleteMapping("{courseId}")
    public R deleteCourse(@PathVariable String courseId) {
    
        courseService.removeCourse(courseId);
        return R.ok();
    }
}
@Service
public class EduCourseServiceImpl extends ServiceImpl<EduCourseMapper, EduCourse> implements EduCourseService {
    
    //  Course description 
    @Autowired
    private EduCourseDescriptionService courseDescriptionService;

    //  Inject sections and chapters service
    @Autowired
    private EduVideoService eduVideoService;

    @Autowired
    private EduChapterService eduChapterService;

    //  Delete course 
    @Override
    public void removeCourse(String courseId) {
    
        // 1. According to the course id Delete section 
        eduVideoService.removeVideoByCourseId(courseId);
        // 2. According to the course id Delete chapter 
        eduChapterService.removeChapterByCourseId(courseId);
        // 3. According to the course id Delete description 
        courseDescriptionService.removeById(courseId);
        // 4. According to the course id Delete the course itself 
        int result = baseMapper.deleteById(courseId);
        if(result == 0) {
       //  Failure to return 
            throw new LemonException(20001, " Delete failed ");
        }
    }
}
public interface EduVideoService extends IService<EduVideo> {
    
    void removeVideoByCourseId(String courseId);
}
@Service
public class EduVideoServiceImpl extends ServiceImpl<EduVideoMapper, EduVideo> implements EduVideoService {
    
    //  According to the course id Delete section 
    // TODO  Delete section , Delete the corresponding video file 
    @Override
    public void removeVideoByCourseId(String courseId) {
    
        QueryWrapper<EduVideo> wrapper = new QueryWrapper<>();
        wrapper.eq("course_id", courseId);
        baseMapper.delete(wrapper);
    }
}
public interface EduChapterService extends IService<EduChapter> {
    
    //  According to the course id Delete chapter 
    void removeChapterByCourseId(String courseId);
}
@Service
public class EduChapterServiceImpl extends ServiceImpl<EduChapterMapper, EduChapter> implements EduChapterService {
    

    @Autowired
    private EduVideoService videoService;   //  Injection section service

    //  According to the course id Delete chapter 
    @Override
    public void removeChapterByCourseId(String courseId) {
    
        QueryWrapper<EduChapter> wrapper = new QueryWrapper<>();
        wrapper.eq("course_id", courseId);
        baseMapper.delete(wrapper);
    }
}

23. Alibaba cloud video on demand

 Insert picture description here

  • video on demand (ApsaraVideo for VoD) It's a collection of audio and video collection 、 edit 、 Upload 、 Automatic transcoding 、 Media resource management 、 A one-stop audio and video on demand solution with distribution acceleration .
  • Application scenarios
    • Audio and video websites : Whether it's a start-up video service enterprise , Or already have a huge amount of video resources , Customized on-demand services help customers quickly build an extreme viewing experience 、 Secure and reliable VOD applications .
    • Short video : Audio and video shooting 、 Special effects editor 、 Local transcoding 、 High speed upload 、 Automatic cloud transcoding 、 Media resource management 、 Distribution acceleration 、 Play in one complete short video solution . Has helped 1000+APP Fast implementation of mobile phone short video function .
    • Live to on demand : Record the live stream synchronously as a video on demand , For looking back . And support media management 、 Media processing ( Transcoding and content auditing / Smart head map, etc AI Handle )、 Content production ( Cloud clip )、CDN Distribution acceleration and a series of operations .
    • Online education : Easy to use for online education customers 、 Secure and reliable VOD service . Through the console /API And other ways to upload teaching videos , The powerful transcoding capability ensures that videos can be released quickly , The acceleration node covering the whole network ensures the fluency of students' watching . Anti theft chain 、 Video encryption and other copyright protection programs protect teaching content from theft .
    • Video production : Provide online visual editing platform and rich OpenAPI, Help customers deal with 、 Making video content . Except for the shear splicing of the foundation 、 Mixing 、 Cover label 、 Special effects 、 Besides a series of functions such as synthesis , Relying on cloud editing and on-demand integrated services, standardization can also be achieved 、 Intelligent editing production , The threshold of video production is greatly reduced , Shorten production time , Improve content productivity .
    • Content review : For short video platform 、 Media industry audit, etc , Help customers from voice 、 written words 、 Vision and other multi-dimensional accurate recognition of video 、 cover 、 The prohibited content of the title or comment is carried out AI Intelligent audit and manual audit .
  • Function is introduced
     Insert picture description here

24. Alicloud video on demand SDK( Get video address )

 Insert picture description here

  • Create a video on demand micro service

    • Create a microservice module Artifact:service-vod
    • pom
      • service-vod Introduce dependency in
    <dependencies>
            <dependency>
                <groupId>com.aliyun</groupId>
                <artifactId>aliyun-java-sdk-core</artifactId>
            </dependency>
            <dependency>
                <groupId>com.aliyun.oss</groupId>
                <artifactId>aliyun-sdk-oss</artifactId>
            </dependency>
            <dependency>
                <groupId>com.aliyun</groupId>
                <artifactId>aliyun-java-sdk-vod</artifactId>
            </dependency>
            <dependency>
                <groupId>com.aliyun</groupId>
                <artifactId>aliyun-sdk-vod-upload</artifactId>
            </dependency>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
            </dependency>
            <dependency>
                <groupId>org.json</groupId>
                <artifactId>json</artifactId>
            </dependency>
            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
            </dependency>
            <dependency>
                <groupId>joda-time</groupId>
                <artifactId>joda-time</artifactId>
            </dependency>
    </dependencies>
    
  • test

    public class InitObject {
          
        public static DefaultAcsClient initVodClient(String accessKeyId, String accessKeySecret) throws ClientException {
          
            String regionId = "cn-shanghai";  //  On demand service access area 
            DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
            DefaultAcsClient client = new DefaultAcsClient(profile);
            return client;
        }
    }
    
    public class TestVod {
          
        public static void main(String[] args) throws Exception{
          
            // 1. According to the video id Get video playback address 
            //  Create initialization object 
            DefaultAcsClient client = InitObject.initVodClient(" Secret key ", " password ");
    
            //  Create get video address request and response
            GetPlayInfoRequest request = new GetPlayInfoRequest();
            GetPlayInfoResponse response = new GetPlayInfoResponse();
    
            //  towards request Set the video in the object id
            request.setVideoId("7272bc8cc64344c2a3209c15881712fe");
            //  Call the method in the initialization object , Pass on request, get data 
            response = client.getAcsResponse(request);
    
            List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();
            // Broadcast address 
            for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {
          
                System.out.print("PlayInfo.PlayURL = " + playInfo.getPlayURL() + "\n");
            }
            //Base Information 
            System.out.print("VideoBase.Title = " + response.getVideoBase().getTitle() + "\n");
        }
    }
    

25. Alicloud video on demand SDK( Get video credentials )

public class TestVod {
    
    public static void main(String[] args) throws Exception{
    
        // 2. According to the video id Get video playback credentials 
        //  Create initialization object 
        //  Create initialization object 
        DefaultAcsClient client = InitObject.initVodClient(" Secret key ", " password ");

        //  Create and obtain video credentials request and response
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();

        //  towards request Set the video in the object id
        request.setVideoId("7272bc8cc64344c2a3209c15881712fe");
        //  Call the method in the initialization object , Pass on request, get data 
        response = client.getAcsResponse(request);
        System.out.println("platauth: " + response.getPlayAuth());
    }
}

26. Alicloud video on demand ( Upload video )

 Insert picture description here

public class TestVod {
    
    public static void main(String[] args){
    
        String accessKeyId = " Secret key ";
        String accessKeySecret = " password ";

        String title = "3 - How Does Project Submission Work - upload by sdk";  //  The name of the file after uploading 
        String fileName = "D:/abc/3 - How Does Project Submission Work.mp4";   //  The path and name of the local file 

        //  How to upload video 
        UploadVideoRequest request = new UploadVideoRequest(accessKeyId, accessKeySecret, title, fileName);
        /*  You can specify the size of each slice when uploading slices , The default is 2M byte  */
        request.setPartSize(2 * 1024 * 1024L);
        /*  You can specify the number of concurrent threads during fragment upload , The default is 1,( notes : This configuration will occupy the server CPU resources , It needs to be specified according to the situation of the server )*/
        request.setTaskNum(1);
        UploadVideoImpl uploader = new UploadVideoImpl();
        UploadVideoResponse response = uploader.uploadVideo(request);
        System.out.print("RequestId=" + response.getRequestId() + "\n");  // Request for video on demand service ID
        if (response.isSuccess()) {
    
            System.out.print("VideoId=" + response.getVideoId() + "\n");
        } else {
    
            /*  If the callback is set URL Invalid , Does not affect the video upload , Can return VideoId At the same time, the error code will be returned . In other cases, the upload fails ,VideoId It's empty , At this time, you need to analyze the specific error reason according to the returned error code  */
            System.out.print("VideoId=" + response.getVideoId() + "\n");
            System.out.print("ErrorCode=" + response.getCode() + "\n");
            System.out.print("ErrorMessage=" + response.getMessage() + "\n");
        }
    }
}
原网站

版权声明
本文为[Lemon cap]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202160458584783.html