package com.sckw.contract.repository;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sckw.contract.dao.KwcContractTradeMapper;
import com.sckw.contract.model.entity.KwcContractTrade;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author :chenXiaoFei
 * @version :1.0
 * @description : 贸易合同接口
 * @create :2025-11-05 09:27:00
 */
@Repository
public class KwcContractTradeRepository extends ServiceImpl<KwcContractTradeMapper, KwcContractTrade> {
    public List<KwcContractTrade> queryByPid( Long pid) {
        return list(Wrappers.<KwcContractTrade>lambdaQuery()
                .eq(KwcContractTrade::getDelFlag, 0)
                .eq(KwcContractTrade::getContractPid, pid));
    }

    public KwcContractTrade queryByContractId( String contractId) {
        return getOne(Wrappers.<KwcContractTrade>lambdaQuery()
                .eq(KwcContractTrade::getDelFlag, 0)
                .eq(KwcContractTrade::getContractNo, contractId)
                .last("limit 1"));
    }

    public Boolean updateByContractId(KwcContractTrade updateKwcContractTrade) {
       return update(updateKwcContractTrade, Wrappers.<KwcContractTrade>lambdaQuery()
                .eq(KwcContractTrade::getId, updateKwcContractTrade.getId()));
    }

    public KwcContractTrade queryByContractNo( String contractCode) {
        return getOne(Wrappers.<KwcContractTrade>lambdaQuery()
                .eq(KwcContractTrade::getDelFlag, 0)
                .eq(KwcContractTrade::getContractNo, contractCode)
                .last("limit 1"));
    }
}
