package com.palmnest.service.estateserve.impl;

import com.palmnest.dao.estateserve.ServeConfigDao;
import com.palmnest.model.estateserve.ServiceFunctionRelation;
import com.palmnest.model.estateserve.ServiceProjectAllocation;
import com.palmnest.model.estateserve.ServiceTypeInfo;
import com.palmnest.service.estateserve.ServeConfigManager;
import com.palmnest.service.impl.GenericManagerImpl;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * @Author HXT
 * @Description TODO
 * @Date 2018/8/13 17:25
 **/
@Service("serveConfigManager")
public class ServeConfigManagerImpl extends GenericManagerImpl<ServiceFunctionRelation, Long> implements ServeConfigManager {

	private Logger logger = LoggerFactory.getLogger(ServeConfigManagerImpl.class);

	@Autowired
	private ServeConfigDao serveConfigDao;

	@Override
	public void saveUpdate(Integer serverId, Integer port, String[] funcIds) {

		//删除之前关系
		serveConfigDao.deleteByServerIdAndType(serverId, port);

		//保存/修改关系
		for (String id : funcIds) {
			if (StringUtils.isNotBlank(id)) {
				ServiceFunctionRelation re = new ServiceFunctionRelation();
				re.setServiceId(serverId);
				re.setFunctionId(Integer.parseInt(id));
				re.setType(port);
				serveConfigDao.saveObj(re);
			}
		}
	}

	@Override
	public List<ServiceFunctionRelation> getFunctionById(Integer serverId, Integer port) {
		return serveConfigDao.getFunctionById(serverId, port);
	}

	@Override
	public List<ServiceTypeInfo> getServiceList() {
		return serveConfigDao.getServiceList();
	}

	@Override
	public List<Map<String, Object>> getFunctionListByProjectId(Integer projectId) {
		return serveConfigDao.getFunctionListByProjectId(projectId);
	}

	@Override
	public ServiceTypeInfo getServiceTypeInfoByFuncId(String funcIds) {
		return serveConfigDao.getServiceTypeInfoByFuncId(funcIds);
	}

	@Override
	public ServiceProjectAllocation getServiceOrgInfo(int serviceId, String orgId) {
		return serveConfigDao.getServiceOrgInfo(serviceId, orgId);
	}
}
