From 2c86a8bd60deed0dd0e044bad6fb83f75d19a332 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期日, 26 十月 2025 15:05:50 +0800
Subject: [PATCH] Merge branch 'feature-task'
---
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleInfoController.java | 88 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 88 insertions(+), 0 deletions(-)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleInfoController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleInfoController.java
index b33aea0..d0c6d76 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleInfoController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleInfoController.java
@@ -1,6 +1,8 @@
package com.ruoyi.web.controller.system;
import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@@ -12,9 +14,11 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.VehicleInfo;
import com.ruoyi.system.service.IVehicleInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
@@ -90,4 +94,88 @@
public AjaxResult remove(@PathVariable Long[] vehicleIds) {
return toAjax(vehicleInfoService.deleteVehicleInfoByIds(vehicleIds));
}
+
+ /**
+ * 缁戝畾杞﹁締鍒扮敤鎴�
+ */
+ @Anonymous
+ @Log(title = "鐢ㄦ埛缁戝畾杞﹁締", businessType = BusinessType.UPDATE)
+ @PostMapping("/bind")
+ public AjaxResult bindVehicle(@RequestBody Map<String, Object> params) {
+ try {
+ Long userId = Long.valueOf(params.get("userId").toString());
+ Long vehicleId = Long.valueOf(params.get("vehicleId").toString());
+
+ // 楠岃瘉杞﹁締鏄惁瀛樺湪
+ VehicleInfo vehicle = vehicleInfoService.selectVehicleInfoById(vehicleId);
+ if (vehicle == null) {
+ return error("杞﹁締涓嶅瓨鍦�");
+ }
+
+ // 楠岃瘉杞﹁締鐘舵�佹槸鍚︽甯�
+ if (!"0".equals(vehicle.getStatus())) {
+ return error("杞﹁締鐘舵�佸紓甯革紝鏃犳硶缁戝畾");
+ }
+
+ // 璋冪敤缁戝畾鏈嶅姟
+ int result = vehicleInfoService.bindVehicleToUser(userId, vehicleId);
+ if (result > 0) {
+ return success("杞﹁締缁戝畾鎴愬姛");
+ } else {
+ return error("杞﹁締缁戝畾澶辫触");
+ }
+ } catch (Exception e) {
+ logger.error("缁戝畾杞﹁締澶辫触", e);
+ return error("缁戝畾杞﹁締澶辫触锛�" + e.getMessage());
+ }
+ }
+
+ /**
+ * 瑙g粦鐢ㄦ埛杞﹁締
+ */
+ @Anonymous
+ @Log(title = "鐢ㄦ埛瑙g粦杞﹁締", businessType = BusinessType.UPDATE)
+ @PostMapping("/unbind")
+ public AjaxResult unbindVehicle(@RequestBody Map<String, Object> params) {
+ try {
+ Long userId = Long.valueOf(params.get("userId").toString());
+ Long vehicleId = Long.valueOf(params.get("vehicleId").toString());
+
+ // 璋冪敤瑙g粦鏈嶅姟
+ int result = vehicleInfoService.unbindVehicleFromUser(userId, vehicleId);
+ if (result > 0) {
+ return success("杞﹁締瑙g粦鎴愬姛");
+ } else {
+ return error("杞﹁締瑙g粦澶辫触");
+ }
+ } catch (Exception e) {
+ logger.error("瑙g粦杞﹁締澶辫触", e);
+ return error("瑙g粦杞﹁締澶辫触锛�" + e.getMessage());
+ }
+ }
+
+ /**
+ * 鑾峰彇鐢ㄦ埛褰撳墠缁戝畾鐨勮溅杈�
+ */
+ @Anonymous
+ @GetMapping("/user/bound/{userId}")
+ public AjaxResult getUserBoundVehicle(@PathVariable("userId") Long userId) {
+ try {
+ VehicleInfo vehicle = vehicleInfoService.getUserBoundVehicle(userId);
+ if (vehicle != null) {
+ Map<String, Object> result = new HashMap<>();
+ result.put("vehicleId", vehicle.getVehicleId());
+ result.put("vehicleNumber", vehicle.getVehicleNo());
+ result.put("vehicleType", vehicle.getVehicleType());
+ result.put("vehicleBrand", vehicle.getVehicleBrand());
+ result.put("vehicleModel", vehicle.getVehicleModel());
+ return success(result);
+ } else {
+ return success(null);
+ }
+ } catch (Exception e) {
+ logger.error("鑾峰彇鐢ㄦ埛缁戝畾杞﹁締澶辫触", e);
+ return error("鑾峰彇鐢ㄦ埛缁戝畾杞﹁締澶辫触锛�" + e.getMessage());
+ }
+ }
}
\ No newline at end of file
--
Gitblit v1.9.1