SystemController.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package com.ym.controller;
  2. import com.ym.mec.common.entity.ImSystemMessage;
  3. import com.ym.mec.common.entity.ImTxtMessage;
  4. import com.ym.service.MessageService;
  5. import io.rong.messages.TxtMessage;
  6. import io.rong.models.message.BroadcastMessage;
  7. import io.rong.models.message.GroupMessage;
  8. import io.rong.models.message.SystemMessage;
  9. import io.rong.models.message.TemplateMessage;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.web.bind.annotation.RequestBody;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RequestMethod;
  14. import org.springframework.web.bind.annotation.RestController;
  15. import java.lang.reflect.Array;
  16. import java.util.Arrays;
  17. import java.util.List;
  18. import java.util.Set;
  19. import java.util.stream.Collectors;
  20. @RestController
  21. @RequestMapping("/system")
  22. public class SystemController {
  23. @Autowired
  24. MessageService messageService;
  25. @RequestMapping(value = "/send", method = RequestMethod.POST)
  26. public Object send(@RequestBody ImSystemMessage imSystemMessage) throws Exception {
  27. SystemMessage systemMessage = new SystemMessage();
  28. ImTxtMessage content = (ImTxtMessage)imSystemMessage.getContent();
  29. TxtMessage txtMessage = new TxtMessage(content.getContent(),content.getExtra());
  30. systemMessage.setContent(txtMessage);
  31. systemMessage.setSenderId(imSystemMessage.getSenderId());
  32. systemMessage.setObjectName(imSystemMessage.getObjectName());
  33. String[] targetId = imSystemMessage.getTargetId();
  34. long i = Math.round(targetId.length / 100d);
  35. for (int j = 0; j < i; j++) {
  36. List<String> collect = Arrays.stream(targetId).skip(j * 100).limit(100).collect(Collectors.toList());
  37. String[] objects = collect.toArray(new String[100]);
  38. systemMessage.setTargetId(objects);
  39. messageService.systemSend(systemMessage);
  40. }
  41. return null;
  42. }
  43. @RequestMapping(value = "/broadcast", method = RequestMethod.POST)
  44. public Object broadcast(@RequestBody BroadcastMessage broadcastMessage) throws Exception {
  45. return messageService.systemBroadcast(broadcastMessage);
  46. }
  47. @RequestMapping(value = "/sendTemplate", method = RequestMethod.POST)
  48. public Object sendTemplate(@RequestBody TemplateMessage templateMessage) throws Exception {
  49. return messageService.systemSendTemplate(templateMessage);
  50. }
  51. }