/**
 * @filename:PurchaseOrderLogisticsInformationServiceImpl 2024-09-10
 * @project KJT v1.0.0 Copyright(c) 2024 wanglang Co. Ltd. All right reserved.
 */
package com.trade.service.trade.purchaseorder.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.trade.common.utils.ConstantUtil;
import com.trade.service.filestorage.enums.FileTypeEnum;
import com.trade.service.filestorage.service.BusinessRelateFileBaseService;
import com.trade.service.trade.purchaseorder.domain.PurchaseOrderLogistics;
import com.trade.service.trade.purchaseorder.dto.PurchaseOrderLogisticsDocumentSearchDto;
import com.trade.service.trade.purchaseorder.service.PurchaseOrderLogisticsService;
import com.trade.service.trade.purchaseorder.dto.PurchaseOrderLogisticsSearchDto;
import com.trade.service.trade.purchaseorder.mapper.PurchaseOrderLogisticsMapper;
import com.trade.service.trade.purchaseorder.vo.PurchaseOrderLogisticsDocumentVo;
import com.trade.service.trade.purchaseorder.vo.PurchaseOrderLogisticsPageVo;
import com.trade.service.trade.purchaseorder.vo.PurchaseOrderLogisticsVo;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

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

/**
 * @Description:采购订单物流信息服务实现
 * @version: v1.0.0
 * @author: wanglang
 */
@Service
public class PurchaseOrderLogisticsServiceImpl extends ServiceImpl<PurchaseOrderLogisticsMapper, PurchaseOrderLogistics> implements PurchaseOrderLogisticsService {

    @Resource
    private BusinessRelateFileBaseService businessRelateFileBaseService;

    @Override
    public PurchaseOrderLogisticsVo queryByPurchaseOrderId(Long purchaseOrderId) {
        return this.baseMapper.selectByPurchaseOrderId(purchaseOrderId);
    }

    @Override
    public List<PurchaseOrderLogisticsPageVo> queryOrderLogisticsByPage(
            PurchaseOrderLogisticsSearchDto orderLogisticsSearch) {
        List<PurchaseOrderLogisticsPageVo> pageVos = this.baseMapper.selectOrderLogisticsByPage(orderLogisticsSearch);
        if (CollectionUtil.isNotEmpty(pageVos)) {
            for (PurchaseOrderLogisticsPageVo pageVo : pageVos) {
                businessRelateFileBaseService.fillBizObjFiles(pageVo, pageVo.getId(), ConstantUtil.PURCHASE_ORDER,
                        FileTypeEnum.PURCHASE_ORDER_TRANS_PROVE.getCode());
            }
        }
        return pageVos;
    }

    @Override
    public List<PurchaseOrderLogisticsDocumentVo> queryPurchaseOrderLogisticsDocument(
            PurchaseOrderLogisticsDocumentSearchDto documentSearchDto) {
        List<PurchaseOrderLogisticsDocumentVo> documentVos = this.baseMapper
                .selectPurchaseOrderLogisticsDocument(documentSearchDto);
        if (CollectionUtil.isNotEmpty(documentVos)) {
            for (PurchaseOrderLogisticsDocumentVo pageVo : documentVos) {
                businessRelateFileBaseService.fillBizObjFiles(pageVo, pageVo.getId(), ConstantUtil.PURCHASE_ORDER,
                        FileTypeEnum.PURCHASE_ORDER_TRANS_PROVE.getCode());
            }
        }
        return documentVos;
    }

    @Override
    public List<PurchaseOrderLogisticsVo> queryByPurchaseContractNo(String purchaseContractNo) {
        return this.baseMapper.selectByPurchaseContractNo(purchaseContractNo);
    }
}
