1.查询所有摄像头 selectAll 增加缓存
This commit is contained in:
parent
cbfb409a11
commit
8122e35574
13
pom.xml
13
pom.xml
|
@ -68,6 +68,19 @@
|
|||
<artifactId>javacv-platform</artifactId>
|
||||
<version>1.5.7</version>
|
||||
</dependency>
|
||||
<!--缓存-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-cache</artifactId>
|
||||
<version>2.4.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sf.ehcache</groupId>
|
||||
<artifactId>ehcache</artifactId>
|
||||
<version>2.10.6</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!--<dependency>
|
||||
<groupId>org.bytedeco</groupId>
|
||||
|
|
|
@ -3,11 +3,13 @@ package com.hisense.monitormanage;
|
|||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@SpringBootApplication
|
||||
@MapperScan("com.hisense.monitormanage.mapper")
|
||||
|
||||
@EnableCaching
|
||||
@EnableScheduling
|
||||
public class MonitorManageApplication {
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package com.hisense.monitormanage.config;
|
||||
|
||||
import net.sf.ehcache.CacheManager;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.ehcache.EhCacheCacheManager;
|
||||
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* @version 1.0.0
|
||||
* @ClassName CachingConfig.java
|
||||
* @Description cache配置
|
||||
* @createTime 2022年05月12日 09:45:00
|
||||
*/
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
public class CachingConfig {
|
||||
@Bean
|
||||
public EhCacheCacheManager cacheManager(CacheManager cm) {
|
||||
return new EhCacheCacheManager(cm);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public EhCacheManagerFactoryBean ehcache() {
|
||||
EhCacheManagerFactoryBean cacheManagerFactoryBean = new EhCacheManagerFactoryBean();
|
||||
cacheManagerFactoryBean.setConfigLocation(new ClassPathResource("ehcache.xml"));
|
||||
return cacheManagerFactoryBean;
|
||||
}
|
||||
}
|
|
@ -53,6 +53,9 @@ public class Controller {
|
|||
@Autowired
|
||||
private RoadDataService roadDataService;
|
||||
|
||||
@Autowired
|
||||
private CameraChannelService cameraChannelService;
|
||||
|
||||
@RequestMapping("all")
|
||||
public Object all(){
|
||||
List<Project> projects = projectMapper.selectList(null);
|
||||
|
@ -105,19 +108,19 @@ public class Controller {
|
|||
|
||||
/**
|
||||
* 查询所有摄像头
|
||||
* @param cameraChannel
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("selectAll")
|
||||
public Result selectAll(CameraChannel cameraChannel,Integer page,Integer pageSize){
|
||||
public Result selectAll(){
|
||||
|
||||
List<CameraChannelDto> list = cameraChannelMapper.selectAll(cameraChannel,page,pageSize);
|
||||
|
||||
Result success = Result.success(list);
|
||||
//System.out.println("selectAll start->"+System.currentTimeMillis());
|
||||
String listStr = cameraChannelService.selectAll();
|
||||
//System.out.println("selectAll end->"+System.currentTimeMillis());
|
||||
Result success = Result.success(listStr);
|
||||
|
||||
return success;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -378,7 +381,7 @@ public class Controller {
|
|||
@RequestParam(value="start") String start,
|
||||
@RequestParam(value = "end") String end
|
||||
){
|
||||
System.out.println("listTrailSanitationByPoints......");
|
||||
// System.out.println("listTrailSanitationByPoints......");
|
||||
List<TrailSanitation> list = trailSanitationService.listSedimentTrailByPoints(longitude,latitude,raidus,start,end);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||
|
||||
public interface CameraChannelMapper extends BaseMapper<CameraChannel> {
|
||||
|
||||
List<CameraChannelDto> selectAll(CameraChannel cameraChannel,@Param("page") Integer page,@Param("pageSize") Integer pageSize);
|
||||
List<CameraChannelDto> selectAll();
|
||||
|
||||
@Select("select cc.*,cp.pic_url from t_camera_channel cc LEFT JOIN t_channel_picture cp ON cc.channel_code=cp.channel_code where cc.channel_id = #{channelId}")
|
||||
List<CameraChannelDto1> selectByChannelId(@Param("channelId") String channelId);
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package com.hisense.monitormanage.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hisense.monitormanage.dto.CameraChannelDto;
|
||||
import com.hisense.monitormanage.entity.CameraChannel;
|
||||
import com.hisense.monitormanage.entity.Result;
|
||||
import com.hisense.monitormanage.mapper.CameraChannelMapper;
|
||||
import com.hisense.monitormanage.utils.EhcacheUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.ehcache.EhCacheCacheManager;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* @version 1.0.0
|
||||
* @ClassName CameraChannelService.java
|
||||
* @Description TODO
|
||||
* @createTime 2022年05月12日 09:19:00
|
||||
*/
|
||||
@Service
|
||||
public class CameraChannelService {
|
||||
@Autowired
|
||||
private CameraChannelMapper cameraChannelMapper;
|
||||
|
||||
@Autowired
|
||||
private EhCacheCacheManager ehCacheCacheManager;
|
||||
|
||||
//查询所有摄像头
|
||||
//@Cacheable(value = "fillIn")
|
||||
public String selectAll(){
|
||||
String list = (String)EhcacheUtil.getInstance().get("fillIn", "allCameraList");
|
||||
if(StringUtils.isEmpty(list)){
|
||||
List<CameraChannelDto> cameraChannelDtos = cameraChannelMapper.selectAll();
|
||||
list = JSONObject.toJSONString(cameraChannelDtos);
|
||||
EhcacheUtil.getInstance().put("fillIn", "allCameraList",list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.hisense.monitormanage.utils;
|
||||
|
||||
import net.sf.ehcache.CacheManager;
|
||||
import java.net.URL;
|
||||
import net.sf.ehcache.Cache;
|
||||
import net.sf.ehcache.Element;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* @version 1.0.0
|
||||
* @ClassName EhcacheUtil.java
|
||||
* @Description TODO
|
||||
* @createTime 2022年05月12日 10:20:00
|
||||
*/
|
||||
public class EhcacheUtil {
|
||||
private static final String path = "/ehcache.xml";
|
||||
private URL url;
|
||||
private CacheManager manager;
|
||||
private static EhcacheUtil ehCache;
|
||||
private EhcacheUtil(String path) {
|
||||
url = getClass().getResource(path);
|
||||
manager = CacheManager.create(url);
|
||||
}
|
||||
|
||||
public static EhcacheUtil getInstance() {
|
||||
if (ehCache== null) {
|
||||
ehCache= new EhcacheUtil(path);
|
||||
}
|
||||
return ehCache;
|
||||
}
|
||||
|
||||
public void put(String cacheName, String key, Object value) {
|
||||
Cache cache = manager.getCache(cacheName);
|
||||
Element element = new Element(key, value);
|
||||
cache.put(element);
|
||||
}
|
||||
|
||||
public Object get(String cacheName, String key) {
|
||||
Cache cache = manager.getCache(cacheName);
|
||||
Element element = cache.get(key);
|
||||
return element == null ? null : element.getObjectValue();
|
||||
}
|
||||
|
||||
public Cache get(String cacheName) {
|
||||
return manager.getCache(cacheName);
|
||||
}
|
||||
|
||||
public void remove(String cacheName, String key) {
|
||||
Cache cache = manager.getCache(cacheName);
|
||||
cache.remove(key);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ehcache updateCheck="false" name="defaultCache">
|
||||
<!-- 磁盘缓存位置 -->
|
||||
<diskStore path="java.io.tmpdir/ehcache"/>
|
||||
<!--
|
||||
maxEntriesLocalHeap:堆内存中最大缓存对象数
|
||||
eternal:对象是否永久有效,一但设置了,timeout将不起作用
|
||||
overflowToDisk:当缓存达到maxElementsInMemory值是,是否允许溢出到磁盘
|
||||
timeToIdleSeconds:当缓存闲置n秒后销毁
|
||||
timeToLiveSeconds:当缓存存活n秒后销毁
|
||||
maxEntriesLocalDisk:硬盘最大缓存个数
|
||||
diskPersistent:磁盘缓存在JVM重新启动时是否保持
|
||||
-->
|
||||
<!-- 默认缓存 -->
|
||||
<defaultCache
|
||||
maxEntriesLocalHeap="10000"
|
||||
eternal="false"
|
||||
timeToIdleSeconds="600"
|
||||
timeToLiveSeconds="600"
|
||||
maxEntriesLocalDisk="10000000"
|
||||
diskExpiryThreadIntervalSeconds="120"
|
||||
memoryStoreEvictionPolicy="LRU"/>
|
||||
|
||||
<!-- fill-in缓存 -->
|
||||
<cache name="fillIn"
|
||||
maxElementsInMemory="10000"
|
||||
eternal="false"
|
||||
timeToIdleSeconds="600"
|
||||
timeToLiveSeconds="600"
|
||||
overflowToDisk="false"
|
||||
memoryStoreEvictionPolicy="LRU"/>
|
||||
|
||||
</ehcache>
|
|
@ -12,9 +12,9 @@
|
|||
<select id="selectAll" resultType="com.hisense.monitormanage.dto.CameraChannelDto">
|
||||
select c.* from t_camera_channel c
|
||||
where (c.gps_x NOT IN('0.0','0','','-1000.0') OR c.gps_y NOT IN('0.0','0','','-1000.0'))
|
||||
AND c.status != 0 order by channel_id desc
|
||||
<bind name="page" value="(page-1)*pageSize"/>
|
||||
limit #{page},#{pageSize}
|
||||
AND c.status != 0
|
||||
<!-- <bind name="page" value="(page-1)*pageSize"/>-->
|
||||
<!-- limit #{page},#{pageSize}-->
|
||||
</select>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue