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

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

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 com.ssj.dao.weixin.problem.dao.YdzQueryDao;
import com.ssj.framework.core.persistence.PagingHibernateJdbcDao;

@Repository
public class YdzQueryDaoImpl   implements YdzQueryDao{
	@Autowired
	private PagingHibernateJdbcDao dao;

	@Override
	public Page<Map<String, Object>> findArticePage(
			Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT * FROM ydz_artice ");
        selSQL.append(" WHERE 1=1");
        if (searchParams.get("headline") != null && !searchParams.get("headline").equals("")) {
        	selSQL.append("  and    headline LIKE  CONCAT(CONCAT('%',?,'%'))  ");
        	queryParams.add(searchParams.get("headline"));
        }
        selSQL.append("  ORDER BY number");
        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
}

	@Override
	public Page<Map<String, Object>> findMatterPage(
			Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT * FROM ydz_artice_matter ");
        selSQL.append(" WHERE artice_id= ? ");
        queryParams.add(searchParams.get("artice_id"));
        if (searchParams.get("matter") != null && !searchParams.get("matter").equals("")) {
        	selSQL.append("  and    matter LIKE  CONCAT(CONCAT('%',?,'%'))  ");
        	queryParams.add(searchParams.get("matter"));
        }
        selSQL.append("  ORDER BY count");
        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
}

	@Override
	public Page<Map<String, Object>> findSolutionPage(
			Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT * FROM ydz_artice_matter_solution ");
        selSQL.append(" WHERE matter_id= ? ");
        queryParams.add(searchParams.get("matter_id"));
        if (searchParams.get("solution") != null && !searchParams.get("solution").equals("")) {
        	selSQL.append("  and    solution LIKE  CONCAT(CONCAT('%',?,'%'))  ");
        	queryParams.add(searchParams.get("solution"));
        }
        selSQL.append("  ORDER BY sequence");
        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
}

}
