package com.zhujizheng.IHome.msgnotify.service; import com.zhujizheng.IHome.generator.dao.PYMsgNotify; import com.zhujizheng.IHome.generator.mapper.PYMsgNotifyMapper; import com.zhujizheng.IHome.msgnotify.vo.PYMsgNotifyVO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; @Slf4j @Service @Transactional(rollbackFor = RuntimeException.class) public class PYMsgNotifyServerImpl implements PYMsgNotifyServer { @Autowired private PYMsgNotifyMapper msgNotifyMapper; @Override public PYMsgNotifyVO addOrUpdateMsgNotify(PYMsgNotify msgNotify) { if (msgNotify.getId() == null) { int result = msgNotifyMapper.insertNotify(msgNotify); if (result == 0) { log.error("新增消息通知异常"); return null; } log.info("新增消息通知成功"); return PYMsgNotifyVO.createVO(msgNotify); } else { int result = msgNotifyMapper.updateNotify(msgNotify); if (result == 0) { log.error("更新消息通知异常"); return null; } log.info("更新消息通知成功"); return PYMsgNotifyVO.createVO(msgNotify); } } @Override public PYMsgNotifyVO deleteMsgNotify(int notifyId) { int result = msgNotifyMapper.deleteMsgNotify(notifyId); if (result == 0) { log.warn("删除消息失败了 notifyId:" + notifyId); return null; } PYMsgNotify msgNotify = msgNotifyMapper.selectNotifyWithId(notifyId); log.info("删除消息后查询消息:msgNotify:" + msgNotify); return PYMsgNotifyVO.createVO(msgNotify); } @Override public PYMsgNotifyVO clearMsgNotify(int notifyId) { int result = msgNotifyMapper.clearMsgNotify(notifyId); if (result == 0) { log.warn("清理消息失败了 notifyId:" + notifyId); return null; } PYMsgNotify msgNotify = msgNotifyMapper.selectNotifyWithId(notifyId); log.info("清理消息后查询消息:msgNotify:" + msgNotify); return PYMsgNotifyVO.createVO(msgNotify); } @Override public List selectMsgNotifys(int userId, long time) { List msgNotifies = msgNotifyMapper.selectNotifys(userId, time); if (msgNotifies != null) { List vos = new ArrayList<>(); for (PYMsgNotify msgNotify : msgNotifies) { PYMsgNotifyVO vo = PYMsgNotifyVO.createVO(msgNotify); vos.add(vo); } return vos; } return null; } @Override public int clearAllMsgNotify(int userId) { return msgNotifyMapper.clearAllMsgNotify(userId); } }