|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.core.annotations.ManagerAuth; | 
|---|
|  |  |  | import com.core.common.BaseRes; | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.zy.asrs.entity.BasDevp; | 
|---|
|  |  |  | import com.zy.asrs.entity.LocDetl; | 
|---|
|  |  |  | import com.zy.asrs.entity.OrderDetl; | 
|---|
|  |  |  | import com.zy.asrs.entity.result.StoPreTab; | 
|---|
|  |  |  | import com.zy.asrs.service.*; | 
|---|
|  |  |  | import com.zy.common.model.DetlDto; | 
|---|
|  |  |  | import com.zy.common.model.LocDto; | 
|---|
|  |  |  | import com.zy.common.model.TaskDto; | 
|---|
|  |  |  | import com.zy.common.web.BaseController; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.PostMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestBody; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestParam; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * Created by vincent on 2022/3/26 | 
|---|
|  |  |  | 
|---|
|  |  |  | private BasDevpService basDevpService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //    @PostMapping("/out/pakout/preview/auth") | 
|---|
|  |  |  | //    public R pakoutPreview(@RequestBody List<Long> ids) { | 
|---|
|  |  |  | //        if (Cools.isEmpty(ids)) { | 
|---|
|  |  |  | //            return R.parse(BaseRes.PARAM); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        List<OrderDetl> orderDetls = orderDetlService.selectBatchIds(ids); | 
|---|
|  |  |  | //        Set<DetlDto> detlDtos = new HashSet<>(); | 
|---|
|  |  |  | //        for (OrderDetl orderDetl : orderDetls) { | 
|---|
|  |  |  | //            if (DetlDto.hasList(detlDtos, orderDetl)) { | 
|---|
|  |  |  | //                DetlDto detlDto = DetlDto.find(detlDtos, orderDetl.getMatnr(), orderDetl.getBatch()); | 
|---|
|  |  |  | //                assert detlDto != null; | 
|---|
|  |  |  | //                detlDto.setAnfme(detlDto.getAnfme() + orderDetl.getAnfme()); | 
|---|
|  |  |  | //            } else { | 
|---|
|  |  |  | //                detlDtos.add(new DetlDto(orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getAnfme())); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        List<LocDto> locDtos = new ArrayList<>(); | 
|---|
|  |  |  | //        for (DetlDto detlDto : detlDtos) { | 
|---|
|  |  |  | //            double issued = Optional.ofNullable(detlDto.getAnfme()).orElse(0.0D) ; | 
|---|
|  |  |  | //            List<LocDetl> locDetls = locDetlService.queryStock(detlDto.getMatnr(), detlDto.getBatch(), null); | 
|---|
|  |  |  | //            for (LocDetl locDetl : locDetls) { | 
|---|
|  |  |  | //                if (issued > 0) { | 
|---|
|  |  |  | //                    locDtos.add(new LocDto(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getBatch(), issued>=locDetl.getAnfme()?locDetl.getAnfme():issued)); | 
|---|
|  |  |  | //                    // 剩余待出数量递减 | 
|---|
|  |  |  | //                    issued = issued - locDetl.getAnfme(); | 
|---|
|  |  |  | //                } else { | 
|---|
|  |  |  | //                    break; | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        return R.ok().add(locDtos); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | @PostMapping("/out/pakout/orderDetlIds/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R pakoutOrderDetlIds(@RequestParam Long orderId) throws InterruptedException { | 
|---|
|  |  |  | Thread.sleep(200); | 
|---|
|  |  |  | return R.ok().add(orderDetlService.selectByOrderId(orderId).stream().map(OrderDetl::getId).distinct().collect(Collectors.toList())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/out/pakout/preview/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<OrderDetl> orderDetls = orderDetlService.selectBatchIds(ids); | 
|---|
|  |  |  | List<LocDto> locDtos = new ArrayList<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Set<String> exist = new HashSet<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (OrderDetl orderDetl : orderDetls) { | 
|---|
|  |  |  | double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getQty()).orElse(0.0D); | 
|---|
|  |  |  | double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getWorkQty()).orElse(0.0D); | 
|---|
|  |  |  | if (issued <= 0.0D) { continue; } | 
|---|
|  |  |  | List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(), orderDetl.getBatch(), null); | 
|---|
|  |  |  | List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(), orderDetl.getBatch(), null, exist); | 
|---|
|  |  |  | for (LocDetl locDetl : locDetls) { | 
|---|
|  |  |  | if (issued > 0) { | 
|---|
|  |  |  | LocDto locDto = new LocDto(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getMaktx(), locDetl.getBatch(), orderDetl.getOrderNo(), | 
|---|
|  |  |  | 
|---|
|  |  |  | List<Integer> staNos = staDescService.queryOutStaNosByLocNo(locDetl.getLocNo(), issued >= locDetl.getAnfme() ? 101 : 103); | 
|---|
|  |  |  | locDto.setStaNos(staNos); | 
|---|
|  |  |  | locDtos.add(locDto); | 
|---|
|  |  |  | exist.add(locDetl.getLocNo()); | 
|---|
|  |  |  | // 剩余待出数量递减 | 
|---|
|  |  |  | issued = issued - locDetl.getAnfme(); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | 
|---|
|  |  |  | if (Cools.isEmpty(locDtos)) { | 
|---|
|  |  |  | return R.parse(BaseRes.PARAM); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | boolean refuse = true; | 
|---|
|  |  |  | boolean lack = true; | 
|---|
|  |  |  | for (LocDto locDto : locDtos) { | 
|---|
|  |  |  | if (!locDto.isLack()) { | 
|---|
|  |  |  | refuse = !refuse; | 
|---|
|  |  |  | lack = false; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (refuse) { | 
|---|
|  |  |  | if (lack) { | 
|---|
|  |  |  | return R.error("库存不足"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Thread.sleep(500L); | 
|---|
|  |  |  | Thread.sleep(1000L); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<TaskDto> taskDtos = new ArrayList<>(); | 
|---|
|  |  |  | // 根据 (库位 & 出库站) 分组; 理想状态:一组为一次出库任务 | 
|---|