Commit d2837c7a authored by zhoumaotao's avatar zhoumaotao

文件流传入

parent 29097f3b
...@@ -2,13 +2,11 @@ package com.gavel.kwell.controller; ...@@ -2,13 +2,11 @@ package com.gavel.kwell.controller;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.gavel.common.base.controller.BaseController; import com.gavel.common.base.controller.BaseController;
import com.gavel.common.utils.ThreadContext;
import com.gavel.kwell.service.KmesBoardService; import com.gavel.kwell.service.KmesBoardService;
import com.gavel.kwell.vo.GpfkHgVO; import com.gavel.kwell.vo.GpfkHgVO;
import com.gavel.kwell.vo.PcslVO; import com.gavel.kwell.vo.PcslVO;
import com.gavel.kwell.vo.SdclVO; import com.gavel.kwell.vo.SdclVO;
import com.gavel.kwell.vo.UWoVO; import com.gavel.kwell.vo.UWoVO;
import com.gavel.wo.persistent.Pcjhmx;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
...@@ -16,6 +14,8 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -16,6 +14,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.util.List; import java.util.List;
@Controller @Controller
...@@ -127,25 +127,24 @@ public class KmesBoardController extends BaseController { ...@@ -127,25 +127,24 @@ public class KmesBoardController extends BaseController {
/** /**
* 视频路径api * pdf路径api
*/ */
@RequestMapping(value ="getPdf", method = RequestMethod.POST) @RequestMapping(value ="getPdf")
@ResponseBody public void getPdf(HttpServletResponse response) {
public Object getPdf(@RequestBody JSONObject param) { FileInputStream fileInputStream = kmesBoardService.getPdf();
returnData().add("pdf", kmesBoardService.getPdf()); kmesBoardService.doAttachmentPreview(response, fileInputStream);
return ThreadContext.getReturnData();
} }
/** /**
* 视频路径api * 视频路径api
*/ */
@RequestMapping(value ="getVideo", method = RequestMethod.POST) @RequestMapping(value ="getVideo")
@ResponseBody public void getVideo(HttpServletResponse response) {
public Object getVideo(@RequestBody JSONObject param) { FileInputStream fileInputStream = kmesBoardService.getVideo();
returnData().add("video", kmesBoardService.getVideo()); kmesBoardService.doAttachmentPreview(response, fileInputStream);
return ThreadContext.getReturnData();
} }
} }
...@@ -7,6 +7,8 @@ import com.gavel.kwell.vo.SdclVO; ...@@ -7,6 +7,8 @@ import com.gavel.kwell.vo.SdclVO;
import com.gavel.kwell.vo.UWoVO; import com.gavel.kwell.vo.UWoVO;
import com.gavel.wo.persistent.Pcjhmx; import com.gavel.wo.persistent.Pcjhmx;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.util.List; import java.util.List;
...@@ -26,7 +28,11 @@ public interface KmesBoardService extends BaseEditService { ...@@ -26,7 +28,11 @@ public interface KmesBoardService extends BaseEditService {
public List<GpfkHgVO> queryGpfkHgl(); 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; ...@@ -4,6 +4,7 @@ import com.gavel.common.base.service.impl.BaseEditServiceImpl;
import com.gavel.common.business.service.CommonService; import com.gavel.common.business.service.CommonService;
import com.gavel.common.utils.DateUtils; import com.gavel.common.utils.DateUtils;
import com.gavel.common.utils.NumberUtils; import com.gavel.common.utils.NumberUtils;
import com.gavel.common.utils.StringUtils;
import com.gavel.kwell.dao.GpfkcxDao; import com.gavel.kwell.dao.GpfkcxDao;
import com.gavel.kwell.dao.KmesBoardDao; import com.gavel.kwell.dao.KmesBoardDao;
import com.gavel.kwell.persistent.Gpfk; import com.gavel.kwell.persistent.Gpfk;
...@@ -15,10 +16,14 @@ import com.gavel.kwell.vo.PcslVO; ...@@ -15,10 +16,14 @@ import com.gavel.kwell.vo.PcslVO;
import com.gavel.kwell.vo.SdclVO; import com.gavel.kwell.vo.SdclVO;
import com.gavel.kwell.vo.UWoVO; import com.gavel.kwell.vo.UWoVO;
import com.gavel.wo.persistent.Pcjhmx; import com.gavel.wo.persistent.Pcjhmx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
...@@ -29,6 +34,9 @@ import java.util.List; ...@@ -29,6 +34,9 @@ import java.util.List;
@Transactional @Transactional
public class KmesBoardServiceImpl extends BaseEditServiceImpl implements KmesBoardService { public class KmesBoardServiceImpl extends BaseEditServiceImpl implements KmesBoardService {
private Logger logger = LoggerFactory.getLogger(KmesBoardServiceImpl.class);
@Autowired @Autowired
private KmesBoardDao kmesBoardDao; private KmesBoardDao kmesBoardDao;
...@@ -135,12 +143,64 @@ public class KmesBoardServiceImpl extends BaseEditServiceImpl implements KmesBoa ...@@ -135,12 +143,64 @@ public class KmesBoardServiceImpl extends BaseEditServiceImpl implements KmesBoa
} }
@Override @Override
public String getPdf() { public FileInputStream getPdf() {
return commonService.getStringOptionValue(KwellParamEnum.DASHBORAD_PDF.getId()); 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 @Override
public String getVideo() { public FileInputStream downloadFile(String path) {
return commonService.getStringOptionValue(KwellParamEnum.DASHBORAD_VIDEO.getId()); 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