package com.saye.hrs.service.system.impl;

import com.saye.hrs.mapper.system.ServiceParamsMapper;
import com.saye.hrs.model.ServiceParams;
import com.saye.hrs.service.system.ServiceParamsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

@Service
public class ServiceParamsServiceImpl implements ServiceParamsService {
	@Autowired
	private ServiceParamsMapper serviceParamsMapper;

	
	@Override
	public List<ServiceParams> selectServiceParams(HashMap<String, String> map) {
		// TODO Auto-generated method stub
		return serviceParamsMapper.selectServiceParams(map);
	}

	@Override
	@Transactional
	public int insertServiceParams(ServiceParams sp) throws Exception {
		// 1.先根据参数编码查询，是否有重复编码
		List<HashMap<Object, Object>> result=serviceParamsMapper.findParamValByParamCode(sp.getParamCode());
		if(result.size()>0){
			//大于0代表编码已存在
			return -1;
		}
		return serviceParamsMapper.insertServiceParams(sp);
	}

	@Override
	@Transactional
	public int updateServiceParams(ServiceParams sp) throws Exception{
		return serviceParamsMapper.updateServiceParams(sp);
	}
	
	

	@Override
	@Transactional
	public int deleteServiceParams(String paramId) throws Exception{
		// TODO Auto-generated method stub
		return serviceParamsMapper.deleteServiceParams(paramId);
	}

	@Override
	public List<HashMap<Object, Object>> findParamVal() throws Exception {
		
		return serviceParamsMapper.findParamVal();
	}

	/**
	 * @description 根据code查询配置的val
	 * @author thuang       
	 * @created 2020年1月3日 下午6:41:37
	 */
	@Override
	public List<HashMap<Object, Object>> findParamValByParamCode(String code) {
		List<HashMap<Object, Object>> result=null;
		try {
			result=serviceParamsMapper.findParamValByParamCode(code);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
	
	/**
	 * @description 根据code修改val
	 * @author dqzhang       
	 * @created 2020年5月19日 上午10:01:32
	 */
	public void updateServiceParamsValBycode(HashMap<String,String> map){
		
		this.serviceParamsMapper.updateServiceParamsValBycode(map);
	}
}
