检查等待时间改为从配置文件获取
修改初始插入员工信息时的判重条件 调岗刷数范围改成批量月1号至月末 BIZ032增加null的处理
This commit is contained in:
parent
71edd69307
commit
30cea58021
@ -1,5 +1,6 @@
|
||||
package com.gtsoft.mps.batch;
|
||||
|
||||
import com.gtsoft.mps.batch.config.ConfigManager;
|
||||
import com.gtsoft.mps.batch.config.LogConfig;
|
||||
import com.gtsoft.mps.batch.exception.NoDataToProcessException;
|
||||
import com.gtsoft.mps.batch.processor.AbstractBusinessProcessor;
|
||||
@ -44,7 +45,7 @@ public class MpsFormalBatchMain {
|
||||
// 最大等待时间(小时)
|
||||
private static final int MAX_WAIT_HOURS = 240;
|
||||
// 状态检查间隔时间
|
||||
private static final int WAIT_TIME = 10;
|
||||
private static final int WAIT_TIME = Integer.parseInt(ConfigManager.getString("batch.query.wait.time", "60"));
|
||||
|
||||
public MpsFormalBatchMain() {
|
||||
this.batchStatusService = new BatchStatusService();
|
||||
|
||||
@ -105,8 +105,8 @@ public class BIZ032Processor extends AbstractBusinessProcessor {
|
||||
" a.jb_id AS marketer_code, " +
|
||||
" ? AS record_date, " +
|
||||
" COUNT(1) AS total_count, " +
|
||||
" SUM(CASE WHEN a.yx_id = a.jb_id THEN h.payment_amount END) AS self_marketing_amt, " +
|
||||
" SUM(CASE WHEN a.yx_id <> a.jb_id THEN h.payment_amount END) AS other_marketing_amt, " +
|
||||
" SUM(CASE WHEN a.yx_id = a.jb_id THEN h.payment_amount ELSE 0 END) AS self_marketing_amt, " +
|
||||
" SUM(CASE WHEN a.yx_id <> a.jb_id THEN h.payment_amount ELSE 0 END) AS other_marketing_amt, " +
|
||||
" MAX(COALESCE(g.pricing_rule, 1)) AS pricing_rule, " +
|
||||
" MAX(COALESCE(f.jb_percent, 1)) AS jb_percent " +
|
||||
" FROM mps_market a " +
|
||||
|
||||
@ -99,7 +99,7 @@ public class DeptTransferProcessor extends AbstractBusinessProcessor {
|
||||
|
||||
String sql = "SELECT COUNT(1) AS record_count " +
|
||||
"FROM sys_dept_transfer " +
|
||||
"WHERE transfer_date > ? AND transfer_date <= ? ";
|
||||
"WHERE transfer_date >= ? AND transfer_date <= ? ";
|
||||
|
||||
try (ResultSet rs = executeParameterizedQuery(connection, sql, startDate, endDate)) {
|
||||
if (rs.next()) {
|
||||
@ -115,53 +115,19 @@ public class DeptTransferProcessor extends AbstractBusinessProcessor {
|
||||
* 从mps_batch表获取处理时间范围
|
||||
*
|
||||
* @param connection 数据库连接
|
||||
* @param batchMonth 批次月份(格式: yyyyMM)
|
||||
* @param batchMonth 批次月份(格式: yyyy-MM)
|
||||
* @return 时间范围对象,包含开始日期和结束日期
|
||||
* @throws SQLException 如果查询数据库时发生异常
|
||||
*/
|
||||
private BatchDateRange getBatchDateRange(Connection connection, String batchMonth) throws SQLException {
|
||||
|
||||
//上月末
|
||||
String startDate = DateUtils.getFirstDayOfLastMonthYyyy_Mm_Dd();
|
||||
;
|
||||
//当前日期
|
||||
String endDate = DateUtils.getTodayYyyy_Mm_Dd();
|
||||
//月初
|
||||
String startDate = DateUtils.getFirstDayOfMonth(batchMonth);
|
||||
|
||||
String sql = "SELECT after_batch_date FROM mps_batch ORDER BY batch_month DESC";
|
||||
//月末
|
||||
String endDate = DateUtils.getLastDayOfMonth(batchMonth);
|
||||
|
||||
try (ResultSet rs = executeParameterizedQuery(connection, sql)) {
|
||||
List<String> batchDates = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
String date = rs.getString("after_batch_date");
|
||||
if (date != null && !date.isEmpty()) {
|
||||
batchDates.add(date);
|
||||
}
|
||||
}
|
||||
|
||||
if (batchDates.isEmpty()) {
|
||||
logger.warn("mps_batch表中无有效记录,取上月1号和当前日期");
|
||||
return new BatchDateRange(startDate, endDate);
|
||||
}
|
||||
|
||||
// 最新记录为结束日期
|
||||
endDate = batchDates.get(0);
|
||||
|
||||
// 确定开始日期
|
||||
if (batchDates.size() >= 2) {
|
||||
// 有两条以上记录,取上一条记录作为开始日期
|
||||
startDate = batchDates.get(1);
|
||||
} else {
|
||||
// 只有一条记录,取上月1号
|
||||
try {
|
||||
startDate = DateUtils.getFirstDayOfLastMonthYyyy_Mm_Dd();
|
||||
logger.info("只有一条记录,取上月1号为开始日期: {}", startDate);
|
||||
} catch (Exception e) {
|
||||
logger.error("计算开始日期时发生异常,batchDate: {}", batchMonth, e);
|
||||
throw new RuntimeException("计算开始日期时发生异常,batchDate: {}", e);
|
||||
}
|
||||
}
|
||||
return new BatchDateRange(startDate, endDate);
|
||||
}
|
||||
return new BatchDateRange(startDate, endDate);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -214,7 +180,7 @@ public class DeptTransferProcessor extends AbstractBusinessProcessor {
|
||||
"LEFT JOIN sys_dept new on a.new_dept_id=new.dept_id " +
|
||||
"LEFT JOIN sys_dept old on a.old_dept_id=old.dept_id " +
|
||||
"WHERE " +
|
||||
" a.transfer_date > ? AND a.transfer_date <= ? " +
|
||||
" a.transfer_date >= ? AND a.transfer_date <= ? " +
|
||||
"ORDER BY " +
|
||||
" a.mkt_no, " +
|
||||
" a.transfer_date asc";
|
||||
|
||||
@ -110,6 +110,7 @@ public class InitInsertProcessor extends AbstractBusinessProcessor {
|
||||
"AND NOT EXISTS (" +
|
||||
" SELECT 1 FROM %s mp " +
|
||||
" WHERE mp.marketer_code = a.yx_id " +
|
||||
" and mp.branch_id = e.dept_category " +
|
||||
" AND mp.record_date = ?" +
|
||||
") and substr(a.entry_date,1,7)=? )"
|
||||
, tableName, tableName);
|
||||
@ -153,6 +154,7 @@ public class InitInsertProcessor extends AbstractBusinessProcessor {
|
||||
" %s mp " +
|
||||
" WHERE " +
|
||||
" mp.marketer_code = a.marketing_code " +
|
||||
" and mp.branch_id = e.dept_category " +
|
||||
" AND mp.record_date = ? " +
|
||||
") " +
|
||||
")"
|
||||
@ -196,6 +198,7 @@ public class InitInsertProcessor extends AbstractBusinessProcessor {
|
||||
" %s mp " +
|
||||
" WHERE " +
|
||||
" mp.marketer_code = a.marketing_code " +
|
||||
" and mp.branch_id = e.dept_category " +
|
||||
" AND mp.record_date = ? " +
|
||||
") " +
|
||||
")"
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.gtsoft.mps.batch.service;
|
||||
|
||||
import com.gtsoft.mps.batch.config.ConfigManager;
|
||||
import com.gtsoft.mps.batch.util.DatabaseConnection;
|
||||
import com.gtsoft.mps.batch.util.DateUtils;
|
||||
import org.slf4j.Logger;
|
||||
@ -40,7 +41,7 @@ public class BatchStatusService {
|
||||
// 正式批量第二次正式处理汇总结果表
|
||||
public static final String MARKETING_PERFORMANCE_M = "marketing_performance_m";
|
||||
// 状态检查间隔时间
|
||||
private static final int WAIT_TIME = 10;
|
||||
private static final int WAIT_TIME = Integer.parseInt(ConfigManager.getString("batch.query.wait.time", "60"));;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(BatchStatusService.class);
|
||||
private static final Logger batchLogger = LoggerFactory.getLogger("BATCH_EXECUTION");
|
||||
|
||||
@ -9,13 +9,13 @@ public class BizTest {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
AbstractBusinessProcessor processor = BusinessProcessorFactory.createProcessor("BIZ002");
|
||||
AbstractBusinessProcessor processor = BusinessProcessorFactory.createProcessor("BIZ032");
|
||||
|
||||
// 设置测试参数
|
||||
String batchDate = "2025-09"; // 测试日期
|
||||
String batchDate = "2025-10"; // 测试日期
|
||||
String batchType = "PRE"; // 批量类型
|
||||
|
||||
System.out.println("创建BIZ002处理器成功,开始执行业务处理...");
|
||||
System.out.println("创建BIZ32处理器成功,开始执行业务处理...");
|
||||
|
||||
// 执行业务处理
|
||||
AbstractBusinessProcessor.ProcessResult result = processor.process(batchDate, batchType);
|
||||
|
||||
@ -5,6 +5,8 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
import java.time.YearMonth;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@ -20,9 +22,110 @@ public class DateUtils {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DateUtils.class);
|
||||
|
||||
// 日期格式化器
|
||||
private static final DateTimeFormatter YYYY_MM_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM");
|
||||
private static final DateTimeFormatter YYYYMMDD_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||
private static final DateTimeFormatter YYYY_MM_DD_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
|
||||
|
||||
/**
|
||||
* 获取指定年月的月末日期
|
||||
*
|
||||
* @param yearMonth 格式为 "YYYY-MM" 的字符串
|
||||
* @return 格式为 "YYYY-MM-dd" 的月末日期
|
||||
* @throws IllegalArgumentException 如果输入参数无效
|
||||
*/
|
||||
public static String getLastDayOfMonth(String yearMonth) {
|
||||
validateYearMonth(yearMonth);
|
||||
YearMonth ym = YearMonth.parse(yearMonth.trim(), YYYY_MM_FORMATTER);
|
||||
return ym.atEndOfMonth().format(YYYY_MM_DD_FORMATTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取月末日期(紧凑格式,不带连字符)
|
||||
*
|
||||
* @param yearMonth 格式为 "YYYY-MM" 的字符串
|
||||
* @return 格式为 "YYYYMMdd" 的月末日期
|
||||
*/
|
||||
public static String getLastDayOfMonthCompact(String yearMonth) {
|
||||
validateYearMonth(yearMonth);
|
||||
YearMonth ym = YearMonth.parse(yearMonth.trim(), YYYY_MM_FORMATTER);
|
||||
return ym.atEndOfMonth().format(YYYYMMDD_FORMATTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取月初日期
|
||||
*
|
||||
* @param yearMonth 格式为 "YYYY-MM" 的字符串
|
||||
* @return 格式为 "YYYY-MM-dd" 的月初日期(1号)
|
||||
*/
|
||||
public static String getFirstDayOfMonth(String yearMonth) {
|
||||
validateYearMonth(yearMonth);
|
||||
YearMonth ym = YearMonth.parse(yearMonth.trim(), YYYY_MM_FORMATTER);
|
||||
return ym.atDay(1).format(YYYY_MM_DD_FORMATTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取月份的天数
|
||||
*
|
||||
* @param yearMonth 格式为 "YYYY-MM" 的字符串
|
||||
* @return 该月的天数
|
||||
*/
|
||||
public static int getDaysInMonth(String yearMonth) {
|
||||
validateYearMonth(yearMonth);
|
||||
YearMonth ym = YearMonth.parse(yearMonth.trim(), YYYY_MM_FORMATTER);
|
||||
return ym.lengthOfMonth();
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证年月字符串格式
|
||||
*/
|
||||
private static void validateYearMonth(String yearMonth) {
|
||||
if (yearMonth == null || yearMonth.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("年月参数不能为空");
|
||||
}
|
||||
|
||||
if (!yearMonth.matches("\\d{4}-\\d{2}")) {
|
||||
throw new IllegalArgumentException("年月格式不正确,应为 YYYY-MM: " + yearMonth);
|
||||
}
|
||||
|
||||
// 验证月份是否在有效范围内
|
||||
String[] parts = yearMonth.split("-");
|
||||
int year = Integer.parseInt(parts[0]);
|
||||
int month = Integer.parseInt(parts[1]);
|
||||
|
||||
if (month < 1 || month > 12) {
|
||||
throw new IllegalArgumentException("月份必须在 1-12 之间: " + yearMonth);
|
||||
}
|
||||
|
||||
if (year < 1900 || year > 2100) {
|
||||
throw new IllegalArgumentException("年份超出有效范围 (1900-2100): " + yearMonth);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前月份的上一个月
|
||||
*
|
||||
* @param yearMonth 格式为 "YYYY-MM" 的字符串
|
||||
* @return 上一个月的 YYYY-MM 格式字符串
|
||||
*/
|
||||
public static String getPreviousMonth(String yearMonth) {
|
||||
validateYearMonth(yearMonth);
|
||||
YearMonth ym = YearMonth.parse(yearMonth.trim(), YYYY_MM_FORMATTER);
|
||||
return ym.minusMonths(1).format(YYYY_MM_FORMATTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前月份的下一个月
|
||||
*
|
||||
* @param yearMonth 格式为 "YYYY-MM" 的字符串
|
||||
* @return 下一个月的 YYYY-MM 格式字符串
|
||||
*/
|
||||
public static String getNextMonth(String yearMonth) {
|
||||
validateYearMonth(yearMonth);
|
||||
YearMonth ym = YearMonth.parse(yearMonth.trim(), YYYY_MM_FORMATTER);
|
||||
return ym.plusMonths(1).format(YYYY_MM_FORMATTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取今天的日期字符串 (yyyyMMdd格式)
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user