|
@@ -1,479 +0,0 @@
|
|
|
-//package com.management.collectdata.task;
|
|
|
-//
|
|
|
-//import com.management.collectdata.entity.BusinessTrip;
|
|
|
-//import com.management.collectdata.entity.ErpOrderInfo;
|
|
|
-//import com.management.collectdata.entity.LeaveSheet;
|
|
|
-//import com.management.collectdata.entity.UserFvTime;
|
|
|
-//import com.management.collectdata.mapper.BusinessTripMapper;
|
|
|
-//import com.management.collectdata.mapper.ErpOrderInfoMapper;
|
|
|
-//import com.management.collectdata.mapper.LeaveSheetMapper;
|
|
|
-//import com.management.collectdata.mapper.UserFvTimeMapper;
|
|
|
-//import com.zaxxer.hikari.HikariConfig;
|
|
|
-//import com.zaxxer.hikari.HikariDataSource;
|
|
|
-//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-//import org.springframework.beans.factory.annotation.Value;
|
|
|
-//import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
-//import org.springframework.scheduling.annotation.Scheduled;
|
|
|
-//import org.springframework.stereotype.Component;
|
|
|
-//import org.springframework.util.CollectionUtils;
|
|
|
-//
|
|
|
-//import javax.annotation.Resource;
|
|
|
-//import java.math.BigDecimal;
|
|
|
-//import java.math.RoundingMode;
|
|
|
-//import java.sql.Connection;
|
|
|
-//import java.sql.PreparedStatement;
|
|
|
-//import java.sql.ResultSet;
|
|
|
-//import java.sql.SQLException;
|
|
|
-//import java.text.SimpleDateFormat;
|
|
|
-//import java.time.LocalDate;
|
|
|
-//import java.time.LocalDateTime;
|
|
|
-//import java.time.format.DateTimeFormatter;
|
|
|
-//import java.util.ArrayList;
|
|
|
-//import java.util.List;
|
|
|
-//import java.util.stream.Collectors;
|
|
|
-//
|
|
|
-//@Component
|
|
|
-//@EnableScheduling
|
|
|
-//public class TimeTask {
|
|
|
-//
|
|
|
-// @Value("${company.companyid}")
|
|
|
-// private Integer companyId;
|
|
|
-//
|
|
|
-// @Resource
|
|
|
-// private ErpOrderInfoMapper erpOrderInfoMapper;
|
|
|
-//
|
|
|
-// private static HikariDataSource sqlServerDataSource;
|
|
|
-//
|
|
|
-// private static HikariDataSource mysqlDataSource;
|
|
|
-//
|
|
|
-// private static final int BATCH_SIZE = 1000;
|
|
|
-//
|
|
|
-// static {
|
|
|
-// HikariConfig sqlServerConfig = new HikariConfig();
|
|
|
-// sqlServerConfig.setJdbcUrl("jdbc:sqlserver://1.94.62.58:1433;databaseName=dbo_test;encrypt=true;trustServerCertificate=true");
|
|
|
-// sqlServerConfig.setUsername("sa");
|
|
|
-// sqlServerConfig.setPassword("HuoShi@Test");
|
|
|
-// sqlServerConfig.setMaximumPoolSize(5);
|
|
|
-// sqlServerDataSource = new HikariDataSource(sqlServerConfig);
|
|
|
-//
|
|
|
-//
|
|
|
-// HikariConfig mysqlConfig = new HikariConfig();
|
|
|
-// mysqlConfig.setJdbcUrl("jdbc:mysql://1.94.62.58:17089/ehr?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&rewriteBatchedStatements=true&useSSL=false");
|
|
|
-// mysqlConfig.setUsername("root");
|
|
|
-// mysqlConfig.setPassword("P011430@Huoshi*");
|
|
|
-// sqlServerConfig.setMaximumPoolSize(5);
|
|
|
-// mysqlDataSource = new HikariDataSource(mysqlConfig);
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// private UserFvTimeMapper userFvTimeMapper;
|
|
|
-// @Autowired
|
|
|
-// private BusinessTripMapper businessTripMapper;
|
|
|
-// @Autowired
|
|
|
-// private LeaveSheetMapper leaveSheetMapper;
|
|
|
-//
|
|
|
-// @Scheduled(cron = "0 0 1 * * ?")
|
|
|
-// public void sqlServerTask() {
|
|
|
-// String sqlCount = "select count(*) from mom_orderdetail where status in (3,4) ";
|
|
|
-//
|
|
|
-// String sqlQuery = " select MoDId ,SUBSTRING(cbSysBarCode, 8, 15) as orderId,Define24 as projectId,Define25 as projectName,RIGHT(cbSysBarCode,1) as line,status " +
|
|
|
-// " from mom_orderdetail " +
|
|
|
-// " where status in (3,4) "
|
|
|
-// +" ORDER BY MoDId OFFSET ? ROWS FETCH NEXT ? ROWS ONLY "
|
|
|
-// ;
|
|
|
-//
|
|
|
-// try (Connection connection = sqlServerDataSource.getConnection()) {
|
|
|
-// PreparedStatement countStmt = connection.prepareStatement(sqlCount);
|
|
|
-// PreparedStatement queryStmt = connection.prepareStatement(sqlQuery);
|
|
|
-//
|
|
|
-// List<ErpOrderInfo> resList = new ArrayList<>();
|
|
|
-// List<ErpOrderInfo> toAddList = new ArrayList<>();
|
|
|
-// List<ErpOrderInfo> toUpdateList = new ArrayList<>();
|
|
|
-// int pageSize = 4000;
|
|
|
-// int offset = 0;
|
|
|
-// int totalCount = 0;
|
|
|
-// ResultSet countRs = countStmt.executeQuery();
|
|
|
-// if (countRs.next()) {
|
|
|
-// totalCount = countRs.getInt(1);
|
|
|
-// }
|
|
|
-// System.out.println("开始迁移工时申请单,总记录数: " + totalCount);
|
|
|
-// if(totalCount > 0){
|
|
|
-// while (offset < totalCount) {
|
|
|
-// queryStmt.setInt(1, offset);
|
|
|
-// queryStmt.setInt(2, pageSize);
|
|
|
-// try (ResultSet resultSet = queryStmt.executeQuery()) {
|
|
|
-// int batchCount = 0;
|
|
|
-// while (resultSet.next()) {
|
|
|
-// ErpOrderInfo erpOrderInfo = new ErpOrderInfo();
|
|
|
-// erpOrderInfo.setMoDId(resultSet.getString("MoDId"));
|
|
|
-// erpOrderInfo.setOrderId(resultSet.getString("orderId"));
|
|
|
-// erpOrderInfo.setProjectId(resultSet.getString("projectId"));
|
|
|
-// erpOrderInfo.setProjectName(resultSet.getString("projectName"));
|
|
|
-// erpOrderInfo.setLine(resultSet.getInt("line"));
|
|
|
-// erpOrderInfo.setStatus(resultSet.getInt("status"));
|
|
|
-// resList.add(erpOrderInfo);
|
|
|
-// batchCount++;
|
|
|
-// if (batchCount % BATCH_SIZE == 0) {
|
|
|
-// List<String> collect = resList.stream().map(ErpOrderInfo::getMoDId).collect(Collectors.toList());
|
|
|
-// List<String> existIds = erpOrderInfoMapper.getExistIds(collect);
|
|
|
-// if(!CollectionUtils.isEmpty(existIds)){
|
|
|
-// toUpdateList.addAll(resList.stream().filter(t -> existIds.contains(t.getMoDId())).collect(Collectors.toList()));
|
|
|
-// toAddList.addAll(resList.stream().filter(t -> !existIds.contains(t.getMoDId())).collect(Collectors.toList()));
|
|
|
-// }
|
|
|
-// if(!CollectionUtils.isEmpty(toAddList)){
|
|
|
-// erpOrderInfoMapper.batchInsert(toAddList);
|
|
|
-// }
|
|
|
-// if(!CollectionUtils.isEmpty(toUpdateList)){
|
|
|
-// for (ErpOrderInfo orderInfo : toUpdateList) {
|
|
|
-// erpOrderInfoMapper.updateById(orderInfo);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// resList.clear();
|
|
|
-// toUpdateList.clear();
|
|
|
-// toAddList.clear();
|
|
|
-// }
|
|
|
-// offset += pageSize;
|
|
|
-// }
|
|
|
-// if(!resList.isEmpty()){
|
|
|
-// List<String> collect = resList.stream().map(ErpOrderInfo::getMoDId).collect(Collectors.toList());
|
|
|
-// List<String> existIds = erpOrderInfoMapper.getExistIds(collect);
|
|
|
-// if(!CollectionUtils.isEmpty(existIds)){
|
|
|
-// toUpdateList.addAll(resList.stream().filter(t -> existIds.contains(t.getMoDId())).collect(Collectors.toList()));
|
|
|
-// toAddList.addAll(resList.stream().filter(t -> !existIds.contains(t.getMoDId())).collect(Collectors.toList()));
|
|
|
-// }
|
|
|
-// if(!CollectionUtils.isEmpty(toAddList)){
|
|
|
-// erpOrderInfoMapper.batchInsert(toAddList);
|
|
|
-// }
|
|
|
-// if(!CollectionUtils.isEmpty(toUpdateList)){
|
|
|
-// for (ErpOrderInfo orderInfo : toUpdateList) {
|
|
|
-// erpOrderInfoMapper.updateById(orderInfo);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// resList.clear();
|
|
|
-// toUpdateList.clear();
|
|
|
-// toAddList.clear();
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// System.out.println("工时申请单数据迁移完成");
|
|
|
-// } catch (SQLException e) {
|
|
|
-// System.err.println("数据库操作错误: " + e.getMessage());
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-// @Scheduled(cron = "0 30 1 * * ?")
|
|
|
-// public void workDayTask(){
|
|
|
-// String sqlCount = "select count(*) from att_work_hour_day where create_date >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) ";
|
|
|
-//
|
|
|
-// String sqlQuery = " select id,emp_no,attendance_date,earliest_clock_date,last_clock_date,worktime_total_hour,overtime_total_hour " +
|
|
|
-// " from att_work_hour_day where create_date >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) order by id limit ?,? ";
|
|
|
-//
|
|
|
-// try (Connection connection = mysqlDataSource.getConnection()) {
|
|
|
-// PreparedStatement countStmt = connection.prepareStatement(sqlCount);
|
|
|
-// PreparedStatement queryStmt = connection.prepareStatement(sqlQuery);
|
|
|
-// List<UserFvTime> resList = new ArrayList<>();
|
|
|
-// List<UserFvTime> toAddList = new ArrayList<>();
|
|
|
-// List<UserFvTime> toUpdateList = new ArrayList<>();
|
|
|
-// int pageSize = 4000;
|
|
|
-// int offset = 0;
|
|
|
-// int totalCount = 0;
|
|
|
-// ResultSet countRs = countStmt.executeQuery();
|
|
|
-// if (countRs.next()) {
|
|
|
-// totalCount = countRs.getInt(1);
|
|
|
-// }
|
|
|
-// System.out.println("开始迁移打卡数据,总记录数: " + totalCount);
|
|
|
-//
|
|
|
-// if(totalCount > 0){
|
|
|
-// SimpleDateFormat sdfAll = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
-// while (offset < totalCount) {
|
|
|
-// queryStmt.setInt(1, offset);
|
|
|
-// queryStmt.setInt(2, pageSize);
|
|
|
-// try (ResultSet resultSet = queryStmt.executeQuery()) {
|
|
|
-// int batchCount = 0;
|
|
|
-// while (resultSet.next()) {
|
|
|
-// UserFvTime userFvTime = new UserFvTime();
|
|
|
-// userFvTime.setCompanyId(companyId);
|
|
|
-// userFvTime.setProcinstId(resultSet.getString("id"));
|
|
|
-// userFvTime.setUserId(resultSet.getString("emp_no"));
|
|
|
-// userFvTime.setWorkDate(LocalDate.parse(sdfAll.format(resultSet.getDate("attendance_date")), DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
-// userFvTime.setStartTime(sdfAll.format(resultSet.getDate("earliest_clock_date")));
|
|
|
-// userFvTime.setEndTime(sdfAll.format(resultSet.getDate("last_clock_date")));
|
|
|
-// userFvTime.setWorkHours(resultSet.getBigDecimal("worktime_total_hour").setScale(2, RoundingMode.HALF_UP).floatValue());
|
|
|
-// userFvTime.setOverTimeSeconds(resultSet.getBigDecimal("worktime_total_hour").setScale(1,RoundingMode.HALF_UP)
|
|
|
-// .multiply(new BigDecimal("3600")).longValue());
|
|
|
-//
|
|
|
-// resList.add(userFvTime);
|
|
|
-// batchCount++;
|
|
|
-// if (batchCount % BATCH_SIZE == 0) {
|
|
|
-// List<String> collect = resList.stream().map(UserFvTime::getProcinstId).collect(Collectors.toList());
|
|
|
-// List<String> existIds = userFvTimeMapper.getExistIds(collect);
|
|
|
-// if(!CollectionUtils.isEmpty(existIds)){
|
|
|
-// toUpdateList.addAll(resList.stream().filter(t -> existIds.contains(t.getProcinstId())).collect(Collectors.toList()));
|
|
|
-// toAddList.addAll(resList.stream().filter(t -> !existIds.contains(t.getProcinstId())).collect(Collectors.toList()));
|
|
|
-// }
|
|
|
-// if(!CollectionUtils.isEmpty(toAddList)){
|
|
|
-// userFvTimeMapper.batchInsert(toAddList);
|
|
|
-// }
|
|
|
-// if(!CollectionUtils.isEmpty(toUpdateList)){
|
|
|
-// for (UserFvTime tmp : toUpdateList) {
|
|
|
-// userFvTimeMapper.updateById(tmp);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// resList.clear();
|
|
|
-// toUpdateList.clear();
|
|
|
-// toAddList.clear();
|
|
|
-// }
|
|
|
-// offset += pageSize;
|
|
|
-// }
|
|
|
-// if(!resList.isEmpty()){
|
|
|
-// List<String> collect = resList.stream().map(UserFvTime::getProcinstId).collect(Collectors.toList());
|
|
|
-// List<String> existIds = userFvTimeMapper.getExistIds(collect);
|
|
|
-// if(!CollectionUtils.isEmpty(existIds)){
|
|
|
-// toUpdateList.addAll(resList.stream().filter(t -> existIds.contains(t.getProcinstId())).collect(Collectors.toList()));
|
|
|
-// toAddList.addAll(resList.stream().filter(t -> !existIds.contains(t.getProcinstId())).collect(Collectors.toList()));
|
|
|
-// }
|
|
|
-//
|
|
|
-// if(!CollectionUtils.isEmpty(toAddList)){
|
|
|
-// userFvTimeMapper.batchInsert(toAddList);
|
|
|
-// }
|
|
|
-// if(!CollectionUtils.isEmpty(toUpdateList)){
|
|
|
-// for (UserFvTime tmp : toUpdateList) {
|
|
|
-// userFvTimeMapper.updateById(tmp);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// resList.clear();
|
|
|
-// toUpdateList.clear();
|
|
|
-// toAddList.clear();
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// System.out.println("打卡数据数据迁移完成");
|
|
|
-// } catch (SQLException e) {
|
|
|
-// System.err.println("数据库操作错误: " + e.getMessage());
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Scheduled(cron = "0 0 2 * * ?")
|
|
|
-// public void leaveSheetTask(){
|
|
|
-// String sqlCount = "select count(*) from att_holiday_leave_order where audit_status = 3 and is_delete = 0 and create_date >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)";
|
|
|
-//
|
|
|
-// String sqlQuery = "select ahlo.id,ahlo.company_id,ahlo.emp_no,ahlo.emp_name " +
|
|
|
-// " ,ahlo.begin_date,ahlo.end_date,ahlo.leave_category_name " +
|
|
|
-// " ,ahlo.audit_status,ahlo.reason, eic.emp_no as operator_id " +
|
|
|
-// " ,ahlo.total_hour,ahlo.total_day,eie.mobile " +
|
|
|
-// " from att_holiday_leave_order ahlo " +
|
|
|
-// " left join emp_info eie on ahlo.emp_origin_id = eie.origin_id " +
|
|
|
-// " left join emp_info eic on ahlo.create_id = eic.origin_id " +
|
|
|
-// " where ahlo.audit_status = 3 and ahlo.is_delete = 0 and ahlo.create_date >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) order by ahlo.id limit ?,? ";
|
|
|
-//
|
|
|
-// try (Connection connection = mysqlDataSource.getConnection()) {
|
|
|
-// PreparedStatement countStmt = connection.prepareStatement(sqlCount);
|
|
|
-// PreparedStatement queryStmt = connection.prepareStatement(sqlQuery);
|
|
|
-// List<LeaveSheet> resList = new ArrayList<>();
|
|
|
-// List<LeaveSheet> toAddList = new ArrayList<>();
|
|
|
-// List<LeaveSheet> toUpdateList = new ArrayList<>();
|
|
|
-// int pageSize = 4000;
|
|
|
-// int offset = 0;
|
|
|
-// int totalCount = 0;
|
|
|
-// ResultSet countRs = countStmt.executeQuery();
|
|
|
-// if (countRs.next()) {
|
|
|
-// totalCount = countRs.getInt(1);
|
|
|
-// }
|
|
|
-// System.out.println("开始迁移出差数据,总记录数: " + totalCount);
|
|
|
-// SimpleDateFormat sdfAll = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
-// SimpleDateFormat sdfYmd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
-// if(totalCount > 0){
|
|
|
-// while (offset < totalCount) {
|
|
|
-// queryStmt.setInt(1, offset);
|
|
|
-// queryStmt.setInt(2, pageSize);
|
|
|
-// try (ResultSet resultSet = queryStmt.executeQuery()) {
|
|
|
-// int batchCount = 0;
|
|
|
-// while (resultSet.next()) {
|
|
|
-// LeaveSheet leaveSheet = new LeaveSheet();
|
|
|
-// leaveSheet.setCompanyId(companyId);
|
|
|
-// leaveSheet.setOwnerId(resultSet.getString("emp_no"));
|
|
|
-// leaveSheet.setOwnerName(resultSet.getString("emp_name"));
|
|
|
-// leaveSheet.setStartDate(LocalDate.parse(sdfYmd.format(resultSet.getDate("begin_date")),DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
-// leaveSheet.setEndDate(LocalDate.parse(sdfYmd.format(resultSet.getDate("end_date")),DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
-// switch (resultSet.getString("leave_category_name")){
|
|
|
-// case "调休假" : leaveSheet.setLeaveType(6); break;
|
|
|
-// case "年假" : leaveSheet.setLeaveType(2); break;
|
|
|
-// case "事假" : leaveSheet.setLeaveType(0); break;
|
|
|
-// case "病假" : leaveSheet.setLeaveType(1);break;
|
|
|
-// case "婚假" : leaveSheet.setLeaveType(4);break;
|
|
|
-// case "产假" : leaveSheet.setLeaveType(3);break;
|
|
|
-// case "哺乳假" : leaveSheet.setLeaveType(3);break;
|
|
|
-// case "陪产假" : leaveSheet.setLeaveType(7);break;
|
|
|
-// case "丧假" : leaveSheet.setLeaveType(5);break;
|
|
|
-// case "工伤假" : leaveSheet.setLeaveType(1);break;
|
|
|
-// case "育儿假" : leaveSheet.setLeaveType(3);break;
|
|
|
-// case "福利病假" : leaveSheet.setLeaveType(1);break;
|
|
|
-// default: leaveSheet.setLeaveType(8);break;
|
|
|
-// }
|
|
|
-// leaveSheet.setStatus(0);
|
|
|
-// leaveSheet.setRemark(resultSet.getString("reason"));
|
|
|
-// leaveSheet.setOperatorId(resultSet.getString("operator_id"));
|
|
|
-// leaveSheet.setTimeHours(resultSet.getBigDecimal("total_hour").setScale(1,RoundingMode.HALF_UP).floatValue());
|
|
|
-// leaveSheet.setTimeDays(resultSet.getBigDecimal("total_day").setScale(0,RoundingMode.HALF_UP).floatValue());
|
|
|
-// leaveSheet.setIndate(LocalDateTime.now());
|
|
|
-// leaveSheet.setTimeType(0);
|
|
|
-// leaveSheet.setTel(resultSet.getString("mobile"));
|
|
|
-// leaveSheet.setProcinstId(resultSet.getString("id"));
|
|
|
-//
|
|
|
-// resList.add(leaveSheet);
|
|
|
-// batchCount++;
|
|
|
-// if (batchCount % BATCH_SIZE == 0) {
|
|
|
-// List<String> collect = resList.stream().map(LeaveSheet::getProcinstId).collect(Collectors.toList());
|
|
|
-// List<String> existIds = leaveSheetMapper.getExistIds(collect);
|
|
|
-// if(!CollectionUtils.isEmpty(existIds)){
|
|
|
-// toUpdateList.addAll(resList.stream().filter(t -> existIds.contains(t.getProcinstId())).collect(Collectors.toList()));
|
|
|
-// toAddList.addAll(resList.stream().filter(t -> !existIds.contains(t.getProcinstId())).collect(Collectors.toList()));
|
|
|
-// }
|
|
|
-// if(!CollectionUtils.isEmpty(toAddList)){
|
|
|
-// leaveSheetMapper.batchInsert(toAddList);
|
|
|
-// }
|
|
|
-// if(!CollectionUtils.isEmpty(toUpdateList)){
|
|
|
-// for (LeaveSheet tmp : toUpdateList) {
|
|
|
-// leaveSheetMapper.updateById(tmp);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// resList.clear();
|
|
|
-// toUpdateList.clear();
|
|
|
-// toAddList.clear();
|
|
|
-// }
|
|
|
-// offset += pageSize;
|
|
|
-// }
|
|
|
-// if(!resList.isEmpty()){
|
|
|
-// List<String> collect = resList.stream().map(LeaveSheet::getProcinstId).collect(Collectors.toList());
|
|
|
-// List<String> existIds = leaveSheetMapper.getExistIds(collect);
|
|
|
-// if(!CollectionUtils.isEmpty(existIds)){
|
|
|
-// toUpdateList.addAll(resList.stream().filter(t -> existIds.contains(t.getProcinstId())).collect(Collectors.toList()));
|
|
|
-// toAddList.addAll(resList.stream().filter(t -> !existIds.contains(t.getProcinstId())).collect(Collectors.toList()));
|
|
|
-// }
|
|
|
-// if(!CollectionUtils.isEmpty(toAddList)){
|
|
|
-// leaveSheetMapper.batchInsert(toAddList);
|
|
|
-// }
|
|
|
-// if(!CollectionUtils.isEmpty(toUpdateList)){
|
|
|
-// for (LeaveSheet tmp : toUpdateList) {
|
|
|
-// leaveSheetMapper.updateById(tmp);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// resList.clear();
|
|
|
-// toUpdateList.clear();
|
|
|
-// toAddList.clear();
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// System.out.println("出差数据迁移完成");
|
|
|
-// } catch (SQLException e) {
|
|
|
-// System.err.println("数据库操作错误: " + e.getMessage());
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Scheduled(cron = "0 30 2 * * ?")
|
|
|
-// public void businessTripTask(){
|
|
|
-// String sqlCount = "select count(*) from att_business_trip_order where audit_status = 3 and is_delete = 0 and create_date >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) ";
|
|
|
-//
|
|
|
-// String sqlQuery = "select id,emp_no,emp_name,reason,begin_date,end_date,c_departure_place_city " +
|
|
|
-// " ,c_destination_place_city,trip_day " +
|
|
|
-// " from att_business_trip_order abto " +
|
|
|
-// " where abto.audit_status = 3 and abto.is_delete = 0 and abto.create_date >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) order by id limit ?,? ";
|
|
|
-//
|
|
|
-// try (Connection connection = mysqlDataSource.getConnection()) {
|
|
|
-// PreparedStatement countStmt = connection.prepareStatement(sqlCount);
|
|
|
-// PreparedStatement queryStmt = connection.prepareStatement(sqlQuery);
|
|
|
-// List<BusinessTrip> resList = new ArrayList<>();
|
|
|
-// List<BusinessTrip> toAddList = new ArrayList<>();
|
|
|
-// List<BusinessTrip> toUpdateList = new ArrayList<>();
|
|
|
-// int pageSize = 4000;
|
|
|
-// int offset = 0;
|
|
|
-// int totalCount = 0;
|
|
|
-// ResultSet countRs = countStmt.executeQuery();
|
|
|
-// if (countRs.next()) {
|
|
|
-// totalCount = countRs.getInt(1);
|
|
|
-// }
|
|
|
-// System.out.println("开始迁移出差数据,总记录数: " + totalCount);
|
|
|
-// if(totalCount > 0){
|
|
|
-// SimpleDateFormat sdfAll = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
-// SimpleDateFormat sdfYmd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
-// while (offset < totalCount) {
|
|
|
-// queryStmt.setInt(1, offset);
|
|
|
-// queryStmt.setInt(2, pageSize);
|
|
|
-// try (ResultSet resultSet = queryStmt.executeQuery()) {
|
|
|
-// int batchCount = 0;
|
|
|
-// while (resultSet.next()) {
|
|
|
-// BusinessTrip businessTrip = new BusinessTrip();
|
|
|
-// businessTrip.setCompanyId(companyId);
|
|
|
-// businessTrip.setWay(4);
|
|
|
-// businessTrip.setOwnerId(resultSet.getString("emp_no"));
|
|
|
-// businessTrip.setOwnerName(resultSet.getString("emp_name"));
|
|
|
-// businessTrip.setReason(resultSet.getString("reason"));
|
|
|
-// businessTrip.setStatus(0);
|
|
|
-// businessTrip.setStartDate(LocalDate.parse(sdfYmd.format(resultSet.getDate("begin_date")),DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
-// businessTrip.setEndDate(LocalDate.parse(sdfYmd.format(resultSet.getDate("end_date")),DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
-// businessTrip.setCityFrom(resultSet.getString("c_departure_place_city"));
|
|
|
-// businessTrip.setCityTo(resultSet.getString("c_destination_place_city"));
|
|
|
-// businessTrip.setDayCount(resultSet.getBigDecimal("trip_day").setScale(0,RoundingMode.HALF_UP).intValue());
|
|
|
-// businessTrip.setIndate(LocalDateTime.now());
|
|
|
-// businessTrip.setProcinstId(resultSet.getString("id"));
|
|
|
-//
|
|
|
-// resList.add(businessTrip);
|
|
|
-// batchCount++;
|
|
|
-// if (batchCount % BATCH_SIZE == 0) {
|
|
|
-// List<String> collect = resList.stream().map(BusinessTrip::getProcinstId).collect(Collectors.toList());
|
|
|
-// List<String> existIds = businessTripMapper.getExistIds(collect);
|
|
|
-// if(!CollectionUtils.isEmpty(existIds)){
|
|
|
-// toUpdateList.addAll(resList.stream().filter(t -> existIds.contains(t.getProcinstId())).collect(Collectors.toList()));
|
|
|
-// toAddList.addAll(resList.stream().filter(t -> !existIds.contains(t.getProcinstId())).collect(Collectors.toList()));
|
|
|
-// }
|
|
|
-// if(!CollectionUtils.isEmpty(toAddList)){
|
|
|
-// businessTripMapper.batchInsert(toAddList);
|
|
|
-// }
|
|
|
-// if(!CollectionUtils.isEmpty(toUpdateList)){
|
|
|
-// for (BusinessTrip tmp : toUpdateList) {
|
|
|
-// businessTripMapper.updateById(tmp);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// resList.clear();
|
|
|
-// toUpdateList.clear();
|
|
|
-// toAddList.clear();
|
|
|
-// }
|
|
|
-// offset += pageSize;
|
|
|
-// }
|
|
|
-// if(!resList.isEmpty()){
|
|
|
-// List<String> collect = resList.stream().map(BusinessTrip::getProcinstId).collect(Collectors.toList());
|
|
|
-// List<String> existIds = businessTripMapper.getExistIds(collect);
|
|
|
-// if(!CollectionUtils.isEmpty(existIds)){
|
|
|
-// toUpdateList.addAll(resList.stream().filter(t -> existIds.contains(t.getProcinstId())).collect(Collectors.toList()));
|
|
|
-// toAddList.addAll(resList.stream().filter(t -> !existIds.contains(t.getProcinstId())).collect(Collectors.toList()));
|
|
|
-// }
|
|
|
-// if(!CollectionUtils.isEmpty(toAddList)){
|
|
|
-// businessTripMapper.batchInsert(toAddList);
|
|
|
-// }
|
|
|
-// if(!CollectionUtils.isEmpty(toUpdateList)){
|
|
|
-// for (BusinessTrip tmp : toUpdateList) {
|
|
|
-// businessTripMapper.updateById(tmp);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// resList.clear();
|
|
|
-// toUpdateList.clear();
|
|
|
-// toAddList.clear();
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// System.out.println("出差数据迁移完成");
|
|
|
-// } catch (SQLException e) {
|
|
|
-// System.err.println("数据库操作错误: " + e.getMessage());
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-//}
|