Commit d2837c7a authored by zhoumaotao's avatar zhoumaotao

文件流传入

parent 29097f3b
......@@ -2,13 +2,11 @@ package com.gavel.kwell.controller;
import com.alibaba.fastjson.JSONObject;
import com.gavel.common.base.controller.BaseController;
import com.gavel.common.utils.ThreadContext;
import com.gavel.kwell.service.KmesBoardService;
import com.gavel.kwell.vo.GpfkHgVO;
import com.gavel.kwell.vo.PcslVO;
import com.gavel.kwell.vo.SdclVO;
import com.gavel.kwell.vo.UWoVO;
import com.gavel.wo.persistent.Pcjhmx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -16,6 +14,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.util.List;
@Controller
......@@ -127,25 +127,24 @@ public class KmesBoardController extends BaseController {
/**
* 视频路径api
* pdf路径api
*/
@RequestMapping(value ="getPdf", method = RequestMethod.POST)
@ResponseBody
public Object getPdf(@RequestBody JSONObject param) {
returnData().add("pdf", kmesBoardService.getPdf());
return ThreadContext.getReturnData();
@RequestMapping(value ="getPdf")
public void getPdf(HttpServletResponse response) {
FileInputStream fileInputStream = kmesBoardService.getPdf();
kmesBoardService.doAttachmentPreview(response, fileInputStream);
}
/**
* 视频路径api
*/
@RequestMapping(value ="getVideo", method = RequestMethod.POST)
@ResponseBody
public Object getVideo(@RequestBody JSONObject param) {
returnData().add("video", kmesBoardService.getVideo());
return ThreadContext.getReturnData();
@RequestMapping(value ="getVideo")
public void getVideo(HttpServletResponse response) {
FileInputStream fileInputStream = kmesBoardService.getVideo();
kmesBoardService.doAttachmentPreview(response, fileInputStream);
}
}
......@@ -7,6 +7,8 @@ import com.gavel.kwell.vo.SdclVO;
import com.gavel.kwell.vo.UWoVO;
import com.gavel.wo.persistent.Pcjhmx;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.util.List;
......@@ -26,7 +28,11 @@ public interface KmesBoardService extends BaseEditService {
public List<GpfkHgVO> queryGpfkHgl();
public String getPdf();
public FileInputStream getPdf();
public String getVideo();
public FileInputStream getVideo();
public FileInputStream downloadFile(String path);
public void doAttachmentPreview(HttpServletResponse response, FileInputStream fileInputStream);
}
......@@ -4,6 +4,7 @@ import com.gavel.common.base.service.impl.BaseEditServiceImpl;
import com.gavel.common.business.service.CommonService;
import com.gavel.common.utils.DateUtils;
import com.gavel.common.utils.NumberUtils;
import com.gavel.common.utils.StringUtils;
import com.gavel.kwell.dao.GpfkcxDao;
import com.gavel.kwell.dao.KmesBoardDao;
import com.gavel.kwell.persistent.Gpfk;
......@@ -15,10 +16,14 @@ import com.gavel.kwell.vo.PcslVO;
import com.gavel.kwell.vo.SdclVO;
import com.gavel.kwell.vo.UWoVO;
import com.gavel.wo.persistent.Pcjhmx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
......@@ -29,6 +34,9 @@ import java.util.List;
@Transactional
public class KmesBoardServiceImpl extends BaseEditServiceImpl implements KmesBoardService {
private Logger logger = LoggerFactory.getLogger(KmesBoardServiceImpl.class);
@Autowired
private KmesBoardDao kmesBoardDao;
......@@ -135,12 +143,64 @@ public class KmesBoardServiceImpl extends BaseEditServiceImpl implements KmesBoa
}
@Override
public String getPdf() {
return commonService.getStringOptionValue(KwellParamEnum.DASHBORAD_PDF.getId());
public FileInputStream getPdf() {
String path = commonService.getStringOptionValue(KwellParamEnum.DASHBORAD_PDF.getId());
if(StringUtils.isEmpty(path)) {
logger.error("文件路径参数为空,请检查!");
return null;
}
return downloadFile(path);
}
@Override
public FileInputStream getVideo() {
String path = commonService.getStringOptionValue(KwellParamEnum.DASHBORAD_VIDEO.getId());
if(StringUtils.isEmpty(path)) {
logger.error("文件路径参数为空,请检查!");
return null;
}
return downloadFile(path);
}
@Override
public void doAttachmentPreview(HttpServletResponse response, FileInputStream fileInputStream) {
try {
BufferedInputStream bis = new BufferedInputStream(fileInputStream);
try {
BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
try {
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
} finally {
bos.close();
}
} finally {
bis.close();
}
} catch (Exception var23) {
this.logger.error("", var23);
}
}
@Override
public String getVideo() {
return commonService.getStringOptionValue(KwellParamEnum.DASHBORAD_VIDEO.getId());
public FileInputStream downloadFile(String path) {
File dataFile = new File(path);
if (dataFile.exists()) {
//获取输入流
FileInputStream inStream = null;
try {
inStream = new FileInputStream(dataFile);
} catch (FileNotFoundException e) {
logger.error(e.getMessage());
}
return inStream;
}
return null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment