云
20 小时以前 704265308b1227dbada5a36b2027b588c062ded2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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<MesProBagCodeDO> bags) {
        Set<Long> 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;
    }
}