@Override
public ExchangeRate getRateByMonth(String currencyCode, String yearMonth) {
StringBuilder sb = new StringBuilder();
StringBuilder condition = new StringBuilder();
sb.append("select e.* from exchange_rate e where 1 = 1 ");
if (StringUtils.isNotBlank(currencyCode)) {
condition.append("and e.currency_id = '" + currencyCode + "' ");
}
if (StringUtils.isNotBlank(currencyCode)) {
condition.append("and date_format(e.rate_date,'%Y-%m')='"+yearMonth+"' ");
}
sb.append(condition).append(" order by id limit 1 ");
Query query = entityManager.createNativeQuery(sb.toString(),ExchangeRate.class);
List<ExchangeRate> list = query.getResultList();
if(list != null && list.size() > 0){
return list.get(0);
}
return null;
}