package com.palmnest.dao.wxpay.impl;

import com.palmnest.dao.hibernate.GenericDaoHibernate;
import com.palmnest.dao.wxpay.MerchantDetailDao;
import com.palmnest.model.wxpay.MerchantDetail;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

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

@Repository("merchantDetailDao")
public class MerchantDetailDaoImpl extends GenericDaoHibernate<MerchantDetail, Long> implements MerchantDetailDao {

	public MerchantDetailDaoImpl() {
		super(MerchantDetail.class);
	}

	@Override
	public List<MerchantDetail> findBy(Map<String, String> params) {
		StringBuilder strSQL = new StringBuilder("select * from tb_merchant_detail where is_enabled=1 ");
		if (StringUtils.isNotBlank(params.get("orgId"))) {
			strSQL.append(" and org_id=").append(params.get("orgId"));
		}
		if (StringUtils.isNotBlank(params.get("moduleCode"))) {
			strSQL.append(" and module_code='").append(params.get("moduleCode")).append("'");
		}
		return getSession().createSQLQuery(strSQL.toString()).addEntity(MerchantDetail.class).list();
	}


}
