Commit 605580c6 by 刘栋

UDI-匹配规则更新

parent bb59e340
...@@ -132,35 +132,48 @@ public class MatchHelper { ...@@ -132,35 +132,48 @@ public class MatchHelper {
private void match(Long taskId, MatchData matchData){ private void match(Long taskId, MatchData matchData){
// 查询udi // 查询udi
//Page<UdiVo> voPage = this.queryUdi(udiPageNo,pageSize,matchData); //Page<UdiVo> voPage = this.queryUdi(udiPageNo,pageSize,matchData);
List<UdiMatchRateVo> matchRateVoList = new ArrayList<>(); List<UdiMatchRateVo> matchRateVoAllList = new ArrayList<>();
boolean haveHundredFlag = false;
if(StringUtils.isNotBlank(matchData.getUdiCode())){ if(StringUtils.isNotBlank(matchData.getUdiCode())){
// 去匹配udiCode // 去匹配udiCode
matchRateVoList = this.queryUdiNew(matchData); List<UdiMatchRateVo> matchRateVoList = this.queryUdiNew(matchData);
matchRateVoList.forEach(i->i.setSource(1)); this.setSource(matchRateVoList,1);
} else if(StringUtils.isNotBlank(matchData.getYiBaoCode())){ matchRateVoAllList.addAll(matchRateVoList);
haveHundredFlag = this.haveHundred(matchRateVoList);
}
if(!haveHundredFlag && StringUtils.isNotBlank(matchData.getYiBaoCode())){
// 去匹配YiBaoCode // 去匹配YiBaoCode
matchRateVoList = this.queryYiBaoCode(matchData); List<UdiMatchRateVo> matchRateVoList = this.queryYiBaoCode(matchData);
matchRateVoList.forEach(i->i.setSource(2)); this.setSource(matchRateVoList,2);
} else if(StringUtils.isNotBlank(matchData.getCompanyName()) || StringUtils.isNotBlank(matchData.getProductFactoryCode())){ matchRateVoAllList.addAll(matchRateVoList);
haveHundredFlag = this.haveHundred(matchRateVoList);
}
if(!haveHundredFlag && (StringUtils.isNotBlank(matchData.getCompanyName()) || StringUtils.isNotBlank(matchData.getProductFactoryCode())) ){
// 厂家+产品货号/编号 // 厂家+产品货号/编号
matchRateVoList = matchESHelper.three(matchData.getCompanyName(), matchData.getProductFactoryCode()); List<UdiMatchRateVo> matchRateVoList = matchESHelper.three(matchData.getCompanyName(), matchData.getProductFactoryCode());
matchRateVoList.forEach(i->i.setSource(3)); this.setSource(matchRateVoList,3);
} else if (StringUtils.isNotBlank(matchData.getBrandName()) matchRateVoAllList.addAll(matchRateVoList);
haveHundredFlag = this.haveHundred(matchRateVoList);
}
if (!haveHundredFlag && (StringUtils.isNotBlank(matchData.getBrandName())
|| StringUtils.isNotBlank(matchData.getProductName()) || StringUtils.isNotBlank(matchData.getProductName())
|| StringUtils.isNotBlank(matchData.getSpecification()) || StringUtils.isNotBlank(matchData.getSpecification())
|| StringUtils.isNotBlank(matchData.getModel())) { || StringUtils.isNotBlank(matchData.getModel())) ) {
// 品牌+名称+规格+型号; // 品牌+名称+规格+型号;
matchRateVoList = matchESHelper.four(matchData.getBrandName(), List<UdiMatchRateVo> matchRateVoList = matchESHelper.four(matchData.getBrandName(),
matchData.getProductName(), matchData.getProductName(),
matchData.getSpecification(), matchData.getSpecification(),
matchData.getModel()); matchData.getModel());
matchRateVoList.forEach(i->i.setSource(4)); this.setSource(matchRateVoList,4);
matchRateVoAllList.addAll(matchRateVoList);
} }
// 需要按照匹配率高低排序,留20条
List<UdiMatchRateVo> matchRateVoSortList = this.getTopNMatchRates(matchRateVoAllList, 20);
// 计算匹配率 // 计算匹配率
List<MatchTemp> matchTempList = new ArrayList<>(); List<MatchTemp> matchTempList = new ArrayList<>();
boolean hundredRate = false; boolean hundredRate = false;
for (UdiMatchRateVo udiVo : matchRateVoList) { for (UdiMatchRateVo udiVo : matchRateVoSortList) {
// 核心匹配率逻辑 // 核心匹配率逻辑
BigDecimal matchRate = udiVo.getMatchRatio(); BigDecimal matchRate = udiVo.getMatchRatio();
if(matchRate.compareTo(ONE_HUNDRED_RATE) == 0){ if(matchRate.compareTo(ONE_HUNDRED_RATE) == 0){
...@@ -207,6 +220,30 @@ public class MatchHelper { ...@@ -207,6 +220,30 @@ public class MatchHelper {
} }
} }
/**
* 判断是否有百分之百的数据存在
* @param list
* @return
*/
private boolean haveHundred(List<UdiMatchRateVo> list){
for (UdiMatchRateVo udiMatchRateVo : list) {
BigDecimal matchRatio = udiMatchRateVo.getMatchRatio();
if(matchRatio.compareTo(ONE_HUNDRED_RATE) == 0){
return true;
}
}
return false;
}
private List<UdiMatchRateVo> getTopNMatchRates(List<UdiMatchRateVo> matchRateVoAllList, int n){
// 按照 matchRatio 字段降序排序,并且保留前 n 条数据
// todo 是否需要根据id进行去重?
return matchRateVoAllList.stream()
.sorted((vo1, vo2) -> vo2.getMatchRatio().compareTo(vo1.getMatchRatio()))
.limit(n)
.collect(Collectors.toList());
}
/** /**
* 查询udi * 查询udi
...@@ -260,7 +297,7 @@ public class MatchHelper { ...@@ -260,7 +297,7 @@ public class MatchHelper {
} }
} }
return udiMapper.getUdiCodeRegex(yiBaoCode,yiBaoCodeRegexList); return udiMapper.getYiBaoCodeRegex(yiBaoCode,yiBaoCodeRegexList);
} }
private void setSource(List<UdiMatchRateVo> list, Integer source){ private void setSource(List<UdiMatchRateVo> list, Integer source){
......
...@@ -101,7 +101,7 @@ ...@@ -101,7 +101,7 @@
FROM product as p FROM product as p
WHERE p.yi_bao_code = #{yiBaoCode} WHERE p.yi_bao_code = #{yiBaoCode}
OR p.yi_bao_code like CONCAT(#{yiBaoCode},'%') OR p.yi_bao_code like CONCAT(#{yiBaoCode},'%')
<foreach collection="udiCodeList" item="item" open="" close="" separator=""> <foreach collection="yiBaoCodeList" item="item" open="" close="" separator="">
OR p.yi_bao_code like CONCAT(#{item},'%') OR p.yi_bao_code like CONCAT(#{item},'%')
</foreach> </foreach>
ORDER BY match_ratio DESC , p.yi_bao_code DESC ORDER BY match_ratio DESC , p.yi_bao_code DESC
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment