All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.didiglobal.logi.security.service.impl.MessageServiceImpl Maven / Gradle / Ivy

The newest version!
package com.didiglobal.logi.security.service.impl;

import com.didiglobal.logi.security.common.dto.message.MessageDTO;
import com.didiglobal.logi.security.common.entity.Message;
import com.didiglobal.logi.security.common.vo.message.MessageVO;
import com.didiglobal.logi.security.dao.MessageDao;
import com.didiglobal.logi.security.service.MessageService;
import com.didiglobal.logi.security.util.CopyBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author cjm
 */
@Service("logiSecurityMessageServiceImpl")
public class MessageServiceImpl implements MessageService {

    @Autowired
    private MessageDao messageDao;

    @Override
    public void saveMessage(MessageDTO messageDTO) {
        Message message = CopyBeanUtil.copy(messageDTO, Message.class);
        messageDao.insert(message);
    }

    @Override
    public List getMessageListByUserIdAndReadTag(Integer userId, Boolean readTag) {
        List messageList = messageDao.selectListByUserIdAndReadTag(userId, readTag);

        List result = new ArrayList<>();
        for(Message message : messageList) {
            MessageVO messageVO = CopyBeanUtil.copy(message, MessageVO.class);
            messageVO.setCreateTime(message.getCreateTime().getTime());
            result.add(messageVO);
        }
        return result;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void changeMessageStatus(List messageIdList) {
        if(CollectionUtils.isEmpty(messageIdList)) {
            return;
        }
        List messageList = messageDao.selectListByMessageIdList(messageIdList);
        for(Message message : messageList) {
            // 反转已读状态
            message.setReadTag(!message.getReadTag());
            messageDao.update(message);
        }
    }

    @Override
    public void saveMessages(List messageDTOList) {
        if(CollectionUtils.isEmpty(messageDTOList)) {
            return;
        }
        List messageList = CopyBeanUtil.copyList(messageDTOList, Message.class);
        messageDao.insertBatch(messageList);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy