资源下载链路打通
This commit is contained in:
16
src/main/java/com/quinn/service/SourceCategoryService.java
Normal file
16
src/main/java/com/quinn/service/SourceCategoryService.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.quinn.service;
|
||||
|
||||
import com.quinn.pojo.SourceCategory;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2022-05-03
|
||||
*/
|
||||
public interface SourceCategoryService extends IService<SourceCategory> {
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.quinn.service;
|
||||
|
||||
import com.quinn.pojo.Say;
|
||||
import com.quinn.pojo.SourceComment;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
@@ -9,8 +9,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2020-07-01
|
||||
* @since 2022-05-03
|
||||
*/
|
||||
public interface SayService extends IService<Say> {
|
||||
public interface SourceCommentService extends IService<SourceComment> {
|
||||
|
||||
}
|
||||
22
src/main/java/com/quinn/service/SourceService.java
Normal file
22
src/main/java/com/quinn/service/SourceService.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.quinn.service;
|
||||
|
||||
import com.quinn.pojo.Source;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2022-05-03
|
||||
*/
|
||||
public interface SourceService extends IService<Source> {
|
||||
|
||||
void downloadSource(ServletOutputStream outputStream, String sid) throws IOException;
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.quinn.service.impl;
|
||||
|
||||
import com.quinn.pojo.Say;
|
||||
import com.quinn.mapper.SayMapper;
|
||||
import com.quinn.service.SayService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2020-07-01
|
||||
*/
|
||||
@Service
|
||||
public class SayServiceImpl extends ServiceImpl<SayMapper, Say> implements SayService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.quinn.service.impl;
|
||||
|
||||
import com.quinn.pojo.SourceCategory;
|
||||
import com.quinn.mapper.SourceCategoryMapper;
|
||||
import com.quinn.service.SourceCategoryService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2022-05-03
|
||||
*/
|
||||
@Service
|
||||
public class SourceCategoryServiceImpl extends ServiceImpl<SourceCategoryMapper, SourceCategory> implements SourceCategoryService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.quinn.service.impl;
|
||||
|
||||
import com.quinn.pojo.SourceComment;
|
||||
import com.quinn.mapper.SourceCommentMapper;
|
||||
import com.quinn.service.SourceCommentService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2022-05-03
|
||||
*/
|
||||
@Service
|
||||
public class SourceCommentServiceImpl extends ServiceImpl<SourceCommentMapper, SourceComment> implements SourceCommentService {
|
||||
|
||||
}
|
||||
52
src/main/java/com/quinn/service/impl/SourceServiceImpl.java
Normal file
52
src/main/java/com/quinn/service/impl/SourceServiceImpl.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package com.quinn.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.quinn.pojo.Source;
|
||||
import com.quinn.mapper.SourceMapper;
|
||||
import com.quinn.service.SourceService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.quinn.utils.OSSClientUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2022-05-03
|
||||
*/
|
||||
@Service
|
||||
public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> implements SourceService {
|
||||
|
||||
@Resource
|
||||
OSSClientUtil ossClientUtil;
|
||||
|
||||
@Override
|
||||
public void downloadSource(ServletOutputStream outputStream, String sid) throws IOException {
|
||||
Source source = getOne(new QueryWrapper<Source>().eq("id", sid));
|
||||
String sourceLink = source.getSourceLink();
|
||||
// 读取文件内容。
|
||||
BufferedInputStream in = new BufferedInputStream(ossClientUtil.downloadFile(sourceLink));
|
||||
BufferedOutputStream out = new BufferedOutputStream(outputStream);
|
||||
byte[] buffer = new byte[1024];
|
||||
int lenght = 0;
|
||||
while ((lenght = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, lenght);
|
||||
}
|
||||
if (out != null) {
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user