hejianhao
2026-09-01 f4e8dfd7f8f11966f4b5dc8c6661cbc3feccc4cf
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
113
114
115
116
117
package com.tcm.training.admin.points.controller;
 
import com.tcm.training.admin.common.ApiResponse;
import com.tcm.training.admin.common.PageResponse;
import com.tcm.training.admin.points.dto.ExchangeShipRequest;
import com.tcm.training.admin.points.service.PointsExchangeAppService;
import com.tcm.training.admin.points.vo.PointsExchangeItemDetailVO;
import com.tcm.training.admin.points.vo.PointsExchangeItemListItemVO;
import com.tcm.training.admin.points.vo.PointsExchangeOrderListItemVO;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
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;
 
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.time.LocalDateTime;
 
@Validated
@RestController
@RequestMapping({"/api/v1", "/api"})
public class PointsExchangeController {
 
    private final PointsExchangeAppService pointsExchangeAppService;
 
    public PointsExchangeController(PointsExchangeAppService pointsExchangeAppService) {
        this.pointsExchangeAppService = pointsExchangeAppService;
    }
 
    @GetMapping("/points-exchange/orders")
    public ApiResponse<PageResponse<PointsExchangeOrderListItemVO>> orderPage(
            @RequestParam(required = false, defaultValue = "1") int page,
            @RequestParam(required = false, defaultValue = "10") int pageSize,
            @RequestParam(required = false) String giftName,
            @RequestParam(required = false) String receiverPhone,
            @RequestParam(required = false) Integer status,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime createdFrom,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime createdTo) {
        return ApiResponse.ok(pointsExchangeAppService.pageOrders(page, pageSize, giftName, receiverPhone, status, createdFrom, createdTo));
    }
 
    @GetMapping("/points-exchange/orders/export")
    public void exportOrders(HttpServletResponse response,
                             @RequestParam(required = false) String giftName,
                             @RequestParam(required = false) String receiverPhone,
                             @RequestParam(required = false) Integer status,
                             @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime createdFrom,
                             @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime createdTo) throws IOException {
        pointsExchangeAppService.exportOrders(response, giftName, receiverPhone, status, createdFrom, createdTo);
    }
 
    @GetMapping("/points-exchange/order-items")
    public ApiResponse<PageResponse<PointsExchangeItemListItemVO>> itemPage(
            @RequestParam(required = false, defaultValue = "1") int page,
            @RequestParam(required = false, defaultValue = "10") int pageSize,
            @RequestParam(required = false) Long orderId,
            @RequestParam(required = false) String orderNo,
            @RequestParam(required = false) String buyerPhone,
            @RequestParam(required = false) String giftName,
            @RequestParam(required = false) String receiverPhone,
            @RequestParam(required = false) Integer status,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime createdFrom,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime createdTo) {
        return ApiResponse.ok(pointsExchangeAppService.pageItems(
                page, pageSize, orderId, orderNo, buyerPhone, giftName, receiverPhone, status, createdFrom, createdTo
        ));
    }
 
    @GetMapping("/points-exchange/order-items/export")
    public void exportItems(HttpServletResponse response,
                            @RequestParam(required = false) Long orderId,
                            @RequestParam(required = false) String orderNo,
                            @RequestParam(required = false) String buyerPhone,
                            @RequestParam(required = false) String giftName,
                            @RequestParam(required = false) String receiverPhone,
                            @RequestParam(required = false) Integer status,
                            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime createdFrom,
                            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime createdTo) throws IOException {
        pointsExchangeAppService.exportItems(response, orderId, orderNo, buyerPhone, giftName, receiverPhone, status, createdFrom, createdTo);
    }
 
    @GetMapping("/points-exchange/order-items/{id}")
    public ApiResponse<PointsExchangeItemDetailVO> itemDetail(@PathVariable("id") Long id) {
        return ApiResponse.ok(pointsExchangeAppService.itemDetail(id));
    }
 
    @PostMapping("/points-exchange/orders/{id}/ship")
    public ApiResponse<Void> shipOrder(@PathVariable("id") Long id, @Valid @RequestBody ExchangeShipRequest request) {
        pointsExchangeAppService.shipOrder(id, request);
        return ApiResponse.ok(null);
    }
 
    @PostMapping("/points-exchange/order-items/{id}/ship")
    public ApiResponse<Void> shipItem(@PathVariable("id") Long id, @Valid @RequestBody ExchangeShipRequest request) {
        pointsExchangeAppService.shipItem(id, request);
        return ApiResponse.ok(null);
    }
 
    @DeleteMapping("/points-exchange/orders/{id}")
    public ApiResponse<Void> deleteOrder(@PathVariable("id") Long id) {
        pointsExchangeAppService.deleteOrder(id);
        return ApiResponse.ok(null);
    }
 
    @DeleteMapping("/points-exchange/order-items/{id}")
    public ApiResponse<Void> deleteItem(@PathVariable("id") Long id) {
        pointsExchangeAppService.deleteItem(id);
        return ApiResponse.ok(null);
    }
}