PushMessage.java 27 KB

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