DeviceAlgorithmChargingJob.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package com.xy.job;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.xxl.job.core.biz.model.ReturnT;
  5. import com.xxl.job.core.handler.annotation.XxlJob;
  6. import com.xy.entity.DeviceAlgorithmCharging;
  7. import com.xy.service.DeviceAlgorithmChargingServiceImpl;
  8. import com.xy.utils.DataTime;
  9. import com.xy.utils.Emptys;
  10. import com.xy.utils.PageBean;
  11. import com.xy.utils.PlusBeans;
  12. import lombok.AllArgsConstructor;
  13. import lombok.extern.slf4j.Slf4j;
  14. import org.springframework.stereotype.Component;
  15. import java.util.List;
  16. /**
  17. * 设备算法计费job
  18. */
  19. @Slf4j
  20. @Component
  21. @AllArgsConstructor
  22. public class DeviceAlgorithmChargingJob {
  23. private DeviceAlgorithmChargingServiceImpl deviceAlgorithmChargingService;
  24. /**
  25. * 扣除设备算法计费过期时间
  26. *
  27. * @return
  28. */
  29. @XxlJob("deviceAlgorithmChargingTimeout")
  30. public ReturnT<String> deviceAlgorithmChargingTimeout() {
  31. deviceAlgorithmCharging(1, 50, Integer.valueOf(DataTime.getSring("yyyyMM")));
  32. return ReturnT.SUCCESS;
  33. }
  34. public void deviceAlgorithmCharging(int current, int size, Integer beginTime) {
  35. log.info("扣除设备算法计费过期时间开始第{}页", current);
  36. LambdaQueryWrapper<DeviceAlgorithmCharging> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceAlgorithmCharging>()
  37. .gt(DeviceAlgorithmCharging::getTimeout, 0)
  38. .le(DeviceAlgorithmCharging::getBeginTime, beginTime);
  39. IPage<DeviceAlgorithmCharging> iPage = deviceAlgorithmChargingService.page(PlusBeans.toIPage(new PageBean().setCurrent(current).setSize(size)), lambdaQueryWrapper);
  40. List<DeviceAlgorithmCharging> records = iPage.getRecords();
  41. if (!Emptys.check(records)) {
  42. return;
  43. }
  44. records.forEach(deviceAlgorithmCharging -> deviceAlgorithmCharging.setTimeout(deviceAlgorithmCharging.getTimeout() - 1));
  45. deviceAlgorithmChargingService.updateBatchById(records);
  46. //判断是否继续下一页
  47. if (iPage.getPages() <= current) {
  48. return;
  49. } else {
  50. deviceAlgorithmCharging(current + 1, size, beginTime);
  51. }
  52. }
  53. }