| | |
| | | import com.whyc.util.ActionUtil; |
| | | import org.apache.poi.hssf.usermodel.*; |
| | | import org.apache.poi.ss.usermodel.ClientAnchor; |
| | | import org.apache.poi.ss.usermodel.IndexedColors; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | HSSFWorkbook wb = new HSSFWorkbook(); |
| | | //字体格式-加粗 |
| | | HSSFCellStyle cellStyle = wb.createCellStyle(); |
| | | cellStyle.setFillForegroundColor(IndexedColors.GOLD.getIndex());//添加前景色,内容看的清楚 |
| | | cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); |
| | | HSSFFont font = wb.createFont(); |
| | | font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); |
| | | font.setColor(HSSFFont.COLOR_RED); |
| | | //font.setColor(HSSFFont.COLOR_RED); |
| | | cellStyle.setFont(font); |
| | | |
| | | HSSFSheet sheet = wb.createSheet("bom_"+pHistory.getVersion()+"信息"); |
| | |
| | | if(bom.getMaterialId().equals(baseBom.getMaterialId())){ |
| | | if(!bom.getQuantity().equals(baseBom.getQuantity())){ |
| | | ProductBomHistory history = new ProductBomHistory(); |
| | | String diffSubModel = "原数量:"+baseBom.getQuantity()+"/新数量:"+bom.getQuantity(); |
| | | history.setNotes(diffSubModel); |
| | | String diffQuantity = "原数量:"+baseBom.getQuantity()+"/新数量:"+bom.getQuantity(); |
| | | history.setNotes(diffQuantity); |
| | | history.setMaterialObj(bom.getMaterialObj()); |
| | | diffList.add(history); |
| | | } |
| | |
| | | */ |
| | | public Map<String, List> parseCompare(Product baseProduct, Product product) { |
| | | List<ProductBom> bomList = product.getBomList(); |
| | | List<ProductBom> baseBomList = new LinkedList<>(); |
| | | ProductBom baseProductBom = null; |
| | | List<ProductBom> baseProductBomList = null; |
| | | |
| | | Map<String,List> compareMap = new HashMap<>(); |
| | | List<ProductBomHistory> diffList = new LinkedList<>(); |
| | | List<ProductBomHistory> addList = new LinkedList<>(); |
| | | List<ProductBomHistory> deleteList = new LinkedList<>(); |
| | | List<ProductBom> diffList = new LinkedList<>(); |
| | | List<ProductBom> addList = new LinkedList<>(); |
| | | List<ProductBom> deleteList = new LinkedList<>(); |
| | | |
| | | //根据baseProduct的code和custom_code,查找到基准产品 |
| | | if(baseProduct == null){ |
| | | baseProductBom = bomService.getEnabledStandardBomListByParentCode(product.getParentCode()); |
| | | }else{ |
| | | |
| | | //查找到基准产品 |
| | | if(baseProduct == null){ //查找上传的产品最新标准版本 |
| | | baseProductBomList = bomService.getEnabledBomListByParentCodeAndCustomCode(product.getParentCode(),"0"); |
| | | }else{ //根据baseProduct的code和custom_code |
| | | baseProductBomList = bomService.getEnabledBomListByParentCodeAndCustomCode(baseProduct.getParentCode(),baseProduct.getCustomCode()); |
| | | } |
| | | |
| | | //对比:根据code+model定位,比较数量 |
| | | List<String> baseCodeModelList = baseProductBomList.stream().map(bom -> bom.getMaterialObj().getSubCode() + "/" + bom.getMaterialObj().getSubModel()).collect(Collectors.toList()); |
| | | Map<String, List<ProductBom>> groupedBaseBomList = baseProductBomList.stream().collect(Collectors.groupingBy(bom -> bom.getMaterialObj().getSubCode() + "/" + bom.getMaterialObj().getSubModel())); |
| | | List<String> codeModelList = bomList.stream().map(bom -> bom.getSubCode() + "/" + bom.getSubModel()).collect(Collectors.toList()); |
| | | |
| | | |
| | | bomList.forEach(bom->{ |
| | | String codeModel = bom.getSubCode() + "/" + bom.getSubModel(); |
| | | if(!baseCodeModelList.contains(codeModel)){ |
| | | addList.add(bom); |
| | | }else{ |
| | | ProductBom baseBom = groupedBaseBomList.get(codeModel).get(0); |
| | | if(bom.getQuantity().intValue()!=baseBom.getQuantity()){ |
| | | ProductBom diffBom = new ProductBom(); |
| | | String diffQuantity = "原数量:"+baseBom.getQuantity()+"/新数量:"+bom.getQuantity(); |
| | | diffBom.setNotes(diffQuantity); |
| | | diffBom.setMaterialObj(bom.getMaterialObj()); |
| | | diffList.add(diffBom); |
| | | } |
| | | } |
| | | }); |
| | | baseProductBomList.forEach(bom->{ |
| | | String codeModel = bom.getMaterialObj().getSubCode() + "/" + bom.getMaterialObj().getSubModel(); |
| | | if(!codeModelList.contains(codeModel)){ |
| | | deleteList.add(bom); |
| | | } |
| | | }); |
| | | compareMap.put("diffList",diffList); |
| | | compareMap.put("addList",addList); |
| | | compareMap.put("deleteList",deleteList); |