Ver código fonte

分页查询 - 6

wangzhe 2 anos atrás
pai
commit
5e861322c6

+ 24 - 0
mybusiness/src/main/java/com/sooka/system/gas/zenner_gas_purchase_center_infor/mapper/TGuijiZennerGasPurchaseCenterMapper.java

@@ -54,6 +54,30 @@ public interface TGuijiZennerGasPurchaseCenterMapper
     public Long getDataCount(Map tableName);
 
     /**
+     * 创建数据缓存(通用)
+     *
+     * @param cache 缓存名称,缓存值
+     * @return 数据数量
+     */
+    public void createCache(Map cache);
+
+    /**
+     * 刷新数据缓存(通用)
+     *
+     * @param cache 缓存ID,缓存值
+     * @return 数据数量
+     */
+    public void refreshCache(Map cache);
+
+    /**
+     * 查询数据缓存(通用)
+     *
+     * @param cacheName 缓存名称
+     * @return 数据数量
+     */
+    public Long getCache(String cacheName);
+
+    /**
      * 新增真兰收费系统-中心计费购气信息
      *
      * @param param 真兰收费系统-中心计费购气信息

+ 41 - 0
mybusiness/src/main/java/com/sooka/system/gas/zenner_gas_purchase_center_infor/service/impl/TGuijiZennerGasPurchaseCenterInforServiceImpl.java

@@ -56,6 +56,47 @@ public class TGuijiZennerGasPurchaseCenterInforServiceImpl implements ITGuijiZen
      */
     public Long getTotal(String tableName, String paramStr)
     {
+//        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){
+            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("cacheName", cacheName);
+            map.put("total", total);
+            mapper.createCache(map);
+            System.out.println("分页功能 缓存创建成功:" + tableName);
+        }else {
+//            total = Long.valueOf(cache.get("total").toString());
+            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);
+                    }catch (Exception e){
+                        e.printStackTrace();
+                    }
+                }
+            }.start();
+        }
+        return total;
+    }
+
+    /**
+     * 获取cache name
+     *
+     * @return 缓存名
+     */
+    public Long getTotal_abandon(String tableName, String paramStr)
+    {
         Long total = Convert.toLong(CacheUtils.get("guiji-data-count", tableName + "," + paramStr));//cacheName, cacheKey
         if(total == null){
             Map map = new HashMap();

+ 10 - 0
mybusiness/src/main/resources/mapper/system/TGuijiZennerGasPurchaseCenterInforMapper.xml

@@ -57,6 +57,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         select count(id) from ${tableName}
     </select>
 
+    <insert id="createCache" parameterType="java.util.Map">
+        insert into t_cache_guiji (cache_name, total) values (#{cacheName}, #{total})
+    </insert>
+    <update id="refreshCache" parameterType="java.util.Map">
+        update t_cache_guiji set total = #{total} where cache_name = #{cacheName}
+    </update>
+    <select id="getCache" parameterType="java.lang.String" resultType="java.lang.Long">
+        select total from t_cache_guiji where cache_name = #{cacheName}
+    </select>
+
     <insert id="insert" parameterType="TGuijiZennerGasPurchaseCenterInfor">
         insert into t_guiji_gas_zenner_gas_purchase_center_infor
         <trim prefix="(" suffix=")" suffixOverrides=",">