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

import java.util.Date;
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.Message;
import com.cloudcross.ssp.back.service.IMessageService;
import com.cloudcross.ssp.base.dao.GenericIBatisDao;
import com.cloudcross.ssp.common.utils.Pager;
import com.cloudcross.ssp.common.utils.SqlHelper;

@Service
public class MessageService implements IMessageService {
	@Autowired
	private GenericIBatisDao myBatisDao;
	
	@Override
	public Message findById(Long id) {
		return myBatisDao.get("back.messageSqlMapper.selectById", id);
	}
	@Override
	public Message selectByRead(Long id) {
		return myBatisDao.get("back.messageSqlMapper.selectByRead", id);
	}
	@Override
	public int countByParams(Map<String, Object> paramMap) {
		if(paramMap.get("searchValue")!=null && paramMap.get("searchValue")!=""){
			String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
			paramMap.put("value", searchValue);
		}else{
			paramMap.put("value", null);
		}
		return myBatisDao.get("back.messageSqlMapper.countByParams", paramMap);
	}

	@Override
	public List<Message> findByParams(Map<String, Object> paramMap, Pager pager) {
		if(paramMap.get("searchValue")!=null && paramMap.get("searchValue")!=""){
			String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
			paramMap.put("value", searchValue);
		}else{
			paramMap.put("value", null);
		}
		paramMap.put("pager", pager);
		return myBatisDao.getList("back.messageSqlMapper.selectByParams", paramMap);
	}

	@Override
	public boolean add(Message t) {
		t.setRead(false);
		t.setSendTime(new Date());
		myBatisDao.save("back.messageSqlMapper.addMessage", t);
		return true;
	}

	@Override
	public boolean edit(Message t) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public int countByStatus(Map<String, Object> paramMap) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<Message> findByType(int type) {
		return myBatisDao.getList("back.messageSqlMapper.findByType", type);
	}

	@Override
	public boolean updateStatus(List<Long> idList, int status) {	
		return false;
	}
	
	
	
}
