puzhibing
2024-03-06 f6d50410b2674c2564be93b3887fff60e5769bd1
cloud-server-communityWorldCup/src/main/java/com/dsh/communityWorldCup/service/impl/WorldCupCompetitorServiceImpl.java
@@ -17,6 +17,7 @@
import com.dsh.communityWorldCup.model.*;
import com.dsh.communityWorldCup.service.IWorldCupCompetitorService;
import com.dsh.communityWorldCup.service.IWorldCupService;
import com.dsh.communityWorldCup.util.ToolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -24,6 +25,7 @@
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.*;
/**
@@ -342,4 +344,177 @@
        map1.put("total", count);
        return map1;
    }
    /**
     * 获取比赛统计详情列表
     * @param worldCupGameStatisticsInfoList
     * @return
     */
    @Override
    public Map<String, Object> worldCupGameStatisticsInfoList(WorldCupGameStatisticsInfoList worldCupGameStatisticsInfoList) {
        Map<String, Object> map1 = new HashMap<>();
        Integer id = worldCupGameStatisticsInfoList.getId();
        String name = worldCupGameStatisticsInfoList.getName();
        String phone = worldCupGameStatisticsInfoList.getPhone();
        String idcard = worldCupGameStatisticsInfoList.getIdcard();
        List<Map<String, Object>> mapList = this.baseMapper.worldCupGameStatisticsInfoList(id);
        List<Map<String, Object>> list = new ArrayList<>();
        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 appUserId = Integer.valueOf(map.get("appUserId").toString());
            Integer totalSession = Integer.valueOf(map.get("totalSession").toString());
            Integer win = Integer.valueOf(map.get("win").toString());
            Integer lose = totalSession - win;
            map.put("lose", lose);
            AppUser appUser = appUserClient.getAppUser(appUserId);
            map.put("province", appUser.getProvince() + appUser.getCity());
            if(1 == participantType){
                TStudent tStudent = studentClient.queryById(participantId);
                if(ToolUtil.isNotEmpty(name) && tStudent.getName().indexOf(name) == -1){
                    continue;
                }
                if(ToolUtil.isNotEmpty(phone) && tStudent.getPhone().indexOf(phone) == -1){
                    continue;
                }
                if(ToolUtil.isNotEmpty(idcard) && tStudent.getIdCard().indexOf(idcard) == -1){
                    continue;
                }
                map.put("name", tStudent.getName());
                map.put("phone", tStudent.getPhone());
            }else{
                Participant participant = participantClient.getParticipant(participantId);
                if(ToolUtil.isNotEmpty(name) && participant.getName().indexOf(name) == -1){
                    continue;
                }
                if(ToolUtil.isNotEmpty(phone) && participant.getPhone().indexOf(phone) == -1){
                    continue;
                }
                if(ToolUtil.isNotEmpty(idcard) && participant.getIdcard().indexOf(idcard) == -1){
                    continue;
                }
                map.put("name", participant.getName());
                map.put("phone", participant.getPhone());
            }
            list.add(map);
        }
        map1.put("total", mapList.size());
        Integer offset = worldCupGameStatisticsInfoList.getOffset();
        Integer limit = worldCupGameStatisticsInfoList.getLimit();
        limit += offset;
        map1.put("rows", mapList.subList(offset, mapList.size() >= limit ? limit : mapList.size()));
        return map1;
    }
    /**
     * 获取单场参赛详情列表
     * @return
     */
    @Override
    public Map<String, Object> worldCupGameStatisticsListInfo(WorldCupGameStatisticsListInfo worldCupGameStatisticsListInfo) {
        Long id = worldCupGameStatisticsListInfo.getId();
        String name = worldCupGameStatisticsListInfo.getName();
        WorldCupCompetitor worldCupCompetitor = this.getById(id);
        List<WorldCupCompetitor> list = this.list(new QueryWrapper<WorldCupCompetitor>().eq("code", worldCupCompetitor.getCode()));
        List<Map<String, Object>> mapList = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.HH.dd HH:mm");
        for (WorldCupCompetitor cupCompetitor : list) {
            Map<String, Object> map = new HashMap<>();
            map.put("id", cupCompetitor.getId());
            Integer participantType = cupCompetitor.getParticipantType();
            Integer participantId = cupCompetitor.getParticipantId();
            if(1 == participantType){
                TStudent tStudent = studentClient.queryById(participantId);
                if(ToolUtil.isNotEmpty(name) && tStudent.getName().indexOf(name) == -1){
                    continue;
                }
                map.put("name", tStudent.getName());
            }else{
                Participant participant = participantClient.getParticipant(participantId);
                if(ToolUtil.isNotEmpty(name) && participant.getName().indexOf(name) == -1){
                    continue;
                }
                map.put("name", participant.getName());
            }
            map.put("startTime", sdf.format(cupCompetitor.getStartTime()));
            map.put("score", cupCompetitor.getOurScore().compareTo(cupCompetitor.getOpponentScore()) > 0 ?
                    cupCompetitor.getOurScore() + ":" + cupCompetitor.getOpponentScore() :
                    cupCompetitor.getOpponentScore() + ":" + cupCompetitor.getOurScore());
            map.put("matchResult", cupCompetitor.getMatchResult() == 1 ? "胜" : "负");
            mapList.add(map);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("rows", mapList);
        map.put("total", mapList.size());
        return map;
    }
    /**
     * 修改比分
     * @param changeScore
     */
    @Override
    public void changeScore(ChangeScore changeScore) {
        Long id = changeScore.getId();
        Integer blue = changeScore.getBlue();
        Integer red = changeScore.getRed();
        WorldCupCompetitor worldCupCompetitor = this.getById(id);
        List<WorldCupCompetitor> blueList = this.list(new QueryWrapper<WorldCupCompetitor>().eq("code", worldCupCompetitor.getCode()).eq("participant", 1));
        WorldCup worldCup = worldCupService.getById(blueList.get(0).getWorldCupId());
        for (WorldCupCompetitor cupCompetitor : blueList) {
            //如果之前输了,现在赢了,需要增加积分
            if(cupCompetitor.getMatchResult() == -1 && blue.compareTo(red) > 0){
                AppUser appUser = appUserClient.getAppUser(cupCompetitor.getAppUserId());
                appUser.setIntegral(appUser.getIntegral() + worldCup.getWinIntegral());
                appUserClient.updateAppUser(appUser);
                cupCompetitor.setMatchResult(1);
                cupCompetitor.setWinIntegral(worldCup.getWinIntegral());
            }
            //如果之前赢了,现在输了,需要扣减积分
            if(cupCompetitor.getMatchResult() == 1 && blue.compareTo(red) < 0){
                AppUser appUser = appUserClient.getAppUser(cupCompetitor.getAppUserId());
                appUser.setIntegral(appUser.getIntegral() - worldCup.getWinIntegral());
                appUserClient.updateAppUser(appUser);
                cupCompetitor.setMatchResult(-1);
                cupCompetitor.setWinIntegral(0);
            }
            cupCompetitor.setOurScore(blue);
            cupCompetitor.setOpponentScore(red);
        }
        this.updateBatchById(blueList);
        List<WorldCupCompetitor> redList = this.list(new QueryWrapper<WorldCupCompetitor>().eq("code", worldCupCompetitor.getCode()).eq("participant", 2));
        for (WorldCupCompetitor cupCompetitor : redList) {
            //如果之前输了,现在赢了,需要增加积分
            if(cupCompetitor.getMatchResult() == -1 && red.compareTo(blue) > 0){
                AppUser appUser = appUserClient.getAppUser(cupCompetitor.getAppUserId());
                appUser.setIntegral(appUser.getIntegral() + worldCup.getWinIntegral());
                appUserClient.updateAppUser(appUser);
                cupCompetitor.setMatchResult(1);
                cupCompetitor.setWinIntegral(worldCup.getWinIntegral());
            }
            //如果之前赢了,现在输了,需要扣减积分
            if(cupCompetitor.getMatchResult() == 1 && red.compareTo(blue) < 0){
                AppUser appUser = appUserClient.getAppUser(cupCompetitor.getAppUserId());
                appUser.setIntegral(appUser.getIntegral() - worldCup.getWinIntegral());
                appUserClient.updateAppUser(appUser);
                cupCompetitor.setMatchResult(-1);
                cupCompetitor.setWinIntegral(0);
            }
            cupCompetitor.setOurScore(red);
            cupCompetitor.setOpponentScore(blue);
        }
        this.updateBatchById(blueList);
    }
}