ソースを参照

feat(order): 新增订单数据转JSON功能并优化客户信息查询

- 在OrderMainService中新增orderMainInfoToJson方法实现订单信息转JSON
- 添加SalSO、SalSODet、SOComProd实体类用于ERP数据推送
- 重构ClientSiteServiceImpl增加远程客户服务引用和客户信息查询
- 优化ProtocolInfoServiceImpl中的销售员和服务员信息获取逻辑
- 删除废弃的RemoteCustInfoService接口及其实现类
- 更新RemoteOrderInfoService接口增加订单和退货详情JSON转换方法
- 在CategoryServiceImpl中添加客户ID字段映射
- 引入JSON工具类和日期工具类进行数据格式转换
hurx 6 時間 前
コミット
ca56262c31

+ 0 - 6
ruoyi-api/ruoyi-api-external/src/main/java/org/dromara/external/api/service/RemoteCustInfoService.java

@@ -1,6 +0,0 @@
-package org.dromara.external.api.service;
-
-public interface RemoteCustInfoService {
-
-    String customerInfoJson();
-}

+ 15 - 0
ruoyi-api/ruoyi-api-order/src/main/java/org/dromara/product/api/RemoteOrderInfoService.java

@@ -48,4 +48,19 @@ public interface RemoteOrderInfoService {
      * @return 订单统计数据
      */
     PartnerOrderIndexDto getPartnerOrderIndex(Long partnerId);
+
+    /**
+     * 获取订单详情JSON
+     * @param orderId 订单ID
+     * @return 订单详情JSON
+     */
+    String orderMainInfoToJson(Long orderId);
+
+    /**
+     * 获取退货详情JSON
+     * @param returnId 退货ID
+     * @return 退货详情JSON
+     */
+    String orderReturnToJson(Long returnId);
+
 }

+ 50 - 0
ruoyi-api/ruoyi-api-order/src/main/java/org/dromara/product/api/domain/push/SOComProd.java

@@ -0,0 +1,50 @@
+package org.dromara.product.api.domain.push;
+
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * 组合产品子件 - ERP推送
+ *
+ * @author LionLi
+ * @date 2026-06-10
+ */
+@Data
+public class SOComProd implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    /** 折数(%) */
+    private BigDecimal DiscRt;
+
+    /** 金额 */
+    private BigDecimal OAmt;
+
+    /** 含税金额 */
+    private BigDecimal OAmtWTax;
+
+    /** 备注 */
+    private String Remark;
+
+    /** 标识号 */
+    private Integer RowCd;
+
+    /** 序号 */
+    private Integer RowNo;
+
+    /** 交易价 */
+    private BigDecimal SPr;
+
+    /** 交易数量 */
+    private BigDecimal SQty;
+
+    /** 子件编号 */
+    private String SubProdId;
+
+    /** 子件规格 */
+    private String SubProdSpec;
+}

+ 61 - 0
ruoyi-api/ruoyi-api-order/src/main/java/org/dromara/product/api/domain/push/SalSO.java

@@ -0,0 +1,61 @@
+package org.dromara.product.api.domain.push;
+
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+
+/**
+ * 订单主表 - ERP推送
+ *
+ * @author LionLi
+ * @date 2026-06-10
+ */
+@Data
+public class SalSO implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    /** 单据日期 */
+    private Integer BlDa;
+
+    /** 公司 */
+    private String CoId;
+
+    /** 交易币别 */
+    private String CurId;
+
+    /** 客户 */
+    private String CustId;
+
+    /** 业务人员 */
+    private String PerId;
+
+    /** 送货地址编号 */
+    private String AddrNo;
+
+    /** 单据编号 */
+    private String BlNo;
+
+    /** 下单日期 */
+    private Integer CU_xdrq;
+
+    /** 客户订单 */
+    private String CustOrd;
+
+    /** 单价含税 */
+    private Boolean IsPrWTax;
+
+    /** 所属项目 */
+    private String ProjId;
+
+    /** 备注 */
+    private String Remark;
+
+    /** 单据类型 */
+    private String TypeId;
+
+    /** 商城订单号 */
+    private String X_WebOrdNo;
+}

+ 62 - 0
ruoyi-api/ruoyi-api-order/src/main/java/org/dromara/product/api/domain/push/SalSODet.java

@@ -0,0 +1,62 @@
+package org.dromara.product.api.domain.push;
+
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * 订单明细 - ERP推送
+ *
+ * @author LionLi
+ * @date 2026-06-10
+ */
+@Data
+public class SalSODet implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    /** 单据编号 */
+    private String BlNo;
+
+    /** 预出库日 */
+    private Integer PreDlvDa;
+
+    /** 税码编号 */
+    private String TaxId;
+
+    /** 外调 */
+    private Boolean IsOutAllot;
+
+    /** 类型 */
+    private Integer IxTy;
+
+    /** 产品编号 */
+    private String ProdId;
+
+    /** 分录备注 */
+    private String Remark;
+
+    /** 标识号 */
+    private Integer RowCd;
+
+    /** 序号 */
+    private Integer RowNo;
+
+    /** 交易价 */
+    private BigDecimal SPr;
+
+    /** 交易数量 */
+    private BigDecimal SQty;
+
+    /** 交易单位编号 */
+    private String SUiId;
+
+    /** 基本数量 */
+    private BigDecimal Qty;
+
+    /** 仓库编号 */
+    private String WhsId;
+}

+ 0 - 15
ruoyi-modules/ruoyi-external/src/main/java/org/dromara/external/dubbo/RemoteCustInfoServiceImpl.java

@@ -1,15 +0,0 @@
-package org.dromara.external.dubbo;
-
-import org.apache.dubbo.config.annotation.DubboReference;
-import org.dromara.customer.api.RemoteCustomerService;
-import org.dromara.external.api.service.RemoteCustInfoService;
-
-public class RemoteCustInfoServiceImpl implements RemoteCustInfoService {
-
-    @DubboReference
-    private RemoteCustomerService remoteCustomerService;
-    @Override
-    public String customerInfoJson() {
-        return remoteCustomerService.customerInfoJson(null);
-    }
-}

+ 10 - 0
ruoyi-modules/ruoyi-order/src/main/java/org/dromara/order/dubbo/RemoteOrderInfoServiceImpl.java

@@ -335,4 +335,14 @@ public class RemoteOrderInfoServiceImpl implements RemoteOrderInfoService {
         dto.setLatestShipments(shipments);
         return dto;
     }
+
+    @Override
+    public String orderMainInfoToJson(Long orderId) {
+        return orderMainService.orderMainInfoToJson(orderId);
+    }
+
+    @Override
+    public String orderReturnToJson(Long returnId) {
+        return orderReturnService.orderReturnToJson(returnId);
+    }
 }

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

@@ -197,4 +197,6 @@ public interface IOrderMainService extends IService<OrderMain> {
      */
     R<PurchaseDetailVo> purchaseDetail(Long customerId);
 
+    String orderMainInfoToJson(Long orderId);
+
 }

+ 117 - 1
ruoyi-modules/ruoyi-order/src/main/java/org/dromara/order/service/impl/OrderMainServiceImpl.java

@@ -2,6 +2,7 @@ package org.dromara.order.service.impl;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -17,6 +18,7 @@ import org.dromara.common.core.domain.R;
 import org.dromara.common.core.enums.*;
 import org.dromara.common.core.exception.ServiceException;
 import org.dromara.common.core.exception.api.ZhongcheException;
+import org.dromara.common.core.utils.DateUtils;
 import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.core.utils.ObjectUtils;
 import org.dromara.common.core.utils.StringUtils;
@@ -49,6 +51,9 @@ import org.dromara.order.utils.kd100.domain.TrackVO;
 import org.dromara.product.api.RemoteProductService;
 import org.dromara.product.api.RemoteProductShoppingCartService;
 import org.dromara.product.api.domain.ProductVo;
+import org.dromara.product.api.domain.push.SOComProd;
+import org.dromara.product.api.domain.push.SalSO;
+import org.dromara.product.api.domain.push.SalSODet;
 import org.dromara.system.api.*;
 import org.dromara.system.api.model.LoginUser;
 import org.mybatis.spring.MyBatisSystemException;
