PlatformOpenAppController.java
4.04 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
package com.diligrp.rider.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.diligrp.rider.common.result.Result;
import com.diligrp.rider.dto.PlatformMockDeliveryCreateDTO;
import com.diligrp.rider.entity.OpenApp;
import com.diligrp.rider.entity.WebhookLog;
import com.diligrp.rider.mapper.OpenAppMapper;
import com.diligrp.rider.mapper.WebhookLogMapper;
import com.diligrp.rider.service.DeliveryOrderService;
import com.diligrp.rider.service.OpenAppService;
import com.diligrp.rider.service.WebhookService;
import com.diligrp.rider.vo.DeliveryOrderCreateVO;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 平台后台:开放平台应用管理
*/
@RestController
@RequestMapping("/api/platform/open")
@RequiredArgsConstructor
public class PlatformOpenAppController {
private final OpenAppService openAppService;
private final WebhookService webhookService;
private final WebhookLogMapper webhookLogMapper;
private final OpenAppMapper openAppMapper;
private final DeliveryOrderService deliveryOrderService;
/** 应用列表 */
@GetMapping("/list")
public Result<List<OpenApp>> list(@RequestParam(defaultValue = "1") int page) {
return Result.success(openAppService.list(page));
}
/** 创建应用 */
@PostMapping("/create")
public Result<OpenApp> create(@RequestParam String appName,
@RequestParam Long cityId,
@RequestParam(required = false) Long storeId,
@RequestParam(required = false) String webhookUrl,
@RequestParam(required = false) String webhookEvents,
@RequestParam(required = false) String remark) {
return Result.success(openAppService.create(appName, cityId, storeId, webhookUrl, webhookEvents, remark));
}
/** 平台后台模拟推送配送单 */
@PostMapping("/mockDelivery/create")
public Result<DeliveryOrderCreateVO> mockDeliveryCreate(@Valid @RequestBody PlatformMockDeliveryCreateDTO dto) {
OpenApp app = openAppMapper.selectById(dto.getAppId());
if (app == null) {
return Result.error("应用不存在");
}
return Result.success(deliveryOrderService.create(app.getAppKey(), dto));
}
/** 重置 AppSecret */
@PostMapping("/resetSecret")
public Result<String> resetSecret(@RequestParam Long appId) {
return Result.success(openAppService.resetSecret(appId));
}
/** 启用/禁用应用:status=0禁用 1启用 */
@PostMapping("/setStatus")
public Result<Void> setStatus(@RequestParam Long appId, @RequestParam int status) {
openAppService.setStatus(appId, status);
return Result.success();
}
/** 更新 Webhook 配置 */
@PostMapping("/updateWebhook")
public Result<Void> updateWebhook(@RequestParam Long appId,
@RequestParam String webhookUrl,
@RequestParam String webhookEvents) {
openAppService.updateWebhook(appId, webhookUrl, webhookEvents);
return Result.success();
}
/** Webhook 推送日志 */
@GetMapping("/webhook/logs")
public Result<List<WebhookLog>> webhookLogs(@RequestParam Long appId,
@RequestParam(defaultValue = "1") int page) {
int offset = (page - 1) * 20;
List<WebhookLog> logs = webhookLogMapper.selectList(
new LambdaQueryWrapper<WebhookLog>()
.eq(WebhookLog::getAppId, appId)
.orderByDesc(WebhookLog::getId)
.last("LIMIT " + offset + ",20"));
return Result.success(logs);
}
/** 重试失败的 Webhook */
@PostMapping("/webhook/retry")
public Result<Void> retryWebhook(@RequestParam Long logId) {
webhookService.retry(logId);
return Result.success();
}
}