* 下载银行文件
*/
public String updateCardFile() {
OutputStream os = null;
InputStream is = null;
try {
String cardFileId = request.getParameter("cardFileId");
SimpleDateFormat sdf = new SimpleDateFormat(Const.YYYY_MM_DD_HH_MM_SS);
// SimpleDateFormat sdf = new SimpleDateFormat(Const.YYYY_MM_DD);
// Calendar calendar = Calendar.getInstance(Locale.CHINA);
// calendar.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
// Calendar calendarTwo = Calendar.getInstance(Locale.CHINA);
// calendarTwo.add(Calendar.WEEK_OF_YEAR, -1);
// calendarTwo.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
// String fileName = sdf.format(calendar.getTime());
// filePath = Const.EXCEL_PATH;// Thread.currentThread().getContextClassLoader().getResource(Const.EXCEL_PATH).toString();
// filePath = Const.EXCEL_PATH + fileName + Const.DOT
// + Const.FILE_TYPE_XLS;
// File file = new File(filePath);
// if (!file.exists()) {
// fileName = sdf.format(calendarTwo.getTime());
// filePath = Const.EXCEL_PATH + fileName + Const.DOT
// + Const.FILE_TYPE_XLS;
// }
if(null!=cardFileId&&!"".equals(cardFileId)){
CardFileQuery cardFileQuery = new CardFileQuery();
cardFileQuery.setCard_File_Id(Integer.parseInt(cardFileId));
PageInfo pageInfo = new PageInfo(Integer.MAX_VALUE, Const.DEFAULT_PAGE_NO,Const.DEFAULT_MAX_RECORD);
List<CardFileVO> cardFileVOs = cardFileServiceImpl.getCardFileByList(cardFileQuery, pageInfo);
if(null!=cardFileVOs&&cardFileVOs.size()>0){
CardFileVO cardFileVO = cardFileVOs.get(0);
String path = cardFileVO.getCard_File_Path();
String fileName = cardFileVO.getCard_File_Create_Time();
File file = new File(path);
is = new BufferedInputStream(new FileInputStream(file));
cardFileQuery = new CardFileQuery();
cardFileQuery.setCard_File_Id(cardFileVO.getCard_File_Id());
if(null!=cardFileVO.getCard_File_Update_Count()){
cardFileQuery.setCard_File_Update_Count(cardFileVO.getCard_File_Update_Count()+1);
}else{
cardFileQuery.setCard_File_Update_Count(1);
}
cardFileQuery.setCard_File_Update_Time(sdf.format(new Date()));
cardFileServiceImpl.updateCardFile(cardFileQuery);
byte[] buffer = new byte[is.available()];
is.read(buffer);
// 清空response
response.reset();
response.setContentType(Const.EXCEL_CONTENT_TYPE);// 设置生成的文件类型
response.setHeader("Content-Disposition", "filename="
+ new String(fileName.getBytes(Const.ENCODING_UTF8),
Const.ENCODING_ISO88951) + Const.DOT
+ Const.FILE_TYPE_XLS);// 设置文件头编码方式和文件名
os = response.getOutputStream();
response.setContentType("application/octet-stream");
os.write(buffer);
Utils.insertLogInfo("获取提现自动生成的EXCEL", "相关信息:"+path, Utils.getUserID(request, Const.COOKIEID));
}else{
System.out.println("cardFileVOs为空");
}
}else{
System.out.println("cardFileId为空");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (os != null) {
os.flush();
os.close();
}
if (is != null) {
is.close();
}
} catch (IOException e) {
e.printStackTrace();
}
System.gc();
}
return null;
}
/**
* 下载EXCEL
*/
private void uploadExcel(int cashState) {
OutputStream os = null;
try {
HSSFWorkbook workbook = createCashExcelReport(cashState);
if (workbook != null) {
String fileName = UUID.randomUUID().toString();
response.setContentType(Const.EXCEL_CONTENT_TYPE);// 设置生成的文件类型
response.setHeader("Content-Disposition", "filename="
+ new String(fileName.getBytes(Const.ENCODING_UTF8),
Const.ENCODING_ISO88951) + ".xls");// 设置文件头编码方式和文件名
os = response.getOutputStream();
workbook.write(os);
}
Utils.insertLogInfo("下载提现EXCEL", "提现状态:"+cashState,
Utils.getUserID(request, Const.COOKIEID));
} catch (Exception e) {
e.printStackTrace();
} finally {
if (os != null) {
try {
os.flush();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.gc();
}
}
/**
* 创建提现EXCEL报表
*
* @param cashState
* @return
*/
private HSSFWorkbook createCashExcelReport(int cashState) {
HSSFWorkbook workbook = null;
try {
logger.info("创建Excel");
UserCashDetailQuery query = new UserCashDetailQuery();
query.setCashState(cashState);
PageInfo pageInfo = new PageInfo(Integer.MAX_VALUE, Const.DEFAULT_PAGE_NO, Const.DEFAULT_MAX_RECORD);
List<UserCashDetailVO> lists = pPayAccountServiceImpl
.getUserCashDetailByPage(query, pageInfo);
BigDecimal money = pPayAccountServiceImpl
.getUserCashDetailMoney(query);
String sheetName = cashState == Const.CASE_STATE_ONE ? Const.CASE_STATE_ONE_STR
: cashState == Const.CASE_STATE_TWO ? Const.CASE_STATE_TWO_STR
: cashState == Const.CASE_STATE_THREE ? Const.CASE_STATE_THREE_STR
: cashState == Const.CASE_STATE_FOUR ? Const.CASE_STATE_FOUR_STR
: Const.CASE_STATE_OTHER;
workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet(sheetName);
sheet.setDefaultColumnWidth(15);
sheet.createFreezePane(0, 1);
String[] titles = { "编号", "交易ID", "申请时间", "昵称", "姓名", "银行账号",
"开户行", "金额" };
HSSFRow row = sheet.createRow((short) 0);
if (titles != null && titles.length > 0) {
for (int i = 0; i < titles.length; i++) {
ExcelReportUtil.cteateCell(workbook, row, i, titles[i]);
}
}
if (lists != null && lists.size() > 0) {
int size = lists.size();
for (int i = 0; i < lists.size(); i++) {
int num = i + 1;
row = sheet.createRow((short) num);
UserCashDetailVO userCashDetailVO = lists.get(i);
ExcelReportUtil.cteateCell(workbook, row, 0,
String.valueOf(num));
ExcelReportUtil.cteateCell(workbook, row, 1,
userCashDetailVO.getTradeNum());
ExcelReportUtil.cteateCell(workbook, row, 2,
userCashDetailVO.getApplyTime());
ExcelReportUtil.cteateCell(workbook, row, 3,
userCashDetailVO.getNick());
ExcelReportUtil.cteateCell(workbook, row, 4,
userCashDetailVO.getBackUserName());
ExcelReportUtil.cteateCell(workbook, row, 5,
userCashDetailVO.getBackCardNum());
ExcelReportUtil.cteateCell(workbook, row, 6,
userCashDetailVO.getBankCardName());
ExcelReportUtil.cteateCell(workbook, row, 7, String
.valueOf(userCashDetailVO.getMoney().intValue()));
}
row = sheet.createRow((short) size + 1);
ExcelReportUtil.cteateCell(workbook, row, 6, "总金额:");
ExcelReportUtil.cteateCell(workbook, row, 7,
String.valueOf(money.intValue()));
}
} catch (Exception e) {
e.printStackTrace();
}finally{
System.gc();
}
return workbook;
}