Blame view

CompanyDictServiceImpl.java 12.3 KB
涂亚平 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
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
49
    private AdministerCompanyMappingMapper administerCompanyMappingMapper;
涂亚平 committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

    @Autowired
    private JobDictMapper jobDictMapper;

    @Autowired
    private ClassTypeDictMapper classTypeDictMapper;

    @Autowired
    private ClassHourDictMapper classHourDictMapper;

    @Autowired
    private RankDictMapper rankDictMapper;

    @Autowired
    private RotationImgDictMapper rotationImgDictMapper;

    @Autowired
    private CompanyMemberMappingMapper companyMemberMappingMapper;

涂亚平 committed
69 70 71 72 73 74
    @Autowired
    private DepartmentDictMapper departmentDictMapper;

    @Autowired
    private ServiceFileTreeMapper serviceFileTreeMapper;

涂亚平 committed
75 76
    public IPage<OperatorsVO> operators(OperatorsDTO operatorsDTO) {
        Page pager = new Page(operatorsDTO.getPageNum(), operatorsDTO.getPageSize());
涂亚平 committed
77
        IPage page = this.baseMapper.operators(pager, operatorsDTO.getCompanyName(), operatorsDTO.getFieldId(), operatorsDTO.getSuperviseName());
涂亚平 committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
        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);
            }
        }

涂亚平 committed
109 110 111 112 113 114 115 116 117 118 119 120 121
        //先查一遍企业的唯一账号

        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);
        }


涂亚平 committed
122 123
        //查找企业管理员
        AdministerDO administerDO = administerMapper.selectOne(new QueryWrapper<AdministerDO>()
涂亚平 committed
124 125 126
                .lambda()
                .eq(AdministerDO::getCompanyId, addCompanyDTO.getId())
                .eq(AdministerDO::getRole, 3));
涂亚平 committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
        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);

涂亚平 committed
165 166 167 168 169 170 171
        int count1 = administerMapper.selectCount(new QueryWrapper<AdministerDO>()
                .lambda()
                .eq(AdministerDO::getAccountName, addCompanyDTO.getAccountName()));
        if (count1 > 0) {
            throw new HttpException(10014);
        }

涂亚平 committed
172
        AdministerDO administerDO = new AdministerDO();
涂亚平 committed
173
        BeanUtils.copyProperties(addCompanyDTO, administerDO);
涂亚平 committed
174 175 176
        administerDO.setCompanyId(companyDictDO.getId());
        administerDO.setRole(3);
        administerDO.setStatus("1");
涂亚平 committed
177
        administerDO.setUserName(companyDictDO.getCompanyName());
涂亚平 committed
178 179 180
        administerDO.setPassword("admin321");
        administerMapper.insert(administerDO);

181 182 183 184 185
        AdministerCompanyMappingDO administerCompanyMappingDO = new AdministerCompanyMappingDO();
        administerCompanyMappingDO.setCompanyId(companyDictDO.getId());
        administerCompanyMappingDO.setAdministerId(administerDO.getId());
        administerCompanyMappingMapper.insert(administerCompanyMappingDO);

涂亚平 committed
186 187 188 189 190 191 192 193 194 195 196 197 198
        //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);

涂亚平 committed
199 200 201 202 203 204 205
        //添加默认部门  名称为公司名称
        DepartmentDictDO departmentDictDO = new DepartmentDictDO();
        departmentDictDO.setCompanyId(companyDictDO.getId());
        departmentDictDO.setDepartmentName(companyDictDO.getCompanyName());
        departmentDictDO.setFullName(companyDictDO.getCompanyName());
        departmentDictMapper.insert(departmentDictDO);

涂亚平 committed
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
        //行业
        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);
涂亚平 committed
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268

        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);
涂亚平 committed
269 270 271 272 273 274 275 276 277 278
        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();
涂亚平 committed
279
        for (GetCompanyMembersVO gcmv : records) {
涂亚平 committed
280 281 282 283 284 285 286 287 288 289 290

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

        }
        return companyMembersVOIPage;
    }

    public void exportCompanyMembers(GetCompanyMembersDTO getCompanyMembersDTO) {
        Page pager = new Page(1, -1);
涂亚平 committed
291
        List<GetCompanyMembersVO> getCompanyMembersVOS = this.baseMapper.getCompanyMembers(pager, getCompanyMembersDTO.getCompanyId(), getCompanyMembersDTO.getUserName(), getCompanyMembersDTO.getMemberStatus()).getRecords();
涂亚平 committed
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
        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;
    }
}