package com.ningdatech.carapi.company.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ningdatech.carapi.common.aop.BuildChildrenRegionEntity;
import com.ningdatech.carapi.common.util.CodeUtil;
import com.ningdatech.carapi.company.entity.NdCompanySecurityProductDuty;
import com.ningdatech.carapi.company.entity.dto.ResSecurityProductDutyDTO;
import com.ningdatech.carapi.company.entity.po.CompanySecurityProductDutyPO;
import com.ningdatech.carapi.company.mapper.NdCompanySecurityProductDutyMapper;
import com.ningdatech.carapi.company.service.INdCompanySecurityProductDutyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ningdatech.carapi.datascope.aop.XmlDataScope;
import lombok.RequiredArgsConstructor;
import org.springframework.aop.framework.AopContext;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 安全生产责任体系 服务实现类
 * </p>
 *
 * @author liushuai
 * @since 2022-10-10
 */
@Service
@RequiredArgsConstructor
public class NdCompanySecurityProductDutyServiceImpl extends ServiceImpl<NdCompanySecurityProductDutyMapper, NdCompanySecurityProductDuty> implements INdCompanySecurityProductDutyService {

    private final NdCompanySecurityProductDutyMapper ndCompanySecurityProductDutyMapper;

    @Override
    public Page<ResSecurityProductDutyDTO> securityProductDutyList(Long regionId, String companyName, String startTime, String endTime, Integer fileType, int pageNum, int pageSize) {
        NdCompanySecurityProductDutyServiceImpl context = (NdCompanySecurityProductDutyServiceImpl)AopContext.currentProxy();
        return context.searchList(new Page<>(pageNum, pageSize),
                new CompanySecurityProductDutyPO(regionId,null, companyName, startTime, endTime, fileType,null));
    }

    @XmlDataScope(entityIndex = 1)
    @BuildChildrenRegionEntity(entityIndex = 1)
    public Page<ResSecurityProductDutyDTO> searchList(Page<ResSecurityProductDutyDTO> page,
                                                      CompanySecurityProductDutyPO po) {
        ndCompanySecurityProductDutyMapper.securityProductDutyList(page,po);
        CodeUtil.searchCompanyNamesAndRegionNames(page.getRecords());
        return page;
    }
}
