修改总控中第一次和第二次批量调用内容
This commit is contained in:
parent
d24055f1f1
commit
3822844ee4
@ -7,7 +7,6 @@ import com.gtsoft.mps.batch.processor.BusinessProcessorFactory;
|
||||
import com.gtsoft.mps.batch.service.BatchStatusService;
|
||||
import com.gtsoft.mps.batch.service.BusinessControlService;
|
||||
import com.gtsoft.mps.batch.util.DatabaseConnection;
|
||||
import com.gtsoft.mps.batch.util.DateUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -263,7 +262,7 @@ public class MpsFormalBatchMain {
|
||||
BatchStatusService.STATUS_RUNNING,
|
||||
"正式批量重跑开始执行"
|
||||
);
|
||||
return executeMainBatch(batchMonth);
|
||||
return executeAfterBatch(batchMonth);
|
||||
}
|
||||
|
||||
// 如果导入状态未完成,等待60分钟
|
||||
@ -326,7 +325,7 @@ public class MpsFormalBatchMain {
|
||||
"正式批量开始执行"
|
||||
);
|
||||
//执行正式批量
|
||||
return executeMainBatch(batchMonth);
|
||||
return executeAfterBatch(batchMonth);
|
||||
}
|
||||
|
||||
// 如果导入状态未完成,等待60分钟
|
||||
@ -386,9 +385,33 @@ public class MpsFormalBatchMain {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 执行前置业务程序
|
||||
if (!executePreBusinessProcessors(batchMonth)) {
|
||||
String message = "预处理业务程序执行失败";
|
||||
// 执行初始化业务程序
|
||||
if (!executeInitializationProcessors(batchMonth)) {
|
||||
String message = "初始化业务程序执行失败";
|
||||
batchStatusService.updateBatchStatus(
|
||||
batchMonth,
|
||||
BatchStatusService.BATCH_TYPE_PRE,
|
||||
BatchStatusService.STATUS_FAILED,
|
||||
message
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 执行业务指标加工批量
|
||||
if (!executeBizProcesses(batchMonth)) {
|
||||
String message = "业务指标加工程序执行失败";
|
||||
batchStatusService.updateBatchStatus(
|
||||
batchMonth,
|
||||
BatchStatusService.BATCH_TYPE_PRE,
|
||||
BatchStatusService.STATUS_FAILED,
|
||||
message
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 执行汇总批量
|
||||
if (!executeTotalProcesses(batchMonth)) {
|
||||
String message = "汇总程序执行失败";
|
||||
batchStatusService.updateBatchStatus(
|
||||
batchMonth,
|
||||
BatchStatusService.BATCH_TYPE_PRE,
|
||||
@ -435,9 +458,195 @@ public class MpsFormalBatchMain {
|
||||
/**
|
||||
* 执行正式批量
|
||||
*/
|
||||
private boolean executeMainBatch(String batchMonth) {
|
||||
private boolean executeAfterBatch(String batchMonth) {
|
||||
batchLogger.info("========== 开始执行正式批量: {} ==========", batchMonth);
|
||||
|
||||
try {
|
||||
|
||||
// 执行初始化业务程序
|
||||
if (!executeInitializationProcessors(batchMonth)) {
|
||||
String message = "初始化业务程序执行失败";
|
||||
batchStatusService.updateBatchStatus(
|
||||
batchMonth,
|
||||
BatchStatusService.BATCH_TYPE_PRE,
|
||||
BatchStatusService.STATUS_FAILED,
|
||||
message
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 执行业务指标加工批量
|
||||
if (!executeBizProcesses(batchMonth)) {
|
||||
String message = "业务指标加工程序执行失败";
|
||||
batchStatusService.updateBatchStatus(
|
||||
batchMonth,
|
||||
BatchStatusService.BATCH_TYPE_PRE,
|
||||
BatchStatusService.STATUS_FAILED,
|
||||
message
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 执行汇总批量
|
||||
if (!executeTotalProcesses(batchMonth)) {
|
||||
String message = "汇总程序执行失败";
|
||||
batchStatusService.updateBatchStatus(
|
||||
batchMonth,
|
||||
BatchStatusService.BATCH_TYPE_PRE,
|
||||
BatchStatusService.STATUS_FAILED,
|
||||
message
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 更新状态为成功
|
||||
batchStatusService.updateBatchStatus(
|
||||
batchMonth,
|
||||
BatchStatusService.BATCH_TYPE_MAIN,
|
||||
BatchStatusService.STATUS_SUCCESS,
|
||||
"正式批量执行完成"
|
||||
);
|
||||
|
||||
batchLogger.info("========== 正式批量成功完成 ==========");
|
||||
return true;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("正式批量执行异常: {}", batchMonth, e);
|
||||
batchStatusService.updateBatchStatus(
|
||||
batchMonth,
|
||||
BatchStatusService.BATCH_TYPE_PRE,
|
||||
BatchStatusService.STATUS_FAILED,
|
||||
"正式批量异常: " + e.getMessage()
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行数据初始化检查
|
||||
*/
|
||||
private boolean executeDataInitializationCheck(String batchMonth) throws NoDataToProcessException {
|
||||
batchLogger.info("开始执行数据初始化检查...");
|
||||
|
||||
try {
|
||||
// 检查当日是否有需要处理的营销数据
|
||||
if (!checkTodayProcessingData(batchMonth)) {
|
||||
batchLogger.info("营销表中未查询到[" + batchMonth + "]数据");
|
||||
throw new NoDataToProcessException("营销表中未查询到[" + batchMonth + "]数据");
|
||||
}
|
||||
|
||||
batchLogger.info("数据初始化检查完成");
|
||||
return true;
|
||||
|
||||
} catch (NoDataToProcessException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
batchLogger.error("数据初始化检查异常: {}", e.getMessage());
|
||||
logger.error("数据初始化检查异常", e);
|
||||
throw new RuntimeException("数据初始化检查失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查当日是否有需要处理的营销数据
|
||||
*/
|
||||
private boolean checkTodayProcessingData(String batchMonth) {
|
||||
batchLogger.info("检查当日营销数据,批次: {}", batchMonth);
|
||||
|
||||
try {
|
||||
DatabaseConnection dbConnection = DatabaseConnection.getInstance();
|
||||
|
||||
// 检查当日是否有可以处理的经办人员数据
|
||||
String jbCountSql =
|
||||
"SELECT COUNT(1) " +
|
||||
"FROM mps_market a " +
|
||||
"INNER JOIN sys_user b ON a.jb_id = b.mkt_no AND a.del_flag = '0' " +
|
||||
"WHERE a.del_flag = '0' AND substr(a.entry_date,1,7) = ?";
|
||||
|
||||
int count = dbConnection.queryForInt(jbCountSql, batchMonth);
|
||||
batchLogger.info("当日营销数据数量: {}", count);
|
||||
|
||||
if (count == 0) {
|
||||
batchLogger.info("当日未查询到有效营销数据记录");
|
||||
return false;
|
||||
}
|
||||
|
||||
batchLogger.info("当日营销数据检查通过,预计可处理营销记录数量: {}", count);
|
||||
return true;
|
||||
|
||||
} catch (Exception e) {
|
||||
batchLogger.error("检查当日营销数据异常: {}", e.getMessage());
|
||||
logger.error("检查当日营销数据异常", e);
|
||||
throw new RuntimeException("检查当日营销数据失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行初始化业务程序
|
||||
*/
|
||||
private boolean executeInitializationProcessors(String batchMonth) throws NoDataToProcessException {
|
||||
batchLogger.info("开始执行初始化业务程序...");
|
||||
|
||||
try {
|
||||
// 定义前置业务程序列表
|
||||
String[] preBusinessCodes = {
|
||||
"PRE001", // 调岗信息
|
||||
"PRE002", // 初始员工信息
|
||||
// 其他前置业务程序
|
||||
};
|
||||
|
||||
batchLogger.info("需要执行的初始化业务程序数量: {}", preBusinessCodes.length);
|
||||
|
||||
// 按顺序执行每个前置业务程序
|
||||
for (String businessCode : preBusinessCodes) {
|
||||
batchLogger.info("开始执行初始化业务程序: {}", businessCode);
|
||||
|
||||
try {
|
||||
// 检查业务处理器是否支持
|
||||
if (!BusinessProcessorFactory.isSupported(businessCode)) {
|
||||
batchLogger.error("初始化业务程序{}不支持,请检查配置", businessCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 创建并执行业务处理器
|
||||
AbstractBusinessProcessor processor = BusinessProcessorFactory.createProcessor(businessCode);
|
||||
AbstractBusinessProcessor.ProcessResult result = processor.process(batchMonth);
|
||||
|
||||
if (!result.isSuccess()) {
|
||||
batchLogger.error("初始化业务程序{}执行失败: {}", businessCode, result.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
batchLogger.info("初始化业务程序{}执行成功,处理记录数: {}, 耗时: {}ms",
|
||||
businessCode, result.getProcessedCount(), result.getDuration());
|
||||
|
||||
} catch (NoDataToProcessException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
batchLogger.error("初始化业务程序{}执行异常: {}", businessCode, e.getMessage());
|
||||
logger.error("初始化业务程序{}执行异常", businessCode, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
batchLogger.info("所有初始化业务程序执行完成");
|
||||
return true;
|
||||
|
||||
} catch (NoDataToProcessException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
batchLogger.error("初始化业务程序执行异常: {}", e.getMessage());
|
||||
logger.error("初始化业务程序执行异常", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行指标加工程序
|
||||
*/
|
||||
private boolean executeBizProcesses(String batchMonth) {
|
||||
batchLogger.info("开始执行指标加工程序...");
|
||||
|
||||
try {
|
||||
// 获取需要执行的业务列表
|
||||
List<String> businessesToExecute = getBusinessesToExecute();
|
||||
@ -509,179 +718,12 @@ public class MpsFormalBatchMain {
|
||||
}
|
||||
}
|
||||
|
||||
// 执行汇总程序
|
||||
if (!executeAfterProcesses(batchMonth)) {
|
||||
String message = "汇总程序执行失败";
|
||||
batchStatusService.updateBatchStatus(
|
||||
batchMonth,
|
||||
BatchStatusService.BATCH_TYPE_MAIN,
|
||||
BatchStatusService.STATUS_FAILED,
|
||||
message
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 更新批量状态
|
||||
if (allSuccess) {
|
||||
String message = String.format("批量处理成功,共处理%d个业务", results.size());
|
||||
batchStatusService.updateBatchStatus(
|
||||
batchMonth,
|
||||
BatchStatusService.BATCH_TYPE_MAIN,
|
||||
BatchStatusService.STATUS_SUCCESS,
|
||||
message
|
||||
);
|
||||
|
||||
// 打印处理结果摘要
|
||||
printExecutionSummary(batchMonth, results);
|
||||
|
||||
batchLogger.info("========== 正式批量成功完成 ==========");
|
||||
return true;
|
||||
} else {
|
||||
// 使用详细的错误信息
|
||||
String message = failureReason != null ? failureReason :
|
||||
"批量处理失败,部分业务处理失败";
|
||||
batchStatusService.updateBatchStatus(
|
||||
batchMonth,
|
||||
BatchStatusService.BATCH_TYPE_MAIN,
|
||||
BatchStatusService.STATUS_FAILED,
|
||||
message
|
||||
);
|
||||
|
||||
// 打印已处理业务的结果摘要
|
||||
if (!results.isEmpty()) {
|
||||
printExecutionSummary(batchMonth, results);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("正式批量执行异常: {}", batchMonth, e);
|
||||
batchStatusService.updateBatchStatus(
|
||||
batchMonth,
|
||||
BatchStatusService.BATCH_TYPE_MAIN,
|
||||
BatchStatusService.STATUS_FAILED,
|
||||
"正式批量异常: " + e.getMessage()
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行数据初始化检查
|
||||
*/
|
||||
private boolean executeDataInitializationCheck(String batchMonth) throws NoDataToProcessException {
|
||||
batchLogger.info("开始执行数据初始化检查...");
|
||||
|
||||
try {
|
||||
// 检查当日是否有需要处理的营销数据
|
||||
if (!checkTodayProcessingData(batchMonth)) {
|
||||
batchLogger.info("营销表中未查询到[" + batchMonth + "]数据");
|
||||
throw new NoDataToProcessException("营销表中未查询到[" + batchMonth + "]数据");
|
||||
}
|
||||
|
||||
batchLogger.info("数据初始化检查完成");
|
||||
return true;
|
||||
|
||||
} catch (NoDataToProcessException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
batchLogger.error("数据初始化检查异常: {}", e.getMessage());
|
||||
logger.error("数据初始化检查异常", e);
|
||||
throw new RuntimeException("数据初始化检查失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查当日是否有需要处理的营销数据
|
||||
*/
|
||||
private boolean checkTodayProcessingData(String batchMonth) {
|
||||
batchLogger.info("检查当日营销数据,批次: {}", batchMonth);
|
||||
|
||||
try {
|
||||
DatabaseConnection dbConnection = DatabaseConnection.getInstance();
|
||||
|
||||
// 检查当日是否有可以处理的经办人员数据
|
||||
String jbCountSql =
|
||||
"SELECT COUNT(1) " +
|
||||
"FROM mps_market a " +
|
||||
"INNER JOIN sys_user b ON a.jb_id = b.mkt_no AND a.del_flag = '0' " +
|
||||
"WHERE a.del_flag = '0' AND substr(a.entry_date,1,7) = ?";
|
||||
|
||||
int count = dbConnection.queryForInt(jbCountSql, batchMonth);
|
||||
batchLogger.info("当日营销数据数量: {}", count);
|
||||
|
||||
if (count == 0) {
|
||||
batchLogger.info("当日未查询到有效营销数据记录");
|
||||
return false;
|
||||
}
|
||||
|
||||
batchLogger.info("当日营销数据检查通过,预计可处理营销记录数量: {}", count);
|
||||
batchLogger.info("所有指标加工业务程序执行完成");
|
||||
return true;
|
||||
|
||||
} catch (Exception e) {
|
||||
batchLogger.error("检查当日营销数据异常: {}", e.getMessage());
|
||||
logger.error("检查当日营销数据异常", e);
|
||||
throw new RuntimeException("检查当日营销数据失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行前置业务程序
|
||||
*/
|
||||
private boolean executePreBusinessProcessors(String batchMonth) throws NoDataToProcessException {
|
||||
batchLogger.info("开始执行前置业务程序...");
|
||||
|
||||
try {
|
||||
// 定义前置业务程序列表
|
||||
String[] preBusinessCodes = {
|
||||
"PRE001", // 调岗信息
|
||||
"PRE002", // 初始员工信息
|
||||
// 其他前置业务程序
|
||||
};
|
||||
|
||||
batchLogger.info("需要执行的前置业务程序数量: {}", preBusinessCodes.length);
|
||||
|
||||
// 按顺序执行每个前置业务程序
|
||||
for (String businessCode : preBusinessCodes) {
|
||||
batchLogger.info("开始执行前置业务程序: {}", businessCode);
|
||||
|
||||
try {
|
||||
// 检查业务处理器是否支持
|
||||
if (!BusinessProcessorFactory.isSupported(businessCode)) {
|
||||
batchLogger.error("前置业务程序{}不支持,请检查配置", businessCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 创建并执行业务处理器
|
||||
AbstractBusinessProcessor processor = BusinessProcessorFactory.createProcessor(businessCode);
|
||||
AbstractBusinessProcessor.ProcessResult result = processor.process(batchMonth);
|
||||
|
||||
if (!result.isSuccess()) {
|
||||
batchLogger.error("前置业务程序{}执行失败: {}", businessCode, result.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
batchLogger.info("前置业务程序{}执行成功,处理记录数: {}, 耗时: {}ms",
|
||||
businessCode, result.getProcessedCount(), result.getDuration());
|
||||
|
||||
} catch (NoDataToProcessException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
batchLogger.error("前置业务程序{}执行异常: {}", businessCode, e.getMessage());
|
||||
logger.error("前置业务程序{}执行异常", businessCode, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
batchLogger.info("所有前置业务程序执行完成");
|
||||
return true;
|
||||
|
||||
} catch (NoDataToProcessException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
batchLogger.error("前置业务程序执行异常: {}", e.getMessage());
|
||||
logger.error("前置业务程序执行异常", e);
|
||||
batchLogger.error("指标加工程序执行异常: {}", e.getMessage());
|
||||
logger.error("指标加工程序执行异常", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -689,7 +731,7 @@ public class MpsFormalBatchMain {
|
||||
/**
|
||||
* 执行汇总程序
|
||||
*/
|
||||
private boolean executeAfterProcesses(String batchMonth) {
|
||||
private boolean executeTotalProcesses(String batchMonth) {
|
||||
batchLogger.info("开始执行汇总程序...");
|
||||
|
||||
try {
|
||||
|
@ -210,7 +210,7 @@ public class BatchStatusService {
|
||||
BatchStatus status = getBatchStatus(batchMonth);
|
||||
if (status == null) return false;
|
||||
|
||||
return "1".equals(status.importStatus) &&
|
||||
return STATUS_SUCCESS.equals(status.importStatus) &&
|
||||
(STATUS_INITIAL.equals(status.preBatchStatus) ||
|
||||
STATUS_FAILED.equals(status.preBatchStatus));
|
||||
}
|
||||
@ -223,7 +223,7 @@ public class BatchStatusService {
|
||||
if (status == null) return false;
|
||||
|
||||
return STATUS_SUCCESS.equals(status.preBatchStatus) &&
|
||||
"1".equals(status.checkStatus) &&
|
||||
STATUS_SUCCESS.equals(status.checkStatus) &&
|
||||
(STATUS_INITIAL.equals(status.afterBatchStatus) ||
|
||||
STATUS_FAILED.equals(status.afterBatchStatus));
|
||||
}
|
||||
@ -234,7 +234,7 @@ public class BatchStatusService {
|
||||
public boolean isImportCompleted(String batchMonth) {
|
||||
BatchStatus status = getBatchStatus(batchMonth);
|
||||
if (status == null) return false;
|
||||
return "1".equals(status.importStatus);
|
||||
return STATUS_SUCCESS.equals(status.importStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -244,7 +244,7 @@ public class BatchStatusService {
|
||||
BatchStatus status = getBatchStatus(batchMonth);
|
||||
if (status == null) return false;
|
||||
return STATUS_SUCCESS.equals(status.preBatchStatus) &&
|
||||
"1".equals(status.checkStatus);
|
||||
STATUS_SUCCESS.equals(status.checkStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user