|
|
|
@ -12,9 +12,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.Constant; |
|
|
|
import com.elink.esua.epdc.commons.tools.page.PageData; |
|
|
|
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.Constant; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.NumConstant; |
|
|
|
import com.elink.esua.epdc.commons.tools.page.PageData; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.Result; |
|
|
|
import com.elink.esua.epdc.dao.OssDao; |
|
|
|
@ -23,6 +21,11 @@ import com.elink.esua.epdc.entity.OssEntity; |
|
|
|
import com.elink.esua.epdc.service.OssService; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.*; |
|
|
|
import java.net.MalformedURLException; |
|
|
|
import java.net.URL; |
|
|
|
import java.net.URLEncoder; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@ -53,4 +56,45 @@ public class OssServiceImpl extends BaseServiceImpl<OssDao, OssEntity> implement |
|
|
|
|
|
|
|
return new Result<UploadDTO>().ok(dto); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void download(String fileUrl, HttpServletResponse response) { |
|
|
|
URL url; |
|
|
|
try { |
|
|
|
url = new URL(fileUrl); |
|
|
|
|
|
|
|
DataInputStream dataInputStream = new DataInputStream(url.openStream()); |
|
|
|
if (null != dataInputStream) { |
|
|
|
|
|
|
|
String filename = fileUrl.substring(fileUrl.lastIndexOf("/") + 1); |
|
|
|
// 设定输出文件头
|
|
|
|
response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(filename, "UTF-8")); |
|
|
|
|
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
response.setHeader("Pragma", "No-Cache"); |
|
|
|
response.setHeader("Cache-Control", "No-Cache"); |
|
|
|
response.setDateHeader("Expires", 0); |
|
|
|
response.setContentType("application/msexcel; charset=UTF-8"); |
|
|
|
|
|
|
|
byte[] buf = new byte[1024]; |
|
|
|
int L; |
|
|
|
|
|
|
|
OutputStream toClient = new BufferedOutputStream(response.getOutputStream()); |
|
|
|
while ((L = dataInputStream.read(buf)) != NumConstant.ONE_NEG) { |
|
|
|
toClient.write(buf, NumConstant.ZERO, L); |
|
|
|
} |
|
|
|
dataInputStream.close(); |
|
|
|
toClient.flush(); |
|
|
|
toClient.close(); |
|
|
|
} |
|
|
|
} catch (MalformedURLException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} catch (UnsupportedEncodingException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|