package com.jwipc.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jwipc.sys.entity.StatementPaymentSetting;
import com.jwipc.sys.mapper.StatementPaymentSettingMapper;
import com.jwipc.sys.service.IStatementPaymentSettingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 对账模块查询配置(1个供应商对应多个对账采购组) 服务实现类
 * </p>
 *
 * @author qzc
 * @since 2025-02-07
 */
@Service
public class StatementPaymentSettingServiceImpl extends ServiceImpl<StatementPaymentSettingMapper, StatementPaymentSetting> implements IStatementPaymentSettingService {


    @Override
    public List<StatementPaymentSetting> findStatementPaymentSettingList(Long userId, String purchaseGroupCode, String supplierCode) {
        //通过获取到当前登录用户id,采购组code,供应商id
        return baseMapper.selectList(
                new LambdaQueryWrapper<StatementPaymentSetting>()
                        .eq(StatementPaymentSetting::getUserId,userId)
                        .eq(StatementPaymentSetting::getPurchaseGroupCode,purchaseGroupCode)
                        .eq(StatementPaymentSetting::getSupplierCode,supplierCode)
                        .eq(StatementPaymentSetting::getDelFlag,0));
    }

    @Override
    public List<StatementPaymentSetting> findStatementPaymentSettingBySupplierCodeList(String supplierCode) {
        return baseMapper.selectList(new LambdaQueryWrapper<StatementPaymentSetting>()
                .eq(StatementPaymentSetting::getSupplierCode,supplierCode)
                .eq(StatementPaymentSetting::getDelFlag,0));
    }

    @Override
    public String findByPurchaseGroupCode(String purchaseGroupCode) {
        List<StatementPaymentSetting> statementPaymentSettings = baseMapper.selectList(new LambdaQueryWrapper<StatementPaymentSetting>()
                .eq(StatementPaymentSetting::getPurchaseGroupCode, purchaseGroupCode)
                .eq(StatementPaymentSetting::getDelFlag, 0));
        if(CollectionUtils.isNotEmpty(statementPaymentSettings)){
            return "1";
        }
        return "0";

    }
}
