| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service("locItemService") |
| | | public class LocItemServiceImpl extends ServiceImpl<LocItemMapper, LocItem> implements LocItemService { |
| | | |
| | | private static final BigDecimal FULL_OUT_QTY_TOLERANCE = new BigDecimal("0.000001"); |
| | | |
| | | Logger logger = LoggerFactory.getLogger(LocItemServiceImpl.class); |
| | | |
| | |
| | | private WaveService waveService; |
| | | @Autowired |
| | | private BasStationService basStationService; |
| | | @Autowired |
| | | private MatnrService matnrService; |
| | | |
| | | /** 入库/出库保存前:若规格或型号为空则从物料带出 */ |
| | | private void fillSpecModelFromMatnr(LocItem item) { |
| | | if (item == null || item.getMatnrId() == null) { |
| | | return; |
| | | } |
| | | if (StringUtils.isNotBlank(item.getSpec()) && StringUtils.isNotBlank(item.getModel())) { |
| | | return; |
| | | } |
| | | Matnr matnr = matnrService.getById(item.getMatnrId()); |
| | | if (matnr == null) { |
| | | return; |
| | | } |
| | | if (StringUtils.isBlank(item.getSpec())) { |
| | | item.setSpec(matnr.getSpec()); |
| | | } |
| | | if (StringUtils.isBlank(item.getModel())) { |
| | | item.setModel(matnr.getModel()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public boolean save(LocItem entity) { |
| | | fillSpecModelFromMatnr(entity); |
| | | return super.save(entity); |
| | | } |
| | | |
| | | @Override |
| | | public boolean saveBatch(Collection<LocItem> entityList) { |
| | | if (entityList != null) { |
| | | entityList.forEach(this::fillSpecModelFromMatnr); |
| | | } |
| | | return super.saveBatch(entityList); |
| | | } |
| | | |
| | | @Override |
| | | public boolean saveBatch(Collection<LocItem> entityList, int batchSize) { |
| | | if (entityList != null) { |
| | | entityList.forEach(this::fillSpecModelFromMatnr); |
| | | } |
| | | return super.saveBatch(entityList, batchSize); |
| | | } |
| | | |
| | | @Override |
| | | public void fillSpecModelFromMatnrForRecords(List<LocItem> records) { |
| | | if (records == null || records.isEmpty()) { |
| | | return; |
| | | } |
| | | Set<Long> matnrIds = new HashSet<>(); |
| | | for (LocItem r : records) { |
| | | if (r.getMatnrId() != null && (StringUtils.isBlank(r.getSpec()) || StringUtils.isBlank(r.getModel()))) { |
| | | matnrIds.add(r.getMatnrId()); |
| | | } |
| | | } |
| | | if (matnrIds.isEmpty()) { |
| | | return; |
| | | } |
| | | Map<Long, Matnr> matnrMap = matnrService.listByIds(matnrIds).stream() |
| | | .collect(Collectors.toMap(Matnr::getId, m -> m)); |
| | | for (LocItem r : records) { |
| | | if (r.getMatnrId() == null) { |
| | | continue; |
| | | } |
| | | Matnr m = matnrMap.get(r.getMatnrId()); |
| | | if (m == null) { |
| | | continue; |
| | | } |
| | | if (StringUtils.isBlank(r.getSpec())) { |
| | | r.setSpec(m.getSpec()); |
| | | } |
| | | if (StringUtils.isBlank(r.getModel())) { |
| | | r.setModel(m.getModel()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 库存出库生成出库任务 |
| | |
| | | Double orgQty = locItems.stream().mapToDouble(LocItem::getAnfme).sum(); |
| | | List<LocItem> locItemList = listMap.get(key); |
| | | Double outQty = locItemList.stream().mapToDouble(LocItem::getOutQty).sum(); |
| | | BigDecimal orgQtyBd = BigDecimal.valueOf(orgQty).setScale(6, RoundingMode.HALF_UP); |
| | | BigDecimal outQtyBd = BigDecimal.valueOf(outQty).setScale(6, RoundingMode.HALF_UP); |
| | | |
| | | if (map.getType().equals(Constants.TASK_TYPE_OUT_STOCK) |
| | | || map.getType().equals(Constants.TASK_TYPE_ORDER_OUT_STOCK) |
| | | || map.getType().equals(Constants.TASK_TYPE_WAVE_OUT_STOCK)) { |
| | | if (orgQty.compareTo(outQty) > 0) { |
| | | //拣料出库 -- 盘点出库 |
| | | // 出库量达到库位库存(含容差)视为全版出库,避免浮点误差导致误判为拣料/部分出库 |
| | | if (orgQtyBd.subtract(outQtyBd).compareTo(FULL_OUT_QTY_TOLERANCE) > 0) { |
| | | // 拣料出库(部分出库) |
| | | DeviceSite deviceSite = deviceSiteService.getOne(new LambdaQueryWrapper<DeviceSite>() |
| | | .eq(DeviceSite::getSite, siteNo) |
| | | .eq(!Objects.isNull(loc.getChannel()),DeviceSite::getChannel, loc.getChannel()) |