package com.ssj.dao.weixin.library.dao.impl;

import com.ssj.dao.weixin.library.dao.IReadVipQueryDao;
import com.ssj.framework.core.persistence.PagingHibernateJdbcDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

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

/**
 * @author sh
 * @className ReadVipQueryDaoImpl
 * @description jpa实现
 * @date 2020/4/17
 */
@Repository
public class ReadVipQueryDaoImpl implements IReadVipQueryDao {

    @Autowired
    private PagingHibernateJdbcDao dao;

    @Override
    public List<Map<String, Object>> getServiceVip(String userId, String species) {
        StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT  e.lib_id,v.id as vip_id,v.child_name,v.img_url,e.species, e.type , DATE_FORMAT(e.end_time ,'%Y-%m-%d') as end_time  ");
        selSQL.append(" , (SELECT n.league_name from  tb_lib_join  n where n.id =e.lib_id) as lname  ");
        selSQL.append("  FROM  tb_lib_read_vip v   JOIN tb_lib_vip_service  e  ");
        selSQL.append("  on e.vip_id =v.id  ");
        selSQL.append("  where   v.user_id=? and e.species=?  and e.stat=1   ");
        queryParams.add(userId);
        queryParams.add(species);
        selSQL.append("  ORDER BY  e.end_time desc    ");
        return dao.findMap(selSQL.toString(), queryParams.toArray());
    }
}
