package com.ym.mec.biz.service.impl;

import com.ym.mec.biz.event.TenantConfigChangeEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;

import com.ym.mec.biz.dal.dao.SysConfigDao;
import com.ym.mec.biz.dal.entity.SysConfig;
import com.ym.mec.biz.service.SysConfigService;
import com.ym.mec.common.dal.BaseDAO;
import com.ym.mec.common.service.impl.BaseServiceImpl;

import java.util.List;

@Service
public class SysConfigServiceImpl extends BaseServiceImpl<Long, SysConfig>  implements SysConfigService, ApplicationEventPublisherAware {
	
	@Autowired
	private SysConfigDao sysConfigDao;

	@Override
	public BaseDAO<Long, SysConfig> getDAO() {
		return sysConfigDao;
	}

	private ApplicationEventPublisher applicationEventPublisher;

	@Override
	public SysConfig findByParamName(String paramName) {
		return sysConfigDao.findByParamName(paramName);
	}

    @Override
    public void batchUpdate(List<SysConfig> configList) {
		sysConfigDao.batchUpdate(configList);
		applicationEventPublisher.publishEvent(new TenantConfigChangeEvent(this));
    }

	@Override
	public void updateConfig(SysConfig config) {
		sysConfigDao.update(config);
		applicationEventPublisher.publishEvent(new TenantConfigChangeEvent(this));
	}

	@Override
	public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
		this.applicationEventPublisher = applicationEventPublisher;
	}
}
