package com.jwipc.sys.logic.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jwipc.page.PageUtil;
import com.jwipc.page.PageView;
import com.jwipc.sys.convert.ThirdLogConvert;
import com.jwipc.sys.dto.LogThirdPartyCallDTO;
import com.jwipc.sys.dto.LogThirdPartyInterfaceDTO;
import com.jwipc.sys.entity.LogThirdPartyCall;
import com.jwipc.sys.entity.LogThirdPartyInterface;
import com.jwipc.sys.logic.ThirdLogLogic;
import com.jwipc.sys.model.po.LogThirdPartyCallPO;
import com.jwipc.sys.model.po.LogThirdPartyInterfacePO;
import com.jwipc.sys.model.query.ThirdLogQuery;
import com.jwipc.sys.service.ILogThirdPartyCallService;
import com.jwipc.sys.service.ILogThirdPartyInterfaceService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author shenyang.ou
 * @date 2024/1/30 16:03
 * @desc
 */
@Service
@RequiredArgsConstructor
public class ThirdLogLogicImpl implements ThirdLogLogic {
    private final ThirdLogConvert thirdLogConvert;
    private final ILogThirdPartyInterfaceService logThirdPartyInterfaceService;
    private final ILogThirdPartyCallService logThirdPartyCallService;
    @Override
    public PageView findByPage(ThirdLogQuery query) {
        final Page<LogThirdPartyInterface> dbPage = PageUtil.toPage(query);
        List<LogThirdPartyInterfacePO> sapLogInfoPOS = logThirdPartyInterfaceService.findPageByQuery(dbPage, query);
        return PageUtil.getPV(thirdLogConvert.po2DTOList(sapLogInfoPOS), dbPage.getTotal());
    }

    @Override
    public PageView findCallByPage(ThirdLogQuery query) {
        final Page<LogThirdPartyCall> dbPage = PageUtil.toPage(query);
        List<LogThirdPartyCallPO> sapLogInfoPOS = logThirdPartyCallService.findPageByQuery(dbPage, query);
        return PageUtil.getPV(thirdLogConvert.callPO2DTOList(sapLogInfoPOS), dbPage.getTotal());
    }

    @Override
    public LogThirdPartyInterfaceDTO getById(String id) {
        LogThirdPartyInterface logThirdPartyInterface = logThirdPartyInterfaceService.getById(id);
        return thirdLogConvert.entity2DTO(logThirdPartyInterface);
    }

    @Override
    public LogThirdPartyCallDTO getCallById(String id) {
        LogThirdPartyCall logThirdPartyCall = logThirdPartyCallService.getById(id);
        return thirdLogConvert.callEntity2DTO(logThirdPartyCall);
    }
}
