ClassDictServiceImpl.java 3.99 KB
package com.subsidy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.subsidy.dto.classDict.AddClassDTO;
import com.subsidy.dto.classDict.AddMemberToClassDTO;
import com.subsidy.dto.classDict.GetAllClassesDTO;
import com.subsidy.dto.classDict.GetSpareMembersDTO;
import com.subsidy.mapper.AdministerMapper;
import com.subsidy.mapper.ClassMemberMappingMapper;
import com.subsidy.mapper.RoleAdministerMappingMapper;
import com.subsidy.model.*;
import com.subsidy.mapper.ClassDictMapper;
import com.subsidy.service.ClassDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import com.subsidy.vo.classdict.GetAllClassesVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.management.relation.Role;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 班级id 服务实现类
 * </p>
 *
 * @author DengMin
 * @since 2021-10-12
 */
@Service
public class ClassDictServiceImpl extends ServiceImpl<ClassDictMapper, ClassDictDO> implements ClassDictService {

    @Autowired
    private ClassMemberMappingMapper classMemberMappingMapper;

    @Autowired
    private RoleAdministerMappingMapper roleAdministerMappingMapper;


    public List<GetAllClassesVO> getAllClasses(ClassDictDO classDictDO) {
        return this.baseMapper.getAllClasses(classDictDO);
    }

    @Transactional
    public String deleteClasses(ClassDictDO classDictDO) {
        this.baseMapper.deleteById(classDictDO.getId());

        classMemberMappingMapper.delete(new QueryWrapper<ClassMemberMappingDO>()
                .lambda()
                .eq(ClassMemberMappingDO::getClassId, classDictDO.getId()));
        return ConstantUtils.DELETE_SUCCESS;
    }

    public String addClass(AddClassDTO addClassDTO) {

        //查看当前登录人的角色
        int count = roleAdministerMappingMapper.selectCount(new QueryWrapper<RoleAdministerMappingDO>()
        .lambda()
        .eq(RoleAdministerMappingDO::getAdministerId,addClassDTO.getUserId())
        .eq(RoleAdministerMappingDO::getRoleId,1));

        ClassDictDO classDictDO = new ClassDictDO();
        BeanUtils.copyProperties(addClassDTO,classDictDO);

        if (count>0){
            classDictDO.setClassType("平台支持");
        }else{
            classDictDO.setClassType("企业自荐");
        }

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

    public String updateClass(ClassDictDO classDictDO) {
        this.baseMapper.updateById(classDictDO);
        return ConstantUtils.SET_SUCCESS;
    }

    public ClassDictDO classDetail(ClassDictDO classDictDO) {
        return this.baseMapper.selectById(classDictDO.getId());
    }

    public String removeMember(ClassMemberMappingDO classMemberMappingDO) {
        classMemberMappingMapper.delete(new QueryWrapper<ClassMemberMappingDO>()
                .lambda()
                .eq(ClassMemberMappingDO::getClassId, classMemberMappingDO.getClassId())
                .eq(ClassMemberMappingDO::getMemberId, classMemberMappingDO.getMemberId()));
        return ConstantUtils.DELETE_SUCCESS;
    }

    public List<MemberDO> getSpareMembers(GetSpareMembersDTO getSpareMembersDTO){
        return this.baseMapper.getSpareMembers(getSpareMembersDTO);
    }

    public String addMemberToClass(AddMemberToClassDTO addMemberToClassDTO){

        List<Long> memberIds = addMemberToClassDTO.getMemberIds();

        for (Long lg : memberIds){
            ClassMemberMappingDO classMemberMappingDO = new ClassMemberMappingDO();
            classMemberMappingDO.setClassId(addMemberToClassDTO.getClassId());
            classMemberMappingDO.setMemberId(lg);
            classMemberMappingMapper.insert(classMemberMappingDO);
        }
        return ConstantUtils.ADD_SUCCESS;
    }

}