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 |   85 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 85 insertions(+), 0 deletions(-)

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 07e78b8..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,10 +1,26 @@
 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;
 import org.jeecg.modules.mdc.mapper.MdcEquipmentDayScheduleMapper;
 import org.jeecg.modules.mdc.service.IMdcEquipmentDayScheduleService;
+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
@@ -13,4 +29,73 @@
  */
 @Service
 public class MdcEquipmentDayScheduleServiceImpl extends ServiceImpl<MdcEquipmentDayScheduleMapper, MdcEquipmentDaySchedule> implements IMdcEquipmentDayScheduleService {
+
+    @Resource
+    private IMdcProductionService mdcProductionService;
+
+    @Override
+    public IPage<MdcEquipmentDaySchedule> pageList(MdcEquipmentDayScheduleVo mdcEquipmentDayScheduleVo, Page<MdcEquipmentDaySchedule> page) {
+        IPage<MdcEquipmentDaySchedule> mdcEquipmentDayScheduleIPage = this.baseMapper.pageList(mdcEquipmentDayScheduleVo, page);
+        if (mdcEquipmentDayScheduleIPage.getRecords() != null && !mdcEquipmentDayScheduleIPage.getRecords().isEmpty()) {
+            MdcProduction mdcProduction = mdcProductionService.getById(mdcEquipmentDayScheduleVo.getProductionId());
+            mdcEquipmentDayScheduleIPage.getRecords().forEach(mdcEquipmentDaySchedule -> {
+                mdcEquipmentDaySchedule.setWorkshop(mdcProduction.getProductionName());
+                BigDecimal batchNum = new BigDecimal(mdcEquipmentDaySchedule.getBatchNum());
+                BigDecimal qualifiedQty = new BigDecimal(mdcEquipmentDaySchedule.getQualifiedQty());
+                if (batchNum.compareTo(BigDecimal.ZERO) != 0) {
+                    mdcEquipmentDaySchedule.setQualifiedRate(qualifiedQty.multiply(new BigDecimal("100")).divide(batchNum, 2, RoundingMode.HALF_UP));
+                }
+                if (batchNum.compareTo(qualifiedQty) > 0) {
+                    mdcEquipmentDaySchedule.setQualifiedStatus("鏈畬鎴�");
+                } else {
+                    mdcEquipmentDaySchedule.setQualifiedStatus("宸插畬鎴�");
+                }
+            });
+        }
+        return mdcEquipmentDayScheduleIPage;
+    }
+
+    @Override
+    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;
+    }
 }

--
Gitblit v1.9.3