| | |
| | | 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 |
| | |
| | | */ |
| | | @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; |
| | | } |
| | | |
| | | // 按mesId分组处理 |
| | | 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()); |
| | | // 保留原ID |
| | | 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; |
| | | } |
| | | } |