package com.huimv.admin.repo.secondary;

import com.huimv.admin.domain.secondary.DaLqda;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

public interface DaLqdaRepository extends JpaRepository<DaLqda, Integer>, JpaSpecificationExecutor<DaLqda> {

    @Query(nativeQuery = true ,value = "select * from da_lqda where zsid like %?1%   limit ?2 , ?3")
    List<DaLqda> findAll(String name, Integer startPage, Integer pageSize);



    @Query(nativeQuery = true ,value = " SELECT  * FROM  da_lqda ORDER BY id DESC  LIMIT 1   ")
    DaLqda  findlast();


    @Query(nativeQuery = true ,value = "select * from da_lqda where zsid like %?1%  ORDER BY id DESC LIMIT 1")
    List<DaLqda> findAllByZsid(Integer ZSID);

    @Query(nativeQuery = true ,value = "SELECT lq.*,zs.ZSMC FROM `da_lqda` lq,`da_zsda` zs WHERE lq.ZSID = zs.ID and lq.ZSID in (?1) and lq.LQMC like %?2% limit ?3,?4")
    List<Map<String,Object>> findAllByZsids(List<Integer> zsids, String name, Integer startPage, Integer pageSize);

    @Query(nativeQuery = true , value = "select count(*) from da_lqda where ZSID in (?1) and LQMC like %?2%")
    Integer findAllByZsidAll(List<Integer> zsids,String name);


//    @Query(nativeQuery = true , value = "SELECT id,CGQID,lqid,dqaq,CJSJ,SCSJ FROM sj_hk_aq WHERE id IN(SELECT MAX(id) FROM sj_hk_aq WHERE lqid IN(?1) AND DATE_FORMAT(CJSJ,'%Y-%m-%d')=?2 GROUP BY lqid)")
//    List<SjHkAqEntity> getLastAq(List<Integer> lqids,String todayDate);

    @Query(nativeQuery = true , value = "select LQMC from da_lqda where id = ?1")
   String findBy(Integer dqlq);

}