fix(分润管理):前端功能实现,统计功能实现
This commit is contained in:
+14
@@ -3,11 +3,13 @@ package com.central.order.controller;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.model.ProfitSharing;
|
||||
import com.central.order.model.vo.ProfitSharingStatisticsVO;
|
||||
import com.central.order.service.IProfitSharingService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -45,4 +47,16 @@ public class ProfitSharingController {
|
||||
return Result.failed("分账执行失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "获取分账统计数据")
|
||||
@GetMapping("/statistics")
|
||||
public Result<ProfitSharingStatisticsVO> getStatistics() {
|
||||
try {
|
||||
ProfitSharingStatisticsVO statistics = profitSharingService.getStatistics();
|
||||
return Result.succeed(statistics);
|
||||
} catch (Exception e) {
|
||||
log.error("获取分账统计数据失败", e);
|
||||
return Result.failed("获取统计数据失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -45,16 +45,16 @@ public interface DashboardMapper {
|
||||
})
|
||||
Long getTodayIncome();
|
||||
|
||||
@Select("SELECT COUNT(*) FROM waylines WHERE is_del = 0")
|
||||
@Select("SELECT COUNT(*) FROM device-center.wayline_file WHERE is_del = 0")
|
||||
Long getTotalWaylines();
|
||||
|
||||
@Select("SELECT COUNT(*) FROM waylines WHERE is_del = 0 AND last_use_time >= DATE_SUB(NOW(), INTERVAL 7 DAY)")
|
||||
@Select("SELECT COUNT(*) FROM device-center.wayline_file WHERE is_del = 0 AND last_use_time >= DATE_SUB(NOW(), INTERVAL 7 DAY)")
|
||||
Long getActiveWaylines();
|
||||
|
||||
@Select("SELECT COUNT(*) FROM devices WHERE is_del = 0")
|
||||
@Select("SELECT COUNT(*) FROM device-center.manage_device WHERE is_del = 0")
|
||||
Long getTotalDevices();
|
||||
|
||||
@Select("SELECT COUNT(*) FROM devices WHERE is_del = 0 AND status = 1")
|
||||
@Select("SELECT COUNT(*) FROM device-center.manage_device WHERE is_del = 0 AND status = 1")
|
||||
Long getOnlineDevices();
|
||||
|
||||
@Select({
|
||||
|
||||
+34
@@ -3,7 +3,41 @@ package com.central.order.mapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.central.order.model.ProfitSharing;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface ProfitSharingMapper extends BaseMapper<ProfitSharing> {
|
||||
// 获取总体统计
|
||||
@Select("SELECT " +
|
||||
"COUNT(*) as total_count, " +
|
||||
"SUM(CASE WHEN status = 2 THEN 1 ELSE 0 END) as success_count, " +
|
||||
"SUM(CASE WHEN status = 3 THEN 1 ELSE 0 END) as fail_count, " +
|
||||
"SUM(qrcode_amount) as total_amount " +
|
||||
"FROM profit_sharing")
|
||||
Map<String, Object> getTotalStatistics();
|
||||
|
||||
// 获取每日金额趋势
|
||||
@Select("SELECT " +
|
||||
"DATE_FORMAT(create_time, '%Y-%m-%d') as date, " +
|
||||
"'DAY' as type, " +
|
||||
"SUM(qrcode_amount) as amount " +
|
||||
"FROM profit_sharing " +
|
||||
"WHERE create_time >= #{startTime} " +
|
||||
"GROUP BY DATE_FORMAT(create_time, '%Y-%m-%d')")
|
||||
List<Map<String, Object>> getDailyAmountTrend(@Param("startTime") Date startTime);
|
||||
|
||||
// 获取每日成功率
|
||||
@Select("SELECT " +
|
||||
"DATE_FORMAT(create_time, '%Y-%m-%d') as date, " +
|
||||
"'DAY' as type, " +
|
||||
"ROUND(SUM(CASE WHEN status = 2 THEN 1 ELSE 0 END) * 100.0 / COUNT(*), 2) as value " +
|
||||
"FROM profit_sharing " +
|
||||
"WHERE create_time >= #{startTime} " +
|
||||
"GROUP BY DATE_FORMAT(create_time, '%Y-%m-%d')")
|
||||
List<Map<String, Object>> getDailySuccessRate(@Param("startTime") Date startTime);
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package com.central.order.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.Builder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@Schema(description = "分账统计数据")
|
||||
public class ProfitSharingStatisticsVO {
|
||||
@Schema(description = "总分账笔数")
|
||||
private Long totalCount;
|
||||
|
||||
@Schema(description = "成功笔数")
|
||||
private Long successCount;
|
||||
|
||||
@Schema(description = "失败笔数")
|
||||
private Long failCount;
|
||||
|
||||
@Schema(description = "总分账金额(分)")
|
||||
private Long totalAmount;
|
||||
|
||||
@Schema(description = "金额趋势数据")
|
||||
private List<TrendData> amountTrend;
|
||||
|
||||
@Schema(description = "成功率数据")
|
||||
private List<RateData> successRate;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public static class TrendData {
|
||||
@Schema(description = "日期")
|
||||
private String date;
|
||||
|
||||
@Schema(description = "类型(DAY-日,WEEK-周,MONTH-月)")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "金额(分)")
|
||||
private Long amount;
|
||||
}
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public static class RateData {
|
||||
@Schema(description = "日期")
|
||||
private String date;
|
||||
|
||||
@Schema(description = "类型(DAY-日,WEEK-周,MONTH-月)")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "成功率(0-100)")
|
||||
private Double value;
|
||||
}
|
||||
}
|
||||
+3
@@ -6,6 +6,7 @@ import com.central.order.model.Order;
|
||||
import com.central.order.model.ProfitSharing;
|
||||
import com.central.order.model.ProfitSharingResult;
|
||||
import com.central.order.model.QrCode;
|
||||
import com.central.order.model.vo.ProfitSharingStatisticsVO;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -54,4 +55,6 @@ public interface IProfitSharingService extends ISuperService<ProfitSharing> {
|
||||
* 查询分账状态
|
||||
*/
|
||||
ProfitSharingResult queryProfitSharingStatus(String orderNo);
|
||||
|
||||
ProfitSharingStatisticsVO getStatistics();
|
||||
}
|
||||
|
||||
+3
-3
@@ -29,10 +29,10 @@ public class DashboardServiceImpl implements IDashboardService {
|
||||
statistics.setIncomeStats(getIncomeStatistics());
|
||||
|
||||
// 3. 获取航线统计
|
||||
statistics.setWaylineStats(getWaylineStatistics());
|
||||
// statistics.setWaylineStats(getWaylineStatistics());
|
||||
|
||||
// 4. 获取设备统计
|
||||
statistics.setDeviceStats(getDeviceStatistics());
|
||||
// statistics.setDeviceStats(getDeviceStatistics());
|
||||
|
||||
// 5. 获取图表统计
|
||||
statistics.setChartStats(getChartStatistics());
|
||||
@@ -156,7 +156,7 @@ public class DashboardServiceImpl implements IDashboardService {
|
||||
stats.setOrderTrend(dashboardMapper.getOrderTrend());
|
||||
|
||||
// 获取设备分布
|
||||
stats.setDeviceDistribution(dashboardMapper.getDeviceDistribution());
|
||||
// stats.setDeviceDistribution(dashboardMapper.getDeviceDistribution());
|
||||
|
||||
// 获取收入构成
|
||||
stats.setIncomeData(dashboardMapper.getIncomeData());
|
||||
|
||||
+68
@@ -14,6 +14,7 @@ import com.central.order.model.Order;
|
||||
import com.central.order.model.ProfitSharing;
|
||||
import com.central.order.model.ProfitSharingResult;
|
||||
import com.central.order.model.QrCode;
|
||||
import com.central.order.model.vo.ProfitSharingStatisticsVO;
|
||||
import com.central.order.service.IProfitSharingService;
|
||||
import com.central.order.service.IQrCodeService;
|
||||
import com.wechat.pay.java.service.profitsharing.ProfitsharingService;
|
||||
@@ -21,6 +22,7 @@ import com.wechat.pay.java.service.profitsharing.model.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
@@ -59,6 +61,9 @@ public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapp
|
||||
@Value("${wechat.pay.platform-rate:0.30}")
|
||||
private String platformRate;
|
||||
|
||||
@Autowired
|
||||
private ProfitSharingMapper profitSharingMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ProfitSharing createProfitSharing(Order order) {
|
||||
@@ -693,4 +698,67 @@ public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapp
|
||||
throw new BusinessException("分账金额不能超过订单总额");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfitSharingStatisticsVO getStatistics() {
|
||||
try {
|
||||
// 1. 获取总体统计
|
||||
Map<String, Object> totalStats = profitSharingMapper.getTotalStatistics();
|
||||
|
||||
// 2. 获取最近30天的数据
|
||||
Date startTime = DateUtils.addDays(new Date(), -30);
|
||||
|
||||
// 3. 获取趋势数据
|
||||
List<Map<String, Object>> dailyTrend = profitSharingMapper.getDailyAmountTrend(startTime);
|
||||
List<ProfitSharingStatisticsVO.TrendData> amountTrend = convertToTrendData(dailyTrend);
|
||||
|
||||
// 4. 获取成功率数据
|
||||
List<Map<String, Object>> dailyRate = profitSharingMapper.getDailySuccessRate(startTime);
|
||||
List<ProfitSharingStatisticsVO.RateData> successRate = convertToRateData(dailyRate);
|
||||
|
||||
// 5. 构建返回数据
|
||||
return ProfitSharingStatisticsVO.builder()
|
||||
.totalCount(getLongValue(totalStats, "total_count"))
|
||||
.successCount(getLongValue(totalStats, "success_count"))
|
||||
.failCount(getLongValue(totalStats, "fail_count"))
|
||||
.totalAmount(getLongValue(totalStats, "total_amount"))
|
||||
.amountTrend(amountTrend)
|
||||
.successRate(successRate)
|
||||
.build();
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("获取分账统计数据失败", e);
|
||||
throw new BusinessException("获取统计数据失败");
|
||||
}
|
||||
}
|
||||
|
||||
private List<ProfitSharingStatisticsVO.TrendData> convertToTrendData(List<Map<String, Object>> dailyTrend) {
|
||||
return dailyTrend.stream()
|
||||
.map(map -> ProfitSharingStatisticsVO.TrendData.builder()
|
||||
.date(String.valueOf(map.get("date")))
|
||||
.type(String.valueOf(map.get("type")))
|
||||
.amount(getLongValue(map, "amount"))
|
||||
.build())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<ProfitSharingStatisticsVO.RateData> convertToRateData(List<Map<String, Object>> dailyRate) {
|
||||
return dailyRate.stream()
|
||||
.map(map -> ProfitSharingStatisticsVO.RateData.builder()
|
||||
.date(String.valueOf(map.get("date")))
|
||||
.type(String.valueOf(map.get("type")))
|
||||
.value(getDoubleValue(map, "value"))
|
||||
.build())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private Long getLongValue(Map<String, Object> map, String key) {
|
||||
Object value = map.get(key);
|
||||
return value == null ? 0L : Long.valueOf(String.valueOf(value));
|
||||
}
|
||||
|
||||
private Double getDoubleValue(Map<String, Object> map, String key) {
|
||||
Object value = map.get(key);
|
||||
return value == null ? 0.0 : Double.valueOf(String.valueOf(value));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user