CourseDictServiceImpl.java 4.24 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.*;
import com.subsidy.mapper.CourseDictMapper;
import com.subsidy.service.CompanyDictService;
import com.subsidy.service.CourseDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import com.subsidy.util.SMSUtils;
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;

    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());
        return this.baseMapper.queryCompanyCourse(pager, queryCoursesDTO.getCourseName(), queryCoursesDTO.getCategoryId(), queryCoursesDTO.getCourseType(), queryCoursesDTO.getCourseSource(), queryCoursesDTO.getCompanyId());
    }


}