DeviceSimJob.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package com.xy.job;
  2. import com.baomidou.mybatisplus.core.metadata.IPage;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.xxl.job.core.biz.model.ReturnT;
  5. import com.xxl.job.core.handler.annotation.XxlJob;
  6. import com.xy.collections.map.JHashMap;
  7. import com.xy.collections.map.JMap;
  8. import com.xy.device.EnumDeviceCharging;
  9. import com.xy.dto.MercMsgInfoDto;
  10. import com.xy.entity.SysDictRedis;
  11. import com.xy.mapper.DeviceSimMapper;
  12. import com.xy.service.MercMsgInfoService;
  13. import com.xy.sys.EnumMercCostMsgConfig;
  14. import com.xy.utils.*;
  15. import lombok.AllArgsConstructor;
  16. import lombok.extern.slf4j.Slf4j;
  17. import org.springframework.stereotype.Component;
  18. import java.util.List;
  19. import java.util.Map;
  20. /**
  21. * 设备流量卡job
  22. */
  23. @Slf4j
  24. @Component
  25. @AllArgsConstructor
  26. public class DeviceSimJob {
  27. private DeviceSimMapper deviceSimMapper;
  28. private MercMsgInfoService mercMsgInfoService;
  29. /**
  30. * 设备流量卡过期消息
  31. *
  32. * @return
  33. */
  34. @XxlJob("deviceSimTimeout")
  35. public ReturnT<String> deviceSimTimeout() {
  36. String now = DataTime.getSring();
  37. Map<String, SysDictRedis> stringSysDictRedisMap = SysDictUtils.get(EnumMercCostMsgConfig.Code.CODE.getCode());
  38. String tel = stringSysDictRedisMap.get(EnumMercCostMsgConfig.CUSTOM_TEL.getCode()).getValue();
  39. String mmiTime = DataTime.getStringAround(0, -1, 0, 0, 0, 0, now);
  40. //即将过期
  41. FunctionUtils.NoParamsNoResult timeout1 = () -> {
  42. int day = SysDictUtils.getValue(EnumDeviceCharging.Code.CODE.getCode(), EnumDeviceCharging.N_200.getCode(), Integer.class);
  43. String end = DataTime.getStringAround(0, 0, day, 0, 0, 0);
  44. JMap<String, Object> map = new JHashMap<String, Object>()
  45. .set("mmiTime", mmiTime)
  46. .set("workType", 1)
  47. .set("begin", now)
  48. .set("end", end);
  49. deviceSimTimeout1(map, 1, 100, tel);
  50. };
  51. //欠费
  52. FunctionUtils.NoParamsNoResult timeout2 = () -> {
  53. int day = Integer.valueOf(stringSysDictRedisMap.get(EnumMercCostMsgConfig.ARREARAGE_DAY.getCode()).getValue());
  54. String time1 = DataTime.getStringAround(0, 0, day, 0, 0, 0, now);
  55. JMap<String, Object> map = new JHashMap<String, Object>()
  56. .set("mmiTime", mmiTime)
  57. .set("workType", 2)
  58. .set("end", now);
  59. deviceSimTimeout2(map, now, time1, 1, 100, tel);
  60. };
  61. timeout1.run();
  62. timeout2.run();
  63. return ReturnT.SUCCESS;
  64. }
  65. /**
  66. * 即将过期
  67. *
  68. * @param map
  69. * @param current
  70. * @param size
  71. * @param tel
  72. */
  73. private void deviceSimTimeout1(JMap<String, Object> map, long current, long size, String tel) {
  74. //查询数据
  75. IPage<Long> longIPage = deviceSimMapper.deviceSimTimeout(Page.of(current, size), map);
  76. List<Long> mercIds = longIPage.getRecords();
  77. if (!Emptys.check(mercIds)) {
  78. return;
  79. }
  80. //发送消息
  81. JMap<String, Object> officialParams = new JHashMap<String, Object>()
  82. .set("content", String.format("尊敬的客户,您有设备流量卡即将到期,为避免设备停机,请及时续费,客服电话%s", tel));
  83. JMap<String, Object> mxrParams = officialParams;
  84. MsgUtils.sendMsg(17L, mercIds)
  85. .official(userInfo -> new MsgUtils.MsgInfo(userInfo.getMpOpenid(), officialParams))
  86. .mxr(userInfo -> new MsgUtils.MsgInfo(String.valueOf(userInfo.getAuthorizeUserId()), mxrParams))
  87. .builder();
  88. //写入记录
  89. mercMsgInfoService.save(new MercMsgInfoDto.Save()
  90. .setMercId(mercIds)
  91. .setType(2)
  92. .setWorkType(1)
  93. );
  94. //下一页
  95. current++;
  96. deviceSimTimeout1(map, current, size, tel);
  97. }
  98. /**
  99. * 已欠费
  100. *
  101. * @param map
  102. * @param thisTime
  103. * @param current
  104. * @param size
  105. * @param tel
  106. */
  107. private void deviceSimTimeout2(JMap<String, Object> map, String thisTime, String time1, long current, long size, String tel) {
  108. //查询数据
  109. IPage<Long> longIPage = deviceSimMapper.deviceSimTimeout(Page.of(current, size), map);
  110. List<Long> mercIds = longIPage.getRecords();
  111. if (!Emptys.check(mercIds)) {
  112. return;
  113. }
  114. //发送消息
  115. JMap<String, Object> officialParams = new JHashMap<String, Object>()
  116. .set("content", String.format("尊敬的客户,截止%s您的%s已欠费,如您在%s前未完成续费,您的设备将停止交易,客服电话%s", thisTime, "设备流量卡", time1, tel));
  117. JMap<String, Object> mxrParams = officialParams;
  118. MsgUtils.sendMsg(17L, mercIds)
  119. .official(userInfo -> new MsgUtils.MsgInfo(userInfo.getMpOpenid(), officialParams))
  120. .mxr(userInfo -> new MsgUtils.MsgInfo(String.valueOf(userInfo.getAuthorizeUserId()), mxrParams))
  121. .builder();
  122. //写入记录
  123. mercMsgInfoService.save(new MercMsgInfoDto.Save()
  124. .setMercId(mercIds)
  125. .setType(2)
  126. .setWorkType(2)
  127. );
  128. //下一页
  129. current++;
  130. deviceSimTimeout2(map, thisTime, time1, current, size, tel);
  131. }
  132. }