Browse Source

代码优化

dzk 1 year ago
parent
commit
1e3a61683a

+ 18 - 17
ruoyi-demo/src/main/java/com/ruoyi/demo/utils/WdRedisStoreage.java

@@ -8,6 +8,7 @@ import com.ruoyi.common.utils.redis.RedisUtils;
 import com.ruoyi.demo.constant.RedisContant;
 import com.ruoyi.demo.entity.WdInfo;
 import com.ruoyi.demo.mapper.WdInfoDao;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.ibatis.cursor.Cursor;
 import org.apache.ibatis.session.SqlSession;
 import org.apache.ibatis.session.SqlSessionFactory;
@@ -27,6 +28,7 @@ import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
 import java.util.stream.Collectors;
 
+@Slf4j
 @Component
 public class WdRedisStoreage {
 
@@ -102,7 +104,7 @@ public class WdRedisStoreage {
     public void writeWdGeoRedis1() throws Exception {
         //1.将网点坐标存入redis中
         long start = System.currentTimeMillis();
-        Console.log("开始将网点坐标存入redis");
+        log.info("开始将网点坐标存入redis");
         //从Redis中获取时间
         String time = RedisUtils.getCacheObject(RedisContant.WD_TAG_LASTTIME);
 
@@ -116,7 +118,7 @@ public class WdRedisStoreage {
         queryWrapper.select("wd_id", "addr_code", "lng", "lat").orderByAsc("collect_time");
 
         //使用sqlSessionFactory打开一个sqlSession,在没有读取完数据之前不要提交事务或关闭sqlSession
-        Console.log("----开启sqlSession");
+        log.info("----开启sqlSession");
         SqlSession sqlSession = sqlSessionFactory.openSession();
         Cursor<WdInfo> cursor = null;
         try {
@@ -133,40 +135,39 @@ public class WdRedisStoreage {
                     RedisUtils.setCacheObject(RedisContant.WD_TAG_LASTTIME, DateUtil.formatDateTime(wdInfo.getCollectTime()));
 
                     //打印进度条
-                    //Console.print("{}当前进度:{} {}/{}", '\r', StrUtil.repeat('#', (int) (50 * (cursor.getCurrentIndex() + 1) / total)), cursor.getCurrentIndex() + 1, total);
                     Console.print("{}当前进度:{}/{}", '\r', cursor.getCurrentIndex() + 1, total);
                 }
                 if (cursor.isConsumed()) {
-                    Console.log("----查询sql匹配中的数据已经消费完毕!");
+                    log.info("----查询sql匹配中的数据已经消费完毕!");
                 }
             }
             sqlSession.commit();
-            Console.log("----提交事务");
+            log.info("----提交事务");
         } catch (Exception e) {
-            Console.log(e, "数据消费异常");
+            log.error("数据消费异常", e);
             sqlSession.rollback();
         } finally {
             if (cursor != null && cursor.isOpen()) {
                 //关闭cursor
                 cursor.close();
-                Console.log("----关闭cursor");
+                log.info("----关闭cursor");
             }
             if (sqlSession != null) {
                 //全部数据读取并且做好其他业务操作之后,提交事务并关闭连接;
                 sqlSession.close();
-                Console.log("----关闭sqlSession");
+                log.info("----关闭sqlSession");
             }
 
         }
 
         long end = System.currentTimeMillis();
-        Console.log("完成存入 耗时:" + (end - start) / (1000 * 60) + "分钟");
+        log.info("完成存入 耗时:" + (end - start) / (1000 * 60) + "分钟");
     }
 
     public void writeWdGeoRedis2(String[] wdTypeCodes) throws IOException {
         //对所有网点坐标进行分析打标签
         long start = System.currentTimeMillis();
-        Console.log("开始打标签");
+        log.info("开始打标签");
 
         //开始
         QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
@@ -177,7 +178,7 @@ public class WdRedisStoreage {
 
 
         //使用sqlSessionFactory打开一个sqlSession,在没有读取完数据之前不要提交事务或关闭sqlSession
-        Console.log("----开启sqlSession");
+        log.info("----开启sqlSession");
         SqlSession sqlSession = sqlSessionFactory.openSession();
         Cursor<WdInfo> cursor = null;
         try {
@@ -193,30 +194,30 @@ public class WdRedisStoreage {
                     Console.print("{}当前进度:{}/{}", '\r', cursor.getCurrentIndex() + 1, total);
                 }
                 if (cursor.isConsumed()) {
-                    Console.log("----查询sql匹配中的数据已经消费完毕!");
+                    log.info("----查询sql匹配中的数据已经消费完毕!");
                 }
             }
             sqlSession.commit();
-            Console.log("----提交事务");
+            log.info("----提交事务");
         } catch (Exception e) {
-            Console.log(e, "数据消费异常");
+            log.info("数据消费异常", e);
             sqlSession.rollback();
         } finally {
             if (cursor != null && cursor.isOpen()) {
                 //关闭cursor
                 cursor.close();
-                Console.log("----关闭cursor");
+                log.info("----关闭cursor");
             }
             if (sqlSession != null) {
                 //全部数据读取并且做好其他业务操作之后,提交事务并关闭连接;
                 sqlSession.close();
-                Console.log("----关闭sqlSession");
+                log.info("----关闭sqlSession");
             }
 
         }
 
         long end = System.currentTimeMillis();
-        Console.log("完成打标签 耗时:" + (end - start) / (1000 * 60) + "分钟");
+        log.info("完成打标签 耗时:" + (end - start) / (1000 * 60) + "分钟");
 
     }
 

+ 3 - 2
ruoyi-job/src/main/java/com/ruoyi/job/service/BenyunService.java

@@ -34,13 +34,14 @@ public class BenyunService {
      * */
     @XxlJob("WriteRedisJob")
     public void WriteRedisJob() throws IOException {
-        XxlJobHelper.log("WriteRedisJob start");
+        XxlJobHelper.log("将网点数据加载到redis中 start");
         try {
             wdRedisStoreage.writeWdGeoRedis1();
         } catch (Exception e) {
-            XxlJobHelper.log("WriteRedisJob ERROR:");
+            XxlJobHelper.log("将网点数据加载到redis中 ERROR:");
             XxlJobHelper.log(e);
         }
+        XxlJobHelper.log("将网点数据加载到redis中 end");
     }
 
     /**