DrawLotsGroupJudgesServiceImpl.java 7.01 KB
package com.subsidy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.subsidy.dto.group.JudgeScoreScreenDTO;
import com.subsidy.dto.group.MatchJudgesDTO;
import com.subsidy.dto.judge.AddJudgeDTO;
import com.subsidy.mapper.DrawLotGroupDictMapper;
import com.subsidy.mapper.DrawLotsGroupItemsMapper;
import com.subsidy.mapper.ProjectMapper;
import com.subsidy.model.DrawLotGroupDictDO;
import com.subsidy.model.DrawLotsGroupItemsDO;
import com.subsidy.model.DrawLotsGroupJudgesDO;
import com.subsidy.mapper.DrawLotsGroupJudgesMapper;
import com.subsidy.model.DrawLotsScenesDO;
import com.subsidy.service.DrawLotsGroupJudgesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import com.subsidy.vo.group.JudgeScoreScreenVO;
import com.subsidy.vo.group.MatchJudgesVO;
import com.subsidy.vo.group.ScoreScreenVO;
import com.subsidy.vo.group.SelectJudgesVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 赛组评委表 服务实现类
 * </p>
 *
 * @author Tuyp
 * @since 2025-12-10
 */
@Service
public class DrawLotsGroupJudgesServiceImpl extends ServiceImpl<DrawLotsGroupJudgesMapper, DrawLotsGroupJudgesDO> implements DrawLotsGroupJudgesService {

    @Autowired
    private DrawLotGroupDictMapper drawLotGroupDictMapper;

    @Autowired
    private DrawLotsGroupItemsMapper drawLotsGroupItemsMapper;

    @Autowired
    private DrawLotsGroupJudgesMapper drawLotsGroupJudgesMapper;

    @Autowired
    private ProjectMapper projectMapper;

    @Override
    public IPage<MatchJudgesVO> matchJudges(MatchJudgesDTO matchJudgesDTO) {
        Page page = new Page(matchJudgesDTO.getPageNum(), matchJudgesDTO.getPageSize());
        IPage<MatchJudgesVO> matchJudgesVOIPage = this.baseMapper.matchJudges(page, matchJudgesDTO.getSceneId(), matchJudgesDTO.getUserName(), matchJudgesDTO.getExpectorType(), matchJudgesDTO.getRoleType());

        List<MatchJudgesVO> matchJudgesVOS = matchJudgesVOIPage.getRecords();
        for (MatchJudgesVO matchJudgesVO : matchJudgesVOS){
            List<DrawLotGroupDictDO> drawLotGroupDictDOS = drawLotsGroupJudgesMapper.judgeGroups(matchJudgesVO.getId(),matchJudgesDTO.getSceneId());
            matchJudgesVO.setGroupDictDOS(drawLotGroupDictDOS);
        }
        return matchJudgesVOIPage;
    }

    @Override
    public IPage<SelectJudgesVO> selectJudges(MatchJudgesDTO matchJudgesDTO) {
        Page page = new Page(matchJudgesDTO.getPageNum(), matchJudgesDTO.getPageSize());
        return this.baseMapper.selectJudges(page, matchJudgesDTO.getSceneId(), matchJudgesDTO.getUserName());
    }

    @Override
    public String removeJudge(DrawLotsGroupJudgesDO drawLotsGroupJudgesDO) {
        this.baseMapper.deleteById(drawLotsGroupJudgesDO.getId());
        return ConstantUtils.DELETE_SUCCESS;
    }

    @Override
    public String updateJudge(AddJudgeDTO addJudgeDTO) {

        //将之前的清掉
        this.baseMapper.delete(new QueryWrapper<DrawLotsGroupJudgesDO>()
                .lambda()
                .eq(DrawLotsGroupJudgesDO::getJudgeId,addJudgeDTO.getId()));

        List<Long> groupIds = addJudgeDTO.getGroupIds();
        for (Long id : groupIds){
            DrawLotsGroupJudgesDO drawLotsGroupJudgesDO = new DrawLotsGroupJudgesDO();
            drawLotsGroupJudgesDO.setJudgeId(addJudgeDTO.getId());
            drawLotsGroupJudgesDO.setGroupId(id);
            drawLotsGroupJudgesDO.setSceneId(addJudgeDTO.getSceneId());
            this.baseMapper.insert(drawLotsGroupJudgesDO);
        }

        return ConstantUtils.SUCCESS_UPDATE;
    }

