DrawLotsScenesServiceImpl.java 3.68 KB
package com.zhongzhi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhongzhi.common.constant.OpenStatus;
import com.zhongzhi.common.exception.HttpException;
import com.zhongzhi.common.utils.ConstantUtils;
import com.zhongzhi.dao.DrawLotGroupDictMapper;
import com.zhongzhi.dao.DrawLotsGroupItemsMapper;
import com.zhongzhi.model.DrawLotGroupDictDO;
import com.zhongzhi.model.DrawLotsGroupItemsDO;
import com.zhongzhi.model.DrawLotsScenesDO;
import com.zhongzhi.dao.DrawLotsScenesMapper;
import com.zhongzhi.service.DrawLotsScenesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongzhi.vo.project.AllMatchScenesVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

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

    @Autowired
    private DrawLotGroupDictMapper drawLotGroupDictMapper;

    @Autowired
    private DrawLotsGroupItemsMapper drawLotsGroupItemsMapper;

    @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);

            //评委数量
            allMatchScenesVO.setJudgeCnt(0);

            //排位项目数量
            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;
    }
}