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.CompanyConvert;
import com.jwipc.sys.dto.CompanyDTO;
import com.jwipc.sys.entity.Company;
import com.jwipc.sys.logic.CompanyLogic;
import com.jwipc.sys.model.po.CompanyPO;
import com.jwipc.sys.model.query.CompanyQuery;
import com.jwipc.sys.service.ICompanyService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author shenyang.ou
 * @date 2024/1/29 16:02
 * @desc
 */
@Service
@RequiredArgsConstructor
public class CompanyLogicImpl implements CompanyLogic {
    private final ICompanyService companyService;
    private final CompanyConvert companyConvert;
    @Override
    public PageView findByPage(CompanyQuery query) {
        final Page<Company> dbPage = PageUtil.toPage(query);
        if(StringUtils.isEmpty(query.getLanguage())){
            query.setLanguage("1");
        }
        List<CompanyPO> companyPOS = companyService.findPageByQuery(dbPage, query);

        return PageUtil.getPV(companyConvert.po2PageListDTO(companyPOS), dbPage.getTotal());
    }
    @Override
    public List<CompanyDTO> listAll(CompanyQuery query) {
        List<CompanyPO> companyPOS = companyService.findPageByQuery(null, query);
        return companyConvert.po2PageListDTO(companyPOS);
    }
}
