From c0efb2e8358f4e7ee0774c340afd453c3d0c2471 Mon Sep 17 00:00:00 2001 From: liding <756868258@qq.com> Date: 星期二, 10 六月 2025 17:19:03 +0800 Subject: [PATCH] 1.待入库煤质维护入正式库 2.电子档案tree --- main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java | 79 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 79 insertions(+), 0 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 ac74173..adbc5e9 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 @@ -3,19 +3,31 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; 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.CoalValue; import com.ruoyi.basic.mapper.CoalFieldMapper; 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.PendingInventoryService; +import com.ruoyi.common.exception.base.BaseException; import com.ruoyi.common.utils.bean.BeanUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; /** * <p> @@ -30,6 +42,8 @@ public class PendingInventoryServiceImpl extends ServiceImpl<PendingInventoryMapper, PendingInventory> implements PendingInventoryService { private final PendingInventoryMapper pendingInventoryMapper; + + private final OfficialInventoryMapper officialInventoryMapper; private final CoalValueMapper coalValueMapper; @@ -66,4 +80,69 @@ // 鎵ц鎵归噺閫昏緫鍒犻櫎 return pendingInventoryMapper.update(null, updateWrapper); } + + @Transactional + @Override + public int addOrEditCoalValue(PendingInventoryDto pendingInventoryDto) { + // Step 1: 鍒犻櫎鍘熸湁 planId 鐩稿叧鏁版嵁 + coalValueMapper.delete(new LambdaQueryWrapper<CoalValue>() + .eq(CoalValue::getPlanId, pendingInventoryDto.getPId())); + // Step 2: 鏋勫缓鍩虹 CoalValue 瀵硅薄 + CoalValue coalValue = new CoalValue(); + BeanUtils.copyProperties(coalValue, pendingInventoryDto); + coalValue.setPlanId(pendingInventoryDto.getPId()); + List<Map<String, String>> fieldValue = pendingInventoryDto.getFieldValue(); + if (CollectionUtils.isEmpty(fieldValue)) { + throw new BaseException("瀛楁鍊间笉鑳戒负绌�"); + } + // Step 3: 鎻愬墠鑾峰彇鎵�鏈� field -> CoalField 鏄犲皠锛岄伩鍏嶉噸澶嶆煡搴� + Set<String> allFields = fieldValue.stream() + .flatMap(map -> map.keySet().stream()) + .collect(Collectors.toSet()); + 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)); + // Step 4: 鎵归噺鎻掑叆 + int i = 0; + for (Map<String, String> fieldMapEntry : fieldValue) { + 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("瀛楁鍚嶄笉瀛樺湪"); + } + coalValue.setId(null); // 娓呯┖ id锛岀‘淇濇瘡娆¢兘鏄柊璁板綍 + coalValue.setCoalValue(value); + coalValue.setFields(key); + coalValue.setFieldName(fieldName); + i = coalValueMapper.insert(coalValue); + } + } + if (i > 0) { + BigDecimal quantity = pendingInventoryDto.getInventoryQuantity(); + PendingInventory pendingInventory = pendingInventoryMapper.selectById(pendingInventoryDto.getPId()); + if (pendingInventory == null) { + throw new BaseException("寰呭叆搴撹褰曚笉瀛樺湪"); + } + BigDecimal left = pendingInventory.getInventoryQuantity().subtract(quantity); + if (left.compareTo(BigDecimal.ZERO) > 0) { + pendingInventory.setInventoryQuantity(left); + pendingInventoryMapper.updateById(pendingInventory); + } else { + pendingInventoryMapper.deleteById(pendingInventoryDto.getPId()); + } + officialInventoryMapper.delete(new LambdaQueryWrapper<OfficialInventory>().eq(OfficialInventory::getPendingId, pendingInventoryDto.getPId())); + OfficialInventory officialInventory = new OfficialInventory(); + BeanUtils.copyProperties(pendingInventory, officialInventory); + officialInventory.setId(null); + officialInventory.setPendingId(pendingInventoryDto.getPId()); + officialInventory.setInventoryQuantity(quantity); + officialInventoryMapper.insert(officialInventory); + } + return i; + } } -- Gitblit v1.9.3