AdminRiderWithdrawController.java
3.97 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
package com.diligrp.rider.controller;
import com.diligrp.rider.common.result.Result;
import com.diligrp.rider.dto.WithdrawAuditDTO;
import com.diligrp.rider.dto.WithdrawMarkPaidDTO;
import com.diligrp.rider.service.RiderWithdrawService;
import com.diligrp.rider.vo.PageResultVO;
import com.diligrp.rider.vo.RiderWithdrawApplyVO;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/admin/rider/withdraw")
@RequiredArgsConstructor
public class AdminRiderWithdrawController {
private final RiderWithdrawService withdrawService;
@GetMapping("/list")
public Result<PageResultVO<RiderWithdrawApplyVO>> list(@RequestParam(required = false) Long cityId,
@RequestParam(required = false) Integer status,
@RequestParam(required = false) String keyword,
@RequestParam(required = false) String startDate,
@RequestParam(required = false) String endDate,
@RequestParam(defaultValue = "1") int page,
HttpServletRequest request) {
return Result.success(withdrawService.adminList(resolveQueryCityId(request, cityId), status, keyword, startDate, endDate, page));
}
@GetMapping("/{id}")
public Result<RiderWithdrawApplyVO> detail(@PathVariable Long id, HttpServletRequest request) {
return Result.success(withdrawService.adminDetail(id, resolveScopedCityId(request)));
}
@PostMapping("/{id}/approve")
public Result<Void> approve(@PathVariable Long id,
@RequestBody(required = false) WithdrawAuditDTO dto,
HttpServletRequest request) {
withdrawService.approve(id, dto, resolveScopedCityId(request), currentAdminId(request), currentRole(request));
return Result.success();
}
@PostMapping("/{id}/reject")
public Result<Void> reject(@PathVariable Long id,
@RequestBody(required = false) WithdrawAuditDTO dto,
HttpServletRequest request) {
withdrawService.reject(id, dto, resolveScopedCityId(request), currentAdminId(request), currentRole(request));
return Result.success();
}
@PostMapping("/{id}/mark-paid")
public Result<Void> markPaid(@PathVariable Long id,
@Valid @RequestBody WithdrawMarkPaidDTO dto,
HttpServletRequest request) {
withdrawService.markPaid(id, dto, resolveScopedCityId(request), currentAdminId(request), currentRole(request));
return Result.success();
}
private Long resolveScopedCityId(HttpServletRequest request) {
return "substation".equals(request.getAttribute("role")) ? (Long) request.getAttribute("cityId") : null;
}
private Long resolveQueryCityId(HttpServletRequest request, Long queryCityId) {
Long scopedCityId = resolveScopedCityId(request);
return scopedCityId != null ? scopedCityId : queryCityId;
}
private Long currentAdminId(HttpServletRequest request) {
return (Long) request.getAttribute("adminId");
}
private String currentRole(HttpServletRequest request) {
Object role = request.getAttribute("role");
return role == null ? "" : role.toString();
}
}