123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- package com.xy.job;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.xxl.job.core.biz.model.ReturnT;
- import com.xxl.job.core.handler.annotation.XxlJob;
- import com.xy.collections.map.JHashMap;
- import com.xy.collections.map.JMap;
- import com.xy.device.EnumDeviceCharging;
- import com.xy.dto.MercMsgInfoDto;
- import com.xy.entity.SysDictRedis;
- import com.xy.mapper.DeviceSimMapper;
- import com.xy.service.MercMsgInfoService;
- import com.xy.sys.EnumMercCostMsgConfig;
- import com.xy.utils.*;
- import lombok.AllArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.stereotype.Component;
- import java.util.List;
- import java.util.Map;
- /**
- * 设备流量卡job
- */
- @Slf4j
- @Component
- @AllArgsConstructor
- public class DeviceSimJob {
- private DeviceSimMapper deviceSimMapper;
- private MercMsgInfoService mercMsgInfoService;
- /**
- * 设备流量卡过期消息
- *
- * @return
- */
- @XxlJob("deviceSimTimeout")
- public ReturnT<String> deviceSimTimeout() {
- String now = DataTime.getSring();
- Map<String, SysDictRedis> stringSysDictRedisMap = SysDictUtils.get(EnumMercCostMsgConfig.Code.CODE.getCode());
- String tel = stringSysDictRedisMap.get(EnumMercCostMsgConfig.CUSTOM_TEL.getCode()).getValue();
- String mmiTime = DataTime.getStringAround(0, -1, 0, 0, 0, 0, now);
- //即将过期
- FunctionUtils.NoParamsNoResult timeout1 = () -> {
- int day = SysDictUtils.getValue(EnumDeviceCharging.Code.CODE.getCode(), EnumDeviceCharging.N_200.getCode(), Integer.class);
- String end = DataTime.getStringAround(0, 0, day, 0, 0, 0);
- JMap<String, Object> map = new JHashMap<String, Object>()
- .set("mmiTime", mmiTime)
- .set("workType", 1)
- .set("begin", now)
- .set("end", end);
- deviceSimTimeout1(map, 1, 100, tel);
- };
- //欠费
- FunctionUtils.NoParamsNoResult timeout2 = () -> {
- int day = Integer.valueOf(stringSysDictRedisMap.get(EnumMercCostMsgConfig.ARREARAGE_DAY.getCode()).getValue());
- String time1 = DataTime.getStringAround(0, 0, day, 0, 0, 0, now);
- JMap<String, Object> map = new JHashMap<String, Object>()
- .set("mmiTime", mmiTime)
- .set("workType", 2)
- .set("end", now);
- deviceSimTimeout2(map, now, time1, 1, 100, tel);
- };
- timeout1.run();
- timeout2.run();
- return ReturnT.SUCCESS;
- }
- /**
- * 即将过期
- *
- * @param map
- * @param current
- * @param size
- * @param tel
- */
- private void deviceSimTimeout1(JMap<String, Object> map, long current, long size, String tel) {
- //查询数据
- IPage<Long> longIPage = deviceSimMapper.deviceSimTimeout(Page.of(current, size), map);
- List<Long> mercIds = longIPage.getRecords();
- if (!Emptys.check(mercIds)) {
- return;
- }
- //发送消息
- JMap<String, Object> officialParams = new JHashMap<String, Object>()
- .set("content", String.format("尊敬的客户,您有设备流量卡即将到期,为避免设备停机,请及时续费,客服电话%s", tel));
- JMap<String, Object> mxrParams = officialParams;
- MsgUtils.sendMsg(17L, mercIds)
- .official(userInfo -> new MsgUtils.MsgInfo(userInfo.getMpOpenid(), officialParams))
- .mxr(userInfo -> new MsgUtils.MsgInfo(String.valueOf(userInfo.getAuthorizeUserId()), mxrParams))
- .builder();
- //写入记录
- mercMsgInfoService.save(new MercMsgInfoDto.Save()
- .setMercId(mercIds)
- .setType(2)
- .setWorkType(1)
- );
- //下一页
- current++;
- deviceSimTimeout1(map, current, size, tel);
- }
- /**
- * 已欠费
- *
- * @param map
- * @param thisTime
- * @param current
- * @param size
- * @param tel
- */
- private void deviceSimTimeout2(JMap<String, Object> map, String thisTime, String time1, long current, long size, String tel) {
- //查询数据
- IPage<Long> longIPage = deviceSimMapper.deviceSimTimeout(Page.of(current, size), map);
- List<Long> mercIds = longIPage.getRecords();
- if (!Emptys.check(mercIds)) {
- return;
- }
- //发送消息
- JMap<String, Object> officialParams = new JHashMap<String, Object>()
- .set("content", String.format("尊敬的客户,截止%s您的%s已欠费,如您在%s前未完成续费,您的设备将停止交易,客服电话%s", thisTime, "设备流量卡", time1, tel));
- JMap<String, Object> mxrParams = officialParams;
- MsgUtils.sendMsg(17L, mercIds)
- .official(userInfo -> new MsgUtils.MsgInfo(userInfo.getMpOpenid(), officialParams))
- .mxr(userInfo -> new MsgUtils.MsgInfo(String.valueOf(userInfo.getAuthorizeUserId()), mxrParams))
- .builder();
- //写入记录
- mercMsgInfoService.save(new MercMsgInfoDto.Save()
- .setMercId(mercIds)
- .setType(2)
- .setWorkType(2)
- );
- //下一页
- current++;
- deviceSimTimeout2(map, thisTime, time1, current, size, tel);
- }
- }
|