package cn.iocoder.yudao.module.mes.service.pro.pallet; import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.module.mes.dal.dataobject.pro.bagcode.MesProBagCodeDO; import cn.iocoder.yudao.module.mes.dal.dataobject.pro.pallet.MesProPalletDO; import java.util.*; /** 托盘品种以托盘记录和有效袋码共同校验,兼容历史托盘。 */ public final class MesProPalletItemResolver { private MesProPalletItemResolver() {} public static Long resolve(MesProPalletDO pallet, List bags) { Set items = new HashSet<>(); if (pallet.getItemId() != null) items.add(pallet.getItemId()); for (MesProBagCodeDO bag : bags) { if (Integer.valueOf(30).equals(bag.getStatus())) continue; if (bag.getItemId() == null) throw new ServiceException(400, "托盘内袋码缺少品种,请先完善品种信息"); items.add(bag.getItemId()); } if (items.size() > 1) throw new ServiceException(400, "托盘和袋码必须属于同一品种"); return items.isEmpty() ? null : items.iterator().next(); } public static Long merge(Long current, Long candidate) { if (current != null && candidate != null && !current.equals(candidate)) throw new ServiceException(400, "生产批次只能绑定相同品种的托盘,且须与批次品种一致"); return current == null ? candidate : current; } }