| | |
| | | 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.baomidou.mybatisplus.mapper.Wrapper; |
| | |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.*; |
| | | import com.core.exception.CoolException; |
| | | 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 com.zy.common.config.AdminInterceptor; |
| | | import com.zy.common.model.DetlDto; |
| | | import com.zy.common.utils.BarcodeUtils; |
| | | import com.zy.common.utils.QrCode; |
| | | import com.zy.common.web.BaseController; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | 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 WrkDetlService wrkDetlService; |
| | | @Autowired |
| | | private WaitPakinService waitPakinService; |
| | | @Autowired |
| | | 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 |
| | |
| | | @RequestMapping(value = "/order/detl/all/auth") |
| | | @ManagerAuth |
| | | public R head(@RequestParam Long orderId){ |
| | | return R.ok().add(orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_id", orderId))); |
| | | List<OrderDetl> orderDetls = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_id", orderId)); |
| | | List<OrderDetl> orderDetls1 = new ArrayList<>(); |
| | | for (OrderDetl orderDetl : orderDetls){ |
| | | double v = orderDetl.getAnfme() - orderDetl.getWorkQty(); |
| | | double v1 = new BigDecimal(v).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
| | | if (v1!=0.0){ |
| | | orderDetls1.add(orderDetl); |
| | | } |
| | | } |
| | | return R.ok().add(orderDetls1); |
| | | } |
| | | |
| | | @RequestMapping(value = "/order/form/add/auth") |
| | | @ManagerAuth(memo = "手动添加订单") |
| | | @Transactional |
| | | public R formAdd(@RequestBody OrderDomainParam param){ |
| | | String prefix = ""; |
| | | DocType docType = docTypeService.selectById(param.getDocType()); |
| | | if(!Cools.isEmpty(docType)){ |
| | | prefix = docType.getPakin() == 1 ? "RK" : "CK"; |
| | | } |
| | | if(Cools.isEmpty(param.getOrderNo())){ |
| | | String prefix = ""; |
| | | DocType docType = docTypeService.selectById(param.getDocType()); |
| | | if(!Cools.isEmpty(docType)){ |
| | | prefix = docType.getPakin() == 1 ? "RK" : "CK"; |
| | | } |
| | | param.setOrderNo(prefix + snowflakeIdWorker.nextId()); |
| | | } |
| | | Order order = orderService.selectByNo(param.getOrderNo()); |
| | | OrderLog orderLog = orderLogService.selectByNo(param.getOrderNo()); |
| | | if (order != null) { |
| | | return R.error("单据编号已存在"); |
| | | } |
| | | if (orderLog != null) { |
| | | return R.error("单据编号在历史档中已存在"); |
| | | } |
| | | OrderDetl orderDetl1 = new OrderDetl(); |
| | | for (OrderDetl orderDetl : param.getOrderDetlList()) { |
| | | if (orderDetl1.getId() == null){ |
| | | orderDetl1.sync(orderDetl); |
| | | } |
| | | if (orderDetl1.getOwner() != orderDetl.getOwner()){ |
| | | return R.error("同个单据中只能存在一个货主代码"); |
| | | } |
| | | } |
| | | Date now = new Date(); |
| | | order = new Order( |
| | |
| | | } |
| | | List<DetlDto> list = new ArrayList<>(); |
| | | for (OrderDetl orderDetl : param.getOrderDetlList()) { |
| | | if (Cools.isEmpty(orderDetl.getOwner())){ |
| | | throw new CoolException("保存订单明细档失败,请输入货主编号"); |
| | | }else { |
| | | LocOwner locOwner = locOwnerService.selectById(orderDetl.getOwner()); |
| | | if (Cools.isEmpty(locOwner)){ |
| | | throw new CoolException("保存订单明细档失败,请输入存在的货主编号(整数)"); |
| | | } |
| | | } |
| | | if (orderDetl.getBatch() == null) { |
| | | orderDetl.setBatch(""); |
| | | } |
| | | DetlDto dto = new DetlDto(orderDetl.getMatnr(), orderDetl.getBatch()); |
| | | if (DetlDto.has(list, dto)) { |
| | | OrderDetl item = orderDetlService.selectItem(order.getId(), orderDetl.getMatnr(), orderDetl.getBatch()); |
| | |
| | | orderDetl.setUpdateTime(now); |
| | | orderDetl.setStatus(1); |
| | | orderDetl.setQty(0.0D); |
| | | if(orderDetl.getPayment() == null){ |
| | | orderDetl.setPayment(1); |
| | | } |
| | | orderDetl.setUuid(String.valueOf(System.currentTimeMillis())); |
| | | if (!orderDetlService.insert(orderDetl)) { |
| | | throw new CoolException("保存订单明细档失败"); |
| | | } |
| | |
| | | if (order == null || order.getStatus() == 0) { |
| | | return R.error("订单不存在"); |
| | | } |
| | | |
| | | OrderDetl orderDetl1 = new OrderDetl(); |
| | | for (OrderDetl orderDetl : param.getOrderDetlList()) { |
| | | if (orderDetl1.getId() == null){ |
| | | orderDetl1.sync(orderDetl); |
| | | } |
| | | if (orderDetl1.getOwner() != orderDetl.getOwner()){ |
| | | return R.error("同个单据中只能存在一个货主代码"); |
| | | } |
| | | } |
| | | |
| | | Date now = new Date(); |
| | | Long userId = getUserId(); |
| | | // 修改主档 |
| | |
| | | } |
| | | return R.ok(); |
| | | } |
| | | @RequestMapping(value = "/order/print/auth") |
| | | @ManagerAuth(memo = "订单编码打印") |
| | | public R orderPrint(@RequestParam(value = "param[]") String[] param) { |
| | | if(Cools.isEmpty(param)) { |
| | | return R.parse(CodeRes.EMPTY); |
| | | } |
| | | List<OrderDetl> res = new ArrayList<>(); |
| | | for (String orderNo : param){ |
| | | res = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", orderNo)); |
| | | } |
| | | return R.ok().add(res); |
| | | } |
| | | |
| | | @RequestMapping("/order/in") |
| | | public R in(@RequestBody JSONObject param){ |
| | | System.out.println("111 = " + 111); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/order/printExport/auth") |
| | | // @ManagerAuth(memo = "盘点单导出") |
| | | public void export(HttpServletResponse response, @RequestParam String orderNo) throws IOException { |
| | | //从数据库查询数据 |
| | | EntityWrapper<OrderDetl> locCheckEntityWrapper = new EntityWrapper<>(); |
| | | locCheckEntityWrapper.eq("order_no",orderNo); |
| | | List<OrderDetl> list = orderDetlService.selectList(locCheckEntityWrapper); |
| | | List<OrderDetlVo> orderDetlVos=new ArrayList<>(); |
| | | for (OrderDetl o:list) { |
| | | OrderDetlVo orderDetlVo=new OrderDetlVo(); |
| | | orderDetlVo.setOrderNo(o.getOrderNo()); |
| | | orderDetlVo.setMatnr(o.getMatnr()); |
| | | orderDetlVo.setMaktx(o.getMaktx()); |
| | | orderDetlVo.setSpecs(o.getSpecs()); |
| | | orderDetlVo.setOwner(o.getOwner$()); |
| | | orderDetlVo.setPayment(o.getPayment$()); |
| | | orderDetlVo.setAnfme(o.getAnfme()); |
| | | orderDetlVo.setQty(o.getQty()); |
| | | orderDetlVo.setWorkQty(o.getWorkQty()); |
| | | orderDetlVo.setWeight(o.getWeight()); |
| | | orderDetlVos.add(orderDetlVo); |
| | | } |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | String fileName = URLEncoder.encode("单据", "UTF-8"); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName+ orderNo + ".xlsx"); |
| | | Set<String> includeColumnFiledNames = new HashSet<String>(); |
| | | includeColumnFiledNames.add("orderNo"); |
| | | includeColumnFiledNames.add("matnr"); |
| | | includeColumnFiledNames.add("maktx"); |
| | | includeColumnFiledNames.add("specs"); |
| | | includeColumnFiledNames.add("owner"); |
| | | includeColumnFiledNames.add("payment"); |
| | | includeColumnFiledNames.add("anfme"); |
| | | includeColumnFiledNames.add("qty"); |
| | | includeColumnFiledNames.add("workQty"); |
| | | includeColumnFiledNames.add("weight"); |
| | | EasyExcel.write(response.getOutputStream(), OrderDetlVo.class) |
| | | .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) |
| | | .includeColumnFiledNames(includeColumnFiledNames) |
| | | .sheet("表1") |
| | | .doWrite(orderDetlVos); |
| | | } |
| | | |
| | | @RequestMapping(value = "/order/list/all") |
| | | public R orderList() { |
| | | |
| | | return R.ok(orderService.selectAllorderNo()); |
| | | } |
| | | |
| | | @RequestMapping(value = "/order/list/AllCu") |
| | | @ManagerAuth |
| | | public R orderCuList(@RequestParam(required = false) String orderNo){ |
| | | EntityWrapper<Order> wrapper = new EntityWrapper<>(); |
| | | if (!Cools.isEmpty(orderNo)) { |
| | | wrapper.like("order_no", orderNo); |
| | | } |
| | | wrapper.le("settle", 2).eq("status", 1); |
| | | wrapper.orderBy("create_time", false); |
| | | List<Order> orders = orderService.selectList(wrapper); |
| | | // 保留出库单 |
| | | if (!Cools.isEmpty(orders)) { |
| | | Iterator<Order> iterator = orders.iterator(); |
| | | while (iterator.hasNext()) { |
| | | Order order = iterator.next(); |
| | | if (order.getDocType() != null) { |
| | | DocType docType = docTypeService.selectById(order.getDocType()); |
| | | if (docType != null) { |
| | | if (docType.getPakout() == 1) { |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return R.ok().add(orders); |
| | | } |
| | | |
| | | //订单组托2 |
| | | @RequestMapping(value = "/order/list/orderNo") |
| | | public R orderListorderNo(@RequestParam String orderNo) { |
| | | //数量修改成为完成数量 |
| | | List<OrderDetl> orderDetl1=orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no",orderNo)); |
| | | List<OrderDetl> orderDetls= new ArrayList<OrderDetl>(); |
| | | for (OrderDetl o: orderDetl1) { |
| | | o.setAnfme(o.getAnfme()-o.getWorkQty()); |
| | | BigDecimal c1 = new BigDecimal(o.getAnfme()).setScale(2,BigDecimal.ROUND_HALF_UP); |
| | | o.setAnfme(c1.doubleValue()); |
| | | orderDetls.add(o); |
| | | } |
| | | return R.ok(orderDetls); |
| | | } |
| | | |
| | | @RequestMapping(value = "/order/print2/auth") |
| | | @ManagerAuth(memo = "订单编码打印") |
| | | public R manPakOutPrint(@RequestParam(value = "param[]") String[] param) { |
| | | if(Cools.isEmpty(param)) { |
| | | return R.parse(CodeRes.EMPTY); |
| | | } |
| | | List<OrderDetl> res = new ArrayList<>(); |
| | | for (String orderNo : param){ |
| | | res = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", orderNo)); |
| | | } |
| | | return R.ok().add(res); |
| | | } |
| | | @RequestMapping(value = "/order/code/auth") |
| | | // @ManagerAuth(memo = "物料编码条形码获取(type:1(条形码);2(二维码)") |
| | | public R manPakOutCodeBarcode(@RequestParam(defaultValue = "2") Integer type |
| | | , @RequestParam String param |
| | | , HttpServletResponse response) throws Exception { |
| | | AdminInterceptor.cors(response); |
| | | if (Cools.isEmpty(param)){ |
| | | return R.parse(BaseRes.EMPTY); |
| | | } |
| | | BufferedImage img; |
| | | if (type == 1) { |
| | | img = BarcodeUtils.encode(param); |
| | | } else { |
| | | img = QrCode.createImg(param); |
| | | } |
| | | if (!ImageIO.write(img, "jpg", response.getOutputStream())) { |
| | | throw new IOException("Could not write an image of format jpg"); |
| | | } |
| | | response.getOutputStream().flush(); |
| | | response.getOutputStream().close(); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | |
| | | } |