package com.topsun.posclient.sales.core; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import com.topsun.posclient.common.AppConstants; import com.topsun.posclient.common.POSException; import com.topsun.posclient.datamodel.Item; import com.topsun.posclient.datamodel.PartSales; import com.topsun.posclient.datamodel.Promotion; import com.topsun.posclient.datamodel.PromotionA; import com.topsun.posclient.datamodel.PromotionM; import com.topsun.posclient.datamodel.RetailM; /** * 促销方案算法 * * @author Dong * */ public class PromotionMath { /** * 将销售单品数据转换成零售数据以及明细 * @param items 单品数据 * @param salesInfo 销售信息 * @return 零售数据以及明细 * @throws POSException */ public static List<RetailM> getPromotionRetailMListFromPartSales(PartSales partSales) throws POSException{ if(null == partSales){ return null; } List<Item> items = partSales.getItemList(); if(null == items){ return null; } //设置明细 List<RetailM> retailMList = new ArrayList<RetailM>(); for(int i=0; i<items.size(); i++){ //旧金和服务费不参加促销 if(items.get(i).getItemType().equals(AppConstants.ITEM_TYPE_OLDGOLD) || items.get(i).getItemType().equals(AppConstants.ITEM_TYPE_SERVICEFEE)){ continue; } //特价单品不参与促销 if(null != items.get(i).getZSFTJ() && items.get(i).getZSFTJ().equals("X")){ continue; } retailMList.add(SalesDataUtil.convertItemToRetailM(items.get(i), partSales, i)); } return retailMList; } /** * 将促销之后Retail转成Item集合,用于UI显示 * @param itemDto * @param retail * @return */ public static List<Item> convertRetailToItemList(List<Item> items, List<RetailM> retailMs){ List<Item> newItemList = new ArrayList<Item>(); for(Item item : items){ newItemList.add(refeshItem(item, retailMs)); } return newItemList; } /** * 刷新单品(促销之后刷新相关字段) * @param item 单品 * @param retail 零售明细 * @return */ private static Item refeshItem(Item item, List<RetailM> retailms){ for(RetailM rm : retailms){ if(rm.getItemId() == item.getId()){ // item.setSalesAmount(rm.getSalesAmount());//刷新应售价,工费打折和扣减的时候涉及到应售价的修改 item.setFactAmount(rm.getFactAmount());//刷新实售金额 // item.setZJGF(rm.getProcessFee()); item.setFactZJGF(rm.getProcessFee_S()); BigDecimal pretlAmount = rm.getSalesAmount().subtract(rm.getFactAmount()); if(pretlAmount.compareTo(new BigDecimal(0)) == -1 ){ pretlAmount = new BigDecimal(0); } item.setPretlAmount(pretlAmount);//刷新优惠金额 if(rm.getItemName().contains("有赠品")){ item.setHasGiveaway(1); } item.setItemName(rm.getItemName());//刷新商品名称(显示有赠品) item.setPromotionId(rm.getPromotionID()); item.setPromotionName(rm.getPromotionName()); } } return item; } /**************************************促销算法**********************************************************************************/ /** * 单品促销 * @param retailMs 零售明细集合 * @param promotion 促销方案 * @return 促销之后的单品集合 * @throws POSException */ public static List<RetailM> applySingle(List<RetailM> retailMs, Promotion promotion) throws POSException { if(null == retailMs){ return retailMs; } List<RetailM> ret = new ArrayList<RetailM>(); for(RetailM retailM : retailMs){ setRetailM(retailM, promotion); if(retailM.getFactAmount().compareTo(new BigDecimal(0)) != 1){ ret.add(retailM); continue; } if(promotion.getIsAll() == 1){//全场 if(!isExclude(retailM, promotion)){//不排除 retailM.setFactAmount(retailM.getFactAmount().multiply(promotion.getRate()).setScale(2, BigDecimal.ROUND_HALF_UP)); } }else{ if(filterInclud(retailM, promotion)){ //包含&排除算法 retailM.setFactAmount(retailM.getFactAmount().multiply(promotion.getRate()).setScale(2, BigDecimal.ROUND_HALF_UP)); } } ret.add(retailM); } return ret; } /** * 单件金额满N减M * @param retailMs * @param promotion * @return * @throws POSException */ public static List<RetailM> applySingleNM(List<RetailM> retailMs, Promotion promotion) throws POSException { if(null == retailMs){ return retailMs; } List<RetailM> ret = new ArrayList<RetailM>(); for(RetailM retailM : retailMs){ setRetailM(retailM, promotion); if(retailM.getFactAmount().compareTo(new BigDecimal(0)) != 1){ ret.add(retailM); continue; } if(promotion.getIsAll() == 1){//全场 if(!isExclude(retailM, promotion)){//不排除 //零售明细的实售金额大于促销方案设定值1,满足单件满N减M的条件 if(retailM.getFactAmount().compareTo(promotion.getPromotionAList().get(0).getSet1()) == 1){ retailM.setFactAmount(retailM.getFactAmount().subtract(promotion.getPromotionAList().get(0).getSet2())); } } }else{ if(!filterInclud(retailM, promotion)){//包含不排除 ret.add(retailM); continue; } //零售明细的实售金额大于促销方案设定值1,满足单件满N减M的条件 if(retailM.getFactAmount().compareTo(promotion.getPromotionAList().get(0).getSet1()) == 1){ retailM.setFactAmount(retailM.getFactAmount().subtract(promotion.getPromotionAList().get(0).getSet2())); } } ret.add(retailM); } return ret; } /** * 数量满减(减折扣) * @param retailMs 零售明细集合 * @param promotion 促销方案 * @return * @throws POSException */ public static List<RetailM> applyNumNm(List<RetailM> retailMs, Promotion promotion) throws POSException { if(null == retailMs || retailMs.size() <= 0){ return retailMs; } List<RetailM> ret = new ArrayList<RetailM>(); int num = 0; List<RetailM> rms = null; //全场 if(promotion.getIsAll() == 1){ rms = new ArrayList<RetailM>(); for(RetailM rm : retailMs){ if(isExclude(rm, promotion)){//是否排除 continue; } rms.add(rm); } num = rms.size();//排除之后的整单数量 }else{//非全场 rms = new ArrayList<RetailM>(); for(RetailM rm : retailMs){ if(filterInclud(rm, promotion)){//包含且不排除 rms.add(rm); } } num = rms.size();//包含且不排除之后的整单数量 } //判断数量是否满足促销的数量设定值 大于等于则进行整单打折 if(null == promotion.getPromotionAList() || promotion.getPromotionAList().size() == 0){ return retailMs; } PromotionA pa = promotion.getPromotionAList().get(0); if(null == pa){ return retailMs; } if(null != promotion.getPromotionAList() && null != pa && num >= pa.getSet1().intValue()){ BigDecimal countPrices = new BigDecimal(0); //将不在包含排除之内的明细数据直接放在ret返回值中 for(RetailM retailM : retailMs){ if(!rms.contains(retailM)){ ret.add(retailM); continue; } countPrices = countPrices.add(retailM.getFactAmount());//累加实售价为总价 } BigDecimal discountVal = promotion.getPromotionAList().get(0).getSet2(); for(int i=0; i<rms.size(); i++){ RetailM rm = rms.get(i); setRetailM(rm, promotion); if(rm.getFactAmount().compareTo(new BigDecimal(0)) != 1){ ret.add(rm); continue; } rm.setFactAmount(rm.getFactAmount().multiply(discountVal)); ret.add(rm); } }else{ return retailMs; } return ret; } /** * 单品满送赠品 * @param retailMs 零售明细列表 * @param promotion 促销方案 * @return * @throws POSException */ public static List<RetailM> applySingleNG(List<RetailM> retailMs, Promotion promotion) throws POSException { if(null == retailMs){ return retailMs; } List<RetailM> ret = new ArrayList<RetailM>(); List<String> appointList = getAppointListFromPromi(promotion);//指定的物料编码 for(RetailM retailM : retailMs){ setRetailM(retailM, promotion); if(retailM.getFactAmount().compareTo(new BigDecimal(0)) != 1){ ret.add(retailM); continue; } if(promotion.getIsAll() == 1){ if(!isExclude(retailM, promotion)){//不排除 if(retailM.getFactAmount().intValue() > promotion.getPromotionAList().get(0).getSet1().intValue()){ for(String matnr : appointList){ if(retailM.getMATNR().startsWith(matnr)){ retailM.setItemName(retailM.getItemName()+"(有赠品)"); } } } } }else{ if(!filterInclud(retailM, promotion)){ ret.add(retailM); continue; } if(retailM.getFactAmount().intValue() > promotion.getPromotionAList().get(0).getSet1().intValue()){ for(String matnr : appointList){ if(retailM.getMATNR().startsWith(matnr)){//零售明细编号在促销方案指定物料编号列表中 retailM.setItemName(retailM.getItemName()+"(有赠品)"); } } } } ret.add(retailM); } return ret; } /** * 买指定商品可选购指定商品(折扣) * @param retailMs 零售明细集合 * @param promotion 促销方案 * @return * @throws POSException */ public static List<RetailM> applyAppoint(List<RetailM> retailMs, Promotion promotion) throws POSException { if(null == retailMs){ return retailMs; } List<RetailM> ret = new ArrayList<RetailM>(); if(promotion.getIsAll() == 1){//全场 if(isExcludeAll(retailMs, promotion)){ return retailMs; }else{ for(RetailM rm : retailMs){ if(rm.getFactAmount().compareTo(new BigDecimal(0)) != 1){ ret.add(rm); continue; } if(isAppoint(rm, promotion)){//在指定范围内 rm.setFactAmount(rm.getFactAmount().multiply(promotion.getPromotionAList().get(0).getSet1())); setRetailM(rm, promotion); } ret.add(rm); } } }else{ if(isIncludOne(retailMs, promotion)){ for(RetailM rm : retailMs){ if(rm.getFactAmount().compareTo(new BigDecimal(0)) != 1){ ret.add(rm); continue; } if(isAppoint(rm, promotion)){//在指定范围内 rm.setFactAmount(rm.getFactAmount().multiply(promotion.getPromotionAList().get(0).getSet1())); setRetailM(rm, promotion); } ret.add(rm); } }else{ return retailMs; } } return ret; } /** * 买指定商品可选购指定商品(折扣) * @param retailMs 零售明细集合 * @param promotion 促销方案 * @return * @throws POSException */ @Deprecated public static List<RetailM> applyAppoint1(List<RetailM> retailMs, Promotion promotion) throws POSException { if(null == retailMs){ return retailMs; } List<RetailM> ret = new ArrayList<RetailM>(); for(RetailM rm : retailMs){ setRetailM(rm, promotion); if(rm.getFactAmount().compareTo(new BigDecimal(0)) != 1){ ret.add(rm); continue; } if(promotion.getIsAll() == 1){//全场 if(isExclude(rm, promotion)){//全场排除 ret.add(rm); continue; }else{//不排除 if(isAppoint(rm, promotion)){//在指定范围内 rm.setFactAmount(rm.getFactAmount().multiply(promotion.getPromotionAList().get(0).getSet1())); }else{ ret.add(rm); continue; } } }else{//非全场 if(!filterInclud(rm, promotion)){//包含&排除 ret.add(rm); continue; }else{ if(isAppoint(rm, promotion)){//在指定范围内 rm.setFactAmount(rm.getFactAmount().multiply(promotion.getPromotionAList().get(0).getSet1())); }else{ ret.add(rm); continue; } } } ret.add(rm); } return ret; } /** * 捆绑销售:读取参与物料编号,排除不参与的物料编号,按设定值1进行打折(素金产品工费打折)。 * @param retailMs 零售明细集合 * @param promotion 促销方案 * @return * @throws POSException */ public static List<RetailM> applyPackage(List<RetailM> retailMs, Promotion promotion) throws POSException { if(null == retailMs){ return retailMs; } List<RetailM> ret = new ArrayList<RetailM>(); for(RetailM rm : retailMs){ setRetailM(rm, promotion); if(rm.getFactAmount().compareTo(new BigDecimal(0)) != 1){ ret.add(rm); continue; } List<PromotionA> promotionAList = promotion.getPromotionAList(); if(null == promotionAList || promotionAList.size() == 0){ return retailMs; } if(promotion.getIsAll() == 1){//全场 if(isExclude(rm, promotion)){ ret.add(rm); continue; } if(rm.getMatkl().startsWith("1")){//判断是否为素金 rm.setProcessFee_S(rm.getProcessFee().multiply(promotionAList.get(0).getSet1())); rm.setFactAmount(rm.getFactAmount().subtract(rm.getProcessFee().subtract(rm.getProcessFee_S())));//工费折扣之后修改实售价 }else{ rm.setFactAmount(rm.getFactAmount().multiply(promotionAList.get(0).getSet1())); } }else{ List<PromotionM> promotionMList = promotion.getPromotionMList(); if(null == promotionMList || promotionMList.size() == 0){ if(rm.getMatkl().startsWith("1")){//判断是否为素金 rm.setProcessFee_S(rm.getProcessFee_S().multiply(promotionAList.get(0).getSet1())); rm.setFactAmount(rm.getFactAmount().subtract(rm.getProcessFee().subtract(rm.getProcessFee_S())));//工费折扣之后修改实售价 }else{ rm.setFactAmount(rm.getFactAmount().multiply(promotionAList.get(0).getSet1())); } }else{ //包含并不在排除列表则打折 if(filterInclud(rm, promotion)){ BigDecimal setVal = promotionAList.get(0).getSet1(); if(rm.getMatkl().startsWith("1")){//判断是否为素金 rm.setProcessFee_S(rm.getProcessFee_S().multiply(setVal)); rm.setFactAmount(rm.getFactAmount().subtract(rm.getProcessFee().subtract(rm.getProcessFee_S())));//工费折扣之后修改实售价 }else{ rm.setFactAmount(rm.getFactAmount().multiply(setVal)); } } } } ret.add(rm); } return ret; } /** * 第N件打M折 * @param items * @param promotion * @return * @throws POSException */ public static List<RetailM> applyNM(List<RetailM> retailMs, Promotion promotion) throws POSException { if(null == retailMs){ return retailMs; } retailMs = filterRetailMs(retailMs, promotion); List<RetailM> retailMList = new ArrayList<RetailM>(); int num = promotion.getPromotionAList().get(0).getSet1().intValue();//第N件 BigDecimal points = promotion.getPromotionAList().get(0).getSet2();//打M折 for(int i=0; i<retailMs.size(); i++){ RetailM rm = retailMs.get(i); setRetailM(rm, promotion); // if(rm.getFactAmount().compareTo(new BigDecimal(0)) != 1){ retailMList.add(rm); continue; } if(i+1 != num){//当前bu是第num件 retailMList.add(rm); continue; } if(promotion.getIsAll() == 1){ if(isExclude(rm, promotion)){ retailMList.add(rm); continue; } rm.setFactAmount(rm.getFactAmount().multiply(points)); }else{ if(filterInclud(rm, promotion)){ rm.setFactAmount(rm.getFactAmount().multiply(points)); } } retailMList.add(rm); } return retailMList; } /** * 获取的优先的满减值,如A、满1000减100、B、满2000减200、C、满3000减300,如果当前整单为2500,同时满足A和B,那么应该优先按照B来促销 * @param factAmountCount * @param promotion * @return */ private static PromotionA getFirstPromotionA(BigDecimal factAmountCount, Promotion promotion){ PromotionA ret = null; List<PromotionA> pas = promotion.getPromotionAList(); if(null == pas || pas.size() == 0){ return null; } for(PromotionA pa : pas){ if(factAmountCount.compareTo(pa.getSet1()) == 1){ ret = pa; } } return ret; } /** * 整单满减 * @param retailMs 单品集合 * @param promotion 促销方案 * @return 促销之后的单品集合 * @throws POSException */ public static List<RetailM> applyAllNM(List<RetailM> retailMs, Promotion promotion) throws POSException { if(null == retailMs){ return retailMs; } BigDecimal factAmountCount = calculateFactAmountCountByFilter(retailMs, promotion); PromotionA promotionA = getFirstPromotionA(factAmountCount, promotion);//获取的优先的满减值,如满1000减100、满2000减200、满3000减300, if(null == promotionA){ return retailMs; } //按权重将减少的M元分摊到每件商品 List<RetailM> rmList = new ArrayList<RetailM>(); BigDecimal afterCountPrices = new BigDecimal(0);//单品折后价累加 BigDecimal afterNMCountPrices = factAmountCount.subtract(promotionA.getSet2());//折后总价 int num = 0; List<RetailM> rms = filterRetailMs(retailMs, promotion); for(int i=0; i<retailMs.size(); i++){ RetailM rm = retailMs.get(i); setRetailM(rm, promotion); if(rm.getFactAmount().compareTo(new BigDecimal(0)) != 1){ rmList.add(rm); continue; } if(rms.contains(rm)){ num = num+1; BigDecimal itemFactAnount = rm.getFactAmount();//单品实售价 BigDecimal pricesPoint = itemFactAnount.divide(factAmountCount, 4, BigDecimal.ROUND_HALF_UP); BigDecimal afterNMPrices = itemFactAnount.subtract(promotionA.getSet2().multiply(pricesPoint).setScale(2, BigDecimal.ROUND_HALF_UP));//单品折后价 //如果是最后一件 if(num == rms.size()){ rm.setFactAmount(afterNMCountPrices.subtract(afterCountPrices));//最后一件的折后价=折后总价-单品折后价累加 }else{ afterCountPrices = afterCountPrices.add(afterNMPrices);//折后总价=单品折后价累加(不包括最后一件) rm.setFactAmount(itemFactAnount.subtract(promotionA.getSet2().multiply(pricesPoint).setScale(2, BigDecimal.ROUND_HALF_UP))); } rmList.add(rm); }else{ rmList.add(rm); } } return rmList; } /** * 工费扣减 * @param retailMs * @param promotion * @return * @throws POSException */ public static List<RetailM> applyFeeD(List<RetailM> retailMs, Promotion promotion) throws POSException { if(null == retailMs){ return retailMs; } List<RetailM> ret = new ArrayList<RetailM>(); for(RetailM retailM : retailMs){ setRetailM(retailM, promotion); if((retailM.getFactAmount().compareTo(new BigDecimal(0)) != 1) || (retailM.getProcessFee_S().compareTo(new BigDecimal(0)) != 1)){ ret.add(retailM); continue; } BigDecimal subValue = promotion.getPromotionAList().get(0).getSet1();//扣减值 BigDecimal subAmount = retailM.getSalesWeight().multiply(subValue); if(subAmount.compareTo(retailM.getProcessFee_S()) == 1){ subAmount = retailM.getProcessFee_S(); } BigDecimal value = retailM.getProcessFee_S().subtract(subAmount);//扣减之后的实际工费 if(promotion.getIsAll() == 1){//全场 if(isExclude(retailM, promotion)){ ret.add(retailM); continue; } retailM.setProcessFee_S(value); }else{ if(!filterInclud(retailM, promotion)){//包含&排除 ret.add(retailM); continue; }else{ retailM.setProcessFee_S(value); } } retailM.setFactAmount(retailM.getFactAmount().subtract(subAmount));//工费扣减之后修改实售价 ret.add(retailM); } return ret; } /** * 工费打折 * @param retailMs * @param promotion * @return * @throws POSException */ public static List<RetailM> applyFee(List<RetailM> retailMs, Promotion promotion) throws POSException { if(null == retailMs){ return retailMs; } List<RetailM> ret = new ArrayList<RetailM>(); BigDecimal saleValue = promotion.getPromotionAList().get(0).getSet1();//折扣值 for(RetailM retailM : retailMs){ setRetailM(retailM, promotion); if(retailM.getFactAmount().compareTo(new BigDecimal(0)) != 1){ ret.add(retailM); continue; } BigDecimal value = retailM.getProcessFee_S().multiply(saleValue);//折扣之后的实际工费 BigDecimal factAmount = retailM.getFactAmount(); if(promotion.getIsAll() == 1){//全场 if(isExclude(retailM, promotion)){ ret.add(retailM); continue; } retailM.setFactAmount(factAmount.subtract(retailM.getProcessFee_S().subtract(value)));//工费折扣之后修改实售价 retailM.setProcessFee_S(retailM.getProcessFee_S().multiply(promotion.getPromotionAList().get(0).getSet1())); }else{ if(!filterInclud(retailM, promotion)){//包含&排除 ret.add(retailM); continue; }else{ retailM.setFactAmount(retailM.getFactAmount().subtract(retailM.getProcessFee_S().subtract(value)));//工费折扣之后修改实售价 retailM.setProcessFee_S(value); } } ret.add(retailM); } return ret; } /*****************************************************************************************/ /** * 设置零售明细促销方案ID和标题 * @param retailM 零售明细 * @param promotion 促销方案 */ private static void setRetailM(RetailM retailM, Promotion promotion){ retailM.setPromotionID(((null == retailM.getPromotionID())?"":retailM.getPromotionID())+promotion.getID()+","); retailM.setPromotionName(""); } /** * 根据是否全场、包含排除等过滤零售明细 * @param retailMs * @param promotion * @return */ private static List<RetailM> filterRetailMs(List<RetailM> retailMs, Promotion promotion){ List<RetailM> ret = new ArrayList<RetailM>(); if(promotion.getIsAll() == 1){ for(RetailM rm : retailMs){ if(isExclude(rm, promotion)){ continue; } ret.add(rm); } return ret; } for(RetailM retailM : retailMs){ if(filterInclud(retailM, promotion)){ ret.add(retailM); } } return ret; } /** * 判断是否全场,并计算包含之类排除之外的所有单品实售金额总和 * @param retailMs * @param promotion * @return */ private static BigDecimal calculateFactAmountCountByFilter(List<RetailM> retailMs, Promotion promotion){ BigDecimal factAmountCount = new BigDecimal(0); for(RetailM retailM : retailMs){ if(promotion.getIsAll() == 1){ factAmountCount = factAmountCount.add(retailM.getFactAmount()); }else{ if(filterInclud(retailM, promotion)){ factAmountCount = factAmountCount.add(retailM.getFactAmount()); } } } return factAmountCount; } /** * 包含&排除 =true * @param retailM * @param promotion * @return 不包含 false 包含,排除 false 包含不排除 true */ private static boolean filterInclud(RetailM retailM, Promotion promotion){ return !isExclude(retailM, promotion) && isInclud(retailM, promotion); } /** * 是否排除 * @param retailM * @param promotion * @return */ private static boolean isExclude(RetailM retailM, Promotion promotion){ boolean flag = false; List<PromotionM> promotionMList = promotion.getPromotionMList(); if(null == promotionMList || promotionMList.size() == 0){ return false; } for(PromotionM pm : promotionMList){ if(pm.getType().equals(AppConstants.PROMO_EXCLU)){ if(retailM.getMATNR().startsWith(pm.getMATNR())){ flag = true; } } } return flag; } /** * 是否全部排除 * @param retailM * @param promotion * @return */ private static boolean isExcludeAll(List<RetailM> retailMs, Promotion promotion){ boolean flag = true; for(RetailM rm : retailMs){ if(!isExclude(rm, promotion)){ flag = false; break; } } return flag; } /** * 是否包含(当前选购单品列表,只要有一个单品在包含中则返回true) * @param retailMs * @param promotion * @return */ private static boolean isIncludOne(List<RetailM> retailMs, Promotion promotion){ boolean flag = false; for(RetailM rm : retailMs){ if(isInclud(rm, promotion)){ flag = true; break; } } return flag; } /** * 是否包含 * @param retailM * @param promotion * @return */ private static boolean isInclud(RetailM retailM, Promotion promotion){ boolean flag = true; List<PromotionM> promotionMList = promotion.getPromotionMList(); if(null == promotionMList){ return true; } for(PromotionM pm : promotionMList){ if(pm.getType().equals(AppConstants.PROMO_INCLUD)){ if(retailM.getMATNR().startsWith(pm.getMATNR())){ flag = true; return flag;//多个包含的只要满足一个包含就返回true }else{ flag = false; } } } return flag; } /** * 获取某个促销方案指定物料编号列表 * @param promotion 促销方案 * @return */ private static List<String> getAppointListFromPromi(Promotion promotion){ List<String> appointList = new ArrayList<String>();//指定物料编号列表 List<PromotionM> promotionMList = promotion.getPromotionMList(); if(null == promotionMList){ return appointList; } for(PromotionM pm : promotionMList){ if(pm.getType().equals(AppConstants.PROMO_TO)){ appointList.add(pm.getMATNR()); } } return appointList; } /** * 是否在指定物料编号范围内 * @param rm 零售明细 * @param promotion 促销方案 * @return */ private static boolean isAppoint(RetailM rm, Promotion promotion){ boolean flag = false; List<String> appointList = new ArrayList<String>();//指定物料编号列表 List<PromotionM> promotionMList = promotion.getPromotionMList(); if(null == promotionMList || promotionMList.size() == 0){ return true; } for(PromotionM pm : promotionMList){ if(pm.getType().equals(AppConstants.PROMO_TO)){ appointList.add(pm.getMATNR()); } } for(String val : appointList){ if(rm.getMATNR().startsWith(val)){ flag = true; } } return flag; } }