ServiceCompanyMappingServiceImpl.java 2.81 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.service.CancelAuthDTO;
import com.subsidy.dto.service.GetServiceCompaniesDTO;
import com.subsidy.model.ServiceCompanyMappingDO;
import com.subsidy.mapper.ServiceCompanyMappingMapper;
import com.subsidy.service.ServiceCompanyMappingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import com.subsidy.vo.service.GetServiceCompaniesVO;
import com.subsidy.vo.service.ServiceCompaniesVO;
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 ServiceCompanyMappingServiceImpl extends ServiceImpl<ServiceCompanyMappingMapper, ServiceCompanyMappingDO> implements ServiceCompanyMappingService {


    public IPage<GetServiceCompaniesVO> getServiceCompanies(GetServiceCompaniesDTO getServiceCompaniesDTO) {
        Page pager = new Page(getServiceCompaniesDTO.getPageNum(), getServiceCompaniesDTO.getPageSize());
        return this.baseMapper.getServiceCompanies(pager, getServiceCompaniesDTO.getServiceId(), getServiceCompaniesDTO.getCompanyName(), getServiceCompaniesDTO.getAuthStatus());
    }

    @Transactional(rollbackFor = Exception.class)
    public String cancelAuth(CancelAuthDTO cancelAuthDTO) {
        List<Long> companyIds = cancelAuthDTO.getCompanyIds();
        for (Long companyId : companyIds) {
            this.baseMapper.delete(new QueryWrapper<ServiceCompanyMappingDO>()
                    .lambda()
                    .eq(ServiceCompanyMappingDO::getCompanyId, companyId)
                    .eq(ServiceCompanyMappingDO::getServiceId, cancelAuthDTO.getServiceId()));
        }
        return ConstantUtils.DELETE_SUCCESS;
    }

    @Transactional(rollbackFor = Exception.class)
    public String addAuth(CancelAuthDTO cancelAuthDTO) {
        List<Long> companyIds = cancelAuthDTO.getCompanyIds();
        for (Long companyId : companyIds) {
            ServiceCompanyMappingDO serviceCompanyMappingDO = new ServiceCompanyMappingDO();
            serviceCompanyMappingDO.setCompanyId(companyId);
            serviceCompanyMappingDO.setServiceId(cancelAuthDTO.getServiceId());
            this.baseMapper.insert(serviceCompanyMappingDO);
        }
        return ConstantUtils.ADD_SUCCESS;
    }

    public List<ServiceCompaniesVO> serviceCompanies(GetServiceCompaniesDTO getServiceCompaniesDTO) {
        return this.baseMapper.serviceCompanies(getServiceCompaniesDTO.getServiceId(),getServiceCompaniesDTO.getCompanyName());
    }

}