DrawLotGroupDictServiceImpl.java 5.25 KB
package com.zhongzhi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhongzhi.common.constant.RoleType;
import com.zhongzhi.common.exception.HttpException;
import com.zhongzhi.common.utils.ConstantUtils;
import com.zhongzhi.dao.DrawLotsGroupItemsMapper;
import com.zhongzhi.dao.DrawLotsGroupJudgesMapper;
import com.zhongzhi.dao.MatchDictDAO;
import com.zhongzhi.model.DrawLotGroupDictDO;
import com.zhongzhi.dao.DrawLotGroupDictMapper;
import com.zhongzhi.model.DrawLotsGroupItemsDO;
import com.zhongzhi.model.DrawLotsGroupJudgesDO;
import com.zhongzhi.service.DrawLotGroupDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongzhi.vo.drawlots.AllGroupsVO;
import com.zhongzhi.vo.drawlots.GroupJudgesVO;
import com.zhongzhi.vo.drawlots.SceneGroupsVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author DengMin
 * @since 2025-06-19
 */
@Service
public class DrawLotGroupDictServiceImpl extends ServiceImpl<DrawLotGroupDictMapper, DrawLotGroupDictDO> implements DrawLotGroupDictService {

    @Autowired
    private DrawLotsGroupJudgesMapper drawLotsGroupJudgesMapper;

    @Autowired
    private DrawLotsGroupItemsMapper drawLotsGroupItemsMapper;

    @Override
    public List<AllGroupsVO> allGroups(DrawLotGroupDictDO drawLotGroupDictDO) {

        List<AllGroupsVO> result = new ArrayList<>();

        List<DrawLotGroupDictDO> drawLotGroupDictDOS = this.baseMapper.selectList(new QueryWrapper<DrawLotGroupDictDO>()
                .lambda()
                .eq(DrawLotGroupDictDO::getSceneId, drawLotGroupDictDO.getSceneId()));

        for (DrawLotGroupDictDO dlgd : drawLotGroupDictDOS){
            AllGroupsVO allGroupsVO = new AllGroupsVO();
            BeanUtils.copyProperties(dlgd,allGroupsVO);
            //组长
            List<GroupJudgesVO> leader = this.baseMapper.groupJudges(dlgd.getId(), RoleType.TEAMLEADER);
            allGroupsVO.setLeader(leader);
            //成员
            List<GroupJudgesVO> member = this.baseMapper.groupJudges(dlgd.getId(), RoleType.TEAMMEMBER);
            allGroupsVO.setMember(member);
            result.add(allGroupsVO);
        }
        return result;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public String addGroup(DrawLotGroupDictDO drawLotGroupDictDO) {

        int count = this.baseMapper.selectCount(new QueryWrapper<DrawLotGroupDictDO>()
                .lambda()
                .eq(DrawLotGroupDictDO::getSceneId, drawLotGroupDictDO.getSceneId())
                .eq(DrawLotGroupDictDO::getGroupName, drawLotGroupDictDO.getGroupName()));

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

        this.baseMapper.insert(drawLotGroupDictDO);
        return ConstantUtils.ADD_SUCCESS;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)

    public String updateGroup(DrawLotGroupDictDO drawLotGroupDictDO) {

        int count = this.baseMapper.selectCount(new QueryWrapper<DrawLotGroupDictDO>()
                .lambda()
                .eq(DrawLotGroupDictDO::getSceneId, drawLotGroupDictDO.getSceneId())
                .eq(DrawLotGroupDictDO::getGroupName, drawLotGroupDictDO.getGroupName())
                .ne(DrawLotGroupDictDO::getId, drawLotGroupDictDO.getId()));

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

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

    @Override
    @Transactional(rollbackFor = Exception.class)
    public String deleteGroup(DrawLotGroupDictDO drawLotGroupDictDO) {

        //删除专家
        drawLotsGroupJudgesMapper.delete(new QueryWrapper<DrawLotsGroupJudgesDO>()
        .lambda()
        .eq(DrawLotsGroupJudgesDO::getGroupId,drawLotGroupDictDO.getId()));

        //删除组别
        drawLotsGroupItemsMapper.delete(new QueryWrapper<DrawLotsGroupItemsDO>()
        .lambda()
        .eq(DrawLotsGroupItemsDO::getGroupId,drawLotGroupDictDO.getId()));

        this.baseMapper.deleteById(drawLotGroupDictDO.getId());
        return ConstantUtils.DELETE_SUCCESS;
    }

    @Override
    public List<SceneGroupsVO> sceneGroups(DrawLotGroupDictDO drawLotGroupDictDO) {

        List<SceneGroupsVO> result = new ArrayList<>();
        List<DrawLotGroupDictDO> drawLotGroupDictDOS = this.baseMapper.selectList(new QueryWrapper<DrawLotGroupDictDO>()
        .lambda()
        .eq(DrawLotGroupDictDO::getSceneId,drawLotGroupDictDO.getSceneId())
        .orderByAsc(DrawLotGroupDictDO::getId));
        for (DrawLotGroupDictDO drawLotGroupDictDO1 : drawLotGroupDictDOS){

            SceneGroupsVO sceneGroupsVO = new SceneGroupsVO();
            sceneGroupsVO.setGroupId(drawLotGroupDictDO1.getId());
            sceneGroupsVO.setGroupName(drawLotGroupDictDO1.getGroupName());
            //编号
            List<Integer> integer = this.baseMapper.groupNums(drawLotGroupDictDO1.getId());
            sceneGroupsVO.setGroupNums(integer);
            result.add(sceneGroupsVO);
        }
        return result;
    }
}