@@ -99,6 +104,12 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
     @DubboReference
     private RemoteComDeptService remoteComDeptService;
 
+    @DubboReference
+    private RemoteComCompanyService remoteComCompanyService;
+
+    @DubboReference
+    private RemoteComWarehouseService remoteComWarehouseService;
+
     private RemoteErpStaffService remoteErpStaffService;
 
     @DubboReference
@@ -711,6 +722,7 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
             // 5. 批量插入订单商品
             orderProductMapper.insertBatch(orderProducts);
 
+            orderMainInfoToJson(orderId);
             log.info("成功新增订单,ID: {}", orderId);
             return orderId;
         } catch (RuntimeException e) {
@@ -817,7 +829,7 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
             if (bo.getPlaceOrderType() == 1) {
                 remoteProductShoppingCartService.deleteWithValidByIds(bo.getProductShoppingCartId());
             }
-
+            orderMainInfoToJson(orderId);
             return orderId;
         } else {
             // 插入失败,抛出异常触发事务回滚
@@ -2508,4 +2520,108 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
             .setData(data3).setColor("#f4c542").setType("line"));
         return list;
     }
+
+    @Override
+    public String orderMainInfoToJson(Long orderId) {
+        OrderMainVo orderMain = queryById(orderId);
+        if (orderMain == null) {
+            return "{}";
+        }
+
+        // 查询客户信息
+        CustomerInfoDTO customerInfo = null;
+        if (orderMain.getCustomerId() != null) {
+            customerInfo = remoteCustomerService.selectCustomerInfoById(orderMain.getCustomerId());
+        }
+
+        // 1. 映射 SalSO
+        SalSO salSO = new SalSO();
+        if (orderMain.getOrderTime() != null) {
+            salSO.setBlDa(Integer.parseInt(DateUtils.parseDateToStr(FormatsType.YYYYMMDD, orderMain.getOrderTime())));
+        }
+        if (customerInfo != null && customerInfo.getBelongCompanyId() != null) {
+            salSO.setCoId(remoteComCompanyService.selectCompanyCodeById(customerInfo.getBelongCompanyId()));
+        }
+        salSO.setCurId(customerInfo != null && StringUtils.isNotBlank(customerInfo.getCurrencyCode()) ? customerInfo.getCurrencyCode() : "");
+        salSO.setCustId(orderMain.getCustomerCode() != null ? orderMain.getCustomerCode() : "");
+        if (customerInfo != null && customerInfo.getSalesPersonId() != null) {
+            salSO.setPerId(remoteComStaffService.selectStaffCodeById(customerInfo.getSalesPersonId()));
+        }
+        if (orderMain.getShippingAddressId() != null) {
+            salSO.setAddrNo(remoteCustomerService.selectCustomerShippingAddressNoById(orderMain.getShippingAddressId()));
+        }
+        salSO.setBlNo(orderMain.getOrderNo() != null ? orderMain.getOrderNo() : "");
+        if (orderMain.getOrderTime() != null) {
+            salSO.setCU_xdrq(Integer.parseInt(DateUtils.parseDateToStr(FormatsType.YYYYMMDD, orderMain.getOrderTime())));
+        }
+        salSO.setCustOrd(orderMain.getDataSource() != null ? orderMain.getDataSource() : "");
+        salSO.setIsPrWTax(true);
+        salSO.setProjId(orderMain.getProjectOrderNo() != null ? orderMain.getProjectOrderNo() : "");
+        salSO.setRemark(orderMain.getRemark() != null ? orderMain.getRemark() : "");
+        salSO.setTypeId(orderMain.getOrderType() != null ? orderMain.getOrderType() : "");
+        salSO.setX_WebOrdNo(orderMain.getOrderNo() != null ? orderMain.getOrderNo() : "");
+
+        // 2. 映射 SalSODet 列表(主商品,parentItemId == null)
+        List<SalSODet> salSODetList = new ArrayList<>();
+        List<OrderProductVo> products = orderMain.getOrderProductList();
+        if (CollUtil.isNotEmpty(products)) {
+            int rowNo = 1;
+            for (OrderProductVo item : products) {
+                // 只处理主商品
+                if (item.getParentItemId() != null) {
+                    continue;
+                }
+                SalSODet det = new SalSODet();
+                det.setBlNo(orderMain.getOrderNo() != null ? orderMain.getOrderNo() : "");
+                if (item.getPreDeliveryDate() != null) {
+                    det.setPreDlvDa(Integer.parseInt(DateUtils.parseDateToStr(FormatsType.YYYYMMDD, item.getPreDeliveryDate())));
+                }
+                det.setTaxId("");
+                det.setIsOutAllot(false);
+                det.setIxTy(1);
+                det.setProdId(item.getProductNo() != null ? item.getProductNo() : "");
+                det.setRemark(item.getRemark() != null ? item.getRemark() : "");
+                det.setRowCd(item.getId() != null ? item.getId().intValue() : null);
+                det.setRowNo(rowNo++);
+                det.setSPr(item.getOrderPrice() != null ? item.getOrderPrice() : BigDecimal.ZERO);
+                det.setSQty(item.getOrderQuantity() != null ? BigDecimal.valueOf(item.getOrderQuantity()) : BigDecimal.ZERO);
+                det.setSUiId(item.getProductUnit() != null ? item.getProductUnit() : "");
+                det.setQty(item.getOrderQuantity() != null ? BigDecimal.valueOf(item.getOrderQuantity()) : BigDecimal.ZERO);
+                if (orderMain.getWarehouseId() != null) {
+                    det.setWhsId(remoteComWarehouseService.getWarehouseNoById(orderMain.getWarehouseId()));
+                }
+                salSODetList.add(det);
+            }
+        }
+
+        // 3. 映射 SOComProd 列表(组合子件,parentItemId != null)
+        List<SOComProd> soComProdList = new ArrayList<>();
+        if (CollUtil.isNotEmpty(products)) {
+            int rowNo = 1;
+            for (OrderProductVo item : products) {
+                if (item.getRootItemId() == null) {
+                    continue;
+                }
+                SOComProd com = new SOComProd();
+                com.setDiscRt(BigDecimal.ZERO);
+                com.setOAmt(item.getSubtotal() != null ? item.getSubtotal() : BigDecimal.ZERO);
+                com.setOAmtWTax(item.getSubtotal() != null ? item.getSubtotal() : BigDecimal.ZERO);
+                com.setRemark(item.getRemark() != null ? item.getRemark() : "");
+                com.setRowCd(item.getId() != null ? item.getId().intValue() : null);
+                com.setRowNo(rowNo++);
+                com.setSPr(item.getOrderPrice() != null ? item.getOrderPrice() : BigDecimal.ZERO);
+                com.setSQty(item.getOrderQuantity() != null ? BigDecimal.valueOf(item.getOrderQuantity()) : BigDecimal.ZERO);
+                com.setSubProdId(item.getProductNo() != null ? item.getProductNo() : "");
+                com.setSubProdSpec(item.getProductName() != null ? item.getProductName() : "");
+                soComProdList.add(com);
+            }
+        }
+
+        // 4. 组装返回JSON
+        Map<String, Object> result = new LinkedHashMap<>();
+        result.put("salSO", salSO);
+        result.put("salSODet", salSODetList);
+        result.put("SOComProd", soComProdList);
+        return JSONUtil.toJsonStr(result);
+    }
 }

