JtMessageProducerServiceImpl.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package com.goafanti.message.service.impl;
  2. import java.util.Date;
  3. import java.util.HashMap;
  4. import java.util.Iterator;
  5. import java.util.List;
  6. import java.util.Map;
  7. import java.util.UUID;
  8. import org.apache.commons.lang3.StringUtils;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import com.goafanti.common.dao.JtMessageConsumerMapper;
  12. import com.goafanti.common.dao.JtMessageProducerMapper;
  13. import com.goafanti.common.dao.UserMapper;
  14. import com.goafanti.common.model.JtMessageConsumer;
  15. import com.goafanti.common.model.JtMessageProducer;
  16. import com.goafanti.core.mybatis.BaseMybatisDao;
  17. import com.goafanti.core.mybatis.page.Pagination;
  18. import com.goafanti.core.shiro.token.TokenManager;
  19. import com.goafanti.message.service.JtMessageProducerService;
  20. @Service
  21. public class JtMessageProducerServiceImpl extends BaseMybatisDao<JtMessageProducerMapper> implements JtMessageProducerService{
  22. @Autowired
  23. private JtMessageProducerMapper jtMessageProducerMapper;
  24. @Autowired
  25. private UserMapper userMapper;
  26. @Autowired
  27. private JtMessageConsumerMapper jtMessageConsumerMapper;
  28. @Override
  29. public int addMessage(JtMessageProducer messageProducer) {
  30. //处理消息内容
  31. messageProducer.setId(UUID.randomUUID().toString());
  32. //获得当前登录用户名字
  33. String create = userMapper.selectByPrimaryKey(TokenManager.getUserId()).getUsername();
  34. messageProducer.setCreater(create);
  35. if(null != messageProducer.getCreateTime()){
  36. messageProducer.setCreateTime(new Date());
  37. }
  38. return jtMessageProducerMapper.insertSelective(messageProducer);
  39. }
  40. @Override
  41. public int addSendMessage(String messageId) {
  42. // 获得所有正常使用的注册用户
  43. List<JtMessageConsumer> list = userMapper.getAllUser();
  44. Iterator<JtMessageConsumer> it = list.iterator();
  45. while (it.hasNext()) {
  46. JtMessageConsumer mc = (JtMessageConsumer) it.next();
  47. mc.setId(UUID.randomUUID().toString());
  48. mc.setMessageId(messageId);
  49. }
  50. JtMessageProducer messageProducer = new JtMessageProducer();
  51. messageProducer.setId(messageId);
  52. messageProducer.setSendTime(new Date());
  53. messageProducer.setIsSend(true);
  54. messageProducer.setIsDraft(false);
  55. jtMessageProducerMapper.updateByPrimaryKeySelective(messageProducer);
  56. return jtMessageConsumerMapper.addBatch(list);
  57. }
  58. @Override
  59. public JtMessageProducer getMessageById(String messageId) {
  60. return jtMessageProducerMapper.selectByPrimaryKey(messageId);
  61. }
  62. @Override
  63. public int updateMessageById(JtMessageProducer messageProducer) {
  64. int count = 0;
  65. // 推送消息
  66. if(messageProducer.getIsSend() && !messageProducer.getDeleteSign() && !messageProducer.getIsDraft()){
  67. if(null == messageProducer.getSendTime()) messageProducer.setSendTime(new Date());
  68. count += addSendMessage(messageProducer.getId());
  69. }
  70. // 修改消息
  71. messageProducer.setCreateTime(null);//不修改创建时间
  72. count = jtMessageProducerMapper.updateByPrimaryKeySelective(messageProducer);
  73. return count;
  74. }
  75. @SuppressWarnings("unchecked")
  76. @Override
  77. public Pagination<JtMessageProducer> getMessageList(JtMessageProducer messageProducer, String sendStartTime, String sendEndTime, Integer pageNo,Integer pageSize) {
  78. if(pageNo==null || pageNo<1)pageNo=1;
  79. if(pageSize==null ||pageSize<1)pageSize=10;
  80. Map<String, Object> params=new HashMap<String,Object>();
  81. //params.put("create", TokenManager.getUserId());
  82. if(StringUtils.isNotBlank(messageProducer.getTitle()))params.put("title",messageProducer.getTitle());
  83. if(null != messageProducer.getIsDraft())params.put("isDraft",messageProducer.getIsDraft());
  84. if(null != messageProducer.getIsSend())params.put("isSend",messageProducer.getIsSend());
  85. if(StringUtils.isNotBlank(sendStartTime))params.put("sendStartTime",sendStartTime);
  86. if(StringUtils.isNotBlank(sendEndTime))params.put("sendEndTime",sendEndTime);
  87. return (Pagination<JtMessageProducer>) findPage("getMyMessageList", "getMyMessageCount", params, pageNo, pageSize);
  88. }
  89. }