use of com.itrus.portal.utils.ExcelFileGenerator in project portal by ixinportal.
the class StoreBillController method excelExport.
/**
* @param serviceClientId
* @param statPeriod
* @param queryDate1
* @param queryDate2
* @param serviceName
* @param userGe
* @param accountingStrategy
* @param request
* @param response
* @return
*/
@RequestMapping("/excel")
public String excelExport(@RequestParam(value = "appId", required = false) Long appId, @RequestParam(value = "serviceClientId", required = false) Long serviceClientId, @RequestParam(value = "statPeriod", required = false) Long statPeriod, @RequestParam(value = "months", required = false) Long months, @RequestParam(value = "quarters", required = false) Long quarters, @RequestParam(value = "queryDate1", required = false) Integer queryDate1, @RequestParam(value = "queryDate2", required = false) Integer queryDate2, @RequestParam(value = "userGe", required = false) Long userGe, @RequestParam(value = "accountingStrategy", required = false) Long accountingStrategy, HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
boolean isEmpty = false;
String serviceName = new String((request.getParameter("serviceName")).getBytes("ISO-8859-1"), "UTF-8");
Map<String, Object> param = new HashMap<>();
// 应用id
if (appId != null) {
param.put("appId", appId);
}
// 服务委托人
if (serviceClientId != null) {
param.put("serviceClientId", serviceClientId);
}
// 统计周期
if (null != statPeriod) {
param.put("period", statPeriod);
} else {
param.put("period", 1);
}
// 月份 当统计周期为月的时候
if (null != months) {
param.put("months", months);
}
// 季度 当统计周期为季度的时候
if (null != quarters) {
param.put("quarters", quarters);
}
// 统计时间 默认从2017年开始有计费服务
if (null != queryDate1) {
param.put("queryDate1", queryDate1);
}
if (null != queryDate2) {
param.put("queryDate2", queryDate2);
} else {
param.put("queryDate2", 2017);
}
// 服务名称
if (serviceName != null && !"".equals(serviceName)) {
param.put("serviceName", "%" + serviceName + "%");
}
// 使用用途
if (null != userGe) {
param.put("userGe", userGe);
}
// 计费策略
if (null != accountingStrategy) {
param.put("accountingStrategy", accountingStrategy);
}
// 存证
param.put("chargingType", ComNames.SERVICE_TYPE_STORE);
// 查询服务名称信息,无返回 返回空界面
List<Long> serviceLists = sqlSession.selectList("com.itrus.portal.db.ChargingMapper.selectStoreServiceId", param);
if (serviceLists != null && serviceLists.size() > 0) {
param.put("serviceLists", serviceLists);
} else {
isEmpty = true;
}
String connSql = chargService.connSql(statPeriod, new Long(queryDate1), new Long(queryDate2));
param.put("connSql", connSql);
List<Map<String, Object>> cAll = sqlSession.selectList("com.itrus.portal.db.ChargingMapper.selectStoreByCondition", param);
cAll = chargService.explainBillService(cAll);
cAll = chargService.explainBillCode(cAll);
if (cAll != null && cAll.size() > 0) {
// 增加总计行
cAll = chargService.addBillTotalRow(cAll);
}
if (!isEmpty) {
// 创建excel标头
ArrayList<String> fildName = chargService.excelStoreBillFildName(statPeriod);
// 导入内容
ArrayList<ArrayList<String>> excelFildData = chargService.excelStoreFildData(cAll);
ExcelFileGenerator generator = new ExcelFileGenerator(fildName, excelFildData);
try {
// 重置response对象中的缓冲区,该方法可以不写,但是你要保证response缓冲区没有其他数据,否则导出可能会出现问题,建议加上
response.reset();
String filename = "存证服务账单" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + // 设置下载时客户端Excel的名称,此处需要用到encodeFilename()方法来转换编码,否则中文会被过滤掉
".xls";
filename = generator.encodeFilename(filename, request);
response.setHeader("Content-disposition", "attachment;filename=" + filename);
response.setCharacterEncoding("utf-8");
// 由于导出格式是excel的文件,设置导出文件的响应头部信息
response.setContentType("application/vnd.ms-excel");
// 生成excel,传递输出流
// 用response对象获取输出流
OutputStream os = response.getOutputStream();
generator.expordExcel(os);
// 清理刷新缓冲区,将缓存中的数据将数据导出excel
os.flush();
// 关闭os
if (os != null) {
os.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
use of com.itrus.portal.utils.ExcelFileGenerator in project portal by ixinportal.
the class MakeCertController method excelExport.
// 导出Excel
@RequestMapping(value = "/excel")
public String excelExport(@RequestParam(value = "billNo", required = false) String billNo, @RequestParam(value = "keySn", required = false) String keySn, @RequestParam(value = "projectName", required = false) String projectName, @RequestParam(value = "enterpriseName", required = false) String enterpriseName, @RequestParam(value = "queryDate1", required = false) Date queryDate1, @RequestParam(value = "queryDate2", required = false) Date queryDate2, @RequestParam(value = "businessType", required = false) Integer businessType, @RequestParam(value = "type", required = false) Integer type, HttpServletRequest request, HttpServletResponse response, Model uiModel) {
Map<String, Object> param1 = new HashMap<String, Object>();
// 管理员项目权限
Long[] projectsOfAdmin = getProjectLongIdsOfAdmin();
param1.put("hasProjects", Arrays.asList(projectsOfAdmin));
if (queryDate1 == null && queryDate2 == null) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.add(Calendar.MILLISECOND, -1);
queryDate2 = calendar.getTime();
calendar.add(Calendar.MILLISECOND, 1);
calendar.add(Calendar.MONTH, -1);
queryDate1 = calendar.getTime();
}
param1.put("queryDate1", queryDate1);
param1.put("queryDate2", queryDate2);
if (StringUtils.isNotEmpty(billNo)) {
param1.put("billNo", "%" + billNo + "%");
}
if (StringUtils.isNotEmpty(projectName)) {
param1.put("projectName", "%" + projectName + "%");
}
if (StringUtils.isNotEmpty(enterpriseName)) {
param1.put("enterpriseName", "%" + enterpriseName + "%");
}
if (StringUtils.isNotBlank(keySn)) {
param1.put("keySn", "%" + keySn + "%");
}
param1.put("billStatus", ComNames.BILL_STATUS_6);
if (type != null) {
if (type >= 0 && type < 3) {
param1.put("initBuy", type);
}
if (type == 3) {
param1.put("updateWay", 0);
}
}
param1.put("businessType", businessType);
// Integer count = sqlSession.selectOne("com.itrus.portal.db.BillMapper.selectCountByMakeCert", param1);
List<Map> makecertexall = sqlSession.selectList("com.itrus.portal.db.BillMapper.selectByAllMakeCert", param1);
Map<String, List<Map>> listmake = new HashMap<String, List<Map>>();
// 获取证书信息
for (int i = 0; i < makecertexall.size(); i++) {
// System.out.println("mid"+makecertexall.get(i).get("id"));
List makecertexall2 = sqlSession.selectList("com.itrus.portal.db.UserCertMapper.selectByPrimaryBillKey1", makecertexall.get(i).get("id"));
// System.out.println(makecertexall2.size());
listmake.put(makecertexall.get(i).get("id").toString(), makecertexall2);
}
ArrayList<String> fieldName = makeCerServiceImpl.excelFieldName();
ArrayList<ArrayList<String>> fieldDatas = makeCerServiceImpl.excelFieldData(makecertexall, listmake);
ExcelFileGenerator generator = new ExcelFileGenerator(fieldName, fieldDatas);
try {
// 重置response对象中的缓冲区,该方法可以不写,但是你要保证response缓冲区没有其他数据,否则导出可能会出现问题,建议加上
response.reset();
// 设置下载时客户端Excel的名称,此处需要用到encodeFilename()方法来转换编码,否则中文会被过滤掉
String filename = "已制证信息" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".xls";
filename = generator.encodeFilename(filename, request);
response.setHeader("Content-disposition", "attachment;filename=" + filename);
response.setCharacterEncoding("utf-8");
// 由于导出格式是excel的文件,设置导出文件的响应头部信息
response.setContentType("application/vnd.ms-excel");
// 生成excel,传递输出流
// 用response对象获取输出流
OutputStream os = response.getOutputStream();
generator.expordExcel(os);
// 清理刷新缓冲区,将缓存中的数据将数据导出excel
os.flush();
// 关闭os
if (os != null) {
os.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of com.itrus.portal.utils.ExcelFileGenerator in project portal by ixinportal.
the class MessageStatsController method excelExport.
// 导出Excel
@RequestMapping(value = "/excel")
public String excelExport(@RequestParam(value = "cycle_sel", required = false) Integer cycle, @RequestParam(value = "applicationName", required = false) Long applicationName, @RequestParam(value = "year1_sel", required = false) Integer year1, @RequestParam(value = "year2_sel", required = false) Integer year2, @RequestParam(value = "type", required = false) Integer type, @RequestParam(value = "status_sel", required = false) Integer status_sel, Model uiModel, HttpServletRequest request, HttpServletResponse response) throws Exception {
Map param = new HashMap();
Map param2 = new HashMap();
Integer year3 = null;
if (year1 != null) {
year3 = year1;
}
List<Map<Integer, Integer>> list = new ArrayList<Map<Integer, Integer>>();
java.util.Date nowdate = new java.util.Date();
String[] monthList = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" };
String[] seasonList = { "S1", "S2", "S3", "S4" };
String month = null;
String season = null;
String year = null;
Calendar calendar = Calendar.getInstance();
Calendar calendar2 = Calendar.getInstance();
String applicationName1 = null;
if (null != cycle && cycle == 12) {
while (year1 <= year2) {
for (int j = 0; j <= 11; j++) {
calendar.set(Calendar.YEAR, year1);
calendar.set(Calendar.MONTH, j);
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
// calendar.add(Calendar.MILLISECOND, -1);
Date dt1 = calendar.getTime();
calendar2.set(Calendar.YEAR, year1);
calendar2.set(Calendar.MONTH, j + 1);
calendar2.set(Calendar.DAY_OF_MONTH, 1);
calendar2.set(Calendar.HOUR_OF_DAY, 0);
calendar2.set(Calendar.MINUTE, 0);
calendar2.set(Calendar.SECOND, 0);
calendar2.set(Calendar.MILLISECOND, 0);
// calendar2.add(Calendar.MILLISECOND, -1);
Date dt2 = calendar2.getTime();
if (applicationName != null && applicationName != 0) {
AppConfig application = sqlSession.selectOne("com.itrus.portal.db.AppConfigMapper.selectByPrimaryKey", applicationName);
applicationName1 = application.getAppName();
param.put("applicationName", applicationName);
}
param2.put("applicationName", applicationName);
param2.put("type", type);
if (status_sel != null && status_sel != 2) {
param.put("gate", status_sel);
} else {
param.put("gate", null);
}
param2.put("gate", status_sel);
if (dt2.before(nowdate)) {
month = year1 + "-" + monthList[j];
param2.put("month", month);
MsgStatsRecord msr = sqlSession.selectOne("com.itrus.portal.db.MsgStatsRecordMapper.selectByMonth1", param2);
if (null != msr) {
Integer count = msr.getCount1();
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
map.put(count, year1);
list.add(map);
} else {
param.put("queryDate1", dt1);
param.put("queryDate2", dt2);
Integer count = sqlSession.selectOne("com.itrus.portal.db.AppConfigMapper.selectCountByPeriod", param);
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
map.put(count, year1);
list.add(map);
MsgStatsRecord msr2 = new MsgStatsRecord();
msr2.setMonth1(month);
msr2.setAppId(applicationName);
msr2.setCount1(count);
msr2.setType(type);
msr2.setGate(status_sel);
msr2.setCreateTime(new Date());
sqlSession.insert("com.itrus.portal.db.MsgStatsRecordMapper.insert", msr2);
}
} else {
param.put("queryDate1", dt1);
param.put("queryDate2", dt2);
Integer count = sqlSession.selectOne("com.itrus.portal.db.AppConfigMapper.selectCountByPeriod", param);
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
map.put(count, year1);
list.add(map);
}
}
year1++;
}
}
if (null != cycle && cycle == 4) {
while (year1 <= year2) {
for (int j = 0; j <= 9; j = j + 3) {
calendar.set(Calendar.YEAR, year1);
calendar.set(Calendar.MONTH, j);
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
// calendar.add(Calendar.MILLISECOND, -1);
Date dt1 = calendar.getTime();
calendar2.set(Calendar.YEAR, year1);
calendar2.set(Calendar.MONTH, j + 3);
calendar2.set(Calendar.DAY_OF_MONTH, 1);
calendar2.set(Calendar.HOUR_OF_DAY, 0);
calendar2.set(Calendar.MINUTE, 0);
calendar2.set(Calendar.SECOND, 0);
calendar2.set(Calendar.MILLISECOND, 0);
// calendar2.add(Calendar.MILLISECOND, -1);
Date dt2 = calendar2.getTime();
if (applicationName != null && applicationName != 0) {
AppConfig application = sqlSession.selectOne("com.itrus.portal.db.AppConfigMapper.selectByPrimaryKey", applicationName);
applicationName1 = application.getAppName();
param.put("applicationName", applicationName);
}
param2.put("applicationName", applicationName);
param2.put("type", type);
if (status_sel != null && status_sel != 2) {
param.put("gate", status_sel);
} else {
param.put("gate", null);
}
param2.put("gate", status_sel);
if (dt2.before(nowdate)) {
season = year1 + "-" + seasonList[j / 3];
param2.put("season", season);
MsgStatsRecord msr = sqlSession.selectOne("com.itrus.portal.db.MsgStatsRecordMapper.selectBySeason2", param2);
if (null != msr) {
Integer count = msr.getCount1();
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
map.put(count, year1);
list.add(map);
} else {
param.put("queryDate1", dt1);
param.put("queryDate2", dt2);
Integer count = sqlSession.selectOne("com.itrus.portal.db.AppConfigMapper.selectCountByPeriod", param);
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
map.put(count, year1);
list.add(map);
MsgStatsRecord msr2 = new MsgStatsRecord();
msr2.setSeason1(season);
msr2.setAppId(applicationName);
msr2.setCount1(count);
msr2.setType(type);
msr2.setGate(status_sel);
msr2.setCreateTime(new Date());
sqlSession.insert("com.itrus.portal.db.MsgStatsRecordMapper.insert", msr2);
}
} else {
param.put("queryDate1", dt1);
param.put("queryDate2", dt2);
Integer count = sqlSession.selectOne("com.itrus.portal.db.AppConfigMapper.selectCountByPeriod", param);
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
map.put(count, year1);
list.add(map);
}
}
year1++;
}
}
if (null != cycle && cycle == 1) {
while (year1 <= year2) {
calendar.set(Calendar.YEAR, year1);
calendar.set(Calendar.MONTH, 0);
calendar.set(Calendar.DATE, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
// calendar.add(Calendar.MILLISECOND, -1);
Date dt1 = calendar.getTime();
calendar2.set(Calendar.YEAR, year1 + 1);
calendar2.set(Calendar.MONTH, 0);
calendar2.set(Calendar.DAY_OF_MONTH, 1);
calendar2.set(Calendar.HOUR_OF_DAY, 0);
calendar2.set(Calendar.MINUTE, 0);
calendar2.set(Calendar.SECOND, 0);
calendar2.set(Calendar.MILLISECOND, 0);
// calendar2.add(Calendar.MILLISECOND, -1);
Date dt2 = calendar2.getTime();
if (applicationName != null && applicationName != 0) {
AppConfig application = sqlSession.selectOne("com.itrus.portal.db.AppConfigMapper.selectByPrimaryKey", applicationName);
applicationName1 = application.getAppName();
param.put("applicationName", applicationName);
}
param2.put("applicationName", applicationName);
param2.put("type", type);
if (status_sel != null && status_sel != 2) {
param.put("gate", status_sel);
} else {
param.put("gate", null);
}
param2.put("gate", status_sel);
if (dt2.before(nowdate)) {
year = year1 + "Y";
param2.put("year", year);
MsgStatsRecord msr = sqlSession.selectOne("com.itrus.portal.db.MsgStatsRecordMapper.selectByYear1", param2);
if (null != msr) {
Integer count = msr.getCount1();
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
map.put(count, year1);
list.add(map);
} else {
param.put("queryDate1", dt1);
param.put("queryDate2", dt2);
Integer count = sqlSession.selectOne("com.itrus.portal.db.AppConfigMapper.selectCountByPeriod", param);
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
map.put(count, year1);
list.add(map);
MsgStatsRecord msr2 = new MsgStatsRecord();
msr2.setYear1(year);
msr2.setAppId(applicationName);
msr2.setCount1(count);
msr2.setType(type);
msr2.setGate(status_sel);
msr2.setCreateTime(new Date());
sqlSession.insert("com.itrus.portal.db.MsgStatsRecordMapper.insert", msr2);
}
} else {
param.put("queryDate1", dt1);
param.put("queryDate2", dt2);
Integer count = sqlSession.selectOne("com.itrus.portal.db.AppConfigMapper.selectCountByPeriod", param);
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
map.put(count, year1);
list.add(map);
}
year1++;
}
}
if (null == applicationName || 0 == applicationName) {
applicationName1 = "所有应用";
}
String sgName = "";
if (status_sel == 0)
sgName = "亿美";
if (status_sel == 1)
sgName = "未来无线";
if (status_sel == 2)
sgName = "所有端口";
ArrayList<String> fieldName = messageStatsService.excelFieldName();
ArrayList<ArrayList<String>> fieldDatas = messageStatsService.excelFieldData(list, applicationName1, cycle, sgName);
ExcelFileGenerator generator = new ExcelFileGenerator(fieldName, fieldDatas);
try {
// 重置response对象中的缓冲区,该方法可以不写,但是你要保证response缓冲区没有其他数据,否则导出可能会出现问题,建议加上
response.reset();
String filename = "短信统计信息" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + // 设置下载时客户端Excel的名称,此处需要用到encodeFilename()方法来转换编码,否则中文会被过滤掉
".xls";
filename = generator.encodeFilename(filename, request);
response.setHeader("Content-disposition", "attachment;filename=" + filename);
response.setCharacterEncoding("utf-8");
// 由于导出格式是excel的文件,设置导出文件的响应头部信息
response.setContentType("application/vnd.ms-excel");
// 生成excel,传递输出流
// 用response对象获取输出流
OutputStream os = response.getOutputStream();
generator.expordExcel(os);
// 清理刷新缓冲区,将缓存中的数据将数据导出excel
os.flush();
// 关闭os
if (os != null) {
os.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of com.itrus.portal.utils.ExcelFileGenerator in project portal by ixinportal.
the class BillController method excelExport.
// 导出Excel
@RequestMapping(value = "/excel")
public String excelExport(@RequestParam(value = "sn", required = false) String sn, @RequestParam(value = "projectname", required = false) String projectname, @RequestParam(value = "entname", required = false) String entname, @RequestParam(value = "cost", required = false) Integer cost, @RequestParam(value = "queryDate1", required = false) Date queryDate1, @RequestParam(value = "queryDate2", required = false) Date queryDate2, @RequestParam(value = "type1", required = false) Integer type1, @RequestParam(value = "name", required = false) String name, @RequestParam(value = "phone", required = false) String phone, @RequestParam(value = "status", required = false) Integer status, HttpServletRequest request, HttpServletResponse response) {
Map param = new HashMap();
// 管理员项目权限
Long[] projectsOfAdmin = getProjectLongIdsOfAdmin();
param.put("hasProjects", Arrays.asList(projectsOfAdmin));
if (StringUtils.isNotEmpty(sn)) {
param.put("sn", "%" + sn + "%");
}
param.put("queryDate1", queryDate1);
param.put("queryDate2", queryDate2);
if (StringUtils.isNotEmpty(projectname)) {
param.put("projectname", "%" + projectname + "%");
}
if (StringUtils.isNotEmpty(entname)) {
param.put("entname", "%" + entname + "%");
}
param.put("type", type1);
if (StringUtils.isNotEmpty(name)) {
param.put("name", "%" + name + "%");
}
if (StringUtils.isNotEmpty(phone)) {
param.put("phone", "%" + phone + "%");
}
param.put("status", status);
param.put("desc", 1);
List<Map> billexall = sqlSession.selectList("com.itrus.portal.db.BillMapper.selectByCondition", param);
ArrayList<String> fieldName = billservice.excelFildName();
ArrayList<ArrayList<String>> fieldDatas = billservice.excelFildData(billexall);
ExcelFileGenerator generator = new ExcelFileGenerator(fieldName, fieldDatas);
try {
// 重置response对象中的缓冲区,该方法可以不写,但是你要保证response缓冲区没有其他数据,否则导出可能会出现问题,建议加上
response.reset();
// 设置下载时客户端Excel的名称,此处需要用到encodeFilename()方法来转换编码,否则中文会被过滤掉
String filename = "用户信息" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".xls";
filename = generator.encodeFilename(filename, request);
response.setHeader("Content-disposition", "attachment;filename=" + filename);
response.setCharacterEncoding("utf-8");
// 由于导出格式是excel的文件,设置导出文件的响应头部信息
response.setContentType("application/vnd.ms-excel");
// 生成excel,传递输出流
// 用response对象获取输出流
OutputStream os = response.getOutputStream();
generator.expordExcel(os);
// 清理刷新缓冲区,将缓存中的数据将数据导出excel
os.flush();
// 关闭os
if (os != null) {
os.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of com.itrus.portal.utils.ExcelFileGenerator in project portal by ixinportal.
the class BillReceiptController method excelExport.
// 导出Excel
@RequestMapping(value = "/excel")
public String excelExport(@RequestParam(value = "billNo", required = false) String billNo, @RequestParam(value = "projectName", required = false) String projectName, @RequestParam(value = "enterpriseName", required = false) String enterpriseName, @RequestParam(value = "cost", required = false) Integer cost, @RequestParam(value = "queryDate1", required = false) Date queryDate1, @RequestParam(value = "queryDate2", required = false) Date queryDate2, HttpServletRequest request, HttpServletResponse response) {
Map param = new HashMap();
// 管理员项目权限
Long[] projectsOfAdmin = getProjectLongIdsOfAdmin();
param.put("hasProjects", Arrays.asList(projectsOfAdmin));
if (org.apache.commons.lang3.StringUtils.isNotEmpty(billNo)) {
param.put("billNo", "%" + billNo + "%");
}
if (org.apache.commons.lang3.StringUtils.isNotEmpty(projectName)) {
param.put("projectName", "%" + projectName + "%");
}
if (org.apache.commons.lang3.StringUtils.isNotEmpty(enterpriseName)) {
param.put("enterpriseName", "%" + enterpriseName + "%");
}
param.put("queryDate1", queryDate1);
param.put("queryDate2", queryDate2);
List<Map> billexall = sqlSession.selectList("com.itrus.portal.db.BillMapper.selectExcelByBillReceipt", param);
ArrayList<String> fieldName = billReceiptService.excelFieldName();
ArrayList<ArrayList<String>> fieldDatas = billReceiptService.excelFieldData(billexall);
ExcelFileGenerator generator = new ExcelFileGenerator(fieldName, fieldDatas);
try {
// 重置response对象中的缓冲区,该方法可以不写,但是你要保证response缓冲区没有其他数据,否则导出可能会出现问题,建议加上
response.reset();
String filename = "凭证纸票开票信息" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + // 设置下载时客户端Excel的名称,此处需要用到encodeFilename()方法来转换编码,否则中文会被过滤掉
".xls";
filename = generator.encodeFilename(filename, request);
response.setHeader("Content-disposition", "attachment;filename=" + filename);
response.setCharacterEncoding("utf-8");
// 由于导出格式是excel的文件,设置导出文件的响应头部信息
response.setContentType("application/vnd.ms-excel");
// 生成excel,传递输出流
// 用response对象获取输出流
OutputStream os = response.getOutputStream();
generator.expordExcel(os);
// 清理刷新缓冲区,将缓存中的数据将数据导出excel
os.flush();
// 关闭os
if (os != null) {
os.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Aggregations