package com.palmnest.dao.washcar.impl;

import com.palmnest.dao.hibernate.GenericDaoHibernate;
import com.palmnest.dao.washcar.ExtraServiceDao;
import com.palmnest.model.washcar.ExtraService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * 额外服务设置dao实现类
 *
 * @author longmeizhen
 */
@Slf4j
@Repository("extraServiceDao")
public class ExtraServiceDaoImpl extends GenericDaoHibernate<ExtraService, Long> implements ExtraServiceDao {


	public ExtraServiceDaoImpl() {
		super(ExtraService.class);
	}

	@Override
	public List<ExtraService> getAll() {
		String             strHql    = "from ExtraService where isEnabled='1' ";
		List<ExtraService> extraList = getSession().createQuery(strHql).list();
		return extraList;
	}

	@Override
	public Integer deleteExtra(Long id, String userId) throws Exception {
		String sql = "update tb_extra_service set isEnabled='0',modifier='" + userId + "',modifyTime=SYSDATE() where id=" + id;
		return getSession().createSQLQuery(sql).executeUpdate();
	}

	@Override
	public List<ExtraService> getExtraBySetId(Long setId) throws Exception {
		String             strHql    = "from ExtraService where isEnabled='1' and  proSetId=?";
		List<ExtraService> extraList = getSession().createQuery(strHql).setLong(0, setId).list();
		return extraList;
	}

	@Override
	public List<ExtraService> findByProSetId(Long proSetId) {
		String             strHql    = "from ExtraService where isEnabled='1'  and proSetId=? and isOther<>2";
		List<ExtraService> extraList = getSession().createQuery(strHql).setLong(0, proSetId).list();
		return extraList;
	}

	@Override
	public List<ExtraService> findByProSetIdandNotIsOther(Long proSetId)
			throws Exception {
		String             strHql    = "from ExtraService where isEnabled='1'  and proSetId=? and isOther=2 ";
		List<ExtraService> extraList = getSession().createQuery(strHql).setLong(0, proSetId).list();
		return extraList;
	}
}
