package com.xingxi.master.vendor.service.impl;

import com.xingxi.common.core.text.Convert;
import com.xingxi.common.enums.EDelFlag;
import com.xingxi.common.utils.DateUtils;
import com.xingxi.common.utils.ShiroUtils;
import com.xingxi.master.vendor.domain.Vendor;
import com.xingxi.master.vendor.mapper.VendorMapper;
import com.xingxi.master.vendor.service.IVendorService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 供应商Service业务层处理
 *
 * @author xingxi
 * @date 2025-03-06
 */
@Service
public class VendorServiceImpl implements IVendorService {
    @Resource
    private VendorMapper vendorMapper;

    /**
     * 查询供应商
     *
     * @param vendorId 供应商主键
     * @return 供应商
     */
    @Override
    public Vendor selectVendorByVendorId(Long vendorId) {
        return vendorMapper.selectVendorByVendorId(vendorId);
    }

    /**
     * 查询供应商列表
     *
     * @param vendor 供应商
     * @return 供应商
     */
    @Override
    public List<Vendor> selectVendorList(Vendor vendor) {
        vendor.setDelFlag(EDelFlag.NO.getVal());
        return vendorMapper.selectVendorList(vendor);
    }

    /**
     * 新增供应商
     *
     * @param vendor 供应商
     * @return 结果
     */
    @Override
    public int insertVendor(Vendor vendor) {
        vendor.setDelFlag(EDelFlag.NO.getVal());
        vendor.setCreateUser(ShiroUtils.getLoginName());
        vendor.setCreateTime(DateUtils.getNowDate());
        return vendorMapper.insertVendor(vendor);
    }

    /**
     * 新增供应商
     *
     * @param vendorList 供应商
     * @return 结果
     */
    @Override
    public int batchInsertVendor(List<Vendor> vendorList) {
        return vendorMapper.batchInsertVendor(vendorList);
    }

    /**
     * 修改供应商
     *
     * @param vendor 供应商
     * @return 结果
     */
    @Override
    public int updateVendor(Vendor vendor) {
        vendor.setUpdateUser(ShiroUtils.getLoginName());
        vendor.setUpdateTime(DateUtils.getNowDate());
        return vendorMapper.updateVendor(vendor);
    }

    /**
     * 批量删除供应商
     *
     * @param vendorIds 需要删除的供应商主键
     * @return 结果
     */
    @Override
    public int deleteVendorByVendorIds(String vendorIds) {
        return vendorMapper.deleteVendorByVendorIds(Convert.toStrArray(vendorIds));
    }

    /**
     * 删除供应商信息
     *
     * @param vendorId 供应商主键
     * @return 结果
     */
    @Override
    public int deleteVendorByVendorId(Long vendorId) {
        return vendorMapper.deleteVendorByVendorId(vendorId);
    }

    /**
     * 逻辑删除供应商
     *
     * @param vendorId 供应商主键
     * @return 结果
     */
    @Override
    public int logicDeleteVendorByVendorId(Long vendorId) {
        return vendorMapper.logicDeleteVendorByVendorId(vendorId);
    }

    /**
     * 逻辑批量删除供应商
     *
     * @param vendorIds 需要删除的数据主键集合
     * @return 结果
     */
    @Override
    public int logicDeleteVendorByVendorIds(String[] vendorIds) {
        return vendorMapper.logicDeleteVendorByVendorIds(vendorIds);
    }

    /**
     * 逻辑批量删除供应商
     *
     * @param vendor 供应商
     * @return 结果
     */
    @Override
    public int logicDeleteVendorByCondition(Vendor vendor) {
        return vendorMapper.logicDeleteVendorByCondition(vendor);
    }
}
