1
This commit is contained in:
@@ -12,77 +12,30 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 客户端本地服务控制器
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public class AuthController {
|
||||
@Autowired
|
||||
private IAuthService authService;
|
||||
@Autowired
|
||||
private AuthTokenRepository authTokenRepository;
|
||||
@Autowired
|
||||
private CacheDataRepository cacheDataRepository;
|
||||
@PostMapping("/login")
|
||||
public ResponseEntity<?> login(@RequestBody Map<String, Object> loginData) {
|
||||
String username = (String) loginData.get("username");
|
||||
String password = (String) loginData.get("password");
|
||||
Map<String, Object> result = authService.login(username, password);
|
||||
Object success = result.get("success");
|
||||
Object tokenObj = result.get("token");
|
||||
if (Boolean.TRUE.equals(success) && tokenObj instanceof String token && token != null && !token.isEmpty()) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add(HttpHeaders.SET_COOKIE, buildHttpOnlyCookie("FX_TOKEN", token, 2 * 24 * 60 * 60));
|
||||
return ResponseEntity.ok().headers(headers).body(result);
|
||||
}
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
@PostMapping("/verify")
|
||||
public ResponseEntity<?> verifyToken(@RequestBody Map<String, Object> data) {
|
||||
String token = (String) data.get("token");
|
||||
if (token == null) {
|
||||
return ResponseEntity.ok(Map.of("code", 400, "message", "token不能为空"));
|
||||
}
|
||||
Map<String, Object> result = authService.verifyToken(token);
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
@PostMapping("/register")
|
||||
public ResponseEntity<?> register(@RequestBody Map<String, Object> registerData) {
|
||||
String username = (String) registerData.get("username");
|
||||
String password = (String) registerData.get("password");
|
||||
if (username == null || password == null) {
|
||||
return ResponseEntity.ok(Map.of("code", 400, "message", "用户名和密码不能为空"));
|
||||
}
|
||||
Map<String, Object> result = authService.register(username, password);
|
||||
Object success2 = result.get("success");
|
||||
Object tokenObj2 = result.get("token");
|
||||
if (Boolean.TRUE.equals(success2) && tokenObj2 instanceof String token && token != null && !token.isEmpty()) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add(HttpHeaders.SET_COOKIE, buildHttpOnlyCookie("FX_TOKEN", token, 2 * 24 * 60 * 60));
|
||||
return ResponseEntity.ok().headers(headers).body(result);
|
||||
}
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 退出登录(清理本地状态)
|
||||
*/
|
||||
@PostMapping("/logout")
|
||||
public ResponseEntity<?> logout(@RequestBody Map<String, Object> data) {
|
||||
authService.logout();
|
||||
// 清理本地缓存
|
||||
try {
|
||||
cacheDataRepository.deleteByCacheKey("token");
|
||||
cacheDataRepository.deleteByCacheKey("deviceId");
|
||||
} catch (Exception ignored) {}
|
||||
return ResponseEntity.ok(Map.of("code", 0, "message", "退出成功"));
|
||||
}
|
||||
|
||||
@GetMapping("/check-username")
|
||||
public ResponseEntity<?> checkUsername(@RequestParam String username) {
|
||||
if (username == null || username.trim().isEmpty()) {
|
||||
return ResponseEntity.ok(Map.of("code", 400, "message", "用户名不能为空"));
|
||||
}
|
||||
boolean available = authService.checkUsername(username);
|
||||
return ResponseEntity.ok(Map.of(
|
||||
"code", 200,
|
||||
"message", "检查成功",
|
||||
"data", available
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存认证密钥
|
||||
*/
|
||||
@@ -179,15 +132,12 @@ public class AuthController {
|
||||
return JsonData.buildSuccess("会话已恢复");
|
||||
}
|
||||
|
||||
private String buildHttpOnlyCookie(String name, String value, int maxAgeSeconds) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(name).append("=").append(value).append(";");
|
||||
sb.append(" Path=/;");
|
||||
sb.append(" HttpOnly;");
|
||||
sb.append(" SameSite=Strict;");
|
||||
if (maxAgeSeconds > 0) {
|
||||
sb.append(" Max-Age=").append(maxAgeSeconds).append(";");
|
||||
}
|
||||
return sb.toString();
|
||||
/**
|
||||
* 获取设备ID(硬件UUID)
|
||||
*/
|
||||
@GetMapping("/device-id")
|
||||
public JsonData getDeviceId() {
|
||||
String deviceId = com.tashow.erp.utils.DeviceUtils.generateDeviceId();
|
||||
return JsonData.buildSuccess(deviceId);
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package com.tashow.erp.controller;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.tashow.erp.utils.ApiForwarder;
|
||||
import com.tashow.erp.utils.DeviceUtils;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* 设备管理代理控制器
|
||||
* 简化职责:透传请求到后端服务
|
||||
*/
|
||||
@RestController
|
||||
public class DeviceProxyController {
|
||||
|
||||
/**
|
||||
* 注册设备
|
||||
*/
|
||||
@Autowired
|
||||
private ApiForwarder apiForwarder;
|
||||
|
||||
@PostMapping("/api/device/register")
|
||||
public ResponseEntity<?> deviceRegister(@RequestBody Map<String, Object> body, @RequestHeader(value = "Authorization", required = false) String auth) {
|
||||
Map<String, Object> deviceData = new HashMap<>(body);
|
||||
deviceData.put("deviceId", DeviceUtils.generateDeviceId());
|
||||
return apiForwarder.post("/monitor/device/register", deviceData, auth);
|
||||
}
|
||||
@PostMapping("/api/device/remove")
|
||||
public ResponseEntity<?> deviceRemove(@RequestBody Map<String, Object> body, @RequestHeader(value = "Authorization", required = false) String auth) {
|
||||
return apiForwarder.post("/monitor/device/remove", body, auth);
|
||||
}
|
||||
|
||||
@PostMapping("/api/device/offline")
|
||||
public ResponseEntity<?> deviceOffline(@RequestBody Map<String, Object> body, @RequestHeader(value = "Authorization", required = false) String auth) {
|
||||
return apiForwarder.post("/monitor/device/offline", body, auth);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备心跳
|
||||
*/
|
||||
@PostMapping("/api/device/heartbeat")
|
||||
public ResponseEntity<?> deviceHeartbeat(@RequestBody Map<String, Object> body, @RequestHeader(value = "Authorization", required = false) String auth) {
|
||||
return apiForwarder.post("/monitor/device/heartbeat", body, auth);
|
||||
}
|
||||
|
||||
@GetMapping("/api/device/quota")
|
||||
public ResponseEntity<?> deviceQuota(@RequestParam("username") String username, @RequestHeader(value = "Authorization", required = false) String auth) {
|
||||
return apiForwarder.get("/monitor/device/quota?username=" + username, auth);
|
||||
}
|
||||
|
||||
@GetMapping("/api/device/list")
|
||||
public ResponseEntity<?> deviceList(@RequestParam("username") String username, @RequestHeader(value = "Authorization", required = false) String auth) {
|
||||
return apiForwarder.get("/monitor/device/list?username=" + username, auth);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.tashow.erp.service.IAuthService;
|
||||
import com.tashow.erp.utils.ApiForwarder;
|
||||
import com.tashow.erp.utils.DeviceUtils;
|
||||
import lombok.Getter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.HashMap;
|
||||
@@ -20,12 +21,11 @@ public class AuthServiceImpl implements IAuthService {
|
||||
|
||||
@Value("${project.version:2.1.0}")
|
||||
private String appVersion;
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
@org.springframework.beans.factory.annotation.Autowired
|
||||
@Autowired
|
||||
private ApiForwarder apiForwarder;
|
||||
|
||||
@org.springframework.beans.factory.annotation.Autowired
|
||||
@Autowired
|
||||
private com.tashow.erp.repository.CacheDataRepository cacheDataRepository;
|
||||
|
||||
@Getter
|
||||
@@ -164,7 +164,6 @@ public class AuthServiceImpl implements IAuthService {
|
||||
Map<String, Object> verifyData = new HashMap<>();
|
||||
verifyData.put("token", token);
|
||||
JsonNode response = sendPostRequest("/monitor/account/verify", verifyData);
|
||||
|
||||
if (response.has("code") && response.get("code").asInt() == 200) {
|
||||
JsonNode dataNode = response.has("data") ? response.get("data") : response;
|
||||
result.put("success", true);
|
||||
|
||||
@@ -28,7 +28,7 @@ import java.util.stream.Collectors;
|
||||
public class BanmaOrderServiceImpl implements IBanmaOrderService {
|
||||
private static final Logger logger = LoggerUtil.getLogger(BanmaOrderServiceImpl.class);
|
||||
private static final String SERVICE_NAME = "banma";
|
||||
private static final String RUOYI_ADMIN_BASE = "http://127.0.0.1:8080";
|
||||
private static final String RUOYI_ADMIN_BASE = "http://192.168.1.89:8085";
|
||||
private static final String API_URL = "https://banma365.cn/api/order/list?%srecipientName=&page=%d&size=%d&markFlag=0&state=4&_t=%d";
|
||||
private static final String API_URL_WITH_TIME = "https://banma365.cn/api/order/list?%srecipientName=&page=%d&size=%d&markFlag=0&state=4&orderedAtStart=%s&orderedAtEnd=%s&_t=%d";
|
||||
private static final String TRACKING_URL = "https://banma365.cn/zebraExpressHub/web/tracking/getByExpressNumber/%s";
|
||||
|
||||
@@ -28,6 +28,6 @@ public class DeviceUtils {
|
||||
} catch (Exception e) {
|
||||
// 静默处理异常
|
||||
}
|
||||
return UUID.randomUUID().toString();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ import com.tashow.erp.service.IAuthService;
|
||||
@Component
|
||||
public class ErrorReporter {
|
||||
|
||||
@Value("${server.monitor.url:http://localhost:8080}")
|
||||
@Value("${api.server.base-url}")
|
||||
private String serverUrl;
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -43,7 +43,7 @@ api:
|
||||
server:
|
||||
# 主服务器API配置
|
||||
# base-url: "http://8.138.23.49:8080"
|
||||
base-url: "http://192.168.1.89:8080"
|
||||
base-url: "http://192.168.1.89:8085"
|
||||
paths:
|
||||
monitor: "/monitor/client/api"
|
||||
login: "/monitor/account/login"
|
||||
|
||||
Reference in New Issue
Block a user