MobileUtil.java 1.4 KB
package com.huaheng.mobile.util;

import com.huaheng.mobile.inventory.MobileInventory;
import com.huaheng.pc.inventory.inventory.domain.Inventory;
import com.huaheng.pc.inventory.inventory.domain.InventorySearch;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class MobileUtil {

    public static List<MobileInventory> mergeMobileInventory(List<MobileInventory> mobileInventories) {
        List<MobileInventory> mobileInventoryList = new ArrayList<>();
        for(int i=0; i<mobileInventories.size(); i ++ ) {
            int size = mobileInventories.size();
            for(int j=i+1; j< size; j++) {
                MobileInventory mobileInventory1 = mobileInventories.get(i);
                MobileInventory mobileInventory2 = mobileInventories.get(j);
                if(mobileInventory1.getMaterialCode().equals(mobileInventory2.getMaterialCode())
                        && mobileInventory1.getLocationCode().equals(mobileInventory2.getLocationCode())) {
                    mobileInventory1.setQty(mobileInventory1.getQty().add(mobileInventory2.getQty()));
                    mobileInventory1.setTaskQty(mobileInventory1.getTaskQty().add(mobileInventory2.getTaskQty()));
                    mobileInventoryList.add(mobileInventory2);
                }
            }
            mobileInventories.removeAll(mobileInventoryList);
        }
        return mobileInventories;
    }
}