From cb966ac5c02835eab5a99b7b93a5a9a063cf3201 Mon Sep 17 00:00:00 2001 From: liding <756868258@qq.com> Date: 星期三, 25 六月 2025 15:55:08 +0800 Subject: [PATCH] 人员优化 --- main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java | 65 +++++++++++++++++++++++++++++++- 1 files changed, 62 insertions(+), 3 deletions(-) diff --git a/main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java b/main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java index 35c3e91..5e340eb 100644 --- a/main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java +++ b/main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java @@ -7,23 +7,30 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.basic.entity.CoalField; +import com.ruoyi.basic.entity.CoalInfo; import com.ruoyi.basic.entity.CoalValue; import com.ruoyi.basic.mapper.CoalFieldMapper; +import com.ruoyi.basic.mapper.CoalInfoMapper; import com.ruoyi.basic.mapper.CoalValueMapper; import com.ruoyi.business.dto.PendingInventoryDto; import com.ruoyi.business.entity.OfficialInventory; import com.ruoyi.business.entity.PendingInventory; import com.ruoyi.business.mapper.OfficialInventoryMapper; import com.ruoyi.business.mapper.PendingInventoryMapper; +import com.ruoyi.business.service.InputInventoryRecordService; +import com.ruoyi.business.service.InventorySummaryService; import com.ruoyi.business.service.PendingInventoryService; +import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.exception.base.BaseException; import com.ruoyi.common.utils.bean.BeanUtils; +import com.ruoyi.system.mapper.SysUserMapper; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.util.*; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -46,6 +53,14 @@ private final CoalFieldMapper coalFieldMapper; + private final CoalInfoMapper coalInfoMapper; + + private final SysUserMapper sysUserMapper; + + private final InputInventoryRecordService inputInventoryRecordService; + + private final InventorySummaryService inventorySummaryService; + @Override public IPage<PendingInventoryDto> selectPendingInventoryList(Page page, PendingInventoryDto pendingInventoryDto) { // 1. 鏋勫缓涓绘煡璇� @@ -65,19 +80,62 @@ .map(PendingInventory::getId) .collect(Collectors.toList()); - // 5. 鎵归噺鏌ヨ鍏宠仈鐨勬寮忓簱瀛樹俊鎭� + // 5. 鎵归噺鏌ヨ鍏宠仈鐨勭叅鐐俊鎭拰姝e紡搴撳瓨淇℃伅 + List<Long> coalIds = pendingInventoryPage.getRecords().stream() + .map(PendingInventory::getCoalId) + .distinct() + .collect(Collectors.toList()); + + // 鎵归噺鏌ヨCoalInfo + Map<Long, CoalInfo> coalInfoMap; + if (!coalIds.isEmpty()) { + List<CoalInfo> coalInfos = coalInfoMapper.selectList(new LambdaQueryWrapper<CoalInfo>().in(CoalInfo::getId, coalIds)); + coalInfoMap = coalInfos.stream().collect(Collectors.toMap(CoalInfo::getId, Function.identity())); + } else { + coalInfoMap = new HashMap<>(); + } + + // 5. 鎵归噺鏌ヨ鐧昏浜篿d + List<Long> registrantIds = pendingInventoryPage.getRecords().stream() + .map(PendingInventory::getRegistrantId) + .distinct() + .toList(); + // 鎵归噺鏌ヨ鐧昏浜� + Map<Long, SysUser> sysUserMap; + if (!registrantIds.isEmpty()) { + List<SysUser> sysUsers = sysUserMapper.selectList(registrantIds); + sysUserMap = sysUsers.stream().collect(Collectors.toMap(SysUser::getUserId, Function.identity())); + } else { + sysUserMap = new HashMap<>(); + } + + // 鎵归噺鏌ヨ姝e紡搴撳瓨淇℃伅 Map<Long, Long> pendingToOfficialMap = getOfficialInventoryMap(pendingIds); - // 6. 浣跨敤MyBatis-Plus鐨刢onvert鏂规硶杞崲DTO + // 6. 杞崲DTO骞惰缃浉鍏冲瓧娈� return pendingInventoryPage.convert(record -> { PendingInventoryDto dto = new PendingInventoryDto(); BeanUtils.copyProperties(record, dto); + // 璁剧疆Coal淇℃伅 + CoalInfo coalInfo = coalInfoMap.get(record.getCoalId()); + if (coalInfo != null) { + dto.setCoal(coalInfo.getCoal()); + } + + // 璁剧疆鐧昏浜� + SysUser sysUser = sysUserMap.get(record.getRegistrantId()); + if (sysUser != null) { + dto.setRegistrant(sysUser.getNickName()); + } + // 浠庨鍔犺浇鐨凪ap涓幏鍙杘fficialId dto.setOfficialId(pendingToOfficialMap.getOrDefault(record.getId(), null)); + return dto; }); } + // 鎵归噺鑾峰彇寰呭鐞嗗簱瀛樹笌姝e紡搴撳瓨鐨勬槧灏勫叧绯� private Map<Long, Long> getOfficialInventoryMap(List<Long> pendingIds) { @@ -162,6 +220,7 @@ coalValue.setCoalValue(value); coalValue.setFields(key); coalValue.setFieldName(fieldName); + coalValue.setType(String.valueOf(1)); i = coalValueMapper.insert(coalValue); } } @@ -186,7 +245,7 @@ officialInventory.setPendingId(pendingInventoryDto.getPId()); officialInventory.setInventoryQuantity(quantity); officialInventoryMapper.insert(officialInventory); - }else { + } else { OfficialInventory officialInventory = officialInventoryMapper.selectById(pendingInventoryDto.getOfficialId()); officialInventory.setInventoryQuantity(quantity.add(officialInventory.getInventoryQuantity())); officialInventoryMapper.updateById(officialInventory); -- Gitblit v1.9.3