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

import com.ssj.dao.sys.appinfo.dao.AppInfoQueryDao;
import com.ssj.framework.basic.utils.StringUtils;
import com.ssj.framework.core.persistence.PagingHibernateJdbcDao;
import com.ssj.service.sys.appinfo.service.dto.LastVersionAppInfoDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

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

@Repository
public class AppInfoQueryDaoImpl implements AppInfoQueryDao {

    @Autowired
    private PagingHibernateJdbcDao dao;

    @Override
    public List<LastVersionAppInfoDto> findLastPackageByTypes(List<Integer> types, String versionType) {
        StringBuilder sb = new StringBuilder();
        sb.append(" select ai.type, ai.version, ai.file_key from")
                .append(" (select type, max(create_time) create_time from scon_app_info ")
                .append(" where type in (")
                .append(StringUtils.join(types, ","))
                .append(") and is_delete = 0 and version_type=?  group by type) maxai ")
                .append(" left join  scon_app_info ai on maxai.type=ai.type and maxai.create_time=ai.create_time");
        List<Object> param = new ArrayList<>();
        param.add(versionType);
        return dao.findList(sb.toString(), param.toArray(), LastVersionAppInfoDto.class);
    }


}
