|  |  |  | 
|---|
|  |  |  | import com.zy.common.model.LocDto; | 
|---|
|  |  |  | import com.zy.common.model.TaskDto; | 
|---|
|  |  |  | import com.zy.common.web.BaseController; | 
|---|
|  |  |  | import com.zy.system.entity.User; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.PostMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestBody; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/out/pakout/preview/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R pakoutPreview(@RequestBody List<Long> ids) { | 
|---|
|  |  |  | public R pakoutPreview(@RequestBody HashMap<String,Object> param) { | 
|---|
|  |  |  | List<Long> ids = (List<Long>) param.get("ids"); | 
|---|
|  |  |  | if (Cools.isEmpty(ids)) { | 
|---|
|  |  |  | return R.parse(BaseRes.PARAM); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String cstateid = param.getOrDefault("cstateid", "").toString(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<OrderDetlPakout> orderDetlPakouts = orderDetlPakoutService.selectBatchIds(ids); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (orderDetlPakouts.size() == 0) { | 
|---|
|  |  |  | return R.parse("订单明细为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<String> disableCstateidList = new ArrayList<>(); | 
|---|
|  |  |  | disableCstateidList.add("1001A1100000000H0KJP");//不合格 | 
|---|
|  |  |  | disableCstateidList.add("1001A1100000000LFERA");//待处理 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<LocDto> locDtos = new ArrayList<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | if (issued <= 0.0D) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<LocDetl> locDetls = locDetlService.queryStockAll(null, exist,orderDetl.getMatnr(), orderDetl.getBatch(), | 
|---|
|  |  |  | orderDetl.getBrand(),orderDetl.getStandby1(),orderDetl.getStandby2(),orderDetl.getStandby3(),orderDetl.getBoxType1(),orderDetl.getBoxType2(),orderDetl.getBoxType3()); | 
|---|
|  |  |  | List<LocDetl> locDetls = locDetlService.queryStockAll(null, exist, orderDetl.getMatnr(), orderDetl.getBatch(), | 
|---|
|  |  |  | orderDetl.getBrand(), orderDetl.getStandby1(), orderDetl.getStandby2(), orderDetl.getStandby3(), orderDetl.getBoxType1(), orderDetl.getBoxType2(), orderDetl.getBoxType3(), cstateid); | 
|---|
|  |  |  | for (LocDetl locDetl : locDetls) { | 
|---|
|  |  |  | if (issued > 0) { | 
|---|
|  |  |  | LocDto locDto = new LocDto(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getMaktx(), locDetl.getBatch(), orderDetl.getOrderNo(), | 
|---|
|  |  |  | 
|---|
|  |  |  | if (issued <= 0.0D) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<LocDetl> locDetls = locDetlService.queryStockAll(null, exist,orderDetl.getMatnr(), orderDetl.getBatch(), | 
|---|
|  |  |  | orderDetl.getBrand(),orderDetl.getStandby1(),orderDetl.getStandby2(),orderDetl.getStandby3(),orderDetl.getBoxType1(),orderDetl.getBoxType2(),orderDetl.getBoxType3()); | 
|---|
|  |  |  | List<LocDetl> locDetls = locDetlService.queryStockAll(null, exist, orderDetl.getMatnr(), orderDetl.getBatch(), | 
|---|
|  |  |  | orderDetl.getBrand(), orderDetl.getStandby1(), orderDetl.getStandby2(), orderDetl.getStandby3(), orderDetl.getBoxType1(), orderDetl.getBoxType2(), orderDetl.getBoxType3(), cstateid); | 
|---|
|  |  |  | for (LocDetl locDetl : locDetls) { | 
|---|
|  |  |  | if (disableCstateidList.contains(locDetl.getCstateid())) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (issued > 0) { | 
|---|
|  |  |  | LocDto locDto = new LocDto(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getMaktx(), locDetl.getBatch(), orderDetl.getOrderNo(), | 
|---|
|  |  |  | issued >= locDetl.getAnfme() ? locDetl.getAnfme() : issued); | 
|---|
|  |  |  | 
|---|
|  |  |  | locDto.setBoxType2(orderDetl.getBoxType2()); | 
|---|
|  |  |  | locDto.setBoxType3(orderDetl.getBoxType3()); | 
|---|
|  |  |  | locDto.setUnit(orderDetl.getUnit()); | 
|---|
|  |  |  | locDto.setInitialAnfme(locDetl.getAnfme());//原托盘数量 | 
|---|
|  |  |  | locDto.setInitialWeight(locDetl.getWeight());//原托盘辅数量 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //计算辅单位 | 
|---|
|  |  |  | Double weight = MatUtils.calcWeight(locDto.getMatnr(), locDto.getAnfme()); | 
|---|
|  |  |  | 
|---|
|  |  |  | locDtos.add(locDto); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 重新计算出库站点,可能存在一个托盘多条明细,多条明细统计下来可全板出库,但实际给出的站点只能拣选出库 | 
|---|
|  |  |  | HashMap<String, Double> locAnfmeMap = new HashMap<>(); | 
|---|
|  |  |  | for (LocDto locDto : locDtos) { | 
|---|
|  |  |  | if(locAnfmeMap.containsKey(locDto.getLocNo())) { | 
|---|
|  |  |  | Double anfme = locAnfmeMap.get(locDto.getLocNo()); | 
|---|
|  |  |  | BigDecimal decimal = BigDecimal.valueOf(locDto.getAnfme()).add(BigDecimal.valueOf(anfme)); | 
|---|
|  |  |  | locAnfmeMap.put(locDto.getLocNo(), decimal.doubleValue()); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | locAnfmeMap.put(locDto.getLocNo(), locDto.getAnfme()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | HashMap<String, List<Integer>> locStaNosMap = new HashMap<>(); | 
|---|
|  |  |  | for (Map.Entry<String, Double> entry : locAnfmeMap.entrySet()) { | 
|---|
|  |  |  | String locNo = entry.getKey(); | 
|---|
|  |  |  | Double realAnfme = entry.getValue(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | double stockAnfme = 0D; | 
|---|
|  |  |  | List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", locNo)); | 
|---|
|  |  |  | for (LocDetl locDetl : locDetls) { | 
|---|
|  |  |  | BigDecimal decimal = BigDecimal.valueOf(stockAnfme).add(BigDecimal.valueOf(locDetl.getAnfme())); | 
|---|
|  |  |  | stockAnfme = decimal.doubleValue(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int ioType = 103; | 
|---|
|  |  |  | if(stockAnfme == realAnfme) { | 
|---|
|  |  |  | ioType = 101; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Integer> staNos = staDescService.queryOutStaNosByLocNo(locNo, ioType); | 
|---|
|  |  |  | User user = null; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | user = getUser(); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(user != null) { | 
|---|
|  |  |  | Integer defaultOutSta = user.getDefaultOutSta(); | 
|---|
|  |  |  | if(defaultOutSta != null) { | 
|---|
|  |  |  | if (staNos.contains(defaultOutSta)) { | 
|---|
|  |  |  | staNos.remove(defaultOutSta); | 
|---|
|  |  |  | staNos.add(0, defaultOutSta); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | locStaNosMap.put(locNo, staNos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (LocDto locDto : locDtos) { | 
|---|
|  |  |  | List<Integer> staNos = locStaNosMap.get(locDto.getLocNo()); | 
|---|
|  |  |  | locDto.setStaNos(staNos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok().add(locDtos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|