|  |  |  | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestParam; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<OrderDetl> orderDetls = orderDetlService.selectBatchIds(ids); | 
|---|
|  |  |  | List<LocDto> locDtos = new ArrayList<>(); | 
|---|
|  |  |  | for (OrderDetl o: orderDetls) { | 
|---|
|  |  |  | if (o.getAnfme().equals(o.getWorkQty())){ | 
|---|
|  |  |  | return R.error("出库的明细中有已出库物料"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Set<String> exist = new HashSet<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (OrderDetl orderDetl : orderDetls) { | 
|---|
|  |  |  | double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getQty()).orElse(0.0D); | 
|---|
|  |  |  | BigDecimal a1 = new BigDecimal(orderDetl.getAnfme()).setScale(2,BigDecimal.ROUND_HALF_UP); | 
|---|
|  |  |  | BigDecimal b1 = new BigDecimal(orderDetl.getQty()).setScale(2,BigDecimal.ROUND_HALF_UP); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getWorkQty()).orElse(0.0D); | 
|---|
|  |  |  | if (issued <= 0.0D) { continue; } | 
|---|
|  |  |  | List<LocDetl> locDetls = locDetlService.queryStock2(orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getOwner()); | 
|---|
|  |  |  | for (LocDetl locDetl : locDetls) { | 
|---|
|  |  |  | List<ManLocDetl> manLocDetls = manLocDetlService.queryStock(orderDetl.getMatnr(),orderDetl.getBatch()); | 
|---|
|  |  |  | for (ManLocDetl locDetl : manLocDetls) { | 
|---|
|  |  |  | if (issued > 0) { | 
|---|
|  |  |  | LocDto locDto = new LocDto(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getMaktx(), locDetl.getBatch(), orderDetl.getOrderNo(), | 
|---|
|  |  |  | issued >= locDetl.getAnfme() ? locDetl.getAnfme() : issued,locDetl.getOwner(),locDetl.getPayment()); | 
|---|
|  |  |  | List<Integer> staNos = staDescService.queryOutStaNosByLocNo(locDetl.getLocNo(), issued >= locDetl.getAnfme() ? 101 : 103); | 
|---|
|  |  |  | boolean sign = false; | 
|---|
|  |  |  | if (issued > locDetl.getAnfme() || locDetl.getAnfme().equals(issued)){ | 
|---|
|  |  |  | sign=true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | LocDto locDto = new LocDto(locDetl.getHostId(),locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getMaktx(), locDetl.getBatch(), orderDetl.getOrderNo(), | 
|---|
|  |  |  | sign ? locDetl.getAnfme() : issued,"平库"); | 
|---|
|  |  |  | List<Integer> staNos = staDescService.queryOutStaNosByLocNo(locDetl.getLocNo(),  sign? 101 : 103); | 
|---|
|  |  |  | //                    LocDto locDto = new LocDto(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getMaktx(), locDetl.getBatch(), orderDetl.getOrderNo(), | 
|---|
|  |  |  | //                            locDetl.getAnfme(), issued < locDetl.getAnfme()? issued : locDetl.getAnfme()); | 
|---|
|  |  |  | //                    //速腾只有全板,所以只能101全板出库 | 
|---|
|  |  |  | //                    List<Integer> staNos = staDescService.queryOutStaNosByLocNo(locDetl.getLocNo(), 101); | 
|---|
|  |  |  | locDto.setStaNos(staNos); | 
|---|
|  |  |  | locDto.setManu(locDetl.getManu()); | 
|---|
|  |  |  | locDtos.add(locDto); | 
|---|
|  |  |  | exist.add(locDetl.getLocNo()); | 
|---|
|  |  |  | BigDecimal iss=new BigDecimal(Double.toString(issued)).setScale(2,BigDecimal.ROUND_HALF_UP); | 
|---|
|  |  |  | BigDecimal an=new BigDecimal(Double.toString(locDetl.getAnfme())).setScale(2,BigDecimal.ROUND_HALF_UP); | 
|---|
|  |  |  | // 剩余待出数量递减 | 
|---|
|  |  |  | issued = issued - locDetl.getAnfme(); | 
|---|
|  |  |  | issued=iss.subtract(an).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue(); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (issued > 0) { | 
|---|
|  |  |  | LocDto locDto = new LocDto(null, orderDetl.getMatnr(), orderDetl.getMaktx(), orderDetl.getBatch(), orderDetl.getOrderNo(), issued,orderDetl.getOwner(),1); | 
|---|
|  |  |  | LocDto locDto = new LocDto(null,null, orderDetl.getMatnr(), orderDetl.getMaktx(), orderDetl.getBatch(), orderDetl.getOrderNo(), issued,"平库"); | 
|---|
|  |  |  | //                LocDto locDto = new LocDto(null, orderDetl.getMatnr(), orderDetl.getMaktx(), orderDetl.getBatch(), orderDetl.getOrderNo(), 0.0,issued); | 
|---|
|  |  |  | locDto.setLack(Boolean.TRUE); | 
|---|
|  |  |  | locDtos.add(locDto); | 
|---|
|  |  |  | 
|---|
|  |  |  | LocDto locDto = locDtos.get(locDtos.size() - 1 - i); | 
|---|
|  |  |  | if (locDto.getLocNo() == null) { | 
|---|
|  |  |  | is[i][0] = 1; | 
|---|
|  |  |  | } else if (locDto.getManu().equals("立库")){ | 
|---|
|  |  |  | is[i][0] = 2; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | is[i][0] = 0; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | ManLocDetl manLocDetl = manLocDetlService.selectItem(locDto.getLocNo(), locDto.getMatnr(), locDto.getBatch()); | 
|---|
|  |  |  | if (!Cools.isEmpty(manLocDetl) && !(locDto.getAnfme()>manLocDetl.getAnfme())) { | 
|---|
|  |  |  | manLocDetl.setStatus(0); | 
|---|
|  |  |  | if (manLocDetlService.update(manLocDetl, new EntityWrapper<ManLocDetl>().eq("uuid", manLocDetl.getUuid()))) { | 
|---|
|  |  |  | if (manLocDetlService.update(manLocDetl, new EntityWrapper<ManLocDetl>().eq("loc_no", manLocDetl.getLocNo()).eq("matnr",manLocDetl.getMatnr()))) { | 
|---|
|  |  |  | if (addPakOUT(locDto,uuid).equals(R.ok())) { | 
|---|
|  |  |  | Order order = orderService.selectByNo(locDto.getOrderNo()); | 
|---|
|  |  |  | if (Cools.isEmpty(order)){ | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private R addPakOUT(LocDto locDto,String uuid){ | 
|---|
|  |  |  | ManPakOut manPakOut=new ManPakOut(); | 
|---|
|  |  |  | manPakOut.setDocId(locDto.getHostId()); | 
|---|
|  |  |  | manPakOut.setWrkNo(locDto.getOrderNo()+"-"+System.currentTimeMillis()); | 
|---|
|  |  |  | manPakOut.setWrkSts((long)1); | 
|---|
|  |  |  | manPakOut.setAnfme(locDto.getAnfme()); | 
|---|
|  |  |  | 
|---|
|  |  |  | manPakOut.setMatnr(locDto.getMatnr()); | 
|---|
|  |  |  | manPakOut.setMaktx(locDto.getMaktx()); | 
|---|
|  |  |  | manPakOut.setDocNum(locDto.getOrderNo()); | 
|---|
|  |  |  | manPakOut.setCount(0); | 
|---|
|  |  |  | manPakOut.setCount(0.0); | 
|---|
|  |  |  | manPakOut.setStatus(0); | 
|---|
|  |  |  | manPakOut.setCreateTime(new Date()); | 
|---|
|  |  |  | manPakOut.setBatch(locDto.getBatch()); | 
|---|
|  |  |  | manPakOut.setUpdateTime(new Date()); | 
|---|
|  |  |  | manPakOut.setPayment(locDto.getPayment()); | 
|---|
|  |  |  | manPakOut.setOwner(locDto.getOwner()); | 
|---|
|  |  |  | manPakOut.setUuid(uuid); | 
|---|
|  |  |  | if (Cools.isEmpty(manPakOutService.selectOne(new EntityWrapper<ManPakOut>().eq("doc_num",locDto.getOrderNo())))){ | 
|---|
|  |  |  | manPakOut.setName(locDto.getMaktx()); | 
|---|