PushMessage.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. package cn.com.ty.lift.common.model;
  2. import cn.com.ty.lift.common.utils.ValuePool;
  3. import cn.hutool.core.collection.IterUtil;
  4. import lombok.Data;
  5. import lombok.extern.slf4j.Slf4j;
  6. import org.springframework.jms.core.JmsMessagingTemplate;
  7. import org.springframework.messaging.support.GenericMessage;
  8. import java.io.Serializable;
  9. import java.time.LocalDate;
  10. import java.time.LocalDateTime;
  11. import java.util.*;
  12. /**
  13. * 推送消息
  14. *
  15. * @author wcz
  16. * @since 2020/4/14
  17. */
  18. @Slf4j
  19. @Data
  20. public class PushMessage implements Serializable {
  21. private static final long serialVersionUID = 4125096758372084309L;
  22. private String title;
  23. private String content;
  24. private List<String> toList = new ArrayList<>();
  25. //the count of try again. Increase 1 for each failure, maximum times 100
  26. private int tryCount = 0;
  27. private PushMessage() {
  28. }
  29. private PushMessage(String title, String content) {
  30. this.title = title;
  31. this.content = content;
  32. }
  33. public PushMessage add(String to){
  34. this.toList.add(to);
  35. return this;
  36. }
  37. private static PushMessage create(String title, String content) {
  38. return new PushMessage(title, content);
  39. }
  40. private static PushMessage team(String content) {
  41. return create("团队消息", content);
  42. }
  43. private static PushMessage work(String content) {
  44. return create("工作消息", content);
  45. }
  46. private static PushMessage maintain(String content) {
  47. return create("保养消息", content);
  48. }
  49. private static PushMessage emergency(String content) {
  50. return create("急修消息", content);
  51. }
  52. private static PushMessage manager(String content) {
  53. return create("提醒", content);
  54. }
  55. private static PushMessage inspection(String content) {
  56. return create("年检消息", content);
  57. }
  58. /**
  59. * PC
  60. * 所有文员
  61. * 申请团队
  62. * 【申请人】申请加入【团队名称】。
  63. */
  64. public static PushMessage teamApply(String applyName, String teamName) {
  65. String message = "%s申请加入%s。";
  66. String content = String.format(message, applyName, teamName);
  67. return team(content);
  68. }
  69. /**
  70. * 移动端
  71. * 区域主管、申请人
  72. * 加入团队成功
  73. * 【申请人】已经成功加入【团队名称】。
  74. */
  75. public static PushMessage teamJoin(String applyName, String teamName) {
  76. String message = "%s已经成功加入%s。";
  77. String content = String.format(message, applyName, teamName);
  78. return team(content);
  79. }
  80. /**
  81. * 移动端
  82. * 区域主管、被踢人
  83. * 移出团队
  84. * 【被踢人】已经被移出【团队名称】
  85. */
  86. public static PushMessage teamKickOut(String kickName, String teamName) {
  87. String message = "%s已经被踢出%s。";
  88. String content = String.format(message, kickName, teamName);
  89. return team(content);
  90. }
  91. /**
  92. * PC/移动端
  93. * 区域主管(项目所属)、所有文员
  94. * 物业申请项目
  95. * 物业【申请人】申请【项目名称】【评价/查看】权限。
  96. */
  97. public static PushMessage workApplyPermission(String applyName, String projectName, String permission) {
  98. String message = "物业%s申请%s的%s权限。";
  99. String content = String.format(message, applyName, projectName, permission);
  100. return work(content);
  101. }
  102. /**
  103. * 移动端
  104. * 区域主管(项目所属)
  105. * 物业获得权限
  106. * 物业【申请人】成功获得【项目名称】【评价/查看】权限。
  107. */
  108. public static PushMessage workObtainPermission(String applyName, String projectName, String permission) {
  109. String message = "物业%s成功获得%s的%s权限。";
  110. String content = String.format(message, applyName, projectName, permission);
  111. return work(content);
  112. }
  113. /**
  114. * 移动端
  115. * 区域主管(项目所属)
  116. * 取消物业权限
  117. * 物业【申请人】失去【项目名称】【评价/查看】权限。
  118. */
  119. public static PushMessage workAbolishPermission(String applyName, String projectName, String permission) {
  120. String message = "物业%s失去%s的%s权限。";
  121. String content = String.format(message, applyName, projectName, permission);
  122. return work(content);
  123. }
  124. /**
  125. * PC/移动端
  126. * 超管、区域主管(项目所属)、所有文员(项目所属)
  127. * 新增项目
  128. * 【区域名称】新增【项目名称】项目,共计【台量】台,生效时间【生效时间】,区域主管【区域主管】。
  129. */
  130. public static PushMessage workAddProject(String areaName, String projectName, int num, String startDate, String directorName) {
  131. String message = "%s新增%s项目,共计%s台,生效时间%s,区域主管%s。";
  132. String content = String.format(message, areaName, projectName, num, startDate, directorName);
  133. return work(content);
  134. }
  135. /**
  136. * PC/移动端
  137. * 超管、区域主管(项目所属)、所有文员(项目所属)
  138. * 项目开始生效
  139. * 【区域名称】【项目名称】项目进入服务期。
  140. */
  141. public static PushMessage workStartProject(String areaName, String projectName) {
  142. String message = "%s的%s项目进入服务期。";
  143. String content = String.format(message, areaName, projectName);
  144. return work(content);
  145. }
  146. /**
  147. * PC/移动端
  148. * 超管、区域主管(项目所属)、所有文员(项目所属)
  149. * 项目逾期
  150. * 【区域名称】【项目名称】已经逾期,请尽快办理合同续签或停止服务手续。
  151. */
  152. public static PushMessage workProjectOverdue(String areaName, String projectName) {
  153. String message = "%s的%s已经逾期,请尽快办理合同续签或停止服务手续。";
  154. String content = String.format(message, areaName, projectName);
  155. return work(content);
  156. }
  157. /**
  158. * PC/移动端
  159. * 超管、区域主管(项目所属)、所有文员(项目所属)
  160. * 停止服务
  161. * 【区域名称】【项目名称】已经停止服务,共计【台量】台。
  162. */
  163. public static PushMessage workProjectStopService(String areaName, String projectName, int num) {
  164. String message = "%s的%s已经停止服务,共计%s台。";
  165. String content = String.format(message, areaName, projectName, num);
  166. return work(content);
  167. }
  168. /**
  169. * PC/移动端
  170. * 超管、区域主管(项目所属)、所有文员(项目所属)
  171. * 恢复逾期
  172. * 【区域名称】【项目名称】已经续签完毕。
  173. */
  174. public static PushMessage workProjectRecoverService(String areaName, String projectName) {
  175. String message = "%s的%s已经续签完毕。";
  176. String content = String.format(message, areaName, projectName);
  177. return work(content);
  178. }
  179. /**
  180. * PC/移动端
  181. * 超管、区域主管(项目所属)、所有文员(项目所属)
  182. * 区域更换负责人
  183. * 【区域名称】的负责人,由【原区域主管】变更为【新区域主管】
  184. */
  185. public static PushMessage workReplaceRegionCharger(String areaName, String original, String newer) {
  186. String message = "%s的负责人,由%s变更为%s";
  187. String content = String.format(message, areaName, original, newer);
  188. return work(content);
  189. }
  190. /**
  191. * PC/移动端
  192. * 超管、区域主管(项目所属)、所有文员(项目所属)
  193. * 创建电梯
  194. * 【创建人】为【项目名称】新增电梯位于【电梯位置】,注册代码【注册代码】
  195. */
  196. public static PushMessage workCreateLift(String operator, String projectName, String devicePosition, String registrationCode) {
  197. String message = "%s为%s新增电梯位于%s,注册代码%s";
  198. String content = String.format(message, operator, projectName, devicePosition, registrationCode);
  199. return work(content);
  200. }
  201. /**
  202. * PC/移动端
  203. * 超管、区域主管(项目所属)、所有文员(项目所属)
  204. * 更新电梯信息(除定位、更换负责人)
  205. * 【更新人】更新【项目名称】【电梯位置】的电梯信息,注册代码【注册代码】
  206. */
  207. public static PushMessage workModifyLift(String operator, String projectName, String devicePosition, String registrationCode) {
  208. String message = "%s更新%s的%s的电梯信息,注册代码%s";
  209. String content = String.format(message, operator, projectName, devicePosition, registrationCode);
  210. return work(content);
  211. }
  212. /**
  213. * PC/移动端
  214. * 超管、区域主管(项目所属)、所有文员(项目所属)
  215. * 更新电梯定位
  216. * 【更新人】更新【项目名称】【电梯位置】的电梯定位为【电梯位置新】,注册代码【注册代码】
  217. */
  218. public static PushMessage workModifyLiftPosition(String operator, String projectName, String devicePosition, String newPosition, String registrationCode) {
  219. String message = "%s更新%s的%s的电梯定位为%s,注册代码%s";
  220. String content = String.format(message, operator, projectName, devicePosition, newPosition, registrationCode);
  221. return work(content);
  222. }
  223. /**
  224. * PC/移动端
  225. * 超管、区域主管(项目所属)、所有文员(项目所属)、相关维保工
  226. * 电梯更换主要负责人
  227. * 【区域名称】的【项目名称】的【电梯位置】电梯,【注册代码】,主要负责人由【原负责人】更换为【新负责人】。
  228. */
  229. public static PushMessage workReplaceLiftCharger(String areaName, String projectName, String devicePosition, String registrationCode, String original, String newer) {
  230. String message = "%s的%s的%s电梯,注册代码%s,主要负责人由%s更换为%s。";
  231. String content = String.format(message, areaName, projectName, devicePosition, registrationCode, original, newer);
  232. return work(content);
  233. }
  234. //保养类型 1.半月,2.季度,3.半年,4.全年
  235. private static String getMaintainType(int type) {
  236. switch (type) {
  237. case 1:
  238. return "半月保";
  239. case 2:
  240. return "季度保";
  241. case 3:
  242. return "半年保";
  243. case 4:
  244. return "全年保";
  245. default:
  246. return "未知类型";
  247. }
  248. }
  249. /**
  250. * 移动端
  251. * 区域主管、相关维保工
  252. * 制定保养计划
  253. * 维保计划制定:【区域名称】【项目名称】的【电梯位置】电梯,【注册代码】,保养间隔时间【x】天,下次保养时间【下次保养时间】,保养类型【保养类型】,负责人【电梯负责人】。制定人【操作人】
  254. * 保养类型 1.半月,2.季度,3.半年,4.全年
  255. */
  256. public static PushMessage maintainCreatePlan(String areaName, String projectName, String devicePosition, String registrationCode, int interval, LocalDate planDate, int type, String liftCharge, String operator) {
  257. String message = "维保计划制定:%s%s的%s电梯,%s,保养间隔时间%s天,下次保养时间%tF,保养类型%s,负责人%s。制定人%s";
  258. String content = String.format(message, areaName, projectName, devicePosition, registrationCode, interval, planDate, getMaintainType(type), liftCharge, operator);
  259. return maintain(content);
  260. }
  261. /**
  262. * 移动端
  263. * 区域主管、相关维保工
  264. * 修改保养计划
  265. * 维保计划修改:【区域名称】【项目名称】的【电梯位置】电梯,【注册代码】,保养间隔时间【x】天,下次保养时间【下次保养时间】,保养类型【保养类型】,负责人【电梯负责人】。修改人【操作人】
  266. */
  267. public static PushMessage maintainModifyPlan(String areaName, String projectName, String devicePosition, String registrationCode, int interval, LocalDate planDate, int type, String liftCharge, String operator) {
  268. String message = "维保计划修改:%s%s的%s电梯,%s,保养间隔时间%s天,下次保养时间%tF,保养类型%s,负责人%s。修改人%s";
  269. String content = String.format(message, areaName, projectName, devicePosition, registrationCode, interval, planDate, getMaintainType(type), liftCharge, operator);
  270. return maintain(content);
  271. }
  272. /**
  273. * 移动端
  274. * 相关维保工
  275. * 每天有维保任务
  276. * 您今天有需要保养的电梯【x】台,请查看任务!
  277. */
  278. public static PushMessage maintainHasTaskDaily(int num) {
  279. String message = "您今天有需要保养的电梯%s台,请查看任务!";
  280. String content = String.format(message, num);
  281. return maintain(content);
  282. }
  283. private static String getTrappedDesc(int isTrapped) {
  284. return isTrapped == 1 ? "已" : "未";
  285. }
  286. /**
  287. * 移动端
  288. * 总经理、区域主管(项目所属)、相关维保工
  289. * 急修指派
  290. * 【区域名称】的【项目名称】的【电梯位置】电梯,注册代码【注册代码】,于【报修时间】接到召修信息,【已/未】困人,请【被派单人】立即响应。
  291. */
  292. public static PushMessage emergencyAssign(String areaName, String projectName, String devicePosition, String registrationCode, LocalDateTime callerDate, int isTrapped, String callerFaultDescription, String workerName) {
  293. String message = "%s的%s的%s电梯,注册代码%s,于%tF %tT接到召修信息,%s困人,召修描述:%s,请%s立即响应。";
  294. String content = String.format(message, areaName, projectName, devicePosition, registrationCode, callerDate, callerDate, getTrappedDesc(isTrapped), callerFaultDescription, workerName);
  295. return emergency(content);
  296. }
  297. /**
  298. * PC/移动端
  299. * 总经理、区域主管(项目所属)、所有文员(项目所属)、相关维保工
  300. * 物业发起急修
  301. * 【区域名称】的【项目名称】的【电梯位置】电梯,注册代码【注册代码】,物业端于【报修时间】发出召修信息,【已/未】困人,请【电梯主要负责人】立即响应。
  302. */
  303. public static PushMessage emergencyAssignByProperty(String areaName, String projectName, String devicePosition, String registrationCode, LocalDateTime callerDate, int isTrapped, String callerFaultDescription, String workerName) {
  304. String message = "%s的%s的%s电梯,注册代码%s,物业端于%tF %tT发出召修信息,%s困人,召修描述:%s,请%s立即响应。";
  305. String content = String.format(message, areaName, projectName, devicePosition, registrationCode, callerDate, callerDate, getTrappedDesc(isTrapped), callerFaultDescription, workerName);
  306. return emergency(content);
  307. }
  308. /**
  309. * 移动端
  310. * 总经理、区域主管(项目所属)、相关维保工
  311. * 转派
  312. * 【区域名称】的【项目名称】的【电梯位置】电梯,注册代码【注册代码】,物业端于【报修时间】发出召修信息,【已/未】困人,请【被派单人】立即响应。
  313. * 【原被派单人】:【区域名称】的【项目名称】的【电梯位置】电梯,注册代码【注册代码】,急修信息已经转派给【被派单人】。
  314. */
  315. public static PushMessage emergencyTransfer(String areaName, String projectName, String devicePosition, String registrationCode, LocalDateTime callerDate, int isTrapped, String callerFaultDescription, String workerName) {
  316. String message = "%s的%s的%s电梯,注册代码%s,物业端于%tF %tT发出召修信息,%s困人,召修描述:%s,请%s立即响应。";
  317. String content = String.format(message, areaName, projectName, devicePosition, registrationCode, callerDate, callerDate, getTrappedDesc(isTrapped), callerFaultDescription, workerName);
  318. return emergency(content);
  319. }
  320. /**
  321. * 移动端
  322. * 【原被派单人】收到消息:【区域名称】的【项目名称】的【电梯位置】电梯,注册代码【注册代码】,急修信息已经转派给【被派单人】。
  323. */
  324. public static PushMessage emergencyTransferForOriginal(String areaName, String projectName, String devicePosition, String registrationCode, String workerName) {
  325. String message = "%s的%s的%s电梯,注册代码%s,急修信息已经转派给%s。";
  326. String content = String.format(message, areaName, projectName, devicePosition, registrationCode, workerName);
  327. return emergency(content);
  328. }
  329. /**
  330. * PC/移动端
  331. * 总经理、区域主管(项目所属)、所有文员(项目所属)
  332. * 维保工接收急修通知
  333. * 【区域名称】的【项目名称】的【电梯位置】电梯,注册代码【注册代码】,于【报修时间】接到召修信息,维保工已确认。
  334. */
  335. public static PushMessage emergencyTaking(String areaName, String projectName, String devicePosition, String registrationCode, LocalDateTime callerDate) {
  336. String message = "%s的%s的%s电梯,注册代码%s,于%tF %tT接到召修信息,维保工已接收通知。";
  337. String content = String.format(message, areaName, projectName, devicePosition, registrationCode, callerDate, callerDate);
  338. return emergency(content);
  339. }
  340. /**
  341. * PC/移动端
  342. * 总经理、区域主管(项目所属)、所有文员(项目所属)
  343. * 维保工到达现场
  344. * 【区域名称】的【项目名称】的【电梯位置】电梯,注册代码【注册代码】,于【报修时间】接到召修信息,维保工已于【到达时间】到达现场。
  345. */
  346. public static PushMessage emergencyArrive(String areaName, String projectName, String devicePosition, String registrationCode, LocalDateTime callerDate, LocalDateTime arriveTime) {
  347. String message = "%s的%s的%s电梯,注册代码%s,于%tF %tT接到召修信息,维保工已于%tF %tT到达现场。";
  348. String content = String.format(message, areaName, projectName, devicePosition, registrationCode, callerDate, callerDate, arriveTime, arriveTime);
  349. return emergency(content);
  350. }
  351. /**
  352. * PC/移动端
  353. * 总经理、区域主管(项目所属)、所有文员(项目所属)
  354. * 维保工提交急修单
  355. * 【区域名称】的【项目名称】的【电梯位置】电梯,注册代码【注册代码】,于【报修时间】接到召修信息,电梯已于【恢复时间】恢复正常。
  356. */
  357. public static PushMessage emergencyOrder(String areaName, String projectName, String devicePosition, String registrationCode, LocalDateTime callerDate, LocalDateTime recoveryDate) {
  358. String message = "%s的%s的%s电梯,注册代码%s,于%tF %tT接到召修信息,电梯已于%tF %tT恢复正常。";
  359. String content = String.format(message, areaName, projectName, devicePosition, registrationCode, callerDate, callerDate, recoveryDate, recoveryDate);
  360. return emergency(content);
  361. }
  362. /**
  363. * PC/移动端
  364. * 所有人
  365. * 公司发送公告
  366. * 有一条公司公告,请查收
  367. */
  368. public static PushMessage announcementNotice() {
  369. return create("公司公告", "有一条公司公告,请查收");
  370. }
  371. /**
  372. * PC
  373. * 所有文员
  374. * 早上8点
  375. * 即时提醒:今天计划有X台电梯需保养,X台电梯正在维修中。
  376. */
  377. public static PushMessage managerMaintainDaily(int maintain, int repair) {
  378. String message = "即时提醒:今天计划有%s台电梯需保养,%s台电梯正在维修中。";
  379. String content = String.format(message, maintain, repair);
  380. return manager(content);
  381. }
  382. /**
  383. * 移动端
  384. * 区域主管(项目所属)
  385. * 下午4点
  386. * 即时提醒:【区域名称】今天共发生急修X次,已维修完毕X次,X次仍在处理中;X台电梯计划保养未完成。
  387. */
  388. public static PushMessage managerTaskForRegionChargerDaily(String areaName, int total, int finish, int doings, int todos) {
  389. String message = "即时提醒:%s今天共发生急修%s次,已维修完毕%s次,%s次仍在处理中;%s台电梯计划保养未完成。";
  390. String content = String.format(message, areaName, total, finish, doings, todos);
  391. return manager(content);
  392. }
  393. /**
  394. * 移动端
  395. * 总经理
  396. * 下午4点
  397. * 即时提醒:今天共发生急修X次,已维修完毕X次,X次仍在处理中;X台电梯计划保养未完成。
  398. */
  399. public static PushMessage managerTaskForLeaderDaily(int total, int finish, int doings, int todos) {
  400. String message = "即时提醒:今天共发生急修%s次,已维修完毕%s次,%s次仍在处理中;%s台电梯计划保养未完成。";
  401. String content = String.format(message, total, finish, doings, todos);
  402. return manager(content);
  403. }
  404. /**
  405. * 移动端
  406. * 总经理,区域主管(项目所属)
  407. * 晚上8点
  408. * 日报:截止目前,今天应保养X台,已完成X台,X台即将超期;今天共发起急修X起,已处理完成X起,X起正在处理中。
  409. */
  410. public static PushMessage managerReportDaily(int needs, int finish, int overdue, int totalRepair, int finishRepair, int doingRepair) {
  411. String message = "日报:截止目前,今天应保养%s台,已完成%s台,%s台即将超期;今天共发起急修%s起,已处理完成%s起,%s起正在处理中。";
  412. String content = String.format(message, needs, finish, overdue, totalRepair, finishRepair, doingRepair);
  413. return manager(content);
  414. }
  415. /**
  416. * PC/移动端
  417. * 区域主管(项目所属),文员(所属文员),电梯主要负责人
  418. * 年检到期前45天
  419. * 【项目名称】的【电梯位置】电梯,注册代码【注册代码】,将于45日后年检到期。
  420. */
  421. public static PushMessage inspectionAdvance45daysNotice(String projectName, String devicePosition, String registrationCode) {
  422. String message = "%s的%s电梯,注册代码%s,将于45日后年检到期。";
  423. String content = String.format(message, projectName, devicePosition, registrationCode);
  424. return inspection(content);
  425. }
  426. /**
  427. * PC/移动端
  428. * 区域主管(项目所属),文员(所属文员),电梯主要负责人
  429. * 年检到期前15天
  430. * 【项目名称】的【电梯位置】电梯,注册代码【注册代码】,仍未启动年检,将于15日后年检到期。
  431. */
  432. public static PushMessage inspectionAdvance15daysNotice(String projectName, String devicePosition, String registrationCode) {
  433. String message = "%s的%s电梯,注册代码%s,仍未启动年检,将于15日后年检到期。";
  434. String content = String.format(message, projectName, devicePosition, registrationCode);
  435. return inspection(content);
  436. }
  437. /**
  438. * PC/移动端
  439. * 区域主管(项目所属),电梯负责人
  440. * 确认现场检验时间
  441. * 【项目名称】的【电梯位置】电梯,注册代码【注册代码】,已确认现场检验时间为【现场检验时间】。
  442. */
  443. public static PushMessage inspectionConfirmCheckDate(String projectName, String devicePosition, String registrationCode, LocalDate checkDate) {
  444. String message = "%s的%s电梯,注册代码%s,已确认现场检验时间为%tF。";
  445. String content = String.format(message, projectName, devicePosition, registrationCode, checkDate);
  446. return inspection(content);
  447. }
  448. /**
  449. * 移动端
  450. * 所有人
  451. * 【新闻标题】
  452. */
  453. public static PushMessage newsNotice(String title) {
  454. return create("发布新闻", title);
  455. }
  456. /**
  457. * 检查推送列表总数是否需要拆分,信鸽推送一次最多1000
  458. */
  459. public boolean needSplit() {
  460. return Objects.nonNull(toList) && toList.size() > ValuePool.PUSH_MAX_SIZE;
  461. }
  462. /**
  463. * 拆分推送设备列表
  464. */
  465. public List<ArrayList<String>> doSplit(final int length) {
  466. List<ArrayList<String>> splits = new ArrayList<>();
  467. int size = toList.size();
  468. log.info("the size of toList is {}, need to split.", size);
  469. //0 1000 2000
  470. for (int i = 0; i < size; i += length) {
  471. if (i + length > size) {
  472. splits.add(new ArrayList<>(toList.subList(i, size)));
  473. } else {
  474. splits.add(new ArrayList<>(toList.subList(i, i + length)));
  475. }
  476. }
  477. log.info("the size of splits : {}", splits.size());
  478. return splits;
  479. }
  480. /**
  481. * 同时推送到多个设备token
  482. */
  483. public boolean sendTokenOnPlatform(JmsMessagingTemplate jmsMessagingTemplate, List<PushUserInfo> pushUserInfos) {
  484. try {
  485. if(IterUtil.isEmpty(pushUserInfos)){
  486. return false;
  487. }
  488. Set<String> toAndroid = new HashSet<>();
  489. Set<String> toIos = new HashSet<>();
  490. for (PushUserInfo pushUserInfo : pushUserInfos) {
  491. if (pushUserInfo.available()) {
  492. if (pushUserInfo.isAndroid()) {
  493. toAndroid.add(pushUserInfo.getDeviceFlag());
  494. } else if (pushUserInfo.isIos()) {
  495. toIos.add(pushUserInfo.getDeviceFlag());
  496. }
  497. }
  498. }
  499. if (IterUtil.isNotEmpty(toAndroid)) {
  500. this.setToList(new ArrayList<>(toAndroid));
  501. jmsMessagingTemplate.send(ValuePool.PUSH_QUEUE_ANDROID_TOKEN, new GenericMessage<>(this));
  502. } else if (IterUtil.isNotEmpty(toIos)) {
  503. this.setToList(new ArrayList<>(toIos));
  504. jmsMessagingTemplate.send(ValuePool.PUSH_QUEUE_IOS_TOKEN, new GenericMessage<>(this));
  505. } else {
  506. return false;
  507. }
  508. return true;
  509. } catch (Exception e) {
  510. log.error("Failed to Send pushMessage to ANDROID & IOS TOKEN Message Queue: ", e);
  511. return false;
  512. }
  513. }
  514. /**
  515. * 推送到单个设备
  516. */
  517. public boolean sendTokenOnPlatform(JmsMessagingTemplate jmsMessagingTemplate, PushUserInfo pushUserInfo) {
  518. try {
  519. if (Objects.isNull(pushUserInfo)) {
  520. return false;
  521. }
  522. if(!pushUserInfo.available()){
  523. return false;
  524. }
  525. this.add(pushUserInfo.getDeviceFlag());
  526. if (pushUserInfo.isAndroid()) {
  527. jmsMessagingTemplate.send(ValuePool.PUSH_QUEUE_ANDROID_TOKEN, new GenericMessage<>(this));
  528. } else if (pushUserInfo.isIos()) {
  529. jmsMessagingTemplate.send(ValuePool.PUSH_QUEUE_IOS_TOKEN, new GenericMessage<>(this));
  530. } else {
  531. return false;
  532. }
  533. return true;
  534. } catch (Exception e) {
  535. log.error("Failed to Send pushMessage to ANDROID & IOS TOKEN Message Queue: ", e);
  536. return false;
  537. }
  538. }
  539. /**
  540. * 同时推送android和ios全平台
  541. */
  542. public boolean sendAllOnPlatform(JmsMessagingTemplate jmsMessagingTemplate) {
  543. try {
  544. jmsMessagingTemplate.send(ValuePool.PUSH_QUEUE_ANDROID_ALL, new GenericMessage<>(this));
  545. jmsMessagingTemplate.send(ValuePool.PUSH_QUEUE_IOS_ALL, new GenericMessage<>(this));
  546. return true;
  547. } catch (Exception e) {
  548. log.error("Failed to Send pushMessage to ANDROID & IOS ALL Message Queue: ", e);
  549. return false;
  550. }
  551. }
  552. }