From a217dbfc7378ff9cf5b6d3ca8b229a2b9d932e51 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期二, 02 六月 2026 11:52:19 +0800
Subject: [PATCH] feat(device): 添加设备保养验收功能和年度定时任务支持

---
 src/main/java/com/ruoyi/stock/controller/StockInventoryController.java |  126 ++++++++++++++++++++++++++++++++++++------
 1 files changed, 108 insertions(+), 18 deletions(-)

diff --git a/src/main/java/com/ruoyi/stock/controller/StockInventoryController.java b/src/main/java/com/ruoyi/stock/controller/StockInventoryController.java
index 3c67ab1..a04f869 100644
--- a/src/main/java/com/ruoyi/stock/controller/StockInventoryController.java
+++ b/src/main/java/com/ruoyi/stock/controller/StockInventoryController.java
@@ -1,25 +1,32 @@
 package com.ruoyi.stock.controller;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum;
 import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.device.pojo.DeviceLedger;
+import com.ruoyi.device.service.IDeviceLedgerService;
 import com.ruoyi.framework.aspectj.lang.annotation.Log;
 import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
 import com.ruoyi.framework.web.domain.R;
+import com.ruoyi.http.service.impl.RealTimeEnergyConsumptionServiceImpl;
 import com.ruoyi.stock.dto.StockInventoryDto;
+import com.ruoyi.stock.dto.StockIotRealtimeDto;
 import com.ruoyi.stock.execl.StockInventoryExportData;
+import com.ruoyi.stock.pojo.StockInventory;
 import com.ruoyi.stock.service.StockInventoryService;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import io.swagger.v3.oas.annotations.Operation;
 import jakarta.servlet.http.HttpServletResponse;
 import lombok.AllArgsConstructor;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -31,28 +38,43 @@
  */
 @RestController
 @RequestMapping("/stockInventory")
