|
@@ -0,0 +1,120 @@
|
|
|
+package com.ichaoj.ams.task;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.ListUtil;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.ichaoj.ams.entity.AmsAddressAccount;
|
|
|
+import com.ichaoj.ams.response.statistics.DailyCostResponse;
|
|
|
+import com.ichaoj.ams.response.statistics.NotifyTaskResponse;
|
|
|
+import com.ichaoj.ams.service.*;
|
|
|
+import com.ichaoj.web.util.ParamTemplate;
|
|
|
+import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author gavin
|
|
|
+ * @date 2023/6/1
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Slf4j
|
|
|
+public class NotifyTask {
|
|
|
+
|
|
|
+ private final IAmsTradeRecordService tradeService;
|
|
|
+
|
|
|
+ private final IAmsAirdropProjectService projectService;
|
|
|
+
|
|
|
+ private final IAmsAddressAccountService accountService;
|
|
|
+
|
|
|
+ private final IAmsAirdropTaskService taskService;
|
|
|
+
|
|
|
+ private final IAmsExecuteRecordService executeRecordService;
|
|
|
+ private final ParamTemplate paramTemplate;
|
|
|
+
|
|
|
+ @XxlJob("ams_weekly_report")
|
|
|
+ public void statisticsWeeklyReport() {
|
|
|
+ NotifyTaskResponse response = new NotifyTaskResponse();
|
|
|
+
|
|
|
+ LocalDateTime startTime = LocalDateTimeUtil.of(DateUtil.lastWeek());
|
|
|
+ LocalDateTime endTime = LocalDateTime.now();
|
|
|
+
|
|
|
+ // 统计最近的gas和amount日常支出
|
|
|
+ getDailyCost(response, startTime, endTime);
|
|
|
+
|
|
|
+ // 统计总gas和amount支出
|
|
|
+ getDailyCost(response, null, null);
|
|
|
+
|
|
|
+ // 统计最近添加地址数量和精品号数量
|
|
|
+ countAddress(response, startTime, endTime, 0);
|
|
|
+ countAddress(response, null, null, 0);
|
|
|
+ countAddress(response, startTime, endTime, 1);
|
|
|
+ countAddress(response, null, null, 1);
|
|
|
+
|
|
|
+ // 统计项目数量
|
|
|
+// countProject();
|
|
|
+
|
|
|
+
|
|
|
+ String emailStr = paramTemplate.getParamValue("str_ams_data_notify_email");
|
|
|
+ String[] emails = emailStr.split(StrUtil.COMMA);
|
|
|
+ Set<String> emailSet = new HashSet<>();
|
|
|
+ if (emails.length == 1) {
|
|
|
+ emailSet.add(emailStr);
|
|
|
+ } else {
|
|
|
+ emailSet.addAll(ListUtil.of(emails));
|
|
|
+ }
|
|
|
+ for (String email : emailSet) {
|
|
|
+ sendEmail(response, email);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendEmail(NotifyTaskResponse response, String email) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void countAddress(NotifyTaskResponse response, LocalDateTime startTime, LocalDateTime endTime, int addressType) {
|
|
|
+ long count = accountService.count(new LambdaQueryWrapper<AmsAddressAccount>()
|
|
|
+ .eq(AmsAddressAccount::getAddressType, addressType)
|
|
|
+ .ge(startTime != null, AmsAddressAccount::getCreateTime, startTime)
|
|
|
+ .le(endTime != null, AmsAddressAccount::getCreateTime, endTime)
|
|
|
+ );
|
|
|
+ if (startTime == null) {
|
|
|
+ if (addressType == 0) {
|
|
|
+ response.setTotalPremiumCount(count);
|
|
|
+ } else {
|
|
|
+ response.setTotalBatchCount(count);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (addressType == 0) {
|
|
|
+ response.setRecentPremiumCount(count);
|
|
|
+ } else {
|
|
|
+ response.setRecentBatchCount(count);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getDailyCost(NotifyTaskResponse response, LocalDateTime startTime, LocalDateTime endTime) {
|
|
|
+ List<DailyCostResponse> list = tradeService.dailyCostStatistics(startTime, endTime, null);
|
|
|
+ BigDecimal gasCost = BigDecimal.valueOf(list.stream().mapToDouble(d -> d.getGas().doubleValue()).sum());
|
|
|
+ BigDecimal amountCost = BigDecimal.valueOf(list.stream().mapToDouble(d -> d.getPrincipal().doubleValue()).sum());
|
|
|
+ if (startTime == null) {
|
|
|
+ response.setTotalGas(gasCost);
|
|
|
+ response.setTotalGas(amountCost);
|
|
|
+ } else {
|
|
|
+ response.setRecentGas(gasCost);
|
|
|
+ response.setRecentGas(amountCost);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|