package com.JN.demo.bizquery.mapper;

import com.JN.demo.bizquery.dto.BizDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @ClassName BizMapper
 * @Description TODO
 * @Author JN
 * @Date 2024/1/8 10:11
 * @Version 1.0
 */
@Mapper
@Repository
public interface BizMapper {
    @Select("select  kunnr,name1 from openquery(hana2,'select top 10 * from SAPHANADB.kna1 where name1 like ''%${name}%'' and name1 not like ''冻结''')")
    List<BizDto> queryBizListByName(String name);

    @Select("select * from openquery(hana2,'select max(erdat)  from SAPHANADB.likp where kunnr = ''${kunnr}'' and   erdat >= ''${time}''')")
    String queryLatestShippingDate(String kunnr, String time);

    @Select("select * from openquery(hana2,'select max(erdat)  from SAPHANADB.vbak where kunnr = ''${kunnr}'' and   erdat >= ''${time}'' and VBTYP = ''C''')")
    String queryLatestOrderDate(String kunnr,  String time);

    @Select("select * from \n" +
            "openquery(hana2,'select count(distinct b.kunnr)  from SAPHANADB.vbak as a inner join SAPHANADB.vbpa  as b \n" +
            "on a.vbeln = b.vbeln where a.kunnr = ''${kunnr}'' and b.PARVW = ''Z1'' and   a.erdat >= ''${time}''')")
    String querySalespersonCount(String kunnr, String time);

    @Select("select max(create_time_0)  from [JNERP].[jn_erp].[dbo].[CRM_MESSAGE] where client_name_0 = '${name}'")
    String queryLatestQuotationDate(String name);

    @Select("select * from openquery(hana2,'select max(erdat)  from SAPHANADB.vbak where kunnr = ''${kunnr}'' and   erdat >= ''${time}'' and VBTYP = ''G''')")
    String queryLatestContractDate(String kunnr, String time);

    @Select("SELECT TOP 1 A.createdon\n" +
            "FROM [CRM].[JNCRM_MSCRM].[dbo].[new_bid_informationBase] A\n" +
            "LEFT JOIN [CRM].[JNCRM_MSCRM].[dbo].AccountBase B on B.AccountId = A.new_accountid\n" +
            "where A.statecode = 0 and B.Name is not null and A.new_examinetenderoffice <> 10\n" +
            "and B.new_sapcustomer_code = '${kunnr}' \n" +
            "ORDER BY A.createdon DESC")
    String queryLatestBidDate(String kunnr);
}
