From e63255bf33f3835e99e30efaf3c6a3fc7fc4d1ba Mon Sep 17 00:00:00 2001
From: lyh <925863403@qq.com>
Date: 星期四, 29 五月 2025 16:10:52 +0800
Subject: [PATCH] 修改自动化代码

---
 lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/service/impl/MsiWebapiJsonServiceImpl.java |   89 ++++++++++++++++++++++++++++++++++++++------
 1 files changed, 76 insertions(+), 13 deletions(-)

diff --git a/lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/service/impl/MsiWebapiJsonServiceImpl.java b/lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/service/impl/MsiWebapiJsonServiceImpl.java
index 72e2db6..5c649d2 100644
--- a/lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/service/impl/MsiWebapiJsonServiceImpl.java
+++ b/lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/service/impl/MsiWebapiJsonServiceImpl.java
@@ -1,7 +1,8 @@
 package org.jeecg.modules.msi.webapi.service.impl;
 
-import cn.hutool.core.date.DateUtil;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import liquibase.util.JdbcUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.modules.msi.webapi.entity.MsiWebapiJsonEntity;
@@ -9,8 +10,15 @@
 import org.jeecg.modules.msi.webapi.service.IMsiWebapiJsonService;
 import org.jeecg.modules.msi.webapi.vo.DetailedListVo;
 import org.jeecg.modules.msi.webapi.vo.MachineEquipentInfo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.datasource.DataSourceUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -19,7 +27,14 @@
 @Service
 public class MsiWebapiJsonServiceImpl extends ServiceImpl<MsiWebapiJsonMapper, MsiWebapiJsonEntity> implements IMsiWebapiJsonService {
 
+    @Autowired
+    private JdbcTemplate jdbcTemplate;
 
+    /**
+     * 瑙f瀽鍗曟潯鏁版嵁淇濆瓨鍒板崟琛�
+     * @param data
+     * @return
+     */
     @Override
     public boolean saveTableAutomationOne(List<MachineEquipentInfo> data) {
         if (data ==null || data.isEmpty()) {
@@ -38,9 +53,51 @@
                 listParameter.add(parameter);
             }
         }
-        //鐘舵�佹暟鎹�
+        // 鎵ц鐘舵�佹暟鎹甋QL
+        try {
+            executeBatchSql(listStatus);
+            executeBatchSql(listParameter);
+            return true;
+        } catch (Exception e) {
+            log.error("鎵цSQL鎵归噺鎻掑叆澶辫触", e);
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            return false;
+        }
+    }
 
-        return false;
+    /**
+     * 鎵归噺鎵цSQL璇彞
+     * @param sqlList SQL璇彞鍒楄〃
+     * @throws SQLException
+     */
+    private void executeBatchSql(List<String> sqlList) throws SQLException {
+        if (CollectionUtils.isEmpty(sqlList)) {
+            return;
+        }
+
+        Connection connection = null;
+        Statement statement = null;
+
+        try {
+            connection = DataSourceUtils.getConnection(jdbcTemplate.getDataSource());
+            connection.setAutoCommit(false);
+            statement = connection.createStatement();
+
+            for (String sql : sqlList) {
+                statement.addBatch(sql);
+            }
+
+            statement.executeBatch();
+            connection.commit();
+        } catch (SQLException e) {
+            if (connection != null) {
+                connection.rollback();
+            }
+            throw e;
+        } finally {
+            JdbcUtils.closeStatement(statement);
+            DataSourceUtils.releaseConnection(connection, jdbcTemplate.getDataSource());
+        }
     }
 
 
@@ -77,43 +134,49 @@
         if (itemMap.containsKey("runningStatus")) {
             sql = sql + "'" + itemMap.get("runningStatus").getItemValue() + "', ";
         } else {
-            sql = sql + null + ", ";
+            sql = sql + "NULL, ";
         }
         //spindleSpeed
         if (itemMap.containsKey("spindleSpeed")) {
             sql = sql + "'" + itemMap.get("spindleSpeed").getItemValue() + "', ";
         } else {
-            sql = sql + null + ", ";
+            sql = sql + "NULL, ";
+        }
+        //feedRatio
+        if (itemMap.containsKey("feedRatio")) {
+            sql = sql + "'" + itemMap.get("feedRatio").getItemValue() + "', ";
+        }else {
+            sql = sql + "NULL, ";
         }
         //runDuration
         if (itemMap.containsKey("runDuration")) {
             sql = sql + "'" + itemMap.get("runDuration").getItemValue() + "', ";
         } else {
-            sql = sql + null + ", ";
+            sql = sql + "NULL, ";
         }
         //spindleDuration
         if (itemMap.containsKey("spindleDuration")) {
             sql = sql + "'" + itemMap.get("spindleDuration").getItemValue() + "', ";
         } else {
-            sql = sql + null + ", ";
+            sql = sql + "NULL, ";
         }
         //progName
-        if (itemMap.containsKey("spindleSpeed")) {
-            sql = sql + "'" + itemMap.get("spindleSpeed").getItemValue() + "', ";
+        if (itemMap.containsKey("progName")) {  // 淇涓� "progName"
+            sql = sql + "'" + itemMap.get("progName").getItemValue() + "', ";
         } else {
-            sql = sql + null + ", ";
+            sql = sql + "NULL, ";
         }
         //progStatus
         if (itemMap.containsKey("progStatus")) {
             sql = sql + "'" + itemMap.get("progStatus").getItemValue() + "', ";
         } else {
-            sql = sql + null + ", ";
+            sql = sql + "NULL, ";
         }
         //toolNo
         if (itemMap.containsKey("toolNo")) {
-            sql = sql + "'" + itemMap.get("toolNo").getItemValue() + "'  ";
+            sql = sql + "'" + itemMap.get("toolNo").getItemValue() + "' ";
         } else {
-            sql = sql + null;
+            sql = sql + "NULL";
         }
 
         sql = sql + "); \n";

--
Gitblit v1.9.3