Преглед на файлове

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

肖路 преди 1 месец
родител
ревизия
d17b20b715

+ 25 - 13
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/impl/CustomerInfoServiceImpl.java

@@ -537,27 +537,39 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
                 return false;
             }
             String platform = PlatformContext.getPlatform();
+            // 1. 提前校验名称是否存在 (核心修改点)
+            String customerName = bo.getCustomerName();
+            if (customerName == null || customerName.trim().isEmpty()) {
+                throw new IllegalArgumentException("客户名称不能为空");
+            }
 
-            boolean isNew = bo.getId() == null || bo.getId() <= 0;
+            // 构造查询条件
+            LambdaQueryWrapper<CustomerInfo> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(CustomerInfo::getCustomerName, customerName.trim());
 
-            // 1. 处理主表 CustomerInfo
-            CustomerInfo entity = MapstructUtils.convert(bo, CustomerInfo.class);
-            validEntityBeforeSave(entity);
+            // 执行查询
+            CustomerInfo existingCustomer = baseMapper.selectOne(queryWrapper);
 
-            boolean success;
+            boolean isNew = bo.getId() == null || bo.getId() <= 0;
+            CustomerInfo entity = null;
             if (isNew) {
-                success = baseMapper.insert(entity) > 0;
-                if (success) {
+                // --- 新增场景 ---
+                if (existingCustomer != null) {
+                    // 数据库中已存在同名用户
+                    throw new IllegalArgumentException("该客户已存在,请勿重复添加");
+                }
+                // 不存在,继续执行插入
+                entity = MapstructUtils.convert(bo, CustomerInfo.class);
+
+                int insertResult = baseMapper.insert(entity);
+                if (insertResult > 0) {
                     bo.setId(entity.getId()); // 回填ID
+                    return true;
+                } else {
+                    return false;
                 }
-            } else {
-                success = baseMapper.updateById(entity) > 0;
-            }
 
-            if (!success) {
-                return false;
             }
-
             Long customerId = entity.getId();
 
             /*新增客户时给每个客户创建自己的组织架构*/

+ 1 - 1
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/impl/SupplierBankServiceImpl.java

@@ -75,7 +75,7 @@ public class SupplierBankServiceImpl  extends ServiceImpl<SupplierBankMapper, Su
     private LambdaQueryWrapper<SupplierBank> buildQueryWrapper(SupplierBankBo bo) {
         Map<String, Object> params = bo.getParams();
         LambdaQueryWrapper<SupplierBank> lqw = Wrappers.lambdaQuery();
-        lqw.orderByAsc(SupplierBank::getId);
+        lqw.orderByDesc(SupplierBank::getId);
         lqw.eq(bo.getNum() != null, SupplierBank::getNum, bo.getNum());
         lqw.eq(StringUtils.isNotBlank(bo.getSupplierNo()), SupplierBank::getSupplierNo, bo.getSupplierNo());
         lqw.eq(bo.getSupplierId() != null, SupplierBank::getSupplierId, bo.getSupplierId());

+ 2 - 1
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/impl/SupplierBusinessInfoServiceImpl.java

@@ -1,6 +1,7 @@
 package org.dromara.customer.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.dromara.common.core.exception.ServiceException;
 import org.dromara.common.core.utils.DateUtils;
 import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.core.utils.StringUtils;
@@ -161,7 +162,7 @@ public class SupplierBusinessInfoServiceImpl  extends ServiceImpl<SupplierBusine
         // 2. 调用企查查接口
         CompanyInfoResponse response = QccUtils.getCompanyInfo(enterpriseName);
         if (response == null || response.getResult() == null) {
-            return null; // 或抛异常,根据业务需求
+            throw new ServiceException("未查到该企业信息");
         }
 
         // 3. 映射 QCC 数据到实体(注意:不设置 businessLicense)

+ 14 - 2
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/impl/SupplierInfoServiceImpl.java

@@ -111,6 +111,20 @@ public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, Sup
      */
     @Override
     public Boolean insertByBo(SupplierInfoBo bo) {
+        // 1. 判断 businessName 是否已存在
+        LambdaQueryWrapper<SupplierInfo> checkWrapper = new LambdaQueryWrapper<>();
+        checkWrapper.eq(SupplierInfo::getBusinessName, bo.getBusinessName());
+        Long count = baseMapper.selectCount(checkWrapper);
+        if (count > 0) {
+            throw new ServiceException("该企业工商信息已存在,不能重复添加");
+        }
+        //2.判断enterpriseName 是否已存在
+        LambdaQueryWrapper<SupplierInfo> checkWrapper1 = new LambdaQueryWrapper<>();
+        checkWrapper1.eq(SupplierInfo::getEnterpriseName, bo.getEnterpriseName());
+        Long count1 = baseMapper.selectCount(checkWrapper1);
+        if (count1 > 0) {
+            throw new ServiceException("该企业名称已存在,不能重复添加");
+        }
         LambdaQueryWrapper<SupplierInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
         // 按supplier_no降序排序,取第一条(最大值)
         lambdaQueryWrapper.select(SupplierInfo::getSupplierNo)
@@ -123,8 +137,6 @@ public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, Sup
         add.setSupplierNo(supplierNo);
         add.setCooperative(0L);
         boolean flag = baseMapper.insert(add) > 0;
-
-
         if (flag) {
             bo.setId(add.getId());
             // 解析 otherCustomers JSON 并保存工商信息

+ 1 - 0
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/impl/SupplyAreaServiceImpl.java

@@ -411,6 +411,7 @@ public class SupplyAreaServiceImpl  extends ServiceImpl<SupplyAreaMapper, Supply
 
             // 2.3 批量插入正式库(MyBatis-Plus自带saveBatch,高效无冗余)
             try {
+                baseMapper.delete(new LambdaQueryWrapper<SupplyArea>().eq(SupplyArea::getSupplierId, supplierId));
                 boolean b = baseMapper.insertBatch(supplyAreaOfficialList);
                 return b;
             } catch (Exception e) {

+ 1 - 14
ruoyi-modules/ruoyi-order/src/main/java/org/dromara/order/controller/pc/PcOrderController.java

@@ -413,20 +413,7 @@ public class PcOrderController extends BaseController {
             mainBo.setOrderProductBos(orderProductBos);
 
             // 5. 保存订单(关键:成功后再删除购物车)
-            Long orderId = orderMainService.insertByBo(mainBo);
-            if (orderId != null && orderId > 0) {
-                //初始化审批流程
-                Boolean initOrderFlow = orderCustomerFlowService.initOrderFlow(orderId);
-                if (initOrderFlow) {
-                    orderMainService.update(Wrappers.lambdaUpdate(OrderMain.class).eq(OrderMain::getId, orderId).set(OrderMain::getOrderStatus, 1));
-                }
-                if (bo.getPlaceOrderType() == 1) {
-                    // 成功下单后,删除对应的购物车项
-                    remoteProductShoppingCartService.deleteWithValidByIds(bo.getProductShoppingCartId());
-                }
-            } else {
-                throw new RuntimeException("订单创建失败");
-            }
+            Long orderId = orderMainService.insertOrder(bo, mainBo);
 
             return R.ok(orderId); // 正确返回 ID
         } catch (Exception e) {

+ 3 - 0
ruoyi-modules/ruoyi-order/src/main/java/org/dromara/order/service/IOrderMainService.java

@@ -7,6 +7,7 @@ import org.dromara.common.mybatis.core.page.TableDataInfo;
 import org.dromara.order.domain.OrderMain;
 import org.dromara.order.domain.bo.OrderMainBo;
 import org.dromara.order.domain.bo.OrderProductBo;
+import org.dromara.order.domain.bo.PcSubmitOrderBo;
 import org.dromara.order.domain.vo.*;
 import org.dromara.order.utils.kd100.domain.TrackData;
 
@@ -72,6 +73,8 @@ public interface IOrderMainService extends IService<OrderMain> {
      */
     Boolean updateByBo(OrderMainBo bo);
 
+    Long insertOrder(PcSubmitOrderBo bo, OrderMainBo mainBo);
+
     /**
      * 订单确认
      *

+ 54 - 11
ruoyi-modules/ruoyi-order/src/main/java/org/dromara/order/service/impl/OrderDeliverServiceImpl.java

@@ -234,20 +234,63 @@ public class OrderDeliverServiceImpl extends ServiceImpl<OrderDeliverMapper, Ord
 
             orderMainMapper.update(null, updateWrapper);
 
-            // 3. 【新增逻辑】如果存在父订单,同步更新父订单状态
+            // 3. 【新增逻辑】如果存在父订单,根据策略同步更新父订单状态
             if (currentOrder.getParentOrderId() != null) {
-                // “同步更新”处理,即直接设为相同状态。
-
-                LambdaUpdateWrapper<OrderMain> parentUpdateWrapper = new LambdaUpdateWrapper<OrderMain>()
-                    .eq(OrderMain::getId, currentOrder.getParentOrderId())
-                    .set(OrderMain::getOrderStatus, newStatus);
-
-                orderMainMapper.update(null, parentUpdateWrapper);
-
-                // 可选:如果需要递归更新更上层的父订单(如果存在多级嵌套),可以在此处加循环或递归调用
+                Long parentId = currentOrder.getParentOrderId();
+                boolean shouldUpdateParent = false;
+                String targetParentStatus = null;
+
+                // 场景 1: 当前子单变为 "已发货" (SHIPPED)
+                if (OrderStatus.SHIPPED.getCode().equals(newStatus)) {
+                    // 逻辑:查询该父订单下所有的子订单
+                    List<OrderMain> siblingOrders = orderMainMapper.selectList(
+                        new LambdaQueryWrapper<OrderMain>()
+                            .eq(OrderMain::getParentOrderId, parentId)
+                            .select(OrderMain::getOrderStatus) // 只查状态字段,优化性能
+                    );
+
+                    // 校验:是否所有子订单都已经是 "已发货"
+                    if (!siblingOrders.isEmpty()) {
+                        boolean allShipped = siblingOrders.stream()
+                            .allMatch(order -> OrderStatus.SHIPPED.getCode().equals(order.getOrderStatus()));
+
+                        if (allShipped) {
+                            shouldUpdateParent = true;
+                            targetParentStatus = OrderStatus.SHIPPED.getCode();
+                        }
+                        // 如果并非全部发货,则父订单不应更新为 SHIPPED (保持原状或维持 PARTIALLY_SHIPPED)
+                    }
+
+                }
+                // 场景 2: 当前子单变为 "部分发货" (PARTIALLY_SHIPPED)
+                else if (OrderStatus.PARTIALLY_SHIPPED.getCode().equals(newStatus)) {
+                    // 逻辑:子单部分发货,父单必然也是部分发货,直接标记需要更新
+                    shouldUpdateParent = true;
+                    targetParentStatus = OrderStatus.PARTIALLY_SHIPPED.getCode();
+                }
+                // 场景 3: 状态无变化 (保持原状态)
+                else if (currentOrder.getOrderStatus().equals(newStatus)) {
+                    // 逻辑:状态没变,不需要处理父订单
+                    shouldUpdateParent = false;
+                }
+                // [可选扩展] 场景 4: 其他状态 (如取消 CANCELLED, 关闭 CLOSED 等)
+                // 如果你的业务要求子单取消父单也必须取消,可以在这里添加 else if 分支
+                // else if (OrderStatus.CANCELLED.getCode().equals(newStatus)) { ... }
+
+                // 执行父订单更新
+                if (shouldUpdateParent && targetParentStatus != null) {
+                    LambdaUpdateWrapper<OrderMain> parentUpdateWrapper = new LambdaUpdateWrapper<OrderMain>()
+                        .eq(OrderMain::getId, parentId)
+                        // 优化:只有当父订单当前状态不等于目标状态时才更新,避免无效写操作
+                        .ne(OrderMain::getOrderStatus, targetParentStatus)
+                        .set(OrderMain::getOrderStatus, targetParentStatus);
+
+                    // 再次确认父订单存在且状态不同再执行,ne 条件已经涵盖了大部分,但为了严谨可以执行 update
+                    // 如果 ne 条件不满足,update 返回 0,不会报错
+                    orderMainMapper.update(null, parentUpdateWrapper);
+                }
             }
 
-
             log.info("新增订单发货单成功:{}", bo.getId());
             return true;
         } catch (RuntimeException e) {

+ 64 - 10
ruoyi-modules/ruoyi-order/src/main/java/org/dromara/order/service/impl/OrderMainServiceImpl.java

@@ -32,16 +32,16 @@ import org.dromara.order.domain.OrderMainCrrcExt;
 import org.dromara.order.domain.OrderProduct;
 import org.dromara.order.domain.bo.OrderMainBo;
 import org.dromara.order.domain.bo.OrderProductBo;
+import org.dromara.order.domain.bo.PcSubmitOrderBo;
 import org.dromara.order.domain.dto.AssignmentStatsDto;
 import org.dromara.order.domain.vo.*;
 import org.dromara.order.mapper.*;
-import org.dromara.order.service.IOrderDeliverService;
-import org.dromara.order.service.IOrderMainCrrcExtService;
-import org.dromara.order.service.IOrderMainService;
+import org.dromara.order.service.*;
 import org.dromara.order.utils.kd100.Kd100Util;
 import org.dromara.order.utils.kd100.domain.QueryTrackDTO;
 import org.dromara.order.utils.kd100.domain.TrackData;
 import org.dromara.order.utils.kd100.domain.TrackVO;
+import org.dromara.product.api.RemoteProductShoppingCartService;
 import org.dromara.system.api.RemoteComLogisticsCompanyService;
 import org.dromara.system.api.RemoteDeptService;
 import org.dromara.system.api.RemoteUserService;
@@ -79,6 +79,16 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
     @DubboReference
     private RemoteCustomerSalesService remoteCustomerSalesService;
 
+    //客户订单流程
+    private final IOrderCustomerFlowService orderCustomerFlowService;
+
+    @DubboReference
+    private RemoteProductShoppingCartService remoteProductShoppingCartService;
+
+    private final IOrderCustomerFlowLinkService orderCustomerFlowLinkService;
+
+    private final IOrderCustomerFlowNodeLinkService orderCustomerFlowNodeLinkService;
+
     private final OrderMainMapper baseMapper;
 
     private final OrderProductMapper orderProductMapper;
@@ -465,6 +475,35 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
         }
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Long insertOrder(PcSubmitOrderBo bo, OrderMainBo mainBo) {
+        // 1. 插入主订单,获取生成的 ID
+        Long orderId = this.insertByBo(mainBo);
+
+        // 2. 校验插入是否成功
+        if (orderId != null && orderId > 0) {
+            // 3. 初始化审批流程
+            Boolean initOrderFlow = orderCustomerFlowService.initOrderFlow(orderId);
+
+            // 4. 如果流程初始化成功,更新订单状态 (注意:这里再次触发了数据库更新)
+            if (initOrderFlow) {
+                this.update(Wrappers.lambdaUpdate(OrderMain.class)
+                    .eq(OrderMain::getId, orderId)
+                    .set(OrderMain::getOrderStatus, 1)); // 假设 1 代表某种特定状态,需确认枚举值
+            }
+
+            // 5. 如果是从购物车下单,删除购物车数据
+            if (bo.getPlaceOrderType() == 1) {
+                remoteProductShoppingCartService.deleteWithValidByIds(bo.getProductShoppingCartId());
+            }
+
+            return orderId;
+        } else {
+            // 插入失败,抛出异常触发事务回滚
+            throw new RuntimeException("订单创建失败:未能生成有效的订单ID");
+        }
+    }
 
     /**
      * 订单确认
@@ -724,20 +763,35 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Boolean batchConfirmation(Set<Long> ids) {
-        // 2. 参数校验
+        // 1. 参数校验
         if (CollectionUtils.isEmpty(ids)) {
             return true;
         }
 
+        // 将 Set 转为 List 以便 Wrapper 使用 (MyBatis-Plus in 方法通常接受 Collection)
+        List<Long> idList = new ArrayList<>(ids);
+
+        // 2. 构造更新条件
         LambdaUpdateWrapper<OrderMain> updateWrapper = new LambdaUpdateWrapper<>();
-        updateWrapper.in(OrderMain::getId, ids)
-            .eq(OrderMain::getOrderStatus, OrderStatus.SHIPPED.getCode()) // 只有已发货的订单才能确认收货
-            .set(OrderMain::getOrderStatus, OrderStatus.COMPLETED.getCode());
 
-        // 执行更新
-        boolean updateSuccess = this.update(updateWrapper);
+        // 设置更新后的值
+        updateWrapper.set(OrderMain::getOrderStatus, OrderStatus.COMPLETED.getCode());
+
+        // 构建 WHERE 条件逻辑:
+        // (id IN (...) OR parentOrderId IN (...)) AND orderStatus = SHIPPED
+        updateWrapper.and(wrapper -> wrapper
+                .in(OrderMain::getId, idList)
+                .or()
+                .in(OrderMain::getParentOrderId, idList)
+            )
+            // 只有已发货的订单才能确认收货 (同时限制父单和子单的原状态)
+            .eq(OrderMain::getOrderStatus, OrderStatus.SHIPPED.getCode());
+
+        // 3. 执行更新
+        // 如果至少有一行被更新,则视为成功
+        int updateCount = baseMapper.update(updateWrapper);
 
-        return updateSuccess;
+        return updateCount > 0;
     }
 
     @Override