| | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.ProductMapper; |
| | | import com.whyc.pojo.*; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.CommonUtil; |
| | | import com.whyc.util.DateUtil; |
| | | import com.whyc.util.FileUtil; |
| | | import com.whyc.util.Zip4jUtil; |
| | | import com.whyc.util.*; |
| | | import org.apache.poi.openxml4j.exceptions.InvalidFormatException; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import java.io.*; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.function.Function; |
| | | import java.util.function.Predicate; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | |
| | | List<String> subCodeList = materialExistList.stream().map(material -> material.getSubCode()+"/"+material.getSubModel()).collect(Collectors.toList()); |
| | | List<Material> materialList = new LinkedList<>(); |
| | | List<Material> materialUpdateList = new LinkedList<>(); |
| | | bomList.forEach(bom -> { |
| | | for (ProductBom bom : bomList) { |
| | | if (!subCodeList.contains(bom.getSubCode()+"/"+bom.getSubModel())) { |
| | | Material material = new Material(); |
| | | material.setCreateDate(date); |
| | |
| | | materialUpdateList.add(material); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | //对新增到物料表中的物料,根据 物料编码+物料型号 进行去重处理 |
| | | materialList = materialList.stream().filter(distinctByKey(m->m.getSubCode()+"/"+m.getSubModel())).collect(Collectors.toList()); |
| | | |
| | | //母料是否存在 |
| | | Material materialDB = mService.getByCodeAndModel(product.getParentCode(), product.getParentModel()); |
| | | if (materialDB == null) { |
| | |
| | | // product的主键沿用对应product_history的 |
| | | //根据编码和型号确定物料id并对应quantity,存入数据库. |
| | | //List<Material> bomMaterialList = mService.getListByCodeAndModelList2(bomList); |
| | | List<ProductBom> bomMaterialList = pbService.getListByCodeAndModelList2(bomList); |
| | | //List<ProductBom> bomMaterialList = pbService.getListByCodeAndModelList2(bomList); |
| | | List<Material> existMaterialListWithSameSubCodeAndModel = mService.getSameSubCodeAndModel(bomList); |
| | | List<ProductBom> bomMaterialList; |
| | | bomList.forEach(bom->{ |
| | | String codeModelUnionStr = bom.getSubCode() + "/" + bom.getSubModel(); |
| | | for (int i = 0; i < existMaterialListWithSameSubCodeAndModel.size(); i++) { |
| | | Material materialExists = existMaterialListWithSameSubCodeAndModel.get(i); |
| | | if(codeModelUnionStr.equals(materialExists.getSubCode() + "/" + materialExists.getSubModel())){ |
| | | bom.setId(materialExists.getId()); |
| | | break; |
| | | } |
| | | } |
| | | }); |
| | | bomMaterialList = bomList; |
| | | // -> product_history |
| | | ProductHistory productHistory = new ProductHistory(); |
| | | productHistory.setParentCode(product.getParentCode()); |
| | |
| | | List list=mapper.selectList(null); |
| | | return new Response().setII(1,list.size()>0,list,"产品对比下拉选中-查询当前使用的所有的产品"); |
| | | } |
| | | public static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) { |
| | | Map<Object, Boolean> seen = new ConcurrentHashMap<>(); |
| | | return object -> seen.putIfAbsent(keyExtractor.apply(object), Boolean.TRUE) == null; |
| | | } |
| | | |
| | | } |