Browse Source

日常保存

lifuquan 1 year ago
parent
commit
c23aaff856

+ 6 - 0
pom.xml

@@ -36,6 +36,12 @@
     </properties>
 
     <dependencies>
+        <!-- push-message-starter -->
+        <dependency>
+            <groupId>com.nokia</groupId>
+            <artifactId>push-message-starter</artifactId>
+            <version>1.1.0</version>
+        </dependency>
         <!-- common-utils -->
         <dependency>
             <groupId>com.nokia</groupId>

+ 9 - 0
src/main/java/com/nokia/tsl_data/dao/UserCountRepository.java

@@ -0,0 +1,9 @@
+package com.nokia.tsl_data.dao;
+
+import com.nokia.tsl_data.entity.UserCount;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface UserCountRepository extends JpaRepository<UserCount, Long> {
+}

+ 40 - 0
src/main/java/com/nokia/tsl_data/entity/UserCount.java

@@ -0,0 +1,40 @@
+package com.nokia.tsl_data.entity;
+
+import lombok.Data;
+import org.springframework.data.annotation.CreatedDate;
+import org.springframework.data.annotation.LastModifiedDate;
+import org.springframework.data.jpa.domain.support.AuditingEntityListener;
+
+import javax.persistence.*;
+import java.time.Instant;
+
+@Data
+@Entity
+@EntityListeners(AuditingEntityListener.class)
+@Table(name = "user_count", schema = "tsl_data")
+public class UserCount {
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    private Long id;
+
+    @Column(name = "month_id", columnDefinition = "varchar(8)", nullable = false)
+    private String monthId;
+
+    @Column(name = "city_name", columnDefinition = "varchar(50)", nullable = false)
+    private String cityName;
+
+    // 管理端用户数统计
+    @Column
+    private Double managementUserCount;
+
+    // 客户端用户数统计
+    @Column
+    private Double customerUserCount;
+
+    @CreatedDate
+    private Instant createDate;
+
+    @LastModifiedDate
+    private Instant lastUpdateDate;
+}

+ 23 - 0
src/main/java/com/nokia/tsl_data/properties/DataWarehouseProperties.java

@@ -7,10 +7,33 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
 @ConfigurationProperties(prefix = "tsl.source")
 public class DataWarehouseProperties {
 
+    /**
+     * 河北_CEM高品质2日详表
+     */
     // HighQualityListDay 文件存储路径
     private String dirOfHighQualityListDay = "/data/nenglishangdian/high_quality_list_day";
     // HighQualityListDay 文件前缀
     private String prefixOfHighQualityListDay = "HE_D_HIGH_QUALITY_LIST_DAY_1114200095151828992_";
     // HighQualityListDay 字段数量
     private Integer filedNumOfHighQualityListDay = 70;
+
+    /**
+     * 河北_CEM高品质2日统计
+     */
+    // HighQualityCountDay 文件存储路径
+    private String dirOfHighQualityCountDay = "/data/nenglishangdian/high_quality_count/";
+    // HighQualityCountDay 文件前缀
+    private String prefixOfHighQualityCountDay = "HE_D_HIGH_QUALITY_COUNT_DAY_1087387382887477248_";
+    // HighQualityCountDay 字段数量
+    private Integer filedNumOfHighQualityCountDay = 33;
+
+    /**
+     * 河北_CEM移网质量投诉明细
+     */
+    // HighQualityCountDay 文件存储路径
+    private String dirOfMobileComplaint = "/data/nenglishangdian/mobile_complaint/";
+    // HighQualityCountDay 文件前缀
+    private String prefixOfMobileComplaint = "HE_D_MOBILE_COMPLAINT_DETAILS_DAY_1087468015013851136_";
+    // HighQualityCountDay 字段数量
+    private Integer filedNumOfMobileComplaint = 47;
 }

+ 88 - 2
src/main/java/com/nokia/tsl_data/service/DataWarehouseService.java

@@ -31,11 +31,24 @@ public class DataWarehouseService {
         this.dataWarehouseProperties = dataWarehouseProperties;
     }
 
+    // TODO
+    public void checkSource(String day) {
+
+    }
+
+    // TODO
+    private boolean checkHighQualityListDay(String day) {
+        String fileName = dataWarehouseProperties.getPrefixOfHighQualityListDay() + day + ".csv";
+        Path path = Paths.get(dataWarehouseProperties.getDirOfHighQualityListDay(), fileName);
+        return path.toFile().exists();
+    }
+
+
     public void warehouseHighQualityListDay(String day) {
         String fileName = dataWarehouseProperties.getPrefixOfHighQualityListDay() + day + ".csv";
         Path path = Paths.get(dataWarehouseProperties.getDirOfHighQualityListDay(), fileName);
         warehouseHighQualityListDay(path.toFile());
-        log.info("河北高质量2日明细数据入库成功: {}...", day);
+        log.info("河北_CEM高质量2日明细数据入库成功: {}...", day);
     }
 
     /**
@@ -53,6 +66,7 @@ public class DataWarehouseService {
                     .build().parse(reader);
             List<CSVRecord> records = parser.getRecords();
             List<Object[]> list = new ArrayList<>();
+            // 查找全部需要筛选的类型
             Set<String> allServTypeNames = sysDataDictionaryRepository.findAllServTypeNames();
             for (CSVRecord record : records) {
                 // 按照serv_type_name进行筛选
@@ -67,7 +81,79 @@ public class DataWarehouseService {
             tslDataDao.batchInsertHighQualityListDay(list);
         } catch (IOException e) {
             e.printStackTrace();
-            throw new RuntimeException("河北高质量2日明细数据入库失败..." + e.getMessage());
+            throw new RuntimeException("河北_CEM高质量2日明细数据入库失败..." + e.getMessage());
+        }
+    }
+
+    public void warehouseMobileComplaintDay(String day) {
+        String fileName = dataWarehouseProperties.getPrefixOfMobileComplaint() + day + ".csv";
+        Path path = Paths.get(dataWarehouseProperties.getDirOfMobileComplaint(), fileName);
+        warehouseMobileComplaintDay(path.toFile());
+        log.info("河北_CEM移网质量投诉明细数据入库成功: {}...", day);
+    }
+
+    /**
+     * 入库 河北_CEM移网质量投诉明细
+     */
+    private void warehouseMobileComplaintDay(File file) {
+        try (Reader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) {
+            // SOH作为分割符
+            char delimiter = 1;
+            CSVParser parser = CSVFormat.DEFAULT.builder()
+                    .setRecordSeparator("\n")
+                    .setQuote(null)
+                    .setDelimiter(delimiter)
+                    .setSkipHeaderRecord(false)
+                    .build().parse(reader);
+            List<CSVRecord> records = parser.getRecords();
+            List<Object[]> list = new ArrayList<>();
+            for (CSVRecord record : records) {
+                Object[] ps = new Object[dataWarehouseProperties.getFiledNumOfMobileComplaint().intValue()];
+                list.add(ps);
+                for (int i = 0; i < ps.length; i++) {
+                    ps[i] = record.get(i);
+                }
+            }
+            tslDataDao.batchInsertHighQualityListDay(list);
+        } catch (IOException e) {
+            e.printStackTrace();
+            throw new RuntimeException("河北_CEM移网质量投诉明细数据入库失败..." + e.getMessage());
+        }
+    }
+
+    public void warehouseHighQualityCountDay(String day) {
+        String fileName = dataWarehouseProperties.getPrefixOfHighQualityCountDay() + day + ".csv";
+        Path path = Paths.get(dataWarehouseProperties.getDirOfHighQualityCountDay(), fileName);
+        warehouseHighQualityCountDay(path.toFile());
+        log.info("河北_CEM高品质2日统计数据入库成功: {}...", day);
+    }
+
+    /**
+     * 入库 河北_CEM高品质2日统计
+     */
+    private void warehouseHighQualityCountDay(File file) {
+        try (Reader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) {
+            // SOH作为分割符
+            char delimiter = 1;
+            CSVParser parser = CSVFormat.DEFAULT.builder()
+                    .setRecordSeparator("\n")
+                    .setQuote(null)
+                    .setDelimiter(delimiter)
+                    .setSkipHeaderRecord(false)
+                    .build().parse(reader);
+            List<CSVRecord> records = parser.getRecords();
+            List<Object[]> list = new ArrayList<>();
+            for (CSVRecord record : records) {
+                Object[] ps = new Object[dataWarehouseProperties.getFiledNumOfMobileComplaint().intValue()];
+                list.add(ps);
+                for (int i = 0; i < ps.length; i++) {
+                    ps[i] = record.get(i);
+                }
+            }
+            tslDataDao.batchInsertHighQualityListDay(list);
+        } catch (IOException e) {
+            e.printStackTrace();
+            throw new RuntimeException("河北_CEM高品质2日统计数据入库失败..." + e.getMessage());
         }
     }
 }

+ 11 - 0
src/test/java/com/nokia/tsl_data/TslDataApplicationTest.java

@@ -1,6 +1,7 @@
 package com.nokia.tsl_data;
 
 import com.nokia.common.io.TextUtil;
+import com.nokia.pushmessage.service.PushMessageService;
 import com.nokia.tsl_data.dao.HighQualityListDayMapper;
 import com.nokia.tsl_data.dao.SysDataDictionaryRepository;
 import com.nokia.tsl_data.dao.TaskRecordRepository;
@@ -51,4 +52,14 @@ class TslDataApplicationTest {
     void test2() {
         cronTaskService.tempTableCleanCronTask();
     }
+
+    @Autowired(required = false)
+    private PushMessageService pushMessageService;
+
+    @Test
+    void test3() {
+        String accessToken = "b2f1424d6119affaacab614b184f043fcd2c73db2651bb86eff29992d66820bf";
+        String prefix = "CUC:";
+        pushMessageService.sendMarkdownMessage(accessToken, prefix, "abc");
+    }
 }