MercFeeCountMonthJob.java 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package com.xy.job;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.collection.CollUtil;
  4. import cn.hutool.core.date.DatePattern;
  5. import cn.hutool.core.date.DateTime;
  6. import cn.hutool.core.date.DateUtil;
  7. import cn.hutool.core.util.StrUtil;
  8. import com.xxl.job.core.biz.model.ReturnT;
  9. import com.xxl.job.core.handler.annotation.XxlJob;
  10. import com.xy.annotate.RestMappingController;
  11. import com.xy.dto.MercFeeCountDayDto;
  12. import com.xy.dto.MercFeeCountMonthDto;
  13. import com.xy.entity.MercFeeCountMonth;
  14. import com.xy.error.CommRuntimeException;
  15. import com.xy.service.MercFeeCountDayServiceImpl;
  16. import com.xy.service.MercFeeCountMonthServiceImpl;
  17. import com.xy.utils.R;
  18. import io.swagger.annotations.Api;
  19. import io.swagger.annotations.ApiOperation;
  20. import lombok.RequiredArgsConstructor;
  21. import lombok.extern.slf4j.Slf4j;
  22. import org.springframework.stereotype.Component;
  23. import org.springframework.validation.annotation.Validated;
  24. import org.springframework.web.bind.annotation.PostMapping;
  25. import org.springframework.web.bind.annotation.RequestBody;
  26. import java.util.List;
  27. /**
  28. * 商户佣金费用收益每月统计任务(不含本月) 每月1号凌晨2点执行
  29. */
  30. @Slf4j
  31. @Component
  32. @RequiredArgsConstructor
  33. @Api(tags = "商户佣金费用收益每月统计任务")
  34. @RestMappingController("job/feeCountMonth")
  35. public class MercFeeCountMonthJob {
  36. private final MercFeeCountDayServiceImpl mercFeeCountDayService;
  37. private final MercFeeCountMonthServiceImpl mercFeeCountMonthService;
  38. @PostMapping("excuteJob")
  39. @ApiOperation("指定日期执行")
  40. public R excuteJob(@RequestBody @Validated MercFeeCountMonthDto.ExcuteDayDTO dto) {
  41. return R.ok(monthJob(dto.getDate()));
  42. }
  43. /**
  44. * 商户佣金费用收益每月统计任务(不含今天)
  45. * 类型 1设备管理费。2设备激活费。3算法扣费标准。4流量卡费
  46. *
  47. * @param date yyyyMM
  48. * @return
  49. */
  50. @XxlJob("mercFeeCountMonthJob")
  51. public ReturnT<String> monthJob(String date) {
  52. //获取上个月
  53. DateTime lastMonth = DateUtil.lastMonth();
  54. String queryDay = DateUtil.format(lastMonth, DatePattern.SIMPLE_MONTH_PATTERN);
  55. if (StrUtil.isNotEmpty(date)) {
  56. queryDay = date;
  57. //指定日期需要判断是否重复执行
  58. MercFeeCountMonthDto.SelectList selectList = new MercFeeCountMonthDto.SelectList();
  59. selectList.setDateValue(Integer.valueOf(DateUtil.format(lastMonth, DatePattern.PURE_DATE_PATTERN)));
  60. List<MercFeeCountMonthDto.Vo> vos = R.feignCheckData(mercFeeCountMonthService.list(selectList));
  61. if (CollUtil.isNotEmpty(vos)) {
  62. throw new CommRuntimeException("已存在日期【" + date + "】的数据,请勿重复执行!");
  63. }
  64. }
  65. //年月
  66. Integer monthValue = Integer.valueOf(queryDay);
  67. // 按商户id,父商户ID,缴费类型 统计指定月份 缴费总和、佣金总和
  68. List<MercFeeCountDayDto.CountByMonthVO> countByMonthVOS = mercFeeCountDayService.countByMonth(new MercFeeCountDayDto.CountByMonth().setMonthValue(monthValue));
  69. if (CollUtil.isNotEmpty(countByMonthVOS)) {
  70. List<MercFeeCountMonth> mercFeeCountMonths = BeanUtil.copyToList(countByMonthVOS, MercFeeCountMonth.class);
  71. mercFeeCountMonths.forEach(mfm -> {
  72. mfm.setDateValue(monthValue);
  73. });
  74. mercFeeCountMonthService.saveBatch(mercFeeCountMonths);
  75. }
  76. return ReturnT.SUCCESS;
  77. }
  78. }