Я новичок ie когда доходит до запроса, и у меня возникают некоторые проблемы, подобные этой.
У меня есть 2 таблицы, подобные этой
transactions
+-----+------------+----------+------------+
| id | trans |trans_code| trans_time |
+-----+------------+----------+------------+
| 1 | trans1 | x01 | 22:00 |
| 2 | trans2 | x01 | 17:00 |
| 3 | trans3 | x02 | 23:00 |
| 4 | trans4 | x03 | 20:00 |
+-----+------------+----------+------------+
restricted_code
+-----+--------+----------------+--------------+
| id | code |time_limit_start|time_limit_end|
+-----+--------+----------------+--------------+
| 1 | x01 | 21:00 | 24:00 |
| 2 | x03 | 16:00 | 23:00 |
+-----+--------+----------------+--------------+
expected result
+-----+------------+----------+------------+
| id | trans |trans_code| trans_time |
+-----+------------+----------+------------+
| 1 | trans1 | x01 | 22:00 |
| 4 | trans4 | x03 | 20:00 |
+-----+------------+----------+------------+
Я хочу получить каждую транзакцию, где trans_code присутствует в любой строке из таблицы limited_code и trans_time между time_limit_start и time_limit_end из соответствующей строки
Я пытался использовать @Query в JPARepository для выполнения запроса с этим кодом
@Query(value = "select t from transactions t, restricted_code rc where t.trans_code = rc.code and t.trans_time >= rc.time_limit_start and t.trans_time <= rc.time_limit_end")
возможно ли получить ожидаемые результаты? или мне нужно получить все данные и l oop это вручную, чтобы проверить, какие транзакции соответствуют условию?
edit 1
вот мой код
@Repository
public interface TransactionRequestRepository extends JpaRepository<TransactionRequest, Long> {
@Query(value = "select tr.transactionAmount as transactionAmount, ta.status as transactionStatus, ta.authResponseCode as authResponseCode, tr.posEntryMode as posEntryMode, tr.serviceCode as serviceCode, ta.cardHolderName as cardHolderName, tr.transactionType as transactionType, ta.latitude as latitude, ta.longitude as longitude, b.bankName as bankName, mc.companyName as companyName, ta.txid as transactionId, ta.pan as panNumber, ta.createdDate as transactionCreatedDate from transaction_request tr, transaction_authorized ta, bank b, merchant mc, mid m, master_mcc masmcc, unexpected_transaction_mcc utm, category_master_mcc cmmcc" +
" where ta.transactionDate = :transactionDate " +
" and ta.transactionTime >= :startTime " +
" and ta.transactionTime<= :endTime " +
" and ta.transactionAuthorizedId = tr.transactionauthorizedFk.transactionAuthorizedId " +
" and ta.mid = m.mid" +
" and m.bankFk = b " +
" and m.merchantFk = mc" +
" and mc.categoryMasterMcc = cmmcc" +
" and cmmcc.categoryMasterMccId = masmcc.categoryMasterMccFk.categoryMasterMccId " +
" and ((tr.serviceCode is null " +
" and (tr.posEntryMode = '021' " +
" or tr.posEntryMode = '022')) " +
" or (ta.authResponseCode = '04' " +
" or ta.authResponseCode = '07' " +
" or ta.authResponseCode = '12' " +
" or ta.authResponseCode = '34' " +
" or ta.authResponseCode = '41' " +
" or ta.authResponseCode = '43') " +
" or ( inner join utm.mccId on masmcc.mcc and ta.transactionTime <= utm.timeLimitEnd and ta.transactionTime >= utm.timeLimitStart )) ")
List<SuspiciousTransactionProjection> findTransactionRequestByPosEntryModeAndServiceCode(@Param("transactionDate") String transactionDate,
@Param("startTime") String startTime,
@Param("endTime") String endTime);
public interface SuspiciousTransactionProjection {
Long getSuspiciousTransactionId();
String getTransactionId();
String getBankName();
String getCompanyName();
String getTransactionAmount();
String getTransactionStatus();
String getAuthResponseCode();
String getPosEntryMode();
String getServiceCode();
String getCardHolderName();
String getTransactionType();
String getLatitude();
String getLongitude();
String getPanNumber();
Date getTransactionCreatedDate();
}
я не знаете, как заставить это работать или чище, я почти уверен, что это неправильный запрос
он прекрасно работает до того, как моя последняя строка запроса
должна ли я также опубликовать другую сущность? поскольку у некоторых из них много столбцов, я не знаю, хватит ли этих двух