|
@@ -1,22 +1,28 @@
|
|
|
package com.ichaoj.ams.controller;
|
|
|
|
|
|
-import com.ichaoj.ams.service.IAmsAddressAccountService;
|
|
|
-import com.ichaoj.ams.service.IAmsTradeRecordService;
|
|
|
+import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.ichaoj.ams.entity.AmsAirdropTask;
|
|
|
+import com.ichaoj.ams.entity.AmsExecuteRecord;
|
|
|
+import com.ichaoj.ams.entity.AmsTradeRecord;
|
|
|
+import com.ichaoj.ams.request.count.DailyCostRequest;
|
|
|
+import com.ichaoj.ams.response.address.CountAddressResponse;
|
|
|
+import com.ichaoj.ams.response.count.DailyCostResponse;
|
|
|
+import com.ichaoj.ams.response.count.PredictCostResponse;
|
|
|
+import com.ichaoj.ams.response.task.TaskProgressResponse;
|
|
|
+import com.ichaoj.ams.service.*;
|
|
|
import com.ichaoj.common.annotation.AuthResource;
|
|
|
import com.ichaoj.common.model.PublicResult;
|
|
|
import com.ichaoj.common.model.PublicUserInfo;
|
|
|
import com.ichaoj.web.context.SuperWhaleContext;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author : cjwen
|
|
@@ -30,35 +36,118 @@ public class StatisticsController {
|
|
|
|
|
|
@Resource
|
|
|
private IAmsTradeRecordService tradeService;
|
|
|
+ @Resource
|
|
|
+ private IAmsAirdropProjectService projectService;
|
|
|
|
|
|
@Resource
|
|
|
private IAmsAddressAccountService accountService;
|
|
|
+ @Resource
|
|
|
+ private IAmsAirdropTaskService taskService;
|
|
|
+ @Resource
|
|
|
+ private IAmsExecuteRecordService executeRecordService;
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping("address-group")
|
|
|
+ @Operation(summary = "地址统计")
|
|
|
+ @AuthResource
|
|
|
+ private PublicResult<List<CountAddressResponse>> getGroupAndWalletNum() {
|
|
|
+ List<String> list = accountService.queryGroupList(0);
|
|
|
+ List<CountAddressResponse> responseList = new ArrayList<>();
|
|
|
+ CountAddressResponse preCount = new CountAddressResponse();
|
|
|
+ preCount.setGroupName("精品号");
|
|
|
+ preCount.setAddressCount(list.size());
|
|
|
+ responseList.add(0, preCount);
|
|
|
+ String userId = SuperWhaleContext.getContext(PublicUserInfo.class).getUserId();
|
|
|
+ List<CountAddressResponse> batchList = accountService.countBatchCount(userId);
|
|
|
+ responseList.addAll(batchList);
|
|
|
+ return PublicResult.success(responseList);
|
|
|
+ }
|
|
|
|
|
|
@GetMapping("daily-cost")
|
|
|
@Operation(summary = "每日消耗gas和本金")
|
|
|
@AuthResource
|
|
|
- public PublicResult<Map<String, Object>> dailyCostStatistics() {
|
|
|
- Map<String, Object> map = new HashMap<>(5);
|
|
|
- String userId = SuperWhaleContext.getContext(PublicUserInfo.class).getUserId();
|
|
|
- List<String> batchAddresses = accountService.queryGroupList(1);
|
|
|
+ public PublicResult<List<DailyCostResponse>> dailyCostStatistics() {
|
|
|
+ List<DailyCostResponse> list = tradeService.dailyCostStatistics();
|
|
|
+ return PublicResult.success(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("predict-cost")
|
|
|
+ @Operation(summary = "统计预计投入")
|
|
|
+ @AuthResource
|
|
|
+ public PublicResult<PredictCostResponse> predictCostStatistics() {
|
|
|
+ PredictCostResponse response = projectService.predictCostStatistics();
|
|
|
+ return PublicResult.success(response);
|
|
|
+ }
|
|
|
|
|
|
+ @GetMapping("count-fee")
|
|
|
+ @Operation(summary = "费用统计")
|
|
|
+ @AuthResource
|
|
|
+ public PublicResult<Map<String, Object>> feeCostStatistics() {
|
|
|
+ Map<String, Object> map = new HashMap<>(5);
|
|
|
+ List<String> batchAddresses = accountService.queryBatchAddress(1);
|
|
|
// 从链上获取当日gas费用
|
|
|
- BigDecimal dailyGasCost = getDailyGasCost(userId);
|
|
|
+ BigDecimal dailyGasCost = getGasCost(batchAddresses);
|
|
|
+ map.put("expendGas", dailyGasCost);
|
|
|
// 从链上获取当日本金消耗量
|
|
|
-// BigDecimal dailyPrincipalCost = getDailyPrincipalCost(userId);
|
|
|
- // 总消耗 = gas费用 + 本金消耗
|
|
|
-// BigDecimal totalCost = dailyGasCost.add(dailyPrincipalCost);
|
|
|
+ BigDecimal dailyPrincipalCost = getPrincipalCost(batchAddresses);
|
|
|
+ // 本金余额
|
|
|
+ map.put("principalBalance", dailyPrincipalCost);
|
|
|
+
|
|
|
+ map.put("predictTotalCost", projectService.list().stream().mapToDouble(p -> Double.parseDouble(p.getEstimatedCost())).sum());
|
|
|
return PublicResult.success(map);
|
|
|
}
|
|
|
|
|
|
- private void getGroupAndWalletNum(Map<String, Object> map) {
|
|
|
- List<String> list = accountService.queryGroupList(0);
|
|
|
- map.put("premiumCount", list.size());
|
|
|
+ @GetMapping("task-progress")
|
|
|
+ @Operation(summary = "统计任务进度")
|
|
|
+ @AuthResource
|
|
|
+ public PublicResult<List<TaskProgressResponse>> countTaskProgress() {
|
|
|
+ List<TaskProgressResponse> responseList = new ArrayList<>();
|
|
|
+ List<AmsAirdropTask> list = taskService.list();
|
|
|
+ for (AmsAirdropTask task : list) {
|
|
|
+ TaskProgressResponse response = new TaskProgressResponse();
|
|
|
+ Integer planTimes = task.getPlanTimes();
|
|
|
+ response.setTotalCount(planTimes);
|
|
|
+ long count = executeRecordService.count(
|
|
|
+ new LambdaQueryWrapper<AmsExecuteRecord>()
|
|
|
+ .eq(AmsExecuteRecord::getTaskId, task.getAmsTaskId())
|
|
|
+ .eq(AmsExecuteRecord::getExecuteStatus, 1)
|
|
|
+ );
|
|
|
+ response.setFinishCount((int) count);
|
|
|
+ response.setTaskName(task.getTaskName());
|
|
|
+ responseList.add(response);
|
|
|
+ }
|
|
|
+ return PublicResult.success(responseList);
|
|
|
+ }
|
|
|
+
|
|
|
+ private BigDecimal getPrincipalCost(List<String> batchAddresses) {
|
|
|
+ List<AmsTradeRecord> list = getTradeRecordList(batchAddresses);
|
|
|
+ double sumAmount = list.stream().mapToDouble(t -> Double.parseDouble(t.getCurrentBalance())).sum();
|
|
|
+ return BigDecimal.valueOf(sumAmount);
|
|
|
+ }
|
|
|
+
|
|
|
+ private BigDecimal getGasCost(List<String> batchAddresses) {
|
|
|
+ List<AmsTradeRecord> list = getTradeRecordList(batchAddresses);
|
|
|
+ double sumGas = list.stream().mapToDouble(t -> Double.parseDouble(t.getGas())).sum();
|
|
|
+ return BigDecimal.valueOf(sumGas);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
+ private List<AmsTradeRecord> getTradeRecordList(List<String> batchAddresses) {
|
|
|
+ return tradeService.list(new LambdaQueryWrapper<AmsTradeRecord>()
|
|
|
+ .in(AmsTradeRecord::getAddress, batchAddresses)
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
- private BigDecimal getDailyGasCost(String userId) {
|
|
|
- return BigDecimal.ZERO;
|
|
|
+ private static LocalDateTime getTodayStartTime() {
|
|
|
+ // 获取Calendar实例
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ // 获取今天凌晨的日期时间
|
|
|
+ cal.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ cal.set(Calendar.MINUTE, 0);
|
|
|
+ cal.set(Calendar.SECOND, 0);
|
|
|
+ cal.set(Calendar.MILLISECOND, 0);
|
|
|
+ Date todayStart = cal.getTime();
|
|
|
+ return LocalDateTimeUtil.of(todayStart);
|
|
|
}
|
|
|
|
|
|
}
|