-@Api(tags = "搴撳瓨琛�")
+@Tag(name = "搴撳瓨琛�")
 @AllArgsConstructor
 public class StockInventoryController {
 
     private StockInventoryService stockInventoryService;
+    private IDeviceLedgerService deviceLedgerService;
+    private RealTimeEnergyConsumptionServiceImpl realTimeEnergyConsumptionService;
 
     @GetMapping("/pagestockInventory")
-    @ApiOperation("鍒嗛〉鏌ヨ搴撳瓨")
+    @Operation(summary = "鍒嗛〉鏌ヨ搴撳瓨")
     public R pagestockInventory(Page page, StockInventoryDto stockInventoryDto) {
         IPage<StockInventoryDto> stockInventoryDtoIPage = stockInventoryService.pagestockInventory(page, stockInventoryDto);
         return R.ok(stockInventoryDtoIPage);
     }
 
     @GetMapping("/pageListCombinedStockInventory")
-    @ApiOperation("鍒嗛〉鏌ヨ鑱斿悎搴撳瓨鍒楄〃")
+    @Operation(summary = "鍒嗛〉鏌ヨ鑱斿悎搴撳瓨鍒楄〃")
     public R pageListCombinedStockInventory(Page page, StockInventoryDto stockInventoryDto) {
         IPage<StockInventoryDto> stockInventoryDtoIPage = stockInventoryService.pageListCombinedStockInventory(page, stockInventoryDto);
         return R.ok(stockInventoryDtoIPage);
     }
 
+    /**
+     * 鏌ヨ瀵瑰簲鎵瑰彿鍜屾暟閲�
+     * @param page
+     * @param stockInventoryDto
+     * @return
+     */
+    @GetMapping("/getBatchNoQty")
+    @Operation(summary = "鏌ヨ瀵瑰簲鎵瑰彿鍜屾暟閲�")
+    public R getBatchNoQty(Page page, StockInventoryDto stockInventoryDto) {
+        IPage<StockInventoryDto> stockInventoryDtoIPage = stockInventoryService.getBatchNoQty(page, stockInventoryDto);
+        return R.ok(stockInventoryDtoIPage);
+    }
+
     @PostMapping("/addstockInventory")
-    @ApiOperation("鏂板搴撳瓨")
+    @Operation(summary = "鏂板搴撳瓨")
     public R addstockInventory(@RequestBody StockInventoryDto stockInventoryDto) {
         stockInventoryDto.setRecordType(String.valueOf(StockInQualifiedRecordTypeEnum.CUSTOMIZATION_STOCK_IN.getCode()));
         stockInventoryDto.setRecordId(0L);
@@ -61,16 +83,32 @@
 
 
     @PostMapping("/subtractStockInventory")
-    @ApiOperation("鎵e噺搴撳瓨")
+    @Operation(summary = "鎵e噺搴撳瓨")
     public R subtractStockInventory(@RequestBody StockInventoryDto stockInventoryDto) {
         stockInventoryDto.setRecordType(String.valueOf(StockOutQualifiedRecordTypeEnum.CUSTOMIZATION_STOCK_OUT.getCode()));
         stockInventoryDto.setRecordId(0L);
         return R.ok(stockInventoryService.subtractStockInventory(stockInventoryDto));
     }
 
+    @PostMapping("/addStockInRecordOnly")
+    @Operation(summary = "鏂板鍏ュ簱璁板綍锛堜粎鍒涘缓璁板綍锛屼笉璋冩暣搴撳瓨锛�")
+    public R addStockInRecordOnly(@RequestBody StockInventoryDto stockInventoryDto) {
+        stockInventoryDto.setRecordType(String.valueOf(StockInQualifiedRecordTypeEnum.CUSTOMIZATION_STOCK_IN.getCode()));
+        stockInventoryDto.setRecordId(0L);
+        return R.ok(stockInventoryService.addStockInRecordOnly(stockInventoryDto));
+    }
 
-    @PostMapping("importStockInventory")
-    @ApiOperation("瀵煎叆搴撳瓨")
+    @PostMapping("/addStockOutRecordOnly")
+    @Operation(summary = "鏂板鍑哄簱璁板綍锛堜粎鍒涘缓璁板綍锛屼笉璋冩暣搴撳瓨锛�")
+    public R addStockOutRecordOnly(@RequestBody StockInventoryDto stockInventoryDto) {
+        stockInventoryDto.setRecordType(String.valueOf(StockOutQualifiedRecordTypeEnum.CUSTOMIZATION_STOCK_OUT.getCode()));
+        stockInventoryDto.setRecordId(0L);
+        return R.ok(stockInventoryService.addStockOutRecordOnly(stockInventoryDto));
+    }
+
+
+    @PostMapping("/importStockInventory")
+    @Operation(summary = "瀵煎叆搴撳瓨")
     public R importStockInventory(MultipartFile file) {
         return stockInventoryService.importStockInventory(file);
     }
@@ -84,32 +122,84 @@
     }
 
     @PostMapping("/exportStockInventory")
-    @ApiOperation("瀵煎嚭搴撳瓨")
+    @Operation(summary = "瀵煎嚭搴撳瓨")
     public void exportStockInventory(HttpServletResponse response, StockInventoryDto stockInventoryDto) {
         stockInventoryService.exportStockInventory(response, stockInventoryDto);
     }
 
-    @GetMapping("stockInventoryPage")
-    @ApiOperation("搴撳瓨鎶ヨ〃鏌ヨ")
+    @GetMapping("/stockInventoryPage")
+    @Operation(summary = "搴撳瓨鎶ヨ〃鏌ヨ")
     public R stockInventoryPage(Page page, StockInventoryDto stockInventoryDto) {
         return R.ok(stockInventoryService.stockInventoryPage(stockInventoryDto,page));
     }
 
-    @GetMapping("stockInAndOutRecord")
-    @ApiOperation("缁熻鍚勪釜浜у搧鐨勫叆搴撳拰鍑哄簱璁板綍")
+    @GetMapping("/stockInAndOutRecord")
+    @Operation(summary = "缁熻鍚勪釜浜у搧鐨勫叆搴撳拰鍑哄簱璁板綍")
     public R stockInAndOutRecord(StockInventoryDto stockInventoryDto,Page page) {
         return R.ok(stockInventoryService.stockInAndOutRecord(stockInventoryDto,page));
     }
 
     @PostMapping("/frozenStock")
-    @ApiOperation("鍐荤粨搴撳瓨")
+    @Operation(summary = "鍐荤粨搴撳瓨")
     public R frozenStock(@RequestBody StockInventoryDto stockInventoryDto) {
         return R.ok(stockInventoryService.frozenStock(stockInventoryDto));
     }
 
     @PostMapping("/thawStock")
-    @ApiOperation("瑙e喕搴撳瓨")
+    @Operation(summary = "瑙e喕搴撳瓨")
     public R thawStock(@RequestBody StockInventoryDto stockInventoryDto) {
         return R.ok(stockInventoryService.thawStock(stockInventoryDto));
     }
+
+    @GetMapping("/getByModelId")
+    @Operation(summary = "鏍规嵁浜у搧瑙勬牸ID鑾峰彇鍏ュ簱璁板綍")
+    public R getByModelId(Long productModelId) {
+        return R.ok(stockInventoryService.getByModelId(productModelId));
+    }
+
+    @PostMapping("/iotRealtime")
+    @Operation(summary = "鑾峰彇搴撳瓨缁戝畾鐨勭墿鑱旇澶囧疄鏃舵暟閲囨暟鎹�")
+    @Log(title = "搴撳瓨鐗╄仈璁惧瀹炴椂鏁伴噰", businessType = BusinessType.OTHER)
+    public R iotRealtime(@RequestBody List<Long> ids) {
+
+        StockIotRealtimeDto result = new StockIotRealtimeDto();
+
+        if (ids.isEmpty()) {
+            result.setDevices(Collections.emptyList());
+            return R.ok(result);
+        }
+
+        List<DeviceLedger> devices = deviceLedgerService.listByIds(ids);
+        List<String> guidList = devices.stream()
+                .map(DeviceLedger::getExternalCode)
+                .filter(StringUtils::isNotEmpty)
+                .collect(Collectors.toList());
+
+        Map<String, Map<String, String>> realTimeDataMap = new HashMap<>();
+        if (!guidList.isEmpty()) {
+            List<Map<String, String>> realTimeList = realTimeEnergyConsumptionService.getRealData(guidList);
+            for (Map<String, String> item : realTimeList) {
+                String guid = item.get("guid");
+                if (StringUtils.isNotEmpty(guid)) {
+                    realTimeDataMap.put(guid.trim(), item);
+                }
+            }
+        }
+
+        List<Map<String, String>> deviceDataList = devices.stream().map(device -> {
+            Map<String, String> data = new LinkedHashMap<>();
+            data.put("deviceId", String.valueOf(device.getId()));
+            data.put("deviceName", device.getDeviceName() != null ? device.getDeviceName() : "");
+            data.put("deviceModel", device.getDeviceModel() != null ? device.getDeviceModel() : "");
+            data.put("externalCode", device.getExternalCode() != null ? device.getExternalCode() : "");
+            Map<String, String> rt = realTimeDataMap.getOrDefault(
+                    device.getExternalCode() != null ? device.getExternalCode().trim() : "",
+                    Collections.emptyMap());
+            data.putAll(rt);
+            return data;
+        }).collect(Collectors.toList());
+
+        result.setDevices(deviceDataList);
+        return R.ok(result);
+    }
 }

--
Gitblit v1.9.3