[英]Passing PL/SQL parameter in Java Batch
您好,我有一个邮件批处理应用程序。 在此应用程序中,有一个 sql 脚本,脚本值中的 2 个字段应取自变量,并且此变量连接到服务器中的 .yml 文件。 首先,我从配置文件(.yml)中获取值,但无法在我的 sql 脚本中分配该值。 我也有行映射器。 注意我可以从 .yml 文件中获取值,但我没有成功地将这些值分配给 sql。 这些值在我的 tasklet 中的 createAlertMailDto 方法中,它们的名称是 CountParameterValue 和 IntervalMinuteParameterValue。 我在下面添加我的代码谢谢。 我的 sql:
WITH qM AS (
SELECT /*+parallel(8)*/ mdmtxn.MID,
mdmtxn.MDSTATUS,
mdmtxn.BIN,
COUNT(*) AS COUNT,
ROUND(ratio_to_report(COUNT(*)) OVER (PARTITION BY MID,BIN), 2) AS RATIO,
mer.MERCHANT_NAME
FROM MDM59.MDMTRANSACTION2 mdmtxn
INNER JOIN OC_VPOS.VPOS_MERCHANT mer on mer.MERCHANT_NO = MID AND mer.STATUS = 1
WHERE
mdmtxn.CREATEDDATE > TO_CHAR(SYSDATE - INTERVAL ':intervalMinuteParameterValue'
MINUTE ,'YYYYMMDD HH24:MI:SS')
GROUP BY mdmtxn.MID, mdmtxn.MDSTATUS, mdmtxn.BIN, mer.MERCHANT_NAME
ORDER BY COUNT(*) DESC, mdmtxn.MID, mdmtxn.BIN
)
SELECT * FROM qM
WHERE MDSTATUS IN ('2','4','9')
AND COUNT >=: countParameterValue
我的 model
@Value
@Builder
@Data
public class VposNotificationBatchDto {
public String mid;
public String mdStatus;
public String bin;
public String count;
public String ratio;
public String merchantName;
}
我的行映射器:
@Component
public class DailyNotificationReportRw implements
RowMapper<VposNotificationBatchDto> {
@Override
public VposNotificationBatchDto mapRow(ResultSet rs, int rowNum) throws
SQLException {
return VposNotificationBatchDto.builder()
.mid(rs.getString("MID"))
.mdStatus(rs.getString("MDSTATUS"))
.bin(rs.getString("BIN"))
.count(rs.getString("COUNT"))
.ratio(rs.getString("RATIO"))
.merchantName(rs.getString("MERCHANT_NAME"))
.build();
}
private static class DailyNotificationDetailRwHolder {
private static final DailyNotificationReportRw INSTANCE = new
DailyNotificationReportRw();
}
public static DailyNotificationReportRw getInstance() {
return DailyNotificationReportRw.DailyNotificationDetailRwHolder.INSTANCE;
}
}
我的小任务:
@Slf4j
@Component
@RequiredArgsConstructor
public class NotificationTasklet implements Tasklet {
private final PofPostOfficeServiceClient pofPostOfficeServiceClient;
private JdbcTemplate jdbcTemplate;
private String notificationMailSql;
private String endOfHtmlString = "</table></body></html>";
private String jobName = "vposbatchclosetransporter";
private final SequenceSysGuid sequenceSysGuid;
private final BatchProps batchProps;
private String reportErrorMessage = "";
private int severity = Constants.SEVERITY_SUCCESS;
@Override
public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
reportErrorMessage = "";
severity = Constants.SEVERITY_SUCCESS;
List<VposNotificationBatchDto> notificationList = getNotificationList();
AlertMailDto alertMailDto = createAlertMailDto(notificationList);
sendMail(alertMailDto);
return RepeatStatus.FINISHED;
}
private void sendMail(AlertMailDto alertMailDto) {
try {
pofPostOfficeServiceClient.sendOperationalMail(alertMailDto);
} catch (Exception ex) {
log.error(ex.getMessage());
}
}
public AlertMailDto createAlertMailDto(List<VposNotificationBatchDto> notificationList ) {
AlertMailDto alertMailDto = new AlertMailDto();
alertMailDto.setCcAddressList(batchProps.getJobProps()
.get(jobName).getAlertProps().getCcAddressList());
alertMailDto.setToAddressList(batchProps.getJobProps()
.get(jobName).getAlertProps().getToAddressList());
alertMailDto.setMailSubject(batchProps.getJobProps()
.get(jobName).getAlertProps().getMailSubject());
alertMailDto.setSenderAddress(batchProps.getJobProps()
.get(jobName).getAlertProps().getSenderAddress());
alertMailDto.setUserName(batchProps.getJobProps()
.get(jobName).getAlertProps().getUserName());
alertMailDto.setSenderAlias(batchProps.getJobProps()
.get(jobName).getAlertProps().getSenderAlias());
alertMailDto.setIntervalMinuteParameterValue(batchProps.getJobProps()
.get(jobName).getAlertProps().getIntervalMinuteParameterValue());
alertMailDto.setCountParameterValue(batchProps.getJobProps()
.get(jobName).getAlertProps().getCountParameterValue());
alertMailDto.setMailBody(createMailBody(notificationList));
String currentMailSubject = batchProps.getJobProps().get(jobName).getAlertProps().getMailSubject();
if (severity == Constants.SEVERITY_ERROR) {
alertMailDto.setMailSubject("***ERROR*** - " + currentMailSubject);
} else if (severity == Constants.SEVERITY_WARNING) {
alertMailDto.setMailSubject("***WARNING*** - " + currentMailSubject);
}
return alertMailDto;
}
public String createMailBody(List<VposNotificationBatchDto> notificationList) {
String mailBody = "Merhaba,<br/><br/>Güvenli İşlem Raporu için işlem detayları aşağıdaki gibidir.";
String errorBody = "errorBody";
mailBody += errorBody;
mailBody += "<br/><br/><br/>";
mailBody += "<html><head><style>table{font-family: arial, sans-serif;border-collapse: collapse;width: 75%;}th{background-color: #9A9A9A;}";
mailBody += "td,th{border: 1px solid #dddddd;text-align: left;padding: 8px;}tr:nth-child(even){background-color: #dddddd;}</style>";
mailBody += "</head><body><h3>Güvenli İşlem Rapor Detayları : </h3><table><tr><th>ÜYE İŞYERİ ID</th><th>MD STATUS</th><th>BIN</th><th>İŞLEM SAYISI</th><th>ORAN</th><th>ÜYE İŞYERİ</th></tr>";
for (int i = 0; i < notificationList.size(); i++) {
mailBody += "<tr><td>" + notificationList.get(i).getMid() + "</td>";
mailBody += "<td>" + notificationList.get(i).getMdStatus() + "</td>";
mailBody += "<td>" + notificationList.get(i).getBin() + "</td>";
mailBody += "<td>" + notificationList.get(i).getCount() + "</td>";
mailBody += "<td>" + notificationList.get(i).getRatio() + "</td>";
mailBody += "<td>" + notificationList.get(i).getMerchantName() + "</td></tr>";
//mailBody += endOfHtmlString;
//mailBody += "<br/><br/><br/><br/>";
//mailBody += createMetricDetails(vposNotificationBatchDtoList,i);
String currentMailSubject = batchProps.getJobProps().get(jobName).getAlertProps().getMailSubject();
if (severity == Constants.SEVERITY_SUCCESS) {
mailBody = mailBody.replace("th{background-color: #9A9A9A;}","th{background-color: #5FA8CC;}");
mailBody = mailBody.replace("errorBody","");
} else if (severity == Constants.SEVERITY_ERROR) {
mailBody = mailBody.replace("th{background-color: #9A9A9A;}","th{background-color: #DE0202;}");
mailBody = mailBody.replace("errorBody","<br/><br/><br/><div style=\"width: 75%;\">"
+ "<h4 style=\"background-color:yellow; color:#701500; border: 1px solid\">Lütfen aşağıda belirtilen "
+ "metrikleri kontrol ediniz : <br/><br/>" + reportErrorMessage + "</h4></div>");
} else if (severity == Constants.SEVERITY_WARNING) {
mailBody = mailBody.replace("th{background-color: #9A9A9A;}", "th{background-color: #E96A06;}");
mailBody = mailBody.replace("errorBody", "<br/><br/><br/><div style=\"width: 75%;\">"
+ "<h4 style=\"background-color:yellow; color:#701500; border: 1px solid\">Lütfen aşağıda belirtilen metrikleri "
+ "kontrol ediniz : <br/><br/><h3>" + reportErrorMessage + "</h4></div>");
break;
}
}
mailBody += endOfHtmlString;
return mailBody;
}
List<VposNotificationBatchDto> getNotificationList() {
return jdbcTemplate.query(
notificationMailSql,
new DailyNotificationReportRw());
}
@Autowired
public void setNotificationMailSql(@Value("classpath:sql/vposbatchclosetransporter/select_notification_batch_data.sql")
Resource res) {
this.notificationMailSql = SqlUtils.readSql(res);
}
@Autowired
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.