CompanyDictServiceImpl.java 12.3 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.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.common.exception.HttpException;
import com.subsidy.dto.company.AddCompanyDTO;
import com.subsidy.dto.company.GetCompanyMembersDTO;
import com.subsidy.dto.company.OperatorsDTO;
import com.subsidy.dto.company.OperatorsVO;
import com.subsidy.mapper.*;
import com.subsidy.model.*;
import com.subsidy.service.CompanyDictService;
import com.subsidy.util.ConstantUtils;
import com.subsidy.util.excel.ExcelUtil;
import com.subsidy.vo.company.GetCompanyMembersVO;
import com.subsidy.vo.company.MemberSummaryVO;
import com.subsidy.vo.member.MemberCompanyVO;
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.List;

/**
 * <p>
 * 企业字典表 服务实现类
 * </p>
 *
 * @author Tuyp
 * @since 2024-01-11
 */
@Service
public class CompanyDictServiceImpl extends ServiceImpl<CompanyDictMapper, CompanyDictDO> implements CompanyDictService {

    @Autowired
    private AdministerMapper administerMapper;

    @Autowired
    private FieldDictMapper fieldDictMapper;

    @Autowired
    private CompanyFieldMappingMapper companyFieldMappingMapper;

    @Autowired
    private AdministerCompanyMappingMapper administerCompanyMappingMapper;

    @Autowired
    private JobDictMapper jobDictMapper;

    @Autowired
    private ClassTypeDictMapper classTypeDictMapper;

    @Autowired
    private ClassHourDictMapper classHourDictMapper;

    @Autowired
    private RankDictMapper rankDictMapper;

    @Autowired
    private RotationImgDictMapper rotationImgDictMapper;

    @Autowired
    private CompanyMemberMappingMapper companyMemberMappingMapper;

    @Autowired
    private DepartmentDictMapper departmentDictMapper;

    @Autowired
    private ServiceFileTreeMapper serviceFileTreeMapper;

    public IPage<OperatorsVO> operators(OperatorsDTO operatorsDTO) {
        Page pager = new Page(operatorsDTO.getPageNum(), operatorsDTO.getPageSize());
        IPage page = this.baseMapper.operators(pager, operatorsDTO.getCompanyName(), operatorsDTO.getFieldId(), operatorsDTO.getSuperviseName());
        List<OperatorsVO> operatorsVOS = page.getRecords();
        for (OperatorsVO operatorsVO : operatorsVOS) {
            //查看公司所在行业
            List<FieldDictDO> fieldDictDOS = fieldDictMapper.queryCompanyFields(operatorsVO.getCompanyId());
            operatorsVO.setField(fieldDictDOS);
        }
        page.setRecords(operatorsVOS);
        return page;
    }


    public String updateAdminister(AddCompanyDTO addCompanyDTO) {

        CompanyDictDO companyDictDO = new CompanyDictDO();
        BeanUtils.copyProperties(addCompanyDTO, companyDictDO);
        this.baseMapper.updateById(companyDictDO);

        if (null != addCompanyDTO.getField() && addCompanyDTO.getField().size() > 0) {
            companyFieldMappingMapper.delete(new QueryWrapper<CompanyFieldMappingDO>()
                    .lambda()
                    .eq(CompanyFieldMappingDO::getCompanyId, addCompanyDTO.getId()));

            List<Long> longs = addCompanyDTO.getField();
            for (Long lg : longs) {
                CompanyFieldMappingDO companyFieldMappingDO = new CompanyFieldMappingDO();
                companyFieldMappingDO.setFieldId(lg);
                companyFieldMappingDO.setCompanyId(addCompanyDTO.getId());
                companyFieldMappingMapper.insert(companyFieldMappingDO);
            }
        }

        //先查一遍企业的唯一账号

        AdministerDO administerDO1 = administerMapper.uniqueAdminister(companyDictDO.getId());

        int count1 = administerMapper.selectCount(new QueryWrapper<AdministerDO>()
                .lambda()
                .eq(AdministerDO::getAccountName, addCompanyDTO.getAccountName())
                .ne(AdministerDO::getId, administerDO1.getId()));
        if (count1 > 0) {
            throw new HttpException(10014);
        }


        //查找企业管理员
        AdministerDO administerDO = administerMapper.selectOne(new QueryWrapper<AdministerDO>()
                .lambda()
                .eq(AdministerDO::getCompanyId, addCompanyDTO.getId())
                .eq(AdministerDO::getRole, 3));
        if (null != administerDO) {
            if (StringUtils.isNotBlank(addCompanyDTO.getAccountName())) {
                administerDO.setAccountName(addCompanyDTO.getAccountName());
            }
            if (StringUtils.isBlank(addCompanyDTO.getPassword())) {
                addCompanyDTO.setPassword(addCompanyDTO.getPassword());
            }
            administerMapper.updateById(administerDO);
        }
        return ConstantUtils.SET_SUCCESS;
    }

