| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.vincent.rsf.server.manager.utils.OptimalAlgorithmUtil; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.IntStream; |
| | | |
| | | @Service("waveService") |
| | | public class WaveServiceImpl extends ServiceImpl<WaveMapper, Wave> implements WaveService { |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R publicTask(Map<String, Object> map) { |
| | | List<Long> ids = (List<Long>) map.get("ids"); |
| | | if (Objects.isNull(ids) || ids.isEmpty()) { |
| | | List<WaveItem> itemParams = (List<WaveItem>) map.get("wave"); |
| | | if (Objects.isNull(itemParams) || itemParams.isEmpty()) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | List<Long> ids = itemParams.stream().map(WaveItem::getWaveId).collect(Collectors.toList()); |
| | | List<Wave> waves = this.list(new LambdaQueryWrapper<Wave>().in(Wave::getId, ids)); |
| | | if (Objects.isNull(waves) || waves.isEmpty()) { |
| | | throw new CoolException("波次数据不存在!!"); |
| | |
| | | throw new CoolException("波次明细不存在!!"); |
| | | } |
| | | List<Long> orderIds = waveItems.stream().map(WaveItem::getOrderId).collect(Collectors.toList()); |
| | | |
| | | /**查询每条明细匹配的库位*/ |
| | | try { |
| | | List<WaveItem> items = getLocs(waveItems); |
| | | // List<WaveItem> items = getLocs(waveItems); |
| | | } catch (Exception e) { |
| | | throw new CoolException("库位获取失败!!!"); |
| | | } |
| | |
| | | // 2. 根据物料SKU寻找符合物料库位 {1. 根据物料编码,批次,动态字段 查询符合的库位,再根据库位中物料的数量选择最适合的库位 2. 判断当前订单是全拖出库还是拣料入库} |
| | | // 3. 修改主单、波次执行数量 |
| | | // 4. 判断全仓出库或拣料出库 |
| | | List<AsnOrder> orders = asnOrderService.list(new LambdaQueryWrapper<AsnOrder>().in(AsnOrder::getId, orderIds)); |
| | | /**修改原出库单状态*/ |
| | | if (!asnOrderService.update(new LambdaQueryWrapper<AsnOrder>() |
| | | .eq(AsnOrder::getExceStatus, AsnExceStatus.OUT_STOCK_STATUS_TASK_WORKING.val) |
| | | .in(AsnOrder::getId, orders))) { |
| | | throw new CoolException("出库单据状态修改失败!!"); |
| | | } |
| | | if (!this.update(new LambdaUpdateWrapper<Wave>().set(Wave::getExceStatus, WaveExceStatus.WAVE_EXCE_STATUS_TASK).in(Wave::getId, ids))) { |
| | | throw new CoolException("波次状态修改失败!!"); |
| | | } |
| | | // List<AsnOrder> orders = asnOrderService.list(new LambdaQueryWrapper<AsnOrder>().in(AsnOrder::getId, orderIds)); |
| | | // /**修改原出库单状态*/ |
| | | // if (!asnOrderService.update(new LambdaQueryWrapper<AsnOrder>() |
| | | // .eq(AsnOrder::getExceStatus, AsnExceStatus.OUT_STOCK_STATUS_TASK_WORKING.val) |
| | | // .in(AsnOrder::getId, orders))) { |
| | | // throw new CoolException("出库单据状态修改失败!!"); |
| | | // } |
| | | // if (!this.update(new LambdaUpdateWrapper<Wave>().set(Wave::getExceStatus, WaveExceStatus.WAVE_EXCE_STATUS_TASK).in(Wave::getId, ids))) { |
| | | // throw new CoolException("波次状态修改失败!!"); |
| | | // } |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | .eq(LocItem::getSplrBatch, waveItem.getSplrBatch()) |
| | | .eq(StringUtils.isNotBlank(waveItem.getFieldsIndex()), LocItem::getFieldsIndex, waveItem.getFieldsIndex()) |
| | | .groupBy(LocItem::getMatnrCode, LocItem::getSplrBatch, LocItem::getFieldsIndex, LocItem::getId)); |
| | | List<Double> doubles1 = locItems.stream().map(LocItem::getAnfme).collect(Collectors.toList()); |
| | | double[] doubles = doubles1.stream().mapToDouble(Double::doubleValue).toArray(); |
| | | |
| | | Double[] doubles = locItems.stream().map(LocItem::getAnfme).toArray(Double[]::new); |
| | | List<Double> result = OptimalAlgorithmUtil.findBestCombination(doubles, waveItem.getAnfme()); |
| | | |
| | | |
| | | String locs = JSONArray.toJSONString(new ArrayList<>()); |
| | | |
| | | if (!locItems.isEmpty()) { |
| | | List<String> codes = locItems.stream().map(LocItem::getLocCode).collect(Collectors.toList()); |
| | | locs = JSONArray.toJSONString(codes); |
| | | /**使用回溯算法计算,获取符合出库量的最简组合*/ |
| | | List<Integer> result = OptimalAlgorithmUtil.findCombination(doubles, waveItem.getAnfme()); |
| | | String locs = "[]"; |
| | | if (Objects.isNull(result)) { |
| | | waveItem.setStockLocs(locs).setStockQty(0.0); |
| | | } else { |
| | | /**过滤集合中最简短的组合*/ |
| | | List<LocItem> locsInfo = result.stream() |
| | | .filter(i -> i >= 0 && i < locItems.size()) |
| | | .map(locItems::get).collect(Collectors.toList()); |
| | | locs = JSONArray.toJSONString(locsInfo); |
| | | double sumQty = locItems.stream().mapToDouble(LocItem::getAnfme).sum(); |
| | | double surQty = locItems.stream().mapToDouble(LocItem::getWorkQty).sum(); |
| | | double qty = locItems.stream().mapToDouble(LocItem::getQty).sum(); |
| | | double v = sumQty - surQty - qty; |
| | | waveItem.setStockLocs(locs).setStockQty(v); |
| | | } |
| | | waveItem.setStockLocs(locs); |
| | | }); |
| | | return waveItems; |
| | | } |