DrawLotsScenesServiceImpl.java 3.91 KB
package com.subsidy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.subsidy.common.constant.OpenStatus;
import com.subsidy.common.exception.HttpException;
import com.subsidy.mapper.DrawLotGroupDictMapper;
import com.subsidy.mapper.DrawLotsGroupItemsMapper;
import com.subsidy.mapper.DrawLotsGroupJudgesMapper;
import com.subsidy.model.DrawLotGroupDictDO;
import com.subsidy.model.DrawLotsGroupItemsDO;
import com.subsidy.model.DrawLotsGroupJudgesDO;
import com.subsidy.model.DrawLotsScenesDO;
import com.subsidy.mapper.DrawLotsScenesMapper;
import com.subsidy.service.DrawLotsScenesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import com.subsidy.vo.group.AllMatchScenesVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Tuyp
 * @since 2025-12-10
 */
@Service
public class DrawLotsScenesServiceImpl extends ServiceImpl<DrawLotsScenesMapper, DrawLotsScenesDO> implements DrawLotsScenesService {

    @Autowired
    private DrawLotGroupDictMapper drawLotGroupDictMapper;

    @Autowired
    private DrawLotsGroupItemsMapper drawLotsGroupItemsMapper;

    @Autowired
    private DrawLotsGroupJudgesMapper drawLotsGroupJudgesMapper;

    @Override
    public List<AllMatchScenesVO> allMatchScenes(DrawLotsScenesDO drawLotsScenesDO) {
        List<AllMatchScenesVO> allMatchScenesVOS = this.baseMapper.allMatchScenes(drawLotsScenesDO.getMatchId(), drawLotsScenesDO.getOpenStatus());

        for (AllMatchScenesVO allMatchScenesVO : allMatchScenesVOS){
            //小组项目数量
            int projectCnt = drawLotsGroupItemsMapper.selectCount(new QueryWrapper<DrawLotsGroupItemsDO>()
                    .lambda()
                    .eq(DrawLotsGroupItemsDO::getSceneId,allMatchScenesVO.getId()));
            allMatchScenesVO.setProjectCnt(projectCnt);

            //赛组数量
            int groupCnt = drawLotGroupDictMapper.selectCount(new QueryWrapper<DrawLotGroupDictDO>()
                    .lambda()
                    .eq(DrawLotGroupDictDO::getSceneId,allMatchScenesVO.getId()));
            allMatchScenesVO.setGroupCnt(groupCnt);

            //评委数量
            Integer integer = drawLotsGroupJudgesMapper.judgeCnt(allMatchScenesVO.getId());
            allMatchScenesVO.setJudgeCnt(integer);

            //排位项目数量
            allMatchScenesVO.setRankCnt(0);
        }

        return allMatchScenesVOS;
    }

    @Override
    public String addMatchScene(DrawLotsScenesDO drawLotsScenesDO) {

        int count = this.baseMapper.selectCount(new QueryWrapper<DrawLotsScenesDO>()
                .lambda()
                .eq(DrawLotsScenesDO::getSceneName,drawLotsScenesDO.getSceneName())
                .eq(DrawLotsScenesDO::getMatchId, drawLotsScenesDO.getMatchId()));

        if (count > 0) {
            throw new HttpException(10034);
        }

        drawLotsScenesDO.setOpenStatus(OpenStatus.TODO);
        drawLotsScenesDO.setRankStatus("未排位");
        this.baseMapper.insert(drawLotsScenesDO);
        return ConstantUtils.ADD_SUCCESS;
    }

    @Override
    public String updateMatchScene(DrawLotsScenesDO drawLotsScenesDO) {

        int count = this.baseMapper.selectCount(new QueryWrapper<DrawLotsScenesDO>()
                .lambda()
                .ne(DrawLotsScenesDO::getMatchId, drawLotsScenesDO.getMatchId())
                .ne(DrawLotsScenesDO::getId, drawLotsScenesDO.getId()));

        if (count > 0) {
            throw new HttpException(10034);
        }

        this.baseMapper.updateById(drawLotsScenesDO);
        return ConstantUtils.SUCCESS_UPDATE;
    }

    @Override
    public String deleteMatchScene(DrawLotsScenesDO drawLotsScenesDO) {
        this.baseMapper.deleteById(drawLotsScenesDO.getId());
        return ConstantUtils.DELETE_SUCCESS;
    }

}