package com.sckw.contract.repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sckw.contract.dao.KwcContractTradeUnitMapper;
import com.sckw.contract.model.entity.KwcContractTradeUnit;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * @author :chenXiaoFei
 * @version :1.0
 * @description : 公司合同信息接口
 * @create :2025-11-05 14:52:00
 */
@Repository
public class KwcContractTradeUnitRepository extends ServiceImpl<KwcContractTradeUnitMapper, KwcContractTradeUnit> {
    public List<KwcContractTradeUnit> queryByContractId(Long contractId) {
        return list(Wrappers.<KwcContractTradeUnit>lambdaQuery()
                .eq(KwcContractTradeUnit::getContractId, contractId)
                .eq(KwcContractTradeUnit::getDelFlag, 0));
    }

    public List<KwcContractTradeUnit> queryByEntIds(Set<Long> entIds) {
        return list(Wrappers.<KwcContractTradeUnit>lambdaQuery()
                .eq(KwcContractTradeUnit::getDelFlag, 0)
                .in(KwcContractTradeUnit::getEntId, entIds));
    }

    public List<KwcContractTradeUnit> queryByContractIds(Set<Long> tradeContractIds) {
        return list(Wrappers.<KwcContractTradeUnit>lambdaQuery()
                .eq(KwcContractTradeUnit::getDelFlag, 0)
                .in(KwcContractTradeUnit::getContractId, tradeContractIds));
    }

    public List<KwcContractTradeUnit> queryByContractIdsAndEntType(Set<Long> tradeContractIds,Integer entType) {
        QueryWrapper<KwcContractTradeUnit> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("DISTINCT ent_id,firm_name")
                .eq("del_flag", 0)
                .in("contract_id", tradeContractIds)
                .eq("unit_type", entType);
        return list(queryWrapper);
    }

    public List<KwcContractTradeUnit> queryByEntIdAndUnitType(Long entId, Integer unitType) {
       return list(Wrappers.<KwcContractTradeUnit>lambdaQuery()
                .eq(KwcContractTradeUnit::getEntId, entId)
                .eq(KwcContractTradeUnit::getUnitType, unitType)
                .eq(KwcContractTradeUnit::getDelFlag, 0));
    }
}
