From f73f8cb6753f8d8ab2c689b4640cd2688e6f6f62 Mon Sep 17 00:00:00 2001
From: Lius <Lius2225@163.com>
Date: 星期二, 16 九月 2025 11:06:42 +0800
Subject: [PATCH] update

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentDayScheduleServiceImpl.java |   46 +++++++++++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/LogTableServiceImpl.java                |    4 -
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentMapper.xml                    |    6 +
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentDaySummaryServiceImpl.java  |   48 ++++++++++++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentDayScheduleService.java         |    4 +
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentDaySummaryService.java          |    4 +
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcEquipmentVo.java                               |    1 
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/webservice/impl/EquipmentWebServiceImpl.java         |  113 +++++++++++++++++++++-------
 8 files changed, 193 insertions(+), 33 deletions(-)

diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentMapper.xml b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentMapper.xml
index 05d4b7d..0c73a4d 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentMapper.xml
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentMapper.xml
@@ -218,6 +218,12 @@
             <if test="mdcEquipment.deviceCategory != null and mdcEquipment.deviceCategory != '' ">
                 AND t1.device_category = #{mdcEquipment.deviceCategory}
             </if>
+            <if test="mdcEquipment.equipmentStatus != null ">
+                AND t1.equipment_status = #{mdcEquipment.equipmentStatus}
+            </if>
+            <if test="mdcEquipment.attribute != null ">
+                AND t1.attribute = #{mdcEquipment.attribute}
+            </if>
             <if test="mdcEquipment.productionIds != null and mdcEquipment.productionIds.size() > 0 ">
                 AND t3.id IN
                 <foreach collection="mdcEquipment.productionIds" index="index" item="id" open="(" separator="," close=")">
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentDayScheduleService.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentDayScheduleService.java
index 51c282b..37a67fa 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentDayScheduleService.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentDayScheduleService.java
@@ -6,9 +6,13 @@
 import org.jeecg.modules.mdc.entity.MdcEquipmentDaySchedule;
 import org.jeecg.modules.mdc.vo.MdcEquipmentDayScheduleVo;
 
+import java.util.List;
+
 public interface IMdcEquipmentDayScheduleService extends IService<MdcEquipmentDaySchedule> {
 
     IPage<MdcEquipmentDaySchedule> pageList(MdcEquipmentDayScheduleVo mdcEquipmentDayScheduleVo, Page<MdcEquipmentDaySchedule> page);
 
     MdcEquipmentDaySchedule selectLast(String equipmentId);
+
+    boolean saveOrUpdateBatchByMesId(List<MdcEquipmentDaySchedule> mdcList);
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentDaySummaryService.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentDaySummaryService.java
index 8420ae7..eb67d66 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentDaySummaryService.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentDaySummaryService.java
@@ -3,7 +3,11 @@
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.jeecg.modules.mdc.entity.MdcEquipmentDaySummary;
 
+import java.util.List;
+
 public interface IMdcEquipmentDaySummaryService extends IService<MdcEquipmentDaySummary> {
 
     MdcEquipmentDaySummary statisticsQty(String productionId);
+
+    boolean saveOrUpdateBatchByMesId(List<MdcEquipmentDaySummary> mdcList);
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/LogTableServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/LogTableServiceImpl.java
index 884c72c..e6578f1 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/LogTableServiceImpl.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/LogTableServiceImpl.java
@@ -107,8 +107,6 @@
 
             // 鏂囦欢璺緞
             String locFilePath = localFilePath + TYPE + today + String.format("%06d", sequenceNumber) + ".xml";
-//            FileWriter writer = new FileWriter(locFilePath);
-//            writer.writeLines(sqlList);
             String listSql = String.join("\n", sqlList);
             try {
                 FileUtils.fileWriterSql(locFilePath, listSql);
@@ -226,7 +224,6 @@
                         sqlExecutor.execute(sql);
                     } catch (Exception e) {
                         failedSqlList.add(sql);
-//                        throw new JeecgBootException("鎵цsql澶辫触锛�");
                     }
                 }
                 if (!failedSqlList.isEmpty()) {
@@ -236,7 +233,6 @@
                         throw new JeecgBootException("鏁版嵁鍐欏叆鏂囦欢澶辫触锛�");
                     }
                 }
