From cf6b1cf6fa8f7784c6d7c64b7326d4662bc3d4b3 Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期二, 14 十月 2025 17:39:06 +0800
Subject: [PATCH] yys 1.智能排产 2.物料看板 3.报表分析
---
main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java | 592 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 590 insertions(+), 2 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 516da13..be1daf3 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
@@ -1,11 +1,46 @@
package com.ruoyi.business.service.impl;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+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 com.ruoyi.basic.entity.CoalField;
+import com.ruoyi.basic.entity.CoalInfo;
+import com.ruoyi.basic.entity.CoalValue;
+import com.ruoyi.basic.entity.Supply;
+import com.ruoyi.basic.mapper.CoalFieldMapper;
+import com.ruoyi.basic.mapper.CoalInfoMapper;
+import com.ruoyi.basic.mapper.CoalValueMapper;
+import com.ruoyi.basic.mapper.SupplyMapper;
+import com.ruoyi.business.dto.OfficialInventoryDto;
+import com.ruoyi.business.dto.SalesRecordDto;
import com.ruoyi.business.entity.OfficialInventory;
+import com.ruoyi.business.entity.SalesRecord;
import com.ruoyi.business.mapper.OfficialInventoryMapper;
import com.ruoyi.business.service.OfficialInventoryService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import org.springframework.stereotype.Service;
+import com.ruoyi.business.utils.DynamicExcelUtil;
+import com.ruoyi.business.vo.OfficialInventoryExportVo;
+import com.ruoyi.business.vo.OfficialInventoryVo;
+import com.ruoyi.business.vo.SalesRecordExportVo;
+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.common.utils.poi.ExcelUtil;
+import com.ruoyi.system.mapper.SysUserMapper;
+import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+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;
/**
* <p>
@@ -16,7 +51,560 @@
* @since 2025-06-04
*/
@Service
+@Slf4j
@RequiredArgsConstructor
public class OfficialInventoryServiceImpl extends ServiceImpl<OfficialInventoryMapper, OfficialInventory> implements OfficialInventoryService {
+ private final OfficialInventoryMapper officialInventoryMapper;
+
+ private final CoalValueMapper coalValueMapper;
+
+ private final CoalFieldMapper coalFieldMapper;
+
+ private final CoalInfoMapper coalInfoMapper;
+
+ private final SupplyMapper supplyMapper;
+
+ private final SysUserMapper sysUserMapper;
+
+
+ @Override
+ public IPage<OfficialInventoryDto> selectOfficialInventoryList(Page<OfficialInventory> page, OfficialInventoryDto officialInventoryDto) {
+
+ // 鍏堟煡鍑哄師濮嬫暟鎹紙OfficialInventory锛�
+ LambdaQueryWrapper<OfficialInventory> queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.orderByAsc(OfficialInventory::getCreateTime);
+ IPage<OfficialInventory> entityPage = officialInventoryMapper.selectPage(page, queryWrapper);
+
+ // 鍒涘缓涓�涓柊鐨� Dto 鍒嗛〉缁撴灉
+ IPage<OfficialInventoryDto> dtoPage = new Page<>();
+ BeanUtils.copyProperties(entityPage, dtoPage);
+
+ List<OfficialInventoryDto> dtoList = new ArrayList<>();
+
+ List<Long> supplierIds = entityPage.getRecords().stream()
+ .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));
+ supplyMap = infos.stream().collect(Collectors.toMap(Supply::getId, Function.identity()));
+ } else {
+ 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()
+ .toList();
+
+ //鏌ヨ鐓ょids
+ List<Long> coalIds = entityPage.getRecords().stream()
+ .map(OfficialInventory::getCoalId)
+ .distinct()
+ .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<>();
+ }
+
+ // 閬嶅巻姣忔潯璁板綍锛岃繘琛岃浆鎹㈠苟濉厖 fields
+ for (OfficialInventory entity : entityPage.getRecords()) {
+ OfficialInventoryDto dto = new OfficialInventoryDto();
+ BeanUtils.copyProperties(entity, dto);
+
+ // 渚涘簲鍟嗕俊鎭�
+ 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;
+ if (entity.getMergeId() == null) {
+ coalValues = coalValueMapper.selectList(new LambdaQueryWrapper<CoalValue>()
+ .eq(CoalValue::getPlanId, entity.getPendingId())
+ .and(wrapper -> wrapper.ne(CoalValue::getType, "2").or().isNull(CoalValue::getType))
+ );
+ } else {
+ coalValues = coalValueMapper.selectList(new LambdaQueryWrapper<CoalValue>()
+ .eq(CoalValue::getPlanId, entity.getId())
+ .eq(CoalValue::getType, "2")
+ );
+ }
+
+ // 鏋勫缓 Map<fieldName, value>
+ Map<String, String> fieldValueMap = coalValues.stream()
+ .collect(Collectors.toMap(
+ CoalValue::getFields,
+ CoalValue::getCoalValue,
+ (existing, replacement) -> existing // 閲嶅瀛楁淇濈暀绗竴涓�
+ ));
+
+ // 鏋勯�犳渶缁� fields 鍒楄〃锛屽寘鍚墍鏈夊瓧娈靛悕锛屽苟璁剧疆榛樿鍊� "-"
+ List<Map<String, String>> fields = new ArrayList<>();
+ for (String field : allFieldNames) {
+ Map<String, String> fieldMap = new HashMap<>();
+ fieldMap.put(field, fieldValueMap.getOrDefault(field, "-"));
+ fields.add(fieldMap);
+ }
+
+ // 璁剧疆Coal淇℃伅
+ CoalInfo coalInfo = coalInfoMap.get(entity.getCoalId());
+ if (coalInfo != null) {
+ dto.setCoal(coalInfo.getCoal());
+ }
+
+ // 璁剧疆鍒� DTO 涓�
+ dto.setFields(fields);
+ dtoList.add(dto);
+ }
+
+ dtoPage.setRecords(dtoList); // 璁剧疆杞崲鍚庣殑 DtoList
+ return dtoPage;
+ }
+
+ @Override
+ public int editOfficial(OfficialInventoryDto officialInventoryDto) {
+ OfficialInventory officialInventory = new OfficialInventory();
+ BeanUtils.copyProperties(officialInventoryDto, officialInventory);
+
+ if (officialInventoryDto.getMergeId() != null) {
+ // 1. 鏋勫缓鏌ヨ鏉′欢
+ LambdaQueryWrapper<CoalValue> queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.eq(CoalValue::getPlanId, officialInventoryDto.getId())
+ .eq(CoalValue::getType, "2");
+
+ // 2. 鏌ヨ澶氫釜绗﹀悎鏉′欢鐨凜oalValue璁板綍
+ List<CoalValue> coalValues = coalValueMapper.selectList(queryWrapper);
+
+ if (!CollectionUtils.isEmpty(coalValues) && !CollectionUtils.isEmpty(officialInventoryDto.getFields())) {
+ // 3. 鍒涘缓瀛楁鏄犲皠鍏崇郴 (field key -> coal_value)
+ Map<String, String> fieldValueMap = new HashMap<>();
+ for (Map<String, String> fieldMap : officialInventoryDto.getFields()) {
+ fieldValueMap.putAll(fieldMap);
+ }
+
+ // 4. 鏇存柊
+ for (CoalValue coalValue : coalValues) {
+ String fieldKey = coalValue.getFields(); // 鏁版嵁搴撲腑鐨刦ield key
+ if (fieldValueMap.containsKey(fieldKey)) {
+ String newValue = fieldValueMap.get(fieldKey);
+ if (!Objects.equals(coalValue.getCoalValue(), newValue)) {
+ coalValue.setCoalValue(newValue);
+ coalValueMapper.updateById(coalValue);
+ }
+ }
+ }
+ }
+ } else {
+ // 鏋勫缓鏌ヨ鏉′欢
+ LambdaQueryWrapper<CoalValue> queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.eq(CoalValue::getPlanId, officialInventoryDto.getPendingId())
+ .eq(CoalValue::getType, "1");
+
+ // 2. 鏌ヨ澶氫釜绗﹀悎鏉′欢鐨凜oalValue璁板綍
+ List<CoalValue> coalValues = coalValueMapper.selectList(queryWrapper);
+
+ if (!CollectionUtils.isEmpty(coalValues) && !CollectionUtils.isEmpty(officialInventoryDto.getFields())) {
+ // 3. 鍒涘缓瀛楁鏄犲皠鍏崇郴 (field key -> coal_value)
+ Map<String, String> fieldValueMap = new HashMap<>();
+ for (Map<String, String> fieldMap : officialInventoryDto.getFields()) {
+ fieldValueMap.putAll(fieldMap);
+ }
+
+ // 4. 鏇存柊
+ for (CoalValue coalValue : coalValues) {
+ String fieldKey = coalValue.getFields(); // 鏁版嵁搴撲腑鐨刦ield key
+ if (fieldValueMap.containsKey(fieldKey)) {
+ String newValue = fieldValueMap.get(fieldKey);
+ if (!Objects.equals(coalValue.getCoalValue(), newValue)) {
+ coalValue.setCoalValue(newValue);
+ coalValueMapper.updateById(coalValue);
+ }
+ }
+ }
+ }
+ }
+ return officialInventoryMapper.updateById(officialInventory);
+ }
+
+ @Override
+ public List<OfficialInventoryVo> selectOfficialList(OfficialInventoryVo officialInventoryVo) {
+ List<OfficialInventory> officialInventories = officialInventoryMapper.selectList(null);
+ return officialInventories.stream()
+ .map(OI -> {
+ OfficialInventoryVo vo = new OfficialInventoryVo();
+ BeanUtils.copyProperties(OI, vo);
+ CoalInfo coalInfo = coalInfoMapper.selectById(OI.getCoalId());
+ vo.setCoal(coalInfo.getCoal());
+ return vo;
+ })
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public List<OfficialInventory> selectOfficialAll() {
+ return officialInventoryMapper.selectList(null);
+ }
+
+ @Transactional
+ @Override
+ public int mergeAll(OfficialInventoryDto officialInventoryDto) {
+ List<Long> ids = officialInventoryDto.getIds();
+
+ // 鏍¢獙鍙傛暟
+ if (CollectionUtils.isEmpty(ids) || ids.size() < 2) {
+ throw new BaseException("璇烽�変腑鑷冲皯涓ゆ潯鏁版嵁");
+ }
+ if (CollectionUtils.isEmpty(officialInventoryDto.getFields())) {
+ throw new BaseException("瀛楁鍊间笉鑳戒负绌�");
+ }
+
+ // 1. 鎵归噺鏍囪鍒犻櫎鏃ф暟鎹�
+ LambdaUpdateWrapper<OfficialInventory> updateWrapper = new LambdaUpdateWrapper<>();
+ updateWrapper.in(OfficialInventory::getId, ids)
+ .set(OfficialInventory::getDeleted, 1);
+ int rowsAffected = officialInventoryMapper.update(null, updateWrapper);
+ if (rowsAffected == 0) {
+ throw new BaseException("鏈壘鍒板尮閰嶇殑鏁版嵁锛岃纭閫夋嫨鏄惁姝g‘");
+ }
+
+ // 2. 鎻掑叆鏂板簱瀛樿褰�
+ OfficialInventory officialInventory = new OfficialInventory();
+ BeanUtils.copyProperties(officialInventoryDto, officialInventory);
+ officialInventory.setId(null);
+ officialInventory.setMergeId(ids.toString());
+ officialInventory.setSupplierId(officialInventoryDto.getSupplierId());
+ officialInventory.setRegistrantId(SecurityUtils.getLoginUser().getUser().getUserId());
+ if (officialInventoryMapper.insert(officialInventory) <= 0) {
+ throw new BaseException("搴撳瓨璁板綍鍒涘缓澶辫触");
+ }
+
+ // 3. 鎵归噺澶勭悊瀛楁鍊�
+ batchProcessCoalValues(officialInventory.getId(), officialInventoryDto.getFields());
+
+ return rowsAffected;
+ }
+
+ private void batchProcessCoalValues(Long planId, List<Map<String, String>> fields) {
+ // 1. 鎻愬彇鎵�鏈夊敮涓�瀛楁鏍囪瘑
+ Set<String> allFields = fields.stream()
+ .flatMap(map -> map.keySet().stream())
+ .collect(Collectors.toSet());
+
+ // 2. 鏌ヨ瀛楁鏄犲皠鍏崇郴
+ List<CoalField> coalFields = coalFieldMapper.selectList(
+ new LambdaQueryWrapper<CoalField>().in(CoalField::getFields, allFields)
+ );
+
+ Map<String, String> fieldMap = coalFields.stream()
+ .collect(Collectors.toMap(
+ CoalField::getFields,
+ CoalField::getFieldName
+ ));
+
+ // 3. 鏋勯�犲苟鎻掑叆姣忔潯璁板綍
+ CoalValue coalValueTemplate = new CoalValue();
+ coalValueTemplate.setPlanId(planId);
+ coalValueTemplate.setType("2");
+
+ for (Map<String, String> fieldMapEntry : fields) {
+ for (Map.Entry<String, String> entry : fieldMapEntry.entrySet()) {
+ String key = entry.getKey();
+ String value = entry.getValue();
+
+ String fieldName = fieldMap.get(key);
+ if (fieldName == null) {
+ throw new BaseException("瀛楁鍚嶄笉瀛樺湪: " + key);
+ }
+
+ CoalValue coalValue = new CoalValue();
+ BeanUtils.copyProperties(coalValueTemplate, coalValue); // 澶嶇敤妯℃澘灞炴��
+ coalValue.setId(null);
+ coalValue.setCoalValue(value);
+ coalValue.setType("2");
+ coalValue.setPlanId(planId);
+ coalValue.setFields(key);
+ coalValue.setFieldName(fieldName);
+
+ // 鍗曟潯鎻掑叆
+ int result = coalValueMapper.insert(coalValue);
+ if (result <= 0) {
+ throw new BaseException("瀛楁鍊间繚瀛樺け璐ワ紝瀛楁锛�" + key);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void officialInventoryExport(HttpServletResponse response, OfficialInventoryDto officialInventoryDto) {
+ try {
+ // 鑾峰彇鐓よ川瀛楁閰嶇疆
+ List<CoalField> allCoalFields = coalFieldMapper.selectList(null);
+ List<String> dynamicHeaders = allCoalFields.stream()
+ .map(CoalField::getFieldName)
+ .collect(Collectors.toList());
+
+ // 鑾峰彇鏁版嵁
+ List<OfficialInventory> list = officialInventoryDto.getExportIds() != null && !officialInventoryDto.getExportIds().isEmpty()
+ ? officialInventoryMapper.selectByIds(officialInventoryDto.getExportIds())
+ : officialInventoryMapper.selectList(null);
+
+ // 杞崲涓哄鍑篤O
+ List<OfficialInventoryExportVo> exportData = convertToExportVo(list, allCoalFields);
+
+ // 浣跨敤澧炲己鐨凟xcel宸ュ叿瀵煎嚭
+ DynamicExcelUtil<OfficialInventoryExportVo> util =
+ new DynamicExcelUtil<>(OfficialInventoryExportVo.class, dynamicHeaders);
+
+ // 瀵煎嚭Excel
+ util.exportExcel(response, exportData, "搴撳瓨鏁版嵁");
+
+ } catch (Exception e) {
+ log.error("搴撳瓨瀵煎嚭澶辫触", e);
+ // 鍙互鑰冭檻杩斿洖鏇村弸濂界殑閿欒淇℃伅缁欏墠绔�
+ throw new RuntimeException("瀵煎嚭澶辫触: " + e.getMessage());
+ }
+ }
+
+ private List<OfficialInventoryExportVo> convertToExportVo(List<OfficialInventory> list, List<CoalField> coalFields) {
+ if (CollectionUtils.isEmpty(list)) {
+ return Collections.emptyList();
+ }
+
+ // 鏀堕泦鎵�鏈夐渶瑕佹煡璇㈢殑ID
+ Set<Long> coalIds = list.stream()
+ .map(OfficialInventory::getCoalId)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toSet());
+
+ Set<Long> supplierIds = list.stream()
+ .map(OfficialInventory::getSupplierId)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toSet());
+
+ Set<Long> registrantIds = list.stream()
+ .map(OfficialInventory::getRegistrantId)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toSet());
+
+ Set<Long> planIds = list.stream()
+ .map(OfficialInventory::getCoalPlanId)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toSet());
+
+ // 鎵归噺鏌ヨ鍏宠仈鏁版嵁
+ Map<Long, CoalInfo> coalInfoMap = getCoalInfoMap(coalIds);
+ Map<Long, Supply> supplyMap = getSupplyMap(supplierIds);
+ Map<Long, SysUser> userMap = getUserMap(registrantIds);
+ Map<Long, List<CoalValue>> coalValuesMap = getCoalValuesMap(planIds);
+
+ // 鏋勫缓瀛楁ID鍒板瓧娈靛悕绉扮殑鏄犲皠锛屾彁楂樻煡鎵炬晥鐜�
+ Map<String, String> fieldIdToNameMap = coalFields.stream()
+ .collect(Collectors.toMap(CoalField::getFields, CoalField::getFieldName));
+
+ // 杞崲鏁版嵁
+ return list.stream().map(record -> {
+ OfficialInventoryExportVo vo = new OfficialInventoryExportVo();
+ vo.initDynamicFields(); // 鍒濆鍖�
+
+ // 璁剧疆鍩虹灞炴��
+ BeanUtils.copyProperties(record, vo);
+
+ // 璁剧疆鍏宠仈淇℃伅
+ setCoalInfo(vo, record.getCoalId(), coalInfoMap);
+ setSupplierInfo(vo, record.getSupplierId(), supplyMap);
+ setUserMapInfo(vo, record.getRegistrantId(), userMap);
+
+ // 鍔ㄦ�佸瓧娈靛鐞�
+ if (record.getCoalPlanId() != null) {
+ List<CoalValue> values = coalValuesMap.getOrDefault(record.getCoalPlanId(), Collections.emptyList());
+ setDynamicFields(vo, values, fieldIdToNameMap);
+ }
+
+ return vo;
+ }).collect(Collectors.toList());
+ }
+
+ private void setCoalInfo(OfficialInventoryExportVo vo, Long coalId, Map<Long, CoalInfo> coalInfoMap) {
+ if (coalId != null && coalInfoMap.containsKey(coalId)) {
+ vo.setCoal(coalInfoMap.get(coalId).getCoal());
+ }
+ }
+
+ private void setSupplierInfo(OfficialInventoryExportVo vo, Long supplierId, Map<Long, Supply> supplyMap) {
+ if (supplierId != null && supplyMap.containsKey(supplierId)) {
+ vo.setSupplierName(supplyMap.get(supplierId).getSupplierName());
+ }
+ }
+
+ private void setUserMapInfo(OfficialInventoryExportVo vo, Long registrantId, Map<Long, SysUser> userMap) {
+ if (registrantId != null && userMap.containsKey(registrantId)) {
+ vo.setRegistrant(userMap.get(registrantId).getNickName());
+ }
+ }
+
+ private void setDynamicFields(OfficialInventoryExportVo vo, List<CoalValue> values, Map<String, String> fieldIdToNameMap) {
+ for (CoalValue value : values) {
+ String fieldName = fieldIdToNameMap.get(value.getFields());
+ if (fieldName != null) {
+ vo.getCoalQualityProperties().put(fieldName, value.getCoalValue());
+ }
+ }
+ }
+
+ private Map<Long, List<CoalValue>> getCoalValuesMap(Set<Long> planIds) {
+ if (CollectionUtils.isEmpty(planIds)) {
+ return Collections.emptyMap();
+ }
+
+ List<CoalValue> allValues = coalValueMapper.selectList(
+ new LambdaQueryWrapper<CoalValue>()
+ .in(CoalValue::getPlanId, planIds));
+
+ return allValues.stream()
+ .collect(Collectors.groupingBy(CoalValue::getPlanId));
+ }
+
+ private Map<Long, CoalInfo> getCoalInfoMap(Set<Long> coalIds) {
+ if (CollectionUtils.isEmpty(coalIds)) {
+ return Collections.emptyMap();
+ }
+ return coalInfoMapper.selectByIds(coalIds).stream()
+ .collect(Collectors.toMap(CoalInfo::getId, Function.identity()));
+ }
+
+ private Map<Long, Supply> getSupplyMap(Set<Long> supplierIds) {
+ if (CollectionUtils.isEmpty(supplierIds)) {
+ return Collections.emptyMap();
+ }
+ return supplyMapper.selectByIds(supplierIds).stream()
+ .collect(Collectors.toMap(Supply::getId, Function.identity()));
+ }
+
+ private Map<Long, SysUser> getUserMap(Set<Long> registrantIds) {
+ if (CollectionUtils.isEmpty(registrantIds)) {
+ return Collections.emptyMap();
+ }
+ return sysUserMapper.selectBatchIds(registrantIds).stream()
+ .collect(Collectors.toMap(SysUser::getUserId, Function.identity()));
+ }
+
+ @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;
+ if (!coalIds.isEmpty()) {
+ coalInfoMap = coalInfoMapper.selectByIds(coalIds).stream()
+ .collect(Collectors.toMap(CoalInfo::getId, Function.identity()));
+ } else {
+ coalInfoMap = new HashMap<>();
+ }
+
+ Map<Long, Supply> supplyMap;
+ if (!supplierIds.isEmpty()) {
+ supplyMap = supplyMapper.selectByIds(supplierIds).stream()
+ .collect(Collectors.toMap(Supply::getId, Function.identity()));
+ } else {
+ supplyMap = new HashMap<>();
+ log.warn("supplierIds 涓虹┖锛岃烦杩囨煡璇� Supply");
+ }
+
+ Map<Long, List<CoalValue>> coalValuesMap;
+ if (!planIds.isEmpty()) {
+ coalValuesMap = coalValueMapper.selectList(
+ new LambdaQueryWrapper<CoalValue>().in(CoalValue::getPlanId, planIds))
+ .stream()
+ .collect(Collectors.groupingBy(CoalValue::getPlanId));
+ } else {
+ coalValuesMap = new HashMap<>();
+ log.warn("planIds 涓虹┖锛岃烦杩囨煡璇� CoalValue");
+ }
+ // 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())
+ .stream()
+ .map(coalValue -> {
+ Map<String, String> map = new HashMap<>();
+ map.put("fieldName", coalValue.getFieldName());
+ map.put("coalValue", coalValue.getCoalValue());
+ return map;
+ })
+ .collect(Collectors.toList()));
+ 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