    public String deleteAdminister(CompanyDictDO companyDictDO) {
        this.baseMapper.deleteById(companyDictDO.getId());

        administerMapper.delete(new QueryWrapper<AdministerDO>()
                .lambda()
                .eq(AdministerDO::getCompanyId, companyDictDO.getId()));

        return ConstantUtils.DELETE_SUCCESS;
    }


    @Transactional(rollbackFor = Exception.class)
    public String addOperator(AddCompanyDTO addCompanyDTO) {

        Integer count = this.baseMapper.selectCount(new QueryWrapper<CompanyDictDO>()
                .lambda()
                .eq(CompanyDictDO::getCompanyName, addCompanyDTO.getAccountName()));

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

        CompanyDictDO companyDictDO = new CompanyDictDO();
        BeanUtils.copyProperties(addCompanyDTO, companyDictDO);
        this.baseMapper.insert(companyDictDO);

        int count1 = administerMapper.selectCount(new QueryWrapper<AdministerDO>()
                .lambda()
                .eq(AdministerDO::getAccountName, addCompanyDTO.getAccountName()));
        if (count1 > 0) {
            throw new HttpException(10014);
        }

        AdministerDO administerDO = new AdministerDO();
        BeanUtils.copyProperties(addCompanyDTO, administerDO);
        administerDO.setCompanyId(companyDictDO.getId());
        administerDO.setRole(3);
        administerDO.setStatus("1");
        administerDO.setUserName(companyDictDO.getCompanyName());
        administerDO.setPassword("admin321");
        administerMapper.insert(administerDO);

        AdministerCompanyMappingDO administerCompanyMappingDO = new AdministerCompanyMappingDO();
        administerCompanyMappingDO.setCompanyId(companyDictDO.getId());
        administerCompanyMappingDO.setAdministerId(administerDO.getId());
        administerCompanyMappingMapper.insert(administerCompanyMappingDO);

        //class_hour_dict
        ClassHourDictDO classHourDictDO2 = new ClassHourDictDO();
        classHourDictDO2.setCompanyId(companyDictDO.getId());
        classHourDictDO2.setStatus(0);
        classHourDictDO2.setClassHour(6);

        classHourDictDO2.setInterruptStatus(0);
        classHourDictDO2.setInterrupt(15);

        classHourDictDO2.setRepeatStatus(0);
        classHourDictDO2.setRepeatTime(3);
        classHourDictMapper.insert(classHourDictDO2);

        //添加默认部门  名称为公司名称
        DepartmentDictDO departmentDictDO = new DepartmentDictDO();
        departmentDictDO.setCompanyId(companyDictDO.getId());
        departmentDictDO.setDepartmentName(companyDictDO.getCompanyName());
        departmentDictDO.setFullName(companyDictDO.getCompanyName());
        departmentDictMapper.insert(departmentDictDO);

        //行业
        List<Long> fields = addCompanyDTO.getField();
        for (Long lg : fields) {
            CompanyFieldMappingDO companyFieldMappingDO = new CompanyFieldMappingDO();
            companyFieldMappingDO.setCompanyId(companyDictDO.getId());
            companyFieldMappingDO.setFieldId(lg);
            companyFieldMappingMapper.insert(companyFieldMappingDO);
        }

        //初始化平台的岗位到企业的岗位
        List<JobDictDO> jobDictDOS = jobDictMapper.selectList(new QueryWrapper<JobDictDO>()
                .lambda()
                .isNull(JobDictDO::getCompanyId));
        for (JobDictDO jobDictDO : jobDictDOS) {
            jobDictDO.setCompanyId(companyDictDO.getId());
            jobDictMapper.insert(jobDictDO);
        }

        //初始化运营者的职级
        List<RankDictDO> rankDictDOS = rankDictMapper.selectList(new QueryWrapper<RankDictDO>()
                .lambda()
                .isNull(RankDictDO::getCompanyId));
        for (RankDictDO rankDictDO : rankDictDOS) {
            rankDictDO.setCompanyId(companyDictDO.getId());
            rankDictMapper.insert(rankDictDO);
        }

        //初始化轮播图
        List<RotationImgDictDO> rotationImgDictDOS = rotationImgDictMapper.selectList(new QueryWrapper<RotationImgDictDO>()
                .lambda()
                .isNull(RotationImgDictDO::getCompanyId));
        for (RotationImgDictDO rotationImgDictDO : rotationImgDictDOS) {
            rotationImgDictDO.setCompanyId(companyDictDO.getId());
            rotationImgDictMapper.insert(rotationImgDictDO);
        }

        //班级类型
        ClassTypeDictDO classTypeDictDO = new ClassTypeDictDO();
        classTypeDictDO.setClassType("企业内训");
        classTypeDictDO.setCompanyId(companyDictDO.getId());
        classTypeDictMapper.insert(classTypeDictDO);

        classTypeDictDO.setClassType("社会化、学徒制");
        classTypeDictMapper.insert(classTypeDictDO);

        classTypeDictDO.setClassType("补贴培训");
        classTypeDictMapper.insert(classTypeDictDO);

        ServiceFileTreeDO serviceFileTreeDO = new ServiceFileTreeDO();
        serviceFileTreeDO.setCompanyId(companyDictDO.getId());
        serviceFileTreeDO.setTreeName("业务合同");
        serviceFileTreeDO.setServiceId(1L);
        serviceFileTreeMapper.insert(serviceFileTreeDO);

        serviceFileTreeDO.setCompanyId(companyDictDO.getId());
        serviceFileTreeDO.setServiceId(4L);
        serviceFileTreeMapper.insert(serviceFileTreeDO);

        serviceFileTreeDO.setTreeName("业务材料");
        serviceFileTreeMapper.insert(serviceFileTreeDO);

        serviceFileTreeDO.setServiceId(1L);
        serviceFileTreeMapper.insert(serviceFileTreeDO);
        return ConstantUtils.ADD_SUCCESS;

    }

