From af8cab142a6b15c06e131a8474574dd5b00df982 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期四, 04 十二月 2025 22:09:58 +0800
Subject: [PATCH] feat: 改造微信accesstoken存放在系统配置表中
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/VehicleInfoServiceImpl.java | 188 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 185 insertions(+), 3 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..a04d09a 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;
/**
* 鏌ヨ杞﹁締淇℃伅
@@ -23,7 +44,23 @@
*/
@Override
public VehicleInfo selectVehicleInfoById(Long vehicleId) {
- return vehicleInfoMapper.selectVehicleInfoById(vehicleId);
+ return vehicleInfoMapper.selectVehicleInfoWithDeptsById(vehicleId);
+ }
+
+ /**
+ * 鏌ヨ杞﹁締淇℃伅锛堝寘鍚鍒嗗叕鍙稿叧鑱旓級
+ *
+ * @param vehicleId 杞﹁締淇℃伅涓婚敭
+ * @return 杞﹁締淇℃伅锛堝寘鍚玠eptIds鍜宒eptNames锛�
+ */
+ @Override
+ public VehicleInfo selectVehicleInfoWithDeptsById(Long vehicleId) {
+ VehicleInfo vehicle = vehicleInfoMapper.selectVehicleInfoWithDeptsById(vehicleId);
+ // 鍒濆鍖栧欢杩熷姞杞界殑灞炴�э紝閬垮厤搴忓垪鍖栭棶棰�
+ if (vehicle != null) {
+ vehicle.initializeLazyProperties();
+ }
+ return vehicle;
}
/**
@@ -45,7 +82,12 @@
*/
@Override
public List<VehicleInfo> selectVehicleInfoList(VehicleInfo vehicleInfo) {
- return vehicleInfoMapper.selectVehicleInfoList(vehicleInfo);
+ List<VehicleInfo> list = vehicleInfoMapper.selectVehicleInfoListWithDepts(vehicleInfo);
+ // 鍒濆鍖栧欢杩熷姞杞界殑灞炴�э紝閬垮厤搴忓垪鍖栭棶棰�
+ for (VehicleInfo vehicle : list) {
+ vehicle.initializeLazyProperties();
+ }
+ return list;
}
/**
@@ -55,8 +97,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;
}
/**
@@ -65,9 +115,48 @@
* @param vehicleInfo 杞﹁締淇℃伅
* @return 缁撴灉
*/
+ /**
+ * 淇敼杞﹁締淇℃伅
+ * 娉ㄦ剰:
+ * - 濡傛灉闇�瑕佹洿鏂伴儴闂ㄥ叧鑱�,璇疯缃� vehicleInfo.deptIds
+ * - 濡傛灉涓嶉渶瑕佹洿鏂伴儴闂ㄥ叧鑱�(浠呮洿鏂拌溅杈嗗熀鏈俊鎭�),璇蜂繚鎸� vehicleInfo.deptIds = null
+ * - 杩欐牱鍙互閬垮厤骞跺彂鍚屾鏃剁殑姝婚攣闂
+ *
+ * @param vehicleInfo 杞﹁締淇℃伅
+ * @return 缁撴灉
+ */
@Override
+ @Transactional
public int updateVehicleInfo(VehicleInfo vehicleInfo) {
+ // 鍙湁褰� deptIds 涓嶄负 null 鏃舵墠鏇存柊閮ㄩ棬鍏宠仈(閬垮厤涓嶅繀瑕佺殑閿佺珵浜�)
+ if (vehicleInfo.getDeptIds() != null) {
+ // 鍏堝垹闄ゆ棫鐨勫叧鑱斿叧绯�
+ vehicleInfoMapper.deleteVehicleDeptByVehicleId(vehicleInfo.getVehicleId());
+
+ // 濡傛灉閫夋嫨浜嗗涓垎鍏徃,淇濆瓨鍒板叧鑱旇〃
+ if (!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 +180,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