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

import com.ssj.dao.sys.cardinfo.dao.ICardInfoQueryDao;
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;
import java.util.Map;


@Repository
public class CardInfoQueryDaoImpl implements ICardInfoQueryDao {

	@Autowired
	private PagingHibernateJdbcDao dao;

	@Override
	public Page<Map<String, Object>> findCardInfoPage(Map<String, Object> params, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append("select a.*,b.wx_name,c.league_name from tb_card_info a  \n");
		selSQL.append("left join tb_user b on a.user_id = b.id \n ");
		selSQL.append("left join tb_lib_join c on a.lib_id = b.id \n");
		if(params.get("LIKE_realName")!=null && !"".equals(params.get("LIKE_realName"))){
			selSQL.append(" where card_name like CONCAT('%',?,'%') \n");
			queryParams.add(params.get("LIKE_realName"));
		}
		return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}
}
