From f086c57f64ff30b719d0fd51cbb62a2e5d0240aa Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期二, 20 十月 2026 14:00:26 +0800
Subject: [PATCH] chore: 和鑫电器配置文件
---
src/main/java/com/ruoyi/device/service/impl/DeviceMaintenanceServiceImpl.java | 205 +++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 181 insertions(+), 24 deletions(-)
diff --git a/src/main/java/com/ruoyi/device/service/impl/DeviceMaintenanceServiceImpl.java b/src/main/java/com/ruoyi/device/service/impl/DeviceMaintenanceServiceImpl.java
index 4a92286..6e0ab49 100644
--- a/src/main/java/com/ruoyi/device/service/impl/DeviceMaintenanceServiceImpl.java
+++ b/src/main/java/com/ruoyi/device/service/impl/DeviceMaintenanceServiceImpl.java
@@ -4,49 +4,138 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.basic.enums.RecordTypeEnum;
+import com.ruoyi.basic.utils.FileUtil;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.device.dto.DeviceMaintenanceDto;
import com.ruoyi.device.execl.DeviceMaintenanceExeclDto;
import com.ruoyi.device.mapper.DeviceMaintenanceMapper;
+import com.ruoyi.device.mapper.DeviceMaintenanceItemMapper;
+import com.ruoyi.device.mapper.MaintenanceItemMapper;
import com.ruoyi.device.pojo.DeviceMaintenance;
+import com.ruoyi.device.pojo.DeviceMaintenanceItem;
+import com.ruoyi.device.pojo.MaintenanceItem;
import com.ruoyi.device.service.IDeviceMaintenanceService;
+import com.ruoyi.device.vo.DeviceMaintenanceVo;
+import com.ruoyi.device.vo.DeviceRepairVo;
import com.ruoyi.framework.web.domain.AjaxResult;
-import org.springframework.beans.factory.annotation.Autowired;
+import com.ruoyi.measuringinstrumentledger.mapper.SparePartsMapper;
+import com.ruoyi.measuringinstrumentledger.pojo.SpareParts;
+import com.ruoyi.measuringinstrumentledger.pojo.SparePartsRequisitionRecord;
+import com.ruoyi.measuringinstrumentledger.service.SparePartsRequisitionRecordService;
+import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
+import jakarta.servlet.http.HttpServletResponse;
+import lombok.RequiredArgsConstructor;
+import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import javax.servlet.http.HttpServletResponse;
+import java.math.BigDecimal;
import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.time.LocalDateTime;
@Service
+@RequiredArgsConstructor
public class DeviceMaintenanceServiceImpl extends ServiceImpl<DeviceMaintenanceMapper, DeviceMaintenance> implements IDeviceMaintenanceService {
-
-
- @Autowired
- private DeviceMaintenanceMapper deviceMaintenanceMapper;
+ private final DeviceMaintenanceMapper deviceMaintenanceMapper;
+ private final SparePartsMapper sparePartsMapper;
+ private final SparePartsRequisitionRecordService sparePartsRequisitionRecordService;
+ private final FileUtil fileUtil;
+ private final DeviceMaintenanceItemMapper deviceMaintenanceItemMapper;
+ private final MaintenanceItemMapper maintenanceItemMapper;
@Override
public IPage<DeviceMaintenanceDto> queryPage(Page page, DeviceMaintenanceDto deviceMaintenanceDto) {
-
- return deviceMaintenanceMapper.queryPage(page, deviceMaintenanceDto);
+ IPage<DeviceMaintenanceDto> result = deviceMaintenanceMapper.queryPage(page, deviceMaintenanceDto);
+ if (result.getRecords() != null && !result.getRecords().isEmpty()) {
+ List<Long> ids = result.getRecords().stream().map(DeviceMaintenance::getId).toList();
+ List<DeviceMaintenanceItem> items = deviceMaintenanceItemMapper.selectList(new LambdaQueryWrapper<DeviceMaintenanceItem>().in(DeviceMaintenanceItem::getDeviceMaintenanceId, ids).orderByAsc(DeviceMaintenanceItem::getSortNum));
+ Map<Long, List<DeviceMaintenanceItem>> byRecord = items.stream().collect(Collectors.groupingBy(DeviceMaintenanceItem::getDeviceMaintenanceId));
+ result.getRecords().forEach(record -> record.setMaintenanceItems(byRecord.getOrDefault(record.getId(), new ArrayList<>())));
+ }
+ return result;
}
@Override
- public AjaxResult saveDeviceRepair(DeviceMaintenance deviceRepair) {
- boolean save = this.save(deviceRepair);
- if (save){
+ @Transactional(rollbackFor = Exception.class)
+ public AjaxResult saveDeviceRepair(DeviceMaintenanceDto deviceMaintenance) {
+ List<MaintenanceItem> selectedItems = getSelectedItems(deviceMaintenance.getMaintenanceItemIds(), null, deviceMaintenance.getDeviceLedgerId(), deviceMaintenance.getFrequencyType());
+ if (selectedItems == null) return AjaxResult.error("璇烽�夋嫨鑷冲皯涓�涓湁鏁堢殑淇濆吇椤圭洰");
+ boolean save = this.save(deviceMaintenance);
+ if (save) {
+ saveRecordItems(deviceMaintenance, selectedItems);
+ // 澶勭悊鍥剧墖涓婁紶
+ fileUtil.saveStorageAttachmentByRecordTypeAndRecordId("file", RecordTypeEnum.DEVICE_MAINTENANCE, deviceMaintenance.getId(), deviceMaintenance.getStorageBlobDTOs());
return AjaxResult.success();
}
return AjaxResult.error();
}
@Override
- public AjaxResult updateDeviceRepair(DeviceMaintenance deviceRepair) {
- if (this.updateById(deviceRepair)) {
+ @Transactional(rollbackFor = Exception.class)
+ public AjaxResult updateDeviceDeviceMaintenance(DeviceMaintenanceDto deviceMaintenance) {
+ DeviceMaintenance oldDeviceMaintenance = this.getById(deviceMaintenance.getId());
+ if (oldDeviceMaintenance == null) return AjaxResult.error("淇濆吇璁板綍涓嶅瓨鍦�");
+ if (deviceMaintenance.getMaintenanceItems() != null) {
+ AjaxResult validation = validateRecordItems(deviceMaintenance, oldDeviceMaintenance);
+ if (validation != null) return validation;
+ }
+ // 澶勭悊澶囦欢浣跨敤鎯呭喌
+ if (CollectionUtils.isNotEmpty(deviceMaintenance.getSparePartsUseList())) {
+ List<Long> sparePartIds = new ArrayList<>();
+ for (DeviceMaintenance.SparePartUse sparePartUse : deviceMaintenance.getSparePartsUseList()) {
+ // 鑾峰彇澶囦欢淇℃伅
+ SpareParts spareParts = sparePartsMapper.selectById(sparePartUse.getId());
+ if (spareParts != null) {
+ // 妫�鏌ユ暟閲忔槸鍚﹁冻澶�
+ if (spareParts.getQuantity().compareTo(new BigDecimal(sparePartUse.getQuantity())) >= 0) {
+ // 鏇存柊鏁伴噺
+ spareParts.setQuantity(spareParts.getQuantity().subtract(new BigDecimal(sparePartUse.getQuantity())));
+ sparePartsMapper.updateById(spareParts);
+ sparePartIds.add(sparePartUse.getId());
+
+ // 鍒涘缓澶囦欢棰嗙敤璁板綍
+ SparePartsRequisitionRecord record = new SparePartsRequisitionRecord();
+ record.setSourceType(1); // 1 淇濆吇
+ record.setSourceId(deviceMaintenance.getId());
+ record.setDeviceLedgerId(oldDeviceMaintenance.getDeviceLedgerId());
+ record.setSparePartsId(sparePartUse.getId());
+ record.setQuantity(sparePartUse.getQuantity());
+ sparePartsRequisitionRecordService.save(record);
+ } else {
+ return AjaxResult.error("澶囦欢 " + spareParts.getName() + " 鏁伴噺涓嶈冻");
+ }
+ }
+ }
+ // 鏇存柊澶囦欢IDs瀛楁
+ if (!sparePartIds.isEmpty()) {
+ deviceMaintenance.setSparePartsIds(StringUtils.join(sparePartIds, ","));
+ }
+ }
+
+ if (deviceMaintenance.getMaintenanceItems() != null) {
+ AjaxResult itemResult = updateRecordItems(deviceMaintenance, oldDeviceMaintenance);
+ if (itemResult != null) return itemResult;
+ } else if (deviceMaintenance.getMaintenanceItemIds() != null) {
+ List<MaintenanceItem> selectedItems = getSelectedItems(deviceMaintenance.getMaintenanceItemIds(), deviceMaintenance.getId(), oldDeviceMaintenance.getDeviceLedgerId(), oldDeviceMaintenance.getFrequencyType());
+ if (selectedItems == null) return AjaxResult.error("璇烽�夋嫨鑷冲皯涓�涓湁鏁堢殑淇濆吇椤圭洰");
+ deviceMaintenanceItemMapper.delete(new LambdaQueryWrapper<DeviceMaintenanceItem>().eq(DeviceMaintenanceItem::getDeviceMaintenanceId, deviceMaintenance.getId()));
+ saveRecordItems(deviceMaintenance, selectedItems);
+ }
+
+ if (this.updateById(deviceMaintenance)) {
+ // 澶勭悊鍥剧墖涓婁紶
+ fileUtil.saveStorageAttachmentByRecordTypeAndRecordId("file", RecordTypeEnum.DEVICE_MAINTENANCE, deviceMaintenance.getId(), deviceMaintenance.getStorageBlobDTOs());
return AjaxResult.success();
}
return AjaxResult.error();
@@ -54,21 +143,89 @@
@Override
public void export(HttpServletResponse response, Long[] ids) {
- ArrayList<Long> arrayList = new ArrayList<>();
- Arrays.stream(ids).map(id -> {
- return arrayList.add( id);
- });
- List<DeviceMaintenance> supplierManageList = deviceMaintenanceMapper.selectBatchIds(arrayList);
+ List<DeviceMaintenance> supplierManageList = deviceMaintenanceMapper.selectList(null);
ArrayList<DeviceMaintenanceExeclDto> deviceLedgerExeclDtos = new ArrayList<>();
- supplierManageList.stream().forEach(deviceMaintenance -> {
+ supplierManageList.forEach(deviceMaintenance -> {
DeviceMaintenanceExeclDto deviceRepairExeclDto = new DeviceMaintenanceExeclDto();
- BeanUtils.copyProperties(deviceMaintenance,deviceRepairExeclDto);
- deviceRepairExeclDto.setStatus(deviceMaintenance.getStatus() == 0 ? "寰呯淮淇�" : "瀹岀粨");
- deviceRepairExeclDto.setMaintenanceResult(deviceMaintenance.getMaintenanceResult() == 0 ? "缁翠慨" : "瀹屽ソ");
-
+ BeanUtils.copyProperties(deviceMaintenance, deviceRepairExeclDto);
+ List<DeviceMaintenanceItem> recordItems = deviceMaintenanceItemMapper.selectList(new LambdaQueryWrapper<DeviceMaintenanceItem>().eq(DeviceMaintenanceItem::getDeviceMaintenanceId, deviceMaintenance.getId()).orderByAsc(DeviceMaintenanceItem::getSortNum));
+ deviceRepairExeclDto.setMachineryCategory(recordItems.stream().map(DeviceMaintenanceItem::getItemName).collect(Collectors.joining("銆�")));
+ deviceRepairExeclDto.setStatus(deviceMaintenance.getStatus() == 0 ? "寰呯淮淇�" : deviceMaintenance.getStatus() == 1 ? "瀹岀粨" : "澶辫触");
+// deviceRepairExeclDto.setMaintenanceResult(deviceMaintenance.getMaintenanceResult() != null && deviceMaintenance.getMaintenanceResult() == 0 ? "缁翠慨" : "瀹屽ソ");
deviceLedgerExeclDtos.add(deviceRepairExeclDto);
});
ExcelUtil<DeviceMaintenanceExeclDto> util = new ExcelUtil<DeviceMaintenanceExeclDto>(DeviceMaintenanceExeclDto.class);
util.exportExcel(response, deviceLedgerExeclDtos, "璁惧鎶ヤ慨瀵煎嚭");
}
+
+ @Override
+ public DeviceMaintenanceVo detailById(Long id) {
+ DeviceMaintenanceVo vo = deviceMaintenanceMapper.detailById(id);
+ if (vo != null) {
+ vo.setMaintenanceItems(deviceMaintenanceItemMapper.selectList(new LambdaQueryWrapper<DeviceMaintenanceItem>().eq(DeviceMaintenanceItem::getDeviceMaintenanceId, id).orderByAsc(DeviceMaintenanceItem::getSortNum)));
+ }
+ vo.setStorageBlobVOs(fileUtil.getStorageBlobVOsByRecordTypeAndRecordId(RecordTypeEnum.DEVICE_MAINTENANCE, id));
+ return vo;
+ }
+
+ private List<MaintenanceItem> getSelectedItems(List<Long> ids, Long recordId, Long deviceId, String frequencyType) {
+ if (deviceId == null || !List.of("DAILY", "WEEKLY", "MONTHLY", "QUARTERLY").contains(frequencyType) || ids == null || ids.isEmpty() || new HashSet<>(ids).size() != ids.size())
+ return null;
+ List<MaintenanceItem> items = maintenanceItemMapper.selectList(new LambdaQueryWrapper<MaintenanceItem>().in(MaintenanceItem::getId, ids));
+ if (items.size() != ids.size()) return null;
+ if (items.stream().anyMatch(item -> (item.getDeviceLedgerId() != null && !deviceId.equals(item.getDeviceLedgerId())) || !(frequencyType.equals(item.getFrequencyType()) || "ALL".equals(item.getFrequencyType()))))
+ return null;
+ Map<Long, MaintenanceItem> itemMap = items.stream().collect(Collectors.toMap(MaintenanceItem::getId, item -> item));
+ Set<Long> existingIds = recordId == null ? Collections.emptySet() : deviceMaintenanceItemMapper.selectList(new LambdaQueryWrapper<DeviceMaintenanceItem>().eq(DeviceMaintenanceItem::getDeviceMaintenanceId, recordId)).stream().map(DeviceMaintenanceItem::getMaintenanceItemId).collect(Collectors.toSet());
+ if (items.stream().anyMatch(item -> (item.getDeleted() != null && item.getDeleted() == 1 || item.getIsActive() == null || item.getIsActive() != 1) && !existingIds.contains(item.getId())))
+ return null;
+ return ids.stream().map(itemMap::get).toList();
+ }
+
+ private void saveRecordItems(DeviceMaintenance record, List<MaintenanceItem> selectedItems) {
+ for (int i = 0; i < selectedItems.size(); i++) {
+ MaintenanceItem source = selectedItems.get(i);
+ DeviceMaintenanceItem item = new DeviceMaintenanceItem();
+ item.setDeviceMaintenanceId(record.getId());
+ item.setMaintenanceItemId(source.getId());
+ item.setItemProject(source.getItemProject());
+ item.setItemName(source.getItemName());
+ item.setItemStatus(0);
+ item.setSortNum(i);
+ item.setTenantId(record.getTenantId());
+ item.setDeptId(record.getDeptId());
+ deviceMaintenanceItemMapper.insert(item);
+ }
+ }
+
+ private AjaxResult updateRecordItems(DeviceMaintenanceDto request, DeviceMaintenance record) {
+ AjaxResult validation = validateRecordItems(request, record);
+ if (validation != null) return validation;
+ List<DeviceMaintenanceItem> current = deviceMaintenanceItemMapper.selectList(new LambdaQueryWrapper<DeviceMaintenanceItem>().eq(DeviceMaintenanceItem::getDeviceMaintenanceId, record.getId()));
+ Map<Long, DeviceMaintenanceItem> currentById = current.stream().collect(Collectors.toMap(DeviceMaintenanceItem::getId, item -> item));
+ for (DeviceMaintenanceItem requested : request.getMaintenanceItems()) {
+ DeviceMaintenanceItem item = currentById.get(requested.getId());
+ int status = requested.getItemStatus() == null ? 0 : requested.getItemStatus();
+ item.setItemStatus(status);
+ if (requested.getRemarks() != null) item.setRemarks(requested.getRemarks());
+ item.setCompletedBy(status == 1 ? request.getMaintenanceActuallyName() : null);
+ item.setCompletedTime(status == 1 ? LocalDateTime.now() : null);
+ deviceMaintenanceItemMapper.updateById(item);
+ }
+ return null;
+ }
+
+ private AjaxResult validateRecordItems(DeviceMaintenanceDto request, DeviceMaintenance record) {
+ List<DeviceMaintenanceItem> requestedItems = request.getMaintenanceItems();
+ if (requestedItems.stream().anyMatch(item -> item == null || item.getId() == null || (item.getItemStatus() != null && (item.getItemStatus() < 0 || item.getItemStatus() > 2)))) {
+ return AjaxResult.error("淇濆吇椤圭洰鐘舵�佹棤鏁�");
+ }
+ List<DeviceMaintenanceItem> current = deviceMaintenanceItemMapper.selectList(new LambdaQueryWrapper<DeviceMaintenanceItem>().eq(DeviceMaintenanceItem::getDeviceMaintenanceId, record.getId()));
+ Set<Long> currentIds = current.stream().map(DeviceMaintenanceItem::getId).collect(Collectors.toSet());
+ Set<Long> requestedIds = requestedItems.stream().map(DeviceMaintenanceItem::getId).collect(Collectors.toSet());
+ if (requestedIds.size() != current.size() || !requestedIds.equals(currentIds)) {
+ return AjaxResult.error("淇濆吇椤圭洰娓呭崟宸插彉鍖栵紝璇峰埛鏂板悗閲嶈瘯");
+ }
+ return null;
+ }
}
--
Gitblit v1.9.3