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

import com.ssj.bean.conch.conch.domain.SconOtaManager;
import com.ssj.dao.sys.sconota.dao.SconOtaManagerVersionDao;
import com.ssj.framework.core.persistence.PagingHibernateJdbcDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yanghuan
 * @title: SconOtaManagerDaoImpl
 * @projectName ssj
 * @description: TODO
 * @date 2019/7/3 17:30
 */
@Repository
public class SconOtaManagerDaoImpl implements SconOtaManagerVersionDao {
    @Autowired
    private PagingHibernateJdbcDao dao;

    @Override
    public Page<SconOtaManager> findAllOtaVersion(Pageable pageable){
        StringBuilder sql = new StringBuilder();
        List<Object> queryParams = new ArrayList<>();
        sql.append("select * from scon_ota_manager a where not exists(select 1 from scon_ota_manager where update_version=a.update_version and current_version=a.current_version and id<a.id) order by a.create_time desc");
        return dao.findPage(sql.toString(),pageable,SconOtaManager.class);


    }


    @Override
    public Page<SconOtaManager> findAllOtaPack(Pageable pageable){
        StringBuilder sql = new StringBuilder();
        List<Object> queryParams = new ArrayList<>();
        sql.append("select * from scon_ota_manager where update_pack_name is not null order by create_time desc");
        return dao.findPage(sql.toString(),pageable,SconOtaManager.class);
    }
}
