package com.ssj.dao.sys.sconota.dao;

import com.ssj.bean.conch.conch.domain.SconOtaManager;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author yanghuan
 * @title: SconOtaDao
 * @projectName ssj
 * @description: TODO
 * @date 2019/7/2 11:21
 */
@Repository
public interface SconOtaDao extends JpaRepository<SconOtaManager, String> {

    List<SconOtaManager> findByCurrentVersionAndTypeOrderByCreateTimeDesc(String versionType, int type);

    @Query(nativeQuery = true,value = "select * from scon_ota_manager a where not exists(select 1 from scon_ota_manager where current_version=a.current_version and id<a.id) order by a.create_time desc")
    List<SconOtaManager> findAllCurrentVersion();

    @Query(nativeQuery = true,value = "select * from scon_ota_manager a where not exists(select 1 from scon_ota_manager where update_version=a.update_version and id<a.id) order by a.create_time desc")
    List<SconOtaManager> findAllUpdateVersion();

    Page<SconOtaManager> findAll(Specification<SconOtaManager> specification, Pageable page);
}
