| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.ExcelWriter; |
| | | |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | import com.alibaba.excel.write.metadata.fill.FillConfig; |
| | | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | |
| | | import com.sun.org.apache.xpath.internal.operations.Or; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.OrderDomainParam; |
| | | import com.zy.asrs.entity.result.LocDetlAll; |
| | | import com.zy.asrs.entity.result.OrderDetlVo; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.common.CodeRes; |
| | |
| | | import javax.imageio.ImageIO; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | 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 |
| | | public R statis2(@RequestParam(defaultValue = "1")Integer curr, |
| | | @RequestParam(defaultValue = "10")Integer limit, |
| | | @RequestParam Map<String, Object> param) { |
| | | |
| | | |
| | | |
| | | Page<Order> stockStatis = orderService.getOrderAll(toPage(curr, limit, param, Order.class)); |
| | | |
| | | return R.ok().add(stockStatis); |
| | | } |
| | | |
| | | @RequestMapping("/download_excel") |
| | | 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,type,map); |
| | | outputStream.flush(); |
| | | outputStream.close(); |
| | | } |
| | | |
| | | public void orderExport(OutputStream outputStream,Integer type,Map<String, Object> map) throws IOException { |
| | | |
| | | //获取订单明细数据 |
| | | 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(); |
| | | |
| | | //总计数量,重量 |
| | | 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(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/order/nav/list/auth") |
| | | @ManagerAuth |