package com.cloudcross.ssp.back.service.impl;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloudcross.ssp.back.model.Dimension;
import com.cloudcross.ssp.back.service.IDimensionService;
import com.cloudcross.ssp.base.dao.GenericIBatisDao;
import com.cloudcross.ssp.common.utils.Pager;
import com.cloudcross.ssp.common.utils.SqlHelper;


	
	
	
	@Service
	public class DimensionService implements IDimensionService{
		
		
		@Autowired
		private GenericIBatisDao myBatisDao;
	
		
		@Override
		public boolean add(Dimension dimension) {
			
			// 添加一个用户。
			dimension.setId(dimension.getId());
			dimension.setName(dimension.getName());
			dimension.setContent(dimension.getContent());
			dimension.setIsDefault(dimension.getIsDefault());
			myBatisDao.save("back.dimensionSqlMapper.addDimension", dimension);
			
			return true;
		}

		@Override
		public int countByParams(Map<String, Object> paramMap) {
			String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
			paramMap.put("key", paramMap.get("searchKey"));
			paramMap.put("value", searchValue);
			return myBatisDao.get("back.dimensionSqlMapper.countByParams", paramMap);
		}
		@Override
		public boolean edit(Dimension dimension) {
			
			myBatisDao.save("back.dimensionSqlMapper.editDimension", dimension);
			return true;
		}

		@Override
		public Dimension findById(Long id) {
			return myBatisDao.get("back.dimensionSqlMapper.selectById", id);
		}
		
		@Override
		public List<Dimension> findByParams(Map<String, Object> paramMap, Pager pager) {
			String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
			paramMap.put("key", paramMap.get("searchKey"));
			paramMap.put("value", searchValue);
			paramMap.put("pager", pager);
			if(pager == null){
				return myBatisDao.getList("back.dimensionSqlMapper.selectByParams1", paramMap);
			}else{
				return myBatisDao.getList("back.dimensionSqlMapper.selectByParams", paramMap);
			}
		}

		@Override
		public Dimension findByName(String name) {
			return myBatisDao.get("back.dimensionSqlMapper.selectByName", name);
		}

		@Override
		public boolean updateStatus(List<Long> idList, int status) {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public boolean deleteById(HashMap<String, Object> paraMap) {
			myBatisDao.delete("back.dimensionSqlMapper.deleteById", paraMap);
			return true;
		}

		@Override
		public boolean updateDimensionDefault(long dimensionId){
			myBatisDao.save("back.dimensionSqlMapper.updateDimensionDefault", dimensionId);
			myBatisDao.save("back.dimensionSqlMapper.updateDimensionDefaultById", dimensionId);
			return true;
		}

		@Override
		public HashMap<String,Object> selectDimensionIdBydefault() {
			// TODO Auto-generated method stub
			return myBatisDao.get("back.dimensionSqlMapper.selectDimensionIdBydefault",0);
		}

		}

		
	
