|
@@ -1,28 +1,12 @@
|
|
|
package com.xy.job;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.xxl.job.core.biz.model.ReturnT;
|
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
-import com.xy.collections.list.JArrayList;
|
|
|
-import com.xy.collections.map.JMap;
|
|
|
-import com.xy.device.EnumDeviceCharging;
|
|
|
-import com.xy.dto.DeviceInfoDto;
|
|
|
-import com.xy.entity.DeviceCharging;
|
|
|
-import com.xy.entity.SysDictRedis;
|
|
|
import com.xy.mapper.DeviceChargingMapper;
|
|
|
-import com.xy.service.DeviceChargingServiceImpl;
|
|
|
-import com.xy.service.DeviceInfoServiceImpl;
|
|
|
-import com.xy.utils.*;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
/**
|
|
|
* 设备计费job
|
|
|
*/
|
|
@@ -31,14 +15,10 @@ import java.util.Map;
|
|
|
@AllArgsConstructor
|
|
|
public class DeviceChargingJob {
|
|
|
|
|
|
- private DeviceChargingServiceImpl deviceChargingService;
|
|
|
-
|
|
|
- private DeviceInfoServiceImpl deviceInfoService;
|
|
|
-
|
|
|
private DeviceChargingMapper deviceChargingMapper;
|
|
|
|
|
|
/**
|
|
|
- * 扣除设备服务费试用天数
|
|
|
+ * 扣除设备管理费剩余天数
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
@@ -48,73 +28,4 @@ public class DeviceChargingJob {
|
|
|
log.info("设备试用时间扣除完成~");
|
|
|
return ReturnT.SUCCESS;
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 设备计费
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- @XxlJob("deviceCharging")
|
|
|
- public ReturnT<String> deviceCharging() {
|
|
|
- deviceCharging(1, 50, LocalDateTime.now());
|
|
|
- log.info("设备计费完成~");
|
|
|
- return ReturnT.SUCCESS;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 递归执行
|
|
|
- *
|
|
|
- * @param current
|
|
|
- * @param size
|
|
|
- * @param thisDateTime
|
|
|
- */
|
|
|
- public void deviceCharging(int current, int size, LocalDateTime thisDateTime) {
|
|
|
- log.info("设备计费开始第{}页", current);
|
|
|
- List<DeviceCharging> updateDeviceChargings = new ArrayList<>();
|
|
|
- List<DeviceInfoDto.Update> updateDeviceInfos = new ArrayList<>();
|
|
|
- //查询已过期计费记录
|
|
|
- IPage<DeviceCharging> iPage = deviceChargingService.page(PlusBeans.toIPage(new PageBean().setCurrent(current).setSize(size)), new LambdaQueryWrapper<DeviceCharging>()
|
|
|
- .le(DeviceCharging::getTimeout, thisDateTime)
|
|
|
- .eq(DeviceCharging::getIsJob, true)
|
|
|
- .le(DeviceCharging::getChargingX, 0)
|
|
|
- );
|
|
|
- List<DeviceCharging> records = iPage.getRecords();
|
|
|
- if (!Emptys.check(records)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- JMap<Long, DeviceCharging> deviceChargingsJMaps = new JArrayList<>(records).toMap(DeviceCharging::getDeviceId).cover();
|
|
|
- //字典
|
|
|
- Map<String, SysDictRedis> stringSysDictRedisMap = SysDictUtils.get(EnumDeviceCharging.Code.CODE.getCode());
|
|
|
- SysDictRedis sysDictRedisY = stringSysDictRedisMap.get(EnumDeviceCharging.N_Y.getCode());
|
|
|
- Integer y = Integer.valueOf(sysDictRedisY.getValue());
|
|
|
- //开始计费
|
|
|
- deviceChargingsJMaps.forEach((deviceId, deviceCharging) -> {
|
|
|
- //当前时间 - 过期时间 > y
|
|
|
- long day = DataTime.diff(thisDateTime, deviceCharging.getTimeout(), "d");
|
|
|
- if (day > y) {
|
|
|
- DeviceInfoDto.Update update = new DeviceInfoDto.Update()
|
|
|
- .setDeviceId(deviceId);
|
|
|
- update.setFreezeStatus(2);
|
|
|
- update.setBusyState(2);
|
|
|
- deviceCharging.setIsJob(false);
|
|
|
- updateDeviceChargings.add(deviceCharging);
|
|
|
- //updateDeviceInfos.add(update);
|
|
|
- }
|
|
|
- });
|
|
|
- //修改设备计费记录
|
|
|
- if (Emptys.check(updateDeviceChargings)) {
|
|
|
- deviceChargingService.updateBatchById(updateDeviceChargings);
|
|
|
- }
|
|
|
- //冻结设备
|
|
|
- if (Emptys.check(updateDeviceInfos)) {
|
|
|
- deviceInfoService.updateBatch(updateDeviceInfos);
|
|
|
- }
|
|
|
- //判断是否继续下一页
|
|
|
- if (iPage.getPages() <= current) {
|
|
|
- return;
|
|
|
- } else {
|
|
|
- deviceCharging(current + 1, size, thisDateTime);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
}
|