package com.trade.admin.trade.purchasecontract.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.trade.admin.trade.purchasecontract.dto.PurchaseContractSearchDto;
import com.trade.admin.trade.purchasecontract.service.PurchaseContractService;
import com.trade.common.core.page.GridPage;
import com.trade.common.utils.ConstantUtil;
import com.trade.service.filestorage.service.BusinessRelateFileBaseService;
import com.trade.service.trade.filingdoc.vo.Contract4FilingDocSearch;
import com.trade.service.trade.filingdoc.vo.PurchaseContract4FilingDocVO;
import com.trade.service.trade.purchasecontract.dto.PurchaseContractDetailDto;
import com.trade.service.trade.purchasecontract.dto.PurchaseContractDto;
import com.trade.service.trade.purchasecontract.dto.PurchaseContractSearchBaseDto;
import com.trade.service.trade.purchasecontract.service.PurchaseContractBaseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 采购合同表基础表服务实现类
 *
 * @author hlb
 * @since 2024-09-07 16:30:38
 */
@Service("purchaseContractService")
public class PurchaseContractServiceImpl implements PurchaseContractService {

    private static final Logger logger = LoggerFactory.getLogger(PurchaseContractServiceImpl.class);
    @Resource
    private PurchaseContractBaseService purchaseContractBaseService;
    @Resource
    private BusinessRelateFileBaseService businessRelateFileBaseService;

    @Override
    public GridPage<PurchaseContractDto> getPurchaseContractBySearch(PurchaseContractSearchDto searchDto) {
        PurchaseContractSearchBaseDto searchBaseDto = new PurchaseContractSearchBaseDto();
        searchBaseDto.setPoint(false);
        searchBaseDto.setContractStatus(searchDto.getContractStatus());
        searchBaseDto.setContractInfo(searchDto.getContractInfo());
        searchBaseDto.setCustomerUserInfo(searchDto.getCustomerUserInfo());
        searchBaseDto.setVendorEntityNo(searchDto.getVendorEntityNo());
        searchBaseDto.setAgencyCertNo(searchDto.getAgencyCertNo());
        searchBaseDto.setSalesContractNo(searchDto.getSalesContractNo());
        searchBaseDto.setTimeStart(searchDto.getGmtSubmitStart());
        searchBaseDto.setTimeEnd(searchDto.getGmtSubmitEnd());
        return purchaseContractBaseService.getPurchaseContractBySearch(searchBaseDto);
    }

    @Override
    public PurchaseContractDetailDto findPurchaseContractDetailById(Long id) {
        return purchaseContractBaseService.findPurchaseContractDetailById(id);
    }

    @Override
    public PageInfo<PurchaseContract4FilingDocVO> queryList4FilingDocBySearch(Contract4FilingDocSearch search) {
        PageHelper.startPage(search.getPage(), search.getRows());
        List<PurchaseContract4FilingDocVO> list = purchaseContractBaseService.queryList4FilingDocBySearch(search);
        // 填充文件信息
        list.forEach(item -> businessRelateFileBaseService.fillBizObjFiles(item, item.getId(),
                ConstantUtil.PURCHASE_CONTRACT, null));
        return new PageInfo<>(list);
    }
}
