| | |
| | | package com.consum.base.controller; |
| | | |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.TemplateExportParams; |
| | | import com.consum.base.BaseController; |
| | | import com.consum.base.core.utils.CommonUtil; |
| | | import com.consum.base.core.utils.PageUtil; |
| | | import com.consum.base.pojo.excel.InventoryExcelTemplate; |
| | | import com.consum.base.pojo.query.LWhFormInventoryQry; |
| | | import com.consum.base.pojo.request.FormInventoryParam; |
| | | import com.consum.base.pojo.request.LWhFormInventoryParam; |
| | |
| | | import com.consum.model.po.LWhFormInventory; |
| | | import com.iplatform.model.po.S_user_core; |
| | | import com.walker.db.page.GenericPager; |
| | | import com.walker.infrastructure.utils.CollectionUtils; |
| | | import com.walker.infrastructure.utils.DateUtils; |
| | | import com.walker.web.ResponseValue; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiResponse; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.net.URLEncoder; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.Optional; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | |
| | | return ResponseValue.success(formInventoryVO); |
| | | } |
| | | |
| | | @ApiOperation(value = "盘点单导出", notes = "盘点单导出") |
| | | @GetMapping("/list/export") |
| | | public void export(Long id, HttpServletResponse response) throws IOException { |
| | | |
| | | List<InventoryExcelTemplate> exportList = lWhFormInventoryService.getExportList(id); |
| | | if (CollectionUtils.isEmpty(exportList)) { |
| | | throw new RuntimeException("数据为空"); |
| | | } |
| | | TemplateExportParams params = new TemplateExportParams("import/低值易耗品盘点表.xls"); |
| | | params.setHeadingStartRow(2); |
| | | |
| | | Optional<InventoryExcelTemplate> first = exportList.stream().findFirst(); |
| | | InventoryExcelTemplate inventoryExcelTemplate = first.get(); |
| | | Long createTime = inventoryExcelTemplate.getCreateTime(); |
| | | String operatorName = inventoryExcelTemplate.getOperatorName(); |
| | | String monitorName = inventoryExcelTemplate.getMonitorName(); |
| | | Long endTime = inventoryExcelTemplate.getEndTime(); |
| | | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("date", DateUtils.toShowDate(createTime)); |
| | | map.put("endDate", DateUtils.toShowDate(endTime)); |
| | | map.put("monitorName", monitorName); |
| | | map.put("name", operatorName); |
| | | Workbook workbook = ExcelExportUtil.exportExcel(params, InventoryExcelTemplate.class, |
| | | exportList, map); |
| | | |
| | | downLoadExcel("低值易耗品盘点表", response, workbook); |
| | | } |
| | | |
| | | private void downLoadExcel(String fileName, HttpServletResponse response, Workbook workbook) { |
| | | try (OutputStream out = response.getOutputStream()) { |
| | | response.setCharacterEncoding("UTF-8"); |
| | | response.setHeader("content-Type", "application/vnd.ms-excel"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".xls", "UTF-8")); |
| | | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | workbook.write(baos); |
| | | response.setHeader("Content-Length", String.valueOf(baos.size())); |
| | | out.write(baos.toByteArray()); |
| | | } catch (Exception e) { |
| | | logger.error("导出文件失败", e); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | |