Bläddra i källkod

Merge remote-tracking branch 'origin/main' into main

zhangwei 1 vecka sedan
förälder
incheckning
38b90f81c0

+ 1 - 1
edu-travel-adapter/edu-travel-adapter-currency/src/main/java/edu/travel/adapter/service/currency/CurrencyAdapter.java → edu-travel-adapter/edu-travel-adapter-country/src/main/java/edu/travel/adapter/service/country/CurrencyAdapter.java

@@ -1,4 +1,4 @@
-package edu.travel.adapter.service.currency;
+package edu.travel.adapter.service.country;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import edu.travel.adapter.annotation.AdapterAnnotation;

+ 4 - 4
edu-travel-oauth/src/main/resources/bootstrap-dev.yml

@@ -2,13 +2,13 @@ spring:
   cloud:
     nacos:
       discovery:
-        server-addr: localhost:8848,localhost:8849,localhost:8858
-        namespace: edu-@env@
+        server-addr: 192.168.1.44:8848,192.168.1.44:8849,192.168.1.44:8858
+        namespace: yangzheng-@env@
       config:
         file-extension: yaml
-        server-addr: localhost:8848,localhost:8849,localhost:8858
+        server-addr: 192.168.1.44:8848,192.168.1.44:8849,192.168.1.44:8858
         refresh-enabled: true
-        namespace: edu-@env@
+        namespace: yangzheng-@env@
         shared-configs:
           - data-id: mybatis-config-dev.yaml
             group: DEFAULT_GROUP

+ 115 - 57
edu-travel-service/edu-travel-service-warehouse/src/main/java/edu/travel/warehouse/service/impl/ShopWarehouseServiceImpl.java

@@ -1,5 +1,7 @@
 package edu.travel.warehouse.service.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -23,6 +25,8 @@ import edu.travel.warehouse.mapper.ShopWarehouseStaffMapper;
 import edu.travel.warehouse.service.ShopWarehouseService;
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -290,88 +294,142 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
     }
 
     /**
-     * 连表新增
+     * 新增连表
+     * @param entity
+     * @return
      */
     @Override
-    @Transactional // 确保方法在事务中执行
+    @Transactional // 确保方法在事务中执行
     public RPCBaseResponse<ShopWarehouseVo> saveAllForm(ShopWarehouseSaveDto entity) {
-        // 创建并设置仓库信息
+        // 创建一个新的 ShopWarehouse 实体
         ShopWarehouse warehouse = new ShopWarehouse();
-        copyWarehouseProperties(entity, warehouse);
-
-        // 插入仓库信息
-        shopWarehouseMapper.insert(warehouse);
 
-        // 保存员工角色信息
-        saveStaffRoles(entity.getStaffList(), warehouse.getId());
+        // 获取当前用户 ID
+        Long currentUserId = getCurrentUserId(); // 获取当前用户 ID
 
-        // 构建返回对象
-        return buildWarehouseResponse(warehouse);
-    }
+        // 将 DTO 中的属性复制到实体对象中
+        copyWarehouseProperties(entity, warehouse);
+        warehouse.setCreateUserId(String.valueOf(currentUserId)); // 填充创建人 ID
 
-    // 从 DTO 复制属性到实体
-    private void copyWarehouseProperties(ShopWarehouseSaveDto source, ShopWarehouse target) {
-        target.setParentId(source.getParentId());
-        target.setWarehouseName(source.getWarehouseName());
-        target.setLongitude(source.getLongitude());
-        target.setLatitude(source.getLatitude());
-        target.setCountryServeId(source.getCountryServeId());
-        target.setDetailedAddress(source.getDetailedAddress());
-        target.setStatus(source.getStatus());
-        // 其他需要设置的字段...
-    }
+        // 插入仓库信息到数据库
+        shopWarehouseMapper.insert(warehouse);
 
