package com.hotent.portal.persistence.manager.impl;

import com.hotent.base.manager.impl.BaseManagerImpl;
import com.hotent.base.util.UniqueIdUtil;
import com.hotent.portal.model.MessageRead;
import com.hotent.portal.model.PortalNewsNoticeRead;
import com.hotent.portal.persistence.dao.MessageReadDao;
import com.hotent.portal.persistence.dao.PortalNewsNoticeReadDao;
import com.hotent.portal.persistence.manager.MessageReadManager;
import com.hotent.portal.persistence.manager.PortalNewsNoticeReadManager;
import com.hotent.uc.api.model.IUser;
import org.springframework.stereotype.Service;

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

@Service("portalNewsNoticeReadManager")
public class PortalNewsNoticeReadManagerImpl extends BaseManagerImpl<PortalNewsNoticeReadDao, PortalNewsNoticeRead> implements PortalNewsNoticeReadManager {
	
	@Override
	public void addMessageRead(String msgId, IUser sysUser) {
		Map<String, Object> params = new HashMap<>();
		params.put("userId", sysUser.getUserId());
		params.put("msgId", msgId);
		List<PortalNewsNoticeRead> list = baseMapper.getReadByUser(params);
		if(list==null || list.size()==0){
			PortalNewsNoticeRead read = new PortalNewsNoticeRead();
			read.setId(UniqueIdUtil.getSuid());
			read.setMsgId(msgId);
			read.setReceiverId(sysUser.getUserId());
			read.setReceiver(sysUser.getFullname());
			read.setReceiverTime(LocalDateTime.now());
			this.create(read);
		}
		
	}
	@Override
	public List<PortalNewsNoticeRead> getReadByUser(Map params) {
		return baseMapper.getReadByUser(params);
	}

	@Override
	public List<PortalNewsNoticeRead> getByMessageId(String messageId) {
		return baseMapper.getByMessageId(messageId);
	}
}
