java导出接⼝
/**
* ⾃定义导出过磅记录excel
*
* @param poundLogDto 查询条件
* @return
*/
@RequestMapping(value = "/poundLog/exportCustomExcel", method = {RequestMethod.GET})
@ResponseBody
public Result exportCustomExcel(PoundLogDto poundLogDto) {
//1.获取废品的excel模板
TemplateExportParams params = new TemplateExportParams("doc/customLog.xlsx");
//2.获取所有过磅数据
List<Map<String, Object>> allMap = poundLogService.findAllMapByCondition(poundLogDto, null);
Map<String, Object> map = new HashMap<String, Object>(100);
map.put("poundLogList", allMap);
//3.执⾏excel导出
Workbook workbook = portExcel(params, map);
//4.创建⽂件存储路径
String dateStr = DateUtil.dateString("yyyy_MM_dd", new Date());
File saveFile = new FileLocation() + "/excel/" + dateStr);
if (!ists()) {
saveFile.mkdirs();
}
FileOutputStream fos;
String filePath;
try {
//4.写⼊⽂件
filePath = saveFile + "\\过磅记录.xlsx";
fos = new FileOutputStream(filePath);
workbook.write(fos);
fos.close();
JSONObject data = new JSONObject();
data.put("filepath", filePath);
return ResultUtil.success("数据导出成功!", data);
} catch (FileNotFoundException e) {
el表达式获取map的值<("FileNotFoundException={}", e.getMessage());
("数据导出失败!" + e.getMessage());
} catch (IOException e) {
<("IOException={}", e.getMessage());
("数据导出失败!" + e.getMessage());
}
}
/**
* 获取所有数据封装成mapList
*
* @param poundLogDto 查询条件
* @param types 进出货类型 0:进货 1:出货 null:全选
* @return mapList
*/
@Override
public List<Map<String, Object>> findAllMapByCondition(PoundLogDto poundLogDto, Integer types) {
if (Integer.valueOf(PoundLogConstant.TYPES_IN).equals(types) || Integer.valueOf(PoundLogConstant.TYPES_OUT).equals(types)) { poundLogDto.setTypes(types);
}
List<PoundLog> poundLogList = httpService.findAllLogByCondition(poundLogDto);
if (null == poundLogList) {
return new ArrayList<>(0);
}
List<Map<String, Object>> mapList = new ArrayList<>(poundLogList.size());
for (PoundLog poundLog : poundLogList) {
Map<String, Object> mapOne = new HashMap<>(100);
if (StringUtils.ShopCode())) {
WorkShop workShop = workShopMapper.ShopCode());
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论