DeviceSimJob.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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> miniParams = new JHashMap<String, Object>()
  84. .set("content", "您有设备流量卡即将到期")
  85. .set("phone", tel);
  86. MsgUtils.sendMsg(17L, mercIds)
  87. .official(userInfo -> new MsgUtils.MsgInfo(userInfo.getMpOpenid(), officialParams))
  88. .mini(userInfo -> new MsgUtils.MsgInfo(userInfo.getWechatOpenid(), miniParams))
  89. .builder();
  90. //写入记录
  91. mercMsgInfoService.save(new MercMsgInfoDto.Save()
  92. .setMercId(mercIds)
  93. .setType(2)
  94. .setWorkType(1)
  95. );
  96. //下一页
  97. current++;
  98. deviceSimTimeout1(map, current, size, tel);
  99. }
  100. /**
  101. * 已欠费
  102. *
  103. * @param map
  104. * @param thisTime
  105. * @param current
  106. * @param size
  107. * @param tel
  108. */
  109. private void deviceSimTimeout2(JMap<String, Object> map, String thisTime, String time1, long current, long size, String tel) {
  110. //查询数据
  111. IPage<Long> longIPage = deviceSimMapper.deviceSimTimeout(Page.of(current, size), map);
  112. List<Long> mercIds = longIPage.getRecords();
  113. if (!Emptys.check(mercIds)) {
  114. return;
  115. }
  116. //发送消息
  117. JMap<String, Object> officialParams = new JHashMap<String, Object>()
  118. .set("content", String.format("尊敬的客户,截止%s您的%s已欠费,如您在%s前未完成续费,您的设备将停止交易,客服电话%s", thisTime, "设备流量卡", time1, tel));
  119. JMap<String, Object> miniParams = new JHashMap<String, Object>()
  120. .set("time0", thisTime)
  121. .set("type", "设备流量卡")
  122. .set("time1", time1)
  123. .set("phone", tel);
  124. MsgUtils.sendMsg(17L, mercIds)
  125. .official(userInfo -> new MsgUtils.MsgInfo(userInfo.getMpOpenid(), officialParams))
  126. .mini(userInfo -> new MsgUtils.MsgInfo(userInfo.getWechatOpenid(), miniParams))
  127. .builder();
  128. //写入记录
  129. mercMsgInfoService.save(new MercMsgInfoDto.Save()
  130. .setMercId(mercIds)
  131. .setType(2)
  132. .setWorkType(2)
  133. );
  134. //下一页
  135. current++;
  136. deviceSimTimeout2(map, thisTime, time1, current, size, tel);
  137. }
  138. }