    @Override
    public String addJudge(AddJudgeDTO addJudgeDTO) {

        List<Long> judgeIds = addJudgeDTO.getJudgeIds();
        for (Long judgeId : judgeIds) {
            DrawLotsGroupJudgesDO drawLotsGroupJudgesDO = new DrawLotsGroupJudgesDO();
            drawLotsGroupJudgesDO.setJudgeId(judgeId);
            drawLotsGroupJudgesDO.setSceneId(addJudgeDTO.getSceneId());
            this.baseMapper.insert(drawLotsGroupJudgesDO);
        }
        return ConstantUtils.ADD_SUCCESS;
    }

    @Override
    public String assignJudge(AddJudgeDTO addJudgeDTO) {

        List<Long> judgeIds = addJudgeDTO.getIds();

        List<Long> groupIds = addJudgeDTO.getGroupIds();

        for (Long id : judgeIds) {
            //将之前的清掉
            this.baseMapper.delete(new QueryWrapper<DrawLotsGroupJudgesDO>()
                    .lambda()
                    .eq(DrawLotsGroupJudgesDO::getJudgeId,id));

            for (Long groupId : groupIds){
                DrawLotsGroupJudgesDO drawLotsGroupJudgesDO = new DrawLotsGroupJudgesDO();
                drawLotsGroupJudgesDO.setJudgeId(id);
                drawLotsGroupJudgesDO.setGroupId(groupId);
                drawLotsGroupJudgesDO.setSceneId(addJudgeDTO.getSceneId());
                this.baseMapper.insert(drawLotsGroupJudgesDO);
            }
        }
        return ConstantUtils.SUCCESS_UPDATE;
    }

    @Override
    public List<JudgeScoreScreenVO> judgeScoreScreen(JudgeScoreScreenDTO judgeScoreScreenDTO) {

        List<JudgeScoreScreenVO> result = new ArrayList<>();
        //项目编号
        List<Integer> integers = judgeScoreScreenDTO.getGroupNums();

        DrawLotGroupDictDO drawLotGroupDictDO = drawLotGroupDictMapper.selectById(judgeScoreScreenDTO.getGroupId());

        for (Integer integer : integers) {
            JudgeScoreScreenVO judgeScoreScreenVO = new JudgeScoreScreenVO();

            String userName = projectMapper.projectUserName(Long.valueOf(integer));
            judgeScoreScreenVO.setUserName(userName);

            judgeScoreScreenVO.setGroupName(drawLotGroupDictDO.getGroupName());
            judgeScoreScreenVO.setGroupNum(integer);
            List<ScoreScreenVO> scoreScreenVOS = this.baseMapper.judgeScoreScreen(judgeScoreScreenDTO.getGroupId(), integer);
            judgeScoreScreenVO.setScoreScreenVOS(scoreScreenVOS);

            DrawLotsGroupItemsDO drawLotsGroupItemsDO = drawLotsGroupItemsMapper.selectOne(new QueryWrapper<DrawLotsGroupItemsDO>()
                    .lambda()
                    .eq(DrawLotsGroupItemsDO::getGroupId, judgeScoreScreenDTO.getGroupId())
                    .eq(DrawLotsGroupItemsDO::getProjectId, integer));
            judgeScoreScreenVO.setTotalScore(drawLotsGroupItemsDO.getTotalScore());
            result.add(judgeScoreScreenVO);
        }

        return result;
    }

    @Override
    public List<DrawLotsScenesDO> judgeScenes(DrawLotsGroupJudgesDO drawLotsGroupJudgesDO) {
        return this.baseMapper.judgeScenes(drawLotsGroupJudgesDO.getJudgeId());
    }

    @Override
    public List<DrawLotGroupDictDO> judgeGroups(DrawLotsGroupJudgesDO drawLotsGroupJudgesDO) {
        return this.baseMapper.judgeGroups(drawLotsGroupJudgesDO.getJudgeId(),drawLotsGroupJudgesDO.getSceneId());
    }
}