public void awardFootballAutoRecommend(String mid) {
FootballAutoRecommend autoRecommend = footballAutoRecommendMapper.getByMid(mid);
if (autoRecommend == null) {
log.info("[mid:{}][比赛没有自动推荐]", mid);
return;
}
FootballHistory footballHistory = footballHistoryMapper.getByMid(Integer.parseInt(mid));
if (footballHistory == null) {
throw new CommonException("审核比赛不存在,mid:" + mid);
}
if (com.zhencai.common.business.czzj.crawler.constant.ConstantCommon.FOOTBALL_MATCH_AUDIT_CANCEL.equals(footballHistory.getState())) {
autoRecommend.setState(com.zhencai.common.business.czzj.crawler.constant.ConstantCommon.FOOTBALL_MATCH_AUDIT_CANCEL);
} else {
autoRecommend.setState(com.zhencai.common.business.czzj.crawler.constant.ConstantCommon.FOOTBALL_MATCH_AUDIT_FINISH);
if (StringUtils.isNotBlank(autoRecommend.getSpfRec())) {
if (StringUtils.isNotBlank(footballHistory.getSpfS())) {
autoRecommend.setSpfS(footballHistory.getSpfS());
autoRecommend.setSpfHit(autoRecommend.getSpfRec().contains(footballHistory.getSpfS()) ? ConstantCommon.AUTO_RECOMMEND_IS_HIT : ConstantCommon.AUTO_RECOMMEND_IS_UNHIT);
} else {
throw new CommonException("胜平负推荐结算失败,mid:" + mid);
}
}
if (StringUtils.isNotBlank(autoRecommend.getRqspfRec())) {
if (StringUtils.isNotBlank(footballHistory.getRqspfS())) {
autoRecommend.setRqspfS(footballHistory.getRqspfS());
autoRecommend.setRqspfHit(autoRecommend.getRqspfRec().contains(footballHistory.getRqspfS()) ? ConstantCommon.AUTO_RECOMMEND_IS_HIT : ConstantCommon.AUTO_RECOMMEND_IS_UNHIT);
autoRecommend.setRqspfHit1(autoRecommend.getRqspfRec1().contains(footballHistory.getRqspfS()) ? ConstantCommon.AUTO_RECOMMEND_IS_HIT : ConstantCommon.AUTO_RECOMMEND_IS_UNHIT);
} else {
throw new CommonException("让球胜平负推荐结算失败,mid:" + mid);
}
}
if (StringUtils.isNotBlank(autoRecommend.getJqsRec())) {
if (StringUtils.isNotBlank(footballHistory.getJqS())) {
autoRecommend.setJqsS(footballHistory.getJqS());
autoRecommend.setJqsHit(autoRecommend.getJqsRec().contains(footballHistory.getJqS()) ? ConstantCommon.AUTO_RECOMMEND_IS_HIT : ConstantCommon.AUTO_RECOMMEND_IS_UNHIT);
} else {
throw new CommonException("总进球推荐结算失败,mid:" + mid);
}
}
if (StringUtils.isNotBlank(autoRecommend.getBqcRec())) {
if (StringUtils.isNotBlank(footballHistory.getBqcS())) {
autoRecommend.setBqcS(footballHistory.getBqcS());
autoRecommend.setBqcHit(autoRecommend.getBqcRec().contains(footballHistory.getBqcS()) ? ConstantCommon.AUTO_RECOMMEND_IS_HIT : ConstantCommon.AUTO_RECOMMEND_IS_UNHIT);
} else {
throw new CommonException("半全场推荐结算失败,mid:" + mid);
}
}
if (StringUtils.isNotBlank(autoRecommend.getBfRec())) {
if (StringUtils.isNotBlank(footballHistory.getBfS())) {
autoRecommend.setBfS(footballHistory.getBfS());
autoRecommend.setBfHit(autoRecommend.getBfRec().contains(footballHistory.getBfS()) ? ConstantCommon.AUTO_RECOMMEND_IS_HIT : ConstantCommon.AUTO_RECOMMEND_IS_UNHIT);
} else {
throw new CommonException("比分推荐结算失败,mid:" + mid);
}
}
}
footballAutoRecommendMapper.audited(autoRecommend);
}
private void setAutoRecSpfInfo(MatchBattle matchBattle, FootballAutoRecommend footballAutoRecommend, Integer type) {
Integer tempRate = null;
String tempRec = null;
List<Map<String, Object>> spfHit = null;
spfHit = footballHistoryMapper.getHitBySpfRate(matchBattle.getMtime(), matchBattle.getSpfRate3(), matchBattle.getSpfRate1(),
matchBattle.getSpfRate0(), null, type, matchBattle.getRq());
Integer countMatch = 0;
for (Map<String, Object> stringObjectMap : spfHit) {
countMatch += Integer.parseInt(stringObjectMap.get("HIT").toString());
}
if (spfHit != null && spfHit.size() == 3 && countMatch > 15) {
Double maxHitOdd = null, midHitOdd = null;
Integer maxHit = Integer.parseInt(spfHit.get(0).get("HIT").toString());
Integer midHit = Integer.parseInt(spfHit.get(1).get("HIT").toString());
Integer minHit = Integer.parseInt(spfHit.get(2).get("HIT").toString());
String maxHitS = spfHit.get(0).get("SPF_S").toString();
String midHitS = spfHit.get(1).get("SPF_S").toString();
String minHitS = spfHit.get(2).get("SPF_S").toString();
Integer maxHitPreRate = null, midHitPreRate = null, minHitPreRate = null;
List<Integer> preRate = new ArrayList<>();
if (type == 1) {
maxHitOdd = Double.parseDouble(matchBattle.getSpfOddByResult(maxHitS));
midHitOdd = Double.parseDouble(matchBattle.getSpfOddByResult(midHitS));
maxHitPreRate = matchBattle.getSpfRateByResult(spfHit.get(0).get("SPF_S").toString());
midHitPreRate = matchBattle.getSpfRateByResult(spfHit.get(1).get("SPF_S").toString());
minHitPreRate = matchBattle.getSpfRateByResult(spfHit.get(2).get("SPF_S").toString());
} else {
maxHitOdd = Double.parseDouble(matchBattle.getRqspfOddByResult(maxHitS));
midHitOdd = Double.parseDouble(matchBattle.getRqspfOddByResult(midHitS));
maxHitPreRate = matchBattle.getRqspfRateByResult(spfHit.get(0).get("SPF_S").toString());
midHitPreRate = matchBattle.getRqspfRateByResult(spfHit.get(1).get("SPF_S").toString());
minHitPreRate = matchBattle.getRqspfRateByResult(spfHit.get(2).get("SPF_S").toString());
}
preRate.add(maxHitPreRate);
preRate.add(midHitPreRate);
preRate.add(minHitPreRate);
Collections.sort(preRate);
if (maxHit != null && midHit != null && minHit != null && StringUtils.isNotBlank(maxHitS) && StringUtils.isNotBlank(midHitS) && StringUtils.isNotBlank(minHitS)) {
BigDecimal sumResult = new BigDecimal(maxHit + midHit + minHit);
Integer maxHitRate = new BigDecimal("10000").multiply(new BigDecimal(maxHit).divide(sumResult, 4, BigDecimal.ROUND_HALF_UP)).setScale(0).intValue();
Integer midHitRate = new BigDecimal("10000").multiply(new BigDecimal(midHit).divide(sumResult, 4, BigDecimal.ROUND_HALF_UP)).setScale(0).intValue();
Integer minHitRate = new BigDecimal("10000").multiply(new BigDecimal(minHit).divide(sumResult, 4, BigDecimal.ROUND_HALF_UP)).setScale(0).intValue();
if (maxHitOdd <= ConstantCommon.FOOTBALL_AUTO_REC_SPF_MIN_ODD || (maxHitOdd <= ConstantCommon.FOOTBALL_AUTO_REC_SPF_MID_ODD && maxHitRate >= ConstantCommon.FOOTBALL_AUTO_REC_SPF_MID_RATE)) {
tempRec = maxHitS;
tempRate = maxHitRate > maxHitPreRate ? maxHitRate + preRate.get(0) : maxHitPreRate;
tempRate = tempRate < ConstantCommon.FOOTBALL_AUTO_REC_SPF_SINGLE_MIN_RATE
? ConstantCommon.FOOTBALL_AUTO_REC_SPF_SINGLE_MIN_RATE : tempRate > ConstantCommon.FOOTBALL_AUTO_REC_SPF_SINGLE_MAX_RATE
? ConstantCommon.FOOTBALL_AUTO_REC_SPF_SINGLE_MAX_RATE : tempRate;
} else {
if (midHitOdd < ConstantCommon.FOOTBALL_AUTO_REC_SPF_MID_ODD) {
tempRec = maxHitS + "," + minHitS;
tempRate = (maxHitRate + minHitRate) > (maxHitPreRate + minHitPreRate) ? maxHitRate + minHitRate + preRate.get(0) : maxHitRate + minHitRate;
} else {
tempRec = maxHitS + "," + midHitS;
tempRate = (maxHitRate + midHitRate) > (maxHitPreRate + midHitPreRate) ? maxHitRate + midHitRate + (4 * preRate.get(0) / 5) : maxHitRate + midHitRate;
}
tempRate = tempRate < ConstantCommon.FOOTBALL_AUTO_REC_SPF_STRAND_MIN_RATE
? ConstantCommon.FOOTBALL_AUTO_REC_SPF_STRAND_MIN_RATE : tempRate > ConstantCommon.FOOTBALL_AUTO_REC_SPF_STRAND_MAX_RATE
? ConstantCommon.FOOTBALL_AUTO_REC_SPF_STRAND_MAX_RATE : tempRate;
}
}
if (tempRate != null) {
tempRate = tempRate / 100 + (tempRate % 100 >= 50 ? 1 : 0);
}
if (type == 1) {
footballAutoRecommend.setSpfRec(tempRec);
footballAutoRecommend.setSpfRate(tempRate == null ? null : tempRate.toString());
} else if (type == 2) {
footballAutoRecommend.setRqspfRec(tempRec);
footballAutoRecommend.setRqspfRate(tempRate == null ? null : tempRate.toString());
} else {
footballAutoRecommend.setRqspfRec1(tempRec);
footballAutoRecommend.setRqspfRate1(tempRate == null ? null : tempRate.toString());
}
} else {
setNoRateSpfSelect(matchBattle, footballAutoRecommend, type, true);
}
}
private void setAutoRecJqsInfo(FootballMatchOdds6 beginOdds, FootballAutoRecommend footballAutoRecommend) {
List<Map<String, Object>> hitByJqsRate = footballHistoryMapper.getHitByJqsRate(beginOdds.getDt());
BigDecimal returnTate = MatchUtils.getAvgRate(beginOdds.getJqsSp0(), beginOdds.getJqsSp1(), beginOdds.getJqsSp2(), beginOdds.getJqsSp3(), beginOdds.getJqsSp4(), beginOdds.getJqsSp5(),
beginOdds.getJqsSp6(), beginOdds.getJqsSp7());
final Map<String, Map<String, BigDecimal>> allsMap = new HashMap<>();
for (Map<String, Object> infoMap : hitByJqsRate) {
BigDecimal realOdd = new BigDecimal(beginOdds.getJqsOddByResult(infoMap.get("JQ_S").toString()));
BigDecimal jqsRate = new BigDecimal("10000").multiply(returnTate.divide(new BigDecimal(beginOdds.getJqsOddByResult(infoMap.get("JQ_S").toString())), 4, BigDecimal.ROUND_HALF_UP)).setScale(0);
allsMap.put(infoMap.get("JQ_S").toString(), getJqsRecInfoMap(infoMap, realOdd, jqsRate));
}
List<String> recList = new ArrayList<>();
List<BigDecimal> oddsList = new ArrayList<>();
for (Map.Entry<String, Map<String, BigDecimal>> entry : allsMap.entrySet()) {
Map<String, BigDecimal> entryValue = entry.getValue();
oddsList.add(entryValue.get("ODD"));
if (entryValue.get("ODD").compareTo(entryValue.get("AVG_SP").subtract(entryValue.get("STD_SP"))) == -1) {
recList.add(entry.getKey());
}
}
String tempRec = "";
BigDecimal rate = new BigDecimal("0");
boolean flag = false;
if (recList.size() <= 1) {
flag = true;
if (MatchUtils.firstIsMin(allsMap.get(FootballResultType.JQS_3.getResult()).get("ODD"), oddsList)) {
recList.clear();
if (allsMap.get(FootballResultType.JQS_1.getResult()).get("ODD").compareTo(allsMap.get(FootballResultType.JQS_4.getResult()).get("ODD")) != -1) {
if (!recList.contains(FootballResultType.JQS_2.getResult())) {
recList.add(FootballResultType.JQS_2.getResult());
}
if (!recList.contains(FootballResultType.JQS_3.getResult())) {
recList.add(FootballResultType.JQS_3.getResult());
}
} else {
if (!recList.contains(FootballResultType.JQS_1.getResult())) {
recList.add(FootballResultType.JQS_1.getResult());
}
if (!recList.contains(FootballResultType.JQS_3.getResult())) {
recList.add(FootballResultType.JQS_3.getResult());
}
}
} else if (MatchUtils.firstIsMin(allsMap.get(FootballResultType.JQS_2.getResult()).get("ODD"), oddsList)) {
if (allsMap.get(FootballResultType.JQS_1.getResult()).get("ODD").compareTo(allsMap.get(FootballResultType.JQS_4.getResult()).get("ODD")) != -1) {
if (!recList.contains(FootballResultType.JQS_2.getResult())) {
recList.add(FootballResultType.JQS_2.getResult());
}
if (!recList.contains(FootballResultType.JQS_3.getResult())) {
recList.add(FootballResultType.JQS_3.getResult());
}
} else {
if (!recList.contains(FootballResultType.JQS_1.getResult())) {
recList.add(FootballResultType.JQS_1.getResult());
}
if (!recList.contains(FootballResultType.JQS_2.getResult())) {
recList.add(FootballResultType.JQS_2.getResult());
}
}
} else {
flag = true;
if (!recList.contains(FootballResultType.JQS_2.getResult())) {
recList.add(FootballResultType.JQS_2.getResult());
}
if (!recList.contains(FootballResultType.JQS_3.getResult())) {
recList.add(FootballResultType.JQS_3.getResult());
}
}
}
List<String> deleteKeys = new ArrayList<>();
Iterator<String> iterator = recList.iterator();
while (iterator.hasNext()) {
String key = iterator.next();
if (allsMap.get(key).get("ODD").compareTo(allsMap.get(key).get("AVG_SP").add(allsMap.get(key).get("STD_SP"))) == 1) {
iterator.remove();
deleteKeys.add(key);
}
}
if (!deleteKeys.isEmpty()) {
if (recList.isEmpty()) {
recList.add(FootballResultType.JQS_2.getResult());
recList.add(FootballResultType.JQS_3.getResult());
} else {
BigDecimal sumOdd = new BigDecimal("0");
for (String rec : recList) {
sumOdd = sumOdd.add(allsMap.get(rec).get("ODD"));
}
if (ConstantCommon.FOOTBALL_JQS_REC_RATE > new BigDecimal(ConstantCommon.FOOTBALL_JQS_RETURN_RATE).divide(sumOdd, 0, BigDecimal.ROUND_HALF_UP).intValue()) {
recList.add(getTheMinWhereInStdOdd(allsMap, recList));
}
}
}
if (flag) {
BigDecimal minRate = new BigDecimal("0");
for (String rec : recList) {
rate = rate.add(allsMap.get(rec).get("RATE"));
tempRec += rec + ",";
if (allsMap.get(rec).get("RATE").compareTo(minRate) == -1 || minRate.compareTo(new BigDecimal("0")) == 0) {
minRate = allsMap.get(rec).get("RATE");
}
}
rate = rate.add(minRate.multiply(new BigDecimal("1.5")));
} else {
Collections.sort(recList, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return allsMap.get(o1).get("ODD").compareTo(allsMap.get(o2).get("ODD"));
}
});
recList = recList.subList(0, 2);
recList.add(getTheMinWhereInStdOdd(allsMap, recList));
for (String rec : recList) {
rate = rate.add(allsMap.get(rec).get("RATE"));
tempRec += rec + ",";
}
BigDecimal subtract = new BigDecimal("2.5").subtract(new BigDecimal("0.1").multiply(new BigDecimal(recList.size())));
rate = rate.multiply(subtract);
}
rate.setScale(0, BigDecimal.ROUND_HALF_UP);
Integer jqsRate = null;
if (recList.size() == 1) {
if (rate.intValue() < ConstantCommon.FOOTBALL_AUTO_REC_JQS_SINGLE_MIN_RATE) {
jqsRate = ConstantCommon.FOOTBALL_AUTO_REC_SPF_SINGLE_MIN_RATE;
} else if (rate.intValue() > ConstantCommon.FOOTBALL_AUTO_REC_JQS_SINGLE_MAX_RATE) {
jqsRate = ConstantCommon.FOOTBALL_AUTO_REC_JQS_SINGLE_MAX_RATE;
} else {
jqsRate = rate.intValue();
}
} else if (recList.size() > 1) {
if (rate.intValue() < ConstantCommon.FOOTBALL_AUTO_REC_JQS_STRAND_MIN_RATE) {
jqsRate = ConstantCommon.FOOTBALL_AUTO_REC_JQS_STRAND_MIN_RATE;
} else if (rate.intValue() > ConstantCommon.FOOTBALL_AUTO_REC_JQS_STRAND_MAX_RATE) {
jqsRate = ConstantCommon.FOOTBALL_AUTO_REC_JQS_STRAND_MAX_RATE;
} else {
jqsRate = rate.intValue();
}
}
if (jqsRate != null) {
jqsRate = jqsRate / 100 + (jqsRate % 100 >= 50 ? 1 : 0);
}
tempRec = tempRec.substring(0, tempRec.length() - 1);
footballAutoRecommend.setJqsRate(jqsRate == null ? null : jqsRate.toString());
footballAutoRecommend.setJqsRec(tempRec);
}