CourseDictServiceImpl.java 5.75 KB
package com.subsidy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.subsidy.common.exception.HttpException;
import com.subsidy.dto.course.QueryCoursesDTO;
import com.subsidy.mapper.AdministerMapper;
import com.subsidy.mapper.CompanyDictMapper;
import com.subsidy.mapper.RoleAdministerMappingMapper;
import com.subsidy.model.AdministerDO;
import com.subsidy.model.CompanyDictDO;
import com.subsidy.model.CourseDictDO;
import com.subsidy.mapper.CourseDictMapper;
import com.subsidy.model.RoleAdministerMappingDO;
import com.subsidy.service.CompanyDictService;
import com.subsidy.service.CourseDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author DengMin
 * @since 2021-10-11
 */
@Service
public class CourseDictServiceImpl extends ServiceImpl<CourseDictMapper, CourseDictDO> implements CourseDictService {

    @Autowired
    private RoleAdministerMappingMapper roleAdministerMappingMapper;

    @Autowired
    private AdministerMapper administerMapper;

    @Autowired
    private CompanyDictMapper companyDictMapper;

    public String addCourse(CourseDictDO courseDictDO) {

        int count = 0;

        if (null != courseDictDO.getCompanyId()) {
            count = this.baseMapper.selectCount(new QueryWrapper<CourseDictDO>()
                    .lambda()
                    .eq(CourseDictDO::getCourseName, courseDictDO.getCourseName())
                    .isNull(CourseDictDO::getCompanyId));

        } else {
            count = this.baseMapper.selectCount(new QueryWrapper<CourseDictDO>()
                    .lambda()
                    .eq(CourseDictDO::getCourseName, courseDictDO.getCourseName())
                    .eq(CourseDictDO::getCompanyId, courseDictDO.getCompanyId()));
        }

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

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

    public String deleteCourse(CourseDictDO courseDictDO) {
        this.baseMapper.deleteById(courseDictDO.getId());
        return ConstantUtils.DELETE_SUCCESS;
    }

    public IPage queryCourses(QueryCoursesDTO queryCoursesDTO) {
        Page pager = new Page(queryCoursesDTO.getPageNum(), queryCoursesDTO.getPageSize());

        //判断当前用户是运营者还是企业者
        Integer count = roleAdministerMappingMapper.selectCount(new QueryWrapper<RoleAdministerMappingDO>()
                .lambda()
                .eq(RoleAdministerMappingDO::getAdministerId,queryCoursesDTO.getAdministerId())
                .eq(RoleAdministerMappingDO::getRoleId,1));

        if (count > 0){
            queryCoursesDTO.setCompanyId(null);
        }

        return this.baseMapper.queryCourses(pager, queryCoursesDTO.getCourseName(), queryCoursesDTO.getCategoryId(), queryCoursesDTO.getCourseType(), queryCoursesDTO.getCourseSource(), queryCoursesDTO.getCompanyId());
    }

    public String updateCourses(CourseDictDO courseDictDO) {
        int count = 0;

        if (null != courseDictDO.getCompanyId()) {
            count = this.baseMapper.selectCount(new QueryWrapper<CourseDictDO>()
                    .lambda()
                    .eq(CourseDictDO::getCourseName, courseDictDO.getCourseName())
                    .ne(CourseDictDO::getId, courseDictDO.getCompanyId()));

        } else {
            count = this.baseMapper.selectCount(new QueryWrapper<CourseDictDO>()
                    .lambda()
                    .eq(CourseDictDO::getCourseName, courseDictDO.getCourseName())
                    .isNull(CourseDictDO::getCompanyId));
        }

        if (count > 0) {
            throw new HttpException(20001);
        }
        this.baseMapper.updateById(courseDictDO);
        return ConstantUtils.DELETE_SUCCESS;
    }

    public IPage queryCompanyCourse(QueryCoursesDTO queryCoursesDTO) {
        Page pager = new Page(queryCoursesDTO.getPageNum(), queryCoursesDTO.getPageSize());

        ////判断角色
        //List<RoleAdministerMappingDO> roleAdministerMappingDOS = roleAdministerMappingMapper.selectList(new QueryWrapper<RoleAdministerMappingDO>()
        //.lambda()
        //.eq(RoleAdministerMappingDO::getAdministerId,roleAdministerMappingMapper));
        //
        //Boolean flag = false;
        //for (RoleAdministerMappingDO roleAdministerMappingDO : roleAdministerMappingDOS){
        //
        //    if (roleAdministerMappingDO.getRoleId() ==3){
        //        flag= false;
        //    }else if(roleAdministerMappingDO.getRoleId()==2) {
        //        flag = true;
        //    }
        //}

        //List<Long> longs = new ArrayList<>();
        //if (flag){
        //    //运营者账号 该企业下的所有课程 管理员
        //    //获取该企业下所有老师的课程
        //    AdministerDO administerDO = administerMapper.selectById(queryCoursesDTO.getAdministerId());
        //
        //    List<AdministerDO> administerDOS = administerMapper.selectList(new QueryWrapper<AdministerDO>()
        //    .lambda()
        //    .eq(AdministerDO::getCompanyId,administerDO.getCompanyId()));
        //    for (AdministerDO administerDO1 : administerDOS){
        //        longs.add(administerDO1.getId());
        //    }
        return this.baseMapper.queryCompanyCourse(pager, queryCoursesDTO.getCourseName(), queryCoursesDTO.getCategoryId(), queryCoursesDTO.getCourseType(), queryCoursesDTO.getCourseSource(), queryCoursesDTO.getCompanyId());
        //}

    }

}