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

import com.ssj.dao.weixin.user.dao.SubActivityQueryDao;
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;

/**
 * @author sh
 * @className SubActivityQueryDaoImpl
 * @description 自定义查询类
 * @date 2020/5/6
 */
@Repository
public class SubActivityQueryDaoImpl implements SubActivityQueryDao {

    @Autowired
    private PagingHibernateJdbcDao dao;

    @Override
    public Page<Map<String, Object>> findByTypePages(Map<String, Object> searchParams, Pageable initPage) {
        StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append("  SELECT t11.wx_name,t11.photo,t.parent_id,date_format(t.create_time,'%Y-%m-%d %H:%i:%s') as create_time from tb_sub_activity t ");
        selSQL.append("  left join tb_user t11 on t.openid = t11.wx_account ");
        selSQL.append("  where t.type = 4    ");
        if (searchParams.get("area") != null && !searchParams.get("area").equals("")) {
            selSQL.append(" and  t.parent_id LIKE  CONCAT(CONCAT('%',?,'%')) ");
            queryParams.add(searchParams.get("area"));
        }
        selSQL.append(" order by t.create_time desc");
        return dao.findPage(selSQL.toString(), queryParams.toArray(), initPage);
    }
}
