From 0bf199cf85a36157113d217363bb96314956b75f Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期四, 13 十一月 2025 22:14:12 +0800
Subject: [PATCH] feat: 修复小程序上传附件
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/VehicleInfoServiceImpl.java | 150 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 149 insertions(+), 1 deletions(-)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/VehicleInfoServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/VehicleInfoServiceImpl.java
index 42a8c82..1b4a58d 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/VehicleInfoServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/VehicleInfoServiceImpl.java
@@ -1,11 +1,23 @@
package com.ruoyi.system.service.impl;
+import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
+import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.system.mapper.VehicleInfoMapper;
+import com.ruoyi.system.mapper.SysUserMapper;
+import com.ruoyi.system.mapper.SysDeptMapper;
import com.ruoyi.system.domain.VehicleInfo;
+import com.ruoyi.system.domain.VehicleDept;
import com.ruoyi.system.service.IVehicleInfoService;
+import com.ruoyi.system.service.ISysDeptService;
/**
* 杞﹁締淇℃伅Service涓氬姟灞傚鐞�
@@ -14,6 +26,15 @@
public class VehicleInfoServiceImpl implements IVehicleInfoService {
@Autowired
private VehicleInfoMapper vehicleInfoMapper;
+
+ @Autowired
+ private SysUserMapper sysUserMapper;
+
+ @Autowired
+ private SysDeptMapper sysDeptMapper;
+
+ @Autowired
+ private ISysDeptService sysDeptService;
/**
* 鏌ヨ杞﹁締淇℃伅
@@ -55,8 +76,16 @@
* @return 缁撴灉
*/
@Override
+ @Transactional
public int insertVehicleInfo(VehicleInfo vehicleInfo) {
- return vehicleInfoMapper.insertVehicleInfo(vehicleInfo);
+ int rows = vehicleInfoMapper.insertVehicleInfo(vehicleInfo);
+
+ // 濡傛灉閫夋嫨浜嗗涓垎鍏徃锛屼繚瀛樺埌鍏宠仈琛�
+ if (vehicleInfo.getDeptIds() != null && !vehicleInfo.getDeptIds().isEmpty()) {
+ insertVehicleDept(vehicleInfo);
+ }
+
+ return rows;
}
/**
@@ -66,8 +95,34 @@
* @return 缁撴灉
*/
@Override
+ @Transactional
public int updateVehicleInfo(VehicleInfo vehicleInfo) {
+ // 鍏堝垹闄ゆ棫鐨勫叧鑱斿叧绯�
+ vehicleInfoMapper.deleteVehicleDeptByVehicleId(vehicleInfo.getVehicleId());
+
+ // 濡傛灉閫夋嫨浜嗗涓垎鍏徃锛屼繚瀛樺埌鍏宠仈琛�
+ if (vehicleInfo.getDeptIds() != null && !vehicleInfo.getDeptIds().isEmpty()) {
+ insertVehicleDept(vehicleInfo);
+ }
+
return vehicleInfoMapper.updateVehicleInfo(vehicleInfo);
+ }
+
+ /**
+ * 鎻掑叆杞﹁締-鍒嗗叕鍙稿叧鑱斿叧绯�
+ */
+ private void insertVehicleDept(VehicleInfo vehicleInfo) {
+ List<VehicleDept> vehicleDepts = new ArrayList<>();
+ for (Long deptId : vehicleInfo.getDeptIds()) {
+ VehicleDept vd = new VehicleDept();
+ vd.setVehicleId(vehicleInfo.getVehicleId());
+ vd.setDeptId(deptId);
+ vd.setCreateBy(vehicleInfo.getCreateBy());
+ vehicleDepts.add(vd);
+ }
+ if (!vehicleDepts.isEmpty()) {
+ vehicleInfoMapper.batchInsertVehicleDept(vehicleDepts);
+ }
}
/**
@@ -91,4 +146,97 @@
public int deleteVehicleInfoById(Long vehicleId) {
return vehicleInfoMapper.deleteVehicleInfoById(vehicleId);
}
+
+ /**
+ * 缁戝畾杞﹁締鍒扮敤鎴�
+ *
+ * @param userId 鐢ㄦ埛ID
+ * @param vehicleId 杞﹁締ID
+ * @return 缁撴灉
+ */
+ @Override
+ @Transactional
+ public int bindVehicleToUser(Long userId, Long vehicleId) {
+ // 鍏堣В缁戠敤鎴风殑鎵�鏈夎溅杈嗭紙涓氬姟閫昏緫锛氫竴涓敤鎴峰悓鏃跺彧鑳界粦瀹氫竴杈嗚溅锛�
+ vehicleInfoMapper.unbindAllVehiclesFromUser(userId);
+
+ // 缁戝畾鏂拌溅杈�
+ String bindBy = "";
+ try {
+ bindBy = SecurityUtils.getUsername();
+ } catch (Exception e) {
+ // 濡傛灉鑾峰彇褰撳墠鐢ㄦ埛澶辫触锛屼娇鐢ㄧ┖瀛楃涓�
+ }
+ return vehicleInfoMapper.bindVehicleToUser(userId, vehicleId, bindBy);
+ }
+
+ /**
+ * 瑙g粦鐢ㄦ埛杞﹁締
+ *
+ * @param userId 鐢ㄦ埛ID
+ * @param vehicleId 杞﹁締ID
+ * @return 缁撴灉
+ */
+ @Override
+ public int unbindVehicleFromUser(Long userId, Long vehicleId) {
+ return vehicleInfoMapper.unbindVehicleFromUser(userId, vehicleId);
+ }
+
+ /**
+ * 鑾峰彇鐢ㄦ埛褰撳墠缁戝畾鐨勮溅杈�
+ *
+ * @param userId 鐢ㄦ埛ID
+ * @return 杞﹁締淇℃伅
+ */
+ @Override
+ public VehicleInfo getUserBoundVehicle(Long userId) {
+ return vehicleInfoMapper.getUserBoundVehicle(userId);
+ }
+
+ /**
+ * 鏍规嵁鐢ㄦ埛鏈夋潈闄愮鐞嗙殑鍒嗗叕鍙革紝鏌ヨ鎵�鏈夊彲鐢ㄨ溅杈�
+ * 閫昏緫锛�
+ * 1. 鏌ヨ鐢ㄦ埛淇℃伅
+ * 2. 璋冪敤sysDeptService.computeBranchCompaniesForUser鑾峰彇鐢ㄦ埛绠$悊鐨勬墍鏈夊垎鍏徃
+ * 3. 閫氳繃tb_vehicle_dept鍏宠仈琛ㄦ煡璇㈣繖浜涘垎鍏徃涓嬬殑鎵�鏈夎溅杈�
+ *
+ * @param userId 鐢ㄦ埛ID
+ * @return 杞﹁締鍒楄〃
+ */
+ @Override
+ public List<VehicleInfo> selectAvailableVehiclesByUser(Long userId) {
+ // 1. 鏌ヨ鐢ㄦ埛淇℃伅
+ SysUser user = sysUserMapper.selectUserById(userId);
+ if (user == null) {
+ return new ArrayList<>();
+ }
+
+ // 2. 璋冪敤sysDeptService鑾峰彇鐢ㄦ埛绠$悊鐨勬墍鏈夊垎鍏徃
+ List<SysDept> branchCompanies = sysDeptService.computeBranchCompaniesForUser(user);
+
+ if (branchCompanies.isEmpty()) {
+ // 濡傛灉娌℃湁鎵惧埌浠讳綍鍒嗗叕鍙革紝杩斿洖绌哄垪琛�
+ return new ArrayList<>();
+ }
+
+ // 3. 鏍规嵁鍒嗗叕鍙稿垪琛ㄦ煡璇㈣溅杈嗭紝浣跨敤Set鍘婚噸
+ Set<Long> vehicleIdSet = new HashSet<>();
+ List<VehicleInfo> allVehicles = new ArrayList<>();
+
+ for (SysDept branchCompany : branchCompanies) {
+ VehicleInfo query = new VehicleInfo();
+ query.setDeptId(branchCompany.getDeptId());
+ List<VehicleInfo> vehicles = vehicleInfoMapper.selectVehicleInfoList(query);
+
+ // 鍘婚噸娣诲姞
+ for (VehicleInfo vehicle : vehicles) {
+ if (!vehicleIdSet.contains(vehicle.getVehicleId())) {
+ vehicleIdSet.add(vehicle.getVehicleId());
+ allVehicles.add(vehicle);
+ }
+ }
+ }
+
+ return allVehicles;
+ }
}
\ No newline at end of file
--
Gitblit v1.9.1