package com.trade.service.companyrelated.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.trade.service.companyrelated.domain.ImporterEntity;
import com.trade.service.companyrelated.domain.vo.ImporterEntitySearch;
import com.trade.service.companyrelated.mapper.ImporterEntityMapper;
import com.trade.service.companyrelated.service.IImporterEntityService;

/**
 * <p>
 * 进口商企业信息 服务实现类
 * </p>
 *
 * @author zhangchenm
 * @since 2024-09-03
 */
@Service
public class ImporterEntityServiceImpl extends ServiceImpl<ImporterEntityMapper, ImporterEntity> implements IImporterEntityService {

    @Override
    public PageInfo<ImporterEntity> queryListBySearch(ImporterEntitySearch search) {
        // 使用PageHelper分页插件
        PageHelper.startPage(search.getPage(), search.getRows());
        List<ImporterEntity> list = getBaseMapper().queryListBySearch(search);
        return new PageInfo<>(list);
    }

    @Override
    public List<ImporterEntity> getListByUserId(Long userId) {
        QueryWrapper<ImporterEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        return this.list(queryWrapper);
    }

    @Override
    public ImporterEntity getByEntityId(Long entityId) {
        return this.getById(entityId);
    }

    @Override
    public List<ImporterEntity> getEnabledListByUserId(Long userId) {
        QueryWrapper<ImporterEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        queryWrapper.eq("status", 1);
        return this.list(queryWrapper);
    }
}
