package com.palmnest.service.dinner.manager.impl;

import com.palmnest.dao.dinner.RechargeSetDao;
import com.palmnest.model.dinner.RechargeSet;
import com.palmnest.service.dinner.manager.RechargeSetManager;
import com.palmnest.service.impl.GenericManagerImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Slf4j
@Service("rechargeSetManager")
public class RechargeSetManagerImpl extends GenericManagerImpl<RechargeSet, Long> implements RechargeSetManager {


	private RechargeSetDao rechargeSetDao;

	@Autowired
	public void setRechargeSetDao(RechargeSetDao rechargeSetDao) {
		this.rechargeSetDao = rechargeSetDao;
		this.dao = rechargeSetDao;
	}

	@Override
	public RechargeSet findByOrgId(String orgId) {
		return rechargeSetDao.findByOrgId(orgId);
	}

	@Override
	public RechargeSet saveAndUpdateReSet(RechargeSet reSet) {
		if (reSet.getId() == null) {
			reSet.setCreateTime(new Date());
			reSet.setIsEnabled("1");
			reSet = rechargeSetDao.save(reSet);
		} else {
			reSet.setModifyTime(new Date());
			rechargeSetDao.updateObj(reSet);
		}
		return reSet;
	}
}
