PushMessage.java 28 KB

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