package com.dsk.cscec.service.impl;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dsk.common.core.domain.PageQuery;
import com.dsk.common.core.page.TableDataInfo;
import com.dsk.cscec.domain.DCustomer;
import com.dsk.cscec.domain.bo.CustomerInfoBo;
import com.dsk.cscec.domain.vo.CustomerInfoVo;
import com.dsk.cscec.mapper.DCustomerMapper;
import com.dsk.cscec.mapper.DSubcontractMapper;
import com.dsk.cscec.service.ICustomerInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 组织维表(DCustomer)表服务实现类
 *
 * @author
 * @since 2023-12-10
 */
@Service
public class CustomerInfoServiceImpl extends ServiceImpl<DCustomerMapper, DCustomer> implements ICustomerInfoService {

    @Autowired
    private DSubcontractMapper subcontractMapper;

    @Override
    public TableDataInfo<CustomerInfoVo> queryPageList(CustomerInfoBo bo, PageQuery query) {
        if("劳务分包".equals(bo.getCustomerClass())){
            bo.setServiceTeamLogo("N");
        }
        if("劳务分包队伍".equals(bo.getCustomerClass())){
            bo.setCustomerClass("劳务分包");
            bo.setServiceTeamLogo("Y");
        }
        Page<CustomerInfoVo> page = baseMapper.queryListByType(query.build(), bo);
        if (CollectionUtils.isNotEmpty(page.getRecords())) {
            for (CustomerInfoVo customerInfoVo : page.getRecords()) {
                //公司合作数量
                customerInfoVo.setEnterpriseCooperationCount(subcontractMapper.selectEnterpriseCountByCustomerId(customerInfoVo.getCustomerId()));
                //项目合作数量
                customerInfoVo.setProjectCooperationCount(subcontractMapper.selectProjectCountByCustomerId(customerInfoVo.getCustomerId()));
            }
        }
        return TableDataInfo.build(page);
    }
}
