优化这段代码 使其调用方法后发送结果 @Override protected void executeInternal(JobExecutionContext context)throws JobExecutionException { List<Long> retailShopIdList = retailShopService.queryAllRetailShopId(); for (Long retailShopId : retailShopIdList) { RetailShop retailShop = retailShopService.get(retailShopId); if (retailShop != null) { gspCompanyLicenseService.queryLicenseReminder(retailShopId); gspUserLicenseService.queryLicenseReminder(retailShopId); retailShopLicenseService.queryLicenseReminder(retailShopId); } } }
时间: 2024-02-14 21:18:05 浏览: 66
可以将每个服务的查询方法封装成一个单独的方法,并用一个 StringBuilder 对象保存查询结果,最后将结果发送出去。代码如下:
```
@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
List<Long> retailShopIdList = retailShopService.queryAllRetailShopId();
StringBuilder result = new StringBuilder();
for (Long retailShopId : retailShopIdList) {
RetailShop retailShop = retailShopService.get(retailShopId);
if (retailShop != null) {
result.append(gspCompanyLicenseService.queryLicenseReminder(retailShopId));
result.append(gspUserLicenseService.queryLicenseReminder(retailShopId));
result.append(retailShopLicenseService.queryLicenseReminder(retailShopId));
}
}
// 将查询结果发送出去,可以通过邮件、短信等形式发送
sendResult(result.toString());
}
// 发送结果的方法
private void sendResult(String result) {
// TODO: 将结果发送出去,可以通过邮件、短信等形式发送
}
```
这样做可以将查询结果封装成一个字符串,只需要调用一次发送结果的方法,就可以将结果发送出去。同时,每个服务的查询方法也被封装到了一个单独的方法中,使得代码更加清晰简洁。
阅读全文