From 49e1bc66ebaf696ebd3fc3ed33d65c8795fd3cde Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期二, 01 七月 2025 18:05:12 +0800
Subject: [PATCH] 1.巡检定时任务 2.设备管理 3.文档查询
---
main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 113 insertions(+), 1 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 ba427bd..ceafff7 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
@@ -7,9 +7,13 @@
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.entity.OfficialInventory;
import com.ruoyi.business.mapper.OfficialInventoryMapper;
@@ -23,6 +27,7 @@
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
+import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -43,12 +48,17 @@
private final CoalFieldMapper coalFieldMapper;
+ private final CoalInfoMapper coalInfoMapper;
+
+ private final SupplyMapper supplyMapper;
+
@Override
public IPage<OfficialInventoryDto> selectOfficialInventoryList(Page page, OfficialInventoryDto officialInventoryDto) {
// 鍏堟煡鍑哄師濮嬫暟鎹紙OfficialInventory锛�
LambdaQueryWrapper<OfficialInventory> queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.orderByAsc(OfficialInventory::getCreateTime);
IPage<OfficialInventory> entityPage = officialInventoryMapper.selectPage(page, queryWrapper);
// 鍒涘缓涓�涓柊鐨� Dto 鍒嗛〉缁撴灉
@@ -57,6 +67,19 @@
List<OfficialInventoryDto> dtoList = new ArrayList<>();
+ List<Long> supplierIds = entityPage.getRecords().stream()
+ .map(OfficialInventory::getSupplierId)
+ .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<>();
+ }
+
+
// 鏌ヨ鎵�鏈夊彲鐢ㄥ瓧娈碉紙CoalField锛�
List<CoalField> coalFields = coalFieldMapper.selectList(null);
List<String> allFieldNames = coalFields.stream()
@@ -64,10 +87,32 @@
.distinct()
.collect(Collectors.toList());
+ //鏌ヨ鐓ょids
+ List<Long> coalIds = entityPage.getRecords().stream()
+ .map(OfficialInventory::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<>();
+ }
+
// 閬嶅巻姣忔潯璁板綍锛岃繘琛岃浆鎹㈠苟濉厖 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());
+ }
+
List<CoalValue> coalValues;
if (entity.getMergeId() == null) {
coalValues = coalValueMapper.selectList(new LambdaQueryWrapper<CoalValue>()
@@ -97,6 +142,12 @@
fields.add(fieldMap);
}
+ // 璁剧疆Coal淇℃伅
+ CoalInfo coalInfo = coalInfoMap.get(entity.getCoalId());
+ if (coalInfo != null) {
+ dto.setCoal(coalInfo.getCoal());
+ }
+
// 璁剧疆鍒� DTO 涓�
dto.setFields(fields);
dtoList.add(dto);
@@ -110,6 +161,64 @@
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);
}
@@ -120,6 +229,8 @@
.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());
@@ -157,7 +268,8 @@
BeanUtils.copyProperties(officialInventoryDto, officialInventory);
officialInventory.setId(null);
officialInventory.setMergeId(ids.toString());
- officialInventory.setRegistrantId(SecurityUtils.getLoginUser().getUser().getUserName());
+ officialInventory.setSupplierId(officialInventoryDto.getSupplierId());
+ officialInventory.setRegistrantId(SecurityUtils.getLoginUser().getUser().getUserId());
if (officialInventoryMapper.insert(officialInventory) <= 0) {
throw new BaseException("搴撳瓨璁板綍鍒涘缓澶辫触");
}
--
Gitblit v1.9.3