diff --git a/src/main/java/com/biutag/supervision/controller/data/DataMigrationController.java b/src/main/java/com/biutag/supervision/controller/data/DataMigrationController.java new file mode 100644 index 0000000..bcffc67 --- /dev/null +++ b/src/main/java/com/biutag/supervision/controller/data/DataMigrationController.java @@ -0,0 +1,23 @@ +package com.biutag.supervision.controller.data; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.biutag.supervision.pojo.Result; +import com.biutag.supervision.pojo.model.DataMigrationModel; +import com.biutag.supervision.pojo.param.DataMigrationQueryParam; +import com.biutag.supervision.service.DataMigrationServiceImpl; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RequiredArgsConstructor +@RequestMapping("data/migration") +@RestController +public class DataMigrationController { + private final DataMigrationServiceImpl dataMigrationService; + + @GetMapping("page") + Result> page(DataMigrationQueryParam dataMigrationQueryParam) { + return Result.success(dataMigrationService.page(dataMigrationQueryParam)); + } +} diff --git a/src/main/java/com/biutag/supervision/mapper/DataPoliceMeetingMysqlMapper.java b/src/main/java/com/biutag/supervision/mapper/DataPoliceMeetingMysqlMapper.java index ae40c81..d0044ce 100644 --- a/src/main/java/com/biutag/supervision/mapper/DataPoliceMeetingMysqlMapper.java +++ b/src/main/java/com/biutag/supervision/mapper/DataPoliceMeetingMysqlMapper.java @@ -1,9 +1,15 @@ package com.biutag.supervision.mapper; import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.toolkit.Constants; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.biutag.supervision.pojo.entity.DataPoliceMeeting; +import com.biutag.supervision.pojo.model.DataMigrationModel; +import com.biutag.supervision.pojo.param.DataMigrationQueryParam; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** * @author 舒云 @@ -13,6 +19,7 @@ import org.apache.ibatis.annotations.Mapper; @DS("master") @Mapper public interface DataPoliceMeetingMysqlMapper extends BaseMapper { + Page queryPage(@Param("page") Page page, @Param(Constants.WRAPPER) QueryWrapper queryWrapper); } diff --git a/src/main/java/com/biutag/supervision/mapper/DataPoliceMeetingSqlServerMapper.java b/src/main/java/com/biutag/supervision/mapper/DataPoliceMeetingSqlServerMapper.java deleted file mode 100644 index 89ee979..0000000 --- a/src/main/java/com/biutag/supervision/mapper/DataPoliceMeetingSqlServerMapper.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.biutag.supervision.mapper; - -import com.baomidou.dynamic.datasource.annotation.DS; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.biutag.supervision.pojo.entity.DataPoliceMeetingV; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Select; - -import java.time.LocalDateTime; -import java.util.List; - - -/** -* @author 舒云 -* @createDate 2024-11-13 09:43:04 -*/ -@DS("test1") -@Mapper -public interface DataPoliceMeetingSqlServerMapper extends BaseMapper { - - @Select("select max(create_time) from data_police_meeting") - LocalDateTime selectMaxCreateTime(); - - @Select("select * from data_police_meeting where create_time > #{lastSelectTime} and create_time <= #{now}") - List selectAimList(LocalDateTime lastSelectTime, LocalDateTime now); - - - @Select("SELECT * FROM SampleResultPoolView " + - "WHERE create_time > #{lastSelectTime} AND create_time <= #{now} " + - "ORDER BY create_time " + - "OFFSET #{offset} ROWS FETCH NEXT #{pageSize} ROWS ONLY") - List selectAimListWithPagination(LocalDateTime lastSelectTime, LocalDateTime now, int offset, int pageSize); -} - - - - diff --git a/src/main/java/com/biutag/supervision/pojo/entity/DataPoliceMeeting.java b/src/main/java/com/biutag/supervision/pojo/entity/DataPoliceMeeting.java index eeb8039..117c93f 100644 --- a/src/main/java/com/biutag/supervision/pojo/entity/DataPoliceMeeting.java +++ b/src/main/java/com/biutag/supervision/pojo/entity/DataPoliceMeeting.java @@ -83,8 +83,8 @@ public class DataPoliceMeeting implements Serializable { /** * */ - @TableField(value = "visitime") - private Date visitime; + @TableField(value = "visit_time") + private Date visitTime; /** * diff --git a/src/main/java/com/biutag/supervision/pojo/entity/DataPoliceMeetingV.java b/src/main/java/com/biutag/supervision/pojo/entity/DataPoliceMeetingV.java deleted file mode 100644 index 506e1b2..0000000 --- a/src/main/java/com/biutag/supervision/pojo/entity/DataPoliceMeetingV.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.biutag.supervision.pojo.entity; - -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; - -import java.io.Serializable; -import java.util.Date; - -/** - * sqlServer数据库SampleResultPoolView视图实体类 - * @TableName SampleResultPoolView - */ -@TableName(value ="SampleResultPoolView") -@Data -public class DataPoliceMeetingV implements Serializable { - /** - * - */ - @TableField(value = "sample_id") - private Integer sampleId; - - /** - * - */ - @TableField(value = "name") - private String name; - - /** - * - */ - @TableField(value = "visit_name") - private String visitName; - - /** - * - */ - @TableField(value = "visit_phone") - private String visitPhone; - - /** - * - */ - @TableField(value = "organize_id") - private String organizeId; - - /** - * - */ - @TableField(value = "org_name") - private String orgName; - - /** - * - */ - @TableField(value = "business_id") - private Integer businessId; - - /** - * - */ - @TableField(value = "business_name") - private String businessName; - - /** - * - */ - @TableField(value = "sample_time") - private Date sampleTime; - - /** - * - */ - @TableField(value = "create_time") - private Date createTime; - - /** - * - */ - @TableField(value = "sample_content") - private String sampleContent; - - /** - * - */ - @TableField(value = "visitime") - private Date visitime; - - /** - * - */ - @TableField(value = "result_name") - private String resultName; - - /** - * - */ - @TableField(value = "code") - private String code; - - @TableField(exist = false) - private static final long serialVersionUID = 1L; -} \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/pojo/model/DataMigrationModel.java b/src/main/java/com/biutag/supervision/pojo/model/DataMigrationModel.java new file mode 100644 index 0000000..52996c3 --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/model/DataMigrationModel.java @@ -0,0 +1,24 @@ +package com.biutag.supervision.pojo.model; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Getter; +import lombok.Setter; + +import java.time.LocalDateTime; + +@Setter +@Getter +public class DataMigrationModel { + private Integer sampleId; + private String name; + private String visitName; + private String visitPhone; + private String orgName; + private String businessName; + @JsonFormat(pattern = "YYYY-MM-dd HH:mm") + private LocalDateTime sampleTime; + private String sampleContent; + @JsonFormat(pattern = "YYYY-MM-dd HH:mm") + private LocalDateTime visitTime; + private String resultName; +} diff --git a/src/main/java/com/biutag/supervision/pojo/param/DataMigrationQueryParam.java b/src/main/java/com/biutag/supervision/pojo/param/DataMigrationQueryParam.java new file mode 100644 index 0000000..feebfe3 --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/param/DataMigrationQueryParam.java @@ -0,0 +1,36 @@ +package com.biutag.supervision.pojo.param; + +import lombok.Getter; +import lombok.Setter; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Setter +@Getter +public class DataMigrationQueryParam implements Serializable { + private long current = 1; + private long size = 10; + + private Integer sampleId; + // 事务名 + private String name; + // 受访人 + private String visitName; + private String visitPhone; + private String organizeId; + private String orgName; + private Integer businessId; + private String businessName; + @DateTimeFormat(pattern = "yyyy-MM-dd") + private List sampleTime = new ArrayList<>(); + @DateTimeFormat(pattern = "yyyy-MM-dd") + private List visitTime = new ArrayList<>(); + // 排序字段 + private String sortField; + // 排序顺序(ASC 或 DESC) + private String sortOrder; +} diff --git a/src/main/java/com/biutag/supervision/service/BusinessDepartService.java b/src/main/java/com/biutag/supervision/service/BusinessDepartService.java index ee5594a..cfbf4d4 100644 --- a/src/main/java/com/biutag/supervision/service/BusinessDepartService.java +++ b/src/main/java/com/biutag/supervision/service/BusinessDepartService.java @@ -85,11 +85,6 @@ public class BusinessDepartService extends ServiceImpl { - - @Resource - private DataPoliceMeetingMysqlMapper dataPoliceMeetingMysqlMapper; - @Resource - private DataPoliceMeetingSqlServerMapper dataPoliceMeetingSqlServerMapper; - - @Resource - private DataMigrationMapper dataMigrationMapper; // 迁移记录 - - private static final int BATCH_SIZE = 1000; // 每次处理的记录数 - - public List getDataPoliceMeetingFromSqlServer(LocalDateTime lastSelectTime, LocalDateTime now) { - return dataPoliceMeetingSqlServerMapper.selectAimList(lastSelectTime, now); - } -// @PostConstruct -// public void startMigration() { -// CompletableFuture.runAsync(() -> migrateData()); -// } - - /* @Async - public void migrateDataAsync() { - migrateData(); - }*/ - // @Scheduled(cron = "*/10 * * * * ?") - -// @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; - int total = 0; - List dataPoliceMeetingFromSqlServerList; - do { - dataPoliceMeetingFromSqlServerList = getDataPoliceMeetingFromSqlServer(lastMigrationTime, LocalDateTime.now(), pageNum, pageSize); - System.out.println("查询到" + dataPoliceMeetingFromSqlServerList.size() + "条数据"); - // 3、开始新的迁移 - boolean migrationSuccessful = updateMigration(dataPoliceMeetingFromSqlServerList); - total += dataPoliceMeetingFromSqlServerList.size(); - if (!migrationSuccessful) { - System.out.println("数据迁移失败"); - return; - } - 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(String.valueOf(total)); - LocalDateTime maxCreateTime = dataPoliceMeetingSqlServerMapper.selectMaxCreateTime(); - dataMigration.setTargetMaxTime(maxCreateTime); - dataMigrationMapper.insert(dataMigration); - System.out.println("数据迁移成功"); - } - - private boolean updateMigration(List dataPoliceMeetingFromSqlServerList) { - try { - if (!dataPoliceMeetingFromSqlServerList.isEmpty()) { - List 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) { - return false; +public class DataMigrationServiceImpl extends ServiceImpl { + public Page page(DataMigrationQueryParam dataMigrationQueryParam) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.like(dataMigrationQueryParam.getSampleId() != null, "sample_id", dataMigrationQueryParam.getSampleId()) + .like(StrUtil.isNotBlank(dataMigrationQueryParam.getName()), "name", dataMigrationQueryParam.getName()) + .like(StrUtil.isNotBlank(dataMigrationQueryParam.getVisitName()), "visit_name", dataMigrationQueryParam.getVisitName()) + .like(StrUtil.isNotBlank(dataMigrationQueryParam.getVisitPhone()), "visit_phone", dataMigrationQueryParam.getVisitPhone()) + .like(StrUtil.isNotBlank(dataMigrationQueryParam.getOrgName()), "org_name", dataMigrationQueryParam.getOrgName()) + .like(StrUtil.isNotBlank(dataMigrationQueryParam.getBusinessName()), "business_name", dataMigrationQueryParam.getBusinessName()) + .orderBy(StrUtil.isNotBlank(dataMigrationQueryParam.getSortField()), dataMigrationQueryParam.getSortOrder().equals("ASC"), changeSortField(dataMigrationQueryParam.getSortField())); + if (dataMigrationQueryParam.getSampleTime().size() == 2) { + queryWrapper.between("sample_time", dataMigrationQueryParam.getSampleTime().get(0), dataMigrationQueryParam.getSampleTime().get(1)); } + if (dataMigrationQueryParam.getVisitTime().size() == 2) { + queryWrapper.between("visit_time", dataMigrationQueryParam.getVisitTime().get(0), dataMigrationQueryParam.getVisitTime().get(1)); + } + return baseMapper.queryPage(Page.of(dataMigrationQueryParam.getCurrent(), dataMigrationQueryParam.getSize()), queryWrapper); } - // 大数据分页查询 - public List 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 dataPoliceMeetingFromSqlServerList) { - DataMigration dataMigration = new DataMigration(); - dataMigration.setTarget("sqlServer"); - dataMigration.setStartTime(startTime); - dataMigration.setEndTime(endTime); - dataMigration.setMigrationCount(String.valueOf(dataPoliceMeetingFromSqlServerList.size())); - LocalDateTime maxCreateTime = dataPoliceMeetingSqlServerMapper.selectMaxCreateTime(); - dataMigration.setTargetMaxTime(maxCreateTime); - dataMigrationMapper.insert(dataMigration); + private String changeSortField(String sortField) { + if (sortField.equals("sampleTime")) { + return "sample_time"; + } else if (sortField.equals("visitTime")) { + return "visit_time"; + } + return ""; } } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index a0140b2..b2c2506 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -26,11 +26,6 @@ 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 druid: min-evictable-idle-time-millis: 300000 test-on-borrow: false diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 02bebe5..fbbc244 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -26,12 +26,6 @@ spring: url: jdbc:dm://65.47.22.243:5236?SCHEMA=JSDZ_4GDB username: DCZD password: DCZD@2024 -# 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 diff --git a/src/main/resources/mapper/DataPoliceMeetingMysqlMapper.xml b/src/main/resources/mapper/DataPoliceMeetingMysqlMapper.xml new file mode 100644 index 0000000..452dd16 --- /dev/null +++ b/src/main/resources/mapper/DataPoliceMeetingMysqlMapper.xml @@ -0,0 +1,14 @@ + + + + + + + + \ No newline at end of file