package com.palmnest.dao.notice.impl;

import com.palmnest.application.bean.Page;
import com.palmnest.dao.hibernate.GenericDaoHibernate;
import com.palmnest.dao.notice.MobileConfigDao;
import com.palmnest.model.notice.MobileConfigModel;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author HIAPAD
 * @Description TODO
 * @Date 2018/9/11 16:46
 **/
@Repository("mobileConfigDao")
public class MobileConfigDaoImpl extends GenericDaoHibernate<MobileConfigModel, Long> implements MobileConfigDao {

	public MobileConfigDaoImpl() {
		super(MobileConfigModel.class);
	}

	@Override
	public Page getMobileConfigList(String orgIds, int pageNo, int pageSize) throws Exception {
		StringBuilder strHql = new StringBuilder("select org.name as orgName,em.* from tb_mobile_config em  ");
		strHql.append(" left join tb_organization org on org.id=em.orgId ");
		strHql.append(" where em.isEnable=1 ");

		if (StringUtils.isNotBlank(orgIds)) {
			strHql.append(" and em.orgId in (" + orgIds + ") ");
		}
		strHql.append(" order by createTime desc ");
		return pagedQueryByJdbcTemplate(strHql.toString(), pageNo, pageSize);
	}

	/**
	 *
	 * @param orgIds
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<MobileConfigModel> getMobileConfigList(String orgIds) throws Exception {
		StringBuilder strHql = new StringBuilder("select * from tb_mobile_config em ");
		strHql.append(" left join tb_organization org on org.id=em.orgId ");
		strHql.append(" where em.isEnable=1 ");

		if (StringUtils.isNotBlank(orgIds)) {
			strHql.append(" and em.orgId in (" + orgIds + ") ");
		}
		strHql.append(" order by em.createTime desc ");
		return getSession().createSQLQuery(strHql.toString()).addEntity(MobileConfigModel.class).list();
	}
}
