| | |
| | | import java.io.OutputStream; |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | @RestController |
| | |
| | | private LocOwnerService locOwnerService; |
| | | @Autowired |
| | | private OrderLogService orderLogService; |
| | | @Autowired |
| | | private OrderDetlLogService orderDetlLogService; |
| | | |
| | | @RequestMapping(value = "/order/all") |
| | | @ManagerAuth |
| | |
| | | |
| | | return R.ok().add(stockStatis); |
| | | } |
| | | // @RequestMapping(value = "/order/export") |
| | | // @ManagerAuth |
| | | // public void orderExport(HttpServletResponse response,OrderExport orderExport) throws IOException { |
| | | // List<OrderDetl> orderNo = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", orderExport.getOrderNo())); |
| | | // |
| | | // response.setContentType("application/vnd.ms-excel"); |
| | | // response.setCharacterEncoding("utf-8"); |
| | | // String templateFileName = |
| | | // this.getClass().getClassLoader().getResource("ru.xlsx").getPath();; |
| | | // |
| | | // String fileName = "complexFill" + System.currentTimeMillis() + ".xlsx"; |
| | | // |
| | | // response.setHeader("Content-disposition", "attachment;filename=" + fileName); |
| | | // ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build(); |
| | | // WriteSheet writeSheet = EasyExcel.writerSheet().build(); |
| | | // // 这里注意 入参用了forceNewRow 代表在写入list的时候不管list下面有没有空行 都会创建一行,然后下面的数据往后移动。默认 是false,会直接使用下一行,如果没有则创建。 |
| | | // // forceNewRow 如果设置了true,有个缺点 就是他会把所有的数据都放到内存了,所以慎用 |
| | | // // 简单的说 如果你的模板有list,且list不是最后一行,下面还有数据需要填充 就必须设置 forceNewRow=true 但是这个就会把所有数据放到内存 会很耗内存 |
| | | // // 如果数据量大 list不是最后一行 参照下一个 |
| | | // FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); |
| | | // excelWriter.fill(orderNo, fillConfig, writeSheet); |
| | | //// excelWriter.fill(orderNo, fillConfig, writeSheet); |
| | | // Map<String, Object> map = new HashMap<String, Object>(); |
| | | // map.put("date", "2019年10月9日13:28:28"); |
| | | // map.put("total", 1000); |
| | | // excelWriter.fill(map, writeSheet); |
| | | // excelWriter.finish(); |
| | | // |
| | | // |
| | | // } |
| | | |
| | | @RequestMapping("/download_excel") |
| | | public void downloadExcel(HttpServletResponse response,@RequestParam String orderNo) throws IOException { |
| | | public void downloadExcel(HttpServletResponse response, |
| | | @RequestParam String orderNo, |
| | | @RequestParam Integer type, |
| | | @RequestParam String name, |
| | | @RequestParam String threeCode) throws IOException { |
| | | |
| | | //获取单据类型 |
| | | DocType docType = docTypeService.selectOne(new EntityWrapper<DocType>().eq("doc_id", type)); |
| | | if (docType.getPakin()==1 && docType.getPakout()==0){ |
| | | type = 1; |
| | | } else if (docType.getPakin()==0 && docType.getPakout()==1) { |
| | | type = 2; |
| | | }else { |
| | | throw new CoolException("单据类型有误"); |
| | | } |
| | | //设置http返回头和文件名 |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | String fileName = "Order " + orderNo + ".xlsx"; |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName); |
| | | |
| | | //excel写入的数据 |
| | | Map<String, Object> map = new HashMap<String, Object>(); |
| | | map.put("orderNo", orderNo); |
| | | map.put("name",name); |
| | | map.put("threeCode",threeCode); |
| | | |
| | | OutputStream outputStream = response.getOutputStream(); |
| | | orderExport(outputStream, orderNo); |
| | | orderExport(outputStream,type,map); |
| | | outputStream.flush(); |
| | | outputStream.close(); |
| | | } |
| | | |
| | | public void orderExport(OutputStream outputStream, String orderNo) throws IOException { |
| | | List<OrderDetl> orderDetls = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", orderNo)); |
| | | public void orderExport(OutputStream outputStream,Integer type,Map<String, Object> map) throws IOException { |
| | | |
| | | String templateFileName = this.getClass().getClassLoader().getResource("ru.xlsx").getPath(); |
| | | //获取订单明细数据 |
| | | List<OrderDetl> orderDetls = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", map.get("orderNo"))); |
| | | List<OrderDetlLog> orderDetlLogs = new ArrayList<>(); |
| | | if (Cools.isEmpty(orderDetls)){ |
| | | orderDetlLogs = orderDetlLogService.selectList(new EntityWrapper<OrderDetlLog>().eq("order_no", map.get("orderNo"))); |
| | | } |
| | | //获取模版路径 |
| | | String templateFileName = null ; |
| | | if (type == 1){ |
| | | templateFileName = this.getClass().getClassLoader().getResource("ru.xlsx").getPath(); |
| | | } else if (type ==2 ) { |
| | | templateFileName = this.getClass().getClassLoader().getResource("cu.xlsx").getPath(); |
| | | } |
| | | |
| | | |
| | | //把文件写入到outputStream中 |
| | | ExcelWriter excelWriter = EasyExcel.write(outputStream).withTemplate(templateFileName).build(); |
| | | WriteSheet writeSheet = EasyExcel.writerSheet().build(); |
| | | FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); |
| | | excelWriter.fill(orderDetls, fillConfig, writeSheet); |
| | | Map<String, Object> map = new HashMap<String, Object>(); |
| | | map.put("date", "2019年10月9日13:28:28"); |
| | | map.put("orderNo", orderNo); |
| | | |
| | | //总计数量,重量 |
| | | BigDecimal sumWeight = new BigDecimal(0); |
| | | BigDecimal sumAnfme = new BigDecimal(0); |
| | | |
| | | if (Cools.isEmpty(orderDetls)){ |
| | | //序号 |
| | | int i = 1; |
| | | for (OrderDetlLog orderDetlLog:orderDetlLogs){ |
| | | orderDetlLog.setThreeCode(map.get("threeCode").toString()); |
| | | orderDetlLog.setDanger(i); |
| | | i++; |
| | | if (Cools.isEmpty(orderDetlLog.getWeight())){ |
| | | orderDetlLog.setWeight(0.0); |
| | | } |
| | | sumWeight = sumWeight.add(BigDecimal.valueOf(orderDetlLog.getWeight())); |
| | | sumAnfme = sumAnfme.add(BigDecimal.valueOf(orderDetlLog.getAnfme())); |
| | | } |
| | | //写入orderDetlLogs中的数据 |
| | | excelWriter.fill(orderDetlLogs, fillConfig, writeSheet); |
| | | map.put("comp",orderDetlLogs.get(0).getOwner$()); |
| | | map.put("sumVol",sumWeight); |
| | | map.put("sumAnfme",sumAnfme); |
| | | }else { |
| | | int i = 1; |
| | | for (OrderDetl orderDetl:orderDetls){ |
| | | orderDetl.setThreeCode(map.get("threeCode").toString()); |
| | | orderDetl.setDanger(i); |
| | | i++; |
| | | if (Cools.isEmpty(orderDetl.getWeight())){ |
| | | orderDetl.setWeight(0.0); |
| | | } |
| | | sumWeight = sumWeight.add(BigDecimal.valueOf(orderDetl.getWeight())); |
| | | sumAnfme = sumAnfme.add(BigDecimal.valueOf(orderDetl.getAnfme())); |
| | | |
| | | } |
| | | excelWriter.fill(orderDetls, fillConfig, writeSheet); |
| | | map.put("comp",orderDetls.get(0).getOwner$()); |
| | | map.put("sumVol",sumWeight); |
| | | map.put("sumAnfme",sumAnfme); |
| | | } |
| | | Date date = new Date(); |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); |
| | | |
| | | map.put("time",dateFormat.format(date)); |
| | | |
| | | //写入map中的数据 |
| | | excelWriter.fill(map, writeSheet); |
| | | excelWriter.finish(); |
| | | } |