瀏覽代碼

新增垛位管理分页查询接口以及首页统计剩余接口增加缓存

lingpeng.li 4 月之前
父節點
當前提交
06ea7df253

+ 78 - 7
zgztBus/jeecg-module-lesm/src/main/java/org/jeecg/modules/homePageData/controller/HomePageDataController.java

@@ -11,12 +11,12 @@ import org.jeecg.modules.homePageData.entity.IllegalResult;
 import org.jeecg.modules.homePageData.service.IHomePageDataService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.ValueOperations;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
@@ -125,13 +125,33 @@ public class HomePageDataController {
      * @return
      */
     @AutoLog(value = "峰平谷时间段用电量")
-    @ApiOperation(value="峰平谷时间段用电量", notes="峰平谷时间段用电量")
+    @ApiOperation(value = "峰平谷时间段用电量", notes = "峰平谷时间段用电量")
     @GetMapping(value = "/fpvTimeElectricity")
-    public Result<Map<String, List>> fpvTimeElectricity(@RequestParam(name="modelId",required=false) String modelId) {
-        if (oConvertUtils.isEmpty(modelId) || "0".equals(modelId)){
+    public Result<Map<String, List>> fpvTimeElectricity(@RequestParam(name = "modelId", required = false) String modelId) {
+        // 验证参数
+        if (oConvertUtils.isEmpty(modelId) || "0".equals(modelId)) {
             return Result.error("查询失败,请设置模型!");
         }
+
+        // 构建缓存的 Key
+        String cacheKey = "fpvTimeElectricity:" + modelId;
+        ValueOperations<String, Object> valueOps = redisTemplate.opsForValue();
+
+        // 尝试从 Redis 获取缓存数据
+        @SuppressWarnings("unchecked")
+        Map<String, List> cachedData = (Map<String, List>) valueOps.get(cacheKey);
+
+        if (cachedData != null) {
+            // 如果缓存存在,直接返回
+            return Result.OK(cachedData);
+        }
+
+        // 缓存不存在,调用服务查询
         Map<String, List> res = homePageDataService.fpvTimeElectricity(modelId);
+
+        // 将查询结果存入 Redis 并设置过期时间为 10 分钟
+        valueOps.set(cacheKey, res, 10, TimeUnit.MINUTES);
+
         return Result.OK(res);
     }
 
@@ -156,10 +176,27 @@ public class HomePageDataController {
      * @return
      */
     @AutoLog(value = "实时设备运行")
-    @ApiOperation(value="实时设备运行", notes="实时设备运行")
+    @ApiOperation(value = "实时设备运行", notes = "实时设备运行")
     @GetMapping(value = "/realDeviceRun")
     public Result<List<Map<String, String>>> realDeviceRun() {
+        String cacheKey = "realDeviceRun:data"; // 缓存的 key
+        ValueOperations<String, Object> valueOps = redisTemplate.opsForValue();
+
+        // 从 Redis 中尝试获取缓存数据
+        @SuppressWarnings("unchecked")
+        List<Map<String, String>> cachedData = (List<Map<String, String>>) valueOps.get(cacheKey);
+
+        if (cachedData != null) {
+            // 如果缓存中有数据,直接返回
+            return Result.OK(cachedData);
+        }
+
+        // 如果缓存中没有数据,查询数据库
         List<Map<String, String>> res = homePageDataService.realDeviceRun();
+
+        // 将结果缓存到 Redis,设置过期时间为 10 分钟
+        valueOps.set(cacheKey, res, 10, TimeUnit.MINUTES);
+
         return Result.OK(res);
     }
 
@@ -198,10 +235,27 @@ public class HomePageDataController {
      * @return
      */
     @AutoLog(value = "尖峰时段违规启动设备统计")
-    @ApiOperation(value="尖峰时段违规启动设备统计", notes="尖峰时段违规启动设备统计")
+    @ApiOperation(value = "尖峰时段违规启动设备统计", notes = "尖峰时段违规启动设备统计")
     @GetMapping(value = "/illegalActivation")
     public Result<Map<String, Integer>> illegalActivation() {
+        String cacheKey = "illegalActivation:statistics"; // 缓存的 key
+        ValueOperations<String, Object> valueOps = redisTemplate.opsForValue();
+
+        // 从 Redis 中尝试获取缓存数据
+        @SuppressWarnings("unchecked")
+        Map<String, Integer> cachedData = (Map<String, Integer>) valueOps.get(cacheKey);
+
+        if (cachedData != null) {
+            // 如果缓存中有数据,直接返回
+            return Result.OK(cachedData);
+        }
+
+        // 如果缓存中没有数据,查询服务
         Map<String, Integer> res = homePageDataService.illegalActivation();
+
+        // 将结果缓存到 Redis,设置过期时间为 10 分钟
+        valueOps.set(cacheKey, res, 10, TimeUnit.MINUTES);
+
         return Result.OK(res);
     }
 
@@ -229,10 +283,27 @@ public class HomePageDataController {
      * @return
      */
     @AutoLog(value = "最新消息")
-    @ApiOperation(value="最新消息", notes="最新消息")
+    @ApiOperation(value = "最新消息", notes = "最新消息")
     @GetMapping(value = "/lastestMsg")
     public Result<List<String>> lastestMsg() {
+        String cacheKey = "latestMsg:data"; // 缓存的 key
+        ValueOperations<String, Object> valueOps = redisTemplate.opsForValue();
+
+        // 尝试从 Redis 获取缓存数据
+        @SuppressWarnings("unchecked")
+        List<String> cachedData = (List<String>) valueOps.get(cacheKey);
+
+        if (cachedData != null) {
+            // 如果缓存存在,直接返回
+            return Result.OK(cachedData);
+        }
+
+        // 缓存不存在,调用服务查询
         List<String> res = homePageDataService.latestMsg();
+
+        // 将结果存入 Redis 并设置过期时间为 10 分钟
+        valueOps.set(cacheKey, res, 10, TimeUnit.MINUTES);
+
         return Result.OK(res);
     }
 

+ 91 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/stackingAndLoadingVehicles/controller/StackingLogController.java

@@ -0,0 +1,91 @@
+package org.jeecg.modules.billet.stackingAndLoadingVehicles.controller;
+
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.aspect.annotation.AutoLog;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.modules.billet.stackingAndLoadingVehicles.dto.StackingLogDTO;
+import org.jeecg.modules.billet.stackingAndLoadingVehicles.entity.StackingDownLog;
+import org.jeecg.modules.billet.stackingAndLoadingVehicles.entity.StackingUpLog;
+import org.jeecg.modules.billet.stackingAndLoadingVehicles.service.IStackingDownLogService;
+import org.jeecg.modules.billet.stackingAndLoadingVehicles.service.IStackingUpLogService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * @Description: 垛位日志表
+ * @Author: llp
+ * @Date: 2025-01-22
+ * @Version: V1.0
+ */
+@Api(tags = "垛位日志表")
+@RestController
+@RequestMapping("/stackingLog/stackingLog")
+@Slf4j
+public class StackingLogController {
+
+    @Autowired
+    private IStackingUpLogService stackingUpLogService;
+
+    @Autowired
+    private IStackingDownLogService stackingDownLogService;
+
+
+    /**
+     * 分页列表查询
+     *
+     * @param dto
+     * @param pageNo
+     * @param pageSize
+     * @param req
+     * @return
+     */
+    @AutoLog(value = "垛位日志表-分页列表查询")
+    @ApiOperation(value = "垛位日志表-分页列表查询", notes = "垛位日志表-分页列表查询")
+    @GetMapping(value = "/list")
+    public Result<IPage<?>> queryPageList(StackingLogDTO dto, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
+
+        // 根据类型调用不同的服务方法
+        if (1 == dto.getType()) {
+            // 查询上料日志
+            StackingUpLog stackingUpLog = new StackingUpLog();
+            stackingUpLog.setLayer(dto.getLayer());
+            stackingUpLog.setAddress(dto.getAddress());
+            stackingUpLog.setStackAddr(dto.getStackAddr());
+
+            QueryWrapper<StackingUpLog> queryWrapper = QueryGenerator.initQueryWrapper(stackingUpLog, req.getParameterMap());
+            Page<StackingUpLog> page = new Page<StackingUpLog>(pageNo, pageSize);
+            IPage<StackingUpLog> pageList = stackingUpLogService.page(page, queryWrapper);
+            return Result.ok(pageList);
+
+        } else if (2 == dto.getType()) {
+            // 查询下料日志
+            StackingDownLog stackingDownLog = new StackingDownLog();
+            stackingDownLog.setStackStorey(dto.getLayer());
+            stackingDownLog.setStackNum(dto.getAddress());
+            stackingDownLog.setStackAddr(dto.getStackAddr());
+            QueryWrapper<StackingDownLog> queryWrapper = QueryGenerator.initQueryWrapper(stackingDownLog, req.getParameterMap());
+
+            Page<StackingDownLog> page = new Page<StackingDownLog>(pageNo, pageSize);
+            IPage<StackingDownLog> pageList = stackingDownLogService.page(page, queryWrapper);
+            return Result.ok(pageList);
+
+
+        } else {
+            return Result.error("无效的类型参数!");
+        }
+
+    }
+
+}

+ 32 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/stackingAndLoadingVehicles/dto/StackingLogDTO.java

@@ -0,0 +1,32 @@
+package org.jeecg.modules.billet.stackingAndLoadingVehicles.dto;
+
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+public class StackingLogDTO {
+
+    /**
+     * 所在层数(1-20)
+     */
+    @ApiModelProperty(value = "所在层数(1-20)")
+    private String layer;
+
+    /**
+     * 所在位置(1-9)
+     */
+    @ApiModelProperty(value = "所在位置(1-9)")
+    private String address;
+
+    /**
+     * 垛位
+     */
+    @ApiModelProperty(value = "垛位")
+    private String stackAddr;
+
+    /**
+     * 类型  1上垛   2下垛
+     */
+    private Integer type;
+}