CertCompanyMappingServiceImpl.java 4.72 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.dto.cert.ChangeCompanyCertsDTO;
import com.subsidy.dto.cert.GetCompanyCertsDTO;
import com.subsidy.dto.cert.GetCompanyCertsWithStatusDTO;
import com.subsidy.mapper.CertMemberMappingMapper;
import com.subsidy.mapper.CertTypeDictMapper;
import com.subsidy.model.CertCompanyMappingDO;
import com.subsidy.mapper.CertCompanyMappingMapper;
import com.subsidy.model.CertDictDO;
import com.subsidy.model.CertMemberMappingDO;
import com.subsidy.model.CertTypeDictDO;
import com.subsidy.service.CertCompanyMappingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import com.subsidy.vo.cert.GetCompanyCertsVO;
import com.subsidy.vo.cert.GetCompanyCertsWithStatusVO;
import org.springframework.beans.BeanUtils;
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 2022-05-11
 */
@Service
public class CertCompanyMappingServiceImpl extends ServiceImpl<CertCompanyMappingMapper, CertCompanyMappingDO> implements CertCompanyMappingService {

    @Autowired
    private CertMemberMappingMapper certMemberMappingMapper;

    @Autowired
    private CertTypeDictMapper certTypeDictMapper;

    @Autowired
    private CertCompanyMappingMapper certCompanyMappingMapper;

    public List<GetCompanyCertsWithStatusVO> getCompanyCertsWithStatus(GetCompanyCertsWithStatusDTO getCompanyCertsDTO){

        List<GetCompanyCertsWithStatusVO> getCompanyCertsWithStatusVOS = new ArrayList<>();

        //查看某个公司所有的证书
        List<CertDictDO> certDictDOS = this.baseMapper.getCompanyCerts(getCompanyCertsDTO.getCompanyId(),getCompanyCertsDTO.getTypeId());
        for (CertDictDO certDictDO : certDictDOS){

            GetCompanyCertsWithStatusVO getCompanyCertsWithStatusVO = new GetCompanyCertsWithStatusVO();
            BeanUtils.copyProperties(certDictDO,getCompanyCertsWithStatusVO);

            int count = certMemberMappingMapper.selectCount(new QueryWrapper<CertMemberMappingDO>()
            .lambda()
            .eq(CertMemberMappingDO::getCertId,certDictDO.getId())
            .eq(CertMemberMappingDO::getMemberId,getCompanyCertsDTO.getMemberId()));

            if (count>0){
                getCompanyCertsWithStatusVO.setStatus(true);
            }else {
                getCompanyCertsWithStatusVO.setStatus(false);
            }
            getCompanyCertsWithStatusVOS.add(getCompanyCertsWithStatusVO);
        }
        return getCompanyCertsWithStatusVOS;
    }

    public IPage<GetCompanyCertsVO> getCompanyCerts(GetCompanyCertsDTO getCompanyCertsDTO){

        Page pager = new Page(getCompanyCertsDTO.getPageNum(), getCompanyCertsDTO.getPageSize());

        IPage<GetCompanyCertsVO> getCompanyCertsVOIPage = this.baseMapper.getCompanyCertStatus(pager);

        List<GetCompanyCertsVO> getCompanyCertsVOS = getCompanyCertsVOIPage.getRecords();

        for (GetCompanyCertsVO getCompanyCertsVO : getCompanyCertsVOS){
            List<CertTypeDictDO> certTypeDictDOS = certTypeDictMapper.getCertTypes(getCompanyCertsVO.getId());
            getCompanyCertsVO.setCertTypeDictDOS(certTypeDictDOS);

            int count = certCompanyMappingMapper.selectCount(new QueryWrapper<CertCompanyMappingDO>()
            .lambda()
            .eq(CertCompanyMappingDO::getCertId,getCompanyCertsVO.getId())
            .eq(CertCompanyMappingDO::getCompanyId,getCompanyCertsDTO.getCompanyId()));

            if (count>0){
                getCompanyCertsVO.setSignStatus(true);
            }else {
                getCompanyCertsVO.setSignStatus(false);
            }
        }
        return getCompanyCertsVOIPage;
    }

    public String changeCompanyCerts(ChangeCompanyCertsDTO changeCompanyCertsDTO){

        if (changeCompanyCertsDTO.getSignStatus()){
            CertCompanyMappingDO certCompanyMappingDO = new CertCompanyMappingDO();
            certCompanyMappingDO.setCertId(changeCompanyCertsDTO.getCertId());
            certCompanyMappingDO.setCompanyId(changeCompanyCertsDTO.getCompanyId());
            this.baseMapper.insert(certCompanyMappingDO);
        }else {
            this.baseMapper.delete(new QueryWrapper<CertCompanyMappingDO>()
            .lambda()
            .eq(CertCompanyMappingDO::getCertId,changeCompanyCertsDTO.getCertId())
            .eq(CertCompanyMappingDO::getCompanyId,changeCompanyCertsDTO.getCompanyId()));
        }
        return ConstantUtils.SET_SUCCESS;
    }

}