-    // 保存员工角色
-    private void saveStaffRoles(List<ShopWarehouseStaffDto> staffList, Long warehouseId) {
-        if (staffList != null && !staffList.isEmpty()) {
-            for (ShopWarehouseStaffDto staffDto : staffList) {
-                ShopWarehouseStaff staff = new ShopWarehouseStaff();
-                staff.setWarehouseId(warehouseId);
-                staff.setUserId(staffDto.getUserId());
-                staff.setRoleId(staffDto.getRoleId());
-                shopWarehouseStaffMapper.insert(staff);
-            }
+        // 如果存在员工列表,则保存员工角色信息
+        if (entity.getStaffList() != null && !entity.getStaffList().isEmpty()) {
+            saveStaffRoles(entity.getStaffList(), warehouse.getId(), currentUserId); // 传入用户 ID
         }
-    }
 
-    // 构建返回对象
-    private RPCBaseResponse<ShopWarehouseVo> buildWarehouseResponse(ShopWarehouse warehouse) {
+        // 构建并返回响应对象
         ShopWarehouseVo warehouseVo = new ShopWarehouseVo();
         warehouseVo.setId(warehouse.getId());
         warehouseVo.setWarehouseName(warehouse.getWarehouseName());
+        warehouseVo.setProject(warehouse.getProject());
+        warehouseVo.setCreateTime(warehouse.getCreateTime());
+        warehouseVo.setCreateUserId(warehouse.getCreateUserId());
+        warehouseVo.setUpdateTime(warehouse.getUpdateTime());
+        warehouseVo.setUpdateUserId(warehouse.getUpdateUserId());
+        warehouseVo.setDeleteFlag(warehouse.getDeleteFlag());
+        warehouseVo.setParentId(warehouse.getParentId());
+        warehouseVo.setLongitude(warehouse.getLongitude());
+        warehouseVo.setLatitude(warehouse.getLatitude());
+        warehouseVo.setCountryServeId(warehouse.getCountryServeId());
+        warehouseVo.setDetailedAddress(warehouse.getDetailedAddress());
+        warehouseVo.setStatus(warehouse.getStatus());
         // 其他字段映射...
+
+        // 返回成功的响应
         return new RPCBaseResponse<>(200, "SUCCESS", warehouseVo);
     }
 
-
-
-    /**
-     * 更新
-     */
     @Override
-    @Transactional // 确保此方法在事务中执行
+    @Transactional // 确保方法在事务中执行
     public RPCBaseResponse<ShopWarehouseVo> updateWarehouse(ShopWarehouseSaveDto entity) {
-        // 更新仓库信息
-        ShopWarehouse warehouse = new ShopWarehouse();
-        warehouse.setId(entity.getId());
-        copyWarehouseProperties(entity, warehouse);
-        shopWarehouseMapper.updateById(warehouse);
+        // 根据 ID 查找现有的仓库信息
+        ShopWarehouse existingWarehouse = shopWarehouseMapper.selectById(entity.getId());
+
+        // 如果找不到该仓库,返回错误响应
+        if (existingWarehouse == null) {
+            return new RPCBaseResponse<>(404, "NULL", null);
+        }
+
+        // 更新现有仓库的属性
+        copyWarehouseProperties(entity, existingWarehouse);
+
+        // 获取当前用户 ID
+        Long currentUserId = getCurrentUserId(); // 获取当前用户 ID
+        existingWarehouse.setUpdateUserId(String.valueOf(currentUserId)); // 填充更新人 ID
+
+        // 更新仓库信息到数据库
+        shopWarehouseMapper.updateById(existingWarehouse);
 
         // 更新员工角色信息
-        updateStaffRoles(entity.getStaffList(), entity.getId());
+        if (entity.getStaffList() != null) {
+            // 先删除原有员工信息
+            shopWarehouseStaffMapper.deleteByWarehouseId(existingWarehouse.getId());
+            // 然后插入新的员工角色信息
+            saveStaffRoles(entity.getStaffList(), existingWarehouse.getId(), currentUserId); // 传入用户 ID
+        }
 
-        // 构建返回对象
-        return buildWarehouseResponse(warehouse);
-    }
+        // 构建并返回响应对象
+        ShopWarehouseVo warehouseVo = new ShopWarehouseVo();
+        warehouseVo.setId(existingWarehouse.getId());
+        warehouseVo.setWarehouseName(existingWarehouse.getWarehouseName());
+        warehouseVo.setProject(existingWarehouse.getProject());
+        warehouseVo.setCreateTime(existingWarehouse.getCreateTime());
+        warehouseVo.setCreateUserId(existingWarehouse.getCreateUserId());
+        warehouseVo.setUpdateTime(existingWarehouse.getUpdateTime());
+        warehouseVo.setUpdateUserId(existingWarehouse.getUpdateUserId());
+        warehouseVo.setDeleteFlag(existingWarehouse.getDeleteFlag());
+        warehouseVo.setParentId(existingWarehouse.getParentId());
+        warehouseVo.setLongitude(existingWarehouse.getLongitude());
+        warehouseVo.setLatitude(existingWarehouse.getLatitude());
+        warehouseVo.setCountryServeId(existingWarehouse.getCountryServeId());
+        warehouseVo.setDetailedAddress(existingWarehouse.getDetailedAddress());
+        warehouseVo.setStatus(existingWarehouse.getStatus());
+        // 其他字段映射...
 
-    // 更新员工角色
-    private void updateStaffRoles(List<ShopWarehouseStaffDto> staffList, Long warehouseId) {
-        // 删除原有的员工记录
-        shopWarehouseStaffMapper.deleteByWarehouseId(warehouseId);
+        // 返回成功的响应
+        return new RPCBaseResponse<>(200, "更新成功", warehouseVo);
+    }
 
-        // 插入新的员工角色信息
-        saveStaffRoles(staffList, warehouseId);
+    // 复制仓库属性的方法
+    private void copyWarehouseProperties(ShopWarehouseSaveDto source, ShopWarehouse target) {
+        target.setParentId(source.getParentId());
+        target.setWarehouseName(source.getWarehouseName());
+        target.setLongitude(source.getLongitude());
+        target.setLatitude(source.getLatitude());
+        target.setCountryServeId(source.getCountryServeId());
+        target.setDetailedAddress(source.getDetailedAddress());
+        target.setStatus(source.getStatus());
+        if (source.getProject() != null) {
+            target.setProject(source.getProject());
+        }
+        // 其他需要设置的字段...
     }
 
+    // 获取当前用户 ID 的方法
+    private Long getCurrentUserId() {
+        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+        Object principal = authentication.getPrincipal();
+        Long userId = null;
+
+        if (!(principal instanceof String && "anonymousUser".equals(principal))) {
+            String jsonString = JSON.toJSONString(principal);
+            JSONObject jsonObject = JSON.parseObject(jsonString);
+            userId = jsonObject.getLong("id");
+        }
 
+        return userId;
+    }
+    // 保存员工角色信息的方法
+    private void saveStaffRoles(List<ShopWarehouseStaffDto> staffList, Long warehouseId, Long currentUserId) {
+        for (ShopWarehouseStaffDto staffDto : staffList) {
+            ShopWarehouseStaff staff = new ShopWarehouseStaff();
+            staff.setWarehouseId(warehouseId);
+            staff.setUserId(staffDto.getUserId());
+            staff.setRoleId(staffDto.getRoleId());
+            staff.setCreateUserId(String.valueOf(currentUserId)); // 设置创建用户 ID
+            shopWarehouseStaffMapper.insert(staff);
+        }
+    }
 }