From 6733a32d4bcd7ad3ec3f109da0f3d2524766f7bb Mon Sep 17 00:00:00 2001 From: liding <756868258@qq.com> Date: 星期二, 15 七月 2025 15:54:33 +0800 Subject: [PATCH] 1.数据优化 2.配煤计算器入库优化 --- main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java | 95 ++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 92 insertions(+), 3 deletions(-) diff --git a/main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java b/main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java index ceafff7..eba9e50 100644 --- a/main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java +++ b/main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java @@ -19,14 +19,18 @@ import com.ruoyi.business.mapper.OfficialInventoryMapper; import com.ruoyi.business.service.OfficialInventoryService; import com.ruoyi.business.vo.OfficialInventoryVo; +import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.exception.base.BaseException; import com.ruoyi.common.utils.SecurityUtils; 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.BiConsumer; import java.util.function.Function; import java.util.stream.Collectors; @@ -52,9 +56,11 @@ private final SupplyMapper supplyMapper; + private final SysUserMapper sysUserMapper; + @Override - public IPage<OfficialInventoryDto> selectOfficialInventoryList(Page page, OfficialInventoryDto officialInventoryDto) { + public IPage<OfficialInventoryDto> selectOfficialInventoryList(Page<OfficialInventory> page, OfficialInventoryDto officialInventoryDto) { // 鍏堟煡鍑哄師濮嬫暟鎹紙OfficialInventory锛� LambdaQueryWrapper<OfficialInventory> queryWrapper = new LambdaQueryWrapper<>(); @@ -71,6 +77,10 @@ .map(OfficialInventory::getSupplierId) .toList(); + List<Long> registrantIds = entityPage.getRecords().stream() + .map(OfficialInventory::getRegistrantId) + .toList(); + Map<Long, Supply> supplyMap; if (!supplierIds.isEmpty()) { List<Supply> infos = supplyMapper.selectList(new LambdaQueryWrapper<Supply>().in(Supply::getId, supplierIds)); @@ -79,19 +89,27 @@ supplyMap = new HashMap<>(); } + //鐧昏浜� + Map<Long, SysUser> userMap; + if (!registrantIds.isEmpty()) { + List<SysUser> sysUsers = sysUserMapper.selectList(registrantIds); + userMap = sysUsers.stream().collect(Collectors.toMap(SysUser::getUserId, Function.identity())); + }else { + userMap = new HashMap<>(); + } // 鏌ヨ鎵�鏈夊彲鐢ㄥ瓧娈碉紙CoalField锛� List<CoalField> coalFields = coalFieldMapper.selectList(null); List<String> allFieldNames = coalFields.stream() .map(CoalField::getFields) .distinct() - .collect(Collectors.toList()); + .toList(); //鏌ヨ鐓ょids List<Long> coalIds = entityPage.getRecords().stream() .map(OfficialInventory::getCoalId) .distinct() - .collect(Collectors.toList()); + .toList(); // 鎵归噺鏌ヨCoalInfo Map<Long, CoalInfo> coalInfoMap; @@ -111,6 +129,12 @@ Supply supply = supplyMap.get(entity.getSupplierId()); if (supply != null) { dto.setSupplierName(supply.getSupplierName()); + } + + // 鐧昏浜� + SysUser sysUser = userMap.get(entity.getRegistrantId()); + if (sysUser != null) { + dto.setRegistrant(sysUser.getNickName()); } List<CoalValue> coalValues; @@ -330,4 +354,69 @@ } } + @Override + public List<OfficialInventoryDto> coalBlendingList() { + // 1. 鏌ヨ鍩虹搴撳瓨鏁版嵁 + List<OfficialInventory> officialInventories = officialInventoryMapper.selectList(null); + // 2. 鏀堕泦鎵�鏈夐渶瑕佹煡璇㈢殑ID + Set<Long> coalIds = new HashSet<>(); + Set<Long> supplierIds = new HashSet<>(); + Set<Long> planIds = new HashSet<>(); + + officialInventories.forEach(inventory -> { + coalIds.add(inventory.getCoalId()); + supplierIds.add(inventory.getSupplierId()); + planIds.add(inventory.getCoalPlanId()); + }); + // 3. 鎵归噺鏌ヨ鍏宠仈鏁版嵁 + Map<Long, CoalInfo> coalInfoMap = coalInfoMapper.selectByIds(coalIds).stream() + .collect(Collectors.toMap(CoalInfo::getId, Function.identity())); + + Map<Long, Supply> supplyMap = supplyMapper.selectByIds(supplierIds).stream() + .collect(Collectors.toMap(Supply::getId, Function.identity())); + + Map<Long, List<CoalValue>> coalValuesMap = coalValueMapper.selectList( + new LambdaQueryWrapper<CoalValue>().in(CoalValue::getPlanId, planIds)) + .stream() + .collect(Collectors.groupingBy(CoalValue::getPlanId)); + // 4. 缁勮DTO + return officialInventories.stream() + .map(inventory -> { + OfficialInventoryDto dto = new OfficialInventoryDto(); + BeanUtils.copyProperties(inventory, dto); + // 璁剧疆鐓ょ淇℃伅 + CoalInfo coalInfo = coalInfoMap.get(inventory.getCoalId()); + Supply supply = supplyMap.get(inventory.getSupplierId()); + if (coalInfo != null && supply != null) { + dto.setSupplierCoal(supply.getSupplierName() + " - " + coalInfo.getCoal()); + } + // 璁剧疆鐓よ川鏁版嵁 + dto.setCoalValues(coalValuesMap.getOrDefault(inventory.getCoalPlanId(), Collections.emptyList())); + return dto; + }) + .collect(Collectors.toList()); + } + + @Override + public Map<String, BigDecimal> selectOfficialAllInfo() { + // 1. 鏌ヨ official_inventory 琛ㄦ暟鎹� + List<OfficialInventory> officialInventories = officialInventoryMapper.selectList(null); + + // 鐢ㄤ簬瀛樺偍鏈�缁堢粨鏋滐紝key 涓虹叅绉嶅悕绉帮紝value 涓哄簱瀛樻暟閲忔嫾鎺モ�滃惃鈥� + Map<String, BigDecimal> resultMap = new LinkedHashMap<>(); + + // 2. 閬嶅巻鏌ヨ缁撴灉锛屽叧鑱� coalInfo 鑾峰彇鐓ょ鍚嶇О骞剁粍瑁呮暟鎹� + for (OfficialInventory inventory : officialInventories) { + Long coalId = inventory.getCoalId(); + // 鏍规嵁 coalId 鍒� coalInfoMapper 鏌ヨ鐓ょ鍚嶇О + CoalInfo coalInfo = coalInfoMapper.selectById(coalId); + if (coalInfo != null) { + String coalName = coalInfo.getCoal(); // 鍋囪 CoalInfo 鏈� getCoalName 鏂规硶鑾峰彇鐓ょ鍚嶇О + BigDecimal quantity = inventory.getInventoryQuantity(); + resultMap.put(coalName, quantity); + } + } + return resultMap; + } + } -- Gitblit v1.9.3