package com.jwipc.inquiry.logic.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jwipc.inquiry.convert.InquirySupplierQuoteLogConvert;
import com.jwipc.inquiry.dto.InquiryDTO;
import com.jwipc.inquiry.dto.InquirySupplierQuoteLogDTO;
import com.jwipc.inquiry.entity.Inquiry;
import com.jwipc.inquiry.entity.InquirySupplierQuoteLog;
import com.jwipc.inquiry.logic.InquirySupplierQuoteLogLogic;
import com.jwipc.inquiry.model.po.InquiryPO;
import com.jwipc.inquiry.model.po.InquirySupplierQuoteLogPO;
import com.jwipc.inquiry.model.query.InquirySupplierQuoteLogQuery;
import com.jwipc.inquiry.service.IInquirySupplierQuoteLogService;
import com.jwipc.page.PageUtil;
import com.jwipc.page.PageView;
import com.jwipc.security.LoginUtil;
import com.jwipc.sys.client.UserPurchaseGroupClient;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @author shenyang.ou
 * @date 2024/3/1 10:47
 * @desc
 */
@Service
@RequiredArgsConstructor
public class InquirySupplierQuoteLogLogicImpl implements InquirySupplierQuoteLogLogic {
    private final IInquirySupplierQuoteLogService inquirySupplierQuoteLogService;
    private final InquirySupplierQuoteLogConvert inquirySupplierQuoteLogConvert;
    private final UserPurchaseGroupClient userPurchaseGroupClient;
    @Override
    public PageView findByPage(InquirySupplierQuoteLogQuery query) {
        final Set<String> userPurchaseGroupCode = userPurchaseGroupClient.getUserPurchaseGroupCode(
                LoginUtil.getUserId());
        query.setUserPurchaseGroupCodes(userPurchaseGroupCode);
        final Page<InquirySupplierQuoteLog> dbPage = PageUtil.toPage(query);
        List<InquirySupplierQuoteLogPO> inquiryPOS = inquirySupplierQuoteLogService.findPageByQuery(dbPage, query);
        List<InquirySupplierQuoteLogDTO> inquiryDTOS = inquirySupplierQuoteLogConvert.po2DTOList(inquiryPOS);
        return PageUtil.getPV(inquiryDTOS, dbPage.getTotal());
    }

    @Override
    public List<InquirySupplierQuoteLogDTO> listAll(InquirySupplierQuoteLogQuery query) {
        final Set<String> userPurchaseGroupCode = userPurchaseGroupClient.getUserPurchaseGroupCode(
                LoginUtil.getUserId());
        query.setUserPurchaseGroupCodes(userPurchaseGroupCode);
        List<InquirySupplierQuoteLogPO> inquiryPOS = inquirySupplierQuoteLogService.findPageByQuery(null, query);
        return inquirySupplierQuoteLogConvert.po2DTOList(inquiryPOS);
    }
}