    public IPage<GetCompanyMembersVO> getCompanyMembers(GetCompanyMembersDTO getCompanyMembersDTO) {
        Page pager = new Page(getCompanyMembersDTO.getPageNum(), getCompanyMembersDTO.getPageSize());

        IPage<GetCompanyMembersVO> companyMembersVOIPage = this.baseMapper.getCompanyMembers(pager, getCompanyMembersDTO.getCompanyId(), getCompanyMembersDTO.getUserName(), getCompanyMembersDTO.getMemberStatus());

        List<GetCompanyMembersVO> records = companyMembersVOIPage.getRecords();
        for (GetCompanyMembersVO gcmv : records) {

            //历史带过的企业
            List<MemberCompanyVO> memberCompanyVOS = companyMemberMappingMapper.memberCompanys(gcmv.getId());
            gcmv.setMemberCompanyVOS(memberCompanyVOS);

        }
        return companyMembersVOIPage;
    }

    public void exportCompanyMembers(GetCompanyMembersDTO getCompanyMembersDTO) {
        Page pager = new Page(1, -1);
        List<GetCompanyMembersVO> getCompanyMembersVOS = this.baseMapper.getCompanyMembers(pager, getCompanyMembersDTO.getCompanyId(), getCompanyMembersDTO.getUserName(), getCompanyMembersDTO.getMemberStatus()).getRecords();
        ExcelUtil.writeExcel(getCompanyMembersVOS, GetCompanyMembersVO.class);
    }


    public MemberSummaryVO memberSummary(GetCompanyMembersDTO getCompanyMembersDTO) {

        MemberSummaryVO memberSummaryVO = new MemberSummaryVO();

        //总数
        Integer total = companyMemberMappingMapper.selectCount(new QueryWrapper<CompanyMemberMappingDO>()
                .lambda()
                .eq(CompanyMemberMappingDO::getCompanyId, getCompanyMembersDTO.getCompanyId()));
        memberSummaryVO.setTotal(total);

        //短信验证
        Integer smsCnt = companyMemberMappingMapper.companyAuthMembersCount(getCompanyMembersDTO.getCompanyId());
        memberSummaryVO.setSmsCnt(smsCnt);

        memberSummaryVO.setImgCnt(total - smsCnt);
        return memberSummaryVO;
    }
}