From 2f58ddd5085b9e51bcc4b7e1ad2e850a95e43bbd Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期三, 11 三月 2026 17:42:59 +0800
Subject: [PATCH] feat: 同步物料编码数据

---
 src/main/java/com/ruoyi/production/task/ProductMaterialTask.java                      |   27 ++
 src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java    |    2 
 src/main/java/com/ruoyi/framework/config/AliDingConfig.java                           |   10 
 src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java       |  306 +++++++++++++++++++++++++
 src/main/java/com/ruoyi/production/pojo/ProductMaterial.java                          |   87 +++++++
 src/main/java/com/ruoyi/production/enums/MaterialConfigTypeEnum.java                  |   25 ++
 src/main/java/com/ruoyi/production/mapper/ProductMaterialConfigMapper.java            |   16 +
 src/main/java/com/ruoyi/production/service/ProductMaterialService.java                |   20 +
 doc/宁夏-中盛建材.sql                                                                       |   37 +++
 src/main/java/com/ruoyi/production/mapper/ProductMaterialMapper.java                  |   16 +
 src/main/java/com/ruoyi/production/controller/ProductMaterialController.java          |   37 +++
 src/main/java/com/ruoyi/production/pojo/ProductMaterialConfig.java                    |   33 ++
 src/main/java/com/ruoyi/production/service/impl/ProductMaterialConfigServiceImpl.java |   24 ++
 src/main/resources/application-zsjc.yml                                               |    3 
 src/main/java/com/ruoyi/production/service/ProductMaterialConfigService.java          |   16 +
 src/main/resources/mapper/production/ProductMaterialMapper.xml                        |   26 ++
 16 files changed, 680 insertions(+), 5 deletions(-)

diff --git "a/doc/\345\256\201\345\244\217-\344\270\255\347\233\233\345\273\272\346\235\220.sql" "b/doc/\345\256\201\345\244\217-\344\270\255\347\233\233\345\273\272\346\235\220.sql"
index b831f87..7c58d7a 100644
--- "a/doc/\345\256\201\345\244\217-\344\270\255\347\233\233\345\273\272\346\235\220.sql"
+++ "b/doc/\345\256\201\345\244\217-\344\270\255\347\233\233\345\273\272\346\235\220.sql"
@@ -106,4 +106,39 @@
     index idx_product_order_id (product_order_id),
     index idx_production_plan_id (production_plan_id),
     unique idx_product_order_production_plan (product_order_id, production_plan_id)
-);
\ No newline at end of file
+);
+
+CREATE TABLE `product_material`
+(
+    `id`                    INT NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT '涓婚敭ID',
+    `tenant_id`             BIGINT       DEFAULT NULL COMMENT '绉熸埛ID',
+    `material_type_id`      INT          DEFAULT NULL COMMENT '鍏宠仈鐗╂枡绫诲瀷ID',
+    `inventory_category_id` INT          DEFAULT NULL COMMENT '鍏宠仈瀛樿揣绫诲埆ID',
+    `identifier_code`       VARCHAR(100) DEFAULT NULL COMMENT '鏍囪瘑缂栫爜',
+    `material_code`         VARCHAR(100) DEFAULT NULL COMMENT '鐗╂枡浠g爜',
+    `product_name`          VARCHAR(255) DEFAULT NULL COMMENT '浜у搧鍚嶇О',
+    `material_name`         VARCHAR(255) DEFAULT NULL COMMENT '鐗╂枡鍝佸悕',
+    `specification`         VARCHAR(255) DEFAULT NULL COMMENT '瑙勬牸鍨嬪彿',
+    `base_unit`             VARCHAR(50)  DEFAULT NULL COMMENT '鍩烘湰鍗曚綅',
+    `material_attribute`    VARCHAR(100) DEFAULT NULL COMMENT '鐗╂枡灞炴��',
+    `finished_product_name` VARCHAR(100) DEFAULT NULL COMMENT '鎴愬搧鍝佸悕',
+    `originator_name`       VARCHAR(100) DEFAULT NULL COMMENT '鎻愪氦浜哄鍚�',
+    `originator_org`        VARCHAR(255) DEFAULT '瀹佸涓垱缁胯兘瀹炰笟闆嗗洟鏈夐檺鍏徃',
+    `remark`                TEXT COMMENT '澶囨敞',
+    `create_time`           DATETIME     DEFAULT CURRENT_TIMESTAMP,
+    `update_time`           DATETIME     DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+    INDEX `idx_type_id` (`material_type_id`),
+    INDEX `idx_cat_id` (`inventory_category_id`)
+) ENGINE = INNODB
+  DEFAULT CHARSET = utf8mb4 COMMENT = '鐗╂枡淇℃伅琛�';
+
+ALTER TABLE product_material
+    ADD COLUMN form_instance_id   VARCHAR(100) DEFAULT NULL COMMENT '瀹滄惌琛ㄥ崟瀹炰緥ID',
+    ADD COLUMN form_modified_time DATETIME     DEFAULT NULL COMMENT '瀹滄惌淇敼鏃堕棿';
+
+CREATE TABLE `product_material_config`
+(
+    `id`          int          NOT NULL AUTO_INCREMENT PRIMARY KEY,
+    `config_type` varchar(50)  NOT NULL COMMENT '鍖哄垎绫诲瀷: MATERIAL_TYPE 鎴� INVENTORY_CAT',
+    `config_name` varchar(100) NOT NULL COMMENT '鏄剧ず鐨勫悕绉�'
+) ENGINE = InnoDB COMMENT ='鐗╂枡淇℃伅琛ㄩ厤缃〃';
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/framework/config/AliDingConfig.java b/src/main/java/com/ruoyi/framework/config/AliDingConfig.java
index db23477..cb18169 100644
--- a/src/main/java/com/ruoyi/framework/config/AliDingConfig.java
+++ b/src/main/java/com/ruoyi/framework/config/AliDingConfig.java
@@ -42,9 +42,15 @@
     private String appType;
 
     /**
-     * 瀹滄惌琛ㄥ崟ID
+     * 閿�鍞敓浜ч渶姹�-瀹滄惌琛ㄥ崟ID
      */
-    private String formUuid;
+    private String producePlanFormUuid;
+
+
+    /**
+     * 鐗╂枡缂栫爜-瀹滄惌琛ㄥ崟ID
+     */
+    private String materialCodeFormUuid;
 
     /**
      * 瀹滄惌搴旂敤瀵嗛挜
diff --git a/src/main/java/com/ruoyi/production/controller/ProductMaterialController.java b/src/main/java/com/ruoyi/production/controller/ProductMaterialController.java
new file mode 100644
index 0000000..144b3f2
--- /dev/null
+++ b/src/main/java/com/ruoyi/production/controller/ProductMaterialController.java
@@ -0,0 +1,37 @@
+package com.ruoyi.production.controller;
+
+import com.ruoyi.framework.aspectj.lang.annotation.Log;
+import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
+import com.ruoyi.framework.web.domain.AjaxResult;
+import com.ruoyi.production.service.ProductMaterialService;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <br>
+ * 浜у搧鐗╂枡淇℃伅鎺у埗灞�
+ * </br>
+ *
+ * @author deslrey
+ * @version 1.0
+ * @since 2026/03/11 16:38
+ */
+@RestController
+@RequestMapping("/productMaterial")
+public class ProductMaterialController {
+
+    @Autowired
+    private ProductMaterialService productMaterialService;
+
+    @GetMapping("/loadData")
+    @ApiOperation("鎷夊彇鐗╂枡缂栫爜鏁版嵁")
+    @Log(title = "鎷夊彇鐗╂枡缂栫爜鏁版嵁", businessType = BusinessType.INSERT)
+    public AjaxResult loadProductMaterialData() {
+        productMaterialService.loadProductMaterialData();
+        return AjaxResult.success();
+    }
+
+}
diff --git a/src/main/java/com/ruoyi/production/enums/MaterialConfigTypeEnum.java b/src/main/java/com/ruoyi/production/enums/MaterialConfigTypeEnum.java
new file mode 100644
index 0000000..7b8f0d9
--- /dev/null
+++ b/src/main/java/com/ruoyi/production/enums/MaterialConfigTypeEnum.java
@@ -0,0 +1,25 @@
+package com.ruoyi.production.enums;
+
+/**
+ * <br>
+ * 鐗╂枡閰嶇疆绫诲瀷鏋氫妇
+ * </br>
+ *
+ * @author deslrey
+ * @version 1.0
+ * @since 2026/03/11 17:24
+ */
+public enum MaterialConfigTypeEnum {
+
+    /**
+     * 鐗╂枡绫诲瀷
+     * 瀵瑰簲鏁版嵁搴� config_type = MATERIAL_TYPE
+     */
+    MATERIAL_TYPE,
+
+    /**
+     * 瀛樿揣绫诲埆
+     * 瀵瑰簲鏁版嵁搴� config_type = INVENTORY_CAT
+     */
+    INVENTORY_CAT
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/production/mapper/ProductMaterialConfigMapper.java b/src/main/java/com/ruoyi/production/mapper/ProductMaterialConfigMapper.java
new file mode 100644
index 0000000..8c6a2a7
--- /dev/null
+++ b/src/main/java/com/ruoyi/production/mapper/ProductMaterialConfigMapper.java
@@ -0,0 +1,16 @@
+package com.ruoyi.production.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruoyi.production.pojo.ProductMaterialConfig;
+
+/**
+ * <br>
+ * 鐗╂枡淇℃伅琛ㄩ厤缃甅apper
+ * </br>
+ *
+ * @author deslrey
+ * @version 1.0
+ * @since 2026/03/11 16:58
+ */
+public interface ProductMaterialConfigMapper extends BaseMapper<ProductMaterialConfig> {
+}
diff --git a/src/main/java/com/ruoyi/production/mapper/ProductMaterialMapper.java b/src/main/java/com/ruoyi/production/mapper/ProductMaterialMapper.java
new file mode 100644
index 0000000..277d9e1
--- /dev/null
+++ b/src/main/java/com/ruoyi/production/mapper/ProductMaterialMapper.java
@@ -0,0 +1,16 @@
+package com.ruoyi.production.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruoyi.production.pojo.ProductMaterial;
+
+/**
+ * <br>
+ * 浜у搧鐗╂枡淇℃伅Mapper
+ * </br>
+ *
+ * @author deslrey
+ * @version 1.0
+ * @since 2026/03/11 16:35
+ */
+public interface ProductMaterialMapper extends BaseMapper<ProductMaterial> {
+}
diff --git a/src/main/java/com/ruoyi/production/pojo/ProductMaterial.java b/src/main/java/com/ruoyi/production/pojo/ProductMaterial.java
new file mode 100644
index 0000000..65f8a85
--- /dev/null
+++ b/src/main/java/com/ruoyi/production/pojo/ProductMaterial.java
@@ -0,0 +1,87 @@
+package com.ruoyi.production.pojo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+/**
+ * <br>
+ * 浜у搧鐗╂枡淇℃伅琛�
+ * </br>
+ *
+ * @author deslrey
+ * @version 1.0
+ * @since 2026/03/11 16:31
+ */
+@Data
+@TableName("product_material")
+@ApiModel(value = "ProductMaterial", description = "浜у搧鐗╂枡淇℃伅琛�")
+public class ProductMaterial {
+
+    @TableId(type = IdType.AUTO)
+    @ApiModelProperty("涓婚敭ID")
+    private Integer id;
+
+    @ApiModelProperty("绉熸埛ID")
+    private Long tenantId;
+
+    @ApiModelProperty("鐗╂枡绫诲瀷ID")
+    private Integer materialTypeId;
+
+    @ApiModelProperty("瀛樿揣绫诲埆ID")
+    private Integer inventoryCategoryId;
+
+    @ApiModelProperty("鏍囪瘑缂栫爜")
+    private String identifierCode;
+
+    @ApiModelProperty("鐗╂枡浠g爜")
+    private String materialCode;
+
+    @ApiModelProperty("浜у搧鍚嶇О")
+    private String productName;
+
+    @ApiModelProperty("鐗╂枡鍝佸悕")
+    private String materialName;
+
+    @ApiModelProperty("瑙勬牸鍨嬪彿")
+    private String specification;
+
+    @ApiModelProperty("鍩烘湰鍗曚綅")
+    private String baseUnit;
+
+    @ApiModelProperty("鐗╂枡灞炴��")
+    private String materialAttribute;
+
+    @ApiModelProperty("鎴愬搧鍝佸悕")
+    private String finishedProductName;
+
+    @ApiModelProperty("鎻愪氦浜哄鍚�")
+    private String originatorName;
+
+    @ApiModelProperty("鎻愪氦浜虹粍缁�")
+    private String originatorOrg;
+
+    @ApiModelProperty("澶囨敞")
+    private String remark;
+
+    @ApiModelProperty("鍒涘缓鏃堕棿")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime createTime;
+
+    @ApiModelProperty("淇敼鏃堕棿")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime updateTime;
+
+    @ApiModelProperty("瀹滄惌琛ㄥ崟瀹炰緥ID")
+    private String formInstanceId;
+
+    @ApiModelProperty("瀹滄惌淇敼鏃堕棿")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime formModifiedTime;
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/production/pojo/ProductMaterialConfig.java b/src/main/java/com/ruoyi/production/pojo/ProductMaterialConfig.java
new file mode 100644
index 0000000..8d5d721
--- /dev/null
+++ b/src/main/java/com/ruoyi/production/pojo/ProductMaterialConfig.java
@@ -0,0 +1,33 @@
+package com.ruoyi.production.pojo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * <br>
+ * 鐗╂枡淇℃伅琛ㄩ厤缃〃
+ * </br>
+ *
+ * @author deslrey
+ * @version 1.0
+ * @since 2026/03/11 16:57
+ */
+@Data
+@TableName("product_material_config")
+@ApiModel(value = "ProductMaterialConfig", description = "鐗╂枡淇℃伅閰嶇疆琛�")
+public class ProductMaterialConfig {
+
+    @TableId(type = IdType.AUTO)
+    @ApiModelProperty("涓婚敭ID")
+    private Integer id;
+
+    @ApiModelProperty("鍖哄垎绫诲瀷: MATERIAL_TYPE 鎴� INVENTORY_CAT")
+    private String configType;
+
+    @ApiModelProperty("閰嶇疆鍚嶇О")
+    private String configName;
+}
diff --git a/src/main/java/com/ruoyi/production/service/ProductMaterialConfigService.java b/src/main/java/com/ruoyi/production/service/ProductMaterialConfigService.java
new file mode 100644
index 0000000..e31fcf5
--- /dev/null
+++ b/src/main/java/com/ruoyi/production/service/ProductMaterialConfigService.java
@@ -0,0 +1,16 @@
+package com.ruoyi.production.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ruoyi.production.pojo.ProductMaterialConfig;
+
+/**
+ * <br>
+ * 鐗╂枡淇℃伅琛ㄩ厤缃帴鍙�
+ * </br>
+ *
+ * @author deslrey
+ * @version 1.0
+ * @since 2026/03/11 16:58
+ */
+public interface ProductMaterialConfigService extends IService<ProductMaterialConfig> {
+}
diff --git a/src/main/java/com/ruoyi/production/service/ProductMaterialService.java b/src/main/java/com/ruoyi/production/service/ProductMaterialService.java
new file mode 100644
index 0000000..34fd9a7
--- /dev/null
+++ b/src/main/java/com/ruoyi/production/service/ProductMaterialService.java
@@ -0,0 +1,20 @@
+package com.ruoyi.production.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ruoyi.production.pojo.ProductMaterial;
+
+/**
+ * <br>
+ * 浜у搧鐗╂枡淇℃伅鎺ュ彛
+ * </br>
+ *
+ * @author deslrey
+ * @version 1.0
+ * @since 2026/03/11 16:35
+ */
+public interface ProductMaterialService extends IService<ProductMaterial> {
+
+    void loadProductMaterialData();
+
+    void syncProductMaterialJob();
+}
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductMaterialConfigServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductMaterialConfigServiceImpl.java
new file mode 100644
index 0000000..7136f8a
--- /dev/null
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductMaterialConfigServiceImpl.java
@@ -0,0 +1,24 @@
+package com.ruoyi.production.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.production.mapper.ProductMaterialConfigMapper;
+import com.ruoyi.production.pojo.ProductMaterialConfig;
+import com.ruoyi.production.service.ProductMaterialConfigService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+/**
+ * <br>
+ * 鐗╂枡淇℃伅琛ㄩ厤缃帴鍙e疄鐜扮被
+ * </br>
+ *
+ * @author deslrey
+ * @version 1.0
+ * @since 2026/03/11 16:59
+ */
+@Slf4j
+@Service
+public class ProductMaterialConfigServiceImpl extends ServiceImpl<ProductMaterialConfigMapper, ProductMaterialConfig> implements ProductMaterialConfigService {
+
+
+}
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java
new file mode 100644
index 0000000..7367dc7
--- /dev/null
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java
@@ -0,0 +1,306 @@
+package com.ruoyi.production.service.impl;
+
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.http.HttpUtils;
+import com.ruoyi.framework.config.AliDingConfig;
+import com.ruoyi.production.enums.MaterialConfigTypeEnum;
+import com.ruoyi.production.mapper.ProductMaterialMapper;
+import com.ruoyi.production.pojo.ProductMaterial;
+import com.ruoyi.production.pojo.ProductMaterialConfig;
+import com.ruoyi.production.service.ProductMaterialConfigService;
+import com.ruoyi.production.service.ProductMaterialService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.nio.charset.StandardCharsets;
+import java.time.LocalDateTime;
+import java.time.OffsetDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeParseException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.locks.ReentrantLock;
+
+/**
+ * <br>
+ * 浜у搧鐗╂枡淇℃伅鎺ュ彛瀹炵幇绫�
+ * </br>
+ *
+ * @author deslrey
+ * @version 1.0
+ * @since 2026/03/11 16:36
+ */
+@Slf4j
+@Service
+public class ProductMaterialServiceImpl extends ServiceImpl<ProductMaterialMapper, ProductMaterial> implements ProductMaterialService {
+
+    @Autowired
+    private AliDingConfig aliDingConfig;
+
+    @Autowired
+    private ProductMaterialConfigService productMaterialConfigService;
+
+    /**
+     * 鍚屾閿侊紝闃叉鎵嬪姩鍜屽畾鏃朵换鍔″悓鏃舵墽琛�
+     */
+    private final ReentrantLock syncLock = new ReentrantLock();
+
+    @Override
+    public void loadProductMaterialData() {
+        syncProductMaterialData(1);
+    }
+
+    @Override
+    public void syncProductMaterialJob() {
+        syncProductMaterialData(2);
+    }
+
+    /**
+     * 鍚屾鏁版嵁
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void syncProductMaterialData(Integer dataSyncType) {
+        if (!syncLock.tryLock()) {
+            log.warn("鍚屾姝e湪杩涜涓紝鏈 {} 鍚屾璇锋眰琚烦杩�", dataSyncType == 1 ? "鎵嬪姩" : "瀹氭椂浠诲姟");
+            return;
+        }
+
+        try {
+            // 鑾峰彇 AccessToken
+            String accessToken = getAccessToken();
+            if (StringUtils.isEmpty(accessToken)) {
+                return;
+            }
+
+            // 鑾峰彇鏈湴鏈�鍚庡悓姝ユ椂闂�
+            LocalDateTime lastSyncTime = getLastSyncTime();
+            log.info("寮�濮嬬墿鏂欑紪鐮佸閲忓悓姝ワ紝鏈湴鏈�鍚庝慨鏀规椂闂�: {}", lastSyncTime);
+
+            int pageNumber = 1;
+            int pageSize = 50;
+            boolean hasMore = true;
+            int totalSynced = 0;
+
+            while (hasMore) {
+                // 鏌ヨ鍙傛暟
+                JSONObject searchParam = buildSearchParam(lastSyncTime, pageNumber, pageSize);
+
+                // 璋冪敤瀹滄惌鎺ュ彛鎷夊彇鏁版嵁
+                String dataRes = HttpUtils.sendPostJson(
+                        aliDingConfig.getSearchFormDataUrl(),
+                        searchParam.toJSONString(),
+                        StandardCharsets.UTF_8.name(),
+                        null,
+                        accessToken
+                );
+
+                if (StringUtils.isEmpty(dataRes)) {
+                    log.warn("绗� {} 椤垫媺鍙栨暟鎹负绌�", pageNumber);
+                    break;
+                }
+
+                JSONObject resultObj = JSON.parseObject(dataRes);
+                JSONArray dataArr = resultObj.getJSONArray("data");
+                Integer totalCount = resultObj.getInteger("totalCount");
+
+                if (dataArr == null || dataArr.isEmpty()) {
+                    log.info("娌℃湁鏇村鏂版暟鎹渶瑕佸悓姝�");
+                    break;
+                }
+
+                // 瑙f瀽骞朵繚瀛樻暟鎹�
+                List<ProductMaterial> list = parseProductMaterials(dataArr, totalCount);
+                if (!list.isEmpty()) {
+                    // 澶勭悊鏇存柊鎴栨柊澧�
+                    int affected = processSaveOrUpdate(list);
+                    totalSynced += affected;
+                }
+
+                // 鍒ゆ柇鏄惁杩樻湁涓嬩竴椤�
+                hasMore = (pageNumber * pageSize) < totalCount;
+                pageNumber++;
+
+                log.info("姝e湪鍚屾绗� {} 椤碉紝褰撳墠宸插悓姝� {}/{}", pageNumber - 1, totalSynced, totalCount);
+            }
+
+            log.info("鐗╂枡鏁版嵁鍚屾瀹屾垚锛屽叡鍚屾 {} 鏉℃暟鎹�", totalSynced);
+        } catch (Exception e) {
+            log.error("鍚屾鐗╂枡缂栫爜寮傚父", e);
+        } finally {
+            // 閲婃斁閿�
+            syncLock.unlock();
+        }
+    }
+
+    private String getAccessToken() {
+        String params = "appkey=" + aliDingConfig.getAppKey()
+                + "&appsecret=" + aliDingConfig.getAppSecret();
+        String tokenRes = HttpUtils.sendGet(aliDingConfig.getAccessTokenUrl(), params);
+        JSONObject tokenObj = JSON.parseObject(tokenRes);
+        String accessToken = tokenObj.getString("access_token");
+        if (StringUtils.isEmpty(accessToken)) {
+            log.error("鑾峰彇閽夐拤AccessToken澶辫触: {}", tokenRes);
+        }
+        return accessToken;
+    }
+
+    private LocalDateTime getLastSyncTime() {
+        LambdaQueryWrapper<ProductMaterial> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.orderByDesc(ProductMaterial::getFormModifiedTime).last("LIMIT 1");
+        ProductMaterial lastRecord = this.getOne(queryWrapper);
+        return lastRecord != null ? lastRecord.getFormModifiedTime() : null;
+    }
+
+    private JSONObject buildSearchParam(LocalDateTime lastSyncTime, int pageNumber, int pageSize) {
+        JSONObject searchParam = new JSONObject();
+        searchParam.put("appType", aliDingConfig.getAppType());
+        searchParam.put("systemToken", aliDingConfig.getSystemToken());
+        searchParam.put("userId", aliDingConfig.getUserId());
+        searchParam.put("formUuid", aliDingConfig.getMaterialCodeFormUuid());
+        searchParam.put("currentPage", pageNumber);
+        searchParam.put("pageSize", pageSize);
+
+        JSONArray searchConditions = new JSONArray();
+        JSONObject statusCondition = new JSONObject();
+        statusCondition.put("key", "processInstanceStatus");
+        JSONArray statusValueArray = new JSONArray();
+        statusValueArray.add("COMPLETED");
+        statusCondition.put("value", statusValueArray);
+        statusCondition.put("type", "ARRAY");
+        statusCondition.put("operator", "in");
+        statusCondition.put("componentName", "SelectField");
+        searchConditions.add(statusCondition);
+
+        JSONObject resultCondition = new JSONObject();
+        resultCondition.put("key", "processApprovedResult");
+        JSONArray resultValueArray = new JSONArray();
+        resultValueArray.add("agree");
+        resultCondition.put("value", resultValueArray);
+        resultCondition.put("type", "ARRAY");
+        resultCondition.put("operator", "in");
+        resultCondition.put("componentName", "SelectField");
+        searchConditions.add(resultCondition);
+
+        searchParam.put("searchFieldJson", searchConditions.toJSONString());
+        searchParam.put("orderConfigJson", "{\"gmt_modified\":\"+\"}");
+
+        if (lastSyncTime != null) {
+            String startTime = lastSyncTime.plusSeconds(1).atZone(ZoneId.systemDefault())
+                    .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+            searchParam.put("modifiedFromTimeGMT", startTime);
+        }
+
+        String endTime = LocalDateTime.now().atZone(ZoneId.systemDefault())
+                .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+        searchParam.put("modifiedToTimeGMT", endTime);
+
+        return searchParam;
+    }
+
+    private List<ProductMaterial> parseProductMaterials(JSONArray dataArr, Integer totalCount) {
+        List<ProductMaterial> list = new ArrayList<>();
+        LocalDateTime now = LocalDateTime.now();
+
+        for (int i = 0; i < dataArr.size(); i++) {
+            JSONObject item = dataArr.getJSONObject(i);
+            String formInstanceId = item.getString("formInstanceId");
+
+            JSONObject originator = item.getJSONObject("originator");
+            String originatorName = originator != null && originator.containsKey("userName")
+                    ? originator.getJSONObject("userName").getString("nameInChinese") : "鏈煡";
+
+            JSONObject formData = item.getJSONObject("formData");
+            ProductMaterial material = new ProductMaterial();
+
+            material.setFormInstanceId(formInstanceId);
+            material.setIdentifierCode(formData.getString("textField_l92h77ju"));
+            material.setMaterialCode(formData.getString("textField_l92f36f2"));
+            material.setMaterialName(formData.getString("textField_l92f36f5"));
+            material.setSpecification(formData.getString("textField_l92f36f6"));
+            material.setBaseUnit(formData.getString("textField_la147lnw"));
+            material.setMaterialAttribute(formData.getString("selectField_la14k51j"));
+            material.setFinishedProductName(formData.getString("radioField_lbkk2nn2"));
+            material.setRemark(formData.getString("textareaField_l92f36f9"));
+
+            // 澶勭悊鐗╂枡绫诲瀷鍜屽瓨璐х被鍒�
+            String materialType = formData.getString("selectField_l92f36fb");
+            String inventoryCat = formData.getString("selectField_la154noy");
+            material.setMaterialTypeId(getOrCreateConfigId(materialType, MaterialConfigTypeEnum.MATERIAL_TYPE.name()));
+            material.setInventoryCategoryId(getOrCreateConfigId(inventoryCat, MaterialConfigTypeEnum.INVENTORY_CAT.name()));
+
+            material.setOriginatorName(originatorName);
+            material.setOriginatorOrg("瀹佸涓垱缁胯兘瀹炰笟闆嗗洟鏈夐檺鍏徃");
+
+            material.setFormModifiedTime(parseUtcTime(item.getString("modifiedTimeGMT")));
+            material.setCreateTime(now);
+            material.setUpdateTime(now);
+
+            list.add(material);
+        }
+        return list;
+    }
+
+    private Integer getOrCreateConfigId(String name, String type) {
+        if (StringUtils.isEmpty(name)) {
+            return null;
+        }
+        ProductMaterialConfig config = productMaterialConfigService.getOne(new LambdaQueryWrapper<ProductMaterialConfig>()
+                .eq(ProductMaterialConfig::getConfigName, name)
+                .eq(ProductMaterialConfig::getConfigType, type));
+        if (config == null) {
+            config = new ProductMaterialConfig();
+            config.setConfigName(name);
+            config.setConfigType(type);
+            productMaterialConfigService.save(config);
+        }
+        return config.getId();
+    }
+
+    private int processSaveOrUpdate(List<ProductMaterial> list) {
+        if (list == null || list.isEmpty()) {
+            return 0;
+        }
+        int affected = 0;
+
+        for (ProductMaterial material : list) {
+            ProductMaterial exist = this.getOne(new LambdaQueryWrapper<ProductMaterial>()
+                    .eq(ProductMaterial::getFormInstanceId, material.getFormInstanceId()));
+
+            if (exist == null) {
+                this.save(material);
+                affected++;
+                log.info("鏂板鐗╂枡鏁版嵁 formInstanceId={}", material.getFormInstanceId());
+            } else {
+                if (exist.getFormModifiedTime() == null || !exist.getFormModifiedTime().equals(material.getFormModifiedTime())) {
+                    material.setId(exist.getId());
+                    material.setCreateTime(exist.getCreateTime());
+                    this.updateById(material);
+                    affected++;
+                    log.info("鏇存柊鐗╂枡鏁版嵁 formInstanceId={}", material.getFormInstanceId());
+                }
+            }
+        }
+        return affected;
+    }
+
+    private LocalDateTime parseUtcTime(String utcString) {
+        if (StringUtils.isEmpty(utcString)) {
+            return null;
+        }
+        try {
+            OffsetDateTime odt = OffsetDateTime.parse(utcString);
+            return odt.toLocalDateTime();
+        } catch (DateTimeParseException ex) {
+            log.warn("瑙f瀽鏃堕棿 {} 澶辫触: {}", utcString, ex.getMessage());
+            return null;
+        }
+    }
+}
diff --git a/src/main/java/com/ruoyi/production/task/ProductMaterialTask.java b/src/main/java/com/ruoyi/production/task/ProductMaterialTask.java
new file mode 100644
index 0000000..aa65f38
--- /dev/null
+++ b/src/main/java/com/ruoyi/production/task/ProductMaterialTask.java
@@ -0,0 +1,27 @@
+package com.ruoyi.production.task;
+
+import com.ruoyi.production.service.ProductMaterialService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+/**
+ * <br>
+ *
+ * </br>
+ *
+ * @author deslrey
+ * @version 1.0
+ * @since 2026/03/11 16:39
+ */
+@Component
+public class ProductMaterialTask {
+
+    @Autowired
+    private ProductMaterialService productMaterialService;
+
+    @Scheduled(cron = "0 0 * * * ?")
+    public void syncProdDataJob() {
+        productMaterialService.syncProductMaterialJob();
+    }
+}
diff --git a/src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java b/src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
index 9f44dd7..f0584d7 100644
--- a/src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
+++ b/src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
@@ -306,7 +306,7 @@
         searchParam.put("appType", aliDingConfig.getAppType());
         searchParam.put("systemToken", aliDingConfig.getSystemToken());
         searchParam.put("userId", aliDingConfig.getUserId());
-        searchParam.put("formUuid", aliDingConfig.getFormUuid());
+        searchParam.put("formUuid", aliDingConfig.getProducePlanFormUuid());
         searchParam.put("currentPage", pageNumber);
         searchParam.put("pageSize", pageSize);
 
diff --git a/src/main/resources/application-zsjc.yml b/src/main/resources/application-zsjc.yml
index 367ac75..18e7c76 100644
--- a/src/main/resources/application-zsjc.yml
+++ b/src/main/resources/application-zsjc.yml
@@ -30,7 +30,8 @@
     app-secret: "fO07qSZC5SMLw9It3Ydd3BuoFyVbRlsWXUnVr2kwPJXz0OpUntCAO5dqnr8G7zq5"
     user-id: "290166234126410562"
     app-type: "APP_UY8XMO7GNA8OF08EFNVQ"
-    form-uuid: "FORM-4IA66891C5H3QWMDBSGO05C0OX9628GRPYF7L8"
+    produce-plan-form-uuid: "FORM-4IA66891C5H3QWMDBSGO05C0OX9628GRPYF7L8"
+    material-code-form-uuid: "FORM-8I666N718RW4ALO4ETYDDB0U6U8T3EIWTQ0ALL1"
     system-token: "4J766L91OFH3V612E7LG5B4DI8M13MQF9VF7LG4"
     # 鎺ュ彛鍦板潃
     access-token-url: "https://oapi.dingtalk.com/gettoken"
diff --git a/src/main/resources/mapper/production/ProductMaterialMapper.xml b/src/main/resources/mapper/production/ProductMaterialMapper.xml
new file mode 100644
index 0000000..32c1ba1
--- /dev/null
+++ b/src/main/resources/mapper/production/ProductMaterialMapper.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.ruoyi.production.mapper.ProductMaterialMapper">
+    <resultMap id="ProductMaterialResultMap" type="com.ruoyi.production.pojo.ProductMaterial">
+        <id property="id" column="id"/>
+        <result property="tenantId" column="tenant_id"/>
+        <result property="materialType" column="material_type"/>
+        <result property="inventoryCategory" column="inventory_category"/>
+        <result property="identifierCode" column="identifier_code"/>
+        <result property="materialCode" column="material_code"/>
+        <result property="productName" column="product_name"/>
+        <result property="materialName" column="material_name"/>
+        <result property="specification" column="specification"/>
+        <result property="baseUnit" column="base_unit"/>
+        <result property="materialAttribute" column="material_attribute"/>
+        <result property="finishedProductName" column="finished_product_name"/>
+        <result property="originatorName" column="originator_name"/>
+        <result property="originatorOrg" column="originator_org"/>
+        <result property="remark" column="remark"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateTime" column="update_time"/>
+    </resultMap>
+
+</mapper>
\ No newline at end of file

--
Gitblit v1.9.3