MerchantFundServiceImpl.java
4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.diligrp.rider.service.impl;
import com.diligrp.rider.common.exception.BizException;
import com.diligrp.rider.mapper.MerchantFundMapper;
import com.diligrp.rider.service.MerchantFundService;
import com.diligrp.rider.vo.*;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.ZoneId;
@Service
@RequiredArgsConstructor
public class MerchantFundServiceImpl implements MerchantFundService {
private static final int PAGE_SIZE = 20;
private static final ZoneId ZONE_ID = ZoneId.of("Asia/Shanghai");
private final MerchantFundMapper merchantFundMapper;
@Override
public PageResultVO<MerchantBillItemVO> merchantBillList(Long cityId, String keyword, String startDate, String endDate, int page) {
long startTime = parseStartTime(startDate);
long endTime = parseEndTime(endDate);
int currentPage = normalizePage(page);
int offset = (currentPage - 1) * PAGE_SIZE;
PageResultVO<MerchantBillItemVO> result = new PageResultVO<>();
result.setList(merchantFundMapper.selectMerchantBills(cityId, normalizeKeyword(keyword), startTime, endTime, offset, PAGE_SIZE));
result.setPage(currentPage);
result.setPageSize(PAGE_SIZE);
result.setTotal(merchantFundMapper.countMerchantBills(cityId, normalizeKeyword(keyword), startTime, endTime));
return result;
}
@Override
public PageResultVO<MerchantBillDetailItemVO> merchantBillDetail(Long cityId, String outStoreId, String startDate, String endDate, int page) {
if (outStoreId == null || outStoreId.isBlank()) {
throw new BizException("店铺编号不能为空");
}
long startTime = parseStartTime(startDate);
long endTime = parseEndTime(endDate);
int currentPage = normalizePage(page);
int offset = (currentPage - 1) * PAGE_SIZE;
PageResultVO<MerchantBillDetailItemVO> result = new PageResultVO<>();
result.setList(merchantFundMapper.selectMerchantBillDetails(cityId, outStoreId, startTime, endTime, offset, PAGE_SIZE));
result.setPage(currentPage);
result.setPageSize(PAGE_SIZE);
result.setTotal(merchantFundMapper.countMerchantBillDetails(cityId, outStoreId, startTime, endTime));
return result;
}
@Override
public PageResultVO<RiderBillItemVO> riderBillList(Long cityId, String keyword, String startDate, String endDate, int page) {
long startTime = parseStartTime(startDate);
long endTime = parseEndTime(endDate);
int currentPage = normalizePage(page);
int offset = (currentPage - 1) * PAGE_SIZE;
PageResultVO<RiderBillItemVO> result = new PageResultVO<>();
result.setList(merchantFundMapper.selectRiderBills(cityId, normalizeKeyword(keyword), startTime, endTime, offset, PAGE_SIZE));
result.setPage(currentPage);
result.setPageSize(PAGE_SIZE);
result.setTotal(merchantFundMapper.countRiderBills(cityId, normalizeKeyword(keyword), startTime, endTime));
return result;
}
@Override
public PageResultVO<RiderBillDetailItemVO> riderBillDetail(Long cityId, Long riderId, String startDate, String endDate, int page) {
if (riderId == null || riderId < 1) {
throw new BizException("骑手ID不能为空");
}
long startTime = parseStartTime(startDate);
long endTime = parseEndTime(endDate);
int currentPage = normalizePage(page);
int offset = (currentPage - 1) * PAGE_SIZE;
PageResultVO<RiderBillDetailItemVO> result = new PageResultVO<>();
result.setList(merchantFundMapper.selectRiderBillDetails(cityId, riderId, startTime, endTime, offset, PAGE_SIZE));
result.setPage(currentPage);
result.setPageSize(PAGE_SIZE);
result.setTotal(merchantFundMapper.countRiderBillDetails(cityId, riderId, startTime, endTime));
return result;
}
private int normalizePage(int page) {
return Math.max(page, 1);
}
private String normalizeKeyword(String keyword) {
return keyword == null || keyword.isBlank() ? null : keyword.trim();
}
private long parseStartTime(String startDate) {
LocalDate date = parseDate(startDate, "开始日期不能为空");
return date.atStartOfDay(ZONE_ID).toEpochSecond();
}
private long parseEndTime(String endDate) {
LocalDate date = parseDate(endDate, "结束日期不能为空");
return date.plusDays(1).atStartOfDay(ZONE_ID).toEpochSecond();
}
private LocalDate parseDate(String value, String errorMessage) {
if (value == null || value.isBlank()) {
throw new BizException(errorMessage);
}
try {
return LocalDate.parse(value);
} catch (Exception ex) {
throw new BizException(errorMessage);
}
}
}