package com.palmnest.dao.notice.impl;

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

import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Repository;

import cn.superdesk.libs.common.json.JsonUtils;

import com.palmnest.application.dto.input.ApprovalTypeDto;
import com.palmnest.dao.hibernate.GenericDaoHibernate;
import com.palmnest.dao.notice.NoticeApprovalTypeDao;
import com.palmnest.model.notice.NoticeApprovalTypeModel;
import com.palmnest.webapp.controller.notice.NoticeApprovalController;

@Slf4j
@Repository("noticeApprovalTypeDao")
public class NoticeApprovalTypeDaoImpl extends GenericDaoHibernate<NoticeApprovalTypeModel, Integer> implements NoticeApprovalTypeDao {
	public NoticeApprovalTypeDaoImpl() {
		super(NoticeApprovalTypeModel.class);

	}
	/**
	 * 根据审核开启记录查询审核类型
	 * @param setId
	 * @return
	 */
	@Override
	public List<NoticeApprovalTypeModel> getTypeListBySetId(Integer enabled,Integer setId) {
		StringBuilder sql=new StringBuilder("from NoticeApprovalTypeModel where enabled=? and approvalsetId=? ");
		return getSession().createQuery(sql.toString()).setInteger(0, enabled).setInteger(1, setId).list();
	}
	/**
	 * 根据项目获取该项目下所有的审核类型
	 * @param orgId
	 * @return
	 */
	@Override
	public List<Map<String, Object>> getTypeByOrgId(Integer orgId) {
		StringBuilder sql=new StringBuilder("");
		sql.append("  SELECT t.id, t.`name` FROM tb_app_notice_approval_type t, tb_app_notice_approvalset a WHERE 1 = 1 AND a.id = t.approvalset_id    ");
		sql.append("  AND t.enabled = 1   ");
		sql.append("  AND a.is_open = 1   ");
		sql.append("  AND a.org_id  ="+orgId);
		log.info("getTypeByOrgId-sql:{}",JsonUtils.toJson(sql));
		List<Map<String, Object>> list = getJdbcTemplate().queryForList(sql.toString());
		log.info("getTypeByOrgId-list:{}",JsonUtils.toJson(list));
		return list;
	}

}
