Browse Source

新增获取警务评议数据功能

main
sjh 1 year ago
parent
commit
b11657500c
  1. 22
      pom.xml
  2. 4
      src/main/java/com/biutag/supervision/pojo/entity/DataMigration.java
  3. 2
      src/main/java/com/biutag/supervision/pojo/entity/DataPoliceMeeting.java
  4. 2
      src/main/java/com/biutag/supervision/pojo/entity/DataPoliceMeetingV.java
  5. 8
      src/main/java/com/biutag/supervision/service/BusinessDepartService.java
  6. 47
      src/main/java/com/biutag/supervision/service/DataMigrationServiceImpl.java
  7. 10
      src/main/resources/application-dev.yml
  8. 11
      src/main/resources/application-prod.yml

22
pom.xml

@ -48,7 +48,27 @@
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>9.4.0.jre11</version>
<version>12.8.1.jre11</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>

4
src/main/java/com/biutag/supervision/pojo/entity/DataMigration.java

@ -1,5 +1,6 @@
package com.biutag.supervision.pojo.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
@ -7,7 +8,6 @@ import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;
/**
* 数据库迁移记录
@ -19,7 +19,7 @@ public class DataMigration implements Serializable {
/**
* 数据迁移操作id
*/
@TableId(value = "id")
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/**

2
src/main/java/com/biutag/supervision/pojo/entity/DataPoliceMeeting.java

@ -54,7 +54,7 @@ public class DataPoliceMeeting implements Serializable {
*
*/
@TableField(value = "business_id")
private String businessId;
private Integer businessId;
/**
*

2
src/main/java/com/biutag/supervision/pojo/entity/DataPoliceMeetingV.java

@ -54,7 +54,7 @@ public class DataPoliceMeetingV implements Serializable {
*
*/
@TableField(value = "business_id")
private String businessId;
private Integer businessId;
/**
*

8
src/main/java/com/biutag/supervision/service/BusinessDepartService.java

@ -46,6 +46,8 @@ public class BusinessDepartService extends ServiceImpl<BusinessDepartMapper, Bus
private final DataRightsComfortService dataRightsComfortService;
private final DataMigrationServiceImpl dataMigrationServiceImpl;
public Page<BusinessPoliceModel> page(BusinessQueryParam businessQueryParam) {
// 测基础数据
if (businessQueryParam.getDepartName() != null && businessQueryParam.getDepartName().equals("开始导入今年所有的数据")) {
@ -83,6 +85,12 @@ public class BusinessDepartService extends ServiceImpl<BusinessDepartMapper, Bus
int i = 0;
}
if (departName != null && departName.equals("运行导入")) {
System.out.println("开始执行导入");
dataMigrationServiceImpl.migrateData();
System.out.println("导入执行完毕");
}
// 测导入单位关联表
if (businessQueryParam.getDepartName() != null && businessQueryParam.getDepartName().equals("导入单位")) {
System.out.println("开始导入单位");

47
src/main/java/com/biutag/supervision/service/DataMigrationServiceImpl.java

@ -1,7 +1,6 @@
package com.biutag.supervision.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.biutag.supervision.mapper.DataMigrationMapper;
import com.biutag.supervision.mapper.DataPoliceMeetingMysqlMapper;
@ -9,25 +8,14 @@ import com.biutag.supervision.mapper.DataPoliceMeetingSqlServerMapper;
import com.biutag.supervision.pojo.entity.DataMigration;
import com.biutag.supervision.pojo.entity.DataPoliceMeeting;
import com.biutag.supervision.pojo.entity.DataPoliceMeetingV;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.DateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream;
/**
* @author 舒云
@ -48,12 +36,9 @@ public class DataMigrationServiceImpl extends ServiceImpl<DataMigrationMapper, D
private static final int BATCH_SIZE = 1000; // 每次处理的记录数
public List<DataPoliceMeetingV> getDataPoliceMeetingFromSqlServer(LocalDateTime lastSelectTime, LocalDateTime now) {
return dataPoliceMeetingSqlServerMapper.selectAimList(lastSelectTime, now);
}
// @PostConstruct
// public void startMigration() {
// CompletableFuture.runAsync(() -> migrateData());
@ -67,21 +52,20 @@ public class DataMigrationServiceImpl extends ServiceImpl<DataMigrationMapper, D
// @Async
public void migrateData() {
LocalDateTime startTime = LocalDateTime.now(); // 开始迁移时间
// 1. 查询数据库中最后一次迁移的时间
DataMigration lastMigration = dataMigrationMapper.selectLastMigrationTime();
LocalDateTime lastMigrationTime = (lastMigration == null || lastMigration.getTargetMaxTime() == null)
? LocalDateTime.of(1970, 1, 1, 0, 0)
: lastMigration.getTargetMaxTime();
// 2、准备数据
int pageNum = 1;
int pageSize = 1000;
Long total = 0L;
int total = 0;
List<DataPoliceMeetingV> dataPoliceMeetingFromSqlServerList;
do {
dataPoliceMeetingFromSqlServerList = getDataPoliceMeetingFromSqlServer(lastMigrationTime, LocalDateTime.now(), pageNum, pageSize);
System.out.println("查询到" + dataPoliceMeetingFromSqlServerList.size() + "条数据");
// 3、开始新的迁移
boolean migrationSuccessful = updateMigration(dataPoliceMeetingFromSqlServerList);
total += dataPoliceMeetingFromSqlServerList.size();
@ -92,30 +76,30 @@ public class DataMigrationServiceImpl extends ServiceImpl<DataMigrationMapper, D
pageNum++;
} while (!dataPoliceMeetingFromSqlServerList.isEmpty());
LocalDateTime endTime = LocalDateTime.now();
// updateMigrationRecord(startTime, endTime, dataPoliceMeetingFromSqlServerList);
DataMigration dataMigration = new DataMigration();
dataMigration.setTarget("sqlServer");
dataMigration.setStartTime(startTime);
dataMigration.setEndTime(endTime);
dataMigration.setMigrationCount(total.toString());
dataMigration.setMigrationCount(String.valueOf(total));
LocalDateTime maxCreateTime = dataPoliceMeetingSqlServerMapper.selectMaxCreateTime();
dataMigration.setTargetMaxTime(maxCreateTime);
dataMigrationMapper.insert(dataMigration);
System.out.println("数据迁移成功");
}
private boolean updateMigration(List<DataPoliceMeetingV> dataPoliceMeetingFromSqlServerList) {
try {
for (DataPoliceMeetingV dataPoliceMeetingV : dataPoliceMeetingFromSqlServerList) {
DataPoliceMeeting dataPoliceMeeting = new DataPoliceMeeting();
BeanUtils.copyProperties(dataPoliceMeetingV, dataPoliceMeeting);
dataPoliceMeetingMysqlMapper.insert(dataPoliceMeeting);
if (!dataPoliceMeetingFromSqlServerList.isEmpty()) {
List<DataPoliceMeeting> dataPoliceMeetingList = new ArrayList<>(dataPoliceMeetingFromSqlServerList.size());
for (DataPoliceMeetingV dataPoliceMeetingV : dataPoliceMeetingFromSqlServerList) {
DataPoliceMeeting dataPoliceMeeting = new DataPoliceMeeting();
BeanUtils.copyProperties(dataPoliceMeetingV, dataPoliceMeeting);
dataPoliceMeetingList.add(dataPoliceMeeting);
}
System.out.println("准备插入" + dataPoliceMeetingList.size() + "条数据");
dataPoliceMeetingMysqlMapper.insert(dataPoliceMeetingList);
System.out.println("插入成功");
}
return true;
} catch (BeansException e) {
@ -126,10 +110,10 @@ public class DataMigrationServiceImpl extends ServiceImpl<DataMigrationMapper, D
// 大数据分页查询
public List<DataPoliceMeetingV> getDataPoliceMeetingFromSqlServer(LocalDateTime lastSelectTime, LocalDateTime now, int pageNum, int pageSize) {
int offset = (pageNum - 1) * pageSize;
System.out.println("开始查询sqlserver,offset:" + offset);
return dataPoliceMeetingSqlServerMapper.selectAimListWithPagination(lastSelectTime, now, offset, pageSize);
}
private void updateMigrationRecord(LocalDateTime startTime, LocalDateTime endTime, List<DataPoliceMeetingV> dataPoliceMeetingFromSqlServerList) {
DataMigration dataMigration = new DataMigration();
dataMigration.setTarget("sqlServer");
@ -140,9 +124,6 @@ public class DataMigrationServiceImpl extends ServiceImpl<DataMigrationMapper, D
dataMigration.setTargetMaxTime(maxCreateTime);
dataMigrationMapper.insert(dataMigration);
}
}

10
src/main/resources/application-dev.yml

@ -26,11 +26,11 @@ spring:
url: jdbc:mysql://172.31.217.20:31868/negative?serverTimezone=GMT%2B8
username: root
password: ip12341234
test1:
url: jdbc:sqlserver://8.155.28.101:1433;databaseName=test1
username: SA
password: shihao&&200003
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
# test1:
# url: jdbc:sqlserver://8.155.28.101:1433;databaseName=test1
# username: SA
# password: shihao&&200003
# driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
druid:
min-evictable-idle-time-millis: 300000
test-on-borrow: false

11
src/main/resources/application-prod.yml

@ -26,11 +26,12 @@ spring:
url: jdbc:dm://65.47.22.243:5236?SCHEMA=JSDZ_4GDB
username: DCZD
password: DCZD@2024
# test1:
# url: jdbc:sqlserver://65.47.6.114:1433;databaseName=VisitManage_CS
# username: ck1112
# password: CK@20241112
# driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
test1:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://65.47.6.114:1433;databaseName=VisitManage_CS
username: ck1112
password: CK@20241112
druid:
min-evictable-idle-time-millis: 300000
test-on-borrow: false

Loading…
Cancel
Save