DrawLotGroupDictServiceImpl.java 5.54 KB
package com.subsidy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.subsidy.common.constant.RoleType;
import com.subsidy.common.exception.HttpException;
import com.subsidy.mapper.DrawLotsGroupItemsMapper;
import com.subsidy.mapper.DrawLotsGroupJudgesMapper;
import com.subsidy.model.DrawLotGroupDictDO;
import com.subsidy.mapper.DrawLotGroupDictMapper;
import com.subsidy.model.DrawLotsGroupItemsDO;
import com.subsidy.model.DrawLotsGroupJudgesDO;
import com.subsidy.service.DrawLotGroupDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import com.subsidy.vo.group.AllGroupsVO;
import com.subsidy.vo.group.GroupJudgesVO;
import com.subsidy.vo.group.GroupNumsVO;
import com.subsidy.vo.group.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 Tuyp
 * @since 2025-12-10
 */
@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);

            Integer count = drawLotsGroupItemsMapper.selectCount(new QueryWrapper<DrawLotsGroupItemsDO>()
                    .lambda()
                    .eq(DrawLotsGroupItemsDO::getGroupId, dlgd.getId()));
            allGroupsVO.setProjectCnt(count+"");

            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<GroupNumsVO> integer = this.baseMapper.groupNums(drawLotGroupDictDO1.getId());
            sceneGroupsVO.setGroupNums(integer);
            result.add(sceneGroupsVO);
        }
        return result;
    }
}