+ 1 - 0
ruoyi-modules/ruoyi-product/src/main/java/org/dromara/product/dubbo/RemoteCategoryServiceImpl.java

@@ -168,6 +168,7 @@ public class RemoteCategoryServiceImpl implements RemoteCategoryService {
             category.setPlatform(dto.getPlatform());
             category.setRemark(dto.getRemark());
             category.setReviewerId(dto.getReviewerId());
+            category.setCustomerId(dto.getCustomerId());
             categories.add(category);
         }
 

+ 23 - 0
ruoyi-modules/ruoyi-product/src/main/java/org/dromara/product/service/impl/ClientSiteServiceImpl.java

@@ -1,6 +1,8 @@
 package org.dromara.product.service.impl;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.dubbo.config.annotation.DubboReference;
 import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
@@ -10,6 +12,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.dromara.customer.api.RemoteCustomerService;
+import org.dromara.customer.api.domain.CustomerApiVo;
 import org.springframework.stereotype.Service;
 import org.dromara.product.domain.bo.ClientSiteBo;
 import org.dromara.product.domain.vo.ClientSiteVo;
@@ -20,6 +24,8 @@ import org.dromara.product.service.IClientSiteService;
 import java.util.List;
 import java.util.Map;
 import java.util.Collection;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 /**
  * 客户站点配置Service业务层处理
@@ -32,6 +38,9 @@ import java.util.Collection;
 @Service
 public class ClientSiteServiceImpl  extends ServiceImpl<ClientSiteMapper, ClientSite> implements IClientSiteService {
 
+    @DubboReference
+    private RemoteCustomerService remoteCustomerService;
+
     private final ClientSiteMapper baseMapper;
 
     /**
@@ -56,6 +65,20 @@ public class ClientSiteServiceImpl  extends ServiceImpl<ClientSiteMapper, Client
     public TableDataInfo<ClientSiteVo> queryPageList(ClientSiteBo bo, PageQuery pageQuery) {
         LambdaQueryWrapper<ClientSite> lqw = buildQueryWrapper(bo);
         Page<ClientSiteVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
+        List<ClientSiteVo> records = result.getRecords();
+        if (ObjectUtil.isNotEmpty( records)){
+            Set<Long> customerIds = records.stream().map(ClientSiteVo::getClientId).collect(Collectors.toSet());
+            Map<Long, CustomerApiVo> longCustomerApiVoMap = remoteCustomerService.selectCustomerByIds(customerIds);
+            records.forEach(item -> {
+                CustomerApiVo customerApiVo = longCustomerApiVoMap.get(item.getClientId());
+                if (ObjectUtil.isNotNull(customerApiVo)){
+                    item.setClientName(customerApiVo.getCustomerName());
+                    item.setClientNo(customerApiVo.getCustomerNo());
+
+                }
+            });
+        }
+
         return TableDataInfo.build(result);
     }
 

+ 6 - 8
ruoyi-modules/ruoyi-product/src/main/java/org/dromara/product/service/impl/ProtocolInfoServiceImpl.java

@@ -88,20 +88,18 @@ public class ProtocolInfoServiceImpl  extends ServiceImpl<ProtocolInfoMapper, Pr
         LambdaQueryWrapper<ProtocolInfo> lqw = buildQueryWrapper(bo);
         Page<ProtocolInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
         result.getRecords().forEach(item -> {
-            if(ObjectUtil.isNotEmpty(item.getSalesmanId()) && ObjectUtil.isNotEmpty(item.getServiceId())){
-                Set<Long> staffIds = new HashSet<>();
-                staffIds.add(item.getSalesmanId());
-                staffIds.add(item.getServiceId());
-                Map<Long, String> staffMap = remoteComStaffService.selectStaffNameByIds(staffIds);
-                item.setSalesmanName(staffMap.get(item.getSalesmanId()));
-                item.setServiceName(staffMap.get(item.getServiceId()));
-            }
             //获取客户信息
             if (ObjectUtil.isNotEmpty(item.getCustomerId())){
                 CustomerInfoDTO customerInfoDTO = remoteCustomerService.selectCustomerInfoById(item.getCustomerId());
                 if(ObjectUtil.isNotEmpty(customerInfoDTO)){
                     item.setCustomerName(customerInfoDTO.getCustomerName());
                     item.setCustomerNo(customerInfoDTO.getCustomerNo());
+                    Set<Long> staffIds = new HashSet<>();
+                    staffIds.add(customerInfoDTO.getSalesPersonId());
+                    staffIds.add(customerInfoDTO.getServiceStaffId());
+                    Map<Long, String> staffMap = remoteComStaffService.selectStaffNameByIds(staffIds);
+                    item.setSalesmanName(staffMap.get(customerInfoDTO.getSalesPersonId()));
+                    item.setServiceName(staffMap.get(customerInfoDTO.getServiceStaffId()));
                 }
 
             }