package com.goafanti.sc.service.impl;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.goafanti.common.dao.ScMessageMapper;
import com.goafanti.common.model.ScMessage;
import com.goafanti.common.utils.StringUtils;
import com.goafanti.core.mybatis.BaseMybatisDao;
import com.goafanti.core.mybatis.page.Pagination;
import com.goafanti.sc.bo.ScMessageListBo;
import com.goafanti.sc.service.CommonService;


@Service
public class CommonServiceImpl extends BaseMybatisDao<ScMessageMapper> implements CommonService 	{
	
	@Autowired
	private ScMessageMapper	 scMessageMapper;
	
	
	@Override
	public int addMessage(ScMessage s) {
		s.setId(UUID.randomUUID().toString());
		return scMessageMapper.insertSelective(s);
	}


	@SuppressWarnings("unchecked")
	@Override
	public Pagination<ScMessageListBo> listMessage(String id, Integer pSize, Integer pNo) {
		Map<String, Object> params =new HashMap<>();
		if (pNo == null || pNo < 0)	pNo = 1;
		if (pSize == null || pSize < 0 || pSize > 10) pSize = 10;
		if(StringUtils.isNotBlank(id))params.put("id", id);
		return (Pagination<ScMessageListBo>) findPage("findMessageListByPage",
				"findMessageCount",params,
				pNo, pSize);
	}

	

	
}
