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

import java.util.List;

import com.trade.service.enterprise.companyrelated.domain.vo.VendorEntityDict;
import com.trade.service.enterprise.companyrelated.domain.vo.VendorEntityVO;
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.enterprise.companyrelated.domain.VendorEntity;
import com.trade.service.enterprise.companyrelated.domain.vo.VendorEntitySearch;
import com.trade.service.enterprise.companyrelated.mapper.VendorEntityMapper;
import com.trade.service.enterprise.companyrelated.service.IVendorEntityService;

/**
 * <p>
 * 供应商企业信息 服务实现类
 * </p>
 *
 * @author zhangchenm
 * @since 2024-09-03
 */
@Service
public class VendorEntityServiceImpl extends ServiceImpl<VendorEntityMapper, VendorEntity> implements IVendorEntityService {

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

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

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

    @Override
    public VendorEntityVO getVOByEntityId(Long entityId) {
        return getBaseMapper().getVOByEntityId(entityId);
    }

    @Override
    public VendorEntity getByEntityNo(String entityNo) {
        return this.lambdaQuery().eq(VendorEntity::getEntityNo, entityNo).one();
    }

    @Override
    public List<VendorEntityDict> getList4Dict() {
        return getBaseMapper().getList4Dict();
    }
}
