public class CloudCustDownloadVO {
/**
* 下载文件名称
*/
private String outputFileName;
/**
* 下载文件内容
*/
private byte[] data;
/**
* Getter method for property <tt>outputFileName</tt>.
*
* @return property value of outputFileName
*/
public String getOutputFileName() {
return outputFileName;
}
/**
* Setter method for property <tt>outputFileName</tt>.
*
* @param outputFileName value to be assigned to property outputFileName
*/
public void setOutputFileName(String outputFileName) {
this.outputFileName = outputFileName;
}
/**
* Getter method for property <tt>data</tt>.
*
* @return property value of data
*/
public byte[] getData() {
return data;
}
/**
* Setter method for property <tt>data</tt>.
*
* @param data value to be assigned to property data
*/
public void setData(byte[] data) {
this.data = data;
}
}
public Result<CloudCustDownloadVO> downloadRecod(Date startTime,Date endTime) throws Exception {
Result<CloudCustDownloadVO> result = new Result<>();
HashMap<String, Object> custParam = Maps.newHashMap();
custParam.put("gmtStart", startTime);
custParam.put("gmtEnd", endTime);
List<questionRecordDO> questionRecordDOS =
questionRecordDAO.selectByQuery(custParam);
//写文件
Workbook wb = assembleQuestionRecord(questionRecordDOS);
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
wb.write(os);
} catch (IOException e) {
logger.error(e);
throw new Exception("下载试算结果错误,文件写入异常");
}
CloudCustDownloadVO downloadVO = new CloudCustDownloadVO();
downloadVO.setData(os.toByteArray());
downloadVO.setOutputFileName("result_" + DateUtil.getLongDateString(startTime) + "-"
+ DateUtil.getLongDateString(endTime) + ".xlsx");
result.setSuccess(true);
result.setResultObj(downloadVO);
return result;
}