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/MdcEquipmentDaySummaryServiceImpl.java | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 52 insertions(+), 0 deletions(-) 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 eb6b7d3..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 @@ -13,4 +21,48 @@ */ @Service public class MdcEquipmentDaySummaryServiceImpl extends ServiceImpl<MdcEquipmentDaySummaryMapper, MdcEquipmentDaySummary> implements IMdcEquipmentDaySummaryService { + @Override + 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; + } } -- Gitblit v1.9.3