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 deviceSimTimeout() { String now = DataTime.getSring(); Map 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 map = new JHashMap() .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 map = new JHashMap() .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 map, long current, long size, String tel) { //查询数据 IPage longIPage = deviceSimMapper.deviceSimTimeout(Page.of(current, size), map); List mercIds = longIPage.getRecords(); if (!Emptys.check(mercIds)) { return; } //发送消息 JMap officialParams = new JHashMap() .set("content", String.format("尊敬的客户,您有设备流量卡即将到期,为避免设备停机,请及时续费,客服电话%s", tel)); JMap miniParams = new JHashMap() .set("content", "您有设备流量卡即将到期") .set("phone", tel); MsgUtils.sendMsg(17L, mercIds) .official(userInfo -> new MsgUtils.MsgInfo(userInfo.getMpOpenid(), officialParams)) .mini(userInfo -> new MsgUtils.MsgInfo(userInfo.getWechatOpenid(), miniParams)) .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 map, String thisTime, String time1, long current, long size, String tel) { //查询数据 IPage longIPage = deviceSimMapper.deviceSimTimeout(Page.of(current, size), map); List mercIds = longIPage.getRecords(); if (!Emptys.check(mercIds)) { return; } //发送消息 JMap officialParams = new JHashMap() .set("content", String.format("尊敬的客户,截止%s您的%s已欠费,如您在%s前未完成续费,您的设备将停止交易,客服电话%s", thisTime, "设备流量卡", time1, tel)); JMap miniParams = new JHashMap() .set("time0", thisTime) .set("type", "设备流量卡") .set("time1", time1) .set("phone", tel); MsgUtils.sendMsg(17L, mercIds) .official(userInfo -> new MsgUtils.MsgInfo(userInfo.getMpOpenid(), officialParams)) .mini(userInfo -> new MsgUtils.MsgInfo(userInfo.getWechatOpenid(), miniParams)) .builder(); //写入记录 mercMsgInfoService.save(new MercMsgInfoDto.Save() .setMercId(mercIds) .setType(2) .setWorkType(2) ); //下一页 current++; deviceSimTimeout2(map, thisTime, time1, current, size, tel); } }