|
@@ -9,6 +9,8 @@ import com.sooka.system.gas.zenner_gas_purchase_center_infor.service.ITGuijiZenn
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -58,29 +60,50 @@ public class TGuijiZennerGasPurchaseCenterInforServiceImpl implements ITGuijiZen
|
|
|
{
|
|
|
// Long total = Convert.toLong(CacheUtils.get("guiji-data-count", tableName + "," + paramStr));//cacheName, cacheKey
|
|
|
String cacheName = tableName + "," + paramStr;
|
|
|
- Long total = mapper.getCache(cacheName);
|
|
|
- if(total == null){
|
|
|
+// Long total = mapper.getCache(cacheName);
|
|
|
+ Map cache = mapper.getCache(cacheName);
|
|
|
+ Long total;
|
|
|
+ if(cache == null){
|
|
|
String msg = "21:17:55.281 [http-nio-8080-exec-27] INFO o.a.s.c.e.EhCacheManager - [getCache,158] - Cache with name 'guiji-data-count' does not yet exist. Creating now.";
|
|
|
Map map = new HashMap();
|
|
|
map.put("tableName", tableName);
|
|
|
total = mapper.getDataCount(map);
|
|
|
+ map.put("updateTime", new Date());
|
|
|
map.put("cacheName", cacheName);
|
|
|
map.put("total", total);
|
|
|
mapper.createCache(map);
|
|
|
System.out.println("分页功能 缓存创建成功:" + tableName);
|
|
|
}else {
|
|
|
+ total = Long.valueOf(cache.get("total").toString());
|
|
|
+// Map map = new HashMap();
|
|
|
+// map.put("tableName", tableName);
|
|
|
+// total = mapper.getDataCount(map);
|
|
|
// total = Long.valueOf(cache.get("total").toString());
|
|
|
+// final Long count = total;
|
|
|
System.out.println("分页功能 根据缓存名称获取缓存:" + tableName);
|
|
|
new Thread() {
|
|
|
public void run() {
|
|
|
try{
|
|
|
- Map map = new HashMap();
|
|
|
- map.put("tableName", tableName);
|
|
|
- Long total = mapper.getDataCount(map);
|
|
|
- map.put("cacheName", cacheName);
|
|
|
- map.put("total", total);
|
|
|
- mapper.refreshCache(map);
|
|
|
- System.out.println("分页功能 缓存刷新成功:" + tableName);
|
|
|
+ String updateTime = cache.get("updateTime").toString();
|
|
|
+ System.out.println(updateTime.split("\\.")[0] + "=updateTime");//2022-12-01 15:26:16.0
|
|
|
+ boolean refresh = new Date().getTime() - new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(updateTime.split("\\.")[0]).getTime() > 10 * 60 * 1000;//最多10分钟刷新一次最新数据
|
|
|
+ if(refresh){
|
|
|
+ System.out.println("分页功能 缓存刷新中。。。:" + tableName);
|
|
|
+ // String updateTime = cache.get("updateTime").toString();
|
|
|
+ // System.out.println(updateTime + "=updateTime");
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("updateTime", new Date());
|
|
|
+ map.put("cacheName", cacheName);
|
|
|
+ mapper.updateCache(map);//更新更新时间 防止多次操作
|
|
|
+ // System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + interfaceinfo.getInterfaceName() + "更新更新时间 防止多次操作");
|
|
|
+ map.put("tableName", tableName);
|
|
|
+ Long total = mapper.getDataCount(map);//select count(id) from ${tableName} 此处最为耗时
|
|
|
+ map.put("total", total);
|
|
|
+ mapper.refreshCache(map);
|
|
|
+ System.out.println("分页功能 缓存刷新成功:" + tableName);
|
|
|
+ }else {
|
|
|
+ System.out.println("分页功能 缓存已是最新:" + tableName);
|
|
|
+ }
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|