Browse Source

大屏接口demo

master
张泽亮 2 days ago
parent
commit
a22a2c0300
9 changed files with 159 additions and 19 deletions
  1. +75
    -0
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/bigscreen/CommonBigController.java
  2. +38
    -0
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/bigscreen/ResourceBigController.java
  3. +10
    -18
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java
  4. +4
    -0
      ruoyi-admin/src/main/resources/application.yml
  5. +11
    -1
      ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheConstants.java
  6. +2
    -0
      ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java
  7. +4
    -0
      ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java
  8. +10
    -0
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
  9. +5
    -0
      ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml

+ 75
- 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/bigscreen/CommonBigController.java View File

@@ -0,0 +1,75 @@
package com.ruoyi.web.controller.bigscreen;

import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.service.ISysDeptService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
* @description: 通用大屏接口
* @author: zzl
* @date: Created in 2025-09-02 15:11
* @version: 1.0
* @modified By:
*/
@RestController
@RequestMapping("/big/common")
public class CommonBigController extends BaseController {

@Autowired
private ISysDeptService sysDeptService;

@Autowired
private TokenService tokenService;

@Autowired
private RedisCache redisCache;

// 大屏接口缓存时间
@Value("${rongxin.big.expireTime}")
private int expireTime;


@ApiOperation("根据部门deptId获取其下级部门列表")
@GetMapping(value = "/nextDeptListByDeptId/{deptId}")
public AjaxResult nextDeptListByDeptId(@PathVariable("deptId") Long deptId) {

Object geoJson = redisCache.getCacheObject(CacheConstants.BIG_DATA_COMMON_KEY + "_nextDeptList_" + deptId);
if (Objects.nonNull(geoJson)) {
return AjaxResult.success(geoJson);
}
List<SysDept> deptList = sysDeptService.selectDeptByParentId(deptId);
redisCache.setCacheObject(CacheConstants.BIG_DATA_COMMON_KEY + "_nextDeptList_" + deptId, deptList, expireTime, TimeUnit.MINUTES);
return AjaxResult.success(deptList);

}

@ApiOperation("根据部门deptId获取其下级部门列表")
@GetMapping(value = "/nextDeptListByOrgCode/{orgCode}")
public AjaxResult nextDeptListByOrgCode(@PathVariable("orgCode") String orgCode) {

Object geoJson = redisCache.getCacheObject(CacheConstants.BIG_DATA_COMMON_KEY + "_nextDeptList_" + orgCode);
if (Objects.nonNull(geoJson)) {
return AjaxResult.success(geoJson);
}
SysDept dept = sysDeptService.selectDeptByOrgCode(orgCode);
List<SysDept> deptList = sysDeptService.selectDeptByParentId(dept.getDeptId());
redisCache.setCacheObject(CacheConstants.BIG_DATA_COMMON_KEY + "_nextDeptList_" + orgCode, deptList, expireTime, TimeUnit.MINUTES);
return AjaxResult.success(deptList);

}
}

+ 38
- 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/bigscreen/ResourceBigController.java View File

@@ -0,0 +1,38 @@
package com.ruoyi.web.controller.bigscreen;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* @description:
* @author: zzl
* @date: Created in 2025-09-02 15:11
* @version: 1.0
* @modified By:
*/
@RestController
@RequestMapping("/big/resource")
public class ResourceBigController extends BaseController {

@Autowired
private ISysDeptService sysDeptService;

@Autowired
private TokenService tokenService;

@Autowired
private RedisCache redisCache;

// 大屏接口缓存时间
@Value("${rongxin.big.expireTime}")
private int expireTime;



}

+ 10
- 18
ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java View File

@@ -1,30 +1,20 @@
package com.ruoyi.web.controller.monitor;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.SysCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
* 缓存监控
*
*
* @author ruoyi
*/
@RestController
@@ -43,6 +33,8 @@ public class CacheController
caches.add(new SysCache(CacheConstants.REPEAT_SUBMIT_KEY, "防重提交"));
caches.add(new SysCache(CacheConstants.RATE_LIMIT_KEY, "限流处理"));
caches.add(new SysCache(CacheConstants.PWD_ERR_CNT_KEY, "密码错误次数"));
caches.add(new SysCache(CacheConstants.BIG_DATA_COMMON_KEY, "通用大屏数据"));
caches.add(new SysCache(CacheConstants.BIG_DATA_RESOURCE_KEY, "资源大屏数据"));
}

@PreAuthorize("@ss.hasPermi('monitor:cache:list')")


+ 4
- 0
ruoyi-admin/src/main/resources/application.yml View File

@@ -99,6 +99,10 @@ token:
# 令牌有效期(默认30分钟)
expireTime: 30

rongxin:
big:
expireTime: 30

# MyBatis配置
mybatis:
# 搜索指定包别名


+ 11
- 1
ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheConstants.java View File

@@ -2,7 +2,7 @@ package com.ruoyi.common.constant;

/**
* 缓存的key 常量
*
*
* @author ruoyi
*/
public class CacheConstants
@@ -41,4 +41,14 @@ public class CacheConstants
* 登录账户密码错误次数 redis key
*/
public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:";

/**
* 【通用】大屏接口数据缓存 redis key
*/
public static final String BIG_DATA_COMMON_KEY = "big_data_common:";

/**
* 【资源】大屏接口数据缓存 redis key
*/
public static final String BIG_DATA_RESOURCE_KEY = "big_data_resource:";
}

+ 2
- 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java View File

@@ -53,6 +53,8 @@ public interface SysDeptMapper
*/
public int selectNormalChildrenDeptById(Long deptId);

public List<SysDept> selectDeptByParentId(Long parentId);

/**
* 是否存在子节点
*


+ 4
- 0
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java View File

@@ -69,6 +69,10 @@ public interface ISysDeptService
*/
public int selectNormalChildrenDeptById(Long deptId);

public List<SysDept> selectDeptByParentId(Long parentId);

public SysDept selectDeptByOrgCode(String orgCode);

/**
* 是否存在部门子节点
*


+ 10
- 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java View File

@@ -143,6 +143,16 @@ public class SysDeptServiceImpl implements ISysDeptService {
return deptMapper.selectNormalChildrenDeptById(deptId);
}

@Override
public List<SysDept> selectDeptByParentId(Long parentId) {
return deptMapper.selectDeptByParentId(parentId);
}

@Override
public SysDept selectDeptByOrgCode(String orgCode) {
return deptMapper.selectDeptByOrgCode(orgCode);
}

/**
* 是否存在子节点
*


+ 5
- 0
ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml View File

@@ -249,6 +249,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
delete from sys_dept
</delete>

<select id="selectDeptByParentId" parameterType="Long" resultMap="SysDeptResult">
<include refid="selectDeptVo"/>
where d.parent_id = #{parentId}
</select>

<select id="selectDeptByOrgCode" parameterType="String" resultMap="SysDeptResult">
<include refid="selectDeptVo"/>
where d.org_code = #{orgCode}


Loading…
Cancel
Save