package com.palmnest.dao.notice.impl;

import java.util.List;

import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Repository;

import com.palmnest.dao.hibernate.GenericDaoHibernate;
import com.palmnest.dao.notice.NoticeSubGroupDao;
import com.palmnest.model.estateserve.VirtualAccount;
import com.palmnest.model.notice.NoticeSubGroupModel;

@Slf4j
@Repository("noticeSubGroupDao")
public class NoticeSubGroupDaoImpl extends GenericDaoHibernate<NoticeSubGroupModel, Integer> implements NoticeSubGroupDao{
	public NoticeSubGroupDaoImpl() {
		super(NoticeSubGroupModel.class);

	}

	/**
	 * 删除已经存在的关系
	 * @param type
	 * @param sourceId
	 */
	@Override
	public void delBySourceId(Integer type, Integer sourceId,Integer modify) {
		StringBuilder sql=new StringBuilder("update tb_notice_subgroup set enabled=0 , updated_at=SYSDATE() , updated_by = "+modify);
		sql.append(" where type="+type);
		sql.append(" and source_id="+sourceId);
		getJdbcTemplate().execute(sql.toString());
	}

	/**
	 * 根据源id获取订单的分组部门信息
	 * @param type
	 * @param sourceId
	 * @return
	 */
	@Override
	public List<NoticeSubGroupModel> findBySourceId(Integer type,
			Integer sourceId) {
		String sql="from NoticeSubGroupModel where type=? and source_id=? and enabled=1 ";
		List<NoticeSubGroupModel> list=getSession().createQuery(sql).setInteger(0, type).setInteger(1, sourceId).list();
		return list;
	}
}
