package com.dsh.communityWorldCup.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.dsh.communityWorldCup.entity.WorldCupCompetitor;
|
import com.dsh.communityWorldCup.feignclient.account.AppUserClient;
|
import com.dsh.communityWorldCup.feignclient.account.StudentClient;
|
import com.dsh.communityWorldCup.feignclient.account.model.AppUser;
|
import com.dsh.communityWorldCup.feignclient.account.model.TStudent;
|
import com.dsh.communityWorldCup.feignclient.competition.ParticipantClient;
|
import com.dsh.communityWorldCup.feignclient.competition.model.Participant;
|
import com.dsh.communityWorldCup.feignclient.other.StoreClient;
|
import com.dsh.communityWorldCup.mapper.WorldCupCompetitorMapper;
|
import com.dsh.communityWorldCup.model.EntrantRank;
|
import com.dsh.communityWorldCup.model.EntrantRankVo;
|
import com.dsh.communityWorldCup.service.IWorldCupCompetitorService;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.math.MathContext;
|
import java.math.RoundingMode;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @author zhibing.pu
|
* @Date 2024/2/19 15:47
|
*/
|
@Service
|
public class WorldCupCompetitorServiceImpl extends ServiceImpl<WorldCupCompetitorMapper, WorldCupCompetitor> implements IWorldCupCompetitorService {
|
|
@Resource
|
private StudentClient studentClient;
|
|
@Resource
|
private ParticipantClient participantClient;
|
|
@Resource
|
private AppUserClient appUserClient;
|
|
|
|
|
|
/**
|
* 获取参赛人员名次信息
|
* @param entrantRank
|
* @return
|
*/
|
@Override
|
public EntrantRankVo getEntrantRank(EntrantRank entrantRank) {
|
EntrantRankVo entrantRankVo = new EntrantRankVo();
|
if(entrantRank.getIsStudent() == 0){
|
//参赛人员
|
Participant participant = participantClient.getParticipant(entrantRank.getId());
|
entrantRankVo.setName(participant.getName());
|
}else{
|
//学员
|
TStudent tStudent = studentClient.queryById(entrantRank.getId());
|
entrantRankVo.setName(tStudent.getName());
|
}
|
//全国排名---直接数据库分组查询后排序
|
entrantRankVo.setNationalRank(0);
|
List<Map<String, Object>> mapList = this.baseMapper.getNumberOfGamesRanked(null);
|
for (int i = 0; i < mapList.size(); i++) {
|
Map<String, Object> map = mapList.get(i);
|
Integer participantType = Integer.valueOf(map.get("participantType").toString());
|
Integer participantId = Integer.valueOf(map.get("participantId").toString());
|
Integer num = Integer.valueOf(map.get("num").toString());
|
if(null != participantId && participantId.equals(entrantRank.getId()) && participantType.equals(entrantRank.getIsStudent())){
|
entrantRankVo.setNationalRank(i + 1);
|
}
|
}
|
/**
|
* 城市排名
|
* 1、先查询出当前用户对应的城市
|
* 2、再根据城市查询对应的所有人员
|
* 3、再根据查询出来的参赛人分组查询出参赛次数后排序
|
*/
|
entrantRankVo.setCityRank(0);
|
AppUser appUser = appUserClient.getAppUser(entrantRank.getAppUserId());
|
entrantRankVo.setCityName(appUser.getCity());
|
List<Integer> appUserIds = appUserClient.getAppUserIds(appUser.getCityCode());
|
List<Map<String, Object>> mapList1 = this.baseMapper.getNumberOfGamesRanked(appUserIds);
|
for (int i = 0; i < mapList1.size(); i++) {
|
Map<String, Object> map = mapList1.get(i);
|
Integer participantType = Integer.valueOf(map.get("participantType").toString());
|
Integer participantId = Integer.valueOf(map.get("participantId").toString());
|
Integer num = Integer.valueOf(map.get("num").toString());
|
if(null != participantId && participantId.equals(entrantRank.getId()) && participantType.equals(entrantRank.getIsStudent())){
|
entrantRankVo.setCityRank(i + 1);
|
}
|
}
|
QueryWrapper<WorldCupCompetitor> wrapper = new QueryWrapper<>();
|
if(entrantRank.getIsStudent() == 0){
|
wrapper.eq("participantType", 2);
|
}else{
|
wrapper.eq("participantType", 1);
|
}
|
int win = this.count(wrapper.eq("participantId", entrantRank.getId()).eq("matchResult", 1));
|
entrantRankVo.setWin(win);
|
|
wrapper = new QueryWrapper<>();
|
if(entrantRank.getIsStudent() == 0){
|
wrapper.eq("participantType", 2);
|
}else{
|
wrapper.eq("participantType", 1);
|
}
|
int lose = this.count(wrapper.eq("participantId", entrantRank.getId()).eq("matchResult", -1));
|
entrantRankVo.setLose(lose);
|
if((win + lose) == 0){
|
entrantRankVo.setWinRate(0D);
|
}else{
|
entrantRankVo.setWinRate(new BigDecimal(win).divide(new BigDecimal(win + lose), new MathContext(4, RoundingMode.HALF_EVEN)).multiply(new BigDecimal(100)).doubleValue());
|
}
|
return entrantRankVo;
|
}
|
}
|