-//                String sqlList = fileReader.readString();
 
                 if (Integer.parseInt(file.getName().substring(file.getName().length() - 10, file.getName().length() - 4)) == 1) {
                     // 鍒犻櫎鍘嗗彶鏂囦欢
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentDayScheduleServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentDayScheduleServiceImpl.java
index 1237fb3..27c0421 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentDayScheduleServiceImpl.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentDayScheduleServiceImpl.java
@@ -1,6 +1,7 @@
 package org.jeecg.modules.mdc.service.impl;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.jeecg.modules.mdc.entity.MdcEquipmentDaySchedule;
@@ -9,11 +10,17 @@
 import org.jeecg.modules.mdc.vo.MdcEquipmentDayScheduleVo;
 import org.jeecg.modules.system.entity.MdcProduction;
 import org.jeecg.modules.system.service.IMdcProductionService;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * @Author: Lius
@@ -52,4 +59,43 @@
     public MdcEquipmentDaySchedule selectLast(String equipmentId) {
         return this.baseMapper.selectLast(equipmentId);
     }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean saveOrUpdateBatchByMesId(List<MdcEquipmentDaySchedule> entityList) {
+        if (CollectionUtils.isEmpty(entityList)) {
+            return true;
+        }
+
+        // 鎸塵esId鍒嗙粍澶勭悊
+        Map<String, MdcEquipmentDaySchedule> mesIdMap = entityList.stream()
+                .collect(Collectors.toMap(MdcEquipmentDaySchedule::getMesId,
+                        mdcEquipmentDaySchedule -> mdcEquipmentDaySchedule,       // 鍊硷細鐢ㄦ埛瀵硅薄鏈韩
+                        (existing, replacement) -> existing));
+
+        // 鎵归噺鏌ヨ宸插瓨鍦ㄧ殑mesId
+        List<MdcEquipmentDaySchedule> existList = this.lambdaQuery()
+                .in(MdcEquipmentDaySchedule::getMesId, mesIdMap.keySet())
+                .list();
+
+        // 鍒嗙闇�瑕佹柊澧炲拰鏇存柊鐨勬暟鎹�
+        List<MdcEquipmentDaySchedule> toInsert = new ArrayList<>();
+        List<MdcEquipmentDaySchedule> toUpdate = new ArrayList<>();
+
+        existList.forEach(exist -> {
+            MdcEquipmentDaySchedule newData = mesIdMap.get(exist.getMesId());
+            // 淇濈暀鍘烮D
+            BeanUtils.copyProperties(newData, exist);
+            toUpdate.add(exist);
+            mesIdMap.remove(exist.getMesId());
+        });
+
+        toInsert.addAll(mesIdMap.values());
+
+        // 鎵ц鎵归噺鎿嶄綔
+        boolean insertResult = toInsert.isEmpty() || this.saveBatch(toInsert);
+        boolean updateResult = toUpdate.isEmpty() || this.updateBatchById(toUpdate);
+
+        return insertResult && updateResult;
+    }
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentDaySummaryServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentDaySummaryServiceImpl.java
index 9c89ed6..c80525b 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentDaySummaryServiceImpl.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentDaySummaryServiceImpl.java
@@ -1,10 +1,18 @@
 package org.jeecg.modules.mdc.service.impl;
 
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.jeecg.modules.mdc.entity.MdcEquipmentDaySummary;
 import org.jeecg.modules.mdc.mapper.MdcEquipmentDaySummaryMapper;
 import org.jeecg.modules.mdc.service.IMdcEquipmentDaySummaryService;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * @Author: Lius
@@ -17,4 +25,44 @@
     public MdcEquipmentDaySummary statisticsQty(String productionId) {
         return this.baseMapper.statisticsQty(productionId);
     }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean saveOrUpdateBatchByMesId(List<MdcEquipmentDaySummary> entityList) {
+        if (CollectionUtils.isEmpty(entityList)) {
+            return true;
+        }
+
+        // 鎸塵esId鍒嗙粍澶勭悊
+        Map<String, MdcEquipmentDaySummary> mesIdMap = entityList.stream()
+                .collect(Collectors.toMap(MdcEquipmentDaySummary::getMesId,
+                        mdcEquipmentDaySummary -> mdcEquipmentDaySummary,       // 鍊硷細鐢ㄦ埛瀵硅薄鏈韩
+                        (existing, replacement) -> existing));
+
+        // 鎵归噺鏌ヨ宸插瓨鍦ㄧ殑mesId
+        List<MdcEquipmentDaySummary> existList = this.lambdaQuery()
+                .in(MdcEquipmentDaySummary::getMesId, mesIdMap.keySet())
+                .list();
+
+
+        // 鍒嗙闇�瑕佹柊澧炲拰鏇存柊鐨勬暟鎹�
+        List<MdcEquipmentDaySummary> toInsert = new ArrayList<>();
+        List<MdcEquipmentDaySummary> toUpdate = new ArrayList<>();
+
+        existList.forEach(exist -> {
+            MdcEquipmentDaySummary newData = mesIdMap.get(exist.getMesId());
+            // 淇濈暀鍘烮D
+            BeanUtils.copyProperties(newData, exist);
+            toUpdate.add(exist);
+            mesIdMap.remove(exist.getMesId());
+        });
+
+        toInsert.addAll(mesIdMap.values());
+
+        // 鎵ц鎵归噺鎿嶄綔
+        boolean insertResult = toInsert.isEmpty() || this.saveBatch(toInsert);
+        boolean updateResult = toUpdate.isEmpty() || this.updateBatchById(toUpdate);
+
+        return insertResult && updateResult;
+    }
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcEquipmentVo.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcEquipmentVo.java
index d99d4e9..840d406 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcEquipmentVo.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcEquipmentVo.java
@@ -21,5 +21,6 @@
     private String deviceCategory;
     private String driveType;
     private String productionName;
+    private String attribute;
     private List<String> productionIds;
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/webservice/impl/EquipmentWebServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/webservice/impl/EquipmentWebServiceImpl.java
index 26d8c68..4465b98 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/webservice/impl/EquipmentWebServiceImpl.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/webservice/impl/EquipmentWebServiceImpl.java
@@ -1,6 +1,7 @@
 package org.jeecg.modules.mdc.webservice.impl;
 
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.modules.mdc.entity.MdcEquipmentDaySchedule;
 import org.jeecg.modules.mdc.entity.MdcEquipmentDaySummary;
@@ -15,8 +16,8 @@
 
 import javax.annotation.Resource;
 import javax.jws.WebService;
-import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 
 /**
@@ -40,41 +41,95 @@
     @Override
     public String equipmentDaySchedule(String msg) {
         log.info("鎺ユ敹MES涓婃姤鏃ヨ鍒掑師濮嬫暟鎹� === {}", msg);
-        List<EquipmentDaySchedule> equipmentDayScheduleList = JSONObject.parseArray(msg, EquipmentDaySchedule.class);
-        if (equipmentDayScheduleList == null || equipmentDayScheduleList.isEmpty()) {
-            WsResult wsResult = new WsResult("0", "json瑙f瀽澶辫触");
-            return JSONObject.toJSONString(wsResult);
-        }
-        List<MdcEquipmentDaySchedule> mdcEquipmentDayScheduleList = new ArrayList<>();
-        for (EquipmentDaySchedule equipmentDaySchedule : equipmentDayScheduleList) {
-            MdcEquipmentDaySchedule mdcEquipmentDaySchedule = new MdcEquipmentDaySchedule();
-            BeanUtils.copyProperties(equipmentDaySchedule, mdcEquipmentDaySchedule);
-            mdcEquipmentDayScheduleList.add(mdcEquipmentDaySchedule);
-        }
-        mdcEquipmentDayScheduleService.saveBatch(mdcEquipmentDayScheduleList);
 
-        log.info("鎺ユ敹MES涓婃姤鏃ヨ鍒掓暟鎹垚鍔燂紒");
-        WsResult wsResult = new WsResult("1", "鎴愬姛");
-        return JSONObject.toJSONString(wsResult);
+        // 1. 鏁版嵁瑙f瀽涓庢牎楠�
+        List<EquipmentDaySchedule> equipmentDayScheduleList;
+        try {
+            equipmentDayScheduleList = JSONObject.parseArray(msg, EquipmentDaySchedule.class);
+            if (CollectionUtils.isEmpty(equipmentDayScheduleList)) {
+                return buildErrorResult("鏁版嵁涓虹┖鎴栬В鏋愬け璐�");
+            }
+        } catch (Exception e) {
+            log.error("JSON瑙f瀽寮傚父", e);
+            return buildErrorResult("鏁版嵁鏍煎紡閿欒");
+        }
+
+        // 2. 鏁版嵁杞崲
+        List<MdcEquipmentDaySchedule> mdcList = equipmentDayScheduleList.stream()
+                .map(source -> {
+                    MdcEquipmentDaySchedule target = new MdcEquipmentDaySchedule();
+                    BeanUtils.copyProperties(source, target);
+                    return target;
+                })
+                .collect(Collectors.toList());
+
+        // 3. 鎸塵esId鎵归噺淇濆瓨鎴栨洿鏂�
+        try {
+            boolean result = mdcEquipmentDayScheduleService.saveOrUpdateBatchByMesId(mdcList);
+            if (!result) {
+                log.error("閮ㄥ垎鏁版嵁淇濆瓨澶辫触");
+                return buildErrorResult("閮ㄥ垎鏁版嵁淇濆瓨澶辫触");
+            }
+
+            log.info("鎴愬姛澶勭悊{}鏉℃棩璁″垝鏁版嵁", mdcList.size());
+            return buildSuccessResult();
+        } catch (Exception e) {
+            log.error("鏃ヨ鍒掓暟鎹繚瀛樺紓甯�", e);
+            return buildErrorResult("绯荤粺澶勭悊寮傚父");
+        }
+    }
+
+    // 鏋勫缓鎴愬姛鍝嶅簲
+    private String buildSuccessResult() {
+        return JSONObject.toJSONString(new WsResult("1", "鎴愬姛"));
+    }
+
+    // 鏋勫缓閿欒鍝嶅簲
+    private String buildErrorResult(String message) {
+        return JSONObject.toJSONString(new WsResult("0", message));
     }
 
     @Override
     public String equipmentDaySummary(String msg) {
         log.info("鎺ユ敹MES涓婃姤鏃ユ眹鎬诲師濮嬫暟鎹� === {}", msg);
-        List<EquipmentDaySummary> equipmentDaySummaryList = JSONObject.parseArray(msg, EquipmentDaySummary.class);
-        if (equipmentDaySummaryList == null || equipmentDaySummaryList.isEmpty()) {
-            WsResult wsResult = new WsResult("0", "json瑙f瀽澶辫触");
-            return JSONObject.toJSONString(wsResult);
+
+        // 1. 鏁版嵁瑙f瀽涓庢牎楠�
+        List<EquipmentDaySummary> equipmentDaySummaryList;
+
+        try {
+            equipmentDaySummaryList = JSONObject.parseArray(msg, EquipmentDaySummary.class);
+            if (CollectionUtils.isEmpty(equipmentDaySummaryList)) {
+                return buildErrorResult("鏁版嵁涓虹┖鎴栬В鏋愬け璐�");
+            }
+        } catch (Exception e) {
+            log.error("JSON瑙f瀽寮傚父", e);
+            return buildErrorResult("鏁版嵁鏍煎紡閿欒");
         }
-        List<MdcEquipmentDaySummary> mdcEquipmentDaySummaryList = new ArrayList<>();
-        for (EquipmentDaySummary equipmentDaySummary : equipmentDaySummaryList) {
-            MdcEquipmentDaySummary mdcEquipmentDaySummary = new MdcEquipmentDaySummary();
-            BeanUtils.copyProperties(equipmentDaySummary, mdcEquipmentDaySummary);
-            mdcEquipmentDaySummaryList.add(mdcEquipmentDaySummary);
+
+        // 2. 鏁版嵁杞崲
+        List<MdcEquipmentDaySummary> mdcList = equipmentDaySummaryList.stream()
+                .map(source -> {
+                    MdcEquipmentDaySummary target = new MdcEquipmentDaySummary();
+                    BeanUtils.copyProperties(source, target);
+                    return target;
+                })
+                .collect(Collectors.toList());
+
+
+        // 3. 鎸塵esId鎵归噺淇濆瓨鎴栨洿鏂�
+        try {
+            boolean result = mdcEquipmentDaySummaryService.saveOrUpdateBatchByMesId(mdcList);
+            if (!result) {
+                log.error("閮ㄥ垎鏁版嵁淇濆瓨澶辫触");
+                return buildErrorResult("閮ㄥ垎鏁版嵁淇濆瓨澶辫触");
+            }
+
+            log.info("鎴愬姛澶勭悊{}鏉℃棩璁″垝鏁版嵁", mdcList.size());
+            return buildSuccessResult();
+        } catch (Exception e) {
+            log.error("鏃ヨ鍒掓暟鎹繚瀛樺紓甯�", e);
+            return buildErrorResult("绯荤粺澶勭悊寮傚父");
         }
-        mdcEquipmentDaySummaryService.saveBatch(mdcEquipmentDaySummaryList);
-        log.info("鎺ユ敹MES涓婃姤鏃ユ眹鎬绘暟鎹垚鍔燂紒");
-        WsResult wsResult = new WsResult("1", "鎴愬姛");
-        return JSONObject.toJSONString(wsResult);
+
     }
 }

--
Gitblit v1.9.3